bnx2x_main.c 403 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883
  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: Ariel Elior <ariel.elior@qlogic.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/aer.h>
  29. #include <linux/init.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/bitops.h>
  35. #include <linux/irq.h>
  36. #include <linux/delay.h>
  37. #include <asm/byteorder.h>
  38. #include <linux/time.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mii.h>
  41. #include <linux/if_vlan.h>
  42. #include <linux/crash_dump.h>
  43. #include <net/ip.h>
  44. #include <net/ipv6.h>
  45. #include <net/tcp.h>
  46. #include <net/vxlan.h>
  47. #include <net/checksum.h>
  48. #include <net/ip6_checksum.h>
  49. #include <linux/workqueue.h>
  50. #include <linux/crc32.h>
  51. #include <linux/crc32c.h>
  52. #include <linux/prefetch.h>
  53. #include <linux/zlib.h>
  54. #include <linux/io.h>
  55. #include <linux/semaphore.h>
  56. #include <linux/stringify.h>
  57. #include <linux/vmalloc.h>
  58. #include "bnx2x.h"
  59. #include "bnx2x_init.h"
  60. #include "bnx2x_init_ops.h"
  61. #include "bnx2x_cmn.h"
  62. #include "bnx2x_vfpf.h"
  63. #include "bnx2x_dcb.h"
  64. #include "bnx2x_sp.h"
  65. #include <linux/firmware.h>
  66. #include "bnx2x_fw_file_hdr.h"
  67. /* FW files */
  68. #define FW_FILE_VERSION \
  69. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  70. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  71. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  72. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  73. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  74. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  75. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  76. /* Time in jiffies before concluding the transmitter is hung */
  77. #define TX_TIMEOUT (5*HZ)
  78. static char version[] =
  79. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  80. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  81. MODULE_AUTHOR("Eliezer Tamir");
  82. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  83. "BCM57710/57711/57711E/"
  84. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  85. "57840/57840_MF Driver");
  86. MODULE_LICENSE("GPL");
  87. MODULE_VERSION(DRV_MODULE_VERSION);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  89. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  90. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  91. int bnx2x_num_queues;
  92. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  93. MODULE_PARM_DESC(num_queues,
  94. " Set number of queues (default is as a number of CPUs)");
  95. static int disable_tpa;
  96. module_param(disable_tpa, int, S_IRUGO);
  97. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  98. static int int_mode;
  99. module_param(int_mode, int, S_IRUGO);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, S_IRUGO);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, S_IRUGO);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, S_IRUGO);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. static struct workqueue_struct *bnx2x_wq;
  112. struct workqueue_struct *bnx2x_iov_wq;
  113. struct bnx2x_mac_vals {
  114. u32 xmac_addr;
  115. u32 xmac_val;
  116. u32 emac_addr;
  117. u32 emac_val;
  118. u32 umac_addr[2];
  119. u32 umac_val[2];
  120. u32 bmac_addr;
  121. u32 bmac_val[2];
  122. };
  123. enum bnx2x_board_type {
  124. BCM57710 = 0,
  125. BCM57711,
  126. BCM57711E,
  127. BCM57712,
  128. BCM57712_MF,
  129. BCM57712_VF,
  130. BCM57800,
  131. BCM57800_MF,
  132. BCM57800_VF,
  133. BCM57810,
  134. BCM57810_MF,
  135. BCM57810_VF,
  136. BCM57840_4_10,
  137. BCM57840_2_20,
  138. BCM57840_MF,
  139. BCM57840_VF,
  140. BCM57811,
  141. BCM57811_MF,
  142. BCM57840_O,
  143. BCM57840_MFO,
  144. BCM57811_VF
  145. };
  146. /* indexed by board_type, above */
  147. static struct {
  148. char *name;
  149. } board_info[] = {
  150. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  151. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  152. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  153. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  154. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  155. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  156. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  157. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  158. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  159. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  160. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  161. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  162. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  163. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  164. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  165. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  166. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  167. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  168. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  169. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  170. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  171. };
  172. #ifndef PCI_DEVICE_ID_NX2_57710
  173. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  174. #endif
  175. #ifndef PCI_DEVICE_ID_NX2_57711
  176. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  177. #endif
  178. #ifndef PCI_DEVICE_ID_NX2_57711E
  179. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  180. #endif
  181. #ifndef PCI_DEVICE_ID_NX2_57712
  182. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  183. #endif
  184. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  185. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  186. #endif
  187. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  188. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  189. #endif
  190. #ifndef PCI_DEVICE_ID_NX2_57800
  191. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  192. #endif
  193. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  194. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  195. #endif
  196. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  197. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  198. #endif
  199. #ifndef PCI_DEVICE_ID_NX2_57810
  200. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  201. #endif
  202. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  203. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  204. #endif
  205. #ifndef PCI_DEVICE_ID_NX2_57840_O
  206. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  207. #endif
  208. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  209. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  210. #endif
  211. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  212. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  213. #endif
  214. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  215. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  216. #endif
  217. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  218. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  219. #endif
  220. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  221. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  222. #endif
  223. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  224. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  225. #endif
  226. #ifndef PCI_DEVICE_ID_NX2_57811
  227. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  228. #endif
  229. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  230. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  231. #endif
  232. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  233. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  234. #endif
  235. static const struct pci_device_id bnx2x_pci_tbl[] = {
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  256. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  257. { 0 }
  258. };
  259. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  260. /* Global resources for unloading a previously loaded device */
  261. #define BNX2X_PREV_WAIT_NEEDED 1
  262. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  263. static LIST_HEAD(bnx2x_prev_list);
  264. /* Forward declaration */
  265. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  266. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  267. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  268. /****************************************************************************
  269. * General service functions
  270. ****************************************************************************/
  271. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  272. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  273. u32 addr, dma_addr_t mapping)
  274. {
  275. REG_WR(bp, addr, U64_LO(mapping));
  276. REG_WR(bp, addr + 4, U64_HI(mapping));
  277. }
  278. static void storm_memset_spq_addr(struct bnx2x *bp,
  279. dma_addr_t mapping, u16 abs_fid)
  280. {
  281. u32 addr = XSEM_REG_FAST_MEMORY +
  282. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  283. __storm_memset_dma_mapping(bp, addr, mapping);
  284. }
  285. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  286. u16 pf_id)
  287. {
  288. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  291. pf_id);
  292. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  293. pf_id);
  294. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  295. pf_id);
  296. }
  297. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  298. u8 enable)
  299. {
  300. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  303. enable);
  304. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  305. enable);
  306. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  307. enable);
  308. }
  309. static void storm_memset_eq_data(struct bnx2x *bp,
  310. struct event_ring_data *eq_data,
  311. u16 pfid)
  312. {
  313. size_t size = sizeof(struct event_ring_data);
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  315. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  316. }
  317. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  318. u16 pfid)
  319. {
  320. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  321. REG_WR16(bp, addr, eq_prod);
  322. }
  323. /* used only at init
  324. * locking is done by mcp
  325. */
  326. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  327. {
  328. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  331. PCICFG_VENDOR_ID_OFFSET);
  332. }
  333. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  334. {
  335. u32 val;
  336. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  337. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  338. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  339. PCICFG_VENDOR_ID_OFFSET);
  340. return val;
  341. }
  342. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  343. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  344. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  345. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  346. #define DMAE_DP_DST_NONE "dst_addr [none]"
  347. static void bnx2x_dp_dmae(struct bnx2x *bp,
  348. struct dmae_command *dmae, int msglvl)
  349. {
  350. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  351. int i;
  352. switch (dmae->opcode & DMAE_COMMAND_DST) {
  353. case DMAE_CMD_DST_PCI:
  354. if (src_type == DMAE_CMD_SRC_PCI)
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. else
  363. DP(msglvl, "DMAE: opcode 0x%08x\n"
  364. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  365. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  366. dmae->opcode, dmae->src_addr_lo >> 2,
  367. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  368. dmae->comp_addr_hi, dmae->comp_addr_lo,
  369. dmae->comp_val);
  370. break;
  371. case DMAE_CMD_DST_GRC:
  372. if (src_type == DMAE_CMD_SRC_PCI)
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. else
  381. DP(msglvl, "DMAE: opcode 0x%08x\n"
  382. "src [%08x], len [%d*4], dst [%08x]\n"
  383. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  384. dmae->opcode, dmae->src_addr_lo >> 2,
  385. dmae->len, dmae->dst_addr_lo >> 2,
  386. dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. break;
  389. default:
  390. if (src_type == DMAE_CMD_SRC_PCI)
  391. DP(msglvl, "DMAE: opcode 0x%08x\n"
  392. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  393. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  394. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  395. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  396. dmae->comp_val);
  397. else
  398. DP(msglvl, "DMAE: opcode 0x%08x\n"
  399. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  400. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  401. dmae->opcode, dmae->src_addr_lo >> 2,
  402. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  403. dmae->comp_val);
  404. break;
  405. }
  406. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  407. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  408. i, *(((u32 *)dmae) + i));
  409. }
  410. /* copy command into DMAE command memory and set DMAE command go */
  411. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  412. {
  413. u32 cmd_offset;
  414. int i;
  415. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  416. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  417. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  418. }
  419. REG_WR(bp, dmae_reg_go_c[idx], 1);
  420. }
  421. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  422. {
  423. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  424. DMAE_CMD_C_ENABLE);
  425. }
  426. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  427. {
  428. return opcode & ~DMAE_CMD_SRC_RESET;
  429. }
  430. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  431. bool with_comp, u8 comp_type)
  432. {
  433. u32 opcode = 0;
  434. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  435. (dst_type << DMAE_COMMAND_DST_SHIFT));
  436. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  437. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  438. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  439. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  440. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  441. #ifdef __BIG_ENDIAN
  442. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  443. #else
  444. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  445. #endif
  446. if (with_comp)
  447. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  448. return opcode;
  449. }
  450. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  451. struct dmae_command *dmae,
  452. u8 src_type, u8 dst_type)
  453. {
  454. memset(dmae, 0, sizeof(struct dmae_command));
  455. /* set the opcode */
  456. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  457. true, DMAE_COMP_PCI);
  458. /* fill in the completion parameters */
  459. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  460. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  461. dmae->comp_val = DMAE_COMP_VAL;
  462. }
  463. /* issue a dmae command over the init-channel and wait for completion */
  464. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  465. u32 *comp)
  466. {
  467. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  468. int rc = 0;
  469. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  470. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  471. * as long as this code is called both from syscall context and
  472. * from ndo_set_rx_mode() flow that may be called from BH.
  473. */
  474. spin_lock_bh(&bp->dmae_lock);
  475. /* reset completion */
  476. *comp = 0;
  477. /* post the command on the channel used for initializations */
  478. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  479. /* wait for completion */
  480. udelay(5);
  481. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  482. if (!cnt ||
  483. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  484. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  485. BNX2X_ERR("DMAE timeout!\n");
  486. rc = DMAE_TIMEOUT;
  487. goto unlock;
  488. }
  489. cnt--;
  490. udelay(50);
  491. }
  492. if (*comp & DMAE_PCI_ERR_FLAG) {
  493. BNX2X_ERR("DMAE PCI error!\n");
  494. rc = DMAE_PCI_ERROR;
  495. }
  496. unlock:
  497. spin_unlock_bh(&bp->dmae_lock);
  498. return rc;
  499. }
  500. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  501. u32 len32)
  502. {
  503. int rc;
  504. struct dmae_command dmae;
  505. if (!bp->dmae_ready) {
  506. u32 *data = bnx2x_sp(bp, wb_data[0]);
  507. if (CHIP_IS_E1(bp))
  508. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  509. else
  510. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  511. return;
  512. }
  513. /* set opcode and fixed command fields */
  514. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  515. /* fill in addresses and len */
  516. dmae.src_addr_lo = U64_LO(dma_addr);
  517. dmae.src_addr_hi = U64_HI(dma_addr);
  518. dmae.dst_addr_lo = dst_addr >> 2;
  519. dmae.dst_addr_hi = 0;
  520. dmae.len = len32;
  521. /* issue the command and wait for completion */
  522. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  523. if (rc) {
  524. BNX2X_ERR("DMAE returned failure %d\n", rc);
  525. #ifdef BNX2X_STOP_ON_ERROR
  526. bnx2x_panic();
  527. #endif
  528. }
  529. }
  530. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  531. {
  532. int rc;
  533. struct dmae_command dmae;
  534. if (!bp->dmae_ready) {
  535. u32 *data = bnx2x_sp(bp, wb_data[0]);
  536. int i;
  537. if (CHIP_IS_E1(bp))
  538. for (i = 0; i < len32; i++)
  539. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  540. else
  541. for (i = 0; i < len32; i++)
  542. data[i] = REG_RD(bp, src_addr + i*4);
  543. return;
  544. }
  545. /* set opcode and fixed command fields */
  546. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  547. /* fill in addresses and len */
  548. dmae.src_addr_lo = src_addr >> 2;
  549. dmae.src_addr_hi = 0;
  550. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  551. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  552. dmae.len = len32;
  553. /* issue the command and wait for completion */
  554. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  555. if (rc) {
  556. BNX2X_ERR("DMAE returned failure %d\n", rc);
  557. #ifdef BNX2X_STOP_ON_ERROR
  558. bnx2x_panic();
  559. #endif
  560. }
  561. }
  562. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  563. u32 addr, u32 len)
  564. {
  565. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  566. int offset = 0;
  567. while (len > dmae_wr_max) {
  568. bnx2x_write_dmae(bp, phys_addr + offset,
  569. addr + offset, dmae_wr_max);
  570. offset += dmae_wr_max * 4;
  571. len -= dmae_wr_max;
  572. }
  573. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  574. }
  575. enum storms {
  576. XSTORM,
  577. TSTORM,
  578. CSTORM,
  579. USTORM,
  580. MAX_STORMS
  581. };
  582. #define STORMS_NUM 4
  583. #define REGS_IN_ENTRY 4
  584. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  585. enum storms storm,
  586. int entry)
  587. {
  588. switch (storm) {
  589. case XSTORM:
  590. return XSTORM_ASSERT_LIST_OFFSET(entry);
  591. case TSTORM:
  592. return TSTORM_ASSERT_LIST_OFFSET(entry);
  593. case CSTORM:
  594. return CSTORM_ASSERT_LIST_OFFSET(entry);
  595. case USTORM:
  596. return USTORM_ASSERT_LIST_OFFSET(entry);
  597. case MAX_STORMS:
  598. default:
  599. BNX2X_ERR("unknown storm\n");
  600. }
  601. return -EINVAL;
  602. }
  603. static int bnx2x_mc_assert(struct bnx2x *bp)
  604. {
  605. char last_idx;
  606. int i, j, rc = 0;
  607. enum storms storm;
  608. u32 regs[REGS_IN_ENTRY];
  609. u32 bar_storm_intmem[STORMS_NUM] = {
  610. BAR_XSTRORM_INTMEM,
  611. BAR_TSTRORM_INTMEM,
  612. BAR_CSTRORM_INTMEM,
  613. BAR_USTRORM_INTMEM
  614. };
  615. u32 storm_assert_list_index[STORMS_NUM] = {
  616. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  617. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  618. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  619. USTORM_ASSERT_LIST_INDEX_OFFSET
  620. };
  621. char *storms_string[STORMS_NUM] = {
  622. "XSTORM",
  623. "TSTORM",
  624. "CSTORM",
  625. "USTORM"
  626. };
  627. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  628. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  629. storm_assert_list_index[storm]);
  630. if (last_idx)
  631. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  632. storms_string[storm], last_idx);
  633. /* print the asserts */
  634. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  635. /* read a single assert entry */
  636. for (j = 0; j < REGS_IN_ENTRY; j++)
  637. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  638. bnx2x_get_assert_list_entry(bp,
  639. storm,
  640. i) +
  641. sizeof(u32) * j);
  642. /* log entry if it contains a valid assert */
  643. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  644. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  645. storms_string[storm], i, regs[3],
  646. regs[2], regs[1], regs[0]);
  647. rc++;
  648. } else {
  649. break;
  650. }
  651. }
  652. }
  653. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  654. CHIP_IS_E1(bp) ? "everest1" :
  655. CHIP_IS_E1H(bp) ? "everest1h" :
  656. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  657. BCM_5710_FW_MAJOR_VERSION,
  658. BCM_5710_FW_MINOR_VERSION,
  659. BCM_5710_FW_REVISION_VERSION);
  660. return rc;
  661. }
  662. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  663. #define SCRATCH_BUFFER_SIZE(bp) \
  664. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  665. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  666. {
  667. u32 addr, val;
  668. u32 mark, offset;
  669. __be32 data[9];
  670. int word;
  671. u32 trace_shmem_base;
  672. if (BP_NOMCP(bp)) {
  673. BNX2X_ERR("NO MCP - can not dump\n");
  674. return;
  675. }
  676. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  677. (bp->common.bc_ver & 0xff0000) >> 16,
  678. (bp->common.bc_ver & 0xff00) >> 8,
  679. (bp->common.bc_ver & 0xff));
  680. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  681. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  682. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  683. if (BP_PATH(bp) == 0)
  684. trace_shmem_base = bp->common.shmem_base;
  685. else
  686. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  687. /* sanity */
  688. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  689. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  690. SCRATCH_BUFFER_SIZE(bp)) {
  691. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  692. trace_shmem_base);
  693. return;
  694. }
  695. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  696. /* validate TRCB signature */
  697. mark = REG_RD(bp, addr);
  698. if (mark != MFW_TRACE_SIGNATURE) {
  699. BNX2X_ERR("Trace buffer signature is missing.");
  700. return ;
  701. }
  702. /* read cyclic buffer pointer */
  703. addr += 4;
  704. mark = REG_RD(bp, addr);
  705. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  706. if (mark >= trace_shmem_base || mark < addr + 4) {
  707. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  708. return;
  709. }
  710. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  711. printk("%s", lvl);
  712. /* dump buffer after the mark */
  713. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  714. for (word = 0; word < 8; word++)
  715. data[word] = htonl(REG_RD(bp, offset + 4*word));
  716. data[8] = 0x0;
  717. pr_cont("%s", (char *)data);
  718. }
  719. /* dump buffer before the mark */
  720. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  721. for (word = 0; word < 8; word++)
  722. data[word] = htonl(REG_RD(bp, offset + 4*word));
  723. data[8] = 0x0;
  724. pr_cont("%s", (char *)data);
  725. }
  726. printk("%s" "end of fw dump\n", lvl);
  727. }
  728. static void bnx2x_fw_dump(struct bnx2x *bp)
  729. {
  730. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  731. }
  732. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  733. {
  734. int port = BP_PORT(bp);
  735. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  736. u32 val = REG_RD(bp, addr);
  737. /* in E1 we must use only PCI configuration space to disable
  738. * MSI/MSIX capability
  739. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  740. */
  741. if (CHIP_IS_E1(bp)) {
  742. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  743. * Use mask register to prevent from HC sending interrupts
  744. * after we exit the function
  745. */
  746. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  747. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  748. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  749. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  750. } else
  751. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  752. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  753. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  754. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  755. DP(NETIF_MSG_IFDOWN,
  756. "write %x to HC %d (addr 0x%x)\n",
  757. val, port, addr);
  758. /* flush all outstanding writes */
  759. mmiowb();
  760. REG_WR(bp, addr, val);
  761. if (REG_RD(bp, addr) != val)
  762. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  763. }
  764. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  765. {
  766. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  767. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  768. IGU_PF_CONF_INT_LINE_EN |
  769. IGU_PF_CONF_ATTN_BIT_EN);
  770. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  771. /* flush all outstanding writes */
  772. mmiowb();
  773. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  774. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  775. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  776. }
  777. static void bnx2x_int_disable(struct bnx2x *bp)
  778. {
  779. if (bp->common.int_block == INT_BLOCK_HC)
  780. bnx2x_hc_int_disable(bp);
  781. else
  782. bnx2x_igu_int_disable(bp);
  783. }
  784. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  785. {
  786. int i;
  787. u16 j;
  788. struct hc_sp_status_block_data sp_sb_data;
  789. int func = BP_FUNC(bp);
  790. #ifdef BNX2X_STOP_ON_ERROR
  791. u16 start = 0, end = 0;
  792. u8 cos;
  793. #endif
  794. if (IS_PF(bp) && disable_int)
  795. bnx2x_int_disable(bp);
  796. bp->stats_state = STATS_STATE_DISABLED;
  797. bp->eth_stats.unrecoverable_error++;
  798. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  799. BNX2X_ERR("begin crash dump -----------------\n");
  800. /* Indices */
  801. /* Common */
  802. if (IS_PF(bp)) {
  803. struct host_sp_status_block *def_sb = bp->def_status_blk;
  804. int data_size, cstorm_offset;
  805. 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",
  806. bp->def_idx, bp->def_att_idx, bp->attn_state,
  807. bp->spq_prod_idx, bp->stats_counter);
  808. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  809. def_sb->atten_status_block.attn_bits,
  810. def_sb->atten_status_block.attn_bits_ack,
  811. def_sb->atten_status_block.status_block_id,
  812. def_sb->atten_status_block.attn_bits_index);
  813. BNX2X_ERR(" def (");
  814. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  815. pr_cont("0x%x%s",
  816. def_sb->sp_sb.index_values[i],
  817. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  818. data_size = sizeof(struct hc_sp_status_block_data) /
  819. sizeof(u32);
  820. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  821. for (i = 0; i < data_size; i++)
  822. *((u32 *)&sp_sb_data + i) =
  823. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  824. i * sizeof(u32));
  825. 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",
  826. sp_sb_data.igu_sb_id,
  827. sp_sb_data.igu_seg_id,
  828. sp_sb_data.p_func.pf_id,
  829. sp_sb_data.p_func.vnic_id,
  830. sp_sb_data.p_func.vf_id,
  831. sp_sb_data.p_func.vf_valid,
  832. sp_sb_data.state);
  833. }
  834. for_each_eth_queue(bp, i) {
  835. struct bnx2x_fastpath *fp = &bp->fp[i];
  836. int loop;
  837. struct hc_status_block_data_e2 sb_data_e2;
  838. struct hc_status_block_data_e1x sb_data_e1x;
  839. struct hc_status_block_sm *hc_sm_p =
  840. CHIP_IS_E1x(bp) ?
  841. sb_data_e1x.common.state_machine :
  842. sb_data_e2.common.state_machine;
  843. struct hc_index_data *hc_index_p =
  844. CHIP_IS_E1x(bp) ?
  845. sb_data_e1x.index_data :
  846. sb_data_e2.index_data;
  847. u8 data_size, cos;
  848. u32 *sb_data_p;
  849. struct bnx2x_fp_txdata txdata;
  850. if (!bp->fp)
  851. break;
  852. if (!fp->rx_cons_sb)
  853. continue;
  854. /* Rx */
  855. 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",
  856. i, fp->rx_bd_prod, fp->rx_bd_cons,
  857. fp->rx_comp_prod,
  858. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  859. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  860. fp->rx_sge_prod, fp->last_max_sge,
  861. le16_to_cpu(fp->fp_hc_idx));
  862. /* Tx */
  863. for_each_cos_in_tx_queue(fp, cos)
  864. {
  865. if (!fp->txdata_ptr[cos])
  866. break;
  867. txdata = *fp->txdata_ptr[cos];
  868. if (!txdata.tx_cons_sb)
  869. continue;
  870. 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",
  871. i, txdata.tx_pkt_prod,
  872. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  873. txdata.tx_bd_cons,
  874. le16_to_cpu(*txdata.tx_cons_sb));
  875. }
  876. loop = CHIP_IS_E1x(bp) ?
  877. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  878. /* host sb data */
  879. if (IS_FCOE_FP(fp))
  880. continue;
  881. BNX2X_ERR(" run indexes (");
  882. for (j = 0; j < HC_SB_MAX_SM; j++)
  883. pr_cont("0x%x%s",
  884. fp->sb_running_index[j],
  885. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  886. BNX2X_ERR(" indexes (");
  887. for (j = 0; j < loop; j++)
  888. pr_cont("0x%x%s",
  889. fp->sb_index_values[j],
  890. (j == loop - 1) ? ")" : " ");
  891. /* VF cannot access FW refelection for status block */
  892. if (IS_VF(bp))
  893. continue;
  894. /* fw sb data */
  895. data_size = CHIP_IS_E1x(bp) ?
  896. sizeof(struct hc_status_block_data_e1x) :
  897. sizeof(struct hc_status_block_data_e2);
  898. data_size /= sizeof(u32);
  899. sb_data_p = CHIP_IS_E1x(bp) ?
  900. (u32 *)&sb_data_e1x :
  901. (u32 *)&sb_data_e2;
  902. /* copy sb data in here */
  903. for (j = 0; j < data_size; j++)
  904. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  905. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  906. j * sizeof(u32));
  907. if (!CHIP_IS_E1x(bp)) {
  908. 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",
  909. sb_data_e2.common.p_func.pf_id,
  910. sb_data_e2.common.p_func.vf_id,
  911. sb_data_e2.common.p_func.vf_valid,
  912. sb_data_e2.common.p_func.vnic_id,
  913. sb_data_e2.common.same_igu_sb_1b,
  914. sb_data_e2.common.state);
  915. } else {
  916. 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",
  917. sb_data_e1x.common.p_func.pf_id,
  918. sb_data_e1x.common.p_func.vf_id,
  919. sb_data_e1x.common.p_func.vf_valid,
  920. sb_data_e1x.common.p_func.vnic_id,
  921. sb_data_e1x.common.same_igu_sb_1b,
  922. sb_data_e1x.common.state);
  923. }
  924. /* SB_SMs data */
  925. for (j = 0; j < HC_SB_MAX_SM; j++) {
  926. 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",
  927. j, hc_sm_p[j].__flags,
  928. hc_sm_p[j].igu_sb_id,
  929. hc_sm_p[j].igu_seg_id,
  930. hc_sm_p[j].time_to_expire,
  931. hc_sm_p[j].timer_value);
  932. }
  933. /* Indices data */
  934. for (j = 0; j < loop; j++) {
  935. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  936. hc_index_p[j].flags,
  937. hc_index_p[j].timeout);
  938. }
  939. }
  940. #ifdef BNX2X_STOP_ON_ERROR
  941. if (IS_PF(bp)) {
  942. /* event queue */
  943. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  944. for (i = 0; i < NUM_EQ_DESC; i++) {
  945. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  946. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  947. i, bp->eq_ring[i].message.opcode,
  948. bp->eq_ring[i].message.error);
  949. BNX2X_ERR("data: %x %x %x\n",
  950. data[0], data[1], data[2]);
  951. }
  952. }
  953. /* Rings */
  954. /* Rx */
  955. for_each_valid_rx_queue(bp, i) {
  956. struct bnx2x_fastpath *fp = &bp->fp[i];
  957. if (!bp->fp)
  958. break;
  959. if (!fp->rx_cons_sb)
  960. continue;
  961. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  962. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  963. for (j = start; j != end; j = RX_BD(j + 1)) {
  964. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  965. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  966. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  967. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  968. }
  969. start = RX_SGE(fp->rx_sge_prod);
  970. end = RX_SGE(fp->last_max_sge);
  971. for (j = start; j != end; j = RX_SGE(j + 1)) {
  972. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  973. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  974. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  975. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  976. }
  977. start = RCQ_BD(fp->rx_comp_cons - 10);
  978. end = RCQ_BD(fp->rx_comp_cons + 503);
  979. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  980. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  981. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  982. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  983. }
  984. }
  985. /* Tx */
  986. for_each_valid_tx_queue(bp, i) {
  987. struct bnx2x_fastpath *fp = &bp->fp[i];
  988. if (!bp->fp)
  989. break;
  990. for_each_cos_in_tx_queue(fp, cos) {
  991. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  992. if (!fp->txdata_ptr[cos])
  993. break;
  994. if (!txdata->tx_cons_sb)
  995. continue;
  996. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  997. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  998. for (j = start; j != end; j = TX_BD(j + 1)) {
  999. struct sw_tx_bd *sw_bd =
  1000. &txdata->tx_buf_ring[j];
  1001. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1002. i, cos, j, sw_bd->skb,
  1003. sw_bd->first_bd);
  1004. }
  1005. start = TX_BD(txdata->tx_bd_cons - 10);
  1006. end = TX_BD(txdata->tx_bd_cons + 254);
  1007. for (j = start; j != end; j = TX_BD(j + 1)) {
  1008. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1009. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1010. i, cos, j, tx_bd[0], tx_bd[1],
  1011. tx_bd[2], tx_bd[3]);
  1012. }
  1013. }
  1014. }
  1015. #endif
  1016. if (IS_PF(bp)) {
  1017. bnx2x_fw_dump(bp);
  1018. bnx2x_mc_assert(bp);
  1019. }
  1020. BNX2X_ERR("end crash dump -----------------\n");
  1021. }
  1022. /*
  1023. * FLR Support for E2
  1024. *
  1025. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1026. * initialization.
  1027. */
  1028. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1029. #define FLR_WAIT_INTERVAL 50 /* usec */
  1030. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1031. struct pbf_pN_buf_regs {
  1032. int pN;
  1033. u32 init_crd;
  1034. u32 crd;
  1035. u32 crd_freed;
  1036. };
  1037. struct pbf_pN_cmd_regs {
  1038. int pN;
  1039. u32 lines_occup;
  1040. u32 lines_freed;
  1041. };
  1042. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1043. struct pbf_pN_buf_regs *regs,
  1044. u32 poll_count)
  1045. {
  1046. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1047. u32 cur_cnt = poll_count;
  1048. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1049. crd = crd_start = REG_RD(bp, regs->crd);
  1050. init_crd = REG_RD(bp, regs->init_crd);
  1051. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1052. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1053. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1054. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1055. (init_crd - crd_start))) {
  1056. if (cur_cnt--) {
  1057. udelay(FLR_WAIT_INTERVAL);
  1058. crd = REG_RD(bp, regs->crd);
  1059. crd_freed = REG_RD(bp, regs->crd_freed);
  1060. } else {
  1061. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1062. regs->pN);
  1063. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1064. regs->pN, crd);
  1065. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1066. regs->pN, crd_freed);
  1067. break;
  1068. }
  1069. }
  1070. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1071. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1072. }
  1073. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1074. struct pbf_pN_cmd_regs *regs,
  1075. u32 poll_count)
  1076. {
  1077. u32 occup, to_free, freed, freed_start;
  1078. u32 cur_cnt = poll_count;
  1079. occup = to_free = REG_RD(bp, regs->lines_occup);
  1080. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1081. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1082. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1083. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1084. if (cur_cnt--) {
  1085. udelay(FLR_WAIT_INTERVAL);
  1086. occup = REG_RD(bp, regs->lines_occup);
  1087. freed = REG_RD(bp, regs->lines_freed);
  1088. } else {
  1089. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1090. regs->pN);
  1091. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1092. regs->pN, occup);
  1093. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1094. regs->pN, freed);
  1095. break;
  1096. }
  1097. }
  1098. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1099. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1100. }
  1101. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1102. u32 expected, u32 poll_count)
  1103. {
  1104. u32 cur_cnt = poll_count;
  1105. u32 val;
  1106. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1107. udelay(FLR_WAIT_INTERVAL);
  1108. return val;
  1109. }
  1110. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1111. char *msg, u32 poll_cnt)
  1112. {
  1113. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1114. if (val != 0) {
  1115. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1116. return 1;
  1117. }
  1118. return 0;
  1119. }
  1120. /* Common routines with VF FLR cleanup */
  1121. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1122. {
  1123. /* adjust polling timeout */
  1124. if (CHIP_REV_IS_EMUL(bp))
  1125. return FLR_POLL_CNT * 2000;
  1126. if (CHIP_REV_IS_FPGA(bp))
  1127. return FLR_POLL_CNT * 120;
  1128. return FLR_POLL_CNT;
  1129. }
  1130. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1131. {
  1132. struct pbf_pN_cmd_regs cmd_regs[] = {
  1133. {0, (CHIP_IS_E3B0(bp)) ?
  1134. PBF_REG_TQ_OCCUPANCY_Q0 :
  1135. PBF_REG_P0_TQ_OCCUPANCY,
  1136. (CHIP_IS_E3B0(bp)) ?
  1137. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1138. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1139. {1, (CHIP_IS_E3B0(bp)) ?
  1140. PBF_REG_TQ_OCCUPANCY_Q1 :
  1141. PBF_REG_P1_TQ_OCCUPANCY,
  1142. (CHIP_IS_E3B0(bp)) ?
  1143. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1144. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1145. {4, (CHIP_IS_E3B0(bp)) ?
  1146. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1147. PBF_REG_P4_TQ_OCCUPANCY,
  1148. (CHIP_IS_E3B0(bp)) ?
  1149. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1150. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1151. };
  1152. struct pbf_pN_buf_regs buf_regs[] = {
  1153. {0, (CHIP_IS_E3B0(bp)) ?
  1154. PBF_REG_INIT_CRD_Q0 :
  1155. PBF_REG_P0_INIT_CRD ,
  1156. (CHIP_IS_E3B0(bp)) ?
  1157. PBF_REG_CREDIT_Q0 :
  1158. PBF_REG_P0_CREDIT,
  1159. (CHIP_IS_E3B0(bp)) ?
  1160. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1161. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1162. {1, (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INIT_CRD_Q1 :
  1164. PBF_REG_P1_INIT_CRD,
  1165. (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_CREDIT_Q1 :
  1167. PBF_REG_P1_CREDIT,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1170. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1171. {4, (CHIP_IS_E3B0(bp)) ?
  1172. PBF_REG_INIT_CRD_LB_Q :
  1173. PBF_REG_P4_INIT_CRD,
  1174. (CHIP_IS_E3B0(bp)) ?
  1175. PBF_REG_CREDIT_LB_Q :
  1176. PBF_REG_P4_CREDIT,
  1177. (CHIP_IS_E3B0(bp)) ?
  1178. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1179. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1180. };
  1181. int i;
  1182. /* Verify the command queues are flushed P0, P1, P4 */
  1183. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1184. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1185. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1186. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1187. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1188. }
  1189. #define OP_GEN_PARAM(param) \
  1190. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1191. #define OP_GEN_TYPE(type) \
  1192. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1193. #define OP_GEN_AGG_VECT(index) \
  1194. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1195. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1196. {
  1197. u32 op_gen_command = 0;
  1198. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1199. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1200. int ret = 0;
  1201. if (REG_RD(bp, comp_addr)) {
  1202. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1203. return 1;
  1204. }
  1205. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1206. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1207. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1208. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1209. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1210. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1211. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1212. BNX2X_ERR("FW final cleanup did not succeed\n");
  1213. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1214. (REG_RD(bp, comp_addr)));
  1215. bnx2x_panic();
  1216. return 1;
  1217. }
  1218. /* Zero completion for next FLR */
  1219. REG_WR(bp, comp_addr, 0);
  1220. return ret;
  1221. }
  1222. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1223. {
  1224. u16 status;
  1225. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1226. return status & PCI_EXP_DEVSTA_TRPND;
  1227. }
  1228. /* PF FLR specific routines
  1229. */
  1230. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1231. {
  1232. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1233. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1234. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1235. "CFC PF usage counter timed out",
  1236. poll_cnt))
  1237. return 1;
  1238. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1239. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1240. DORQ_REG_PF_USAGE_CNT,
  1241. "DQ PF usage counter timed out",
  1242. poll_cnt))
  1243. return 1;
  1244. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1245. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1246. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1247. "QM PF usage counter timed out",
  1248. poll_cnt))
  1249. return 1;
  1250. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1251. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1252. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1253. "Timers VNIC usage counter timed out",
  1254. poll_cnt))
  1255. return 1;
  1256. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1257. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1258. "Timers NUM_SCANS usage counter timed out",
  1259. poll_cnt))
  1260. return 1;
  1261. /* Wait DMAE PF usage counter to zero */
  1262. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1263. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1264. "DMAE command register timed out",
  1265. poll_cnt))
  1266. return 1;
  1267. return 0;
  1268. }
  1269. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1270. {
  1271. u32 val;
  1272. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1273. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1274. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1275. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1276. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1277. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1278. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1279. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1280. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1281. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1282. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1283. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1284. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1285. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1286. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1287. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1288. val);
  1289. }
  1290. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1291. {
  1292. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1293. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1294. /* Re-enable PF target read access */
  1295. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1296. /* Poll HW usage counters */
  1297. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1298. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1299. return -EBUSY;
  1300. /* Zero the igu 'trailing edge' and 'leading edge' */
  1301. /* Send the FW cleanup command */
  1302. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1303. return -EBUSY;
  1304. /* ATC cleanup */
  1305. /* Verify TX hw is flushed */
  1306. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1307. /* Wait 100ms (not adjusted according to platform) */
  1308. msleep(100);
  1309. /* Verify no pending pci transactions */
  1310. if (bnx2x_is_pcie_pending(bp->pdev))
  1311. BNX2X_ERR("PCIE Transactions still pending\n");
  1312. /* Debug */
  1313. bnx2x_hw_enable_status(bp);
  1314. /*
  1315. * Master enable - Due to WB DMAE writes performed before this
  1316. * register is re-initialized as part of the regular function init
  1317. */
  1318. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1319. return 0;
  1320. }
  1321. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1322. {
  1323. int port = BP_PORT(bp);
  1324. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1325. u32 val = REG_RD(bp, addr);
  1326. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1327. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1328. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1329. if (msix) {
  1330. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1331. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1332. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1333. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1334. if (single_msix)
  1335. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1336. } else if (msi) {
  1337. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1338. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1339. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1340. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1341. } else {
  1342. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1343. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1344. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1345. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1346. if (!CHIP_IS_E1(bp)) {
  1347. DP(NETIF_MSG_IFUP,
  1348. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1349. REG_WR(bp, addr, val);
  1350. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1351. }
  1352. }
  1353. if (CHIP_IS_E1(bp))
  1354. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1355. DP(NETIF_MSG_IFUP,
  1356. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1357. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1358. REG_WR(bp, addr, val);
  1359. /*
  1360. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1361. */
  1362. mmiowb();
  1363. barrier();
  1364. if (!CHIP_IS_E1(bp)) {
  1365. /* init leading/trailing edge */
  1366. if (IS_MF(bp)) {
  1367. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1368. if (bp->port.pmf)
  1369. /* enable nig and gpio3 attention */
  1370. val |= 0x1100;
  1371. } else
  1372. val = 0xffff;
  1373. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1374. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1375. }
  1376. /* Make sure that interrupts are indeed enabled from here on */
  1377. mmiowb();
  1378. }
  1379. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1380. {
  1381. u32 val;
  1382. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1383. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1384. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1385. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1386. if (msix) {
  1387. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1388. IGU_PF_CONF_SINGLE_ISR_EN);
  1389. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1390. IGU_PF_CONF_ATTN_BIT_EN);
  1391. if (single_msix)
  1392. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1393. } else if (msi) {
  1394. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1395. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1396. IGU_PF_CONF_ATTN_BIT_EN |
  1397. IGU_PF_CONF_SINGLE_ISR_EN);
  1398. } else {
  1399. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1400. val |= (IGU_PF_CONF_INT_LINE_EN |
  1401. IGU_PF_CONF_ATTN_BIT_EN |
  1402. IGU_PF_CONF_SINGLE_ISR_EN);
  1403. }
  1404. /* Clean previous status - need to configure igu prior to ack*/
  1405. if ((!msix) || single_msix) {
  1406. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1407. bnx2x_ack_int(bp);
  1408. }
  1409. val |= IGU_PF_CONF_FUNC_EN;
  1410. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1411. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1412. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1413. if (val & IGU_PF_CONF_INT_LINE_EN)
  1414. pci_intx(bp->pdev, true);
  1415. barrier();
  1416. /* init leading/trailing edge */
  1417. if (IS_MF(bp)) {
  1418. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1419. if (bp->port.pmf)
  1420. /* enable nig and gpio3 attention */
  1421. val |= 0x1100;
  1422. } else
  1423. val = 0xffff;
  1424. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1425. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1426. /* Make sure that interrupts are indeed enabled from here on */
  1427. mmiowb();
  1428. }
  1429. void bnx2x_int_enable(struct bnx2x *bp)
  1430. {
  1431. if (bp->common.int_block == INT_BLOCK_HC)
  1432. bnx2x_hc_int_enable(bp);
  1433. else
  1434. bnx2x_igu_int_enable(bp);
  1435. }
  1436. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1437. {
  1438. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1439. int i, offset;
  1440. if (disable_hw)
  1441. /* prevent the HW from sending interrupts */
  1442. bnx2x_int_disable(bp);
  1443. /* make sure all ISRs are done */
  1444. if (msix) {
  1445. synchronize_irq(bp->msix_table[0].vector);
  1446. offset = 1;
  1447. if (CNIC_SUPPORT(bp))
  1448. offset++;
  1449. for_each_eth_queue(bp, i)
  1450. synchronize_irq(bp->msix_table[offset++].vector);
  1451. } else
  1452. synchronize_irq(bp->pdev->irq);
  1453. /* make sure sp_task is not running */
  1454. cancel_delayed_work(&bp->sp_task);
  1455. cancel_delayed_work(&bp->period_task);
  1456. flush_workqueue(bnx2x_wq);
  1457. }
  1458. /* fast path */
  1459. /*
  1460. * General service functions
  1461. */
  1462. /* Return true if succeeded to acquire the lock */
  1463. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1464. {
  1465. u32 lock_status;
  1466. u32 resource_bit = (1 << resource);
  1467. int func = BP_FUNC(bp);
  1468. u32 hw_lock_control_reg;
  1469. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1470. "Trying to take a lock on resource %d\n", resource);
  1471. /* Validating that the resource is within range */
  1472. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1473. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1474. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1475. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1476. return false;
  1477. }
  1478. if (func <= 5)
  1479. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1480. else
  1481. hw_lock_control_reg =
  1482. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1483. /* Try to acquire the lock */
  1484. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1485. lock_status = REG_RD(bp, hw_lock_control_reg);
  1486. if (lock_status & resource_bit)
  1487. return true;
  1488. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1489. "Failed to get a lock on resource %d\n", resource);
  1490. return false;
  1491. }
  1492. /**
  1493. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1494. *
  1495. * @bp: driver handle
  1496. *
  1497. * Returns the recovery leader resource id according to the engine this function
  1498. * belongs to. Currently only only 2 engines is supported.
  1499. */
  1500. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1501. {
  1502. if (BP_PATH(bp))
  1503. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1504. else
  1505. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1506. }
  1507. /**
  1508. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1509. *
  1510. * @bp: driver handle
  1511. *
  1512. * Tries to acquire a leader lock for current engine.
  1513. */
  1514. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1515. {
  1516. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1517. }
  1518. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1519. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1520. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1521. {
  1522. /* Set the interrupt occurred bit for the sp-task to recognize it
  1523. * must ack the interrupt and transition according to the IGU
  1524. * state machine.
  1525. */
  1526. atomic_set(&bp->interrupt_occurred, 1);
  1527. /* The sp_task must execute only after this bit
  1528. * is set, otherwise we will get out of sync and miss all
  1529. * further interrupts. Hence, the barrier.
  1530. */
  1531. smp_wmb();
  1532. /* schedule sp_task to workqueue */
  1533. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1534. }
  1535. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1536. {
  1537. struct bnx2x *bp = fp->bp;
  1538. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1539. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1540. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1541. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1542. DP(BNX2X_MSG_SP,
  1543. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1544. fp->index, cid, command, bp->state,
  1545. rr_cqe->ramrod_cqe.ramrod_type);
  1546. /* If cid is within VF range, replace the slowpath object with the
  1547. * one corresponding to this VF
  1548. */
  1549. if (cid >= BNX2X_FIRST_VF_CID &&
  1550. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1551. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1552. switch (command) {
  1553. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1554. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1555. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1556. break;
  1557. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1558. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1559. drv_cmd = BNX2X_Q_CMD_SETUP;
  1560. break;
  1561. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1562. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1563. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1564. break;
  1565. case (RAMROD_CMD_ID_ETH_HALT):
  1566. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1567. drv_cmd = BNX2X_Q_CMD_HALT;
  1568. break;
  1569. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1570. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1571. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1572. break;
  1573. case (RAMROD_CMD_ID_ETH_EMPTY):
  1574. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1575. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1576. break;
  1577. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1578. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1579. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1580. break;
  1581. default:
  1582. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1583. command, fp->index);
  1584. return;
  1585. }
  1586. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1587. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1588. /* q_obj->complete_cmd() failure means that this was
  1589. * an unexpected completion.
  1590. *
  1591. * In this case we don't want to increase the bp->spq_left
  1592. * because apparently we haven't sent this command the first
  1593. * place.
  1594. */
  1595. #ifdef BNX2X_STOP_ON_ERROR
  1596. bnx2x_panic();
  1597. #else
  1598. return;
  1599. #endif
  1600. smp_mb__before_atomic();
  1601. atomic_inc(&bp->cq_spq_left);
  1602. /* push the change in bp->spq_left and towards the memory */
  1603. smp_mb__after_atomic();
  1604. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1605. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1606. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1607. /* if Q update ramrod is completed for last Q in AFEX vif set
  1608. * flow, then ACK MCP at the end
  1609. *
  1610. * mark pending ACK to MCP bit.
  1611. * prevent case that both bits are cleared.
  1612. * At the end of load/unload driver checks that
  1613. * sp_state is cleared, and this order prevents
  1614. * races
  1615. */
  1616. smp_mb__before_atomic();
  1617. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1618. wmb();
  1619. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1620. smp_mb__after_atomic();
  1621. /* schedule the sp task as mcp ack is required */
  1622. bnx2x_schedule_sp_task(bp);
  1623. }
  1624. return;
  1625. }
  1626. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1627. {
  1628. struct bnx2x *bp = netdev_priv(dev_instance);
  1629. u16 status = bnx2x_ack_int(bp);
  1630. u16 mask;
  1631. int i;
  1632. u8 cos;
  1633. /* Return here if interrupt is shared and it's not for us */
  1634. if (unlikely(status == 0)) {
  1635. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1636. return IRQ_NONE;
  1637. }
  1638. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1639. #ifdef BNX2X_STOP_ON_ERROR
  1640. if (unlikely(bp->panic))
  1641. return IRQ_HANDLED;
  1642. #endif
  1643. for_each_eth_queue(bp, i) {
  1644. struct bnx2x_fastpath *fp = &bp->fp[i];
  1645. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1646. if (status & mask) {
  1647. /* Handle Rx or Tx according to SB id */
  1648. for_each_cos_in_tx_queue(fp, cos)
  1649. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1650. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1651. napi_schedule_irqoff(&bnx2x_fp(bp, fp->index, napi));
  1652. status &= ~mask;
  1653. }
  1654. }
  1655. if (CNIC_SUPPORT(bp)) {
  1656. mask = 0x2;
  1657. if (status & (mask | 0x1)) {
  1658. struct cnic_ops *c_ops = NULL;
  1659. rcu_read_lock();
  1660. c_ops = rcu_dereference(bp->cnic_ops);
  1661. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1662. CNIC_DRV_STATE_HANDLES_IRQ))
  1663. c_ops->cnic_handler(bp->cnic_data, NULL);
  1664. rcu_read_unlock();
  1665. status &= ~mask;
  1666. }
  1667. }
  1668. if (unlikely(status & 0x1)) {
  1669. /* schedule sp task to perform default status block work, ack
  1670. * attentions and enable interrupts.
  1671. */
  1672. bnx2x_schedule_sp_task(bp);
  1673. status &= ~0x1;
  1674. if (!status)
  1675. return IRQ_HANDLED;
  1676. }
  1677. if (unlikely(status))
  1678. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1679. status);
  1680. return IRQ_HANDLED;
  1681. }
  1682. /* Link */
  1683. /*
  1684. * General service functions
  1685. */
  1686. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1687. {
  1688. u32 lock_status;
  1689. u32 resource_bit = (1 << resource);
  1690. int func = BP_FUNC(bp);
  1691. u32 hw_lock_control_reg;
  1692. int cnt;
  1693. /* Validating that the resource is within range */
  1694. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1695. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1696. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1697. return -EINVAL;
  1698. }
  1699. if (func <= 5) {
  1700. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1701. } else {
  1702. hw_lock_control_reg =
  1703. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1704. }
  1705. /* Validating that the resource is not already taken */
  1706. lock_status = REG_RD(bp, hw_lock_control_reg);
  1707. if (lock_status & resource_bit) {
  1708. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1709. lock_status, resource_bit);
  1710. return -EEXIST;
  1711. }
  1712. /* Try for 5 second every 5ms */
  1713. for (cnt = 0; cnt < 1000; cnt++) {
  1714. /* Try to acquire the lock */
  1715. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1716. lock_status = REG_RD(bp, hw_lock_control_reg);
  1717. if (lock_status & resource_bit)
  1718. return 0;
  1719. usleep_range(5000, 10000);
  1720. }
  1721. BNX2X_ERR("Timeout\n");
  1722. return -EAGAIN;
  1723. }
  1724. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1725. {
  1726. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1727. }
  1728. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1729. {
  1730. u32 lock_status;
  1731. u32 resource_bit = (1 << resource);
  1732. int func = BP_FUNC(bp);
  1733. u32 hw_lock_control_reg;
  1734. /* Validating that the resource is within range */
  1735. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1736. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1737. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1738. return -EINVAL;
  1739. }
  1740. if (func <= 5) {
  1741. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1742. } else {
  1743. hw_lock_control_reg =
  1744. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1745. }
  1746. /* Validating that the resource is currently taken */
  1747. lock_status = REG_RD(bp, hw_lock_control_reg);
  1748. if (!(lock_status & resource_bit)) {
  1749. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1750. lock_status, resource_bit);
  1751. return -EFAULT;
  1752. }
  1753. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1754. return 0;
  1755. }
  1756. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1757. {
  1758. /* The GPIO should be swapped if swap register is set and active */
  1759. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1760. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1761. int gpio_shift = gpio_num +
  1762. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1763. u32 gpio_mask = (1 << gpio_shift);
  1764. u32 gpio_reg;
  1765. int value;
  1766. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1767. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1768. return -EINVAL;
  1769. }
  1770. /* read GPIO value */
  1771. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1772. /* get the requested pin value */
  1773. if ((gpio_reg & gpio_mask) == gpio_mask)
  1774. value = 1;
  1775. else
  1776. value = 0;
  1777. return value;
  1778. }
  1779. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1780. {
  1781. /* The GPIO should be swapped if swap register is set and active */
  1782. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1783. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1784. int gpio_shift = gpio_num +
  1785. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1786. u32 gpio_mask = (1 << gpio_shift);
  1787. u32 gpio_reg;
  1788. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1789. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1790. return -EINVAL;
  1791. }
  1792. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1793. /* read GPIO and mask except the float bits */
  1794. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1795. switch (mode) {
  1796. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1797. DP(NETIF_MSG_LINK,
  1798. "Set GPIO %d (shift %d) -> output low\n",
  1799. gpio_num, gpio_shift);
  1800. /* clear FLOAT and set CLR */
  1801. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1802. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1803. break;
  1804. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1805. DP(NETIF_MSG_LINK,
  1806. "Set GPIO %d (shift %d) -> output high\n",
  1807. gpio_num, gpio_shift);
  1808. /* clear FLOAT and set SET */
  1809. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1810. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1811. break;
  1812. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1813. DP(NETIF_MSG_LINK,
  1814. "Set GPIO %d (shift %d) -> input\n",
  1815. gpio_num, gpio_shift);
  1816. /* set FLOAT */
  1817. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1818. break;
  1819. default:
  1820. break;
  1821. }
  1822. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1823. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1824. return 0;
  1825. }
  1826. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1827. {
  1828. u32 gpio_reg = 0;
  1829. int rc = 0;
  1830. /* Any port swapping should be handled by caller. */
  1831. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1832. /* read GPIO and mask except the float bits */
  1833. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1834. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1835. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1836. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1837. switch (mode) {
  1838. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1839. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1840. /* set CLR */
  1841. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1842. break;
  1843. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1844. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1845. /* set SET */
  1846. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1847. break;
  1848. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1849. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1850. /* set FLOAT */
  1851. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1852. break;
  1853. default:
  1854. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1855. rc = -EINVAL;
  1856. break;
  1857. }
  1858. if (rc == 0)
  1859. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1860. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1861. return rc;
  1862. }
  1863. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1864. {
  1865. /* The GPIO should be swapped if swap register is set and active */
  1866. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1867. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1868. int gpio_shift = gpio_num +
  1869. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1870. u32 gpio_mask = (1 << gpio_shift);
  1871. u32 gpio_reg;
  1872. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1873. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1874. return -EINVAL;
  1875. }
  1876. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1877. /* read GPIO int */
  1878. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1879. switch (mode) {
  1880. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1881. DP(NETIF_MSG_LINK,
  1882. "Clear GPIO INT %d (shift %d) -> output low\n",
  1883. gpio_num, gpio_shift);
  1884. /* clear SET and set CLR */
  1885. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1886. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1887. break;
  1888. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1889. DP(NETIF_MSG_LINK,
  1890. "Set GPIO INT %d (shift %d) -> output high\n",
  1891. gpio_num, gpio_shift);
  1892. /* clear CLR and set SET */
  1893. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1894. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1895. break;
  1896. default:
  1897. break;
  1898. }
  1899. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1900. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1901. return 0;
  1902. }
  1903. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1904. {
  1905. u32 spio_reg;
  1906. /* Only 2 SPIOs are configurable */
  1907. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1908. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1909. return -EINVAL;
  1910. }
  1911. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1912. /* read SPIO and mask except the float bits */
  1913. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1914. switch (mode) {
  1915. case MISC_SPIO_OUTPUT_LOW:
  1916. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1917. /* clear FLOAT and set CLR */
  1918. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1919. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1920. break;
  1921. case MISC_SPIO_OUTPUT_HIGH:
  1922. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1923. /* clear FLOAT and set SET */
  1924. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1925. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1926. break;
  1927. case MISC_SPIO_INPUT_HI_Z:
  1928. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1929. /* set FLOAT */
  1930. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1931. break;
  1932. default:
  1933. break;
  1934. }
  1935. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1936. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1937. return 0;
  1938. }
  1939. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1940. {
  1941. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1942. switch (bp->link_vars.ieee_fc &
  1943. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1944. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1945. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1946. ADVERTISED_Pause);
  1947. break;
  1948. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1949. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1950. ADVERTISED_Pause);
  1951. break;
  1952. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1953. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1954. break;
  1955. default:
  1956. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1957. ADVERTISED_Pause);
  1958. break;
  1959. }
  1960. }
  1961. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1962. {
  1963. /* Initialize link parameters structure variables
  1964. * It is recommended to turn off RX FC for jumbo frames
  1965. * for better performance
  1966. */
  1967. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1968. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1969. else
  1970. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1971. }
  1972. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1973. {
  1974. u32 pause_enabled = 0;
  1975. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1976. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1977. pause_enabled = 1;
  1978. REG_WR(bp, BAR_USTRORM_INTMEM +
  1979. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1980. pause_enabled);
  1981. }
  1982. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1983. pause_enabled ? "enabled" : "disabled");
  1984. }
  1985. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1986. {
  1987. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1988. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1989. if (!BP_NOMCP(bp)) {
  1990. bnx2x_set_requested_fc(bp);
  1991. bnx2x_acquire_phy_lock(bp);
  1992. if (load_mode == LOAD_DIAG) {
  1993. struct link_params *lp = &bp->link_params;
  1994. lp->loopback_mode = LOOPBACK_XGXS;
  1995. /* do PHY loopback at 10G speed, if possible */
  1996. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1997. if (lp->speed_cap_mask[cfx_idx] &
  1998. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1999. lp->req_line_speed[cfx_idx] =
  2000. SPEED_10000;
  2001. else
  2002. lp->req_line_speed[cfx_idx] =
  2003. SPEED_1000;
  2004. }
  2005. }
  2006. if (load_mode == LOAD_LOOPBACK_EXT) {
  2007. struct link_params *lp = &bp->link_params;
  2008. lp->loopback_mode = LOOPBACK_EXT;
  2009. }
  2010. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2011. bnx2x_release_phy_lock(bp);
  2012. bnx2x_init_dropless_fc(bp);
  2013. bnx2x_calc_fc_adv(bp);
  2014. if (bp->link_vars.link_up) {
  2015. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2016. bnx2x_link_report(bp);
  2017. }
  2018. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2019. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2020. return rc;
  2021. }
  2022. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2023. return -EINVAL;
  2024. }
  2025. void bnx2x_link_set(struct bnx2x *bp)
  2026. {
  2027. if (!BP_NOMCP(bp)) {
  2028. bnx2x_acquire_phy_lock(bp);
  2029. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2030. bnx2x_release_phy_lock(bp);
  2031. bnx2x_init_dropless_fc(bp);
  2032. bnx2x_calc_fc_adv(bp);
  2033. } else
  2034. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2035. }
  2036. static void bnx2x__link_reset(struct bnx2x *bp)
  2037. {
  2038. if (!BP_NOMCP(bp)) {
  2039. bnx2x_acquire_phy_lock(bp);
  2040. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2041. bnx2x_release_phy_lock(bp);
  2042. } else
  2043. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2044. }
  2045. void bnx2x_force_link_reset(struct bnx2x *bp)
  2046. {
  2047. bnx2x_acquire_phy_lock(bp);
  2048. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2049. bnx2x_release_phy_lock(bp);
  2050. }
  2051. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2052. {
  2053. u8 rc = 0;
  2054. if (!BP_NOMCP(bp)) {
  2055. bnx2x_acquire_phy_lock(bp);
  2056. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2057. is_serdes);
  2058. bnx2x_release_phy_lock(bp);
  2059. } else
  2060. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2061. return rc;
  2062. }
  2063. /* Calculates the sum of vn_min_rates.
  2064. It's needed for further normalizing of the min_rates.
  2065. Returns:
  2066. sum of vn_min_rates.
  2067. or
  2068. 0 - if all the min_rates are 0.
  2069. In the later case fairness algorithm should be deactivated.
  2070. If not all min_rates are zero then those that are zeroes will be set to 1.
  2071. */
  2072. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2073. struct cmng_init_input *input)
  2074. {
  2075. int all_zero = 1;
  2076. int vn;
  2077. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2078. u32 vn_cfg = bp->mf_config[vn];
  2079. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2080. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2081. /* Skip hidden vns */
  2082. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2083. vn_min_rate = 0;
  2084. /* If min rate is zero - set it to 1 */
  2085. else if (!vn_min_rate)
  2086. vn_min_rate = DEF_MIN_RATE;
  2087. else
  2088. all_zero = 0;
  2089. input->vnic_min_rate[vn] = vn_min_rate;
  2090. }
  2091. /* if ETS or all min rates are zeros - disable fairness */
  2092. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2093. input->flags.cmng_enables &=
  2094. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2095. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2096. } else if (all_zero) {
  2097. input->flags.cmng_enables &=
  2098. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2099. DP(NETIF_MSG_IFUP,
  2100. "All MIN values are zeroes fairness will be disabled\n");
  2101. } else
  2102. input->flags.cmng_enables |=
  2103. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2104. }
  2105. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2106. struct cmng_init_input *input)
  2107. {
  2108. u16 vn_max_rate;
  2109. u32 vn_cfg = bp->mf_config[vn];
  2110. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2111. vn_max_rate = 0;
  2112. else {
  2113. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2114. if (IS_MF_SI(bp)) {
  2115. /* maxCfg in percents of linkspeed */
  2116. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2117. } else /* SD modes */
  2118. /* maxCfg is absolute in 100Mb units */
  2119. vn_max_rate = maxCfg * 100;
  2120. }
  2121. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2122. input->vnic_max_rate[vn] = vn_max_rate;
  2123. }
  2124. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2125. {
  2126. if (CHIP_REV_IS_SLOW(bp))
  2127. return CMNG_FNS_NONE;
  2128. if (IS_MF(bp))
  2129. return CMNG_FNS_MINMAX;
  2130. return CMNG_FNS_NONE;
  2131. }
  2132. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2133. {
  2134. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2135. if (BP_NOMCP(bp))
  2136. return; /* what should be the default value in this case */
  2137. /* For 2 port configuration the absolute function number formula
  2138. * is:
  2139. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2140. *
  2141. * and there are 4 functions per port
  2142. *
  2143. * For 4 port configuration it is
  2144. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2145. *
  2146. * and there are 2 functions per port
  2147. */
  2148. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2149. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2150. if (func >= E1H_FUNC_MAX)
  2151. break;
  2152. bp->mf_config[vn] =
  2153. MF_CFG_RD(bp, func_mf_config[func].config);
  2154. }
  2155. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2156. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2157. bp->flags |= MF_FUNC_DIS;
  2158. } else {
  2159. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2160. bp->flags &= ~MF_FUNC_DIS;
  2161. }
  2162. }
  2163. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2164. {
  2165. struct cmng_init_input input;
  2166. memset(&input, 0, sizeof(struct cmng_init_input));
  2167. input.port_rate = bp->link_vars.line_speed;
  2168. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2169. int vn;
  2170. /* read mf conf from shmem */
  2171. if (read_cfg)
  2172. bnx2x_read_mf_cfg(bp);
  2173. /* vn_weight_sum and enable fairness if not 0 */
  2174. bnx2x_calc_vn_min(bp, &input);
  2175. /* calculate and set min-max rate for each vn */
  2176. if (bp->port.pmf)
  2177. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2178. bnx2x_calc_vn_max(bp, vn, &input);
  2179. /* always enable rate shaping and fairness */
  2180. input.flags.cmng_enables |=
  2181. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2182. bnx2x_init_cmng(&input, &bp->cmng);
  2183. return;
  2184. }
  2185. /* rate shaping and fairness are disabled */
  2186. DP(NETIF_MSG_IFUP,
  2187. "rate shaping and fairness are disabled\n");
  2188. }
  2189. static void storm_memset_cmng(struct bnx2x *bp,
  2190. struct cmng_init *cmng,
  2191. u8 port)
  2192. {
  2193. int vn;
  2194. size_t size = sizeof(struct cmng_struct_per_port);
  2195. u32 addr = BAR_XSTRORM_INTMEM +
  2196. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2197. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2198. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2199. int func = func_by_vn(bp, vn);
  2200. addr = BAR_XSTRORM_INTMEM +
  2201. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2202. size = sizeof(struct rate_shaping_vars_per_vn);
  2203. __storm_memset_struct(bp, addr, size,
  2204. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2205. addr = BAR_XSTRORM_INTMEM +
  2206. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2207. size = sizeof(struct fairness_vars_per_vn);
  2208. __storm_memset_struct(bp, addr, size,
  2209. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2210. }
  2211. }
  2212. /* init cmng mode in HW according to local configuration */
  2213. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2214. {
  2215. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2216. if (cmng_fns != CMNG_FNS_NONE) {
  2217. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2218. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2219. } else {
  2220. /* rate shaping and fairness are disabled */
  2221. DP(NETIF_MSG_IFUP,
  2222. "single function mode without fairness\n");
  2223. }
  2224. }
  2225. /* This function is called upon link interrupt */
  2226. static void bnx2x_link_attn(struct bnx2x *bp)
  2227. {
  2228. /* Make sure that we are synced with the current statistics */
  2229. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2230. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2231. bnx2x_init_dropless_fc(bp);
  2232. if (bp->link_vars.link_up) {
  2233. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2234. struct host_port_stats *pstats;
  2235. pstats = bnx2x_sp(bp, port_stats);
  2236. /* reset old mac stats */
  2237. memset(&(pstats->mac_stx[0]), 0,
  2238. sizeof(struct mac_stx));
  2239. }
  2240. if (bp->state == BNX2X_STATE_OPEN)
  2241. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2242. }
  2243. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2244. bnx2x_set_local_cmng(bp);
  2245. __bnx2x_link_report(bp);
  2246. if (IS_MF(bp))
  2247. bnx2x_link_sync_notify(bp);
  2248. }
  2249. void bnx2x__link_status_update(struct bnx2x *bp)
  2250. {
  2251. if (bp->state != BNX2X_STATE_OPEN)
  2252. return;
  2253. /* read updated dcb configuration */
  2254. if (IS_PF(bp)) {
  2255. bnx2x_dcbx_pmf_update(bp);
  2256. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2257. if (bp->link_vars.link_up)
  2258. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2259. else
  2260. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2261. /* indicate link status */
  2262. bnx2x_link_report(bp);
  2263. } else { /* VF */
  2264. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2265. SUPPORTED_10baseT_Full |
  2266. SUPPORTED_100baseT_Half |
  2267. SUPPORTED_100baseT_Full |
  2268. SUPPORTED_1000baseT_Full |
  2269. SUPPORTED_2500baseX_Full |
  2270. SUPPORTED_10000baseT_Full |
  2271. SUPPORTED_TP |
  2272. SUPPORTED_FIBRE |
  2273. SUPPORTED_Autoneg |
  2274. SUPPORTED_Pause |
  2275. SUPPORTED_Asym_Pause);
  2276. bp->port.advertising[0] = bp->port.supported[0];
  2277. bp->link_params.bp = bp;
  2278. bp->link_params.port = BP_PORT(bp);
  2279. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2280. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2281. bp->link_params.req_line_speed[0] = SPEED_10000;
  2282. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2283. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2284. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2285. bp->link_vars.line_speed = SPEED_10000;
  2286. bp->link_vars.link_status =
  2287. (LINK_STATUS_LINK_UP |
  2288. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2289. bp->link_vars.link_up = 1;
  2290. bp->link_vars.duplex = DUPLEX_FULL;
  2291. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2292. __bnx2x_link_report(bp);
  2293. bnx2x_sample_bulletin(bp);
  2294. /* if bulletin board did not have an update for link status
  2295. * __bnx2x_link_report will report current status
  2296. * but it will NOT duplicate report in case of already reported
  2297. * during sampling bulletin board.
  2298. */
  2299. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2300. }
  2301. }
  2302. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2303. u16 vlan_val, u8 allowed_prio)
  2304. {
  2305. struct bnx2x_func_state_params func_params = {NULL};
  2306. struct bnx2x_func_afex_update_params *f_update_params =
  2307. &func_params.params.afex_update;
  2308. func_params.f_obj = &bp->func_obj;
  2309. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2310. /* no need to wait for RAMROD completion, so don't
  2311. * set RAMROD_COMP_WAIT flag
  2312. */
  2313. f_update_params->vif_id = vifid;
  2314. f_update_params->afex_default_vlan = vlan_val;
  2315. f_update_params->allowed_priorities = allowed_prio;
  2316. /* if ramrod can not be sent, response to MCP immediately */
  2317. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2318. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2319. return 0;
  2320. }
  2321. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2322. u16 vif_index, u8 func_bit_map)
  2323. {
  2324. struct bnx2x_func_state_params func_params = {NULL};
  2325. struct bnx2x_func_afex_viflists_params *update_params =
  2326. &func_params.params.afex_viflists;
  2327. int rc;
  2328. u32 drv_msg_code;
  2329. /* validate only LIST_SET and LIST_GET are received from switch */
  2330. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2331. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2332. cmd_type);
  2333. func_params.f_obj = &bp->func_obj;
  2334. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2335. /* set parameters according to cmd_type */
  2336. update_params->afex_vif_list_command = cmd_type;
  2337. update_params->vif_list_index = vif_index;
  2338. update_params->func_bit_map =
  2339. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2340. update_params->func_to_clear = 0;
  2341. drv_msg_code =
  2342. (cmd_type == VIF_LIST_RULE_GET) ?
  2343. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2344. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2345. /* if ramrod can not be sent, respond to MCP immediately for
  2346. * SET and GET requests (other are not triggered from MCP)
  2347. */
  2348. rc = bnx2x_func_state_change(bp, &func_params);
  2349. if (rc < 0)
  2350. bnx2x_fw_command(bp, drv_msg_code, 0);
  2351. return 0;
  2352. }
  2353. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2354. {
  2355. struct afex_stats afex_stats;
  2356. u32 func = BP_ABS_FUNC(bp);
  2357. u32 mf_config;
  2358. u16 vlan_val;
  2359. u32 vlan_prio;
  2360. u16 vif_id;
  2361. u8 allowed_prio;
  2362. u8 vlan_mode;
  2363. u32 addr_to_write, vifid, addrs, stats_type, i;
  2364. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2365. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2366. DP(BNX2X_MSG_MCP,
  2367. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2368. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2369. }
  2370. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2371. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2372. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2373. DP(BNX2X_MSG_MCP,
  2374. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2375. vifid, addrs);
  2376. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2377. addrs);
  2378. }
  2379. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2380. addr_to_write = SHMEM2_RD(bp,
  2381. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2382. stats_type = SHMEM2_RD(bp,
  2383. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2384. DP(BNX2X_MSG_MCP,
  2385. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2386. addr_to_write);
  2387. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2388. /* write response to scratchpad, for MCP */
  2389. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2390. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2391. *(((u32 *)(&afex_stats))+i));
  2392. /* send ack message to MCP */
  2393. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2394. }
  2395. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2396. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2397. bp->mf_config[BP_VN(bp)] = mf_config;
  2398. DP(BNX2X_MSG_MCP,
  2399. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2400. mf_config);
  2401. /* if VIF_SET is "enabled" */
  2402. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2403. /* set rate limit directly to internal RAM */
  2404. struct cmng_init_input cmng_input;
  2405. struct rate_shaping_vars_per_vn m_rs_vn;
  2406. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2407. u32 addr = BAR_XSTRORM_INTMEM +
  2408. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2409. bp->mf_config[BP_VN(bp)] = mf_config;
  2410. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2411. m_rs_vn.vn_counter.rate =
  2412. cmng_input.vnic_max_rate[BP_VN(bp)];
  2413. m_rs_vn.vn_counter.quota =
  2414. (m_rs_vn.vn_counter.rate *
  2415. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2416. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2417. /* read relevant values from mf_cfg struct in shmem */
  2418. vif_id =
  2419. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2420. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2421. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2422. vlan_val =
  2423. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2424. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2425. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2426. vlan_prio = (mf_config &
  2427. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2428. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2429. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2430. vlan_mode =
  2431. (MF_CFG_RD(bp,
  2432. func_mf_config[func].afex_config) &
  2433. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2434. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2435. allowed_prio =
  2436. (MF_CFG_RD(bp,
  2437. func_mf_config[func].afex_config) &
  2438. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2439. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2440. /* send ramrod to FW, return in case of failure */
  2441. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2442. allowed_prio))
  2443. return;
  2444. bp->afex_def_vlan_tag = vlan_val;
  2445. bp->afex_vlan_mode = vlan_mode;
  2446. } else {
  2447. /* notify link down because BP->flags is disabled */
  2448. bnx2x_link_report(bp);
  2449. /* send INVALID VIF ramrod to FW */
  2450. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2451. /* Reset the default afex VLAN */
  2452. bp->afex_def_vlan_tag = -1;
  2453. }
  2454. }
  2455. }
  2456. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2457. {
  2458. struct bnx2x_func_switch_update_params *switch_update_params;
  2459. struct bnx2x_func_state_params func_params;
  2460. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2461. switch_update_params = &func_params.params.switch_update;
  2462. func_params.f_obj = &bp->func_obj;
  2463. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2464. if (IS_MF_UFP(bp)) {
  2465. int func = BP_ABS_FUNC(bp);
  2466. u32 val;
  2467. /* Re-learn the S-tag from shmem */
  2468. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2469. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2470. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2471. bp->mf_ov = val;
  2472. } else {
  2473. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2474. goto fail;
  2475. }
  2476. /* Configure new S-tag in LLH */
  2477. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2478. bp->mf_ov);
  2479. /* Send Ramrod to update FW of change */
  2480. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2481. &switch_update_params->changes);
  2482. switch_update_params->vlan = bp->mf_ov;
  2483. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2484. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2485. bp->mf_ov);
  2486. goto fail;
  2487. }
  2488. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n", bp->mf_ov);
  2489. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2490. return;
  2491. }
  2492. /* not supported by SW yet */
  2493. fail:
  2494. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2495. }
  2496. static void bnx2x_pmf_update(struct bnx2x *bp)
  2497. {
  2498. int port = BP_PORT(bp);
  2499. u32 val;
  2500. bp->port.pmf = 1;
  2501. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2502. /*
  2503. * We need the mb() to ensure the ordering between the writing to
  2504. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2505. */
  2506. smp_mb();
  2507. /* queue a periodic task */
  2508. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2509. bnx2x_dcbx_pmf_update(bp);
  2510. /* enable nig attention */
  2511. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2512. if (bp->common.int_block == INT_BLOCK_HC) {
  2513. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2514. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2515. } else if (!CHIP_IS_E1x(bp)) {
  2516. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2517. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2518. }
  2519. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2520. }
  2521. /* end of Link */
  2522. /* slow path */
  2523. /*
  2524. * General service functions
  2525. */
  2526. /* send the MCP a request, block until there is a reply */
  2527. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2528. {
  2529. int mb_idx = BP_FW_MB_IDX(bp);
  2530. u32 seq;
  2531. u32 rc = 0;
  2532. u32 cnt = 1;
  2533. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2534. mutex_lock(&bp->fw_mb_mutex);
  2535. seq = ++bp->fw_seq;
  2536. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2537. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2538. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2539. (command | seq), param);
  2540. do {
  2541. /* let the FW do it's magic ... */
  2542. msleep(delay);
  2543. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2544. /* Give the FW up to 5 second (500*10ms) */
  2545. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2546. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2547. cnt*delay, rc, seq);
  2548. /* is this a reply to our command? */
  2549. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2550. rc &= FW_MSG_CODE_MASK;
  2551. else {
  2552. /* FW BUG! */
  2553. BNX2X_ERR("FW failed to respond!\n");
  2554. bnx2x_fw_dump(bp);
  2555. rc = 0;
  2556. }
  2557. mutex_unlock(&bp->fw_mb_mutex);
  2558. return rc;
  2559. }
  2560. static void storm_memset_func_cfg(struct bnx2x *bp,
  2561. struct tstorm_eth_function_common_config *tcfg,
  2562. u16 abs_fid)
  2563. {
  2564. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2565. u32 addr = BAR_TSTRORM_INTMEM +
  2566. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2567. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2568. }
  2569. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2570. {
  2571. if (CHIP_IS_E1x(bp)) {
  2572. struct tstorm_eth_function_common_config tcfg = {0};
  2573. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2574. }
  2575. /* Enable the function in the FW */
  2576. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2577. storm_memset_func_en(bp, p->func_id, 1);
  2578. /* spq */
  2579. if (p->func_flgs & FUNC_FLG_SPQ) {
  2580. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2581. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2582. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2583. }
  2584. }
  2585. /**
  2586. * bnx2x_get_common_flags - Return common flags
  2587. *
  2588. * @bp device handle
  2589. * @fp queue handle
  2590. * @zero_stats TRUE if statistics zeroing is needed
  2591. *
  2592. * Return the flags that are common for the Tx-only and not normal connections.
  2593. */
  2594. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2595. struct bnx2x_fastpath *fp,
  2596. bool zero_stats)
  2597. {
  2598. unsigned long flags = 0;
  2599. /* PF driver will always initialize the Queue to an ACTIVE state */
  2600. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2601. /* tx only connections collect statistics (on the same index as the
  2602. * parent connection). The statistics are zeroed when the parent
  2603. * connection is initialized.
  2604. */
  2605. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2606. if (zero_stats)
  2607. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2608. if (bp->flags & TX_SWITCHING)
  2609. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2610. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2611. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2612. #ifdef BNX2X_STOP_ON_ERROR
  2613. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2614. #endif
  2615. return flags;
  2616. }
  2617. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2618. struct bnx2x_fastpath *fp,
  2619. bool leading)
  2620. {
  2621. unsigned long flags = 0;
  2622. /* calculate other queue flags */
  2623. if (IS_MF_SD(bp))
  2624. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2625. if (IS_FCOE_FP(fp)) {
  2626. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2627. /* For FCoE - force usage of default priority (for afex) */
  2628. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2629. }
  2630. if (fp->mode != TPA_MODE_DISABLED) {
  2631. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2632. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2633. if (fp->mode == TPA_MODE_GRO)
  2634. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2635. }
  2636. if (leading) {
  2637. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2638. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2639. }
  2640. /* Always set HW VLAN stripping */
  2641. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2642. /* configure silent vlan removal */
  2643. if (IS_MF_AFEX(bp))
  2644. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2645. return flags | bnx2x_get_common_flags(bp, fp, true);
  2646. }
  2647. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2648. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2649. u8 cos)
  2650. {
  2651. gen_init->stat_id = bnx2x_stats_id(fp);
  2652. gen_init->spcl_id = fp->cl_id;
  2653. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2654. if (IS_FCOE_FP(fp))
  2655. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2656. else
  2657. gen_init->mtu = bp->dev->mtu;
  2658. gen_init->cos = cos;
  2659. gen_init->fp_hsi = ETH_FP_HSI_VERSION;
  2660. }
  2661. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2662. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2663. struct bnx2x_rxq_setup_params *rxq_init)
  2664. {
  2665. u8 max_sge = 0;
  2666. u16 sge_sz = 0;
  2667. u16 tpa_agg_size = 0;
  2668. if (fp->mode != TPA_MODE_DISABLED) {
  2669. pause->sge_th_lo = SGE_TH_LO(bp);
  2670. pause->sge_th_hi = SGE_TH_HI(bp);
  2671. /* validate SGE ring has enough to cross high threshold */
  2672. WARN_ON(bp->dropless_fc &&
  2673. pause->sge_th_hi + FW_PREFETCH_CNT >
  2674. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2675. tpa_agg_size = TPA_AGG_SIZE;
  2676. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2677. SGE_PAGE_SHIFT;
  2678. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2679. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2680. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2681. }
  2682. /* pause - not for e1 */
  2683. if (!CHIP_IS_E1(bp)) {
  2684. pause->bd_th_lo = BD_TH_LO(bp);
  2685. pause->bd_th_hi = BD_TH_HI(bp);
  2686. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2687. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2688. /*
  2689. * validate that rings have enough entries to cross
  2690. * high thresholds
  2691. */
  2692. WARN_ON(bp->dropless_fc &&
  2693. pause->bd_th_hi + FW_PREFETCH_CNT >
  2694. bp->rx_ring_size);
  2695. WARN_ON(bp->dropless_fc &&
  2696. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2697. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2698. pause->pri_map = 1;
  2699. }
  2700. /* rxq setup */
  2701. rxq_init->dscr_map = fp->rx_desc_mapping;
  2702. rxq_init->sge_map = fp->rx_sge_mapping;
  2703. rxq_init->rcq_map = fp->rx_comp_mapping;
  2704. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2705. /* This should be a maximum number of data bytes that may be
  2706. * placed on the BD (not including paddings).
  2707. */
  2708. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2709. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2710. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2711. rxq_init->tpa_agg_sz = tpa_agg_size;
  2712. rxq_init->sge_buf_sz = sge_sz;
  2713. rxq_init->max_sges_pkt = max_sge;
  2714. rxq_init->rss_engine_id = BP_FUNC(bp);
  2715. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2716. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2717. *
  2718. * For PF Clients it should be the maximum available number.
  2719. * VF driver(s) may want to define it to a smaller value.
  2720. */
  2721. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2722. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2723. rxq_init->fw_sb_id = fp->fw_sb_id;
  2724. if (IS_FCOE_FP(fp))
  2725. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2726. else
  2727. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2728. /* configure silent vlan removal
  2729. * if multi function mode is afex, then mask default vlan
  2730. */
  2731. if (IS_MF_AFEX(bp)) {
  2732. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2733. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2734. }
  2735. }
  2736. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2737. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2738. u8 cos)
  2739. {
  2740. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2741. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2742. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2743. txq_init->fw_sb_id = fp->fw_sb_id;
  2744. /*
  2745. * set the tss leading client id for TX classification ==
  2746. * leading RSS client id
  2747. */
  2748. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2749. if (IS_FCOE_FP(fp)) {
  2750. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2751. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2752. }
  2753. }
  2754. static void bnx2x_pf_init(struct bnx2x *bp)
  2755. {
  2756. struct bnx2x_func_init_params func_init = {0};
  2757. struct event_ring_data eq_data = { {0} };
  2758. u16 flags;
  2759. if (!CHIP_IS_E1x(bp)) {
  2760. /* reset IGU PF statistics: MSIX + ATTN */
  2761. /* PF */
  2762. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2763. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2764. (CHIP_MODE_IS_4_PORT(bp) ?
  2765. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2766. /* ATTN */
  2767. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2768. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2769. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2770. (CHIP_MODE_IS_4_PORT(bp) ?
  2771. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2772. }
  2773. /* function setup flags */
  2774. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2775. /* This flag is relevant for E1x only.
  2776. * E2 doesn't have a TPA configuration in a function level.
  2777. */
  2778. flags |= (bp->dev->features & NETIF_F_LRO) ? FUNC_FLG_TPA : 0;
  2779. func_init.func_flgs = flags;
  2780. func_init.pf_id = BP_FUNC(bp);
  2781. func_init.func_id = BP_FUNC(bp);
  2782. func_init.spq_map = bp->spq_mapping;
  2783. func_init.spq_prod = bp->spq_prod_idx;
  2784. bnx2x_func_init(bp, &func_init);
  2785. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2786. /*
  2787. * Congestion management values depend on the link rate
  2788. * There is no active link so initial link rate is set to 10 Gbps.
  2789. * When the link comes up The congestion management values are
  2790. * re-calculated according to the actual link rate.
  2791. */
  2792. bp->link_vars.line_speed = SPEED_10000;
  2793. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2794. /* Only the PMF sets the HW */
  2795. if (bp->port.pmf)
  2796. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2797. /* init Event Queue - PCI bus guarantees correct endianity*/
  2798. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2799. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2800. eq_data.producer = bp->eq_prod;
  2801. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2802. eq_data.sb_id = DEF_SB_ID;
  2803. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2804. }
  2805. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2806. {
  2807. int port = BP_PORT(bp);
  2808. bnx2x_tx_disable(bp);
  2809. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2810. }
  2811. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2812. {
  2813. int port = BP_PORT(bp);
  2814. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2815. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2816. /* Tx queue should be only re-enabled */
  2817. netif_tx_wake_all_queues(bp->dev);
  2818. /*
  2819. * Should not call netif_carrier_on since it will be called if the link
  2820. * is up when checking for link state
  2821. */
  2822. }
  2823. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2824. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2825. {
  2826. struct eth_stats_info *ether_stat =
  2827. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2828. struct bnx2x_vlan_mac_obj *mac_obj =
  2829. &bp->sp_objs->mac_obj;
  2830. int i;
  2831. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2832. ETH_STAT_INFO_VERSION_LEN);
  2833. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2834. * mac_local field in ether_stat struct. The base address is offset by 2
  2835. * bytes to account for the field being 8 bytes but a mac address is
  2836. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2837. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2838. * allocated by the ether_stat struct, so the macs will land in their
  2839. * proper positions.
  2840. */
  2841. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2842. memset(ether_stat->mac_local + i, 0,
  2843. sizeof(ether_stat->mac_local[0]));
  2844. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2845. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2846. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2847. ETH_ALEN);
  2848. ether_stat->mtu_size = bp->dev->mtu;
  2849. if (bp->dev->features & NETIF_F_RXCSUM)
  2850. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2851. if (bp->dev->features & NETIF_F_TSO)
  2852. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2853. ether_stat->feature_flags |= bp->common.boot_mode;
  2854. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2855. ether_stat->txq_size = bp->tx_ring_size;
  2856. ether_stat->rxq_size = bp->rx_ring_size;
  2857. #ifdef CONFIG_BNX2X_SRIOV
  2858. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2859. #endif
  2860. }
  2861. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2862. {
  2863. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2864. struct fcoe_stats_info *fcoe_stat =
  2865. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2866. if (!CNIC_LOADED(bp))
  2867. return;
  2868. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2869. fcoe_stat->qos_priority =
  2870. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2871. /* insert FCoE stats from ramrod response */
  2872. if (!NO_FCOE(bp)) {
  2873. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2874. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2875. tstorm_queue_statistics;
  2876. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2877. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2878. xstorm_queue_statistics;
  2879. struct fcoe_statistics_params *fw_fcoe_stat =
  2880. &bp->fw_stats_data->fcoe;
  2881. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2882. fcoe_stat->rx_bytes_lo,
  2883. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2884. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2885. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2886. fcoe_stat->rx_bytes_lo,
  2887. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2888. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2889. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2890. fcoe_stat->rx_bytes_lo,
  2891. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2892. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2893. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2894. fcoe_stat->rx_bytes_lo,
  2895. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2896. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2897. fcoe_stat->rx_frames_lo,
  2898. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2899. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2900. fcoe_stat->rx_frames_lo,
  2901. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2902. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2903. fcoe_stat->rx_frames_lo,
  2904. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2905. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2906. fcoe_stat->rx_frames_lo,
  2907. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2908. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2909. fcoe_stat->tx_bytes_lo,
  2910. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2911. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2912. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2913. fcoe_stat->tx_bytes_lo,
  2914. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2915. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2916. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2917. fcoe_stat->tx_bytes_lo,
  2918. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2919. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2920. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2921. fcoe_stat->tx_bytes_lo,
  2922. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2923. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2924. fcoe_stat->tx_frames_lo,
  2925. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2926. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2927. fcoe_stat->tx_frames_lo,
  2928. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2929. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2930. fcoe_stat->tx_frames_lo,
  2931. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2932. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2933. fcoe_stat->tx_frames_lo,
  2934. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2935. }
  2936. /* ask L5 driver to add data to the struct */
  2937. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2938. }
  2939. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2940. {
  2941. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2942. struct iscsi_stats_info *iscsi_stat =
  2943. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2944. if (!CNIC_LOADED(bp))
  2945. return;
  2946. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2947. ETH_ALEN);
  2948. iscsi_stat->qos_priority =
  2949. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2950. /* ask L5 driver to add data to the struct */
  2951. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2952. }
  2953. /* called due to MCP event (on pmf):
  2954. * reread new bandwidth configuration
  2955. * configure FW
  2956. * notify others function about the change
  2957. */
  2958. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2959. {
  2960. if (bp->link_vars.link_up) {
  2961. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2962. bnx2x_link_sync_notify(bp);
  2963. }
  2964. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2965. }
  2966. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2967. {
  2968. bnx2x_config_mf_bw(bp);
  2969. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2970. }
  2971. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2972. {
  2973. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2974. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2975. }
  2976. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2977. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2978. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2979. {
  2980. enum drv_info_opcode op_code;
  2981. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2982. bool release = false;
  2983. int wait;
  2984. /* if drv_info version supported by MFW doesn't match - send NACK */
  2985. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2986. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2987. return;
  2988. }
  2989. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2990. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2991. /* Must prevent other flows from accessing drv_info_to_mcp */
  2992. mutex_lock(&bp->drv_info_mutex);
  2993. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2994. sizeof(union drv_info_to_mcp));
  2995. switch (op_code) {
  2996. case ETH_STATS_OPCODE:
  2997. bnx2x_drv_info_ether_stat(bp);
  2998. break;
  2999. case FCOE_STATS_OPCODE:
  3000. bnx2x_drv_info_fcoe_stat(bp);
  3001. break;
  3002. case ISCSI_STATS_OPCODE:
  3003. bnx2x_drv_info_iscsi_stat(bp);
  3004. break;
  3005. default:
  3006. /* if op code isn't supported - send NACK */
  3007. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3008. goto out;
  3009. }
  3010. /* if we got drv_info attn from MFW then these fields are defined in
  3011. * shmem2 for sure
  3012. */
  3013. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3014. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3015. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3016. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3017. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3018. /* Since possible management wants both this and get_driver_version
  3019. * need to wait until management notifies us it finished utilizing
  3020. * the buffer.
  3021. */
  3022. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3023. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3024. } else if (!bp->drv_info_mng_owner) {
  3025. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3026. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3027. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3028. /* Management is done; need to clear indication */
  3029. if (indication & bit) {
  3030. SHMEM2_WR(bp, mfw_drv_indication,
  3031. indication & ~bit);
  3032. release = true;
  3033. break;
  3034. }
  3035. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3036. }
  3037. }
  3038. if (!release) {
  3039. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3040. bp->drv_info_mng_owner = true;
  3041. }
  3042. out:
  3043. mutex_unlock(&bp->drv_info_mutex);
  3044. }
  3045. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3046. {
  3047. u8 vals[4];
  3048. int i = 0;
  3049. if (bnx2x_format) {
  3050. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3051. &vals[0], &vals[1], &vals[2], &vals[3]);
  3052. if (i > 0)
  3053. vals[0] -= '0';
  3054. } else {
  3055. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3056. &vals[0], &vals[1], &vals[2], &vals[3]);
  3057. }
  3058. while (i < 4)
  3059. vals[i++] = 0;
  3060. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3061. }
  3062. void bnx2x_update_mng_version(struct bnx2x *bp)
  3063. {
  3064. u32 iscsiver = DRV_VER_NOT_LOADED;
  3065. u32 fcoever = DRV_VER_NOT_LOADED;
  3066. u32 ethver = DRV_VER_NOT_LOADED;
  3067. int idx = BP_FW_MB_IDX(bp);
  3068. u8 *version;
  3069. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3070. return;
  3071. mutex_lock(&bp->drv_info_mutex);
  3072. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3073. if (bp->drv_info_mng_owner)
  3074. goto out;
  3075. if (bp->state != BNX2X_STATE_OPEN)
  3076. goto out;
  3077. /* Parse ethernet driver version */
  3078. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3079. if (!CNIC_LOADED(bp))
  3080. goto out;
  3081. /* Try getting storage driver version via cnic */
  3082. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3083. sizeof(union drv_info_to_mcp));
  3084. bnx2x_drv_info_iscsi_stat(bp);
  3085. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3086. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3087. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3088. sizeof(union drv_info_to_mcp));
  3089. bnx2x_drv_info_fcoe_stat(bp);
  3090. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3091. fcoever = bnx2x_update_mng_version_utility(version, false);
  3092. out:
  3093. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3094. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3095. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3096. mutex_unlock(&bp->drv_info_mutex);
  3097. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3098. ethver, iscsiver, fcoever);
  3099. }
  3100. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3101. {
  3102. u32 cmd_ok, cmd_fail;
  3103. /* sanity */
  3104. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3105. event & DRV_STATUS_OEM_EVENT_MASK) {
  3106. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3107. return;
  3108. }
  3109. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3110. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3111. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3112. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3113. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3114. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3115. }
  3116. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3117. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3118. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3119. /* This is the only place besides the function initialization
  3120. * where the bp->flags can change so it is done without any
  3121. * locks
  3122. */
  3123. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3124. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3125. bp->flags |= MF_FUNC_DIS;
  3126. bnx2x_e1h_disable(bp);
  3127. } else {
  3128. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3129. bp->flags &= ~MF_FUNC_DIS;
  3130. bnx2x_e1h_enable(bp);
  3131. }
  3132. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3133. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3134. }
  3135. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3136. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3137. bnx2x_config_mf_bw(bp);
  3138. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3139. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3140. }
  3141. /* Report results to MCP */
  3142. if (event)
  3143. bnx2x_fw_command(bp, cmd_fail, 0);
  3144. else
  3145. bnx2x_fw_command(bp, cmd_ok, 0);
  3146. }
  3147. /* must be called under the spq lock */
  3148. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3149. {
  3150. struct eth_spe *next_spe = bp->spq_prod_bd;
  3151. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3152. bp->spq_prod_bd = bp->spq;
  3153. bp->spq_prod_idx = 0;
  3154. DP(BNX2X_MSG_SP, "end of spq\n");
  3155. } else {
  3156. bp->spq_prod_bd++;
  3157. bp->spq_prod_idx++;
  3158. }
  3159. return next_spe;
  3160. }
  3161. /* must be called under the spq lock */
  3162. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3163. {
  3164. int func = BP_FUNC(bp);
  3165. /*
  3166. * Make sure that BD data is updated before writing the producer:
  3167. * BD data is written to the memory, the producer is read from the
  3168. * memory, thus we need a full memory barrier to ensure the ordering.
  3169. */
  3170. mb();
  3171. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3172. bp->spq_prod_idx);
  3173. mmiowb();
  3174. }
  3175. /**
  3176. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3177. *
  3178. * @cmd: command to check
  3179. * @cmd_type: command type
  3180. */
  3181. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3182. {
  3183. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3184. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3185. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3186. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3187. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3188. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3189. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3190. return true;
  3191. else
  3192. return false;
  3193. }
  3194. /**
  3195. * bnx2x_sp_post - place a single command on an SP ring
  3196. *
  3197. * @bp: driver handle
  3198. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3199. * @cid: SW CID the command is related to
  3200. * @data_hi: command private data address (high 32 bits)
  3201. * @data_lo: command private data address (low 32 bits)
  3202. * @cmd_type: command type (e.g. NONE, ETH)
  3203. *
  3204. * SP data is handled as if it's always an address pair, thus data fields are
  3205. * not swapped to little endian in upper functions. Instead this function swaps
  3206. * data as if it's two u32 fields.
  3207. */
  3208. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3209. u32 data_hi, u32 data_lo, int cmd_type)
  3210. {
  3211. struct eth_spe *spe;
  3212. u16 type;
  3213. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3214. #ifdef BNX2X_STOP_ON_ERROR
  3215. if (unlikely(bp->panic)) {
  3216. BNX2X_ERR("Can't post SP when there is panic\n");
  3217. return -EIO;
  3218. }
  3219. #endif
  3220. spin_lock_bh(&bp->spq_lock);
  3221. if (common) {
  3222. if (!atomic_read(&bp->eq_spq_left)) {
  3223. BNX2X_ERR("BUG! EQ ring full!\n");
  3224. spin_unlock_bh(&bp->spq_lock);
  3225. bnx2x_panic();
  3226. return -EBUSY;
  3227. }
  3228. } else if (!atomic_read(&bp->cq_spq_left)) {
  3229. BNX2X_ERR("BUG! SPQ ring full!\n");
  3230. spin_unlock_bh(&bp->spq_lock);
  3231. bnx2x_panic();
  3232. return -EBUSY;
  3233. }
  3234. spe = bnx2x_sp_get_next(bp);
  3235. /* CID needs port number to be encoded int it */
  3236. spe->hdr.conn_and_cmd_data =
  3237. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3238. HW_CID(bp, cid));
  3239. /* In some cases, type may already contain the func-id
  3240. * mainly in SRIOV related use cases, so we add it here only
  3241. * if it's not already set.
  3242. */
  3243. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3244. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3245. SPE_HDR_CONN_TYPE;
  3246. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3247. SPE_HDR_FUNCTION_ID);
  3248. } else {
  3249. type = cmd_type;
  3250. }
  3251. spe->hdr.type = cpu_to_le16(type);
  3252. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3253. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3254. /*
  3255. * It's ok if the actual decrement is issued towards the memory
  3256. * somewhere between the spin_lock and spin_unlock. Thus no
  3257. * more explicit memory barrier is needed.
  3258. */
  3259. if (common)
  3260. atomic_dec(&bp->eq_spq_left);
  3261. else
  3262. atomic_dec(&bp->cq_spq_left);
  3263. DP(BNX2X_MSG_SP,
  3264. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3265. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3266. (u32)(U64_LO(bp->spq_mapping) +
  3267. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3268. HW_CID(bp, cid), data_hi, data_lo, type,
  3269. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3270. bnx2x_sp_prod_update(bp);
  3271. spin_unlock_bh(&bp->spq_lock);
  3272. return 0;
  3273. }
  3274. /* acquire split MCP access lock register */
  3275. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3276. {
  3277. u32 j, val;
  3278. int rc = 0;
  3279. might_sleep();
  3280. for (j = 0; j < 1000; j++) {
  3281. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3282. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3283. if (val & MCPR_ACCESS_LOCK_LOCK)
  3284. break;
  3285. usleep_range(5000, 10000);
  3286. }
  3287. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3288. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3289. rc = -EBUSY;
  3290. }
  3291. return rc;
  3292. }
  3293. /* release split MCP access lock register */
  3294. static void bnx2x_release_alr(struct bnx2x *bp)
  3295. {
  3296. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3297. }
  3298. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3299. #define BNX2X_DEF_SB_IDX 0x0002
  3300. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3301. {
  3302. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3303. u16 rc = 0;
  3304. barrier(); /* status block is written to by the chip */
  3305. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3306. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3307. rc |= BNX2X_DEF_SB_ATT_IDX;
  3308. }
  3309. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3310. bp->def_idx = def_sb->sp_sb.running_index;
  3311. rc |= BNX2X_DEF_SB_IDX;
  3312. }
  3313. /* Do not reorder: indices reading should complete before handling */
  3314. barrier();
  3315. return rc;
  3316. }
  3317. /*
  3318. * slow path service functions
  3319. */
  3320. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3321. {
  3322. int port = BP_PORT(bp);
  3323. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3324. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3325. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3326. NIG_REG_MASK_INTERRUPT_PORT0;
  3327. u32 aeu_mask;
  3328. u32 nig_mask = 0;
  3329. u32 reg_addr;
  3330. if (bp->attn_state & asserted)
  3331. BNX2X_ERR("IGU ERROR\n");
  3332. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3333. aeu_mask = REG_RD(bp, aeu_addr);
  3334. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3335. aeu_mask, asserted);
  3336. aeu_mask &= ~(asserted & 0x3ff);
  3337. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3338. REG_WR(bp, aeu_addr, aeu_mask);
  3339. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3340. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3341. bp->attn_state |= asserted;
  3342. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3343. if (asserted & ATTN_HARD_WIRED_MASK) {
  3344. if (asserted & ATTN_NIG_FOR_FUNC) {
  3345. bnx2x_acquire_phy_lock(bp);
  3346. /* save nig interrupt mask */
  3347. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3348. /* If nig_mask is not set, no need to call the update
  3349. * function.
  3350. */
  3351. if (nig_mask) {
  3352. REG_WR(bp, nig_int_mask_addr, 0);
  3353. bnx2x_link_attn(bp);
  3354. }
  3355. /* handle unicore attn? */
  3356. }
  3357. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3358. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3359. if (asserted & GPIO_2_FUNC)
  3360. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3361. if (asserted & GPIO_3_FUNC)
  3362. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3363. if (asserted & GPIO_4_FUNC)
  3364. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3365. if (port == 0) {
  3366. if (asserted & ATTN_GENERAL_ATTN_1) {
  3367. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3368. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3369. }
  3370. if (asserted & ATTN_GENERAL_ATTN_2) {
  3371. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3372. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3373. }
  3374. if (asserted & ATTN_GENERAL_ATTN_3) {
  3375. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3376. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3377. }
  3378. } else {
  3379. if (asserted & ATTN_GENERAL_ATTN_4) {
  3380. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3381. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3382. }
  3383. if (asserted & ATTN_GENERAL_ATTN_5) {
  3384. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3385. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3386. }
  3387. if (asserted & ATTN_GENERAL_ATTN_6) {
  3388. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3389. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3390. }
  3391. }
  3392. } /* if hardwired */
  3393. if (bp->common.int_block == INT_BLOCK_HC)
  3394. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3395. COMMAND_REG_ATTN_BITS_SET);
  3396. else
  3397. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3398. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3399. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3400. REG_WR(bp, reg_addr, asserted);
  3401. /* now set back the mask */
  3402. if (asserted & ATTN_NIG_FOR_FUNC) {
  3403. /* Verify that IGU ack through BAR was written before restoring
  3404. * NIG mask. This loop should exit after 2-3 iterations max.
  3405. */
  3406. if (bp->common.int_block != INT_BLOCK_HC) {
  3407. u32 cnt = 0, igu_acked;
  3408. do {
  3409. igu_acked = REG_RD(bp,
  3410. IGU_REG_ATTENTION_ACK_BITS);
  3411. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3412. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3413. if (!igu_acked)
  3414. DP(NETIF_MSG_HW,
  3415. "Failed to verify IGU ack on time\n");
  3416. barrier();
  3417. }
  3418. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3419. bnx2x_release_phy_lock(bp);
  3420. }
  3421. }
  3422. static void bnx2x_fan_failure(struct bnx2x *bp)
  3423. {
  3424. int port = BP_PORT(bp);
  3425. u32 ext_phy_config;
  3426. /* mark the failure */
  3427. ext_phy_config =
  3428. SHMEM_RD(bp,
  3429. dev_info.port_hw_config[port].external_phy_config);
  3430. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3431. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3432. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3433. ext_phy_config);
  3434. /* log the failure */
  3435. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3436. "Please contact OEM Support for assistance\n");
  3437. /* Schedule device reset (unload)
  3438. * This is due to some boards consuming sufficient power when driver is
  3439. * up to overheat if fan fails.
  3440. */
  3441. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3442. }
  3443. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3444. {
  3445. int port = BP_PORT(bp);
  3446. int reg_offset;
  3447. u32 val;
  3448. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3449. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3450. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3451. val = REG_RD(bp, reg_offset);
  3452. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3453. REG_WR(bp, reg_offset, val);
  3454. BNX2X_ERR("SPIO5 hw attention\n");
  3455. /* Fan failure attention */
  3456. bnx2x_hw_reset_phy(&bp->link_params);
  3457. bnx2x_fan_failure(bp);
  3458. }
  3459. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3460. bnx2x_acquire_phy_lock(bp);
  3461. bnx2x_handle_module_detect_int(&bp->link_params);
  3462. bnx2x_release_phy_lock(bp);
  3463. }
  3464. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3465. val = REG_RD(bp, reg_offset);
  3466. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3467. REG_WR(bp, reg_offset, val);
  3468. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3469. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3470. bnx2x_panic();
  3471. }
  3472. }
  3473. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3474. {
  3475. u32 val;
  3476. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3477. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3478. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3479. /* DORQ discard attention */
  3480. if (val & 0x2)
  3481. BNX2X_ERR("FATAL error from DORQ\n");
  3482. }
  3483. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3484. int port = BP_PORT(bp);
  3485. int reg_offset;
  3486. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3487. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3488. val = REG_RD(bp, reg_offset);
  3489. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3490. REG_WR(bp, reg_offset, val);
  3491. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3492. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3493. bnx2x_panic();
  3494. }
  3495. }
  3496. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3497. {
  3498. u32 val;
  3499. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3500. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3501. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3502. /* CFC error attention */
  3503. if (val & 0x2)
  3504. BNX2X_ERR("FATAL error from CFC\n");
  3505. }
  3506. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3507. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3508. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3509. /* RQ_USDMDP_FIFO_OVERFLOW */
  3510. if (val & 0x18000)
  3511. BNX2X_ERR("FATAL error from PXP\n");
  3512. if (!CHIP_IS_E1x(bp)) {
  3513. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3514. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3515. }
  3516. }
  3517. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3518. int port = BP_PORT(bp);
  3519. int reg_offset;
  3520. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3521. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3522. val = REG_RD(bp, reg_offset);
  3523. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3524. REG_WR(bp, reg_offset, val);
  3525. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3526. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3527. bnx2x_panic();
  3528. }
  3529. }
  3530. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3531. {
  3532. u32 val;
  3533. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3534. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3535. int func = BP_FUNC(bp);
  3536. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3537. bnx2x_read_mf_cfg(bp);
  3538. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3539. func_mf_config[BP_ABS_FUNC(bp)].config);
  3540. val = SHMEM_RD(bp,
  3541. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3542. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3543. DRV_STATUS_OEM_EVENT_MASK))
  3544. bnx2x_oem_event(bp,
  3545. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3546. DRV_STATUS_OEM_EVENT_MASK)));
  3547. if (val & DRV_STATUS_SET_MF_BW)
  3548. bnx2x_set_mf_bw(bp);
  3549. if (val & DRV_STATUS_DRV_INFO_REQ)
  3550. bnx2x_handle_drv_info_req(bp);
  3551. if (val & DRV_STATUS_VF_DISABLED)
  3552. bnx2x_schedule_iov_task(bp,
  3553. BNX2X_IOV_HANDLE_FLR);
  3554. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3555. bnx2x_pmf_update(bp);
  3556. if (bp->port.pmf &&
  3557. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3558. bp->dcbx_enabled > 0)
  3559. /* start dcbx state machine */
  3560. bnx2x_dcbx_set_params(bp,
  3561. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3562. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3563. bnx2x_handle_afex_cmd(bp,
  3564. val & DRV_STATUS_AFEX_EVENT_MASK);
  3565. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3566. bnx2x_handle_eee_event(bp);
  3567. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3568. bnx2x_handle_update_svid_cmd(bp);
  3569. if (bp->link_vars.periodic_flags &
  3570. PERIODIC_FLAGS_LINK_EVENT) {
  3571. /* sync with link */
  3572. bnx2x_acquire_phy_lock(bp);
  3573. bp->link_vars.periodic_flags &=
  3574. ~PERIODIC_FLAGS_LINK_EVENT;
  3575. bnx2x_release_phy_lock(bp);
  3576. if (IS_MF(bp))
  3577. bnx2x_link_sync_notify(bp);
  3578. bnx2x_link_report(bp);
  3579. }
  3580. /* Always call it here: bnx2x_link_report() will
  3581. * prevent the link indication duplication.
  3582. */
  3583. bnx2x__link_status_update(bp);
  3584. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3585. BNX2X_ERR("MC assert!\n");
  3586. bnx2x_mc_assert(bp);
  3587. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3588. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3589. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3590. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3591. bnx2x_panic();
  3592. } else if (attn & BNX2X_MCP_ASSERT) {
  3593. BNX2X_ERR("MCP assert!\n");
  3594. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3595. bnx2x_fw_dump(bp);
  3596. } else
  3597. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3598. }
  3599. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3600. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3601. if (attn & BNX2X_GRC_TIMEOUT) {
  3602. val = CHIP_IS_E1(bp) ? 0 :
  3603. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3604. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3605. }
  3606. if (attn & BNX2X_GRC_RSV) {
  3607. val = CHIP_IS_E1(bp) ? 0 :
  3608. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3609. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3610. }
  3611. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3612. }
  3613. }
  3614. /*
  3615. * Bits map:
  3616. * 0-7 - Engine0 load counter.
  3617. * 8-15 - Engine1 load counter.
  3618. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3619. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3620. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3621. * on the engine
  3622. * 19 - Engine1 ONE_IS_LOADED.
  3623. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3624. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3625. * just the one belonging to its engine).
  3626. *
  3627. */
  3628. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3629. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3630. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3631. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3632. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3633. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3634. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3635. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3636. /*
  3637. * Set the GLOBAL_RESET bit.
  3638. *
  3639. * Should be run under rtnl lock
  3640. */
  3641. void bnx2x_set_reset_global(struct bnx2x *bp)
  3642. {
  3643. u32 val;
  3644. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3645. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3646. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3647. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3648. }
  3649. /*
  3650. * Clear the GLOBAL_RESET bit.
  3651. *
  3652. * Should be run under rtnl lock
  3653. */
  3654. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3655. {
  3656. u32 val;
  3657. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3658. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3659. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3660. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3661. }
  3662. /*
  3663. * Checks the GLOBAL_RESET bit.
  3664. *
  3665. * should be run under rtnl lock
  3666. */
  3667. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3668. {
  3669. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3670. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3671. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3672. }
  3673. /*
  3674. * Clear RESET_IN_PROGRESS bit for the current engine.
  3675. *
  3676. * Should be run under rtnl lock
  3677. */
  3678. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3679. {
  3680. u32 val;
  3681. u32 bit = BP_PATH(bp) ?
  3682. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3683. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3684. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3685. /* Clear the bit */
  3686. val &= ~bit;
  3687. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3688. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3689. }
  3690. /*
  3691. * Set RESET_IN_PROGRESS for the current engine.
  3692. *
  3693. * should be run under rtnl lock
  3694. */
  3695. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3696. {
  3697. u32 val;
  3698. u32 bit = BP_PATH(bp) ?
  3699. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3700. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3701. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3702. /* Set the bit */
  3703. val |= bit;
  3704. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3705. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3706. }
  3707. /*
  3708. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3709. * should be run under rtnl lock
  3710. */
  3711. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3712. {
  3713. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3714. u32 bit = engine ?
  3715. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3716. /* return false if bit is set */
  3717. return (val & bit) ? false : true;
  3718. }
  3719. /*
  3720. * set pf load for the current pf.
  3721. *
  3722. * should be run under rtnl lock
  3723. */
  3724. void bnx2x_set_pf_load(struct bnx2x *bp)
  3725. {
  3726. u32 val1, val;
  3727. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3728. BNX2X_PATH0_LOAD_CNT_MASK;
  3729. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3730. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3731. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3732. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3733. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3734. /* get the current counter value */
  3735. val1 = (val & mask) >> shift;
  3736. /* set bit of that PF */
  3737. val1 |= (1 << bp->pf_num);
  3738. /* clear the old value */
  3739. val &= ~mask;
  3740. /* set the new one */
  3741. val |= ((val1 << shift) & mask);
  3742. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3743. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3744. }
  3745. /**
  3746. * bnx2x_clear_pf_load - clear pf load mark
  3747. *
  3748. * @bp: driver handle
  3749. *
  3750. * Should be run under rtnl lock.
  3751. * Decrements the load counter for the current engine. Returns
  3752. * whether other functions are still loaded
  3753. */
  3754. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3755. {
  3756. u32 val1, val;
  3757. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3758. BNX2X_PATH0_LOAD_CNT_MASK;
  3759. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3760. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3761. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3762. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3763. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3764. /* get the current counter value */
  3765. val1 = (val & mask) >> shift;
  3766. /* clear bit of that PF */
  3767. val1 &= ~(1 << bp->pf_num);
  3768. /* clear the old value */
  3769. val &= ~mask;
  3770. /* set the new one */
  3771. val |= ((val1 << shift) & mask);
  3772. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3773. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3774. return val1 != 0;
  3775. }
  3776. /*
  3777. * Read the load status for the current engine.
  3778. *
  3779. * should be run under rtnl lock
  3780. */
  3781. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3782. {
  3783. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3784. BNX2X_PATH0_LOAD_CNT_MASK);
  3785. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3786. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3787. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3788. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3789. val = (val & mask) >> shift;
  3790. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3791. engine, val);
  3792. return val != 0;
  3793. }
  3794. static void _print_parity(struct bnx2x *bp, u32 reg)
  3795. {
  3796. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3797. }
  3798. static void _print_next_block(int idx, const char *blk)
  3799. {
  3800. pr_cont("%s%s", idx ? ", " : "", blk);
  3801. }
  3802. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3803. int *par_num, bool print)
  3804. {
  3805. u32 cur_bit;
  3806. bool res;
  3807. int i;
  3808. res = false;
  3809. for (i = 0; sig; i++) {
  3810. cur_bit = (0x1UL << i);
  3811. if (sig & cur_bit) {
  3812. res |= true; /* Each bit is real error! */
  3813. if (print) {
  3814. switch (cur_bit) {
  3815. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3816. _print_next_block((*par_num)++, "BRB");
  3817. _print_parity(bp,
  3818. BRB1_REG_BRB1_PRTY_STS);
  3819. break;
  3820. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3821. _print_next_block((*par_num)++,
  3822. "PARSER");
  3823. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3824. break;
  3825. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3826. _print_next_block((*par_num)++, "TSDM");
  3827. _print_parity(bp,
  3828. TSDM_REG_TSDM_PRTY_STS);
  3829. break;
  3830. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3831. _print_next_block((*par_num)++,
  3832. "SEARCHER");
  3833. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3834. break;
  3835. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3836. _print_next_block((*par_num)++, "TCM");
  3837. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3838. break;
  3839. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3840. _print_next_block((*par_num)++,
  3841. "TSEMI");
  3842. _print_parity(bp,
  3843. TSEM_REG_TSEM_PRTY_STS_0);
  3844. _print_parity(bp,
  3845. TSEM_REG_TSEM_PRTY_STS_1);
  3846. break;
  3847. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3848. _print_next_block((*par_num)++, "XPB");
  3849. _print_parity(bp, GRCBASE_XPB +
  3850. PB_REG_PB_PRTY_STS);
  3851. break;
  3852. }
  3853. }
  3854. /* Clear the bit */
  3855. sig &= ~cur_bit;
  3856. }
  3857. }
  3858. return res;
  3859. }
  3860. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3861. int *par_num, bool *global,
  3862. bool print)
  3863. {
  3864. u32 cur_bit;
  3865. bool res;
  3866. int i;
  3867. res = false;
  3868. for (i = 0; sig; i++) {
  3869. cur_bit = (0x1UL << i);
  3870. if (sig & cur_bit) {
  3871. res |= true; /* Each bit is real error! */
  3872. switch (cur_bit) {
  3873. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3874. if (print) {
  3875. _print_next_block((*par_num)++, "PBF");
  3876. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3877. }
  3878. break;
  3879. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3880. if (print) {
  3881. _print_next_block((*par_num)++, "QM");
  3882. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3883. }
  3884. break;
  3885. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3886. if (print) {
  3887. _print_next_block((*par_num)++, "TM");
  3888. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3889. }
  3890. break;
  3891. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3892. if (print) {
  3893. _print_next_block((*par_num)++, "XSDM");
  3894. _print_parity(bp,
  3895. XSDM_REG_XSDM_PRTY_STS);
  3896. }
  3897. break;
  3898. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3899. if (print) {
  3900. _print_next_block((*par_num)++, "XCM");
  3901. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3902. }
  3903. break;
  3904. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3905. if (print) {
  3906. _print_next_block((*par_num)++,
  3907. "XSEMI");
  3908. _print_parity(bp,
  3909. XSEM_REG_XSEM_PRTY_STS_0);
  3910. _print_parity(bp,
  3911. XSEM_REG_XSEM_PRTY_STS_1);
  3912. }
  3913. break;
  3914. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3915. if (print) {
  3916. _print_next_block((*par_num)++,
  3917. "DOORBELLQ");
  3918. _print_parity(bp,
  3919. DORQ_REG_DORQ_PRTY_STS);
  3920. }
  3921. break;
  3922. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3923. if (print) {
  3924. _print_next_block((*par_num)++, "NIG");
  3925. if (CHIP_IS_E1x(bp)) {
  3926. _print_parity(bp,
  3927. NIG_REG_NIG_PRTY_STS);
  3928. } else {
  3929. _print_parity(bp,
  3930. NIG_REG_NIG_PRTY_STS_0);
  3931. _print_parity(bp,
  3932. NIG_REG_NIG_PRTY_STS_1);
  3933. }
  3934. }
  3935. break;
  3936. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3937. if (print)
  3938. _print_next_block((*par_num)++,
  3939. "VAUX PCI CORE");
  3940. *global = true;
  3941. break;
  3942. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3943. if (print) {
  3944. _print_next_block((*par_num)++,
  3945. "DEBUG");
  3946. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3947. }
  3948. break;
  3949. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3950. if (print) {
  3951. _print_next_block((*par_num)++, "USDM");
  3952. _print_parity(bp,
  3953. USDM_REG_USDM_PRTY_STS);
  3954. }
  3955. break;
  3956. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3957. if (print) {
  3958. _print_next_block((*par_num)++, "UCM");
  3959. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3960. }
  3961. break;
  3962. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3963. if (print) {
  3964. _print_next_block((*par_num)++,
  3965. "USEMI");
  3966. _print_parity(bp,
  3967. USEM_REG_USEM_PRTY_STS_0);
  3968. _print_parity(bp,
  3969. USEM_REG_USEM_PRTY_STS_1);
  3970. }
  3971. break;
  3972. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3973. if (print) {
  3974. _print_next_block((*par_num)++, "UPB");
  3975. _print_parity(bp, GRCBASE_UPB +
  3976. PB_REG_PB_PRTY_STS);
  3977. }
  3978. break;
  3979. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3980. if (print) {
  3981. _print_next_block((*par_num)++, "CSDM");
  3982. _print_parity(bp,
  3983. CSDM_REG_CSDM_PRTY_STS);
  3984. }
  3985. break;
  3986. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3987. if (print) {
  3988. _print_next_block((*par_num)++, "CCM");
  3989. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3990. }
  3991. break;
  3992. }
  3993. /* Clear the bit */
  3994. sig &= ~cur_bit;
  3995. }
  3996. }
  3997. return res;
  3998. }
  3999. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  4000. int *par_num, bool print)
  4001. {
  4002. u32 cur_bit;
  4003. bool res;
  4004. int i;
  4005. res = false;
  4006. for (i = 0; sig; i++) {
  4007. cur_bit = (0x1UL << i);
  4008. if (sig & cur_bit) {
  4009. res = true; /* Each bit is real error! */
  4010. if (print) {
  4011. switch (cur_bit) {
  4012. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4013. _print_next_block((*par_num)++,
  4014. "CSEMI");
  4015. _print_parity(bp,
  4016. CSEM_REG_CSEM_PRTY_STS_0);
  4017. _print_parity(bp,
  4018. CSEM_REG_CSEM_PRTY_STS_1);
  4019. break;
  4020. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4021. _print_next_block((*par_num)++, "PXP");
  4022. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4023. _print_parity(bp,
  4024. PXP2_REG_PXP2_PRTY_STS_0);
  4025. _print_parity(bp,
  4026. PXP2_REG_PXP2_PRTY_STS_1);
  4027. break;
  4028. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4029. _print_next_block((*par_num)++,
  4030. "PXPPCICLOCKCLIENT");
  4031. break;
  4032. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4033. _print_next_block((*par_num)++, "CFC");
  4034. _print_parity(bp,
  4035. CFC_REG_CFC_PRTY_STS);
  4036. break;
  4037. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4038. _print_next_block((*par_num)++, "CDU");
  4039. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4040. break;
  4041. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4042. _print_next_block((*par_num)++, "DMAE");
  4043. _print_parity(bp,
  4044. DMAE_REG_DMAE_PRTY_STS);
  4045. break;
  4046. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4047. _print_next_block((*par_num)++, "IGU");
  4048. if (CHIP_IS_E1x(bp))
  4049. _print_parity(bp,
  4050. HC_REG_HC_PRTY_STS);
  4051. else
  4052. _print_parity(bp,
  4053. IGU_REG_IGU_PRTY_STS);
  4054. break;
  4055. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4056. _print_next_block((*par_num)++, "MISC");
  4057. _print_parity(bp,
  4058. MISC_REG_MISC_PRTY_STS);
  4059. break;
  4060. }
  4061. }
  4062. /* Clear the bit */
  4063. sig &= ~cur_bit;
  4064. }
  4065. }
  4066. return res;
  4067. }
  4068. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4069. int *par_num, bool *global,
  4070. bool print)
  4071. {
  4072. bool res = false;
  4073. u32 cur_bit;
  4074. int i;
  4075. for (i = 0; sig; i++) {
  4076. cur_bit = (0x1UL << i);
  4077. if (sig & cur_bit) {
  4078. switch (cur_bit) {
  4079. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4080. if (print)
  4081. _print_next_block((*par_num)++,
  4082. "MCP ROM");
  4083. *global = true;
  4084. res = true;
  4085. break;
  4086. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4087. if (print)
  4088. _print_next_block((*par_num)++,
  4089. "MCP UMP RX");
  4090. *global = true;
  4091. res = true;
  4092. break;
  4093. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4094. if (print)
  4095. _print_next_block((*par_num)++,
  4096. "MCP UMP TX");
  4097. *global = true;
  4098. res = true;
  4099. break;
  4100. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4101. if (print)
  4102. _print_next_block((*par_num)++,
  4103. "MCP SCPAD");
  4104. /* clear latched SCPAD PATIRY from MCP */
  4105. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4106. 1UL << 10);
  4107. break;
  4108. }
  4109. /* Clear the bit */
  4110. sig &= ~cur_bit;
  4111. }
  4112. }
  4113. return res;
  4114. }
  4115. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4116. int *par_num, bool print)
  4117. {
  4118. u32 cur_bit;
  4119. bool res;
  4120. int i;
  4121. res = false;
  4122. for (i = 0; sig; i++) {
  4123. cur_bit = (0x1UL << i);
  4124. if (sig & cur_bit) {
  4125. res = true; /* Each bit is real error! */
  4126. if (print) {
  4127. switch (cur_bit) {
  4128. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4129. _print_next_block((*par_num)++,
  4130. "PGLUE_B");
  4131. _print_parity(bp,
  4132. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4133. break;
  4134. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4135. _print_next_block((*par_num)++, "ATC");
  4136. _print_parity(bp,
  4137. ATC_REG_ATC_PRTY_STS);
  4138. break;
  4139. }
  4140. }
  4141. /* Clear the bit */
  4142. sig &= ~cur_bit;
  4143. }
  4144. }
  4145. return res;
  4146. }
  4147. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4148. u32 *sig)
  4149. {
  4150. bool res = false;
  4151. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4152. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4153. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4154. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4155. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4156. int par_num = 0;
  4157. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4158. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4159. sig[0] & HW_PRTY_ASSERT_SET_0,
  4160. sig[1] & HW_PRTY_ASSERT_SET_1,
  4161. sig[2] & HW_PRTY_ASSERT_SET_2,
  4162. sig[3] & HW_PRTY_ASSERT_SET_3,
  4163. sig[4] & HW_PRTY_ASSERT_SET_4);
  4164. if (print)
  4165. netdev_err(bp->dev,
  4166. "Parity errors detected in blocks: ");
  4167. res |= bnx2x_check_blocks_with_parity0(bp,
  4168. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4169. res |= bnx2x_check_blocks_with_parity1(bp,
  4170. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4171. res |= bnx2x_check_blocks_with_parity2(bp,
  4172. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4173. res |= bnx2x_check_blocks_with_parity3(bp,
  4174. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4175. res |= bnx2x_check_blocks_with_parity4(bp,
  4176. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4177. if (print)
  4178. pr_cont("\n");
  4179. }
  4180. return res;
  4181. }
  4182. /**
  4183. * bnx2x_chk_parity_attn - checks for parity attentions.
  4184. *
  4185. * @bp: driver handle
  4186. * @global: true if there was a global attention
  4187. * @print: show parity attention in syslog
  4188. */
  4189. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4190. {
  4191. struct attn_route attn = { {0} };
  4192. int port = BP_PORT(bp);
  4193. attn.sig[0] = REG_RD(bp,
  4194. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4195. port*4);
  4196. attn.sig[1] = REG_RD(bp,
  4197. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4198. port*4);
  4199. attn.sig[2] = REG_RD(bp,
  4200. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4201. port*4);
  4202. attn.sig[3] = REG_RD(bp,
  4203. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4204. port*4);
  4205. /* Since MCP attentions can't be disabled inside the block, we need to
  4206. * read AEU registers to see whether they're currently disabled
  4207. */
  4208. attn.sig[3] &= ((REG_RD(bp,
  4209. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4210. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4211. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4212. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4213. if (!CHIP_IS_E1x(bp))
  4214. attn.sig[4] = REG_RD(bp,
  4215. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4216. port*4);
  4217. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4218. }
  4219. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4220. {
  4221. u32 val;
  4222. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4223. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4224. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4225. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4226. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4227. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4228. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4229. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4230. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4231. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4232. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4233. if (val &
  4234. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4235. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4236. if (val &
  4237. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4238. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4239. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4240. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4241. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4242. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4243. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4244. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4245. }
  4246. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4247. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4248. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4249. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4250. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4251. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4252. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4253. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4254. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4255. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4256. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4257. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4258. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4259. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4260. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4261. }
  4262. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4263. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4264. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4265. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4266. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4267. }
  4268. }
  4269. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4270. {
  4271. struct attn_route attn, *group_mask;
  4272. int port = BP_PORT(bp);
  4273. int index;
  4274. u32 reg_addr;
  4275. u32 val;
  4276. u32 aeu_mask;
  4277. bool global = false;
  4278. /* need to take HW lock because MCP or other port might also
  4279. try to handle this event */
  4280. bnx2x_acquire_alr(bp);
  4281. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4282. #ifndef BNX2X_STOP_ON_ERROR
  4283. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4284. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4285. /* Disable HW interrupts */
  4286. bnx2x_int_disable(bp);
  4287. /* In case of parity errors don't handle attentions so that
  4288. * other function would "see" parity errors.
  4289. */
  4290. #else
  4291. bnx2x_panic();
  4292. #endif
  4293. bnx2x_release_alr(bp);
  4294. return;
  4295. }
  4296. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4297. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4298. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4299. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4300. if (!CHIP_IS_E1x(bp))
  4301. attn.sig[4] =
  4302. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4303. else
  4304. attn.sig[4] = 0;
  4305. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4306. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4307. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4308. if (deasserted & (1 << index)) {
  4309. group_mask = &bp->attn_group[index];
  4310. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4311. index,
  4312. group_mask->sig[0], group_mask->sig[1],
  4313. group_mask->sig[2], group_mask->sig[3],
  4314. group_mask->sig[4]);
  4315. bnx2x_attn_int_deasserted4(bp,
  4316. attn.sig[4] & group_mask->sig[4]);
  4317. bnx2x_attn_int_deasserted3(bp,
  4318. attn.sig[3] & group_mask->sig[3]);
  4319. bnx2x_attn_int_deasserted1(bp,
  4320. attn.sig[1] & group_mask->sig[1]);
  4321. bnx2x_attn_int_deasserted2(bp,
  4322. attn.sig[2] & group_mask->sig[2]);
  4323. bnx2x_attn_int_deasserted0(bp,
  4324. attn.sig[0] & group_mask->sig[0]);
  4325. }
  4326. }
  4327. bnx2x_release_alr(bp);
  4328. if (bp->common.int_block == INT_BLOCK_HC)
  4329. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4330. COMMAND_REG_ATTN_BITS_CLR);
  4331. else
  4332. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4333. val = ~deasserted;
  4334. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4335. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4336. REG_WR(bp, reg_addr, val);
  4337. if (~bp->attn_state & deasserted)
  4338. BNX2X_ERR("IGU ERROR\n");
  4339. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4340. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4341. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4342. aeu_mask = REG_RD(bp, reg_addr);
  4343. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4344. aeu_mask, deasserted);
  4345. aeu_mask |= (deasserted & 0x3ff);
  4346. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4347. REG_WR(bp, reg_addr, aeu_mask);
  4348. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4349. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4350. bp->attn_state &= ~deasserted;
  4351. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4352. }
  4353. static void bnx2x_attn_int(struct bnx2x *bp)
  4354. {
  4355. /* read local copy of bits */
  4356. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4357. attn_bits);
  4358. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4359. attn_bits_ack);
  4360. u32 attn_state = bp->attn_state;
  4361. /* look for changed bits */
  4362. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4363. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4364. DP(NETIF_MSG_HW,
  4365. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4366. attn_bits, attn_ack, asserted, deasserted);
  4367. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4368. BNX2X_ERR("BAD attention state\n");
  4369. /* handle bits that were raised */
  4370. if (asserted)
  4371. bnx2x_attn_int_asserted(bp, asserted);
  4372. if (deasserted)
  4373. bnx2x_attn_int_deasserted(bp, deasserted);
  4374. }
  4375. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4376. u16 index, u8 op, u8 update)
  4377. {
  4378. u32 igu_addr = bp->igu_base_addr;
  4379. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4380. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4381. igu_addr);
  4382. }
  4383. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4384. {
  4385. /* No memory barriers */
  4386. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4387. mmiowb(); /* keep prod updates ordered */
  4388. }
  4389. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4390. union event_ring_elem *elem)
  4391. {
  4392. u8 err = elem->message.error;
  4393. if (!bp->cnic_eth_dev.starting_cid ||
  4394. (cid < bp->cnic_eth_dev.starting_cid &&
  4395. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4396. return 1;
  4397. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4398. if (unlikely(err)) {
  4399. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4400. cid);
  4401. bnx2x_panic_dump(bp, false);
  4402. }
  4403. bnx2x_cnic_cfc_comp(bp, cid, err);
  4404. return 0;
  4405. }
  4406. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4407. {
  4408. struct bnx2x_mcast_ramrod_params rparam;
  4409. int rc;
  4410. memset(&rparam, 0, sizeof(rparam));
  4411. rparam.mcast_obj = &bp->mcast_obj;
  4412. netif_addr_lock_bh(bp->dev);
  4413. /* Clear pending state for the last command */
  4414. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4415. /* If there are pending mcast commands - send them */
  4416. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4417. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4418. if (rc < 0)
  4419. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4420. rc);
  4421. }
  4422. netif_addr_unlock_bh(bp->dev);
  4423. }
  4424. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4425. union event_ring_elem *elem)
  4426. {
  4427. unsigned long ramrod_flags = 0;
  4428. int rc = 0;
  4429. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4430. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4431. /* Always push next commands out, don't wait here */
  4432. __set_bit(RAMROD_CONT, &ramrod_flags);
  4433. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4434. >> BNX2X_SWCID_SHIFT) {
  4435. case BNX2X_FILTER_MAC_PENDING:
  4436. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4437. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4438. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4439. else
  4440. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4441. break;
  4442. case BNX2X_FILTER_MCAST_PENDING:
  4443. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4444. /* This is only relevant for 57710 where multicast MACs are
  4445. * configured as unicast MACs using the same ramrod.
  4446. */
  4447. bnx2x_handle_mcast_eqe(bp);
  4448. return;
  4449. default:
  4450. BNX2X_ERR("Unsupported classification command: %d\n",
  4451. elem->message.data.eth_event.echo);
  4452. return;
  4453. }
  4454. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4455. if (rc < 0)
  4456. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4457. else if (rc > 0)
  4458. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4459. }
  4460. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4461. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4462. {
  4463. netif_addr_lock_bh(bp->dev);
  4464. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4465. /* Send rx_mode command again if was requested */
  4466. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4467. bnx2x_set_storm_rx_mode(bp);
  4468. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4469. &bp->sp_state))
  4470. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4471. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4472. &bp->sp_state))
  4473. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4474. netif_addr_unlock_bh(bp->dev);
  4475. }
  4476. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4477. union event_ring_elem *elem)
  4478. {
  4479. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4480. DP(BNX2X_MSG_SP,
  4481. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4482. elem->message.data.vif_list_event.func_bit_map);
  4483. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4484. elem->message.data.vif_list_event.func_bit_map);
  4485. } else if (elem->message.data.vif_list_event.echo ==
  4486. VIF_LIST_RULE_SET) {
  4487. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4488. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4489. }
  4490. }
  4491. /* called with rtnl_lock */
  4492. static void bnx2x_after_function_update(struct bnx2x *bp)
  4493. {
  4494. int q, rc;
  4495. struct bnx2x_fastpath *fp;
  4496. struct bnx2x_queue_state_params queue_params = {NULL};
  4497. struct bnx2x_queue_update_params *q_update_params =
  4498. &queue_params.params.update;
  4499. /* Send Q update command with afex vlan removal values for all Qs */
  4500. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4501. /* set silent vlan removal values according to vlan mode */
  4502. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4503. &q_update_params->update_flags);
  4504. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4505. &q_update_params->update_flags);
  4506. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4507. /* in access mode mark mask and value are 0 to strip all vlans */
  4508. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4509. q_update_params->silent_removal_value = 0;
  4510. q_update_params->silent_removal_mask = 0;
  4511. } else {
  4512. q_update_params->silent_removal_value =
  4513. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4514. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4515. }
  4516. for_each_eth_queue(bp, q) {
  4517. /* Set the appropriate Queue object */
  4518. fp = &bp->fp[q];
  4519. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4520. /* send the ramrod */
  4521. rc = bnx2x_queue_state_change(bp, &queue_params);
  4522. if (rc < 0)
  4523. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4524. q);
  4525. }
  4526. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4527. fp = &bp->fp[FCOE_IDX(bp)];
  4528. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4529. /* clear pending completion bit */
  4530. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4531. /* mark latest Q bit */
  4532. smp_mb__before_atomic();
  4533. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4534. smp_mb__after_atomic();
  4535. /* send Q update ramrod for FCoE Q */
  4536. rc = bnx2x_queue_state_change(bp, &queue_params);
  4537. if (rc < 0)
  4538. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4539. q);
  4540. } else {
  4541. /* If no FCoE ring - ACK MCP now */
  4542. bnx2x_link_report(bp);
  4543. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4544. }
  4545. }
  4546. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4547. struct bnx2x *bp, u32 cid)
  4548. {
  4549. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4550. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4551. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4552. else
  4553. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4554. }
  4555. static void bnx2x_eq_int(struct bnx2x *bp)
  4556. {
  4557. u16 hw_cons, sw_cons, sw_prod;
  4558. union event_ring_elem *elem;
  4559. u8 echo;
  4560. u32 cid;
  4561. u8 opcode;
  4562. int rc, spqe_cnt = 0;
  4563. struct bnx2x_queue_sp_obj *q_obj;
  4564. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4565. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4566. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4567. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4568. * when we get the next-page we need to adjust so the loop
  4569. * condition below will be met. The next element is the size of a
  4570. * regular element and hence incrementing by 1
  4571. */
  4572. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4573. hw_cons++;
  4574. /* This function may never run in parallel with itself for a
  4575. * specific bp, thus there is no need in "paired" read memory
  4576. * barrier here.
  4577. */
  4578. sw_cons = bp->eq_cons;
  4579. sw_prod = bp->eq_prod;
  4580. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4581. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4582. for (; sw_cons != hw_cons;
  4583. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4584. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4585. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4586. if (!rc) {
  4587. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4588. rc);
  4589. goto next_spqe;
  4590. }
  4591. /* elem CID originates from FW; actually LE */
  4592. cid = SW_CID((__force __le32)
  4593. elem->message.data.cfc_del_event.cid);
  4594. opcode = elem->message.opcode;
  4595. /* handle eq element */
  4596. switch (opcode) {
  4597. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4598. bnx2x_vf_mbx_schedule(bp,
  4599. &elem->message.data.vf_pf_event);
  4600. continue;
  4601. case EVENT_RING_OPCODE_STAT_QUERY:
  4602. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4603. "got statistics comp event %d\n",
  4604. bp->stats_comp++);
  4605. /* nothing to do with stats comp */
  4606. goto next_spqe;
  4607. case EVENT_RING_OPCODE_CFC_DEL:
  4608. /* handle according to cid range */
  4609. /*
  4610. * we may want to verify here that the bp state is
  4611. * HALTING
  4612. */
  4613. DP(BNX2X_MSG_SP,
  4614. "got delete ramrod for MULTI[%d]\n", cid);
  4615. if (CNIC_LOADED(bp) &&
  4616. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4617. goto next_spqe;
  4618. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4619. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4620. break;
  4621. goto next_spqe;
  4622. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4623. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4624. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4625. if (f_obj->complete_cmd(bp, f_obj,
  4626. BNX2X_F_CMD_TX_STOP))
  4627. break;
  4628. goto next_spqe;
  4629. case EVENT_RING_OPCODE_START_TRAFFIC:
  4630. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4631. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4632. if (f_obj->complete_cmd(bp, f_obj,
  4633. BNX2X_F_CMD_TX_START))
  4634. break;
  4635. goto next_spqe;
  4636. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4637. echo = elem->message.data.function_update_event.echo;
  4638. if (echo == SWITCH_UPDATE) {
  4639. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4640. "got FUNC_SWITCH_UPDATE ramrod\n");
  4641. if (f_obj->complete_cmd(
  4642. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4643. break;
  4644. } else {
  4645. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4646. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4647. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4648. f_obj->complete_cmd(bp, f_obj,
  4649. BNX2X_F_CMD_AFEX_UPDATE);
  4650. /* We will perform the Queues update from
  4651. * sp_rtnl task as all Queue SP operations
  4652. * should run under rtnl_lock.
  4653. */
  4654. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4655. }
  4656. goto next_spqe;
  4657. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4658. f_obj->complete_cmd(bp, f_obj,
  4659. BNX2X_F_CMD_AFEX_VIFLISTS);
  4660. bnx2x_after_afex_vif_lists(bp, elem);
  4661. goto next_spqe;
  4662. case EVENT_RING_OPCODE_FUNCTION_START:
  4663. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4664. "got FUNC_START ramrod\n");
  4665. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4666. break;
  4667. goto next_spqe;
  4668. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4669. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4670. "got FUNC_STOP ramrod\n");
  4671. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4672. break;
  4673. goto next_spqe;
  4674. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4675. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4676. "got set_timesync ramrod completion\n");
  4677. if (f_obj->complete_cmd(bp, f_obj,
  4678. BNX2X_F_CMD_SET_TIMESYNC))
  4679. break;
  4680. goto next_spqe;
  4681. }
  4682. switch (opcode | bp->state) {
  4683. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4684. BNX2X_STATE_OPEN):
  4685. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4686. BNX2X_STATE_OPENING_WAIT4_PORT):
  4687. cid = elem->message.data.eth_event.echo &
  4688. BNX2X_SWCID_MASK;
  4689. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4690. cid);
  4691. rss_raw->clear_pending(rss_raw);
  4692. break;
  4693. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4694. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4695. case (EVENT_RING_OPCODE_SET_MAC |
  4696. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4697. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4698. BNX2X_STATE_OPEN):
  4699. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4700. BNX2X_STATE_DIAG):
  4701. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4702. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4703. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4704. bnx2x_handle_classification_eqe(bp, elem);
  4705. break;
  4706. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4707. BNX2X_STATE_OPEN):
  4708. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4709. BNX2X_STATE_DIAG):
  4710. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4711. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4712. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4713. bnx2x_handle_mcast_eqe(bp);
  4714. break;
  4715. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4716. BNX2X_STATE_OPEN):
  4717. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4718. BNX2X_STATE_DIAG):
  4719. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4720. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4721. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4722. bnx2x_handle_rx_mode_eqe(bp);
  4723. break;
  4724. default:
  4725. /* unknown event log error and continue */
  4726. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4727. elem->message.opcode, bp->state);
  4728. }
  4729. next_spqe:
  4730. spqe_cnt++;
  4731. } /* for */
  4732. smp_mb__before_atomic();
  4733. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4734. bp->eq_cons = sw_cons;
  4735. bp->eq_prod = sw_prod;
  4736. /* Make sure that above mem writes were issued towards the memory */
  4737. smp_wmb();
  4738. /* update producer */
  4739. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4740. }
  4741. static void bnx2x_sp_task(struct work_struct *work)
  4742. {
  4743. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4744. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4745. /* make sure the atomic interrupt_occurred has been written */
  4746. smp_rmb();
  4747. if (atomic_read(&bp->interrupt_occurred)) {
  4748. /* what work needs to be performed? */
  4749. u16 status = bnx2x_update_dsb_idx(bp);
  4750. DP(BNX2X_MSG_SP, "status %x\n", status);
  4751. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4752. atomic_set(&bp->interrupt_occurred, 0);
  4753. /* HW attentions */
  4754. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4755. bnx2x_attn_int(bp);
  4756. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4757. }
  4758. /* SP events: STAT_QUERY and others */
  4759. if (status & BNX2X_DEF_SB_IDX) {
  4760. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4761. if (FCOE_INIT(bp) &&
  4762. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4763. /* Prevent local bottom-halves from running as
  4764. * we are going to change the local NAPI list.
  4765. */
  4766. local_bh_disable();
  4767. napi_schedule(&bnx2x_fcoe(bp, napi));
  4768. local_bh_enable();
  4769. }
  4770. /* Handle EQ completions */
  4771. bnx2x_eq_int(bp);
  4772. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4773. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4774. status &= ~BNX2X_DEF_SB_IDX;
  4775. }
  4776. /* if status is non zero then perhaps something went wrong */
  4777. if (unlikely(status))
  4778. DP(BNX2X_MSG_SP,
  4779. "got an unknown interrupt! (status 0x%x)\n", status);
  4780. /* ack status block only if something was actually handled */
  4781. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4782. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4783. }
  4784. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4785. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4786. &bp->sp_state)) {
  4787. bnx2x_link_report(bp);
  4788. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4789. }
  4790. }
  4791. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4792. {
  4793. struct net_device *dev = dev_instance;
  4794. struct bnx2x *bp = netdev_priv(dev);
  4795. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4796. IGU_INT_DISABLE, 0);
  4797. #ifdef BNX2X_STOP_ON_ERROR
  4798. if (unlikely(bp->panic))
  4799. return IRQ_HANDLED;
  4800. #endif
  4801. if (CNIC_LOADED(bp)) {
  4802. struct cnic_ops *c_ops;
  4803. rcu_read_lock();
  4804. c_ops = rcu_dereference(bp->cnic_ops);
  4805. if (c_ops)
  4806. c_ops->cnic_handler(bp->cnic_data, NULL);
  4807. rcu_read_unlock();
  4808. }
  4809. /* schedule sp task to perform default status block work, ack
  4810. * attentions and enable interrupts.
  4811. */
  4812. bnx2x_schedule_sp_task(bp);
  4813. return IRQ_HANDLED;
  4814. }
  4815. /* end of slow path */
  4816. void bnx2x_drv_pulse(struct bnx2x *bp)
  4817. {
  4818. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4819. bp->fw_drv_pulse_wr_seq);
  4820. }
  4821. static void bnx2x_timer(unsigned long data)
  4822. {
  4823. struct bnx2x *bp = (struct bnx2x *) data;
  4824. if (!netif_running(bp->dev))
  4825. return;
  4826. if (IS_PF(bp) &&
  4827. !BP_NOMCP(bp)) {
  4828. int mb_idx = BP_FW_MB_IDX(bp);
  4829. u16 drv_pulse;
  4830. u16 mcp_pulse;
  4831. ++bp->fw_drv_pulse_wr_seq;
  4832. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4833. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4834. bnx2x_drv_pulse(bp);
  4835. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4836. MCP_PULSE_SEQ_MASK);
  4837. /* The delta between driver pulse and mcp response
  4838. * should not get too big. If the MFW is more than 5 pulses
  4839. * behind, we should worry about it enough to generate an error
  4840. * log.
  4841. */
  4842. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4843. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4844. drv_pulse, mcp_pulse);
  4845. }
  4846. if (bp->state == BNX2X_STATE_OPEN)
  4847. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4848. /* sample pf vf bulletin board for new posts from pf */
  4849. if (IS_VF(bp))
  4850. bnx2x_timer_sriov(bp);
  4851. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4852. }
  4853. /* end of Statistics */
  4854. /* nic init */
  4855. /*
  4856. * nic init service functions
  4857. */
  4858. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4859. {
  4860. u32 i;
  4861. if (!(len%4) && !(addr%4))
  4862. for (i = 0; i < len; i += 4)
  4863. REG_WR(bp, addr + i, fill);
  4864. else
  4865. for (i = 0; i < len; i++)
  4866. REG_WR8(bp, addr + i, fill);
  4867. }
  4868. /* helper: writes FP SP data to FW - data_size in dwords */
  4869. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4870. int fw_sb_id,
  4871. u32 *sb_data_p,
  4872. u32 data_size)
  4873. {
  4874. int index;
  4875. for (index = 0; index < data_size; index++)
  4876. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4877. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4878. sizeof(u32)*index,
  4879. *(sb_data_p + index));
  4880. }
  4881. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4882. {
  4883. u32 *sb_data_p;
  4884. u32 data_size = 0;
  4885. struct hc_status_block_data_e2 sb_data_e2;
  4886. struct hc_status_block_data_e1x sb_data_e1x;
  4887. /* disable the function first */
  4888. if (!CHIP_IS_E1x(bp)) {
  4889. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4890. sb_data_e2.common.state = SB_DISABLED;
  4891. sb_data_e2.common.p_func.vf_valid = false;
  4892. sb_data_p = (u32 *)&sb_data_e2;
  4893. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4894. } else {
  4895. memset(&sb_data_e1x, 0,
  4896. sizeof(struct hc_status_block_data_e1x));
  4897. sb_data_e1x.common.state = SB_DISABLED;
  4898. sb_data_e1x.common.p_func.vf_valid = false;
  4899. sb_data_p = (u32 *)&sb_data_e1x;
  4900. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4901. }
  4902. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4903. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4904. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4905. CSTORM_STATUS_BLOCK_SIZE);
  4906. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4907. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4908. CSTORM_SYNC_BLOCK_SIZE);
  4909. }
  4910. /* helper: writes SP SB data to FW */
  4911. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4912. struct hc_sp_status_block_data *sp_sb_data)
  4913. {
  4914. int func = BP_FUNC(bp);
  4915. int i;
  4916. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4917. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4918. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4919. i*sizeof(u32),
  4920. *((u32 *)sp_sb_data + i));
  4921. }
  4922. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4923. {
  4924. int func = BP_FUNC(bp);
  4925. struct hc_sp_status_block_data sp_sb_data;
  4926. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4927. sp_sb_data.state = SB_DISABLED;
  4928. sp_sb_data.p_func.vf_valid = false;
  4929. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4930. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4931. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4932. CSTORM_SP_STATUS_BLOCK_SIZE);
  4933. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4934. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4935. CSTORM_SP_SYNC_BLOCK_SIZE);
  4936. }
  4937. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4938. int igu_sb_id, int igu_seg_id)
  4939. {
  4940. hc_sm->igu_sb_id = igu_sb_id;
  4941. hc_sm->igu_seg_id = igu_seg_id;
  4942. hc_sm->timer_value = 0xFF;
  4943. hc_sm->time_to_expire = 0xFFFFFFFF;
  4944. }
  4945. /* allocates state machine ids. */
  4946. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4947. {
  4948. /* zero out state machine indices */
  4949. /* rx indices */
  4950. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4951. /* tx indices */
  4952. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4953. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4954. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4955. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4956. /* map indices */
  4957. /* rx indices */
  4958. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4959. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4960. /* tx indices */
  4961. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4962. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4963. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4964. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4965. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4966. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4967. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4968. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4969. }
  4970. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4971. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4972. {
  4973. int igu_seg_id;
  4974. struct hc_status_block_data_e2 sb_data_e2;
  4975. struct hc_status_block_data_e1x sb_data_e1x;
  4976. struct hc_status_block_sm *hc_sm_p;
  4977. int data_size;
  4978. u32 *sb_data_p;
  4979. if (CHIP_INT_MODE_IS_BC(bp))
  4980. igu_seg_id = HC_SEG_ACCESS_NORM;
  4981. else
  4982. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4983. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4984. if (!CHIP_IS_E1x(bp)) {
  4985. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4986. sb_data_e2.common.state = SB_ENABLED;
  4987. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4988. sb_data_e2.common.p_func.vf_id = vfid;
  4989. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4990. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4991. sb_data_e2.common.same_igu_sb_1b = true;
  4992. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4993. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4994. hc_sm_p = sb_data_e2.common.state_machine;
  4995. sb_data_p = (u32 *)&sb_data_e2;
  4996. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4997. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4998. } else {
  4999. memset(&sb_data_e1x, 0,
  5000. sizeof(struct hc_status_block_data_e1x));
  5001. sb_data_e1x.common.state = SB_ENABLED;
  5002. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5003. sb_data_e1x.common.p_func.vf_id = 0xff;
  5004. sb_data_e1x.common.p_func.vf_valid = false;
  5005. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5006. sb_data_e1x.common.same_igu_sb_1b = true;
  5007. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5008. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5009. hc_sm_p = sb_data_e1x.common.state_machine;
  5010. sb_data_p = (u32 *)&sb_data_e1x;
  5011. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5012. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5013. }
  5014. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5015. igu_sb_id, igu_seg_id);
  5016. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5017. igu_sb_id, igu_seg_id);
  5018. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5019. /* write indices to HW - PCI guarantees endianity of regpairs */
  5020. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5021. }
  5022. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5023. u16 tx_usec, u16 rx_usec)
  5024. {
  5025. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5026. false, rx_usec);
  5027. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5028. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5029. tx_usec);
  5030. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5031. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5032. tx_usec);
  5033. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5034. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5035. tx_usec);
  5036. }
  5037. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5038. {
  5039. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5040. dma_addr_t mapping = bp->def_status_blk_mapping;
  5041. int igu_sp_sb_index;
  5042. int igu_seg_id;
  5043. int port = BP_PORT(bp);
  5044. int func = BP_FUNC(bp);
  5045. int reg_offset, reg_offset_en5;
  5046. u64 section;
  5047. int index;
  5048. struct hc_sp_status_block_data sp_sb_data;
  5049. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5050. if (CHIP_INT_MODE_IS_BC(bp)) {
  5051. igu_sp_sb_index = DEF_SB_IGU_ID;
  5052. igu_seg_id = HC_SEG_ACCESS_DEF;
  5053. } else {
  5054. igu_sp_sb_index = bp->igu_dsb_id;
  5055. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5056. }
  5057. /* ATTN */
  5058. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5059. atten_status_block);
  5060. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5061. bp->attn_state = 0;
  5062. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5063. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5064. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5065. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5066. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5067. int sindex;
  5068. /* take care of sig[0]..sig[4] */
  5069. for (sindex = 0; sindex < 4; sindex++)
  5070. bp->attn_group[index].sig[sindex] =
  5071. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5072. if (!CHIP_IS_E1x(bp))
  5073. /*
  5074. * enable5 is separate from the rest of the registers,
  5075. * and therefore the address skip is 4
  5076. * and not 16 between the different groups
  5077. */
  5078. bp->attn_group[index].sig[4] = REG_RD(bp,
  5079. reg_offset_en5 + 0x4*index);
  5080. else
  5081. bp->attn_group[index].sig[4] = 0;
  5082. }
  5083. if (bp->common.int_block == INT_BLOCK_HC) {
  5084. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5085. HC_REG_ATTN_MSG0_ADDR_L);
  5086. REG_WR(bp, reg_offset, U64_LO(section));
  5087. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5088. } else if (!CHIP_IS_E1x(bp)) {
  5089. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5090. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5091. }
  5092. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5093. sp_sb);
  5094. bnx2x_zero_sp_sb(bp);
  5095. /* PCI guarantees endianity of regpairs */
  5096. sp_sb_data.state = SB_ENABLED;
  5097. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5098. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5099. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5100. sp_sb_data.igu_seg_id = igu_seg_id;
  5101. sp_sb_data.p_func.pf_id = func;
  5102. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5103. sp_sb_data.p_func.vf_id = 0xff;
  5104. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5105. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5106. }
  5107. void bnx2x_update_coalesce(struct bnx2x *bp)
  5108. {
  5109. int i;
  5110. for_each_eth_queue(bp, i)
  5111. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5112. bp->tx_ticks, bp->rx_ticks);
  5113. }
  5114. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5115. {
  5116. spin_lock_init(&bp->spq_lock);
  5117. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5118. bp->spq_prod_idx = 0;
  5119. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5120. bp->spq_prod_bd = bp->spq;
  5121. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5122. }
  5123. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5124. {
  5125. int i;
  5126. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5127. union event_ring_elem *elem =
  5128. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5129. elem->next_page.addr.hi =
  5130. cpu_to_le32(U64_HI(bp->eq_mapping +
  5131. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5132. elem->next_page.addr.lo =
  5133. cpu_to_le32(U64_LO(bp->eq_mapping +
  5134. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5135. }
  5136. bp->eq_cons = 0;
  5137. bp->eq_prod = NUM_EQ_DESC;
  5138. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5139. /* we want a warning message before it gets wrought... */
  5140. atomic_set(&bp->eq_spq_left,
  5141. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5142. }
  5143. /* called with netif_addr_lock_bh() */
  5144. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5145. unsigned long rx_mode_flags,
  5146. unsigned long rx_accept_flags,
  5147. unsigned long tx_accept_flags,
  5148. unsigned long ramrod_flags)
  5149. {
  5150. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5151. int rc;
  5152. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5153. /* Prepare ramrod parameters */
  5154. ramrod_param.cid = 0;
  5155. ramrod_param.cl_id = cl_id;
  5156. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5157. ramrod_param.func_id = BP_FUNC(bp);
  5158. ramrod_param.pstate = &bp->sp_state;
  5159. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5160. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5161. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5162. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5163. ramrod_param.ramrod_flags = ramrod_flags;
  5164. ramrod_param.rx_mode_flags = rx_mode_flags;
  5165. ramrod_param.rx_accept_flags = rx_accept_flags;
  5166. ramrod_param.tx_accept_flags = tx_accept_flags;
  5167. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5168. if (rc < 0) {
  5169. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5170. return rc;
  5171. }
  5172. return 0;
  5173. }
  5174. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5175. unsigned long *rx_accept_flags,
  5176. unsigned long *tx_accept_flags)
  5177. {
  5178. /* Clear the flags first */
  5179. *rx_accept_flags = 0;
  5180. *tx_accept_flags = 0;
  5181. switch (rx_mode) {
  5182. case BNX2X_RX_MODE_NONE:
  5183. /*
  5184. * 'drop all' supersedes any accept flags that may have been
  5185. * passed to the function.
  5186. */
  5187. break;
  5188. case BNX2X_RX_MODE_NORMAL:
  5189. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5190. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5191. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5192. /* internal switching mode */
  5193. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5194. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5195. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5196. break;
  5197. case BNX2X_RX_MODE_ALLMULTI:
  5198. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5199. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5200. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5201. /* internal switching mode */
  5202. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5203. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5204. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5205. break;
  5206. case BNX2X_RX_MODE_PROMISC:
  5207. /* According to definition of SI mode, iface in promisc mode
  5208. * should receive matched and unmatched (in resolution of port)
  5209. * unicast packets.
  5210. */
  5211. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5212. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5213. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5214. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5215. /* internal switching mode */
  5216. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5217. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5218. if (IS_MF_SI(bp))
  5219. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5220. else
  5221. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5222. break;
  5223. default:
  5224. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5225. return -EINVAL;
  5226. }
  5227. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5228. if (rx_mode != BNX2X_RX_MODE_NONE) {
  5229. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5230. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5231. }
  5232. return 0;
  5233. }
  5234. /* called with netif_addr_lock_bh() */
  5235. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5236. {
  5237. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5238. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5239. int rc;
  5240. if (!NO_FCOE(bp))
  5241. /* Configure rx_mode of FCoE Queue */
  5242. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5243. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5244. &tx_accept_flags);
  5245. if (rc)
  5246. return rc;
  5247. __set_bit(RAMROD_RX, &ramrod_flags);
  5248. __set_bit(RAMROD_TX, &ramrod_flags);
  5249. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5250. rx_accept_flags, tx_accept_flags,
  5251. ramrod_flags);
  5252. }
  5253. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5254. {
  5255. int i;
  5256. /* Zero this manually as its initialization is
  5257. currently missing in the initTool */
  5258. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5259. REG_WR(bp, BAR_USTRORM_INTMEM +
  5260. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5261. if (!CHIP_IS_E1x(bp)) {
  5262. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5263. CHIP_INT_MODE_IS_BC(bp) ?
  5264. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5265. }
  5266. }
  5267. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5268. {
  5269. switch (load_code) {
  5270. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5271. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5272. bnx2x_init_internal_common(bp);
  5273. /* no break */
  5274. case FW_MSG_CODE_DRV_LOAD_PORT:
  5275. /* nothing to do */
  5276. /* no break */
  5277. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5278. /* internal memory per function is
  5279. initialized inside bnx2x_pf_init */
  5280. break;
  5281. default:
  5282. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5283. break;
  5284. }
  5285. }
  5286. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5287. {
  5288. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5289. }
  5290. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5291. {
  5292. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5293. }
  5294. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5295. {
  5296. if (CHIP_IS_E1x(fp->bp))
  5297. return BP_L_ID(fp->bp) + fp->index;
  5298. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5299. return bnx2x_fp_igu_sb_id(fp);
  5300. }
  5301. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5302. {
  5303. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5304. u8 cos;
  5305. unsigned long q_type = 0;
  5306. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5307. fp->rx_queue = fp_idx;
  5308. fp->cid = fp_idx;
  5309. fp->cl_id = bnx2x_fp_cl_id(fp);
  5310. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5311. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5312. /* qZone id equals to FW (per path) client id */
  5313. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5314. /* init shortcut */
  5315. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5316. /* Setup SB indices */
  5317. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5318. /* Configure Queue State object */
  5319. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5320. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5321. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5322. /* init tx data */
  5323. for_each_cos_in_tx_queue(fp, cos) {
  5324. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5325. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5326. FP_COS_TO_TXQ(fp, cos, bp),
  5327. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5328. cids[cos] = fp->txdata_ptr[cos]->cid;
  5329. }
  5330. /* nothing more for vf to do here */
  5331. if (IS_VF(bp))
  5332. return;
  5333. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5334. fp->fw_sb_id, fp->igu_sb_id);
  5335. bnx2x_update_fpsb_idx(fp);
  5336. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5337. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5338. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5339. /**
  5340. * Configure classification DBs: Always enable Tx switching
  5341. */
  5342. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5343. DP(NETIF_MSG_IFUP,
  5344. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5345. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5346. fp->igu_sb_id);
  5347. }
  5348. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5349. {
  5350. int i;
  5351. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5352. struct eth_tx_next_bd *tx_next_bd =
  5353. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5354. tx_next_bd->addr_hi =
  5355. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5356. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5357. tx_next_bd->addr_lo =
  5358. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5359. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5360. }
  5361. *txdata->tx_cons_sb = cpu_to_le16(0);
  5362. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5363. txdata->tx_db.data.zero_fill1 = 0;
  5364. txdata->tx_db.data.prod = 0;
  5365. txdata->tx_pkt_prod = 0;
  5366. txdata->tx_pkt_cons = 0;
  5367. txdata->tx_bd_prod = 0;
  5368. txdata->tx_bd_cons = 0;
  5369. txdata->tx_pkt = 0;
  5370. }
  5371. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5372. {
  5373. int i;
  5374. for_each_tx_queue_cnic(bp, i)
  5375. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5376. }
  5377. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5378. {
  5379. int i;
  5380. u8 cos;
  5381. for_each_eth_queue(bp, i)
  5382. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5383. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5384. }
  5385. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5386. {
  5387. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5388. unsigned long q_type = 0;
  5389. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5390. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5391. BNX2X_FCOE_ETH_CL_ID_IDX);
  5392. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5393. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5394. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5395. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5396. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5397. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5398. fp);
  5399. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5400. /* qZone id equals to FW (per path) client id */
  5401. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5402. /* init shortcut */
  5403. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5404. bnx2x_rx_ustorm_prods_offset(fp);
  5405. /* Configure Queue State object */
  5406. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5407. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5408. /* No multi-CoS for FCoE L2 client */
  5409. BUG_ON(fp->max_cos != 1);
  5410. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5411. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5412. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5413. DP(NETIF_MSG_IFUP,
  5414. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5415. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5416. fp->igu_sb_id);
  5417. }
  5418. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5419. {
  5420. if (!NO_FCOE(bp))
  5421. bnx2x_init_fcoe_fp(bp);
  5422. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5423. BNX2X_VF_ID_INVALID, false,
  5424. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5425. /* ensure status block indices were read */
  5426. rmb();
  5427. bnx2x_init_rx_rings_cnic(bp);
  5428. bnx2x_init_tx_rings_cnic(bp);
  5429. /* flush all */
  5430. mb();
  5431. mmiowb();
  5432. }
  5433. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5434. {
  5435. int i;
  5436. /* Setup NIC internals and enable interrupts */
  5437. for_each_eth_queue(bp, i)
  5438. bnx2x_init_eth_fp(bp, i);
  5439. /* ensure status block indices were read */
  5440. rmb();
  5441. bnx2x_init_rx_rings(bp);
  5442. bnx2x_init_tx_rings(bp);
  5443. if (IS_PF(bp)) {
  5444. /* Initialize MOD_ABS interrupts */
  5445. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5446. bp->common.shmem_base,
  5447. bp->common.shmem2_base, BP_PORT(bp));
  5448. /* initialize the default status block and sp ring */
  5449. bnx2x_init_def_sb(bp);
  5450. bnx2x_update_dsb_idx(bp);
  5451. bnx2x_init_sp_ring(bp);
  5452. } else {
  5453. bnx2x_memset_stats(bp);
  5454. }
  5455. }
  5456. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5457. {
  5458. bnx2x_init_eq_ring(bp);
  5459. bnx2x_init_internal(bp, load_code);
  5460. bnx2x_pf_init(bp);
  5461. bnx2x_stats_init(bp);
  5462. /* flush all before enabling interrupts */
  5463. mb();
  5464. mmiowb();
  5465. bnx2x_int_enable(bp);
  5466. /* Check for SPIO5 */
  5467. bnx2x_attn_int_deasserted0(bp,
  5468. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5469. AEU_INPUTS_ATTN_BITS_SPIO5);
  5470. }
  5471. /* gzip service functions */
  5472. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5473. {
  5474. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5475. &bp->gunzip_mapping, GFP_KERNEL);
  5476. if (bp->gunzip_buf == NULL)
  5477. goto gunzip_nomem1;
  5478. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5479. if (bp->strm == NULL)
  5480. goto gunzip_nomem2;
  5481. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5482. if (bp->strm->workspace == NULL)
  5483. goto gunzip_nomem3;
  5484. return 0;
  5485. gunzip_nomem3:
  5486. kfree(bp->strm);
  5487. bp->strm = NULL;
  5488. gunzip_nomem2:
  5489. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5490. bp->gunzip_mapping);
  5491. bp->gunzip_buf = NULL;
  5492. gunzip_nomem1:
  5493. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5494. return -ENOMEM;
  5495. }
  5496. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5497. {
  5498. if (bp->strm) {
  5499. vfree(bp->strm->workspace);
  5500. kfree(bp->strm);
  5501. bp->strm = NULL;
  5502. }
  5503. if (bp->gunzip_buf) {
  5504. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5505. bp->gunzip_mapping);
  5506. bp->gunzip_buf = NULL;
  5507. }
  5508. }
  5509. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5510. {
  5511. int n, rc;
  5512. /* check gzip header */
  5513. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5514. BNX2X_ERR("Bad gzip header\n");
  5515. return -EINVAL;
  5516. }
  5517. n = 10;
  5518. #define FNAME 0x8
  5519. if (zbuf[3] & FNAME)
  5520. while ((zbuf[n++] != 0) && (n < len));
  5521. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5522. bp->strm->avail_in = len - n;
  5523. bp->strm->next_out = bp->gunzip_buf;
  5524. bp->strm->avail_out = FW_BUF_SIZE;
  5525. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5526. if (rc != Z_OK)
  5527. return rc;
  5528. rc = zlib_inflate(bp->strm, Z_FINISH);
  5529. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5530. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5531. bp->strm->msg);
  5532. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5533. if (bp->gunzip_outlen & 0x3)
  5534. netdev_err(bp->dev,
  5535. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5536. bp->gunzip_outlen);
  5537. bp->gunzip_outlen >>= 2;
  5538. zlib_inflateEnd(bp->strm);
  5539. if (rc == Z_STREAM_END)
  5540. return 0;
  5541. return rc;
  5542. }
  5543. /* nic load/unload */
  5544. /*
  5545. * General service functions
  5546. */
  5547. /* send a NIG loopback debug packet */
  5548. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5549. {
  5550. u32 wb_write[3];
  5551. /* Ethernet source and destination addresses */
  5552. wb_write[0] = 0x55555555;
  5553. wb_write[1] = 0x55555555;
  5554. wb_write[2] = 0x20; /* SOP */
  5555. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5556. /* NON-IP protocol */
  5557. wb_write[0] = 0x09000000;
  5558. wb_write[1] = 0x55555555;
  5559. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5560. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5561. }
  5562. /* some of the internal memories
  5563. * are not directly readable from the driver
  5564. * to test them we send debug packets
  5565. */
  5566. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5567. {
  5568. int factor;
  5569. int count, i;
  5570. u32 val = 0;
  5571. if (CHIP_REV_IS_FPGA(bp))
  5572. factor = 120;
  5573. else if (CHIP_REV_IS_EMUL(bp))
  5574. factor = 200;
  5575. else
  5576. factor = 1;
  5577. /* Disable inputs of parser neighbor blocks */
  5578. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5579. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5580. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5581. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5582. /* Write 0 to parser credits for CFC search request */
  5583. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5584. /* send Ethernet packet */
  5585. bnx2x_lb_pckt(bp);
  5586. /* TODO do i reset NIG statistic? */
  5587. /* Wait until NIG register shows 1 packet of size 0x10 */
  5588. count = 1000 * factor;
  5589. while (count) {
  5590. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5591. val = *bnx2x_sp(bp, wb_data[0]);
  5592. if (val == 0x10)
  5593. break;
  5594. usleep_range(10000, 20000);
  5595. count--;
  5596. }
  5597. if (val != 0x10) {
  5598. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5599. return -1;
  5600. }
  5601. /* Wait until PRS register shows 1 packet */
  5602. count = 1000 * factor;
  5603. while (count) {
  5604. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5605. if (val == 1)
  5606. break;
  5607. usleep_range(10000, 20000);
  5608. count--;
  5609. }
  5610. if (val != 0x1) {
  5611. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5612. return -2;
  5613. }
  5614. /* Reset and init BRB, PRS */
  5615. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5616. msleep(50);
  5617. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5618. msleep(50);
  5619. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5620. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5621. DP(NETIF_MSG_HW, "part2\n");
  5622. /* Disable inputs of parser neighbor blocks */
  5623. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5624. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5625. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5626. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5627. /* Write 0 to parser credits for CFC search request */
  5628. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5629. /* send 10 Ethernet packets */
  5630. for (i = 0; i < 10; i++)
  5631. bnx2x_lb_pckt(bp);
  5632. /* Wait until NIG register shows 10 + 1
  5633. packets of size 11*0x10 = 0xb0 */
  5634. count = 1000 * factor;
  5635. while (count) {
  5636. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5637. val = *bnx2x_sp(bp, wb_data[0]);
  5638. if (val == 0xb0)
  5639. break;
  5640. usleep_range(10000, 20000);
  5641. count--;
  5642. }
  5643. if (val != 0xb0) {
  5644. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5645. return -3;
  5646. }
  5647. /* Wait until PRS register shows 2 packets */
  5648. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5649. if (val != 2)
  5650. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5651. /* Write 1 to parser credits for CFC search request */
  5652. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5653. /* Wait until PRS register shows 3 packets */
  5654. msleep(10 * factor);
  5655. /* Wait until NIG register shows 1 packet of size 0x10 */
  5656. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5657. if (val != 3)
  5658. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5659. /* clear NIG EOP FIFO */
  5660. for (i = 0; i < 11; i++)
  5661. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5662. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5663. if (val != 1) {
  5664. BNX2X_ERR("clear of NIG failed\n");
  5665. return -4;
  5666. }
  5667. /* Reset and init BRB, PRS, NIG */
  5668. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5669. msleep(50);
  5670. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5671. msleep(50);
  5672. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5673. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5674. if (!CNIC_SUPPORT(bp))
  5675. /* set NIC mode */
  5676. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5677. /* Enable inputs of parser neighbor blocks */
  5678. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5679. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5680. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5681. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5682. DP(NETIF_MSG_HW, "done\n");
  5683. return 0; /* OK */
  5684. }
  5685. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5686. {
  5687. u32 val;
  5688. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5689. if (!CHIP_IS_E1x(bp))
  5690. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5691. else
  5692. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5693. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5694. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5695. /*
  5696. * mask read length error interrupts in brb for parser
  5697. * (parsing unit and 'checksum and crc' unit)
  5698. * these errors are legal (PU reads fixed length and CAC can cause
  5699. * read length error on truncated packets)
  5700. */
  5701. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5702. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5703. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5704. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5705. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5706. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5707. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5708. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5709. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5710. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5711. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5712. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5713. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5714. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5715. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5716. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5717. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5718. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5719. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5720. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5721. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5722. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5723. if (!CHIP_IS_E1x(bp))
  5724. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5725. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5726. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5727. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5728. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5729. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5730. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5731. if (!CHIP_IS_E1x(bp))
  5732. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5733. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5734. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5735. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5736. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5737. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5738. }
  5739. static void bnx2x_reset_common(struct bnx2x *bp)
  5740. {
  5741. u32 val = 0x1400;
  5742. /* reset_common */
  5743. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5744. 0xd3ffff7f);
  5745. if (CHIP_IS_E3(bp)) {
  5746. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5747. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5748. }
  5749. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5750. }
  5751. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5752. {
  5753. bp->dmae_ready = 0;
  5754. spin_lock_init(&bp->dmae_lock);
  5755. }
  5756. static void bnx2x_init_pxp(struct bnx2x *bp)
  5757. {
  5758. u16 devctl;
  5759. int r_order, w_order;
  5760. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5761. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5762. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5763. if (bp->mrrs == -1)
  5764. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5765. else {
  5766. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5767. r_order = bp->mrrs;
  5768. }
  5769. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5770. }
  5771. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5772. {
  5773. int is_required;
  5774. u32 val;
  5775. int port;
  5776. if (BP_NOMCP(bp))
  5777. return;
  5778. is_required = 0;
  5779. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5780. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5781. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5782. is_required = 1;
  5783. /*
  5784. * The fan failure mechanism is usually related to the PHY type since
  5785. * the power consumption of the board is affected by the PHY. Currently,
  5786. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5787. */
  5788. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5789. for (port = PORT_0; port < PORT_MAX; port++) {
  5790. is_required |=
  5791. bnx2x_fan_failure_det_req(
  5792. bp,
  5793. bp->common.shmem_base,
  5794. bp->common.shmem2_base,
  5795. port);
  5796. }
  5797. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5798. if (is_required == 0)
  5799. return;
  5800. /* Fan failure is indicated by SPIO 5 */
  5801. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5802. /* set to active low mode */
  5803. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5804. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5805. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5806. /* enable interrupt to signal the IGU */
  5807. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5808. val |= MISC_SPIO_SPIO5;
  5809. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5810. }
  5811. void bnx2x_pf_disable(struct bnx2x *bp)
  5812. {
  5813. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5814. val &= ~IGU_PF_CONF_FUNC_EN;
  5815. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5816. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5817. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5818. }
  5819. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5820. {
  5821. u32 shmem_base[2], shmem2_base[2];
  5822. /* Avoid common init in case MFW supports LFA */
  5823. if (SHMEM2_RD(bp, size) >
  5824. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5825. return;
  5826. shmem_base[0] = bp->common.shmem_base;
  5827. shmem2_base[0] = bp->common.shmem2_base;
  5828. if (!CHIP_IS_E1x(bp)) {
  5829. shmem_base[1] =
  5830. SHMEM2_RD(bp, other_shmem_base_addr);
  5831. shmem2_base[1] =
  5832. SHMEM2_RD(bp, other_shmem2_base_addr);
  5833. }
  5834. bnx2x_acquire_phy_lock(bp);
  5835. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5836. bp->common.chip_id);
  5837. bnx2x_release_phy_lock(bp);
  5838. }
  5839. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5840. {
  5841. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5842. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5843. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5844. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5845. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5846. /* make sure this value is 0 */
  5847. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5848. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5849. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5850. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5851. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5852. }
  5853. static void bnx2x_set_endianity(struct bnx2x *bp)
  5854. {
  5855. #ifdef __BIG_ENDIAN
  5856. bnx2x_config_endianity(bp, 1);
  5857. #else
  5858. bnx2x_config_endianity(bp, 0);
  5859. #endif
  5860. }
  5861. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5862. {
  5863. bnx2x_config_endianity(bp, 0);
  5864. }
  5865. /**
  5866. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5867. *
  5868. * @bp: driver handle
  5869. */
  5870. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5871. {
  5872. u32 val;
  5873. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5874. /*
  5875. * take the RESET lock to protect undi_unload flow from accessing
  5876. * registers while we're resetting the chip
  5877. */
  5878. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5879. bnx2x_reset_common(bp);
  5880. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5881. val = 0xfffc;
  5882. if (CHIP_IS_E3(bp)) {
  5883. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5884. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5885. }
  5886. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5887. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5888. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5889. if (!CHIP_IS_E1x(bp)) {
  5890. u8 abs_func_id;
  5891. /**
  5892. * 4-port mode or 2-port mode we need to turn of master-enable
  5893. * for everyone, after that, turn it back on for self.
  5894. * so, we disregard multi-function or not, and always disable
  5895. * for all functions on the given path, this means 0,2,4,6 for
  5896. * path 0 and 1,3,5,7 for path 1
  5897. */
  5898. for (abs_func_id = BP_PATH(bp);
  5899. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5900. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5901. REG_WR(bp,
  5902. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5903. 1);
  5904. continue;
  5905. }
  5906. bnx2x_pretend_func(bp, abs_func_id);
  5907. /* clear pf enable */
  5908. bnx2x_pf_disable(bp);
  5909. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5910. }
  5911. }
  5912. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5913. if (CHIP_IS_E1(bp)) {
  5914. /* enable HW interrupt from PXP on USDM overflow
  5915. bit 16 on INT_MASK_0 */
  5916. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5917. }
  5918. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5919. bnx2x_init_pxp(bp);
  5920. bnx2x_set_endianity(bp);
  5921. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5922. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5923. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5924. /* let the HW do it's magic ... */
  5925. msleep(100);
  5926. /* finish PXP init */
  5927. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5928. if (val != 1) {
  5929. BNX2X_ERR("PXP2 CFG failed\n");
  5930. return -EBUSY;
  5931. }
  5932. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5933. if (val != 1) {
  5934. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5935. return -EBUSY;
  5936. }
  5937. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5938. * have entries with value "0" and valid bit on.
  5939. * This needs to be done by the first PF that is loaded in a path
  5940. * (i.e. common phase)
  5941. */
  5942. if (!CHIP_IS_E1x(bp)) {
  5943. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5944. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5945. * This occurs when a different function (func2,3) is being marked
  5946. * as "scan-off". Real-life scenario for example: if a driver is being
  5947. * load-unloaded while func6,7 are down. This will cause the timer to access
  5948. * the ilt, translate to a logical address and send a request to read/write.
  5949. * Since the ilt for the function that is down is not valid, this will cause
  5950. * a translation error which is unrecoverable.
  5951. * The Workaround is intended to make sure that when this happens nothing fatal
  5952. * will occur. The workaround:
  5953. * 1. First PF driver which loads on a path will:
  5954. * a. After taking the chip out of reset, by using pretend,
  5955. * it will write "0" to the following registers of
  5956. * the other vnics.
  5957. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5958. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5959. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5960. * And for itself it will write '1' to
  5961. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5962. * dmae-operations (writing to pram for example.)
  5963. * note: can be done for only function 6,7 but cleaner this
  5964. * way.
  5965. * b. Write zero+valid to the entire ILT.
  5966. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5967. * VNIC3 (of that port). The range allocated will be the
  5968. * entire ILT. This is needed to prevent ILT range error.
  5969. * 2. Any PF driver load flow:
  5970. * a. ILT update with the physical addresses of the allocated
  5971. * logical pages.
  5972. * b. Wait 20msec. - note that this timeout is needed to make
  5973. * sure there are no requests in one of the PXP internal
  5974. * queues with "old" ILT addresses.
  5975. * c. PF enable in the PGLC.
  5976. * d. Clear the was_error of the PF in the PGLC. (could have
  5977. * occurred while driver was down)
  5978. * e. PF enable in the CFC (WEAK + STRONG)
  5979. * f. Timers scan enable
  5980. * 3. PF driver unload flow:
  5981. * a. Clear the Timers scan_en.
  5982. * b. Polling for scan_on=0 for that PF.
  5983. * c. Clear the PF enable bit in the PXP.
  5984. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5985. * e. Write zero+valid to all ILT entries (The valid bit must
  5986. * stay set)
  5987. * f. If this is VNIC 3 of a port then also init
  5988. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5989. * to the last entry in the ILT.
  5990. *
  5991. * Notes:
  5992. * Currently the PF error in the PGLC is non recoverable.
  5993. * In the future the there will be a recovery routine for this error.
  5994. * Currently attention is masked.
  5995. * Having an MCP lock on the load/unload process does not guarantee that
  5996. * there is no Timer disable during Func6/7 enable. This is because the
  5997. * Timers scan is currently being cleared by the MCP on FLR.
  5998. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5999. * there is error before clearing it. But the flow above is simpler and
  6000. * more general.
  6001. * All ILT entries are written by zero+valid and not just PF6/7
  6002. * ILT entries since in the future the ILT entries allocation for
  6003. * PF-s might be dynamic.
  6004. */
  6005. struct ilt_client_info ilt_cli;
  6006. struct bnx2x_ilt ilt;
  6007. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6008. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6009. /* initialize dummy TM client */
  6010. ilt_cli.start = 0;
  6011. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6012. ilt_cli.client_num = ILT_CLIENT_TM;
  6013. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6014. * Step 2: set the timers first/last ilt entry to point
  6015. * to the entire range to prevent ILT range error for 3rd/4th
  6016. * vnic (this code assumes existence of the vnic)
  6017. *
  6018. * both steps performed by call to bnx2x_ilt_client_init_op()
  6019. * with dummy TM client
  6020. *
  6021. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6022. * and his brother are split registers
  6023. */
  6024. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6025. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6026. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6027. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6028. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6029. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6030. }
  6031. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6032. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6033. if (!CHIP_IS_E1x(bp)) {
  6034. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6035. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6036. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6037. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6038. /* let the HW do it's magic ... */
  6039. do {
  6040. msleep(200);
  6041. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6042. } while (factor-- && (val != 1));
  6043. if (val != 1) {
  6044. BNX2X_ERR("ATC_INIT failed\n");
  6045. return -EBUSY;
  6046. }
  6047. }
  6048. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6049. bnx2x_iov_init_dmae(bp);
  6050. /* clean the DMAE memory */
  6051. bp->dmae_ready = 1;
  6052. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6053. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6054. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6055. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6056. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6057. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6058. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6059. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6060. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6061. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6062. /* QM queues pointers table */
  6063. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6064. /* soft reset pulse */
  6065. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6066. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6067. if (CNIC_SUPPORT(bp))
  6068. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6069. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6070. if (!CHIP_REV_IS_SLOW(bp))
  6071. /* enable hw interrupt from doorbell Q */
  6072. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6073. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6074. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6075. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6076. if (!CHIP_IS_E1(bp))
  6077. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6078. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6079. if (IS_MF_AFEX(bp)) {
  6080. /* configure that VNTag and VLAN headers must be
  6081. * received in afex mode
  6082. */
  6083. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6084. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6085. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6086. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6087. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6088. } else {
  6089. /* Bit-map indicating which L2 hdrs may appear
  6090. * after the basic Ethernet header
  6091. */
  6092. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6093. bp->path_has_ovlan ? 7 : 6);
  6094. }
  6095. }
  6096. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6097. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6098. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6099. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6100. if (!CHIP_IS_E1x(bp)) {
  6101. /* reset VFC memories */
  6102. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6103. VFC_MEMORIES_RST_REG_CAM_RST |
  6104. VFC_MEMORIES_RST_REG_RAM_RST);
  6105. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6106. VFC_MEMORIES_RST_REG_CAM_RST |
  6107. VFC_MEMORIES_RST_REG_RAM_RST);
  6108. msleep(20);
  6109. }
  6110. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6111. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6112. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6113. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6114. /* sync semi rtc */
  6115. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6116. 0x80000000);
  6117. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6118. 0x80000000);
  6119. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6120. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6121. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6122. if (!CHIP_IS_E1x(bp)) {
  6123. if (IS_MF_AFEX(bp)) {
  6124. /* configure that VNTag and VLAN headers must be
  6125. * sent in afex mode
  6126. */
  6127. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6128. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6129. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6130. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6131. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6132. } else {
  6133. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6134. bp->path_has_ovlan ? 7 : 6);
  6135. }
  6136. }
  6137. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6138. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6139. if (CNIC_SUPPORT(bp)) {
  6140. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6141. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6142. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6143. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6144. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6145. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6146. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6147. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6148. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6149. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6150. }
  6151. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6152. if (sizeof(union cdu_context) != 1024)
  6153. /* we currently assume that a context is 1024 bytes */
  6154. dev_alert(&bp->pdev->dev,
  6155. "please adjust the size of cdu_context(%ld)\n",
  6156. (long)sizeof(union cdu_context));
  6157. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6158. val = (4 << 24) + (0 << 12) + 1024;
  6159. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6160. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6161. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6162. /* enable context validation interrupt from CFC */
  6163. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6164. /* set the thresholds to prevent CFC/CDU race */
  6165. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6166. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6167. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6168. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6169. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6170. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6171. /* Reset PCIE errors for debug */
  6172. REG_WR(bp, 0x2814, 0xffffffff);
  6173. REG_WR(bp, 0x3820, 0xffffffff);
  6174. if (!CHIP_IS_E1x(bp)) {
  6175. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6176. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6177. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6178. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6179. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6180. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6181. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6182. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6183. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6184. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6185. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6186. }
  6187. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6188. if (!CHIP_IS_E1(bp)) {
  6189. /* in E3 this done in per-port section */
  6190. if (!CHIP_IS_E3(bp))
  6191. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6192. }
  6193. if (CHIP_IS_E1H(bp))
  6194. /* not applicable for E2 (and above ...) */
  6195. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6196. if (CHIP_REV_IS_SLOW(bp))
  6197. msleep(200);
  6198. /* finish CFC init */
  6199. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6200. if (val != 1) {
  6201. BNX2X_ERR("CFC LL_INIT failed\n");
  6202. return -EBUSY;
  6203. }
  6204. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6205. if (val != 1) {
  6206. BNX2X_ERR("CFC AC_INIT failed\n");
  6207. return -EBUSY;
  6208. }
  6209. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6210. if (val != 1) {
  6211. BNX2X_ERR("CFC CAM_INIT failed\n");
  6212. return -EBUSY;
  6213. }
  6214. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6215. if (CHIP_IS_E1(bp)) {
  6216. /* read NIG statistic
  6217. to see if this is our first up since powerup */
  6218. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6219. val = *bnx2x_sp(bp, wb_data[0]);
  6220. /* do internal memory self test */
  6221. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6222. BNX2X_ERR("internal mem self test failed\n");
  6223. return -EBUSY;
  6224. }
  6225. }
  6226. bnx2x_setup_fan_failure_detection(bp);
  6227. /* clear PXP2 attentions */
  6228. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6229. bnx2x_enable_blocks_attention(bp);
  6230. bnx2x_enable_blocks_parity(bp);
  6231. if (!BP_NOMCP(bp)) {
  6232. if (CHIP_IS_E1x(bp))
  6233. bnx2x__common_init_phy(bp);
  6234. } else
  6235. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6236. return 0;
  6237. }
  6238. /**
  6239. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6240. *
  6241. * @bp: driver handle
  6242. */
  6243. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6244. {
  6245. int rc = bnx2x_init_hw_common(bp);
  6246. if (rc)
  6247. return rc;
  6248. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6249. if (!BP_NOMCP(bp))
  6250. bnx2x__common_init_phy(bp);
  6251. return 0;
  6252. }
  6253. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6254. {
  6255. int port = BP_PORT(bp);
  6256. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6257. u32 low, high;
  6258. u32 val, reg;
  6259. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6260. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6261. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6263. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6264. /* Timers bug workaround: disables the pf_master bit in pglue at
  6265. * common phase, we need to enable it here before any dmae access are
  6266. * attempted. Therefore we manually added the enable-master to the
  6267. * port phase (it also happens in the function phase)
  6268. */
  6269. if (!CHIP_IS_E1x(bp))
  6270. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6271. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6272. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6273. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6274. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6275. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6276. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6277. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6278. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6279. /* QM cid (connection) count */
  6280. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6281. if (CNIC_SUPPORT(bp)) {
  6282. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6283. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6284. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6285. }
  6286. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6287. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6288. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6289. if (IS_MF(bp))
  6290. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6291. else if (bp->dev->mtu > 4096) {
  6292. if (bp->flags & ONE_PORT_FLAG)
  6293. low = 160;
  6294. else {
  6295. val = bp->dev->mtu;
  6296. /* (24*1024 + val*4)/256 */
  6297. low = 96 + (val/64) +
  6298. ((val % 64) ? 1 : 0);
  6299. }
  6300. } else
  6301. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6302. high = low + 56; /* 14*1024/256 */
  6303. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6304. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6305. }
  6306. if (CHIP_MODE_IS_4_PORT(bp))
  6307. REG_WR(bp, (BP_PORT(bp) ?
  6308. BRB1_REG_MAC_GUARANTIED_1 :
  6309. BRB1_REG_MAC_GUARANTIED_0), 40);
  6310. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6311. if (CHIP_IS_E3B0(bp)) {
  6312. if (IS_MF_AFEX(bp)) {
  6313. /* configure headers for AFEX mode */
  6314. REG_WR(bp, BP_PORT(bp) ?
  6315. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6316. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6317. REG_WR(bp, BP_PORT(bp) ?
  6318. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6319. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6320. REG_WR(bp, BP_PORT(bp) ?
  6321. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6322. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6323. } else {
  6324. /* Ovlan exists only if we are in multi-function +
  6325. * switch-dependent mode, in switch-independent there
  6326. * is no ovlan headers
  6327. */
  6328. REG_WR(bp, BP_PORT(bp) ?
  6329. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6330. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6331. (bp->path_has_ovlan ? 7 : 6));
  6332. }
  6333. }
  6334. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6335. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6336. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6337. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6338. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6339. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6340. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6341. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6342. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6343. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6344. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6345. if (CHIP_IS_E1x(bp)) {
  6346. /* configure PBF to work without PAUSE mtu 9000 */
  6347. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6348. /* update threshold */
  6349. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6350. /* update init credit */
  6351. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6352. /* probe changes */
  6353. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6354. udelay(50);
  6355. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6356. }
  6357. if (CNIC_SUPPORT(bp))
  6358. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6359. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6360. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6361. if (CHIP_IS_E1(bp)) {
  6362. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6363. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6364. }
  6365. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6366. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6367. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6368. /* init aeu_mask_attn_func_0/1:
  6369. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6370. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6371. * bits 4-7 are used for "per vn group attention" */
  6372. val = IS_MF(bp) ? 0xF7 : 0x7;
  6373. /* Enable DCBX attention for all but E1 */
  6374. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6375. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6376. /* SCPAD_PARITY should NOT trigger close the gates */
  6377. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6378. REG_WR(bp, reg,
  6379. REG_RD(bp, reg) &
  6380. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6381. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6382. REG_WR(bp, reg,
  6383. REG_RD(bp, reg) &
  6384. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6385. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6386. if (!CHIP_IS_E1x(bp)) {
  6387. /* Bit-map indicating which L2 hdrs may appear after the
  6388. * basic Ethernet header
  6389. */
  6390. if (IS_MF_AFEX(bp))
  6391. REG_WR(bp, BP_PORT(bp) ?
  6392. NIG_REG_P1_HDRS_AFTER_BASIC :
  6393. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6394. else
  6395. REG_WR(bp, BP_PORT(bp) ?
  6396. NIG_REG_P1_HDRS_AFTER_BASIC :
  6397. NIG_REG_P0_HDRS_AFTER_BASIC,
  6398. IS_MF_SD(bp) ? 7 : 6);
  6399. if (CHIP_IS_E3(bp))
  6400. REG_WR(bp, BP_PORT(bp) ?
  6401. NIG_REG_LLH1_MF_MODE :
  6402. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6403. }
  6404. if (!CHIP_IS_E3(bp))
  6405. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6406. if (!CHIP_IS_E1(bp)) {
  6407. /* 0x2 disable mf_ov, 0x1 enable */
  6408. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6409. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6410. if (!CHIP_IS_E1x(bp)) {
  6411. val = 0;
  6412. switch (bp->mf_mode) {
  6413. case MULTI_FUNCTION_SD:
  6414. val = 1;
  6415. break;
  6416. case MULTI_FUNCTION_SI:
  6417. case MULTI_FUNCTION_AFEX:
  6418. val = 2;
  6419. break;
  6420. }
  6421. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6422. NIG_REG_LLH0_CLS_TYPE), val);
  6423. }
  6424. {
  6425. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6426. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6427. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6428. }
  6429. }
  6430. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6431. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6432. if (val & MISC_SPIO_SPIO5) {
  6433. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6434. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6435. val = REG_RD(bp, reg_addr);
  6436. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6437. REG_WR(bp, reg_addr, val);
  6438. }
  6439. return 0;
  6440. }
  6441. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6442. {
  6443. int reg;
  6444. u32 wb_write[2];
  6445. if (CHIP_IS_E1(bp))
  6446. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6447. else
  6448. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6449. wb_write[0] = ONCHIP_ADDR1(addr);
  6450. wb_write[1] = ONCHIP_ADDR2(addr);
  6451. REG_WR_DMAE(bp, reg, wb_write, 2);
  6452. }
  6453. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6454. {
  6455. u32 data, ctl, cnt = 100;
  6456. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6457. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6458. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6459. u32 sb_bit = 1 << (idu_sb_id%32);
  6460. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6461. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6462. /* Not supported in BC mode */
  6463. if (CHIP_INT_MODE_IS_BC(bp))
  6464. return;
  6465. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6466. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6467. IGU_REGULAR_CLEANUP_SET |
  6468. IGU_REGULAR_BCLEANUP;
  6469. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6470. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6471. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6472. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6473. data, igu_addr_data);
  6474. REG_WR(bp, igu_addr_data, data);
  6475. mmiowb();
  6476. barrier();
  6477. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6478. ctl, igu_addr_ctl);
  6479. REG_WR(bp, igu_addr_ctl, ctl);
  6480. mmiowb();
  6481. barrier();
  6482. /* wait for clean up to finish */
  6483. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6484. msleep(20);
  6485. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6486. DP(NETIF_MSG_HW,
  6487. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6488. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6489. }
  6490. }
  6491. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6492. {
  6493. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6494. }
  6495. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6496. {
  6497. u32 i, base = FUNC_ILT_BASE(func);
  6498. for (i = base; i < base + ILT_PER_FUNC; i++)
  6499. bnx2x_ilt_wr(bp, i, 0);
  6500. }
  6501. static void bnx2x_init_searcher(struct bnx2x *bp)
  6502. {
  6503. int port = BP_PORT(bp);
  6504. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6505. /* T1 hash bits value determines the T1 number of entries */
  6506. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6507. }
  6508. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6509. {
  6510. int rc;
  6511. struct bnx2x_func_state_params func_params = {NULL};
  6512. struct bnx2x_func_switch_update_params *switch_update_params =
  6513. &func_params.params.switch_update;
  6514. /* Prepare parameters for function state transitions */
  6515. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6516. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6517. func_params.f_obj = &bp->func_obj;
  6518. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6519. /* Function parameters */
  6520. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6521. &switch_update_params->changes);
  6522. if (suspend)
  6523. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6524. &switch_update_params->changes);
  6525. rc = bnx2x_func_state_change(bp, &func_params);
  6526. return rc;
  6527. }
  6528. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6529. {
  6530. int rc, i, port = BP_PORT(bp);
  6531. int vlan_en = 0, mac_en[NUM_MACS];
  6532. /* Close input from network */
  6533. if (bp->mf_mode == SINGLE_FUNCTION) {
  6534. bnx2x_set_rx_filter(&bp->link_params, 0);
  6535. } else {
  6536. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6537. NIG_REG_LLH0_FUNC_EN);
  6538. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6539. NIG_REG_LLH0_FUNC_EN, 0);
  6540. for (i = 0; i < NUM_MACS; i++) {
  6541. mac_en[i] = REG_RD(bp, port ?
  6542. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6543. 4 * i) :
  6544. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6545. 4 * i));
  6546. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6547. 4 * i) :
  6548. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6549. }
  6550. }
  6551. /* Close BMC to host */
  6552. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6553. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6554. /* Suspend Tx switching to the PF. Completion of this ramrod
  6555. * further guarantees that all the packets of that PF / child
  6556. * VFs in BRB were processed by the Parser, so it is safe to
  6557. * change the NIC_MODE register.
  6558. */
  6559. rc = bnx2x_func_switch_update(bp, 1);
  6560. if (rc) {
  6561. BNX2X_ERR("Can't suspend tx-switching!\n");
  6562. return rc;
  6563. }
  6564. /* Change NIC_MODE register */
  6565. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6566. /* Open input from network */
  6567. if (bp->mf_mode == SINGLE_FUNCTION) {
  6568. bnx2x_set_rx_filter(&bp->link_params, 1);
  6569. } else {
  6570. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6571. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6572. for (i = 0; i < NUM_MACS; i++) {
  6573. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6574. 4 * i) :
  6575. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6576. mac_en[i]);
  6577. }
  6578. }
  6579. /* Enable BMC to host */
  6580. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6581. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6582. /* Resume Tx switching to the PF */
  6583. rc = bnx2x_func_switch_update(bp, 0);
  6584. if (rc) {
  6585. BNX2X_ERR("Can't resume tx-switching!\n");
  6586. return rc;
  6587. }
  6588. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6589. return 0;
  6590. }
  6591. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6592. {
  6593. int rc;
  6594. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6595. if (CONFIGURE_NIC_MODE(bp)) {
  6596. /* Configure searcher as part of function hw init */
  6597. bnx2x_init_searcher(bp);
  6598. /* Reset NIC mode */
  6599. rc = bnx2x_reset_nic_mode(bp);
  6600. if (rc)
  6601. BNX2X_ERR("Can't change NIC mode!\n");
  6602. return rc;
  6603. }
  6604. return 0;
  6605. }
  6606. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  6607. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  6608. * the addresses of the transaction, resulting in was-error bit set in the pci
  6609. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  6610. * to clear the interrupt which detected this from the pglueb and the was done
  6611. * bit
  6612. */
  6613. static void bnx2x_clean_pglue_errors(struct bnx2x *bp)
  6614. {
  6615. if (!CHIP_IS_E1x(bp))
  6616. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  6617. 1 << BP_ABS_FUNC(bp));
  6618. }
  6619. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6620. {
  6621. int port = BP_PORT(bp);
  6622. int func = BP_FUNC(bp);
  6623. int init_phase = PHASE_PF0 + func;
  6624. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6625. u16 cdu_ilt_start;
  6626. u32 addr, val;
  6627. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6628. int i, main_mem_width, rc;
  6629. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6630. /* FLR cleanup - hmmm */
  6631. if (!CHIP_IS_E1x(bp)) {
  6632. rc = bnx2x_pf_flr_clnup(bp);
  6633. if (rc) {
  6634. bnx2x_fw_dump(bp);
  6635. return rc;
  6636. }
  6637. }
  6638. /* set MSI reconfigure capability */
  6639. if (bp->common.int_block == INT_BLOCK_HC) {
  6640. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6641. val = REG_RD(bp, addr);
  6642. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6643. REG_WR(bp, addr, val);
  6644. }
  6645. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6646. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6647. ilt = BP_ILT(bp);
  6648. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6649. if (IS_SRIOV(bp))
  6650. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6651. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6652. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6653. * those of the VFs, so start line should be reset
  6654. */
  6655. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6656. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6657. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6658. ilt->lines[cdu_ilt_start + i].page_mapping =
  6659. bp->context[i].cxt_mapping;
  6660. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6661. }
  6662. bnx2x_ilt_init_op(bp, INITOP_SET);
  6663. if (!CONFIGURE_NIC_MODE(bp)) {
  6664. bnx2x_init_searcher(bp);
  6665. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6666. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6667. } else {
  6668. /* Set NIC mode */
  6669. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6670. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6671. }
  6672. if (!CHIP_IS_E1x(bp)) {
  6673. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6674. /* Turn on a single ISR mode in IGU if driver is going to use
  6675. * INT#x or MSI
  6676. */
  6677. if (!(bp->flags & USING_MSIX_FLAG))
  6678. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6679. /*
  6680. * Timers workaround bug: function init part.
  6681. * Need to wait 20msec after initializing ILT,
  6682. * needed to make sure there are no requests in
  6683. * one of the PXP internal queues with "old" ILT addresses
  6684. */
  6685. msleep(20);
  6686. /*
  6687. * Master enable - Due to WB DMAE writes performed before this
  6688. * register is re-initialized as part of the regular function
  6689. * init
  6690. */
  6691. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6692. /* Enable the function in IGU */
  6693. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6694. }
  6695. bp->dmae_ready = 1;
  6696. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6697. bnx2x_clean_pglue_errors(bp);
  6698. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6699. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6700. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6701. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6702. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6703. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6704. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6705. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6706. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6707. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6708. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6709. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6710. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6711. if (!CHIP_IS_E1x(bp))
  6712. REG_WR(bp, QM_REG_PF_EN, 1);
  6713. if (!CHIP_IS_E1x(bp)) {
  6714. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6715. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6716. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6717. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6718. }
  6719. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6720. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6721. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6722. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6723. bnx2x_iov_init_dq(bp);
  6724. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6725. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6726. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6727. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6728. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6729. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6730. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6731. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6732. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6733. if (!CHIP_IS_E1x(bp))
  6734. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6735. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6736. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6737. if (!CHIP_IS_E1x(bp))
  6738. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6739. if (IS_MF(bp)) {
  6740. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6741. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6742. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6743. bp->mf_ov);
  6744. }
  6745. }
  6746. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6747. /* HC init per function */
  6748. if (bp->common.int_block == INT_BLOCK_HC) {
  6749. if (CHIP_IS_E1H(bp)) {
  6750. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6751. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6752. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6753. }
  6754. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6755. } else {
  6756. int num_segs, sb_idx, prod_offset;
  6757. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6758. if (!CHIP_IS_E1x(bp)) {
  6759. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6760. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6761. }
  6762. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6763. if (!CHIP_IS_E1x(bp)) {
  6764. int dsb_idx = 0;
  6765. /**
  6766. * Producer memory:
  6767. * E2 mode: address 0-135 match to the mapping memory;
  6768. * 136 - PF0 default prod; 137 - PF1 default prod;
  6769. * 138 - PF2 default prod; 139 - PF3 default prod;
  6770. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6771. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6772. * 144-147 reserved.
  6773. *
  6774. * E1.5 mode - In backward compatible mode;
  6775. * for non default SB; each even line in the memory
  6776. * holds the U producer and each odd line hold
  6777. * the C producer. The first 128 producers are for
  6778. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6779. * producers are for the DSB for each PF.
  6780. * Each PF has five segments: (the order inside each
  6781. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6782. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6783. * 144-147 attn prods;
  6784. */
  6785. /* non-default-status-blocks */
  6786. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6787. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6788. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6789. prod_offset = (bp->igu_base_sb + sb_idx) *
  6790. num_segs;
  6791. for (i = 0; i < num_segs; i++) {
  6792. addr = IGU_REG_PROD_CONS_MEMORY +
  6793. (prod_offset + i) * 4;
  6794. REG_WR(bp, addr, 0);
  6795. }
  6796. /* send consumer update with value 0 */
  6797. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6798. USTORM_ID, 0, IGU_INT_NOP, 1);
  6799. bnx2x_igu_clear_sb(bp,
  6800. bp->igu_base_sb + sb_idx);
  6801. }
  6802. /* default-status-blocks */
  6803. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6804. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6805. if (CHIP_MODE_IS_4_PORT(bp))
  6806. dsb_idx = BP_FUNC(bp);
  6807. else
  6808. dsb_idx = BP_VN(bp);
  6809. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6810. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6811. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6812. /*
  6813. * igu prods come in chunks of E1HVN_MAX (4) -
  6814. * does not matters what is the current chip mode
  6815. */
  6816. for (i = 0; i < (num_segs * E1HVN_MAX);
  6817. i += E1HVN_MAX) {
  6818. addr = IGU_REG_PROD_CONS_MEMORY +
  6819. (prod_offset + i)*4;
  6820. REG_WR(bp, addr, 0);
  6821. }
  6822. /* send consumer update with 0 */
  6823. if (CHIP_INT_MODE_IS_BC(bp)) {
  6824. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6825. USTORM_ID, 0, IGU_INT_NOP, 1);
  6826. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6827. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6828. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6829. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6830. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6831. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6832. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6833. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6834. } else {
  6835. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6836. USTORM_ID, 0, IGU_INT_NOP, 1);
  6837. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6838. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6839. }
  6840. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6841. /* !!! These should become driver const once
  6842. rf-tool supports split-68 const */
  6843. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6844. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6845. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6846. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6847. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6848. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6849. }
  6850. }
  6851. /* Reset PCIE errors for debug */
  6852. REG_WR(bp, 0x2114, 0xffffffff);
  6853. REG_WR(bp, 0x2120, 0xffffffff);
  6854. if (CHIP_IS_E1x(bp)) {
  6855. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6856. main_mem_base = HC_REG_MAIN_MEMORY +
  6857. BP_PORT(bp) * (main_mem_size * 4);
  6858. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6859. main_mem_width = 8;
  6860. val = REG_RD(bp, main_mem_prty_clr);
  6861. if (val)
  6862. DP(NETIF_MSG_HW,
  6863. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6864. val);
  6865. /* Clear "false" parity errors in MSI-X table */
  6866. for (i = main_mem_base;
  6867. i < main_mem_base + main_mem_size * 4;
  6868. i += main_mem_width) {
  6869. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6870. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6871. i, main_mem_width / 4);
  6872. }
  6873. /* Clear HC parity attention */
  6874. REG_RD(bp, main_mem_prty_clr);
  6875. }
  6876. #ifdef BNX2X_STOP_ON_ERROR
  6877. /* Enable STORMs SP logging */
  6878. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6879. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6880. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6881. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6882. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6883. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6884. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6885. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6886. #endif
  6887. bnx2x_phy_probe(&bp->link_params);
  6888. return 0;
  6889. }
  6890. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6891. {
  6892. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6893. if (!CHIP_IS_E1x(bp))
  6894. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6895. sizeof(struct host_hc_status_block_e2));
  6896. else
  6897. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6898. sizeof(struct host_hc_status_block_e1x));
  6899. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6900. }
  6901. void bnx2x_free_mem(struct bnx2x *bp)
  6902. {
  6903. int i;
  6904. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6905. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6906. if (IS_VF(bp))
  6907. return;
  6908. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6909. sizeof(struct host_sp_status_block));
  6910. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6911. sizeof(struct bnx2x_slowpath));
  6912. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6913. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6914. bp->context[i].size);
  6915. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6916. BNX2X_FREE(bp->ilt->lines);
  6917. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6918. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6919. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6920. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6921. bnx2x_iov_free_mem(bp);
  6922. }
  6923. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6924. {
  6925. if (!CHIP_IS_E1x(bp)) {
  6926. /* size = the status block + ramrod buffers */
  6927. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6928. sizeof(struct host_hc_status_block_e2));
  6929. if (!bp->cnic_sb.e2_sb)
  6930. goto alloc_mem_err;
  6931. } else {
  6932. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6933. sizeof(struct host_hc_status_block_e1x));
  6934. if (!bp->cnic_sb.e1x_sb)
  6935. goto alloc_mem_err;
  6936. }
  6937. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6938. /* allocate searcher T2 table, as it wasn't allocated before */
  6939. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6940. if (!bp->t2)
  6941. goto alloc_mem_err;
  6942. }
  6943. /* write address to which L5 should insert its values */
  6944. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6945. &bp->slowpath->drv_info_to_mcp;
  6946. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6947. goto alloc_mem_err;
  6948. return 0;
  6949. alloc_mem_err:
  6950. bnx2x_free_mem_cnic(bp);
  6951. BNX2X_ERR("Can't allocate memory\n");
  6952. return -ENOMEM;
  6953. }
  6954. int bnx2x_alloc_mem(struct bnx2x *bp)
  6955. {
  6956. int i, allocated, context_size;
  6957. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6958. /* allocate searcher T2 table */
  6959. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6960. if (!bp->t2)
  6961. goto alloc_mem_err;
  6962. }
  6963. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6964. sizeof(struct host_sp_status_block));
  6965. if (!bp->def_status_blk)
  6966. goto alloc_mem_err;
  6967. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6968. sizeof(struct bnx2x_slowpath));
  6969. if (!bp->slowpath)
  6970. goto alloc_mem_err;
  6971. /* Allocate memory for CDU context:
  6972. * This memory is allocated separately and not in the generic ILT
  6973. * functions because CDU differs in few aspects:
  6974. * 1. There are multiple entities allocating memory for context -
  6975. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6976. * its own ILT lines.
  6977. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6978. * for the other ILT clients), to be efficient we want to support
  6979. * allocation of sub-page-size in the last entry.
  6980. * 3. Context pointers are used by the driver to pass to FW / update
  6981. * the context (for the other ILT clients the pointers are used just to
  6982. * free the memory during unload).
  6983. */
  6984. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6985. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6986. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6987. (context_size - allocated));
  6988. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6989. bp->context[i].size);
  6990. if (!bp->context[i].vcxt)
  6991. goto alloc_mem_err;
  6992. allocated += bp->context[i].size;
  6993. }
  6994. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6995. GFP_KERNEL);
  6996. if (!bp->ilt->lines)
  6997. goto alloc_mem_err;
  6998. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6999. goto alloc_mem_err;
  7000. if (bnx2x_iov_alloc_mem(bp))
  7001. goto alloc_mem_err;
  7002. /* Slow path ring */
  7003. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  7004. if (!bp->spq)
  7005. goto alloc_mem_err;
  7006. /* EQ */
  7007. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  7008. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  7009. if (!bp->eq_ring)
  7010. goto alloc_mem_err;
  7011. return 0;
  7012. alloc_mem_err:
  7013. bnx2x_free_mem(bp);
  7014. BNX2X_ERR("Can't allocate memory\n");
  7015. return -ENOMEM;
  7016. }
  7017. /*
  7018. * Init service functions
  7019. */
  7020. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7021. struct bnx2x_vlan_mac_obj *obj, bool set,
  7022. int mac_type, unsigned long *ramrod_flags)
  7023. {
  7024. int rc;
  7025. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7026. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7027. /* Fill general parameters */
  7028. ramrod_param.vlan_mac_obj = obj;
  7029. ramrod_param.ramrod_flags = *ramrod_flags;
  7030. /* Fill a user request section if needed */
  7031. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7032. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7033. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7034. /* Set the command: ADD or DEL */
  7035. if (set)
  7036. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7037. else
  7038. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7039. }
  7040. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7041. if (rc == -EEXIST) {
  7042. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7043. /* do not treat adding same MAC as error */
  7044. rc = 0;
  7045. } else if (rc < 0)
  7046. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7047. return rc;
  7048. }
  7049. int bnx2x_del_all_macs(struct bnx2x *bp,
  7050. struct bnx2x_vlan_mac_obj *mac_obj,
  7051. int mac_type, bool wait_for_comp)
  7052. {
  7053. int rc;
  7054. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7055. /* Wait for completion of requested */
  7056. if (wait_for_comp)
  7057. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7058. /* Set the mac type of addresses we want to clear */
  7059. __set_bit(mac_type, &vlan_mac_flags);
  7060. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7061. if (rc < 0)
  7062. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7063. return rc;
  7064. }
  7065. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7066. {
  7067. if (IS_PF(bp)) {
  7068. unsigned long ramrod_flags = 0;
  7069. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7070. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7071. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7072. &bp->sp_objs->mac_obj, set,
  7073. BNX2X_ETH_MAC, &ramrod_flags);
  7074. } else { /* vf */
  7075. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7076. bp->fp->index, true);
  7077. }
  7078. }
  7079. int bnx2x_setup_leading(struct bnx2x *bp)
  7080. {
  7081. if (IS_PF(bp))
  7082. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7083. else /* VF */
  7084. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7085. }
  7086. /**
  7087. * bnx2x_set_int_mode - configure interrupt mode
  7088. *
  7089. * @bp: driver handle
  7090. *
  7091. * In case of MSI-X it will also try to enable MSI-X.
  7092. */
  7093. int bnx2x_set_int_mode(struct bnx2x *bp)
  7094. {
  7095. int rc = 0;
  7096. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7097. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7098. return -EINVAL;
  7099. }
  7100. switch (int_mode) {
  7101. case BNX2X_INT_MODE_MSIX:
  7102. /* attempt to enable msix */
  7103. rc = bnx2x_enable_msix(bp);
  7104. /* msix attained */
  7105. if (!rc)
  7106. return 0;
  7107. /* vfs use only msix */
  7108. if (rc && IS_VF(bp))
  7109. return rc;
  7110. /* failed to enable multiple MSI-X */
  7111. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7112. bp->num_queues,
  7113. 1 + bp->num_cnic_queues);
  7114. /* falling through... */
  7115. case BNX2X_INT_MODE_MSI:
  7116. bnx2x_enable_msi(bp);
  7117. /* falling through... */
  7118. case BNX2X_INT_MODE_INTX:
  7119. bp->num_ethernet_queues = 1;
  7120. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7121. BNX2X_DEV_INFO("set number of queues to 1\n");
  7122. break;
  7123. default:
  7124. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7125. return -EINVAL;
  7126. }
  7127. return 0;
  7128. }
  7129. /* must be called prior to any HW initializations */
  7130. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7131. {
  7132. if (IS_SRIOV(bp))
  7133. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7134. return L2_ILT_LINES(bp);
  7135. }
  7136. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7137. {
  7138. struct ilt_client_info *ilt_client;
  7139. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7140. u16 line = 0;
  7141. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7142. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7143. /* CDU */
  7144. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7145. ilt_client->client_num = ILT_CLIENT_CDU;
  7146. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7147. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7148. ilt_client->start = line;
  7149. line += bnx2x_cid_ilt_lines(bp);
  7150. if (CNIC_SUPPORT(bp))
  7151. line += CNIC_ILT_LINES;
  7152. ilt_client->end = line - 1;
  7153. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7154. ilt_client->start,
  7155. ilt_client->end,
  7156. ilt_client->page_size,
  7157. ilt_client->flags,
  7158. ilog2(ilt_client->page_size >> 12));
  7159. /* QM */
  7160. if (QM_INIT(bp->qm_cid_count)) {
  7161. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7162. ilt_client->client_num = ILT_CLIENT_QM;
  7163. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7164. ilt_client->flags = 0;
  7165. ilt_client->start = line;
  7166. /* 4 bytes for each cid */
  7167. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7168. QM_ILT_PAGE_SZ);
  7169. ilt_client->end = line - 1;
  7170. DP(NETIF_MSG_IFUP,
  7171. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7172. ilt_client->start,
  7173. ilt_client->end,
  7174. ilt_client->page_size,
  7175. ilt_client->flags,
  7176. ilog2(ilt_client->page_size >> 12));
  7177. }
  7178. if (CNIC_SUPPORT(bp)) {
  7179. /* SRC */
  7180. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7181. ilt_client->client_num = ILT_CLIENT_SRC;
  7182. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7183. ilt_client->flags = 0;
  7184. ilt_client->start = line;
  7185. line += SRC_ILT_LINES;
  7186. ilt_client->end = line - 1;
  7187. DP(NETIF_MSG_IFUP,
  7188. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7189. ilt_client->start,
  7190. ilt_client->end,
  7191. ilt_client->page_size,
  7192. ilt_client->flags,
  7193. ilog2(ilt_client->page_size >> 12));
  7194. /* TM */
  7195. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7196. ilt_client->client_num = ILT_CLIENT_TM;
  7197. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7198. ilt_client->flags = 0;
  7199. ilt_client->start = line;
  7200. line += TM_ILT_LINES;
  7201. ilt_client->end = line - 1;
  7202. DP(NETIF_MSG_IFUP,
  7203. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7204. ilt_client->start,
  7205. ilt_client->end,
  7206. ilt_client->page_size,
  7207. ilt_client->flags,
  7208. ilog2(ilt_client->page_size >> 12));
  7209. }
  7210. BUG_ON(line > ILT_MAX_LINES);
  7211. }
  7212. /**
  7213. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7214. *
  7215. * @bp: driver handle
  7216. * @fp: pointer to fastpath
  7217. * @init_params: pointer to parameters structure
  7218. *
  7219. * parameters configured:
  7220. * - HC configuration
  7221. * - Queue's CDU context
  7222. */
  7223. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7224. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7225. {
  7226. u8 cos;
  7227. int cxt_index, cxt_offset;
  7228. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7229. if (!IS_FCOE_FP(fp)) {
  7230. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7231. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7232. /* If HC is supported, enable host coalescing in the transition
  7233. * to INIT state.
  7234. */
  7235. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7236. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7237. /* HC rate */
  7238. init_params->rx.hc_rate = bp->rx_ticks ?
  7239. (1000000 / bp->rx_ticks) : 0;
  7240. init_params->tx.hc_rate = bp->tx_ticks ?
  7241. (1000000 / bp->tx_ticks) : 0;
  7242. /* FW SB ID */
  7243. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7244. fp->fw_sb_id;
  7245. /*
  7246. * CQ index among the SB indices: FCoE clients uses the default
  7247. * SB, therefore it's different.
  7248. */
  7249. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7250. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7251. }
  7252. /* set maximum number of COSs supported by this queue */
  7253. init_params->max_cos = fp->max_cos;
  7254. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7255. fp->index, init_params->max_cos);
  7256. /* set the context pointers queue object */
  7257. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7258. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7259. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7260. ILT_PAGE_CIDS);
  7261. init_params->cxts[cos] =
  7262. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7263. }
  7264. }
  7265. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7266. struct bnx2x_queue_state_params *q_params,
  7267. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7268. int tx_index, bool leading)
  7269. {
  7270. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7271. /* Set the command */
  7272. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7273. /* Set tx-only QUEUE flags: don't zero statistics */
  7274. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7275. /* choose the index of the cid to send the slow path on */
  7276. tx_only_params->cid_index = tx_index;
  7277. /* Set general TX_ONLY_SETUP parameters */
  7278. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7279. /* Set Tx TX_ONLY_SETUP parameters */
  7280. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7281. DP(NETIF_MSG_IFUP,
  7282. "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",
  7283. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7284. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7285. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7286. /* send the ramrod */
  7287. return bnx2x_queue_state_change(bp, q_params);
  7288. }
  7289. /**
  7290. * bnx2x_setup_queue - setup queue
  7291. *
  7292. * @bp: driver handle
  7293. * @fp: pointer to fastpath
  7294. * @leading: is leading
  7295. *
  7296. * This function performs 2 steps in a Queue state machine
  7297. * actually: 1) RESET->INIT 2) INIT->SETUP
  7298. */
  7299. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7300. bool leading)
  7301. {
  7302. struct bnx2x_queue_state_params q_params = {NULL};
  7303. struct bnx2x_queue_setup_params *setup_params =
  7304. &q_params.params.setup;
  7305. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7306. &q_params.params.tx_only;
  7307. int rc;
  7308. u8 tx_index;
  7309. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7310. /* reset IGU state skip FCoE L2 queue */
  7311. if (!IS_FCOE_FP(fp))
  7312. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7313. IGU_INT_ENABLE, 0);
  7314. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7315. /* We want to wait for completion in this context */
  7316. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7317. /* Prepare the INIT parameters */
  7318. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7319. /* Set the command */
  7320. q_params.cmd = BNX2X_Q_CMD_INIT;
  7321. /* Change the state to INIT */
  7322. rc = bnx2x_queue_state_change(bp, &q_params);
  7323. if (rc) {
  7324. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7325. return rc;
  7326. }
  7327. DP(NETIF_MSG_IFUP, "init complete\n");
  7328. /* Now move the Queue to the SETUP state... */
  7329. memset(setup_params, 0, sizeof(*setup_params));
  7330. /* Set QUEUE flags */
  7331. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7332. /* Set general SETUP parameters */
  7333. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7334. FIRST_TX_COS_INDEX);
  7335. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7336. &setup_params->rxq_params);
  7337. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7338. FIRST_TX_COS_INDEX);
  7339. /* Set the command */
  7340. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7341. if (IS_FCOE_FP(fp))
  7342. bp->fcoe_init = true;
  7343. /* Change the state to SETUP */
  7344. rc = bnx2x_queue_state_change(bp, &q_params);
  7345. if (rc) {
  7346. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7347. return rc;
  7348. }
  7349. /* loop through the relevant tx-only indices */
  7350. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7351. tx_index < fp->max_cos;
  7352. tx_index++) {
  7353. /* prepare and send tx-only ramrod*/
  7354. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7355. tx_only_params, tx_index, leading);
  7356. if (rc) {
  7357. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7358. fp->index, tx_index);
  7359. return rc;
  7360. }
  7361. }
  7362. return rc;
  7363. }
  7364. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7365. {
  7366. struct bnx2x_fastpath *fp = &bp->fp[index];
  7367. struct bnx2x_fp_txdata *txdata;
  7368. struct bnx2x_queue_state_params q_params = {NULL};
  7369. int rc, tx_index;
  7370. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7371. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7372. /* We want to wait for completion in this context */
  7373. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7374. /* close tx-only connections */
  7375. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7376. tx_index < fp->max_cos;
  7377. tx_index++){
  7378. /* ascertain this is a normal queue*/
  7379. txdata = fp->txdata_ptr[tx_index];
  7380. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7381. txdata->txq_index);
  7382. /* send halt terminate on tx-only connection */
  7383. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7384. memset(&q_params.params.terminate, 0,
  7385. sizeof(q_params.params.terminate));
  7386. q_params.params.terminate.cid_index = tx_index;
  7387. rc = bnx2x_queue_state_change(bp, &q_params);
  7388. if (rc)
  7389. return rc;
  7390. /* send halt terminate on tx-only connection */
  7391. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7392. memset(&q_params.params.cfc_del, 0,
  7393. sizeof(q_params.params.cfc_del));
  7394. q_params.params.cfc_del.cid_index = tx_index;
  7395. rc = bnx2x_queue_state_change(bp, &q_params);
  7396. if (rc)
  7397. return rc;
  7398. }
  7399. /* Stop the primary connection: */
  7400. /* ...halt the connection */
  7401. q_params.cmd = BNX2X_Q_CMD_HALT;
  7402. rc = bnx2x_queue_state_change(bp, &q_params);
  7403. if (rc)
  7404. return rc;
  7405. /* ...terminate the connection */
  7406. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7407. memset(&q_params.params.terminate, 0,
  7408. sizeof(q_params.params.terminate));
  7409. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7410. rc = bnx2x_queue_state_change(bp, &q_params);
  7411. if (rc)
  7412. return rc;
  7413. /* ...delete cfc entry */
  7414. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7415. memset(&q_params.params.cfc_del, 0,
  7416. sizeof(q_params.params.cfc_del));
  7417. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7418. return bnx2x_queue_state_change(bp, &q_params);
  7419. }
  7420. static void bnx2x_reset_func(struct bnx2x *bp)
  7421. {
  7422. int port = BP_PORT(bp);
  7423. int func = BP_FUNC(bp);
  7424. int i;
  7425. /* Disable the function in the FW */
  7426. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7427. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7428. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7429. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7430. /* FP SBs */
  7431. for_each_eth_queue(bp, i) {
  7432. struct bnx2x_fastpath *fp = &bp->fp[i];
  7433. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7434. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7435. SB_DISABLED);
  7436. }
  7437. if (CNIC_LOADED(bp))
  7438. /* CNIC SB */
  7439. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7440. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7441. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7442. /* SP SB */
  7443. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7444. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7445. SB_DISABLED);
  7446. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7447. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7448. 0);
  7449. /* Configure IGU */
  7450. if (bp->common.int_block == INT_BLOCK_HC) {
  7451. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7452. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7453. } else {
  7454. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7455. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7456. }
  7457. if (CNIC_LOADED(bp)) {
  7458. /* Disable Timer scan */
  7459. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7460. /*
  7461. * Wait for at least 10ms and up to 2 second for the timers
  7462. * scan to complete
  7463. */
  7464. for (i = 0; i < 200; i++) {
  7465. usleep_range(10000, 20000);
  7466. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7467. break;
  7468. }
  7469. }
  7470. /* Clear ILT */
  7471. bnx2x_clear_func_ilt(bp, func);
  7472. /* Timers workaround bug for E2: if this is vnic-3,
  7473. * we need to set the entire ilt range for this timers.
  7474. */
  7475. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7476. struct ilt_client_info ilt_cli;
  7477. /* use dummy TM client */
  7478. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7479. ilt_cli.start = 0;
  7480. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7481. ilt_cli.client_num = ILT_CLIENT_TM;
  7482. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7483. }
  7484. /* this assumes that reset_port() called before reset_func()*/
  7485. if (!CHIP_IS_E1x(bp))
  7486. bnx2x_pf_disable(bp);
  7487. bp->dmae_ready = 0;
  7488. }
  7489. static void bnx2x_reset_port(struct bnx2x *bp)
  7490. {
  7491. int port = BP_PORT(bp);
  7492. u32 val;
  7493. /* Reset physical Link */
  7494. bnx2x__link_reset(bp);
  7495. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7496. /* Do not rcv packets to BRB */
  7497. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7498. /* Do not direct rcv packets that are not for MCP to the BRB */
  7499. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7500. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7501. /* Configure AEU */
  7502. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7503. msleep(100);
  7504. /* Check for BRB port occupancy */
  7505. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7506. if (val)
  7507. DP(NETIF_MSG_IFDOWN,
  7508. "BRB1 is not empty %d blocks are occupied\n", val);
  7509. /* TODO: Close Doorbell port? */
  7510. }
  7511. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7512. {
  7513. struct bnx2x_func_state_params func_params = {NULL};
  7514. /* Prepare parameters for function state transitions */
  7515. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7516. func_params.f_obj = &bp->func_obj;
  7517. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7518. func_params.params.hw_init.load_phase = load_code;
  7519. return bnx2x_func_state_change(bp, &func_params);
  7520. }
  7521. static int bnx2x_func_stop(struct bnx2x *bp)
  7522. {
  7523. struct bnx2x_func_state_params func_params = {NULL};
  7524. int rc;
  7525. /* Prepare parameters for function state transitions */
  7526. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7527. func_params.f_obj = &bp->func_obj;
  7528. func_params.cmd = BNX2X_F_CMD_STOP;
  7529. /*
  7530. * Try to stop the function the 'good way'. If fails (in case
  7531. * of a parity error during bnx2x_chip_cleanup()) and we are
  7532. * not in a debug mode, perform a state transaction in order to
  7533. * enable further HW_RESET transaction.
  7534. */
  7535. rc = bnx2x_func_state_change(bp, &func_params);
  7536. if (rc) {
  7537. #ifdef BNX2X_STOP_ON_ERROR
  7538. return rc;
  7539. #else
  7540. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7541. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7542. return bnx2x_func_state_change(bp, &func_params);
  7543. #endif
  7544. }
  7545. return 0;
  7546. }
  7547. /**
  7548. * bnx2x_send_unload_req - request unload mode from the MCP.
  7549. *
  7550. * @bp: driver handle
  7551. * @unload_mode: requested function's unload mode
  7552. *
  7553. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7554. */
  7555. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7556. {
  7557. u32 reset_code = 0;
  7558. int port = BP_PORT(bp);
  7559. /* Select the UNLOAD request mode */
  7560. if (unload_mode == UNLOAD_NORMAL)
  7561. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7562. else if (bp->flags & NO_WOL_FLAG)
  7563. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7564. else if (bp->wol) {
  7565. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7566. u8 *mac_addr = bp->dev->dev_addr;
  7567. struct pci_dev *pdev = bp->pdev;
  7568. u32 val;
  7569. u16 pmc;
  7570. /* The mac address is written to entries 1-4 to
  7571. * preserve entry 0 which is used by the PMF
  7572. */
  7573. u8 entry = (BP_VN(bp) + 1)*8;
  7574. val = (mac_addr[0] << 8) | mac_addr[1];
  7575. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7576. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7577. (mac_addr[4] << 8) | mac_addr[5];
  7578. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7579. /* Enable the PME and clear the status */
  7580. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7581. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7582. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7583. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7584. } else
  7585. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7586. /* Send the request to the MCP */
  7587. if (!BP_NOMCP(bp))
  7588. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7589. else {
  7590. int path = BP_PATH(bp);
  7591. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7592. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7593. bnx2x_load_count[path][2]);
  7594. bnx2x_load_count[path][0]--;
  7595. bnx2x_load_count[path][1 + port]--;
  7596. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7597. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7598. bnx2x_load_count[path][2]);
  7599. if (bnx2x_load_count[path][0] == 0)
  7600. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7601. else if (bnx2x_load_count[path][1 + port] == 0)
  7602. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7603. else
  7604. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7605. }
  7606. return reset_code;
  7607. }
  7608. /**
  7609. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7610. *
  7611. * @bp: driver handle
  7612. * @keep_link: true iff link should be kept up
  7613. */
  7614. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7615. {
  7616. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7617. /* Report UNLOAD_DONE to MCP */
  7618. if (!BP_NOMCP(bp))
  7619. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7620. }
  7621. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7622. {
  7623. int tout = 50;
  7624. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7625. if (!bp->port.pmf)
  7626. return 0;
  7627. /*
  7628. * (assumption: No Attention from MCP at this stage)
  7629. * PMF probably in the middle of TX disable/enable transaction
  7630. * 1. Sync IRS for default SB
  7631. * 2. Sync SP queue - this guarantees us that attention handling started
  7632. * 3. Wait, that TX disable/enable transaction completes
  7633. *
  7634. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7635. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7636. * received completion for the transaction the state is TX_STOPPED.
  7637. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7638. * transaction.
  7639. */
  7640. /* make sure default SB ISR is done */
  7641. if (msix)
  7642. synchronize_irq(bp->msix_table[0].vector);
  7643. else
  7644. synchronize_irq(bp->pdev->irq);
  7645. flush_workqueue(bnx2x_wq);
  7646. flush_workqueue(bnx2x_iov_wq);
  7647. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7648. BNX2X_F_STATE_STARTED && tout--)
  7649. msleep(20);
  7650. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7651. BNX2X_F_STATE_STARTED) {
  7652. #ifdef BNX2X_STOP_ON_ERROR
  7653. BNX2X_ERR("Wrong function state\n");
  7654. return -EBUSY;
  7655. #else
  7656. /*
  7657. * Failed to complete the transaction in a "good way"
  7658. * Force both transactions with CLR bit
  7659. */
  7660. struct bnx2x_func_state_params func_params = {NULL};
  7661. DP(NETIF_MSG_IFDOWN,
  7662. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7663. func_params.f_obj = &bp->func_obj;
  7664. __set_bit(RAMROD_DRV_CLR_ONLY,
  7665. &func_params.ramrod_flags);
  7666. /* STARTED-->TX_ST0PPED */
  7667. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7668. bnx2x_func_state_change(bp, &func_params);
  7669. /* TX_ST0PPED-->STARTED */
  7670. func_params.cmd = BNX2X_F_CMD_TX_START;
  7671. return bnx2x_func_state_change(bp, &func_params);
  7672. #endif
  7673. }
  7674. return 0;
  7675. }
  7676. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7677. {
  7678. int port = BP_PORT(bp);
  7679. /* Disable sending PTP packets to host */
  7680. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7681. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7682. /* Reset PTP event detection rules */
  7683. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7684. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7685. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7686. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7687. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7688. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7689. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7690. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7691. /* Disable the PTP feature */
  7692. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7693. NIG_REG_P0_PTP_EN, 0x0);
  7694. }
  7695. /* Called during unload, to stop PTP-related stuff */
  7696. static void bnx2x_stop_ptp(struct bnx2x *bp)
  7697. {
  7698. /* Cancel PTP work queue. Should be done after the Tx queues are
  7699. * drained to prevent additional scheduling.
  7700. */
  7701. cancel_work_sync(&bp->ptp_task);
  7702. if (bp->ptp_tx_skb) {
  7703. dev_kfree_skb_any(bp->ptp_tx_skb);
  7704. bp->ptp_tx_skb = NULL;
  7705. }
  7706. /* Disable PTP in HW */
  7707. bnx2x_disable_ptp(bp);
  7708. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7709. }
  7710. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7711. {
  7712. int port = BP_PORT(bp);
  7713. int i, rc = 0;
  7714. u8 cos;
  7715. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7716. u32 reset_code;
  7717. /* Wait until tx fastpath tasks complete */
  7718. for_each_tx_queue(bp, i) {
  7719. struct bnx2x_fastpath *fp = &bp->fp[i];
  7720. for_each_cos_in_tx_queue(fp, cos)
  7721. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7722. #ifdef BNX2X_STOP_ON_ERROR
  7723. if (rc)
  7724. return;
  7725. #endif
  7726. }
  7727. /* Give HW time to discard old tx messages */
  7728. usleep_range(1000, 2000);
  7729. /* Clean all ETH MACs */
  7730. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7731. false);
  7732. if (rc < 0)
  7733. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7734. /* Clean up UC list */
  7735. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7736. true);
  7737. if (rc < 0)
  7738. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7739. rc);
  7740. /* Disable LLH */
  7741. if (!CHIP_IS_E1(bp))
  7742. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7743. /* Set "drop all" (stop Rx).
  7744. * We need to take a netif_addr_lock() here in order to prevent
  7745. * a race between the completion code and this code.
  7746. */
  7747. netif_addr_lock_bh(bp->dev);
  7748. /* Schedule the rx_mode command */
  7749. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7750. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7751. else
  7752. bnx2x_set_storm_rx_mode(bp);
  7753. /* Cleanup multicast configuration */
  7754. rparam.mcast_obj = &bp->mcast_obj;
  7755. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7756. if (rc < 0)
  7757. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7758. netif_addr_unlock_bh(bp->dev);
  7759. bnx2x_iov_chip_cleanup(bp);
  7760. /*
  7761. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7762. * this function should perform FUNC, PORT or COMMON HW
  7763. * reset.
  7764. */
  7765. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7766. /*
  7767. * (assumption: No Attention from MCP at this stage)
  7768. * PMF probably in the middle of TX disable/enable transaction
  7769. */
  7770. rc = bnx2x_func_wait_started(bp);
  7771. if (rc) {
  7772. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7773. #ifdef BNX2X_STOP_ON_ERROR
  7774. return;
  7775. #endif
  7776. }
  7777. /* Close multi and leading connections
  7778. * Completions for ramrods are collected in a synchronous way
  7779. */
  7780. for_each_eth_queue(bp, i)
  7781. if (bnx2x_stop_queue(bp, i))
  7782. #ifdef BNX2X_STOP_ON_ERROR
  7783. return;
  7784. #else
  7785. goto unload_error;
  7786. #endif
  7787. if (CNIC_LOADED(bp)) {
  7788. for_each_cnic_queue(bp, i)
  7789. if (bnx2x_stop_queue(bp, i))
  7790. #ifdef BNX2X_STOP_ON_ERROR
  7791. return;
  7792. #else
  7793. goto unload_error;
  7794. #endif
  7795. }
  7796. /* If SP settings didn't get completed so far - something
  7797. * very wrong has happen.
  7798. */
  7799. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7800. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7801. #ifndef BNX2X_STOP_ON_ERROR
  7802. unload_error:
  7803. #endif
  7804. rc = bnx2x_func_stop(bp);
  7805. if (rc) {
  7806. BNX2X_ERR("Function stop failed!\n");
  7807. #ifdef BNX2X_STOP_ON_ERROR
  7808. return;
  7809. #endif
  7810. }
  7811. /* stop_ptp should be after the Tx queues are drained to prevent
  7812. * scheduling to the cancelled PTP work queue. It should also be after
  7813. * function stop ramrod is sent, since as part of this ramrod FW access
  7814. * PTP registers.
  7815. */
  7816. bnx2x_stop_ptp(bp);
  7817. /* Disable HW interrupts, NAPI */
  7818. bnx2x_netif_stop(bp, 1);
  7819. /* Delete all NAPI objects */
  7820. bnx2x_del_all_napi(bp);
  7821. if (CNIC_LOADED(bp))
  7822. bnx2x_del_all_napi_cnic(bp);
  7823. /* Release IRQs */
  7824. bnx2x_free_irq(bp);
  7825. /* Reset the chip */
  7826. rc = bnx2x_reset_hw(bp, reset_code);
  7827. if (rc)
  7828. BNX2X_ERR("HW_RESET failed\n");
  7829. /* Report UNLOAD_DONE to MCP */
  7830. bnx2x_send_unload_done(bp, keep_link);
  7831. }
  7832. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7833. {
  7834. u32 val;
  7835. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7836. if (CHIP_IS_E1(bp)) {
  7837. int port = BP_PORT(bp);
  7838. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7839. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7840. val = REG_RD(bp, addr);
  7841. val &= ~(0x300);
  7842. REG_WR(bp, addr, val);
  7843. } else {
  7844. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7845. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7846. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7847. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7848. }
  7849. }
  7850. /* Close gates #2, #3 and #4: */
  7851. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7852. {
  7853. u32 val;
  7854. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7855. if (!CHIP_IS_E1(bp)) {
  7856. /* #4 */
  7857. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7858. /* #2 */
  7859. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7860. }
  7861. /* #3 */
  7862. if (CHIP_IS_E1x(bp)) {
  7863. /* Prevent interrupts from HC on both ports */
  7864. val = REG_RD(bp, HC_REG_CONFIG_1);
  7865. REG_WR(bp, HC_REG_CONFIG_1,
  7866. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7867. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7868. val = REG_RD(bp, HC_REG_CONFIG_0);
  7869. REG_WR(bp, HC_REG_CONFIG_0,
  7870. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7871. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7872. } else {
  7873. /* Prevent incoming interrupts in IGU */
  7874. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7875. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7876. (!close) ?
  7877. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7878. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7879. }
  7880. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7881. close ? "closing" : "opening");
  7882. mmiowb();
  7883. }
  7884. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7885. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7886. {
  7887. /* Do some magic... */
  7888. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7889. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7890. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7891. }
  7892. /**
  7893. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7894. *
  7895. * @bp: driver handle
  7896. * @magic_val: old value of the `magic' bit.
  7897. */
  7898. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7899. {
  7900. /* Restore the `magic' bit value... */
  7901. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7902. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7903. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7904. }
  7905. /**
  7906. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7907. *
  7908. * @bp: driver handle
  7909. * @magic_val: old value of 'magic' bit.
  7910. *
  7911. * Takes care of CLP configurations.
  7912. */
  7913. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7914. {
  7915. u32 shmem;
  7916. u32 validity_offset;
  7917. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7918. /* Set `magic' bit in order to save MF config */
  7919. if (!CHIP_IS_E1(bp))
  7920. bnx2x_clp_reset_prep(bp, magic_val);
  7921. /* Get shmem offset */
  7922. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7923. validity_offset =
  7924. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7925. /* Clear validity map flags */
  7926. if (shmem > 0)
  7927. REG_WR(bp, shmem + validity_offset, 0);
  7928. }
  7929. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7930. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7931. /**
  7932. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7933. *
  7934. * @bp: driver handle
  7935. */
  7936. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7937. {
  7938. /* special handling for emulation and FPGA,
  7939. wait 10 times longer */
  7940. if (CHIP_REV_IS_SLOW(bp))
  7941. msleep(MCP_ONE_TIMEOUT*10);
  7942. else
  7943. msleep(MCP_ONE_TIMEOUT);
  7944. }
  7945. /*
  7946. * initializes bp->common.shmem_base and waits for validity signature to appear
  7947. */
  7948. static int bnx2x_init_shmem(struct bnx2x *bp)
  7949. {
  7950. int cnt = 0;
  7951. u32 val = 0;
  7952. do {
  7953. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7954. if (bp->common.shmem_base) {
  7955. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7956. if (val & SHR_MEM_VALIDITY_MB)
  7957. return 0;
  7958. }
  7959. bnx2x_mcp_wait_one(bp);
  7960. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7961. BNX2X_ERR("BAD MCP validity signature\n");
  7962. return -ENODEV;
  7963. }
  7964. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7965. {
  7966. int rc = bnx2x_init_shmem(bp);
  7967. /* Restore the `magic' bit value */
  7968. if (!CHIP_IS_E1(bp))
  7969. bnx2x_clp_reset_done(bp, magic_val);
  7970. return rc;
  7971. }
  7972. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7973. {
  7974. if (!CHIP_IS_E1(bp)) {
  7975. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7976. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7977. mmiowb();
  7978. }
  7979. }
  7980. /*
  7981. * Reset the whole chip except for:
  7982. * - PCIE core
  7983. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7984. * one reset bit)
  7985. * - IGU
  7986. * - MISC (including AEU)
  7987. * - GRC
  7988. * - RBCN, RBCP
  7989. */
  7990. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7991. {
  7992. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7993. u32 global_bits2, stay_reset2;
  7994. /*
  7995. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7996. * (per chip) blocks.
  7997. */
  7998. global_bits2 =
  7999. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  8000. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  8001. /* Don't reset the following blocks.
  8002. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  8003. * reset, as in 4 port device they might still be owned
  8004. * by the MCP (there is only one leader per path).
  8005. */
  8006. not_reset_mask1 =
  8007. MISC_REGISTERS_RESET_REG_1_RST_HC |
  8008. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  8009. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  8010. not_reset_mask2 =
  8011. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8012. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8013. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8014. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8015. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8016. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8017. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8018. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8019. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8020. MISC_REGISTERS_RESET_REG_2_PGLC |
  8021. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8022. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8023. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8024. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8025. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8026. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8027. /*
  8028. * Keep the following blocks in reset:
  8029. * - all xxMACs are handled by the bnx2x_link code.
  8030. */
  8031. stay_reset2 =
  8032. MISC_REGISTERS_RESET_REG_2_XMAC |
  8033. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8034. /* Full reset masks according to the chip */
  8035. reset_mask1 = 0xffffffff;
  8036. if (CHIP_IS_E1(bp))
  8037. reset_mask2 = 0xffff;
  8038. else if (CHIP_IS_E1H(bp))
  8039. reset_mask2 = 0x1ffff;
  8040. else if (CHIP_IS_E2(bp))
  8041. reset_mask2 = 0xfffff;
  8042. else /* CHIP_IS_E3 */
  8043. reset_mask2 = 0x3ffffff;
  8044. /* Don't reset global blocks unless we need to */
  8045. if (!global)
  8046. reset_mask2 &= ~global_bits2;
  8047. /*
  8048. * In case of attention in the QM, we need to reset PXP
  8049. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8050. * because otherwise QM reset would release 'close the gates' shortly
  8051. * before resetting the PXP, then the PSWRQ would send a write
  8052. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8053. * read the payload data from PSWWR, but PSWWR would not
  8054. * respond. The write queue in PGLUE would stuck, dmae commands
  8055. * would not return. Therefore it's important to reset the second
  8056. * reset register (containing the
  8057. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8058. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8059. * bit).
  8060. */
  8061. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8062. reset_mask2 & (~not_reset_mask2));
  8063. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8064. reset_mask1 & (~not_reset_mask1));
  8065. barrier();
  8066. mmiowb();
  8067. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8068. reset_mask2 & (~stay_reset2));
  8069. barrier();
  8070. mmiowb();
  8071. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8072. mmiowb();
  8073. }
  8074. /**
  8075. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8076. * It should get cleared in no more than 1s.
  8077. *
  8078. * @bp: driver handle
  8079. *
  8080. * It should get cleared in no more than 1s. Returns 0 if
  8081. * pending writes bit gets cleared.
  8082. */
  8083. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8084. {
  8085. u32 cnt = 1000;
  8086. u32 pend_bits = 0;
  8087. do {
  8088. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8089. if (pend_bits == 0)
  8090. break;
  8091. usleep_range(1000, 2000);
  8092. } while (cnt-- > 0);
  8093. if (cnt <= 0) {
  8094. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8095. pend_bits);
  8096. return -EBUSY;
  8097. }
  8098. return 0;
  8099. }
  8100. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8101. {
  8102. int cnt = 1000;
  8103. u32 val = 0;
  8104. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8105. u32 tags_63_32 = 0;
  8106. /* Empty the Tetris buffer, wait for 1s */
  8107. do {
  8108. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8109. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8110. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8111. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8112. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8113. if (CHIP_IS_E3(bp))
  8114. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8115. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8116. ((port_is_idle_0 & 0x1) == 0x1) &&
  8117. ((port_is_idle_1 & 0x1) == 0x1) &&
  8118. (pgl_exp_rom2 == 0xffffffff) &&
  8119. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8120. break;
  8121. usleep_range(1000, 2000);
  8122. } while (cnt-- > 0);
  8123. if (cnt <= 0) {
  8124. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8125. 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",
  8126. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8127. pgl_exp_rom2);
  8128. return -EAGAIN;
  8129. }
  8130. barrier();
  8131. /* Close gates #2, #3 and #4 */
  8132. bnx2x_set_234_gates(bp, true);
  8133. /* Poll for IGU VQs for 57712 and newer chips */
  8134. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8135. return -EAGAIN;
  8136. /* TBD: Indicate that "process kill" is in progress to MCP */
  8137. /* Clear "unprepared" bit */
  8138. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8139. barrier();
  8140. /* Make sure all is written to the chip before the reset */
  8141. mmiowb();
  8142. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8143. * PSWHST, GRC and PSWRD Tetris buffer.
  8144. */
  8145. usleep_range(1000, 2000);
  8146. /* Prepare to chip reset: */
  8147. /* MCP */
  8148. if (global)
  8149. bnx2x_reset_mcp_prep(bp, &val);
  8150. /* PXP */
  8151. bnx2x_pxp_prep(bp);
  8152. barrier();
  8153. /* reset the chip */
  8154. bnx2x_process_kill_chip_reset(bp, global);
  8155. barrier();
  8156. /* clear errors in PGB */
  8157. if (!CHIP_IS_E1x(bp))
  8158. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8159. /* Recover after reset: */
  8160. /* MCP */
  8161. if (global && bnx2x_reset_mcp_comp(bp, val))
  8162. return -EAGAIN;
  8163. /* TBD: Add resetting the NO_MCP mode DB here */
  8164. /* Open the gates #2, #3 and #4 */
  8165. bnx2x_set_234_gates(bp, false);
  8166. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8167. * reset state, re-enable attentions. */
  8168. return 0;
  8169. }
  8170. static int bnx2x_leader_reset(struct bnx2x *bp)
  8171. {
  8172. int rc = 0;
  8173. bool global = bnx2x_reset_is_global(bp);
  8174. u32 load_code;
  8175. /* if not going to reset MCP - load "fake" driver to reset HW while
  8176. * driver is owner of the HW
  8177. */
  8178. if (!global && !BP_NOMCP(bp)) {
  8179. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8180. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8181. if (!load_code) {
  8182. BNX2X_ERR("MCP response failure, aborting\n");
  8183. rc = -EAGAIN;
  8184. goto exit_leader_reset;
  8185. }
  8186. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8187. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8188. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8189. rc = -EAGAIN;
  8190. goto exit_leader_reset2;
  8191. }
  8192. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8193. if (!load_code) {
  8194. BNX2X_ERR("MCP response failure, aborting\n");
  8195. rc = -EAGAIN;
  8196. goto exit_leader_reset2;
  8197. }
  8198. }
  8199. /* Try to recover after the failure */
  8200. if (bnx2x_process_kill(bp, global)) {
  8201. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8202. BP_PATH(bp));
  8203. rc = -EAGAIN;
  8204. goto exit_leader_reset2;
  8205. }
  8206. /*
  8207. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8208. * state.
  8209. */
  8210. bnx2x_set_reset_done(bp);
  8211. if (global)
  8212. bnx2x_clear_reset_global(bp);
  8213. exit_leader_reset2:
  8214. /* unload "fake driver" if it was loaded */
  8215. if (!global && !BP_NOMCP(bp)) {
  8216. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8217. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8218. }
  8219. exit_leader_reset:
  8220. bp->is_leader = 0;
  8221. bnx2x_release_leader_lock(bp);
  8222. smp_mb();
  8223. return rc;
  8224. }
  8225. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8226. {
  8227. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8228. /* Disconnect this device */
  8229. netif_device_detach(bp->dev);
  8230. /*
  8231. * Block ifup for all function on this engine until "process kill"
  8232. * or power cycle.
  8233. */
  8234. bnx2x_set_reset_in_progress(bp);
  8235. /* Shut down the power */
  8236. bnx2x_set_power_state(bp, PCI_D3hot);
  8237. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8238. smp_mb();
  8239. }
  8240. /*
  8241. * Assumption: runs under rtnl lock. This together with the fact
  8242. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8243. * will never be called when netif_running(bp->dev) is false.
  8244. */
  8245. static void bnx2x_parity_recover(struct bnx2x *bp)
  8246. {
  8247. bool global = false;
  8248. u32 error_recovered, error_unrecovered;
  8249. bool is_parity;
  8250. DP(NETIF_MSG_HW, "Handling parity\n");
  8251. while (1) {
  8252. switch (bp->recovery_state) {
  8253. case BNX2X_RECOVERY_INIT:
  8254. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8255. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8256. WARN_ON(!is_parity);
  8257. /* Try to get a LEADER_LOCK HW lock */
  8258. if (bnx2x_trylock_leader_lock(bp)) {
  8259. bnx2x_set_reset_in_progress(bp);
  8260. /*
  8261. * Check if there is a global attention and if
  8262. * there was a global attention, set the global
  8263. * reset bit.
  8264. */
  8265. if (global)
  8266. bnx2x_set_reset_global(bp);
  8267. bp->is_leader = 1;
  8268. }
  8269. /* Stop the driver */
  8270. /* If interface has been removed - break */
  8271. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8272. return;
  8273. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8274. /* Ensure "is_leader", MCP command sequence and
  8275. * "recovery_state" update values are seen on other
  8276. * CPUs.
  8277. */
  8278. smp_mb();
  8279. break;
  8280. case BNX2X_RECOVERY_WAIT:
  8281. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8282. if (bp->is_leader) {
  8283. int other_engine = BP_PATH(bp) ? 0 : 1;
  8284. bool other_load_status =
  8285. bnx2x_get_load_status(bp, other_engine);
  8286. bool load_status =
  8287. bnx2x_get_load_status(bp, BP_PATH(bp));
  8288. global = bnx2x_reset_is_global(bp);
  8289. /*
  8290. * In case of a parity in a global block, let
  8291. * the first leader that performs a
  8292. * leader_reset() reset the global blocks in
  8293. * order to clear global attentions. Otherwise
  8294. * the gates will remain closed for that
  8295. * engine.
  8296. */
  8297. if (load_status ||
  8298. (global && other_load_status)) {
  8299. /* Wait until all other functions get
  8300. * down.
  8301. */
  8302. schedule_delayed_work(&bp->sp_rtnl_task,
  8303. HZ/10);
  8304. return;
  8305. } else {
  8306. /* If all other functions got down -
  8307. * try to bring the chip back to
  8308. * normal. In any case it's an exit
  8309. * point for a leader.
  8310. */
  8311. if (bnx2x_leader_reset(bp)) {
  8312. bnx2x_recovery_failed(bp);
  8313. return;
  8314. }
  8315. /* If we are here, means that the
  8316. * leader has succeeded and doesn't
  8317. * want to be a leader any more. Try
  8318. * to continue as a none-leader.
  8319. */
  8320. break;
  8321. }
  8322. } else { /* non-leader */
  8323. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8324. /* Try to get a LEADER_LOCK HW lock as
  8325. * long as a former leader may have
  8326. * been unloaded by the user or
  8327. * released a leadership by another
  8328. * reason.
  8329. */
  8330. if (bnx2x_trylock_leader_lock(bp)) {
  8331. /* I'm a leader now! Restart a
  8332. * switch case.
  8333. */
  8334. bp->is_leader = 1;
  8335. break;
  8336. }
  8337. schedule_delayed_work(&bp->sp_rtnl_task,
  8338. HZ/10);
  8339. return;
  8340. } else {
  8341. /*
  8342. * If there was a global attention, wait
  8343. * for it to be cleared.
  8344. */
  8345. if (bnx2x_reset_is_global(bp)) {
  8346. schedule_delayed_work(
  8347. &bp->sp_rtnl_task,
  8348. HZ/10);
  8349. return;
  8350. }
  8351. error_recovered =
  8352. bp->eth_stats.recoverable_error;
  8353. error_unrecovered =
  8354. bp->eth_stats.unrecoverable_error;
  8355. bp->recovery_state =
  8356. BNX2X_RECOVERY_NIC_LOADING;
  8357. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8358. error_unrecovered++;
  8359. netdev_err(bp->dev,
  8360. "Recovery failed. Power cycle needed\n");
  8361. /* Disconnect this device */
  8362. netif_device_detach(bp->dev);
  8363. /* Shut down the power */
  8364. bnx2x_set_power_state(
  8365. bp, PCI_D3hot);
  8366. smp_mb();
  8367. } else {
  8368. bp->recovery_state =
  8369. BNX2X_RECOVERY_DONE;
  8370. error_recovered++;
  8371. smp_mb();
  8372. }
  8373. bp->eth_stats.recoverable_error =
  8374. error_recovered;
  8375. bp->eth_stats.unrecoverable_error =
  8376. error_unrecovered;
  8377. return;
  8378. }
  8379. }
  8380. default:
  8381. return;
  8382. }
  8383. }
  8384. }
  8385. static int bnx2x_close(struct net_device *dev);
  8386. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8387. * scheduled on a general queue in order to prevent a dead lock.
  8388. */
  8389. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8390. {
  8391. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8392. rtnl_lock();
  8393. if (!netif_running(bp->dev)) {
  8394. rtnl_unlock();
  8395. return;
  8396. }
  8397. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8398. #ifdef BNX2X_STOP_ON_ERROR
  8399. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8400. "you will need to reboot when done\n");
  8401. goto sp_rtnl_not_reset;
  8402. #endif
  8403. /*
  8404. * Clear all pending SP commands as we are going to reset the
  8405. * function anyway.
  8406. */
  8407. bp->sp_rtnl_state = 0;
  8408. smp_mb();
  8409. bnx2x_parity_recover(bp);
  8410. rtnl_unlock();
  8411. return;
  8412. }
  8413. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8414. #ifdef BNX2X_STOP_ON_ERROR
  8415. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8416. "you will need to reboot when done\n");
  8417. goto sp_rtnl_not_reset;
  8418. #endif
  8419. /*
  8420. * Clear all pending SP commands as we are going to reset the
  8421. * function anyway.
  8422. */
  8423. bp->sp_rtnl_state = 0;
  8424. smp_mb();
  8425. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8426. bnx2x_nic_load(bp, LOAD_NORMAL);
  8427. rtnl_unlock();
  8428. return;
  8429. }
  8430. #ifdef BNX2X_STOP_ON_ERROR
  8431. sp_rtnl_not_reset:
  8432. #endif
  8433. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8434. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8435. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8436. bnx2x_after_function_update(bp);
  8437. /*
  8438. * in case of fan failure we need to reset id if the "stop on error"
  8439. * debug flag is set, since we trying to prevent permanent overheating
  8440. * damage
  8441. */
  8442. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8443. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8444. netif_device_detach(bp->dev);
  8445. bnx2x_close(bp->dev);
  8446. rtnl_unlock();
  8447. return;
  8448. }
  8449. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8450. DP(BNX2X_MSG_SP,
  8451. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8452. bnx2x_vfpf_set_mcast(bp->dev);
  8453. }
  8454. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8455. &bp->sp_rtnl_state)){
  8456. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8457. bnx2x_tx_disable(bp);
  8458. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8459. }
  8460. }
  8461. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8462. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8463. bnx2x_set_rx_mode_inner(bp);
  8464. }
  8465. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8466. &bp->sp_rtnl_state))
  8467. bnx2x_pf_set_vfs_vlan(bp);
  8468. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8469. bnx2x_dcbx_stop_hw_tx(bp);
  8470. bnx2x_dcbx_resume_hw_tx(bp);
  8471. }
  8472. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8473. &bp->sp_rtnl_state))
  8474. bnx2x_update_mng_version(bp);
  8475. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8476. * can be called from other contexts as well)
  8477. */
  8478. rtnl_unlock();
  8479. /* enable SR-IOV if applicable */
  8480. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8481. &bp->sp_rtnl_state)) {
  8482. bnx2x_disable_sriov(bp);
  8483. bnx2x_enable_sriov(bp);
  8484. }
  8485. }
  8486. static void bnx2x_period_task(struct work_struct *work)
  8487. {
  8488. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8489. if (!netif_running(bp->dev))
  8490. goto period_task_exit;
  8491. if (CHIP_REV_IS_SLOW(bp)) {
  8492. BNX2X_ERR("period task called on emulation, ignoring\n");
  8493. goto period_task_exit;
  8494. }
  8495. bnx2x_acquire_phy_lock(bp);
  8496. /*
  8497. * The barrier is needed to ensure the ordering between the writing to
  8498. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8499. * the reading here.
  8500. */
  8501. smp_mb();
  8502. if (bp->port.pmf) {
  8503. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8504. /* Re-queue task in 1 sec */
  8505. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8506. }
  8507. bnx2x_release_phy_lock(bp);
  8508. period_task_exit:
  8509. return;
  8510. }
  8511. /*
  8512. * Init service functions
  8513. */
  8514. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8515. {
  8516. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8517. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8518. return base + (BP_ABS_FUNC(bp)) * stride;
  8519. }
  8520. static bool bnx2x_prev_unload_close_umac(struct bnx2x *bp,
  8521. u8 port, u32 reset_reg,
  8522. struct bnx2x_mac_vals *vals)
  8523. {
  8524. u32 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8525. u32 base_addr;
  8526. if (!(mask & reset_reg))
  8527. return false;
  8528. BNX2X_DEV_INFO("Disable umac Rx %02x\n", port);
  8529. base_addr = port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8530. vals->umac_addr[port] = base_addr + UMAC_REG_COMMAND_CONFIG;
  8531. vals->umac_val[port] = REG_RD(bp, vals->umac_addr[port]);
  8532. REG_WR(bp, vals->umac_addr[port], 0);
  8533. return true;
  8534. }
  8535. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8536. struct bnx2x_mac_vals *vals)
  8537. {
  8538. u32 val, base_addr, offset, mask, reset_reg;
  8539. bool mac_stopped = false;
  8540. u8 port = BP_PORT(bp);
  8541. /* reset addresses as they also mark which values were changed */
  8542. memset(vals, 0, sizeof(*vals));
  8543. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8544. if (!CHIP_IS_E3(bp)) {
  8545. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8546. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8547. if ((mask & reset_reg) && val) {
  8548. u32 wb_data[2];
  8549. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8550. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8551. : NIG_REG_INGRESS_BMAC0_MEM;
  8552. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8553. : BIGMAC_REGISTER_BMAC_CONTROL;
  8554. /*
  8555. * use rd/wr since we cannot use dmae. This is safe
  8556. * since MCP won't access the bus due to the request
  8557. * to unload, and no function on the path can be
  8558. * loaded at this time.
  8559. */
  8560. wb_data[0] = REG_RD(bp, base_addr + offset);
  8561. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8562. vals->bmac_addr = base_addr + offset;
  8563. vals->bmac_val[0] = wb_data[0];
  8564. vals->bmac_val[1] = wb_data[1];
  8565. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8566. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8567. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8568. }
  8569. BNX2X_DEV_INFO("Disable emac Rx\n");
  8570. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8571. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8572. REG_WR(bp, vals->emac_addr, 0);
  8573. mac_stopped = true;
  8574. } else {
  8575. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8576. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8577. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8578. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8579. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8580. val & ~(1 << 1));
  8581. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8582. val | (1 << 1));
  8583. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8584. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8585. REG_WR(bp, vals->xmac_addr, 0);
  8586. mac_stopped = true;
  8587. }
  8588. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 0,
  8589. reset_reg, vals);
  8590. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 1,
  8591. reset_reg, vals);
  8592. }
  8593. if (mac_stopped)
  8594. msleep(20);
  8595. }
  8596. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8597. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8598. 0x1848 + ((f) << 4))
  8599. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8600. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8601. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8602. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8603. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8604. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8605. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8606. {
  8607. /* UNDI marks its presence in DORQ -
  8608. * it initializes CID offset for normal bell to 0x7
  8609. */
  8610. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8611. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8612. return false;
  8613. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8614. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8615. return true;
  8616. }
  8617. return false;
  8618. }
  8619. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8620. {
  8621. u16 rcq, bd;
  8622. u32 addr, tmp_reg;
  8623. if (BP_FUNC(bp) < 2)
  8624. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8625. else
  8626. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8627. tmp_reg = REG_RD(bp, addr);
  8628. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8629. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8630. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8631. REG_WR(bp, addr, tmp_reg);
  8632. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8633. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8634. }
  8635. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8636. {
  8637. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8638. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8639. if (!rc) {
  8640. BNX2X_ERR("MCP response failure, aborting\n");
  8641. return -EBUSY;
  8642. }
  8643. return 0;
  8644. }
  8645. static struct bnx2x_prev_path_list *
  8646. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8647. {
  8648. struct bnx2x_prev_path_list *tmp_list;
  8649. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8650. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8651. bp->pdev->bus->number == tmp_list->bus &&
  8652. BP_PATH(bp) == tmp_list->path)
  8653. return tmp_list;
  8654. return NULL;
  8655. }
  8656. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8657. {
  8658. struct bnx2x_prev_path_list *tmp_list;
  8659. int rc;
  8660. rc = down_interruptible(&bnx2x_prev_sem);
  8661. if (rc) {
  8662. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8663. return rc;
  8664. }
  8665. tmp_list = bnx2x_prev_path_get_entry(bp);
  8666. if (tmp_list) {
  8667. tmp_list->aer = 1;
  8668. rc = 0;
  8669. } else {
  8670. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8671. BP_PATH(bp));
  8672. }
  8673. up(&bnx2x_prev_sem);
  8674. return rc;
  8675. }
  8676. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8677. {
  8678. struct bnx2x_prev_path_list *tmp_list;
  8679. bool rc = false;
  8680. if (down_trylock(&bnx2x_prev_sem))
  8681. return false;
  8682. tmp_list = bnx2x_prev_path_get_entry(bp);
  8683. if (tmp_list) {
  8684. if (tmp_list->aer) {
  8685. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8686. BP_PATH(bp));
  8687. } else {
  8688. rc = true;
  8689. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8690. BP_PATH(bp));
  8691. }
  8692. }
  8693. up(&bnx2x_prev_sem);
  8694. return rc;
  8695. }
  8696. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8697. {
  8698. struct bnx2x_prev_path_list *entry;
  8699. bool val;
  8700. down(&bnx2x_prev_sem);
  8701. entry = bnx2x_prev_path_get_entry(bp);
  8702. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8703. up(&bnx2x_prev_sem);
  8704. return val;
  8705. }
  8706. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8707. {
  8708. struct bnx2x_prev_path_list *tmp_list;
  8709. int rc;
  8710. rc = down_interruptible(&bnx2x_prev_sem);
  8711. if (rc) {
  8712. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8713. return rc;
  8714. }
  8715. /* Check whether the entry for this path already exists */
  8716. tmp_list = bnx2x_prev_path_get_entry(bp);
  8717. if (tmp_list) {
  8718. if (!tmp_list->aer) {
  8719. BNX2X_ERR("Re-Marking the path.\n");
  8720. } else {
  8721. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8722. BP_PATH(bp));
  8723. tmp_list->aer = 0;
  8724. }
  8725. up(&bnx2x_prev_sem);
  8726. return 0;
  8727. }
  8728. up(&bnx2x_prev_sem);
  8729. /* Create an entry for this path and add it */
  8730. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8731. if (!tmp_list) {
  8732. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8733. return -ENOMEM;
  8734. }
  8735. tmp_list->bus = bp->pdev->bus->number;
  8736. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8737. tmp_list->path = BP_PATH(bp);
  8738. tmp_list->aer = 0;
  8739. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8740. rc = down_interruptible(&bnx2x_prev_sem);
  8741. if (rc) {
  8742. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8743. kfree(tmp_list);
  8744. } else {
  8745. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8746. BP_PATH(bp));
  8747. list_add(&tmp_list->list, &bnx2x_prev_list);
  8748. up(&bnx2x_prev_sem);
  8749. }
  8750. return rc;
  8751. }
  8752. static int bnx2x_do_flr(struct bnx2x *bp)
  8753. {
  8754. struct pci_dev *dev = bp->pdev;
  8755. if (CHIP_IS_E1x(bp)) {
  8756. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8757. return -EINVAL;
  8758. }
  8759. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8760. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8761. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8762. bp->common.bc_ver);
  8763. return -EINVAL;
  8764. }
  8765. if (!pci_wait_for_pending_transaction(dev))
  8766. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8767. BNX2X_DEV_INFO("Initiating FLR\n");
  8768. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8769. return 0;
  8770. }
  8771. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8772. {
  8773. int rc;
  8774. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8775. /* Test if previous unload process was already finished for this path */
  8776. if (bnx2x_prev_is_path_marked(bp))
  8777. return bnx2x_prev_mcp_done(bp);
  8778. BNX2X_DEV_INFO("Path is unmarked\n");
  8779. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8780. if (bnx2x_prev_is_after_undi(bp))
  8781. goto out;
  8782. /* If function has FLR capabilities, and existing FW version matches
  8783. * the one required, then FLR will be sufficient to clean any residue
  8784. * left by previous driver
  8785. */
  8786. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8787. if (!rc) {
  8788. /* fw version is good */
  8789. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8790. rc = bnx2x_do_flr(bp);
  8791. }
  8792. if (!rc) {
  8793. /* FLR was performed */
  8794. BNX2X_DEV_INFO("FLR successful\n");
  8795. return 0;
  8796. }
  8797. BNX2X_DEV_INFO("Could not FLR\n");
  8798. out:
  8799. /* Close the MCP request, return failure*/
  8800. rc = bnx2x_prev_mcp_done(bp);
  8801. if (!rc)
  8802. rc = BNX2X_PREV_WAIT_NEEDED;
  8803. return rc;
  8804. }
  8805. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8806. {
  8807. u32 reset_reg, tmp_reg = 0, rc;
  8808. bool prev_undi = false;
  8809. struct bnx2x_mac_vals mac_vals;
  8810. /* It is possible a previous function received 'common' answer,
  8811. * but hasn't loaded yet, therefore creating a scenario of
  8812. * multiple functions receiving 'common' on the same path.
  8813. */
  8814. BNX2X_DEV_INFO("Common unload Flow\n");
  8815. memset(&mac_vals, 0, sizeof(mac_vals));
  8816. if (bnx2x_prev_is_path_marked(bp))
  8817. return bnx2x_prev_mcp_done(bp);
  8818. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8819. /* Reset should be performed after BRB is emptied */
  8820. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8821. u32 timer_count = 1000;
  8822. /* Close the MAC Rx to prevent BRB from filling up */
  8823. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8824. /* close LLH filters for both ports towards the BRB */
  8825. bnx2x_set_rx_filter(&bp->link_params, 0);
  8826. bp->link_params.port ^= 1;
  8827. bnx2x_set_rx_filter(&bp->link_params, 0);
  8828. bp->link_params.port ^= 1;
  8829. /* Check if the UNDI driver was previously loaded */
  8830. if (bnx2x_prev_is_after_undi(bp)) {
  8831. prev_undi = true;
  8832. /* clear the UNDI indication */
  8833. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8834. /* clear possible idle check errors */
  8835. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8836. }
  8837. if (!CHIP_IS_E1x(bp))
  8838. /* block FW from writing to host */
  8839. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8840. /* wait until BRB is empty */
  8841. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8842. while (timer_count) {
  8843. u32 prev_brb = tmp_reg;
  8844. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8845. if (!tmp_reg)
  8846. break;
  8847. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8848. /* reset timer as long as BRB actually gets emptied */
  8849. if (prev_brb > tmp_reg)
  8850. timer_count = 1000;
  8851. else
  8852. timer_count--;
  8853. /* If UNDI resides in memory, manually increment it */
  8854. if (prev_undi)
  8855. bnx2x_prev_unload_undi_inc(bp, 1);
  8856. udelay(10);
  8857. }
  8858. if (!timer_count)
  8859. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8860. }
  8861. /* No packets are in the pipeline, path is ready for reset */
  8862. bnx2x_reset_common(bp);
  8863. if (mac_vals.xmac_addr)
  8864. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8865. if (mac_vals.umac_addr[0])
  8866. REG_WR(bp, mac_vals.umac_addr[0], mac_vals.umac_val[0]);
  8867. if (mac_vals.umac_addr[1])
  8868. REG_WR(bp, mac_vals.umac_addr[1], mac_vals.umac_val[1]);
  8869. if (mac_vals.emac_addr)
  8870. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8871. if (mac_vals.bmac_addr) {
  8872. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8873. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8874. }
  8875. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8876. if (rc) {
  8877. bnx2x_prev_mcp_done(bp);
  8878. return rc;
  8879. }
  8880. return bnx2x_prev_mcp_done(bp);
  8881. }
  8882. static int bnx2x_prev_unload(struct bnx2x *bp)
  8883. {
  8884. int time_counter = 10;
  8885. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8886. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8887. /* clear hw from errors which may have resulted from an interrupted
  8888. * dmae transaction.
  8889. */
  8890. bnx2x_clean_pglue_errors(bp);
  8891. /* Release previously held locks */
  8892. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8893. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8894. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8895. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8896. if (hw_lock_val) {
  8897. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8898. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8899. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8900. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8901. }
  8902. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8903. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8904. } else
  8905. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8906. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8907. BNX2X_DEV_INFO("Release previously held alr\n");
  8908. bnx2x_release_alr(bp);
  8909. }
  8910. do {
  8911. int aer = 0;
  8912. /* Lock MCP using an unload request */
  8913. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8914. if (!fw) {
  8915. BNX2X_ERR("MCP response failure, aborting\n");
  8916. rc = -EBUSY;
  8917. break;
  8918. }
  8919. rc = down_interruptible(&bnx2x_prev_sem);
  8920. if (rc) {
  8921. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8922. rc);
  8923. } else {
  8924. /* If Path is marked by EEH, ignore unload status */
  8925. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8926. bnx2x_prev_path_get_entry(bp)->aer);
  8927. up(&bnx2x_prev_sem);
  8928. }
  8929. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8930. rc = bnx2x_prev_unload_common(bp);
  8931. break;
  8932. }
  8933. /* non-common reply from MCP might require looping */
  8934. rc = bnx2x_prev_unload_uncommon(bp);
  8935. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8936. break;
  8937. msleep(20);
  8938. } while (--time_counter);
  8939. if (!time_counter || rc) {
  8940. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8941. rc = -EPROBE_DEFER;
  8942. }
  8943. /* Mark function if its port was used to boot from SAN */
  8944. if (bnx2x_port_after_undi(bp))
  8945. bp->link_params.feature_config_flags |=
  8946. FEATURE_CONFIG_BOOT_FROM_SAN;
  8947. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8948. return rc;
  8949. }
  8950. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8951. {
  8952. u32 val, val2, val3, val4, id, boot_mode;
  8953. u16 pmc;
  8954. /* Get the chip revision id and number. */
  8955. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8956. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8957. id = ((val & 0xffff) << 16);
  8958. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8959. id |= ((val & 0xf) << 12);
  8960. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8961. * the configuration space (so we need to reg_rd)
  8962. */
  8963. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8964. id |= (((val >> 24) & 0xf) << 4);
  8965. val = REG_RD(bp, MISC_REG_BOND_ID);
  8966. id |= (val & 0xf);
  8967. bp->common.chip_id = id;
  8968. /* force 57811 according to MISC register */
  8969. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8970. if (CHIP_IS_57810(bp))
  8971. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8972. (bp->common.chip_id & 0x0000FFFF);
  8973. else if (CHIP_IS_57810_MF(bp))
  8974. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8975. (bp->common.chip_id & 0x0000FFFF);
  8976. bp->common.chip_id |= 0x1;
  8977. }
  8978. /* Set doorbell size */
  8979. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8980. if (!CHIP_IS_E1x(bp)) {
  8981. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8982. if ((val & 1) == 0)
  8983. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8984. else
  8985. val = (val >> 1) & 1;
  8986. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8987. "2_PORT_MODE");
  8988. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8989. CHIP_2_PORT_MODE;
  8990. if (CHIP_MODE_IS_4_PORT(bp))
  8991. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8992. else
  8993. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8994. } else {
  8995. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8996. bp->pfid = bp->pf_num; /* 0..7 */
  8997. }
  8998. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8999. bp->link_params.chip_id = bp->common.chip_id;
  9000. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  9001. val = (REG_RD(bp, 0x2874) & 0x55);
  9002. if ((bp->common.chip_id & 0x1) ||
  9003. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  9004. bp->flags |= ONE_PORT_FLAG;
  9005. BNX2X_DEV_INFO("single port device\n");
  9006. }
  9007. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9008. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9009. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9010. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9011. bp->common.flash_size, bp->common.flash_size);
  9012. bnx2x_init_shmem(bp);
  9013. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9014. MISC_REG_GENERIC_CR_1 :
  9015. MISC_REG_GENERIC_CR_0));
  9016. bp->link_params.shmem_base = bp->common.shmem_base;
  9017. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9018. if (SHMEM2_RD(bp, size) >
  9019. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9020. bp->link_params.lfa_base =
  9021. REG_RD(bp, bp->common.shmem2_base +
  9022. (u32)offsetof(struct shmem2_region,
  9023. lfa_host_addr[BP_PORT(bp)]));
  9024. else
  9025. bp->link_params.lfa_base = 0;
  9026. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9027. bp->common.shmem_base, bp->common.shmem2_base);
  9028. if (!bp->common.shmem_base) {
  9029. BNX2X_DEV_INFO("MCP not active\n");
  9030. bp->flags |= NO_MCP_FLAG;
  9031. return;
  9032. }
  9033. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9034. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9035. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9036. SHARED_HW_CFG_LED_MODE_MASK) >>
  9037. SHARED_HW_CFG_LED_MODE_SHIFT);
  9038. bp->link_params.feature_config_flags = 0;
  9039. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9040. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9041. bp->link_params.feature_config_flags |=
  9042. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9043. else
  9044. bp->link_params.feature_config_flags &=
  9045. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9046. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9047. bp->common.bc_ver = val;
  9048. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9049. if (val < BNX2X_BC_VER) {
  9050. /* for now only warn
  9051. * later we might need to enforce this */
  9052. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9053. BNX2X_BC_VER, val);
  9054. }
  9055. bp->link_params.feature_config_flags |=
  9056. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9057. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9058. bp->link_params.feature_config_flags |=
  9059. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9060. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9061. bp->link_params.feature_config_flags |=
  9062. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9063. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9064. bp->link_params.feature_config_flags |=
  9065. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9066. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9067. bp->link_params.feature_config_flags |=
  9068. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9069. FEATURE_CONFIG_MT_SUPPORT : 0;
  9070. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9071. BC_SUPPORTS_PFC_STATS : 0;
  9072. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9073. BC_SUPPORTS_FCOE_FEATURES : 0;
  9074. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9075. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9076. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9077. BC_SUPPORTS_RMMOD_CMD : 0;
  9078. boot_mode = SHMEM_RD(bp,
  9079. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9080. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9081. switch (boot_mode) {
  9082. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9083. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9084. break;
  9085. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9086. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9087. break;
  9088. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9089. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9090. break;
  9091. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9092. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9093. break;
  9094. }
  9095. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9096. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9097. BNX2X_DEV_INFO("%sWoL capable\n",
  9098. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9099. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9100. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9101. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9102. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9103. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9104. val, val2, val3, val4);
  9105. }
  9106. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9107. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9108. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9109. {
  9110. int pfid = BP_FUNC(bp);
  9111. int igu_sb_id;
  9112. u32 val;
  9113. u8 fid, igu_sb_cnt = 0;
  9114. bp->igu_base_sb = 0xff;
  9115. if (CHIP_INT_MODE_IS_BC(bp)) {
  9116. int vn = BP_VN(bp);
  9117. igu_sb_cnt = bp->igu_sb_cnt;
  9118. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9119. FP_SB_MAX_E1x;
  9120. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9121. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9122. return 0;
  9123. }
  9124. /* IGU in normal mode - read CAM */
  9125. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9126. igu_sb_id++) {
  9127. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9128. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9129. continue;
  9130. fid = IGU_FID(val);
  9131. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9132. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9133. continue;
  9134. if (IGU_VEC(val) == 0)
  9135. /* default status block */
  9136. bp->igu_dsb_id = igu_sb_id;
  9137. else {
  9138. if (bp->igu_base_sb == 0xff)
  9139. bp->igu_base_sb = igu_sb_id;
  9140. igu_sb_cnt++;
  9141. }
  9142. }
  9143. }
  9144. #ifdef CONFIG_PCI_MSI
  9145. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9146. * optional that number of CAM entries will not be equal to the value
  9147. * advertised in PCI.
  9148. * Driver should use the minimal value of both as the actual status
  9149. * block count
  9150. */
  9151. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9152. #endif
  9153. if (igu_sb_cnt == 0) {
  9154. BNX2X_ERR("CAM configuration error\n");
  9155. return -EINVAL;
  9156. }
  9157. return 0;
  9158. }
  9159. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9160. {
  9161. int cfg_size = 0, idx, port = BP_PORT(bp);
  9162. /* Aggregation of supported attributes of all external phys */
  9163. bp->port.supported[0] = 0;
  9164. bp->port.supported[1] = 0;
  9165. switch (bp->link_params.num_phys) {
  9166. case 1:
  9167. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9168. cfg_size = 1;
  9169. break;
  9170. case 2:
  9171. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9172. cfg_size = 1;
  9173. break;
  9174. case 3:
  9175. if (bp->link_params.multi_phy_config &
  9176. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9177. bp->port.supported[1] =
  9178. bp->link_params.phy[EXT_PHY1].supported;
  9179. bp->port.supported[0] =
  9180. bp->link_params.phy[EXT_PHY2].supported;
  9181. } else {
  9182. bp->port.supported[0] =
  9183. bp->link_params.phy[EXT_PHY1].supported;
  9184. bp->port.supported[1] =
  9185. bp->link_params.phy[EXT_PHY2].supported;
  9186. }
  9187. cfg_size = 2;
  9188. break;
  9189. }
  9190. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9191. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9192. SHMEM_RD(bp,
  9193. dev_info.port_hw_config[port].external_phy_config),
  9194. SHMEM_RD(bp,
  9195. dev_info.port_hw_config[port].external_phy_config2));
  9196. return;
  9197. }
  9198. if (CHIP_IS_E3(bp))
  9199. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9200. else {
  9201. switch (switch_cfg) {
  9202. case SWITCH_CFG_1G:
  9203. bp->port.phy_addr = REG_RD(
  9204. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9205. break;
  9206. case SWITCH_CFG_10G:
  9207. bp->port.phy_addr = REG_RD(
  9208. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9209. break;
  9210. default:
  9211. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9212. bp->port.link_config[0]);
  9213. return;
  9214. }
  9215. }
  9216. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9217. /* mask what we support according to speed_cap_mask per configuration */
  9218. for (idx = 0; idx < cfg_size; idx++) {
  9219. if (!(bp->link_params.speed_cap_mask[idx] &
  9220. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9221. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9222. if (!(bp->link_params.speed_cap_mask[idx] &
  9223. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9224. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9225. if (!(bp->link_params.speed_cap_mask[idx] &
  9226. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9227. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9228. if (!(bp->link_params.speed_cap_mask[idx] &
  9229. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9230. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9231. if (!(bp->link_params.speed_cap_mask[idx] &
  9232. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9233. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9234. SUPPORTED_1000baseT_Full);
  9235. if (!(bp->link_params.speed_cap_mask[idx] &
  9236. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9237. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9238. if (!(bp->link_params.speed_cap_mask[idx] &
  9239. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9240. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9241. if (!(bp->link_params.speed_cap_mask[idx] &
  9242. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9243. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9244. }
  9245. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9246. bp->port.supported[1]);
  9247. }
  9248. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9249. {
  9250. u32 link_config, idx, cfg_size = 0;
  9251. bp->port.advertising[0] = 0;
  9252. bp->port.advertising[1] = 0;
  9253. switch (bp->link_params.num_phys) {
  9254. case 1:
  9255. case 2:
  9256. cfg_size = 1;
  9257. break;
  9258. case 3:
  9259. cfg_size = 2;
  9260. break;
  9261. }
  9262. for (idx = 0; idx < cfg_size; idx++) {
  9263. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9264. link_config = bp->port.link_config[idx];
  9265. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9266. case PORT_FEATURE_LINK_SPEED_AUTO:
  9267. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9268. bp->link_params.req_line_speed[idx] =
  9269. SPEED_AUTO_NEG;
  9270. bp->port.advertising[idx] |=
  9271. bp->port.supported[idx];
  9272. if (bp->link_params.phy[EXT_PHY1].type ==
  9273. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9274. bp->port.advertising[idx] |=
  9275. (SUPPORTED_100baseT_Half |
  9276. SUPPORTED_100baseT_Full);
  9277. } else {
  9278. /* force 10G, no AN */
  9279. bp->link_params.req_line_speed[idx] =
  9280. SPEED_10000;
  9281. bp->port.advertising[idx] |=
  9282. (ADVERTISED_10000baseT_Full |
  9283. ADVERTISED_FIBRE);
  9284. continue;
  9285. }
  9286. break;
  9287. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9288. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9289. bp->link_params.req_line_speed[idx] =
  9290. SPEED_10;
  9291. bp->port.advertising[idx] |=
  9292. (ADVERTISED_10baseT_Full |
  9293. ADVERTISED_TP);
  9294. } else {
  9295. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9296. link_config,
  9297. bp->link_params.speed_cap_mask[idx]);
  9298. return;
  9299. }
  9300. break;
  9301. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9302. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9303. bp->link_params.req_line_speed[idx] =
  9304. SPEED_10;
  9305. bp->link_params.req_duplex[idx] =
  9306. DUPLEX_HALF;
  9307. bp->port.advertising[idx] |=
  9308. (ADVERTISED_10baseT_Half |
  9309. ADVERTISED_TP);
  9310. } else {
  9311. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9312. link_config,
  9313. bp->link_params.speed_cap_mask[idx]);
  9314. return;
  9315. }
  9316. break;
  9317. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9318. if (bp->port.supported[idx] &
  9319. SUPPORTED_100baseT_Full) {
  9320. bp->link_params.req_line_speed[idx] =
  9321. SPEED_100;
  9322. bp->port.advertising[idx] |=
  9323. (ADVERTISED_100baseT_Full |
  9324. ADVERTISED_TP);
  9325. } else {
  9326. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9327. link_config,
  9328. bp->link_params.speed_cap_mask[idx]);
  9329. return;
  9330. }
  9331. break;
  9332. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9333. if (bp->port.supported[idx] &
  9334. SUPPORTED_100baseT_Half) {
  9335. bp->link_params.req_line_speed[idx] =
  9336. SPEED_100;
  9337. bp->link_params.req_duplex[idx] =
  9338. DUPLEX_HALF;
  9339. bp->port.advertising[idx] |=
  9340. (ADVERTISED_100baseT_Half |
  9341. ADVERTISED_TP);
  9342. } else {
  9343. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9344. link_config,
  9345. bp->link_params.speed_cap_mask[idx]);
  9346. return;
  9347. }
  9348. break;
  9349. case PORT_FEATURE_LINK_SPEED_1G:
  9350. if (bp->port.supported[idx] &
  9351. SUPPORTED_1000baseT_Full) {
  9352. bp->link_params.req_line_speed[idx] =
  9353. SPEED_1000;
  9354. bp->port.advertising[idx] |=
  9355. (ADVERTISED_1000baseT_Full |
  9356. ADVERTISED_TP);
  9357. } else {
  9358. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9359. link_config,
  9360. bp->link_params.speed_cap_mask[idx]);
  9361. return;
  9362. }
  9363. break;
  9364. case PORT_FEATURE_LINK_SPEED_2_5G:
  9365. if (bp->port.supported[idx] &
  9366. SUPPORTED_2500baseX_Full) {
  9367. bp->link_params.req_line_speed[idx] =
  9368. SPEED_2500;
  9369. bp->port.advertising[idx] |=
  9370. (ADVERTISED_2500baseX_Full |
  9371. ADVERTISED_TP);
  9372. } else {
  9373. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9374. link_config,
  9375. bp->link_params.speed_cap_mask[idx]);
  9376. return;
  9377. }
  9378. break;
  9379. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9380. if (bp->port.supported[idx] &
  9381. SUPPORTED_10000baseT_Full) {
  9382. bp->link_params.req_line_speed[idx] =
  9383. SPEED_10000;
  9384. bp->port.advertising[idx] |=
  9385. (ADVERTISED_10000baseT_Full |
  9386. ADVERTISED_FIBRE);
  9387. } else {
  9388. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9389. link_config,
  9390. bp->link_params.speed_cap_mask[idx]);
  9391. return;
  9392. }
  9393. break;
  9394. case PORT_FEATURE_LINK_SPEED_20G:
  9395. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9396. break;
  9397. default:
  9398. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9399. link_config);
  9400. bp->link_params.req_line_speed[idx] =
  9401. SPEED_AUTO_NEG;
  9402. bp->port.advertising[idx] =
  9403. bp->port.supported[idx];
  9404. break;
  9405. }
  9406. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9407. PORT_FEATURE_FLOW_CONTROL_MASK);
  9408. if (bp->link_params.req_flow_ctrl[idx] ==
  9409. BNX2X_FLOW_CTRL_AUTO) {
  9410. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9411. bp->link_params.req_flow_ctrl[idx] =
  9412. BNX2X_FLOW_CTRL_NONE;
  9413. else
  9414. bnx2x_set_requested_fc(bp);
  9415. }
  9416. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9417. bp->link_params.req_line_speed[idx],
  9418. bp->link_params.req_duplex[idx],
  9419. bp->link_params.req_flow_ctrl[idx],
  9420. bp->port.advertising[idx]);
  9421. }
  9422. }
  9423. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9424. {
  9425. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9426. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9427. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9428. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9429. }
  9430. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9431. {
  9432. int port = BP_PORT(bp);
  9433. u32 config;
  9434. u32 ext_phy_type, ext_phy_config, eee_mode;
  9435. bp->link_params.bp = bp;
  9436. bp->link_params.port = port;
  9437. bp->link_params.lane_config =
  9438. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9439. bp->link_params.speed_cap_mask[0] =
  9440. SHMEM_RD(bp,
  9441. dev_info.port_hw_config[port].speed_capability_mask) &
  9442. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9443. bp->link_params.speed_cap_mask[1] =
  9444. SHMEM_RD(bp,
  9445. dev_info.port_hw_config[port].speed_capability_mask2) &
  9446. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9447. bp->port.link_config[0] =
  9448. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9449. bp->port.link_config[1] =
  9450. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9451. bp->link_params.multi_phy_config =
  9452. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9453. /* If the device is capable of WoL, set the default state according
  9454. * to the HW
  9455. */
  9456. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9457. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9458. (config & PORT_FEATURE_WOL_ENABLED));
  9459. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9460. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9461. bp->flags |= NO_ISCSI_FLAG;
  9462. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9463. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9464. bp->flags |= NO_FCOE_FLAG;
  9465. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9466. bp->link_params.lane_config,
  9467. bp->link_params.speed_cap_mask[0],
  9468. bp->port.link_config[0]);
  9469. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9470. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9471. bnx2x_phy_probe(&bp->link_params);
  9472. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9473. bnx2x_link_settings_requested(bp);
  9474. /*
  9475. * If connected directly, work with the internal PHY, otherwise, work
  9476. * with the external PHY
  9477. */
  9478. ext_phy_config =
  9479. SHMEM_RD(bp,
  9480. dev_info.port_hw_config[port].external_phy_config);
  9481. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9482. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9483. bp->mdio.prtad = bp->port.phy_addr;
  9484. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9485. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9486. bp->mdio.prtad =
  9487. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9488. /* Configure link feature according to nvram value */
  9489. eee_mode = (((SHMEM_RD(bp, dev_info.
  9490. port_feature_config[port].eee_power_mode)) &
  9491. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9492. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9493. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9494. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9495. EEE_MODE_ENABLE_LPI |
  9496. EEE_MODE_OUTPUT_TIME;
  9497. } else {
  9498. bp->link_params.eee_mode = 0;
  9499. }
  9500. }
  9501. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9502. {
  9503. u32 no_flags = NO_ISCSI_FLAG;
  9504. int port = BP_PORT(bp);
  9505. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9506. drv_lic_key[port].max_iscsi_conn);
  9507. if (!CNIC_SUPPORT(bp)) {
  9508. bp->flags |= no_flags;
  9509. return;
  9510. }
  9511. /* Get the number of maximum allowed iSCSI connections */
  9512. bp->cnic_eth_dev.max_iscsi_conn =
  9513. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9514. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9515. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9516. bp->cnic_eth_dev.max_iscsi_conn);
  9517. /*
  9518. * If maximum allowed number of connections is zero -
  9519. * disable the feature.
  9520. */
  9521. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9522. bp->flags |= no_flags;
  9523. }
  9524. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9525. {
  9526. /* Port info */
  9527. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9528. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9529. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9530. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9531. /* Node info */
  9532. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9533. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9534. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9535. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9536. }
  9537. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9538. {
  9539. u8 count = 0;
  9540. if (IS_MF(bp)) {
  9541. u8 fid;
  9542. /* iterate over absolute function ids for this path: */
  9543. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9544. if (IS_MF_SD(bp)) {
  9545. u32 cfg = MF_CFG_RD(bp,
  9546. func_mf_config[fid].config);
  9547. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9548. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9549. FUNC_MF_CFG_PROTOCOL_FCOE))
  9550. count++;
  9551. } else {
  9552. u32 cfg = MF_CFG_RD(bp,
  9553. func_ext_config[fid].
  9554. func_cfg);
  9555. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9556. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9557. count++;
  9558. }
  9559. }
  9560. } else { /* SF */
  9561. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9562. for (port = 0; port < port_cnt; port++) {
  9563. u32 lic = SHMEM_RD(bp,
  9564. drv_lic_key[port].max_fcoe_conn) ^
  9565. FW_ENCODE_32BIT_PATTERN;
  9566. if (lic)
  9567. count++;
  9568. }
  9569. }
  9570. return count;
  9571. }
  9572. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9573. {
  9574. int port = BP_PORT(bp);
  9575. int func = BP_ABS_FUNC(bp);
  9576. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9577. drv_lic_key[port].max_fcoe_conn);
  9578. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9579. if (!CNIC_SUPPORT(bp)) {
  9580. bp->flags |= NO_FCOE_FLAG;
  9581. return;
  9582. }
  9583. /* Get the number of maximum allowed FCoE connections */
  9584. bp->cnic_eth_dev.max_fcoe_conn =
  9585. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9586. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9587. /* Calculate the number of maximum allowed FCoE tasks */
  9588. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9589. /* check if FCoE resources must be shared between different functions */
  9590. if (num_fcoe_func)
  9591. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9592. /* Read the WWN: */
  9593. if (!IS_MF(bp)) {
  9594. /* Port info */
  9595. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9596. SHMEM_RD(bp,
  9597. dev_info.port_hw_config[port].
  9598. fcoe_wwn_port_name_upper);
  9599. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9600. SHMEM_RD(bp,
  9601. dev_info.port_hw_config[port].
  9602. fcoe_wwn_port_name_lower);
  9603. /* Node info */
  9604. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9605. SHMEM_RD(bp,
  9606. dev_info.port_hw_config[port].
  9607. fcoe_wwn_node_name_upper);
  9608. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9609. SHMEM_RD(bp,
  9610. dev_info.port_hw_config[port].
  9611. fcoe_wwn_node_name_lower);
  9612. } else if (!IS_MF_SD(bp)) {
  9613. /* Read the WWN info only if the FCoE feature is enabled for
  9614. * this function.
  9615. */
  9616. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9617. bnx2x_get_ext_wwn_info(bp, func);
  9618. } else {
  9619. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9620. bnx2x_get_ext_wwn_info(bp, func);
  9621. }
  9622. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9623. /*
  9624. * If maximum allowed number of connections is zero -
  9625. * disable the feature.
  9626. */
  9627. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9628. bp->flags |= NO_FCOE_FLAG;
  9629. }
  9630. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9631. {
  9632. /*
  9633. * iSCSI may be dynamically disabled but reading
  9634. * info here we will decrease memory usage by driver
  9635. * if the feature is disabled for good
  9636. */
  9637. bnx2x_get_iscsi_info(bp);
  9638. bnx2x_get_fcoe_info(bp);
  9639. }
  9640. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9641. {
  9642. u32 val, val2;
  9643. int func = BP_ABS_FUNC(bp);
  9644. int port = BP_PORT(bp);
  9645. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9646. u8 *fip_mac = bp->fip_mac;
  9647. if (IS_MF(bp)) {
  9648. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9649. * FCoE MAC then the appropriate feature should be disabled.
  9650. * In non SD mode features configuration comes from struct
  9651. * func_ext_config.
  9652. */
  9653. if (!IS_MF_SD(bp)) {
  9654. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9655. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9656. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9657. iscsi_mac_addr_upper);
  9658. val = MF_CFG_RD(bp, func_ext_config[func].
  9659. iscsi_mac_addr_lower);
  9660. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9661. BNX2X_DEV_INFO
  9662. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9663. } else {
  9664. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9665. }
  9666. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9667. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9668. fcoe_mac_addr_upper);
  9669. val = MF_CFG_RD(bp, func_ext_config[func].
  9670. fcoe_mac_addr_lower);
  9671. bnx2x_set_mac_buf(fip_mac, val, val2);
  9672. BNX2X_DEV_INFO
  9673. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9674. } else {
  9675. bp->flags |= NO_FCOE_FLAG;
  9676. }
  9677. bp->mf_ext_config = cfg;
  9678. } else { /* SD MODE */
  9679. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9680. /* use primary mac as iscsi mac */
  9681. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9682. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9683. BNX2X_DEV_INFO
  9684. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9685. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9686. /* use primary mac as fip mac */
  9687. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9688. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9689. BNX2X_DEV_INFO
  9690. ("Read FIP MAC: %pM\n", fip_mac);
  9691. }
  9692. }
  9693. /* If this is a storage-only interface, use SAN mac as
  9694. * primary MAC. Notice that for SD this is already the case,
  9695. * as the SAN mac was copied from the primary MAC.
  9696. */
  9697. if (IS_MF_FCOE_AFEX(bp))
  9698. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9699. } else {
  9700. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9701. iscsi_mac_upper);
  9702. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9703. iscsi_mac_lower);
  9704. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9705. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9706. fcoe_fip_mac_upper);
  9707. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9708. fcoe_fip_mac_lower);
  9709. bnx2x_set_mac_buf(fip_mac, val, val2);
  9710. }
  9711. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9712. if (!is_valid_ether_addr(iscsi_mac)) {
  9713. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9714. eth_zero_addr(iscsi_mac);
  9715. }
  9716. /* Disable FCoE if MAC configuration is invalid. */
  9717. if (!is_valid_ether_addr(fip_mac)) {
  9718. bp->flags |= NO_FCOE_FLAG;
  9719. eth_zero_addr(bp->fip_mac);
  9720. }
  9721. }
  9722. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9723. {
  9724. u32 val, val2;
  9725. int func = BP_ABS_FUNC(bp);
  9726. int port = BP_PORT(bp);
  9727. /* Zero primary MAC configuration */
  9728. eth_zero_addr(bp->dev->dev_addr);
  9729. if (BP_NOMCP(bp)) {
  9730. BNX2X_ERROR("warning: random MAC workaround active\n");
  9731. eth_hw_addr_random(bp->dev);
  9732. } else if (IS_MF(bp)) {
  9733. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9734. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9735. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9736. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9737. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9738. if (CNIC_SUPPORT(bp))
  9739. bnx2x_get_cnic_mac_hwinfo(bp);
  9740. } else {
  9741. /* in SF read MACs from port configuration */
  9742. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9743. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9744. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9745. if (CNIC_SUPPORT(bp))
  9746. bnx2x_get_cnic_mac_hwinfo(bp);
  9747. }
  9748. if (!BP_NOMCP(bp)) {
  9749. /* Read physical port identifier from shmem */
  9750. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9751. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9752. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9753. bp->flags |= HAS_PHYS_PORT_ID;
  9754. }
  9755. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9756. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9757. dev_err(&bp->pdev->dev,
  9758. "bad Ethernet MAC address configuration: %pM\n"
  9759. "change it manually before bringing up the appropriate network interface\n",
  9760. bp->dev->dev_addr);
  9761. }
  9762. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9763. {
  9764. int tmp;
  9765. u32 cfg;
  9766. if (IS_VF(bp))
  9767. return false;
  9768. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9769. /* Take function: tmp = func */
  9770. tmp = BP_ABS_FUNC(bp);
  9771. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9772. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9773. } else {
  9774. /* Take port: tmp = port */
  9775. tmp = BP_PORT(bp);
  9776. cfg = SHMEM_RD(bp,
  9777. dev_info.port_hw_config[tmp].generic_features);
  9778. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9779. }
  9780. return cfg;
  9781. }
  9782. static void validate_set_si_mode(struct bnx2x *bp)
  9783. {
  9784. u8 func = BP_ABS_FUNC(bp);
  9785. u32 val;
  9786. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9787. /* check for legal mac (upper bytes) */
  9788. if (val != 0xffff) {
  9789. bp->mf_mode = MULTI_FUNCTION_SI;
  9790. bp->mf_config[BP_VN(bp)] =
  9791. MF_CFG_RD(bp, func_mf_config[func].config);
  9792. } else
  9793. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9794. }
  9795. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9796. {
  9797. int /*abs*/func = BP_ABS_FUNC(bp);
  9798. int vn;
  9799. u32 val = 0, val2 = 0;
  9800. int rc = 0;
  9801. /* Validate that chip access is feasible */
  9802. if (REG_RD(bp, MISC_REG_CHIP_NUM) == 0xffffffff) {
  9803. dev_err(&bp->pdev->dev,
  9804. "Chip read returns all Fs. Preventing probe from continuing\n");
  9805. return -EINVAL;
  9806. }
  9807. bnx2x_get_common_hwinfo(bp);
  9808. /*
  9809. * initialize IGU parameters
  9810. */
  9811. if (CHIP_IS_E1x(bp)) {
  9812. bp->common.int_block = INT_BLOCK_HC;
  9813. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9814. bp->igu_base_sb = 0;
  9815. } else {
  9816. bp->common.int_block = INT_BLOCK_IGU;
  9817. /* do not allow device reset during IGU info processing */
  9818. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9819. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9820. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9821. int tout = 5000;
  9822. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9823. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9824. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9825. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9826. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9827. tout--;
  9828. usleep_range(1000, 2000);
  9829. }
  9830. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9831. dev_err(&bp->pdev->dev,
  9832. "FORCING Normal Mode failed!!!\n");
  9833. bnx2x_release_hw_lock(bp,
  9834. HW_LOCK_RESOURCE_RESET);
  9835. return -EPERM;
  9836. }
  9837. }
  9838. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9839. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9840. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9841. } else
  9842. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9843. rc = bnx2x_get_igu_cam_info(bp);
  9844. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9845. if (rc)
  9846. return rc;
  9847. }
  9848. /*
  9849. * set base FW non-default (fast path) status block id, this value is
  9850. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9851. * determine the id used by the FW.
  9852. */
  9853. if (CHIP_IS_E1x(bp))
  9854. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9855. else /*
  9856. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9857. * the same queue are indicated on the same IGU SB). So we prefer
  9858. * FW and IGU SBs to be the same value.
  9859. */
  9860. bp->base_fw_ndsb = bp->igu_base_sb;
  9861. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9862. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9863. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9864. /*
  9865. * Initialize MF configuration
  9866. */
  9867. bp->mf_ov = 0;
  9868. bp->mf_mode = 0;
  9869. bp->mf_sub_mode = 0;
  9870. vn = BP_VN(bp);
  9871. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9872. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9873. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9874. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9875. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9876. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9877. else
  9878. bp->common.mf_cfg_base = bp->common.shmem_base +
  9879. offsetof(struct shmem_region, func_mb) +
  9880. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9881. /*
  9882. * get mf configuration:
  9883. * 1. Existence of MF configuration
  9884. * 2. MAC address must be legal (check only upper bytes)
  9885. * for Switch-Independent mode;
  9886. * OVLAN must be legal for Switch-Dependent mode
  9887. * 3. SF_MODE configures specific MF mode
  9888. */
  9889. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9890. /* get mf configuration */
  9891. val = SHMEM_RD(bp,
  9892. dev_info.shared_feature_config.config);
  9893. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9894. switch (val) {
  9895. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9896. validate_set_si_mode(bp);
  9897. break;
  9898. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9899. if ((!CHIP_IS_E1x(bp)) &&
  9900. (MF_CFG_RD(bp, func_mf_config[func].
  9901. mac_upper) != 0xffff) &&
  9902. (SHMEM2_HAS(bp,
  9903. afex_driver_support))) {
  9904. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9905. bp->mf_config[vn] = MF_CFG_RD(bp,
  9906. func_mf_config[func].config);
  9907. } else {
  9908. BNX2X_DEV_INFO("can not configure afex mode\n");
  9909. }
  9910. break;
  9911. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9912. /* get OV configuration */
  9913. val = MF_CFG_RD(bp,
  9914. func_mf_config[FUNC_0].e1hov_tag);
  9915. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9916. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9917. bp->mf_mode = MULTI_FUNCTION_SD;
  9918. bp->mf_config[vn] = MF_CFG_RD(bp,
  9919. func_mf_config[func].config);
  9920. } else
  9921. BNX2X_DEV_INFO("illegal OV for SD\n");
  9922. break;
  9923. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  9924. bp->mf_mode = MULTI_FUNCTION_SD;
  9925. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  9926. bp->mf_config[vn] =
  9927. MF_CFG_RD(bp,
  9928. func_mf_config[func].config);
  9929. break;
  9930. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9931. bp->mf_config[vn] = 0;
  9932. break;
  9933. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  9934. val2 = SHMEM_RD(bp,
  9935. dev_info.shared_hw_config.config_3);
  9936. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  9937. switch (val2) {
  9938. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  9939. validate_set_si_mode(bp);
  9940. bp->mf_sub_mode =
  9941. SUB_MF_MODE_NPAR1_DOT_5;
  9942. break;
  9943. default:
  9944. /* Unknown configuration */
  9945. bp->mf_config[vn] = 0;
  9946. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  9947. val);
  9948. }
  9949. break;
  9950. default:
  9951. /* Unknown configuration: reset mf_config */
  9952. bp->mf_config[vn] = 0;
  9953. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9954. }
  9955. }
  9956. BNX2X_DEV_INFO("%s function mode\n",
  9957. IS_MF(bp) ? "multi" : "single");
  9958. switch (bp->mf_mode) {
  9959. case MULTI_FUNCTION_SD:
  9960. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9961. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9962. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9963. bp->mf_ov = val;
  9964. bp->path_has_ovlan = true;
  9965. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9966. func, bp->mf_ov, bp->mf_ov);
  9967. } else if (bp->mf_sub_mode == SUB_MF_MODE_UFP) {
  9968. dev_err(&bp->pdev->dev,
  9969. "Unexpected - no valid MF OV for func %d in UFP mode\n",
  9970. func);
  9971. bp->path_has_ovlan = true;
  9972. } else {
  9973. dev_err(&bp->pdev->dev,
  9974. "No valid MF OV for func %d, aborting\n",
  9975. func);
  9976. return -EPERM;
  9977. }
  9978. break;
  9979. case MULTI_FUNCTION_AFEX:
  9980. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9981. break;
  9982. case MULTI_FUNCTION_SI:
  9983. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9984. func);
  9985. break;
  9986. default:
  9987. if (vn) {
  9988. dev_err(&bp->pdev->dev,
  9989. "VN %d is in a single function mode, aborting\n",
  9990. vn);
  9991. return -EPERM;
  9992. }
  9993. break;
  9994. }
  9995. /* check if other port on the path needs ovlan:
  9996. * Since MF configuration is shared between ports
  9997. * Possible mixed modes are only
  9998. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9999. */
  10000. if (CHIP_MODE_IS_4_PORT(bp) &&
  10001. !bp->path_has_ovlan &&
  10002. !IS_MF(bp) &&
  10003. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10004. u8 other_port = !BP_PORT(bp);
  10005. u8 other_func = BP_PATH(bp) + 2*other_port;
  10006. val = MF_CFG_RD(bp,
  10007. func_mf_config[other_func].e1hov_tag);
  10008. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  10009. bp->path_has_ovlan = true;
  10010. }
  10011. }
  10012. /* adjust igu_sb_cnt to MF for E1H */
  10013. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10014. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10015. /* port info */
  10016. bnx2x_get_port_hwinfo(bp);
  10017. /* Get MAC addresses */
  10018. bnx2x_get_mac_hwinfo(bp);
  10019. bnx2x_get_cnic_info(bp);
  10020. return rc;
  10021. }
  10022. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10023. {
  10024. int cnt, i, block_end, rodi;
  10025. char vpd_start[BNX2X_VPD_LEN+1];
  10026. char str_id_reg[VENDOR_ID_LEN+1];
  10027. char str_id_cap[VENDOR_ID_LEN+1];
  10028. char *vpd_data;
  10029. char *vpd_extended_data = NULL;
  10030. u8 len;
  10031. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10032. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10033. if (cnt < BNX2X_VPD_LEN)
  10034. goto out_not_found;
  10035. /* VPD RO tag should be first tag after identifier string, hence
  10036. * we should be able to find it in first BNX2X_VPD_LEN chars
  10037. */
  10038. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10039. PCI_VPD_LRDT_RO_DATA);
  10040. if (i < 0)
  10041. goto out_not_found;
  10042. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10043. pci_vpd_lrdt_size(&vpd_start[i]);
  10044. i += PCI_VPD_LRDT_TAG_SIZE;
  10045. if (block_end > BNX2X_VPD_LEN) {
  10046. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10047. if (vpd_extended_data == NULL)
  10048. goto out_not_found;
  10049. /* read rest of vpd image into vpd_extended_data */
  10050. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10051. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10052. block_end - BNX2X_VPD_LEN,
  10053. vpd_extended_data + BNX2X_VPD_LEN);
  10054. if (cnt < (block_end - BNX2X_VPD_LEN))
  10055. goto out_not_found;
  10056. vpd_data = vpd_extended_data;
  10057. } else
  10058. vpd_data = vpd_start;
  10059. /* now vpd_data holds full vpd content in both cases */
  10060. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10061. PCI_VPD_RO_KEYWORD_MFR_ID);
  10062. if (rodi < 0)
  10063. goto out_not_found;
  10064. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10065. if (len != VENDOR_ID_LEN)
  10066. goto out_not_found;
  10067. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10068. /* vendor specific info */
  10069. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10070. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10071. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10072. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10073. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10074. PCI_VPD_RO_KEYWORD_VENDOR0);
  10075. if (rodi >= 0) {
  10076. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10077. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10078. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10079. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10080. bp->fw_ver[len] = ' ';
  10081. }
  10082. }
  10083. kfree(vpd_extended_data);
  10084. return;
  10085. }
  10086. out_not_found:
  10087. kfree(vpd_extended_data);
  10088. return;
  10089. }
  10090. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10091. {
  10092. u32 flags = 0;
  10093. if (CHIP_REV_IS_FPGA(bp))
  10094. SET_FLAGS(flags, MODE_FPGA);
  10095. else if (CHIP_REV_IS_EMUL(bp))
  10096. SET_FLAGS(flags, MODE_EMUL);
  10097. else
  10098. SET_FLAGS(flags, MODE_ASIC);
  10099. if (CHIP_MODE_IS_4_PORT(bp))
  10100. SET_FLAGS(flags, MODE_PORT4);
  10101. else
  10102. SET_FLAGS(flags, MODE_PORT2);
  10103. if (CHIP_IS_E2(bp))
  10104. SET_FLAGS(flags, MODE_E2);
  10105. else if (CHIP_IS_E3(bp)) {
  10106. SET_FLAGS(flags, MODE_E3);
  10107. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10108. SET_FLAGS(flags, MODE_E3_A0);
  10109. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10110. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10111. }
  10112. if (IS_MF(bp)) {
  10113. SET_FLAGS(flags, MODE_MF);
  10114. switch (bp->mf_mode) {
  10115. case MULTI_FUNCTION_SD:
  10116. SET_FLAGS(flags, MODE_MF_SD);
  10117. break;
  10118. case MULTI_FUNCTION_SI:
  10119. SET_FLAGS(flags, MODE_MF_SI);
  10120. break;
  10121. case MULTI_FUNCTION_AFEX:
  10122. SET_FLAGS(flags, MODE_MF_AFEX);
  10123. break;
  10124. }
  10125. } else
  10126. SET_FLAGS(flags, MODE_SF);
  10127. #if defined(__LITTLE_ENDIAN)
  10128. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10129. #else /*(__BIG_ENDIAN)*/
  10130. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10131. #endif
  10132. INIT_MODE_FLAGS(bp) = flags;
  10133. }
  10134. static int bnx2x_init_bp(struct bnx2x *bp)
  10135. {
  10136. int func;
  10137. int rc;
  10138. mutex_init(&bp->port.phy_mutex);
  10139. mutex_init(&bp->fw_mb_mutex);
  10140. mutex_init(&bp->drv_info_mutex);
  10141. sema_init(&bp->stats_lock, 1);
  10142. bp->drv_info_mng_owner = false;
  10143. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10144. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10145. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10146. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10147. if (IS_PF(bp)) {
  10148. rc = bnx2x_get_hwinfo(bp);
  10149. if (rc)
  10150. return rc;
  10151. } else {
  10152. eth_zero_addr(bp->dev->dev_addr);
  10153. }
  10154. bnx2x_set_modes_bitmap(bp);
  10155. rc = bnx2x_alloc_mem_bp(bp);
  10156. if (rc)
  10157. return rc;
  10158. bnx2x_read_fwinfo(bp);
  10159. func = BP_FUNC(bp);
  10160. /* need to reset chip if undi was active */
  10161. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10162. /* init fw_seq */
  10163. bp->fw_seq =
  10164. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10165. DRV_MSG_SEQ_NUMBER_MASK;
  10166. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10167. rc = bnx2x_prev_unload(bp);
  10168. if (rc) {
  10169. bnx2x_free_mem_bp(bp);
  10170. return rc;
  10171. }
  10172. }
  10173. if (CHIP_REV_IS_FPGA(bp))
  10174. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10175. if (BP_NOMCP(bp) && (func == 0))
  10176. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10177. bp->disable_tpa = disable_tpa;
  10178. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10179. /* Reduce memory usage in kdump environment by disabling TPA */
  10180. bp->disable_tpa |= is_kdump_kernel();
  10181. /* Set TPA flags */
  10182. if (bp->disable_tpa) {
  10183. bp->dev->hw_features &= ~NETIF_F_LRO;
  10184. bp->dev->features &= ~NETIF_F_LRO;
  10185. }
  10186. if (CHIP_IS_E1(bp))
  10187. bp->dropless_fc = 0;
  10188. else
  10189. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10190. bp->mrrs = mrrs;
  10191. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10192. if (IS_VF(bp))
  10193. bp->rx_ring_size = MAX_RX_AVAIL;
  10194. /* make sure that the numbers are in the right granularity */
  10195. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10196. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10197. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10198. init_timer(&bp->timer);
  10199. bp->timer.expires = jiffies + bp->current_interval;
  10200. bp->timer.data = (unsigned long) bp;
  10201. bp->timer.function = bnx2x_timer;
  10202. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10203. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10204. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10205. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10206. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10207. bnx2x_dcbx_init_params(bp);
  10208. } else {
  10209. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10210. }
  10211. if (CHIP_IS_E1x(bp))
  10212. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10213. else
  10214. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10215. /* multiple tx priority */
  10216. if (IS_VF(bp))
  10217. bp->max_cos = 1;
  10218. else if (CHIP_IS_E1x(bp))
  10219. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10220. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10221. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10222. else if (CHIP_IS_E3B0(bp))
  10223. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10224. else
  10225. BNX2X_ERR("unknown chip %x revision %x\n",
  10226. CHIP_NUM(bp), CHIP_REV(bp));
  10227. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10228. /* We need at least one default status block for slow-path events,
  10229. * second status block for the L2 queue, and a third status block for
  10230. * CNIC if supported.
  10231. */
  10232. if (IS_VF(bp))
  10233. bp->min_msix_vec_cnt = 1;
  10234. else if (CNIC_SUPPORT(bp))
  10235. bp->min_msix_vec_cnt = 3;
  10236. else /* PF w/o cnic */
  10237. bp->min_msix_vec_cnt = 2;
  10238. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10239. bp->dump_preset_idx = 1;
  10240. if (CHIP_IS_E3B0(bp))
  10241. bp->flags |= PTP_SUPPORTED;
  10242. return rc;
  10243. }
  10244. /****************************************************************************
  10245. * General service functions
  10246. ****************************************************************************/
  10247. /*
  10248. * net_device service functions
  10249. */
  10250. /* called with rtnl_lock */
  10251. static int bnx2x_open(struct net_device *dev)
  10252. {
  10253. struct bnx2x *bp = netdev_priv(dev);
  10254. int rc;
  10255. bp->stats_init = true;
  10256. netif_carrier_off(dev);
  10257. bnx2x_set_power_state(bp, PCI_D0);
  10258. /* If parity had happen during the unload, then attentions
  10259. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10260. * want the first function loaded on the current engine to
  10261. * complete the recovery.
  10262. * Parity recovery is only relevant for PF driver.
  10263. */
  10264. if (IS_PF(bp)) {
  10265. int other_engine = BP_PATH(bp) ? 0 : 1;
  10266. bool other_load_status, load_status;
  10267. bool global = false;
  10268. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10269. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10270. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10271. bnx2x_chk_parity_attn(bp, &global, true)) {
  10272. do {
  10273. /* If there are attentions and they are in a
  10274. * global blocks, set the GLOBAL_RESET bit
  10275. * regardless whether it will be this function
  10276. * that will complete the recovery or not.
  10277. */
  10278. if (global)
  10279. bnx2x_set_reset_global(bp);
  10280. /* Only the first function on the current
  10281. * engine should try to recover in open. In case
  10282. * of attentions in global blocks only the first
  10283. * in the chip should try to recover.
  10284. */
  10285. if ((!load_status &&
  10286. (!global || !other_load_status)) &&
  10287. bnx2x_trylock_leader_lock(bp) &&
  10288. !bnx2x_leader_reset(bp)) {
  10289. netdev_info(bp->dev,
  10290. "Recovered in open\n");
  10291. break;
  10292. }
  10293. /* recovery has failed... */
  10294. bnx2x_set_power_state(bp, PCI_D3hot);
  10295. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10296. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10297. "If you still see this message after a few retries then power cycle is required.\n");
  10298. return -EAGAIN;
  10299. } while (0);
  10300. }
  10301. }
  10302. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10303. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10304. if (rc)
  10305. return rc;
  10306. return 0;
  10307. }
  10308. /* called with rtnl_lock */
  10309. static int bnx2x_close(struct net_device *dev)
  10310. {
  10311. struct bnx2x *bp = netdev_priv(dev);
  10312. /* Unload the driver, release IRQs */
  10313. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10314. return 0;
  10315. }
  10316. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10317. struct bnx2x_mcast_ramrod_params *p)
  10318. {
  10319. int mc_count = netdev_mc_count(bp->dev);
  10320. struct bnx2x_mcast_list_elem *mc_mac =
  10321. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10322. struct netdev_hw_addr *ha;
  10323. if (!mc_mac)
  10324. return -ENOMEM;
  10325. INIT_LIST_HEAD(&p->mcast_list);
  10326. netdev_for_each_mc_addr(ha, bp->dev) {
  10327. mc_mac->mac = bnx2x_mc_addr(ha);
  10328. list_add_tail(&mc_mac->link, &p->mcast_list);
  10329. mc_mac++;
  10330. }
  10331. p->mcast_list_len = mc_count;
  10332. return 0;
  10333. }
  10334. static void bnx2x_free_mcast_macs_list(
  10335. struct bnx2x_mcast_ramrod_params *p)
  10336. {
  10337. struct bnx2x_mcast_list_elem *mc_mac =
  10338. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10339. link);
  10340. WARN_ON(!mc_mac);
  10341. kfree(mc_mac);
  10342. }
  10343. /**
  10344. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10345. *
  10346. * @bp: driver handle
  10347. *
  10348. * We will use zero (0) as a MAC type for these MACs.
  10349. */
  10350. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10351. {
  10352. int rc;
  10353. struct net_device *dev = bp->dev;
  10354. struct netdev_hw_addr *ha;
  10355. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10356. unsigned long ramrod_flags = 0;
  10357. /* First schedule a cleanup up of old configuration */
  10358. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10359. if (rc < 0) {
  10360. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10361. return rc;
  10362. }
  10363. netdev_for_each_uc_addr(ha, dev) {
  10364. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10365. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10366. if (rc == -EEXIST) {
  10367. DP(BNX2X_MSG_SP,
  10368. "Failed to schedule ADD operations: %d\n", rc);
  10369. /* do not treat adding same MAC as error */
  10370. rc = 0;
  10371. } else if (rc < 0) {
  10372. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10373. rc);
  10374. return rc;
  10375. }
  10376. }
  10377. /* Execute the pending commands */
  10378. __set_bit(RAMROD_CONT, &ramrod_flags);
  10379. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10380. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10381. }
  10382. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10383. {
  10384. struct net_device *dev = bp->dev;
  10385. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10386. int rc = 0;
  10387. rparam.mcast_obj = &bp->mcast_obj;
  10388. /* first, clear all configured multicast MACs */
  10389. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10390. if (rc < 0) {
  10391. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10392. return rc;
  10393. }
  10394. /* then, configure a new MACs list */
  10395. if (netdev_mc_count(dev)) {
  10396. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10397. if (rc) {
  10398. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10399. rc);
  10400. return rc;
  10401. }
  10402. /* Now add the new MACs */
  10403. rc = bnx2x_config_mcast(bp, &rparam,
  10404. BNX2X_MCAST_CMD_ADD);
  10405. if (rc < 0)
  10406. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10407. rc);
  10408. bnx2x_free_mcast_macs_list(&rparam);
  10409. }
  10410. return rc;
  10411. }
  10412. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10413. static void bnx2x_set_rx_mode(struct net_device *dev)
  10414. {
  10415. struct bnx2x *bp = netdev_priv(dev);
  10416. if (bp->state != BNX2X_STATE_OPEN) {
  10417. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10418. return;
  10419. } else {
  10420. /* Schedule an SP task to handle rest of change */
  10421. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10422. NETIF_MSG_IFUP);
  10423. }
  10424. }
  10425. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10426. {
  10427. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10428. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10429. netif_addr_lock_bh(bp->dev);
  10430. if (bp->dev->flags & IFF_PROMISC) {
  10431. rx_mode = BNX2X_RX_MODE_PROMISC;
  10432. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10433. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10434. CHIP_IS_E1(bp))) {
  10435. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10436. } else {
  10437. if (IS_PF(bp)) {
  10438. /* some multicasts */
  10439. if (bnx2x_set_mc_list(bp) < 0)
  10440. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10441. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10442. netif_addr_unlock_bh(bp->dev);
  10443. if (bnx2x_set_uc_list(bp) < 0)
  10444. rx_mode = BNX2X_RX_MODE_PROMISC;
  10445. netif_addr_lock_bh(bp->dev);
  10446. } else {
  10447. /* configuring mcast to a vf involves sleeping (when we
  10448. * wait for the pf's response).
  10449. */
  10450. bnx2x_schedule_sp_rtnl(bp,
  10451. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10452. }
  10453. }
  10454. bp->rx_mode = rx_mode;
  10455. /* handle ISCSI SD mode */
  10456. if (IS_MF_ISCSI_ONLY(bp))
  10457. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10458. /* Schedule the rx_mode command */
  10459. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10460. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10461. netif_addr_unlock_bh(bp->dev);
  10462. return;
  10463. }
  10464. if (IS_PF(bp)) {
  10465. bnx2x_set_storm_rx_mode(bp);
  10466. netif_addr_unlock_bh(bp->dev);
  10467. } else {
  10468. /* VF will need to request the PF to make this change, and so
  10469. * the VF needs to release the bottom-half lock prior to the
  10470. * request (as it will likely require sleep on the VF side)
  10471. */
  10472. netif_addr_unlock_bh(bp->dev);
  10473. bnx2x_vfpf_storm_rx_mode(bp);
  10474. }
  10475. }
  10476. /* called with rtnl_lock */
  10477. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10478. int devad, u16 addr)
  10479. {
  10480. struct bnx2x *bp = netdev_priv(netdev);
  10481. u16 value;
  10482. int rc;
  10483. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10484. prtad, devad, addr);
  10485. /* The HW expects different devad if CL22 is used */
  10486. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10487. bnx2x_acquire_phy_lock(bp);
  10488. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10489. bnx2x_release_phy_lock(bp);
  10490. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10491. if (!rc)
  10492. rc = value;
  10493. return rc;
  10494. }
  10495. /* called with rtnl_lock */
  10496. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10497. u16 addr, u16 value)
  10498. {
  10499. struct bnx2x *bp = netdev_priv(netdev);
  10500. int rc;
  10501. DP(NETIF_MSG_LINK,
  10502. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10503. prtad, devad, addr, value);
  10504. /* The HW expects different devad if CL22 is used */
  10505. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10506. bnx2x_acquire_phy_lock(bp);
  10507. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10508. bnx2x_release_phy_lock(bp);
  10509. return rc;
  10510. }
  10511. /* called with rtnl_lock */
  10512. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10513. {
  10514. struct bnx2x *bp = netdev_priv(dev);
  10515. struct mii_ioctl_data *mdio = if_mii(ifr);
  10516. if (!netif_running(dev))
  10517. return -EAGAIN;
  10518. switch (cmd) {
  10519. case SIOCSHWTSTAMP:
  10520. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10521. default:
  10522. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10523. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10524. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10525. }
  10526. }
  10527. #ifdef CONFIG_NET_POLL_CONTROLLER
  10528. static void poll_bnx2x(struct net_device *dev)
  10529. {
  10530. struct bnx2x *bp = netdev_priv(dev);
  10531. int i;
  10532. for_each_eth_queue(bp, i) {
  10533. struct bnx2x_fastpath *fp = &bp->fp[i];
  10534. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10535. }
  10536. }
  10537. #endif
  10538. static int bnx2x_validate_addr(struct net_device *dev)
  10539. {
  10540. struct bnx2x *bp = netdev_priv(dev);
  10541. /* query the bulletin board for mac address configured by the PF */
  10542. if (IS_VF(bp))
  10543. bnx2x_sample_bulletin(bp);
  10544. if (!is_valid_ether_addr(dev->dev_addr)) {
  10545. BNX2X_ERR("Non-valid Ethernet address\n");
  10546. return -EADDRNOTAVAIL;
  10547. }
  10548. return 0;
  10549. }
  10550. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10551. struct netdev_phys_item_id *ppid)
  10552. {
  10553. struct bnx2x *bp = netdev_priv(netdev);
  10554. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10555. return -EOPNOTSUPP;
  10556. ppid->id_len = sizeof(bp->phys_port_id);
  10557. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10558. return 0;
  10559. }
  10560. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10561. struct net_device *dev,
  10562. netdev_features_t features)
  10563. {
  10564. features = vlan_features_check(skb, features);
  10565. return vxlan_features_check(skb, features);
  10566. }
  10567. static const struct net_device_ops bnx2x_netdev_ops = {
  10568. .ndo_open = bnx2x_open,
  10569. .ndo_stop = bnx2x_close,
  10570. .ndo_start_xmit = bnx2x_start_xmit,
  10571. .ndo_select_queue = bnx2x_select_queue,
  10572. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10573. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10574. .ndo_validate_addr = bnx2x_validate_addr,
  10575. .ndo_do_ioctl = bnx2x_ioctl,
  10576. .ndo_change_mtu = bnx2x_change_mtu,
  10577. .ndo_fix_features = bnx2x_fix_features,
  10578. .ndo_set_features = bnx2x_set_features,
  10579. .ndo_tx_timeout = bnx2x_tx_timeout,
  10580. #ifdef CONFIG_NET_POLL_CONTROLLER
  10581. .ndo_poll_controller = poll_bnx2x,
  10582. #endif
  10583. .ndo_setup_tc = bnx2x_setup_tc,
  10584. #ifdef CONFIG_BNX2X_SRIOV
  10585. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10586. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10587. .ndo_get_vf_config = bnx2x_get_vf_config,
  10588. #endif
  10589. #ifdef NETDEV_FCOE_WWNN
  10590. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10591. #endif
  10592. #ifdef CONFIG_NET_RX_BUSY_POLL
  10593. .ndo_busy_poll = bnx2x_low_latency_recv,
  10594. #endif
  10595. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10596. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10597. .ndo_features_check = bnx2x_features_check,
  10598. };
  10599. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10600. {
  10601. struct device *dev = &bp->pdev->dev;
  10602. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10603. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10604. dev_err(dev, "System does not support DMA, aborting\n");
  10605. return -EIO;
  10606. }
  10607. return 0;
  10608. }
  10609. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10610. {
  10611. if (bp->flags & AER_ENABLED) {
  10612. pci_disable_pcie_error_reporting(bp->pdev);
  10613. bp->flags &= ~AER_ENABLED;
  10614. }
  10615. }
  10616. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10617. struct net_device *dev, unsigned long board_type)
  10618. {
  10619. int rc;
  10620. u32 pci_cfg_dword;
  10621. bool chip_is_e1x = (board_type == BCM57710 ||
  10622. board_type == BCM57711 ||
  10623. board_type == BCM57711E);
  10624. SET_NETDEV_DEV(dev, &pdev->dev);
  10625. bp->dev = dev;
  10626. bp->pdev = pdev;
  10627. rc = pci_enable_device(pdev);
  10628. if (rc) {
  10629. dev_err(&bp->pdev->dev,
  10630. "Cannot enable PCI device, aborting\n");
  10631. goto err_out;
  10632. }
  10633. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10634. dev_err(&bp->pdev->dev,
  10635. "Cannot find PCI device base address, aborting\n");
  10636. rc = -ENODEV;
  10637. goto err_out_disable;
  10638. }
  10639. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10640. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10641. rc = -ENODEV;
  10642. goto err_out_disable;
  10643. }
  10644. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10645. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10646. PCICFG_REVESION_ID_ERROR_VAL) {
  10647. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10648. rc = -ENODEV;
  10649. goto err_out_disable;
  10650. }
  10651. if (atomic_read(&pdev->enable_cnt) == 1) {
  10652. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10653. if (rc) {
  10654. dev_err(&bp->pdev->dev,
  10655. "Cannot obtain PCI resources, aborting\n");
  10656. goto err_out_disable;
  10657. }
  10658. pci_set_master(pdev);
  10659. pci_save_state(pdev);
  10660. }
  10661. if (IS_PF(bp)) {
  10662. if (!pdev->pm_cap) {
  10663. dev_err(&bp->pdev->dev,
  10664. "Cannot find power management capability, aborting\n");
  10665. rc = -EIO;
  10666. goto err_out_release;
  10667. }
  10668. }
  10669. if (!pci_is_pcie(pdev)) {
  10670. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10671. rc = -EIO;
  10672. goto err_out_release;
  10673. }
  10674. rc = bnx2x_set_coherency_mask(bp);
  10675. if (rc)
  10676. goto err_out_release;
  10677. dev->mem_start = pci_resource_start(pdev, 0);
  10678. dev->base_addr = dev->mem_start;
  10679. dev->mem_end = pci_resource_end(pdev, 0);
  10680. dev->irq = pdev->irq;
  10681. bp->regview = pci_ioremap_bar(pdev, 0);
  10682. if (!bp->regview) {
  10683. dev_err(&bp->pdev->dev,
  10684. "Cannot map register space, aborting\n");
  10685. rc = -ENOMEM;
  10686. goto err_out_release;
  10687. }
  10688. /* In E1/E1H use pci device function given by kernel.
  10689. * In E2/E3 read physical function from ME register since these chips
  10690. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10691. * (depending on hypervisor).
  10692. */
  10693. if (chip_is_e1x) {
  10694. bp->pf_num = PCI_FUNC(pdev->devfn);
  10695. } else {
  10696. /* chip is E2/3*/
  10697. pci_read_config_dword(bp->pdev,
  10698. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10699. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10700. ME_REG_ABS_PF_NUM_SHIFT);
  10701. }
  10702. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10703. /* clean indirect addresses */
  10704. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10705. PCICFG_VENDOR_ID_OFFSET);
  10706. /* Set PCIe reset type to fundamental for EEH recovery */
  10707. pdev->needs_freset = 1;
  10708. /* AER (Advanced Error reporting) configuration */
  10709. rc = pci_enable_pcie_error_reporting(pdev);
  10710. if (!rc)
  10711. bp->flags |= AER_ENABLED;
  10712. else
  10713. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10714. /*
  10715. * Clean the following indirect addresses for all functions since it
  10716. * is not used by the driver.
  10717. */
  10718. if (IS_PF(bp)) {
  10719. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10720. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10721. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10722. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10723. if (chip_is_e1x) {
  10724. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10725. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10726. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10727. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10728. }
  10729. /* Enable internal target-read (in case we are probed after PF
  10730. * FLR). Must be done prior to any BAR read access. Only for
  10731. * 57712 and up
  10732. */
  10733. if (!chip_is_e1x)
  10734. REG_WR(bp,
  10735. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10736. }
  10737. dev->watchdog_timeo = TX_TIMEOUT;
  10738. dev->netdev_ops = &bnx2x_netdev_ops;
  10739. bnx2x_set_ethtool_ops(bp, dev);
  10740. dev->priv_flags |= IFF_UNICAST_FLT;
  10741. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10742. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10743. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10744. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10745. if (!chip_is_e1x) {
  10746. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10747. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10748. dev->hw_enc_features =
  10749. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10750. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10751. NETIF_F_GSO_IPIP |
  10752. NETIF_F_GSO_SIT |
  10753. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10754. }
  10755. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10756. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10757. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10758. dev->features |= NETIF_F_HIGHDMA;
  10759. /* Add Loopback capability to the device */
  10760. dev->hw_features |= NETIF_F_LOOPBACK;
  10761. #ifdef BCM_DCBNL
  10762. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10763. #endif
  10764. /* get_port_hwinfo() will set prtad and mmds properly */
  10765. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10766. bp->mdio.mmds = 0;
  10767. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10768. bp->mdio.dev = dev;
  10769. bp->mdio.mdio_read = bnx2x_mdio_read;
  10770. bp->mdio.mdio_write = bnx2x_mdio_write;
  10771. return 0;
  10772. err_out_release:
  10773. if (atomic_read(&pdev->enable_cnt) == 1)
  10774. pci_release_regions(pdev);
  10775. err_out_disable:
  10776. pci_disable_device(pdev);
  10777. err_out:
  10778. return rc;
  10779. }
  10780. static int bnx2x_check_firmware(struct bnx2x *bp)
  10781. {
  10782. const struct firmware *firmware = bp->firmware;
  10783. struct bnx2x_fw_file_hdr *fw_hdr;
  10784. struct bnx2x_fw_file_section *sections;
  10785. u32 offset, len, num_ops;
  10786. __be16 *ops_offsets;
  10787. int i;
  10788. const u8 *fw_ver;
  10789. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10790. BNX2X_ERR("Wrong FW size\n");
  10791. return -EINVAL;
  10792. }
  10793. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10794. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10795. /* Make sure none of the offsets and sizes make us read beyond
  10796. * the end of the firmware data */
  10797. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10798. offset = be32_to_cpu(sections[i].offset);
  10799. len = be32_to_cpu(sections[i].len);
  10800. if (offset + len > firmware->size) {
  10801. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10802. return -EINVAL;
  10803. }
  10804. }
  10805. /* Likewise for the init_ops offsets */
  10806. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10807. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10808. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10809. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10810. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10811. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10812. return -EINVAL;
  10813. }
  10814. }
  10815. /* Check FW version */
  10816. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10817. fw_ver = firmware->data + offset;
  10818. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10819. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10820. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10821. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10822. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10823. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10824. BCM_5710_FW_MAJOR_VERSION,
  10825. BCM_5710_FW_MINOR_VERSION,
  10826. BCM_5710_FW_REVISION_VERSION,
  10827. BCM_5710_FW_ENGINEERING_VERSION);
  10828. return -EINVAL;
  10829. }
  10830. return 0;
  10831. }
  10832. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10833. {
  10834. const __be32 *source = (const __be32 *)_source;
  10835. u32 *target = (u32 *)_target;
  10836. u32 i;
  10837. for (i = 0; i < n/4; i++)
  10838. target[i] = be32_to_cpu(source[i]);
  10839. }
  10840. /*
  10841. Ops array is stored in the following format:
  10842. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10843. */
  10844. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10845. {
  10846. const __be32 *source = (const __be32 *)_source;
  10847. struct raw_op *target = (struct raw_op *)_target;
  10848. u32 i, j, tmp;
  10849. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10850. tmp = be32_to_cpu(source[j]);
  10851. target[i].op = (tmp >> 24) & 0xff;
  10852. target[i].offset = tmp & 0xffffff;
  10853. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10854. }
  10855. }
  10856. /* IRO array is stored in the following format:
  10857. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10858. */
  10859. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10860. {
  10861. const __be32 *source = (const __be32 *)_source;
  10862. struct iro *target = (struct iro *)_target;
  10863. u32 i, j, tmp;
  10864. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10865. target[i].base = be32_to_cpu(source[j]);
  10866. j++;
  10867. tmp = be32_to_cpu(source[j]);
  10868. target[i].m1 = (tmp >> 16) & 0xffff;
  10869. target[i].m2 = tmp & 0xffff;
  10870. j++;
  10871. tmp = be32_to_cpu(source[j]);
  10872. target[i].m3 = (tmp >> 16) & 0xffff;
  10873. target[i].size = tmp & 0xffff;
  10874. j++;
  10875. }
  10876. }
  10877. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10878. {
  10879. const __be16 *source = (const __be16 *)_source;
  10880. u16 *target = (u16 *)_target;
  10881. u32 i;
  10882. for (i = 0; i < n/2; i++)
  10883. target[i] = be16_to_cpu(source[i]);
  10884. }
  10885. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10886. do { \
  10887. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10888. bp->arr = kmalloc(len, GFP_KERNEL); \
  10889. if (!bp->arr) \
  10890. goto lbl; \
  10891. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10892. (u8 *)bp->arr, len); \
  10893. } while (0)
  10894. static int bnx2x_init_firmware(struct bnx2x *bp)
  10895. {
  10896. const char *fw_file_name;
  10897. struct bnx2x_fw_file_hdr *fw_hdr;
  10898. int rc;
  10899. if (bp->firmware)
  10900. return 0;
  10901. if (CHIP_IS_E1(bp))
  10902. fw_file_name = FW_FILE_NAME_E1;
  10903. else if (CHIP_IS_E1H(bp))
  10904. fw_file_name = FW_FILE_NAME_E1H;
  10905. else if (!CHIP_IS_E1x(bp))
  10906. fw_file_name = FW_FILE_NAME_E2;
  10907. else {
  10908. BNX2X_ERR("Unsupported chip revision\n");
  10909. return -EINVAL;
  10910. }
  10911. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10912. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10913. if (rc) {
  10914. BNX2X_ERR("Can't load firmware file %s\n",
  10915. fw_file_name);
  10916. goto request_firmware_exit;
  10917. }
  10918. rc = bnx2x_check_firmware(bp);
  10919. if (rc) {
  10920. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10921. goto request_firmware_exit;
  10922. }
  10923. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10924. /* Initialize the pointers to the init arrays */
  10925. /* Blob */
  10926. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10927. /* Opcodes */
  10928. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10929. /* Offsets */
  10930. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10931. be16_to_cpu_n);
  10932. /* STORMs firmware */
  10933. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10934. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10935. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10936. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10937. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10938. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10939. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10940. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10941. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10942. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10943. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10944. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10945. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10946. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10947. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10948. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10949. /* IRO */
  10950. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10951. return 0;
  10952. iro_alloc_err:
  10953. kfree(bp->init_ops_offsets);
  10954. init_offsets_alloc_err:
  10955. kfree(bp->init_ops);
  10956. init_ops_alloc_err:
  10957. kfree(bp->init_data);
  10958. request_firmware_exit:
  10959. release_firmware(bp->firmware);
  10960. bp->firmware = NULL;
  10961. return rc;
  10962. }
  10963. static void bnx2x_release_firmware(struct bnx2x *bp)
  10964. {
  10965. kfree(bp->init_ops_offsets);
  10966. kfree(bp->init_ops);
  10967. kfree(bp->init_data);
  10968. release_firmware(bp->firmware);
  10969. bp->firmware = NULL;
  10970. }
  10971. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10972. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10973. .init_hw_cmn = bnx2x_init_hw_common,
  10974. .init_hw_port = bnx2x_init_hw_port,
  10975. .init_hw_func = bnx2x_init_hw_func,
  10976. .reset_hw_cmn = bnx2x_reset_common,
  10977. .reset_hw_port = bnx2x_reset_port,
  10978. .reset_hw_func = bnx2x_reset_func,
  10979. .gunzip_init = bnx2x_gunzip_init,
  10980. .gunzip_end = bnx2x_gunzip_end,
  10981. .init_fw = bnx2x_init_firmware,
  10982. .release_fw = bnx2x_release_firmware,
  10983. };
  10984. void bnx2x__init_func_obj(struct bnx2x *bp)
  10985. {
  10986. /* Prepare DMAE related driver resources */
  10987. bnx2x_setup_dmae(bp);
  10988. bnx2x_init_func_obj(bp, &bp->func_obj,
  10989. bnx2x_sp(bp, func_rdata),
  10990. bnx2x_sp_mapping(bp, func_rdata),
  10991. bnx2x_sp(bp, func_afex_rdata),
  10992. bnx2x_sp_mapping(bp, func_afex_rdata),
  10993. &bnx2x_func_sp_drv);
  10994. }
  10995. /* must be called after sriov-enable */
  10996. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10997. {
  10998. int cid_count = BNX2X_L2_MAX_CID(bp);
  10999. if (IS_SRIOV(bp))
  11000. cid_count += BNX2X_VF_CIDS;
  11001. if (CNIC_SUPPORT(bp))
  11002. cid_count += CNIC_CID_MAX;
  11003. return roundup(cid_count, QM_CID_ROUND);
  11004. }
  11005. /**
  11006. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  11007. *
  11008. * @dev: pci device
  11009. *
  11010. */
  11011. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11012. {
  11013. int index;
  11014. u16 control = 0;
  11015. /*
  11016. * If MSI-X is not supported - return number of SBs needed to support
  11017. * one fast path queue: one FP queue + SB for CNIC
  11018. */
  11019. if (!pdev->msix_cap) {
  11020. dev_info(&pdev->dev, "no msix capability found\n");
  11021. return 1 + cnic_cnt;
  11022. }
  11023. dev_info(&pdev->dev, "msix capability found\n");
  11024. /*
  11025. * The value in the PCI configuration space is the index of the last
  11026. * entry, namely one less than the actual size of the table, which is
  11027. * exactly what we want to return from this function: number of all SBs
  11028. * without the default SB.
  11029. * For VFs there is no default SB, then we return (index+1).
  11030. */
  11031. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11032. index = control & PCI_MSIX_FLAGS_QSIZE;
  11033. return index;
  11034. }
  11035. static int set_max_cos_est(int chip_id)
  11036. {
  11037. switch (chip_id) {
  11038. case BCM57710:
  11039. case BCM57711:
  11040. case BCM57711E:
  11041. return BNX2X_MULTI_TX_COS_E1X;
  11042. case BCM57712:
  11043. case BCM57712_MF:
  11044. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11045. case BCM57800:
  11046. case BCM57800_MF:
  11047. case BCM57810:
  11048. case BCM57810_MF:
  11049. case BCM57840_4_10:
  11050. case BCM57840_2_20:
  11051. case BCM57840_O:
  11052. case BCM57840_MFO:
  11053. case BCM57840_MF:
  11054. case BCM57811:
  11055. case BCM57811_MF:
  11056. return BNX2X_MULTI_TX_COS_E3B0;
  11057. case BCM57712_VF:
  11058. case BCM57800_VF:
  11059. case BCM57810_VF:
  11060. case BCM57840_VF:
  11061. case BCM57811_VF:
  11062. return 1;
  11063. default:
  11064. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11065. return -ENODEV;
  11066. }
  11067. }
  11068. static int set_is_vf(int chip_id)
  11069. {
  11070. switch (chip_id) {
  11071. case BCM57712_VF:
  11072. case BCM57800_VF:
  11073. case BCM57810_VF:
  11074. case BCM57840_VF:
  11075. case BCM57811_VF:
  11076. return true;
  11077. default:
  11078. return false;
  11079. }
  11080. }
  11081. /* nig_tsgen registers relative address */
  11082. #define tsgen_ctrl 0x0
  11083. #define tsgen_freecount 0x10
  11084. #define tsgen_synctime_t0 0x20
  11085. #define tsgen_offset_t0 0x28
  11086. #define tsgen_drift_t0 0x30
  11087. #define tsgen_synctime_t1 0x58
  11088. #define tsgen_offset_t1 0x60
  11089. #define tsgen_drift_t1 0x68
  11090. /* FW workaround for setting drift */
  11091. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11092. int best_val, int best_period)
  11093. {
  11094. struct bnx2x_func_state_params func_params = {NULL};
  11095. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11096. &func_params.params.set_timesync;
  11097. /* Prepare parameters for function state transitions */
  11098. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11099. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11100. func_params.f_obj = &bp->func_obj;
  11101. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11102. /* Function parameters */
  11103. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11104. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11105. set_timesync_params->add_sub_drift_adjust_value =
  11106. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11107. set_timesync_params->drift_adjust_value = best_val;
  11108. set_timesync_params->drift_adjust_period = best_period;
  11109. return bnx2x_func_state_change(bp, &func_params);
  11110. }
  11111. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11112. {
  11113. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11114. int rc;
  11115. int drift_dir = 1;
  11116. int val, period, period1, period2, dif, dif1, dif2;
  11117. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11118. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11119. if (!netif_running(bp->dev)) {
  11120. DP(BNX2X_MSG_PTP,
  11121. "PTP adjfreq called while the interface is down\n");
  11122. return -EFAULT;
  11123. }
  11124. if (ppb < 0) {
  11125. ppb = -ppb;
  11126. drift_dir = 0;
  11127. }
  11128. if (ppb == 0) {
  11129. best_val = 1;
  11130. best_period = 0x1FFFFFF;
  11131. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11132. best_val = 31;
  11133. best_period = 1;
  11134. } else {
  11135. /* Changed not to allow val = 8, 16, 24 as these values
  11136. * are not supported in workaround.
  11137. */
  11138. for (val = 0; val <= 31; val++) {
  11139. if ((val & 0x7) == 0)
  11140. continue;
  11141. period1 = val * 1000000 / ppb;
  11142. period2 = period1 + 1;
  11143. if (period1 != 0)
  11144. dif1 = ppb - (val * 1000000 / period1);
  11145. else
  11146. dif1 = BNX2X_MAX_PHC_DRIFT;
  11147. if (dif1 < 0)
  11148. dif1 = -dif1;
  11149. dif2 = ppb - (val * 1000000 / period2);
  11150. if (dif2 < 0)
  11151. dif2 = -dif2;
  11152. dif = (dif1 < dif2) ? dif1 : dif2;
  11153. period = (dif1 < dif2) ? period1 : period2;
  11154. if (dif < best_dif) {
  11155. best_dif = dif;
  11156. best_val = val;
  11157. best_period = period;
  11158. }
  11159. }
  11160. }
  11161. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11162. best_period);
  11163. if (rc) {
  11164. BNX2X_ERR("Failed to set drift\n");
  11165. return -EFAULT;
  11166. }
  11167. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11168. best_period);
  11169. return 0;
  11170. }
  11171. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11172. {
  11173. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11174. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11175. timecounter_adjtime(&bp->timecounter, delta);
  11176. return 0;
  11177. }
  11178. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  11179. {
  11180. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11181. u64 ns;
  11182. ns = timecounter_read(&bp->timecounter);
  11183. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11184. *ts = ns_to_timespec64(ns);
  11185. return 0;
  11186. }
  11187. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11188. const struct timespec64 *ts)
  11189. {
  11190. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11191. u64 ns;
  11192. ns = timespec64_to_ns(ts);
  11193. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11194. /* Re-init the timecounter */
  11195. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11196. return 0;
  11197. }
  11198. /* Enable (or disable) ancillary features of the phc subsystem */
  11199. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11200. struct ptp_clock_request *rq, int on)
  11201. {
  11202. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11203. BNX2X_ERR("PHC ancillary features are not supported\n");
  11204. return -ENOTSUPP;
  11205. }
  11206. static void bnx2x_register_phc(struct bnx2x *bp)
  11207. {
  11208. /* Fill the ptp_clock_info struct and register PTP clock*/
  11209. bp->ptp_clock_info.owner = THIS_MODULE;
  11210. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11211. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11212. bp->ptp_clock_info.n_alarm = 0;
  11213. bp->ptp_clock_info.n_ext_ts = 0;
  11214. bp->ptp_clock_info.n_per_out = 0;
  11215. bp->ptp_clock_info.pps = 0;
  11216. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11217. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11218. bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime;
  11219. bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
  11220. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11221. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11222. if (IS_ERR(bp->ptp_clock)) {
  11223. bp->ptp_clock = NULL;
  11224. BNX2X_ERR("PTP clock registeration failed\n");
  11225. }
  11226. }
  11227. static int bnx2x_init_one(struct pci_dev *pdev,
  11228. const struct pci_device_id *ent)
  11229. {
  11230. struct net_device *dev = NULL;
  11231. struct bnx2x *bp;
  11232. enum pcie_link_width pcie_width;
  11233. enum pci_bus_speed pcie_speed;
  11234. int rc, max_non_def_sbs;
  11235. int rx_count, tx_count, rss_count, doorbell_size;
  11236. int max_cos_est;
  11237. bool is_vf;
  11238. int cnic_cnt;
  11239. /* Management FW 'remembers' living interfaces. Allow it some time
  11240. * to forget previously living interfaces, allowing a proper re-load.
  11241. */
  11242. if (is_kdump_kernel()) {
  11243. ktime_t now = ktime_get_boottime();
  11244. ktime_t fw_ready_time = ktime_set(5, 0);
  11245. if (ktime_before(now, fw_ready_time))
  11246. msleep(ktime_ms_delta(fw_ready_time, now));
  11247. }
  11248. /* An estimated maximum supported CoS number according to the chip
  11249. * version.
  11250. * We will try to roughly estimate the maximum number of CoSes this chip
  11251. * may support in order to minimize the memory allocated for Tx
  11252. * netdev_queue's. This number will be accurately calculated during the
  11253. * initialization of bp->max_cos based on the chip versions AND chip
  11254. * revision in the bnx2x_init_bp().
  11255. */
  11256. max_cos_est = set_max_cos_est(ent->driver_data);
  11257. if (max_cos_est < 0)
  11258. return max_cos_est;
  11259. is_vf = set_is_vf(ent->driver_data);
  11260. cnic_cnt = is_vf ? 0 : 1;
  11261. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11262. /* add another SB for VF as it has no default SB */
  11263. max_non_def_sbs += is_vf ? 1 : 0;
  11264. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11265. rss_count = max_non_def_sbs - cnic_cnt;
  11266. if (rss_count < 1)
  11267. return -EINVAL;
  11268. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11269. rx_count = rss_count + cnic_cnt;
  11270. /* Maximum number of netdev Tx queues:
  11271. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11272. */
  11273. tx_count = rss_count * max_cos_est + cnic_cnt;
  11274. /* dev zeroed in init_etherdev */
  11275. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11276. if (!dev)
  11277. return -ENOMEM;
  11278. bp = netdev_priv(dev);
  11279. bp->flags = 0;
  11280. if (is_vf)
  11281. bp->flags |= IS_VF_FLAG;
  11282. bp->igu_sb_cnt = max_non_def_sbs;
  11283. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11284. bp->msg_enable = debug;
  11285. bp->cnic_support = cnic_cnt;
  11286. bp->cnic_probe = bnx2x_cnic_probe;
  11287. pci_set_drvdata(pdev, dev);
  11288. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11289. if (rc < 0) {
  11290. free_netdev(dev);
  11291. return rc;
  11292. }
  11293. BNX2X_DEV_INFO("This is a %s function\n",
  11294. IS_PF(bp) ? "physical" : "virtual");
  11295. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11296. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11297. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11298. tx_count, rx_count);
  11299. rc = bnx2x_init_bp(bp);
  11300. if (rc)
  11301. goto init_one_exit;
  11302. /* Map doorbells here as we need the real value of bp->max_cos which
  11303. * is initialized in bnx2x_init_bp() to determine the number of
  11304. * l2 connections.
  11305. */
  11306. if (IS_VF(bp)) {
  11307. bp->doorbells = bnx2x_vf_doorbells(bp);
  11308. rc = bnx2x_vf_pci_alloc(bp);
  11309. if (rc)
  11310. goto init_one_exit;
  11311. } else {
  11312. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11313. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11314. dev_err(&bp->pdev->dev,
  11315. "Cannot map doorbells, bar size too small, aborting\n");
  11316. rc = -ENOMEM;
  11317. goto init_one_exit;
  11318. }
  11319. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11320. doorbell_size);
  11321. }
  11322. if (!bp->doorbells) {
  11323. dev_err(&bp->pdev->dev,
  11324. "Cannot map doorbell space, aborting\n");
  11325. rc = -ENOMEM;
  11326. goto init_one_exit;
  11327. }
  11328. if (IS_VF(bp)) {
  11329. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11330. if (rc)
  11331. goto init_one_exit;
  11332. }
  11333. /* Enable SRIOV if capability found in configuration space */
  11334. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11335. if (rc)
  11336. goto init_one_exit;
  11337. /* calc qm_cid_count */
  11338. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11339. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11340. /* disable FCOE L2 queue for E1x*/
  11341. if (CHIP_IS_E1x(bp))
  11342. bp->flags |= NO_FCOE_FLAG;
  11343. /* Set bp->num_queues for MSI-X mode*/
  11344. bnx2x_set_num_queues(bp);
  11345. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11346. * needed.
  11347. */
  11348. rc = bnx2x_set_int_mode(bp);
  11349. if (rc) {
  11350. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11351. goto init_one_exit;
  11352. }
  11353. BNX2X_DEV_INFO("set interrupts successfully\n");
  11354. /* register the net device */
  11355. rc = register_netdev(dev);
  11356. if (rc) {
  11357. dev_err(&pdev->dev, "Cannot register net device\n");
  11358. goto init_one_exit;
  11359. }
  11360. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11361. if (!NO_FCOE(bp)) {
  11362. /* Add storage MAC address */
  11363. rtnl_lock();
  11364. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11365. rtnl_unlock();
  11366. }
  11367. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11368. pcie_speed == PCI_SPEED_UNKNOWN ||
  11369. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11370. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11371. else
  11372. BNX2X_DEV_INFO(
  11373. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11374. board_info[ent->driver_data].name,
  11375. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11376. pcie_width,
  11377. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11378. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11379. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11380. "Unknown",
  11381. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11382. bnx2x_register_phc(bp);
  11383. return 0;
  11384. init_one_exit:
  11385. bnx2x_disable_pcie_error_reporting(bp);
  11386. if (bp->regview)
  11387. iounmap(bp->regview);
  11388. if (IS_PF(bp) && bp->doorbells)
  11389. iounmap(bp->doorbells);
  11390. free_netdev(dev);
  11391. if (atomic_read(&pdev->enable_cnt) == 1)
  11392. pci_release_regions(pdev);
  11393. pci_disable_device(pdev);
  11394. return rc;
  11395. }
  11396. static void __bnx2x_remove(struct pci_dev *pdev,
  11397. struct net_device *dev,
  11398. struct bnx2x *bp,
  11399. bool remove_netdev)
  11400. {
  11401. if (bp->ptp_clock) {
  11402. ptp_clock_unregister(bp->ptp_clock);
  11403. bp->ptp_clock = NULL;
  11404. }
  11405. /* Delete storage MAC address */
  11406. if (!NO_FCOE(bp)) {
  11407. rtnl_lock();
  11408. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11409. rtnl_unlock();
  11410. }
  11411. #ifdef BCM_DCBNL
  11412. /* Delete app tlvs from dcbnl */
  11413. bnx2x_dcbnl_update_applist(bp, true);
  11414. #endif
  11415. if (IS_PF(bp) &&
  11416. !BP_NOMCP(bp) &&
  11417. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11418. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11419. /* Close the interface - either directly or implicitly */
  11420. if (remove_netdev) {
  11421. unregister_netdev(dev);
  11422. } else {
  11423. rtnl_lock();
  11424. dev_close(dev);
  11425. rtnl_unlock();
  11426. }
  11427. bnx2x_iov_remove_one(bp);
  11428. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11429. if (IS_PF(bp)) {
  11430. bnx2x_set_power_state(bp, PCI_D0);
  11431. /* Set endianity registers to reset values in case next driver
  11432. * boots in different endianty environment.
  11433. */
  11434. bnx2x_reset_endianity(bp);
  11435. }
  11436. /* Disable MSI/MSI-X */
  11437. bnx2x_disable_msi(bp);
  11438. /* Power off */
  11439. if (IS_PF(bp))
  11440. bnx2x_set_power_state(bp, PCI_D3hot);
  11441. /* Make sure RESET task is not scheduled before continuing */
  11442. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11443. /* send message via vfpf channel to release the resources of this vf */
  11444. if (IS_VF(bp))
  11445. bnx2x_vfpf_release(bp);
  11446. /* Assumes no further PCIe PM changes will occur */
  11447. if (system_state == SYSTEM_POWER_OFF) {
  11448. pci_wake_from_d3(pdev, bp->wol);
  11449. pci_set_power_state(pdev, PCI_D3hot);
  11450. }
  11451. bnx2x_disable_pcie_error_reporting(bp);
  11452. if (remove_netdev) {
  11453. if (bp->regview)
  11454. iounmap(bp->regview);
  11455. /* For vfs, doorbells are part of the regview and were unmapped
  11456. * along with it. FW is only loaded by PF.
  11457. */
  11458. if (IS_PF(bp)) {
  11459. if (bp->doorbells)
  11460. iounmap(bp->doorbells);
  11461. bnx2x_release_firmware(bp);
  11462. } else {
  11463. bnx2x_vf_pci_dealloc(bp);
  11464. }
  11465. bnx2x_free_mem_bp(bp);
  11466. free_netdev(dev);
  11467. if (atomic_read(&pdev->enable_cnt) == 1)
  11468. pci_release_regions(pdev);
  11469. pci_disable_device(pdev);
  11470. }
  11471. }
  11472. static void bnx2x_remove_one(struct pci_dev *pdev)
  11473. {
  11474. struct net_device *dev = pci_get_drvdata(pdev);
  11475. struct bnx2x *bp;
  11476. if (!dev) {
  11477. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11478. return;
  11479. }
  11480. bp = netdev_priv(dev);
  11481. __bnx2x_remove(pdev, dev, bp, true);
  11482. }
  11483. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11484. {
  11485. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11486. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11487. if (CNIC_LOADED(bp))
  11488. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11489. /* Stop Tx */
  11490. bnx2x_tx_disable(bp);
  11491. /* Delete all NAPI objects */
  11492. bnx2x_del_all_napi(bp);
  11493. if (CNIC_LOADED(bp))
  11494. bnx2x_del_all_napi_cnic(bp);
  11495. netdev_reset_tc(bp->dev);
  11496. del_timer_sync(&bp->timer);
  11497. cancel_delayed_work_sync(&bp->sp_task);
  11498. cancel_delayed_work_sync(&bp->period_task);
  11499. if (!down_timeout(&bp->stats_lock, HZ / 10)) {
  11500. bp->stats_state = STATS_STATE_DISABLED;
  11501. up(&bp->stats_lock);
  11502. }
  11503. bnx2x_save_statistics(bp);
  11504. netif_carrier_off(bp->dev);
  11505. return 0;
  11506. }
  11507. /**
  11508. * bnx2x_io_error_detected - called when PCI error is detected
  11509. * @pdev: Pointer to PCI device
  11510. * @state: The current pci connection state
  11511. *
  11512. * This function is called after a PCI bus error affecting
  11513. * this device has been detected.
  11514. */
  11515. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11516. pci_channel_state_t state)
  11517. {
  11518. struct net_device *dev = pci_get_drvdata(pdev);
  11519. struct bnx2x *bp = netdev_priv(dev);
  11520. rtnl_lock();
  11521. BNX2X_ERR("IO error detected\n");
  11522. netif_device_detach(dev);
  11523. if (state == pci_channel_io_perm_failure) {
  11524. rtnl_unlock();
  11525. return PCI_ERS_RESULT_DISCONNECT;
  11526. }
  11527. if (netif_running(dev))
  11528. bnx2x_eeh_nic_unload(bp);
  11529. bnx2x_prev_path_mark_eeh(bp);
  11530. pci_disable_device(pdev);
  11531. rtnl_unlock();
  11532. /* Request a slot reset */
  11533. return PCI_ERS_RESULT_NEED_RESET;
  11534. }
  11535. /**
  11536. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11537. * @pdev: Pointer to PCI device
  11538. *
  11539. * Restart the card from scratch, as if from a cold-boot.
  11540. */
  11541. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11542. {
  11543. struct net_device *dev = pci_get_drvdata(pdev);
  11544. struct bnx2x *bp = netdev_priv(dev);
  11545. int i;
  11546. rtnl_lock();
  11547. BNX2X_ERR("IO slot reset initializing...\n");
  11548. if (pci_enable_device(pdev)) {
  11549. dev_err(&pdev->dev,
  11550. "Cannot re-enable PCI device after reset\n");
  11551. rtnl_unlock();
  11552. return PCI_ERS_RESULT_DISCONNECT;
  11553. }
  11554. pci_set_master(pdev);
  11555. pci_restore_state(pdev);
  11556. pci_save_state(pdev);
  11557. if (netif_running(dev))
  11558. bnx2x_set_power_state(bp, PCI_D0);
  11559. if (netif_running(dev)) {
  11560. BNX2X_ERR("IO slot reset --> driver unload\n");
  11561. /* MCP should have been reset; Need to wait for validity */
  11562. bnx2x_init_shmem(bp);
  11563. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11564. u32 v;
  11565. v = SHMEM2_RD(bp,
  11566. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11567. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11568. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11569. }
  11570. bnx2x_drain_tx_queues(bp);
  11571. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11572. bnx2x_netif_stop(bp, 1);
  11573. bnx2x_free_irq(bp);
  11574. /* Report UNLOAD_DONE to MCP */
  11575. bnx2x_send_unload_done(bp, true);
  11576. bp->sp_state = 0;
  11577. bp->port.pmf = 0;
  11578. bnx2x_prev_unload(bp);
  11579. /* We should have reseted the engine, so It's fair to
  11580. * assume the FW will no longer write to the bnx2x driver.
  11581. */
  11582. bnx2x_squeeze_objects(bp);
  11583. bnx2x_free_skbs(bp);
  11584. for_each_rx_queue(bp, i)
  11585. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11586. bnx2x_free_fp_mem(bp);
  11587. bnx2x_free_mem(bp);
  11588. bp->state = BNX2X_STATE_CLOSED;
  11589. }
  11590. rtnl_unlock();
  11591. /* If AER, perform cleanup of the PCIe registers */
  11592. if (bp->flags & AER_ENABLED) {
  11593. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11594. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11595. else
  11596. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11597. }
  11598. return PCI_ERS_RESULT_RECOVERED;
  11599. }
  11600. /**
  11601. * bnx2x_io_resume - called when traffic can start flowing again
  11602. * @pdev: Pointer to PCI device
  11603. *
  11604. * This callback is called when the error recovery driver tells us that
  11605. * its OK to resume normal operation.
  11606. */
  11607. static void bnx2x_io_resume(struct pci_dev *pdev)
  11608. {
  11609. struct net_device *dev = pci_get_drvdata(pdev);
  11610. struct bnx2x *bp = netdev_priv(dev);
  11611. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11612. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11613. return;
  11614. }
  11615. rtnl_lock();
  11616. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11617. DRV_MSG_SEQ_NUMBER_MASK;
  11618. if (netif_running(dev))
  11619. bnx2x_nic_load(bp, LOAD_NORMAL);
  11620. netif_device_attach(dev);
  11621. rtnl_unlock();
  11622. }
  11623. static const struct pci_error_handlers bnx2x_err_handler = {
  11624. .error_detected = bnx2x_io_error_detected,
  11625. .slot_reset = bnx2x_io_slot_reset,
  11626. .resume = bnx2x_io_resume,
  11627. };
  11628. static void bnx2x_shutdown(struct pci_dev *pdev)
  11629. {
  11630. struct net_device *dev = pci_get_drvdata(pdev);
  11631. struct bnx2x *bp;
  11632. if (!dev)
  11633. return;
  11634. bp = netdev_priv(dev);
  11635. if (!bp)
  11636. return;
  11637. rtnl_lock();
  11638. netif_device_detach(dev);
  11639. rtnl_unlock();
  11640. /* Don't remove the netdevice, as there are scenarios which will cause
  11641. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11642. * rootfs is mounted from SAN.
  11643. */
  11644. __bnx2x_remove(pdev, dev, bp, false);
  11645. }
  11646. static struct pci_driver bnx2x_pci_driver = {
  11647. .name = DRV_MODULE_NAME,
  11648. .id_table = bnx2x_pci_tbl,
  11649. .probe = bnx2x_init_one,
  11650. .remove = bnx2x_remove_one,
  11651. .suspend = bnx2x_suspend,
  11652. .resume = bnx2x_resume,
  11653. .err_handler = &bnx2x_err_handler,
  11654. #ifdef CONFIG_BNX2X_SRIOV
  11655. .sriov_configure = bnx2x_sriov_configure,
  11656. #endif
  11657. .shutdown = bnx2x_shutdown,
  11658. };
  11659. static int __init bnx2x_init(void)
  11660. {
  11661. int ret;
  11662. pr_info("%s", version);
  11663. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11664. if (bnx2x_wq == NULL) {
  11665. pr_err("Cannot create workqueue\n");
  11666. return -ENOMEM;
  11667. }
  11668. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11669. if (!bnx2x_iov_wq) {
  11670. pr_err("Cannot create iov workqueue\n");
  11671. destroy_workqueue(bnx2x_wq);
  11672. return -ENOMEM;
  11673. }
  11674. ret = pci_register_driver(&bnx2x_pci_driver);
  11675. if (ret) {
  11676. pr_err("Cannot register driver\n");
  11677. destroy_workqueue(bnx2x_wq);
  11678. destroy_workqueue(bnx2x_iov_wq);
  11679. }
  11680. return ret;
  11681. }
  11682. static void __exit bnx2x_cleanup(void)
  11683. {
  11684. struct list_head *pos, *q;
  11685. pci_unregister_driver(&bnx2x_pci_driver);
  11686. destroy_workqueue(bnx2x_wq);
  11687. destroy_workqueue(bnx2x_iov_wq);
  11688. /* Free globally allocated resources */
  11689. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11690. struct bnx2x_prev_path_list *tmp =
  11691. list_entry(pos, struct bnx2x_prev_path_list, list);
  11692. list_del(pos);
  11693. kfree(tmp);
  11694. }
  11695. }
  11696. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11697. {
  11698. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11699. }
  11700. module_init(bnx2x_init);
  11701. module_exit(bnx2x_cleanup);
  11702. /**
  11703. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11704. *
  11705. * @bp: driver handle
  11706. * @set: set or clear the CAM entry
  11707. *
  11708. * This function will wait until the ramrod completion returns.
  11709. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11710. */
  11711. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11712. {
  11713. unsigned long ramrod_flags = 0;
  11714. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11715. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11716. &bp->iscsi_l2_mac_obj, true,
  11717. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11718. }
  11719. /* count denotes the number of new completions we have seen */
  11720. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11721. {
  11722. struct eth_spe *spe;
  11723. int cxt_index, cxt_offset;
  11724. #ifdef BNX2X_STOP_ON_ERROR
  11725. if (unlikely(bp->panic))
  11726. return;
  11727. #endif
  11728. spin_lock_bh(&bp->spq_lock);
  11729. BUG_ON(bp->cnic_spq_pending < count);
  11730. bp->cnic_spq_pending -= count;
  11731. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11732. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11733. & SPE_HDR_CONN_TYPE) >>
  11734. SPE_HDR_CONN_TYPE_SHIFT;
  11735. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11736. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11737. /* Set validation for iSCSI L2 client before sending SETUP
  11738. * ramrod
  11739. */
  11740. if (type == ETH_CONNECTION_TYPE) {
  11741. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11742. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11743. ILT_PAGE_CIDS;
  11744. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11745. (cxt_index * ILT_PAGE_CIDS);
  11746. bnx2x_set_ctx_validation(bp,
  11747. &bp->context[cxt_index].
  11748. vcxt[cxt_offset].eth,
  11749. BNX2X_ISCSI_ETH_CID(bp));
  11750. }
  11751. }
  11752. /*
  11753. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11754. * and in the air. We also check that number of outstanding
  11755. * COMMON ramrods is not more than the EQ and SPQ can
  11756. * accommodate.
  11757. */
  11758. if (type == ETH_CONNECTION_TYPE) {
  11759. if (!atomic_read(&bp->cq_spq_left))
  11760. break;
  11761. else
  11762. atomic_dec(&bp->cq_spq_left);
  11763. } else if (type == NONE_CONNECTION_TYPE) {
  11764. if (!atomic_read(&bp->eq_spq_left))
  11765. break;
  11766. else
  11767. atomic_dec(&bp->eq_spq_left);
  11768. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11769. (type == FCOE_CONNECTION_TYPE)) {
  11770. if (bp->cnic_spq_pending >=
  11771. bp->cnic_eth_dev.max_kwqe_pending)
  11772. break;
  11773. else
  11774. bp->cnic_spq_pending++;
  11775. } else {
  11776. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11777. bnx2x_panic();
  11778. break;
  11779. }
  11780. spe = bnx2x_sp_get_next(bp);
  11781. *spe = *bp->cnic_kwq_cons;
  11782. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11783. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11784. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11785. bp->cnic_kwq_cons = bp->cnic_kwq;
  11786. else
  11787. bp->cnic_kwq_cons++;
  11788. }
  11789. bnx2x_sp_prod_update(bp);
  11790. spin_unlock_bh(&bp->spq_lock);
  11791. }
  11792. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11793. struct kwqe_16 *kwqes[], u32 count)
  11794. {
  11795. struct bnx2x *bp = netdev_priv(dev);
  11796. int i;
  11797. #ifdef BNX2X_STOP_ON_ERROR
  11798. if (unlikely(bp->panic)) {
  11799. BNX2X_ERR("Can't post to SP queue while panic\n");
  11800. return -EIO;
  11801. }
  11802. #endif
  11803. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11804. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11805. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11806. return -EAGAIN;
  11807. }
  11808. spin_lock_bh(&bp->spq_lock);
  11809. for (i = 0; i < count; i++) {
  11810. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11811. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11812. break;
  11813. *bp->cnic_kwq_prod = *spe;
  11814. bp->cnic_kwq_pending++;
  11815. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11816. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11817. spe->data.update_data_addr.hi,
  11818. spe->data.update_data_addr.lo,
  11819. bp->cnic_kwq_pending);
  11820. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11821. bp->cnic_kwq_prod = bp->cnic_kwq;
  11822. else
  11823. bp->cnic_kwq_prod++;
  11824. }
  11825. spin_unlock_bh(&bp->spq_lock);
  11826. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11827. bnx2x_cnic_sp_post(bp, 0);
  11828. return i;
  11829. }
  11830. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11831. {
  11832. struct cnic_ops *c_ops;
  11833. int rc = 0;
  11834. mutex_lock(&bp->cnic_mutex);
  11835. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11836. lockdep_is_held(&bp->cnic_mutex));
  11837. if (c_ops)
  11838. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11839. mutex_unlock(&bp->cnic_mutex);
  11840. return rc;
  11841. }
  11842. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11843. {
  11844. struct cnic_ops *c_ops;
  11845. int rc = 0;
  11846. rcu_read_lock();
  11847. c_ops = rcu_dereference(bp->cnic_ops);
  11848. if (c_ops)
  11849. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11850. rcu_read_unlock();
  11851. return rc;
  11852. }
  11853. /*
  11854. * for commands that have no data
  11855. */
  11856. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11857. {
  11858. struct cnic_ctl_info ctl = {0};
  11859. ctl.cmd = cmd;
  11860. return bnx2x_cnic_ctl_send(bp, &ctl);
  11861. }
  11862. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11863. {
  11864. struct cnic_ctl_info ctl = {0};
  11865. /* first we tell CNIC and only then we count this as a completion */
  11866. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11867. ctl.data.comp.cid = cid;
  11868. ctl.data.comp.error = err;
  11869. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11870. bnx2x_cnic_sp_post(bp, 0);
  11871. }
  11872. /* Called with netif_addr_lock_bh() taken.
  11873. * Sets an rx_mode config for an iSCSI ETH client.
  11874. * Doesn't block.
  11875. * Completion should be checked outside.
  11876. */
  11877. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11878. {
  11879. unsigned long accept_flags = 0, ramrod_flags = 0;
  11880. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11881. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11882. if (start) {
  11883. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11884. * because it's the only way for UIO Queue to accept
  11885. * multicasts (in non-promiscuous mode only one Queue per
  11886. * function will receive multicast packets (leading in our
  11887. * case).
  11888. */
  11889. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11890. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11891. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11892. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11893. /* Clear STOP_PENDING bit if START is requested */
  11894. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11895. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11896. } else
  11897. /* Clear START_PENDING bit if STOP is requested */
  11898. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11899. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11900. set_bit(sched_state, &bp->sp_state);
  11901. else {
  11902. __set_bit(RAMROD_RX, &ramrod_flags);
  11903. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11904. ramrod_flags);
  11905. }
  11906. }
  11907. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11908. {
  11909. struct bnx2x *bp = netdev_priv(dev);
  11910. int rc = 0;
  11911. switch (ctl->cmd) {
  11912. case DRV_CTL_CTXTBL_WR_CMD: {
  11913. u32 index = ctl->data.io.offset;
  11914. dma_addr_t addr = ctl->data.io.dma_addr;
  11915. bnx2x_ilt_wr(bp, index, addr);
  11916. break;
  11917. }
  11918. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11919. int count = ctl->data.credit.credit_count;
  11920. bnx2x_cnic_sp_post(bp, count);
  11921. break;
  11922. }
  11923. /* rtnl_lock is held. */
  11924. case DRV_CTL_START_L2_CMD: {
  11925. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11926. unsigned long sp_bits = 0;
  11927. /* Configure the iSCSI classification object */
  11928. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11929. cp->iscsi_l2_client_id,
  11930. cp->iscsi_l2_cid, BP_FUNC(bp),
  11931. bnx2x_sp(bp, mac_rdata),
  11932. bnx2x_sp_mapping(bp, mac_rdata),
  11933. BNX2X_FILTER_MAC_PENDING,
  11934. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11935. &bp->macs_pool);
  11936. /* Set iSCSI MAC address */
  11937. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11938. if (rc)
  11939. break;
  11940. mmiowb();
  11941. barrier();
  11942. /* Start accepting on iSCSI L2 ring */
  11943. netif_addr_lock_bh(dev);
  11944. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11945. netif_addr_unlock_bh(dev);
  11946. /* bits to wait on */
  11947. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11948. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11949. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11950. BNX2X_ERR("rx_mode completion timed out!\n");
  11951. break;
  11952. }
  11953. /* rtnl_lock is held. */
  11954. case DRV_CTL_STOP_L2_CMD: {
  11955. unsigned long sp_bits = 0;
  11956. /* Stop accepting on iSCSI L2 ring */
  11957. netif_addr_lock_bh(dev);
  11958. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11959. netif_addr_unlock_bh(dev);
  11960. /* bits to wait on */
  11961. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11962. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11963. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11964. BNX2X_ERR("rx_mode completion timed out!\n");
  11965. mmiowb();
  11966. barrier();
  11967. /* Unset iSCSI L2 MAC */
  11968. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11969. BNX2X_ISCSI_ETH_MAC, true);
  11970. break;
  11971. }
  11972. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11973. int count = ctl->data.credit.credit_count;
  11974. smp_mb__before_atomic();
  11975. atomic_add(count, &bp->cq_spq_left);
  11976. smp_mb__after_atomic();
  11977. break;
  11978. }
  11979. case DRV_CTL_ULP_REGISTER_CMD: {
  11980. int ulp_type = ctl->data.register_data.ulp_type;
  11981. if (CHIP_IS_E3(bp)) {
  11982. int idx = BP_FW_MB_IDX(bp);
  11983. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11984. int path = BP_PATH(bp);
  11985. int port = BP_PORT(bp);
  11986. int i;
  11987. u32 scratch_offset;
  11988. u32 *host_addr;
  11989. /* first write capability to shmem2 */
  11990. if (ulp_type == CNIC_ULP_ISCSI)
  11991. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11992. else if (ulp_type == CNIC_ULP_FCOE)
  11993. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11994. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11995. if ((ulp_type != CNIC_ULP_FCOE) ||
  11996. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11997. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11998. break;
  11999. /* if reached here - should write fcoe capabilities */
  12000. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  12001. if (!scratch_offset)
  12002. break;
  12003. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  12004. fcoe_features[path][port]);
  12005. host_addr = (u32 *) &(ctl->data.register_data.
  12006. fcoe_features);
  12007. for (i = 0; i < sizeof(struct fcoe_capabilities);
  12008. i += 4)
  12009. REG_WR(bp, scratch_offset + i,
  12010. *(host_addr + i/4));
  12011. }
  12012. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12013. break;
  12014. }
  12015. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12016. int ulp_type = ctl->data.ulp_type;
  12017. if (CHIP_IS_E3(bp)) {
  12018. int idx = BP_FW_MB_IDX(bp);
  12019. u32 cap;
  12020. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12021. if (ulp_type == CNIC_ULP_ISCSI)
  12022. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12023. else if (ulp_type == CNIC_ULP_FCOE)
  12024. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12025. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12026. }
  12027. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12028. break;
  12029. }
  12030. default:
  12031. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12032. rc = -EINVAL;
  12033. }
  12034. return rc;
  12035. }
  12036. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12037. {
  12038. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12039. if (bp->flags & USING_MSIX_FLAG) {
  12040. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12041. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12042. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12043. } else {
  12044. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12045. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12046. }
  12047. if (!CHIP_IS_E1x(bp))
  12048. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12049. else
  12050. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12051. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12052. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12053. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12054. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12055. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12056. cp->num_irq = 2;
  12057. }
  12058. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12059. {
  12060. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12061. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12062. bnx2x_cid_ilt_lines(bp);
  12063. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12064. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12065. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12066. DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
  12067. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12068. cp->iscsi_l2_cid);
  12069. if (NO_ISCSI_OOO(bp))
  12070. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12071. }
  12072. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12073. void *data)
  12074. {
  12075. struct bnx2x *bp = netdev_priv(dev);
  12076. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12077. int rc;
  12078. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12079. if (ops == NULL) {
  12080. BNX2X_ERR("NULL ops received\n");
  12081. return -EINVAL;
  12082. }
  12083. if (!CNIC_SUPPORT(bp)) {
  12084. BNX2X_ERR("Can't register CNIC when not supported\n");
  12085. return -EOPNOTSUPP;
  12086. }
  12087. if (!CNIC_LOADED(bp)) {
  12088. rc = bnx2x_load_cnic(bp);
  12089. if (rc) {
  12090. BNX2X_ERR("CNIC-related load failed\n");
  12091. return rc;
  12092. }
  12093. }
  12094. bp->cnic_enabled = true;
  12095. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12096. if (!bp->cnic_kwq)
  12097. return -ENOMEM;
  12098. bp->cnic_kwq_cons = bp->cnic_kwq;
  12099. bp->cnic_kwq_prod = bp->cnic_kwq;
  12100. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12101. bp->cnic_spq_pending = 0;
  12102. bp->cnic_kwq_pending = 0;
  12103. bp->cnic_data = data;
  12104. cp->num_irq = 0;
  12105. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12106. cp->iro_arr = bp->iro_arr;
  12107. bnx2x_setup_cnic_irq_info(bp);
  12108. rcu_assign_pointer(bp->cnic_ops, ops);
  12109. /* Schedule driver to read CNIC driver versions */
  12110. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12111. return 0;
  12112. }
  12113. static int bnx2x_unregister_cnic(struct net_device *dev)
  12114. {
  12115. struct bnx2x *bp = netdev_priv(dev);
  12116. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12117. mutex_lock(&bp->cnic_mutex);
  12118. cp->drv_state = 0;
  12119. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12120. mutex_unlock(&bp->cnic_mutex);
  12121. synchronize_rcu();
  12122. bp->cnic_enabled = false;
  12123. kfree(bp->cnic_kwq);
  12124. bp->cnic_kwq = NULL;
  12125. return 0;
  12126. }
  12127. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12128. {
  12129. struct bnx2x *bp = netdev_priv(dev);
  12130. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12131. /* If both iSCSI and FCoE are disabled - return NULL in
  12132. * order to indicate CNIC that it should not try to work
  12133. * with this device.
  12134. */
  12135. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12136. return NULL;
  12137. cp->drv_owner = THIS_MODULE;
  12138. cp->chip_id = CHIP_ID(bp);
  12139. cp->pdev = bp->pdev;
  12140. cp->io_base = bp->regview;
  12141. cp->io_base2 = bp->doorbells;
  12142. cp->max_kwqe_pending = 8;
  12143. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12144. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12145. bnx2x_cid_ilt_lines(bp);
  12146. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12147. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12148. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12149. cp->drv_ctl = bnx2x_drv_ctl;
  12150. cp->drv_register_cnic = bnx2x_register_cnic;
  12151. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12152. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12153. cp->iscsi_l2_client_id =
  12154. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12155. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12156. if (NO_ISCSI_OOO(bp))
  12157. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12158. if (NO_ISCSI(bp))
  12159. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12160. if (NO_FCOE(bp))
  12161. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12162. BNX2X_DEV_INFO(
  12163. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12164. cp->ctx_blk_size,
  12165. cp->ctx_tbl_offset,
  12166. cp->ctx_tbl_len,
  12167. cp->starting_cid);
  12168. return cp;
  12169. }
  12170. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12171. {
  12172. struct bnx2x *bp = fp->bp;
  12173. u32 offset = BAR_USTRORM_INTMEM;
  12174. if (IS_VF(bp))
  12175. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12176. else if (!CHIP_IS_E1x(bp))
  12177. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12178. else
  12179. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12180. return offset;
  12181. }
  12182. /* called only on E1H or E2.
  12183. * When pretending to be PF, the pretend value is the function number 0...7
  12184. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12185. * combination
  12186. */
  12187. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12188. {
  12189. u32 pretend_reg;
  12190. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12191. return -1;
  12192. /* get my own pretend register */
  12193. pretend_reg = bnx2x_get_pretend_reg(bp);
  12194. REG_WR(bp, pretend_reg, pretend_func_val);
  12195. REG_RD(bp, pretend_reg);
  12196. return 0;
  12197. }
  12198. static void bnx2x_ptp_task(struct work_struct *work)
  12199. {
  12200. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12201. int port = BP_PORT(bp);
  12202. u32 val_seq;
  12203. u64 timestamp, ns;
  12204. struct skb_shared_hwtstamps shhwtstamps;
  12205. /* Read Tx timestamp registers */
  12206. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12207. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12208. if (val_seq & 0x10000) {
  12209. /* There is a valid timestamp value */
  12210. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12211. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12212. timestamp <<= 32;
  12213. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12214. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12215. /* Reset timestamp register to allow new timestamp */
  12216. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12217. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12218. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12219. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12220. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12221. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12222. dev_kfree_skb_any(bp->ptp_tx_skb);
  12223. bp->ptp_tx_skb = NULL;
  12224. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12225. timestamp, ns);
  12226. } else {
  12227. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12228. /* Reschedule to keep checking for a valid timestamp value */
  12229. schedule_work(&bp->ptp_task);
  12230. }
  12231. }
  12232. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12233. {
  12234. int port = BP_PORT(bp);
  12235. u64 timestamp, ns;
  12236. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12237. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12238. timestamp <<= 32;
  12239. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12240. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12241. /* Reset timestamp register to allow new timestamp */
  12242. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12243. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12244. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12245. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12246. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12247. timestamp, ns);
  12248. }
  12249. /* Read the PHC */
  12250. static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12251. {
  12252. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12253. int port = BP_PORT(bp);
  12254. u32 wb_data[2];
  12255. u64 phc_cycles;
  12256. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12257. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12258. phc_cycles = wb_data[1];
  12259. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12260. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12261. return phc_cycles;
  12262. }
  12263. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12264. {
  12265. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12266. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12267. bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
  12268. bp->cyclecounter.shift = 1;
  12269. bp->cyclecounter.mult = 1;
  12270. }
  12271. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12272. {
  12273. struct bnx2x_func_state_params func_params = {NULL};
  12274. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12275. &func_params.params.set_timesync;
  12276. /* Prepare parameters for function state transitions */
  12277. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12278. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12279. func_params.f_obj = &bp->func_obj;
  12280. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12281. /* Function parameters */
  12282. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12283. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12284. return bnx2x_func_state_change(bp, &func_params);
  12285. }
  12286. static int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12287. {
  12288. struct bnx2x_queue_state_params q_params;
  12289. int rc, i;
  12290. /* send queue update ramrod to enable PTP packets */
  12291. memset(&q_params, 0, sizeof(q_params));
  12292. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12293. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12294. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12295. &q_params.params.update.update_flags);
  12296. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12297. &q_params.params.update.update_flags);
  12298. /* send the ramrod on all the queues of the PF */
  12299. for_each_eth_queue(bp, i) {
  12300. struct bnx2x_fastpath *fp = &bp->fp[i];
  12301. /* Set the appropriate Queue object */
  12302. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12303. /* Update the Queue state */
  12304. rc = bnx2x_queue_state_change(bp, &q_params);
  12305. if (rc) {
  12306. BNX2X_ERR("Failed to enable PTP packets\n");
  12307. return rc;
  12308. }
  12309. }
  12310. return 0;
  12311. }
  12312. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12313. {
  12314. int port = BP_PORT(bp);
  12315. int rc;
  12316. if (!bp->hwtstamp_ioctl_called)
  12317. return 0;
  12318. switch (bp->tx_type) {
  12319. case HWTSTAMP_TX_ON:
  12320. bp->flags |= TX_TIMESTAMPING_EN;
  12321. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12322. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12323. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12324. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12325. break;
  12326. case HWTSTAMP_TX_ONESTEP_SYNC:
  12327. BNX2X_ERR("One-step timestamping is not supported\n");
  12328. return -ERANGE;
  12329. }
  12330. switch (bp->rx_filter) {
  12331. case HWTSTAMP_FILTER_NONE:
  12332. break;
  12333. case HWTSTAMP_FILTER_ALL:
  12334. case HWTSTAMP_FILTER_SOME:
  12335. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12336. break;
  12337. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12338. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12339. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12340. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12341. /* Initialize PTP detection for UDP/IPv4 events */
  12342. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12343. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12344. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12345. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12346. break;
  12347. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12348. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12349. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12350. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12351. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12352. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12353. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12354. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12355. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12356. break;
  12357. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12358. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12359. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12360. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12361. /* Initialize PTP detection L2 events */
  12362. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12363. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12364. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12365. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12366. break;
  12367. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12368. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12369. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12370. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12371. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12372. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12373. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12374. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12375. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12376. break;
  12377. }
  12378. /* Indicate to FW that this PF expects recorded PTP packets */
  12379. rc = bnx2x_enable_ptp_packets(bp);
  12380. if (rc)
  12381. return rc;
  12382. /* Enable sending PTP packets to host */
  12383. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12384. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12385. return 0;
  12386. }
  12387. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12388. {
  12389. struct hwtstamp_config config;
  12390. int rc;
  12391. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12392. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12393. return -EFAULT;
  12394. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12395. config.tx_type, config.rx_filter);
  12396. if (config.flags) {
  12397. BNX2X_ERR("config.flags is reserved for future use\n");
  12398. return -EINVAL;
  12399. }
  12400. bp->hwtstamp_ioctl_called = 1;
  12401. bp->tx_type = config.tx_type;
  12402. bp->rx_filter = config.rx_filter;
  12403. rc = bnx2x_configure_ptp_filters(bp);
  12404. if (rc)
  12405. return rc;
  12406. config.rx_filter = bp->rx_filter;
  12407. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12408. -EFAULT : 0;
  12409. }
  12410. /* Configures HW for PTP */
  12411. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12412. {
  12413. int rc, port = BP_PORT(bp);
  12414. u32 wb_data[2];
  12415. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12416. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12417. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12418. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12419. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12420. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12421. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12422. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12423. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12424. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12425. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12426. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12427. /* Enable the PTP feature */
  12428. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12429. NIG_REG_P0_PTP_EN, 0x3F);
  12430. /* Enable the free-running counter */
  12431. wb_data[0] = 0;
  12432. wb_data[1] = 0;
  12433. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12434. /* Reset drift register (offset register is not reset) */
  12435. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12436. if (rc) {
  12437. BNX2X_ERR("Failed to reset PHC drift register\n");
  12438. return -EFAULT;
  12439. }
  12440. /* Reset possibly old timestamps */
  12441. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12442. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12443. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12444. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12445. return 0;
  12446. }
  12447. /* Called during load, to initialize PTP-related stuff */
  12448. void bnx2x_init_ptp(struct bnx2x *bp)
  12449. {
  12450. int rc;
  12451. /* Configure PTP in HW */
  12452. rc = bnx2x_configure_ptp(bp);
  12453. if (rc) {
  12454. BNX2X_ERR("Stopping PTP initialization\n");
  12455. return;
  12456. }
  12457. /* Init work queue for Tx timestamping */
  12458. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12459. /* Init cyclecounter and timecounter. This is done only in the first
  12460. * load. If done in every load, PTP application will fail when doing
  12461. * unload / load (e.g. MTU change) while it is running.
  12462. */
  12463. if (!bp->timecounter_init_done) {
  12464. bnx2x_init_cyclecounter(bp);
  12465. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  12466. ktime_to_ns(ktime_get_real()));
  12467. bp->timecounter_init_done = 1;
  12468. }
  12469. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  12470. }