bnx2x_main.c 365 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542
  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. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. struct bnx2x_mac_vals {
  112. u32 xmac_addr;
  113. u32 xmac_val;
  114. u32 emac_addr;
  115. u32 emac_val;
  116. u32 umac_addr;
  117. u32 umac_val;
  118. u32 bmac_addr;
  119. u32 bmac_val[2];
  120. };
  121. enum bnx2x_board_type {
  122. BCM57710 = 0,
  123. BCM57711,
  124. BCM57711E,
  125. BCM57712,
  126. BCM57712_MF,
  127. BCM57712_VF,
  128. BCM57800,
  129. BCM57800_MF,
  130. BCM57800_VF,
  131. BCM57810,
  132. BCM57810_MF,
  133. BCM57810_VF,
  134. BCM57840_4_10,
  135. BCM57840_2_20,
  136. BCM57840_MF,
  137. BCM57840_VF,
  138. BCM57811,
  139. BCM57811_MF,
  140. BCM57840_O,
  141. BCM57840_MFO,
  142. BCM57811_VF
  143. };
  144. /* indexed by board_type, above */
  145. static struct {
  146. char *name;
  147. } board_info[] = {
  148. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  149. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  150. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  151. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  152. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  153. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  154. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  155. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  156. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  157. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  158. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  159. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  160. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  161. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  162. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  163. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  164. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  165. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  166. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  167. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  168. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  169. };
  170. #ifndef PCI_DEVICE_ID_NX2_57710
  171. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  172. #endif
  173. #ifndef PCI_DEVICE_ID_NX2_57711
  174. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  175. #endif
  176. #ifndef PCI_DEVICE_ID_NX2_57711E
  177. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  178. #endif
  179. #ifndef PCI_DEVICE_ID_NX2_57712
  180. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  181. #endif
  182. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  183. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  184. #endif
  185. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  186. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  187. #endif
  188. #ifndef PCI_DEVICE_ID_NX2_57800
  189. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  190. #endif
  191. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  192. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  193. #endif
  194. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  195. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  196. #endif
  197. #ifndef PCI_DEVICE_ID_NX2_57810
  198. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  199. #endif
  200. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  201. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  202. #endif
  203. #ifndef PCI_DEVICE_ID_NX2_57840_O
  204. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  205. #endif
  206. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  207. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  208. #endif
  209. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  210. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  211. #endif
  212. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  213. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  214. #endif
  215. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  216. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  217. #endif
  218. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  219. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  220. #endif
  221. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  222. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  223. #endif
  224. #ifndef PCI_DEVICE_ID_NX2_57811
  225. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  226. #endif
  227. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  228. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  229. #endif
  230. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  231. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  232. #endif
  233. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  255. { 0 }
  256. };
  257. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  258. /* Global resources for unloading a previously loaded device */
  259. #define BNX2X_PREV_WAIT_NEEDED 1
  260. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  261. static LIST_HEAD(bnx2x_prev_list);
  262. /****************************************************************************
  263. * General service functions
  264. ****************************************************************************/
  265. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  266. u32 addr, dma_addr_t mapping)
  267. {
  268. REG_WR(bp, addr, U64_LO(mapping));
  269. REG_WR(bp, addr + 4, U64_HI(mapping));
  270. }
  271. static void storm_memset_spq_addr(struct bnx2x *bp,
  272. dma_addr_t mapping, u16 abs_fid)
  273. {
  274. u32 addr = XSEM_REG_FAST_MEMORY +
  275. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  276. __storm_memset_dma_mapping(bp, addr, mapping);
  277. }
  278. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  279. u16 pf_id)
  280. {
  281. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. }
  290. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  291. u8 enable)
  292. {
  293. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. }
  302. static void storm_memset_eq_data(struct bnx2x *bp,
  303. struct event_ring_data *eq_data,
  304. u16 pfid)
  305. {
  306. size_t size = sizeof(struct event_ring_data);
  307. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  308. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  309. }
  310. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  311. u16 pfid)
  312. {
  313. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  314. REG_WR16(bp, addr, eq_prod);
  315. }
  316. /* used only at init
  317. * locking is done by mcp
  318. */
  319. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  320. {
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  324. PCICFG_VENDOR_ID_OFFSET);
  325. }
  326. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  327. {
  328. u32 val;
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  330. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  331. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  332. PCICFG_VENDOR_ID_OFFSET);
  333. return val;
  334. }
  335. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  336. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  337. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  338. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  339. #define DMAE_DP_DST_NONE "dst_addr [none]"
  340. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  341. {
  342. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  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. }
  398. /* copy command into DMAE command memory and set DMAE command go */
  399. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  400. {
  401. u32 cmd_offset;
  402. int i;
  403. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  404. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  405. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  406. }
  407. REG_WR(bp, dmae_reg_go_c[idx], 1);
  408. }
  409. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  410. {
  411. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  412. DMAE_CMD_C_ENABLE);
  413. }
  414. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  415. {
  416. return opcode & ~DMAE_CMD_SRC_RESET;
  417. }
  418. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  419. bool with_comp, u8 comp_type)
  420. {
  421. u32 opcode = 0;
  422. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  423. (dst_type << DMAE_COMMAND_DST_SHIFT));
  424. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  425. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  426. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  427. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  428. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  429. #ifdef __BIG_ENDIAN
  430. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  431. #else
  432. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  433. #endif
  434. if (with_comp)
  435. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  436. return opcode;
  437. }
  438. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  439. struct dmae_command *dmae,
  440. u8 src_type, u8 dst_type)
  441. {
  442. memset(dmae, 0, sizeof(struct dmae_command));
  443. /* set the opcode */
  444. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  445. true, DMAE_COMP_PCI);
  446. /* fill in the completion parameters */
  447. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  448. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_val = DMAE_COMP_VAL;
  450. }
  451. /* issue a dmae command over the init-channel and wait for completion */
  452. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  453. {
  454. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  455. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  456. int rc = 0;
  457. /*
  458. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  459. * as long as this code is called both from syscall context and
  460. * from ndo_set_rx_mode() flow that may be called from BH.
  461. */
  462. spin_lock_bh(&bp->dmae_lock);
  463. /* reset completion */
  464. *wb_comp = 0;
  465. /* post the command on the channel used for initializations */
  466. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  467. /* wait for completion */
  468. udelay(5);
  469. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  470. if (!cnt ||
  471. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  472. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  473. BNX2X_ERR("DMAE timeout!\n");
  474. rc = DMAE_TIMEOUT;
  475. goto unlock;
  476. }
  477. cnt--;
  478. udelay(50);
  479. }
  480. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  481. BNX2X_ERR("DMAE PCI error!\n");
  482. rc = DMAE_PCI_ERROR;
  483. }
  484. unlock:
  485. spin_unlock_bh(&bp->dmae_lock);
  486. return rc;
  487. }
  488. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  489. u32 len32)
  490. {
  491. struct dmae_command dmae;
  492. if (!bp->dmae_ready) {
  493. u32 *data = bnx2x_sp(bp, wb_data[0]);
  494. if (CHIP_IS_E1(bp))
  495. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  496. else
  497. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  498. return;
  499. }
  500. /* set opcode and fixed command fields */
  501. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  502. /* fill in addresses and len */
  503. dmae.src_addr_lo = U64_LO(dma_addr);
  504. dmae.src_addr_hi = U64_HI(dma_addr);
  505. dmae.dst_addr_lo = dst_addr >> 2;
  506. dmae.dst_addr_hi = 0;
  507. dmae.len = len32;
  508. /* issue the command and wait for completion */
  509. bnx2x_issue_dmae_with_comp(bp, &dmae);
  510. }
  511. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  512. {
  513. struct dmae_command dmae;
  514. if (!bp->dmae_ready) {
  515. u32 *data = bnx2x_sp(bp, wb_data[0]);
  516. int i;
  517. if (CHIP_IS_E1(bp))
  518. for (i = 0; i < len32; i++)
  519. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  520. else
  521. for (i = 0; i < len32; i++)
  522. data[i] = REG_RD(bp, src_addr + i*4);
  523. return;
  524. }
  525. /* set opcode and fixed command fields */
  526. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  527. /* fill in addresses and len */
  528. dmae.src_addr_lo = src_addr >> 2;
  529. dmae.src_addr_hi = 0;
  530. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  531. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.len = len32;
  533. /* issue the command and wait for completion */
  534. bnx2x_issue_dmae_with_comp(bp, &dmae);
  535. }
  536. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  537. u32 addr, u32 len)
  538. {
  539. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  540. int offset = 0;
  541. while (len > dmae_wr_max) {
  542. bnx2x_write_dmae(bp, phys_addr + offset,
  543. addr + offset, dmae_wr_max);
  544. offset += dmae_wr_max * 4;
  545. len -= dmae_wr_max;
  546. }
  547. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  548. }
  549. static int bnx2x_mc_assert(struct bnx2x *bp)
  550. {
  551. char last_idx;
  552. int i, rc = 0;
  553. u32 row0, row1, row2, row3;
  554. /* XSTORM */
  555. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  556. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  557. if (last_idx)
  558. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  559. /* print the asserts */
  560. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  561. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  562. XSTORM_ASSERT_LIST_OFFSET(i));
  563. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  564. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  565. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  566. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  567. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  568. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  569. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  570. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  571. i, row3, row2, row1, row0);
  572. rc++;
  573. } else {
  574. break;
  575. }
  576. }
  577. /* TSTORM */
  578. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  579. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  580. if (last_idx)
  581. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  582. /* print the asserts */
  583. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  584. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  585. TSTORM_ASSERT_LIST_OFFSET(i));
  586. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  587. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  588. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  589. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  590. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  591. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  592. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  593. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  594. i, row3, row2, row1, row0);
  595. rc++;
  596. } else {
  597. break;
  598. }
  599. }
  600. /* CSTORM */
  601. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  602. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  603. if (last_idx)
  604. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  605. /* print the asserts */
  606. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  607. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  608. CSTORM_ASSERT_LIST_OFFSET(i));
  609. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  610. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  611. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  612. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  613. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  614. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  615. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  616. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  617. i, row3, row2, row1, row0);
  618. rc++;
  619. } else {
  620. break;
  621. }
  622. }
  623. /* USTORM */
  624. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  625. USTORM_ASSERT_LIST_INDEX_OFFSET);
  626. if (last_idx)
  627. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  628. /* print the asserts */
  629. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  630. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  631. USTORM_ASSERT_LIST_OFFSET(i));
  632. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  633. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  634. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  635. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  636. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  637. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  638. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  639. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  640. i, row3, row2, row1, row0);
  641. rc++;
  642. } else {
  643. break;
  644. }
  645. }
  646. return rc;
  647. }
  648. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  649. {
  650. u32 addr, val;
  651. u32 mark, offset;
  652. __be32 data[9];
  653. int word;
  654. u32 trace_shmem_base;
  655. if (BP_NOMCP(bp)) {
  656. BNX2X_ERR("NO MCP - can not dump\n");
  657. return;
  658. }
  659. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  660. (bp->common.bc_ver & 0xff0000) >> 16,
  661. (bp->common.bc_ver & 0xff00) >> 8,
  662. (bp->common.bc_ver & 0xff));
  663. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  664. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  665. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  666. if (BP_PATH(bp) == 0)
  667. trace_shmem_base = bp->common.shmem_base;
  668. else
  669. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  670. addr = trace_shmem_base - 0x800;
  671. /* validate TRCB signature */
  672. mark = REG_RD(bp, addr);
  673. if (mark != MFW_TRACE_SIGNATURE) {
  674. BNX2X_ERR("Trace buffer signature is missing.");
  675. return ;
  676. }
  677. /* read cyclic buffer pointer */
  678. addr += 4;
  679. mark = REG_RD(bp, addr);
  680. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  681. + ((mark + 0x3) & ~0x3) - 0x08000000;
  682. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  683. printk("%s", lvl);
  684. /* dump buffer after the mark */
  685. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  686. for (word = 0; word < 8; word++)
  687. data[word] = htonl(REG_RD(bp, offset + 4*word));
  688. data[8] = 0x0;
  689. pr_cont("%s", (char *)data);
  690. }
  691. /* dump buffer before the mark */
  692. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  693. for (word = 0; word < 8; word++)
  694. data[word] = htonl(REG_RD(bp, offset + 4*word));
  695. data[8] = 0x0;
  696. pr_cont("%s", (char *)data);
  697. }
  698. printk("%s" "end of fw dump\n", lvl);
  699. }
  700. static void bnx2x_fw_dump(struct bnx2x *bp)
  701. {
  702. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  703. }
  704. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  705. {
  706. int port = BP_PORT(bp);
  707. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  708. u32 val = REG_RD(bp, addr);
  709. /* in E1 we must use only PCI configuration space to disable
  710. * MSI/MSIX capablility
  711. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  712. */
  713. if (CHIP_IS_E1(bp)) {
  714. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  715. * Use mask register to prevent from HC sending interrupts
  716. * after we exit the function
  717. */
  718. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  719. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  720. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  721. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  722. } else
  723. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  724. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  725. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  726. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  727. DP(NETIF_MSG_IFDOWN,
  728. "write %x to HC %d (addr 0x%x)\n",
  729. val, port, addr);
  730. /* flush all outstanding writes */
  731. mmiowb();
  732. REG_WR(bp, addr, val);
  733. if (REG_RD(bp, addr) != val)
  734. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  735. }
  736. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  737. {
  738. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  739. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  740. IGU_PF_CONF_INT_LINE_EN |
  741. IGU_PF_CONF_ATTN_BIT_EN);
  742. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  743. /* flush all outstanding writes */
  744. mmiowb();
  745. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  746. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  747. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  748. }
  749. static void bnx2x_int_disable(struct bnx2x *bp)
  750. {
  751. if (bp->common.int_block == INT_BLOCK_HC)
  752. bnx2x_hc_int_disable(bp);
  753. else
  754. bnx2x_igu_int_disable(bp);
  755. }
  756. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  757. {
  758. int i;
  759. u16 j;
  760. struct hc_sp_status_block_data sp_sb_data;
  761. int func = BP_FUNC(bp);
  762. #ifdef BNX2X_STOP_ON_ERROR
  763. u16 start = 0, end = 0;
  764. u8 cos;
  765. #endif
  766. if (disable_int)
  767. bnx2x_int_disable(bp);
  768. bp->stats_state = STATS_STATE_DISABLED;
  769. bp->eth_stats.unrecoverable_error++;
  770. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  771. BNX2X_ERR("begin crash dump -----------------\n");
  772. /* Indices */
  773. /* Common */
  774. 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",
  775. bp->def_idx, bp->def_att_idx, bp->attn_state,
  776. bp->spq_prod_idx, bp->stats_counter);
  777. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  778. bp->def_status_blk->atten_status_block.attn_bits,
  779. bp->def_status_blk->atten_status_block.attn_bits_ack,
  780. bp->def_status_blk->atten_status_block.status_block_id,
  781. bp->def_status_blk->atten_status_block.attn_bits_index);
  782. BNX2X_ERR(" def (");
  783. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  784. pr_cont("0x%x%s",
  785. bp->def_status_blk->sp_sb.index_values[i],
  786. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  787. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  788. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  789. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  790. i*sizeof(u32));
  791. 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",
  792. sp_sb_data.igu_sb_id,
  793. sp_sb_data.igu_seg_id,
  794. sp_sb_data.p_func.pf_id,
  795. sp_sb_data.p_func.vnic_id,
  796. sp_sb_data.p_func.vf_id,
  797. sp_sb_data.p_func.vf_valid,
  798. sp_sb_data.state);
  799. for_each_eth_queue(bp, i) {
  800. struct bnx2x_fastpath *fp = &bp->fp[i];
  801. int loop;
  802. struct hc_status_block_data_e2 sb_data_e2;
  803. struct hc_status_block_data_e1x sb_data_e1x;
  804. struct hc_status_block_sm *hc_sm_p =
  805. CHIP_IS_E1x(bp) ?
  806. sb_data_e1x.common.state_machine :
  807. sb_data_e2.common.state_machine;
  808. struct hc_index_data *hc_index_p =
  809. CHIP_IS_E1x(bp) ?
  810. sb_data_e1x.index_data :
  811. sb_data_e2.index_data;
  812. u8 data_size, cos;
  813. u32 *sb_data_p;
  814. struct bnx2x_fp_txdata txdata;
  815. /* Rx */
  816. 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",
  817. i, fp->rx_bd_prod, fp->rx_bd_cons,
  818. fp->rx_comp_prod,
  819. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  820. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  821. fp->rx_sge_prod, fp->last_max_sge,
  822. le16_to_cpu(fp->fp_hc_idx));
  823. /* Tx */
  824. for_each_cos_in_tx_queue(fp, cos)
  825. {
  826. txdata = *fp->txdata_ptr[cos];
  827. 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",
  828. i, txdata.tx_pkt_prod,
  829. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  830. txdata.tx_bd_cons,
  831. le16_to_cpu(*txdata.tx_cons_sb));
  832. }
  833. loop = CHIP_IS_E1x(bp) ?
  834. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  835. /* host sb data */
  836. if (IS_FCOE_FP(fp))
  837. continue;
  838. BNX2X_ERR(" run indexes (");
  839. for (j = 0; j < HC_SB_MAX_SM; j++)
  840. pr_cont("0x%x%s",
  841. fp->sb_running_index[j],
  842. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  843. BNX2X_ERR(" indexes (");
  844. for (j = 0; j < loop; j++)
  845. pr_cont("0x%x%s",
  846. fp->sb_index_values[j],
  847. (j == loop - 1) ? ")" : " ");
  848. /* fw sb data */
  849. data_size = CHIP_IS_E1x(bp) ?
  850. sizeof(struct hc_status_block_data_e1x) :
  851. sizeof(struct hc_status_block_data_e2);
  852. data_size /= sizeof(u32);
  853. sb_data_p = CHIP_IS_E1x(bp) ?
  854. (u32 *)&sb_data_e1x :
  855. (u32 *)&sb_data_e2;
  856. /* copy sb data in here */
  857. for (j = 0; j < data_size; j++)
  858. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  859. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  860. j * sizeof(u32));
  861. if (!CHIP_IS_E1x(bp)) {
  862. 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",
  863. sb_data_e2.common.p_func.pf_id,
  864. sb_data_e2.common.p_func.vf_id,
  865. sb_data_e2.common.p_func.vf_valid,
  866. sb_data_e2.common.p_func.vnic_id,
  867. sb_data_e2.common.same_igu_sb_1b,
  868. sb_data_e2.common.state);
  869. } else {
  870. 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",
  871. sb_data_e1x.common.p_func.pf_id,
  872. sb_data_e1x.common.p_func.vf_id,
  873. sb_data_e1x.common.p_func.vf_valid,
  874. sb_data_e1x.common.p_func.vnic_id,
  875. sb_data_e1x.common.same_igu_sb_1b,
  876. sb_data_e1x.common.state);
  877. }
  878. /* SB_SMs data */
  879. for (j = 0; j < HC_SB_MAX_SM; j++) {
  880. 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",
  881. j, hc_sm_p[j].__flags,
  882. hc_sm_p[j].igu_sb_id,
  883. hc_sm_p[j].igu_seg_id,
  884. hc_sm_p[j].time_to_expire,
  885. hc_sm_p[j].timer_value);
  886. }
  887. /* Indecies data */
  888. for (j = 0; j < loop; j++) {
  889. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  890. hc_index_p[j].flags,
  891. hc_index_p[j].timeout);
  892. }
  893. }
  894. #ifdef BNX2X_STOP_ON_ERROR
  895. /* event queue */
  896. for (i = 0; i < NUM_EQ_DESC; i++) {
  897. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  898. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  899. i, bp->eq_ring[i].message.opcode,
  900. bp->eq_ring[i].message.error);
  901. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  902. }
  903. /* Rings */
  904. /* Rx */
  905. for_each_valid_rx_queue(bp, i) {
  906. struct bnx2x_fastpath *fp = &bp->fp[i];
  907. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  908. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  909. for (j = start; j != end; j = RX_BD(j + 1)) {
  910. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  911. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  912. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  913. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  914. }
  915. start = RX_SGE(fp->rx_sge_prod);
  916. end = RX_SGE(fp->last_max_sge);
  917. for (j = start; j != end; j = RX_SGE(j + 1)) {
  918. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  919. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  920. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  921. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  922. }
  923. start = RCQ_BD(fp->rx_comp_cons - 10);
  924. end = RCQ_BD(fp->rx_comp_cons + 503);
  925. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  926. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  927. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  928. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  929. }
  930. }
  931. /* Tx */
  932. for_each_valid_tx_queue(bp, i) {
  933. struct bnx2x_fastpath *fp = &bp->fp[i];
  934. for_each_cos_in_tx_queue(fp, cos) {
  935. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  936. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  937. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  938. for (j = start; j != end; j = TX_BD(j + 1)) {
  939. struct sw_tx_bd *sw_bd =
  940. &txdata->tx_buf_ring[j];
  941. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  942. i, cos, j, sw_bd->skb,
  943. sw_bd->first_bd);
  944. }
  945. start = TX_BD(txdata->tx_bd_cons - 10);
  946. end = TX_BD(txdata->tx_bd_cons + 254);
  947. for (j = start; j != end; j = TX_BD(j + 1)) {
  948. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  949. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  950. i, cos, j, tx_bd[0], tx_bd[1],
  951. tx_bd[2], tx_bd[3]);
  952. }
  953. }
  954. }
  955. #endif
  956. bnx2x_fw_dump(bp);
  957. bnx2x_mc_assert(bp);
  958. BNX2X_ERR("end crash dump -----------------\n");
  959. }
  960. /*
  961. * FLR Support for E2
  962. *
  963. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  964. * initialization.
  965. */
  966. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  967. #define FLR_WAIT_INTERVAL 50 /* usec */
  968. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  969. struct pbf_pN_buf_regs {
  970. int pN;
  971. u32 init_crd;
  972. u32 crd;
  973. u32 crd_freed;
  974. };
  975. struct pbf_pN_cmd_regs {
  976. int pN;
  977. u32 lines_occup;
  978. u32 lines_freed;
  979. };
  980. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  981. struct pbf_pN_buf_regs *regs,
  982. u32 poll_count)
  983. {
  984. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  985. u32 cur_cnt = poll_count;
  986. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  987. crd = crd_start = REG_RD(bp, regs->crd);
  988. init_crd = REG_RD(bp, regs->init_crd);
  989. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  990. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  991. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  992. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  993. (init_crd - crd_start))) {
  994. if (cur_cnt--) {
  995. udelay(FLR_WAIT_INTERVAL);
  996. crd = REG_RD(bp, regs->crd);
  997. crd_freed = REG_RD(bp, regs->crd_freed);
  998. } else {
  999. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1000. regs->pN);
  1001. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1002. regs->pN, crd);
  1003. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1004. regs->pN, crd_freed);
  1005. break;
  1006. }
  1007. }
  1008. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1009. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1010. }
  1011. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1012. struct pbf_pN_cmd_regs *regs,
  1013. u32 poll_count)
  1014. {
  1015. u32 occup, to_free, freed, freed_start;
  1016. u32 cur_cnt = poll_count;
  1017. occup = to_free = REG_RD(bp, regs->lines_occup);
  1018. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1019. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1020. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1021. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1022. if (cur_cnt--) {
  1023. udelay(FLR_WAIT_INTERVAL);
  1024. occup = REG_RD(bp, regs->lines_occup);
  1025. freed = REG_RD(bp, regs->lines_freed);
  1026. } else {
  1027. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1028. regs->pN);
  1029. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1030. regs->pN, occup);
  1031. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1032. regs->pN, freed);
  1033. break;
  1034. }
  1035. }
  1036. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1037. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1038. }
  1039. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1040. u32 expected, u32 poll_count)
  1041. {
  1042. u32 cur_cnt = poll_count;
  1043. u32 val;
  1044. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1045. udelay(FLR_WAIT_INTERVAL);
  1046. return val;
  1047. }
  1048. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1049. char *msg, u32 poll_cnt)
  1050. {
  1051. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1052. if (val != 0) {
  1053. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1054. return 1;
  1055. }
  1056. return 0;
  1057. }
  1058. /* Common routines with VF FLR cleanup */
  1059. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1060. {
  1061. /* adjust polling timeout */
  1062. if (CHIP_REV_IS_EMUL(bp))
  1063. return FLR_POLL_CNT * 2000;
  1064. if (CHIP_REV_IS_FPGA(bp))
  1065. return FLR_POLL_CNT * 120;
  1066. return FLR_POLL_CNT;
  1067. }
  1068. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1069. {
  1070. struct pbf_pN_cmd_regs cmd_regs[] = {
  1071. {0, (CHIP_IS_E3B0(bp)) ?
  1072. PBF_REG_TQ_OCCUPANCY_Q0 :
  1073. PBF_REG_P0_TQ_OCCUPANCY,
  1074. (CHIP_IS_E3B0(bp)) ?
  1075. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1076. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1077. {1, (CHIP_IS_E3B0(bp)) ?
  1078. PBF_REG_TQ_OCCUPANCY_Q1 :
  1079. PBF_REG_P1_TQ_OCCUPANCY,
  1080. (CHIP_IS_E3B0(bp)) ?
  1081. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1082. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1083. {4, (CHIP_IS_E3B0(bp)) ?
  1084. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1085. PBF_REG_P4_TQ_OCCUPANCY,
  1086. (CHIP_IS_E3B0(bp)) ?
  1087. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1088. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1089. };
  1090. struct pbf_pN_buf_regs buf_regs[] = {
  1091. {0, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_INIT_CRD_Q0 :
  1093. PBF_REG_P0_INIT_CRD ,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_CREDIT_Q0 :
  1096. PBF_REG_P0_CREDIT,
  1097. (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1099. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1100. {1, (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_INIT_CRD_Q1 :
  1102. PBF_REG_P1_INIT_CRD,
  1103. (CHIP_IS_E3B0(bp)) ?
  1104. PBF_REG_CREDIT_Q1 :
  1105. PBF_REG_P1_CREDIT,
  1106. (CHIP_IS_E3B0(bp)) ?
  1107. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1108. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1109. {4, (CHIP_IS_E3B0(bp)) ?
  1110. PBF_REG_INIT_CRD_LB_Q :
  1111. PBF_REG_P4_INIT_CRD,
  1112. (CHIP_IS_E3B0(bp)) ?
  1113. PBF_REG_CREDIT_LB_Q :
  1114. PBF_REG_P4_CREDIT,
  1115. (CHIP_IS_E3B0(bp)) ?
  1116. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1117. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1118. };
  1119. int i;
  1120. /* Verify the command queues are flushed P0, P1, P4 */
  1121. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1122. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1123. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1124. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1125. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1126. }
  1127. #define OP_GEN_PARAM(param) \
  1128. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1129. #define OP_GEN_TYPE(type) \
  1130. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1131. #define OP_GEN_AGG_VECT(index) \
  1132. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1133. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1134. {
  1135. u32 op_gen_command = 0;
  1136. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1137. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1138. int ret = 0;
  1139. if (REG_RD(bp, comp_addr)) {
  1140. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1141. return 1;
  1142. }
  1143. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1144. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1145. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1146. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1147. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1148. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1149. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1150. BNX2X_ERR("FW final cleanup did not succeed\n");
  1151. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1152. (REG_RD(bp, comp_addr)));
  1153. bnx2x_panic();
  1154. return 1;
  1155. }
  1156. /* Zero completion for nxt FLR */
  1157. REG_WR(bp, comp_addr, 0);
  1158. return ret;
  1159. }
  1160. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1161. {
  1162. u16 status;
  1163. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1164. return status & PCI_EXP_DEVSTA_TRPND;
  1165. }
  1166. /* PF FLR specific routines
  1167. */
  1168. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1169. {
  1170. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1171. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1172. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1173. "CFC PF usage counter timed out",
  1174. poll_cnt))
  1175. return 1;
  1176. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1177. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1178. DORQ_REG_PF_USAGE_CNT,
  1179. "DQ PF usage counter timed out",
  1180. poll_cnt))
  1181. return 1;
  1182. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1183. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1184. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1185. "QM PF usage counter timed out",
  1186. poll_cnt))
  1187. return 1;
  1188. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1189. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1190. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1191. "Timers VNIC usage counter timed out",
  1192. poll_cnt))
  1193. return 1;
  1194. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1195. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1196. "Timers NUM_SCANS usage counter timed out",
  1197. poll_cnt))
  1198. return 1;
  1199. /* Wait DMAE PF usage counter to zero */
  1200. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1201. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1202. "DMAE dommand register timed out",
  1203. poll_cnt))
  1204. return 1;
  1205. return 0;
  1206. }
  1207. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1208. {
  1209. u32 val;
  1210. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1211. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1212. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1213. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1214. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1215. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1216. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1217. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1218. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1219. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1220. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1221. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1222. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1223. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1224. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1225. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1226. val);
  1227. }
  1228. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1229. {
  1230. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1231. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1232. /* Re-enable PF target read access */
  1233. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1234. /* Poll HW usage counters */
  1235. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1236. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1237. return -EBUSY;
  1238. /* Zero the igu 'trailing edge' and 'leading edge' */
  1239. /* Send the FW cleanup command */
  1240. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1241. return -EBUSY;
  1242. /* ATC cleanup */
  1243. /* Verify TX hw is flushed */
  1244. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1245. /* Wait 100ms (not adjusted according to platform) */
  1246. msleep(100);
  1247. /* Verify no pending pci transactions */
  1248. if (bnx2x_is_pcie_pending(bp->pdev))
  1249. BNX2X_ERR("PCIE Transactions still pending\n");
  1250. /* Debug */
  1251. bnx2x_hw_enable_status(bp);
  1252. /*
  1253. * Master enable - Due to WB DMAE writes performed before this
  1254. * register is re-initialized as part of the regular function init
  1255. */
  1256. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1257. return 0;
  1258. }
  1259. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1260. {
  1261. int port = BP_PORT(bp);
  1262. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1263. u32 val = REG_RD(bp, addr);
  1264. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1265. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1266. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1267. if (msix) {
  1268. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1269. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1270. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1271. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1272. if (single_msix)
  1273. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1274. } else if (msi) {
  1275. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1276. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1277. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1278. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1279. } else {
  1280. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1281. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1282. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1283. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1284. if (!CHIP_IS_E1(bp)) {
  1285. DP(NETIF_MSG_IFUP,
  1286. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1287. REG_WR(bp, addr, val);
  1288. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1289. }
  1290. }
  1291. if (CHIP_IS_E1(bp))
  1292. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1293. DP(NETIF_MSG_IFUP,
  1294. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1295. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1296. REG_WR(bp, addr, val);
  1297. /*
  1298. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1299. */
  1300. mmiowb();
  1301. barrier();
  1302. if (!CHIP_IS_E1(bp)) {
  1303. /* init leading/trailing edge */
  1304. if (IS_MF(bp)) {
  1305. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1306. if (bp->port.pmf)
  1307. /* enable nig and gpio3 attention */
  1308. val |= 0x1100;
  1309. } else
  1310. val = 0xffff;
  1311. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1312. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1313. }
  1314. /* Make sure that interrupts are indeed enabled from here on */
  1315. mmiowb();
  1316. }
  1317. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1318. {
  1319. u32 val;
  1320. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1321. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1322. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1323. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1324. if (msix) {
  1325. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1326. IGU_PF_CONF_SINGLE_ISR_EN);
  1327. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1328. IGU_PF_CONF_ATTN_BIT_EN);
  1329. if (single_msix)
  1330. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1331. } else if (msi) {
  1332. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1333. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1334. IGU_PF_CONF_ATTN_BIT_EN |
  1335. IGU_PF_CONF_SINGLE_ISR_EN);
  1336. } else {
  1337. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1338. val |= (IGU_PF_CONF_INT_LINE_EN |
  1339. IGU_PF_CONF_ATTN_BIT_EN |
  1340. IGU_PF_CONF_SINGLE_ISR_EN);
  1341. }
  1342. /* Clean previous status - need to configure igu prior to ack*/
  1343. if ((!msix) || single_msix) {
  1344. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1345. bnx2x_ack_int(bp);
  1346. }
  1347. val |= IGU_PF_CONF_FUNC_EN;
  1348. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1349. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1350. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1351. if (val & IGU_PF_CONF_INT_LINE_EN)
  1352. pci_intx(bp->pdev, true);
  1353. barrier();
  1354. /* init leading/trailing edge */
  1355. if (IS_MF(bp)) {
  1356. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1357. if (bp->port.pmf)
  1358. /* enable nig and gpio3 attention */
  1359. val |= 0x1100;
  1360. } else
  1361. val = 0xffff;
  1362. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1363. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1364. /* Make sure that interrupts are indeed enabled from here on */
  1365. mmiowb();
  1366. }
  1367. void bnx2x_int_enable(struct bnx2x *bp)
  1368. {
  1369. if (bp->common.int_block == INT_BLOCK_HC)
  1370. bnx2x_hc_int_enable(bp);
  1371. else
  1372. bnx2x_igu_int_enable(bp);
  1373. }
  1374. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1375. {
  1376. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1377. int i, offset;
  1378. if (disable_hw)
  1379. /* prevent the HW from sending interrupts */
  1380. bnx2x_int_disable(bp);
  1381. /* make sure all ISRs are done */
  1382. if (msix) {
  1383. synchronize_irq(bp->msix_table[0].vector);
  1384. offset = 1;
  1385. if (CNIC_SUPPORT(bp))
  1386. offset++;
  1387. for_each_eth_queue(bp, i)
  1388. synchronize_irq(bp->msix_table[offset++].vector);
  1389. } else
  1390. synchronize_irq(bp->pdev->irq);
  1391. /* make sure sp_task is not running */
  1392. cancel_delayed_work(&bp->sp_task);
  1393. cancel_delayed_work(&bp->period_task);
  1394. flush_workqueue(bnx2x_wq);
  1395. }
  1396. /* fast path */
  1397. /*
  1398. * General service functions
  1399. */
  1400. /* Return true if succeeded to acquire the lock */
  1401. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1402. {
  1403. u32 lock_status;
  1404. u32 resource_bit = (1 << resource);
  1405. int func = BP_FUNC(bp);
  1406. u32 hw_lock_control_reg;
  1407. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1408. "Trying to take a lock on resource %d\n", resource);
  1409. /* Validating that the resource is within range */
  1410. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1411. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1412. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1413. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1414. return false;
  1415. }
  1416. if (func <= 5)
  1417. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1418. else
  1419. hw_lock_control_reg =
  1420. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1421. /* Try to acquire the lock */
  1422. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1423. lock_status = REG_RD(bp, hw_lock_control_reg);
  1424. if (lock_status & resource_bit)
  1425. return true;
  1426. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1427. "Failed to get a lock on resource %d\n", resource);
  1428. return false;
  1429. }
  1430. /**
  1431. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1432. *
  1433. * @bp: driver handle
  1434. *
  1435. * Returns the recovery leader resource id according to the engine this function
  1436. * belongs to. Currently only only 2 engines is supported.
  1437. */
  1438. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1439. {
  1440. if (BP_PATH(bp))
  1441. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1442. else
  1443. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1444. }
  1445. /**
  1446. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1447. *
  1448. * @bp: driver handle
  1449. *
  1450. * Tries to acquire a leader lock for current engine.
  1451. */
  1452. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1453. {
  1454. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1455. }
  1456. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1457. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1458. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1459. {
  1460. /* Set the interrupt occurred bit for the sp-task to recognize it
  1461. * must ack the interrupt and transition according to the IGU
  1462. * state machine.
  1463. */
  1464. atomic_set(&bp->interrupt_occurred, 1);
  1465. /* The sp_task must execute only after this bit
  1466. * is set, otherwise we will get out of sync and miss all
  1467. * further interrupts. Hence, the barrier.
  1468. */
  1469. smp_wmb();
  1470. /* schedule sp_task to workqueue */
  1471. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1472. }
  1473. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1474. {
  1475. struct bnx2x *bp = fp->bp;
  1476. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1477. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1478. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1479. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1480. DP(BNX2X_MSG_SP,
  1481. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1482. fp->index, cid, command, bp->state,
  1483. rr_cqe->ramrod_cqe.ramrod_type);
  1484. /* If cid is within VF range, replace the slowpath object with the
  1485. * one corresponding to this VF
  1486. */
  1487. if (cid >= BNX2X_FIRST_VF_CID &&
  1488. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1489. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1490. switch (command) {
  1491. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1492. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1493. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1494. break;
  1495. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1496. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1497. drv_cmd = BNX2X_Q_CMD_SETUP;
  1498. break;
  1499. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1500. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1501. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1502. break;
  1503. case (RAMROD_CMD_ID_ETH_HALT):
  1504. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1505. drv_cmd = BNX2X_Q_CMD_HALT;
  1506. break;
  1507. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1508. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1509. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1510. break;
  1511. case (RAMROD_CMD_ID_ETH_EMPTY):
  1512. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1513. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1514. break;
  1515. default:
  1516. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1517. command, fp->index);
  1518. return;
  1519. }
  1520. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1521. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1522. /* q_obj->complete_cmd() failure means that this was
  1523. * an unexpected completion.
  1524. *
  1525. * In this case we don't want to increase the bp->spq_left
  1526. * because apparently we haven't sent this command the first
  1527. * place.
  1528. */
  1529. #ifdef BNX2X_STOP_ON_ERROR
  1530. bnx2x_panic();
  1531. #else
  1532. return;
  1533. #endif
  1534. /* SRIOV: reschedule any 'in_progress' operations */
  1535. bnx2x_iov_sp_event(bp, cid, true);
  1536. smp_mb__before_atomic_inc();
  1537. atomic_inc(&bp->cq_spq_left);
  1538. /* push the change in bp->spq_left and towards the memory */
  1539. smp_mb__after_atomic_inc();
  1540. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1541. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1542. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1543. /* if Q update ramrod is completed for last Q in AFEX vif set
  1544. * flow, then ACK MCP at the end
  1545. *
  1546. * mark pending ACK to MCP bit.
  1547. * prevent case that both bits are cleared.
  1548. * At the end of load/unload driver checks that
  1549. * sp_state is cleared, and this order prevents
  1550. * races
  1551. */
  1552. smp_mb__before_clear_bit();
  1553. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1554. wmb();
  1555. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1556. smp_mb__after_clear_bit();
  1557. /* schedule the sp task as mcp ack is required */
  1558. bnx2x_schedule_sp_task(bp);
  1559. }
  1560. return;
  1561. }
  1562. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1563. {
  1564. struct bnx2x *bp = netdev_priv(dev_instance);
  1565. u16 status = bnx2x_ack_int(bp);
  1566. u16 mask;
  1567. int i;
  1568. u8 cos;
  1569. /* Return here if interrupt is shared and it's not for us */
  1570. if (unlikely(status == 0)) {
  1571. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1572. return IRQ_NONE;
  1573. }
  1574. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1575. #ifdef BNX2X_STOP_ON_ERROR
  1576. if (unlikely(bp->panic))
  1577. return IRQ_HANDLED;
  1578. #endif
  1579. for_each_eth_queue(bp, i) {
  1580. struct bnx2x_fastpath *fp = &bp->fp[i];
  1581. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1582. if (status & mask) {
  1583. /* Handle Rx or Tx according to SB id */
  1584. prefetch(fp->rx_cons_sb);
  1585. for_each_cos_in_tx_queue(fp, cos)
  1586. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1587. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1588. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1589. status &= ~mask;
  1590. }
  1591. }
  1592. if (CNIC_SUPPORT(bp)) {
  1593. mask = 0x2;
  1594. if (status & (mask | 0x1)) {
  1595. struct cnic_ops *c_ops = NULL;
  1596. rcu_read_lock();
  1597. c_ops = rcu_dereference(bp->cnic_ops);
  1598. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1599. CNIC_DRV_STATE_HANDLES_IRQ))
  1600. c_ops->cnic_handler(bp->cnic_data, NULL);
  1601. rcu_read_unlock();
  1602. status &= ~mask;
  1603. }
  1604. }
  1605. if (unlikely(status & 0x1)) {
  1606. /* schedule sp task to perform default status block work, ack
  1607. * attentions and enable interrupts.
  1608. */
  1609. bnx2x_schedule_sp_task(bp);
  1610. status &= ~0x1;
  1611. if (!status)
  1612. return IRQ_HANDLED;
  1613. }
  1614. if (unlikely(status))
  1615. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1616. status);
  1617. return IRQ_HANDLED;
  1618. }
  1619. /* Link */
  1620. /*
  1621. * General service functions
  1622. */
  1623. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1624. {
  1625. u32 lock_status;
  1626. u32 resource_bit = (1 << resource);
  1627. int func = BP_FUNC(bp);
  1628. u32 hw_lock_control_reg;
  1629. int cnt;
  1630. /* Validating that the resource is within range */
  1631. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1632. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1633. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1634. return -EINVAL;
  1635. }
  1636. if (func <= 5) {
  1637. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1638. } else {
  1639. hw_lock_control_reg =
  1640. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1641. }
  1642. /* Validating that the resource is not already taken */
  1643. lock_status = REG_RD(bp, hw_lock_control_reg);
  1644. if (lock_status & resource_bit) {
  1645. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1646. lock_status, resource_bit);
  1647. return -EEXIST;
  1648. }
  1649. /* Try for 5 second every 5ms */
  1650. for (cnt = 0; cnt < 1000; cnt++) {
  1651. /* Try to acquire the lock */
  1652. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1653. lock_status = REG_RD(bp, hw_lock_control_reg);
  1654. if (lock_status & resource_bit)
  1655. return 0;
  1656. msleep(5);
  1657. }
  1658. BNX2X_ERR("Timeout\n");
  1659. return -EAGAIN;
  1660. }
  1661. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1662. {
  1663. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1664. }
  1665. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1666. {
  1667. u32 lock_status;
  1668. u32 resource_bit = (1 << resource);
  1669. int func = BP_FUNC(bp);
  1670. u32 hw_lock_control_reg;
  1671. /* Validating that the resource is within range */
  1672. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1673. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1674. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1675. return -EINVAL;
  1676. }
  1677. if (func <= 5) {
  1678. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1679. } else {
  1680. hw_lock_control_reg =
  1681. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1682. }
  1683. /* Validating that the resource is currently taken */
  1684. lock_status = REG_RD(bp, hw_lock_control_reg);
  1685. if (!(lock_status & resource_bit)) {
  1686. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1687. lock_status, resource_bit);
  1688. return -EFAULT;
  1689. }
  1690. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1691. return 0;
  1692. }
  1693. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1694. {
  1695. /* The GPIO should be swapped if swap register is set and active */
  1696. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1697. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1698. int gpio_shift = gpio_num +
  1699. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1700. u32 gpio_mask = (1 << gpio_shift);
  1701. u32 gpio_reg;
  1702. int value;
  1703. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1704. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1705. return -EINVAL;
  1706. }
  1707. /* read GPIO value */
  1708. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1709. /* get the requested pin value */
  1710. if ((gpio_reg & gpio_mask) == gpio_mask)
  1711. value = 1;
  1712. else
  1713. value = 0;
  1714. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1715. return value;
  1716. }
  1717. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1718. {
  1719. /* The GPIO should be swapped if swap register is set and active */
  1720. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1721. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1722. int gpio_shift = gpio_num +
  1723. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1724. u32 gpio_mask = (1 << gpio_shift);
  1725. u32 gpio_reg;
  1726. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1727. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1728. return -EINVAL;
  1729. }
  1730. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1731. /* read GPIO and mask except the float bits */
  1732. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1733. switch (mode) {
  1734. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1735. DP(NETIF_MSG_LINK,
  1736. "Set GPIO %d (shift %d) -> output low\n",
  1737. gpio_num, gpio_shift);
  1738. /* clear FLOAT and set CLR */
  1739. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1740. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1741. break;
  1742. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1743. DP(NETIF_MSG_LINK,
  1744. "Set GPIO %d (shift %d) -> output high\n",
  1745. gpio_num, gpio_shift);
  1746. /* clear FLOAT and set SET */
  1747. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1748. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1749. break;
  1750. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1751. DP(NETIF_MSG_LINK,
  1752. "Set GPIO %d (shift %d) -> input\n",
  1753. gpio_num, gpio_shift);
  1754. /* set FLOAT */
  1755. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1756. break;
  1757. default:
  1758. break;
  1759. }
  1760. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1761. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1762. return 0;
  1763. }
  1764. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1765. {
  1766. u32 gpio_reg = 0;
  1767. int rc = 0;
  1768. /* Any port swapping should be handled by caller. */
  1769. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1770. /* read GPIO and mask except the float bits */
  1771. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1772. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1773. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1774. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1775. switch (mode) {
  1776. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1777. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1778. /* set CLR */
  1779. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1780. break;
  1781. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1782. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1783. /* set SET */
  1784. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1785. break;
  1786. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1787. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1788. /* set FLOAT */
  1789. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1790. break;
  1791. default:
  1792. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1793. rc = -EINVAL;
  1794. break;
  1795. }
  1796. if (rc == 0)
  1797. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1798. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1799. return rc;
  1800. }
  1801. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1802. {
  1803. /* The GPIO should be swapped if swap register is set and active */
  1804. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1805. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1806. int gpio_shift = gpio_num +
  1807. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1808. u32 gpio_mask = (1 << gpio_shift);
  1809. u32 gpio_reg;
  1810. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1811. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1812. return -EINVAL;
  1813. }
  1814. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1815. /* read GPIO int */
  1816. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1817. switch (mode) {
  1818. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1819. DP(NETIF_MSG_LINK,
  1820. "Clear GPIO INT %d (shift %d) -> output low\n",
  1821. gpio_num, gpio_shift);
  1822. /* clear SET and set CLR */
  1823. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1824. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1825. break;
  1826. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1827. DP(NETIF_MSG_LINK,
  1828. "Set GPIO INT %d (shift %d) -> output high\n",
  1829. gpio_num, gpio_shift);
  1830. /* clear CLR and set SET */
  1831. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1832. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1833. break;
  1834. default:
  1835. break;
  1836. }
  1837. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1838. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1839. return 0;
  1840. }
  1841. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1842. {
  1843. u32 spio_reg;
  1844. /* Only 2 SPIOs are configurable */
  1845. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1846. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1847. return -EINVAL;
  1848. }
  1849. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1850. /* read SPIO and mask except the float bits */
  1851. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1852. switch (mode) {
  1853. case MISC_SPIO_OUTPUT_LOW:
  1854. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1855. /* clear FLOAT and set CLR */
  1856. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1857. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1858. break;
  1859. case MISC_SPIO_OUTPUT_HIGH:
  1860. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1861. /* clear FLOAT and set SET */
  1862. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1863. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1864. break;
  1865. case MISC_SPIO_INPUT_HI_Z:
  1866. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1867. /* set FLOAT */
  1868. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1869. break;
  1870. default:
  1871. break;
  1872. }
  1873. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1874. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1875. return 0;
  1876. }
  1877. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1878. {
  1879. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1880. switch (bp->link_vars.ieee_fc &
  1881. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1882. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1883. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1884. ADVERTISED_Pause);
  1885. break;
  1886. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1887. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1888. ADVERTISED_Pause);
  1889. break;
  1890. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1891. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1892. break;
  1893. default:
  1894. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1895. ADVERTISED_Pause);
  1896. break;
  1897. }
  1898. }
  1899. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1900. {
  1901. /* Initialize link parameters structure variables
  1902. * It is recommended to turn off RX FC for jumbo frames
  1903. * for better performance
  1904. */
  1905. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1906. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1907. else
  1908. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1909. }
  1910. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1911. {
  1912. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1913. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1914. if (!BP_NOMCP(bp)) {
  1915. bnx2x_set_requested_fc(bp);
  1916. bnx2x_acquire_phy_lock(bp);
  1917. if (load_mode == LOAD_DIAG) {
  1918. struct link_params *lp = &bp->link_params;
  1919. lp->loopback_mode = LOOPBACK_XGXS;
  1920. /* do PHY loopback at 10G speed, if possible */
  1921. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1922. if (lp->speed_cap_mask[cfx_idx] &
  1923. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1924. lp->req_line_speed[cfx_idx] =
  1925. SPEED_10000;
  1926. else
  1927. lp->req_line_speed[cfx_idx] =
  1928. SPEED_1000;
  1929. }
  1930. }
  1931. if (load_mode == LOAD_LOOPBACK_EXT) {
  1932. struct link_params *lp = &bp->link_params;
  1933. lp->loopback_mode = LOOPBACK_EXT;
  1934. }
  1935. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1936. bnx2x_release_phy_lock(bp);
  1937. bnx2x_calc_fc_adv(bp);
  1938. if (bp->link_vars.link_up) {
  1939. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1940. bnx2x_link_report(bp);
  1941. }
  1942. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1943. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1944. return rc;
  1945. }
  1946. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1947. return -EINVAL;
  1948. }
  1949. void bnx2x_link_set(struct bnx2x *bp)
  1950. {
  1951. if (!BP_NOMCP(bp)) {
  1952. bnx2x_acquire_phy_lock(bp);
  1953. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1954. bnx2x_release_phy_lock(bp);
  1955. bnx2x_calc_fc_adv(bp);
  1956. } else
  1957. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1958. }
  1959. static void bnx2x__link_reset(struct bnx2x *bp)
  1960. {
  1961. if (!BP_NOMCP(bp)) {
  1962. bnx2x_acquire_phy_lock(bp);
  1963. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1964. bnx2x_release_phy_lock(bp);
  1965. } else
  1966. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1967. }
  1968. void bnx2x_force_link_reset(struct bnx2x *bp)
  1969. {
  1970. bnx2x_acquire_phy_lock(bp);
  1971. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1972. bnx2x_release_phy_lock(bp);
  1973. }
  1974. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1975. {
  1976. u8 rc = 0;
  1977. if (!BP_NOMCP(bp)) {
  1978. bnx2x_acquire_phy_lock(bp);
  1979. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1980. is_serdes);
  1981. bnx2x_release_phy_lock(bp);
  1982. } else
  1983. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1984. return rc;
  1985. }
  1986. /* Calculates the sum of vn_min_rates.
  1987. It's needed for further normalizing of the min_rates.
  1988. Returns:
  1989. sum of vn_min_rates.
  1990. or
  1991. 0 - if all the min_rates are 0.
  1992. In the later case fainess algorithm should be deactivated.
  1993. If not all min_rates are zero then those that are zeroes will be set to 1.
  1994. */
  1995. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1996. struct cmng_init_input *input)
  1997. {
  1998. int all_zero = 1;
  1999. int vn;
  2000. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2001. u32 vn_cfg = bp->mf_config[vn];
  2002. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2003. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2004. /* Skip hidden vns */
  2005. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2006. vn_min_rate = 0;
  2007. /* If min rate is zero - set it to 1 */
  2008. else if (!vn_min_rate)
  2009. vn_min_rate = DEF_MIN_RATE;
  2010. else
  2011. all_zero = 0;
  2012. input->vnic_min_rate[vn] = vn_min_rate;
  2013. }
  2014. /* if ETS or all min rates are zeros - disable fairness */
  2015. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2016. input->flags.cmng_enables &=
  2017. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2018. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2019. } else if (all_zero) {
  2020. input->flags.cmng_enables &=
  2021. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2022. DP(NETIF_MSG_IFUP,
  2023. "All MIN values are zeroes fairness will be disabled\n");
  2024. } else
  2025. input->flags.cmng_enables |=
  2026. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2027. }
  2028. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2029. struct cmng_init_input *input)
  2030. {
  2031. u16 vn_max_rate;
  2032. u32 vn_cfg = bp->mf_config[vn];
  2033. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2034. vn_max_rate = 0;
  2035. else {
  2036. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2037. if (IS_MF_SI(bp)) {
  2038. /* maxCfg in percents of linkspeed */
  2039. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2040. } else /* SD modes */
  2041. /* maxCfg is absolute in 100Mb units */
  2042. vn_max_rate = maxCfg * 100;
  2043. }
  2044. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2045. input->vnic_max_rate[vn] = vn_max_rate;
  2046. }
  2047. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2048. {
  2049. if (CHIP_REV_IS_SLOW(bp))
  2050. return CMNG_FNS_NONE;
  2051. if (IS_MF(bp))
  2052. return CMNG_FNS_MINMAX;
  2053. return CMNG_FNS_NONE;
  2054. }
  2055. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2056. {
  2057. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2058. if (BP_NOMCP(bp))
  2059. return; /* what should be the default bvalue in this case */
  2060. /* For 2 port configuration the absolute function number formula
  2061. * is:
  2062. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2063. *
  2064. * and there are 4 functions per port
  2065. *
  2066. * For 4 port configuration it is
  2067. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2068. *
  2069. * and there are 2 functions per port
  2070. */
  2071. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2072. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2073. if (func >= E1H_FUNC_MAX)
  2074. break;
  2075. bp->mf_config[vn] =
  2076. MF_CFG_RD(bp, func_mf_config[func].config);
  2077. }
  2078. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2079. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2080. bp->flags |= MF_FUNC_DIS;
  2081. } else {
  2082. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2083. bp->flags &= ~MF_FUNC_DIS;
  2084. }
  2085. }
  2086. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2087. {
  2088. struct cmng_init_input input;
  2089. memset(&input, 0, sizeof(struct cmng_init_input));
  2090. input.port_rate = bp->link_vars.line_speed;
  2091. if (cmng_type == CMNG_FNS_MINMAX) {
  2092. int vn;
  2093. /* read mf conf from shmem */
  2094. if (read_cfg)
  2095. bnx2x_read_mf_cfg(bp);
  2096. /* vn_weight_sum and enable fairness if not 0 */
  2097. bnx2x_calc_vn_min(bp, &input);
  2098. /* calculate and set min-max rate for each vn */
  2099. if (bp->port.pmf)
  2100. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2101. bnx2x_calc_vn_max(bp, vn, &input);
  2102. /* always enable rate shaping and fairness */
  2103. input.flags.cmng_enables |=
  2104. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2105. bnx2x_init_cmng(&input, &bp->cmng);
  2106. return;
  2107. }
  2108. /* rate shaping and fairness are disabled */
  2109. DP(NETIF_MSG_IFUP,
  2110. "rate shaping and fairness are disabled\n");
  2111. }
  2112. static void storm_memset_cmng(struct bnx2x *bp,
  2113. struct cmng_init *cmng,
  2114. u8 port)
  2115. {
  2116. int vn;
  2117. size_t size = sizeof(struct cmng_struct_per_port);
  2118. u32 addr = BAR_XSTRORM_INTMEM +
  2119. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2120. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2121. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2122. int func = func_by_vn(bp, vn);
  2123. addr = BAR_XSTRORM_INTMEM +
  2124. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2125. size = sizeof(struct rate_shaping_vars_per_vn);
  2126. __storm_memset_struct(bp, addr, size,
  2127. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2128. addr = BAR_XSTRORM_INTMEM +
  2129. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2130. size = sizeof(struct fairness_vars_per_vn);
  2131. __storm_memset_struct(bp, addr, size,
  2132. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2133. }
  2134. }
  2135. /* This function is called upon link interrupt */
  2136. static void bnx2x_link_attn(struct bnx2x *bp)
  2137. {
  2138. /* Make sure that we are synced with the current statistics */
  2139. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2140. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2141. if (bp->link_vars.link_up) {
  2142. /* dropless flow control */
  2143. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2144. int port = BP_PORT(bp);
  2145. u32 pause_enabled = 0;
  2146. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2147. pause_enabled = 1;
  2148. REG_WR(bp, BAR_USTRORM_INTMEM +
  2149. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2150. pause_enabled);
  2151. }
  2152. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2153. struct host_port_stats *pstats;
  2154. pstats = bnx2x_sp(bp, port_stats);
  2155. /* reset old mac stats */
  2156. memset(&(pstats->mac_stx[0]), 0,
  2157. sizeof(struct mac_stx));
  2158. }
  2159. if (bp->state == BNX2X_STATE_OPEN)
  2160. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2161. }
  2162. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2163. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2164. if (cmng_fns != CMNG_FNS_NONE) {
  2165. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2166. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2167. } else
  2168. /* rate shaping and fairness are disabled */
  2169. DP(NETIF_MSG_IFUP,
  2170. "single function mode without fairness\n");
  2171. }
  2172. __bnx2x_link_report(bp);
  2173. if (IS_MF(bp))
  2174. bnx2x_link_sync_notify(bp);
  2175. }
  2176. void bnx2x__link_status_update(struct bnx2x *bp)
  2177. {
  2178. if (bp->state != BNX2X_STATE_OPEN)
  2179. return;
  2180. /* read updated dcb configuration */
  2181. if (IS_PF(bp)) {
  2182. bnx2x_dcbx_pmf_update(bp);
  2183. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2184. if (bp->link_vars.link_up)
  2185. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2186. else
  2187. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2188. /* indicate link status */
  2189. bnx2x_link_report(bp);
  2190. } else { /* VF */
  2191. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2192. SUPPORTED_10baseT_Full |
  2193. SUPPORTED_100baseT_Half |
  2194. SUPPORTED_100baseT_Full |
  2195. SUPPORTED_1000baseT_Full |
  2196. SUPPORTED_2500baseX_Full |
  2197. SUPPORTED_10000baseT_Full |
  2198. SUPPORTED_TP |
  2199. SUPPORTED_FIBRE |
  2200. SUPPORTED_Autoneg |
  2201. SUPPORTED_Pause |
  2202. SUPPORTED_Asym_Pause);
  2203. bp->port.advertising[0] = bp->port.supported[0];
  2204. bp->link_params.bp = bp;
  2205. bp->link_params.port = BP_PORT(bp);
  2206. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2207. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2208. bp->link_params.req_line_speed[0] = SPEED_10000;
  2209. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2210. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2211. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2212. bp->link_vars.line_speed = SPEED_10000;
  2213. bp->link_vars.link_status =
  2214. (LINK_STATUS_LINK_UP |
  2215. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2216. bp->link_vars.link_up = 1;
  2217. bp->link_vars.duplex = DUPLEX_FULL;
  2218. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2219. __bnx2x_link_report(bp);
  2220. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2221. }
  2222. }
  2223. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2224. u16 vlan_val, u8 allowed_prio)
  2225. {
  2226. struct bnx2x_func_state_params func_params = {NULL};
  2227. struct bnx2x_func_afex_update_params *f_update_params =
  2228. &func_params.params.afex_update;
  2229. func_params.f_obj = &bp->func_obj;
  2230. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2231. /* no need to wait for RAMROD completion, so don't
  2232. * set RAMROD_COMP_WAIT flag
  2233. */
  2234. f_update_params->vif_id = vifid;
  2235. f_update_params->afex_default_vlan = vlan_val;
  2236. f_update_params->allowed_priorities = allowed_prio;
  2237. /* if ramrod can not be sent, response to MCP immediately */
  2238. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2239. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2240. return 0;
  2241. }
  2242. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2243. u16 vif_index, u8 func_bit_map)
  2244. {
  2245. struct bnx2x_func_state_params func_params = {NULL};
  2246. struct bnx2x_func_afex_viflists_params *update_params =
  2247. &func_params.params.afex_viflists;
  2248. int rc;
  2249. u32 drv_msg_code;
  2250. /* validate only LIST_SET and LIST_GET are received from switch */
  2251. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2252. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2253. cmd_type);
  2254. func_params.f_obj = &bp->func_obj;
  2255. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2256. /* set parameters according to cmd_type */
  2257. update_params->afex_vif_list_command = cmd_type;
  2258. update_params->vif_list_index = vif_index;
  2259. update_params->func_bit_map =
  2260. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2261. update_params->func_to_clear = 0;
  2262. drv_msg_code =
  2263. (cmd_type == VIF_LIST_RULE_GET) ?
  2264. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2265. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2266. /* if ramrod can not be sent, respond to MCP immediately for
  2267. * SET and GET requests (other are not triggered from MCP)
  2268. */
  2269. rc = bnx2x_func_state_change(bp, &func_params);
  2270. if (rc < 0)
  2271. bnx2x_fw_command(bp, drv_msg_code, 0);
  2272. return 0;
  2273. }
  2274. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2275. {
  2276. struct afex_stats afex_stats;
  2277. u32 func = BP_ABS_FUNC(bp);
  2278. u32 mf_config;
  2279. u16 vlan_val;
  2280. u32 vlan_prio;
  2281. u16 vif_id;
  2282. u8 allowed_prio;
  2283. u8 vlan_mode;
  2284. u32 addr_to_write, vifid, addrs, stats_type, i;
  2285. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2286. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2287. DP(BNX2X_MSG_MCP,
  2288. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2289. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2290. }
  2291. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2292. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2293. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2294. DP(BNX2X_MSG_MCP,
  2295. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2296. vifid, addrs);
  2297. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2298. addrs);
  2299. }
  2300. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2301. addr_to_write = SHMEM2_RD(bp,
  2302. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2303. stats_type = SHMEM2_RD(bp,
  2304. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2305. DP(BNX2X_MSG_MCP,
  2306. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2307. addr_to_write);
  2308. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2309. /* write response to scratchpad, for MCP */
  2310. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2311. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2312. *(((u32 *)(&afex_stats))+i));
  2313. /* send ack message to MCP */
  2314. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2315. }
  2316. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2317. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2318. bp->mf_config[BP_VN(bp)] = mf_config;
  2319. DP(BNX2X_MSG_MCP,
  2320. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2321. mf_config);
  2322. /* if VIF_SET is "enabled" */
  2323. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2324. /* set rate limit directly to internal RAM */
  2325. struct cmng_init_input cmng_input;
  2326. struct rate_shaping_vars_per_vn m_rs_vn;
  2327. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2328. u32 addr = BAR_XSTRORM_INTMEM +
  2329. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2330. bp->mf_config[BP_VN(bp)] = mf_config;
  2331. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2332. m_rs_vn.vn_counter.rate =
  2333. cmng_input.vnic_max_rate[BP_VN(bp)];
  2334. m_rs_vn.vn_counter.quota =
  2335. (m_rs_vn.vn_counter.rate *
  2336. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2337. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2338. /* read relevant values from mf_cfg struct in shmem */
  2339. vif_id =
  2340. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2341. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2342. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2343. vlan_val =
  2344. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2345. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2346. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2347. vlan_prio = (mf_config &
  2348. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2349. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2350. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2351. vlan_mode =
  2352. (MF_CFG_RD(bp,
  2353. func_mf_config[func].afex_config) &
  2354. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2355. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2356. allowed_prio =
  2357. (MF_CFG_RD(bp,
  2358. func_mf_config[func].afex_config) &
  2359. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2360. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2361. /* send ramrod to FW, return in case of failure */
  2362. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2363. allowed_prio))
  2364. return;
  2365. bp->afex_def_vlan_tag = vlan_val;
  2366. bp->afex_vlan_mode = vlan_mode;
  2367. } else {
  2368. /* notify link down because BP->flags is disabled */
  2369. bnx2x_link_report(bp);
  2370. /* send INVALID VIF ramrod to FW */
  2371. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2372. /* Reset the default afex VLAN */
  2373. bp->afex_def_vlan_tag = -1;
  2374. }
  2375. }
  2376. }
  2377. static void bnx2x_pmf_update(struct bnx2x *bp)
  2378. {
  2379. int port = BP_PORT(bp);
  2380. u32 val;
  2381. bp->port.pmf = 1;
  2382. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2383. /*
  2384. * We need the mb() to ensure the ordering between the writing to
  2385. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2386. */
  2387. smp_mb();
  2388. /* queue a periodic task */
  2389. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2390. bnx2x_dcbx_pmf_update(bp);
  2391. /* enable nig attention */
  2392. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2393. if (bp->common.int_block == INT_BLOCK_HC) {
  2394. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2395. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2396. } else if (!CHIP_IS_E1x(bp)) {
  2397. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2398. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2399. }
  2400. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2401. }
  2402. /* end of Link */
  2403. /* slow path */
  2404. /*
  2405. * General service functions
  2406. */
  2407. /* send the MCP a request, block until there is a reply */
  2408. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2409. {
  2410. int mb_idx = BP_FW_MB_IDX(bp);
  2411. u32 seq;
  2412. u32 rc = 0;
  2413. u32 cnt = 1;
  2414. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2415. mutex_lock(&bp->fw_mb_mutex);
  2416. seq = ++bp->fw_seq;
  2417. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2418. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2419. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2420. (command | seq), param);
  2421. do {
  2422. /* let the FW do it's magic ... */
  2423. msleep(delay);
  2424. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2425. /* Give the FW up to 5 second (500*10ms) */
  2426. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2427. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2428. cnt*delay, rc, seq);
  2429. /* is this a reply to our command? */
  2430. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2431. rc &= FW_MSG_CODE_MASK;
  2432. else {
  2433. /* FW BUG! */
  2434. BNX2X_ERR("FW failed to respond!\n");
  2435. bnx2x_fw_dump(bp);
  2436. rc = 0;
  2437. }
  2438. mutex_unlock(&bp->fw_mb_mutex);
  2439. return rc;
  2440. }
  2441. static void storm_memset_func_cfg(struct bnx2x *bp,
  2442. struct tstorm_eth_function_common_config *tcfg,
  2443. u16 abs_fid)
  2444. {
  2445. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2446. u32 addr = BAR_TSTRORM_INTMEM +
  2447. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2448. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2449. }
  2450. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2451. {
  2452. if (CHIP_IS_E1x(bp)) {
  2453. struct tstorm_eth_function_common_config tcfg = {0};
  2454. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2455. }
  2456. /* Enable the function in the FW */
  2457. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2458. storm_memset_func_en(bp, p->func_id, 1);
  2459. /* spq */
  2460. if (p->func_flgs & FUNC_FLG_SPQ) {
  2461. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2462. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2463. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2464. }
  2465. }
  2466. /**
  2467. * bnx2x_get_tx_only_flags - Return common flags
  2468. *
  2469. * @bp device handle
  2470. * @fp queue handle
  2471. * @zero_stats TRUE if statistics zeroing is needed
  2472. *
  2473. * Return the flags that are common for the Tx-only and not normal connections.
  2474. */
  2475. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2476. struct bnx2x_fastpath *fp,
  2477. bool zero_stats)
  2478. {
  2479. unsigned long flags = 0;
  2480. /* PF driver will always initialize the Queue to an ACTIVE state */
  2481. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2482. /* tx only connections collect statistics (on the same index as the
  2483. * parent connection). The statistics are zeroed when the parent
  2484. * connection is initialized.
  2485. */
  2486. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2487. if (zero_stats)
  2488. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2489. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2490. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2491. #ifdef BNX2X_STOP_ON_ERROR
  2492. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2493. #endif
  2494. return flags;
  2495. }
  2496. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2497. struct bnx2x_fastpath *fp,
  2498. bool leading)
  2499. {
  2500. unsigned long flags = 0;
  2501. /* calculate other queue flags */
  2502. if (IS_MF_SD(bp))
  2503. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2504. if (IS_FCOE_FP(fp)) {
  2505. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2506. /* For FCoE - force usage of default priority (for afex) */
  2507. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2508. }
  2509. if (!fp->disable_tpa) {
  2510. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2511. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2512. if (fp->mode == TPA_MODE_GRO)
  2513. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2514. }
  2515. if (leading) {
  2516. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2517. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2518. }
  2519. /* Always set HW VLAN stripping */
  2520. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2521. /* configure silent vlan removal */
  2522. if (IS_MF_AFEX(bp))
  2523. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2524. return flags | bnx2x_get_common_flags(bp, fp, true);
  2525. }
  2526. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2527. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2528. u8 cos)
  2529. {
  2530. gen_init->stat_id = bnx2x_stats_id(fp);
  2531. gen_init->spcl_id = fp->cl_id;
  2532. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2533. if (IS_FCOE_FP(fp))
  2534. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2535. else
  2536. gen_init->mtu = bp->dev->mtu;
  2537. gen_init->cos = cos;
  2538. }
  2539. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2540. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2541. struct bnx2x_rxq_setup_params *rxq_init)
  2542. {
  2543. u8 max_sge = 0;
  2544. u16 sge_sz = 0;
  2545. u16 tpa_agg_size = 0;
  2546. if (!fp->disable_tpa) {
  2547. pause->sge_th_lo = SGE_TH_LO(bp);
  2548. pause->sge_th_hi = SGE_TH_HI(bp);
  2549. /* validate SGE ring has enough to cross high threshold */
  2550. WARN_ON(bp->dropless_fc &&
  2551. pause->sge_th_hi + FW_PREFETCH_CNT >
  2552. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2553. tpa_agg_size = TPA_AGG_SIZE;
  2554. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2555. SGE_PAGE_SHIFT;
  2556. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2557. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2558. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2559. }
  2560. /* pause - not for e1 */
  2561. if (!CHIP_IS_E1(bp)) {
  2562. pause->bd_th_lo = BD_TH_LO(bp);
  2563. pause->bd_th_hi = BD_TH_HI(bp);
  2564. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2565. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2566. /*
  2567. * validate that rings have enough entries to cross
  2568. * high thresholds
  2569. */
  2570. WARN_ON(bp->dropless_fc &&
  2571. pause->bd_th_hi + FW_PREFETCH_CNT >
  2572. bp->rx_ring_size);
  2573. WARN_ON(bp->dropless_fc &&
  2574. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2575. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2576. pause->pri_map = 1;
  2577. }
  2578. /* rxq setup */
  2579. rxq_init->dscr_map = fp->rx_desc_mapping;
  2580. rxq_init->sge_map = fp->rx_sge_mapping;
  2581. rxq_init->rcq_map = fp->rx_comp_mapping;
  2582. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2583. /* This should be a maximum number of data bytes that may be
  2584. * placed on the BD (not including paddings).
  2585. */
  2586. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2587. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2588. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2589. rxq_init->tpa_agg_sz = tpa_agg_size;
  2590. rxq_init->sge_buf_sz = sge_sz;
  2591. rxq_init->max_sges_pkt = max_sge;
  2592. rxq_init->rss_engine_id = BP_FUNC(bp);
  2593. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2594. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2595. *
  2596. * For PF Clients it should be the maximum available number.
  2597. * VF driver(s) may want to define it to a smaller value.
  2598. */
  2599. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2600. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2601. rxq_init->fw_sb_id = fp->fw_sb_id;
  2602. if (IS_FCOE_FP(fp))
  2603. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2604. else
  2605. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2606. /* configure silent vlan removal
  2607. * if multi function mode is afex, then mask default vlan
  2608. */
  2609. if (IS_MF_AFEX(bp)) {
  2610. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2611. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2612. }
  2613. }
  2614. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2615. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2616. u8 cos)
  2617. {
  2618. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2619. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2620. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2621. txq_init->fw_sb_id = fp->fw_sb_id;
  2622. /*
  2623. * set the tss leading client id for TX classfication ==
  2624. * leading RSS client id
  2625. */
  2626. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2627. if (IS_FCOE_FP(fp)) {
  2628. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2629. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2630. }
  2631. }
  2632. static void bnx2x_pf_init(struct bnx2x *bp)
  2633. {
  2634. struct bnx2x_func_init_params func_init = {0};
  2635. struct event_ring_data eq_data = { {0} };
  2636. u16 flags;
  2637. if (!CHIP_IS_E1x(bp)) {
  2638. /* reset IGU PF statistics: MSIX + ATTN */
  2639. /* PF */
  2640. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2641. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2642. (CHIP_MODE_IS_4_PORT(bp) ?
  2643. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2644. /* ATTN */
  2645. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2646. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2647. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2648. (CHIP_MODE_IS_4_PORT(bp) ?
  2649. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2650. }
  2651. /* function setup flags */
  2652. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2653. /* This flag is relevant for E1x only.
  2654. * E2 doesn't have a TPA configuration in a function level.
  2655. */
  2656. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2657. func_init.func_flgs = flags;
  2658. func_init.pf_id = BP_FUNC(bp);
  2659. func_init.func_id = BP_FUNC(bp);
  2660. func_init.spq_map = bp->spq_mapping;
  2661. func_init.spq_prod = bp->spq_prod_idx;
  2662. bnx2x_func_init(bp, &func_init);
  2663. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2664. /*
  2665. * Congestion management values depend on the link rate
  2666. * There is no active link so initial link rate is set to 10 Gbps.
  2667. * When the link comes up The congestion management values are
  2668. * re-calculated according to the actual link rate.
  2669. */
  2670. bp->link_vars.line_speed = SPEED_10000;
  2671. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2672. /* Only the PMF sets the HW */
  2673. if (bp->port.pmf)
  2674. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2675. /* init Event Queue - PCI bus guarantees correct endianity*/
  2676. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2677. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2678. eq_data.producer = bp->eq_prod;
  2679. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2680. eq_data.sb_id = DEF_SB_ID;
  2681. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2682. }
  2683. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2684. {
  2685. int port = BP_PORT(bp);
  2686. bnx2x_tx_disable(bp);
  2687. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2688. }
  2689. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2690. {
  2691. int port = BP_PORT(bp);
  2692. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2693. /* Tx queue should be only reenabled */
  2694. netif_tx_wake_all_queues(bp->dev);
  2695. /*
  2696. * Should not call netif_carrier_on since it will be called if the link
  2697. * is up when checking for link state
  2698. */
  2699. }
  2700. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2701. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2702. {
  2703. struct eth_stats_info *ether_stat =
  2704. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2705. struct bnx2x_vlan_mac_obj *mac_obj =
  2706. &bp->sp_objs->mac_obj;
  2707. int i;
  2708. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2709. ETH_STAT_INFO_VERSION_LEN);
  2710. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2711. * mac_local field in ether_stat struct. The base address is offset by 2
  2712. * bytes to account for the field being 8 bytes but a mac address is
  2713. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2714. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2715. * allocated by the ether_stat struct, so the macs will land in their
  2716. * proper positions.
  2717. */
  2718. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2719. memset(ether_stat->mac_local + i, 0,
  2720. sizeof(ether_stat->mac_local[0]));
  2721. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2722. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2723. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2724. ETH_ALEN);
  2725. ether_stat->mtu_size = bp->dev->mtu;
  2726. if (bp->dev->features & NETIF_F_RXCSUM)
  2727. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2728. if (bp->dev->features & NETIF_F_TSO)
  2729. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2730. ether_stat->feature_flags |= bp->common.boot_mode;
  2731. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2732. ether_stat->txq_size = bp->tx_ring_size;
  2733. ether_stat->rxq_size = bp->rx_ring_size;
  2734. }
  2735. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2736. {
  2737. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2738. struct fcoe_stats_info *fcoe_stat =
  2739. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2740. if (!CNIC_LOADED(bp))
  2741. return;
  2742. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2743. fcoe_stat->qos_priority =
  2744. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2745. /* insert FCoE stats from ramrod response */
  2746. if (!NO_FCOE(bp)) {
  2747. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2748. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2749. tstorm_queue_statistics;
  2750. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2751. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2752. xstorm_queue_statistics;
  2753. struct fcoe_statistics_params *fw_fcoe_stat =
  2754. &bp->fw_stats_data->fcoe;
  2755. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2756. fcoe_stat->rx_bytes_lo,
  2757. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2758. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2759. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2760. fcoe_stat->rx_bytes_lo,
  2761. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2762. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2763. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2764. fcoe_stat->rx_bytes_lo,
  2765. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2766. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2767. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2768. fcoe_stat->rx_bytes_lo,
  2769. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2770. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2771. fcoe_stat->rx_frames_lo,
  2772. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2773. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2774. fcoe_stat->rx_frames_lo,
  2775. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2776. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2777. fcoe_stat->rx_frames_lo,
  2778. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2779. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2780. fcoe_stat->rx_frames_lo,
  2781. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2782. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2783. fcoe_stat->tx_bytes_lo,
  2784. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2785. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2786. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2787. fcoe_stat->tx_bytes_lo,
  2788. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2789. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2790. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2791. fcoe_stat->tx_bytes_lo,
  2792. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2793. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2794. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2795. fcoe_stat->tx_bytes_lo,
  2796. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2797. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2798. fcoe_stat->tx_frames_lo,
  2799. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2800. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2801. fcoe_stat->tx_frames_lo,
  2802. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2803. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2804. fcoe_stat->tx_frames_lo,
  2805. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2806. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2807. fcoe_stat->tx_frames_lo,
  2808. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2809. }
  2810. /* ask L5 driver to add data to the struct */
  2811. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2812. }
  2813. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2814. {
  2815. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2816. struct iscsi_stats_info *iscsi_stat =
  2817. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2818. if (!CNIC_LOADED(bp))
  2819. return;
  2820. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2821. ETH_ALEN);
  2822. iscsi_stat->qos_priority =
  2823. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2824. /* ask L5 driver to add data to the struct */
  2825. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2826. }
  2827. /* called due to MCP event (on pmf):
  2828. * reread new bandwidth configuration
  2829. * configure FW
  2830. * notify others function about the change
  2831. */
  2832. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2833. {
  2834. if (bp->link_vars.link_up) {
  2835. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2836. bnx2x_link_sync_notify(bp);
  2837. }
  2838. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2839. }
  2840. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2841. {
  2842. bnx2x_config_mf_bw(bp);
  2843. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2844. }
  2845. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2846. {
  2847. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2848. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2849. }
  2850. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2851. {
  2852. enum drv_info_opcode op_code;
  2853. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2854. /* if drv_info version supported by MFW doesn't match - send NACK */
  2855. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2856. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2857. return;
  2858. }
  2859. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2860. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2861. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2862. sizeof(union drv_info_to_mcp));
  2863. switch (op_code) {
  2864. case ETH_STATS_OPCODE:
  2865. bnx2x_drv_info_ether_stat(bp);
  2866. break;
  2867. case FCOE_STATS_OPCODE:
  2868. bnx2x_drv_info_fcoe_stat(bp);
  2869. break;
  2870. case ISCSI_STATS_OPCODE:
  2871. bnx2x_drv_info_iscsi_stat(bp);
  2872. break;
  2873. default:
  2874. /* if op code isn't supported - send NACK */
  2875. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2876. return;
  2877. }
  2878. /* if we got drv_info attn from MFW then these fields are defined in
  2879. * shmem2 for sure
  2880. */
  2881. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2882. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2883. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2884. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2885. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2886. }
  2887. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2888. {
  2889. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2890. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2891. /*
  2892. * This is the only place besides the function initialization
  2893. * where the bp->flags can change so it is done without any
  2894. * locks
  2895. */
  2896. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2897. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2898. bp->flags |= MF_FUNC_DIS;
  2899. bnx2x_e1h_disable(bp);
  2900. } else {
  2901. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2902. bp->flags &= ~MF_FUNC_DIS;
  2903. bnx2x_e1h_enable(bp);
  2904. }
  2905. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2906. }
  2907. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2908. bnx2x_config_mf_bw(bp);
  2909. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2910. }
  2911. /* Report results to MCP */
  2912. if (dcc_event)
  2913. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2914. else
  2915. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2916. }
  2917. /* must be called under the spq lock */
  2918. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2919. {
  2920. struct eth_spe *next_spe = bp->spq_prod_bd;
  2921. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2922. bp->spq_prod_bd = bp->spq;
  2923. bp->spq_prod_idx = 0;
  2924. DP(BNX2X_MSG_SP, "end of spq\n");
  2925. } else {
  2926. bp->spq_prod_bd++;
  2927. bp->spq_prod_idx++;
  2928. }
  2929. return next_spe;
  2930. }
  2931. /* must be called under the spq lock */
  2932. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2933. {
  2934. int func = BP_FUNC(bp);
  2935. /*
  2936. * Make sure that BD data is updated before writing the producer:
  2937. * BD data is written to the memory, the producer is read from the
  2938. * memory, thus we need a full memory barrier to ensure the ordering.
  2939. */
  2940. mb();
  2941. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2942. bp->spq_prod_idx);
  2943. mmiowb();
  2944. }
  2945. /**
  2946. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2947. *
  2948. * @cmd: command to check
  2949. * @cmd_type: command type
  2950. */
  2951. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2952. {
  2953. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2954. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2955. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2956. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2957. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2958. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2959. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2960. return true;
  2961. else
  2962. return false;
  2963. }
  2964. /**
  2965. * bnx2x_sp_post - place a single command on an SP ring
  2966. *
  2967. * @bp: driver handle
  2968. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2969. * @cid: SW CID the command is related to
  2970. * @data_hi: command private data address (high 32 bits)
  2971. * @data_lo: command private data address (low 32 bits)
  2972. * @cmd_type: command type (e.g. NONE, ETH)
  2973. *
  2974. * SP data is handled as if it's always an address pair, thus data fields are
  2975. * not swapped to little endian in upper functions. Instead this function swaps
  2976. * data as if it's two u32 fields.
  2977. */
  2978. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2979. u32 data_hi, u32 data_lo, int cmd_type)
  2980. {
  2981. struct eth_spe *spe;
  2982. u16 type;
  2983. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2984. #ifdef BNX2X_STOP_ON_ERROR
  2985. if (unlikely(bp->panic)) {
  2986. BNX2X_ERR("Can't post SP when there is panic\n");
  2987. return -EIO;
  2988. }
  2989. #endif
  2990. spin_lock_bh(&bp->spq_lock);
  2991. if (common) {
  2992. if (!atomic_read(&bp->eq_spq_left)) {
  2993. BNX2X_ERR("BUG! EQ ring full!\n");
  2994. spin_unlock_bh(&bp->spq_lock);
  2995. bnx2x_panic();
  2996. return -EBUSY;
  2997. }
  2998. } else if (!atomic_read(&bp->cq_spq_left)) {
  2999. BNX2X_ERR("BUG! SPQ ring full!\n");
  3000. spin_unlock_bh(&bp->spq_lock);
  3001. bnx2x_panic();
  3002. return -EBUSY;
  3003. }
  3004. spe = bnx2x_sp_get_next(bp);
  3005. /* CID needs port number to be encoded int it */
  3006. spe->hdr.conn_and_cmd_data =
  3007. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3008. HW_CID(bp, cid));
  3009. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3010. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3011. SPE_HDR_FUNCTION_ID);
  3012. spe->hdr.type = cpu_to_le16(type);
  3013. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3014. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3015. /*
  3016. * It's ok if the actual decrement is issued towards the memory
  3017. * somewhere between the spin_lock and spin_unlock. Thus no
  3018. * more explict memory barrier is needed.
  3019. */
  3020. if (common)
  3021. atomic_dec(&bp->eq_spq_left);
  3022. else
  3023. atomic_dec(&bp->cq_spq_left);
  3024. DP(BNX2X_MSG_SP,
  3025. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3026. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3027. (u32)(U64_LO(bp->spq_mapping) +
  3028. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3029. HW_CID(bp, cid), data_hi, data_lo, type,
  3030. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3031. bnx2x_sp_prod_update(bp);
  3032. spin_unlock_bh(&bp->spq_lock);
  3033. return 0;
  3034. }
  3035. /* acquire split MCP access lock register */
  3036. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3037. {
  3038. u32 j, val;
  3039. int rc = 0;
  3040. might_sleep();
  3041. for (j = 0; j < 1000; j++) {
  3042. val = (1UL << 31);
  3043. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3044. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3045. if (val & (1L << 31))
  3046. break;
  3047. msleep(5);
  3048. }
  3049. if (!(val & (1L << 31))) {
  3050. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3051. rc = -EBUSY;
  3052. }
  3053. return rc;
  3054. }
  3055. /* release split MCP access lock register */
  3056. static void bnx2x_release_alr(struct bnx2x *bp)
  3057. {
  3058. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3059. }
  3060. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3061. #define BNX2X_DEF_SB_IDX 0x0002
  3062. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3063. {
  3064. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3065. u16 rc = 0;
  3066. barrier(); /* status block is written to by the chip */
  3067. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3068. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3069. rc |= BNX2X_DEF_SB_ATT_IDX;
  3070. }
  3071. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3072. bp->def_idx = def_sb->sp_sb.running_index;
  3073. rc |= BNX2X_DEF_SB_IDX;
  3074. }
  3075. /* Do not reorder: indecies reading should complete before handling */
  3076. barrier();
  3077. return rc;
  3078. }
  3079. /*
  3080. * slow path service functions
  3081. */
  3082. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3083. {
  3084. int port = BP_PORT(bp);
  3085. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3086. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3087. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3088. NIG_REG_MASK_INTERRUPT_PORT0;
  3089. u32 aeu_mask;
  3090. u32 nig_mask = 0;
  3091. u32 reg_addr;
  3092. if (bp->attn_state & asserted)
  3093. BNX2X_ERR("IGU ERROR\n");
  3094. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3095. aeu_mask = REG_RD(bp, aeu_addr);
  3096. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3097. aeu_mask, asserted);
  3098. aeu_mask &= ~(asserted & 0x3ff);
  3099. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3100. REG_WR(bp, aeu_addr, aeu_mask);
  3101. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3102. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3103. bp->attn_state |= asserted;
  3104. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3105. if (asserted & ATTN_HARD_WIRED_MASK) {
  3106. if (asserted & ATTN_NIG_FOR_FUNC) {
  3107. bnx2x_acquire_phy_lock(bp);
  3108. /* save nig interrupt mask */
  3109. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3110. /* If nig_mask is not set, no need to call the update
  3111. * function.
  3112. */
  3113. if (nig_mask) {
  3114. REG_WR(bp, nig_int_mask_addr, 0);
  3115. bnx2x_link_attn(bp);
  3116. }
  3117. /* handle unicore attn? */
  3118. }
  3119. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3120. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3121. if (asserted & GPIO_2_FUNC)
  3122. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3123. if (asserted & GPIO_3_FUNC)
  3124. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3125. if (asserted & GPIO_4_FUNC)
  3126. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3127. if (port == 0) {
  3128. if (asserted & ATTN_GENERAL_ATTN_1) {
  3129. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3130. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3131. }
  3132. if (asserted & ATTN_GENERAL_ATTN_2) {
  3133. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3134. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3135. }
  3136. if (asserted & ATTN_GENERAL_ATTN_3) {
  3137. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3138. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3139. }
  3140. } else {
  3141. if (asserted & ATTN_GENERAL_ATTN_4) {
  3142. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3143. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3144. }
  3145. if (asserted & ATTN_GENERAL_ATTN_5) {
  3146. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3147. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3148. }
  3149. if (asserted & ATTN_GENERAL_ATTN_6) {
  3150. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3151. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3152. }
  3153. }
  3154. } /* if hardwired */
  3155. if (bp->common.int_block == INT_BLOCK_HC)
  3156. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3157. COMMAND_REG_ATTN_BITS_SET);
  3158. else
  3159. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3160. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3161. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3162. REG_WR(bp, reg_addr, asserted);
  3163. /* now set back the mask */
  3164. if (asserted & ATTN_NIG_FOR_FUNC) {
  3165. /* Verify that IGU ack through BAR was written before restoring
  3166. * NIG mask. This loop should exit after 2-3 iterations max.
  3167. */
  3168. if (bp->common.int_block != INT_BLOCK_HC) {
  3169. u32 cnt = 0, igu_acked;
  3170. do {
  3171. igu_acked = REG_RD(bp,
  3172. IGU_REG_ATTENTION_ACK_BITS);
  3173. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3174. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3175. if (!igu_acked)
  3176. DP(NETIF_MSG_HW,
  3177. "Failed to verify IGU ack on time\n");
  3178. barrier();
  3179. }
  3180. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3181. bnx2x_release_phy_lock(bp);
  3182. }
  3183. }
  3184. static void bnx2x_fan_failure(struct bnx2x *bp)
  3185. {
  3186. int port = BP_PORT(bp);
  3187. u32 ext_phy_config;
  3188. /* mark the failure */
  3189. ext_phy_config =
  3190. SHMEM_RD(bp,
  3191. dev_info.port_hw_config[port].external_phy_config);
  3192. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3193. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3194. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3195. ext_phy_config);
  3196. /* log the failure */
  3197. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3198. "Please contact OEM Support for assistance\n");
  3199. /*
  3200. * Schedule device reset (unload)
  3201. * This is due to some boards consuming sufficient power when driver is
  3202. * up to overheat if fan fails.
  3203. */
  3204. smp_mb__before_clear_bit();
  3205. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3206. smp_mb__after_clear_bit();
  3207. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3208. }
  3209. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3210. {
  3211. int port = BP_PORT(bp);
  3212. int reg_offset;
  3213. u32 val;
  3214. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3215. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3216. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3217. val = REG_RD(bp, reg_offset);
  3218. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3219. REG_WR(bp, reg_offset, val);
  3220. BNX2X_ERR("SPIO5 hw attention\n");
  3221. /* Fan failure attention */
  3222. bnx2x_hw_reset_phy(&bp->link_params);
  3223. bnx2x_fan_failure(bp);
  3224. }
  3225. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3226. bnx2x_acquire_phy_lock(bp);
  3227. bnx2x_handle_module_detect_int(&bp->link_params);
  3228. bnx2x_release_phy_lock(bp);
  3229. }
  3230. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3231. val = REG_RD(bp, reg_offset);
  3232. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3233. REG_WR(bp, reg_offset, val);
  3234. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3235. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3236. bnx2x_panic();
  3237. }
  3238. }
  3239. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3240. {
  3241. u32 val;
  3242. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3243. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3244. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3245. /* DORQ discard attention */
  3246. if (val & 0x2)
  3247. BNX2X_ERR("FATAL error from DORQ\n");
  3248. }
  3249. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3250. int port = BP_PORT(bp);
  3251. int reg_offset;
  3252. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3253. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3254. val = REG_RD(bp, reg_offset);
  3255. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3256. REG_WR(bp, reg_offset, val);
  3257. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3258. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3259. bnx2x_panic();
  3260. }
  3261. }
  3262. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3263. {
  3264. u32 val;
  3265. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3266. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3267. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3268. /* CFC error attention */
  3269. if (val & 0x2)
  3270. BNX2X_ERR("FATAL error from CFC\n");
  3271. }
  3272. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3273. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3274. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3275. /* RQ_USDMDP_FIFO_OVERFLOW */
  3276. if (val & 0x18000)
  3277. BNX2X_ERR("FATAL error from PXP\n");
  3278. if (!CHIP_IS_E1x(bp)) {
  3279. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3280. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3281. }
  3282. }
  3283. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3284. int port = BP_PORT(bp);
  3285. int reg_offset;
  3286. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3287. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3288. val = REG_RD(bp, reg_offset);
  3289. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3290. REG_WR(bp, reg_offset, val);
  3291. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3292. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3293. bnx2x_panic();
  3294. }
  3295. }
  3296. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3297. {
  3298. u32 val;
  3299. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3300. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3301. int func = BP_FUNC(bp);
  3302. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3303. bnx2x_read_mf_cfg(bp);
  3304. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3305. func_mf_config[BP_ABS_FUNC(bp)].config);
  3306. val = SHMEM_RD(bp,
  3307. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3308. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3309. bnx2x_dcc_event(bp,
  3310. (val & DRV_STATUS_DCC_EVENT_MASK));
  3311. if (val & DRV_STATUS_SET_MF_BW)
  3312. bnx2x_set_mf_bw(bp);
  3313. if (val & DRV_STATUS_DRV_INFO_REQ)
  3314. bnx2x_handle_drv_info_req(bp);
  3315. if (val & DRV_STATUS_VF_DISABLED)
  3316. bnx2x_vf_handle_flr_event(bp);
  3317. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3318. bnx2x_pmf_update(bp);
  3319. if (bp->port.pmf &&
  3320. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3321. bp->dcbx_enabled > 0)
  3322. /* start dcbx state machine */
  3323. bnx2x_dcbx_set_params(bp,
  3324. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3325. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3326. bnx2x_handle_afex_cmd(bp,
  3327. val & DRV_STATUS_AFEX_EVENT_MASK);
  3328. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3329. bnx2x_handle_eee_event(bp);
  3330. if (bp->link_vars.periodic_flags &
  3331. PERIODIC_FLAGS_LINK_EVENT) {
  3332. /* sync with link */
  3333. bnx2x_acquire_phy_lock(bp);
  3334. bp->link_vars.periodic_flags &=
  3335. ~PERIODIC_FLAGS_LINK_EVENT;
  3336. bnx2x_release_phy_lock(bp);
  3337. if (IS_MF(bp))
  3338. bnx2x_link_sync_notify(bp);
  3339. bnx2x_link_report(bp);
  3340. }
  3341. /* Always call it here: bnx2x_link_report() will
  3342. * prevent the link indication duplication.
  3343. */
  3344. bnx2x__link_status_update(bp);
  3345. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3346. BNX2X_ERR("MC assert!\n");
  3347. bnx2x_mc_assert(bp);
  3348. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3349. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3350. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3351. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3352. bnx2x_panic();
  3353. } else if (attn & BNX2X_MCP_ASSERT) {
  3354. BNX2X_ERR("MCP assert!\n");
  3355. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3356. bnx2x_fw_dump(bp);
  3357. } else
  3358. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3359. }
  3360. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3361. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3362. if (attn & BNX2X_GRC_TIMEOUT) {
  3363. val = CHIP_IS_E1(bp) ? 0 :
  3364. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3365. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3366. }
  3367. if (attn & BNX2X_GRC_RSV) {
  3368. val = CHIP_IS_E1(bp) ? 0 :
  3369. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3370. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3371. }
  3372. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3373. }
  3374. }
  3375. /*
  3376. * Bits map:
  3377. * 0-7 - Engine0 load counter.
  3378. * 8-15 - Engine1 load counter.
  3379. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3380. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3381. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3382. * on the engine
  3383. * 19 - Engine1 ONE_IS_LOADED.
  3384. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3385. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3386. * just the one belonging to its engine).
  3387. *
  3388. */
  3389. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3390. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3391. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3392. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3393. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3394. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3395. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3396. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3397. /*
  3398. * Set the GLOBAL_RESET bit.
  3399. *
  3400. * Should be run under rtnl lock
  3401. */
  3402. void bnx2x_set_reset_global(struct bnx2x *bp)
  3403. {
  3404. u32 val;
  3405. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3406. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3407. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3408. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3409. }
  3410. /*
  3411. * Clear the GLOBAL_RESET bit.
  3412. *
  3413. * Should be run under rtnl lock
  3414. */
  3415. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3416. {
  3417. u32 val;
  3418. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3419. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3420. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3421. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3422. }
  3423. /*
  3424. * Checks the GLOBAL_RESET bit.
  3425. *
  3426. * should be run under rtnl lock
  3427. */
  3428. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3429. {
  3430. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3431. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3432. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3433. }
  3434. /*
  3435. * Clear RESET_IN_PROGRESS bit for the current engine.
  3436. *
  3437. * Should be run under rtnl lock
  3438. */
  3439. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3440. {
  3441. u32 val;
  3442. u32 bit = BP_PATH(bp) ?
  3443. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3444. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3445. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3446. /* Clear the bit */
  3447. val &= ~bit;
  3448. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3449. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3450. }
  3451. /*
  3452. * Set RESET_IN_PROGRESS for the current engine.
  3453. *
  3454. * should be run under rtnl lock
  3455. */
  3456. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3457. {
  3458. u32 val;
  3459. u32 bit = BP_PATH(bp) ?
  3460. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3461. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3462. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3463. /* Set the bit */
  3464. val |= bit;
  3465. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3466. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3467. }
  3468. /*
  3469. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3470. * should be run under rtnl lock
  3471. */
  3472. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3473. {
  3474. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3475. u32 bit = engine ?
  3476. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3477. /* return false if bit is set */
  3478. return (val & bit) ? false : true;
  3479. }
  3480. /*
  3481. * set pf load for the current pf.
  3482. *
  3483. * should be run under rtnl lock
  3484. */
  3485. void bnx2x_set_pf_load(struct bnx2x *bp)
  3486. {
  3487. u32 val1, val;
  3488. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3489. BNX2X_PATH0_LOAD_CNT_MASK;
  3490. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3491. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3492. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3493. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3494. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3495. /* get the current counter value */
  3496. val1 = (val & mask) >> shift;
  3497. /* set bit of that PF */
  3498. val1 |= (1 << bp->pf_num);
  3499. /* clear the old value */
  3500. val &= ~mask;
  3501. /* set the new one */
  3502. val |= ((val1 << shift) & mask);
  3503. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3504. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3505. }
  3506. /**
  3507. * bnx2x_clear_pf_load - clear pf load mark
  3508. *
  3509. * @bp: driver handle
  3510. *
  3511. * Should be run under rtnl lock.
  3512. * Decrements the load counter for the current engine. Returns
  3513. * whether other functions are still loaded
  3514. */
  3515. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3516. {
  3517. u32 val1, val;
  3518. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3519. BNX2X_PATH0_LOAD_CNT_MASK;
  3520. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3521. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3522. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3523. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3524. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3525. /* get the current counter value */
  3526. val1 = (val & mask) >> shift;
  3527. /* clear bit of that PF */
  3528. val1 &= ~(1 << bp->pf_num);
  3529. /* clear the old value */
  3530. val &= ~mask;
  3531. /* set the new one */
  3532. val |= ((val1 << shift) & mask);
  3533. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3534. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3535. return val1 != 0;
  3536. }
  3537. /*
  3538. * Read the load status for the current engine.
  3539. *
  3540. * should be run under rtnl lock
  3541. */
  3542. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3543. {
  3544. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3545. BNX2X_PATH0_LOAD_CNT_MASK);
  3546. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3547. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3548. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3549. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3550. val = (val & mask) >> shift;
  3551. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3552. engine, val);
  3553. return val != 0;
  3554. }
  3555. static void _print_next_block(int idx, const char *blk)
  3556. {
  3557. pr_cont("%s%s", idx ? ", " : "", blk);
  3558. }
  3559. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3560. bool print)
  3561. {
  3562. int i = 0;
  3563. u32 cur_bit = 0;
  3564. for (i = 0; sig; i++) {
  3565. cur_bit = ((u32)0x1 << i);
  3566. if (sig & cur_bit) {
  3567. switch (cur_bit) {
  3568. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3569. if (print)
  3570. _print_next_block(par_num++, "BRB");
  3571. break;
  3572. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3573. if (print)
  3574. _print_next_block(par_num++, "PARSER");
  3575. break;
  3576. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3577. if (print)
  3578. _print_next_block(par_num++, "TSDM");
  3579. break;
  3580. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3581. if (print)
  3582. _print_next_block(par_num++,
  3583. "SEARCHER");
  3584. break;
  3585. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3586. if (print)
  3587. _print_next_block(par_num++, "TCM");
  3588. break;
  3589. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3590. if (print)
  3591. _print_next_block(par_num++, "TSEMI");
  3592. break;
  3593. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3594. if (print)
  3595. _print_next_block(par_num++, "XPB");
  3596. break;
  3597. }
  3598. /* Clear the bit */
  3599. sig &= ~cur_bit;
  3600. }
  3601. }
  3602. return par_num;
  3603. }
  3604. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3605. bool *global, bool print)
  3606. {
  3607. int i = 0;
  3608. u32 cur_bit = 0;
  3609. for (i = 0; sig; i++) {
  3610. cur_bit = ((u32)0x1 << i);
  3611. if (sig & cur_bit) {
  3612. switch (cur_bit) {
  3613. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3614. if (print)
  3615. _print_next_block(par_num++, "PBF");
  3616. break;
  3617. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3618. if (print)
  3619. _print_next_block(par_num++, "QM");
  3620. break;
  3621. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3622. if (print)
  3623. _print_next_block(par_num++, "TM");
  3624. break;
  3625. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3626. if (print)
  3627. _print_next_block(par_num++, "XSDM");
  3628. break;
  3629. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3630. if (print)
  3631. _print_next_block(par_num++, "XCM");
  3632. break;
  3633. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3634. if (print)
  3635. _print_next_block(par_num++, "XSEMI");
  3636. break;
  3637. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3638. if (print)
  3639. _print_next_block(par_num++,
  3640. "DOORBELLQ");
  3641. break;
  3642. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3643. if (print)
  3644. _print_next_block(par_num++, "NIG");
  3645. break;
  3646. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3647. if (print)
  3648. _print_next_block(par_num++,
  3649. "VAUX PCI CORE");
  3650. *global = true;
  3651. break;
  3652. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3653. if (print)
  3654. _print_next_block(par_num++, "DEBUG");
  3655. break;
  3656. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3657. if (print)
  3658. _print_next_block(par_num++, "USDM");
  3659. break;
  3660. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3661. if (print)
  3662. _print_next_block(par_num++, "UCM");
  3663. break;
  3664. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3665. if (print)
  3666. _print_next_block(par_num++, "USEMI");
  3667. break;
  3668. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3669. if (print)
  3670. _print_next_block(par_num++, "UPB");
  3671. break;
  3672. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3673. if (print)
  3674. _print_next_block(par_num++, "CSDM");
  3675. break;
  3676. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3677. if (print)
  3678. _print_next_block(par_num++, "CCM");
  3679. break;
  3680. }
  3681. /* Clear the bit */
  3682. sig &= ~cur_bit;
  3683. }
  3684. }
  3685. return par_num;
  3686. }
  3687. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3688. bool print)
  3689. {
  3690. int i = 0;
  3691. u32 cur_bit = 0;
  3692. for (i = 0; sig; i++) {
  3693. cur_bit = ((u32)0x1 << i);
  3694. if (sig & cur_bit) {
  3695. switch (cur_bit) {
  3696. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3697. if (print)
  3698. _print_next_block(par_num++, "CSEMI");
  3699. break;
  3700. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3701. if (print)
  3702. _print_next_block(par_num++, "PXP");
  3703. break;
  3704. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3705. if (print)
  3706. _print_next_block(par_num++,
  3707. "PXPPCICLOCKCLIENT");
  3708. break;
  3709. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3710. if (print)
  3711. _print_next_block(par_num++, "CFC");
  3712. break;
  3713. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3714. if (print)
  3715. _print_next_block(par_num++, "CDU");
  3716. break;
  3717. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3718. if (print)
  3719. _print_next_block(par_num++, "DMAE");
  3720. break;
  3721. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3722. if (print)
  3723. _print_next_block(par_num++, "IGU");
  3724. break;
  3725. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3726. if (print)
  3727. _print_next_block(par_num++, "MISC");
  3728. break;
  3729. }
  3730. /* Clear the bit */
  3731. sig &= ~cur_bit;
  3732. }
  3733. }
  3734. return par_num;
  3735. }
  3736. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3737. bool *global, bool print)
  3738. {
  3739. int i = 0;
  3740. u32 cur_bit = 0;
  3741. for (i = 0; sig; i++) {
  3742. cur_bit = ((u32)0x1 << i);
  3743. if (sig & cur_bit) {
  3744. switch (cur_bit) {
  3745. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3746. if (print)
  3747. _print_next_block(par_num++, "MCP ROM");
  3748. *global = true;
  3749. break;
  3750. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3751. if (print)
  3752. _print_next_block(par_num++,
  3753. "MCP UMP RX");
  3754. *global = true;
  3755. break;
  3756. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3757. if (print)
  3758. _print_next_block(par_num++,
  3759. "MCP UMP TX");
  3760. *global = true;
  3761. break;
  3762. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3763. if (print)
  3764. _print_next_block(par_num++,
  3765. "MCP SCPAD");
  3766. *global = true;
  3767. break;
  3768. }
  3769. /* Clear the bit */
  3770. sig &= ~cur_bit;
  3771. }
  3772. }
  3773. return par_num;
  3774. }
  3775. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3776. bool print)
  3777. {
  3778. int i = 0;
  3779. u32 cur_bit = 0;
  3780. for (i = 0; sig; i++) {
  3781. cur_bit = ((u32)0x1 << i);
  3782. if (sig & cur_bit) {
  3783. switch (cur_bit) {
  3784. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3785. if (print)
  3786. _print_next_block(par_num++, "PGLUE_B");
  3787. break;
  3788. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3789. if (print)
  3790. _print_next_block(par_num++, "ATC");
  3791. break;
  3792. }
  3793. /* Clear the bit */
  3794. sig &= ~cur_bit;
  3795. }
  3796. }
  3797. return par_num;
  3798. }
  3799. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3800. u32 *sig)
  3801. {
  3802. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3803. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3804. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3805. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3806. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3807. int par_num = 0;
  3808. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3809. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3810. sig[0] & HW_PRTY_ASSERT_SET_0,
  3811. sig[1] & HW_PRTY_ASSERT_SET_1,
  3812. sig[2] & HW_PRTY_ASSERT_SET_2,
  3813. sig[3] & HW_PRTY_ASSERT_SET_3,
  3814. sig[4] & HW_PRTY_ASSERT_SET_4);
  3815. if (print)
  3816. netdev_err(bp->dev,
  3817. "Parity errors detected in blocks: ");
  3818. par_num = bnx2x_check_blocks_with_parity0(
  3819. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3820. par_num = bnx2x_check_blocks_with_parity1(
  3821. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3822. par_num = bnx2x_check_blocks_with_parity2(
  3823. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3824. par_num = bnx2x_check_blocks_with_parity3(
  3825. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3826. par_num = bnx2x_check_blocks_with_parity4(
  3827. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3828. if (print)
  3829. pr_cont("\n");
  3830. return true;
  3831. } else
  3832. return false;
  3833. }
  3834. /**
  3835. * bnx2x_chk_parity_attn - checks for parity attentions.
  3836. *
  3837. * @bp: driver handle
  3838. * @global: true if there was a global attention
  3839. * @print: show parity attention in syslog
  3840. */
  3841. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3842. {
  3843. struct attn_route attn = { {0} };
  3844. int port = BP_PORT(bp);
  3845. attn.sig[0] = REG_RD(bp,
  3846. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3847. port*4);
  3848. attn.sig[1] = REG_RD(bp,
  3849. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3850. port*4);
  3851. attn.sig[2] = REG_RD(bp,
  3852. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3853. port*4);
  3854. attn.sig[3] = REG_RD(bp,
  3855. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3856. port*4);
  3857. if (!CHIP_IS_E1x(bp))
  3858. attn.sig[4] = REG_RD(bp,
  3859. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3860. port*4);
  3861. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3862. }
  3863. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3864. {
  3865. u32 val;
  3866. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3867. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3868. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3869. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3870. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3871. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3872. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3873. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3874. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3875. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3876. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3877. if (val &
  3878. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3879. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3880. if (val &
  3881. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3882. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3883. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3884. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3885. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3886. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3887. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3888. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3889. }
  3890. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3891. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3892. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3893. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3894. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3895. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3896. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3897. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3898. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3899. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3900. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3901. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3902. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3903. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3904. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3905. }
  3906. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3907. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3908. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3909. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3910. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3911. }
  3912. }
  3913. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3914. {
  3915. struct attn_route attn, *group_mask;
  3916. int port = BP_PORT(bp);
  3917. int index;
  3918. u32 reg_addr;
  3919. u32 val;
  3920. u32 aeu_mask;
  3921. bool global = false;
  3922. /* need to take HW lock because MCP or other port might also
  3923. try to handle this event */
  3924. bnx2x_acquire_alr(bp);
  3925. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3926. #ifndef BNX2X_STOP_ON_ERROR
  3927. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3928. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3929. /* Disable HW interrupts */
  3930. bnx2x_int_disable(bp);
  3931. /* In case of parity errors don't handle attentions so that
  3932. * other function would "see" parity errors.
  3933. */
  3934. #else
  3935. bnx2x_panic();
  3936. #endif
  3937. bnx2x_release_alr(bp);
  3938. return;
  3939. }
  3940. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3941. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3942. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3943. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3944. if (!CHIP_IS_E1x(bp))
  3945. attn.sig[4] =
  3946. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3947. else
  3948. attn.sig[4] = 0;
  3949. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3950. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3951. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3952. if (deasserted & (1 << index)) {
  3953. group_mask = &bp->attn_group[index];
  3954. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3955. index,
  3956. group_mask->sig[0], group_mask->sig[1],
  3957. group_mask->sig[2], group_mask->sig[3],
  3958. group_mask->sig[4]);
  3959. bnx2x_attn_int_deasserted4(bp,
  3960. attn.sig[4] & group_mask->sig[4]);
  3961. bnx2x_attn_int_deasserted3(bp,
  3962. attn.sig[3] & group_mask->sig[3]);
  3963. bnx2x_attn_int_deasserted1(bp,
  3964. attn.sig[1] & group_mask->sig[1]);
  3965. bnx2x_attn_int_deasserted2(bp,
  3966. attn.sig[2] & group_mask->sig[2]);
  3967. bnx2x_attn_int_deasserted0(bp,
  3968. attn.sig[0] & group_mask->sig[0]);
  3969. }
  3970. }
  3971. bnx2x_release_alr(bp);
  3972. if (bp->common.int_block == INT_BLOCK_HC)
  3973. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3974. COMMAND_REG_ATTN_BITS_CLR);
  3975. else
  3976. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3977. val = ~deasserted;
  3978. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3979. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3980. REG_WR(bp, reg_addr, val);
  3981. if (~bp->attn_state & deasserted)
  3982. BNX2X_ERR("IGU ERROR\n");
  3983. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3984. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3985. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3986. aeu_mask = REG_RD(bp, reg_addr);
  3987. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3988. aeu_mask, deasserted);
  3989. aeu_mask |= (deasserted & 0x3ff);
  3990. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3991. REG_WR(bp, reg_addr, aeu_mask);
  3992. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3993. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3994. bp->attn_state &= ~deasserted;
  3995. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3996. }
  3997. static void bnx2x_attn_int(struct bnx2x *bp)
  3998. {
  3999. /* read local copy of bits */
  4000. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4001. attn_bits);
  4002. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4003. attn_bits_ack);
  4004. u32 attn_state = bp->attn_state;
  4005. /* look for changed bits */
  4006. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4007. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4008. DP(NETIF_MSG_HW,
  4009. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4010. attn_bits, attn_ack, asserted, deasserted);
  4011. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4012. BNX2X_ERR("BAD attention state\n");
  4013. /* handle bits that were raised */
  4014. if (asserted)
  4015. bnx2x_attn_int_asserted(bp, asserted);
  4016. if (deasserted)
  4017. bnx2x_attn_int_deasserted(bp, deasserted);
  4018. }
  4019. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4020. u16 index, u8 op, u8 update)
  4021. {
  4022. u32 igu_addr = bp->igu_base_addr;
  4023. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4024. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4025. igu_addr);
  4026. }
  4027. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4028. {
  4029. /* No memory barriers */
  4030. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4031. mmiowb(); /* keep prod updates ordered */
  4032. }
  4033. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4034. union event_ring_elem *elem)
  4035. {
  4036. u8 err = elem->message.error;
  4037. if (!bp->cnic_eth_dev.starting_cid ||
  4038. (cid < bp->cnic_eth_dev.starting_cid &&
  4039. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4040. return 1;
  4041. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4042. if (unlikely(err)) {
  4043. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4044. cid);
  4045. bnx2x_panic_dump(bp, false);
  4046. }
  4047. bnx2x_cnic_cfc_comp(bp, cid, err);
  4048. return 0;
  4049. }
  4050. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4051. {
  4052. struct bnx2x_mcast_ramrod_params rparam;
  4053. int rc;
  4054. memset(&rparam, 0, sizeof(rparam));
  4055. rparam.mcast_obj = &bp->mcast_obj;
  4056. netif_addr_lock_bh(bp->dev);
  4057. /* Clear pending state for the last command */
  4058. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4059. /* If there are pending mcast commands - send them */
  4060. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4061. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4062. if (rc < 0)
  4063. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4064. rc);
  4065. }
  4066. netif_addr_unlock_bh(bp->dev);
  4067. }
  4068. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4069. union event_ring_elem *elem)
  4070. {
  4071. unsigned long ramrod_flags = 0;
  4072. int rc = 0;
  4073. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4074. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4075. /* Always push next commands out, don't wait here */
  4076. __set_bit(RAMROD_CONT, &ramrod_flags);
  4077. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4078. >> BNX2X_SWCID_SHIFT) {
  4079. case BNX2X_FILTER_MAC_PENDING:
  4080. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4081. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4082. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4083. else
  4084. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4085. break;
  4086. case BNX2X_FILTER_MCAST_PENDING:
  4087. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4088. /* This is only relevant for 57710 where multicast MACs are
  4089. * configured as unicast MACs using the same ramrod.
  4090. */
  4091. bnx2x_handle_mcast_eqe(bp);
  4092. return;
  4093. default:
  4094. BNX2X_ERR("Unsupported classification command: %d\n",
  4095. elem->message.data.eth_event.echo);
  4096. return;
  4097. }
  4098. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4099. if (rc < 0)
  4100. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4101. else if (rc > 0)
  4102. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4103. }
  4104. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4105. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4106. {
  4107. netif_addr_lock_bh(bp->dev);
  4108. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4109. /* Send rx_mode command again if was requested */
  4110. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4111. bnx2x_set_storm_rx_mode(bp);
  4112. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4113. &bp->sp_state))
  4114. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4115. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4116. &bp->sp_state))
  4117. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4118. netif_addr_unlock_bh(bp->dev);
  4119. }
  4120. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4121. union event_ring_elem *elem)
  4122. {
  4123. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4124. DP(BNX2X_MSG_SP,
  4125. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4126. elem->message.data.vif_list_event.func_bit_map);
  4127. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4128. elem->message.data.vif_list_event.func_bit_map);
  4129. } else if (elem->message.data.vif_list_event.echo ==
  4130. VIF_LIST_RULE_SET) {
  4131. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4132. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4133. }
  4134. }
  4135. /* called with rtnl_lock */
  4136. static void bnx2x_after_function_update(struct bnx2x *bp)
  4137. {
  4138. int q, rc;
  4139. struct bnx2x_fastpath *fp;
  4140. struct bnx2x_queue_state_params queue_params = {NULL};
  4141. struct bnx2x_queue_update_params *q_update_params =
  4142. &queue_params.params.update;
  4143. /* Send Q update command with afex vlan removal values for all Qs */
  4144. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4145. /* set silent vlan removal values according to vlan mode */
  4146. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4147. &q_update_params->update_flags);
  4148. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4149. &q_update_params->update_flags);
  4150. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4151. /* in access mode mark mask and value are 0 to strip all vlans */
  4152. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4153. q_update_params->silent_removal_value = 0;
  4154. q_update_params->silent_removal_mask = 0;
  4155. } else {
  4156. q_update_params->silent_removal_value =
  4157. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4158. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4159. }
  4160. for_each_eth_queue(bp, q) {
  4161. /* Set the appropriate Queue object */
  4162. fp = &bp->fp[q];
  4163. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4164. /* send the ramrod */
  4165. rc = bnx2x_queue_state_change(bp, &queue_params);
  4166. if (rc < 0)
  4167. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4168. q);
  4169. }
  4170. if (!NO_FCOE(bp)) {
  4171. fp = &bp->fp[FCOE_IDX(bp)];
  4172. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4173. /* clear pending completion bit */
  4174. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4175. /* mark latest Q bit */
  4176. smp_mb__before_clear_bit();
  4177. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4178. smp_mb__after_clear_bit();
  4179. /* send Q update ramrod for FCoE Q */
  4180. rc = bnx2x_queue_state_change(bp, &queue_params);
  4181. if (rc < 0)
  4182. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4183. q);
  4184. } else {
  4185. /* If no FCoE ring - ACK MCP now */
  4186. bnx2x_link_report(bp);
  4187. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4188. }
  4189. }
  4190. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4191. struct bnx2x *bp, u32 cid)
  4192. {
  4193. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4194. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4195. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4196. else
  4197. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4198. }
  4199. static void bnx2x_eq_int(struct bnx2x *bp)
  4200. {
  4201. u16 hw_cons, sw_cons, sw_prod;
  4202. union event_ring_elem *elem;
  4203. u8 echo;
  4204. u32 cid;
  4205. u8 opcode;
  4206. int rc, spqe_cnt = 0;
  4207. struct bnx2x_queue_sp_obj *q_obj;
  4208. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4209. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4210. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4211. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4212. * when we get the the next-page we nned to adjust so the loop
  4213. * condition below will be met. The next element is the size of a
  4214. * regular element and hence incrementing by 1
  4215. */
  4216. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4217. hw_cons++;
  4218. /* This function may never run in parallel with itself for a
  4219. * specific bp, thus there is no need in "paired" read memory
  4220. * barrier here.
  4221. */
  4222. sw_cons = bp->eq_cons;
  4223. sw_prod = bp->eq_prod;
  4224. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4225. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4226. for (; sw_cons != hw_cons;
  4227. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4228. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4229. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4230. if (!rc) {
  4231. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4232. rc);
  4233. goto next_spqe;
  4234. }
  4235. /* elem CID originates from FW; actually LE */
  4236. cid = SW_CID((__force __le32)
  4237. elem->message.data.cfc_del_event.cid);
  4238. opcode = elem->message.opcode;
  4239. /* handle eq element */
  4240. switch (opcode) {
  4241. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4242. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4243. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4244. continue;
  4245. case EVENT_RING_OPCODE_STAT_QUERY:
  4246. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4247. "got statistics comp event %d\n",
  4248. bp->stats_comp++);
  4249. /* nothing to do with stats comp */
  4250. goto next_spqe;
  4251. case EVENT_RING_OPCODE_CFC_DEL:
  4252. /* handle according to cid range */
  4253. /*
  4254. * we may want to verify here that the bp state is
  4255. * HALTING
  4256. */
  4257. DP(BNX2X_MSG_SP,
  4258. "got delete ramrod for MULTI[%d]\n", cid);
  4259. if (CNIC_LOADED(bp) &&
  4260. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4261. goto next_spqe;
  4262. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4263. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4264. break;
  4265. goto next_spqe;
  4266. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4267. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4268. if (f_obj->complete_cmd(bp, f_obj,
  4269. BNX2X_F_CMD_TX_STOP))
  4270. break;
  4271. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4272. goto next_spqe;
  4273. case EVENT_RING_OPCODE_START_TRAFFIC:
  4274. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4275. if (f_obj->complete_cmd(bp, f_obj,
  4276. BNX2X_F_CMD_TX_START))
  4277. break;
  4278. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4279. goto next_spqe;
  4280. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4281. echo = elem->message.data.function_update_event.echo;
  4282. if (echo == SWITCH_UPDATE) {
  4283. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4284. "got FUNC_SWITCH_UPDATE ramrod\n");
  4285. if (f_obj->complete_cmd(
  4286. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4287. break;
  4288. } else {
  4289. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4290. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4291. f_obj->complete_cmd(bp, f_obj,
  4292. BNX2X_F_CMD_AFEX_UPDATE);
  4293. /* We will perform the Queues update from
  4294. * sp_rtnl task as all Queue SP operations
  4295. * should run under rtnl_lock.
  4296. */
  4297. smp_mb__before_clear_bit();
  4298. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4299. &bp->sp_rtnl_state);
  4300. smp_mb__after_clear_bit();
  4301. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4302. }
  4303. goto next_spqe;
  4304. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4305. f_obj->complete_cmd(bp, f_obj,
  4306. BNX2X_F_CMD_AFEX_VIFLISTS);
  4307. bnx2x_after_afex_vif_lists(bp, elem);
  4308. goto next_spqe;
  4309. case EVENT_RING_OPCODE_FUNCTION_START:
  4310. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4311. "got FUNC_START ramrod\n");
  4312. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4313. break;
  4314. goto next_spqe;
  4315. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4316. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4317. "got FUNC_STOP ramrod\n");
  4318. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4319. break;
  4320. goto next_spqe;
  4321. }
  4322. switch (opcode | bp->state) {
  4323. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4324. BNX2X_STATE_OPEN):
  4325. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4326. BNX2X_STATE_OPENING_WAIT4_PORT):
  4327. cid = elem->message.data.eth_event.echo &
  4328. BNX2X_SWCID_MASK;
  4329. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4330. cid);
  4331. rss_raw->clear_pending(rss_raw);
  4332. break;
  4333. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4334. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4335. case (EVENT_RING_OPCODE_SET_MAC |
  4336. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4337. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4338. BNX2X_STATE_OPEN):
  4339. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4340. BNX2X_STATE_DIAG):
  4341. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4342. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4343. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4344. bnx2x_handle_classification_eqe(bp, elem);
  4345. break;
  4346. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4347. BNX2X_STATE_OPEN):
  4348. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4349. BNX2X_STATE_DIAG):
  4350. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4351. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4352. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4353. bnx2x_handle_mcast_eqe(bp);
  4354. break;
  4355. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4356. BNX2X_STATE_OPEN):
  4357. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4358. BNX2X_STATE_DIAG):
  4359. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4360. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4361. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4362. bnx2x_handle_rx_mode_eqe(bp);
  4363. break;
  4364. default:
  4365. /* unknown event log error and continue */
  4366. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4367. elem->message.opcode, bp->state);
  4368. }
  4369. next_spqe:
  4370. spqe_cnt++;
  4371. } /* for */
  4372. smp_mb__before_atomic_inc();
  4373. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4374. bp->eq_cons = sw_cons;
  4375. bp->eq_prod = sw_prod;
  4376. /* Make sure that above mem writes were issued towards the memory */
  4377. smp_wmb();
  4378. /* update producer */
  4379. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4380. }
  4381. static void bnx2x_sp_task(struct work_struct *work)
  4382. {
  4383. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4384. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4385. /* make sure the atomic interupt_occurred has been written */
  4386. smp_rmb();
  4387. if (atomic_read(&bp->interrupt_occurred)) {
  4388. /* what work needs to be performed? */
  4389. u16 status = bnx2x_update_dsb_idx(bp);
  4390. DP(BNX2X_MSG_SP, "status %x\n", status);
  4391. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4392. atomic_set(&bp->interrupt_occurred, 0);
  4393. /* HW attentions */
  4394. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4395. bnx2x_attn_int(bp);
  4396. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4397. }
  4398. /* SP events: STAT_QUERY and others */
  4399. if (status & BNX2X_DEF_SB_IDX) {
  4400. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4401. if (FCOE_INIT(bp) &&
  4402. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4403. /* Prevent local bottom-halves from running as
  4404. * we are going to change the local NAPI list.
  4405. */
  4406. local_bh_disable();
  4407. napi_schedule(&bnx2x_fcoe(bp, napi));
  4408. local_bh_enable();
  4409. }
  4410. /* Handle EQ completions */
  4411. bnx2x_eq_int(bp);
  4412. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4413. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4414. status &= ~BNX2X_DEF_SB_IDX;
  4415. }
  4416. /* if status is non zero then perhaps something went wrong */
  4417. if (unlikely(status))
  4418. DP(BNX2X_MSG_SP,
  4419. "got an unknown interrupt! (status 0x%x)\n", status);
  4420. /* ack status block only if something was actually handled */
  4421. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4422. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4423. }
  4424. /* must be called after the EQ processing (since eq leads to sriov
  4425. * ramrod completion flows).
  4426. * This flow may have been scheduled by the arrival of a ramrod
  4427. * completion, or by the sriov code rescheduling itself.
  4428. */
  4429. bnx2x_iov_sp_task(bp);
  4430. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4431. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4432. &bp->sp_state)) {
  4433. bnx2x_link_report(bp);
  4434. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4435. }
  4436. }
  4437. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4438. {
  4439. struct net_device *dev = dev_instance;
  4440. struct bnx2x *bp = netdev_priv(dev);
  4441. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4442. IGU_INT_DISABLE, 0);
  4443. #ifdef BNX2X_STOP_ON_ERROR
  4444. if (unlikely(bp->panic))
  4445. return IRQ_HANDLED;
  4446. #endif
  4447. if (CNIC_LOADED(bp)) {
  4448. struct cnic_ops *c_ops;
  4449. rcu_read_lock();
  4450. c_ops = rcu_dereference(bp->cnic_ops);
  4451. if (c_ops)
  4452. c_ops->cnic_handler(bp->cnic_data, NULL);
  4453. rcu_read_unlock();
  4454. }
  4455. /* schedule sp task to perform default status block work, ack
  4456. * attentions and enable interrupts.
  4457. */
  4458. bnx2x_schedule_sp_task(bp);
  4459. return IRQ_HANDLED;
  4460. }
  4461. /* end of slow path */
  4462. void bnx2x_drv_pulse(struct bnx2x *bp)
  4463. {
  4464. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4465. bp->fw_drv_pulse_wr_seq);
  4466. }
  4467. static void bnx2x_timer(unsigned long data)
  4468. {
  4469. struct bnx2x *bp = (struct bnx2x *) data;
  4470. if (!netif_running(bp->dev))
  4471. return;
  4472. if (IS_PF(bp) &&
  4473. !BP_NOMCP(bp)) {
  4474. int mb_idx = BP_FW_MB_IDX(bp);
  4475. u32 drv_pulse;
  4476. u32 mcp_pulse;
  4477. ++bp->fw_drv_pulse_wr_seq;
  4478. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4479. /* TBD - add SYSTEM_TIME */
  4480. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4481. bnx2x_drv_pulse(bp);
  4482. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4483. MCP_PULSE_SEQ_MASK);
  4484. /* The delta between driver pulse and mcp response
  4485. * should be 1 (before mcp response) or 0 (after mcp response)
  4486. */
  4487. if ((drv_pulse != mcp_pulse) &&
  4488. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4489. /* someone lost a heartbeat... */
  4490. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4491. drv_pulse, mcp_pulse);
  4492. }
  4493. }
  4494. if (bp->state == BNX2X_STATE_OPEN)
  4495. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4496. /* sample pf vf bulletin board for new posts from pf */
  4497. if (IS_VF(bp))
  4498. bnx2x_sample_bulletin(bp);
  4499. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4500. }
  4501. /* end of Statistics */
  4502. /* nic init */
  4503. /*
  4504. * nic init service functions
  4505. */
  4506. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4507. {
  4508. u32 i;
  4509. if (!(len%4) && !(addr%4))
  4510. for (i = 0; i < len; i += 4)
  4511. REG_WR(bp, addr + i, fill);
  4512. else
  4513. for (i = 0; i < len; i++)
  4514. REG_WR8(bp, addr + i, fill);
  4515. }
  4516. /* helper: writes FP SP data to FW - data_size in dwords */
  4517. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4518. int fw_sb_id,
  4519. u32 *sb_data_p,
  4520. u32 data_size)
  4521. {
  4522. int index;
  4523. for (index = 0; index < data_size; index++)
  4524. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4525. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4526. sizeof(u32)*index,
  4527. *(sb_data_p + index));
  4528. }
  4529. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4530. {
  4531. u32 *sb_data_p;
  4532. u32 data_size = 0;
  4533. struct hc_status_block_data_e2 sb_data_e2;
  4534. struct hc_status_block_data_e1x sb_data_e1x;
  4535. /* disable the function first */
  4536. if (!CHIP_IS_E1x(bp)) {
  4537. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4538. sb_data_e2.common.state = SB_DISABLED;
  4539. sb_data_e2.common.p_func.vf_valid = false;
  4540. sb_data_p = (u32 *)&sb_data_e2;
  4541. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4542. } else {
  4543. memset(&sb_data_e1x, 0,
  4544. sizeof(struct hc_status_block_data_e1x));
  4545. sb_data_e1x.common.state = SB_DISABLED;
  4546. sb_data_e1x.common.p_func.vf_valid = false;
  4547. sb_data_p = (u32 *)&sb_data_e1x;
  4548. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4549. }
  4550. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4551. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4552. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4553. CSTORM_STATUS_BLOCK_SIZE);
  4554. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4555. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4556. CSTORM_SYNC_BLOCK_SIZE);
  4557. }
  4558. /* helper: writes SP SB data to FW */
  4559. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4560. struct hc_sp_status_block_data *sp_sb_data)
  4561. {
  4562. int func = BP_FUNC(bp);
  4563. int i;
  4564. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4565. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4566. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4567. i*sizeof(u32),
  4568. *((u32 *)sp_sb_data + i));
  4569. }
  4570. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4571. {
  4572. int func = BP_FUNC(bp);
  4573. struct hc_sp_status_block_data sp_sb_data;
  4574. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4575. sp_sb_data.state = SB_DISABLED;
  4576. sp_sb_data.p_func.vf_valid = false;
  4577. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4578. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4579. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4580. CSTORM_SP_STATUS_BLOCK_SIZE);
  4581. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4582. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4583. CSTORM_SP_SYNC_BLOCK_SIZE);
  4584. }
  4585. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4586. int igu_sb_id, int igu_seg_id)
  4587. {
  4588. hc_sm->igu_sb_id = igu_sb_id;
  4589. hc_sm->igu_seg_id = igu_seg_id;
  4590. hc_sm->timer_value = 0xFF;
  4591. hc_sm->time_to_expire = 0xFFFFFFFF;
  4592. }
  4593. /* allocates state machine ids. */
  4594. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4595. {
  4596. /* zero out state machine indices */
  4597. /* rx indices */
  4598. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4599. /* tx indices */
  4600. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4601. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4602. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4603. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4604. /* map indices */
  4605. /* rx indices */
  4606. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4607. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4608. /* tx indices */
  4609. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4610. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4611. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4612. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4613. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4614. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4615. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4616. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4617. }
  4618. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4619. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4620. {
  4621. int igu_seg_id;
  4622. struct hc_status_block_data_e2 sb_data_e2;
  4623. struct hc_status_block_data_e1x sb_data_e1x;
  4624. struct hc_status_block_sm *hc_sm_p;
  4625. int data_size;
  4626. u32 *sb_data_p;
  4627. if (CHIP_INT_MODE_IS_BC(bp))
  4628. igu_seg_id = HC_SEG_ACCESS_NORM;
  4629. else
  4630. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4631. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4632. if (!CHIP_IS_E1x(bp)) {
  4633. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4634. sb_data_e2.common.state = SB_ENABLED;
  4635. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4636. sb_data_e2.common.p_func.vf_id = vfid;
  4637. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4638. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4639. sb_data_e2.common.same_igu_sb_1b = true;
  4640. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4641. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4642. hc_sm_p = sb_data_e2.common.state_machine;
  4643. sb_data_p = (u32 *)&sb_data_e2;
  4644. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4645. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4646. } else {
  4647. memset(&sb_data_e1x, 0,
  4648. sizeof(struct hc_status_block_data_e1x));
  4649. sb_data_e1x.common.state = SB_ENABLED;
  4650. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4651. sb_data_e1x.common.p_func.vf_id = 0xff;
  4652. sb_data_e1x.common.p_func.vf_valid = false;
  4653. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4654. sb_data_e1x.common.same_igu_sb_1b = true;
  4655. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4656. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4657. hc_sm_p = sb_data_e1x.common.state_machine;
  4658. sb_data_p = (u32 *)&sb_data_e1x;
  4659. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4660. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4661. }
  4662. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4663. igu_sb_id, igu_seg_id);
  4664. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4665. igu_sb_id, igu_seg_id);
  4666. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4667. /* write indices to HW - PCI guarantees endianity of regpairs */
  4668. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4669. }
  4670. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4671. u16 tx_usec, u16 rx_usec)
  4672. {
  4673. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4674. false, rx_usec);
  4675. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4676. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4677. tx_usec);
  4678. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4679. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4680. tx_usec);
  4681. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4682. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4683. tx_usec);
  4684. }
  4685. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4686. {
  4687. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4688. dma_addr_t mapping = bp->def_status_blk_mapping;
  4689. int igu_sp_sb_index;
  4690. int igu_seg_id;
  4691. int port = BP_PORT(bp);
  4692. int func = BP_FUNC(bp);
  4693. int reg_offset, reg_offset_en5;
  4694. u64 section;
  4695. int index;
  4696. struct hc_sp_status_block_data sp_sb_data;
  4697. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4698. if (CHIP_INT_MODE_IS_BC(bp)) {
  4699. igu_sp_sb_index = DEF_SB_IGU_ID;
  4700. igu_seg_id = HC_SEG_ACCESS_DEF;
  4701. } else {
  4702. igu_sp_sb_index = bp->igu_dsb_id;
  4703. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4704. }
  4705. /* ATTN */
  4706. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4707. atten_status_block);
  4708. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4709. bp->attn_state = 0;
  4710. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4711. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4712. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4713. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4714. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4715. int sindex;
  4716. /* take care of sig[0]..sig[4] */
  4717. for (sindex = 0; sindex < 4; sindex++)
  4718. bp->attn_group[index].sig[sindex] =
  4719. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4720. if (!CHIP_IS_E1x(bp))
  4721. /*
  4722. * enable5 is separate from the rest of the registers,
  4723. * and therefore the address skip is 4
  4724. * and not 16 between the different groups
  4725. */
  4726. bp->attn_group[index].sig[4] = REG_RD(bp,
  4727. reg_offset_en5 + 0x4*index);
  4728. else
  4729. bp->attn_group[index].sig[4] = 0;
  4730. }
  4731. if (bp->common.int_block == INT_BLOCK_HC) {
  4732. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4733. HC_REG_ATTN_MSG0_ADDR_L);
  4734. REG_WR(bp, reg_offset, U64_LO(section));
  4735. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4736. } else if (!CHIP_IS_E1x(bp)) {
  4737. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4738. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4739. }
  4740. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4741. sp_sb);
  4742. bnx2x_zero_sp_sb(bp);
  4743. /* PCI guarantees endianity of regpairs */
  4744. sp_sb_data.state = SB_ENABLED;
  4745. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4746. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4747. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4748. sp_sb_data.igu_seg_id = igu_seg_id;
  4749. sp_sb_data.p_func.pf_id = func;
  4750. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4751. sp_sb_data.p_func.vf_id = 0xff;
  4752. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4753. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4754. }
  4755. void bnx2x_update_coalesce(struct bnx2x *bp)
  4756. {
  4757. int i;
  4758. for_each_eth_queue(bp, i)
  4759. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4760. bp->tx_ticks, bp->rx_ticks);
  4761. }
  4762. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4763. {
  4764. spin_lock_init(&bp->spq_lock);
  4765. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4766. bp->spq_prod_idx = 0;
  4767. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4768. bp->spq_prod_bd = bp->spq;
  4769. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4770. }
  4771. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4772. {
  4773. int i;
  4774. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4775. union event_ring_elem *elem =
  4776. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4777. elem->next_page.addr.hi =
  4778. cpu_to_le32(U64_HI(bp->eq_mapping +
  4779. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4780. elem->next_page.addr.lo =
  4781. cpu_to_le32(U64_LO(bp->eq_mapping +
  4782. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4783. }
  4784. bp->eq_cons = 0;
  4785. bp->eq_prod = NUM_EQ_DESC;
  4786. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4787. /* we want a warning message before it gets rought... */
  4788. atomic_set(&bp->eq_spq_left,
  4789. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4790. }
  4791. /* called with netif_addr_lock_bh() */
  4792. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4793. unsigned long rx_mode_flags,
  4794. unsigned long rx_accept_flags,
  4795. unsigned long tx_accept_flags,
  4796. unsigned long ramrod_flags)
  4797. {
  4798. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4799. int rc;
  4800. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4801. /* Prepare ramrod parameters */
  4802. ramrod_param.cid = 0;
  4803. ramrod_param.cl_id = cl_id;
  4804. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4805. ramrod_param.func_id = BP_FUNC(bp);
  4806. ramrod_param.pstate = &bp->sp_state;
  4807. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4808. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4809. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4810. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4811. ramrod_param.ramrod_flags = ramrod_flags;
  4812. ramrod_param.rx_mode_flags = rx_mode_flags;
  4813. ramrod_param.rx_accept_flags = rx_accept_flags;
  4814. ramrod_param.tx_accept_flags = tx_accept_flags;
  4815. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4816. if (rc < 0) {
  4817. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4818. return rc;
  4819. }
  4820. return 0;
  4821. }
  4822. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4823. unsigned long *rx_accept_flags,
  4824. unsigned long *tx_accept_flags)
  4825. {
  4826. /* Clear the flags first */
  4827. *rx_accept_flags = 0;
  4828. *tx_accept_flags = 0;
  4829. switch (rx_mode) {
  4830. case BNX2X_RX_MODE_NONE:
  4831. /*
  4832. * 'drop all' supersedes any accept flags that may have been
  4833. * passed to the function.
  4834. */
  4835. break;
  4836. case BNX2X_RX_MODE_NORMAL:
  4837. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4838. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4839. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4840. /* internal switching mode */
  4841. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4842. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4843. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4844. break;
  4845. case BNX2X_RX_MODE_ALLMULTI:
  4846. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4847. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4848. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4849. /* internal switching mode */
  4850. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4851. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4852. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4853. break;
  4854. case BNX2X_RX_MODE_PROMISC:
  4855. /* According to deffinition of SI mode, iface in promisc mode
  4856. * should receive matched and unmatched (in resolution of port)
  4857. * unicast packets.
  4858. */
  4859. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4860. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4861. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4862. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4863. /* internal switching mode */
  4864. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4865. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4866. if (IS_MF_SI(bp))
  4867. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4868. else
  4869. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4870. break;
  4871. default:
  4872. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4873. return -EINVAL;
  4874. }
  4875. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  4876. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4877. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  4878. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  4879. }
  4880. return 0;
  4881. }
  4882. /* called with netif_addr_lock_bh() */
  4883. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4884. {
  4885. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4886. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4887. int rc;
  4888. if (!NO_FCOE(bp))
  4889. /* Configure rx_mode of FCoE Queue */
  4890. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4891. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  4892. &tx_accept_flags);
  4893. if (rc)
  4894. return rc;
  4895. __set_bit(RAMROD_RX, &ramrod_flags);
  4896. __set_bit(RAMROD_TX, &ramrod_flags);
  4897. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  4898. rx_accept_flags, tx_accept_flags,
  4899. ramrod_flags);
  4900. }
  4901. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4902. {
  4903. int i;
  4904. if (IS_MF_SI(bp))
  4905. /*
  4906. * In switch independent mode, the TSTORM needs to accept
  4907. * packets that failed classification, since approximate match
  4908. * mac addresses aren't written to NIG LLH
  4909. */
  4910. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4911. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4912. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4913. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4914. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4915. /* Zero this manually as its initialization is
  4916. currently missing in the initTool */
  4917. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4918. REG_WR(bp, BAR_USTRORM_INTMEM +
  4919. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4920. if (!CHIP_IS_E1x(bp)) {
  4921. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4922. CHIP_INT_MODE_IS_BC(bp) ?
  4923. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4924. }
  4925. }
  4926. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4927. {
  4928. switch (load_code) {
  4929. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4930. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4931. bnx2x_init_internal_common(bp);
  4932. /* no break */
  4933. case FW_MSG_CODE_DRV_LOAD_PORT:
  4934. /* nothing to do */
  4935. /* no break */
  4936. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4937. /* internal memory per function is
  4938. initialized inside bnx2x_pf_init */
  4939. break;
  4940. default:
  4941. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4942. break;
  4943. }
  4944. }
  4945. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4946. {
  4947. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4948. }
  4949. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4950. {
  4951. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4952. }
  4953. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4954. {
  4955. if (CHIP_IS_E1x(fp->bp))
  4956. return BP_L_ID(fp->bp) + fp->index;
  4957. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4958. return bnx2x_fp_igu_sb_id(fp);
  4959. }
  4960. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4961. {
  4962. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4963. u8 cos;
  4964. unsigned long q_type = 0;
  4965. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4966. fp->rx_queue = fp_idx;
  4967. fp->cid = fp_idx;
  4968. fp->cl_id = bnx2x_fp_cl_id(fp);
  4969. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4970. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4971. /* qZone id equals to FW (per path) client id */
  4972. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4973. /* init shortcut */
  4974. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4975. /* Setup SB indicies */
  4976. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4977. /* Configure Queue State object */
  4978. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4979. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4980. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4981. /* init tx data */
  4982. for_each_cos_in_tx_queue(fp, cos) {
  4983. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4984. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4985. FP_COS_TO_TXQ(fp, cos, bp),
  4986. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4987. cids[cos] = fp->txdata_ptr[cos]->cid;
  4988. }
  4989. /* nothing more for vf to do here */
  4990. if (IS_VF(bp))
  4991. return;
  4992. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4993. fp->fw_sb_id, fp->igu_sb_id);
  4994. bnx2x_update_fpsb_idx(fp);
  4995. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4996. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4997. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4998. /**
  4999. * Configure classification DBs: Always enable Tx switching
  5000. */
  5001. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5002. DP(NETIF_MSG_IFUP,
  5003. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5004. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5005. fp->igu_sb_id);
  5006. }
  5007. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5008. {
  5009. int i;
  5010. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5011. struct eth_tx_next_bd *tx_next_bd =
  5012. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5013. tx_next_bd->addr_hi =
  5014. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5015. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5016. tx_next_bd->addr_lo =
  5017. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5018. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5019. }
  5020. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5021. txdata->tx_db.data.zero_fill1 = 0;
  5022. txdata->tx_db.data.prod = 0;
  5023. txdata->tx_pkt_prod = 0;
  5024. txdata->tx_pkt_cons = 0;
  5025. txdata->tx_bd_prod = 0;
  5026. txdata->tx_bd_cons = 0;
  5027. txdata->tx_pkt = 0;
  5028. }
  5029. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5030. {
  5031. int i;
  5032. for_each_tx_queue_cnic(bp, i)
  5033. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5034. }
  5035. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5036. {
  5037. int i;
  5038. u8 cos;
  5039. for_each_eth_queue(bp, i)
  5040. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5041. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5042. }
  5043. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5044. {
  5045. if (!NO_FCOE(bp))
  5046. bnx2x_init_fcoe_fp(bp);
  5047. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5048. BNX2X_VF_ID_INVALID, false,
  5049. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5050. /* ensure status block indices were read */
  5051. rmb();
  5052. bnx2x_init_rx_rings_cnic(bp);
  5053. bnx2x_init_tx_rings_cnic(bp);
  5054. /* flush all */
  5055. mb();
  5056. mmiowb();
  5057. }
  5058. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5059. {
  5060. int i;
  5061. for_each_eth_queue(bp, i)
  5062. bnx2x_init_eth_fp(bp, i);
  5063. /* ensure status block indices were read */
  5064. rmb();
  5065. bnx2x_init_rx_rings(bp);
  5066. bnx2x_init_tx_rings(bp);
  5067. if (IS_VF(bp)) {
  5068. bnx2x_memset_stats(bp);
  5069. return;
  5070. }
  5071. /* Initialize MOD_ABS interrupts */
  5072. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5073. bp->common.shmem_base, bp->common.shmem2_base,
  5074. BP_PORT(bp));
  5075. bnx2x_init_def_sb(bp);
  5076. bnx2x_update_dsb_idx(bp);
  5077. bnx2x_init_sp_ring(bp);
  5078. bnx2x_init_eq_ring(bp);
  5079. bnx2x_init_internal(bp, load_code);
  5080. bnx2x_pf_init(bp);
  5081. bnx2x_stats_init(bp);
  5082. /* flush all before enabling interrupts */
  5083. mb();
  5084. mmiowb();
  5085. bnx2x_int_enable(bp);
  5086. /* Check for SPIO5 */
  5087. bnx2x_attn_int_deasserted0(bp,
  5088. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5089. AEU_INPUTS_ATTN_BITS_SPIO5);
  5090. }
  5091. /* end of nic init */
  5092. /*
  5093. * gzip service functions
  5094. */
  5095. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5096. {
  5097. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5098. &bp->gunzip_mapping, GFP_KERNEL);
  5099. if (bp->gunzip_buf == NULL)
  5100. goto gunzip_nomem1;
  5101. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5102. if (bp->strm == NULL)
  5103. goto gunzip_nomem2;
  5104. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5105. if (bp->strm->workspace == NULL)
  5106. goto gunzip_nomem3;
  5107. return 0;
  5108. gunzip_nomem3:
  5109. kfree(bp->strm);
  5110. bp->strm = NULL;
  5111. gunzip_nomem2:
  5112. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5113. bp->gunzip_mapping);
  5114. bp->gunzip_buf = NULL;
  5115. gunzip_nomem1:
  5116. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5117. return -ENOMEM;
  5118. }
  5119. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5120. {
  5121. if (bp->strm) {
  5122. vfree(bp->strm->workspace);
  5123. kfree(bp->strm);
  5124. bp->strm = NULL;
  5125. }
  5126. if (bp->gunzip_buf) {
  5127. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5128. bp->gunzip_mapping);
  5129. bp->gunzip_buf = NULL;
  5130. }
  5131. }
  5132. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5133. {
  5134. int n, rc;
  5135. /* check gzip header */
  5136. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5137. BNX2X_ERR("Bad gzip header\n");
  5138. return -EINVAL;
  5139. }
  5140. n = 10;
  5141. #define FNAME 0x8
  5142. if (zbuf[3] & FNAME)
  5143. while ((zbuf[n++] != 0) && (n < len));
  5144. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5145. bp->strm->avail_in = len - n;
  5146. bp->strm->next_out = bp->gunzip_buf;
  5147. bp->strm->avail_out = FW_BUF_SIZE;
  5148. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5149. if (rc != Z_OK)
  5150. return rc;
  5151. rc = zlib_inflate(bp->strm, Z_FINISH);
  5152. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5153. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5154. bp->strm->msg);
  5155. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5156. if (bp->gunzip_outlen & 0x3)
  5157. netdev_err(bp->dev,
  5158. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5159. bp->gunzip_outlen);
  5160. bp->gunzip_outlen >>= 2;
  5161. zlib_inflateEnd(bp->strm);
  5162. if (rc == Z_STREAM_END)
  5163. return 0;
  5164. return rc;
  5165. }
  5166. /* nic load/unload */
  5167. /*
  5168. * General service functions
  5169. */
  5170. /* send a NIG loopback debug packet */
  5171. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5172. {
  5173. u32 wb_write[3];
  5174. /* Ethernet source and destination addresses */
  5175. wb_write[0] = 0x55555555;
  5176. wb_write[1] = 0x55555555;
  5177. wb_write[2] = 0x20; /* SOP */
  5178. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5179. /* NON-IP protocol */
  5180. wb_write[0] = 0x09000000;
  5181. wb_write[1] = 0x55555555;
  5182. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5183. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5184. }
  5185. /* some of the internal memories
  5186. * are not directly readable from the driver
  5187. * to test them we send debug packets
  5188. */
  5189. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5190. {
  5191. int factor;
  5192. int count, i;
  5193. u32 val = 0;
  5194. if (CHIP_REV_IS_FPGA(bp))
  5195. factor = 120;
  5196. else if (CHIP_REV_IS_EMUL(bp))
  5197. factor = 200;
  5198. else
  5199. factor = 1;
  5200. /* Disable inputs of parser neighbor blocks */
  5201. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5202. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5203. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5204. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5205. /* Write 0 to parser credits for CFC search request */
  5206. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5207. /* send Ethernet packet */
  5208. bnx2x_lb_pckt(bp);
  5209. /* TODO do i reset NIG statistic? */
  5210. /* Wait until NIG register shows 1 packet of size 0x10 */
  5211. count = 1000 * factor;
  5212. while (count) {
  5213. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5214. val = *bnx2x_sp(bp, wb_data[0]);
  5215. if (val == 0x10)
  5216. break;
  5217. msleep(10);
  5218. count--;
  5219. }
  5220. if (val != 0x10) {
  5221. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5222. return -1;
  5223. }
  5224. /* Wait until PRS register shows 1 packet */
  5225. count = 1000 * factor;
  5226. while (count) {
  5227. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5228. if (val == 1)
  5229. break;
  5230. msleep(10);
  5231. count--;
  5232. }
  5233. if (val != 0x1) {
  5234. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5235. return -2;
  5236. }
  5237. /* Reset and init BRB, PRS */
  5238. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5239. msleep(50);
  5240. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5241. msleep(50);
  5242. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5243. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5244. DP(NETIF_MSG_HW, "part2\n");
  5245. /* Disable inputs of parser neighbor blocks */
  5246. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5247. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5248. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5249. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5250. /* Write 0 to parser credits for CFC search request */
  5251. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5252. /* send 10 Ethernet packets */
  5253. for (i = 0; i < 10; i++)
  5254. bnx2x_lb_pckt(bp);
  5255. /* Wait until NIG register shows 10 + 1
  5256. packets of size 11*0x10 = 0xb0 */
  5257. count = 1000 * factor;
  5258. while (count) {
  5259. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5260. val = *bnx2x_sp(bp, wb_data[0]);
  5261. if (val == 0xb0)
  5262. break;
  5263. msleep(10);
  5264. count--;
  5265. }
  5266. if (val != 0xb0) {
  5267. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5268. return -3;
  5269. }
  5270. /* Wait until PRS register shows 2 packets */
  5271. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5272. if (val != 2)
  5273. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5274. /* Write 1 to parser credits for CFC search request */
  5275. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5276. /* Wait until PRS register shows 3 packets */
  5277. msleep(10 * factor);
  5278. /* Wait until NIG register shows 1 packet of size 0x10 */
  5279. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5280. if (val != 3)
  5281. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5282. /* clear NIG EOP FIFO */
  5283. for (i = 0; i < 11; i++)
  5284. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5285. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5286. if (val != 1) {
  5287. BNX2X_ERR("clear of NIG failed\n");
  5288. return -4;
  5289. }
  5290. /* Reset and init BRB, PRS, NIG */
  5291. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5292. msleep(50);
  5293. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5294. msleep(50);
  5295. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5296. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5297. if (!CNIC_SUPPORT(bp))
  5298. /* set NIC mode */
  5299. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5300. /* Enable inputs of parser neighbor blocks */
  5301. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5302. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5303. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5304. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5305. DP(NETIF_MSG_HW, "done\n");
  5306. return 0; /* OK */
  5307. }
  5308. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5309. {
  5310. u32 val;
  5311. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5312. if (!CHIP_IS_E1x(bp))
  5313. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5314. else
  5315. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5316. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5317. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5318. /*
  5319. * mask read length error interrupts in brb for parser
  5320. * (parsing unit and 'checksum and crc' unit)
  5321. * these errors are legal (PU reads fixed length and CAC can cause
  5322. * read length error on truncated packets)
  5323. */
  5324. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5325. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5326. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5327. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5328. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5329. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5330. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5331. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5332. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5333. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5334. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5335. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5336. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5337. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5338. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5339. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5340. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5341. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5342. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5343. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5344. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5345. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5346. if (!CHIP_IS_E1x(bp))
  5347. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5348. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5349. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5350. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5351. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5352. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5353. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5354. if (!CHIP_IS_E1x(bp))
  5355. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5356. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5357. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5358. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5359. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5360. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5361. }
  5362. static void bnx2x_reset_common(struct bnx2x *bp)
  5363. {
  5364. u32 val = 0x1400;
  5365. /* reset_common */
  5366. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5367. 0xd3ffff7f);
  5368. if (CHIP_IS_E3(bp)) {
  5369. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5370. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5371. }
  5372. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5373. }
  5374. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5375. {
  5376. bp->dmae_ready = 0;
  5377. spin_lock_init(&bp->dmae_lock);
  5378. }
  5379. static void bnx2x_init_pxp(struct bnx2x *bp)
  5380. {
  5381. u16 devctl;
  5382. int r_order, w_order;
  5383. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5384. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5385. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5386. if (bp->mrrs == -1)
  5387. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5388. else {
  5389. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5390. r_order = bp->mrrs;
  5391. }
  5392. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5393. }
  5394. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5395. {
  5396. int is_required;
  5397. u32 val;
  5398. int port;
  5399. if (BP_NOMCP(bp))
  5400. return;
  5401. is_required = 0;
  5402. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5403. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5404. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5405. is_required = 1;
  5406. /*
  5407. * The fan failure mechanism is usually related to the PHY type since
  5408. * the power consumption of the board is affected by the PHY. Currently,
  5409. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5410. */
  5411. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5412. for (port = PORT_0; port < PORT_MAX; port++) {
  5413. is_required |=
  5414. bnx2x_fan_failure_det_req(
  5415. bp,
  5416. bp->common.shmem_base,
  5417. bp->common.shmem2_base,
  5418. port);
  5419. }
  5420. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5421. if (is_required == 0)
  5422. return;
  5423. /* Fan failure is indicated by SPIO 5 */
  5424. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5425. /* set to active low mode */
  5426. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5427. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5428. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5429. /* enable interrupt to signal the IGU */
  5430. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5431. val |= MISC_SPIO_SPIO5;
  5432. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5433. }
  5434. void bnx2x_pf_disable(struct bnx2x *bp)
  5435. {
  5436. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5437. val &= ~IGU_PF_CONF_FUNC_EN;
  5438. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5439. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5440. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5441. }
  5442. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5443. {
  5444. u32 shmem_base[2], shmem2_base[2];
  5445. /* Avoid common init in case MFW supports LFA */
  5446. if (SHMEM2_RD(bp, size) >
  5447. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5448. return;
  5449. shmem_base[0] = bp->common.shmem_base;
  5450. shmem2_base[0] = bp->common.shmem2_base;
  5451. if (!CHIP_IS_E1x(bp)) {
  5452. shmem_base[1] =
  5453. SHMEM2_RD(bp, other_shmem_base_addr);
  5454. shmem2_base[1] =
  5455. SHMEM2_RD(bp, other_shmem2_base_addr);
  5456. }
  5457. bnx2x_acquire_phy_lock(bp);
  5458. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5459. bp->common.chip_id);
  5460. bnx2x_release_phy_lock(bp);
  5461. }
  5462. /**
  5463. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5464. *
  5465. * @bp: driver handle
  5466. */
  5467. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5468. {
  5469. u32 val;
  5470. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5471. /*
  5472. * take the RESET lock to protect undi_unload flow from accessing
  5473. * registers while we're resetting the chip
  5474. */
  5475. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5476. bnx2x_reset_common(bp);
  5477. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5478. val = 0xfffc;
  5479. if (CHIP_IS_E3(bp)) {
  5480. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5481. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5482. }
  5483. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5484. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5485. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5486. if (!CHIP_IS_E1x(bp)) {
  5487. u8 abs_func_id;
  5488. /**
  5489. * 4-port mode or 2-port mode we need to turn of master-enable
  5490. * for everyone, after that, turn it back on for self.
  5491. * so, we disregard multi-function or not, and always disable
  5492. * for all functions on the given path, this means 0,2,4,6 for
  5493. * path 0 and 1,3,5,7 for path 1
  5494. */
  5495. for (abs_func_id = BP_PATH(bp);
  5496. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5497. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5498. REG_WR(bp,
  5499. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5500. 1);
  5501. continue;
  5502. }
  5503. bnx2x_pretend_func(bp, abs_func_id);
  5504. /* clear pf enable */
  5505. bnx2x_pf_disable(bp);
  5506. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5507. }
  5508. }
  5509. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5510. if (CHIP_IS_E1(bp)) {
  5511. /* enable HW interrupt from PXP on USDM overflow
  5512. bit 16 on INT_MASK_0 */
  5513. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5514. }
  5515. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5516. bnx2x_init_pxp(bp);
  5517. #ifdef __BIG_ENDIAN
  5518. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5519. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5520. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5521. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5522. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5523. /* make sure this value is 0 */
  5524. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5525. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5526. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5527. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5528. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5529. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5530. #endif
  5531. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5532. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5533. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5534. /* let the HW do it's magic ... */
  5535. msleep(100);
  5536. /* finish PXP init */
  5537. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5538. if (val != 1) {
  5539. BNX2X_ERR("PXP2 CFG failed\n");
  5540. return -EBUSY;
  5541. }
  5542. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5543. if (val != 1) {
  5544. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5545. return -EBUSY;
  5546. }
  5547. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5548. * have entries with value "0" and valid bit on.
  5549. * This needs to be done by the first PF that is loaded in a path
  5550. * (i.e. common phase)
  5551. */
  5552. if (!CHIP_IS_E1x(bp)) {
  5553. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5554. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5555. * This occurs when a different function (func2,3) is being marked
  5556. * as "scan-off". Real-life scenario for example: if a driver is being
  5557. * load-unloaded while func6,7 are down. This will cause the timer to access
  5558. * the ilt, translate to a logical address and send a request to read/write.
  5559. * Since the ilt for the function that is down is not valid, this will cause
  5560. * a translation error which is unrecoverable.
  5561. * The Workaround is intended to make sure that when this happens nothing fatal
  5562. * will occur. The workaround:
  5563. * 1. First PF driver which loads on a path will:
  5564. * a. After taking the chip out of reset, by using pretend,
  5565. * it will write "0" to the following registers of
  5566. * the other vnics.
  5567. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5568. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5569. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5570. * And for itself it will write '1' to
  5571. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5572. * dmae-operations (writing to pram for example.)
  5573. * note: can be done for only function 6,7 but cleaner this
  5574. * way.
  5575. * b. Write zero+valid to the entire ILT.
  5576. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5577. * VNIC3 (of that port). The range allocated will be the
  5578. * entire ILT. This is needed to prevent ILT range error.
  5579. * 2. Any PF driver load flow:
  5580. * a. ILT update with the physical addresses of the allocated
  5581. * logical pages.
  5582. * b. Wait 20msec. - note that this timeout is needed to make
  5583. * sure there are no requests in one of the PXP internal
  5584. * queues with "old" ILT addresses.
  5585. * c. PF enable in the PGLC.
  5586. * d. Clear the was_error of the PF in the PGLC. (could have
  5587. * occurred while driver was down)
  5588. * e. PF enable in the CFC (WEAK + STRONG)
  5589. * f. Timers scan enable
  5590. * 3. PF driver unload flow:
  5591. * a. Clear the Timers scan_en.
  5592. * b. Polling for scan_on=0 for that PF.
  5593. * c. Clear the PF enable bit in the PXP.
  5594. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5595. * e. Write zero+valid to all ILT entries (The valid bit must
  5596. * stay set)
  5597. * f. If this is VNIC 3 of a port then also init
  5598. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5599. * to the last enrty in the ILT.
  5600. *
  5601. * Notes:
  5602. * Currently the PF error in the PGLC is non recoverable.
  5603. * In the future the there will be a recovery routine for this error.
  5604. * Currently attention is masked.
  5605. * Having an MCP lock on the load/unload process does not guarantee that
  5606. * there is no Timer disable during Func6/7 enable. This is because the
  5607. * Timers scan is currently being cleared by the MCP on FLR.
  5608. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5609. * there is error before clearing it. But the flow above is simpler and
  5610. * more general.
  5611. * All ILT entries are written by zero+valid and not just PF6/7
  5612. * ILT entries since in the future the ILT entries allocation for
  5613. * PF-s might be dynamic.
  5614. */
  5615. struct ilt_client_info ilt_cli;
  5616. struct bnx2x_ilt ilt;
  5617. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5618. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5619. /* initialize dummy TM client */
  5620. ilt_cli.start = 0;
  5621. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5622. ilt_cli.client_num = ILT_CLIENT_TM;
  5623. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5624. * Step 2: set the timers first/last ilt entry to point
  5625. * to the entire range to prevent ILT range error for 3rd/4th
  5626. * vnic (this code assumes existence of the vnic)
  5627. *
  5628. * both steps performed by call to bnx2x_ilt_client_init_op()
  5629. * with dummy TM client
  5630. *
  5631. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5632. * and his brother are split registers
  5633. */
  5634. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5635. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5636. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5637. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5638. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5639. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5640. }
  5641. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5642. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5643. if (!CHIP_IS_E1x(bp)) {
  5644. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5645. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5646. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5647. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5648. /* let the HW do it's magic ... */
  5649. do {
  5650. msleep(200);
  5651. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5652. } while (factor-- && (val != 1));
  5653. if (val != 1) {
  5654. BNX2X_ERR("ATC_INIT failed\n");
  5655. return -EBUSY;
  5656. }
  5657. }
  5658. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5659. bnx2x_iov_init_dmae(bp);
  5660. /* clean the DMAE memory */
  5661. bp->dmae_ready = 1;
  5662. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5663. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5664. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5665. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5666. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5667. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5668. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5669. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5670. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5671. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5672. /* QM queues pointers table */
  5673. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5674. /* soft reset pulse */
  5675. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5676. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5677. if (CNIC_SUPPORT(bp))
  5678. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5679. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5680. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5681. if (!CHIP_REV_IS_SLOW(bp))
  5682. /* enable hw interrupt from doorbell Q */
  5683. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5684. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5685. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5686. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5687. if (!CHIP_IS_E1(bp))
  5688. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5689. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5690. if (IS_MF_AFEX(bp)) {
  5691. /* configure that VNTag and VLAN headers must be
  5692. * received in afex mode
  5693. */
  5694. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5695. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5696. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5697. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5698. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5699. } else {
  5700. /* Bit-map indicating which L2 hdrs may appear
  5701. * after the basic Ethernet header
  5702. */
  5703. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5704. bp->path_has_ovlan ? 7 : 6);
  5705. }
  5706. }
  5707. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5708. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5709. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5710. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5711. if (!CHIP_IS_E1x(bp)) {
  5712. /* reset VFC memories */
  5713. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5714. VFC_MEMORIES_RST_REG_CAM_RST |
  5715. VFC_MEMORIES_RST_REG_RAM_RST);
  5716. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5717. VFC_MEMORIES_RST_REG_CAM_RST |
  5718. VFC_MEMORIES_RST_REG_RAM_RST);
  5719. msleep(20);
  5720. }
  5721. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5722. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5723. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5724. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5725. /* sync semi rtc */
  5726. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5727. 0x80000000);
  5728. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5729. 0x80000000);
  5730. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5731. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5732. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5733. if (!CHIP_IS_E1x(bp)) {
  5734. if (IS_MF_AFEX(bp)) {
  5735. /* configure that VNTag and VLAN headers must be
  5736. * sent in afex mode
  5737. */
  5738. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5739. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5740. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5741. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5742. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5743. } else {
  5744. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5745. bp->path_has_ovlan ? 7 : 6);
  5746. }
  5747. }
  5748. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5749. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5750. if (CNIC_SUPPORT(bp)) {
  5751. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5752. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5753. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5754. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5755. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5756. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5757. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5758. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5759. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5760. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5761. }
  5762. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5763. if (sizeof(union cdu_context) != 1024)
  5764. /* we currently assume that a context is 1024 bytes */
  5765. dev_alert(&bp->pdev->dev,
  5766. "please adjust the size of cdu_context(%ld)\n",
  5767. (long)sizeof(union cdu_context));
  5768. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5769. val = (4 << 24) + (0 << 12) + 1024;
  5770. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5771. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5772. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5773. /* enable context validation interrupt from CFC */
  5774. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5775. /* set the thresholds to prevent CFC/CDU race */
  5776. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5777. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5778. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5779. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5780. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5781. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5782. /* Reset PCIE errors for debug */
  5783. REG_WR(bp, 0x2814, 0xffffffff);
  5784. REG_WR(bp, 0x3820, 0xffffffff);
  5785. if (!CHIP_IS_E1x(bp)) {
  5786. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5787. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5788. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5789. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5790. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5791. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5792. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5793. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5794. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5795. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5796. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5797. }
  5798. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5799. if (!CHIP_IS_E1(bp)) {
  5800. /* in E3 this done in per-port section */
  5801. if (!CHIP_IS_E3(bp))
  5802. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5803. }
  5804. if (CHIP_IS_E1H(bp))
  5805. /* not applicable for E2 (and above ...) */
  5806. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5807. if (CHIP_REV_IS_SLOW(bp))
  5808. msleep(200);
  5809. /* finish CFC init */
  5810. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5811. if (val != 1) {
  5812. BNX2X_ERR("CFC LL_INIT failed\n");
  5813. return -EBUSY;
  5814. }
  5815. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5816. if (val != 1) {
  5817. BNX2X_ERR("CFC AC_INIT failed\n");
  5818. return -EBUSY;
  5819. }
  5820. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5821. if (val != 1) {
  5822. BNX2X_ERR("CFC CAM_INIT failed\n");
  5823. return -EBUSY;
  5824. }
  5825. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5826. if (CHIP_IS_E1(bp)) {
  5827. /* read NIG statistic
  5828. to see if this is our first up since powerup */
  5829. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5830. val = *bnx2x_sp(bp, wb_data[0]);
  5831. /* do internal memory self test */
  5832. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5833. BNX2X_ERR("internal mem self test failed\n");
  5834. return -EBUSY;
  5835. }
  5836. }
  5837. bnx2x_setup_fan_failure_detection(bp);
  5838. /* clear PXP2 attentions */
  5839. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5840. bnx2x_enable_blocks_attention(bp);
  5841. bnx2x_enable_blocks_parity(bp);
  5842. if (!BP_NOMCP(bp)) {
  5843. if (CHIP_IS_E1x(bp))
  5844. bnx2x__common_init_phy(bp);
  5845. } else
  5846. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5847. return 0;
  5848. }
  5849. /**
  5850. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5851. *
  5852. * @bp: driver handle
  5853. */
  5854. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5855. {
  5856. int rc = bnx2x_init_hw_common(bp);
  5857. if (rc)
  5858. return rc;
  5859. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5860. if (!BP_NOMCP(bp))
  5861. bnx2x__common_init_phy(bp);
  5862. return 0;
  5863. }
  5864. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5865. {
  5866. int port = BP_PORT(bp);
  5867. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5868. u32 low, high;
  5869. u32 val;
  5870. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5871. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5872. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5873. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5874. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5875. /* Timers bug workaround: disables the pf_master bit in pglue at
  5876. * common phase, we need to enable it here before any dmae access are
  5877. * attempted. Therefore we manually added the enable-master to the
  5878. * port phase (it also happens in the function phase)
  5879. */
  5880. if (!CHIP_IS_E1x(bp))
  5881. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5882. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5883. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5884. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5885. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5886. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5887. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5888. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5889. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5890. /* QM cid (connection) count */
  5891. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5892. if (CNIC_SUPPORT(bp)) {
  5893. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5894. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5895. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5896. }
  5897. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5898. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5899. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5900. if (IS_MF(bp))
  5901. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5902. else if (bp->dev->mtu > 4096) {
  5903. if (bp->flags & ONE_PORT_FLAG)
  5904. low = 160;
  5905. else {
  5906. val = bp->dev->mtu;
  5907. /* (24*1024 + val*4)/256 */
  5908. low = 96 + (val/64) +
  5909. ((val % 64) ? 1 : 0);
  5910. }
  5911. } else
  5912. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5913. high = low + 56; /* 14*1024/256 */
  5914. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5915. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5916. }
  5917. if (CHIP_MODE_IS_4_PORT(bp))
  5918. REG_WR(bp, (BP_PORT(bp) ?
  5919. BRB1_REG_MAC_GUARANTIED_1 :
  5920. BRB1_REG_MAC_GUARANTIED_0), 40);
  5921. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5922. if (CHIP_IS_E3B0(bp)) {
  5923. if (IS_MF_AFEX(bp)) {
  5924. /* configure headers for AFEX mode */
  5925. REG_WR(bp, BP_PORT(bp) ?
  5926. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5927. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5928. REG_WR(bp, BP_PORT(bp) ?
  5929. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5930. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5931. REG_WR(bp, BP_PORT(bp) ?
  5932. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5933. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5934. } else {
  5935. /* Ovlan exists only if we are in multi-function +
  5936. * switch-dependent mode, in switch-independent there
  5937. * is no ovlan headers
  5938. */
  5939. REG_WR(bp, BP_PORT(bp) ?
  5940. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5941. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5942. (bp->path_has_ovlan ? 7 : 6));
  5943. }
  5944. }
  5945. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5946. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5947. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5948. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5949. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5950. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5951. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5952. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5953. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5954. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5955. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5956. if (CHIP_IS_E1x(bp)) {
  5957. /* configure PBF to work without PAUSE mtu 9000 */
  5958. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5959. /* update threshold */
  5960. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5961. /* update init credit */
  5962. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5963. /* probe changes */
  5964. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5965. udelay(50);
  5966. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5967. }
  5968. if (CNIC_SUPPORT(bp))
  5969. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5970. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5971. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5972. if (CHIP_IS_E1(bp)) {
  5973. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5974. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5975. }
  5976. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5977. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5978. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5979. /* init aeu_mask_attn_func_0/1:
  5980. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5981. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5982. * bits 4-7 are used for "per vn group attention" */
  5983. val = IS_MF(bp) ? 0xF7 : 0x7;
  5984. /* Enable DCBX attention for all but E1 */
  5985. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5986. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5987. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5988. if (!CHIP_IS_E1x(bp)) {
  5989. /* Bit-map indicating which L2 hdrs may appear after the
  5990. * basic Ethernet header
  5991. */
  5992. if (IS_MF_AFEX(bp))
  5993. REG_WR(bp, BP_PORT(bp) ?
  5994. NIG_REG_P1_HDRS_AFTER_BASIC :
  5995. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5996. else
  5997. REG_WR(bp, BP_PORT(bp) ?
  5998. NIG_REG_P1_HDRS_AFTER_BASIC :
  5999. NIG_REG_P0_HDRS_AFTER_BASIC,
  6000. IS_MF_SD(bp) ? 7 : 6);
  6001. if (CHIP_IS_E3(bp))
  6002. REG_WR(bp, BP_PORT(bp) ?
  6003. NIG_REG_LLH1_MF_MODE :
  6004. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6005. }
  6006. if (!CHIP_IS_E3(bp))
  6007. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6008. if (!CHIP_IS_E1(bp)) {
  6009. /* 0x2 disable mf_ov, 0x1 enable */
  6010. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6011. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6012. if (!CHIP_IS_E1x(bp)) {
  6013. val = 0;
  6014. switch (bp->mf_mode) {
  6015. case MULTI_FUNCTION_SD:
  6016. val = 1;
  6017. break;
  6018. case MULTI_FUNCTION_SI:
  6019. case MULTI_FUNCTION_AFEX:
  6020. val = 2;
  6021. break;
  6022. }
  6023. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6024. NIG_REG_LLH0_CLS_TYPE), val);
  6025. }
  6026. {
  6027. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6028. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6029. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6030. }
  6031. }
  6032. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6033. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6034. if (val & MISC_SPIO_SPIO5) {
  6035. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6036. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6037. val = REG_RD(bp, reg_addr);
  6038. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6039. REG_WR(bp, reg_addr, val);
  6040. }
  6041. return 0;
  6042. }
  6043. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6044. {
  6045. int reg;
  6046. u32 wb_write[2];
  6047. if (CHIP_IS_E1(bp))
  6048. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6049. else
  6050. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6051. wb_write[0] = ONCHIP_ADDR1(addr);
  6052. wb_write[1] = ONCHIP_ADDR2(addr);
  6053. REG_WR_DMAE(bp, reg, wb_write, 2);
  6054. }
  6055. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6056. {
  6057. u32 data, ctl, cnt = 100;
  6058. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6059. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6060. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6061. u32 sb_bit = 1 << (idu_sb_id%32);
  6062. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6063. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6064. /* Not supported in BC mode */
  6065. if (CHIP_INT_MODE_IS_BC(bp))
  6066. return;
  6067. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6068. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6069. IGU_REGULAR_CLEANUP_SET |
  6070. IGU_REGULAR_BCLEANUP;
  6071. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6072. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6073. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6074. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6075. data, igu_addr_data);
  6076. REG_WR(bp, igu_addr_data, data);
  6077. mmiowb();
  6078. barrier();
  6079. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6080. ctl, igu_addr_ctl);
  6081. REG_WR(bp, igu_addr_ctl, ctl);
  6082. mmiowb();
  6083. barrier();
  6084. /* wait for clean up to finish */
  6085. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6086. msleep(20);
  6087. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6088. DP(NETIF_MSG_HW,
  6089. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6090. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6091. }
  6092. }
  6093. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6094. {
  6095. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6096. }
  6097. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6098. {
  6099. u32 i, base = FUNC_ILT_BASE(func);
  6100. for (i = base; i < base + ILT_PER_FUNC; i++)
  6101. bnx2x_ilt_wr(bp, i, 0);
  6102. }
  6103. static void bnx2x_init_searcher(struct bnx2x *bp)
  6104. {
  6105. int port = BP_PORT(bp);
  6106. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6107. /* T1 hash bits value determines the T1 number of entries */
  6108. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6109. }
  6110. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6111. {
  6112. int rc;
  6113. struct bnx2x_func_state_params func_params = {NULL};
  6114. struct bnx2x_func_switch_update_params *switch_update_params =
  6115. &func_params.params.switch_update;
  6116. /* Prepare parameters for function state transitions */
  6117. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6118. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6119. func_params.f_obj = &bp->func_obj;
  6120. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6121. /* Function parameters */
  6122. switch_update_params->suspend = suspend;
  6123. rc = bnx2x_func_state_change(bp, &func_params);
  6124. return rc;
  6125. }
  6126. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6127. {
  6128. int rc, i, port = BP_PORT(bp);
  6129. int vlan_en = 0, mac_en[NUM_MACS];
  6130. /* Close input from network */
  6131. if (bp->mf_mode == SINGLE_FUNCTION) {
  6132. bnx2x_set_rx_filter(&bp->link_params, 0);
  6133. } else {
  6134. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6135. NIG_REG_LLH0_FUNC_EN);
  6136. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6137. NIG_REG_LLH0_FUNC_EN, 0);
  6138. for (i = 0; i < NUM_MACS; i++) {
  6139. mac_en[i] = REG_RD(bp, port ?
  6140. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6141. 4 * i) :
  6142. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6143. 4 * i));
  6144. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6145. 4 * i) :
  6146. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6147. }
  6148. }
  6149. /* Close BMC to host */
  6150. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6151. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6152. /* Suspend Tx switching to the PF. Completion of this ramrod
  6153. * further guarantees that all the packets of that PF / child
  6154. * VFs in BRB were processed by the Parser, so it is safe to
  6155. * change the NIC_MODE register.
  6156. */
  6157. rc = bnx2x_func_switch_update(bp, 1);
  6158. if (rc) {
  6159. BNX2X_ERR("Can't suspend tx-switching!\n");
  6160. return rc;
  6161. }
  6162. /* Change NIC_MODE register */
  6163. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6164. /* Open input from network */
  6165. if (bp->mf_mode == SINGLE_FUNCTION) {
  6166. bnx2x_set_rx_filter(&bp->link_params, 1);
  6167. } else {
  6168. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6169. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6170. for (i = 0; i < NUM_MACS; i++) {
  6171. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6172. 4 * i) :
  6173. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6174. mac_en[i]);
  6175. }
  6176. }
  6177. /* Enable BMC to host */
  6178. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6179. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6180. /* Resume Tx switching to the PF */
  6181. rc = bnx2x_func_switch_update(bp, 0);
  6182. if (rc) {
  6183. BNX2X_ERR("Can't resume tx-switching!\n");
  6184. return rc;
  6185. }
  6186. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6187. return 0;
  6188. }
  6189. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6190. {
  6191. int rc;
  6192. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6193. if (CONFIGURE_NIC_MODE(bp)) {
  6194. /* Configrue searcher as part of function hw init */
  6195. bnx2x_init_searcher(bp);
  6196. /* Reset NIC mode */
  6197. rc = bnx2x_reset_nic_mode(bp);
  6198. if (rc)
  6199. BNX2X_ERR("Can't change NIC mode!\n");
  6200. return rc;
  6201. }
  6202. return 0;
  6203. }
  6204. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6205. {
  6206. int port = BP_PORT(bp);
  6207. int func = BP_FUNC(bp);
  6208. int init_phase = PHASE_PF0 + func;
  6209. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6210. u16 cdu_ilt_start;
  6211. u32 addr, val;
  6212. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6213. int i, main_mem_width, rc;
  6214. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6215. /* FLR cleanup - hmmm */
  6216. if (!CHIP_IS_E1x(bp)) {
  6217. rc = bnx2x_pf_flr_clnup(bp);
  6218. if (rc) {
  6219. bnx2x_fw_dump(bp);
  6220. return rc;
  6221. }
  6222. }
  6223. /* set MSI reconfigure capability */
  6224. if (bp->common.int_block == INT_BLOCK_HC) {
  6225. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6226. val = REG_RD(bp, addr);
  6227. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6228. REG_WR(bp, addr, val);
  6229. }
  6230. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6231. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6232. ilt = BP_ILT(bp);
  6233. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6234. if (IS_SRIOV(bp))
  6235. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6236. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6237. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6238. * those of the VFs, so start line should be reset
  6239. */
  6240. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6241. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6242. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6243. ilt->lines[cdu_ilt_start + i].page_mapping =
  6244. bp->context[i].cxt_mapping;
  6245. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6246. }
  6247. bnx2x_ilt_init_op(bp, INITOP_SET);
  6248. if (!CONFIGURE_NIC_MODE(bp)) {
  6249. bnx2x_init_searcher(bp);
  6250. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6251. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6252. } else {
  6253. /* Set NIC mode */
  6254. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6255. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6256. }
  6257. if (!CHIP_IS_E1x(bp)) {
  6258. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6259. /* Turn on a single ISR mode in IGU if driver is going to use
  6260. * INT#x or MSI
  6261. */
  6262. if (!(bp->flags & USING_MSIX_FLAG))
  6263. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6264. /*
  6265. * Timers workaround bug: function init part.
  6266. * Need to wait 20msec after initializing ILT,
  6267. * needed to make sure there are no requests in
  6268. * one of the PXP internal queues with "old" ILT addresses
  6269. */
  6270. msleep(20);
  6271. /*
  6272. * Master enable - Due to WB DMAE writes performed before this
  6273. * register is re-initialized as part of the regular function
  6274. * init
  6275. */
  6276. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6277. /* Enable the function in IGU */
  6278. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6279. }
  6280. bp->dmae_ready = 1;
  6281. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6282. if (!CHIP_IS_E1x(bp))
  6283. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6284. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6285. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6286. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6287. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6288. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6289. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6290. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6291. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6292. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6293. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6294. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6295. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6296. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6297. if (!CHIP_IS_E1x(bp))
  6298. REG_WR(bp, QM_REG_PF_EN, 1);
  6299. if (!CHIP_IS_E1x(bp)) {
  6300. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6301. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6302. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6303. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6304. }
  6305. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6306. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6307. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6308. bnx2x_iov_init_dq(bp);
  6309. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6310. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6312. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6313. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6314. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6315. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6316. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6317. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6318. if (!CHIP_IS_E1x(bp))
  6319. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6320. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6321. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6322. if (!CHIP_IS_E1x(bp))
  6323. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6324. if (IS_MF(bp)) {
  6325. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6326. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6327. }
  6328. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6329. /* HC init per function */
  6330. if (bp->common.int_block == INT_BLOCK_HC) {
  6331. if (CHIP_IS_E1H(bp)) {
  6332. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6333. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6334. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6335. }
  6336. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6337. } else {
  6338. int num_segs, sb_idx, prod_offset;
  6339. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6340. if (!CHIP_IS_E1x(bp)) {
  6341. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6342. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6343. }
  6344. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6345. if (!CHIP_IS_E1x(bp)) {
  6346. int dsb_idx = 0;
  6347. /**
  6348. * Producer memory:
  6349. * E2 mode: address 0-135 match to the mapping memory;
  6350. * 136 - PF0 default prod; 137 - PF1 default prod;
  6351. * 138 - PF2 default prod; 139 - PF3 default prod;
  6352. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6353. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6354. * 144-147 reserved.
  6355. *
  6356. * E1.5 mode - In backward compatible mode;
  6357. * for non default SB; each even line in the memory
  6358. * holds the U producer and each odd line hold
  6359. * the C producer. The first 128 producers are for
  6360. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6361. * producers are for the DSB for each PF.
  6362. * Each PF has five segments: (the order inside each
  6363. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6364. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6365. * 144-147 attn prods;
  6366. */
  6367. /* non-default-status-blocks */
  6368. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6369. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6370. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6371. prod_offset = (bp->igu_base_sb + sb_idx) *
  6372. num_segs;
  6373. for (i = 0; i < num_segs; i++) {
  6374. addr = IGU_REG_PROD_CONS_MEMORY +
  6375. (prod_offset + i) * 4;
  6376. REG_WR(bp, addr, 0);
  6377. }
  6378. /* send consumer update with value 0 */
  6379. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6380. USTORM_ID, 0, IGU_INT_NOP, 1);
  6381. bnx2x_igu_clear_sb(bp,
  6382. bp->igu_base_sb + sb_idx);
  6383. }
  6384. /* default-status-blocks */
  6385. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6386. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6387. if (CHIP_MODE_IS_4_PORT(bp))
  6388. dsb_idx = BP_FUNC(bp);
  6389. else
  6390. dsb_idx = BP_VN(bp);
  6391. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6392. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6393. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6394. /*
  6395. * igu prods come in chunks of E1HVN_MAX (4) -
  6396. * does not matters what is the current chip mode
  6397. */
  6398. for (i = 0; i < (num_segs * E1HVN_MAX);
  6399. i += E1HVN_MAX) {
  6400. addr = IGU_REG_PROD_CONS_MEMORY +
  6401. (prod_offset + i)*4;
  6402. REG_WR(bp, addr, 0);
  6403. }
  6404. /* send consumer update with 0 */
  6405. if (CHIP_INT_MODE_IS_BC(bp)) {
  6406. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6407. USTORM_ID, 0, IGU_INT_NOP, 1);
  6408. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6409. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6410. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6411. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6412. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6413. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6414. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6415. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6416. } else {
  6417. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6418. USTORM_ID, 0, IGU_INT_NOP, 1);
  6419. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6420. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6421. }
  6422. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6423. /* !!! these should become driver const once
  6424. rf-tool supports split-68 const */
  6425. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6426. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6427. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6428. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6429. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6430. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6431. }
  6432. }
  6433. /* Reset PCIE errors for debug */
  6434. REG_WR(bp, 0x2114, 0xffffffff);
  6435. REG_WR(bp, 0x2120, 0xffffffff);
  6436. if (CHIP_IS_E1x(bp)) {
  6437. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6438. main_mem_base = HC_REG_MAIN_MEMORY +
  6439. BP_PORT(bp) * (main_mem_size * 4);
  6440. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6441. main_mem_width = 8;
  6442. val = REG_RD(bp, main_mem_prty_clr);
  6443. if (val)
  6444. DP(NETIF_MSG_HW,
  6445. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6446. val);
  6447. /* Clear "false" parity errors in MSI-X table */
  6448. for (i = main_mem_base;
  6449. i < main_mem_base + main_mem_size * 4;
  6450. i += main_mem_width) {
  6451. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6452. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6453. i, main_mem_width / 4);
  6454. }
  6455. /* Clear HC parity attention */
  6456. REG_RD(bp, main_mem_prty_clr);
  6457. }
  6458. #ifdef BNX2X_STOP_ON_ERROR
  6459. /* Enable STORMs SP logging */
  6460. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6461. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6462. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6463. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6464. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6465. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6466. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6467. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6468. #endif
  6469. bnx2x_phy_probe(&bp->link_params);
  6470. return 0;
  6471. }
  6472. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6473. {
  6474. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6475. if (!CHIP_IS_E1x(bp))
  6476. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6477. sizeof(struct host_hc_status_block_e2));
  6478. else
  6479. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6480. sizeof(struct host_hc_status_block_e1x));
  6481. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6482. }
  6483. void bnx2x_free_mem(struct bnx2x *bp)
  6484. {
  6485. int i;
  6486. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6487. sizeof(struct host_sp_status_block));
  6488. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6489. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6490. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6491. sizeof(struct bnx2x_slowpath));
  6492. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6493. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6494. bp->context[i].size);
  6495. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6496. BNX2X_FREE(bp->ilt->lines);
  6497. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6498. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6499. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6500. bnx2x_iov_free_mem(bp);
  6501. }
  6502. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6503. {
  6504. if (!CHIP_IS_E1x(bp))
  6505. /* size = the status block + ramrod buffers */
  6506. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6507. sizeof(struct host_hc_status_block_e2));
  6508. else
  6509. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6510. &bp->cnic_sb_mapping,
  6511. sizeof(struct
  6512. host_hc_status_block_e1x));
  6513. if (CONFIGURE_NIC_MODE(bp))
  6514. /* allocate searcher T2 table, as it wan't allocated before */
  6515. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6516. /* write address to which L5 should insert its values */
  6517. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6518. &bp->slowpath->drv_info_to_mcp;
  6519. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6520. goto alloc_mem_err;
  6521. return 0;
  6522. alloc_mem_err:
  6523. bnx2x_free_mem_cnic(bp);
  6524. BNX2X_ERR("Can't allocate memory\n");
  6525. return -ENOMEM;
  6526. }
  6527. int bnx2x_alloc_mem(struct bnx2x *bp)
  6528. {
  6529. int i, allocated, context_size;
  6530. if (!CONFIGURE_NIC_MODE(bp))
  6531. /* allocate searcher T2 table */
  6532. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6533. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6534. sizeof(struct host_sp_status_block));
  6535. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6536. sizeof(struct bnx2x_slowpath));
  6537. /* Allocate memory for CDU context:
  6538. * This memory is allocated separately and not in the generic ILT
  6539. * functions because CDU differs in few aspects:
  6540. * 1. There are multiple entities allocating memory for context -
  6541. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6542. * its own ILT lines.
  6543. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6544. * for the other ILT clients), to be efficient we want to support
  6545. * allocation of sub-page-size in the last entry.
  6546. * 3. Context pointers are used by the driver to pass to FW / update
  6547. * the context (for the other ILT clients the pointers are used just to
  6548. * free the memory during unload).
  6549. */
  6550. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6551. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6552. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6553. (context_size - allocated));
  6554. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6555. &bp->context[i].cxt_mapping,
  6556. bp->context[i].size);
  6557. allocated += bp->context[i].size;
  6558. }
  6559. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6560. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6561. goto alloc_mem_err;
  6562. if (bnx2x_iov_alloc_mem(bp))
  6563. goto alloc_mem_err;
  6564. /* Slow path ring */
  6565. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6566. /* EQ */
  6567. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6568. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6569. return 0;
  6570. alloc_mem_err:
  6571. bnx2x_free_mem(bp);
  6572. BNX2X_ERR("Can't allocate memory\n");
  6573. return -ENOMEM;
  6574. }
  6575. /*
  6576. * Init service functions
  6577. */
  6578. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6579. struct bnx2x_vlan_mac_obj *obj, bool set,
  6580. int mac_type, unsigned long *ramrod_flags)
  6581. {
  6582. int rc;
  6583. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6584. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6585. /* Fill general parameters */
  6586. ramrod_param.vlan_mac_obj = obj;
  6587. ramrod_param.ramrod_flags = *ramrod_flags;
  6588. /* Fill a user request section if needed */
  6589. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6590. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6591. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6592. /* Set the command: ADD or DEL */
  6593. if (set)
  6594. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6595. else
  6596. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6597. }
  6598. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6599. if (rc == -EEXIST) {
  6600. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6601. /* do not treat adding same MAC as error */
  6602. rc = 0;
  6603. } else if (rc < 0)
  6604. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6605. return rc;
  6606. }
  6607. int bnx2x_del_all_macs(struct bnx2x *bp,
  6608. struct bnx2x_vlan_mac_obj *mac_obj,
  6609. int mac_type, bool wait_for_comp)
  6610. {
  6611. int rc;
  6612. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6613. /* Wait for completion of requested */
  6614. if (wait_for_comp)
  6615. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6616. /* Set the mac type of addresses we want to clear */
  6617. __set_bit(mac_type, &vlan_mac_flags);
  6618. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6619. if (rc < 0)
  6620. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6621. return rc;
  6622. }
  6623. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6624. {
  6625. unsigned long ramrod_flags = 0;
  6626. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6627. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6628. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6629. "Ignoring Zero MAC for STORAGE SD mode\n");
  6630. return 0;
  6631. }
  6632. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6633. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6634. /* Eth MAC is set on RSS leading client (fp[0]) */
  6635. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6636. set, BNX2X_ETH_MAC, &ramrod_flags);
  6637. }
  6638. int bnx2x_setup_leading(struct bnx2x *bp)
  6639. {
  6640. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6641. }
  6642. /**
  6643. * bnx2x_set_int_mode - configure interrupt mode
  6644. *
  6645. * @bp: driver handle
  6646. *
  6647. * In case of MSI-X it will also try to enable MSI-X.
  6648. */
  6649. int bnx2x_set_int_mode(struct bnx2x *bp)
  6650. {
  6651. int rc = 0;
  6652. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6653. return -EINVAL;
  6654. switch (int_mode) {
  6655. case BNX2X_INT_MODE_MSIX:
  6656. /* attempt to enable msix */
  6657. rc = bnx2x_enable_msix(bp);
  6658. /* msix attained */
  6659. if (!rc)
  6660. return 0;
  6661. /* vfs use only msix */
  6662. if (rc && IS_VF(bp))
  6663. return rc;
  6664. /* failed to enable multiple MSI-X */
  6665. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6666. bp->num_queues,
  6667. 1 + bp->num_cnic_queues);
  6668. /* falling through... */
  6669. case BNX2X_INT_MODE_MSI:
  6670. bnx2x_enable_msi(bp);
  6671. /* falling through... */
  6672. case BNX2X_INT_MODE_INTX:
  6673. bp->num_ethernet_queues = 1;
  6674. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6675. BNX2X_DEV_INFO("set number of queues to 1\n");
  6676. break;
  6677. default:
  6678. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6679. return -EINVAL;
  6680. }
  6681. return 0;
  6682. }
  6683. /* must be called prior to any HW initializations */
  6684. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6685. {
  6686. if (IS_SRIOV(bp))
  6687. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6688. return L2_ILT_LINES(bp);
  6689. }
  6690. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6691. {
  6692. struct ilt_client_info *ilt_client;
  6693. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6694. u16 line = 0;
  6695. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6696. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6697. /* CDU */
  6698. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6699. ilt_client->client_num = ILT_CLIENT_CDU;
  6700. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6701. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6702. ilt_client->start = line;
  6703. line += bnx2x_cid_ilt_lines(bp);
  6704. if (CNIC_SUPPORT(bp))
  6705. line += CNIC_ILT_LINES;
  6706. ilt_client->end = line - 1;
  6707. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6708. ilt_client->start,
  6709. ilt_client->end,
  6710. ilt_client->page_size,
  6711. ilt_client->flags,
  6712. ilog2(ilt_client->page_size >> 12));
  6713. /* QM */
  6714. if (QM_INIT(bp->qm_cid_count)) {
  6715. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6716. ilt_client->client_num = ILT_CLIENT_QM;
  6717. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6718. ilt_client->flags = 0;
  6719. ilt_client->start = line;
  6720. /* 4 bytes for each cid */
  6721. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6722. QM_ILT_PAGE_SZ);
  6723. ilt_client->end = line - 1;
  6724. DP(NETIF_MSG_IFUP,
  6725. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6726. ilt_client->start,
  6727. ilt_client->end,
  6728. ilt_client->page_size,
  6729. ilt_client->flags,
  6730. ilog2(ilt_client->page_size >> 12));
  6731. }
  6732. if (CNIC_SUPPORT(bp)) {
  6733. /* SRC */
  6734. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6735. ilt_client->client_num = ILT_CLIENT_SRC;
  6736. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6737. ilt_client->flags = 0;
  6738. ilt_client->start = line;
  6739. line += SRC_ILT_LINES;
  6740. ilt_client->end = line - 1;
  6741. DP(NETIF_MSG_IFUP,
  6742. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6743. ilt_client->start,
  6744. ilt_client->end,
  6745. ilt_client->page_size,
  6746. ilt_client->flags,
  6747. ilog2(ilt_client->page_size >> 12));
  6748. /* TM */
  6749. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6750. ilt_client->client_num = ILT_CLIENT_TM;
  6751. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6752. ilt_client->flags = 0;
  6753. ilt_client->start = line;
  6754. line += TM_ILT_LINES;
  6755. ilt_client->end = line - 1;
  6756. DP(NETIF_MSG_IFUP,
  6757. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6758. ilt_client->start,
  6759. ilt_client->end,
  6760. ilt_client->page_size,
  6761. ilt_client->flags,
  6762. ilog2(ilt_client->page_size >> 12));
  6763. }
  6764. BUG_ON(line > ILT_MAX_LINES);
  6765. }
  6766. /**
  6767. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6768. *
  6769. * @bp: driver handle
  6770. * @fp: pointer to fastpath
  6771. * @init_params: pointer to parameters structure
  6772. *
  6773. * parameters configured:
  6774. * - HC configuration
  6775. * - Queue's CDU context
  6776. */
  6777. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6778. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6779. {
  6780. u8 cos;
  6781. int cxt_index, cxt_offset;
  6782. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6783. if (!IS_FCOE_FP(fp)) {
  6784. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6785. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6786. /* If HC is supporterd, enable host coalescing in the transition
  6787. * to INIT state.
  6788. */
  6789. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6790. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6791. /* HC rate */
  6792. init_params->rx.hc_rate = bp->rx_ticks ?
  6793. (1000000 / bp->rx_ticks) : 0;
  6794. init_params->tx.hc_rate = bp->tx_ticks ?
  6795. (1000000 / bp->tx_ticks) : 0;
  6796. /* FW SB ID */
  6797. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6798. fp->fw_sb_id;
  6799. /*
  6800. * CQ index among the SB indices: FCoE clients uses the default
  6801. * SB, therefore it's different.
  6802. */
  6803. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6804. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6805. }
  6806. /* set maximum number of COSs supported by this queue */
  6807. init_params->max_cos = fp->max_cos;
  6808. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6809. fp->index, init_params->max_cos);
  6810. /* set the context pointers queue object */
  6811. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6812. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6813. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6814. ILT_PAGE_CIDS);
  6815. init_params->cxts[cos] =
  6816. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6817. }
  6818. }
  6819. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6820. struct bnx2x_queue_state_params *q_params,
  6821. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6822. int tx_index, bool leading)
  6823. {
  6824. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6825. /* Set the command */
  6826. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6827. /* Set tx-only QUEUE flags: don't zero statistics */
  6828. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6829. /* choose the index of the cid to send the slow path on */
  6830. tx_only_params->cid_index = tx_index;
  6831. /* Set general TX_ONLY_SETUP parameters */
  6832. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6833. /* Set Tx TX_ONLY_SETUP parameters */
  6834. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6835. DP(NETIF_MSG_IFUP,
  6836. "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",
  6837. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6838. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6839. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6840. /* send the ramrod */
  6841. return bnx2x_queue_state_change(bp, q_params);
  6842. }
  6843. /**
  6844. * bnx2x_setup_queue - setup queue
  6845. *
  6846. * @bp: driver handle
  6847. * @fp: pointer to fastpath
  6848. * @leading: is leading
  6849. *
  6850. * This function performs 2 steps in a Queue state machine
  6851. * actually: 1) RESET->INIT 2) INIT->SETUP
  6852. */
  6853. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6854. bool leading)
  6855. {
  6856. struct bnx2x_queue_state_params q_params = {NULL};
  6857. struct bnx2x_queue_setup_params *setup_params =
  6858. &q_params.params.setup;
  6859. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6860. &q_params.params.tx_only;
  6861. int rc;
  6862. u8 tx_index;
  6863. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6864. /* reset IGU state skip FCoE L2 queue */
  6865. if (!IS_FCOE_FP(fp))
  6866. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6867. IGU_INT_ENABLE, 0);
  6868. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6869. /* We want to wait for completion in this context */
  6870. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6871. /* Prepare the INIT parameters */
  6872. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6873. /* Set the command */
  6874. q_params.cmd = BNX2X_Q_CMD_INIT;
  6875. /* Change the state to INIT */
  6876. rc = bnx2x_queue_state_change(bp, &q_params);
  6877. if (rc) {
  6878. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6879. return rc;
  6880. }
  6881. DP(NETIF_MSG_IFUP, "init complete\n");
  6882. /* Now move the Queue to the SETUP state... */
  6883. memset(setup_params, 0, sizeof(*setup_params));
  6884. /* Set QUEUE flags */
  6885. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6886. /* Set general SETUP parameters */
  6887. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6888. FIRST_TX_COS_INDEX);
  6889. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6890. &setup_params->rxq_params);
  6891. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6892. FIRST_TX_COS_INDEX);
  6893. /* Set the command */
  6894. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6895. if (IS_FCOE_FP(fp))
  6896. bp->fcoe_init = true;
  6897. /* Change the state to SETUP */
  6898. rc = bnx2x_queue_state_change(bp, &q_params);
  6899. if (rc) {
  6900. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6901. return rc;
  6902. }
  6903. /* loop through the relevant tx-only indices */
  6904. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6905. tx_index < fp->max_cos;
  6906. tx_index++) {
  6907. /* prepare and send tx-only ramrod*/
  6908. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6909. tx_only_params, tx_index, leading);
  6910. if (rc) {
  6911. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6912. fp->index, tx_index);
  6913. return rc;
  6914. }
  6915. }
  6916. return rc;
  6917. }
  6918. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6919. {
  6920. struct bnx2x_fastpath *fp = &bp->fp[index];
  6921. struct bnx2x_fp_txdata *txdata;
  6922. struct bnx2x_queue_state_params q_params = {NULL};
  6923. int rc, tx_index;
  6924. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6925. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6926. /* We want to wait for completion in this context */
  6927. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6928. /* close tx-only connections */
  6929. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6930. tx_index < fp->max_cos;
  6931. tx_index++){
  6932. /* ascertain this is a normal queue*/
  6933. txdata = fp->txdata_ptr[tx_index];
  6934. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6935. txdata->txq_index);
  6936. /* send halt terminate on tx-only connection */
  6937. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6938. memset(&q_params.params.terminate, 0,
  6939. sizeof(q_params.params.terminate));
  6940. q_params.params.terminate.cid_index = tx_index;
  6941. rc = bnx2x_queue_state_change(bp, &q_params);
  6942. if (rc)
  6943. return rc;
  6944. /* send halt terminate on tx-only connection */
  6945. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6946. memset(&q_params.params.cfc_del, 0,
  6947. sizeof(q_params.params.cfc_del));
  6948. q_params.params.cfc_del.cid_index = tx_index;
  6949. rc = bnx2x_queue_state_change(bp, &q_params);
  6950. if (rc)
  6951. return rc;
  6952. }
  6953. /* Stop the primary connection: */
  6954. /* ...halt the connection */
  6955. q_params.cmd = BNX2X_Q_CMD_HALT;
  6956. rc = bnx2x_queue_state_change(bp, &q_params);
  6957. if (rc)
  6958. return rc;
  6959. /* ...terminate the connection */
  6960. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6961. memset(&q_params.params.terminate, 0,
  6962. sizeof(q_params.params.terminate));
  6963. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6964. rc = bnx2x_queue_state_change(bp, &q_params);
  6965. if (rc)
  6966. return rc;
  6967. /* ...delete cfc entry */
  6968. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6969. memset(&q_params.params.cfc_del, 0,
  6970. sizeof(q_params.params.cfc_del));
  6971. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6972. return bnx2x_queue_state_change(bp, &q_params);
  6973. }
  6974. static void bnx2x_reset_func(struct bnx2x *bp)
  6975. {
  6976. int port = BP_PORT(bp);
  6977. int func = BP_FUNC(bp);
  6978. int i;
  6979. /* Disable the function in the FW */
  6980. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6981. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6982. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6983. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6984. /* FP SBs */
  6985. for_each_eth_queue(bp, i) {
  6986. struct bnx2x_fastpath *fp = &bp->fp[i];
  6987. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6988. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6989. SB_DISABLED);
  6990. }
  6991. if (CNIC_LOADED(bp))
  6992. /* CNIC SB */
  6993. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6994. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6995. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6996. /* SP SB */
  6997. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6998. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6999. SB_DISABLED);
  7000. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7001. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7002. 0);
  7003. /* Configure IGU */
  7004. if (bp->common.int_block == INT_BLOCK_HC) {
  7005. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7006. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7007. } else {
  7008. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7009. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7010. }
  7011. if (CNIC_LOADED(bp)) {
  7012. /* Disable Timer scan */
  7013. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7014. /*
  7015. * Wait for at least 10ms and up to 2 second for the timers
  7016. * scan to complete
  7017. */
  7018. for (i = 0; i < 200; i++) {
  7019. msleep(10);
  7020. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7021. break;
  7022. }
  7023. }
  7024. /* Clear ILT */
  7025. bnx2x_clear_func_ilt(bp, func);
  7026. /* Timers workaround bug for E2: if this is vnic-3,
  7027. * we need to set the entire ilt range for this timers.
  7028. */
  7029. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7030. struct ilt_client_info ilt_cli;
  7031. /* use dummy TM client */
  7032. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7033. ilt_cli.start = 0;
  7034. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7035. ilt_cli.client_num = ILT_CLIENT_TM;
  7036. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7037. }
  7038. /* this assumes that reset_port() called before reset_func()*/
  7039. if (!CHIP_IS_E1x(bp))
  7040. bnx2x_pf_disable(bp);
  7041. bp->dmae_ready = 0;
  7042. }
  7043. static void bnx2x_reset_port(struct bnx2x *bp)
  7044. {
  7045. int port = BP_PORT(bp);
  7046. u32 val;
  7047. /* Reset physical Link */
  7048. bnx2x__link_reset(bp);
  7049. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7050. /* Do not rcv packets to BRB */
  7051. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7052. /* Do not direct rcv packets that are not for MCP to the BRB */
  7053. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7054. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7055. /* Configure AEU */
  7056. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7057. msleep(100);
  7058. /* Check for BRB port occupancy */
  7059. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7060. if (val)
  7061. DP(NETIF_MSG_IFDOWN,
  7062. "BRB1 is not empty %d blocks are occupied\n", val);
  7063. /* TODO: Close Doorbell port? */
  7064. }
  7065. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7066. {
  7067. struct bnx2x_func_state_params func_params = {NULL};
  7068. /* Prepare parameters for function state transitions */
  7069. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7070. func_params.f_obj = &bp->func_obj;
  7071. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7072. func_params.params.hw_init.load_phase = load_code;
  7073. return bnx2x_func_state_change(bp, &func_params);
  7074. }
  7075. static int bnx2x_func_stop(struct bnx2x *bp)
  7076. {
  7077. struct bnx2x_func_state_params func_params = {NULL};
  7078. int rc;
  7079. /* Prepare parameters for function state transitions */
  7080. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7081. func_params.f_obj = &bp->func_obj;
  7082. func_params.cmd = BNX2X_F_CMD_STOP;
  7083. /*
  7084. * Try to stop the function the 'good way'. If fails (in case
  7085. * of a parity error during bnx2x_chip_cleanup()) and we are
  7086. * not in a debug mode, perform a state transaction in order to
  7087. * enable further HW_RESET transaction.
  7088. */
  7089. rc = bnx2x_func_state_change(bp, &func_params);
  7090. if (rc) {
  7091. #ifdef BNX2X_STOP_ON_ERROR
  7092. return rc;
  7093. #else
  7094. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7095. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7096. return bnx2x_func_state_change(bp, &func_params);
  7097. #endif
  7098. }
  7099. return 0;
  7100. }
  7101. /**
  7102. * bnx2x_send_unload_req - request unload mode from the MCP.
  7103. *
  7104. * @bp: driver handle
  7105. * @unload_mode: requested function's unload mode
  7106. *
  7107. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7108. */
  7109. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7110. {
  7111. u32 reset_code = 0;
  7112. int port = BP_PORT(bp);
  7113. /* Select the UNLOAD request mode */
  7114. if (unload_mode == UNLOAD_NORMAL)
  7115. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7116. else if (bp->flags & NO_WOL_FLAG)
  7117. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7118. else if (bp->wol) {
  7119. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7120. u8 *mac_addr = bp->dev->dev_addr;
  7121. u32 val;
  7122. u16 pmc;
  7123. /* The mac address is written to entries 1-4 to
  7124. * preserve entry 0 which is used by the PMF
  7125. */
  7126. u8 entry = (BP_VN(bp) + 1)*8;
  7127. val = (mac_addr[0] << 8) | mac_addr[1];
  7128. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7129. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7130. (mac_addr[4] << 8) | mac_addr[5];
  7131. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7132. /* Enable the PME and clear the status */
  7133. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7134. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7135. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7136. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7137. } else
  7138. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7139. /* Send the request to the MCP */
  7140. if (!BP_NOMCP(bp))
  7141. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7142. else {
  7143. int path = BP_PATH(bp);
  7144. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7145. path, load_count[path][0], load_count[path][1],
  7146. load_count[path][2]);
  7147. load_count[path][0]--;
  7148. load_count[path][1 + port]--;
  7149. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7150. path, load_count[path][0], load_count[path][1],
  7151. load_count[path][2]);
  7152. if (load_count[path][0] == 0)
  7153. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7154. else if (load_count[path][1 + port] == 0)
  7155. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7156. else
  7157. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7158. }
  7159. return reset_code;
  7160. }
  7161. /**
  7162. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7163. *
  7164. * @bp: driver handle
  7165. * @keep_link: true iff link should be kept up
  7166. */
  7167. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7168. {
  7169. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7170. /* Report UNLOAD_DONE to MCP */
  7171. if (!BP_NOMCP(bp))
  7172. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7173. }
  7174. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7175. {
  7176. int tout = 50;
  7177. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7178. if (!bp->port.pmf)
  7179. return 0;
  7180. /*
  7181. * (assumption: No Attention from MCP at this stage)
  7182. * PMF probably in the middle of TXdisable/enable transaction
  7183. * 1. Sync IRS for default SB
  7184. * 2. Sync SP queue - this guarantes us that attention handling started
  7185. * 3. Wait, that TXdisable/enable transaction completes
  7186. *
  7187. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7188. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7189. * received complettion for the transaction the state is TX_STOPPED.
  7190. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7191. * transaction.
  7192. */
  7193. /* make sure default SB ISR is done */
  7194. if (msix)
  7195. synchronize_irq(bp->msix_table[0].vector);
  7196. else
  7197. synchronize_irq(bp->pdev->irq);
  7198. flush_workqueue(bnx2x_wq);
  7199. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7200. BNX2X_F_STATE_STARTED && tout--)
  7201. msleep(20);
  7202. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7203. BNX2X_F_STATE_STARTED) {
  7204. #ifdef BNX2X_STOP_ON_ERROR
  7205. BNX2X_ERR("Wrong function state\n");
  7206. return -EBUSY;
  7207. #else
  7208. /*
  7209. * Failed to complete the transaction in a "good way"
  7210. * Force both transactions with CLR bit
  7211. */
  7212. struct bnx2x_func_state_params func_params = {NULL};
  7213. DP(NETIF_MSG_IFDOWN,
  7214. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7215. func_params.f_obj = &bp->func_obj;
  7216. __set_bit(RAMROD_DRV_CLR_ONLY,
  7217. &func_params.ramrod_flags);
  7218. /* STARTED-->TX_ST0PPED */
  7219. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7220. bnx2x_func_state_change(bp, &func_params);
  7221. /* TX_ST0PPED-->STARTED */
  7222. func_params.cmd = BNX2X_F_CMD_TX_START;
  7223. return bnx2x_func_state_change(bp, &func_params);
  7224. #endif
  7225. }
  7226. return 0;
  7227. }
  7228. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7229. {
  7230. int port = BP_PORT(bp);
  7231. int i, rc = 0;
  7232. u8 cos;
  7233. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7234. u32 reset_code;
  7235. /* Wait until tx fastpath tasks complete */
  7236. for_each_tx_queue(bp, i) {
  7237. struct bnx2x_fastpath *fp = &bp->fp[i];
  7238. for_each_cos_in_tx_queue(fp, cos)
  7239. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7240. #ifdef BNX2X_STOP_ON_ERROR
  7241. if (rc)
  7242. return;
  7243. #endif
  7244. }
  7245. /* Give HW time to discard old tx messages */
  7246. usleep_range(1000, 2000);
  7247. /* Clean all ETH MACs */
  7248. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7249. false);
  7250. if (rc < 0)
  7251. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7252. /* Clean up UC list */
  7253. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7254. true);
  7255. if (rc < 0)
  7256. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7257. rc);
  7258. /* Disable LLH */
  7259. if (!CHIP_IS_E1(bp))
  7260. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7261. /* Set "drop all" (stop Rx).
  7262. * We need to take a netif_addr_lock() here in order to prevent
  7263. * a race between the completion code and this code.
  7264. */
  7265. netif_addr_lock_bh(bp->dev);
  7266. /* Schedule the rx_mode command */
  7267. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7268. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7269. else
  7270. bnx2x_set_storm_rx_mode(bp);
  7271. /* Cleanup multicast configuration */
  7272. rparam.mcast_obj = &bp->mcast_obj;
  7273. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7274. if (rc < 0)
  7275. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7276. netif_addr_unlock_bh(bp->dev);
  7277. bnx2x_iov_chip_cleanup(bp);
  7278. /*
  7279. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7280. * this function should perform FUNC, PORT or COMMON HW
  7281. * reset.
  7282. */
  7283. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7284. /*
  7285. * (assumption: No Attention from MCP at this stage)
  7286. * PMF probably in the middle of TXdisable/enable transaction
  7287. */
  7288. rc = bnx2x_func_wait_started(bp);
  7289. if (rc) {
  7290. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7291. #ifdef BNX2X_STOP_ON_ERROR
  7292. return;
  7293. #endif
  7294. }
  7295. /* Close multi and leading connections
  7296. * Completions for ramrods are collected in a synchronous way
  7297. */
  7298. for_each_eth_queue(bp, i)
  7299. if (bnx2x_stop_queue(bp, i))
  7300. #ifdef BNX2X_STOP_ON_ERROR
  7301. return;
  7302. #else
  7303. goto unload_error;
  7304. #endif
  7305. if (CNIC_LOADED(bp)) {
  7306. for_each_cnic_queue(bp, i)
  7307. if (bnx2x_stop_queue(bp, i))
  7308. #ifdef BNX2X_STOP_ON_ERROR
  7309. return;
  7310. #else
  7311. goto unload_error;
  7312. #endif
  7313. }
  7314. /* If SP settings didn't get completed so far - something
  7315. * very wrong has happen.
  7316. */
  7317. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7318. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7319. #ifndef BNX2X_STOP_ON_ERROR
  7320. unload_error:
  7321. #endif
  7322. rc = bnx2x_func_stop(bp);
  7323. if (rc) {
  7324. BNX2X_ERR("Function stop failed!\n");
  7325. #ifdef BNX2X_STOP_ON_ERROR
  7326. return;
  7327. #endif
  7328. }
  7329. /* Disable HW interrupts, NAPI */
  7330. bnx2x_netif_stop(bp, 1);
  7331. /* Delete all NAPI objects */
  7332. bnx2x_del_all_napi(bp);
  7333. if (CNIC_LOADED(bp))
  7334. bnx2x_del_all_napi_cnic(bp);
  7335. /* Release IRQs */
  7336. bnx2x_free_irq(bp);
  7337. /* Reset the chip */
  7338. rc = bnx2x_reset_hw(bp, reset_code);
  7339. if (rc)
  7340. BNX2X_ERR("HW_RESET failed\n");
  7341. /* Report UNLOAD_DONE to MCP */
  7342. bnx2x_send_unload_done(bp, keep_link);
  7343. }
  7344. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7345. {
  7346. u32 val;
  7347. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7348. if (CHIP_IS_E1(bp)) {
  7349. int port = BP_PORT(bp);
  7350. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7351. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7352. val = REG_RD(bp, addr);
  7353. val &= ~(0x300);
  7354. REG_WR(bp, addr, val);
  7355. } else {
  7356. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7357. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7358. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7359. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7360. }
  7361. }
  7362. /* Close gates #2, #3 and #4: */
  7363. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7364. {
  7365. u32 val;
  7366. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7367. if (!CHIP_IS_E1(bp)) {
  7368. /* #4 */
  7369. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7370. /* #2 */
  7371. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7372. }
  7373. /* #3 */
  7374. if (CHIP_IS_E1x(bp)) {
  7375. /* Prevent interrupts from HC on both ports */
  7376. val = REG_RD(bp, HC_REG_CONFIG_1);
  7377. REG_WR(bp, HC_REG_CONFIG_1,
  7378. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7379. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7380. val = REG_RD(bp, HC_REG_CONFIG_0);
  7381. REG_WR(bp, HC_REG_CONFIG_0,
  7382. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7383. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7384. } else {
  7385. /* Prevent incoming interrupts in IGU */
  7386. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7387. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7388. (!close) ?
  7389. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7390. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7391. }
  7392. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7393. close ? "closing" : "opening");
  7394. mmiowb();
  7395. }
  7396. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7397. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7398. {
  7399. /* Do some magic... */
  7400. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7401. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7402. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7403. }
  7404. /**
  7405. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7406. *
  7407. * @bp: driver handle
  7408. * @magic_val: old value of the `magic' bit.
  7409. */
  7410. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7411. {
  7412. /* Restore the `magic' bit value... */
  7413. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7414. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7415. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7416. }
  7417. /**
  7418. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7419. *
  7420. * @bp: driver handle
  7421. * @magic_val: old value of 'magic' bit.
  7422. *
  7423. * Takes care of CLP configurations.
  7424. */
  7425. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7426. {
  7427. u32 shmem;
  7428. u32 validity_offset;
  7429. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7430. /* Set `magic' bit in order to save MF config */
  7431. if (!CHIP_IS_E1(bp))
  7432. bnx2x_clp_reset_prep(bp, magic_val);
  7433. /* Get shmem offset */
  7434. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7435. validity_offset =
  7436. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7437. /* Clear validity map flags */
  7438. if (shmem > 0)
  7439. REG_WR(bp, shmem + validity_offset, 0);
  7440. }
  7441. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7442. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7443. /**
  7444. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7445. *
  7446. * @bp: driver handle
  7447. */
  7448. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7449. {
  7450. /* special handling for emulation and FPGA,
  7451. wait 10 times longer */
  7452. if (CHIP_REV_IS_SLOW(bp))
  7453. msleep(MCP_ONE_TIMEOUT*10);
  7454. else
  7455. msleep(MCP_ONE_TIMEOUT);
  7456. }
  7457. /*
  7458. * initializes bp->common.shmem_base and waits for validity signature to appear
  7459. */
  7460. static int bnx2x_init_shmem(struct bnx2x *bp)
  7461. {
  7462. int cnt = 0;
  7463. u32 val = 0;
  7464. do {
  7465. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7466. if (bp->common.shmem_base) {
  7467. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7468. if (val & SHR_MEM_VALIDITY_MB)
  7469. return 0;
  7470. }
  7471. bnx2x_mcp_wait_one(bp);
  7472. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7473. BNX2X_ERR("BAD MCP validity signature\n");
  7474. return -ENODEV;
  7475. }
  7476. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7477. {
  7478. int rc = bnx2x_init_shmem(bp);
  7479. /* Restore the `magic' bit value */
  7480. if (!CHIP_IS_E1(bp))
  7481. bnx2x_clp_reset_done(bp, magic_val);
  7482. return rc;
  7483. }
  7484. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7485. {
  7486. if (!CHIP_IS_E1(bp)) {
  7487. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7488. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7489. mmiowb();
  7490. }
  7491. }
  7492. /*
  7493. * Reset the whole chip except for:
  7494. * - PCIE core
  7495. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7496. * one reset bit)
  7497. * - IGU
  7498. * - MISC (including AEU)
  7499. * - GRC
  7500. * - RBCN, RBCP
  7501. */
  7502. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7503. {
  7504. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7505. u32 global_bits2, stay_reset2;
  7506. /*
  7507. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7508. * (per chip) blocks.
  7509. */
  7510. global_bits2 =
  7511. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7512. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7513. /* Don't reset the following blocks.
  7514. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7515. * reset, as in 4 port device they might still be owned
  7516. * by the MCP (there is only one leader per path).
  7517. */
  7518. not_reset_mask1 =
  7519. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7520. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7521. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7522. not_reset_mask2 =
  7523. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7524. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7525. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7526. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7527. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7528. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7529. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7530. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7531. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7532. MISC_REGISTERS_RESET_REG_2_PGLC |
  7533. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7534. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7535. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7536. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7537. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7538. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7539. /*
  7540. * Keep the following blocks in reset:
  7541. * - all xxMACs are handled by the bnx2x_link code.
  7542. */
  7543. stay_reset2 =
  7544. MISC_REGISTERS_RESET_REG_2_XMAC |
  7545. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7546. /* Full reset masks according to the chip */
  7547. reset_mask1 = 0xffffffff;
  7548. if (CHIP_IS_E1(bp))
  7549. reset_mask2 = 0xffff;
  7550. else if (CHIP_IS_E1H(bp))
  7551. reset_mask2 = 0x1ffff;
  7552. else if (CHIP_IS_E2(bp))
  7553. reset_mask2 = 0xfffff;
  7554. else /* CHIP_IS_E3 */
  7555. reset_mask2 = 0x3ffffff;
  7556. /* Don't reset global blocks unless we need to */
  7557. if (!global)
  7558. reset_mask2 &= ~global_bits2;
  7559. /*
  7560. * In case of attention in the QM, we need to reset PXP
  7561. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7562. * because otherwise QM reset would release 'close the gates' shortly
  7563. * before resetting the PXP, then the PSWRQ would send a write
  7564. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7565. * read the payload data from PSWWR, but PSWWR would not
  7566. * respond. The write queue in PGLUE would stuck, dmae commands
  7567. * would not return. Therefore it's important to reset the second
  7568. * reset register (containing the
  7569. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7570. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7571. * bit).
  7572. */
  7573. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7574. reset_mask2 & (~not_reset_mask2));
  7575. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7576. reset_mask1 & (~not_reset_mask1));
  7577. barrier();
  7578. mmiowb();
  7579. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7580. reset_mask2 & (~stay_reset2));
  7581. barrier();
  7582. mmiowb();
  7583. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7584. mmiowb();
  7585. }
  7586. /**
  7587. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7588. * It should get cleared in no more than 1s.
  7589. *
  7590. * @bp: driver handle
  7591. *
  7592. * It should get cleared in no more than 1s. Returns 0 if
  7593. * pending writes bit gets cleared.
  7594. */
  7595. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7596. {
  7597. u32 cnt = 1000;
  7598. u32 pend_bits = 0;
  7599. do {
  7600. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7601. if (pend_bits == 0)
  7602. break;
  7603. usleep_range(1000, 2000);
  7604. } while (cnt-- > 0);
  7605. if (cnt <= 0) {
  7606. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7607. pend_bits);
  7608. return -EBUSY;
  7609. }
  7610. return 0;
  7611. }
  7612. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7613. {
  7614. int cnt = 1000;
  7615. u32 val = 0;
  7616. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7617. u32 tags_63_32 = 0;
  7618. /* Empty the Tetris buffer, wait for 1s */
  7619. do {
  7620. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7621. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7622. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7623. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7624. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7625. if (CHIP_IS_E3(bp))
  7626. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7627. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7628. ((port_is_idle_0 & 0x1) == 0x1) &&
  7629. ((port_is_idle_1 & 0x1) == 0x1) &&
  7630. (pgl_exp_rom2 == 0xffffffff) &&
  7631. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7632. break;
  7633. usleep_range(1000, 2000);
  7634. } while (cnt-- > 0);
  7635. if (cnt <= 0) {
  7636. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7637. 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",
  7638. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7639. pgl_exp_rom2);
  7640. return -EAGAIN;
  7641. }
  7642. barrier();
  7643. /* Close gates #2, #3 and #4 */
  7644. bnx2x_set_234_gates(bp, true);
  7645. /* Poll for IGU VQs for 57712 and newer chips */
  7646. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7647. return -EAGAIN;
  7648. /* TBD: Indicate that "process kill" is in progress to MCP */
  7649. /* Clear "unprepared" bit */
  7650. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7651. barrier();
  7652. /* Make sure all is written to the chip before the reset */
  7653. mmiowb();
  7654. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7655. * PSWHST, GRC and PSWRD Tetris buffer.
  7656. */
  7657. usleep_range(1000, 2000);
  7658. /* Prepare to chip reset: */
  7659. /* MCP */
  7660. if (global)
  7661. bnx2x_reset_mcp_prep(bp, &val);
  7662. /* PXP */
  7663. bnx2x_pxp_prep(bp);
  7664. barrier();
  7665. /* reset the chip */
  7666. bnx2x_process_kill_chip_reset(bp, global);
  7667. barrier();
  7668. /* Recover after reset: */
  7669. /* MCP */
  7670. if (global && bnx2x_reset_mcp_comp(bp, val))
  7671. return -EAGAIN;
  7672. /* TBD: Add resetting the NO_MCP mode DB here */
  7673. /* Open the gates #2, #3 and #4 */
  7674. bnx2x_set_234_gates(bp, false);
  7675. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7676. * reset state, re-enable attentions. */
  7677. return 0;
  7678. }
  7679. static int bnx2x_leader_reset(struct bnx2x *bp)
  7680. {
  7681. int rc = 0;
  7682. bool global = bnx2x_reset_is_global(bp);
  7683. u32 load_code;
  7684. /* if not going to reset MCP - load "fake" driver to reset HW while
  7685. * driver is owner of the HW
  7686. */
  7687. if (!global && !BP_NOMCP(bp)) {
  7688. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7689. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7690. if (!load_code) {
  7691. BNX2X_ERR("MCP response failure, aborting\n");
  7692. rc = -EAGAIN;
  7693. goto exit_leader_reset;
  7694. }
  7695. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7696. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7697. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7698. rc = -EAGAIN;
  7699. goto exit_leader_reset2;
  7700. }
  7701. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7702. if (!load_code) {
  7703. BNX2X_ERR("MCP response failure, aborting\n");
  7704. rc = -EAGAIN;
  7705. goto exit_leader_reset2;
  7706. }
  7707. }
  7708. /* Try to recover after the failure */
  7709. if (bnx2x_process_kill(bp, global)) {
  7710. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7711. BP_PATH(bp));
  7712. rc = -EAGAIN;
  7713. goto exit_leader_reset2;
  7714. }
  7715. /*
  7716. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7717. * state.
  7718. */
  7719. bnx2x_set_reset_done(bp);
  7720. if (global)
  7721. bnx2x_clear_reset_global(bp);
  7722. exit_leader_reset2:
  7723. /* unload "fake driver" if it was loaded */
  7724. if (!global && !BP_NOMCP(bp)) {
  7725. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7726. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7727. }
  7728. exit_leader_reset:
  7729. bp->is_leader = 0;
  7730. bnx2x_release_leader_lock(bp);
  7731. smp_mb();
  7732. return rc;
  7733. }
  7734. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7735. {
  7736. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7737. /* Disconnect this device */
  7738. netif_device_detach(bp->dev);
  7739. /*
  7740. * Block ifup for all function on this engine until "process kill"
  7741. * or power cycle.
  7742. */
  7743. bnx2x_set_reset_in_progress(bp);
  7744. /* Shut down the power */
  7745. bnx2x_set_power_state(bp, PCI_D3hot);
  7746. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7747. smp_mb();
  7748. }
  7749. /*
  7750. * Assumption: runs under rtnl lock. This together with the fact
  7751. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7752. * will never be called when netif_running(bp->dev) is false.
  7753. */
  7754. static void bnx2x_parity_recover(struct bnx2x *bp)
  7755. {
  7756. bool global = false;
  7757. u32 error_recovered, error_unrecovered;
  7758. bool is_parity;
  7759. DP(NETIF_MSG_HW, "Handling parity\n");
  7760. while (1) {
  7761. switch (bp->recovery_state) {
  7762. case BNX2X_RECOVERY_INIT:
  7763. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7764. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7765. WARN_ON(!is_parity);
  7766. /* Try to get a LEADER_LOCK HW lock */
  7767. if (bnx2x_trylock_leader_lock(bp)) {
  7768. bnx2x_set_reset_in_progress(bp);
  7769. /*
  7770. * Check if there is a global attention and if
  7771. * there was a global attention, set the global
  7772. * reset bit.
  7773. */
  7774. if (global)
  7775. bnx2x_set_reset_global(bp);
  7776. bp->is_leader = 1;
  7777. }
  7778. /* Stop the driver */
  7779. /* If interface has been removed - break */
  7780. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7781. return;
  7782. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7783. /* Ensure "is_leader", MCP command sequence and
  7784. * "recovery_state" update values are seen on other
  7785. * CPUs.
  7786. */
  7787. smp_mb();
  7788. break;
  7789. case BNX2X_RECOVERY_WAIT:
  7790. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7791. if (bp->is_leader) {
  7792. int other_engine = BP_PATH(bp) ? 0 : 1;
  7793. bool other_load_status =
  7794. bnx2x_get_load_status(bp, other_engine);
  7795. bool load_status =
  7796. bnx2x_get_load_status(bp, BP_PATH(bp));
  7797. global = bnx2x_reset_is_global(bp);
  7798. /*
  7799. * In case of a parity in a global block, let
  7800. * the first leader that performs a
  7801. * leader_reset() reset the global blocks in
  7802. * order to clear global attentions. Otherwise
  7803. * the the gates will remain closed for that
  7804. * engine.
  7805. */
  7806. if (load_status ||
  7807. (global && other_load_status)) {
  7808. /* Wait until all other functions get
  7809. * down.
  7810. */
  7811. schedule_delayed_work(&bp->sp_rtnl_task,
  7812. HZ/10);
  7813. return;
  7814. } else {
  7815. /* If all other functions got down -
  7816. * try to bring the chip back to
  7817. * normal. In any case it's an exit
  7818. * point for a leader.
  7819. */
  7820. if (bnx2x_leader_reset(bp)) {
  7821. bnx2x_recovery_failed(bp);
  7822. return;
  7823. }
  7824. /* If we are here, means that the
  7825. * leader has succeeded and doesn't
  7826. * want to be a leader any more. Try
  7827. * to continue as a none-leader.
  7828. */
  7829. break;
  7830. }
  7831. } else { /* non-leader */
  7832. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7833. /* Try to get a LEADER_LOCK HW lock as
  7834. * long as a former leader may have
  7835. * been unloaded by the user or
  7836. * released a leadership by another
  7837. * reason.
  7838. */
  7839. if (bnx2x_trylock_leader_lock(bp)) {
  7840. /* I'm a leader now! Restart a
  7841. * switch case.
  7842. */
  7843. bp->is_leader = 1;
  7844. break;
  7845. }
  7846. schedule_delayed_work(&bp->sp_rtnl_task,
  7847. HZ/10);
  7848. return;
  7849. } else {
  7850. /*
  7851. * If there was a global attention, wait
  7852. * for it to be cleared.
  7853. */
  7854. if (bnx2x_reset_is_global(bp)) {
  7855. schedule_delayed_work(
  7856. &bp->sp_rtnl_task,
  7857. HZ/10);
  7858. return;
  7859. }
  7860. error_recovered =
  7861. bp->eth_stats.recoverable_error;
  7862. error_unrecovered =
  7863. bp->eth_stats.unrecoverable_error;
  7864. bp->recovery_state =
  7865. BNX2X_RECOVERY_NIC_LOADING;
  7866. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7867. error_unrecovered++;
  7868. netdev_err(bp->dev,
  7869. "Recovery failed. Power cycle needed\n");
  7870. /* Disconnect this device */
  7871. netif_device_detach(bp->dev);
  7872. /* Shut down the power */
  7873. bnx2x_set_power_state(
  7874. bp, PCI_D3hot);
  7875. smp_mb();
  7876. } else {
  7877. bp->recovery_state =
  7878. BNX2X_RECOVERY_DONE;
  7879. error_recovered++;
  7880. smp_mb();
  7881. }
  7882. bp->eth_stats.recoverable_error =
  7883. error_recovered;
  7884. bp->eth_stats.unrecoverable_error =
  7885. error_unrecovered;
  7886. return;
  7887. }
  7888. }
  7889. default:
  7890. return;
  7891. }
  7892. }
  7893. }
  7894. static int bnx2x_close(struct net_device *dev);
  7895. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7896. * scheduled on a general queue in order to prevent a dead lock.
  7897. */
  7898. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7899. {
  7900. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7901. rtnl_lock();
  7902. if (!netif_running(bp->dev)) {
  7903. rtnl_unlock();
  7904. return;
  7905. }
  7906. /* if stop on error is defined no recovery flows should be executed */
  7907. #ifdef BNX2X_STOP_ON_ERROR
  7908. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7909. "you will need to reboot when done\n");
  7910. goto sp_rtnl_not_reset;
  7911. #endif
  7912. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7913. /*
  7914. * Clear all pending SP commands as we are going to reset the
  7915. * function anyway.
  7916. */
  7917. bp->sp_rtnl_state = 0;
  7918. smp_mb();
  7919. bnx2x_parity_recover(bp);
  7920. rtnl_unlock();
  7921. return;
  7922. }
  7923. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7924. /*
  7925. * Clear all pending SP commands as we are going to reset the
  7926. * function anyway.
  7927. */
  7928. bp->sp_rtnl_state = 0;
  7929. smp_mb();
  7930. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7931. bnx2x_nic_load(bp, LOAD_NORMAL);
  7932. rtnl_unlock();
  7933. return;
  7934. }
  7935. #ifdef BNX2X_STOP_ON_ERROR
  7936. sp_rtnl_not_reset:
  7937. #endif
  7938. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7939. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7940. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7941. bnx2x_after_function_update(bp);
  7942. /*
  7943. * in case of fan failure we need to reset id if the "stop on error"
  7944. * debug flag is set, since we trying to prevent permanent overheating
  7945. * damage
  7946. */
  7947. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7948. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7949. netif_device_detach(bp->dev);
  7950. bnx2x_close(bp->dev);
  7951. rtnl_unlock();
  7952. return;
  7953. }
  7954. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7955. DP(BNX2X_MSG_SP,
  7956. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7957. bnx2x_vfpf_set_mcast(bp->dev);
  7958. }
  7959. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7960. &bp->sp_rtnl_state)) {
  7961. DP(BNX2X_MSG_SP,
  7962. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7963. bnx2x_vfpf_storm_rx_mode(bp);
  7964. }
  7965. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  7966. &bp->sp_rtnl_state))
  7967. bnx2x_pf_set_vfs_vlan(bp);
  7968. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7969. * can be called from other contexts as well)
  7970. */
  7971. rtnl_unlock();
  7972. /* enable SR-IOV if applicable */
  7973. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7974. &bp->sp_rtnl_state)) {
  7975. bnx2x_disable_sriov(bp);
  7976. bnx2x_enable_sriov(bp);
  7977. }
  7978. }
  7979. static void bnx2x_period_task(struct work_struct *work)
  7980. {
  7981. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7982. if (!netif_running(bp->dev))
  7983. goto period_task_exit;
  7984. if (CHIP_REV_IS_SLOW(bp)) {
  7985. BNX2X_ERR("period task called on emulation, ignoring\n");
  7986. goto period_task_exit;
  7987. }
  7988. bnx2x_acquire_phy_lock(bp);
  7989. /*
  7990. * The barrier is needed to ensure the ordering between the writing to
  7991. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7992. * the reading here.
  7993. */
  7994. smp_mb();
  7995. if (bp->port.pmf) {
  7996. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7997. /* Re-queue task in 1 sec */
  7998. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7999. }
  8000. bnx2x_release_phy_lock(bp);
  8001. period_task_exit:
  8002. return;
  8003. }
  8004. /*
  8005. * Init service functions
  8006. */
  8007. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8008. {
  8009. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8010. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8011. return base + (BP_ABS_FUNC(bp)) * stride;
  8012. }
  8013. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8014. struct bnx2x_mac_vals *vals)
  8015. {
  8016. u32 val, base_addr, offset, mask, reset_reg;
  8017. bool mac_stopped = false;
  8018. u8 port = BP_PORT(bp);
  8019. /* reset addresses as they also mark which values were changed */
  8020. vals->bmac_addr = 0;
  8021. vals->umac_addr = 0;
  8022. vals->xmac_addr = 0;
  8023. vals->emac_addr = 0;
  8024. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8025. if (!CHIP_IS_E3(bp)) {
  8026. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8027. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8028. if ((mask & reset_reg) && val) {
  8029. u32 wb_data[2];
  8030. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8031. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8032. : NIG_REG_INGRESS_BMAC0_MEM;
  8033. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8034. : BIGMAC_REGISTER_BMAC_CONTROL;
  8035. /*
  8036. * use rd/wr since we cannot use dmae. This is safe
  8037. * since MCP won't access the bus due to the request
  8038. * to unload, and no function on the path can be
  8039. * loaded at this time.
  8040. */
  8041. wb_data[0] = REG_RD(bp, base_addr + offset);
  8042. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8043. vals->bmac_addr = base_addr + offset;
  8044. vals->bmac_val[0] = wb_data[0];
  8045. vals->bmac_val[1] = wb_data[1];
  8046. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8047. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8048. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8049. }
  8050. BNX2X_DEV_INFO("Disable emac Rx\n");
  8051. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8052. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8053. REG_WR(bp, vals->emac_addr, 0);
  8054. mac_stopped = true;
  8055. } else {
  8056. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8057. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8058. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8059. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8060. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8061. val & ~(1 << 1));
  8062. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8063. val | (1 << 1));
  8064. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8065. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8066. REG_WR(bp, vals->xmac_addr, 0);
  8067. mac_stopped = true;
  8068. }
  8069. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8070. if (mask & reset_reg) {
  8071. BNX2X_DEV_INFO("Disable umac Rx\n");
  8072. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8073. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8074. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8075. REG_WR(bp, vals->umac_addr, 0);
  8076. mac_stopped = true;
  8077. }
  8078. }
  8079. if (mac_stopped)
  8080. msleep(20);
  8081. }
  8082. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8083. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8084. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8085. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8086. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8087. {
  8088. u16 rcq, bd;
  8089. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8090. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8091. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8092. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8093. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8094. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8095. port, bd, rcq);
  8096. }
  8097. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8098. {
  8099. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8100. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8101. if (!rc) {
  8102. BNX2X_ERR("MCP response failure, aborting\n");
  8103. return -EBUSY;
  8104. }
  8105. return 0;
  8106. }
  8107. static struct bnx2x_prev_path_list *
  8108. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8109. {
  8110. struct bnx2x_prev_path_list *tmp_list;
  8111. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8112. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8113. bp->pdev->bus->number == tmp_list->bus &&
  8114. BP_PATH(bp) == tmp_list->path)
  8115. return tmp_list;
  8116. return NULL;
  8117. }
  8118. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8119. {
  8120. struct bnx2x_prev_path_list *tmp_list;
  8121. int rc;
  8122. rc = down_interruptible(&bnx2x_prev_sem);
  8123. if (rc) {
  8124. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8125. return rc;
  8126. }
  8127. tmp_list = bnx2x_prev_path_get_entry(bp);
  8128. if (tmp_list) {
  8129. tmp_list->aer = 1;
  8130. rc = 0;
  8131. } else {
  8132. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8133. BP_PATH(bp));
  8134. }
  8135. up(&bnx2x_prev_sem);
  8136. return rc;
  8137. }
  8138. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8139. {
  8140. struct bnx2x_prev_path_list *tmp_list;
  8141. int rc = false;
  8142. if (down_trylock(&bnx2x_prev_sem))
  8143. return false;
  8144. tmp_list = bnx2x_prev_path_get_entry(bp);
  8145. if (tmp_list) {
  8146. if (tmp_list->aer) {
  8147. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8148. BP_PATH(bp));
  8149. } else {
  8150. rc = true;
  8151. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8152. BP_PATH(bp));
  8153. }
  8154. }
  8155. up(&bnx2x_prev_sem);
  8156. return rc;
  8157. }
  8158. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8159. {
  8160. struct bnx2x_prev_path_list *tmp_list;
  8161. int rc;
  8162. rc = down_interruptible(&bnx2x_prev_sem);
  8163. if (rc) {
  8164. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8165. return rc;
  8166. }
  8167. /* Check whether the entry for this path already exists */
  8168. tmp_list = bnx2x_prev_path_get_entry(bp);
  8169. if (tmp_list) {
  8170. if (!tmp_list->aer) {
  8171. BNX2X_ERR("Re-Marking the path.\n");
  8172. } else {
  8173. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8174. BP_PATH(bp));
  8175. tmp_list->aer = 0;
  8176. }
  8177. up(&bnx2x_prev_sem);
  8178. return 0;
  8179. }
  8180. up(&bnx2x_prev_sem);
  8181. /* Create an entry for this path and add it */
  8182. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8183. if (!tmp_list) {
  8184. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8185. return -ENOMEM;
  8186. }
  8187. tmp_list->bus = bp->pdev->bus->number;
  8188. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8189. tmp_list->path = BP_PATH(bp);
  8190. tmp_list->aer = 0;
  8191. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8192. rc = down_interruptible(&bnx2x_prev_sem);
  8193. if (rc) {
  8194. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8195. kfree(tmp_list);
  8196. } else {
  8197. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8198. BP_PATH(bp));
  8199. list_add(&tmp_list->list, &bnx2x_prev_list);
  8200. up(&bnx2x_prev_sem);
  8201. }
  8202. return rc;
  8203. }
  8204. static int bnx2x_do_flr(struct bnx2x *bp)
  8205. {
  8206. int i;
  8207. u16 status;
  8208. struct pci_dev *dev = bp->pdev;
  8209. if (CHIP_IS_E1x(bp)) {
  8210. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8211. return -EINVAL;
  8212. }
  8213. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8214. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8215. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8216. bp->common.bc_ver);
  8217. return -EINVAL;
  8218. }
  8219. /* Wait for Transaction Pending bit clean */
  8220. for (i = 0; i < 4; i++) {
  8221. if (i)
  8222. msleep((1 << (i - 1)) * 100);
  8223. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8224. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8225. goto clear;
  8226. }
  8227. dev_err(&dev->dev,
  8228. "transaction is not cleared; proceeding with reset anyway\n");
  8229. clear:
  8230. BNX2X_DEV_INFO("Initiating FLR\n");
  8231. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8232. return 0;
  8233. }
  8234. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8235. {
  8236. int rc;
  8237. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8238. /* Test if previous unload process was already finished for this path */
  8239. if (bnx2x_prev_is_path_marked(bp))
  8240. return bnx2x_prev_mcp_done(bp);
  8241. BNX2X_DEV_INFO("Path is unmarked\n");
  8242. /* If function has FLR capabilities, and existing FW version matches
  8243. * the one required, then FLR will be sufficient to clean any residue
  8244. * left by previous driver
  8245. */
  8246. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8247. if (!rc) {
  8248. /* fw version is good */
  8249. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8250. rc = bnx2x_do_flr(bp);
  8251. }
  8252. if (!rc) {
  8253. /* FLR was performed */
  8254. BNX2X_DEV_INFO("FLR successful\n");
  8255. return 0;
  8256. }
  8257. BNX2X_DEV_INFO("Could not FLR\n");
  8258. /* Close the MCP request, return failure*/
  8259. rc = bnx2x_prev_mcp_done(bp);
  8260. if (!rc)
  8261. rc = BNX2X_PREV_WAIT_NEEDED;
  8262. return rc;
  8263. }
  8264. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8265. {
  8266. u32 reset_reg, tmp_reg = 0, rc;
  8267. bool prev_undi = false;
  8268. struct bnx2x_mac_vals mac_vals;
  8269. /* It is possible a previous function received 'common' answer,
  8270. * but hasn't loaded yet, therefore creating a scenario of
  8271. * multiple functions receiving 'common' on the same path.
  8272. */
  8273. BNX2X_DEV_INFO("Common unload Flow\n");
  8274. memset(&mac_vals, 0, sizeof(mac_vals));
  8275. if (bnx2x_prev_is_path_marked(bp))
  8276. return bnx2x_prev_mcp_done(bp);
  8277. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8278. /* Reset should be performed after BRB is emptied */
  8279. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8280. u32 timer_count = 1000;
  8281. /* Close the MAC Rx to prevent BRB from filling up */
  8282. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8283. /* close LLH filters towards the BRB */
  8284. bnx2x_set_rx_filter(&bp->link_params, 0);
  8285. /* Check if the UNDI driver was previously loaded
  8286. * UNDI driver initializes CID offset for normal bell to 0x7
  8287. */
  8288. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8289. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8290. if (tmp_reg == 0x7) {
  8291. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8292. prev_undi = true;
  8293. /* clear the UNDI indication */
  8294. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8295. /* clear possible idle check errors */
  8296. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8297. }
  8298. }
  8299. /* wait until BRB is empty */
  8300. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8301. while (timer_count) {
  8302. u32 prev_brb = tmp_reg;
  8303. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8304. if (!tmp_reg)
  8305. break;
  8306. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8307. /* reset timer as long as BRB actually gets emptied */
  8308. if (prev_brb > tmp_reg)
  8309. timer_count = 1000;
  8310. else
  8311. timer_count--;
  8312. /* If UNDI resides in memory, manually increment it */
  8313. if (prev_undi)
  8314. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8315. udelay(10);
  8316. }
  8317. if (!timer_count)
  8318. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8319. }
  8320. /* No packets are in the pipeline, path is ready for reset */
  8321. bnx2x_reset_common(bp);
  8322. if (mac_vals.xmac_addr)
  8323. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8324. if (mac_vals.umac_addr)
  8325. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8326. if (mac_vals.emac_addr)
  8327. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8328. if (mac_vals.bmac_addr) {
  8329. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8330. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8331. }
  8332. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8333. if (rc) {
  8334. bnx2x_prev_mcp_done(bp);
  8335. return rc;
  8336. }
  8337. return bnx2x_prev_mcp_done(bp);
  8338. }
  8339. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8340. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8341. * the addresses of the transaction, resulting in was-error bit set in the pci
  8342. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8343. * to clear the interrupt which detected this from the pglueb and the was done
  8344. * bit
  8345. */
  8346. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8347. {
  8348. if (!CHIP_IS_E1x(bp)) {
  8349. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8350. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8351. DP(BNX2X_MSG_SP,
  8352. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8353. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8354. 1 << BP_FUNC(bp));
  8355. }
  8356. }
  8357. }
  8358. static int bnx2x_prev_unload(struct bnx2x *bp)
  8359. {
  8360. int time_counter = 10;
  8361. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8362. struct bnx2x_prev_path_list *prev_list;
  8363. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8364. /* clear hw from errors which may have resulted from an interrupted
  8365. * dmae transaction.
  8366. */
  8367. bnx2x_prev_interrupted_dmae(bp);
  8368. /* Release previously held locks */
  8369. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8370. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8371. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8372. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8373. if (hw_lock_val) {
  8374. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8375. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8376. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8377. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8378. }
  8379. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8380. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8381. } else
  8382. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8383. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8384. BNX2X_DEV_INFO("Release previously held alr\n");
  8385. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8386. }
  8387. do {
  8388. int aer = 0;
  8389. /* Lock MCP using an unload request */
  8390. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8391. if (!fw) {
  8392. BNX2X_ERR("MCP response failure, aborting\n");
  8393. rc = -EBUSY;
  8394. break;
  8395. }
  8396. rc = down_interruptible(&bnx2x_prev_sem);
  8397. if (rc) {
  8398. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8399. rc);
  8400. } else {
  8401. /* If Path is marked by EEH, ignore unload status */
  8402. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8403. bnx2x_prev_path_get_entry(bp)->aer);
  8404. up(&bnx2x_prev_sem);
  8405. }
  8406. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8407. rc = bnx2x_prev_unload_common(bp);
  8408. break;
  8409. }
  8410. /* non-common reply from MCP night require looping */
  8411. rc = bnx2x_prev_unload_uncommon(bp);
  8412. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8413. break;
  8414. msleep(20);
  8415. } while (--time_counter);
  8416. if (!time_counter || rc) {
  8417. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8418. rc = -EBUSY;
  8419. }
  8420. /* Mark function if its port was used to boot from SAN */
  8421. prev_list = bnx2x_prev_path_get_entry(bp);
  8422. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8423. bp->link_params.feature_config_flags |=
  8424. FEATURE_CONFIG_BOOT_FROM_SAN;
  8425. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8426. return rc;
  8427. }
  8428. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8429. {
  8430. u32 val, val2, val3, val4, id, boot_mode;
  8431. u16 pmc;
  8432. /* Get the chip revision id and number. */
  8433. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8434. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8435. id = ((val & 0xffff) << 16);
  8436. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8437. id |= ((val & 0xf) << 12);
  8438. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8439. * the configuration space (so we need to reg_rd)
  8440. */
  8441. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8442. id |= (((val >> 24) & 0xf) << 4);
  8443. val = REG_RD(bp, MISC_REG_BOND_ID);
  8444. id |= (val & 0xf);
  8445. bp->common.chip_id = id;
  8446. /* force 57811 according to MISC register */
  8447. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8448. if (CHIP_IS_57810(bp))
  8449. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8450. (bp->common.chip_id & 0x0000FFFF);
  8451. else if (CHIP_IS_57810_MF(bp))
  8452. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8453. (bp->common.chip_id & 0x0000FFFF);
  8454. bp->common.chip_id |= 0x1;
  8455. }
  8456. /* Set doorbell size */
  8457. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8458. if (!CHIP_IS_E1x(bp)) {
  8459. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8460. if ((val & 1) == 0)
  8461. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8462. else
  8463. val = (val >> 1) & 1;
  8464. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8465. "2_PORT_MODE");
  8466. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8467. CHIP_2_PORT_MODE;
  8468. if (CHIP_MODE_IS_4_PORT(bp))
  8469. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8470. else
  8471. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8472. } else {
  8473. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8474. bp->pfid = bp->pf_num; /* 0..7 */
  8475. }
  8476. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8477. bp->link_params.chip_id = bp->common.chip_id;
  8478. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8479. val = (REG_RD(bp, 0x2874) & 0x55);
  8480. if ((bp->common.chip_id & 0x1) ||
  8481. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8482. bp->flags |= ONE_PORT_FLAG;
  8483. BNX2X_DEV_INFO("single port device\n");
  8484. }
  8485. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8486. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8487. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8488. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8489. bp->common.flash_size, bp->common.flash_size);
  8490. bnx2x_init_shmem(bp);
  8491. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8492. MISC_REG_GENERIC_CR_1 :
  8493. MISC_REG_GENERIC_CR_0));
  8494. bp->link_params.shmem_base = bp->common.shmem_base;
  8495. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8496. if (SHMEM2_RD(bp, size) >
  8497. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8498. bp->link_params.lfa_base =
  8499. REG_RD(bp, bp->common.shmem2_base +
  8500. (u32)offsetof(struct shmem2_region,
  8501. lfa_host_addr[BP_PORT(bp)]));
  8502. else
  8503. bp->link_params.lfa_base = 0;
  8504. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8505. bp->common.shmem_base, bp->common.shmem2_base);
  8506. if (!bp->common.shmem_base) {
  8507. BNX2X_DEV_INFO("MCP not active\n");
  8508. bp->flags |= NO_MCP_FLAG;
  8509. return;
  8510. }
  8511. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8512. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8513. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8514. SHARED_HW_CFG_LED_MODE_MASK) >>
  8515. SHARED_HW_CFG_LED_MODE_SHIFT);
  8516. bp->link_params.feature_config_flags = 0;
  8517. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8518. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8519. bp->link_params.feature_config_flags |=
  8520. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8521. else
  8522. bp->link_params.feature_config_flags &=
  8523. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8524. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8525. bp->common.bc_ver = val;
  8526. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8527. if (val < BNX2X_BC_VER) {
  8528. /* for now only warn
  8529. * later we might need to enforce this */
  8530. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8531. BNX2X_BC_VER, val);
  8532. }
  8533. bp->link_params.feature_config_flags |=
  8534. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8535. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8536. bp->link_params.feature_config_flags |=
  8537. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8538. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8539. bp->link_params.feature_config_flags |=
  8540. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8541. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8542. bp->link_params.feature_config_flags |=
  8543. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8544. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8545. bp->link_params.feature_config_flags |=
  8546. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8547. FEATURE_CONFIG_MT_SUPPORT : 0;
  8548. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8549. BC_SUPPORTS_PFC_STATS : 0;
  8550. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8551. BC_SUPPORTS_FCOE_FEATURES : 0;
  8552. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8553. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8554. boot_mode = SHMEM_RD(bp,
  8555. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8556. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8557. switch (boot_mode) {
  8558. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8559. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8560. break;
  8561. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8562. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8563. break;
  8564. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8565. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8566. break;
  8567. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8568. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8569. break;
  8570. }
  8571. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8572. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8573. BNX2X_DEV_INFO("%sWoL capable\n",
  8574. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8575. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8576. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8577. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8578. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8579. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8580. val, val2, val3, val4);
  8581. }
  8582. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8583. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8584. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8585. {
  8586. int pfid = BP_FUNC(bp);
  8587. int igu_sb_id;
  8588. u32 val;
  8589. u8 fid, igu_sb_cnt = 0;
  8590. bp->igu_base_sb = 0xff;
  8591. if (CHIP_INT_MODE_IS_BC(bp)) {
  8592. int vn = BP_VN(bp);
  8593. igu_sb_cnt = bp->igu_sb_cnt;
  8594. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8595. FP_SB_MAX_E1x;
  8596. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8597. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8598. return 0;
  8599. }
  8600. /* IGU in normal mode - read CAM */
  8601. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8602. igu_sb_id++) {
  8603. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8604. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8605. continue;
  8606. fid = IGU_FID(val);
  8607. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8608. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8609. continue;
  8610. if (IGU_VEC(val) == 0)
  8611. /* default status block */
  8612. bp->igu_dsb_id = igu_sb_id;
  8613. else {
  8614. if (bp->igu_base_sb == 0xff)
  8615. bp->igu_base_sb = igu_sb_id;
  8616. igu_sb_cnt++;
  8617. }
  8618. }
  8619. }
  8620. #ifdef CONFIG_PCI_MSI
  8621. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8622. * optional that number of CAM entries will not be equal to the value
  8623. * advertised in PCI.
  8624. * Driver should use the minimal value of both as the actual status
  8625. * block count
  8626. */
  8627. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8628. #endif
  8629. if (igu_sb_cnt == 0) {
  8630. BNX2X_ERR("CAM configuration error\n");
  8631. return -EINVAL;
  8632. }
  8633. return 0;
  8634. }
  8635. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8636. {
  8637. int cfg_size = 0, idx, port = BP_PORT(bp);
  8638. /* Aggregation of supported attributes of all external phys */
  8639. bp->port.supported[0] = 0;
  8640. bp->port.supported[1] = 0;
  8641. switch (bp->link_params.num_phys) {
  8642. case 1:
  8643. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8644. cfg_size = 1;
  8645. break;
  8646. case 2:
  8647. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8648. cfg_size = 1;
  8649. break;
  8650. case 3:
  8651. if (bp->link_params.multi_phy_config &
  8652. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8653. bp->port.supported[1] =
  8654. bp->link_params.phy[EXT_PHY1].supported;
  8655. bp->port.supported[0] =
  8656. bp->link_params.phy[EXT_PHY2].supported;
  8657. } else {
  8658. bp->port.supported[0] =
  8659. bp->link_params.phy[EXT_PHY1].supported;
  8660. bp->port.supported[1] =
  8661. bp->link_params.phy[EXT_PHY2].supported;
  8662. }
  8663. cfg_size = 2;
  8664. break;
  8665. }
  8666. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8667. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8668. SHMEM_RD(bp,
  8669. dev_info.port_hw_config[port].external_phy_config),
  8670. SHMEM_RD(bp,
  8671. dev_info.port_hw_config[port].external_phy_config2));
  8672. return;
  8673. }
  8674. if (CHIP_IS_E3(bp))
  8675. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8676. else {
  8677. switch (switch_cfg) {
  8678. case SWITCH_CFG_1G:
  8679. bp->port.phy_addr = REG_RD(
  8680. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8681. break;
  8682. case SWITCH_CFG_10G:
  8683. bp->port.phy_addr = REG_RD(
  8684. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8685. break;
  8686. default:
  8687. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8688. bp->port.link_config[0]);
  8689. return;
  8690. }
  8691. }
  8692. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8693. /* mask what we support according to speed_cap_mask per configuration */
  8694. for (idx = 0; idx < cfg_size; idx++) {
  8695. if (!(bp->link_params.speed_cap_mask[idx] &
  8696. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8697. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8698. if (!(bp->link_params.speed_cap_mask[idx] &
  8699. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8700. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8701. if (!(bp->link_params.speed_cap_mask[idx] &
  8702. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8703. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8704. if (!(bp->link_params.speed_cap_mask[idx] &
  8705. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8706. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8707. if (!(bp->link_params.speed_cap_mask[idx] &
  8708. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8709. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8710. SUPPORTED_1000baseT_Full);
  8711. if (!(bp->link_params.speed_cap_mask[idx] &
  8712. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8713. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8714. if (!(bp->link_params.speed_cap_mask[idx] &
  8715. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8716. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8717. }
  8718. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8719. bp->port.supported[1]);
  8720. }
  8721. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8722. {
  8723. u32 link_config, idx, cfg_size = 0;
  8724. bp->port.advertising[0] = 0;
  8725. bp->port.advertising[1] = 0;
  8726. switch (bp->link_params.num_phys) {
  8727. case 1:
  8728. case 2:
  8729. cfg_size = 1;
  8730. break;
  8731. case 3:
  8732. cfg_size = 2;
  8733. break;
  8734. }
  8735. for (idx = 0; idx < cfg_size; idx++) {
  8736. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8737. link_config = bp->port.link_config[idx];
  8738. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8739. case PORT_FEATURE_LINK_SPEED_AUTO:
  8740. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8741. bp->link_params.req_line_speed[idx] =
  8742. SPEED_AUTO_NEG;
  8743. bp->port.advertising[idx] |=
  8744. bp->port.supported[idx];
  8745. if (bp->link_params.phy[EXT_PHY1].type ==
  8746. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8747. bp->port.advertising[idx] |=
  8748. (SUPPORTED_100baseT_Half |
  8749. SUPPORTED_100baseT_Full);
  8750. } else {
  8751. /* force 10G, no AN */
  8752. bp->link_params.req_line_speed[idx] =
  8753. SPEED_10000;
  8754. bp->port.advertising[idx] |=
  8755. (ADVERTISED_10000baseT_Full |
  8756. ADVERTISED_FIBRE);
  8757. continue;
  8758. }
  8759. break;
  8760. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8761. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8762. bp->link_params.req_line_speed[idx] =
  8763. SPEED_10;
  8764. bp->port.advertising[idx] |=
  8765. (ADVERTISED_10baseT_Full |
  8766. ADVERTISED_TP);
  8767. } else {
  8768. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8769. link_config,
  8770. bp->link_params.speed_cap_mask[idx]);
  8771. return;
  8772. }
  8773. break;
  8774. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8775. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8776. bp->link_params.req_line_speed[idx] =
  8777. SPEED_10;
  8778. bp->link_params.req_duplex[idx] =
  8779. DUPLEX_HALF;
  8780. bp->port.advertising[idx] |=
  8781. (ADVERTISED_10baseT_Half |
  8782. ADVERTISED_TP);
  8783. } else {
  8784. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8785. link_config,
  8786. bp->link_params.speed_cap_mask[idx]);
  8787. return;
  8788. }
  8789. break;
  8790. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8791. if (bp->port.supported[idx] &
  8792. SUPPORTED_100baseT_Full) {
  8793. bp->link_params.req_line_speed[idx] =
  8794. SPEED_100;
  8795. bp->port.advertising[idx] |=
  8796. (ADVERTISED_100baseT_Full |
  8797. ADVERTISED_TP);
  8798. } else {
  8799. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8800. link_config,
  8801. bp->link_params.speed_cap_mask[idx]);
  8802. return;
  8803. }
  8804. break;
  8805. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8806. if (bp->port.supported[idx] &
  8807. SUPPORTED_100baseT_Half) {
  8808. bp->link_params.req_line_speed[idx] =
  8809. SPEED_100;
  8810. bp->link_params.req_duplex[idx] =
  8811. DUPLEX_HALF;
  8812. bp->port.advertising[idx] |=
  8813. (ADVERTISED_100baseT_Half |
  8814. ADVERTISED_TP);
  8815. } else {
  8816. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8817. link_config,
  8818. bp->link_params.speed_cap_mask[idx]);
  8819. return;
  8820. }
  8821. break;
  8822. case PORT_FEATURE_LINK_SPEED_1G:
  8823. if (bp->port.supported[idx] &
  8824. SUPPORTED_1000baseT_Full) {
  8825. bp->link_params.req_line_speed[idx] =
  8826. SPEED_1000;
  8827. bp->port.advertising[idx] |=
  8828. (ADVERTISED_1000baseT_Full |
  8829. ADVERTISED_TP);
  8830. } else {
  8831. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8832. link_config,
  8833. bp->link_params.speed_cap_mask[idx]);
  8834. return;
  8835. }
  8836. break;
  8837. case PORT_FEATURE_LINK_SPEED_2_5G:
  8838. if (bp->port.supported[idx] &
  8839. SUPPORTED_2500baseX_Full) {
  8840. bp->link_params.req_line_speed[idx] =
  8841. SPEED_2500;
  8842. bp->port.advertising[idx] |=
  8843. (ADVERTISED_2500baseX_Full |
  8844. ADVERTISED_TP);
  8845. } else {
  8846. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8847. link_config,
  8848. bp->link_params.speed_cap_mask[idx]);
  8849. return;
  8850. }
  8851. break;
  8852. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8853. if (bp->port.supported[idx] &
  8854. SUPPORTED_10000baseT_Full) {
  8855. bp->link_params.req_line_speed[idx] =
  8856. SPEED_10000;
  8857. bp->port.advertising[idx] |=
  8858. (ADVERTISED_10000baseT_Full |
  8859. ADVERTISED_FIBRE);
  8860. } else {
  8861. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8862. link_config,
  8863. bp->link_params.speed_cap_mask[idx]);
  8864. return;
  8865. }
  8866. break;
  8867. case PORT_FEATURE_LINK_SPEED_20G:
  8868. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8869. break;
  8870. default:
  8871. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8872. link_config);
  8873. bp->link_params.req_line_speed[idx] =
  8874. SPEED_AUTO_NEG;
  8875. bp->port.advertising[idx] =
  8876. bp->port.supported[idx];
  8877. break;
  8878. }
  8879. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8880. PORT_FEATURE_FLOW_CONTROL_MASK);
  8881. if (bp->link_params.req_flow_ctrl[idx] ==
  8882. BNX2X_FLOW_CTRL_AUTO) {
  8883. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8884. bp->link_params.req_flow_ctrl[idx] =
  8885. BNX2X_FLOW_CTRL_NONE;
  8886. else
  8887. bnx2x_set_requested_fc(bp);
  8888. }
  8889. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8890. bp->link_params.req_line_speed[idx],
  8891. bp->link_params.req_duplex[idx],
  8892. bp->link_params.req_flow_ctrl[idx],
  8893. bp->port.advertising[idx]);
  8894. }
  8895. }
  8896. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8897. {
  8898. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  8899. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  8900. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  8901. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  8902. }
  8903. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8904. {
  8905. int port = BP_PORT(bp);
  8906. u32 config;
  8907. u32 ext_phy_type, ext_phy_config, eee_mode;
  8908. bp->link_params.bp = bp;
  8909. bp->link_params.port = port;
  8910. bp->link_params.lane_config =
  8911. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8912. bp->link_params.speed_cap_mask[0] =
  8913. SHMEM_RD(bp,
  8914. dev_info.port_hw_config[port].speed_capability_mask);
  8915. bp->link_params.speed_cap_mask[1] =
  8916. SHMEM_RD(bp,
  8917. dev_info.port_hw_config[port].speed_capability_mask2);
  8918. bp->port.link_config[0] =
  8919. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8920. bp->port.link_config[1] =
  8921. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8922. bp->link_params.multi_phy_config =
  8923. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8924. /* If the device is capable of WoL, set the default state according
  8925. * to the HW
  8926. */
  8927. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8928. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8929. (config & PORT_FEATURE_WOL_ENABLED));
  8930. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8931. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8932. bp->flags |= NO_ISCSI_FLAG;
  8933. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8934. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8935. bp->flags |= NO_FCOE_FLAG;
  8936. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8937. bp->link_params.lane_config,
  8938. bp->link_params.speed_cap_mask[0],
  8939. bp->port.link_config[0]);
  8940. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8941. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8942. bnx2x_phy_probe(&bp->link_params);
  8943. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8944. bnx2x_link_settings_requested(bp);
  8945. /*
  8946. * If connected directly, work with the internal PHY, otherwise, work
  8947. * with the external PHY
  8948. */
  8949. ext_phy_config =
  8950. SHMEM_RD(bp,
  8951. dev_info.port_hw_config[port].external_phy_config);
  8952. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8953. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8954. bp->mdio.prtad = bp->port.phy_addr;
  8955. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8956. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8957. bp->mdio.prtad =
  8958. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8959. /* Configure link feature according to nvram value */
  8960. eee_mode = (((SHMEM_RD(bp, dev_info.
  8961. port_feature_config[port].eee_power_mode)) &
  8962. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8963. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8964. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8965. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8966. EEE_MODE_ENABLE_LPI |
  8967. EEE_MODE_OUTPUT_TIME;
  8968. } else {
  8969. bp->link_params.eee_mode = 0;
  8970. }
  8971. }
  8972. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8973. {
  8974. u32 no_flags = NO_ISCSI_FLAG;
  8975. int port = BP_PORT(bp);
  8976. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8977. drv_lic_key[port].max_iscsi_conn);
  8978. if (!CNIC_SUPPORT(bp)) {
  8979. bp->flags |= no_flags;
  8980. return;
  8981. }
  8982. /* Get the number of maximum allowed iSCSI connections */
  8983. bp->cnic_eth_dev.max_iscsi_conn =
  8984. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8985. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8986. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8987. bp->cnic_eth_dev.max_iscsi_conn);
  8988. /*
  8989. * If maximum allowed number of connections is zero -
  8990. * disable the feature.
  8991. */
  8992. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8993. bp->flags |= no_flags;
  8994. }
  8995. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8996. {
  8997. /* Port info */
  8998. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8999. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9000. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9001. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9002. /* Node info */
  9003. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9004. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9005. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9006. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9007. }
  9008. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9009. {
  9010. int port = BP_PORT(bp);
  9011. int func = BP_ABS_FUNC(bp);
  9012. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9013. drv_lic_key[port].max_fcoe_conn);
  9014. if (!CNIC_SUPPORT(bp)) {
  9015. bp->flags |= NO_FCOE_FLAG;
  9016. return;
  9017. }
  9018. /* Get the number of maximum allowed FCoE connections */
  9019. bp->cnic_eth_dev.max_fcoe_conn =
  9020. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9021. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9022. /* Read the WWN: */
  9023. if (!IS_MF(bp)) {
  9024. /* Port info */
  9025. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9026. SHMEM_RD(bp,
  9027. dev_info.port_hw_config[port].
  9028. fcoe_wwn_port_name_upper);
  9029. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9030. SHMEM_RD(bp,
  9031. dev_info.port_hw_config[port].
  9032. fcoe_wwn_port_name_lower);
  9033. /* Node info */
  9034. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9035. SHMEM_RD(bp,
  9036. dev_info.port_hw_config[port].
  9037. fcoe_wwn_node_name_upper);
  9038. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9039. SHMEM_RD(bp,
  9040. dev_info.port_hw_config[port].
  9041. fcoe_wwn_node_name_lower);
  9042. } else if (!IS_MF_SD(bp)) {
  9043. /*
  9044. * Read the WWN info only if the FCoE feature is enabled for
  9045. * this function.
  9046. */
  9047. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9048. bnx2x_get_ext_wwn_info(bp, func);
  9049. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9050. bnx2x_get_ext_wwn_info(bp, func);
  9051. }
  9052. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9053. /*
  9054. * If maximum allowed number of connections is zero -
  9055. * disable the feature.
  9056. */
  9057. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9058. bp->flags |= NO_FCOE_FLAG;
  9059. }
  9060. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9061. {
  9062. /*
  9063. * iSCSI may be dynamically disabled but reading
  9064. * info here we will decrease memory usage by driver
  9065. * if the feature is disabled for good
  9066. */
  9067. bnx2x_get_iscsi_info(bp);
  9068. bnx2x_get_fcoe_info(bp);
  9069. }
  9070. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9071. {
  9072. u32 val, val2;
  9073. int func = BP_ABS_FUNC(bp);
  9074. int port = BP_PORT(bp);
  9075. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9076. u8 *fip_mac = bp->fip_mac;
  9077. if (IS_MF(bp)) {
  9078. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9079. * FCoE MAC then the appropriate feature should be disabled.
  9080. * In non SD mode features configuration comes from struct
  9081. * func_ext_config.
  9082. */
  9083. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9084. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9085. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9086. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9087. iscsi_mac_addr_upper);
  9088. val = MF_CFG_RD(bp, func_ext_config[func].
  9089. iscsi_mac_addr_lower);
  9090. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9091. BNX2X_DEV_INFO
  9092. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9093. } else {
  9094. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9095. }
  9096. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9097. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9098. fcoe_mac_addr_upper);
  9099. val = MF_CFG_RD(bp, func_ext_config[func].
  9100. fcoe_mac_addr_lower);
  9101. bnx2x_set_mac_buf(fip_mac, val, val2);
  9102. BNX2X_DEV_INFO
  9103. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9104. } else {
  9105. bp->flags |= NO_FCOE_FLAG;
  9106. }
  9107. bp->mf_ext_config = cfg;
  9108. } else { /* SD MODE */
  9109. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9110. /* use primary mac as iscsi mac */
  9111. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9112. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9113. BNX2X_DEV_INFO
  9114. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9115. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9116. /* use primary mac as fip mac */
  9117. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9118. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9119. BNX2X_DEV_INFO
  9120. ("Read FIP MAC: %pM\n", fip_mac);
  9121. }
  9122. }
  9123. /* If this is a storage-only interface, use SAN mac as
  9124. * primary MAC. Notice that for SD this is already the case,
  9125. * as the SAN mac was copied from the primary MAC.
  9126. */
  9127. if (IS_MF_FCOE_AFEX(bp))
  9128. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9129. } else {
  9130. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9131. iscsi_mac_upper);
  9132. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9133. iscsi_mac_lower);
  9134. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9135. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9136. fcoe_fip_mac_upper);
  9137. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9138. fcoe_fip_mac_lower);
  9139. bnx2x_set_mac_buf(fip_mac, val, val2);
  9140. }
  9141. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9142. if (!is_valid_ether_addr(iscsi_mac)) {
  9143. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9144. memset(iscsi_mac, 0, ETH_ALEN);
  9145. }
  9146. /* Disable FCoE if MAC configuration is invalid. */
  9147. if (!is_valid_ether_addr(fip_mac)) {
  9148. bp->flags |= NO_FCOE_FLAG;
  9149. memset(bp->fip_mac, 0, ETH_ALEN);
  9150. }
  9151. }
  9152. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9153. {
  9154. u32 val, val2;
  9155. int func = BP_ABS_FUNC(bp);
  9156. int port = BP_PORT(bp);
  9157. /* Zero primary MAC configuration */
  9158. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9159. if (BP_NOMCP(bp)) {
  9160. BNX2X_ERROR("warning: random MAC workaround active\n");
  9161. eth_hw_addr_random(bp->dev);
  9162. } else if (IS_MF(bp)) {
  9163. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9164. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9165. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9166. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9167. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9168. if (CNIC_SUPPORT(bp))
  9169. bnx2x_get_cnic_mac_hwinfo(bp);
  9170. } else {
  9171. /* in SF read MACs from port configuration */
  9172. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9173. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9174. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9175. if (CNIC_SUPPORT(bp))
  9176. bnx2x_get_cnic_mac_hwinfo(bp);
  9177. }
  9178. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9179. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9180. dev_err(&bp->pdev->dev,
  9181. "bad Ethernet MAC address configuration: %pM\n"
  9182. "change it manually before bringing up the appropriate network interface\n",
  9183. bp->dev->dev_addr);
  9184. }
  9185. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9186. {
  9187. int tmp;
  9188. u32 cfg;
  9189. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9190. /* Take function: tmp = func */
  9191. tmp = BP_ABS_FUNC(bp);
  9192. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9193. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9194. } else {
  9195. /* Take port: tmp = port */
  9196. tmp = BP_PORT(bp);
  9197. cfg = SHMEM_RD(bp,
  9198. dev_info.port_hw_config[tmp].generic_features);
  9199. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9200. }
  9201. return cfg;
  9202. }
  9203. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9204. {
  9205. int /*abs*/func = BP_ABS_FUNC(bp);
  9206. int vn;
  9207. u32 val = 0;
  9208. int rc = 0;
  9209. bnx2x_get_common_hwinfo(bp);
  9210. /*
  9211. * initialize IGU parameters
  9212. */
  9213. if (CHIP_IS_E1x(bp)) {
  9214. bp->common.int_block = INT_BLOCK_HC;
  9215. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9216. bp->igu_base_sb = 0;
  9217. } else {
  9218. bp->common.int_block = INT_BLOCK_IGU;
  9219. /* do not allow device reset during IGU info preocessing */
  9220. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9221. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9222. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9223. int tout = 5000;
  9224. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9225. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9226. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9227. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9228. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9229. tout--;
  9230. usleep_range(1000, 2000);
  9231. }
  9232. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9233. dev_err(&bp->pdev->dev,
  9234. "FORCING Normal Mode failed!!!\n");
  9235. bnx2x_release_hw_lock(bp,
  9236. HW_LOCK_RESOURCE_RESET);
  9237. return -EPERM;
  9238. }
  9239. }
  9240. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9241. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9242. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9243. } else
  9244. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9245. rc = bnx2x_get_igu_cam_info(bp);
  9246. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9247. if (rc)
  9248. return rc;
  9249. }
  9250. /*
  9251. * set base FW non-default (fast path) status block id, this value is
  9252. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9253. * determine the id used by the FW.
  9254. */
  9255. if (CHIP_IS_E1x(bp))
  9256. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9257. else /*
  9258. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9259. * the same queue are indicated on the same IGU SB). So we prefer
  9260. * FW and IGU SBs to be the same value.
  9261. */
  9262. bp->base_fw_ndsb = bp->igu_base_sb;
  9263. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9264. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9265. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9266. /*
  9267. * Initialize MF configuration
  9268. */
  9269. bp->mf_ov = 0;
  9270. bp->mf_mode = 0;
  9271. vn = BP_VN(bp);
  9272. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9273. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9274. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9275. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9276. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9277. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9278. else
  9279. bp->common.mf_cfg_base = bp->common.shmem_base +
  9280. offsetof(struct shmem_region, func_mb) +
  9281. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9282. /*
  9283. * get mf configuration:
  9284. * 1. existence of MF configuration
  9285. * 2. MAC address must be legal (check only upper bytes)
  9286. * for Switch-Independent mode;
  9287. * OVLAN must be legal for Switch-Dependent mode
  9288. * 3. SF_MODE configures specific MF mode
  9289. */
  9290. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9291. /* get mf configuration */
  9292. val = SHMEM_RD(bp,
  9293. dev_info.shared_feature_config.config);
  9294. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9295. switch (val) {
  9296. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9297. val = MF_CFG_RD(bp, func_mf_config[func].
  9298. mac_upper);
  9299. /* check for legal mac (upper bytes)*/
  9300. if (val != 0xffff) {
  9301. bp->mf_mode = MULTI_FUNCTION_SI;
  9302. bp->mf_config[vn] = MF_CFG_RD(bp,
  9303. func_mf_config[func].config);
  9304. } else
  9305. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9306. break;
  9307. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9308. if ((!CHIP_IS_E1x(bp)) &&
  9309. (MF_CFG_RD(bp, func_mf_config[func].
  9310. mac_upper) != 0xffff) &&
  9311. (SHMEM2_HAS(bp,
  9312. afex_driver_support))) {
  9313. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9314. bp->mf_config[vn] = MF_CFG_RD(bp,
  9315. func_mf_config[func].config);
  9316. } else {
  9317. BNX2X_DEV_INFO("can not configure afex mode\n");
  9318. }
  9319. break;
  9320. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9321. /* get OV configuration */
  9322. val = MF_CFG_RD(bp,
  9323. func_mf_config[FUNC_0].e1hov_tag);
  9324. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9325. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9326. bp->mf_mode = MULTI_FUNCTION_SD;
  9327. bp->mf_config[vn] = MF_CFG_RD(bp,
  9328. func_mf_config[func].config);
  9329. } else
  9330. BNX2X_DEV_INFO("illegal OV for SD\n");
  9331. break;
  9332. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9333. bp->mf_config[vn] = 0;
  9334. break;
  9335. default:
  9336. /* Unknown configuration: reset mf_config */
  9337. bp->mf_config[vn] = 0;
  9338. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9339. }
  9340. }
  9341. BNX2X_DEV_INFO("%s function mode\n",
  9342. IS_MF(bp) ? "multi" : "single");
  9343. switch (bp->mf_mode) {
  9344. case MULTI_FUNCTION_SD:
  9345. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9346. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9347. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9348. bp->mf_ov = val;
  9349. bp->path_has_ovlan = true;
  9350. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9351. func, bp->mf_ov, bp->mf_ov);
  9352. } else {
  9353. dev_err(&bp->pdev->dev,
  9354. "No valid MF OV for func %d, aborting\n",
  9355. func);
  9356. return -EPERM;
  9357. }
  9358. break;
  9359. case MULTI_FUNCTION_AFEX:
  9360. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9361. break;
  9362. case MULTI_FUNCTION_SI:
  9363. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9364. func);
  9365. break;
  9366. default:
  9367. if (vn) {
  9368. dev_err(&bp->pdev->dev,
  9369. "VN %d is in a single function mode, aborting\n",
  9370. vn);
  9371. return -EPERM;
  9372. }
  9373. break;
  9374. }
  9375. /* check if other port on the path needs ovlan:
  9376. * Since MF configuration is shared between ports
  9377. * Possible mixed modes are only
  9378. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9379. */
  9380. if (CHIP_MODE_IS_4_PORT(bp) &&
  9381. !bp->path_has_ovlan &&
  9382. !IS_MF(bp) &&
  9383. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9384. u8 other_port = !BP_PORT(bp);
  9385. u8 other_func = BP_PATH(bp) + 2*other_port;
  9386. val = MF_CFG_RD(bp,
  9387. func_mf_config[other_func].e1hov_tag);
  9388. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9389. bp->path_has_ovlan = true;
  9390. }
  9391. }
  9392. /* adjust igu_sb_cnt to MF for E1x */
  9393. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9394. bp->igu_sb_cnt /= E1HVN_MAX;
  9395. /* port info */
  9396. bnx2x_get_port_hwinfo(bp);
  9397. /* Get MAC addresses */
  9398. bnx2x_get_mac_hwinfo(bp);
  9399. bnx2x_get_cnic_info(bp);
  9400. return rc;
  9401. }
  9402. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9403. {
  9404. int cnt, i, block_end, rodi;
  9405. char vpd_start[BNX2X_VPD_LEN+1];
  9406. char str_id_reg[VENDOR_ID_LEN+1];
  9407. char str_id_cap[VENDOR_ID_LEN+1];
  9408. char *vpd_data;
  9409. char *vpd_extended_data = NULL;
  9410. u8 len;
  9411. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9412. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9413. if (cnt < BNX2X_VPD_LEN)
  9414. goto out_not_found;
  9415. /* VPD RO tag should be first tag after identifier string, hence
  9416. * we should be able to find it in first BNX2X_VPD_LEN chars
  9417. */
  9418. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9419. PCI_VPD_LRDT_RO_DATA);
  9420. if (i < 0)
  9421. goto out_not_found;
  9422. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9423. pci_vpd_lrdt_size(&vpd_start[i]);
  9424. i += PCI_VPD_LRDT_TAG_SIZE;
  9425. if (block_end > BNX2X_VPD_LEN) {
  9426. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9427. if (vpd_extended_data == NULL)
  9428. goto out_not_found;
  9429. /* read rest of vpd image into vpd_extended_data */
  9430. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9431. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9432. block_end - BNX2X_VPD_LEN,
  9433. vpd_extended_data + BNX2X_VPD_LEN);
  9434. if (cnt < (block_end - BNX2X_VPD_LEN))
  9435. goto out_not_found;
  9436. vpd_data = vpd_extended_data;
  9437. } else
  9438. vpd_data = vpd_start;
  9439. /* now vpd_data holds full vpd content in both cases */
  9440. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9441. PCI_VPD_RO_KEYWORD_MFR_ID);
  9442. if (rodi < 0)
  9443. goto out_not_found;
  9444. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9445. if (len != VENDOR_ID_LEN)
  9446. goto out_not_found;
  9447. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9448. /* vendor specific info */
  9449. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9450. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9451. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9452. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9453. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9454. PCI_VPD_RO_KEYWORD_VENDOR0);
  9455. if (rodi >= 0) {
  9456. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9457. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9458. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9459. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9460. bp->fw_ver[len] = ' ';
  9461. }
  9462. }
  9463. kfree(vpd_extended_data);
  9464. return;
  9465. }
  9466. out_not_found:
  9467. kfree(vpd_extended_data);
  9468. return;
  9469. }
  9470. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9471. {
  9472. u32 flags = 0;
  9473. if (CHIP_REV_IS_FPGA(bp))
  9474. SET_FLAGS(flags, MODE_FPGA);
  9475. else if (CHIP_REV_IS_EMUL(bp))
  9476. SET_FLAGS(flags, MODE_EMUL);
  9477. else
  9478. SET_FLAGS(flags, MODE_ASIC);
  9479. if (CHIP_MODE_IS_4_PORT(bp))
  9480. SET_FLAGS(flags, MODE_PORT4);
  9481. else
  9482. SET_FLAGS(flags, MODE_PORT2);
  9483. if (CHIP_IS_E2(bp))
  9484. SET_FLAGS(flags, MODE_E2);
  9485. else if (CHIP_IS_E3(bp)) {
  9486. SET_FLAGS(flags, MODE_E3);
  9487. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9488. SET_FLAGS(flags, MODE_E3_A0);
  9489. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9490. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9491. }
  9492. if (IS_MF(bp)) {
  9493. SET_FLAGS(flags, MODE_MF);
  9494. switch (bp->mf_mode) {
  9495. case MULTI_FUNCTION_SD:
  9496. SET_FLAGS(flags, MODE_MF_SD);
  9497. break;
  9498. case MULTI_FUNCTION_SI:
  9499. SET_FLAGS(flags, MODE_MF_SI);
  9500. break;
  9501. case MULTI_FUNCTION_AFEX:
  9502. SET_FLAGS(flags, MODE_MF_AFEX);
  9503. break;
  9504. }
  9505. } else
  9506. SET_FLAGS(flags, MODE_SF);
  9507. #if defined(__LITTLE_ENDIAN)
  9508. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9509. #else /*(__BIG_ENDIAN)*/
  9510. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9511. #endif
  9512. INIT_MODE_FLAGS(bp) = flags;
  9513. }
  9514. static int bnx2x_init_bp(struct bnx2x *bp)
  9515. {
  9516. int func;
  9517. int rc;
  9518. mutex_init(&bp->port.phy_mutex);
  9519. mutex_init(&bp->fw_mb_mutex);
  9520. spin_lock_init(&bp->stats_lock);
  9521. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9522. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9523. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9524. if (IS_PF(bp)) {
  9525. rc = bnx2x_get_hwinfo(bp);
  9526. if (rc)
  9527. return rc;
  9528. } else {
  9529. random_ether_addr(bp->dev->dev_addr);
  9530. }
  9531. bnx2x_set_modes_bitmap(bp);
  9532. rc = bnx2x_alloc_mem_bp(bp);
  9533. if (rc)
  9534. return rc;
  9535. bnx2x_read_fwinfo(bp);
  9536. func = BP_FUNC(bp);
  9537. /* need to reset chip if undi was active */
  9538. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9539. /* init fw_seq */
  9540. bp->fw_seq =
  9541. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9542. DRV_MSG_SEQ_NUMBER_MASK;
  9543. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9544. bnx2x_prev_unload(bp);
  9545. }
  9546. if (CHIP_REV_IS_FPGA(bp))
  9547. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9548. if (BP_NOMCP(bp) && (func == 0))
  9549. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9550. bp->disable_tpa = disable_tpa;
  9551. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9552. /* Set TPA flags */
  9553. if (bp->disable_tpa) {
  9554. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9555. bp->dev->features &= ~NETIF_F_LRO;
  9556. } else {
  9557. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9558. bp->dev->features |= NETIF_F_LRO;
  9559. }
  9560. if (CHIP_IS_E1(bp))
  9561. bp->dropless_fc = 0;
  9562. else
  9563. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9564. bp->mrrs = mrrs;
  9565. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9566. if (IS_VF(bp))
  9567. bp->rx_ring_size = MAX_RX_AVAIL;
  9568. /* make sure that the numbers are in the right granularity */
  9569. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9570. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9571. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9572. init_timer(&bp->timer);
  9573. bp->timer.expires = jiffies + bp->current_interval;
  9574. bp->timer.data = (unsigned long) bp;
  9575. bp->timer.function = bnx2x_timer;
  9576. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9577. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9578. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9579. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9580. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9581. bnx2x_dcbx_init_params(bp);
  9582. } else {
  9583. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9584. }
  9585. if (CHIP_IS_E1x(bp))
  9586. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9587. else
  9588. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9589. /* multiple tx priority */
  9590. if (IS_VF(bp))
  9591. bp->max_cos = 1;
  9592. else if (CHIP_IS_E1x(bp))
  9593. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9594. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9595. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9596. else if (CHIP_IS_E3B0(bp))
  9597. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9598. else
  9599. BNX2X_ERR("unknown chip %x revision %x\n",
  9600. CHIP_NUM(bp), CHIP_REV(bp));
  9601. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9602. /* We need at least one default status block for slow-path events,
  9603. * second status block for the L2 queue, and a third status block for
  9604. * CNIC if supproted.
  9605. */
  9606. if (CNIC_SUPPORT(bp))
  9607. bp->min_msix_vec_cnt = 3;
  9608. else
  9609. bp->min_msix_vec_cnt = 2;
  9610. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9611. return rc;
  9612. }
  9613. /****************************************************************************
  9614. * General service functions
  9615. ****************************************************************************/
  9616. /*
  9617. * net_device service functions
  9618. */
  9619. /* called with rtnl_lock */
  9620. static int bnx2x_open(struct net_device *dev)
  9621. {
  9622. struct bnx2x *bp = netdev_priv(dev);
  9623. bool global = false;
  9624. int other_engine = BP_PATH(bp) ? 0 : 1;
  9625. bool other_load_status, load_status;
  9626. int rc;
  9627. bp->stats_init = true;
  9628. netif_carrier_off(dev);
  9629. bnx2x_set_power_state(bp, PCI_D0);
  9630. /* If parity had happen during the unload, then attentions
  9631. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9632. * want the first function loaded on the current engine to
  9633. * complete the recovery.
  9634. * Parity recovery is only relevant for PF driver.
  9635. */
  9636. if (IS_PF(bp)) {
  9637. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9638. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9639. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9640. bnx2x_chk_parity_attn(bp, &global, true)) {
  9641. do {
  9642. /* If there are attentions and they are in a
  9643. * global blocks, set the GLOBAL_RESET bit
  9644. * regardless whether it will be this function
  9645. * that will complete the recovery or not.
  9646. */
  9647. if (global)
  9648. bnx2x_set_reset_global(bp);
  9649. /* Only the first function on the current
  9650. * engine should try to recover in open. In case
  9651. * of attentions in global blocks only the first
  9652. * in the chip should try to recover.
  9653. */
  9654. if ((!load_status &&
  9655. (!global || !other_load_status)) &&
  9656. bnx2x_trylock_leader_lock(bp) &&
  9657. !bnx2x_leader_reset(bp)) {
  9658. netdev_info(bp->dev,
  9659. "Recovered in open\n");
  9660. break;
  9661. }
  9662. /* recovery has failed... */
  9663. bnx2x_set_power_state(bp, PCI_D3hot);
  9664. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9665. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9666. "If you still see this message after a few retries then power cycle is required.\n");
  9667. return -EAGAIN;
  9668. } while (0);
  9669. }
  9670. }
  9671. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9672. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9673. if (rc)
  9674. return rc;
  9675. return bnx2x_open_epilog(bp);
  9676. }
  9677. /* called with rtnl_lock */
  9678. static int bnx2x_close(struct net_device *dev)
  9679. {
  9680. struct bnx2x *bp = netdev_priv(dev);
  9681. /* Unload the driver, release IRQs */
  9682. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9683. /* Power off */
  9684. bnx2x_set_power_state(bp, PCI_D3hot);
  9685. return 0;
  9686. }
  9687. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9688. struct bnx2x_mcast_ramrod_params *p)
  9689. {
  9690. int mc_count = netdev_mc_count(bp->dev);
  9691. struct bnx2x_mcast_list_elem *mc_mac =
  9692. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9693. struct netdev_hw_addr *ha;
  9694. if (!mc_mac)
  9695. return -ENOMEM;
  9696. INIT_LIST_HEAD(&p->mcast_list);
  9697. netdev_for_each_mc_addr(ha, bp->dev) {
  9698. mc_mac->mac = bnx2x_mc_addr(ha);
  9699. list_add_tail(&mc_mac->link, &p->mcast_list);
  9700. mc_mac++;
  9701. }
  9702. p->mcast_list_len = mc_count;
  9703. return 0;
  9704. }
  9705. static void bnx2x_free_mcast_macs_list(
  9706. struct bnx2x_mcast_ramrod_params *p)
  9707. {
  9708. struct bnx2x_mcast_list_elem *mc_mac =
  9709. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9710. link);
  9711. WARN_ON(!mc_mac);
  9712. kfree(mc_mac);
  9713. }
  9714. /**
  9715. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9716. *
  9717. * @bp: driver handle
  9718. *
  9719. * We will use zero (0) as a MAC type for these MACs.
  9720. */
  9721. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9722. {
  9723. int rc;
  9724. struct net_device *dev = bp->dev;
  9725. struct netdev_hw_addr *ha;
  9726. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9727. unsigned long ramrod_flags = 0;
  9728. /* First schedule a cleanup up of old configuration */
  9729. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9730. if (rc < 0) {
  9731. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9732. return rc;
  9733. }
  9734. netdev_for_each_uc_addr(ha, dev) {
  9735. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9736. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9737. if (rc == -EEXIST) {
  9738. DP(BNX2X_MSG_SP,
  9739. "Failed to schedule ADD operations: %d\n", rc);
  9740. /* do not treat adding same MAC as error */
  9741. rc = 0;
  9742. } else if (rc < 0) {
  9743. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9744. rc);
  9745. return rc;
  9746. }
  9747. }
  9748. /* Execute the pending commands */
  9749. __set_bit(RAMROD_CONT, &ramrod_flags);
  9750. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9751. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9752. }
  9753. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9754. {
  9755. struct net_device *dev = bp->dev;
  9756. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9757. int rc = 0;
  9758. rparam.mcast_obj = &bp->mcast_obj;
  9759. /* first, clear all configured multicast MACs */
  9760. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9761. if (rc < 0) {
  9762. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9763. return rc;
  9764. }
  9765. /* then, configure a new MACs list */
  9766. if (netdev_mc_count(dev)) {
  9767. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9768. if (rc) {
  9769. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9770. rc);
  9771. return rc;
  9772. }
  9773. /* Now add the new MACs */
  9774. rc = bnx2x_config_mcast(bp, &rparam,
  9775. BNX2X_MCAST_CMD_ADD);
  9776. if (rc < 0)
  9777. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9778. rc);
  9779. bnx2x_free_mcast_macs_list(&rparam);
  9780. }
  9781. return rc;
  9782. }
  9783. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9784. void bnx2x_set_rx_mode(struct net_device *dev)
  9785. {
  9786. struct bnx2x *bp = netdev_priv(dev);
  9787. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9788. if (bp->state != BNX2X_STATE_OPEN) {
  9789. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9790. return;
  9791. }
  9792. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9793. if (dev->flags & IFF_PROMISC)
  9794. rx_mode = BNX2X_RX_MODE_PROMISC;
  9795. else if ((dev->flags & IFF_ALLMULTI) ||
  9796. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9797. CHIP_IS_E1(bp)))
  9798. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9799. else {
  9800. if (IS_PF(bp)) {
  9801. /* some multicasts */
  9802. if (bnx2x_set_mc_list(bp) < 0)
  9803. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9804. if (bnx2x_set_uc_list(bp) < 0)
  9805. rx_mode = BNX2X_RX_MODE_PROMISC;
  9806. } else {
  9807. /* configuring mcast to a vf involves sleeping (when we
  9808. * wait for the pf's response). Since this function is
  9809. * called from non sleepable context we must schedule
  9810. * a work item for this purpose
  9811. */
  9812. smp_mb__before_clear_bit();
  9813. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9814. &bp->sp_rtnl_state);
  9815. smp_mb__after_clear_bit();
  9816. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9817. }
  9818. }
  9819. bp->rx_mode = rx_mode;
  9820. /* handle ISCSI SD mode */
  9821. if (IS_MF_ISCSI_SD(bp))
  9822. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9823. /* Schedule the rx_mode command */
  9824. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9825. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9826. return;
  9827. }
  9828. if (IS_PF(bp)) {
  9829. bnx2x_set_storm_rx_mode(bp);
  9830. } else {
  9831. /* configuring rx mode to storms in a vf involves sleeping (when
  9832. * we wait for the pf's response). Since this function is
  9833. * called from non sleepable context we must schedule
  9834. * a work item for this purpose
  9835. */
  9836. smp_mb__before_clear_bit();
  9837. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9838. &bp->sp_rtnl_state);
  9839. smp_mb__after_clear_bit();
  9840. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9841. }
  9842. }
  9843. /* called with rtnl_lock */
  9844. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9845. int devad, u16 addr)
  9846. {
  9847. struct bnx2x *bp = netdev_priv(netdev);
  9848. u16 value;
  9849. int rc;
  9850. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9851. prtad, devad, addr);
  9852. /* The HW expects different devad if CL22 is used */
  9853. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9854. bnx2x_acquire_phy_lock(bp);
  9855. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9856. bnx2x_release_phy_lock(bp);
  9857. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9858. if (!rc)
  9859. rc = value;
  9860. return rc;
  9861. }
  9862. /* called with rtnl_lock */
  9863. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9864. u16 addr, u16 value)
  9865. {
  9866. struct bnx2x *bp = netdev_priv(netdev);
  9867. int rc;
  9868. DP(NETIF_MSG_LINK,
  9869. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9870. prtad, devad, addr, value);
  9871. /* The HW expects different devad if CL22 is used */
  9872. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9873. bnx2x_acquire_phy_lock(bp);
  9874. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9875. bnx2x_release_phy_lock(bp);
  9876. return rc;
  9877. }
  9878. /* called with rtnl_lock */
  9879. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9880. {
  9881. struct bnx2x *bp = netdev_priv(dev);
  9882. struct mii_ioctl_data *mdio = if_mii(ifr);
  9883. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9884. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9885. if (!netif_running(dev))
  9886. return -EAGAIN;
  9887. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9888. }
  9889. #ifdef CONFIG_NET_POLL_CONTROLLER
  9890. static void poll_bnx2x(struct net_device *dev)
  9891. {
  9892. struct bnx2x *bp = netdev_priv(dev);
  9893. int i;
  9894. for_each_eth_queue(bp, i) {
  9895. struct bnx2x_fastpath *fp = &bp->fp[i];
  9896. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9897. }
  9898. }
  9899. #endif
  9900. static int bnx2x_validate_addr(struct net_device *dev)
  9901. {
  9902. struct bnx2x *bp = netdev_priv(dev);
  9903. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9904. BNX2X_ERR("Non-valid Ethernet address\n");
  9905. return -EADDRNOTAVAIL;
  9906. }
  9907. return 0;
  9908. }
  9909. static const struct net_device_ops bnx2x_netdev_ops = {
  9910. .ndo_open = bnx2x_open,
  9911. .ndo_stop = bnx2x_close,
  9912. .ndo_start_xmit = bnx2x_start_xmit,
  9913. .ndo_select_queue = bnx2x_select_queue,
  9914. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9915. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9916. .ndo_validate_addr = bnx2x_validate_addr,
  9917. .ndo_do_ioctl = bnx2x_ioctl,
  9918. .ndo_change_mtu = bnx2x_change_mtu,
  9919. .ndo_fix_features = bnx2x_fix_features,
  9920. .ndo_set_features = bnx2x_set_features,
  9921. .ndo_tx_timeout = bnx2x_tx_timeout,
  9922. #ifdef CONFIG_NET_POLL_CONTROLLER
  9923. .ndo_poll_controller = poll_bnx2x,
  9924. #endif
  9925. .ndo_setup_tc = bnx2x_setup_tc,
  9926. #ifdef CONFIG_BNX2X_SRIOV
  9927. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9928. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  9929. .ndo_get_vf_config = bnx2x_get_vf_config,
  9930. #endif
  9931. #ifdef NETDEV_FCOE_WWNN
  9932. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9933. #endif
  9934. };
  9935. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9936. {
  9937. struct device *dev = &bp->pdev->dev;
  9938. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9939. bp->flags |= USING_DAC_FLAG;
  9940. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9941. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9942. return -EIO;
  9943. }
  9944. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9945. dev_err(dev, "System does not support DMA, aborting\n");
  9946. return -EIO;
  9947. }
  9948. return 0;
  9949. }
  9950. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9951. struct net_device *dev, unsigned long board_type)
  9952. {
  9953. int rc;
  9954. u32 pci_cfg_dword;
  9955. bool chip_is_e1x = (board_type == BCM57710 ||
  9956. board_type == BCM57711 ||
  9957. board_type == BCM57711E);
  9958. SET_NETDEV_DEV(dev, &pdev->dev);
  9959. bp->dev = dev;
  9960. bp->pdev = pdev;
  9961. rc = pci_enable_device(pdev);
  9962. if (rc) {
  9963. dev_err(&bp->pdev->dev,
  9964. "Cannot enable PCI device, aborting\n");
  9965. goto err_out;
  9966. }
  9967. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9968. dev_err(&bp->pdev->dev,
  9969. "Cannot find PCI device base address, aborting\n");
  9970. rc = -ENODEV;
  9971. goto err_out_disable;
  9972. }
  9973. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9974. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9975. rc = -ENODEV;
  9976. goto err_out_disable;
  9977. }
  9978. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9979. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9980. PCICFG_REVESION_ID_ERROR_VAL) {
  9981. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9982. rc = -ENODEV;
  9983. goto err_out_disable;
  9984. }
  9985. if (atomic_read(&pdev->enable_cnt) == 1) {
  9986. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9987. if (rc) {
  9988. dev_err(&bp->pdev->dev,
  9989. "Cannot obtain PCI resources, aborting\n");
  9990. goto err_out_disable;
  9991. }
  9992. pci_set_master(pdev);
  9993. pci_save_state(pdev);
  9994. }
  9995. if (IS_PF(bp)) {
  9996. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9997. if (bp->pm_cap == 0) {
  9998. dev_err(&bp->pdev->dev,
  9999. "Cannot find power management capability, aborting\n");
  10000. rc = -EIO;
  10001. goto err_out_release;
  10002. }
  10003. }
  10004. if (!pci_is_pcie(pdev)) {
  10005. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10006. rc = -EIO;
  10007. goto err_out_release;
  10008. }
  10009. rc = bnx2x_set_coherency_mask(bp);
  10010. if (rc)
  10011. goto err_out_release;
  10012. dev->mem_start = pci_resource_start(pdev, 0);
  10013. dev->base_addr = dev->mem_start;
  10014. dev->mem_end = pci_resource_end(pdev, 0);
  10015. dev->irq = pdev->irq;
  10016. bp->regview = pci_ioremap_bar(pdev, 0);
  10017. if (!bp->regview) {
  10018. dev_err(&bp->pdev->dev,
  10019. "Cannot map register space, aborting\n");
  10020. rc = -ENOMEM;
  10021. goto err_out_release;
  10022. }
  10023. /* In E1/E1H use pci device function given by kernel.
  10024. * In E2/E3 read physical function from ME register since these chips
  10025. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10026. * (depending on hypervisor).
  10027. */
  10028. if (chip_is_e1x) {
  10029. bp->pf_num = PCI_FUNC(pdev->devfn);
  10030. } else {
  10031. /* chip is E2/3*/
  10032. pci_read_config_dword(bp->pdev,
  10033. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10034. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10035. ME_REG_ABS_PF_NUM_SHIFT);
  10036. }
  10037. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10038. bnx2x_set_power_state(bp, PCI_D0);
  10039. /* clean indirect addresses */
  10040. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10041. PCICFG_VENDOR_ID_OFFSET);
  10042. /*
  10043. * Clean the following indirect addresses for all functions since it
  10044. * is not used by the driver.
  10045. */
  10046. if (IS_PF(bp)) {
  10047. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10048. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10049. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10050. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10051. if (chip_is_e1x) {
  10052. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10053. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10054. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10055. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10056. }
  10057. /* Enable internal target-read (in case we are probed after PF
  10058. * FLR). Must be done prior to any BAR read access. Only for
  10059. * 57712 and up
  10060. */
  10061. if (!chip_is_e1x)
  10062. REG_WR(bp,
  10063. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10064. }
  10065. dev->watchdog_timeo = TX_TIMEOUT;
  10066. dev->netdev_ops = &bnx2x_netdev_ops;
  10067. bnx2x_set_ethtool_ops(bp, dev);
  10068. dev->priv_flags |= IFF_UNICAST_FLT;
  10069. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10070. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10071. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10072. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  10073. if (!CHIP_IS_E1x(bp)) {
  10074. dev->hw_features |= NETIF_F_GSO_GRE;
  10075. dev->hw_enc_features =
  10076. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10077. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10078. NETIF_F_GSO_GRE;
  10079. }
  10080. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10081. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10082. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  10083. if (bp->flags & USING_DAC_FLAG)
  10084. dev->features |= NETIF_F_HIGHDMA;
  10085. /* Add Loopback capability to the device */
  10086. dev->hw_features |= NETIF_F_LOOPBACK;
  10087. #ifdef BCM_DCBNL
  10088. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10089. #endif
  10090. /* get_port_hwinfo() will set prtad and mmds properly */
  10091. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10092. bp->mdio.mmds = 0;
  10093. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10094. bp->mdio.dev = dev;
  10095. bp->mdio.mdio_read = bnx2x_mdio_read;
  10096. bp->mdio.mdio_write = bnx2x_mdio_write;
  10097. return 0;
  10098. err_out_release:
  10099. if (atomic_read(&pdev->enable_cnt) == 1)
  10100. pci_release_regions(pdev);
  10101. err_out_disable:
  10102. pci_disable_device(pdev);
  10103. pci_set_drvdata(pdev, NULL);
  10104. err_out:
  10105. return rc;
  10106. }
  10107. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10108. {
  10109. u32 val = 0;
  10110. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10111. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10112. /* return value of 1=2.5GHz 2=5GHz */
  10113. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10114. }
  10115. static int bnx2x_check_firmware(struct bnx2x *bp)
  10116. {
  10117. const struct firmware *firmware = bp->firmware;
  10118. struct bnx2x_fw_file_hdr *fw_hdr;
  10119. struct bnx2x_fw_file_section *sections;
  10120. u32 offset, len, num_ops;
  10121. __be16 *ops_offsets;
  10122. int i;
  10123. const u8 *fw_ver;
  10124. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10125. BNX2X_ERR("Wrong FW size\n");
  10126. return -EINVAL;
  10127. }
  10128. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10129. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10130. /* Make sure none of the offsets and sizes make us read beyond
  10131. * the end of the firmware data */
  10132. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10133. offset = be32_to_cpu(sections[i].offset);
  10134. len = be32_to_cpu(sections[i].len);
  10135. if (offset + len > firmware->size) {
  10136. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10137. return -EINVAL;
  10138. }
  10139. }
  10140. /* Likewise for the init_ops offsets */
  10141. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10142. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10143. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10144. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10145. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10146. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10147. return -EINVAL;
  10148. }
  10149. }
  10150. /* Check FW version */
  10151. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10152. fw_ver = firmware->data + offset;
  10153. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10154. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10155. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10156. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10157. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10158. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10159. BCM_5710_FW_MAJOR_VERSION,
  10160. BCM_5710_FW_MINOR_VERSION,
  10161. BCM_5710_FW_REVISION_VERSION,
  10162. BCM_5710_FW_ENGINEERING_VERSION);
  10163. return -EINVAL;
  10164. }
  10165. return 0;
  10166. }
  10167. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10168. {
  10169. const __be32 *source = (const __be32 *)_source;
  10170. u32 *target = (u32 *)_target;
  10171. u32 i;
  10172. for (i = 0; i < n/4; i++)
  10173. target[i] = be32_to_cpu(source[i]);
  10174. }
  10175. /*
  10176. Ops array is stored in the following format:
  10177. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10178. */
  10179. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10180. {
  10181. const __be32 *source = (const __be32 *)_source;
  10182. struct raw_op *target = (struct raw_op *)_target;
  10183. u32 i, j, tmp;
  10184. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10185. tmp = be32_to_cpu(source[j]);
  10186. target[i].op = (tmp >> 24) & 0xff;
  10187. target[i].offset = tmp & 0xffffff;
  10188. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10189. }
  10190. }
  10191. /* IRO array is stored in the following format:
  10192. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10193. */
  10194. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10195. {
  10196. const __be32 *source = (const __be32 *)_source;
  10197. struct iro *target = (struct iro *)_target;
  10198. u32 i, j, tmp;
  10199. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10200. target[i].base = be32_to_cpu(source[j]);
  10201. j++;
  10202. tmp = be32_to_cpu(source[j]);
  10203. target[i].m1 = (tmp >> 16) & 0xffff;
  10204. target[i].m2 = tmp & 0xffff;
  10205. j++;
  10206. tmp = be32_to_cpu(source[j]);
  10207. target[i].m3 = (tmp >> 16) & 0xffff;
  10208. target[i].size = tmp & 0xffff;
  10209. j++;
  10210. }
  10211. }
  10212. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10213. {
  10214. const __be16 *source = (const __be16 *)_source;
  10215. u16 *target = (u16 *)_target;
  10216. u32 i;
  10217. for (i = 0; i < n/2; i++)
  10218. target[i] = be16_to_cpu(source[i]);
  10219. }
  10220. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10221. do { \
  10222. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10223. bp->arr = kmalloc(len, GFP_KERNEL); \
  10224. if (!bp->arr) \
  10225. goto lbl; \
  10226. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10227. (u8 *)bp->arr, len); \
  10228. } while (0)
  10229. static int bnx2x_init_firmware(struct bnx2x *bp)
  10230. {
  10231. const char *fw_file_name;
  10232. struct bnx2x_fw_file_hdr *fw_hdr;
  10233. int rc;
  10234. if (bp->firmware)
  10235. return 0;
  10236. if (CHIP_IS_E1(bp))
  10237. fw_file_name = FW_FILE_NAME_E1;
  10238. else if (CHIP_IS_E1H(bp))
  10239. fw_file_name = FW_FILE_NAME_E1H;
  10240. else if (!CHIP_IS_E1x(bp))
  10241. fw_file_name = FW_FILE_NAME_E2;
  10242. else {
  10243. BNX2X_ERR("Unsupported chip revision\n");
  10244. return -EINVAL;
  10245. }
  10246. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10247. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10248. if (rc) {
  10249. BNX2X_ERR("Can't load firmware file %s\n",
  10250. fw_file_name);
  10251. goto request_firmware_exit;
  10252. }
  10253. rc = bnx2x_check_firmware(bp);
  10254. if (rc) {
  10255. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10256. goto request_firmware_exit;
  10257. }
  10258. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10259. /* Initialize the pointers to the init arrays */
  10260. /* Blob */
  10261. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10262. /* Opcodes */
  10263. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10264. /* Offsets */
  10265. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10266. be16_to_cpu_n);
  10267. /* STORMs firmware */
  10268. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10269. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10270. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10271. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10272. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10273. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10274. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10275. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10276. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10277. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10278. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10279. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10280. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10281. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10282. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10283. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10284. /* IRO */
  10285. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10286. return 0;
  10287. iro_alloc_err:
  10288. kfree(bp->init_ops_offsets);
  10289. init_offsets_alloc_err:
  10290. kfree(bp->init_ops);
  10291. init_ops_alloc_err:
  10292. kfree(bp->init_data);
  10293. request_firmware_exit:
  10294. release_firmware(bp->firmware);
  10295. bp->firmware = NULL;
  10296. return rc;
  10297. }
  10298. static void bnx2x_release_firmware(struct bnx2x *bp)
  10299. {
  10300. kfree(bp->init_ops_offsets);
  10301. kfree(bp->init_ops);
  10302. kfree(bp->init_data);
  10303. release_firmware(bp->firmware);
  10304. bp->firmware = NULL;
  10305. }
  10306. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10307. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10308. .init_hw_cmn = bnx2x_init_hw_common,
  10309. .init_hw_port = bnx2x_init_hw_port,
  10310. .init_hw_func = bnx2x_init_hw_func,
  10311. .reset_hw_cmn = bnx2x_reset_common,
  10312. .reset_hw_port = bnx2x_reset_port,
  10313. .reset_hw_func = bnx2x_reset_func,
  10314. .gunzip_init = bnx2x_gunzip_init,
  10315. .gunzip_end = bnx2x_gunzip_end,
  10316. .init_fw = bnx2x_init_firmware,
  10317. .release_fw = bnx2x_release_firmware,
  10318. };
  10319. void bnx2x__init_func_obj(struct bnx2x *bp)
  10320. {
  10321. /* Prepare DMAE related driver resources */
  10322. bnx2x_setup_dmae(bp);
  10323. bnx2x_init_func_obj(bp, &bp->func_obj,
  10324. bnx2x_sp(bp, func_rdata),
  10325. bnx2x_sp_mapping(bp, func_rdata),
  10326. bnx2x_sp(bp, func_afex_rdata),
  10327. bnx2x_sp_mapping(bp, func_afex_rdata),
  10328. &bnx2x_func_sp_drv);
  10329. }
  10330. /* must be called after sriov-enable */
  10331. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10332. {
  10333. int cid_count = BNX2X_L2_MAX_CID(bp);
  10334. if (IS_SRIOV(bp))
  10335. cid_count += BNX2X_VF_CIDS;
  10336. if (CNIC_SUPPORT(bp))
  10337. cid_count += CNIC_CID_MAX;
  10338. return roundup(cid_count, QM_CID_ROUND);
  10339. }
  10340. /**
  10341. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10342. *
  10343. * @dev: pci device
  10344. *
  10345. */
  10346. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10347. int cnic_cnt, bool is_vf)
  10348. {
  10349. int pos, index;
  10350. u16 control = 0;
  10351. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10352. /*
  10353. * If MSI-X is not supported - return number of SBs needed to support
  10354. * one fast path queue: one FP queue + SB for CNIC
  10355. */
  10356. if (!pos) {
  10357. dev_info(&pdev->dev, "no msix capability found\n");
  10358. return 1 + cnic_cnt;
  10359. }
  10360. dev_info(&pdev->dev, "msix capability found\n");
  10361. /*
  10362. * The value in the PCI configuration space is the index of the last
  10363. * entry, namely one less than the actual size of the table, which is
  10364. * exactly what we want to return from this function: number of all SBs
  10365. * without the default SB.
  10366. * For VFs there is no default SB, then we return (index+1).
  10367. */
  10368. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10369. index = control & PCI_MSIX_FLAGS_QSIZE;
  10370. return is_vf ? index + 1 : index;
  10371. }
  10372. static int set_max_cos_est(int chip_id)
  10373. {
  10374. switch (chip_id) {
  10375. case BCM57710:
  10376. case BCM57711:
  10377. case BCM57711E:
  10378. return BNX2X_MULTI_TX_COS_E1X;
  10379. case BCM57712:
  10380. case BCM57712_MF:
  10381. case BCM57712_VF:
  10382. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10383. case BCM57800:
  10384. case BCM57800_MF:
  10385. case BCM57800_VF:
  10386. case BCM57810:
  10387. case BCM57810_MF:
  10388. case BCM57840_4_10:
  10389. case BCM57840_2_20:
  10390. case BCM57840_O:
  10391. case BCM57840_MFO:
  10392. case BCM57810_VF:
  10393. case BCM57840_MF:
  10394. case BCM57840_VF:
  10395. case BCM57811:
  10396. case BCM57811_MF:
  10397. case BCM57811_VF:
  10398. return BNX2X_MULTI_TX_COS_E3B0;
  10399. return 1;
  10400. default:
  10401. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10402. return -ENODEV;
  10403. }
  10404. }
  10405. static int set_is_vf(int chip_id)
  10406. {
  10407. switch (chip_id) {
  10408. case BCM57712_VF:
  10409. case BCM57800_VF:
  10410. case BCM57810_VF:
  10411. case BCM57840_VF:
  10412. case BCM57811_VF:
  10413. return true;
  10414. default:
  10415. return false;
  10416. }
  10417. }
  10418. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10419. static int bnx2x_init_one(struct pci_dev *pdev,
  10420. const struct pci_device_id *ent)
  10421. {
  10422. struct net_device *dev = NULL;
  10423. struct bnx2x *bp;
  10424. int pcie_width, pcie_speed;
  10425. int rc, max_non_def_sbs;
  10426. int rx_count, tx_count, rss_count, doorbell_size;
  10427. int max_cos_est;
  10428. bool is_vf;
  10429. int cnic_cnt;
  10430. /* An estimated maximum supported CoS number according to the chip
  10431. * version.
  10432. * We will try to roughly estimate the maximum number of CoSes this chip
  10433. * may support in order to minimize the memory allocated for Tx
  10434. * netdev_queue's. This number will be accurately calculated during the
  10435. * initialization of bp->max_cos based on the chip versions AND chip
  10436. * revision in the bnx2x_init_bp().
  10437. */
  10438. max_cos_est = set_max_cos_est(ent->driver_data);
  10439. if (max_cos_est < 0)
  10440. return max_cos_est;
  10441. is_vf = set_is_vf(ent->driver_data);
  10442. cnic_cnt = is_vf ? 0 : 1;
  10443. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10444. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10445. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10446. if (rss_count < 1)
  10447. return -EINVAL;
  10448. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10449. rx_count = rss_count + cnic_cnt;
  10450. /* Maximum number of netdev Tx queues:
  10451. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10452. */
  10453. tx_count = rss_count * max_cos_est + cnic_cnt;
  10454. /* dev zeroed in init_etherdev */
  10455. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10456. if (!dev)
  10457. return -ENOMEM;
  10458. bp = netdev_priv(dev);
  10459. bp->flags = 0;
  10460. if (is_vf)
  10461. bp->flags |= IS_VF_FLAG;
  10462. bp->igu_sb_cnt = max_non_def_sbs;
  10463. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10464. bp->msg_enable = debug;
  10465. bp->cnic_support = cnic_cnt;
  10466. bp->cnic_probe = bnx2x_cnic_probe;
  10467. pci_set_drvdata(pdev, dev);
  10468. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10469. if (rc < 0) {
  10470. free_netdev(dev);
  10471. return rc;
  10472. }
  10473. BNX2X_DEV_INFO("This is a %s function\n",
  10474. IS_PF(bp) ? "physical" : "virtual");
  10475. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10476. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10477. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10478. tx_count, rx_count);
  10479. rc = bnx2x_init_bp(bp);
  10480. if (rc)
  10481. goto init_one_exit;
  10482. /* Map doorbells here as we need the real value of bp->max_cos which
  10483. * is initialized in bnx2x_init_bp() to determine the number of
  10484. * l2 connections.
  10485. */
  10486. if (IS_VF(bp)) {
  10487. bp->doorbells = bnx2x_vf_doorbells(bp);
  10488. mutex_init(&bp->vf2pf_mutex);
  10489. rc = bnx2x_vf_pci_alloc(bp);
  10490. if (rc)
  10491. goto init_one_exit;
  10492. } else {
  10493. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10494. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10495. dev_err(&bp->pdev->dev,
  10496. "Cannot map doorbells, bar size too small, aborting\n");
  10497. rc = -ENOMEM;
  10498. goto init_one_exit;
  10499. }
  10500. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10501. doorbell_size);
  10502. }
  10503. if (!bp->doorbells) {
  10504. dev_err(&bp->pdev->dev,
  10505. "Cannot map doorbell space, aborting\n");
  10506. rc = -ENOMEM;
  10507. goto init_one_exit;
  10508. }
  10509. if (IS_VF(bp)) {
  10510. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10511. if (rc)
  10512. goto init_one_exit;
  10513. }
  10514. /* Enable SRIOV if capability found in configuration space */
  10515. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10516. if (rc)
  10517. goto init_one_exit;
  10518. /* calc qm_cid_count */
  10519. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10520. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10521. /* disable FCOE L2 queue for E1x*/
  10522. if (CHIP_IS_E1x(bp))
  10523. bp->flags |= NO_FCOE_FLAG;
  10524. /* Set bp->num_queues for MSI-X mode*/
  10525. bnx2x_set_num_queues(bp);
  10526. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10527. * needed.
  10528. */
  10529. rc = bnx2x_set_int_mode(bp);
  10530. if (rc) {
  10531. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10532. goto init_one_exit;
  10533. }
  10534. BNX2X_DEV_INFO("set interrupts successfully\n");
  10535. /* register the net device */
  10536. rc = register_netdev(dev);
  10537. if (rc) {
  10538. dev_err(&pdev->dev, "Cannot register net device\n");
  10539. goto init_one_exit;
  10540. }
  10541. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10542. if (!NO_FCOE(bp)) {
  10543. /* Add storage MAC address */
  10544. rtnl_lock();
  10545. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10546. rtnl_unlock();
  10547. }
  10548. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10549. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10550. pcie_width, pcie_speed);
  10551. BNX2X_DEV_INFO(
  10552. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10553. board_info[ent->driver_data].name,
  10554. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10555. pcie_width,
  10556. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10557. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10558. "5GHz (Gen2)" : "2.5GHz",
  10559. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10560. return 0;
  10561. init_one_exit:
  10562. if (bp->regview)
  10563. iounmap(bp->regview);
  10564. if (IS_PF(bp) && bp->doorbells)
  10565. iounmap(bp->doorbells);
  10566. free_netdev(dev);
  10567. if (atomic_read(&pdev->enable_cnt) == 1)
  10568. pci_release_regions(pdev);
  10569. pci_disable_device(pdev);
  10570. pci_set_drvdata(pdev, NULL);
  10571. return rc;
  10572. }
  10573. static void bnx2x_remove_one(struct pci_dev *pdev)
  10574. {
  10575. struct net_device *dev = pci_get_drvdata(pdev);
  10576. struct bnx2x *bp;
  10577. if (!dev) {
  10578. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10579. return;
  10580. }
  10581. bp = netdev_priv(dev);
  10582. /* Delete storage MAC address */
  10583. if (!NO_FCOE(bp)) {
  10584. rtnl_lock();
  10585. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10586. rtnl_unlock();
  10587. }
  10588. #ifdef BCM_DCBNL
  10589. /* Delete app tlvs from dcbnl */
  10590. bnx2x_dcbnl_update_applist(bp, true);
  10591. #endif
  10592. unregister_netdev(dev);
  10593. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10594. if (IS_PF(bp))
  10595. bnx2x_set_power_state(bp, PCI_D0);
  10596. /* Disable MSI/MSI-X */
  10597. bnx2x_disable_msi(bp);
  10598. /* Power off */
  10599. if (IS_PF(bp))
  10600. bnx2x_set_power_state(bp, PCI_D3hot);
  10601. /* Make sure RESET task is not scheduled before continuing */
  10602. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10603. bnx2x_iov_remove_one(bp);
  10604. /* send message via vfpf channel to release the resources of this vf */
  10605. if (IS_VF(bp))
  10606. bnx2x_vfpf_release(bp);
  10607. if (bp->regview)
  10608. iounmap(bp->regview);
  10609. /* for vf doorbells are part of the regview and were unmapped along with
  10610. * it. FW is only loaded by PF.
  10611. */
  10612. if (IS_PF(bp)) {
  10613. if (bp->doorbells)
  10614. iounmap(bp->doorbells);
  10615. bnx2x_release_firmware(bp);
  10616. }
  10617. bnx2x_free_mem_bp(bp);
  10618. free_netdev(dev);
  10619. if (atomic_read(&pdev->enable_cnt) == 1)
  10620. pci_release_regions(pdev);
  10621. pci_disable_device(pdev);
  10622. pci_set_drvdata(pdev, NULL);
  10623. }
  10624. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10625. {
  10626. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10627. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10628. if (CNIC_LOADED(bp))
  10629. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10630. /* Stop Tx */
  10631. bnx2x_tx_disable(bp);
  10632. /* Delete all NAPI objects */
  10633. bnx2x_del_all_napi(bp);
  10634. if (CNIC_LOADED(bp))
  10635. bnx2x_del_all_napi_cnic(bp);
  10636. netdev_reset_tc(bp->dev);
  10637. del_timer_sync(&bp->timer);
  10638. cancel_delayed_work(&bp->sp_task);
  10639. cancel_delayed_work(&bp->period_task);
  10640. spin_lock_bh(&bp->stats_lock);
  10641. bp->stats_state = STATS_STATE_DISABLED;
  10642. spin_unlock_bh(&bp->stats_lock);
  10643. bnx2x_save_statistics(bp);
  10644. netif_carrier_off(bp->dev);
  10645. return 0;
  10646. }
  10647. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10648. {
  10649. u32 val;
  10650. mutex_init(&bp->port.phy_mutex);
  10651. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10652. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10653. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10654. BNX2X_ERR("BAD MCP validity signature\n");
  10655. }
  10656. /**
  10657. * bnx2x_io_error_detected - called when PCI error is detected
  10658. * @pdev: Pointer to PCI device
  10659. * @state: The current pci connection state
  10660. *
  10661. * This function is called after a PCI bus error affecting
  10662. * this device has been detected.
  10663. */
  10664. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10665. pci_channel_state_t state)
  10666. {
  10667. struct net_device *dev = pci_get_drvdata(pdev);
  10668. struct bnx2x *bp = netdev_priv(dev);
  10669. rtnl_lock();
  10670. BNX2X_ERR("IO error detected\n");
  10671. netif_device_detach(dev);
  10672. if (state == pci_channel_io_perm_failure) {
  10673. rtnl_unlock();
  10674. return PCI_ERS_RESULT_DISCONNECT;
  10675. }
  10676. if (netif_running(dev))
  10677. bnx2x_eeh_nic_unload(bp);
  10678. bnx2x_prev_path_mark_eeh(bp);
  10679. pci_disable_device(pdev);
  10680. rtnl_unlock();
  10681. /* Request a slot reset */
  10682. return PCI_ERS_RESULT_NEED_RESET;
  10683. }
  10684. /**
  10685. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10686. * @pdev: Pointer to PCI device
  10687. *
  10688. * Restart the card from scratch, as if from a cold-boot.
  10689. */
  10690. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10691. {
  10692. struct net_device *dev = pci_get_drvdata(pdev);
  10693. struct bnx2x *bp = netdev_priv(dev);
  10694. int i;
  10695. rtnl_lock();
  10696. BNX2X_ERR("IO slot reset initializing...\n");
  10697. if (pci_enable_device(pdev)) {
  10698. dev_err(&pdev->dev,
  10699. "Cannot re-enable PCI device after reset\n");
  10700. rtnl_unlock();
  10701. return PCI_ERS_RESULT_DISCONNECT;
  10702. }
  10703. pci_set_master(pdev);
  10704. pci_restore_state(pdev);
  10705. if (netif_running(dev))
  10706. bnx2x_set_power_state(bp, PCI_D0);
  10707. if (netif_running(dev)) {
  10708. BNX2X_ERR("IO slot reset --> driver unload\n");
  10709. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10710. u32 v;
  10711. v = SHMEM2_RD(bp,
  10712. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10713. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10714. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10715. }
  10716. bnx2x_drain_tx_queues(bp);
  10717. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10718. bnx2x_netif_stop(bp, 1);
  10719. bnx2x_free_irq(bp);
  10720. /* Report UNLOAD_DONE to MCP */
  10721. bnx2x_send_unload_done(bp, true);
  10722. bp->sp_state = 0;
  10723. bp->port.pmf = 0;
  10724. bnx2x_prev_unload(bp);
  10725. /* We should have resetted the engine, so It's fair to
  10726. * assume the FW will no longer write to the bnx2x driver.
  10727. */
  10728. bnx2x_squeeze_objects(bp);
  10729. bnx2x_free_skbs(bp);
  10730. for_each_rx_queue(bp, i)
  10731. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10732. bnx2x_free_fp_mem(bp);
  10733. bnx2x_free_mem(bp);
  10734. bp->state = BNX2X_STATE_CLOSED;
  10735. }
  10736. rtnl_unlock();
  10737. return PCI_ERS_RESULT_RECOVERED;
  10738. }
  10739. /**
  10740. * bnx2x_io_resume - called when traffic can start flowing again
  10741. * @pdev: Pointer to PCI device
  10742. *
  10743. * This callback is called when the error recovery driver tells us that
  10744. * its OK to resume normal operation.
  10745. */
  10746. static void bnx2x_io_resume(struct pci_dev *pdev)
  10747. {
  10748. struct net_device *dev = pci_get_drvdata(pdev);
  10749. struct bnx2x *bp = netdev_priv(dev);
  10750. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10751. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10752. return;
  10753. }
  10754. rtnl_lock();
  10755. bnx2x_eeh_recover(bp);
  10756. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10757. DRV_MSG_SEQ_NUMBER_MASK;
  10758. if (netif_running(dev))
  10759. bnx2x_nic_load(bp, LOAD_NORMAL);
  10760. netif_device_attach(dev);
  10761. rtnl_unlock();
  10762. }
  10763. static const struct pci_error_handlers bnx2x_err_handler = {
  10764. .error_detected = bnx2x_io_error_detected,
  10765. .slot_reset = bnx2x_io_slot_reset,
  10766. .resume = bnx2x_io_resume,
  10767. };
  10768. static struct pci_driver bnx2x_pci_driver = {
  10769. .name = DRV_MODULE_NAME,
  10770. .id_table = bnx2x_pci_tbl,
  10771. .probe = bnx2x_init_one,
  10772. .remove = bnx2x_remove_one,
  10773. .suspend = bnx2x_suspend,
  10774. .resume = bnx2x_resume,
  10775. .err_handler = &bnx2x_err_handler,
  10776. #ifdef CONFIG_BNX2X_SRIOV
  10777. .sriov_configure = bnx2x_sriov_configure,
  10778. #endif
  10779. };
  10780. static int __init bnx2x_init(void)
  10781. {
  10782. int ret;
  10783. pr_info("%s", version);
  10784. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10785. if (bnx2x_wq == NULL) {
  10786. pr_err("Cannot create workqueue\n");
  10787. return -ENOMEM;
  10788. }
  10789. ret = pci_register_driver(&bnx2x_pci_driver);
  10790. if (ret) {
  10791. pr_err("Cannot register driver\n");
  10792. destroy_workqueue(bnx2x_wq);
  10793. }
  10794. return ret;
  10795. }
  10796. static void __exit bnx2x_cleanup(void)
  10797. {
  10798. struct list_head *pos, *q;
  10799. pci_unregister_driver(&bnx2x_pci_driver);
  10800. destroy_workqueue(bnx2x_wq);
  10801. /* Free globablly allocated resources */
  10802. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10803. struct bnx2x_prev_path_list *tmp =
  10804. list_entry(pos, struct bnx2x_prev_path_list, list);
  10805. list_del(pos);
  10806. kfree(tmp);
  10807. }
  10808. }
  10809. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10810. {
  10811. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10812. }
  10813. module_init(bnx2x_init);
  10814. module_exit(bnx2x_cleanup);
  10815. /**
  10816. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10817. *
  10818. * @bp: driver handle
  10819. * @set: set or clear the CAM entry
  10820. *
  10821. * This function will wait until the ramdord completion returns.
  10822. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10823. */
  10824. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10825. {
  10826. unsigned long ramrod_flags = 0;
  10827. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10828. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10829. &bp->iscsi_l2_mac_obj, true,
  10830. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10831. }
  10832. /* count denotes the number of new completions we have seen */
  10833. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10834. {
  10835. struct eth_spe *spe;
  10836. int cxt_index, cxt_offset;
  10837. #ifdef BNX2X_STOP_ON_ERROR
  10838. if (unlikely(bp->panic))
  10839. return;
  10840. #endif
  10841. spin_lock_bh(&bp->spq_lock);
  10842. BUG_ON(bp->cnic_spq_pending < count);
  10843. bp->cnic_spq_pending -= count;
  10844. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10845. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10846. & SPE_HDR_CONN_TYPE) >>
  10847. SPE_HDR_CONN_TYPE_SHIFT;
  10848. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10849. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10850. /* Set validation for iSCSI L2 client before sending SETUP
  10851. * ramrod
  10852. */
  10853. if (type == ETH_CONNECTION_TYPE) {
  10854. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10855. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10856. ILT_PAGE_CIDS;
  10857. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10858. (cxt_index * ILT_PAGE_CIDS);
  10859. bnx2x_set_ctx_validation(bp,
  10860. &bp->context[cxt_index].
  10861. vcxt[cxt_offset].eth,
  10862. BNX2X_ISCSI_ETH_CID(bp));
  10863. }
  10864. }
  10865. /*
  10866. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10867. * and in the air. We also check that number of outstanding
  10868. * COMMON ramrods is not more than the EQ and SPQ can
  10869. * accommodate.
  10870. */
  10871. if (type == ETH_CONNECTION_TYPE) {
  10872. if (!atomic_read(&bp->cq_spq_left))
  10873. break;
  10874. else
  10875. atomic_dec(&bp->cq_spq_left);
  10876. } else if (type == NONE_CONNECTION_TYPE) {
  10877. if (!atomic_read(&bp->eq_spq_left))
  10878. break;
  10879. else
  10880. atomic_dec(&bp->eq_spq_left);
  10881. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10882. (type == FCOE_CONNECTION_TYPE)) {
  10883. if (bp->cnic_spq_pending >=
  10884. bp->cnic_eth_dev.max_kwqe_pending)
  10885. break;
  10886. else
  10887. bp->cnic_spq_pending++;
  10888. } else {
  10889. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10890. bnx2x_panic();
  10891. break;
  10892. }
  10893. spe = bnx2x_sp_get_next(bp);
  10894. *spe = *bp->cnic_kwq_cons;
  10895. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10896. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10897. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10898. bp->cnic_kwq_cons = bp->cnic_kwq;
  10899. else
  10900. bp->cnic_kwq_cons++;
  10901. }
  10902. bnx2x_sp_prod_update(bp);
  10903. spin_unlock_bh(&bp->spq_lock);
  10904. }
  10905. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10906. struct kwqe_16 *kwqes[], u32 count)
  10907. {
  10908. struct bnx2x *bp = netdev_priv(dev);
  10909. int i;
  10910. #ifdef BNX2X_STOP_ON_ERROR
  10911. if (unlikely(bp->panic)) {
  10912. BNX2X_ERR("Can't post to SP queue while panic\n");
  10913. return -EIO;
  10914. }
  10915. #endif
  10916. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10917. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10918. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10919. return -EAGAIN;
  10920. }
  10921. spin_lock_bh(&bp->spq_lock);
  10922. for (i = 0; i < count; i++) {
  10923. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10924. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10925. break;
  10926. *bp->cnic_kwq_prod = *spe;
  10927. bp->cnic_kwq_pending++;
  10928. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10929. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10930. spe->data.update_data_addr.hi,
  10931. spe->data.update_data_addr.lo,
  10932. bp->cnic_kwq_pending);
  10933. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10934. bp->cnic_kwq_prod = bp->cnic_kwq;
  10935. else
  10936. bp->cnic_kwq_prod++;
  10937. }
  10938. spin_unlock_bh(&bp->spq_lock);
  10939. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10940. bnx2x_cnic_sp_post(bp, 0);
  10941. return i;
  10942. }
  10943. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10944. {
  10945. struct cnic_ops *c_ops;
  10946. int rc = 0;
  10947. mutex_lock(&bp->cnic_mutex);
  10948. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10949. lockdep_is_held(&bp->cnic_mutex));
  10950. if (c_ops)
  10951. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10952. mutex_unlock(&bp->cnic_mutex);
  10953. return rc;
  10954. }
  10955. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10956. {
  10957. struct cnic_ops *c_ops;
  10958. int rc = 0;
  10959. rcu_read_lock();
  10960. c_ops = rcu_dereference(bp->cnic_ops);
  10961. if (c_ops)
  10962. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10963. rcu_read_unlock();
  10964. return rc;
  10965. }
  10966. /*
  10967. * for commands that have no data
  10968. */
  10969. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10970. {
  10971. struct cnic_ctl_info ctl = {0};
  10972. ctl.cmd = cmd;
  10973. return bnx2x_cnic_ctl_send(bp, &ctl);
  10974. }
  10975. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10976. {
  10977. struct cnic_ctl_info ctl = {0};
  10978. /* first we tell CNIC and only then we count this as a completion */
  10979. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10980. ctl.data.comp.cid = cid;
  10981. ctl.data.comp.error = err;
  10982. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10983. bnx2x_cnic_sp_post(bp, 0);
  10984. }
  10985. /* Called with netif_addr_lock_bh() taken.
  10986. * Sets an rx_mode config for an iSCSI ETH client.
  10987. * Doesn't block.
  10988. * Completion should be checked outside.
  10989. */
  10990. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10991. {
  10992. unsigned long accept_flags = 0, ramrod_flags = 0;
  10993. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10994. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10995. if (start) {
  10996. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10997. * because it's the only way for UIO Queue to accept
  10998. * multicasts (in non-promiscuous mode only one Queue per
  10999. * function will receive multicast packets (leading in our
  11000. * case).
  11001. */
  11002. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11003. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11004. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11005. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11006. /* Clear STOP_PENDING bit if START is requested */
  11007. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11008. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11009. } else
  11010. /* Clear START_PENDING bit if STOP is requested */
  11011. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11012. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11013. set_bit(sched_state, &bp->sp_state);
  11014. else {
  11015. __set_bit(RAMROD_RX, &ramrod_flags);
  11016. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11017. ramrod_flags);
  11018. }
  11019. }
  11020. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11021. {
  11022. struct bnx2x *bp = netdev_priv(dev);
  11023. int rc = 0;
  11024. switch (ctl->cmd) {
  11025. case DRV_CTL_CTXTBL_WR_CMD: {
  11026. u32 index = ctl->data.io.offset;
  11027. dma_addr_t addr = ctl->data.io.dma_addr;
  11028. bnx2x_ilt_wr(bp, index, addr);
  11029. break;
  11030. }
  11031. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11032. int count = ctl->data.credit.credit_count;
  11033. bnx2x_cnic_sp_post(bp, count);
  11034. break;
  11035. }
  11036. /* rtnl_lock is held. */
  11037. case DRV_CTL_START_L2_CMD: {
  11038. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11039. unsigned long sp_bits = 0;
  11040. /* Configure the iSCSI classification object */
  11041. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11042. cp->iscsi_l2_client_id,
  11043. cp->iscsi_l2_cid, BP_FUNC(bp),
  11044. bnx2x_sp(bp, mac_rdata),
  11045. bnx2x_sp_mapping(bp, mac_rdata),
  11046. BNX2X_FILTER_MAC_PENDING,
  11047. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11048. &bp->macs_pool);
  11049. /* Set iSCSI MAC address */
  11050. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11051. if (rc)
  11052. break;
  11053. mmiowb();
  11054. barrier();
  11055. /* Start accepting on iSCSI L2 ring */
  11056. netif_addr_lock_bh(dev);
  11057. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11058. netif_addr_unlock_bh(dev);
  11059. /* bits to wait on */
  11060. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11061. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11062. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11063. BNX2X_ERR("rx_mode completion timed out!\n");
  11064. break;
  11065. }
  11066. /* rtnl_lock is held. */
  11067. case DRV_CTL_STOP_L2_CMD: {
  11068. unsigned long sp_bits = 0;
  11069. /* Stop accepting on iSCSI L2 ring */
  11070. netif_addr_lock_bh(dev);
  11071. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11072. netif_addr_unlock_bh(dev);
  11073. /* bits to wait on */
  11074. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11075. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11076. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11077. BNX2X_ERR("rx_mode completion timed out!\n");
  11078. mmiowb();
  11079. barrier();
  11080. /* Unset iSCSI L2 MAC */
  11081. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11082. BNX2X_ISCSI_ETH_MAC, true);
  11083. break;
  11084. }
  11085. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11086. int count = ctl->data.credit.credit_count;
  11087. smp_mb__before_atomic_inc();
  11088. atomic_add(count, &bp->cq_spq_left);
  11089. smp_mb__after_atomic_inc();
  11090. break;
  11091. }
  11092. case DRV_CTL_ULP_REGISTER_CMD: {
  11093. int ulp_type = ctl->data.register_data.ulp_type;
  11094. if (CHIP_IS_E3(bp)) {
  11095. int idx = BP_FW_MB_IDX(bp);
  11096. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11097. int path = BP_PATH(bp);
  11098. int port = BP_PORT(bp);
  11099. int i;
  11100. u32 scratch_offset;
  11101. u32 *host_addr;
  11102. /* first write capability to shmem2 */
  11103. if (ulp_type == CNIC_ULP_ISCSI)
  11104. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11105. else if (ulp_type == CNIC_ULP_FCOE)
  11106. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11107. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11108. if ((ulp_type != CNIC_ULP_FCOE) ||
  11109. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11110. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11111. break;
  11112. /* if reached here - should write fcoe capabilities */
  11113. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11114. if (!scratch_offset)
  11115. break;
  11116. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11117. fcoe_features[path][port]);
  11118. host_addr = (u32 *) &(ctl->data.register_data.
  11119. fcoe_features);
  11120. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11121. i += 4)
  11122. REG_WR(bp, scratch_offset + i,
  11123. *(host_addr + i/4));
  11124. }
  11125. break;
  11126. }
  11127. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11128. int ulp_type = ctl->data.ulp_type;
  11129. if (CHIP_IS_E3(bp)) {
  11130. int idx = BP_FW_MB_IDX(bp);
  11131. u32 cap;
  11132. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11133. if (ulp_type == CNIC_ULP_ISCSI)
  11134. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11135. else if (ulp_type == CNIC_ULP_FCOE)
  11136. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11137. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11138. }
  11139. break;
  11140. }
  11141. default:
  11142. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11143. rc = -EINVAL;
  11144. }
  11145. return rc;
  11146. }
  11147. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11148. {
  11149. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11150. if (bp->flags & USING_MSIX_FLAG) {
  11151. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11152. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11153. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11154. } else {
  11155. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11156. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11157. }
  11158. if (!CHIP_IS_E1x(bp))
  11159. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11160. else
  11161. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11162. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11163. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11164. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11165. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11166. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11167. cp->num_irq = 2;
  11168. }
  11169. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11170. {
  11171. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11172. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11173. bnx2x_cid_ilt_lines(bp);
  11174. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11175. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11176. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11177. if (NO_ISCSI_OOO(bp))
  11178. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11179. }
  11180. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11181. void *data)
  11182. {
  11183. struct bnx2x *bp = netdev_priv(dev);
  11184. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11185. int rc;
  11186. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11187. if (ops == NULL) {
  11188. BNX2X_ERR("NULL ops received\n");
  11189. return -EINVAL;
  11190. }
  11191. if (!CNIC_SUPPORT(bp)) {
  11192. BNX2X_ERR("Can't register CNIC when not supported\n");
  11193. return -EOPNOTSUPP;
  11194. }
  11195. if (!CNIC_LOADED(bp)) {
  11196. rc = bnx2x_load_cnic(bp);
  11197. if (rc) {
  11198. BNX2X_ERR("CNIC-related load failed\n");
  11199. return rc;
  11200. }
  11201. }
  11202. bp->cnic_enabled = true;
  11203. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11204. if (!bp->cnic_kwq)
  11205. return -ENOMEM;
  11206. bp->cnic_kwq_cons = bp->cnic_kwq;
  11207. bp->cnic_kwq_prod = bp->cnic_kwq;
  11208. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11209. bp->cnic_spq_pending = 0;
  11210. bp->cnic_kwq_pending = 0;
  11211. bp->cnic_data = data;
  11212. cp->num_irq = 0;
  11213. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11214. cp->iro_arr = bp->iro_arr;
  11215. bnx2x_setup_cnic_irq_info(bp);
  11216. rcu_assign_pointer(bp->cnic_ops, ops);
  11217. return 0;
  11218. }
  11219. static int bnx2x_unregister_cnic(struct net_device *dev)
  11220. {
  11221. struct bnx2x *bp = netdev_priv(dev);
  11222. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11223. mutex_lock(&bp->cnic_mutex);
  11224. cp->drv_state = 0;
  11225. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11226. mutex_unlock(&bp->cnic_mutex);
  11227. synchronize_rcu();
  11228. kfree(bp->cnic_kwq);
  11229. bp->cnic_kwq = NULL;
  11230. return 0;
  11231. }
  11232. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11233. {
  11234. struct bnx2x *bp = netdev_priv(dev);
  11235. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11236. /* If both iSCSI and FCoE are disabled - return NULL in
  11237. * order to indicate CNIC that it should not try to work
  11238. * with this device.
  11239. */
  11240. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11241. return NULL;
  11242. cp->drv_owner = THIS_MODULE;
  11243. cp->chip_id = CHIP_ID(bp);
  11244. cp->pdev = bp->pdev;
  11245. cp->io_base = bp->regview;
  11246. cp->io_base2 = bp->doorbells;
  11247. cp->max_kwqe_pending = 8;
  11248. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11249. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11250. bnx2x_cid_ilt_lines(bp);
  11251. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11252. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11253. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11254. cp->drv_ctl = bnx2x_drv_ctl;
  11255. cp->drv_register_cnic = bnx2x_register_cnic;
  11256. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11257. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11258. cp->iscsi_l2_client_id =
  11259. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11260. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11261. if (NO_ISCSI_OOO(bp))
  11262. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11263. if (NO_ISCSI(bp))
  11264. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11265. if (NO_FCOE(bp))
  11266. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11267. BNX2X_DEV_INFO(
  11268. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11269. cp->ctx_blk_size,
  11270. cp->ctx_tbl_offset,
  11271. cp->ctx_tbl_len,
  11272. cp->starting_cid);
  11273. return cp;
  11274. }
  11275. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11276. {
  11277. struct bnx2x *bp = fp->bp;
  11278. u32 offset = BAR_USTRORM_INTMEM;
  11279. if (IS_VF(bp))
  11280. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11281. else if (!CHIP_IS_E1x(bp))
  11282. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11283. else
  11284. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11285. return offset;
  11286. }
  11287. /* called only on E1H or E2.
  11288. * When pretending to be PF, the pretend value is the function number 0...7
  11289. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11290. * combination
  11291. */
  11292. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11293. {
  11294. u32 pretend_reg;
  11295. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11296. return -1;
  11297. /* get my own pretend register */
  11298. pretend_reg = bnx2x_get_pretend_reg(bp);
  11299. REG_WR(bp, pretend_reg, pretend_func_val);
  11300. REG_RD(bp, pretend_reg);
  11301. return 0;
  11302. }