bnx2x_main.c 402 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850
  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/checksum.h>
  47. #include <net/ip6_checksum.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/crc32.h>
  50. #include <linux/crc32c.h>
  51. #include <linux/prefetch.h>
  52. #include <linux/zlib.h>
  53. #include <linux/io.h>
  54. #include <linux/semaphore.h>
  55. #include <linux/stringify.h>
  56. #include <linux/vmalloc.h>
  57. #include "bnx2x.h"
  58. #include "bnx2x_init.h"
  59. #include "bnx2x_init_ops.h"
  60. #include "bnx2x_cmn.h"
  61. #include "bnx2x_vfpf.h"
  62. #include "bnx2x_dcb.h"
  63. #include "bnx2x_sp.h"
  64. #include <linux/firmware.h>
  65. #include "bnx2x_fw_file_hdr.h"
  66. /* FW files */
  67. #define FW_FILE_VERSION \
  68. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  69. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  70. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  71. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  72. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  73. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  74. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  75. /* Time in jiffies before concluding the transmitter is hung */
  76. #define TX_TIMEOUT (5*HZ)
  77. static char version[] =
  78. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  79. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  80. MODULE_AUTHOR("Eliezer Tamir");
  81. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  82. "BCM57710/57711/57711E/"
  83. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  84. "57840/57840_MF Driver");
  85. MODULE_LICENSE("GPL");
  86. MODULE_VERSION(DRV_MODULE_VERSION);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  89. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  90. int bnx2x_num_queues;
  91. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  92. MODULE_PARM_DESC(num_queues,
  93. " Set number of queues (default is as a number of CPUs)");
  94. static int disable_tpa;
  95. module_param(disable_tpa, int, S_IRUGO);
  96. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  97. static int int_mode;
  98. module_param(int_mode, int, S_IRUGO);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, S_IRUGO);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, S_IRUGO);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, S_IRUGO);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. static struct workqueue_struct *bnx2x_wq;
  111. struct workqueue_struct *bnx2x_iov_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static const struct pci_device_id bnx2x_pci_tbl[] = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /* Forward declaration */
  264. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  265. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  266. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  267. /****************************************************************************
  268. * General service functions
  269. ****************************************************************************/
  270. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  271. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  272. u32 addr, dma_addr_t mapping)
  273. {
  274. REG_WR(bp, addr, U64_LO(mapping));
  275. REG_WR(bp, addr + 4, U64_HI(mapping));
  276. }
  277. static void storm_memset_spq_addr(struct bnx2x *bp,
  278. dma_addr_t mapping, u16 abs_fid)
  279. {
  280. u32 addr = XSEM_REG_FAST_MEMORY +
  281. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  282. __storm_memset_dma_mapping(bp, addr, mapping);
  283. }
  284. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  285. u16 pf_id)
  286. {
  287. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  290. pf_id);
  291. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  292. pf_id);
  293. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  294. pf_id);
  295. }
  296. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  297. u8 enable)
  298. {
  299. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  302. enable);
  303. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  304. enable);
  305. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  306. enable);
  307. }
  308. static void storm_memset_eq_data(struct bnx2x *bp,
  309. struct event_ring_data *eq_data,
  310. u16 pfid)
  311. {
  312. size_t size = sizeof(struct event_ring_data);
  313. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  314. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  315. }
  316. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  317. u16 pfid)
  318. {
  319. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  320. REG_WR16(bp, addr, eq_prod);
  321. }
  322. /* used only at init
  323. * locking is done by mcp
  324. */
  325. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  326. {
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. }
  332. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  333. {
  334. u32 val;
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  336. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  337. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  338. PCICFG_VENDOR_ID_OFFSET);
  339. return val;
  340. }
  341. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  342. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  343. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  344. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  345. #define DMAE_DP_DST_NONE "dst_addr [none]"
  346. static void bnx2x_dp_dmae(struct bnx2x *bp,
  347. struct dmae_command *dmae, int msglvl)
  348. {
  349. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  350. int i;
  351. switch (dmae->opcode & DMAE_COMMAND_DST) {
  352. case DMAE_CMD_DST_PCI:
  353. if (src_type == DMAE_CMD_SRC_PCI)
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. else
  362. DP(msglvl, "DMAE: opcode 0x%08x\n"
  363. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  364. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  365. dmae->opcode, dmae->src_addr_lo >> 2,
  366. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  367. dmae->comp_addr_hi, dmae->comp_addr_lo,
  368. dmae->comp_val);
  369. break;
  370. case DMAE_CMD_DST_GRC:
  371. if (src_type == DMAE_CMD_SRC_PCI)
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. else
  380. DP(msglvl, "DMAE: opcode 0x%08x\n"
  381. "src [%08x], len [%d*4], dst [%08x]\n"
  382. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  383. dmae->opcode, dmae->src_addr_lo >> 2,
  384. dmae->len, dmae->dst_addr_lo >> 2,
  385. dmae->comp_addr_hi, dmae->comp_addr_lo,
  386. dmae->comp_val);
  387. break;
  388. default:
  389. if (src_type == DMAE_CMD_SRC_PCI)
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. else
  397. DP(msglvl, "DMAE: opcode 0x%08x\n"
  398. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  399. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  400. dmae->opcode, dmae->src_addr_lo >> 2,
  401. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  402. dmae->comp_val);
  403. break;
  404. }
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  406. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  407. i, *(((u32 *)dmae) + i));
  408. }
  409. /* copy command into DMAE command memory and set DMAE command go */
  410. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  411. {
  412. u32 cmd_offset;
  413. int i;
  414. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  415. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  416. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  417. }
  418. REG_WR(bp, dmae_reg_go_c[idx], 1);
  419. }
  420. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  421. {
  422. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  423. DMAE_CMD_C_ENABLE);
  424. }
  425. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  426. {
  427. return opcode & ~DMAE_CMD_SRC_RESET;
  428. }
  429. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  430. bool with_comp, u8 comp_type)
  431. {
  432. u32 opcode = 0;
  433. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  434. (dst_type << DMAE_COMMAND_DST_SHIFT));
  435. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  436. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  437. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  438. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  439. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  440. #ifdef __BIG_ENDIAN
  441. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  442. #else
  443. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  444. #endif
  445. if (with_comp)
  446. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  447. return opcode;
  448. }
  449. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  450. struct dmae_command *dmae,
  451. u8 src_type, u8 dst_type)
  452. {
  453. memset(dmae, 0, sizeof(struct dmae_command));
  454. /* set the opcode */
  455. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  456. true, DMAE_COMP_PCI);
  457. /* fill in the completion parameters */
  458. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  459. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  460. dmae->comp_val = DMAE_COMP_VAL;
  461. }
  462. /* issue a dmae command over the init-channel and wait for completion */
  463. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  464. u32 *comp)
  465. {
  466. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  467. int rc = 0;
  468. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  469. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  470. * as long as this code is called both from syscall context and
  471. * from ndo_set_rx_mode() flow that may be called from BH.
  472. */
  473. spin_lock_bh(&bp->dmae_lock);
  474. /* reset completion */
  475. *comp = 0;
  476. /* post the command on the channel used for initializations */
  477. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  478. /* wait for completion */
  479. udelay(5);
  480. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  481. if (!cnt ||
  482. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  483. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  484. BNX2X_ERR("DMAE timeout!\n");
  485. rc = DMAE_TIMEOUT;
  486. goto unlock;
  487. }
  488. cnt--;
  489. udelay(50);
  490. }
  491. if (*comp & DMAE_PCI_ERR_FLAG) {
  492. BNX2X_ERR("DMAE PCI error!\n");
  493. rc = DMAE_PCI_ERROR;
  494. }
  495. unlock:
  496. spin_unlock_bh(&bp->dmae_lock);
  497. return rc;
  498. }
  499. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  500. u32 len32)
  501. {
  502. int rc;
  503. struct dmae_command dmae;
  504. if (!bp->dmae_ready) {
  505. u32 *data = bnx2x_sp(bp, wb_data[0]);
  506. if (CHIP_IS_E1(bp))
  507. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  508. else
  509. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  510. return;
  511. }
  512. /* set opcode and fixed command fields */
  513. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  514. /* fill in addresses and len */
  515. dmae.src_addr_lo = U64_LO(dma_addr);
  516. dmae.src_addr_hi = U64_HI(dma_addr);
  517. dmae.dst_addr_lo = dst_addr >> 2;
  518. dmae.dst_addr_hi = 0;
  519. dmae.len = len32;
  520. /* issue the command and wait for completion */
  521. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  522. if (rc) {
  523. BNX2X_ERR("DMAE returned failure %d\n", rc);
  524. #ifdef BNX2X_STOP_ON_ERROR
  525. bnx2x_panic();
  526. #endif
  527. }
  528. }
  529. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  530. {
  531. int rc;
  532. struct dmae_command dmae;
  533. if (!bp->dmae_ready) {
  534. u32 *data = bnx2x_sp(bp, wb_data[0]);
  535. int i;
  536. if (CHIP_IS_E1(bp))
  537. for (i = 0; i < len32; i++)
  538. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  539. else
  540. for (i = 0; i < len32; i++)
  541. data[i] = REG_RD(bp, src_addr + i*4);
  542. return;
  543. }
  544. /* set opcode and fixed command fields */
  545. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  546. /* fill in addresses and len */
  547. dmae.src_addr_lo = src_addr >> 2;
  548. dmae.src_addr_hi = 0;
  549. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  550. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  551. dmae.len = len32;
  552. /* issue the command and wait for completion */
  553. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  554. if (rc) {
  555. BNX2X_ERR("DMAE returned failure %d\n", rc);
  556. #ifdef BNX2X_STOP_ON_ERROR
  557. bnx2x_panic();
  558. #endif
  559. }
  560. }
  561. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  562. u32 addr, u32 len)
  563. {
  564. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  565. int offset = 0;
  566. while (len > dmae_wr_max) {
  567. bnx2x_write_dmae(bp, phys_addr + offset,
  568. addr + offset, dmae_wr_max);
  569. offset += dmae_wr_max * 4;
  570. len -= dmae_wr_max;
  571. }
  572. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  573. }
  574. enum storms {
  575. XSTORM,
  576. TSTORM,
  577. CSTORM,
  578. USTORM,
  579. MAX_STORMS
  580. };
  581. #define STORMS_NUM 4
  582. #define REGS_IN_ENTRY 4
  583. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  584. enum storms storm,
  585. int entry)
  586. {
  587. switch (storm) {
  588. case XSTORM:
  589. return XSTORM_ASSERT_LIST_OFFSET(entry);
  590. case TSTORM:
  591. return TSTORM_ASSERT_LIST_OFFSET(entry);
  592. case CSTORM:
  593. return CSTORM_ASSERT_LIST_OFFSET(entry);
  594. case USTORM:
  595. return USTORM_ASSERT_LIST_OFFSET(entry);
  596. case MAX_STORMS:
  597. default:
  598. BNX2X_ERR("unknown storm\n");
  599. }
  600. return -EINVAL;
  601. }
  602. static int bnx2x_mc_assert(struct bnx2x *bp)
  603. {
  604. char last_idx;
  605. int i, j, rc = 0;
  606. enum storms storm;
  607. u32 regs[REGS_IN_ENTRY];
  608. u32 bar_storm_intmem[STORMS_NUM] = {
  609. BAR_XSTRORM_INTMEM,
  610. BAR_TSTRORM_INTMEM,
  611. BAR_CSTRORM_INTMEM,
  612. BAR_USTRORM_INTMEM
  613. };
  614. u32 storm_assert_list_index[STORMS_NUM] = {
  615. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  616. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  617. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  618. USTORM_ASSERT_LIST_INDEX_OFFSET
  619. };
  620. char *storms_string[STORMS_NUM] = {
  621. "XSTORM",
  622. "TSTORM",
  623. "CSTORM",
  624. "USTORM"
  625. };
  626. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  627. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  628. storm_assert_list_index[storm]);
  629. if (last_idx)
  630. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  631. storms_string[storm], last_idx);
  632. /* print the asserts */
  633. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  634. /* read a single assert entry */
  635. for (j = 0; j < REGS_IN_ENTRY; j++)
  636. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  637. bnx2x_get_assert_list_entry(bp,
  638. storm,
  639. i) +
  640. sizeof(u32) * j);
  641. /* log entry if it contains a valid assert */
  642. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  643. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  644. storms_string[storm], i, regs[3],
  645. regs[2], regs[1], regs[0]);
  646. rc++;
  647. } else {
  648. break;
  649. }
  650. }
  651. }
  652. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  653. CHIP_IS_E1(bp) ? "everest1" :
  654. CHIP_IS_E1H(bp) ? "everest1h" :
  655. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  656. BCM_5710_FW_MAJOR_VERSION,
  657. BCM_5710_FW_MINOR_VERSION,
  658. BCM_5710_FW_REVISION_VERSION);
  659. return rc;
  660. }
  661. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  662. #define SCRATCH_BUFFER_SIZE(bp) \
  663. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  664. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  665. {
  666. u32 addr, val;
  667. u32 mark, offset;
  668. __be32 data[9];
  669. int word;
  670. u32 trace_shmem_base;
  671. if (BP_NOMCP(bp)) {
  672. BNX2X_ERR("NO MCP - can not dump\n");
  673. return;
  674. }
  675. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  676. (bp->common.bc_ver & 0xff0000) >> 16,
  677. (bp->common.bc_ver & 0xff00) >> 8,
  678. (bp->common.bc_ver & 0xff));
  679. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  680. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  681. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  682. if (BP_PATH(bp) == 0)
  683. trace_shmem_base = bp->common.shmem_base;
  684. else
  685. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  686. /* sanity */
  687. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  688. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  689. SCRATCH_BUFFER_SIZE(bp)) {
  690. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  691. trace_shmem_base);
  692. return;
  693. }
  694. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  695. /* validate TRCB signature */
  696. mark = REG_RD(bp, addr);
  697. if (mark != MFW_TRACE_SIGNATURE) {
  698. BNX2X_ERR("Trace buffer signature is missing.");
  699. return ;
  700. }
  701. /* read cyclic buffer pointer */
  702. addr += 4;
  703. mark = REG_RD(bp, addr);
  704. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  705. if (mark >= trace_shmem_base || mark < addr + 4) {
  706. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  707. return;
  708. }
  709. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  710. printk("%s", lvl);
  711. /* dump buffer after the mark */
  712. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  713. for (word = 0; word < 8; word++)
  714. data[word] = htonl(REG_RD(bp, offset + 4*word));
  715. data[8] = 0x0;
  716. pr_cont("%s", (char *)data);
  717. }
  718. /* dump buffer before the mark */
  719. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  720. for (word = 0; word < 8; word++)
  721. data[word] = htonl(REG_RD(bp, offset + 4*word));
  722. data[8] = 0x0;
  723. pr_cont("%s", (char *)data);
  724. }
  725. printk("%s" "end of fw dump\n", lvl);
  726. }
  727. static void bnx2x_fw_dump(struct bnx2x *bp)
  728. {
  729. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  730. }
  731. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  732. {
  733. int port = BP_PORT(bp);
  734. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  735. u32 val = REG_RD(bp, addr);
  736. /* in E1 we must use only PCI configuration space to disable
  737. * MSI/MSIX capability
  738. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  739. */
  740. if (CHIP_IS_E1(bp)) {
  741. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  742. * Use mask register to prevent from HC sending interrupts
  743. * after we exit the function
  744. */
  745. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  746. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  747. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  748. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  749. } else
  750. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  751. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  752. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  753. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  754. DP(NETIF_MSG_IFDOWN,
  755. "write %x to HC %d (addr 0x%x)\n",
  756. val, port, addr);
  757. /* flush all outstanding writes */
  758. mmiowb();
  759. REG_WR(bp, addr, val);
  760. if (REG_RD(bp, addr) != val)
  761. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  762. }
  763. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  764. {
  765. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  766. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  767. IGU_PF_CONF_INT_LINE_EN |
  768. IGU_PF_CONF_ATTN_BIT_EN);
  769. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  770. /* flush all outstanding writes */
  771. mmiowb();
  772. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  773. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  774. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  775. }
  776. static void bnx2x_int_disable(struct bnx2x *bp)
  777. {
  778. if (bp->common.int_block == INT_BLOCK_HC)
  779. bnx2x_hc_int_disable(bp);
  780. else
  781. bnx2x_igu_int_disable(bp);
  782. }
  783. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  784. {
  785. int i;
  786. u16 j;
  787. struct hc_sp_status_block_data sp_sb_data;
  788. int func = BP_FUNC(bp);
  789. #ifdef BNX2X_STOP_ON_ERROR
  790. u16 start = 0, end = 0;
  791. u8 cos;
  792. #endif
  793. if (IS_PF(bp) && disable_int)
  794. bnx2x_int_disable(bp);
  795. bp->stats_state = STATS_STATE_DISABLED;
  796. bp->eth_stats.unrecoverable_error++;
  797. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  798. BNX2X_ERR("begin crash dump -----------------\n");
  799. /* Indices */
  800. /* Common */
  801. if (IS_PF(bp)) {
  802. struct host_sp_status_block *def_sb = bp->def_status_blk;
  803. int data_size, cstorm_offset;
  804. 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",
  805. bp->def_idx, bp->def_att_idx, bp->attn_state,
  806. bp->spq_prod_idx, bp->stats_counter);
  807. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  808. def_sb->atten_status_block.attn_bits,
  809. def_sb->atten_status_block.attn_bits_ack,
  810. def_sb->atten_status_block.status_block_id,
  811. def_sb->atten_status_block.attn_bits_index);
  812. BNX2X_ERR(" def (");
  813. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  814. pr_cont("0x%x%s",
  815. def_sb->sp_sb.index_values[i],
  816. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  817. data_size = sizeof(struct hc_sp_status_block_data) /
  818. sizeof(u32);
  819. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  820. for (i = 0; i < data_size; i++)
  821. *((u32 *)&sp_sb_data + i) =
  822. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  823. i * sizeof(u32));
  824. 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",
  825. sp_sb_data.igu_sb_id,
  826. sp_sb_data.igu_seg_id,
  827. sp_sb_data.p_func.pf_id,
  828. sp_sb_data.p_func.vnic_id,
  829. sp_sb_data.p_func.vf_id,
  830. sp_sb_data.p_func.vf_valid,
  831. sp_sb_data.state);
  832. }
  833. for_each_eth_queue(bp, i) {
  834. struct bnx2x_fastpath *fp = &bp->fp[i];
  835. int loop;
  836. struct hc_status_block_data_e2 sb_data_e2;
  837. struct hc_status_block_data_e1x sb_data_e1x;
  838. struct hc_status_block_sm *hc_sm_p =
  839. CHIP_IS_E1x(bp) ?
  840. sb_data_e1x.common.state_machine :
  841. sb_data_e2.common.state_machine;
  842. struct hc_index_data *hc_index_p =
  843. CHIP_IS_E1x(bp) ?
  844. sb_data_e1x.index_data :
  845. sb_data_e2.index_data;
  846. u8 data_size, cos;
  847. u32 *sb_data_p;
  848. struct bnx2x_fp_txdata txdata;
  849. if (!bp->fp)
  850. break;
  851. if (!fp->rx_cons_sb)
  852. continue;
  853. /* Rx */
  854. 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",
  855. i, fp->rx_bd_prod, fp->rx_bd_cons,
  856. fp->rx_comp_prod,
  857. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  858. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  859. fp->rx_sge_prod, fp->last_max_sge,
  860. le16_to_cpu(fp->fp_hc_idx));
  861. /* Tx */
  862. for_each_cos_in_tx_queue(fp, cos)
  863. {
  864. if (!fp->txdata_ptr[cos])
  865. break;
  866. txdata = *fp->txdata_ptr[cos];
  867. if (!txdata.tx_cons_sb)
  868. continue;
  869. 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",
  870. i, txdata.tx_pkt_prod,
  871. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  872. txdata.tx_bd_cons,
  873. le16_to_cpu(*txdata.tx_cons_sb));
  874. }
  875. loop = CHIP_IS_E1x(bp) ?
  876. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  877. /* host sb data */
  878. if (IS_FCOE_FP(fp))
  879. continue;
  880. BNX2X_ERR(" run indexes (");
  881. for (j = 0; j < HC_SB_MAX_SM; j++)
  882. pr_cont("0x%x%s",
  883. fp->sb_running_index[j],
  884. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  885. BNX2X_ERR(" indexes (");
  886. for (j = 0; j < loop; j++)
  887. pr_cont("0x%x%s",
  888. fp->sb_index_values[j],
  889. (j == loop - 1) ? ")" : " ");
  890. /* VF cannot access FW refelection for status block */
  891. if (IS_VF(bp))
  892. continue;
  893. /* fw sb data */
  894. data_size = CHIP_IS_E1x(bp) ?
  895. sizeof(struct hc_status_block_data_e1x) :
  896. sizeof(struct hc_status_block_data_e2);
  897. data_size /= sizeof(u32);
  898. sb_data_p = CHIP_IS_E1x(bp) ?
  899. (u32 *)&sb_data_e1x :
  900. (u32 *)&sb_data_e2;
  901. /* copy sb data in here */
  902. for (j = 0; j < data_size; j++)
  903. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  904. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  905. j * sizeof(u32));
  906. if (!CHIP_IS_E1x(bp)) {
  907. 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",
  908. sb_data_e2.common.p_func.pf_id,
  909. sb_data_e2.common.p_func.vf_id,
  910. sb_data_e2.common.p_func.vf_valid,
  911. sb_data_e2.common.p_func.vnic_id,
  912. sb_data_e2.common.same_igu_sb_1b,
  913. sb_data_e2.common.state);
  914. } else {
  915. 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",
  916. sb_data_e1x.common.p_func.pf_id,
  917. sb_data_e1x.common.p_func.vf_id,
  918. sb_data_e1x.common.p_func.vf_valid,
  919. sb_data_e1x.common.p_func.vnic_id,
  920. sb_data_e1x.common.same_igu_sb_1b,
  921. sb_data_e1x.common.state);
  922. }
  923. /* SB_SMs data */
  924. for (j = 0; j < HC_SB_MAX_SM; j++) {
  925. 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",
  926. j, hc_sm_p[j].__flags,
  927. hc_sm_p[j].igu_sb_id,
  928. hc_sm_p[j].igu_seg_id,
  929. hc_sm_p[j].time_to_expire,
  930. hc_sm_p[j].timer_value);
  931. }
  932. /* Indices data */
  933. for (j = 0; j < loop; j++) {
  934. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  935. hc_index_p[j].flags,
  936. hc_index_p[j].timeout);
  937. }
  938. }
  939. #ifdef BNX2X_STOP_ON_ERROR
  940. if (IS_PF(bp)) {
  941. /* event queue */
  942. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  943. for (i = 0; i < NUM_EQ_DESC; i++) {
  944. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  945. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  946. i, bp->eq_ring[i].message.opcode,
  947. bp->eq_ring[i].message.error);
  948. BNX2X_ERR("data: %x %x %x\n",
  949. data[0], data[1], data[2]);
  950. }
  951. }
  952. /* Rings */
  953. /* Rx */
  954. for_each_valid_rx_queue(bp, i) {
  955. struct bnx2x_fastpath *fp = &bp->fp[i];
  956. if (!bp->fp)
  957. break;
  958. if (!fp->rx_cons_sb)
  959. continue;
  960. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  961. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  962. for (j = start; j != end; j = RX_BD(j + 1)) {
  963. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  964. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  965. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  966. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  967. }
  968. start = RX_SGE(fp->rx_sge_prod);
  969. end = RX_SGE(fp->last_max_sge);
  970. for (j = start; j != end; j = RX_SGE(j + 1)) {
  971. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  972. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  973. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  974. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  975. }
  976. start = RCQ_BD(fp->rx_comp_cons - 10);
  977. end = RCQ_BD(fp->rx_comp_cons + 503);
  978. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  979. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  980. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  981. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  982. }
  983. }
  984. /* Tx */
  985. for_each_valid_tx_queue(bp, i) {
  986. struct bnx2x_fastpath *fp = &bp->fp[i];
  987. if (!bp->fp)
  988. break;
  989. for_each_cos_in_tx_queue(fp, cos) {
  990. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  991. if (!fp->txdata_ptr[cos])
  992. break;
  993. if (!txdata->tx_cons_sb)
  994. continue;
  995. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  996. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  997. for (j = start; j != end; j = TX_BD(j + 1)) {
  998. struct sw_tx_bd *sw_bd =
  999. &txdata->tx_buf_ring[j];
  1000. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1001. i, cos, j, sw_bd->skb,
  1002. sw_bd->first_bd);
  1003. }
  1004. start = TX_BD(txdata->tx_bd_cons - 10);
  1005. end = TX_BD(txdata->tx_bd_cons + 254);
  1006. for (j = start; j != end; j = TX_BD(j + 1)) {
  1007. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1008. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1009. i, cos, j, tx_bd[0], tx_bd[1],
  1010. tx_bd[2], tx_bd[3]);
  1011. }
  1012. }
  1013. }
  1014. #endif
  1015. if (IS_PF(bp)) {
  1016. bnx2x_fw_dump(bp);
  1017. bnx2x_mc_assert(bp);
  1018. }
  1019. BNX2X_ERR("end crash dump -----------------\n");
  1020. }
  1021. /*
  1022. * FLR Support for E2
  1023. *
  1024. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1025. * initialization.
  1026. */
  1027. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1028. #define FLR_WAIT_INTERVAL 50 /* usec */
  1029. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1030. struct pbf_pN_buf_regs {
  1031. int pN;
  1032. u32 init_crd;
  1033. u32 crd;
  1034. u32 crd_freed;
  1035. };
  1036. struct pbf_pN_cmd_regs {
  1037. int pN;
  1038. u32 lines_occup;
  1039. u32 lines_freed;
  1040. };
  1041. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1042. struct pbf_pN_buf_regs *regs,
  1043. u32 poll_count)
  1044. {
  1045. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1046. u32 cur_cnt = poll_count;
  1047. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1048. crd = crd_start = REG_RD(bp, regs->crd);
  1049. init_crd = REG_RD(bp, regs->init_crd);
  1050. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1051. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1052. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1053. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1054. (init_crd - crd_start))) {
  1055. if (cur_cnt--) {
  1056. udelay(FLR_WAIT_INTERVAL);
  1057. crd = REG_RD(bp, regs->crd);
  1058. crd_freed = REG_RD(bp, regs->crd_freed);
  1059. } else {
  1060. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1061. regs->pN);
  1062. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1063. regs->pN, crd);
  1064. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1065. regs->pN, crd_freed);
  1066. break;
  1067. }
  1068. }
  1069. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1070. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1071. }
  1072. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1073. struct pbf_pN_cmd_regs *regs,
  1074. u32 poll_count)
  1075. {
  1076. u32 occup, to_free, freed, freed_start;
  1077. u32 cur_cnt = poll_count;
  1078. occup = to_free = REG_RD(bp, regs->lines_occup);
  1079. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1080. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1081. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1082. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1083. if (cur_cnt--) {
  1084. udelay(FLR_WAIT_INTERVAL);
  1085. occup = REG_RD(bp, regs->lines_occup);
  1086. freed = REG_RD(bp, regs->lines_freed);
  1087. } else {
  1088. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1089. regs->pN);
  1090. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1091. regs->pN, occup);
  1092. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1093. regs->pN, freed);
  1094. break;
  1095. }
  1096. }
  1097. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1098. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1099. }
  1100. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1101. u32 expected, u32 poll_count)
  1102. {
  1103. u32 cur_cnt = poll_count;
  1104. u32 val;
  1105. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1106. udelay(FLR_WAIT_INTERVAL);
  1107. return val;
  1108. }
  1109. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1110. char *msg, u32 poll_cnt)
  1111. {
  1112. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1113. if (val != 0) {
  1114. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1115. return 1;
  1116. }
  1117. return 0;
  1118. }
  1119. /* Common routines with VF FLR cleanup */
  1120. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1121. {
  1122. /* adjust polling timeout */
  1123. if (CHIP_REV_IS_EMUL(bp))
  1124. return FLR_POLL_CNT * 2000;
  1125. if (CHIP_REV_IS_FPGA(bp))
  1126. return FLR_POLL_CNT * 120;
  1127. return FLR_POLL_CNT;
  1128. }
  1129. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1130. {
  1131. struct pbf_pN_cmd_regs cmd_regs[] = {
  1132. {0, (CHIP_IS_E3B0(bp)) ?
  1133. PBF_REG_TQ_OCCUPANCY_Q0 :
  1134. PBF_REG_P0_TQ_OCCUPANCY,
  1135. (CHIP_IS_E3B0(bp)) ?
  1136. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1137. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1138. {1, (CHIP_IS_E3B0(bp)) ?
  1139. PBF_REG_TQ_OCCUPANCY_Q1 :
  1140. PBF_REG_P1_TQ_OCCUPANCY,
  1141. (CHIP_IS_E3B0(bp)) ?
  1142. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1143. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1144. {4, (CHIP_IS_E3B0(bp)) ?
  1145. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1146. PBF_REG_P4_TQ_OCCUPANCY,
  1147. (CHIP_IS_E3B0(bp)) ?
  1148. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1149. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1150. };
  1151. struct pbf_pN_buf_regs buf_regs[] = {
  1152. {0, (CHIP_IS_E3B0(bp)) ?
  1153. PBF_REG_INIT_CRD_Q0 :
  1154. PBF_REG_P0_INIT_CRD ,
  1155. (CHIP_IS_E3B0(bp)) ?
  1156. PBF_REG_CREDIT_Q0 :
  1157. PBF_REG_P0_CREDIT,
  1158. (CHIP_IS_E3B0(bp)) ?
  1159. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1160. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1161. {1, (CHIP_IS_E3B0(bp)) ?
  1162. PBF_REG_INIT_CRD_Q1 :
  1163. PBF_REG_P1_INIT_CRD,
  1164. (CHIP_IS_E3B0(bp)) ?
  1165. PBF_REG_CREDIT_Q1 :
  1166. PBF_REG_P1_CREDIT,
  1167. (CHIP_IS_E3B0(bp)) ?
  1168. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1169. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1170. {4, (CHIP_IS_E3B0(bp)) ?
  1171. PBF_REG_INIT_CRD_LB_Q :
  1172. PBF_REG_P4_INIT_CRD,
  1173. (CHIP_IS_E3B0(bp)) ?
  1174. PBF_REG_CREDIT_LB_Q :
  1175. PBF_REG_P4_CREDIT,
  1176. (CHIP_IS_E3B0(bp)) ?
  1177. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1178. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1179. };
  1180. int i;
  1181. /* Verify the command queues are flushed P0, P1, P4 */
  1182. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1183. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1184. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1185. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1186. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1187. }
  1188. #define OP_GEN_PARAM(param) \
  1189. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1190. #define OP_GEN_TYPE(type) \
  1191. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1192. #define OP_GEN_AGG_VECT(index) \
  1193. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1194. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1195. {
  1196. u32 op_gen_command = 0;
  1197. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1198. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1199. int ret = 0;
  1200. if (REG_RD(bp, comp_addr)) {
  1201. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1202. return 1;
  1203. }
  1204. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1205. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1206. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1207. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1208. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1209. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1210. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1211. BNX2X_ERR("FW final cleanup did not succeed\n");
  1212. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1213. (REG_RD(bp, comp_addr)));
  1214. bnx2x_panic();
  1215. return 1;
  1216. }
  1217. /* Zero completion for next FLR */
  1218. REG_WR(bp, comp_addr, 0);
  1219. return ret;
  1220. }
  1221. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1222. {
  1223. u16 status;
  1224. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1225. return status & PCI_EXP_DEVSTA_TRPND;
  1226. }
  1227. /* PF FLR specific routines
  1228. */
  1229. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1230. {
  1231. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1232. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1233. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1234. "CFC PF usage counter timed out",
  1235. poll_cnt))
  1236. return 1;
  1237. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1238. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1239. DORQ_REG_PF_USAGE_CNT,
  1240. "DQ PF usage counter timed out",
  1241. poll_cnt))
  1242. return 1;
  1243. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1244. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1245. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1246. "QM PF usage counter timed out",
  1247. poll_cnt))
  1248. return 1;
  1249. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1250. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1251. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1252. "Timers VNIC usage counter timed out",
  1253. poll_cnt))
  1254. return 1;
  1255. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1256. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1257. "Timers NUM_SCANS usage counter timed out",
  1258. poll_cnt))
  1259. return 1;
  1260. /* Wait DMAE PF usage counter to zero */
  1261. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1262. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1263. "DMAE command register timed out",
  1264. poll_cnt))
  1265. return 1;
  1266. return 0;
  1267. }
  1268. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1269. {
  1270. u32 val;
  1271. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1272. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1273. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1274. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1275. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1276. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1277. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1278. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1279. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1280. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1281. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1282. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1283. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1284. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1285. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1286. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1287. val);
  1288. }
  1289. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1290. {
  1291. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1292. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1293. /* Re-enable PF target read access */
  1294. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1295. /* Poll HW usage counters */
  1296. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1297. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1298. return -EBUSY;
  1299. /* Zero the igu 'trailing edge' and 'leading edge' */
  1300. /* Send the FW cleanup command */
  1301. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1302. return -EBUSY;
  1303. /* ATC cleanup */
  1304. /* Verify TX hw is flushed */
  1305. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1306. /* Wait 100ms (not adjusted according to platform) */
  1307. msleep(100);
  1308. /* Verify no pending pci transactions */
  1309. if (bnx2x_is_pcie_pending(bp->pdev))
  1310. BNX2X_ERR("PCIE Transactions still pending\n");
  1311. /* Debug */
  1312. bnx2x_hw_enable_status(bp);
  1313. /*
  1314. * Master enable - Due to WB DMAE writes performed before this
  1315. * register is re-initialized as part of the regular function init
  1316. */
  1317. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1318. return 0;
  1319. }
  1320. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1321. {
  1322. int port = BP_PORT(bp);
  1323. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1324. u32 val = REG_RD(bp, addr);
  1325. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1326. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1327. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1328. if (msix) {
  1329. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1330. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1331. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1332. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1333. if (single_msix)
  1334. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1335. } else if (msi) {
  1336. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1337. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1338. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1339. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1340. } else {
  1341. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1342. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1343. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1344. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1345. if (!CHIP_IS_E1(bp)) {
  1346. DP(NETIF_MSG_IFUP,
  1347. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1348. REG_WR(bp, addr, val);
  1349. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1350. }
  1351. }
  1352. if (CHIP_IS_E1(bp))
  1353. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1354. DP(NETIF_MSG_IFUP,
  1355. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1356. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1357. REG_WR(bp, addr, val);
  1358. /*
  1359. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1360. */
  1361. mmiowb();
  1362. barrier();
  1363. if (!CHIP_IS_E1(bp)) {
  1364. /* init leading/trailing edge */
  1365. if (IS_MF(bp)) {
  1366. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1367. if (bp->port.pmf)
  1368. /* enable nig and gpio3 attention */
  1369. val |= 0x1100;
  1370. } else
  1371. val = 0xffff;
  1372. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1373. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1374. }
  1375. /* Make sure that interrupts are indeed enabled from here on */
  1376. mmiowb();
  1377. }
  1378. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1379. {
  1380. u32 val;
  1381. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1382. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1383. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1384. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1385. if (msix) {
  1386. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1387. IGU_PF_CONF_SINGLE_ISR_EN);
  1388. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1389. IGU_PF_CONF_ATTN_BIT_EN);
  1390. if (single_msix)
  1391. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1392. } else if (msi) {
  1393. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1394. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1395. IGU_PF_CONF_ATTN_BIT_EN |
  1396. IGU_PF_CONF_SINGLE_ISR_EN);
  1397. } else {
  1398. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1399. val |= (IGU_PF_CONF_INT_LINE_EN |
  1400. IGU_PF_CONF_ATTN_BIT_EN |
  1401. IGU_PF_CONF_SINGLE_ISR_EN);
  1402. }
  1403. /* Clean previous status - need to configure igu prior to ack*/
  1404. if ((!msix) || single_msix) {
  1405. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1406. bnx2x_ack_int(bp);
  1407. }
  1408. val |= IGU_PF_CONF_FUNC_EN;
  1409. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1410. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1411. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1412. if (val & IGU_PF_CONF_INT_LINE_EN)
  1413. pci_intx(bp->pdev, true);
  1414. barrier();
  1415. /* init leading/trailing edge */
  1416. if (IS_MF(bp)) {
  1417. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1418. if (bp->port.pmf)
  1419. /* enable nig and gpio3 attention */
  1420. val |= 0x1100;
  1421. } else
  1422. val = 0xffff;
  1423. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1424. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1425. /* Make sure that interrupts are indeed enabled from here on */
  1426. mmiowb();
  1427. }
  1428. void bnx2x_int_enable(struct bnx2x *bp)
  1429. {
  1430. if (bp->common.int_block == INT_BLOCK_HC)
  1431. bnx2x_hc_int_enable(bp);
  1432. else
  1433. bnx2x_igu_int_enable(bp);
  1434. }
  1435. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1436. {
  1437. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1438. int i, offset;
  1439. if (disable_hw)
  1440. /* prevent the HW from sending interrupts */
  1441. bnx2x_int_disable(bp);
  1442. /* make sure all ISRs are done */
  1443. if (msix) {
  1444. synchronize_irq(bp->msix_table[0].vector);
  1445. offset = 1;
  1446. if (CNIC_SUPPORT(bp))
  1447. offset++;
  1448. for_each_eth_queue(bp, i)
  1449. synchronize_irq(bp->msix_table[offset++].vector);
  1450. } else
  1451. synchronize_irq(bp->pdev->irq);
  1452. /* make sure sp_task is not running */
  1453. cancel_delayed_work(&bp->sp_task);
  1454. cancel_delayed_work(&bp->period_task);
  1455. flush_workqueue(bnx2x_wq);
  1456. }
  1457. /* fast path */
  1458. /*
  1459. * General service functions
  1460. */
  1461. /* Return true if succeeded to acquire the lock */
  1462. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1463. {
  1464. u32 lock_status;
  1465. u32 resource_bit = (1 << resource);
  1466. int func = BP_FUNC(bp);
  1467. u32 hw_lock_control_reg;
  1468. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1469. "Trying to take a lock on resource %d\n", resource);
  1470. /* Validating that the resource is within range */
  1471. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1472. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1473. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1474. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1475. return false;
  1476. }
  1477. if (func <= 5)
  1478. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1479. else
  1480. hw_lock_control_reg =
  1481. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1482. /* Try to acquire the lock */
  1483. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1484. lock_status = REG_RD(bp, hw_lock_control_reg);
  1485. if (lock_status & resource_bit)
  1486. return true;
  1487. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1488. "Failed to get a lock on resource %d\n", resource);
  1489. return false;
  1490. }
  1491. /**
  1492. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1493. *
  1494. * @bp: driver handle
  1495. *
  1496. * Returns the recovery leader resource id according to the engine this function
  1497. * belongs to. Currently only only 2 engines is supported.
  1498. */
  1499. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1500. {
  1501. if (BP_PATH(bp))
  1502. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1503. else
  1504. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1505. }
  1506. /**
  1507. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1508. *
  1509. * @bp: driver handle
  1510. *
  1511. * Tries to acquire a leader lock for current engine.
  1512. */
  1513. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1514. {
  1515. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1516. }
  1517. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1518. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1519. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1520. {
  1521. /* Set the interrupt occurred bit for the sp-task to recognize it
  1522. * must ack the interrupt and transition according to the IGU
  1523. * state machine.
  1524. */
  1525. atomic_set(&bp->interrupt_occurred, 1);
  1526. /* The sp_task must execute only after this bit
  1527. * is set, otherwise we will get out of sync and miss all
  1528. * further interrupts. Hence, the barrier.
  1529. */
  1530. smp_wmb();
  1531. /* schedule sp_task to workqueue */
  1532. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1533. }
  1534. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1535. {
  1536. struct bnx2x *bp = fp->bp;
  1537. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1538. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1539. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1540. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1541. DP(BNX2X_MSG_SP,
  1542. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1543. fp->index, cid, command, bp->state,
  1544. rr_cqe->ramrod_cqe.ramrod_type);
  1545. /* If cid is within VF range, replace the slowpath object with the
  1546. * one corresponding to this VF
  1547. */
  1548. if (cid >= BNX2X_FIRST_VF_CID &&
  1549. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1550. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1551. switch (command) {
  1552. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1553. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1554. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1555. break;
  1556. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1557. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1558. drv_cmd = BNX2X_Q_CMD_SETUP;
  1559. break;
  1560. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1561. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1562. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1563. break;
  1564. case (RAMROD_CMD_ID_ETH_HALT):
  1565. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1566. drv_cmd = BNX2X_Q_CMD_HALT;
  1567. break;
  1568. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1569. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1570. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1571. break;
  1572. case (RAMROD_CMD_ID_ETH_EMPTY):
  1573. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1574. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1575. break;
  1576. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1577. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1578. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1579. break;
  1580. default:
  1581. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1582. command, fp->index);
  1583. return;
  1584. }
  1585. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1586. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1587. /* q_obj->complete_cmd() failure means that this was
  1588. * an unexpected completion.
  1589. *
  1590. * In this case we don't want to increase the bp->spq_left
  1591. * because apparently we haven't sent this command the first
  1592. * place.
  1593. */
  1594. #ifdef BNX2X_STOP_ON_ERROR
  1595. bnx2x_panic();
  1596. #else
  1597. return;
  1598. #endif
  1599. smp_mb__before_atomic();
  1600. atomic_inc(&bp->cq_spq_left);
  1601. /* push the change in bp->spq_left and towards the memory */
  1602. smp_mb__after_atomic();
  1603. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1604. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1605. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1606. /* if Q update ramrod is completed for last Q in AFEX vif set
  1607. * flow, then ACK MCP at the end
  1608. *
  1609. * mark pending ACK to MCP bit.
  1610. * prevent case that both bits are cleared.
  1611. * At the end of load/unload driver checks that
  1612. * sp_state is cleared, and this order prevents
  1613. * races
  1614. */
  1615. smp_mb__before_atomic();
  1616. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1617. wmb();
  1618. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1619. smp_mb__after_atomic();
  1620. /* schedule the sp task as mcp ack is required */
  1621. bnx2x_schedule_sp_task(bp);
  1622. }
  1623. return;
  1624. }
  1625. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1626. {
  1627. struct bnx2x *bp = netdev_priv(dev_instance);
  1628. u16 status = bnx2x_ack_int(bp);
  1629. u16 mask;
  1630. int i;
  1631. u8 cos;
  1632. /* Return here if interrupt is shared and it's not for us */
  1633. if (unlikely(status == 0)) {
  1634. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1635. return IRQ_NONE;
  1636. }
  1637. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1638. #ifdef BNX2X_STOP_ON_ERROR
  1639. if (unlikely(bp->panic))
  1640. return IRQ_HANDLED;
  1641. #endif
  1642. for_each_eth_queue(bp, i) {
  1643. struct bnx2x_fastpath *fp = &bp->fp[i];
  1644. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1645. if (status & mask) {
  1646. /* Handle Rx or Tx according to SB id */
  1647. for_each_cos_in_tx_queue(fp, cos)
  1648. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1649. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1650. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1651. status &= ~mask;
  1652. }
  1653. }
  1654. if (CNIC_SUPPORT(bp)) {
  1655. mask = 0x2;
  1656. if (status & (mask | 0x1)) {
  1657. struct cnic_ops *c_ops = NULL;
  1658. rcu_read_lock();
  1659. c_ops = rcu_dereference(bp->cnic_ops);
  1660. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1661. CNIC_DRV_STATE_HANDLES_IRQ))
  1662. c_ops->cnic_handler(bp->cnic_data, NULL);
  1663. rcu_read_unlock();
  1664. status &= ~mask;
  1665. }
  1666. }
  1667. if (unlikely(status & 0x1)) {
  1668. /* schedule sp task to perform default status block work, ack
  1669. * attentions and enable interrupts.
  1670. */
  1671. bnx2x_schedule_sp_task(bp);
  1672. status &= ~0x1;
  1673. if (!status)
  1674. return IRQ_HANDLED;
  1675. }
  1676. if (unlikely(status))
  1677. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1678. status);
  1679. return IRQ_HANDLED;
  1680. }
  1681. /* Link */
  1682. /*
  1683. * General service functions
  1684. */
  1685. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1686. {
  1687. u32 lock_status;
  1688. u32 resource_bit = (1 << resource);
  1689. int func = BP_FUNC(bp);
  1690. u32 hw_lock_control_reg;
  1691. int cnt;
  1692. /* Validating that the resource is within range */
  1693. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1694. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1695. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1696. return -EINVAL;
  1697. }
  1698. if (func <= 5) {
  1699. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1700. } else {
  1701. hw_lock_control_reg =
  1702. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1703. }
  1704. /* Validating that the resource is not already taken */
  1705. lock_status = REG_RD(bp, hw_lock_control_reg);
  1706. if (lock_status & resource_bit) {
  1707. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1708. lock_status, resource_bit);
  1709. return -EEXIST;
  1710. }
  1711. /* Try for 5 second every 5ms */
  1712. for (cnt = 0; cnt < 1000; cnt++) {
  1713. /* Try to acquire the lock */
  1714. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1715. lock_status = REG_RD(bp, hw_lock_control_reg);
  1716. if (lock_status & resource_bit)
  1717. return 0;
  1718. usleep_range(5000, 10000);
  1719. }
  1720. BNX2X_ERR("Timeout\n");
  1721. return -EAGAIN;
  1722. }
  1723. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1724. {
  1725. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1726. }
  1727. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1728. {
  1729. u32 lock_status;
  1730. u32 resource_bit = (1 << resource);
  1731. int func = BP_FUNC(bp);
  1732. u32 hw_lock_control_reg;
  1733. /* Validating that the resource is within range */
  1734. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1735. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1736. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1737. return -EINVAL;
  1738. }
  1739. if (func <= 5) {
  1740. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1741. } else {
  1742. hw_lock_control_reg =
  1743. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1744. }
  1745. /* Validating that the resource is currently taken */
  1746. lock_status = REG_RD(bp, hw_lock_control_reg);
  1747. if (!(lock_status & resource_bit)) {
  1748. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1749. lock_status, resource_bit);
  1750. return -EFAULT;
  1751. }
  1752. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1753. return 0;
  1754. }
  1755. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1756. {
  1757. /* The GPIO should be swapped if swap register is set and active */
  1758. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1759. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1760. int gpio_shift = gpio_num +
  1761. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1762. u32 gpio_mask = (1 << gpio_shift);
  1763. u32 gpio_reg;
  1764. int value;
  1765. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1766. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1767. return -EINVAL;
  1768. }
  1769. /* read GPIO value */
  1770. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1771. /* get the requested pin value */
  1772. if ((gpio_reg & gpio_mask) == gpio_mask)
  1773. value = 1;
  1774. else
  1775. value = 0;
  1776. return value;
  1777. }
  1778. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1779. {
  1780. /* The GPIO should be swapped if swap register is set and active */
  1781. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1782. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1783. int gpio_shift = gpio_num +
  1784. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1785. u32 gpio_mask = (1 << gpio_shift);
  1786. u32 gpio_reg;
  1787. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1788. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1789. return -EINVAL;
  1790. }
  1791. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1792. /* read GPIO and mask except the float bits */
  1793. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1794. switch (mode) {
  1795. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1796. DP(NETIF_MSG_LINK,
  1797. "Set GPIO %d (shift %d) -> output low\n",
  1798. gpio_num, gpio_shift);
  1799. /* clear FLOAT and set CLR */
  1800. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1801. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1802. break;
  1803. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1804. DP(NETIF_MSG_LINK,
  1805. "Set GPIO %d (shift %d) -> output high\n",
  1806. gpio_num, gpio_shift);
  1807. /* clear FLOAT and set SET */
  1808. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1809. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1810. break;
  1811. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1812. DP(NETIF_MSG_LINK,
  1813. "Set GPIO %d (shift %d) -> input\n",
  1814. gpio_num, gpio_shift);
  1815. /* set FLOAT */
  1816. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1817. break;
  1818. default:
  1819. break;
  1820. }
  1821. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1822. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1823. return 0;
  1824. }
  1825. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1826. {
  1827. u32 gpio_reg = 0;
  1828. int rc = 0;
  1829. /* Any port swapping should be handled by caller. */
  1830. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1831. /* read GPIO and mask except the float bits */
  1832. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1833. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1834. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1835. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1836. switch (mode) {
  1837. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1838. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1839. /* set CLR */
  1840. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1841. break;
  1842. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1843. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1844. /* set SET */
  1845. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1846. break;
  1847. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1848. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1849. /* set FLOAT */
  1850. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1851. break;
  1852. default:
  1853. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1854. rc = -EINVAL;
  1855. break;
  1856. }
  1857. if (rc == 0)
  1858. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1859. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1860. return rc;
  1861. }
  1862. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1863. {
  1864. /* The GPIO should be swapped if swap register is set and active */
  1865. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1866. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1867. int gpio_shift = gpio_num +
  1868. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1869. u32 gpio_mask = (1 << gpio_shift);
  1870. u32 gpio_reg;
  1871. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1872. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1873. return -EINVAL;
  1874. }
  1875. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1876. /* read GPIO int */
  1877. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1878. switch (mode) {
  1879. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1880. DP(NETIF_MSG_LINK,
  1881. "Clear GPIO INT %d (shift %d) -> output low\n",
  1882. gpio_num, gpio_shift);
  1883. /* clear SET and set CLR */
  1884. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1885. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1886. break;
  1887. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1888. DP(NETIF_MSG_LINK,
  1889. "Set GPIO INT %d (shift %d) -> output high\n",
  1890. gpio_num, gpio_shift);
  1891. /* clear CLR and set SET */
  1892. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1893. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1894. break;
  1895. default:
  1896. break;
  1897. }
  1898. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1899. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1900. return 0;
  1901. }
  1902. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1903. {
  1904. u32 spio_reg;
  1905. /* Only 2 SPIOs are configurable */
  1906. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1907. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1908. return -EINVAL;
  1909. }
  1910. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1911. /* read SPIO and mask except the float bits */
  1912. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1913. switch (mode) {
  1914. case MISC_SPIO_OUTPUT_LOW:
  1915. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1916. /* clear FLOAT and set CLR */
  1917. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1918. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1919. break;
  1920. case MISC_SPIO_OUTPUT_HIGH:
  1921. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1922. /* clear FLOAT and set SET */
  1923. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1924. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1925. break;
  1926. case MISC_SPIO_INPUT_HI_Z:
  1927. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1928. /* set FLOAT */
  1929. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1930. break;
  1931. default:
  1932. break;
  1933. }
  1934. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1935. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1936. return 0;
  1937. }
  1938. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1939. {
  1940. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1941. switch (bp->link_vars.ieee_fc &
  1942. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1943. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1944. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1945. ADVERTISED_Pause);
  1946. break;
  1947. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1948. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1949. ADVERTISED_Pause);
  1950. break;
  1951. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1952. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1953. break;
  1954. default:
  1955. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1956. ADVERTISED_Pause);
  1957. break;
  1958. }
  1959. }
  1960. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1961. {
  1962. /* Initialize link parameters structure variables
  1963. * It is recommended to turn off RX FC for jumbo frames
  1964. * for better performance
  1965. */
  1966. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1967. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1968. else
  1969. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1970. }
  1971. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1972. {
  1973. u32 pause_enabled = 0;
  1974. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1975. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1976. pause_enabled = 1;
  1977. REG_WR(bp, BAR_USTRORM_INTMEM +
  1978. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1979. pause_enabled);
  1980. }
  1981. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1982. pause_enabled ? "enabled" : "disabled");
  1983. }
  1984. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1985. {
  1986. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1987. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1988. if (!BP_NOMCP(bp)) {
  1989. bnx2x_set_requested_fc(bp);
  1990. bnx2x_acquire_phy_lock(bp);
  1991. if (load_mode == LOAD_DIAG) {
  1992. struct link_params *lp = &bp->link_params;
  1993. lp->loopback_mode = LOOPBACK_XGXS;
  1994. /* do PHY loopback at 10G speed, if possible */
  1995. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1996. if (lp->speed_cap_mask[cfx_idx] &
  1997. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1998. lp->req_line_speed[cfx_idx] =
  1999. SPEED_10000;
  2000. else
  2001. lp->req_line_speed[cfx_idx] =
  2002. SPEED_1000;
  2003. }
  2004. }
  2005. if (load_mode == LOAD_LOOPBACK_EXT) {
  2006. struct link_params *lp = &bp->link_params;
  2007. lp->loopback_mode = LOOPBACK_EXT;
  2008. }
  2009. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2010. bnx2x_release_phy_lock(bp);
  2011. bnx2x_init_dropless_fc(bp);
  2012. bnx2x_calc_fc_adv(bp);
  2013. if (bp->link_vars.link_up) {
  2014. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2015. bnx2x_link_report(bp);
  2016. }
  2017. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2018. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2019. return rc;
  2020. }
  2021. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2022. return -EINVAL;
  2023. }
  2024. void bnx2x_link_set(struct bnx2x *bp)
  2025. {
  2026. if (!BP_NOMCP(bp)) {
  2027. bnx2x_acquire_phy_lock(bp);
  2028. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2029. bnx2x_release_phy_lock(bp);
  2030. bnx2x_init_dropless_fc(bp);
  2031. bnx2x_calc_fc_adv(bp);
  2032. } else
  2033. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2034. }
  2035. static void bnx2x__link_reset(struct bnx2x *bp)
  2036. {
  2037. if (!BP_NOMCP(bp)) {
  2038. bnx2x_acquire_phy_lock(bp);
  2039. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2040. bnx2x_release_phy_lock(bp);
  2041. } else
  2042. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2043. }
  2044. void bnx2x_force_link_reset(struct bnx2x *bp)
  2045. {
  2046. bnx2x_acquire_phy_lock(bp);
  2047. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2048. bnx2x_release_phy_lock(bp);
  2049. }
  2050. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2051. {
  2052. u8 rc = 0;
  2053. if (!BP_NOMCP(bp)) {
  2054. bnx2x_acquire_phy_lock(bp);
  2055. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2056. is_serdes);
  2057. bnx2x_release_phy_lock(bp);
  2058. } else
  2059. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2060. return rc;
  2061. }
  2062. /* Calculates the sum of vn_min_rates.
  2063. It's needed for further normalizing of the min_rates.
  2064. Returns:
  2065. sum of vn_min_rates.
  2066. or
  2067. 0 - if all the min_rates are 0.
  2068. In the later case fairness algorithm should be deactivated.
  2069. If not all min_rates are zero then those that are zeroes will be set to 1.
  2070. */
  2071. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2072. struct cmng_init_input *input)
  2073. {
  2074. int all_zero = 1;
  2075. int vn;
  2076. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2077. u32 vn_cfg = bp->mf_config[vn];
  2078. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2079. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2080. /* Skip hidden vns */
  2081. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2082. vn_min_rate = 0;
  2083. /* If min rate is zero - set it to 1 */
  2084. else if (!vn_min_rate)
  2085. vn_min_rate = DEF_MIN_RATE;
  2086. else
  2087. all_zero = 0;
  2088. input->vnic_min_rate[vn] = vn_min_rate;
  2089. }
  2090. /* if ETS or all min rates are zeros - disable fairness */
  2091. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2092. input->flags.cmng_enables &=
  2093. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2094. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2095. } else if (all_zero) {
  2096. input->flags.cmng_enables &=
  2097. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2098. DP(NETIF_MSG_IFUP,
  2099. "All MIN values are zeroes fairness will be disabled\n");
  2100. } else
  2101. input->flags.cmng_enables |=
  2102. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2103. }
  2104. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2105. struct cmng_init_input *input)
  2106. {
  2107. u16 vn_max_rate;
  2108. u32 vn_cfg = bp->mf_config[vn];
  2109. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2110. vn_max_rate = 0;
  2111. else {
  2112. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2113. if (IS_MF_SI(bp)) {
  2114. /* maxCfg in percents of linkspeed */
  2115. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2116. } else /* SD modes */
  2117. /* maxCfg is absolute in 100Mb units */
  2118. vn_max_rate = maxCfg * 100;
  2119. }
  2120. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2121. input->vnic_max_rate[vn] = vn_max_rate;
  2122. }
  2123. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2124. {
  2125. if (CHIP_REV_IS_SLOW(bp))
  2126. return CMNG_FNS_NONE;
  2127. if (IS_MF(bp))
  2128. return CMNG_FNS_MINMAX;
  2129. return CMNG_FNS_NONE;
  2130. }
  2131. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2132. {
  2133. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2134. if (BP_NOMCP(bp))
  2135. return; /* what should be the default value in this case */
  2136. /* For 2 port configuration the absolute function number formula
  2137. * is:
  2138. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2139. *
  2140. * and there are 4 functions per port
  2141. *
  2142. * For 4 port configuration it is
  2143. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2144. *
  2145. * and there are 2 functions per port
  2146. */
  2147. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2148. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2149. if (func >= E1H_FUNC_MAX)
  2150. break;
  2151. bp->mf_config[vn] =
  2152. MF_CFG_RD(bp, func_mf_config[func].config);
  2153. }
  2154. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2155. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2156. bp->flags |= MF_FUNC_DIS;
  2157. } else {
  2158. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2159. bp->flags &= ~MF_FUNC_DIS;
  2160. }
  2161. }
  2162. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2163. {
  2164. struct cmng_init_input input;
  2165. memset(&input, 0, sizeof(struct cmng_init_input));
  2166. input.port_rate = bp->link_vars.line_speed;
  2167. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2168. int vn;
  2169. /* read mf conf from shmem */
  2170. if (read_cfg)
  2171. bnx2x_read_mf_cfg(bp);
  2172. /* vn_weight_sum and enable fairness if not 0 */
  2173. bnx2x_calc_vn_min(bp, &input);
  2174. /* calculate and set min-max rate for each vn */
  2175. if (bp->port.pmf)
  2176. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2177. bnx2x_calc_vn_max(bp, vn, &input);
  2178. /* always enable rate shaping and fairness */
  2179. input.flags.cmng_enables |=
  2180. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2181. bnx2x_init_cmng(&input, &bp->cmng);
  2182. return;
  2183. }
  2184. /* rate shaping and fairness are disabled */
  2185. DP(NETIF_MSG_IFUP,
  2186. "rate shaping and fairness are disabled\n");
  2187. }
  2188. static void storm_memset_cmng(struct bnx2x *bp,
  2189. struct cmng_init *cmng,
  2190. u8 port)
  2191. {
  2192. int vn;
  2193. size_t size = sizeof(struct cmng_struct_per_port);
  2194. u32 addr = BAR_XSTRORM_INTMEM +
  2195. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2196. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2197. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2198. int func = func_by_vn(bp, vn);
  2199. addr = BAR_XSTRORM_INTMEM +
  2200. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2201. size = sizeof(struct rate_shaping_vars_per_vn);
  2202. __storm_memset_struct(bp, addr, size,
  2203. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2204. addr = BAR_XSTRORM_INTMEM +
  2205. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2206. size = sizeof(struct fairness_vars_per_vn);
  2207. __storm_memset_struct(bp, addr, size,
  2208. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2209. }
  2210. }
  2211. /* init cmng mode in HW according to local configuration */
  2212. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2213. {
  2214. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2215. if (cmng_fns != CMNG_FNS_NONE) {
  2216. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2217. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2218. } else {
  2219. /* rate shaping and fairness are disabled */
  2220. DP(NETIF_MSG_IFUP,
  2221. "single function mode without fairness\n");
  2222. }
  2223. }
  2224. /* This function is called upon link interrupt */
  2225. static void bnx2x_link_attn(struct bnx2x *bp)
  2226. {
  2227. /* Make sure that we are synced with the current statistics */
  2228. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2229. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2230. bnx2x_init_dropless_fc(bp);
  2231. if (bp->link_vars.link_up) {
  2232. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2233. struct host_port_stats *pstats;
  2234. pstats = bnx2x_sp(bp, port_stats);
  2235. /* reset old mac stats */
  2236. memset(&(pstats->mac_stx[0]), 0,
  2237. sizeof(struct mac_stx));
  2238. }
  2239. if (bp->state == BNX2X_STATE_OPEN)
  2240. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2241. }
  2242. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2243. bnx2x_set_local_cmng(bp);
  2244. __bnx2x_link_report(bp);
  2245. if (IS_MF(bp))
  2246. bnx2x_link_sync_notify(bp);
  2247. }
  2248. void bnx2x__link_status_update(struct bnx2x *bp)
  2249. {
  2250. if (bp->state != BNX2X_STATE_OPEN)
  2251. return;
  2252. /* read updated dcb configuration */
  2253. if (IS_PF(bp)) {
  2254. bnx2x_dcbx_pmf_update(bp);
  2255. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2256. if (bp->link_vars.link_up)
  2257. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2258. else
  2259. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2260. /* indicate link status */
  2261. bnx2x_link_report(bp);
  2262. } else { /* VF */
  2263. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2264. SUPPORTED_10baseT_Full |
  2265. SUPPORTED_100baseT_Half |
  2266. SUPPORTED_100baseT_Full |
  2267. SUPPORTED_1000baseT_Full |
  2268. SUPPORTED_2500baseX_Full |
  2269. SUPPORTED_10000baseT_Full |
  2270. SUPPORTED_TP |
  2271. SUPPORTED_FIBRE |
  2272. SUPPORTED_Autoneg |
  2273. SUPPORTED_Pause |
  2274. SUPPORTED_Asym_Pause);
  2275. bp->port.advertising[0] = bp->port.supported[0];
  2276. bp->link_params.bp = bp;
  2277. bp->link_params.port = BP_PORT(bp);
  2278. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2279. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2280. bp->link_params.req_line_speed[0] = SPEED_10000;
  2281. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2282. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2283. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2284. bp->link_vars.line_speed = SPEED_10000;
  2285. bp->link_vars.link_status =
  2286. (LINK_STATUS_LINK_UP |
  2287. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2288. bp->link_vars.link_up = 1;
  2289. bp->link_vars.duplex = DUPLEX_FULL;
  2290. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2291. __bnx2x_link_report(bp);
  2292. bnx2x_sample_bulletin(bp);
  2293. /* if bulletin board did not have an update for link status
  2294. * __bnx2x_link_report will report current status
  2295. * but it will NOT duplicate report in case of already reported
  2296. * during sampling bulletin board.
  2297. */
  2298. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2299. }
  2300. }
  2301. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2302. u16 vlan_val, u8 allowed_prio)
  2303. {
  2304. struct bnx2x_func_state_params func_params = {NULL};
  2305. struct bnx2x_func_afex_update_params *f_update_params =
  2306. &func_params.params.afex_update;
  2307. func_params.f_obj = &bp->func_obj;
  2308. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2309. /* no need to wait for RAMROD completion, so don't
  2310. * set RAMROD_COMP_WAIT flag
  2311. */
  2312. f_update_params->vif_id = vifid;
  2313. f_update_params->afex_default_vlan = vlan_val;
  2314. f_update_params->allowed_priorities = allowed_prio;
  2315. /* if ramrod can not be sent, response to MCP immediately */
  2316. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2317. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2318. return 0;
  2319. }
  2320. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2321. u16 vif_index, u8 func_bit_map)
  2322. {
  2323. struct bnx2x_func_state_params func_params = {NULL};
  2324. struct bnx2x_func_afex_viflists_params *update_params =
  2325. &func_params.params.afex_viflists;
  2326. int rc;
  2327. u32 drv_msg_code;
  2328. /* validate only LIST_SET and LIST_GET are received from switch */
  2329. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2330. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2331. cmd_type);
  2332. func_params.f_obj = &bp->func_obj;
  2333. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2334. /* set parameters according to cmd_type */
  2335. update_params->afex_vif_list_command = cmd_type;
  2336. update_params->vif_list_index = vif_index;
  2337. update_params->func_bit_map =
  2338. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2339. update_params->func_to_clear = 0;
  2340. drv_msg_code =
  2341. (cmd_type == VIF_LIST_RULE_GET) ?
  2342. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2343. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2344. /* if ramrod can not be sent, respond to MCP immediately for
  2345. * SET and GET requests (other are not triggered from MCP)
  2346. */
  2347. rc = bnx2x_func_state_change(bp, &func_params);
  2348. if (rc < 0)
  2349. bnx2x_fw_command(bp, drv_msg_code, 0);
  2350. return 0;
  2351. }
  2352. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2353. {
  2354. struct afex_stats afex_stats;
  2355. u32 func = BP_ABS_FUNC(bp);
  2356. u32 mf_config;
  2357. u16 vlan_val;
  2358. u32 vlan_prio;
  2359. u16 vif_id;
  2360. u8 allowed_prio;
  2361. u8 vlan_mode;
  2362. u32 addr_to_write, vifid, addrs, stats_type, i;
  2363. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2364. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2365. DP(BNX2X_MSG_MCP,
  2366. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2367. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2368. }
  2369. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2370. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2371. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2372. DP(BNX2X_MSG_MCP,
  2373. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2374. vifid, addrs);
  2375. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2376. addrs);
  2377. }
  2378. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2379. addr_to_write = SHMEM2_RD(bp,
  2380. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2381. stats_type = SHMEM2_RD(bp,
  2382. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2383. DP(BNX2X_MSG_MCP,
  2384. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2385. addr_to_write);
  2386. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2387. /* write response to scratchpad, for MCP */
  2388. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2389. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2390. *(((u32 *)(&afex_stats))+i));
  2391. /* send ack message to MCP */
  2392. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2393. }
  2394. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2395. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2396. bp->mf_config[BP_VN(bp)] = mf_config;
  2397. DP(BNX2X_MSG_MCP,
  2398. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2399. mf_config);
  2400. /* if VIF_SET is "enabled" */
  2401. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2402. /* set rate limit directly to internal RAM */
  2403. struct cmng_init_input cmng_input;
  2404. struct rate_shaping_vars_per_vn m_rs_vn;
  2405. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2406. u32 addr = BAR_XSTRORM_INTMEM +
  2407. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2408. bp->mf_config[BP_VN(bp)] = mf_config;
  2409. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2410. m_rs_vn.vn_counter.rate =
  2411. cmng_input.vnic_max_rate[BP_VN(bp)];
  2412. m_rs_vn.vn_counter.quota =
  2413. (m_rs_vn.vn_counter.rate *
  2414. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2415. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2416. /* read relevant values from mf_cfg struct in shmem */
  2417. vif_id =
  2418. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2419. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2420. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2421. vlan_val =
  2422. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2423. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2424. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2425. vlan_prio = (mf_config &
  2426. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2427. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2428. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2429. vlan_mode =
  2430. (MF_CFG_RD(bp,
  2431. func_mf_config[func].afex_config) &
  2432. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2433. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2434. allowed_prio =
  2435. (MF_CFG_RD(bp,
  2436. func_mf_config[func].afex_config) &
  2437. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2438. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2439. /* send ramrod to FW, return in case of failure */
  2440. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2441. allowed_prio))
  2442. return;
  2443. bp->afex_def_vlan_tag = vlan_val;
  2444. bp->afex_vlan_mode = vlan_mode;
  2445. } else {
  2446. /* notify link down because BP->flags is disabled */
  2447. bnx2x_link_report(bp);
  2448. /* send INVALID VIF ramrod to FW */
  2449. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2450. /* Reset the default afex VLAN */
  2451. bp->afex_def_vlan_tag = -1;
  2452. }
  2453. }
  2454. }
  2455. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2456. {
  2457. struct bnx2x_func_switch_update_params *switch_update_params;
  2458. struct bnx2x_func_state_params func_params;
  2459. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2460. switch_update_params = &func_params.params.switch_update;
  2461. func_params.f_obj = &bp->func_obj;
  2462. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2463. if (IS_MF_UFP(bp)) {
  2464. int func = BP_ABS_FUNC(bp);
  2465. u32 val;
  2466. /* Re-learn the S-tag from shmem */
  2467. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2468. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2469. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2470. bp->mf_ov = val;
  2471. } else {
  2472. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2473. goto fail;
  2474. }
  2475. /* Configure new S-tag in LLH */
  2476. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2477. bp->mf_ov);
  2478. /* Send Ramrod to update FW of change */
  2479. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2480. &switch_update_params->changes);
  2481. switch_update_params->vlan = bp->mf_ov;
  2482. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2483. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2484. bp->mf_ov);
  2485. goto fail;
  2486. }
  2487. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n", bp->mf_ov);
  2488. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2489. return;
  2490. }
  2491. /* not supported by SW yet */
  2492. fail:
  2493. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2494. }
  2495. static void bnx2x_pmf_update(struct bnx2x *bp)
  2496. {
  2497. int port = BP_PORT(bp);
  2498. u32 val;
  2499. bp->port.pmf = 1;
  2500. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2501. /*
  2502. * We need the mb() to ensure the ordering between the writing to
  2503. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2504. */
  2505. smp_mb();
  2506. /* queue a periodic task */
  2507. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2508. bnx2x_dcbx_pmf_update(bp);
  2509. /* enable nig attention */
  2510. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2511. if (bp->common.int_block == INT_BLOCK_HC) {
  2512. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2513. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2514. } else if (!CHIP_IS_E1x(bp)) {
  2515. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2516. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2517. }
  2518. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2519. }
  2520. /* end of Link */
  2521. /* slow path */
  2522. /*
  2523. * General service functions
  2524. */
  2525. /* send the MCP a request, block until there is a reply */
  2526. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2527. {
  2528. int mb_idx = BP_FW_MB_IDX(bp);
  2529. u32 seq;
  2530. u32 rc = 0;
  2531. u32 cnt = 1;
  2532. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2533. mutex_lock(&bp->fw_mb_mutex);
  2534. seq = ++bp->fw_seq;
  2535. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2536. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2537. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2538. (command | seq), param);
  2539. do {
  2540. /* let the FW do it's magic ... */
  2541. msleep(delay);
  2542. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2543. /* Give the FW up to 5 second (500*10ms) */
  2544. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2545. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2546. cnt*delay, rc, seq);
  2547. /* is this a reply to our command? */
  2548. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2549. rc &= FW_MSG_CODE_MASK;
  2550. else {
  2551. /* FW BUG! */
  2552. BNX2X_ERR("FW failed to respond!\n");
  2553. bnx2x_fw_dump(bp);
  2554. rc = 0;
  2555. }
  2556. mutex_unlock(&bp->fw_mb_mutex);
  2557. return rc;
  2558. }
  2559. static void storm_memset_func_cfg(struct bnx2x *bp,
  2560. struct tstorm_eth_function_common_config *tcfg,
  2561. u16 abs_fid)
  2562. {
  2563. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2564. u32 addr = BAR_TSTRORM_INTMEM +
  2565. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2566. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2567. }
  2568. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2569. {
  2570. if (CHIP_IS_E1x(bp)) {
  2571. struct tstorm_eth_function_common_config tcfg = {0};
  2572. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2573. }
  2574. /* Enable the function in the FW */
  2575. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2576. storm_memset_func_en(bp, p->func_id, 1);
  2577. /* spq */
  2578. if (p->func_flgs & FUNC_FLG_SPQ) {
  2579. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2580. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2581. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2582. }
  2583. }
  2584. /**
  2585. * bnx2x_get_common_flags - Return common flags
  2586. *
  2587. * @bp device handle
  2588. * @fp queue handle
  2589. * @zero_stats TRUE if statistics zeroing is needed
  2590. *
  2591. * Return the flags that are common for the Tx-only and not normal connections.
  2592. */
  2593. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2594. struct bnx2x_fastpath *fp,
  2595. bool zero_stats)
  2596. {
  2597. unsigned long flags = 0;
  2598. /* PF driver will always initialize the Queue to an ACTIVE state */
  2599. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2600. /* tx only connections collect statistics (on the same index as the
  2601. * parent connection). The statistics are zeroed when the parent
  2602. * connection is initialized.
  2603. */
  2604. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2605. if (zero_stats)
  2606. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2607. if (bp->flags & TX_SWITCHING)
  2608. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2609. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2610. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2611. #ifdef BNX2X_STOP_ON_ERROR
  2612. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2613. #endif
  2614. return flags;
  2615. }
  2616. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2617. struct bnx2x_fastpath *fp,
  2618. bool leading)
  2619. {
  2620. unsigned long flags = 0;
  2621. /* calculate other queue flags */
  2622. if (IS_MF_SD(bp))
  2623. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2624. if (IS_FCOE_FP(fp)) {
  2625. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2626. /* For FCoE - force usage of default priority (for afex) */
  2627. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2628. }
  2629. if (!fp->disable_tpa) {
  2630. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2631. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2632. if (fp->mode == TPA_MODE_GRO)
  2633. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2634. }
  2635. if (leading) {
  2636. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2637. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2638. }
  2639. /* Always set HW VLAN stripping */
  2640. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2641. /* configure silent vlan removal */
  2642. if (IS_MF_AFEX(bp))
  2643. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2644. return flags | bnx2x_get_common_flags(bp, fp, true);
  2645. }
  2646. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2647. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2648. u8 cos)
  2649. {
  2650. gen_init->stat_id = bnx2x_stats_id(fp);
  2651. gen_init->spcl_id = fp->cl_id;
  2652. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2653. if (IS_FCOE_FP(fp))
  2654. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2655. else
  2656. gen_init->mtu = bp->dev->mtu;
  2657. gen_init->cos = cos;
  2658. }
  2659. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2660. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2661. struct bnx2x_rxq_setup_params *rxq_init)
  2662. {
  2663. u8 max_sge = 0;
  2664. u16 sge_sz = 0;
  2665. u16 tpa_agg_size = 0;
  2666. if (!fp->disable_tpa) {
  2667. pause->sge_th_lo = SGE_TH_LO(bp);
  2668. pause->sge_th_hi = SGE_TH_HI(bp);
  2669. /* validate SGE ring has enough to cross high threshold */
  2670. WARN_ON(bp->dropless_fc &&
  2671. pause->sge_th_hi + FW_PREFETCH_CNT >
  2672. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2673. tpa_agg_size = TPA_AGG_SIZE;
  2674. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2675. SGE_PAGE_SHIFT;
  2676. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2677. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2678. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2679. }
  2680. /* pause - not for e1 */
  2681. if (!CHIP_IS_E1(bp)) {
  2682. pause->bd_th_lo = BD_TH_LO(bp);
  2683. pause->bd_th_hi = BD_TH_HI(bp);
  2684. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2685. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2686. /*
  2687. * validate that rings have enough entries to cross
  2688. * high thresholds
  2689. */
  2690. WARN_ON(bp->dropless_fc &&
  2691. pause->bd_th_hi + FW_PREFETCH_CNT >
  2692. bp->rx_ring_size);
  2693. WARN_ON(bp->dropless_fc &&
  2694. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2695. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2696. pause->pri_map = 1;
  2697. }
  2698. /* rxq setup */
  2699. rxq_init->dscr_map = fp->rx_desc_mapping;
  2700. rxq_init->sge_map = fp->rx_sge_mapping;
  2701. rxq_init->rcq_map = fp->rx_comp_mapping;
  2702. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2703. /* This should be a maximum number of data bytes that may be
  2704. * placed on the BD (not including paddings).
  2705. */
  2706. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2707. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2708. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2709. rxq_init->tpa_agg_sz = tpa_agg_size;
  2710. rxq_init->sge_buf_sz = sge_sz;
  2711. rxq_init->max_sges_pkt = max_sge;
  2712. rxq_init->rss_engine_id = BP_FUNC(bp);
  2713. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2714. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2715. *
  2716. * For PF Clients it should be the maximum available number.
  2717. * VF driver(s) may want to define it to a smaller value.
  2718. */
  2719. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2720. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2721. rxq_init->fw_sb_id = fp->fw_sb_id;
  2722. if (IS_FCOE_FP(fp))
  2723. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2724. else
  2725. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2726. /* configure silent vlan removal
  2727. * if multi function mode is afex, then mask default vlan
  2728. */
  2729. if (IS_MF_AFEX(bp)) {
  2730. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2731. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2732. }
  2733. }
  2734. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2735. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2736. u8 cos)
  2737. {
  2738. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2739. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2740. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2741. txq_init->fw_sb_id = fp->fw_sb_id;
  2742. /*
  2743. * set the tss leading client id for TX classification ==
  2744. * leading RSS client id
  2745. */
  2746. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2747. if (IS_FCOE_FP(fp)) {
  2748. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2749. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2750. }
  2751. }
  2752. static void bnx2x_pf_init(struct bnx2x *bp)
  2753. {
  2754. struct bnx2x_func_init_params func_init = {0};
  2755. struct event_ring_data eq_data = { {0} };
  2756. u16 flags;
  2757. if (!CHIP_IS_E1x(bp)) {
  2758. /* reset IGU PF statistics: MSIX + ATTN */
  2759. /* PF */
  2760. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2761. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2762. (CHIP_MODE_IS_4_PORT(bp) ?
  2763. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2764. /* ATTN */
  2765. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2766. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2767. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2768. (CHIP_MODE_IS_4_PORT(bp) ?
  2769. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2770. }
  2771. /* function setup flags */
  2772. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2773. /* This flag is relevant for E1x only.
  2774. * E2 doesn't have a TPA configuration in a function level.
  2775. */
  2776. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2777. func_init.func_flgs = flags;
  2778. func_init.pf_id = BP_FUNC(bp);
  2779. func_init.func_id = BP_FUNC(bp);
  2780. func_init.spq_map = bp->spq_mapping;
  2781. func_init.spq_prod = bp->spq_prod_idx;
  2782. bnx2x_func_init(bp, &func_init);
  2783. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2784. /*
  2785. * Congestion management values depend on the link rate
  2786. * There is no active link so initial link rate is set to 10 Gbps.
  2787. * When the link comes up The congestion management values are
  2788. * re-calculated according to the actual link rate.
  2789. */
  2790. bp->link_vars.line_speed = SPEED_10000;
  2791. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2792. /* Only the PMF sets the HW */
  2793. if (bp->port.pmf)
  2794. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2795. /* init Event Queue - PCI bus guarantees correct endianity*/
  2796. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2797. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2798. eq_data.producer = bp->eq_prod;
  2799. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2800. eq_data.sb_id = DEF_SB_ID;
  2801. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2802. }
  2803. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2804. {
  2805. int port = BP_PORT(bp);
  2806. bnx2x_tx_disable(bp);
  2807. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2808. }
  2809. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2810. {
  2811. int port = BP_PORT(bp);
  2812. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2813. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2814. /* Tx queue should be only re-enabled */
  2815. netif_tx_wake_all_queues(bp->dev);
  2816. /*
  2817. * Should not call netif_carrier_on since it will be called if the link
  2818. * is up when checking for link state
  2819. */
  2820. }
  2821. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2822. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2823. {
  2824. struct eth_stats_info *ether_stat =
  2825. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2826. struct bnx2x_vlan_mac_obj *mac_obj =
  2827. &bp->sp_objs->mac_obj;
  2828. int i;
  2829. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2830. ETH_STAT_INFO_VERSION_LEN);
  2831. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2832. * mac_local field in ether_stat struct. The base address is offset by 2
  2833. * bytes to account for the field being 8 bytes but a mac address is
  2834. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2835. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2836. * allocated by the ether_stat struct, so the macs will land in their
  2837. * proper positions.
  2838. */
  2839. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2840. memset(ether_stat->mac_local + i, 0,
  2841. sizeof(ether_stat->mac_local[0]));
  2842. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2843. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2844. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2845. ETH_ALEN);
  2846. ether_stat->mtu_size = bp->dev->mtu;
  2847. if (bp->dev->features & NETIF_F_RXCSUM)
  2848. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2849. if (bp->dev->features & NETIF_F_TSO)
  2850. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2851. ether_stat->feature_flags |= bp->common.boot_mode;
  2852. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2853. ether_stat->txq_size = bp->tx_ring_size;
  2854. ether_stat->rxq_size = bp->rx_ring_size;
  2855. #ifdef CONFIG_BNX2X_SRIOV
  2856. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2857. #endif
  2858. }
  2859. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2860. {
  2861. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2862. struct fcoe_stats_info *fcoe_stat =
  2863. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2864. if (!CNIC_LOADED(bp))
  2865. return;
  2866. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2867. fcoe_stat->qos_priority =
  2868. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2869. /* insert FCoE stats from ramrod response */
  2870. if (!NO_FCOE(bp)) {
  2871. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2872. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2873. tstorm_queue_statistics;
  2874. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2875. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2876. xstorm_queue_statistics;
  2877. struct fcoe_statistics_params *fw_fcoe_stat =
  2878. &bp->fw_stats_data->fcoe;
  2879. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2880. fcoe_stat->rx_bytes_lo,
  2881. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2882. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2883. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2884. fcoe_stat->rx_bytes_lo,
  2885. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2886. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2887. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2888. fcoe_stat->rx_bytes_lo,
  2889. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2890. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2891. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2892. fcoe_stat->rx_bytes_lo,
  2893. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2894. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2895. fcoe_stat->rx_frames_lo,
  2896. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2897. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2898. fcoe_stat->rx_frames_lo,
  2899. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2900. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2901. fcoe_stat->rx_frames_lo,
  2902. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2903. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2904. fcoe_stat->rx_frames_lo,
  2905. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2906. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2907. fcoe_stat->tx_bytes_lo,
  2908. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2909. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2910. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2911. fcoe_stat->tx_bytes_lo,
  2912. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2913. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2914. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2915. fcoe_stat->tx_bytes_lo,
  2916. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2917. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2918. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2919. fcoe_stat->tx_bytes_lo,
  2920. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2921. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2922. fcoe_stat->tx_frames_lo,
  2923. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2924. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2925. fcoe_stat->tx_frames_lo,
  2926. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2927. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2928. fcoe_stat->tx_frames_lo,
  2929. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2930. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2931. fcoe_stat->tx_frames_lo,
  2932. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2933. }
  2934. /* ask L5 driver to add data to the struct */
  2935. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2936. }
  2937. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2938. {
  2939. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2940. struct iscsi_stats_info *iscsi_stat =
  2941. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2942. if (!CNIC_LOADED(bp))
  2943. return;
  2944. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2945. ETH_ALEN);
  2946. iscsi_stat->qos_priority =
  2947. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2948. /* ask L5 driver to add data to the struct */
  2949. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2950. }
  2951. /* called due to MCP event (on pmf):
  2952. * reread new bandwidth configuration
  2953. * configure FW
  2954. * notify others function about the change
  2955. */
  2956. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2957. {
  2958. if (bp->link_vars.link_up) {
  2959. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2960. bnx2x_link_sync_notify(bp);
  2961. }
  2962. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2963. }
  2964. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2965. {
  2966. bnx2x_config_mf_bw(bp);
  2967. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2968. }
  2969. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2970. {
  2971. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2972. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2973. }
  2974. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2975. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2976. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2977. {
  2978. enum drv_info_opcode op_code;
  2979. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2980. bool release = false;
  2981. int wait;
  2982. /* if drv_info version supported by MFW doesn't match - send NACK */
  2983. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2984. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2985. return;
  2986. }
  2987. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2988. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2989. /* Must prevent other flows from accessing drv_info_to_mcp */
  2990. mutex_lock(&bp->drv_info_mutex);
  2991. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2992. sizeof(union drv_info_to_mcp));
  2993. switch (op_code) {
  2994. case ETH_STATS_OPCODE:
  2995. bnx2x_drv_info_ether_stat(bp);
  2996. break;
  2997. case FCOE_STATS_OPCODE:
  2998. bnx2x_drv_info_fcoe_stat(bp);
  2999. break;
  3000. case ISCSI_STATS_OPCODE:
  3001. bnx2x_drv_info_iscsi_stat(bp);
  3002. break;
  3003. default:
  3004. /* if op code isn't supported - send NACK */
  3005. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3006. goto out;
  3007. }
  3008. /* if we got drv_info attn from MFW then these fields are defined in
  3009. * shmem2 for sure
  3010. */
  3011. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3012. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3013. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3014. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3015. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3016. /* Since possible management wants both this and get_driver_version
  3017. * need to wait until management notifies us it finished utilizing
  3018. * the buffer.
  3019. */
  3020. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3021. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3022. } else if (!bp->drv_info_mng_owner) {
  3023. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3024. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3025. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3026. /* Management is done; need to clear indication */
  3027. if (indication & bit) {
  3028. SHMEM2_WR(bp, mfw_drv_indication,
  3029. indication & ~bit);
  3030. release = true;
  3031. break;
  3032. }
  3033. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3034. }
  3035. }
  3036. if (!release) {
  3037. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3038. bp->drv_info_mng_owner = true;
  3039. }
  3040. out:
  3041. mutex_unlock(&bp->drv_info_mutex);
  3042. }
  3043. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3044. {
  3045. u8 vals[4];
  3046. int i = 0;
  3047. if (bnx2x_format) {
  3048. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3049. &vals[0], &vals[1], &vals[2], &vals[3]);
  3050. if (i > 0)
  3051. vals[0] -= '0';
  3052. } else {
  3053. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3054. &vals[0], &vals[1], &vals[2], &vals[3]);
  3055. }
  3056. while (i < 4)
  3057. vals[i++] = 0;
  3058. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3059. }
  3060. void bnx2x_update_mng_version(struct bnx2x *bp)
  3061. {
  3062. u32 iscsiver = DRV_VER_NOT_LOADED;
  3063. u32 fcoever = DRV_VER_NOT_LOADED;
  3064. u32 ethver = DRV_VER_NOT_LOADED;
  3065. int idx = BP_FW_MB_IDX(bp);
  3066. u8 *version;
  3067. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3068. return;
  3069. mutex_lock(&bp->drv_info_mutex);
  3070. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3071. if (bp->drv_info_mng_owner)
  3072. goto out;
  3073. if (bp->state != BNX2X_STATE_OPEN)
  3074. goto out;
  3075. /* Parse ethernet driver version */
  3076. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3077. if (!CNIC_LOADED(bp))
  3078. goto out;
  3079. /* Try getting storage driver version via cnic */
  3080. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3081. sizeof(union drv_info_to_mcp));
  3082. bnx2x_drv_info_iscsi_stat(bp);
  3083. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3084. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3085. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3086. sizeof(union drv_info_to_mcp));
  3087. bnx2x_drv_info_fcoe_stat(bp);
  3088. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3089. fcoever = bnx2x_update_mng_version_utility(version, false);
  3090. out:
  3091. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3092. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3093. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3094. mutex_unlock(&bp->drv_info_mutex);
  3095. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3096. ethver, iscsiver, fcoever);
  3097. }
  3098. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3099. {
  3100. u32 cmd_ok, cmd_fail;
  3101. /* sanity */
  3102. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3103. event & DRV_STATUS_OEM_EVENT_MASK) {
  3104. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3105. return;
  3106. }
  3107. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3108. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3109. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3110. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3111. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3112. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3113. }
  3114. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3115. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3116. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3117. /* This is the only place besides the function initialization
  3118. * where the bp->flags can change so it is done without any
  3119. * locks
  3120. */
  3121. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3122. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3123. bp->flags |= MF_FUNC_DIS;
  3124. bnx2x_e1h_disable(bp);
  3125. } else {
  3126. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3127. bp->flags &= ~MF_FUNC_DIS;
  3128. bnx2x_e1h_enable(bp);
  3129. }
  3130. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3131. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3132. }
  3133. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3134. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3135. bnx2x_config_mf_bw(bp);
  3136. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3137. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3138. }
  3139. /* Report results to MCP */
  3140. if (event)
  3141. bnx2x_fw_command(bp, cmd_fail, 0);
  3142. else
  3143. bnx2x_fw_command(bp, cmd_ok, 0);
  3144. }
  3145. /* must be called under the spq lock */
  3146. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3147. {
  3148. struct eth_spe *next_spe = bp->spq_prod_bd;
  3149. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3150. bp->spq_prod_bd = bp->spq;
  3151. bp->spq_prod_idx = 0;
  3152. DP(BNX2X_MSG_SP, "end of spq\n");
  3153. } else {
  3154. bp->spq_prod_bd++;
  3155. bp->spq_prod_idx++;
  3156. }
  3157. return next_spe;
  3158. }
  3159. /* must be called under the spq lock */
  3160. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3161. {
  3162. int func = BP_FUNC(bp);
  3163. /*
  3164. * Make sure that BD data is updated before writing the producer:
  3165. * BD data is written to the memory, the producer is read from the
  3166. * memory, thus we need a full memory barrier to ensure the ordering.
  3167. */
  3168. mb();
  3169. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3170. bp->spq_prod_idx);
  3171. mmiowb();
  3172. }
  3173. /**
  3174. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3175. *
  3176. * @cmd: command to check
  3177. * @cmd_type: command type
  3178. */
  3179. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3180. {
  3181. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3182. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3183. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3184. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3185. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3186. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3187. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3188. return true;
  3189. else
  3190. return false;
  3191. }
  3192. /**
  3193. * bnx2x_sp_post - place a single command on an SP ring
  3194. *
  3195. * @bp: driver handle
  3196. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3197. * @cid: SW CID the command is related to
  3198. * @data_hi: command private data address (high 32 bits)
  3199. * @data_lo: command private data address (low 32 bits)
  3200. * @cmd_type: command type (e.g. NONE, ETH)
  3201. *
  3202. * SP data is handled as if it's always an address pair, thus data fields are
  3203. * not swapped to little endian in upper functions. Instead this function swaps
  3204. * data as if it's two u32 fields.
  3205. */
  3206. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3207. u32 data_hi, u32 data_lo, int cmd_type)
  3208. {
  3209. struct eth_spe *spe;
  3210. u16 type;
  3211. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3212. #ifdef BNX2X_STOP_ON_ERROR
  3213. if (unlikely(bp->panic)) {
  3214. BNX2X_ERR("Can't post SP when there is panic\n");
  3215. return -EIO;
  3216. }
  3217. #endif
  3218. spin_lock_bh(&bp->spq_lock);
  3219. if (common) {
  3220. if (!atomic_read(&bp->eq_spq_left)) {
  3221. BNX2X_ERR("BUG! EQ ring full!\n");
  3222. spin_unlock_bh(&bp->spq_lock);
  3223. bnx2x_panic();
  3224. return -EBUSY;
  3225. }
  3226. } else if (!atomic_read(&bp->cq_spq_left)) {
  3227. BNX2X_ERR("BUG! SPQ ring full!\n");
  3228. spin_unlock_bh(&bp->spq_lock);
  3229. bnx2x_panic();
  3230. return -EBUSY;
  3231. }
  3232. spe = bnx2x_sp_get_next(bp);
  3233. /* CID needs port number to be encoded int it */
  3234. spe->hdr.conn_and_cmd_data =
  3235. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3236. HW_CID(bp, cid));
  3237. /* In some cases, type may already contain the func-id
  3238. * mainly in SRIOV related use cases, so we add it here only
  3239. * if it's not already set.
  3240. */
  3241. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3242. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3243. SPE_HDR_CONN_TYPE;
  3244. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3245. SPE_HDR_FUNCTION_ID);
  3246. } else {
  3247. type = cmd_type;
  3248. }
  3249. spe->hdr.type = cpu_to_le16(type);
  3250. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3251. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3252. /*
  3253. * It's ok if the actual decrement is issued towards the memory
  3254. * somewhere between the spin_lock and spin_unlock. Thus no
  3255. * more explicit memory barrier is needed.
  3256. */
  3257. if (common)
  3258. atomic_dec(&bp->eq_spq_left);
  3259. else
  3260. atomic_dec(&bp->cq_spq_left);
  3261. DP(BNX2X_MSG_SP,
  3262. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3263. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3264. (u32)(U64_LO(bp->spq_mapping) +
  3265. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3266. HW_CID(bp, cid), data_hi, data_lo, type,
  3267. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3268. bnx2x_sp_prod_update(bp);
  3269. spin_unlock_bh(&bp->spq_lock);
  3270. return 0;
  3271. }
  3272. /* acquire split MCP access lock register */
  3273. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3274. {
  3275. u32 j, val;
  3276. int rc = 0;
  3277. might_sleep();
  3278. for (j = 0; j < 1000; j++) {
  3279. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3280. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3281. if (val & MCPR_ACCESS_LOCK_LOCK)
  3282. break;
  3283. usleep_range(5000, 10000);
  3284. }
  3285. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3286. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3287. rc = -EBUSY;
  3288. }
  3289. return rc;
  3290. }
  3291. /* release split MCP access lock register */
  3292. static void bnx2x_release_alr(struct bnx2x *bp)
  3293. {
  3294. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3295. }
  3296. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3297. #define BNX2X_DEF_SB_IDX 0x0002
  3298. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3299. {
  3300. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3301. u16 rc = 0;
  3302. barrier(); /* status block is written to by the chip */
  3303. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3304. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3305. rc |= BNX2X_DEF_SB_ATT_IDX;
  3306. }
  3307. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3308. bp->def_idx = def_sb->sp_sb.running_index;
  3309. rc |= BNX2X_DEF_SB_IDX;
  3310. }
  3311. /* Do not reorder: indices reading should complete before handling */
  3312. barrier();
  3313. return rc;
  3314. }
  3315. /*
  3316. * slow path service functions
  3317. */
  3318. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3319. {
  3320. int port = BP_PORT(bp);
  3321. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3322. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3323. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3324. NIG_REG_MASK_INTERRUPT_PORT0;
  3325. u32 aeu_mask;
  3326. u32 nig_mask = 0;
  3327. u32 reg_addr;
  3328. if (bp->attn_state & asserted)
  3329. BNX2X_ERR("IGU ERROR\n");
  3330. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3331. aeu_mask = REG_RD(bp, aeu_addr);
  3332. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3333. aeu_mask, asserted);
  3334. aeu_mask &= ~(asserted & 0x3ff);
  3335. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3336. REG_WR(bp, aeu_addr, aeu_mask);
  3337. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3338. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3339. bp->attn_state |= asserted;
  3340. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3341. if (asserted & ATTN_HARD_WIRED_MASK) {
  3342. if (asserted & ATTN_NIG_FOR_FUNC) {
  3343. bnx2x_acquire_phy_lock(bp);
  3344. /* save nig interrupt mask */
  3345. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3346. /* If nig_mask is not set, no need to call the update
  3347. * function.
  3348. */
  3349. if (nig_mask) {
  3350. REG_WR(bp, nig_int_mask_addr, 0);
  3351. bnx2x_link_attn(bp);
  3352. }
  3353. /* handle unicore attn? */
  3354. }
  3355. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3356. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3357. if (asserted & GPIO_2_FUNC)
  3358. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3359. if (asserted & GPIO_3_FUNC)
  3360. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3361. if (asserted & GPIO_4_FUNC)
  3362. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3363. if (port == 0) {
  3364. if (asserted & ATTN_GENERAL_ATTN_1) {
  3365. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3366. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3367. }
  3368. if (asserted & ATTN_GENERAL_ATTN_2) {
  3369. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3370. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3371. }
  3372. if (asserted & ATTN_GENERAL_ATTN_3) {
  3373. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3374. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3375. }
  3376. } else {
  3377. if (asserted & ATTN_GENERAL_ATTN_4) {
  3378. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3379. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3380. }
  3381. if (asserted & ATTN_GENERAL_ATTN_5) {
  3382. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3383. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3384. }
  3385. if (asserted & ATTN_GENERAL_ATTN_6) {
  3386. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3387. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3388. }
  3389. }
  3390. } /* if hardwired */
  3391. if (bp->common.int_block == INT_BLOCK_HC)
  3392. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3393. COMMAND_REG_ATTN_BITS_SET);
  3394. else
  3395. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3396. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3397. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3398. REG_WR(bp, reg_addr, asserted);
  3399. /* now set back the mask */
  3400. if (asserted & ATTN_NIG_FOR_FUNC) {
  3401. /* Verify that IGU ack through BAR was written before restoring
  3402. * NIG mask. This loop should exit after 2-3 iterations max.
  3403. */
  3404. if (bp->common.int_block != INT_BLOCK_HC) {
  3405. u32 cnt = 0, igu_acked;
  3406. do {
  3407. igu_acked = REG_RD(bp,
  3408. IGU_REG_ATTENTION_ACK_BITS);
  3409. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3410. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3411. if (!igu_acked)
  3412. DP(NETIF_MSG_HW,
  3413. "Failed to verify IGU ack on time\n");
  3414. barrier();
  3415. }
  3416. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3417. bnx2x_release_phy_lock(bp);
  3418. }
  3419. }
  3420. static void bnx2x_fan_failure(struct bnx2x *bp)
  3421. {
  3422. int port = BP_PORT(bp);
  3423. u32 ext_phy_config;
  3424. /* mark the failure */
  3425. ext_phy_config =
  3426. SHMEM_RD(bp,
  3427. dev_info.port_hw_config[port].external_phy_config);
  3428. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3429. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3430. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3431. ext_phy_config);
  3432. /* log the failure */
  3433. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3434. "Please contact OEM Support for assistance\n");
  3435. /* Schedule device reset (unload)
  3436. * This is due to some boards consuming sufficient power when driver is
  3437. * up to overheat if fan fails.
  3438. */
  3439. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3440. }
  3441. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3442. {
  3443. int port = BP_PORT(bp);
  3444. int reg_offset;
  3445. u32 val;
  3446. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3447. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3448. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3449. val = REG_RD(bp, reg_offset);
  3450. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3451. REG_WR(bp, reg_offset, val);
  3452. BNX2X_ERR("SPIO5 hw attention\n");
  3453. /* Fan failure attention */
  3454. bnx2x_hw_reset_phy(&bp->link_params);
  3455. bnx2x_fan_failure(bp);
  3456. }
  3457. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3458. bnx2x_acquire_phy_lock(bp);
  3459. bnx2x_handle_module_detect_int(&bp->link_params);
  3460. bnx2x_release_phy_lock(bp);
  3461. }
  3462. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3463. val = REG_RD(bp, reg_offset);
  3464. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3465. REG_WR(bp, reg_offset, val);
  3466. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3467. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3468. bnx2x_panic();
  3469. }
  3470. }
  3471. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3472. {
  3473. u32 val;
  3474. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3475. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3476. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3477. /* DORQ discard attention */
  3478. if (val & 0x2)
  3479. BNX2X_ERR("FATAL error from DORQ\n");
  3480. }
  3481. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3482. int port = BP_PORT(bp);
  3483. int reg_offset;
  3484. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3485. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3486. val = REG_RD(bp, reg_offset);
  3487. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3488. REG_WR(bp, reg_offset, val);
  3489. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3490. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3491. bnx2x_panic();
  3492. }
  3493. }
  3494. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3495. {
  3496. u32 val;
  3497. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3498. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3499. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3500. /* CFC error attention */
  3501. if (val & 0x2)
  3502. BNX2X_ERR("FATAL error from CFC\n");
  3503. }
  3504. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3505. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3506. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3507. /* RQ_USDMDP_FIFO_OVERFLOW */
  3508. if (val & 0x18000)
  3509. BNX2X_ERR("FATAL error from PXP\n");
  3510. if (!CHIP_IS_E1x(bp)) {
  3511. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3512. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3513. }
  3514. }
  3515. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3516. int port = BP_PORT(bp);
  3517. int reg_offset;
  3518. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3519. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3520. val = REG_RD(bp, reg_offset);
  3521. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3522. REG_WR(bp, reg_offset, val);
  3523. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3524. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3525. bnx2x_panic();
  3526. }
  3527. }
  3528. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3529. {
  3530. u32 val;
  3531. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3532. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3533. int func = BP_FUNC(bp);
  3534. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3535. bnx2x_read_mf_cfg(bp);
  3536. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3537. func_mf_config[BP_ABS_FUNC(bp)].config);
  3538. val = SHMEM_RD(bp,
  3539. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3540. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3541. DRV_STATUS_OEM_EVENT_MASK))
  3542. bnx2x_oem_event(bp,
  3543. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3544. DRV_STATUS_OEM_EVENT_MASK)));
  3545. if (val & DRV_STATUS_SET_MF_BW)
  3546. bnx2x_set_mf_bw(bp);
  3547. if (val & DRV_STATUS_DRV_INFO_REQ)
  3548. bnx2x_handle_drv_info_req(bp);
  3549. if (val & DRV_STATUS_VF_DISABLED)
  3550. bnx2x_schedule_iov_task(bp,
  3551. BNX2X_IOV_HANDLE_FLR);
  3552. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3553. bnx2x_pmf_update(bp);
  3554. if (bp->port.pmf &&
  3555. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3556. bp->dcbx_enabled > 0)
  3557. /* start dcbx state machine */
  3558. bnx2x_dcbx_set_params(bp,
  3559. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3560. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3561. bnx2x_handle_afex_cmd(bp,
  3562. val & DRV_STATUS_AFEX_EVENT_MASK);
  3563. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3564. bnx2x_handle_eee_event(bp);
  3565. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3566. bnx2x_handle_update_svid_cmd(bp);
  3567. if (bp->link_vars.periodic_flags &
  3568. PERIODIC_FLAGS_LINK_EVENT) {
  3569. /* sync with link */
  3570. bnx2x_acquire_phy_lock(bp);
  3571. bp->link_vars.periodic_flags &=
  3572. ~PERIODIC_FLAGS_LINK_EVENT;
  3573. bnx2x_release_phy_lock(bp);
  3574. if (IS_MF(bp))
  3575. bnx2x_link_sync_notify(bp);
  3576. bnx2x_link_report(bp);
  3577. }
  3578. /* Always call it here: bnx2x_link_report() will
  3579. * prevent the link indication duplication.
  3580. */
  3581. bnx2x__link_status_update(bp);
  3582. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3583. BNX2X_ERR("MC assert!\n");
  3584. bnx2x_mc_assert(bp);
  3585. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3586. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3587. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3588. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3589. bnx2x_panic();
  3590. } else if (attn & BNX2X_MCP_ASSERT) {
  3591. BNX2X_ERR("MCP assert!\n");
  3592. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3593. bnx2x_fw_dump(bp);
  3594. } else
  3595. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3596. }
  3597. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3598. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3599. if (attn & BNX2X_GRC_TIMEOUT) {
  3600. val = CHIP_IS_E1(bp) ? 0 :
  3601. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3602. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3603. }
  3604. if (attn & BNX2X_GRC_RSV) {
  3605. val = CHIP_IS_E1(bp) ? 0 :
  3606. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3607. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3608. }
  3609. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3610. }
  3611. }
  3612. /*
  3613. * Bits map:
  3614. * 0-7 - Engine0 load counter.
  3615. * 8-15 - Engine1 load counter.
  3616. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3617. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3618. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3619. * on the engine
  3620. * 19 - Engine1 ONE_IS_LOADED.
  3621. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3622. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3623. * just the one belonging to its engine).
  3624. *
  3625. */
  3626. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3627. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3628. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3629. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3630. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3631. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3632. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3633. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3634. /*
  3635. * Set the GLOBAL_RESET bit.
  3636. *
  3637. * Should be run under rtnl lock
  3638. */
  3639. void bnx2x_set_reset_global(struct bnx2x *bp)
  3640. {
  3641. u32 val;
  3642. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3643. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3644. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3645. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3646. }
  3647. /*
  3648. * Clear the GLOBAL_RESET bit.
  3649. *
  3650. * Should be run under rtnl lock
  3651. */
  3652. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3653. {
  3654. u32 val;
  3655. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3656. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3657. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3658. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3659. }
  3660. /*
  3661. * Checks the GLOBAL_RESET bit.
  3662. *
  3663. * should be run under rtnl lock
  3664. */
  3665. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3666. {
  3667. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3668. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3669. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3670. }
  3671. /*
  3672. * Clear RESET_IN_PROGRESS bit for the current engine.
  3673. *
  3674. * Should be run under rtnl lock
  3675. */
  3676. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3677. {
  3678. u32 val;
  3679. u32 bit = BP_PATH(bp) ?
  3680. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3681. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3682. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3683. /* Clear the bit */
  3684. val &= ~bit;
  3685. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3686. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3687. }
  3688. /*
  3689. * Set RESET_IN_PROGRESS for the current engine.
  3690. *
  3691. * should be run under rtnl lock
  3692. */
  3693. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3694. {
  3695. u32 val;
  3696. u32 bit = BP_PATH(bp) ?
  3697. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3698. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3699. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3700. /* Set the bit */
  3701. val |= bit;
  3702. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3703. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3704. }
  3705. /*
  3706. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3707. * should be run under rtnl lock
  3708. */
  3709. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3710. {
  3711. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3712. u32 bit = engine ?
  3713. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3714. /* return false if bit is set */
  3715. return (val & bit) ? false : true;
  3716. }
  3717. /*
  3718. * set pf load for the current pf.
  3719. *
  3720. * should be run under rtnl lock
  3721. */
  3722. void bnx2x_set_pf_load(struct bnx2x *bp)
  3723. {
  3724. u32 val1, val;
  3725. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3726. BNX2X_PATH0_LOAD_CNT_MASK;
  3727. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3728. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3729. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3730. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3731. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3732. /* get the current counter value */
  3733. val1 = (val & mask) >> shift;
  3734. /* set bit of that PF */
  3735. val1 |= (1 << bp->pf_num);
  3736. /* clear the old value */
  3737. val &= ~mask;
  3738. /* set the new one */
  3739. val |= ((val1 << shift) & mask);
  3740. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3741. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3742. }
  3743. /**
  3744. * bnx2x_clear_pf_load - clear pf load mark
  3745. *
  3746. * @bp: driver handle
  3747. *
  3748. * Should be run under rtnl lock.
  3749. * Decrements the load counter for the current engine. Returns
  3750. * whether other functions are still loaded
  3751. */
  3752. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3753. {
  3754. u32 val1, val;
  3755. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3756. BNX2X_PATH0_LOAD_CNT_MASK;
  3757. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3758. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3759. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3760. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3761. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3762. /* get the current counter value */
  3763. val1 = (val & mask) >> shift;
  3764. /* clear bit of that PF */
  3765. val1 &= ~(1 << bp->pf_num);
  3766. /* clear the old value */
  3767. val &= ~mask;
  3768. /* set the new one */
  3769. val |= ((val1 << shift) & mask);
  3770. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3771. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3772. return val1 != 0;
  3773. }
  3774. /*
  3775. * Read the load status for the current engine.
  3776. *
  3777. * should be run under rtnl lock
  3778. */
  3779. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3780. {
  3781. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3782. BNX2X_PATH0_LOAD_CNT_MASK);
  3783. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3784. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3785. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3786. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3787. val = (val & mask) >> shift;
  3788. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3789. engine, val);
  3790. return val != 0;
  3791. }
  3792. static void _print_parity(struct bnx2x *bp, u32 reg)
  3793. {
  3794. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3795. }
  3796. static void _print_next_block(int idx, const char *blk)
  3797. {
  3798. pr_cont("%s%s", idx ? ", " : "", blk);
  3799. }
  3800. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3801. int *par_num, bool print)
  3802. {
  3803. u32 cur_bit;
  3804. bool res;
  3805. int i;
  3806. res = false;
  3807. for (i = 0; sig; i++) {
  3808. cur_bit = (0x1UL << i);
  3809. if (sig & cur_bit) {
  3810. res |= true; /* Each bit is real error! */
  3811. if (print) {
  3812. switch (cur_bit) {
  3813. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3814. _print_next_block((*par_num)++, "BRB");
  3815. _print_parity(bp,
  3816. BRB1_REG_BRB1_PRTY_STS);
  3817. break;
  3818. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3819. _print_next_block((*par_num)++,
  3820. "PARSER");
  3821. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3822. break;
  3823. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3824. _print_next_block((*par_num)++, "TSDM");
  3825. _print_parity(bp,
  3826. TSDM_REG_TSDM_PRTY_STS);
  3827. break;
  3828. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3829. _print_next_block((*par_num)++,
  3830. "SEARCHER");
  3831. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3832. break;
  3833. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3834. _print_next_block((*par_num)++, "TCM");
  3835. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3836. break;
  3837. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3838. _print_next_block((*par_num)++,
  3839. "TSEMI");
  3840. _print_parity(bp,
  3841. TSEM_REG_TSEM_PRTY_STS_0);
  3842. _print_parity(bp,
  3843. TSEM_REG_TSEM_PRTY_STS_1);
  3844. break;
  3845. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3846. _print_next_block((*par_num)++, "XPB");
  3847. _print_parity(bp, GRCBASE_XPB +
  3848. PB_REG_PB_PRTY_STS);
  3849. break;
  3850. }
  3851. }
  3852. /* Clear the bit */
  3853. sig &= ~cur_bit;
  3854. }
  3855. }
  3856. return res;
  3857. }
  3858. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3859. int *par_num, bool *global,
  3860. bool print)
  3861. {
  3862. u32 cur_bit;
  3863. bool res;
  3864. int i;
  3865. res = false;
  3866. for (i = 0; sig; i++) {
  3867. cur_bit = (0x1UL << i);
  3868. if (sig & cur_bit) {
  3869. res |= true; /* Each bit is real error! */
  3870. switch (cur_bit) {
  3871. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3872. if (print) {
  3873. _print_next_block((*par_num)++, "PBF");
  3874. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3875. }
  3876. break;
  3877. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3878. if (print) {
  3879. _print_next_block((*par_num)++, "QM");
  3880. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3881. }
  3882. break;
  3883. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3884. if (print) {
  3885. _print_next_block((*par_num)++, "TM");
  3886. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3887. }
  3888. break;
  3889. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3890. if (print) {
  3891. _print_next_block((*par_num)++, "XSDM");
  3892. _print_parity(bp,
  3893. XSDM_REG_XSDM_PRTY_STS);
  3894. }
  3895. break;
  3896. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3897. if (print) {
  3898. _print_next_block((*par_num)++, "XCM");
  3899. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3900. }
  3901. break;
  3902. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3903. if (print) {
  3904. _print_next_block((*par_num)++,
  3905. "XSEMI");
  3906. _print_parity(bp,
  3907. XSEM_REG_XSEM_PRTY_STS_0);
  3908. _print_parity(bp,
  3909. XSEM_REG_XSEM_PRTY_STS_1);
  3910. }
  3911. break;
  3912. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3913. if (print) {
  3914. _print_next_block((*par_num)++,
  3915. "DOORBELLQ");
  3916. _print_parity(bp,
  3917. DORQ_REG_DORQ_PRTY_STS);
  3918. }
  3919. break;
  3920. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3921. if (print) {
  3922. _print_next_block((*par_num)++, "NIG");
  3923. if (CHIP_IS_E1x(bp)) {
  3924. _print_parity(bp,
  3925. NIG_REG_NIG_PRTY_STS);
  3926. } else {
  3927. _print_parity(bp,
  3928. NIG_REG_NIG_PRTY_STS_0);
  3929. _print_parity(bp,
  3930. NIG_REG_NIG_PRTY_STS_1);
  3931. }
  3932. }
  3933. break;
  3934. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3935. if (print)
  3936. _print_next_block((*par_num)++,
  3937. "VAUX PCI CORE");
  3938. *global = true;
  3939. break;
  3940. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3941. if (print) {
  3942. _print_next_block((*par_num)++,
  3943. "DEBUG");
  3944. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3945. }
  3946. break;
  3947. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3948. if (print) {
  3949. _print_next_block((*par_num)++, "USDM");
  3950. _print_parity(bp,
  3951. USDM_REG_USDM_PRTY_STS);
  3952. }
  3953. break;
  3954. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3955. if (print) {
  3956. _print_next_block((*par_num)++, "UCM");
  3957. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3958. }
  3959. break;
  3960. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3961. if (print) {
  3962. _print_next_block((*par_num)++,
  3963. "USEMI");
  3964. _print_parity(bp,
  3965. USEM_REG_USEM_PRTY_STS_0);
  3966. _print_parity(bp,
  3967. USEM_REG_USEM_PRTY_STS_1);
  3968. }
  3969. break;
  3970. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3971. if (print) {
  3972. _print_next_block((*par_num)++, "UPB");
  3973. _print_parity(bp, GRCBASE_UPB +
  3974. PB_REG_PB_PRTY_STS);
  3975. }
  3976. break;
  3977. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3978. if (print) {
  3979. _print_next_block((*par_num)++, "CSDM");
  3980. _print_parity(bp,
  3981. CSDM_REG_CSDM_PRTY_STS);
  3982. }
  3983. break;
  3984. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3985. if (print) {
  3986. _print_next_block((*par_num)++, "CCM");
  3987. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3988. }
  3989. break;
  3990. }
  3991. /* Clear the bit */
  3992. sig &= ~cur_bit;
  3993. }
  3994. }
  3995. return res;
  3996. }
  3997. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3998. int *par_num, bool print)
  3999. {
  4000. u32 cur_bit;
  4001. bool res;
  4002. int i;
  4003. res = false;
  4004. for (i = 0; sig; i++) {
  4005. cur_bit = (0x1UL << i);
  4006. if (sig & cur_bit) {
  4007. res = true; /* Each bit is real error! */
  4008. if (print) {
  4009. switch (cur_bit) {
  4010. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4011. _print_next_block((*par_num)++,
  4012. "CSEMI");
  4013. _print_parity(bp,
  4014. CSEM_REG_CSEM_PRTY_STS_0);
  4015. _print_parity(bp,
  4016. CSEM_REG_CSEM_PRTY_STS_1);
  4017. break;
  4018. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4019. _print_next_block((*par_num)++, "PXP");
  4020. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4021. _print_parity(bp,
  4022. PXP2_REG_PXP2_PRTY_STS_0);
  4023. _print_parity(bp,
  4024. PXP2_REG_PXP2_PRTY_STS_1);
  4025. break;
  4026. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4027. _print_next_block((*par_num)++,
  4028. "PXPPCICLOCKCLIENT");
  4029. break;
  4030. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4031. _print_next_block((*par_num)++, "CFC");
  4032. _print_parity(bp,
  4033. CFC_REG_CFC_PRTY_STS);
  4034. break;
  4035. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4036. _print_next_block((*par_num)++, "CDU");
  4037. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4038. break;
  4039. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4040. _print_next_block((*par_num)++, "DMAE");
  4041. _print_parity(bp,
  4042. DMAE_REG_DMAE_PRTY_STS);
  4043. break;
  4044. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4045. _print_next_block((*par_num)++, "IGU");
  4046. if (CHIP_IS_E1x(bp))
  4047. _print_parity(bp,
  4048. HC_REG_HC_PRTY_STS);
  4049. else
  4050. _print_parity(bp,
  4051. IGU_REG_IGU_PRTY_STS);
  4052. break;
  4053. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4054. _print_next_block((*par_num)++, "MISC");
  4055. _print_parity(bp,
  4056. MISC_REG_MISC_PRTY_STS);
  4057. break;
  4058. }
  4059. }
  4060. /* Clear the bit */
  4061. sig &= ~cur_bit;
  4062. }
  4063. }
  4064. return res;
  4065. }
  4066. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4067. int *par_num, bool *global,
  4068. bool print)
  4069. {
  4070. bool res = false;
  4071. u32 cur_bit;
  4072. int i;
  4073. for (i = 0; sig; i++) {
  4074. cur_bit = (0x1UL << i);
  4075. if (sig & cur_bit) {
  4076. switch (cur_bit) {
  4077. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4078. if (print)
  4079. _print_next_block((*par_num)++,
  4080. "MCP ROM");
  4081. *global = true;
  4082. res = true;
  4083. break;
  4084. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4085. if (print)
  4086. _print_next_block((*par_num)++,
  4087. "MCP UMP RX");
  4088. *global = true;
  4089. res = true;
  4090. break;
  4091. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4092. if (print)
  4093. _print_next_block((*par_num)++,
  4094. "MCP UMP TX");
  4095. *global = true;
  4096. res = true;
  4097. break;
  4098. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4099. if (print)
  4100. _print_next_block((*par_num)++,
  4101. "MCP SCPAD");
  4102. /* clear latched SCPAD PATIRY from MCP */
  4103. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4104. 1UL << 10);
  4105. break;
  4106. }
  4107. /* Clear the bit */
  4108. sig &= ~cur_bit;
  4109. }
  4110. }
  4111. return res;
  4112. }
  4113. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4114. int *par_num, bool print)
  4115. {
  4116. u32 cur_bit;
  4117. bool res;
  4118. int i;
  4119. res = false;
  4120. for (i = 0; sig; i++) {
  4121. cur_bit = (0x1UL << i);
  4122. if (sig & cur_bit) {
  4123. res = true; /* Each bit is real error! */
  4124. if (print) {
  4125. switch (cur_bit) {
  4126. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4127. _print_next_block((*par_num)++,
  4128. "PGLUE_B");
  4129. _print_parity(bp,
  4130. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4131. break;
  4132. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4133. _print_next_block((*par_num)++, "ATC");
  4134. _print_parity(bp,
  4135. ATC_REG_ATC_PRTY_STS);
  4136. break;
  4137. }
  4138. }
  4139. /* Clear the bit */
  4140. sig &= ~cur_bit;
  4141. }
  4142. }
  4143. return res;
  4144. }
  4145. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4146. u32 *sig)
  4147. {
  4148. bool res = false;
  4149. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4150. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4151. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4152. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4153. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4154. int par_num = 0;
  4155. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4156. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4157. sig[0] & HW_PRTY_ASSERT_SET_0,
  4158. sig[1] & HW_PRTY_ASSERT_SET_1,
  4159. sig[2] & HW_PRTY_ASSERT_SET_2,
  4160. sig[3] & HW_PRTY_ASSERT_SET_3,
  4161. sig[4] & HW_PRTY_ASSERT_SET_4);
  4162. if (print)
  4163. netdev_err(bp->dev,
  4164. "Parity errors detected in blocks: ");
  4165. res |= bnx2x_check_blocks_with_parity0(bp,
  4166. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4167. res |= bnx2x_check_blocks_with_parity1(bp,
  4168. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4169. res |= bnx2x_check_blocks_with_parity2(bp,
  4170. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4171. res |= bnx2x_check_blocks_with_parity3(bp,
  4172. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4173. res |= bnx2x_check_blocks_with_parity4(bp,
  4174. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4175. if (print)
  4176. pr_cont("\n");
  4177. }
  4178. return res;
  4179. }
  4180. /**
  4181. * bnx2x_chk_parity_attn - checks for parity attentions.
  4182. *
  4183. * @bp: driver handle
  4184. * @global: true if there was a global attention
  4185. * @print: show parity attention in syslog
  4186. */
  4187. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4188. {
  4189. struct attn_route attn = { {0} };
  4190. int port = BP_PORT(bp);
  4191. attn.sig[0] = REG_RD(bp,
  4192. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4193. port*4);
  4194. attn.sig[1] = REG_RD(bp,
  4195. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4196. port*4);
  4197. attn.sig[2] = REG_RD(bp,
  4198. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4199. port*4);
  4200. attn.sig[3] = REG_RD(bp,
  4201. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4202. port*4);
  4203. /* Since MCP attentions can't be disabled inside the block, we need to
  4204. * read AEU registers to see whether they're currently disabled
  4205. */
  4206. attn.sig[3] &= ((REG_RD(bp,
  4207. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4208. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4209. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4210. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4211. if (!CHIP_IS_E1x(bp))
  4212. attn.sig[4] = REG_RD(bp,
  4213. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4214. port*4);
  4215. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4216. }
  4217. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4218. {
  4219. u32 val;
  4220. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4221. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4222. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4223. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4224. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4225. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4226. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4227. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4228. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4229. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4230. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4231. if (val &
  4232. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4233. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4234. if (val &
  4235. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4236. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4237. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4238. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4239. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4240. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4241. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4242. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4243. }
  4244. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4245. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4246. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4247. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4248. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4249. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4250. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4251. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4252. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4253. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4254. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4255. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4256. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4257. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4258. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4259. }
  4260. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4261. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4262. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4263. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4264. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4265. }
  4266. }
  4267. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4268. {
  4269. struct attn_route attn, *group_mask;
  4270. int port = BP_PORT(bp);
  4271. int index;
  4272. u32 reg_addr;
  4273. u32 val;
  4274. u32 aeu_mask;
  4275. bool global = false;
  4276. /* need to take HW lock because MCP or other port might also
  4277. try to handle this event */
  4278. bnx2x_acquire_alr(bp);
  4279. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4280. #ifndef BNX2X_STOP_ON_ERROR
  4281. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4282. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4283. /* Disable HW interrupts */
  4284. bnx2x_int_disable(bp);
  4285. /* In case of parity errors don't handle attentions so that
  4286. * other function would "see" parity errors.
  4287. */
  4288. #else
  4289. bnx2x_panic();
  4290. #endif
  4291. bnx2x_release_alr(bp);
  4292. return;
  4293. }
  4294. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4295. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4296. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4297. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4298. if (!CHIP_IS_E1x(bp))
  4299. attn.sig[4] =
  4300. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4301. else
  4302. attn.sig[4] = 0;
  4303. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4304. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4305. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4306. if (deasserted & (1 << index)) {
  4307. group_mask = &bp->attn_group[index];
  4308. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4309. index,
  4310. group_mask->sig[0], group_mask->sig[1],
  4311. group_mask->sig[2], group_mask->sig[3],
  4312. group_mask->sig[4]);
  4313. bnx2x_attn_int_deasserted4(bp,
  4314. attn.sig[4] & group_mask->sig[4]);
  4315. bnx2x_attn_int_deasserted3(bp,
  4316. attn.sig[3] & group_mask->sig[3]);
  4317. bnx2x_attn_int_deasserted1(bp,
  4318. attn.sig[1] & group_mask->sig[1]);
  4319. bnx2x_attn_int_deasserted2(bp,
  4320. attn.sig[2] & group_mask->sig[2]);
  4321. bnx2x_attn_int_deasserted0(bp,
  4322. attn.sig[0] & group_mask->sig[0]);
  4323. }
  4324. }
  4325. bnx2x_release_alr(bp);
  4326. if (bp->common.int_block == INT_BLOCK_HC)
  4327. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4328. COMMAND_REG_ATTN_BITS_CLR);
  4329. else
  4330. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4331. val = ~deasserted;
  4332. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4333. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4334. REG_WR(bp, reg_addr, val);
  4335. if (~bp->attn_state & deasserted)
  4336. BNX2X_ERR("IGU ERROR\n");
  4337. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4338. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4339. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4340. aeu_mask = REG_RD(bp, reg_addr);
  4341. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4342. aeu_mask, deasserted);
  4343. aeu_mask |= (deasserted & 0x3ff);
  4344. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4345. REG_WR(bp, reg_addr, aeu_mask);
  4346. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4347. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4348. bp->attn_state &= ~deasserted;
  4349. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4350. }
  4351. static void bnx2x_attn_int(struct bnx2x *bp)
  4352. {
  4353. /* read local copy of bits */
  4354. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4355. attn_bits);
  4356. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4357. attn_bits_ack);
  4358. u32 attn_state = bp->attn_state;
  4359. /* look for changed bits */
  4360. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4361. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4362. DP(NETIF_MSG_HW,
  4363. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4364. attn_bits, attn_ack, asserted, deasserted);
  4365. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4366. BNX2X_ERR("BAD attention state\n");
  4367. /* handle bits that were raised */
  4368. if (asserted)
  4369. bnx2x_attn_int_asserted(bp, asserted);
  4370. if (deasserted)
  4371. bnx2x_attn_int_deasserted(bp, deasserted);
  4372. }
  4373. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4374. u16 index, u8 op, u8 update)
  4375. {
  4376. u32 igu_addr = bp->igu_base_addr;
  4377. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4378. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4379. igu_addr);
  4380. }
  4381. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4382. {
  4383. /* No memory barriers */
  4384. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4385. mmiowb(); /* keep prod updates ordered */
  4386. }
  4387. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4388. union event_ring_elem *elem)
  4389. {
  4390. u8 err = elem->message.error;
  4391. if (!bp->cnic_eth_dev.starting_cid ||
  4392. (cid < bp->cnic_eth_dev.starting_cid &&
  4393. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4394. return 1;
  4395. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4396. if (unlikely(err)) {
  4397. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4398. cid);
  4399. bnx2x_panic_dump(bp, false);
  4400. }
  4401. bnx2x_cnic_cfc_comp(bp, cid, err);
  4402. return 0;
  4403. }
  4404. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4405. {
  4406. struct bnx2x_mcast_ramrod_params rparam;
  4407. int rc;
  4408. memset(&rparam, 0, sizeof(rparam));
  4409. rparam.mcast_obj = &bp->mcast_obj;
  4410. netif_addr_lock_bh(bp->dev);
  4411. /* Clear pending state for the last command */
  4412. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4413. /* If there are pending mcast commands - send them */
  4414. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4415. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4416. if (rc < 0)
  4417. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4418. rc);
  4419. }
  4420. netif_addr_unlock_bh(bp->dev);
  4421. }
  4422. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4423. union event_ring_elem *elem)
  4424. {
  4425. unsigned long ramrod_flags = 0;
  4426. int rc = 0;
  4427. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4428. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4429. /* Always push next commands out, don't wait here */
  4430. __set_bit(RAMROD_CONT, &ramrod_flags);
  4431. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4432. >> BNX2X_SWCID_SHIFT) {
  4433. case BNX2X_FILTER_MAC_PENDING:
  4434. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4435. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4436. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4437. else
  4438. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4439. break;
  4440. case BNX2X_FILTER_MCAST_PENDING:
  4441. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4442. /* This is only relevant for 57710 where multicast MACs are
  4443. * configured as unicast MACs using the same ramrod.
  4444. */
  4445. bnx2x_handle_mcast_eqe(bp);
  4446. return;
  4447. default:
  4448. BNX2X_ERR("Unsupported classification command: %d\n",
  4449. elem->message.data.eth_event.echo);
  4450. return;
  4451. }
  4452. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4453. if (rc < 0)
  4454. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4455. else if (rc > 0)
  4456. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4457. }
  4458. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4459. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4460. {
  4461. netif_addr_lock_bh(bp->dev);
  4462. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4463. /* Send rx_mode command again if was requested */
  4464. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4465. bnx2x_set_storm_rx_mode(bp);
  4466. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4467. &bp->sp_state))
  4468. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4469. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4470. &bp->sp_state))
  4471. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4472. netif_addr_unlock_bh(bp->dev);
  4473. }
  4474. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4475. union event_ring_elem *elem)
  4476. {
  4477. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4478. DP(BNX2X_MSG_SP,
  4479. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4480. elem->message.data.vif_list_event.func_bit_map);
  4481. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4482. elem->message.data.vif_list_event.func_bit_map);
  4483. } else if (elem->message.data.vif_list_event.echo ==
  4484. VIF_LIST_RULE_SET) {
  4485. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4486. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4487. }
  4488. }
  4489. /* called with rtnl_lock */
  4490. static void bnx2x_after_function_update(struct bnx2x *bp)
  4491. {
  4492. int q, rc;
  4493. struct bnx2x_fastpath *fp;
  4494. struct bnx2x_queue_state_params queue_params = {NULL};
  4495. struct bnx2x_queue_update_params *q_update_params =
  4496. &queue_params.params.update;
  4497. /* Send Q update command with afex vlan removal values for all Qs */
  4498. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4499. /* set silent vlan removal values according to vlan mode */
  4500. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4501. &q_update_params->update_flags);
  4502. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4503. &q_update_params->update_flags);
  4504. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4505. /* in access mode mark mask and value are 0 to strip all vlans */
  4506. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4507. q_update_params->silent_removal_value = 0;
  4508. q_update_params->silent_removal_mask = 0;
  4509. } else {
  4510. q_update_params->silent_removal_value =
  4511. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4512. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4513. }
  4514. for_each_eth_queue(bp, q) {
  4515. /* Set the appropriate Queue object */
  4516. fp = &bp->fp[q];
  4517. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4518. /* send the ramrod */
  4519. rc = bnx2x_queue_state_change(bp, &queue_params);
  4520. if (rc < 0)
  4521. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4522. q);
  4523. }
  4524. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4525. fp = &bp->fp[FCOE_IDX(bp)];
  4526. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4527. /* clear pending completion bit */
  4528. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4529. /* mark latest Q bit */
  4530. smp_mb__before_atomic();
  4531. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4532. smp_mb__after_atomic();
  4533. /* send Q update ramrod for FCoE Q */
  4534. rc = bnx2x_queue_state_change(bp, &queue_params);
  4535. if (rc < 0)
  4536. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4537. q);
  4538. } else {
  4539. /* If no FCoE ring - ACK MCP now */
  4540. bnx2x_link_report(bp);
  4541. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4542. }
  4543. }
  4544. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4545. struct bnx2x *bp, u32 cid)
  4546. {
  4547. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4548. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4549. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4550. else
  4551. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4552. }
  4553. static void bnx2x_eq_int(struct bnx2x *bp)
  4554. {
  4555. u16 hw_cons, sw_cons, sw_prod;
  4556. union event_ring_elem *elem;
  4557. u8 echo;
  4558. u32 cid;
  4559. u8 opcode;
  4560. int rc, spqe_cnt = 0;
  4561. struct bnx2x_queue_sp_obj *q_obj;
  4562. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4563. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4564. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4565. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4566. * when we get the next-page we need to adjust so the loop
  4567. * condition below will be met. The next element is the size of a
  4568. * regular element and hence incrementing by 1
  4569. */
  4570. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4571. hw_cons++;
  4572. /* This function may never run in parallel with itself for a
  4573. * specific bp, thus there is no need in "paired" read memory
  4574. * barrier here.
  4575. */
  4576. sw_cons = bp->eq_cons;
  4577. sw_prod = bp->eq_prod;
  4578. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4579. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4580. for (; sw_cons != hw_cons;
  4581. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4582. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4583. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4584. if (!rc) {
  4585. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4586. rc);
  4587. goto next_spqe;
  4588. }
  4589. /* elem CID originates from FW; actually LE */
  4590. cid = SW_CID((__force __le32)
  4591. elem->message.data.cfc_del_event.cid);
  4592. opcode = elem->message.opcode;
  4593. /* handle eq element */
  4594. switch (opcode) {
  4595. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4596. bnx2x_vf_mbx_schedule(bp,
  4597. &elem->message.data.vf_pf_event);
  4598. continue;
  4599. case EVENT_RING_OPCODE_STAT_QUERY:
  4600. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4601. "got statistics comp event %d\n",
  4602. bp->stats_comp++);
  4603. /* nothing to do with stats comp */
  4604. goto next_spqe;
  4605. case EVENT_RING_OPCODE_CFC_DEL:
  4606. /* handle according to cid range */
  4607. /*
  4608. * we may want to verify here that the bp state is
  4609. * HALTING
  4610. */
  4611. DP(BNX2X_MSG_SP,
  4612. "got delete ramrod for MULTI[%d]\n", cid);
  4613. if (CNIC_LOADED(bp) &&
  4614. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4615. goto next_spqe;
  4616. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4617. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4618. break;
  4619. goto next_spqe;
  4620. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4621. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4622. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4623. if (f_obj->complete_cmd(bp, f_obj,
  4624. BNX2X_F_CMD_TX_STOP))
  4625. break;
  4626. goto next_spqe;
  4627. case EVENT_RING_OPCODE_START_TRAFFIC:
  4628. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4629. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4630. if (f_obj->complete_cmd(bp, f_obj,
  4631. BNX2X_F_CMD_TX_START))
  4632. break;
  4633. goto next_spqe;
  4634. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4635. echo = elem->message.data.function_update_event.echo;
  4636. if (echo == SWITCH_UPDATE) {
  4637. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4638. "got FUNC_SWITCH_UPDATE ramrod\n");
  4639. if (f_obj->complete_cmd(
  4640. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4641. break;
  4642. } else {
  4643. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4644. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4645. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4646. f_obj->complete_cmd(bp, f_obj,
  4647. BNX2X_F_CMD_AFEX_UPDATE);
  4648. /* We will perform the Queues update from
  4649. * sp_rtnl task as all Queue SP operations
  4650. * should run under rtnl_lock.
  4651. */
  4652. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4653. }
  4654. goto next_spqe;
  4655. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4656. f_obj->complete_cmd(bp, f_obj,
  4657. BNX2X_F_CMD_AFEX_VIFLISTS);
  4658. bnx2x_after_afex_vif_lists(bp, elem);
  4659. goto next_spqe;
  4660. case EVENT_RING_OPCODE_FUNCTION_START:
  4661. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4662. "got FUNC_START ramrod\n");
  4663. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4664. break;
  4665. goto next_spqe;
  4666. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4667. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4668. "got FUNC_STOP ramrod\n");
  4669. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4670. break;
  4671. goto next_spqe;
  4672. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4673. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4674. "got set_timesync ramrod completion\n");
  4675. if (f_obj->complete_cmd(bp, f_obj,
  4676. BNX2X_F_CMD_SET_TIMESYNC))
  4677. break;
  4678. goto next_spqe;
  4679. }
  4680. switch (opcode | bp->state) {
  4681. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4682. BNX2X_STATE_OPEN):
  4683. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4684. BNX2X_STATE_OPENING_WAIT4_PORT):
  4685. cid = elem->message.data.eth_event.echo &
  4686. BNX2X_SWCID_MASK;
  4687. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4688. cid);
  4689. rss_raw->clear_pending(rss_raw);
  4690. break;
  4691. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4692. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4693. case (EVENT_RING_OPCODE_SET_MAC |
  4694. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4695. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4696. BNX2X_STATE_OPEN):
  4697. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4698. BNX2X_STATE_DIAG):
  4699. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4700. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4701. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4702. bnx2x_handle_classification_eqe(bp, elem);
  4703. break;
  4704. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4705. BNX2X_STATE_OPEN):
  4706. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4707. BNX2X_STATE_DIAG):
  4708. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4709. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4710. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4711. bnx2x_handle_mcast_eqe(bp);
  4712. break;
  4713. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4714. BNX2X_STATE_OPEN):
  4715. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4716. BNX2X_STATE_DIAG):
  4717. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4718. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4719. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4720. bnx2x_handle_rx_mode_eqe(bp);
  4721. break;
  4722. default:
  4723. /* unknown event log error and continue */
  4724. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4725. elem->message.opcode, bp->state);
  4726. }
  4727. next_spqe:
  4728. spqe_cnt++;
  4729. } /* for */
  4730. smp_mb__before_atomic();
  4731. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4732. bp->eq_cons = sw_cons;
  4733. bp->eq_prod = sw_prod;
  4734. /* Make sure that above mem writes were issued towards the memory */
  4735. smp_wmb();
  4736. /* update producer */
  4737. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4738. }
  4739. static void bnx2x_sp_task(struct work_struct *work)
  4740. {
  4741. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4742. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4743. /* make sure the atomic interrupt_occurred has been written */
  4744. smp_rmb();
  4745. if (atomic_read(&bp->interrupt_occurred)) {
  4746. /* what work needs to be performed? */
  4747. u16 status = bnx2x_update_dsb_idx(bp);
  4748. DP(BNX2X_MSG_SP, "status %x\n", status);
  4749. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4750. atomic_set(&bp->interrupt_occurred, 0);
  4751. /* HW attentions */
  4752. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4753. bnx2x_attn_int(bp);
  4754. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4755. }
  4756. /* SP events: STAT_QUERY and others */
  4757. if (status & BNX2X_DEF_SB_IDX) {
  4758. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4759. if (FCOE_INIT(bp) &&
  4760. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4761. /* Prevent local bottom-halves from running as
  4762. * we are going to change the local NAPI list.
  4763. */
  4764. local_bh_disable();
  4765. napi_schedule(&bnx2x_fcoe(bp, napi));
  4766. local_bh_enable();
  4767. }
  4768. /* Handle EQ completions */
  4769. bnx2x_eq_int(bp);
  4770. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4771. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4772. status &= ~BNX2X_DEF_SB_IDX;
  4773. }
  4774. /* if status is non zero then perhaps something went wrong */
  4775. if (unlikely(status))
  4776. DP(BNX2X_MSG_SP,
  4777. "got an unknown interrupt! (status 0x%x)\n", status);
  4778. /* ack status block only if something was actually handled */
  4779. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4780. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4781. }
  4782. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4783. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4784. &bp->sp_state)) {
  4785. bnx2x_link_report(bp);
  4786. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4787. }
  4788. }
  4789. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4790. {
  4791. struct net_device *dev = dev_instance;
  4792. struct bnx2x *bp = netdev_priv(dev);
  4793. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4794. IGU_INT_DISABLE, 0);
  4795. #ifdef BNX2X_STOP_ON_ERROR
  4796. if (unlikely(bp->panic))
  4797. return IRQ_HANDLED;
  4798. #endif
  4799. if (CNIC_LOADED(bp)) {
  4800. struct cnic_ops *c_ops;
  4801. rcu_read_lock();
  4802. c_ops = rcu_dereference(bp->cnic_ops);
  4803. if (c_ops)
  4804. c_ops->cnic_handler(bp->cnic_data, NULL);
  4805. rcu_read_unlock();
  4806. }
  4807. /* schedule sp task to perform default status block work, ack
  4808. * attentions and enable interrupts.
  4809. */
  4810. bnx2x_schedule_sp_task(bp);
  4811. return IRQ_HANDLED;
  4812. }
  4813. /* end of slow path */
  4814. void bnx2x_drv_pulse(struct bnx2x *bp)
  4815. {
  4816. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4817. bp->fw_drv_pulse_wr_seq);
  4818. }
  4819. static void bnx2x_timer(unsigned long data)
  4820. {
  4821. struct bnx2x *bp = (struct bnx2x *) data;
  4822. if (!netif_running(bp->dev))
  4823. return;
  4824. if (IS_PF(bp) &&
  4825. !BP_NOMCP(bp)) {
  4826. int mb_idx = BP_FW_MB_IDX(bp);
  4827. u16 drv_pulse;
  4828. u16 mcp_pulse;
  4829. ++bp->fw_drv_pulse_wr_seq;
  4830. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4831. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4832. bnx2x_drv_pulse(bp);
  4833. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4834. MCP_PULSE_SEQ_MASK);
  4835. /* The delta between driver pulse and mcp response
  4836. * should not get too big. If the MFW is more than 5 pulses
  4837. * behind, we should worry about it enough to generate an error
  4838. * log.
  4839. */
  4840. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4841. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4842. drv_pulse, mcp_pulse);
  4843. }
  4844. if (bp->state == BNX2X_STATE_OPEN)
  4845. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4846. /* sample pf vf bulletin board for new posts from pf */
  4847. if (IS_VF(bp))
  4848. bnx2x_timer_sriov(bp);
  4849. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4850. }
  4851. /* end of Statistics */
  4852. /* nic init */
  4853. /*
  4854. * nic init service functions
  4855. */
  4856. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4857. {
  4858. u32 i;
  4859. if (!(len%4) && !(addr%4))
  4860. for (i = 0; i < len; i += 4)
  4861. REG_WR(bp, addr + i, fill);
  4862. else
  4863. for (i = 0; i < len; i++)
  4864. REG_WR8(bp, addr + i, fill);
  4865. }
  4866. /* helper: writes FP SP data to FW - data_size in dwords */
  4867. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4868. int fw_sb_id,
  4869. u32 *sb_data_p,
  4870. u32 data_size)
  4871. {
  4872. int index;
  4873. for (index = 0; index < data_size; index++)
  4874. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4875. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4876. sizeof(u32)*index,
  4877. *(sb_data_p + index));
  4878. }
  4879. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4880. {
  4881. u32 *sb_data_p;
  4882. u32 data_size = 0;
  4883. struct hc_status_block_data_e2 sb_data_e2;
  4884. struct hc_status_block_data_e1x sb_data_e1x;
  4885. /* disable the function first */
  4886. if (!CHIP_IS_E1x(bp)) {
  4887. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4888. sb_data_e2.common.state = SB_DISABLED;
  4889. sb_data_e2.common.p_func.vf_valid = false;
  4890. sb_data_p = (u32 *)&sb_data_e2;
  4891. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4892. } else {
  4893. memset(&sb_data_e1x, 0,
  4894. sizeof(struct hc_status_block_data_e1x));
  4895. sb_data_e1x.common.state = SB_DISABLED;
  4896. sb_data_e1x.common.p_func.vf_valid = false;
  4897. sb_data_p = (u32 *)&sb_data_e1x;
  4898. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4899. }
  4900. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4901. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4902. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4903. CSTORM_STATUS_BLOCK_SIZE);
  4904. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4905. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4906. CSTORM_SYNC_BLOCK_SIZE);
  4907. }
  4908. /* helper: writes SP SB data to FW */
  4909. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4910. struct hc_sp_status_block_data *sp_sb_data)
  4911. {
  4912. int func = BP_FUNC(bp);
  4913. int i;
  4914. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4915. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4916. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4917. i*sizeof(u32),
  4918. *((u32 *)sp_sb_data + i));
  4919. }
  4920. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4921. {
  4922. int func = BP_FUNC(bp);
  4923. struct hc_sp_status_block_data sp_sb_data;
  4924. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4925. sp_sb_data.state = SB_DISABLED;
  4926. sp_sb_data.p_func.vf_valid = false;
  4927. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4928. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4929. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4930. CSTORM_SP_STATUS_BLOCK_SIZE);
  4931. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4932. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4933. CSTORM_SP_SYNC_BLOCK_SIZE);
  4934. }
  4935. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4936. int igu_sb_id, int igu_seg_id)
  4937. {
  4938. hc_sm->igu_sb_id = igu_sb_id;
  4939. hc_sm->igu_seg_id = igu_seg_id;
  4940. hc_sm->timer_value = 0xFF;
  4941. hc_sm->time_to_expire = 0xFFFFFFFF;
  4942. }
  4943. /* allocates state machine ids. */
  4944. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4945. {
  4946. /* zero out state machine indices */
  4947. /* rx indices */
  4948. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4949. /* tx indices */
  4950. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4951. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4952. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4953. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4954. /* map indices */
  4955. /* rx indices */
  4956. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4957. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4958. /* tx indices */
  4959. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4960. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4961. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4962. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4963. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4964. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4965. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4966. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4967. }
  4968. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4969. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4970. {
  4971. int igu_seg_id;
  4972. struct hc_status_block_data_e2 sb_data_e2;
  4973. struct hc_status_block_data_e1x sb_data_e1x;
  4974. struct hc_status_block_sm *hc_sm_p;
  4975. int data_size;
  4976. u32 *sb_data_p;
  4977. if (CHIP_INT_MODE_IS_BC(bp))
  4978. igu_seg_id = HC_SEG_ACCESS_NORM;
  4979. else
  4980. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4981. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4982. if (!CHIP_IS_E1x(bp)) {
  4983. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4984. sb_data_e2.common.state = SB_ENABLED;
  4985. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4986. sb_data_e2.common.p_func.vf_id = vfid;
  4987. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4988. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4989. sb_data_e2.common.same_igu_sb_1b = true;
  4990. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4991. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4992. hc_sm_p = sb_data_e2.common.state_machine;
  4993. sb_data_p = (u32 *)&sb_data_e2;
  4994. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4995. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4996. } else {
  4997. memset(&sb_data_e1x, 0,
  4998. sizeof(struct hc_status_block_data_e1x));
  4999. sb_data_e1x.common.state = SB_ENABLED;
  5000. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5001. sb_data_e1x.common.p_func.vf_id = 0xff;
  5002. sb_data_e1x.common.p_func.vf_valid = false;
  5003. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5004. sb_data_e1x.common.same_igu_sb_1b = true;
  5005. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5006. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5007. hc_sm_p = sb_data_e1x.common.state_machine;
  5008. sb_data_p = (u32 *)&sb_data_e1x;
  5009. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5010. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5011. }
  5012. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5013. igu_sb_id, igu_seg_id);
  5014. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5015. igu_sb_id, igu_seg_id);
  5016. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5017. /* write indices to HW - PCI guarantees endianity of regpairs */
  5018. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5019. }
  5020. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5021. u16 tx_usec, u16 rx_usec)
  5022. {
  5023. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5024. false, rx_usec);
  5025. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5026. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5027. tx_usec);
  5028. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5029. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5030. tx_usec);
  5031. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5032. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5033. tx_usec);
  5034. }
  5035. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5036. {
  5037. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5038. dma_addr_t mapping = bp->def_status_blk_mapping;
  5039. int igu_sp_sb_index;
  5040. int igu_seg_id;
  5041. int port = BP_PORT(bp);
  5042. int func = BP_FUNC(bp);
  5043. int reg_offset, reg_offset_en5;
  5044. u64 section;
  5045. int index;
  5046. struct hc_sp_status_block_data sp_sb_data;
  5047. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5048. if (CHIP_INT_MODE_IS_BC(bp)) {
  5049. igu_sp_sb_index = DEF_SB_IGU_ID;
  5050. igu_seg_id = HC_SEG_ACCESS_DEF;
  5051. } else {
  5052. igu_sp_sb_index = bp->igu_dsb_id;
  5053. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5054. }
  5055. /* ATTN */
  5056. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5057. atten_status_block);
  5058. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5059. bp->attn_state = 0;
  5060. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5061. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5062. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5063. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5064. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5065. int sindex;
  5066. /* take care of sig[0]..sig[4] */
  5067. for (sindex = 0; sindex < 4; sindex++)
  5068. bp->attn_group[index].sig[sindex] =
  5069. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5070. if (!CHIP_IS_E1x(bp))
  5071. /*
  5072. * enable5 is separate from the rest of the registers,
  5073. * and therefore the address skip is 4
  5074. * and not 16 between the different groups
  5075. */
  5076. bp->attn_group[index].sig[4] = REG_RD(bp,
  5077. reg_offset_en5 + 0x4*index);
  5078. else
  5079. bp->attn_group[index].sig[4] = 0;
  5080. }
  5081. if (bp->common.int_block == INT_BLOCK_HC) {
  5082. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5083. HC_REG_ATTN_MSG0_ADDR_L);
  5084. REG_WR(bp, reg_offset, U64_LO(section));
  5085. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5086. } else if (!CHIP_IS_E1x(bp)) {
  5087. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5088. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5089. }
  5090. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5091. sp_sb);
  5092. bnx2x_zero_sp_sb(bp);
  5093. /* PCI guarantees endianity of regpairs */
  5094. sp_sb_data.state = SB_ENABLED;
  5095. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5096. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5097. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5098. sp_sb_data.igu_seg_id = igu_seg_id;
  5099. sp_sb_data.p_func.pf_id = func;
  5100. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5101. sp_sb_data.p_func.vf_id = 0xff;
  5102. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5103. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5104. }
  5105. void bnx2x_update_coalesce(struct bnx2x *bp)
  5106. {
  5107. int i;
  5108. for_each_eth_queue(bp, i)
  5109. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5110. bp->tx_ticks, bp->rx_ticks);
  5111. }
  5112. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5113. {
  5114. spin_lock_init(&bp->spq_lock);
  5115. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5116. bp->spq_prod_idx = 0;
  5117. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5118. bp->spq_prod_bd = bp->spq;
  5119. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5120. }
  5121. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5122. {
  5123. int i;
  5124. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5125. union event_ring_elem *elem =
  5126. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5127. elem->next_page.addr.hi =
  5128. cpu_to_le32(U64_HI(bp->eq_mapping +
  5129. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5130. elem->next_page.addr.lo =
  5131. cpu_to_le32(U64_LO(bp->eq_mapping +
  5132. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5133. }
  5134. bp->eq_cons = 0;
  5135. bp->eq_prod = NUM_EQ_DESC;
  5136. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5137. /* we want a warning message before it gets wrought... */
  5138. atomic_set(&bp->eq_spq_left,
  5139. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5140. }
  5141. /* called with netif_addr_lock_bh() */
  5142. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5143. unsigned long rx_mode_flags,
  5144. unsigned long rx_accept_flags,
  5145. unsigned long tx_accept_flags,
  5146. unsigned long ramrod_flags)
  5147. {
  5148. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5149. int rc;
  5150. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5151. /* Prepare ramrod parameters */
  5152. ramrod_param.cid = 0;
  5153. ramrod_param.cl_id = cl_id;
  5154. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5155. ramrod_param.func_id = BP_FUNC(bp);
  5156. ramrod_param.pstate = &bp->sp_state;
  5157. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5158. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5159. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5160. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5161. ramrod_param.ramrod_flags = ramrod_flags;
  5162. ramrod_param.rx_mode_flags = rx_mode_flags;
  5163. ramrod_param.rx_accept_flags = rx_accept_flags;
  5164. ramrod_param.tx_accept_flags = tx_accept_flags;
  5165. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5166. if (rc < 0) {
  5167. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5168. return rc;
  5169. }
  5170. return 0;
  5171. }
  5172. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5173. unsigned long *rx_accept_flags,
  5174. unsigned long *tx_accept_flags)
  5175. {
  5176. /* Clear the flags first */
  5177. *rx_accept_flags = 0;
  5178. *tx_accept_flags = 0;
  5179. switch (rx_mode) {
  5180. case BNX2X_RX_MODE_NONE:
  5181. /*
  5182. * 'drop all' supersedes any accept flags that may have been
  5183. * passed to the function.
  5184. */
  5185. break;
  5186. case BNX2X_RX_MODE_NORMAL:
  5187. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5188. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5189. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5190. /* internal switching mode */
  5191. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5192. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5193. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5194. break;
  5195. case BNX2X_RX_MODE_ALLMULTI:
  5196. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5197. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5198. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5199. /* internal switching mode */
  5200. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5201. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5202. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5203. break;
  5204. case BNX2X_RX_MODE_PROMISC:
  5205. /* According to definition of SI mode, iface in promisc mode
  5206. * should receive matched and unmatched (in resolution of port)
  5207. * unicast packets.
  5208. */
  5209. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5210. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5211. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5212. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5213. /* internal switching mode */
  5214. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5215. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5216. if (IS_MF_SI(bp))
  5217. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5218. else
  5219. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5220. break;
  5221. default:
  5222. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5223. return -EINVAL;
  5224. }
  5225. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5226. if (rx_mode != BNX2X_RX_MODE_NONE) {
  5227. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5228. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5229. }
  5230. return 0;
  5231. }
  5232. /* called with netif_addr_lock_bh() */
  5233. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5234. {
  5235. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5236. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5237. int rc;
  5238. if (!NO_FCOE(bp))
  5239. /* Configure rx_mode of FCoE Queue */
  5240. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5241. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5242. &tx_accept_flags);
  5243. if (rc)
  5244. return rc;
  5245. __set_bit(RAMROD_RX, &ramrod_flags);
  5246. __set_bit(RAMROD_TX, &ramrod_flags);
  5247. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5248. rx_accept_flags, tx_accept_flags,
  5249. ramrod_flags);
  5250. }
  5251. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5252. {
  5253. int i;
  5254. /* Zero this manually as its initialization is
  5255. currently missing in the initTool */
  5256. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5257. REG_WR(bp, BAR_USTRORM_INTMEM +
  5258. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5259. if (!CHIP_IS_E1x(bp)) {
  5260. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5261. CHIP_INT_MODE_IS_BC(bp) ?
  5262. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5263. }
  5264. }
  5265. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5266. {
  5267. switch (load_code) {
  5268. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5269. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5270. bnx2x_init_internal_common(bp);
  5271. /* no break */
  5272. case FW_MSG_CODE_DRV_LOAD_PORT:
  5273. /* nothing to do */
  5274. /* no break */
  5275. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5276. /* internal memory per function is
  5277. initialized inside bnx2x_pf_init */
  5278. break;
  5279. default:
  5280. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5281. break;
  5282. }
  5283. }
  5284. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5285. {
  5286. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5287. }
  5288. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5289. {
  5290. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5291. }
  5292. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5293. {
  5294. if (CHIP_IS_E1x(fp->bp))
  5295. return BP_L_ID(fp->bp) + fp->index;
  5296. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5297. return bnx2x_fp_igu_sb_id(fp);
  5298. }
  5299. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5300. {
  5301. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5302. u8 cos;
  5303. unsigned long q_type = 0;
  5304. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5305. fp->rx_queue = fp_idx;
  5306. fp->cid = fp_idx;
  5307. fp->cl_id = bnx2x_fp_cl_id(fp);
  5308. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5309. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5310. /* qZone id equals to FW (per path) client id */
  5311. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5312. /* init shortcut */
  5313. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5314. /* Setup SB indices */
  5315. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5316. /* Configure Queue State object */
  5317. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5318. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5319. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5320. /* init tx data */
  5321. for_each_cos_in_tx_queue(fp, cos) {
  5322. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5323. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5324. FP_COS_TO_TXQ(fp, cos, bp),
  5325. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5326. cids[cos] = fp->txdata_ptr[cos]->cid;
  5327. }
  5328. /* nothing more for vf to do here */
  5329. if (IS_VF(bp))
  5330. return;
  5331. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5332. fp->fw_sb_id, fp->igu_sb_id);
  5333. bnx2x_update_fpsb_idx(fp);
  5334. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5335. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5336. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5337. /**
  5338. * Configure classification DBs: Always enable Tx switching
  5339. */
  5340. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5341. DP(NETIF_MSG_IFUP,
  5342. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5343. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5344. fp->igu_sb_id);
  5345. }
  5346. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5347. {
  5348. int i;
  5349. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5350. struct eth_tx_next_bd *tx_next_bd =
  5351. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5352. tx_next_bd->addr_hi =
  5353. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5354. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5355. tx_next_bd->addr_lo =
  5356. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5357. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5358. }
  5359. *txdata->tx_cons_sb = cpu_to_le16(0);
  5360. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5361. txdata->tx_db.data.zero_fill1 = 0;
  5362. txdata->tx_db.data.prod = 0;
  5363. txdata->tx_pkt_prod = 0;
  5364. txdata->tx_pkt_cons = 0;
  5365. txdata->tx_bd_prod = 0;
  5366. txdata->tx_bd_cons = 0;
  5367. txdata->tx_pkt = 0;
  5368. }
  5369. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5370. {
  5371. int i;
  5372. for_each_tx_queue_cnic(bp, i)
  5373. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5374. }
  5375. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5376. {
  5377. int i;
  5378. u8 cos;
  5379. for_each_eth_queue(bp, i)
  5380. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5381. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5382. }
  5383. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5384. {
  5385. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5386. unsigned long q_type = 0;
  5387. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5388. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5389. BNX2X_FCOE_ETH_CL_ID_IDX);
  5390. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5391. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5392. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5393. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5394. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5395. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5396. fp);
  5397. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5398. /* qZone id equals to FW (per path) client id */
  5399. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5400. /* init shortcut */
  5401. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5402. bnx2x_rx_ustorm_prods_offset(fp);
  5403. /* Configure Queue State object */
  5404. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5405. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5406. /* No multi-CoS for FCoE L2 client */
  5407. BUG_ON(fp->max_cos != 1);
  5408. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5409. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5410. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5411. DP(NETIF_MSG_IFUP,
  5412. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5413. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5414. fp->igu_sb_id);
  5415. }
  5416. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5417. {
  5418. if (!NO_FCOE(bp))
  5419. bnx2x_init_fcoe_fp(bp);
  5420. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5421. BNX2X_VF_ID_INVALID, false,
  5422. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5423. /* ensure status block indices were read */
  5424. rmb();
  5425. bnx2x_init_rx_rings_cnic(bp);
  5426. bnx2x_init_tx_rings_cnic(bp);
  5427. /* flush all */
  5428. mb();
  5429. mmiowb();
  5430. }
  5431. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5432. {
  5433. int i;
  5434. /* Setup NIC internals and enable interrupts */
  5435. for_each_eth_queue(bp, i)
  5436. bnx2x_init_eth_fp(bp, i);
  5437. /* ensure status block indices were read */
  5438. rmb();
  5439. bnx2x_init_rx_rings(bp);
  5440. bnx2x_init_tx_rings(bp);
  5441. if (IS_PF(bp)) {
  5442. /* Initialize MOD_ABS interrupts */
  5443. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5444. bp->common.shmem_base,
  5445. bp->common.shmem2_base, BP_PORT(bp));
  5446. /* initialize the default status block and sp ring */
  5447. bnx2x_init_def_sb(bp);
  5448. bnx2x_update_dsb_idx(bp);
  5449. bnx2x_init_sp_ring(bp);
  5450. } else {
  5451. bnx2x_memset_stats(bp);
  5452. }
  5453. }
  5454. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5455. {
  5456. bnx2x_init_eq_ring(bp);
  5457. bnx2x_init_internal(bp, load_code);
  5458. bnx2x_pf_init(bp);
  5459. bnx2x_stats_init(bp);
  5460. /* flush all before enabling interrupts */
  5461. mb();
  5462. mmiowb();
  5463. bnx2x_int_enable(bp);
  5464. /* Check for SPIO5 */
  5465. bnx2x_attn_int_deasserted0(bp,
  5466. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5467. AEU_INPUTS_ATTN_BITS_SPIO5);
  5468. }
  5469. /* gzip service functions */
  5470. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5471. {
  5472. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5473. &bp->gunzip_mapping, GFP_KERNEL);
  5474. if (bp->gunzip_buf == NULL)
  5475. goto gunzip_nomem1;
  5476. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5477. if (bp->strm == NULL)
  5478. goto gunzip_nomem2;
  5479. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5480. if (bp->strm->workspace == NULL)
  5481. goto gunzip_nomem3;
  5482. return 0;
  5483. gunzip_nomem3:
  5484. kfree(bp->strm);
  5485. bp->strm = NULL;
  5486. gunzip_nomem2:
  5487. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5488. bp->gunzip_mapping);
  5489. bp->gunzip_buf = NULL;
  5490. gunzip_nomem1:
  5491. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5492. return -ENOMEM;
  5493. }
  5494. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5495. {
  5496. if (bp->strm) {
  5497. vfree(bp->strm->workspace);
  5498. kfree(bp->strm);
  5499. bp->strm = NULL;
  5500. }
  5501. if (bp->gunzip_buf) {
  5502. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5503. bp->gunzip_mapping);
  5504. bp->gunzip_buf = NULL;
  5505. }
  5506. }
  5507. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5508. {
  5509. int n, rc;
  5510. /* check gzip header */
  5511. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5512. BNX2X_ERR("Bad gzip header\n");
  5513. return -EINVAL;
  5514. }
  5515. n = 10;
  5516. #define FNAME 0x8
  5517. if (zbuf[3] & FNAME)
  5518. while ((zbuf[n++] != 0) && (n < len));
  5519. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5520. bp->strm->avail_in = len - n;
  5521. bp->strm->next_out = bp->gunzip_buf;
  5522. bp->strm->avail_out = FW_BUF_SIZE;
  5523. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5524. if (rc != Z_OK)
  5525. return rc;
  5526. rc = zlib_inflate(bp->strm, Z_FINISH);
  5527. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5528. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5529. bp->strm->msg);
  5530. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5531. if (bp->gunzip_outlen & 0x3)
  5532. netdev_err(bp->dev,
  5533. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5534. bp->gunzip_outlen);
  5535. bp->gunzip_outlen >>= 2;
  5536. zlib_inflateEnd(bp->strm);
  5537. if (rc == Z_STREAM_END)
  5538. return 0;
  5539. return rc;
  5540. }
  5541. /* nic load/unload */
  5542. /*
  5543. * General service functions
  5544. */
  5545. /* send a NIG loopback debug packet */
  5546. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5547. {
  5548. u32 wb_write[3];
  5549. /* Ethernet source and destination addresses */
  5550. wb_write[0] = 0x55555555;
  5551. wb_write[1] = 0x55555555;
  5552. wb_write[2] = 0x20; /* SOP */
  5553. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5554. /* NON-IP protocol */
  5555. wb_write[0] = 0x09000000;
  5556. wb_write[1] = 0x55555555;
  5557. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5558. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5559. }
  5560. /* some of the internal memories
  5561. * are not directly readable from the driver
  5562. * to test them we send debug packets
  5563. */
  5564. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5565. {
  5566. int factor;
  5567. int count, i;
  5568. u32 val = 0;
  5569. if (CHIP_REV_IS_FPGA(bp))
  5570. factor = 120;
  5571. else if (CHIP_REV_IS_EMUL(bp))
  5572. factor = 200;
  5573. else
  5574. factor = 1;
  5575. /* Disable inputs of parser neighbor blocks */
  5576. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5577. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5578. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5579. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5580. /* Write 0 to parser credits for CFC search request */
  5581. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5582. /* send Ethernet packet */
  5583. bnx2x_lb_pckt(bp);
  5584. /* TODO do i reset NIG statistic? */
  5585. /* Wait until NIG register shows 1 packet of size 0x10 */
  5586. count = 1000 * factor;
  5587. while (count) {
  5588. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5589. val = *bnx2x_sp(bp, wb_data[0]);
  5590. if (val == 0x10)
  5591. break;
  5592. usleep_range(10000, 20000);
  5593. count--;
  5594. }
  5595. if (val != 0x10) {
  5596. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5597. return -1;
  5598. }
  5599. /* Wait until PRS register shows 1 packet */
  5600. count = 1000 * factor;
  5601. while (count) {
  5602. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5603. if (val == 1)
  5604. break;
  5605. usleep_range(10000, 20000);
  5606. count--;
  5607. }
  5608. if (val != 0x1) {
  5609. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5610. return -2;
  5611. }
  5612. /* Reset and init BRB, PRS */
  5613. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5614. msleep(50);
  5615. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5616. msleep(50);
  5617. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5618. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5619. DP(NETIF_MSG_HW, "part2\n");
  5620. /* Disable inputs of parser neighbor blocks */
  5621. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5622. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5623. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5624. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5625. /* Write 0 to parser credits for CFC search request */
  5626. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5627. /* send 10 Ethernet packets */
  5628. for (i = 0; i < 10; i++)
  5629. bnx2x_lb_pckt(bp);
  5630. /* Wait until NIG register shows 10 + 1
  5631. packets of size 11*0x10 = 0xb0 */
  5632. count = 1000 * factor;
  5633. while (count) {
  5634. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5635. val = *bnx2x_sp(bp, wb_data[0]);
  5636. if (val == 0xb0)
  5637. break;
  5638. usleep_range(10000, 20000);
  5639. count--;
  5640. }
  5641. if (val != 0xb0) {
  5642. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5643. return -3;
  5644. }
  5645. /* Wait until PRS register shows 2 packets */
  5646. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5647. if (val != 2)
  5648. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5649. /* Write 1 to parser credits for CFC search request */
  5650. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5651. /* Wait until PRS register shows 3 packets */
  5652. msleep(10 * factor);
  5653. /* Wait until NIG register shows 1 packet of size 0x10 */
  5654. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5655. if (val != 3)
  5656. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5657. /* clear NIG EOP FIFO */
  5658. for (i = 0; i < 11; i++)
  5659. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5660. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5661. if (val != 1) {
  5662. BNX2X_ERR("clear of NIG failed\n");
  5663. return -4;
  5664. }
  5665. /* Reset and init BRB, PRS, NIG */
  5666. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5667. msleep(50);
  5668. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5669. msleep(50);
  5670. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5671. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5672. if (!CNIC_SUPPORT(bp))
  5673. /* set NIC mode */
  5674. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5675. /* Enable inputs of parser neighbor blocks */
  5676. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5677. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5678. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5679. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5680. DP(NETIF_MSG_HW, "done\n");
  5681. return 0; /* OK */
  5682. }
  5683. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5684. {
  5685. u32 val;
  5686. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5687. if (!CHIP_IS_E1x(bp))
  5688. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5689. else
  5690. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5691. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5692. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5693. /*
  5694. * mask read length error interrupts in brb for parser
  5695. * (parsing unit and 'checksum and crc' unit)
  5696. * these errors are legal (PU reads fixed length and CAC can cause
  5697. * read length error on truncated packets)
  5698. */
  5699. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5700. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5701. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5702. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5703. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5704. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5705. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5706. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5707. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5708. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5709. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5710. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5711. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5712. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5713. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5714. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5715. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5716. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5717. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5718. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5719. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5720. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5721. if (!CHIP_IS_E1x(bp))
  5722. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5723. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5724. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5725. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5726. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5727. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5728. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5729. if (!CHIP_IS_E1x(bp))
  5730. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5731. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5732. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5733. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5734. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5735. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5736. }
  5737. static void bnx2x_reset_common(struct bnx2x *bp)
  5738. {
  5739. u32 val = 0x1400;
  5740. /* reset_common */
  5741. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5742. 0xd3ffff7f);
  5743. if (CHIP_IS_E3(bp)) {
  5744. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5745. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5746. }
  5747. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5748. }
  5749. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5750. {
  5751. bp->dmae_ready = 0;
  5752. spin_lock_init(&bp->dmae_lock);
  5753. }
  5754. static void bnx2x_init_pxp(struct bnx2x *bp)
  5755. {
  5756. u16 devctl;
  5757. int r_order, w_order;
  5758. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5759. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5760. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5761. if (bp->mrrs == -1)
  5762. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5763. else {
  5764. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5765. r_order = bp->mrrs;
  5766. }
  5767. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5768. }
  5769. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5770. {
  5771. int is_required;
  5772. u32 val;
  5773. int port;
  5774. if (BP_NOMCP(bp))
  5775. return;
  5776. is_required = 0;
  5777. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5778. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5779. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5780. is_required = 1;
  5781. /*
  5782. * The fan failure mechanism is usually related to the PHY type since
  5783. * the power consumption of the board is affected by the PHY. Currently,
  5784. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5785. */
  5786. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5787. for (port = PORT_0; port < PORT_MAX; port++) {
  5788. is_required |=
  5789. bnx2x_fan_failure_det_req(
  5790. bp,
  5791. bp->common.shmem_base,
  5792. bp->common.shmem2_base,
  5793. port);
  5794. }
  5795. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5796. if (is_required == 0)
  5797. return;
  5798. /* Fan failure is indicated by SPIO 5 */
  5799. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5800. /* set to active low mode */
  5801. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5802. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5803. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5804. /* enable interrupt to signal the IGU */
  5805. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5806. val |= MISC_SPIO_SPIO5;
  5807. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5808. }
  5809. void bnx2x_pf_disable(struct bnx2x *bp)
  5810. {
  5811. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5812. val &= ~IGU_PF_CONF_FUNC_EN;
  5813. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5814. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5815. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5816. }
  5817. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5818. {
  5819. u32 shmem_base[2], shmem2_base[2];
  5820. /* Avoid common init in case MFW supports LFA */
  5821. if (SHMEM2_RD(bp, size) >
  5822. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5823. return;
  5824. shmem_base[0] = bp->common.shmem_base;
  5825. shmem2_base[0] = bp->common.shmem2_base;
  5826. if (!CHIP_IS_E1x(bp)) {
  5827. shmem_base[1] =
  5828. SHMEM2_RD(bp, other_shmem_base_addr);
  5829. shmem2_base[1] =
  5830. SHMEM2_RD(bp, other_shmem2_base_addr);
  5831. }
  5832. bnx2x_acquire_phy_lock(bp);
  5833. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5834. bp->common.chip_id);
  5835. bnx2x_release_phy_lock(bp);
  5836. }
  5837. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5838. {
  5839. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5840. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5841. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5842. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5843. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5844. /* make sure this value is 0 */
  5845. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5846. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5847. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5848. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5849. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5850. }
  5851. static void bnx2x_set_endianity(struct bnx2x *bp)
  5852. {
  5853. #ifdef __BIG_ENDIAN
  5854. bnx2x_config_endianity(bp, 1);
  5855. #else
  5856. bnx2x_config_endianity(bp, 0);
  5857. #endif
  5858. }
  5859. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5860. {
  5861. bnx2x_config_endianity(bp, 0);
  5862. }
  5863. /**
  5864. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5865. *
  5866. * @bp: driver handle
  5867. */
  5868. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5869. {
  5870. u32 val;
  5871. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5872. /*
  5873. * take the RESET lock to protect undi_unload flow from accessing
  5874. * registers while we're resetting the chip
  5875. */
  5876. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5877. bnx2x_reset_common(bp);
  5878. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5879. val = 0xfffc;
  5880. if (CHIP_IS_E3(bp)) {
  5881. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5882. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5883. }
  5884. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5885. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5886. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5887. if (!CHIP_IS_E1x(bp)) {
  5888. u8 abs_func_id;
  5889. /**
  5890. * 4-port mode or 2-port mode we need to turn of master-enable
  5891. * for everyone, after that, turn it back on for self.
  5892. * so, we disregard multi-function or not, and always disable
  5893. * for all functions on the given path, this means 0,2,4,6 for
  5894. * path 0 and 1,3,5,7 for path 1
  5895. */
  5896. for (abs_func_id = BP_PATH(bp);
  5897. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5898. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5899. REG_WR(bp,
  5900. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5901. 1);
  5902. continue;
  5903. }
  5904. bnx2x_pretend_func(bp, abs_func_id);
  5905. /* clear pf enable */
  5906. bnx2x_pf_disable(bp);
  5907. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5908. }
  5909. }
  5910. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5911. if (CHIP_IS_E1(bp)) {
  5912. /* enable HW interrupt from PXP on USDM overflow
  5913. bit 16 on INT_MASK_0 */
  5914. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5915. }
  5916. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5917. bnx2x_init_pxp(bp);
  5918. bnx2x_set_endianity(bp);
  5919. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5920. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5921. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5922. /* let the HW do it's magic ... */
  5923. msleep(100);
  5924. /* finish PXP init */
  5925. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5926. if (val != 1) {
  5927. BNX2X_ERR("PXP2 CFG failed\n");
  5928. return -EBUSY;
  5929. }
  5930. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5931. if (val != 1) {
  5932. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5933. return -EBUSY;
  5934. }
  5935. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5936. * have entries with value "0" and valid bit on.
  5937. * This needs to be done by the first PF that is loaded in a path
  5938. * (i.e. common phase)
  5939. */
  5940. if (!CHIP_IS_E1x(bp)) {
  5941. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5942. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5943. * This occurs when a different function (func2,3) is being marked
  5944. * as "scan-off". Real-life scenario for example: if a driver is being
  5945. * load-unloaded while func6,7 are down. This will cause the timer to access
  5946. * the ilt, translate to a logical address and send a request to read/write.
  5947. * Since the ilt for the function that is down is not valid, this will cause
  5948. * a translation error which is unrecoverable.
  5949. * The Workaround is intended to make sure that when this happens nothing fatal
  5950. * will occur. The workaround:
  5951. * 1. First PF driver which loads on a path will:
  5952. * a. After taking the chip out of reset, by using pretend,
  5953. * it will write "0" to the following registers of
  5954. * the other vnics.
  5955. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5956. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5957. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5958. * And for itself it will write '1' to
  5959. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5960. * dmae-operations (writing to pram for example.)
  5961. * note: can be done for only function 6,7 but cleaner this
  5962. * way.
  5963. * b. Write zero+valid to the entire ILT.
  5964. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5965. * VNIC3 (of that port). The range allocated will be the
  5966. * entire ILT. This is needed to prevent ILT range error.
  5967. * 2. Any PF driver load flow:
  5968. * a. ILT update with the physical addresses of the allocated
  5969. * logical pages.
  5970. * b. Wait 20msec. - note that this timeout is needed to make
  5971. * sure there are no requests in one of the PXP internal
  5972. * queues with "old" ILT addresses.
  5973. * c. PF enable in the PGLC.
  5974. * d. Clear the was_error of the PF in the PGLC. (could have
  5975. * occurred while driver was down)
  5976. * e. PF enable in the CFC (WEAK + STRONG)
  5977. * f. Timers scan enable
  5978. * 3. PF driver unload flow:
  5979. * a. Clear the Timers scan_en.
  5980. * b. Polling for scan_on=0 for that PF.
  5981. * c. Clear the PF enable bit in the PXP.
  5982. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5983. * e. Write zero+valid to all ILT entries (The valid bit must
  5984. * stay set)
  5985. * f. If this is VNIC 3 of a port then also init
  5986. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5987. * to the last entry in the ILT.
  5988. *
  5989. * Notes:
  5990. * Currently the PF error in the PGLC is non recoverable.
  5991. * In the future the there will be a recovery routine for this error.
  5992. * Currently attention is masked.
  5993. * Having an MCP lock on the load/unload process does not guarantee that
  5994. * there is no Timer disable during Func6/7 enable. This is because the
  5995. * Timers scan is currently being cleared by the MCP on FLR.
  5996. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5997. * there is error before clearing it. But the flow above is simpler and
  5998. * more general.
  5999. * All ILT entries are written by zero+valid and not just PF6/7
  6000. * ILT entries since in the future the ILT entries allocation for
  6001. * PF-s might be dynamic.
  6002. */
  6003. struct ilt_client_info ilt_cli;
  6004. struct bnx2x_ilt ilt;
  6005. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6006. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6007. /* initialize dummy TM client */
  6008. ilt_cli.start = 0;
  6009. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6010. ilt_cli.client_num = ILT_CLIENT_TM;
  6011. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6012. * Step 2: set the timers first/last ilt entry to point
  6013. * to the entire range to prevent ILT range error for 3rd/4th
  6014. * vnic (this code assumes existence of the vnic)
  6015. *
  6016. * both steps performed by call to bnx2x_ilt_client_init_op()
  6017. * with dummy TM client
  6018. *
  6019. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6020. * and his brother are split registers
  6021. */
  6022. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6023. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6024. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6025. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6026. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6027. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6028. }
  6029. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6030. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6031. if (!CHIP_IS_E1x(bp)) {
  6032. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6033. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6034. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6035. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6036. /* let the HW do it's magic ... */
  6037. do {
  6038. msleep(200);
  6039. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6040. } while (factor-- && (val != 1));
  6041. if (val != 1) {
  6042. BNX2X_ERR("ATC_INIT failed\n");
  6043. return -EBUSY;
  6044. }
  6045. }
  6046. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6047. bnx2x_iov_init_dmae(bp);
  6048. /* clean the DMAE memory */
  6049. bp->dmae_ready = 1;
  6050. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6051. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6052. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6053. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6054. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6055. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6056. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6057. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6058. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6059. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6060. /* QM queues pointers table */
  6061. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6062. /* soft reset pulse */
  6063. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6064. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6065. if (CNIC_SUPPORT(bp))
  6066. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6067. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6068. if (!CHIP_REV_IS_SLOW(bp))
  6069. /* enable hw interrupt from doorbell Q */
  6070. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6071. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6072. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6073. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6074. if (!CHIP_IS_E1(bp))
  6075. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6076. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6077. if (IS_MF_AFEX(bp)) {
  6078. /* configure that VNTag and VLAN headers must be
  6079. * received in afex mode
  6080. */
  6081. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6082. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6083. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6084. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6085. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6086. } else {
  6087. /* Bit-map indicating which L2 hdrs may appear
  6088. * after the basic Ethernet header
  6089. */
  6090. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6091. bp->path_has_ovlan ? 7 : 6);
  6092. }
  6093. }
  6094. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6095. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6096. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6097. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6098. if (!CHIP_IS_E1x(bp)) {
  6099. /* reset VFC memories */
  6100. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6101. VFC_MEMORIES_RST_REG_CAM_RST |
  6102. VFC_MEMORIES_RST_REG_RAM_RST);
  6103. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6104. VFC_MEMORIES_RST_REG_CAM_RST |
  6105. VFC_MEMORIES_RST_REG_RAM_RST);
  6106. msleep(20);
  6107. }
  6108. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6109. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6110. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6111. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6112. /* sync semi rtc */
  6113. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6114. 0x80000000);
  6115. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6116. 0x80000000);
  6117. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6118. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6119. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6120. if (!CHIP_IS_E1x(bp)) {
  6121. if (IS_MF_AFEX(bp)) {
  6122. /* configure that VNTag and VLAN headers must be
  6123. * sent in afex mode
  6124. */
  6125. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6126. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6127. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6128. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6129. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6130. } else {
  6131. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6132. bp->path_has_ovlan ? 7 : 6);
  6133. }
  6134. }
  6135. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6136. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6137. if (CNIC_SUPPORT(bp)) {
  6138. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6139. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6140. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6141. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6142. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6143. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6144. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6145. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6146. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6147. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6148. }
  6149. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6150. if (sizeof(union cdu_context) != 1024)
  6151. /* we currently assume that a context is 1024 bytes */
  6152. dev_alert(&bp->pdev->dev,
  6153. "please adjust the size of cdu_context(%ld)\n",
  6154. (long)sizeof(union cdu_context));
  6155. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6156. val = (4 << 24) + (0 << 12) + 1024;
  6157. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6158. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6159. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6160. /* enable context validation interrupt from CFC */
  6161. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6162. /* set the thresholds to prevent CFC/CDU race */
  6163. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6164. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6165. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6166. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6167. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6168. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6169. /* Reset PCIE errors for debug */
  6170. REG_WR(bp, 0x2814, 0xffffffff);
  6171. REG_WR(bp, 0x3820, 0xffffffff);
  6172. if (!CHIP_IS_E1x(bp)) {
  6173. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6174. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6175. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6176. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6177. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6178. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6179. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6180. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6181. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6182. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6183. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6184. }
  6185. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6186. if (!CHIP_IS_E1(bp)) {
  6187. /* in E3 this done in per-port section */
  6188. if (!CHIP_IS_E3(bp))
  6189. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6190. }
  6191. if (CHIP_IS_E1H(bp))
  6192. /* not applicable for E2 (and above ...) */
  6193. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6194. if (CHIP_REV_IS_SLOW(bp))
  6195. msleep(200);
  6196. /* finish CFC init */
  6197. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6198. if (val != 1) {
  6199. BNX2X_ERR("CFC LL_INIT failed\n");
  6200. return -EBUSY;
  6201. }
  6202. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6203. if (val != 1) {
  6204. BNX2X_ERR("CFC AC_INIT failed\n");
  6205. return -EBUSY;
  6206. }
  6207. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6208. if (val != 1) {
  6209. BNX2X_ERR("CFC CAM_INIT failed\n");
  6210. return -EBUSY;
  6211. }
  6212. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6213. if (CHIP_IS_E1(bp)) {
  6214. /* read NIG statistic
  6215. to see if this is our first up since powerup */
  6216. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6217. val = *bnx2x_sp(bp, wb_data[0]);
  6218. /* do internal memory self test */
  6219. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6220. BNX2X_ERR("internal mem self test failed\n");
  6221. return -EBUSY;
  6222. }
  6223. }
  6224. bnx2x_setup_fan_failure_detection(bp);
  6225. /* clear PXP2 attentions */
  6226. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6227. bnx2x_enable_blocks_attention(bp);
  6228. bnx2x_enable_blocks_parity(bp);
  6229. if (!BP_NOMCP(bp)) {
  6230. if (CHIP_IS_E1x(bp))
  6231. bnx2x__common_init_phy(bp);
  6232. } else
  6233. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6234. return 0;
  6235. }
  6236. /**
  6237. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6238. *
  6239. * @bp: driver handle
  6240. */
  6241. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6242. {
  6243. int rc = bnx2x_init_hw_common(bp);
  6244. if (rc)
  6245. return rc;
  6246. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6247. if (!BP_NOMCP(bp))
  6248. bnx2x__common_init_phy(bp);
  6249. return 0;
  6250. }
  6251. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6252. {
  6253. int port = BP_PORT(bp);
  6254. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6255. u32 low, high;
  6256. u32 val, reg;
  6257. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6258. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6259. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6260. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6261. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6262. /* Timers bug workaround: disables the pf_master bit in pglue at
  6263. * common phase, we need to enable it here before any dmae access are
  6264. * attempted. Therefore we manually added the enable-master to the
  6265. * port phase (it also happens in the function phase)
  6266. */
  6267. if (!CHIP_IS_E1x(bp))
  6268. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6269. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6270. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6271. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6272. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6273. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6274. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6275. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6276. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6277. /* QM cid (connection) count */
  6278. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6279. if (CNIC_SUPPORT(bp)) {
  6280. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6281. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6282. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6283. }
  6284. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6285. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6286. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6287. if (IS_MF(bp))
  6288. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6289. else if (bp->dev->mtu > 4096) {
  6290. if (bp->flags & ONE_PORT_FLAG)
  6291. low = 160;
  6292. else {
  6293. val = bp->dev->mtu;
  6294. /* (24*1024 + val*4)/256 */
  6295. low = 96 + (val/64) +
  6296. ((val % 64) ? 1 : 0);
  6297. }
  6298. } else
  6299. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6300. high = low + 56; /* 14*1024/256 */
  6301. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6302. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6303. }
  6304. if (CHIP_MODE_IS_4_PORT(bp))
  6305. REG_WR(bp, (BP_PORT(bp) ?
  6306. BRB1_REG_MAC_GUARANTIED_1 :
  6307. BRB1_REG_MAC_GUARANTIED_0), 40);
  6308. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6309. if (CHIP_IS_E3B0(bp)) {
  6310. if (IS_MF_AFEX(bp)) {
  6311. /* configure headers for AFEX mode */
  6312. REG_WR(bp, BP_PORT(bp) ?
  6313. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6314. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6315. REG_WR(bp, BP_PORT(bp) ?
  6316. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6317. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6318. REG_WR(bp, BP_PORT(bp) ?
  6319. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6320. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6321. } else {
  6322. /* Ovlan exists only if we are in multi-function +
  6323. * switch-dependent mode, in switch-independent there
  6324. * is no ovlan headers
  6325. */
  6326. REG_WR(bp, BP_PORT(bp) ?
  6327. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6328. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6329. (bp->path_has_ovlan ? 7 : 6));
  6330. }
  6331. }
  6332. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6333. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6334. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6335. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6336. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6337. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6338. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6339. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6340. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6341. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6342. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6343. if (CHIP_IS_E1x(bp)) {
  6344. /* configure PBF to work without PAUSE mtu 9000 */
  6345. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6346. /* update threshold */
  6347. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6348. /* update init credit */
  6349. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6350. /* probe changes */
  6351. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6352. udelay(50);
  6353. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6354. }
  6355. if (CNIC_SUPPORT(bp))
  6356. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6357. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6358. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6359. if (CHIP_IS_E1(bp)) {
  6360. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6361. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6362. }
  6363. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6364. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6365. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6366. /* init aeu_mask_attn_func_0/1:
  6367. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6368. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6369. * bits 4-7 are used for "per vn group attention" */
  6370. val = IS_MF(bp) ? 0xF7 : 0x7;
  6371. /* Enable DCBX attention for all but E1 */
  6372. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6373. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6374. /* SCPAD_PARITY should NOT trigger close the gates */
  6375. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6376. REG_WR(bp, reg,
  6377. REG_RD(bp, reg) &
  6378. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6379. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6380. REG_WR(bp, reg,
  6381. REG_RD(bp, reg) &
  6382. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6383. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6384. if (!CHIP_IS_E1x(bp)) {
  6385. /* Bit-map indicating which L2 hdrs may appear after the
  6386. * basic Ethernet header
  6387. */
  6388. if (IS_MF_AFEX(bp))
  6389. REG_WR(bp, BP_PORT(bp) ?
  6390. NIG_REG_P1_HDRS_AFTER_BASIC :
  6391. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6392. else
  6393. REG_WR(bp, BP_PORT(bp) ?
  6394. NIG_REG_P1_HDRS_AFTER_BASIC :
  6395. NIG_REG_P0_HDRS_AFTER_BASIC,
  6396. IS_MF_SD(bp) ? 7 : 6);
  6397. if (CHIP_IS_E3(bp))
  6398. REG_WR(bp, BP_PORT(bp) ?
  6399. NIG_REG_LLH1_MF_MODE :
  6400. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6401. }
  6402. if (!CHIP_IS_E3(bp))
  6403. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6404. if (!CHIP_IS_E1(bp)) {
  6405. /* 0x2 disable mf_ov, 0x1 enable */
  6406. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6407. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6408. if (!CHIP_IS_E1x(bp)) {
  6409. val = 0;
  6410. switch (bp->mf_mode) {
  6411. case MULTI_FUNCTION_SD:
  6412. val = 1;
  6413. break;
  6414. case MULTI_FUNCTION_SI:
  6415. case MULTI_FUNCTION_AFEX:
  6416. val = 2;
  6417. break;
  6418. }
  6419. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6420. NIG_REG_LLH0_CLS_TYPE), val);
  6421. }
  6422. {
  6423. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6424. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6425. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6426. }
  6427. }
  6428. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6429. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6430. if (val & MISC_SPIO_SPIO5) {
  6431. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6432. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6433. val = REG_RD(bp, reg_addr);
  6434. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6435. REG_WR(bp, reg_addr, val);
  6436. }
  6437. return 0;
  6438. }
  6439. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6440. {
  6441. int reg;
  6442. u32 wb_write[2];
  6443. if (CHIP_IS_E1(bp))
  6444. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6445. else
  6446. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6447. wb_write[0] = ONCHIP_ADDR1(addr);
  6448. wb_write[1] = ONCHIP_ADDR2(addr);
  6449. REG_WR_DMAE(bp, reg, wb_write, 2);
  6450. }
  6451. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6452. {
  6453. u32 data, ctl, cnt = 100;
  6454. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6455. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6456. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6457. u32 sb_bit = 1 << (idu_sb_id%32);
  6458. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6459. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6460. /* Not supported in BC mode */
  6461. if (CHIP_INT_MODE_IS_BC(bp))
  6462. return;
  6463. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6464. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6465. IGU_REGULAR_CLEANUP_SET |
  6466. IGU_REGULAR_BCLEANUP;
  6467. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6468. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6469. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6470. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6471. data, igu_addr_data);
  6472. REG_WR(bp, igu_addr_data, data);
  6473. mmiowb();
  6474. barrier();
  6475. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6476. ctl, igu_addr_ctl);
  6477. REG_WR(bp, igu_addr_ctl, ctl);
  6478. mmiowb();
  6479. barrier();
  6480. /* wait for clean up to finish */
  6481. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6482. msleep(20);
  6483. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6484. DP(NETIF_MSG_HW,
  6485. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6486. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6487. }
  6488. }
  6489. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6490. {
  6491. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6492. }
  6493. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6494. {
  6495. u32 i, base = FUNC_ILT_BASE(func);
  6496. for (i = base; i < base + ILT_PER_FUNC; i++)
  6497. bnx2x_ilt_wr(bp, i, 0);
  6498. }
  6499. static void bnx2x_init_searcher(struct bnx2x *bp)
  6500. {
  6501. int port = BP_PORT(bp);
  6502. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6503. /* T1 hash bits value determines the T1 number of entries */
  6504. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6505. }
  6506. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6507. {
  6508. int rc;
  6509. struct bnx2x_func_state_params func_params = {NULL};
  6510. struct bnx2x_func_switch_update_params *switch_update_params =
  6511. &func_params.params.switch_update;
  6512. /* Prepare parameters for function state transitions */
  6513. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6514. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6515. func_params.f_obj = &bp->func_obj;
  6516. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6517. /* Function parameters */
  6518. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6519. &switch_update_params->changes);
  6520. if (suspend)
  6521. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6522. &switch_update_params->changes);
  6523. rc = bnx2x_func_state_change(bp, &func_params);
  6524. return rc;
  6525. }
  6526. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6527. {
  6528. int rc, i, port = BP_PORT(bp);
  6529. int vlan_en = 0, mac_en[NUM_MACS];
  6530. /* Close input from network */
  6531. if (bp->mf_mode == SINGLE_FUNCTION) {
  6532. bnx2x_set_rx_filter(&bp->link_params, 0);
  6533. } else {
  6534. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6535. NIG_REG_LLH0_FUNC_EN);
  6536. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6537. NIG_REG_LLH0_FUNC_EN, 0);
  6538. for (i = 0; i < NUM_MACS; i++) {
  6539. mac_en[i] = REG_RD(bp, port ?
  6540. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6541. 4 * i) :
  6542. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6543. 4 * i));
  6544. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6545. 4 * i) :
  6546. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6547. }
  6548. }
  6549. /* Close BMC to host */
  6550. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6551. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6552. /* Suspend Tx switching to the PF. Completion of this ramrod
  6553. * further guarantees that all the packets of that PF / child
  6554. * VFs in BRB were processed by the Parser, so it is safe to
  6555. * change the NIC_MODE register.
  6556. */
  6557. rc = bnx2x_func_switch_update(bp, 1);
  6558. if (rc) {
  6559. BNX2X_ERR("Can't suspend tx-switching!\n");
  6560. return rc;
  6561. }
  6562. /* Change NIC_MODE register */
  6563. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6564. /* Open input from network */
  6565. if (bp->mf_mode == SINGLE_FUNCTION) {
  6566. bnx2x_set_rx_filter(&bp->link_params, 1);
  6567. } else {
  6568. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6569. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6570. for (i = 0; i < NUM_MACS; i++) {
  6571. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6572. 4 * i) :
  6573. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6574. mac_en[i]);
  6575. }
  6576. }
  6577. /* Enable BMC to host */
  6578. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6579. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6580. /* Resume Tx switching to the PF */
  6581. rc = bnx2x_func_switch_update(bp, 0);
  6582. if (rc) {
  6583. BNX2X_ERR("Can't resume tx-switching!\n");
  6584. return rc;
  6585. }
  6586. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6587. return 0;
  6588. }
  6589. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6590. {
  6591. int rc;
  6592. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6593. if (CONFIGURE_NIC_MODE(bp)) {
  6594. /* Configure searcher as part of function hw init */
  6595. bnx2x_init_searcher(bp);
  6596. /* Reset NIC mode */
  6597. rc = bnx2x_reset_nic_mode(bp);
  6598. if (rc)
  6599. BNX2X_ERR("Can't change NIC mode!\n");
  6600. return rc;
  6601. }
  6602. return 0;
  6603. }
  6604. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6605. {
  6606. int port = BP_PORT(bp);
  6607. int func = BP_FUNC(bp);
  6608. int init_phase = PHASE_PF0 + func;
  6609. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6610. u16 cdu_ilt_start;
  6611. u32 addr, val;
  6612. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6613. int i, main_mem_width, rc;
  6614. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6615. /* FLR cleanup - hmmm */
  6616. if (!CHIP_IS_E1x(bp)) {
  6617. rc = bnx2x_pf_flr_clnup(bp);
  6618. if (rc) {
  6619. bnx2x_fw_dump(bp);
  6620. return rc;
  6621. }
  6622. }
  6623. /* set MSI reconfigure capability */
  6624. if (bp->common.int_block == INT_BLOCK_HC) {
  6625. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6626. val = REG_RD(bp, addr);
  6627. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6628. REG_WR(bp, addr, val);
  6629. }
  6630. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6631. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6632. ilt = BP_ILT(bp);
  6633. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6634. if (IS_SRIOV(bp))
  6635. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6636. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6637. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6638. * those of the VFs, so start line should be reset
  6639. */
  6640. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6641. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6642. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6643. ilt->lines[cdu_ilt_start + i].page_mapping =
  6644. bp->context[i].cxt_mapping;
  6645. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6646. }
  6647. bnx2x_ilt_init_op(bp, INITOP_SET);
  6648. if (!CONFIGURE_NIC_MODE(bp)) {
  6649. bnx2x_init_searcher(bp);
  6650. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6651. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6652. } else {
  6653. /* Set NIC mode */
  6654. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6655. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6656. }
  6657. if (!CHIP_IS_E1x(bp)) {
  6658. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6659. /* Turn on a single ISR mode in IGU if driver is going to use
  6660. * INT#x or MSI
  6661. */
  6662. if (!(bp->flags & USING_MSIX_FLAG))
  6663. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6664. /*
  6665. * Timers workaround bug: function init part.
  6666. * Need to wait 20msec after initializing ILT,
  6667. * needed to make sure there are no requests in
  6668. * one of the PXP internal queues with "old" ILT addresses
  6669. */
  6670. msleep(20);
  6671. /*
  6672. * Master enable - Due to WB DMAE writes performed before this
  6673. * register is re-initialized as part of the regular function
  6674. * init
  6675. */
  6676. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6677. /* Enable the function in IGU */
  6678. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6679. }
  6680. bp->dmae_ready = 1;
  6681. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6682. if (!CHIP_IS_E1x(bp))
  6683. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6684. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6685. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6686. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6687. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6688. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6689. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6690. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6691. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6692. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6693. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6694. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6695. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6696. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6697. if (!CHIP_IS_E1x(bp))
  6698. REG_WR(bp, QM_REG_PF_EN, 1);
  6699. if (!CHIP_IS_E1x(bp)) {
  6700. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6701. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6702. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6703. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6704. }
  6705. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6706. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6707. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6708. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6709. bnx2x_iov_init_dq(bp);
  6710. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6711. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6712. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6713. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6714. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6715. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6716. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6717. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6718. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6719. if (!CHIP_IS_E1x(bp))
  6720. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6721. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6722. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6723. if (!CHIP_IS_E1x(bp))
  6724. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6725. if (IS_MF(bp)) {
  6726. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6727. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6728. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6729. bp->mf_ov);
  6730. }
  6731. }
  6732. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6733. /* HC init per function */
  6734. if (bp->common.int_block == INT_BLOCK_HC) {
  6735. if (CHIP_IS_E1H(bp)) {
  6736. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6737. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6738. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6739. }
  6740. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6741. } else {
  6742. int num_segs, sb_idx, prod_offset;
  6743. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6744. if (!CHIP_IS_E1x(bp)) {
  6745. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6746. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6747. }
  6748. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6749. if (!CHIP_IS_E1x(bp)) {
  6750. int dsb_idx = 0;
  6751. /**
  6752. * Producer memory:
  6753. * E2 mode: address 0-135 match to the mapping memory;
  6754. * 136 - PF0 default prod; 137 - PF1 default prod;
  6755. * 138 - PF2 default prod; 139 - PF3 default prod;
  6756. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6757. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6758. * 144-147 reserved.
  6759. *
  6760. * E1.5 mode - In backward compatible mode;
  6761. * for non default SB; each even line in the memory
  6762. * holds the U producer and each odd line hold
  6763. * the C producer. The first 128 producers are for
  6764. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6765. * producers are for the DSB for each PF.
  6766. * Each PF has five segments: (the order inside each
  6767. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6768. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6769. * 144-147 attn prods;
  6770. */
  6771. /* non-default-status-blocks */
  6772. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6773. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6774. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6775. prod_offset = (bp->igu_base_sb + sb_idx) *
  6776. num_segs;
  6777. for (i = 0; i < num_segs; i++) {
  6778. addr = IGU_REG_PROD_CONS_MEMORY +
  6779. (prod_offset + i) * 4;
  6780. REG_WR(bp, addr, 0);
  6781. }
  6782. /* send consumer update with value 0 */
  6783. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6784. USTORM_ID, 0, IGU_INT_NOP, 1);
  6785. bnx2x_igu_clear_sb(bp,
  6786. bp->igu_base_sb + sb_idx);
  6787. }
  6788. /* default-status-blocks */
  6789. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6790. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6791. if (CHIP_MODE_IS_4_PORT(bp))
  6792. dsb_idx = BP_FUNC(bp);
  6793. else
  6794. dsb_idx = BP_VN(bp);
  6795. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6796. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6797. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6798. /*
  6799. * igu prods come in chunks of E1HVN_MAX (4) -
  6800. * does not matters what is the current chip mode
  6801. */
  6802. for (i = 0; i < (num_segs * E1HVN_MAX);
  6803. i += E1HVN_MAX) {
  6804. addr = IGU_REG_PROD_CONS_MEMORY +
  6805. (prod_offset + i)*4;
  6806. REG_WR(bp, addr, 0);
  6807. }
  6808. /* send consumer update with 0 */
  6809. if (CHIP_INT_MODE_IS_BC(bp)) {
  6810. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6811. USTORM_ID, 0, IGU_INT_NOP, 1);
  6812. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6813. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6814. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6815. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6816. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6817. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6818. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6819. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6820. } else {
  6821. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6822. USTORM_ID, 0, IGU_INT_NOP, 1);
  6823. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6824. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6825. }
  6826. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6827. /* !!! These should become driver const once
  6828. rf-tool supports split-68 const */
  6829. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6830. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6831. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6832. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6833. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6834. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6835. }
  6836. }
  6837. /* Reset PCIE errors for debug */
  6838. REG_WR(bp, 0x2114, 0xffffffff);
  6839. REG_WR(bp, 0x2120, 0xffffffff);
  6840. if (CHIP_IS_E1x(bp)) {
  6841. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6842. main_mem_base = HC_REG_MAIN_MEMORY +
  6843. BP_PORT(bp) * (main_mem_size * 4);
  6844. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6845. main_mem_width = 8;
  6846. val = REG_RD(bp, main_mem_prty_clr);
  6847. if (val)
  6848. DP(NETIF_MSG_HW,
  6849. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6850. val);
  6851. /* Clear "false" parity errors in MSI-X table */
  6852. for (i = main_mem_base;
  6853. i < main_mem_base + main_mem_size * 4;
  6854. i += main_mem_width) {
  6855. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6856. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6857. i, main_mem_width / 4);
  6858. }
  6859. /* Clear HC parity attention */
  6860. REG_RD(bp, main_mem_prty_clr);
  6861. }
  6862. #ifdef BNX2X_STOP_ON_ERROR
  6863. /* Enable STORMs SP logging */
  6864. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6865. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6866. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6867. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6868. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6869. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6870. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6871. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6872. #endif
  6873. bnx2x_phy_probe(&bp->link_params);
  6874. return 0;
  6875. }
  6876. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6877. {
  6878. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6879. if (!CHIP_IS_E1x(bp))
  6880. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6881. sizeof(struct host_hc_status_block_e2));
  6882. else
  6883. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6884. sizeof(struct host_hc_status_block_e1x));
  6885. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6886. }
  6887. void bnx2x_free_mem(struct bnx2x *bp)
  6888. {
  6889. int i;
  6890. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6891. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6892. if (IS_VF(bp))
  6893. return;
  6894. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6895. sizeof(struct host_sp_status_block));
  6896. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6897. sizeof(struct bnx2x_slowpath));
  6898. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6899. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6900. bp->context[i].size);
  6901. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6902. BNX2X_FREE(bp->ilt->lines);
  6903. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6904. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6905. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6906. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6907. bnx2x_iov_free_mem(bp);
  6908. }
  6909. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6910. {
  6911. if (!CHIP_IS_E1x(bp)) {
  6912. /* size = the status block + ramrod buffers */
  6913. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6914. sizeof(struct host_hc_status_block_e2));
  6915. if (!bp->cnic_sb.e2_sb)
  6916. goto alloc_mem_err;
  6917. } else {
  6918. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6919. sizeof(struct host_hc_status_block_e1x));
  6920. if (!bp->cnic_sb.e1x_sb)
  6921. goto alloc_mem_err;
  6922. }
  6923. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6924. /* allocate searcher T2 table, as it wasn't allocated before */
  6925. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6926. if (!bp->t2)
  6927. goto alloc_mem_err;
  6928. }
  6929. /* write address to which L5 should insert its values */
  6930. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6931. &bp->slowpath->drv_info_to_mcp;
  6932. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6933. goto alloc_mem_err;
  6934. return 0;
  6935. alloc_mem_err:
  6936. bnx2x_free_mem_cnic(bp);
  6937. BNX2X_ERR("Can't allocate memory\n");
  6938. return -ENOMEM;
  6939. }
  6940. int bnx2x_alloc_mem(struct bnx2x *bp)
  6941. {
  6942. int i, allocated, context_size;
  6943. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6944. /* allocate searcher T2 table */
  6945. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6946. if (!bp->t2)
  6947. goto alloc_mem_err;
  6948. }
  6949. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6950. sizeof(struct host_sp_status_block));
  6951. if (!bp->def_status_blk)
  6952. goto alloc_mem_err;
  6953. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6954. sizeof(struct bnx2x_slowpath));
  6955. if (!bp->slowpath)
  6956. goto alloc_mem_err;
  6957. /* Allocate memory for CDU context:
  6958. * This memory is allocated separately and not in the generic ILT
  6959. * functions because CDU differs in few aspects:
  6960. * 1. There are multiple entities allocating memory for context -
  6961. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6962. * its own ILT lines.
  6963. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6964. * for the other ILT clients), to be efficient we want to support
  6965. * allocation of sub-page-size in the last entry.
  6966. * 3. Context pointers are used by the driver to pass to FW / update
  6967. * the context (for the other ILT clients the pointers are used just to
  6968. * free the memory during unload).
  6969. */
  6970. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6971. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6972. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6973. (context_size - allocated));
  6974. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6975. bp->context[i].size);
  6976. if (!bp->context[i].vcxt)
  6977. goto alloc_mem_err;
  6978. allocated += bp->context[i].size;
  6979. }
  6980. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6981. GFP_KERNEL);
  6982. if (!bp->ilt->lines)
  6983. goto alloc_mem_err;
  6984. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6985. goto alloc_mem_err;
  6986. if (bnx2x_iov_alloc_mem(bp))
  6987. goto alloc_mem_err;
  6988. /* Slow path ring */
  6989. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  6990. if (!bp->spq)
  6991. goto alloc_mem_err;
  6992. /* EQ */
  6993. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  6994. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6995. if (!bp->eq_ring)
  6996. goto alloc_mem_err;
  6997. return 0;
  6998. alloc_mem_err:
  6999. bnx2x_free_mem(bp);
  7000. BNX2X_ERR("Can't allocate memory\n");
  7001. return -ENOMEM;
  7002. }
  7003. /*
  7004. * Init service functions
  7005. */
  7006. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7007. struct bnx2x_vlan_mac_obj *obj, bool set,
  7008. int mac_type, unsigned long *ramrod_flags)
  7009. {
  7010. int rc;
  7011. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7012. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7013. /* Fill general parameters */
  7014. ramrod_param.vlan_mac_obj = obj;
  7015. ramrod_param.ramrod_flags = *ramrod_flags;
  7016. /* Fill a user request section if needed */
  7017. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7018. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7019. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7020. /* Set the command: ADD or DEL */
  7021. if (set)
  7022. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7023. else
  7024. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7025. }
  7026. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7027. if (rc == -EEXIST) {
  7028. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7029. /* do not treat adding same MAC as error */
  7030. rc = 0;
  7031. } else if (rc < 0)
  7032. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7033. return rc;
  7034. }
  7035. int bnx2x_del_all_macs(struct bnx2x *bp,
  7036. struct bnx2x_vlan_mac_obj *mac_obj,
  7037. int mac_type, bool wait_for_comp)
  7038. {
  7039. int rc;
  7040. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7041. /* Wait for completion of requested */
  7042. if (wait_for_comp)
  7043. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7044. /* Set the mac type of addresses we want to clear */
  7045. __set_bit(mac_type, &vlan_mac_flags);
  7046. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7047. if (rc < 0)
  7048. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7049. return rc;
  7050. }
  7051. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7052. {
  7053. if (IS_PF(bp)) {
  7054. unsigned long ramrod_flags = 0;
  7055. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7056. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7057. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7058. &bp->sp_objs->mac_obj, set,
  7059. BNX2X_ETH_MAC, &ramrod_flags);
  7060. } else { /* vf */
  7061. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7062. bp->fp->index, true);
  7063. }
  7064. }
  7065. int bnx2x_setup_leading(struct bnx2x *bp)
  7066. {
  7067. if (IS_PF(bp))
  7068. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7069. else /* VF */
  7070. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7071. }
  7072. /**
  7073. * bnx2x_set_int_mode - configure interrupt mode
  7074. *
  7075. * @bp: driver handle
  7076. *
  7077. * In case of MSI-X it will also try to enable MSI-X.
  7078. */
  7079. int bnx2x_set_int_mode(struct bnx2x *bp)
  7080. {
  7081. int rc = 0;
  7082. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7083. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7084. return -EINVAL;
  7085. }
  7086. switch (int_mode) {
  7087. case BNX2X_INT_MODE_MSIX:
  7088. /* attempt to enable msix */
  7089. rc = bnx2x_enable_msix(bp);
  7090. /* msix attained */
  7091. if (!rc)
  7092. return 0;
  7093. /* vfs use only msix */
  7094. if (rc && IS_VF(bp))
  7095. return rc;
  7096. /* failed to enable multiple MSI-X */
  7097. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7098. bp->num_queues,
  7099. 1 + bp->num_cnic_queues);
  7100. /* falling through... */
  7101. case BNX2X_INT_MODE_MSI:
  7102. bnx2x_enable_msi(bp);
  7103. /* falling through... */
  7104. case BNX2X_INT_MODE_INTX:
  7105. bp->num_ethernet_queues = 1;
  7106. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7107. BNX2X_DEV_INFO("set number of queues to 1\n");
  7108. break;
  7109. default:
  7110. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7111. return -EINVAL;
  7112. }
  7113. return 0;
  7114. }
  7115. /* must be called prior to any HW initializations */
  7116. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7117. {
  7118. if (IS_SRIOV(bp))
  7119. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7120. return L2_ILT_LINES(bp);
  7121. }
  7122. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7123. {
  7124. struct ilt_client_info *ilt_client;
  7125. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7126. u16 line = 0;
  7127. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7128. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7129. /* CDU */
  7130. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7131. ilt_client->client_num = ILT_CLIENT_CDU;
  7132. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7133. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7134. ilt_client->start = line;
  7135. line += bnx2x_cid_ilt_lines(bp);
  7136. if (CNIC_SUPPORT(bp))
  7137. line += CNIC_ILT_LINES;
  7138. ilt_client->end = line - 1;
  7139. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7140. ilt_client->start,
  7141. ilt_client->end,
  7142. ilt_client->page_size,
  7143. ilt_client->flags,
  7144. ilog2(ilt_client->page_size >> 12));
  7145. /* QM */
  7146. if (QM_INIT(bp->qm_cid_count)) {
  7147. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7148. ilt_client->client_num = ILT_CLIENT_QM;
  7149. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7150. ilt_client->flags = 0;
  7151. ilt_client->start = line;
  7152. /* 4 bytes for each cid */
  7153. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7154. QM_ILT_PAGE_SZ);
  7155. ilt_client->end = line - 1;
  7156. DP(NETIF_MSG_IFUP,
  7157. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7158. ilt_client->start,
  7159. ilt_client->end,
  7160. ilt_client->page_size,
  7161. ilt_client->flags,
  7162. ilog2(ilt_client->page_size >> 12));
  7163. }
  7164. if (CNIC_SUPPORT(bp)) {
  7165. /* SRC */
  7166. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7167. ilt_client->client_num = ILT_CLIENT_SRC;
  7168. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7169. ilt_client->flags = 0;
  7170. ilt_client->start = line;
  7171. line += SRC_ILT_LINES;
  7172. ilt_client->end = line - 1;
  7173. DP(NETIF_MSG_IFUP,
  7174. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7175. ilt_client->start,
  7176. ilt_client->end,
  7177. ilt_client->page_size,
  7178. ilt_client->flags,
  7179. ilog2(ilt_client->page_size >> 12));
  7180. /* TM */
  7181. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7182. ilt_client->client_num = ILT_CLIENT_TM;
  7183. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7184. ilt_client->flags = 0;
  7185. ilt_client->start = line;
  7186. line += TM_ILT_LINES;
  7187. ilt_client->end = line - 1;
  7188. DP(NETIF_MSG_IFUP,
  7189. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7190. ilt_client->start,
  7191. ilt_client->end,
  7192. ilt_client->page_size,
  7193. ilt_client->flags,
  7194. ilog2(ilt_client->page_size >> 12));
  7195. }
  7196. BUG_ON(line > ILT_MAX_LINES);
  7197. }
  7198. /**
  7199. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7200. *
  7201. * @bp: driver handle
  7202. * @fp: pointer to fastpath
  7203. * @init_params: pointer to parameters structure
  7204. *
  7205. * parameters configured:
  7206. * - HC configuration
  7207. * - Queue's CDU context
  7208. */
  7209. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7210. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7211. {
  7212. u8 cos;
  7213. int cxt_index, cxt_offset;
  7214. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7215. if (!IS_FCOE_FP(fp)) {
  7216. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7217. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7218. /* If HC is supported, enable host coalescing in the transition
  7219. * to INIT state.
  7220. */
  7221. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7222. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7223. /* HC rate */
  7224. init_params->rx.hc_rate = bp->rx_ticks ?
  7225. (1000000 / bp->rx_ticks) : 0;
  7226. init_params->tx.hc_rate = bp->tx_ticks ?
  7227. (1000000 / bp->tx_ticks) : 0;
  7228. /* FW SB ID */
  7229. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7230. fp->fw_sb_id;
  7231. /*
  7232. * CQ index among the SB indices: FCoE clients uses the default
  7233. * SB, therefore it's different.
  7234. */
  7235. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7236. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7237. }
  7238. /* set maximum number of COSs supported by this queue */
  7239. init_params->max_cos = fp->max_cos;
  7240. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7241. fp->index, init_params->max_cos);
  7242. /* set the context pointers queue object */
  7243. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7244. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7245. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7246. ILT_PAGE_CIDS);
  7247. init_params->cxts[cos] =
  7248. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7249. }
  7250. }
  7251. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7252. struct bnx2x_queue_state_params *q_params,
  7253. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7254. int tx_index, bool leading)
  7255. {
  7256. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7257. /* Set the command */
  7258. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7259. /* Set tx-only QUEUE flags: don't zero statistics */
  7260. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7261. /* choose the index of the cid to send the slow path on */
  7262. tx_only_params->cid_index = tx_index;
  7263. /* Set general TX_ONLY_SETUP parameters */
  7264. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7265. /* Set Tx TX_ONLY_SETUP parameters */
  7266. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7267. DP(NETIF_MSG_IFUP,
  7268. "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",
  7269. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7270. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7271. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7272. /* send the ramrod */
  7273. return bnx2x_queue_state_change(bp, q_params);
  7274. }
  7275. /**
  7276. * bnx2x_setup_queue - setup queue
  7277. *
  7278. * @bp: driver handle
  7279. * @fp: pointer to fastpath
  7280. * @leading: is leading
  7281. *
  7282. * This function performs 2 steps in a Queue state machine
  7283. * actually: 1) RESET->INIT 2) INIT->SETUP
  7284. */
  7285. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7286. bool leading)
  7287. {
  7288. struct bnx2x_queue_state_params q_params = {NULL};
  7289. struct bnx2x_queue_setup_params *setup_params =
  7290. &q_params.params.setup;
  7291. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7292. &q_params.params.tx_only;
  7293. int rc;
  7294. u8 tx_index;
  7295. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7296. /* reset IGU state skip FCoE L2 queue */
  7297. if (!IS_FCOE_FP(fp))
  7298. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7299. IGU_INT_ENABLE, 0);
  7300. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7301. /* We want to wait for completion in this context */
  7302. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7303. /* Prepare the INIT parameters */
  7304. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7305. /* Set the command */
  7306. q_params.cmd = BNX2X_Q_CMD_INIT;
  7307. /* Change the state to INIT */
  7308. rc = bnx2x_queue_state_change(bp, &q_params);
  7309. if (rc) {
  7310. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7311. return rc;
  7312. }
  7313. DP(NETIF_MSG_IFUP, "init complete\n");
  7314. /* Now move the Queue to the SETUP state... */
  7315. memset(setup_params, 0, sizeof(*setup_params));
  7316. /* Set QUEUE flags */
  7317. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7318. /* Set general SETUP parameters */
  7319. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7320. FIRST_TX_COS_INDEX);
  7321. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7322. &setup_params->rxq_params);
  7323. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7324. FIRST_TX_COS_INDEX);
  7325. /* Set the command */
  7326. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7327. if (IS_FCOE_FP(fp))
  7328. bp->fcoe_init = true;
  7329. /* Change the state to SETUP */
  7330. rc = bnx2x_queue_state_change(bp, &q_params);
  7331. if (rc) {
  7332. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7333. return rc;
  7334. }
  7335. /* loop through the relevant tx-only indices */
  7336. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7337. tx_index < fp->max_cos;
  7338. tx_index++) {
  7339. /* prepare and send tx-only ramrod*/
  7340. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7341. tx_only_params, tx_index, leading);
  7342. if (rc) {
  7343. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7344. fp->index, tx_index);
  7345. return rc;
  7346. }
  7347. }
  7348. return rc;
  7349. }
  7350. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7351. {
  7352. struct bnx2x_fastpath *fp = &bp->fp[index];
  7353. struct bnx2x_fp_txdata *txdata;
  7354. struct bnx2x_queue_state_params q_params = {NULL};
  7355. int rc, tx_index;
  7356. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7357. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7358. /* We want to wait for completion in this context */
  7359. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7360. /* close tx-only connections */
  7361. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7362. tx_index < fp->max_cos;
  7363. tx_index++){
  7364. /* ascertain this is a normal queue*/
  7365. txdata = fp->txdata_ptr[tx_index];
  7366. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7367. txdata->txq_index);
  7368. /* send halt terminate on tx-only connection */
  7369. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7370. memset(&q_params.params.terminate, 0,
  7371. sizeof(q_params.params.terminate));
  7372. q_params.params.terminate.cid_index = tx_index;
  7373. rc = bnx2x_queue_state_change(bp, &q_params);
  7374. if (rc)
  7375. return rc;
  7376. /* send halt terminate on tx-only connection */
  7377. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7378. memset(&q_params.params.cfc_del, 0,
  7379. sizeof(q_params.params.cfc_del));
  7380. q_params.params.cfc_del.cid_index = tx_index;
  7381. rc = bnx2x_queue_state_change(bp, &q_params);
  7382. if (rc)
  7383. return rc;
  7384. }
  7385. /* Stop the primary connection: */
  7386. /* ...halt the connection */
  7387. q_params.cmd = BNX2X_Q_CMD_HALT;
  7388. rc = bnx2x_queue_state_change(bp, &q_params);
  7389. if (rc)
  7390. return rc;
  7391. /* ...terminate the connection */
  7392. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7393. memset(&q_params.params.terminate, 0,
  7394. sizeof(q_params.params.terminate));
  7395. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7396. rc = bnx2x_queue_state_change(bp, &q_params);
  7397. if (rc)
  7398. return rc;
  7399. /* ...delete cfc entry */
  7400. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7401. memset(&q_params.params.cfc_del, 0,
  7402. sizeof(q_params.params.cfc_del));
  7403. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7404. return bnx2x_queue_state_change(bp, &q_params);
  7405. }
  7406. static void bnx2x_reset_func(struct bnx2x *bp)
  7407. {
  7408. int port = BP_PORT(bp);
  7409. int func = BP_FUNC(bp);
  7410. int i;
  7411. /* Disable the function in the FW */
  7412. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7413. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7414. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7415. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7416. /* FP SBs */
  7417. for_each_eth_queue(bp, i) {
  7418. struct bnx2x_fastpath *fp = &bp->fp[i];
  7419. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7420. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7421. SB_DISABLED);
  7422. }
  7423. if (CNIC_LOADED(bp))
  7424. /* CNIC SB */
  7425. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7426. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7427. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7428. /* SP SB */
  7429. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7430. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7431. SB_DISABLED);
  7432. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7433. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7434. 0);
  7435. /* Configure IGU */
  7436. if (bp->common.int_block == INT_BLOCK_HC) {
  7437. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7438. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7439. } else {
  7440. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7441. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7442. }
  7443. if (CNIC_LOADED(bp)) {
  7444. /* Disable Timer scan */
  7445. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7446. /*
  7447. * Wait for at least 10ms and up to 2 second for the timers
  7448. * scan to complete
  7449. */
  7450. for (i = 0; i < 200; i++) {
  7451. usleep_range(10000, 20000);
  7452. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7453. break;
  7454. }
  7455. }
  7456. /* Clear ILT */
  7457. bnx2x_clear_func_ilt(bp, func);
  7458. /* Timers workaround bug for E2: if this is vnic-3,
  7459. * we need to set the entire ilt range for this timers.
  7460. */
  7461. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7462. struct ilt_client_info ilt_cli;
  7463. /* use dummy TM client */
  7464. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7465. ilt_cli.start = 0;
  7466. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7467. ilt_cli.client_num = ILT_CLIENT_TM;
  7468. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7469. }
  7470. /* this assumes that reset_port() called before reset_func()*/
  7471. if (!CHIP_IS_E1x(bp))
  7472. bnx2x_pf_disable(bp);
  7473. bp->dmae_ready = 0;
  7474. }
  7475. static void bnx2x_reset_port(struct bnx2x *bp)
  7476. {
  7477. int port = BP_PORT(bp);
  7478. u32 val;
  7479. /* Reset physical Link */
  7480. bnx2x__link_reset(bp);
  7481. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7482. /* Do not rcv packets to BRB */
  7483. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7484. /* Do not direct rcv packets that are not for MCP to the BRB */
  7485. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7486. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7487. /* Configure AEU */
  7488. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7489. msleep(100);
  7490. /* Check for BRB port occupancy */
  7491. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7492. if (val)
  7493. DP(NETIF_MSG_IFDOWN,
  7494. "BRB1 is not empty %d blocks are occupied\n", val);
  7495. /* TODO: Close Doorbell port? */
  7496. }
  7497. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7498. {
  7499. struct bnx2x_func_state_params func_params = {NULL};
  7500. /* Prepare parameters for function state transitions */
  7501. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7502. func_params.f_obj = &bp->func_obj;
  7503. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7504. func_params.params.hw_init.load_phase = load_code;
  7505. return bnx2x_func_state_change(bp, &func_params);
  7506. }
  7507. static int bnx2x_func_stop(struct bnx2x *bp)
  7508. {
  7509. struct bnx2x_func_state_params func_params = {NULL};
  7510. int rc;
  7511. /* Prepare parameters for function state transitions */
  7512. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7513. func_params.f_obj = &bp->func_obj;
  7514. func_params.cmd = BNX2X_F_CMD_STOP;
  7515. /*
  7516. * Try to stop the function the 'good way'. If fails (in case
  7517. * of a parity error during bnx2x_chip_cleanup()) and we are
  7518. * not in a debug mode, perform a state transaction in order to
  7519. * enable further HW_RESET transaction.
  7520. */
  7521. rc = bnx2x_func_state_change(bp, &func_params);
  7522. if (rc) {
  7523. #ifdef BNX2X_STOP_ON_ERROR
  7524. return rc;
  7525. #else
  7526. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7527. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7528. return bnx2x_func_state_change(bp, &func_params);
  7529. #endif
  7530. }
  7531. return 0;
  7532. }
  7533. /**
  7534. * bnx2x_send_unload_req - request unload mode from the MCP.
  7535. *
  7536. * @bp: driver handle
  7537. * @unload_mode: requested function's unload mode
  7538. *
  7539. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7540. */
  7541. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7542. {
  7543. u32 reset_code = 0;
  7544. int port = BP_PORT(bp);
  7545. /* Select the UNLOAD request mode */
  7546. if (unload_mode == UNLOAD_NORMAL)
  7547. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7548. else if (bp->flags & NO_WOL_FLAG)
  7549. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7550. else if (bp->wol) {
  7551. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7552. u8 *mac_addr = bp->dev->dev_addr;
  7553. struct pci_dev *pdev = bp->pdev;
  7554. u32 val;
  7555. u16 pmc;
  7556. /* The mac address is written to entries 1-4 to
  7557. * preserve entry 0 which is used by the PMF
  7558. */
  7559. u8 entry = (BP_VN(bp) + 1)*8;
  7560. val = (mac_addr[0] << 8) | mac_addr[1];
  7561. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7562. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7563. (mac_addr[4] << 8) | mac_addr[5];
  7564. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7565. /* Enable the PME and clear the status */
  7566. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7567. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7568. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7569. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7570. } else
  7571. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7572. /* Send the request to the MCP */
  7573. if (!BP_NOMCP(bp))
  7574. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7575. else {
  7576. int path = BP_PATH(bp);
  7577. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7578. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7579. bnx2x_load_count[path][2]);
  7580. bnx2x_load_count[path][0]--;
  7581. bnx2x_load_count[path][1 + port]--;
  7582. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7583. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7584. bnx2x_load_count[path][2]);
  7585. if (bnx2x_load_count[path][0] == 0)
  7586. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7587. else if (bnx2x_load_count[path][1 + port] == 0)
  7588. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7589. else
  7590. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7591. }
  7592. return reset_code;
  7593. }
  7594. /**
  7595. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7596. *
  7597. * @bp: driver handle
  7598. * @keep_link: true iff link should be kept up
  7599. */
  7600. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7601. {
  7602. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7603. /* Report UNLOAD_DONE to MCP */
  7604. if (!BP_NOMCP(bp))
  7605. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7606. }
  7607. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7608. {
  7609. int tout = 50;
  7610. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7611. if (!bp->port.pmf)
  7612. return 0;
  7613. /*
  7614. * (assumption: No Attention from MCP at this stage)
  7615. * PMF probably in the middle of TX disable/enable transaction
  7616. * 1. Sync IRS for default SB
  7617. * 2. Sync SP queue - this guarantees us that attention handling started
  7618. * 3. Wait, that TX disable/enable transaction completes
  7619. *
  7620. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7621. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7622. * received completion for the transaction the state is TX_STOPPED.
  7623. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7624. * transaction.
  7625. */
  7626. /* make sure default SB ISR is done */
  7627. if (msix)
  7628. synchronize_irq(bp->msix_table[0].vector);
  7629. else
  7630. synchronize_irq(bp->pdev->irq);
  7631. flush_workqueue(bnx2x_wq);
  7632. flush_workqueue(bnx2x_iov_wq);
  7633. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7634. BNX2X_F_STATE_STARTED && tout--)
  7635. msleep(20);
  7636. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7637. BNX2X_F_STATE_STARTED) {
  7638. #ifdef BNX2X_STOP_ON_ERROR
  7639. BNX2X_ERR("Wrong function state\n");
  7640. return -EBUSY;
  7641. #else
  7642. /*
  7643. * Failed to complete the transaction in a "good way"
  7644. * Force both transactions with CLR bit
  7645. */
  7646. struct bnx2x_func_state_params func_params = {NULL};
  7647. DP(NETIF_MSG_IFDOWN,
  7648. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7649. func_params.f_obj = &bp->func_obj;
  7650. __set_bit(RAMROD_DRV_CLR_ONLY,
  7651. &func_params.ramrod_flags);
  7652. /* STARTED-->TX_ST0PPED */
  7653. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7654. bnx2x_func_state_change(bp, &func_params);
  7655. /* TX_ST0PPED-->STARTED */
  7656. func_params.cmd = BNX2X_F_CMD_TX_START;
  7657. return bnx2x_func_state_change(bp, &func_params);
  7658. #endif
  7659. }
  7660. return 0;
  7661. }
  7662. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7663. {
  7664. int port = BP_PORT(bp);
  7665. /* Disable sending PTP packets to host */
  7666. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7667. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7668. /* Reset PTP event detection rules */
  7669. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7670. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7671. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7672. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7673. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7674. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7675. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7676. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7677. /* Disable the PTP feature */
  7678. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7679. NIG_REG_P0_PTP_EN, 0x0);
  7680. }
  7681. /* Called during unload, to stop PTP-related stuff */
  7682. void bnx2x_stop_ptp(struct bnx2x *bp)
  7683. {
  7684. /* Cancel PTP work queue. Should be done after the Tx queues are
  7685. * drained to prevent additional scheduling.
  7686. */
  7687. cancel_work_sync(&bp->ptp_task);
  7688. if (bp->ptp_tx_skb) {
  7689. dev_kfree_skb_any(bp->ptp_tx_skb);
  7690. bp->ptp_tx_skb = NULL;
  7691. }
  7692. /* Disable PTP in HW */
  7693. bnx2x_disable_ptp(bp);
  7694. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7695. }
  7696. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7697. {
  7698. int port = BP_PORT(bp);
  7699. int i, rc = 0;
  7700. u8 cos;
  7701. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7702. u32 reset_code;
  7703. /* Wait until tx fastpath tasks complete */
  7704. for_each_tx_queue(bp, i) {
  7705. struct bnx2x_fastpath *fp = &bp->fp[i];
  7706. for_each_cos_in_tx_queue(fp, cos)
  7707. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7708. #ifdef BNX2X_STOP_ON_ERROR
  7709. if (rc)
  7710. return;
  7711. #endif
  7712. }
  7713. /* Give HW time to discard old tx messages */
  7714. usleep_range(1000, 2000);
  7715. /* Clean all ETH MACs */
  7716. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7717. false);
  7718. if (rc < 0)
  7719. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7720. /* Clean up UC list */
  7721. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7722. true);
  7723. if (rc < 0)
  7724. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7725. rc);
  7726. /* Disable LLH */
  7727. if (!CHIP_IS_E1(bp))
  7728. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7729. /* Set "drop all" (stop Rx).
  7730. * We need to take a netif_addr_lock() here in order to prevent
  7731. * a race between the completion code and this code.
  7732. */
  7733. netif_addr_lock_bh(bp->dev);
  7734. /* Schedule the rx_mode command */
  7735. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7736. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7737. else
  7738. bnx2x_set_storm_rx_mode(bp);
  7739. /* Cleanup multicast configuration */
  7740. rparam.mcast_obj = &bp->mcast_obj;
  7741. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7742. if (rc < 0)
  7743. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7744. netif_addr_unlock_bh(bp->dev);
  7745. bnx2x_iov_chip_cleanup(bp);
  7746. /*
  7747. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7748. * this function should perform FUNC, PORT or COMMON HW
  7749. * reset.
  7750. */
  7751. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7752. /*
  7753. * (assumption: No Attention from MCP at this stage)
  7754. * PMF probably in the middle of TX disable/enable transaction
  7755. */
  7756. rc = bnx2x_func_wait_started(bp);
  7757. if (rc) {
  7758. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7759. #ifdef BNX2X_STOP_ON_ERROR
  7760. return;
  7761. #endif
  7762. }
  7763. /* Close multi and leading connections
  7764. * Completions for ramrods are collected in a synchronous way
  7765. */
  7766. for_each_eth_queue(bp, i)
  7767. if (bnx2x_stop_queue(bp, i))
  7768. #ifdef BNX2X_STOP_ON_ERROR
  7769. return;
  7770. #else
  7771. goto unload_error;
  7772. #endif
  7773. if (CNIC_LOADED(bp)) {
  7774. for_each_cnic_queue(bp, i)
  7775. if (bnx2x_stop_queue(bp, i))
  7776. #ifdef BNX2X_STOP_ON_ERROR
  7777. return;
  7778. #else
  7779. goto unload_error;
  7780. #endif
  7781. }
  7782. /* If SP settings didn't get completed so far - something
  7783. * very wrong has happen.
  7784. */
  7785. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7786. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7787. #ifndef BNX2X_STOP_ON_ERROR
  7788. unload_error:
  7789. #endif
  7790. rc = bnx2x_func_stop(bp);
  7791. if (rc) {
  7792. BNX2X_ERR("Function stop failed!\n");
  7793. #ifdef BNX2X_STOP_ON_ERROR
  7794. return;
  7795. #endif
  7796. }
  7797. /* stop_ptp should be after the Tx queues are drained to prevent
  7798. * scheduling to the cancelled PTP work queue. It should also be after
  7799. * function stop ramrod is sent, since as part of this ramrod FW access
  7800. * PTP registers.
  7801. */
  7802. bnx2x_stop_ptp(bp);
  7803. /* Disable HW interrupts, NAPI */
  7804. bnx2x_netif_stop(bp, 1);
  7805. /* Delete all NAPI objects */
  7806. bnx2x_del_all_napi(bp);
  7807. if (CNIC_LOADED(bp))
  7808. bnx2x_del_all_napi_cnic(bp);
  7809. /* Release IRQs */
  7810. bnx2x_free_irq(bp);
  7811. /* Reset the chip */
  7812. rc = bnx2x_reset_hw(bp, reset_code);
  7813. if (rc)
  7814. BNX2X_ERR("HW_RESET failed\n");
  7815. /* Report UNLOAD_DONE to MCP */
  7816. bnx2x_send_unload_done(bp, keep_link);
  7817. }
  7818. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7819. {
  7820. u32 val;
  7821. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7822. if (CHIP_IS_E1(bp)) {
  7823. int port = BP_PORT(bp);
  7824. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7825. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7826. val = REG_RD(bp, addr);
  7827. val &= ~(0x300);
  7828. REG_WR(bp, addr, val);
  7829. } else {
  7830. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7831. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7832. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7833. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7834. }
  7835. }
  7836. /* Close gates #2, #3 and #4: */
  7837. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7838. {
  7839. u32 val;
  7840. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7841. if (!CHIP_IS_E1(bp)) {
  7842. /* #4 */
  7843. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7844. /* #2 */
  7845. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7846. }
  7847. /* #3 */
  7848. if (CHIP_IS_E1x(bp)) {
  7849. /* Prevent interrupts from HC on both ports */
  7850. val = REG_RD(bp, HC_REG_CONFIG_1);
  7851. REG_WR(bp, HC_REG_CONFIG_1,
  7852. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7853. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7854. val = REG_RD(bp, HC_REG_CONFIG_0);
  7855. REG_WR(bp, HC_REG_CONFIG_0,
  7856. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7857. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7858. } else {
  7859. /* Prevent incoming interrupts in IGU */
  7860. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7861. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7862. (!close) ?
  7863. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7864. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7865. }
  7866. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7867. close ? "closing" : "opening");
  7868. mmiowb();
  7869. }
  7870. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7871. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7872. {
  7873. /* Do some magic... */
  7874. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7875. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7876. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7877. }
  7878. /**
  7879. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7880. *
  7881. * @bp: driver handle
  7882. * @magic_val: old value of the `magic' bit.
  7883. */
  7884. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7885. {
  7886. /* Restore the `magic' bit value... */
  7887. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7888. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7889. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7890. }
  7891. /**
  7892. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7893. *
  7894. * @bp: driver handle
  7895. * @magic_val: old value of 'magic' bit.
  7896. *
  7897. * Takes care of CLP configurations.
  7898. */
  7899. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7900. {
  7901. u32 shmem;
  7902. u32 validity_offset;
  7903. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7904. /* Set `magic' bit in order to save MF config */
  7905. if (!CHIP_IS_E1(bp))
  7906. bnx2x_clp_reset_prep(bp, magic_val);
  7907. /* Get shmem offset */
  7908. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7909. validity_offset =
  7910. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7911. /* Clear validity map flags */
  7912. if (shmem > 0)
  7913. REG_WR(bp, shmem + validity_offset, 0);
  7914. }
  7915. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7916. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7917. /**
  7918. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7919. *
  7920. * @bp: driver handle
  7921. */
  7922. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7923. {
  7924. /* special handling for emulation and FPGA,
  7925. wait 10 times longer */
  7926. if (CHIP_REV_IS_SLOW(bp))
  7927. msleep(MCP_ONE_TIMEOUT*10);
  7928. else
  7929. msleep(MCP_ONE_TIMEOUT);
  7930. }
  7931. /*
  7932. * initializes bp->common.shmem_base and waits for validity signature to appear
  7933. */
  7934. static int bnx2x_init_shmem(struct bnx2x *bp)
  7935. {
  7936. int cnt = 0;
  7937. u32 val = 0;
  7938. do {
  7939. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7940. if (bp->common.shmem_base) {
  7941. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7942. if (val & SHR_MEM_VALIDITY_MB)
  7943. return 0;
  7944. }
  7945. bnx2x_mcp_wait_one(bp);
  7946. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7947. BNX2X_ERR("BAD MCP validity signature\n");
  7948. return -ENODEV;
  7949. }
  7950. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7951. {
  7952. int rc = bnx2x_init_shmem(bp);
  7953. /* Restore the `magic' bit value */
  7954. if (!CHIP_IS_E1(bp))
  7955. bnx2x_clp_reset_done(bp, magic_val);
  7956. return rc;
  7957. }
  7958. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7959. {
  7960. if (!CHIP_IS_E1(bp)) {
  7961. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7962. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7963. mmiowb();
  7964. }
  7965. }
  7966. /*
  7967. * Reset the whole chip except for:
  7968. * - PCIE core
  7969. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7970. * one reset bit)
  7971. * - IGU
  7972. * - MISC (including AEU)
  7973. * - GRC
  7974. * - RBCN, RBCP
  7975. */
  7976. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7977. {
  7978. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7979. u32 global_bits2, stay_reset2;
  7980. /*
  7981. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7982. * (per chip) blocks.
  7983. */
  7984. global_bits2 =
  7985. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7986. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7987. /* Don't reset the following blocks.
  7988. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7989. * reset, as in 4 port device they might still be owned
  7990. * by the MCP (there is only one leader per path).
  7991. */
  7992. not_reset_mask1 =
  7993. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7994. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7995. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7996. not_reset_mask2 =
  7997. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7998. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7999. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8000. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8001. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8002. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8003. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8004. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8005. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8006. MISC_REGISTERS_RESET_REG_2_PGLC |
  8007. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8008. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8009. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8010. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8011. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8012. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8013. /*
  8014. * Keep the following blocks in reset:
  8015. * - all xxMACs are handled by the bnx2x_link code.
  8016. */
  8017. stay_reset2 =
  8018. MISC_REGISTERS_RESET_REG_2_XMAC |
  8019. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8020. /* Full reset masks according to the chip */
  8021. reset_mask1 = 0xffffffff;
  8022. if (CHIP_IS_E1(bp))
  8023. reset_mask2 = 0xffff;
  8024. else if (CHIP_IS_E1H(bp))
  8025. reset_mask2 = 0x1ffff;
  8026. else if (CHIP_IS_E2(bp))
  8027. reset_mask2 = 0xfffff;
  8028. else /* CHIP_IS_E3 */
  8029. reset_mask2 = 0x3ffffff;
  8030. /* Don't reset global blocks unless we need to */
  8031. if (!global)
  8032. reset_mask2 &= ~global_bits2;
  8033. /*
  8034. * In case of attention in the QM, we need to reset PXP
  8035. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8036. * because otherwise QM reset would release 'close the gates' shortly
  8037. * before resetting the PXP, then the PSWRQ would send a write
  8038. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8039. * read the payload data from PSWWR, but PSWWR would not
  8040. * respond. The write queue in PGLUE would stuck, dmae commands
  8041. * would not return. Therefore it's important to reset the second
  8042. * reset register (containing the
  8043. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8044. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8045. * bit).
  8046. */
  8047. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8048. reset_mask2 & (~not_reset_mask2));
  8049. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8050. reset_mask1 & (~not_reset_mask1));
  8051. barrier();
  8052. mmiowb();
  8053. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8054. reset_mask2 & (~stay_reset2));
  8055. barrier();
  8056. mmiowb();
  8057. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8058. mmiowb();
  8059. }
  8060. /**
  8061. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8062. * It should get cleared in no more than 1s.
  8063. *
  8064. * @bp: driver handle
  8065. *
  8066. * It should get cleared in no more than 1s. Returns 0 if
  8067. * pending writes bit gets cleared.
  8068. */
  8069. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8070. {
  8071. u32 cnt = 1000;
  8072. u32 pend_bits = 0;
  8073. do {
  8074. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8075. if (pend_bits == 0)
  8076. break;
  8077. usleep_range(1000, 2000);
  8078. } while (cnt-- > 0);
  8079. if (cnt <= 0) {
  8080. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8081. pend_bits);
  8082. return -EBUSY;
  8083. }
  8084. return 0;
  8085. }
  8086. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8087. {
  8088. int cnt = 1000;
  8089. u32 val = 0;
  8090. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8091. u32 tags_63_32 = 0;
  8092. /* Empty the Tetris buffer, wait for 1s */
  8093. do {
  8094. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8095. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8096. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8097. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8098. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8099. if (CHIP_IS_E3(bp))
  8100. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8101. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8102. ((port_is_idle_0 & 0x1) == 0x1) &&
  8103. ((port_is_idle_1 & 0x1) == 0x1) &&
  8104. (pgl_exp_rom2 == 0xffffffff) &&
  8105. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8106. break;
  8107. usleep_range(1000, 2000);
  8108. } while (cnt-- > 0);
  8109. if (cnt <= 0) {
  8110. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8111. 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",
  8112. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8113. pgl_exp_rom2);
  8114. return -EAGAIN;
  8115. }
  8116. barrier();
  8117. /* Close gates #2, #3 and #4 */
  8118. bnx2x_set_234_gates(bp, true);
  8119. /* Poll for IGU VQs for 57712 and newer chips */
  8120. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8121. return -EAGAIN;
  8122. /* TBD: Indicate that "process kill" is in progress to MCP */
  8123. /* Clear "unprepared" bit */
  8124. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8125. barrier();
  8126. /* Make sure all is written to the chip before the reset */
  8127. mmiowb();
  8128. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8129. * PSWHST, GRC and PSWRD Tetris buffer.
  8130. */
  8131. usleep_range(1000, 2000);
  8132. /* Prepare to chip reset: */
  8133. /* MCP */
  8134. if (global)
  8135. bnx2x_reset_mcp_prep(bp, &val);
  8136. /* PXP */
  8137. bnx2x_pxp_prep(bp);
  8138. barrier();
  8139. /* reset the chip */
  8140. bnx2x_process_kill_chip_reset(bp, global);
  8141. barrier();
  8142. /* clear errors in PGB */
  8143. if (!CHIP_IS_E1x(bp))
  8144. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8145. /* Recover after reset: */
  8146. /* MCP */
  8147. if (global && bnx2x_reset_mcp_comp(bp, val))
  8148. return -EAGAIN;
  8149. /* TBD: Add resetting the NO_MCP mode DB here */
  8150. /* Open the gates #2, #3 and #4 */
  8151. bnx2x_set_234_gates(bp, false);
  8152. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8153. * reset state, re-enable attentions. */
  8154. return 0;
  8155. }
  8156. static int bnx2x_leader_reset(struct bnx2x *bp)
  8157. {
  8158. int rc = 0;
  8159. bool global = bnx2x_reset_is_global(bp);
  8160. u32 load_code;
  8161. /* if not going to reset MCP - load "fake" driver to reset HW while
  8162. * driver is owner of the HW
  8163. */
  8164. if (!global && !BP_NOMCP(bp)) {
  8165. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8166. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8167. if (!load_code) {
  8168. BNX2X_ERR("MCP response failure, aborting\n");
  8169. rc = -EAGAIN;
  8170. goto exit_leader_reset;
  8171. }
  8172. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8173. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8174. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8175. rc = -EAGAIN;
  8176. goto exit_leader_reset2;
  8177. }
  8178. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8179. if (!load_code) {
  8180. BNX2X_ERR("MCP response failure, aborting\n");
  8181. rc = -EAGAIN;
  8182. goto exit_leader_reset2;
  8183. }
  8184. }
  8185. /* Try to recover after the failure */
  8186. if (bnx2x_process_kill(bp, global)) {
  8187. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8188. BP_PATH(bp));
  8189. rc = -EAGAIN;
  8190. goto exit_leader_reset2;
  8191. }
  8192. /*
  8193. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8194. * state.
  8195. */
  8196. bnx2x_set_reset_done(bp);
  8197. if (global)
  8198. bnx2x_clear_reset_global(bp);
  8199. exit_leader_reset2:
  8200. /* unload "fake driver" if it was loaded */
  8201. if (!global && !BP_NOMCP(bp)) {
  8202. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8203. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8204. }
  8205. exit_leader_reset:
  8206. bp->is_leader = 0;
  8207. bnx2x_release_leader_lock(bp);
  8208. smp_mb();
  8209. return rc;
  8210. }
  8211. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8212. {
  8213. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8214. /* Disconnect this device */
  8215. netif_device_detach(bp->dev);
  8216. /*
  8217. * Block ifup for all function on this engine until "process kill"
  8218. * or power cycle.
  8219. */
  8220. bnx2x_set_reset_in_progress(bp);
  8221. /* Shut down the power */
  8222. bnx2x_set_power_state(bp, PCI_D3hot);
  8223. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8224. smp_mb();
  8225. }
  8226. /*
  8227. * Assumption: runs under rtnl lock. This together with the fact
  8228. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8229. * will never be called when netif_running(bp->dev) is false.
  8230. */
  8231. static void bnx2x_parity_recover(struct bnx2x *bp)
  8232. {
  8233. bool global = false;
  8234. u32 error_recovered, error_unrecovered;
  8235. bool is_parity;
  8236. DP(NETIF_MSG_HW, "Handling parity\n");
  8237. while (1) {
  8238. switch (bp->recovery_state) {
  8239. case BNX2X_RECOVERY_INIT:
  8240. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8241. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8242. WARN_ON(!is_parity);
  8243. /* Try to get a LEADER_LOCK HW lock */
  8244. if (bnx2x_trylock_leader_lock(bp)) {
  8245. bnx2x_set_reset_in_progress(bp);
  8246. /*
  8247. * Check if there is a global attention and if
  8248. * there was a global attention, set the global
  8249. * reset bit.
  8250. */
  8251. if (global)
  8252. bnx2x_set_reset_global(bp);
  8253. bp->is_leader = 1;
  8254. }
  8255. /* Stop the driver */
  8256. /* If interface has been removed - break */
  8257. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8258. return;
  8259. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8260. /* Ensure "is_leader", MCP command sequence and
  8261. * "recovery_state" update values are seen on other
  8262. * CPUs.
  8263. */
  8264. smp_mb();
  8265. break;
  8266. case BNX2X_RECOVERY_WAIT:
  8267. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8268. if (bp->is_leader) {
  8269. int other_engine = BP_PATH(bp) ? 0 : 1;
  8270. bool other_load_status =
  8271. bnx2x_get_load_status(bp, other_engine);
  8272. bool load_status =
  8273. bnx2x_get_load_status(bp, BP_PATH(bp));
  8274. global = bnx2x_reset_is_global(bp);
  8275. /*
  8276. * In case of a parity in a global block, let
  8277. * the first leader that performs a
  8278. * leader_reset() reset the global blocks in
  8279. * order to clear global attentions. Otherwise
  8280. * the gates will remain closed for that
  8281. * engine.
  8282. */
  8283. if (load_status ||
  8284. (global && other_load_status)) {
  8285. /* Wait until all other functions get
  8286. * down.
  8287. */
  8288. schedule_delayed_work(&bp->sp_rtnl_task,
  8289. HZ/10);
  8290. return;
  8291. } else {
  8292. /* If all other functions got down -
  8293. * try to bring the chip back to
  8294. * normal. In any case it's an exit
  8295. * point for a leader.
  8296. */
  8297. if (bnx2x_leader_reset(bp)) {
  8298. bnx2x_recovery_failed(bp);
  8299. return;
  8300. }
  8301. /* If we are here, means that the
  8302. * leader has succeeded and doesn't
  8303. * want to be a leader any more. Try
  8304. * to continue as a none-leader.
  8305. */
  8306. break;
  8307. }
  8308. } else { /* non-leader */
  8309. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8310. /* Try to get a LEADER_LOCK HW lock as
  8311. * long as a former leader may have
  8312. * been unloaded by the user or
  8313. * released a leadership by another
  8314. * reason.
  8315. */
  8316. if (bnx2x_trylock_leader_lock(bp)) {
  8317. /* I'm a leader now! Restart a
  8318. * switch case.
  8319. */
  8320. bp->is_leader = 1;
  8321. break;
  8322. }
  8323. schedule_delayed_work(&bp->sp_rtnl_task,
  8324. HZ/10);
  8325. return;
  8326. } else {
  8327. /*
  8328. * If there was a global attention, wait
  8329. * for it to be cleared.
  8330. */
  8331. if (bnx2x_reset_is_global(bp)) {
  8332. schedule_delayed_work(
  8333. &bp->sp_rtnl_task,
  8334. HZ/10);
  8335. return;
  8336. }
  8337. error_recovered =
  8338. bp->eth_stats.recoverable_error;
  8339. error_unrecovered =
  8340. bp->eth_stats.unrecoverable_error;
  8341. bp->recovery_state =
  8342. BNX2X_RECOVERY_NIC_LOADING;
  8343. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8344. error_unrecovered++;
  8345. netdev_err(bp->dev,
  8346. "Recovery failed. Power cycle needed\n");
  8347. /* Disconnect this device */
  8348. netif_device_detach(bp->dev);
  8349. /* Shut down the power */
  8350. bnx2x_set_power_state(
  8351. bp, PCI_D3hot);
  8352. smp_mb();
  8353. } else {
  8354. bp->recovery_state =
  8355. BNX2X_RECOVERY_DONE;
  8356. error_recovered++;
  8357. smp_mb();
  8358. }
  8359. bp->eth_stats.recoverable_error =
  8360. error_recovered;
  8361. bp->eth_stats.unrecoverable_error =
  8362. error_unrecovered;
  8363. return;
  8364. }
  8365. }
  8366. default:
  8367. return;
  8368. }
  8369. }
  8370. }
  8371. static int bnx2x_close(struct net_device *dev);
  8372. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8373. * scheduled on a general queue in order to prevent a dead lock.
  8374. */
  8375. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8376. {
  8377. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8378. rtnl_lock();
  8379. if (!netif_running(bp->dev)) {
  8380. rtnl_unlock();
  8381. return;
  8382. }
  8383. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8384. #ifdef BNX2X_STOP_ON_ERROR
  8385. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8386. "you will need to reboot when done\n");
  8387. goto sp_rtnl_not_reset;
  8388. #endif
  8389. /*
  8390. * Clear all pending SP commands as we are going to reset the
  8391. * function anyway.
  8392. */
  8393. bp->sp_rtnl_state = 0;
  8394. smp_mb();
  8395. bnx2x_parity_recover(bp);
  8396. rtnl_unlock();
  8397. return;
  8398. }
  8399. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8400. #ifdef BNX2X_STOP_ON_ERROR
  8401. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8402. "you will need to reboot when done\n");
  8403. goto sp_rtnl_not_reset;
  8404. #endif
  8405. /*
  8406. * Clear all pending SP commands as we are going to reset the
  8407. * function anyway.
  8408. */
  8409. bp->sp_rtnl_state = 0;
  8410. smp_mb();
  8411. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8412. bnx2x_nic_load(bp, LOAD_NORMAL);
  8413. rtnl_unlock();
  8414. return;
  8415. }
  8416. #ifdef BNX2X_STOP_ON_ERROR
  8417. sp_rtnl_not_reset:
  8418. #endif
  8419. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8420. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8421. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8422. bnx2x_after_function_update(bp);
  8423. /*
  8424. * in case of fan failure we need to reset id if the "stop on error"
  8425. * debug flag is set, since we trying to prevent permanent overheating
  8426. * damage
  8427. */
  8428. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8429. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8430. netif_device_detach(bp->dev);
  8431. bnx2x_close(bp->dev);
  8432. rtnl_unlock();
  8433. return;
  8434. }
  8435. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8436. DP(BNX2X_MSG_SP,
  8437. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8438. bnx2x_vfpf_set_mcast(bp->dev);
  8439. }
  8440. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8441. &bp->sp_rtnl_state)){
  8442. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8443. bnx2x_tx_disable(bp);
  8444. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8445. }
  8446. }
  8447. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8448. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8449. bnx2x_set_rx_mode_inner(bp);
  8450. }
  8451. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8452. &bp->sp_rtnl_state))
  8453. bnx2x_pf_set_vfs_vlan(bp);
  8454. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8455. bnx2x_dcbx_stop_hw_tx(bp);
  8456. bnx2x_dcbx_resume_hw_tx(bp);
  8457. }
  8458. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8459. &bp->sp_rtnl_state))
  8460. bnx2x_update_mng_version(bp);
  8461. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8462. * can be called from other contexts as well)
  8463. */
  8464. rtnl_unlock();
  8465. /* enable SR-IOV if applicable */
  8466. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8467. &bp->sp_rtnl_state)) {
  8468. bnx2x_disable_sriov(bp);
  8469. bnx2x_enable_sriov(bp);
  8470. }
  8471. }
  8472. static void bnx2x_period_task(struct work_struct *work)
  8473. {
  8474. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8475. if (!netif_running(bp->dev))
  8476. goto period_task_exit;
  8477. if (CHIP_REV_IS_SLOW(bp)) {
  8478. BNX2X_ERR("period task called on emulation, ignoring\n");
  8479. goto period_task_exit;
  8480. }
  8481. bnx2x_acquire_phy_lock(bp);
  8482. /*
  8483. * The barrier is needed to ensure the ordering between the writing to
  8484. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8485. * the reading here.
  8486. */
  8487. smp_mb();
  8488. if (bp->port.pmf) {
  8489. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8490. /* Re-queue task in 1 sec */
  8491. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8492. }
  8493. bnx2x_release_phy_lock(bp);
  8494. period_task_exit:
  8495. return;
  8496. }
  8497. /*
  8498. * Init service functions
  8499. */
  8500. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8501. {
  8502. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8503. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8504. return base + (BP_ABS_FUNC(bp)) * stride;
  8505. }
  8506. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8507. struct bnx2x_mac_vals *vals)
  8508. {
  8509. u32 val, base_addr, offset, mask, reset_reg;
  8510. bool mac_stopped = false;
  8511. u8 port = BP_PORT(bp);
  8512. /* reset addresses as they also mark which values were changed */
  8513. vals->bmac_addr = 0;
  8514. vals->umac_addr = 0;
  8515. vals->xmac_addr = 0;
  8516. vals->emac_addr = 0;
  8517. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8518. if (!CHIP_IS_E3(bp)) {
  8519. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8520. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8521. if ((mask & reset_reg) && val) {
  8522. u32 wb_data[2];
  8523. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8524. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8525. : NIG_REG_INGRESS_BMAC0_MEM;
  8526. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8527. : BIGMAC_REGISTER_BMAC_CONTROL;
  8528. /*
  8529. * use rd/wr since we cannot use dmae. This is safe
  8530. * since MCP won't access the bus due to the request
  8531. * to unload, and no function on the path can be
  8532. * loaded at this time.
  8533. */
  8534. wb_data[0] = REG_RD(bp, base_addr + offset);
  8535. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8536. vals->bmac_addr = base_addr + offset;
  8537. vals->bmac_val[0] = wb_data[0];
  8538. vals->bmac_val[1] = wb_data[1];
  8539. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8540. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8541. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8542. }
  8543. BNX2X_DEV_INFO("Disable emac Rx\n");
  8544. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8545. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8546. REG_WR(bp, vals->emac_addr, 0);
  8547. mac_stopped = true;
  8548. } else {
  8549. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8550. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8551. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8552. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8553. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8554. val & ~(1 << 1));
  8555. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8556. val | (1 << 1));
  8557. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8558. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8559. REG_WR(bp, vals->xmac_addr, 0);
  8560. mac_stopped = true;
  8561. }
  8562. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8563. if (mask & reset_reg) {
  8564. BNX2X_DEV_INFO("Disable umac Rx\n");
  8565. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8566. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8567. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8568. REG_WR(bp, vals->umac_addr, 0);
  8569. mac_stopped = true;
  8570. }
  8571. }
  8572. if (mac_stopped)
  8573. msleep(20);
  8574. }
  8575. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8576. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8577. 0x1848 + ((f) << 4))
  8578. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8579. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8580. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8581. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8582. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8583. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8584. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8585. {
  8586. /* UNDI marks its presence in DORQ -
  8587. * it initializes CID offset for normal bell to 0x7
  8588. */
  8589. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8590. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8591. return false;
  8592. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8593. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8594. return true;
  8595. }
  8596. return false;
  8597. }
  8598. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8599. {
  8600. u16 rcq, bd;
  8601. u32 addr, tmp_reg;
  8602. if (BP_FUNC(bp) < 2)
  8603. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8604. else
  8605. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8606. tmp_reg = REG_RD(bp, addr);
  8607. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8608. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8609. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8610. REG_WR(bp, addr, tmp_reg);
  8611. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8612. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8613. }
  8614. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8615. {
  8616. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8617. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8618. if (!rc) {
  8619. BNX2X_ERR("MCP response failure, aborting\n");
  8620. return -EBUSY;
  8621. }
  8622. return 0;
  8623. }
  8624. static struct bnx2x_prev_path_list *
  8625. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8626. {
  8627. struct bnx2x_prev_path_list *tmp_list;
  8628. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8629. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8630. bp->pdev->bus->number == tmp_list->bus &&
  8631. BP_PATH(bp) == tmp_list->path)
  8632. return tmp_list;
  8633. return NULL;
  8634. }
  8635. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8636. {
  8637. struct bnx2x_prev_path_list *tmp_list;
  8638. int rc;
  8639. rc = down_interruptible(&bnx2x_prev_sem);
  8640. if (rc) {
  8641. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8642. return rc;
  8643. }
  8644. tmp_list = bnx2x_prev_path_get_entry(bp);
  8645. if (tmp_list) {
  8646. tmp_list->aer = 1;
  8647. rc = 0;
  8648. } else {
  8649. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8650. BP_PATH(bp));
  8651. }
  8652. up(&bnx2x_prev_sem);
  8653. return rc;
  8654. }
  8655. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8656. {
  8657. struct bnx2x_prev_path_list *tmp_list;
  8658. bool rc = false;
  8659. if (down_trylock(&bnx2x_prev_sem))
  8660. return false;
  8661. tmp_list = bnx2x_prev_path_get_entry(bp);
  8662. if (tmp_list) {
  8663. if (tmp_list->aer) {
  8664. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8665. BP_PATH(bp));
  8666. } else {
  8667. rc = true;
  8668. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8669. BP_PATH(bp));
  8670. }
  8671. }
  8672. up(&bnx2x_prev_sem);
  8673. return rc;
  8674. }
  8675. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8676. {
  8677. struct bnx2x_prev_path_list *entry;
  8678. bool val;
  8679. down(&bnx2x_prev_sem);
  8680. entry = bnx2x_prev_path_get_entry(bp);
  8681. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8682. up(&bnx2x_prev_sem);
  8683. return val;
  8684. }
  8685. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8686. {
  8687. struct bnx2x_prev_path_list *tmp_list;
  8688. int rc;
  8689. rc = down_interruptible(&bnx2x_prev_sem);
  8690. if (rc) {
  8691. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8692. return rc;
  8693. }
  8694. /* Check whether the entry for this path already exists */
  8695. tmp_list = bnx2x_prev_path_get_entry(bp);
  8696. if (tmp_list) {
  8697. if (!tmp_list->aer) {
  8698. BNX2X_ERR("Re-Marking the path.\n");
  8699. } else {
  8700. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8701. BP_PATH(bp));
  8702. tmp_list->aer = 0;
  8703. }
  8704. up(&bnx2x_prev_sem);
  8705. return 0;
  8706. }
  8707. up(&bnx2x_prev_sem);
  8708. /* Create an entry for this path and add it */
  8709. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8710. if (!tmp_list) {
  8711. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8712. return -ENOMEM;
  8713. }
  8714. tmp_list->bus = bp->pdev->bus->number;
  8715. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8716. tmp_list->path = BP_PATH(bp);
  8717. tmp_list->aer = 0;
  8718. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8719. rc = down_interruptible(&bnx2x_prev_sem);
  8720. if (rc) {
  8721. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8722. kfree(tmp_list);
  8723. } else {
  8724. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8725. BP_PATH(bp));
  8726. list_add(&tmp_list->list, &bnx2x_prev_list);
  8727. up(&bnx2x_prev_sem);
  8728. }
  8729. return rc;
  8730. }
  8731. static int bnx2x_do_flr(struct bnx2x *bp)
  8732. {
  8733. struct pci_dev *dev = bp->pdev;
  8734. if (CHIP_IS_E1x(bp)) {
  8735. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8736. return -EINVAL;
  8737. }
  8738. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8739. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8740. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8741. bp->common.bc_ver);
  8742. return -EINVAL;
  8743. }
  8744. if (!pci_wait_for_pending_transaction(dev))
  8745. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8746. BNX2X_DEV_INFO("Initiating FLR\n");
  8747. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8748. return 0;
  8749. }
  8750. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8751. {
  8752. int rc;
  8753. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8754. /* Test if previous unload process was already finished for this path */
  8755. if (bnx2x_prev_is_path_marked(bp))
  8756. return bnx2x_prev_mcp_done(bp);
  8757. BNX2X_DEV_INFO("Path is unmarked\n");
  8758. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8759. if (bnx2x_prev_is_after_undi(bp))
  8760. goto out;
  8761. /* If function has FLR capabilities, and existing FW version matches
  8762. * the one required, then FLR will be sufficient to clean any residue
  8763. * left by previous driver
  8764. */
  8765. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8766. if (!rc) {
  8767. /* fw version is good */
  8768. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8769. rc = bnx2x_do_flr(bp);
  8770. }
  8771. if (!rc) {
  8772. /* FLR was performed */
  8773. BNX2X_DEV_INFO("FLR successful\n");
  8774. return 0;
  8775. }
  8776. BNX2X_DEV_INFO("Could not FLR\n");
  8777. out:
  8778. /* Close the MCP request, return failure*/
  8779. rc = bnx2x_prev_mcp_done(bp);
  8780. if (!rc)
  8781. rc = BNX2X_PREV_WAIT_NEEDED;
  8782. return rc;
  8783. }
  8784. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8785. {
  8786. u32 reset_reg, tmp_reg = 0, rc;
  8787. bool prev_undi = false;
  8788. struct bnx2x_mac_vals mac_vals;
  8789. /* It is possible a previous function received 'common' answer,
  8790. * but hasn't loaded yet, therefore creating a scenario of
  8791. * multiple functions receiving 'common' on the same path.
  8792. */
  8793. BNX2X_DEV_INFO("Common unload Flow\n");
  8794. memset(&mac_vals, 0, sizeof(mac_vals));
  8795. if (bnx2x_prev_is_path_marked(bp))
  8796. return bnx2x_prev_mcp_done(bp);
  8797. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8798. /* Reset should be performed after BRB is emptied */
  8799. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8800. u32 timer_count = 1000;
  8801. /* Close the MAC Rx to prevent BRB from filling up */
  8802. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8803. /* close LLH filters towards the BRB */
  8804. bnx2x_set_rx_filter(&bp->link_params, 0);
  8805. /* Check if the UNDI driver was previously loaded */
  8806. if (bnx2x_prev_is_after_undi(bp)) {
  8807. prev_undi = true;
  8808. /* clear the UNDI indication */
  8809. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8810. /* clear possible idle check errors */
  8811. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8812. }
  8813. if (!CHIP_IS_E1x(bp))
  8814. /* block FW from writing to host */
  8815. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8816. /* wait until BRB is empty */
  8817. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8818. while (timer_count) {
  8819. u32 prev_brb = tmp_reg;
  8820. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8821. if (!tmp_reg)
  8822. break;
  8823. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8824. /* reset timer as long as BRB actually gets emptied */
  8825. if (prev_brb > tmp_reg)
  8826. timer_count = 1000;
  8827. else
  8828. timer_count--;
  8829. /* If UNDI resides in memory, manually increment it */
  8830. if (prev_undi)
  8831. bnx2x_prev_unload_undi_inc(bp, 1);
  8832. udelay(10);
  8833. }
  8834. if (!timer_count)
  8835. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8836. }
  8837. /* No packets are in the pipeline, path is ready for reset */
  8838. bnx2x_reset_common(bp);
  8839. if (mac_vals.xmac_addr)
  8840. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8841. if (mac_vals.umac_addr)
  8842. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8843. if (mac_vals.emac_addr)
  8844. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8845. if (mac_vals.bmac_addr) {
  8846. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8847. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8848. }
  8849. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8850. if (rc) {
  8851. bnx2x_prev_mcp_done(bp);
  8852. return rc;
  8853. }
  8854. return bnx2x_prev_mcp_done(bp);
  8855. }
  8856. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8857. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8858. * the addresses of the transaction, resulting in was-error bit set in the pci
  8859. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8860. * to clear the interrupt which detected this from the pglueb and the was done
  8861. * bit
  8862. */
  8863. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8864. {
  8865. if (!CHIP_IS_E1x(bp)) {
  8866. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8867. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8868. DP(BNX2X_MSG_SP,
  8869. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8870. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8871. 1 << BP_FUNC(bp));
  8872. }
  8873. }
  8874. }
  8875. static int bnx2x_prev_unload(struct bnx2x *bp)
  8876. {
  8877. int time_counter = 10;
  8878. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8879. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8880. /* clear hw from errors which may have resulted from an interrupted
  8881. * dmae transaction.
  8882. */
  8883. bnx2x_prev_interrupted_dmae(bp);
  8884. /* Release previously held locks */
  8885. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8886. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8887. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8888. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8889. if (hw_lock_val) {
  8890. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8891. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8892. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8893. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8894. }
  8895. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8896. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8897. } else
  8898. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8899. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8900. BNX2X_DEV_INFO("Release previously held alr\n");
  8901. bnx2x_release_alr(bp);
  8902. }
  8903. do {
  8904. int aer = 0;
  8905. /* Lock MCP using an unload request */
  8906. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8907. if (!fw) {
  8908. BNX2X_ERR("MCP response failure, aborting\n");
  8909. rc = -EBUSY;
  8910. break;
  8911. }
  8912. rc = down_interruptible(&bnx2x_prev_sem);
  8913. if (rc) {
  8914. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8915. rc);
  8916. } else {
  8917. /* If Path is marked by EEH, ignore unload status */
  8918. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8919. bnx2x_prev_path_get_entry(bp)->aer);
  8920. up(&bnx2x_prev_sem);
  8921. }
  8922. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8923. rc = bnx2x_prev_unload_common(bp);
  8924. break;
  8925. }
  8926. /* non-common reply from MCP might require looping */
  8927. rc = bnx2x_prev_unload_uncommon(bp);
  8928. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8929. break;
  8930. msleep(20);
  8931. } while (--time_counter);
  8932. if (!time_counter || rc) {
  8933. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8934. rc = -EPROBE_DEFER;
  8935. }
  8936. /* Mark function if its port was used to boot from SAN */
  8937. if (bnx2x_port_after_undi(bp))
  8938. bp->link_params.feature_config_flags |=
  8939. FEATURE_CONFIG_BOOT_FROM_SAN;
  8940. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8941. return rc;
  8942. }
  8943. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8944. {
  8945. u32 val, val2, val3, val4, id, boot_mode;
  8946. u16 pmc;
  8947. /* Get the chip revision id and number. */
  8948. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8949. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8950. id = ((val & 0xffff) << 16);
  8951. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8952. id |= ((val & 0xf) << 12);
  8953. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8954. * the configuration space (so we need to reg_rd)
  8955. */
  8956. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8957. id |= (((val >> 24) & 0xf) << 4);
  8958. val = REG_RD(bp, MISC_REG_BOND_ID);
  8959. id |= (val & 0xf);
  8960. bp->common.chip_id = id;
  8961. /* force 57811 according to MISC register */
  8962. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8963. if (CHIP_IS_57810(bp))
  8964. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8965. (bp->common.chip_id & 0x0000FFFF);
  8966. else if (CHIP_IS_57810_MF(bp))
  8967. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8968. (bp->common.chip_id & 0x0000FFFF);
  8969. bp->common.chip_id |= 0x1;
  8970. }
  8971. /* Set doorbell size */
  8972. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8973. if (!CHIP_IS_E1x(bp)) {
  8974. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8975. if ((val & 1) == 0)
  8976. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8977. else
  8978. val = (val >> 1) & 1;
  8979. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8980. "2_PORT_MODE");
  8981. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8982. CHIP_2_PORT_MODE;
  8983. if (CHIP_MODE_IS_4_PORT(bp))
  8984. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8985. else
  8986. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8987. } else {
  8988. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8989. bp->pfid = bp->pf_num; /* 0..7 */
  8990. }
  8991. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8992. bp->link_params.chip_id = bp->common.chip_id;
  8993. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8994. val = (REG_RD(bp, 0x2874) & 0x55);
  8995. if ((bp->common.chip_id & 0x1) ||
  8996. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8997. bp->flags |= ONE_PORT_FLAG;
  8998. BNX2X_DEV_INFO("single port device\n");
  8999. }
  9000. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9001. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9002. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9003. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9004. bp->common.flash_size, bp->common.flash_size);
  9005. bnx2x_init_shmem(bp);
  9006. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9007. MISC_REG_GENERIC_CR_1 :
  9008. MISC_REG_GENERIC_CR_0));
  9009. bp->link_params.shmem_base = bp->common.shmem_base;
  9010. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9011. if (SHMEM2_RD(bp, size) >
  9012. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9013. bp->link_params.lfa_base =
  9014. REG_RD(bp, bp->common.shmem2_base +
  9015. (u32)offsetof(struct shmem2_region,
  9016. lfa_host_addr[BP_PORT(bp)]));
  9017. else
  9018. bp->link_params.lfa_base = 0;
  9019. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9020. bp->common.shmem_base, bp->common.shmem2_base);
  9021. if (!bp->common.shmem_base) {
  9022. BNX2X_DEV_INFO("MCP not active\n");
  9023. bp->flags |= NO_MCP_FLAG;
  9024. return;
  9025. }
  9026. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9027. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9028. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9029. SHARED_HW_CFG_LED_MODE_MASK) >>
  9030. SHARED_HW_CFG_LED_MODE_SHIFT);
  9031. bp->link_params.feature_config_flags = 0;
  9032. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9033. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9034. bp->link_params.feature_config_flags |=
  9035. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9036. else
  9037. bp->link_params.feature_config_flags &=
  9038. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9039. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9040. bp->common.bc_ver = val;
  9041. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9042. if (val < BNX2X_BC_VER) {
  9043. /* for now only warn
  9044. * later we might need to enforce this */
  9045. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9046. BNX2X_BC_VER, val);
  9047. }
  9048. bp->link_params.feature_config_flags |=
  9049. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9050. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9051. bp->link_params.feature_config_flags |=
  9052. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9053. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9054. bp->link_params.feature_config_flags |=
  9055. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9056. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9057. bp->link_params.feature_config_flags |=
  9058. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9059. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9060. bp->link_params.feature_config_flags |=
  9061. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9062. FEATURE_CONFIG_MT_SUPPORT : 0;
  9063. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9064. BC_SUPPORTS_PFC_STATS : 0;
  9065. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9066. BC_SUPPORTS_FCOE_FEATURES : 0;
  9067. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9068. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9069. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9070. BC_SUPPORTS_RMMOD_CMD : 0;
  9071. boot_mode = SHMEM_RD(bp,
  9072. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9073. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9074. switch (boot_mode) {
  9075. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9076. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9077. break;
  9078. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9079. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9080. break;
  9081. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9082. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9083. break;
  9084. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9085. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9086. break;
  9087. }
  9088. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9089. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9090. BNX2X_DEV_INFO("%sWoL capable\n",
  9091. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9092. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9093. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9094. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9095. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9096. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9097. val, val2, val3, val4);
  9098. }
  9099. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9100. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9101. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9102. {
  9103. int pfid = BP_FUNC(bp);
  9104. int igu_sb_id;
  9105. u32 val;
  9106. u8 fid, igu_sb_cnt = 0;
  9107. bp->igu_base_sb = 0xff;
  9108. if (CHIP_INT_MODE_IS_BC(bp)) {
  9109. int vn = BP_VN(bp);
  9110. igu_sb_cnt = bp->igu_sb_cnt;
  9111. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9112. FP_SB_MAX_E1x;
  9113. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9114. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9115. return 0;
  9116. }
  9117. /* IGU in normal mode - read CAM */
  9118. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9119. igu_sb_id++) {
  9120. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9121. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9122. continue;
  9123. fid = IGU_FID(val);
  9124. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9125. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9126. continue;
  9127. if (IGU_VEC(val) == 0)
  9128. /* default status block */
  9129. bp->igu_dsb_id = igu_sb_id;
  9130. else {
  9131. if (bp->igu_base_sb == 0xff)
  9132. bp->igu_base_sb = igu_sb_id;
  9133. igu_sb_cnt++;
  9134. }
  9135. }
  9136. }
  9137. #ifdef CONFIG_PCI_MSI
  9138. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9139. * optional that number of CAM entries will not be equal to the value
  9140. * advertised in PCI.
  9141. * Driver should use the minimal value of both as the actual status
  9142. * block count
  9143. */
  9144. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9145. #endif
  9146. if (igu_sb_cnt == 0) {
  9147. BNX2X_ERR("CAM configuration error\n");
  9148. return -EINVAL;
  9149. }
  9150. return 0;
  9151. }
  9152. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9153. {
  9154. int cfg_size = 0, idx, port = BP_PORT(bp);
  9155. /* Aggregation of supported attributes of all external phys */
  9156. bp->port.supported[0] = 0;
  9157. bp->port.supported[1] = 0;
  9158. switch (bp->link_params.num_phys) {
  9159. case 1:
  9160. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9161. cfg_size = 1;
  9162. break;
  9163. case 2:
  9164. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9165. cfg_size = 1;
  9166. break;
  9167. case 3:
  9168. if (bp->link_params.multi_phy_config &
  9169. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9170. bp->port.supported[1] =
  9171. bp->link_params.phy[EXT_PHY1].supported;
  9172. bp->port.supported[0] =
  9173. bp->link_params.phy[EXT_PHY2].supported;
  9174. } else {
  9175. bp->port.supported[0] =
  9176. bp->link_params.phy[EXT_PHY1].supported;
  9177. bp->port.supported[1] =
  9178. bp->link_params.phy[EXT_PHY2].supported;
  9179. }
  9180. cfg_size = 2;
  9181. break;
  9182. }
  9183. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9184. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9185. SHMEM_RD(bp,
  9186. dev_info.port_hw_config[port].external_phy_config),
  9187. SHMEM_RD(bp,
  9188. dev_info.port_hw_config[port].external_phy_config2));
  9189. return;
  9190. }
  9191. if (CHIP_IS_E3(bp))
  9192. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9193. else {
  9194. switch (switch_cfg) {
  9195. case SWITCH_CFG_1G:
  9196. bp->port.phy_addr = REG_RD(
  9197. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9198. break;
  9199. case SWITCH_CFG_10G:
  9200. bp->port.phy_addr = REG_RD(
  9201. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9202. break;
  9203. default:
  9204. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9205. bp->port.link_config[0]);
  9206. return;
  9207. }
  9208. }
  9209. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9210. /* mask what we support according to speed_cap_mask per configuration */
  9211. for (idx = 0; idx < cfg_size; idx++) {
  9212. if (!(bp->link_params.speed_cap_mask[idx] &
  9213. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9214. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9215. if (!(bp->link_params.speed_cap_mask[idx] &
  9216. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9217. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9218. if (!(bp->link_params.speed_cap_mask[idx] &
  9219. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9220. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9221. if (!(bp->link_params.speed_cap_mask[idx] &
  9222. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9223. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9224. if (!(bp->link_params.speed_cap_mask[idx] &
  9225. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9226. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9227. SUPPORTED_1000baseT_Full);
  9228. if (!(bp->link_params.speed_cap_mask[idx] &
  9229. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9230. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9231. if (!(bp->link_params.speed_cap_mask[idx] &
  9232. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9233. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9234. if (!(bp->link_params.speed_cap_mask[idx] &
  9235. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9236. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9237. }
  9238. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9239. bp->port.supported[1]);
  9240. }
  9241. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9242. {
  9243. u32 link_config, idx, cfg_size = 0;
  9244. bp->port.advertising[0] = 0;
  9245. bp->port.advertising[1] = 0;
  9246. switch (bp->link_params.num_phys) {
  9247. case 1:
  9248. case 2:
  9249. cfg_size = 1;
  9250. break;
  9251. case 3:
  9252. cfg_size = 2;
  9253. break;
  9254. }
  9255. for (idx = 0; idx < cfg_size; idx++) {
  9256. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9257. link_config = bp->port.link_config[idx];
  9258. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9259. case PORT_FEATURE_LINK_SPEED_AUTO:
  9260. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9261. bp->link_params.req_line_speed[idx] =
  9262. SPEED_AUTO_NEG;
  9263. bp->port.advertising[idx] |=
  9264. bp->port.supported[idx];
  9265. if (bp->link_params.phy[EXT_PHY1].type ==
  9266. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9267. bp->port.advertising[idx] |=
  9268. (SUPPORTED_100baseT_Half |
  9269. SUPPORTED_100baseT_Full);
  9270. } else {
  9271. /* force 10G, no AN */
  9272. bp->link_params.req_line_speed[idx] =
  9273. SPEED_10000;
  9274. bp->port.advertising[idx] |=
  9275. (ADVERTISED_10000baseT_Full |
  9276. ADVERTISED_FIBRE);
  9277. continue;
  9278. }
  9279. break;
  9280. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9281. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9282. bp->link_params.req_line_speed[idx] =
  9283. SPEED_10;
  9284. bp->port.advertising[idx] |=
  9285. (ADVERTISED_10baseT_Full |
  9286. ADVERTISED_TP);
  9287. } else {
  9288. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9289. link_config,
  9290. bp->link_params.speed_cap_mask[idx]);
  9291. return;
  9292. }
  9293. break;
  9294. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9295. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9296. bp->link_params.req_line_speed[idx] =
  9297. SPEED_10;
  9298. bp->link_params.req_duplex[idx] =
  9299. DUPLEX_HALF;
  9300. bp->port.advertising[idx] |=
  9301. (ADVERTISED_10baseT_Half |
  9302. ADVERTISED_TP);
  9303. } else {
  9304. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9305. link_config,
  9306. bp->link_params.speed_cap_mask[idx]);
  9307. return;
  9308. }
  9309. break;
  9310. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9311. if (bp->port.supported[idx] &
  9312. SUPPORTED_100baseT_Full) {
  9313. bp->link_params.req_line_speed[idx] =
  9314. SPEED_100;
  9315. bp->port.advertising[idx] |=
  9316. (ADVERTISED_100baseT_Full |
  9317. ADVERTISED_TP);
  9318. } else {
  9319. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9320. link_config,
  9321. bp->link_params.speed_cap_mask[idx]);
  9322. return;
  9323. }
  9324. break;
  9325. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9326. if (bp->port.supported[idx] &
  9327. SUPPORTED_100baseT_Half) {
  9328. bp->link_params.req_line_speed[idx] =
  9329. SPEED_100;
  9330. bp->link_params.req_duplex[idx] =
  9331. DUPLEX_HALF;
  9332. bp->port.advertising[idx] |=
  9333. (ADVERTISED_100baseT_Half |
  9334. ADVERTISED_TP);
  9335. } else {
  9336. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9337. link_config,
  9338. bp->link_params.speed_cap_mask[idx]);
  9339. return;
  9340. }
  9341. break;
  9342. case PORT_FEATURE_LINK_SPEED_1G:
  9343. if (bp->port.supported[idx] &
  9344. SUPPORTED_1000baseT_Full) {
  9345. bp->link_params.req_line_speed[idx] =
  9346. SPEED_1000;
  9347. bp->port.advertising[idx] |=
  9348. (ADVERTISED_1000baseT_Full |
  9349. ADVERTISED_TP);
  9350. } else {
  9351. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9352. link_config,
  9353. bp->link_params.speed_cap_mask[idx]);
  9354. return;
  9355. }
  9356. break;
  9357. case PORT_FEATURE_LINK_SPEED_2_5G:
  9358. if (bp->port.supported[idx] &
  9359. SUPPORTED_2500baseX_Full) {
  9360. bp->link_params.req_line_speed[idx] =
  9361. SPEED_2500;
  9362. bp->port.advertising[idx] |=
  9363. (ADVERTISED_2500baseX_Full |
  9364. ADVERTISED_TP);
  9365. } else {
  9366. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9367. link_config,
  9368. bp->link_params.speed_cap_mask[idx]);
  9369. return;
  9370. }
  9371. break;
  9372. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9373. if (bp->port.supported[idx] &
  9374. SUPPORTED_10000baseT_Full) {
  9375. bp->link_params.req_line_speed[idx] =
  9376. SPEED_10000;
  9377. bp->port.advertising[idx] |=
  9378. (ADVERTISED_10000baseT_Full |
  9379. ADVERTISED_FIBRE);
  9380. } else {
  9381. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9382. link_config,
  9383. bp->link_params.speed_cap_mask[idx]);
  9384. return;
  9385. }
  9386. break;
  9387. case PORT_FEATURE_LINK_SPEED_20G:
  9388. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9389. break;
  9390. default:
  9391. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9392. link_config);
  9393. bp->link_params.req_line_speed[idx] =
  9394. SPEED_AUTO_NEG;
  9395. bp->port.advertising[idx] =
  9396. bp->port.supported[idx];
  9397. break;
  9398. }
  9399. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9400. PORT_FEATURE_FLOW_CONTROL_MASK);
  9401. if (bp->link_params.req_flow_ctrl[idx] ==
  9402. BNX2X_FLOW_CTRL_AUTO) {
  9403. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9404. bp->link_params.req_flow_ctrl[idx] =
  9405. BNX2X_FLOW_CTRL_NONE;
  9406. else
  9407. bnx2x_set_requested_fc(bp);
  9408. }
  9409. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9410. bp->link_params.req_line_speed[idx],
  9411. bp->link_params.req_duplex[idx],
  9412. bp->link_params.req_flow_ctrl[idx],
  9413. bp->port.advertising[idx]);
  9414. }
  9415. }
  9416. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9417. {
  9418. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9419. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9420. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9421. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9422. }
  9423. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9424. {
  9425. int port = BP_PORT(bp);
  9426. u32 config;
  9427. u32 ext_phy_type, ext_phy_config, eee_mode;
  9428. bp->link_params.bp = bp;
  9429. bp->link_params.port = port;
  9430. bp->link_params.lane_config =
  9431. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9432. bp->link_params.speed_cap_mask[0] =
  9433. SHMEM_RD(bp,
  9434. dev_info.port_hw_config[port].speed_capability_mask) &
  9435. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9436. bp->link_params.speed_cap_mask[1] =
  9437. SHMEM_RD(bp,
  9438. dev_info.port_hw_config[port].speed_capability_mask2) &
  9439. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9440. bp->port.link_config[0] =
  9441. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9442. bp->port.link_config[1] =
  9443. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9444. bp->link_params.multi_phy_config =
  9445. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9446. /* If the device is capable of WoL, set the default state according
  9447. * to the HW
  9448. */
  9449. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9450. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9451. (config & PORT_FEATURE_WOL_ENABLED));
  9452. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9453. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9454. bp->flags |= NO_ISCSI_FLAG;
  9455. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9456. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9457. bp->flags |= NO_FCOE_FLAG;
  9458. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9459. bp->link_params.lane_config,
  9460. bp->link_params.speed_cap_mask[0],
  9461. bp->port.link_config[0]);
  9462. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9463. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9464. bnx2x_phy_probe(&bp->link_params);
  9465. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9466. bnx2x_link_settings_requested(bp);
  9467. /*
  9468. * If connected directly, work with the internal PHY, otherwise, work
  9469. * with the external PHY
  9470. */
  9471. ext_phy_config =
  9472. SHMEM_RD(bp,
  9473. dev_info.port_hw_config[port].external_phy_config);
  9474. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9475. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9476. bp->mdio.prtad = bp->port.phy_addr;
  9477. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9478. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9479. bp->mdio.prtad =
  9480. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9481. /* Configure link feature according to nvram value */
  9482. eee_mode = (((SHMEM_RD(bp, dev_info.
  9483. port_feature_config[port].eee_power_mode)) &
  9484. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9485. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9486. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9487. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9488. EEE_MODE_ENABLE_LPI |
  9489. EEE_MODE_OUTPUT_TIME;
  9490. } else {
  9491. bp->link_params.eee_mode = 0;
  9492. }
  9493. }
  9494. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9495. {
  9496. u32 no_flags = NO_ISCSI_FLAG;
  9497. int port = BP_PORT(bp);
  9498. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9499. drv_lic_key[port].max_iscsi_conn);
  9500. if (!CNIC_SUPPORT(bp)) {
  9501. bp->flags |= no_flags;
  9502. return;
  9503. }
  9504. /* Get the number of maximum allowed iSCSI connections */
  9505. bp->cnic_eth_dev.max_iscsi_conn =
  9506. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9507. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9508. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9509. bp->cnic_eth_dev.max_iscsi_conn);
  9510. /*
  9511. * If maximum allowed number of connections is zero -
  9512. * disable the feature.
  9513. */
  9514. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9515. bp->flags |= no_flags;
  9516. }
  9517. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9518. {
  9519. /* Port info */
  9520. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9521. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9522. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9523. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9524. /* Node info */
  9525. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9526. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9527. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9528. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9529. }
  9530. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9531. {
  9532. u8 count = 0;
  9533. if (IS_MF(bp)) {
  9534. u8 fid;
  9535. /* iterate over absolute function ids for this path: */
  9536. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9537. if (IS_MF_SD(bp)) {
  9538. u32 cfg = MF_CFG_RD(bp,
  9539. func_mf_config[fid].config);
  9540. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9541. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9542. FUNC_MF_CFG_PROTOCOL_FCOE))
  9543. count++;
  9544. } else {
  9545. u32 cfg = MF_CFG_RD(bp,
  9546. func_ext_config[fid].
  9547. func_cfg);
  9548. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9549. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9550. count++;
  9551. }
  9552. }
  9553. } else { /* SF */
  9554. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9555. for (port = 0; port < port_cnt; port++) {
  9556. u32 lic = SHMEM_RD(bp,
  9557. drv_lic_key[port].max_fcoe_conn) ^
  9558. FW_ENCODE_32BIT_PATTERN;
  9559. if (lic)
  9560. count++;
  9561. }
  9562. }
  9563. return count;
  9564. }
  9565. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9566. {
  9567. int port = BP_PORT(bp);
  9568. int func = BP_ABS_FUNC(bp);
  9569. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9570. drv_lic_key[port].max_fcoe_conn);
  9571. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9572. if (!CNIC_SUPPORT(bp)) {
  9573. bp->flags |= NO_FCOE_FLAG;
  9574. return;
  9575. }
  9576. /* Get the number of maximum allowed FCoE connections */
  9577. bp->cnic_eth_dev.max_fcoe_conn =
  9578. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9579. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9580. /* Calculate the number of maximum allowed FCoE tasks */
  9581. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9582. /* check if FCoE resources must be shared between different functions */
  9583. if (num_fcoe_func)
  9584. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9585. /* Read the WWN: */
  9586. if (!IS_MF(bp)) {
  9587. /* Port info */
  9588. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9589. SHMEM_RD(bp,
  9590. dev_info.port_hw_config[port].
  9591. fcoe_wwn_port_name_upper);
  9592. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9593. SHMEM_RD(bp,
  9594. dev_info.port_hw_config[port].
  9595. fcoe_wwn_port_name_lower);
  9596. /* Node info */
  9597. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9598. SHMEM_RD(bp,
  9599. dev_info.port_hw_config[port].
  9600. fcoe_wwn_node_name_upper);
  9601. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9602. SHMEM_RD(bp,
  9603. dev_info.port_hw_config[port].
  9604. fcoe_wwn_node_name_lower);
  9605. } else if (!IS_MF_SD(bp)) {
  9606. /* Read the WWN info only if the FCoE feature is enabled for
  9607. * this function.
  9608. */
  9609. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9610. bnx2x_get_ext_wwn_info(bp, func);
  9611. } else {
  9612. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9613. bnx2x_get_ext_wwn_info(bp, func);
  9614. }
  9615. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9616. /*
  9617. * If maximum allowed number of connections is zero -
  9618. * disable the feature.
  9619. */
  9620. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9621. bp->flags |= NO_FCOE_FLAG;
  9622. }
  9623. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9624. {
  9625. /*
  9626. * iSCSI may be dynamically disabled but reading
  9627. * info here we will decrease memory usage by driver
  9628. * if the feature is disabled for good
  9629. */
  9630. bnx2x_get_iscsi_info(bp);
  9631. bnx2x_get_fcoe_info(bp);
  9632. }
  9633. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9634. {
  9635. u32 val, val2;
  9636. int func = BP_ABS_FUNC(bp);
  9637. int port = BP_PORT(bp);
  9638. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9639. u8 *fip_mac = bp->fip_mac;
  9640. if (IS_MF(bp)) {
  9641. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9642. * FCoE MAC then the appropriate feature should be disabled.
  9643. * In non SD mode features configuration comes from struct
  9644. * func_ext_config.
  9645. */
  9646. if (!IS_MF_SD(bp)) {
  9647. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9648. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9649. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9650. iscsi_mac_addr_upper);
  9651. val = MF_CFG_RD(bp, func_ext_config[func].
  9652. iscsi_mac_addr_lower);
  9653. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9654. BNX2X_DEV_INFO
  9655. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9656. } else {
  9657. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9658. }
  9659. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9660. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9661. fcoe_mac_addr_upper);
  9662. val = MF_CFG_RD(bp, func_ext_config[func].
  9663. fcoe_mac_addr_lower);
  9664. bnx2x_set_mac_buf(fip_mac, val, val2);
  9665. BNX2X_DEV_INFO
  9666. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9667. } else {
  9668. bp->flags |= NO_FCOE_FLAG;
  9669. }
  9670. bp->mf_ext_config = cfg;
  9671. } else { /* SD MODE */
  9672. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9673. /* use primary mac as iscsi mac */
  9674. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9675. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9676. BNX2X_DEV_INFO
  9677. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9678. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9679. /* use primary mac as fip mac */
  9680. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9681. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9682. BNX2X_DEV_INFO
  9683. ("Read FIP MAC: %pM\n", fip_mac);
  9684. }
  9685. }
  9686. /* If this is a storage-only interface, use SAN mac as
  9687. * primary MAC. Notice that for SD this is already the case,
  9688. * as the SAN mac was copied from the primary MAC.
  9689. */
  9690. if (IS_MF_FCOE_AFEX(bp))
  9691. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9692. } else {
  9693. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9694. iscsi_mac_upper);
  9695. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9696. iscsi_mac_lower);
  9697. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9698. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9699. fcoe_fip_mac_upper);
  9700. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9701. fcoe_fip_mac_lower);
  9702. bnx2x_set_mac_buf(fip_mac, val, val2);
  9703. }
  9704. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9705. if (!is_valid_ether_addr(iscsi_mac)) {
  9706. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9707. memset(iscsi_mac, 0, ETH_ALEN);
  9708. }
  9709. /* Disable FCoE if MAC configuration is invalid. */
  9710. if (!is_valid_ether_addr(fip_mac)) {
  9711. bp->flags |= NO_FCOE_FLAG;
  9712. memset(bp->fip_mac, 0, ETH_ALEN);
  9713. }
  9714. }
  9715. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9716. {
  9717. u32 val, val2;
  9718. int func = BP_ABS_FUNC(bp);
  9719. int port = BP_PORT(bp);
  9720. /* Zero primary MAC configuration */
  9721. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9722. if (BP_NOMCP(bp)) {
  9723. BNX2X_ERROR("warning: random MAC workaround active\n");
  9724. eth_hw_addr_random(bp->dev);
  9725. } else if (IS_MF(bp)) {
  9726. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9727. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9728. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9729. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9730. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9731. if (CNIC_SUPPORT(bp))
  9732. bnx2x_get_cnic_mac_hwinfo(bp);
  9733. } else {
  9734. /* in SF read MACs from port configuration */
  9735. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9736. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9737. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9738. if (CNIC_SUPPORT(bp))
  9739. bnx2x_get_cnic_mac_hwinfo(bp);
  9740. }
  9741. if (!BP_NOMCP(bp)) {
  9742. /* Read physical port identifier from shmem */
  9743. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9744. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9745. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9746. bp->flags |= HAS_PHYS_PORT_ID;
  9747. }
  9748. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9749. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9750. dev_err(&bp->pdev->dev,
  9751. "bad Ethernet MAC address configuration: %pM\n"
  9752. "change it manually before bringing up the appropriate network interface\n",
  9753. bp->dev->dev_addr);
  9754. }
  9755. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9756. {
  9757. int tmp;
  9758. u32 cfg;
  9759. if (IS_VF(bp))
  9760. return 0;
  9761. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9762. /* Take function: tmp = func */
  9763. tmp = BP_ABS_FUNC(bp);
  9764. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9765. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9766. } else {
  9767. /* Take port: tmp = port */
  9768. tmp = BP_PORT(bp);
  9769. cfg = SHMEM_RD(bp,
  9770. dev_info.port_hw_config[tmp].generic_features);
  9771. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9772. }
  9773. return cfg;
  9774. }
  9775. static void validate_set_si_mode(struct bnx2x *bp)
  9776. {
  9777. u8 func = BP_ABS_FUNC(bp);
  9778. u32 val;
  9779. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9780. /* check for legal mac (upper bytes) */
  9781. if (val != 0xffff) {
  9782. bp->mf_mode = MULTI_FUNCTION_SI;
  9783. bp->mf_config[BP_VN(bp)] =
  9784. MF_CFG_RD(bp, func_mf_config[func].config);
  9785. } else
  9786. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9787. }
  9788. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9789. {
  9790. int /*abs*/func = BP_ABS_FUNC(bp);
  9791. int vn;
  9792. u32 val = 0, val2 = 0;
  9793. int rc = 0;
  9794. bnx2x_get_common_hwinfo(bp);
  9795. /*
  9796. * initialize IGU parameters
  9797. */
  9798. if (CHIP_IS_E1x(bp)) {
  9799. bp->common.int_block = INT_BLOCK_HC;
  9800. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9801. bp->igu_base_sb = 0;
  9802. } else {
  9803. bp->common.int_block = INT_BLOCK_IGU;
  9804. /* do not allow device reset during IGU info processing */
  9805. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9806. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9807. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9808. int tout = 5000;
  9809. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9810. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9811. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9812. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9813. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9814. tout--;
  9815. usleep_range(1000, 2000);
  9816. }
  9817. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9818. dev_err(&bp->pdev->dev,
  9819. "FORCING Normal Mode failed!!!\n");
  9820. bnx2x_release_hw_lock(bp,
  9821. HW_LOCK_RESOURCE_RESET);
  9822. return -EPERM;
  9823. }
  9824. }
  9825. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9826. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9827. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9828. } else
  9829. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9830. rc = bnx2x_get_igu_cam_info(bp);
  9831. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9832. if (rc)
  9833. return rc;
  9834. }
  9835. /*
  9836. * set base FW non-default (fast path) status block id, this value is
  9837. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9838. * determine the id used by the FW.
  9839. */
  9840. if (CHIP_IS_E1x(bp))
  9841. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9842. else /*
  9843. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9844. * the same queue are indicated on the same IGU SB). So we prefer
  9845. * FW and IGU SBs to be the same value.
  9846. */
  9847. bp->base_fw_ndsb = bp->igu_base_sb;
  9848. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9849. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9850. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9851. /*
  9852. * Initialize MF configuration
  9853. */
  9854. bp->mf_ov = 0;
  9855. bp->mf_mode = 0;
  9856. bp->mf_sub_mode = 0;
  9857. vn = BP_VN(bp);
  9858. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9859. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9860. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9861. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9862. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9863. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9864. else
  9865. bp->common.mf_cfg_base = bp->common.shmem_base +
  9866. offsetof(struct shmem_region, func_mb) +
  9867. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9868. /*
  9869. * get mf configuration:
  9870. * 1. Existence of MF configuration
  9871. * 2. MAC address must be legal (check only upper bytes)
  9872. * for Switch-Independent mode;
  9873. * OVLAN must be legal for Switch-Dependent mode
  9874. * 3. SF_MODE configures specific MF mode
  9875. */
  9876. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9877. /* get mf configuration */
  9878. val = SHMEM_RD(bp,
  9879. dev_info.shared_feature_config.config);
  9880. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9881. switch (val) {
  9882. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9883. validate_set_si_mode(bp);
  9884. break;
  9885. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9886. if ((!CHIP_IS_E1x(bp)) &&
  9887. (MF_CFG_RD(bp, func_mf_config[func].
  9888. mac_upper) != 0xffff) &&
  9889. (SHMEM2_HAS(bp,
  9890. afex_driver_support))) {
  9891. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9892. bp->mf_config[vn] = MF_CFG_RD(bp,
  9893. func_mf_config[func].config);
  9894. } else {
  9895. BNX2X_DEV_INFO("can not configure afex mode\n");
  9896. }
  9897. break;
  9898. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9899. /* get OV configuration */
  9900. val = MF_CFG_RD(bp,
  9901. func_mf_config[FUNC_0].e1hov_tag);
  9902. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9903. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9904. bp->mf_mode = MULTI_FUNCTION_SD;
  9905. bp->mf_config[vn] = MF_CFG_RD(bp,
  9906. func_mf_config[func].config);
  9907. } else
  9908. BNX2X_DEV_INFO("illegal OV for SD\n");
  9909. break;
  9910. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  9911. bp->mf_mode = MULTI_FUNCTION_SD;
  9912. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  9913. bp->mf_config[vn] =
  9914. MF_CFG_RD(bp,
  9915. func_mf_config[func].config);
  9916. break;
  9917. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9918. bp->mf_config[vn] = 0;
  9919. break;
  9920. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  9921. val2 = SHMEM_RD(bp,
  9922. dev_info.shared_hw_config.config_3);
  9923. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  9924. switch (val2) {
  9925. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  9926. validate_set_si_mode(bp);
  9927. bp->mf_sub_mode =
  9928. SUB_MF_MODE_NPAR1_DOT_5;
  9929. break;
  9930. default:
  9931. /* Unknown configuration */
  9932. bp->mf_config[vn] = 0;
  9933. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  9934. val);
  9935. }
  9936. break;
  9937. default:
  9938. /* Unknown configuration: reset mf_config */
  9939. bp->mf_config[vn] = 0;
  9940. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9941. }
  9942. }
  9943. BNX2X_DEV_INFO("%s function mode\n",
  9944. IS_MF(bp) ? "multi" : "single");
  9945. switch (bp->mf_mode) {
  9946. case MULTI_FUNCTION_SD:
  9947. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9948. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9949. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9950. bp->mf_ov = val;
  9951. bp->path_has_ovlan = true;
  9952. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9953. func, bp->mf_ov, bp->mf_ov);
  9954. } else if (bp->mf_sub_mode == SUB_MF_MODE_UFP) {
  9955. dev_err(&bp->pdev->dev,
  9956. "Unexpected - no valid MF OV for func %d in UFP mode\n",
  9957. func);
  9958. bp->path_has_ovlan = true;
  9959. } else {
  9960. dev_err(&bp->pdev->dev,
  9961. "No valid MF OV for func %d, aborting\n",
  9962. func);
  9963. return -EPERM;
  9964. }
  9965. break;
  9966. case MULTI_FUNCTION_AFEX:
  9967. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9968. break;
  9969. case MULTI_FUNCTION_SI:
  9970. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9971. func);
  9972. break;
  9973. default:
  9974. if (vn) {
  9975. dev_err(&bp->pdev->dev,
  9976. "VN %d is in a single function mode, aborting\n",
  9977. vn);
  9978. return -EPERM;
  9979. }
  9980. break;
  9981. }
  9982. /* check if other port on the path needs ovlan:
  9983. * Since MF configuration is shared between ports
  9984. * Possible mixed modes are only
  9985. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9986. */
  9987. if (CHIP_MODE_IS_4_PORT(bp) &&
  9988. !bp->path_has_ovlan &&
  9989. !IS_MF(bp) &&
  9990. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9991. u8 other_port = !BP_PORT(bp);
  9992. u8 other_func = BP_PATH(bp) + 2*other_port;
  9993. val = MF_CFG_RD(bp,
  9994. func_mf_config[other_func].e1hov_tag);
  9995. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9996. bp->path_has_ovlan = true;
  9997. }
  9998. }
  9999. /* adjust igu_sb_cnt to MF for E1H */
  10000. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10001. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10002. /* port info */
  10003. bnx2x_get_port_hwinfo(bp);
  10004. /* Get MAC addresses */
  10005. bnx2x_get_mac_hwinfo(bp);
  10006. bnx2x_get_cnic_info(bp);
  10007. return rc;
  10008. }
  10009. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10010. {
  10011. int cnt, i, block_end, rodi;
  10012. char vpd_start[BNX2X_VPD_LEN+1];
  10013. char str_id_reg[VENDOR_ID_LEN+1];
  10014. char str_id_cap[VENDOR_ID_LEN+1];
  10015. char *vpd_data;
  10016. char *vpd_extended_data = NULL;
  10017. u8 len;
  10018. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10019. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10020. if (cnt < BNX2X_VPD_LEN)
  10021. goto out_not_found;
  10022. /* VPD RO tag should be first tag after identifier string, hence
  10023. * we should be able to find it in first BNX2X_VPD_LEN chars
  10024. */
  10025. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10026. PCI_VPD_LRDT_RO_DATA);
  10027. if (i < 0)
  10028. goto out_not_found;
  10029. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10030. pci_vpd_lrdt_size(&vpd_start[i]);
  10031. i += PCI_VPD_LRDT_TAG_SIZE;
  10032. if (block_end > BNX2X_VPD_LEN) {
  10033. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10034. if (vpd_extended_data == NULL)
  10035. goto out_not_found;
  10036. /* read rest of vpd image into vpd_extended_data */
  10037. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10038. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10039. block_end - BNX2X_VPD_LEN,
  10040. vpd_extended_data + BNX2X_VPD_LEN);
  10041. if (cnt < (block_end - BNX2X_VPD_LEN))
  10042. goto out_not_found;
  10043. vpd_data = vpd_extended_data;
  10044. } else
  10045. vpd_data = vpd_start;
  10046. /* now vpd_data holds full vpd content in both cases */
  10047. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10048. PCI_VPD_RO_KEYWORD_MFR_ID);
  10049. if (rodi < 0)
  10050. goto out_not_found;
  10051. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10052. if (len != VENDOR_ID_LEN)
  10053. goto out_not_found;
  10054. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10055. /* vendor specific info */
  10056. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10057. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10058. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10059. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10060. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10061. PCI_VPD_RO_KEYWORD_VENDOR0);
  10062. if (rodi >= 0) {
  10063. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10064. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10065. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10066. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10067. bp->fw_ver[len] = ' ';
  10068. }
  10069. }
  10070. kfree(vpd_extended_data);
  10071. return;
  10072. }
  10073. out_not_found:
  10074. kfree(vpd_extended_data);
  10075. return;
  10076. }
  10077. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10078. {
  10079. u32 flags = 0;
  10080. if (CHIP_REV_IS_FPGA(bp))
  10081. SET_FLAGS(flags, MODE_FPGA);
  10082. else if (CHIP_REV_IS_EMUL(bp))
  10083. SET_FLAGS(flags, MODE_EMUL);
  10084. else
  10085. SET_FLAGS(flags, MODE_ASIC);
  10086. if (CHIP_MODE_IS_4_PORT(bp))
  10087. SET_FLAGS(flags, MODE_PORT4);
  10088. else
  10089. SET_FLAGS(flags, MODE_PORT2);
  10090. if (CHIP_IS_E2(bp))
  10091. SET_FLAGS(flags, MODE_E2);
  10092. else if (CHIP_IS_E3(bp)) {
  10093. SET_FLAGS(flags, MODE_E3);
  10094. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10095. SET_FLAGS(flags, MODE_E3_A0);
  10096. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10097. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10098. }
  10099. if (IS_MF(bp)) {
  10100. SET_FLAGS(flags, MODE_MF);
  10101. switch (bp->mf_mode) {
  10102. case MULTI_FUNCTION_SD:
  10103. SET_FLAGS(flags, MODE_MF_SD);
  10104. break;
  10105. case MULTI_FUNCTION_SI:
  10106. SET_FLAGS(flags, MODE_MF_SI);
  10107. break;
  10108. case MULTI_FUNCTION_AFEX:
  10109. SET_FLAGS(flags, MODE_MF_AFEX);
  10110. break;
  10111. }
  10112. } else
  10113. SET_FLAGS(flags, MODE_SF);
  10114. #if defined(__LITTLE_ENDIAN)
  10115. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10116. #else /*(__BIG_ENDIAN)*/
  10117. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10118. #endif
  10119. INIT_MODE_FLAGS(bp) = flags;
  10120. }
  10121. static int bnx2x_init_bp(struct bnx2x *bp)
  10122. {
  10123. int func;
  10124. int rc;
  10125. mutex_init(&bp->port.phy_mutex);
  10126. mutex_init(&bp->fw_mb_mutex);
  10127. mutex_init(&bp->drv_info_mutex);
  10128. bp->drv_info_mng_owner = false;
  10129. spin_lock_init(&bp->stats_lock);
  10130. sema_init(&bp->stats_sema, 1);
  10131. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10132. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10133. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10134. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10135. if (IS_PF(bp)) {
  10136. rc = bnx2x_get_hwinfo(bp);
  10137. if (rc)
  10138. return rc;
  10139. } else {
  10140. eth_zero_addr(bp->dev->dev_addr);
  10141. }
  10142. bnx2x_set_modes_bitmap(bp);
  10143. rc = bnx2x_alloc_mem_bp(bp);
  10144. if (rc)
  10145. return rc;
  10146. bnx2x_read_fwinfo(bp);
  10147. func = BP_FUNC(bp);
  10148. /* need to reset chip if undi was active */
  10149. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10150. /* init fw_seq */
  10151. bp->fw_seq =
  10152. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10153. DRV_MSG_SEQ_NUMBER_MASK;
  10154. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10155. rc = bnx2x_prev_unload(bp);
  10156. if (rc) {
  10157. bnx2x_free_mem_bp(bp);
  10158. return rc;
  10159. }
  10160. }
  10161. if (CHIP_REV_IS_FPGA(bp))
  10162. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10163. if (BP_NOMCP(bp) && (func == 0))
  10164. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10165. bp->disable_tpa = disable_tpa;
  10166. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10167. /* Reduce memory usage in kdump environment by disabling TPA */
  10168. bp->disable_tpa |= is_kdump_kernel();
  10169. /* Set TPA flags */
  10170. if (bp->disable_tpa) {
  10171. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10172. bp->dev->features &= ~NETIF_F_LRO;
  10173. } else {
  10174. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10175. bp->dev->features |= NETIF_F_LRO;
  10176. }
  10177. if (CHIP_IS_E1(bp))
  10178. bp->dropless_fc = 0;
  10179. else
  10180. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10181. bp->mrrs = mrrs;
  10182. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10183. if (IS_VF(bp))
  10184. bp->rx_ring_size = MAX_RX_AVAIL;
  10185. /* make sure that the numbers are in the right granularity */
  10186. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10187. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10188. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10189. init_timer(&bp->timer);
  10190. bp->timer.expires = jiffies + bp->current_interval;
  10191. bp->timer.data = (unsigned long) bp;
  10192. bp->timer.function = bnx2x_timer;
  10193. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10194. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10195. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10196. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10197. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10198. bnx2x_dcbx_init_params(bp);
  10199. } else {
  10200. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10201. }
  10202. if (CHIP_IS_E1x(bp))
  10203. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10204. else
  10205. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10206. /* multiple tx priority */
  10207. if (IS_VF(bp))
  10208. bp->max_cos = 1;
  10209. else if (CHIP_IS_E1x(bp))
  10210. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10211. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10212. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10213. else if (CHIP_IS_E3B0(bp))
  10214. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10215. else
  10216. BNX2X_ERR("unknown chip %x revision %x\n",
  10217. CHIP_NUM(bp), CHIP_REV(bp));
  10218. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10219. /* We need at least one default status block for slow-path events,
  10220. * second status block for the L2 queue, and a third status block for
  10221. * CNIC if supported.
  10222. */
  10223. if (IS_VF(bp))
  10224. bp->min_msix_vec_cnt = 1;
  10225. else if (CNIC_SUPPORT(bp))
  10226. bp->min_msix_vec_cnt = 3;
  10227. else /* PF w/o cnic */
  10228. bp->min_msix_vec_cnt = 2;
  10229. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10230. bp->dump_preset_idx = 1;
  10231. if (CHIP_IS_E3B0(bp))
  10232. bp->flags |= PTP_SUPPORTED;
  10233. return rc;
  10234. }
  10235. /****************************************************************************
  10236. * General service functions
  10237. ****************************************************************************/
  10238. /*
  10239. * net_device service functions
  10240. */
  10241. /* called with rtnl_lock */
  10242. static int bnx2x_open(struct net_device *dev)
  10243. {
  10244. struct bnx2x *bp = netdev_priv(dev);
  10245. int rc;
  10246. bp->stats_init = true;
  10247. netif_carrier_off(dev);
  10248. bnx2x_set_power_state(bp, PCI_D0);
  10249. /* If parity had happen during the unload, then attentions
  10250. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10251. * want the first function loaded on the current engine to
  10252. * complete the recovery.
  10253. * Parity recovery is only relevant for PF driver.
  10254. */
  10255. if (IS_PF(bp)) {
  10256. int other_engine = BP_PATH(bp) ? 0 : 1;
  10257. bool other_load_status, load_status;
  10258. bool global = false;
  10259. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10260. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10261. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10262. bnx2x_chk_parity_attn(bp, &global, true)) {
  10263. do {
  10264. /* If there are attentions and they are in a
  10265. * global blocks, set the GLOBAL_RESET bit
  10266. * regardless whether it will be this function
  10267. * that will complete the recovery or not.
  10268. */
  10269. if (global)
  10270. bnx2x_set_reset_global(bp);
  10271. /* Only the first function on the current
  10272. * engine should try to recover in open. In case
  10273. * of attentions in global blocks only the first
  10274. * in the chip should try to recover.
  10275. */
  10276. if ((!load_status &&
  10277. (!global || !other_load_status)) &&
  10278. bnx2x_trylock_leader_lock(bp) &&
  10279. !bnx2x_leader_reset(bp)) {
  10280. netdev_info(bp->dev,
  10281. "Recovered in open\n");
  10282. break;
  10283. }
  10284. /* recovery has failed... */
  10285. bnx2x_set_power_state(bp, PCI_D3hot);
  10286. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10287. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10288. "If you still see this message after a few retries then power cycle is required.\n");
  10289. return -EAGAIN;
  10290. } while (0);
  10291. }
  10292. }
  10293. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10294. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10295. if (rc)
  10296. return rc;
  10297. return 0;
  10298. }
  10299. /* called with rtnl_lock */
  10300. static int bnx2x_close(struct net_device *dev)
  10301. {
  10302. struct bnx2x *bp = netdev_priv(dev);
  10303. /* Unload the driver, release IRQs */
  10304. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10305. return 0;
  10306. }
  10307. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10308. struct bnx2x_mcast_ramrod_params *p)
  10309. {
  10310. int mc_count = netdev_mc_count(bp->dev);
  10311. struct bnx2x_mcast_list_elem *mc_mac =
  10312. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10313. struct netdev_hw_addr *ha;
  10314. if (!mc_mac)
  10315. return -ENOMEM;
  10316. INIT_LIST_HEAD(&p->mcast_list);
  10317. netdev_for_each_mc_addr(ha, bp->dev) {
  10318. mc_mac->mac = bnx2x_mc_addr(ha);
  10319. list_add_tail(&mc_mac->link, &p->mcast_list);
  10320. mc_mac++;
  10321. }
  10322. p->mcast_list_len = mc_count;
  10323. return 0;
  10324. }
  10325. static void bnx2x_free_mcast_macs_list(
  10326. struct bnx2x_mcast_ramrod_params *p)
  10327. {
  10328. struct bnx2x_mcast_list_elem *mc_mac =
  10329. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10330. link);
  10331. WARN_ON(!mc_mac);
  10332. kfree(mc_mac);
  10333. }
  10334. /**
  10335. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10336. *
  10337. * @bp: driver handle
  10338. *
  10339. * We will use zero (0) as a MAC type for these MACs.
  10340. */
  10341. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10342. {
  10343. int rc;
  10344. struct net_device *dev = bp->dev;
  10345. struct netdev_hw_addr *ha;
  10346. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10347. unsigned long ramrod_flags = 0;
  10348. /* First schedule a cleanup up of old configuration */
  10349. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10350. if (rc < 0) {
  10351. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10352. return rc;
  10353. }
  10354. netdev_for_each_uc_addr(ha, dev) {
  10355. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10356. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10357. if (rc == -EEXIST) {
  10358. DP(BNX2X_MSG_SP,
  10359. "Failed to schedule ADD operations: %d\n", rc);
  10360. /* do not treat adding same MAC as error */
  10361. rc = 0;
  10362. } else if (rc < 0) {
  10363. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10364. rc);
  10365. return rc;
  10366. }
  10367. }
  10368. /* Execute the pending commands */
  10369. __set_bit(RAMROD_CONT, &ramrod_flags);
  10370. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10371. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10372. }
  10373. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10374. {
  10375. struct net_device *dev = bp->dev;
  10376. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10377. int rc = 0;
  10378. rparam.mcast_obj = &bp->mcast_obj;
  10379. /* first, clear all configured multicast MACs */
  10380. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10381. if (rc < 0) {
  10382. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10383. return rc;
  10384. }
  10385. /* then, configure a new MACs list */
  10386. if (netdev_mc_count(dev)) {
  10387. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10388. if (rc) {
  10389. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10390. rc);
  10391. return rc;
  10392. }
  10393. /* Now add the new MACs */
  10394. rc = bnx2x_config_mcast(bp, &rparam,
  10395. BNX2X_MCAST_CMD_ADD);
  10396. if (rc < 0)
  10397. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10398. rc);
  10399. bnx2x_free_mcast_macs_list(&rparam);
  10400. }
  10401. return rc;
  10402. }
  10403. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10404. static void bnx2x_set_rx_mode(struct net_device *dev)
  10405. {
  10406. struct bnx2x *bp = netdev_priv(dev);
  10407. if (bp->state != BNX2X_STATE_OPEN) {
  10408. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10409. return;
  10410. } else {
  10411. /* Schedule an SP task to handle rest of change */
  10412. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10413. NETIF_MSG_IFUP);
  10414. }
  10415. }
  10416. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10417. {
  10418. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10419. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10420. netif_addr_lock_bh(bp->dev);
  10421. if (bp->dev->flags & IFF_PROMISC) {
  10422. rx_mode = BNX2X_RX_MODE_PROMISC;
  10423. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10424. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10425. CHIP_IS_E1(bp))) {
  10426. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10427. } else {
  10428. if (IS_PF(bp)) {
  10429. /* some multicasts */
  10430. if (bnx2x_set_mc_list(bp) < 0)
  10431. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10432. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10433. netif_addr_unlock_bh(bp->dev);
  10434. if (bnx2x_set_uc_list(bp) < 0)
  10435. rx_mode = BNX2X_RX_MODE_PROMISC;
  10436. netif_addr_lock_bh(bp->dev);
  10437. } else {
  10438. /* configuring mcast to a vf involves sleeping (when we
  10439. * wait for the pf's response).
  10440. */
  10441. bnx2x_schedule_sp_rtnl(bp,
  10442. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10443. }
  10444. }
  10445. bp->rx_mode = rx_mode;
  10446. /* handle ISCSI SD mode */
  10447. if (IS_MF_ISCSI_ONLY(bp))
  10448. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10449. /* Schedule the rx_mode command */
  10450. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10451. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10452. netif_addr_unlock_bh(bp->dev);
  10453. return;
  10454. }
  10455. if (IS_PF(bp)) {
  10456. bnx2x_set_storm_rx_mode(bp);
  10457. netif_addr_unlock_bh(bp->dev);
  10458. } else {
  10459. /* VF will need to request the PF to make this change, and so
  10460. * the VF needs to release the bottom-half lock prior to the
  10461. * request (as it will likely require sleep on the VF side)
  10462. */
  10463. netif_addr_unlock_bh(bp->dev);
  10464. bnx2x_vfpf_storm_rx_mode(bp);
  10465. }
  10466. }
  10467. /* called with rtnl_lock */
  10468. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10469. int devad, u16 addr)
  10470. {
  10471. struct bnx2x *bp = netdev_priv(netdev);
  10472. u16 value;
  10473. int rc;
  10474. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10475. prtad, devad, addr);
  10476. /* The HW expects different devad if CL22 is used */
  10477. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10478. bnx2x_acquire_phy_lock(bp);
  10479. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10480. bnx2x_release_phy_lock(bp);
  10481. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10482. if (!rc)
  10483. rc = value;
  10484. return rc;
  10485. }
  10486. /* called with rtnl_lock */
  10487. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10488. u16 addr, u16 value)
  10489. {
  10490. struct bnx2x *bp = netdev_priv(netdev);
  10491. int rc;
  10492. DP(NETIF_MSG_LINK,
  10493. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10494. prtad, devad, addr, value);
  10495. /* The HW expects different devad if CL22 is used */
  10496. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10497. bnx2x_acquire_phy_lock(bp);
  10498. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10499. bnx2x_release_phy_lock(bp);
  10500. return rc;
  10501. }
  10502. /* called with rtnl_lock */
  10503. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10504. {
  10505. struct bnx2x *bp = netdev_priv(dev);
  10506. struct mii_ioctl_data *mdio = if_mii(ifr);
  10507. if (!netif_running(dev))
  10508. return -EAGAIN;
  10509. switch (cmd) {
  10510. case SIOCSHWTSTAMP:
  10511. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10512. default:
  10513. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10514. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10515. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10516. }
  10517. }
  10518. #ifdef CONFIG_NET_POLL_CONTROLLER
  10519. static void poll_bnx2x(struct net_device *dev)
  10520. {
  10521. struct bnx2x *bp = netdev_priv(dev);
  10522. int i;
  10523. for_each_eth_queue(bp, i) {
  10524. struct bnx2x_fastpath *fp = &bp->fp[i];
  10525. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10526. }
  10527. }
  10528. #endif
  10529. static int bnx2x_validate_addr(struct net_device *dev)
  10530. {
  10531. struct bnx2x *bp = netdev_priv(dev);
  10532. /* query the bulletin board for mac address configured by the PF */
  10533. if (IS_VF(bp))
  10534. bnx2x_sample_bulletin(bp);
  10535. if (!is_valid_ether_addr(dev->dev_addr)) {
  10536. BNX2X_ERR("Non-valid Ethernet address\n");
  10537. return -EADDRNOTAVAIL;
  10538. }
  10539. return 0;
  10540. }
  10541. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10542. struct netdev_phys_port_id *ppid)
  10543. {
  10544. struct bnx2x *bp = netdev_priv(netdev);
  10545. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10546. return -EOPNOTSUPP;
  10547. ppid->id_len = sizeof(bp->phys_port_id);
  10548. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10549. return 0;
  10550. }
  10551. static const struct net_device_ops bnx2x_netdev_ops = {
  10552. .ndo_open = bnx2x_open,
  10553. .ndo_stop = bnx2x_close,
  10554. .ndo_start_xmit = bnx2x_start_xmit,
  10555. .ndo_select_queue = bnx2x_select_queue,
  10556. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10557. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10558. .ndo_validate_addr = bnx2x_validate_addr,
  10559. .ndo_do_ioctl = bnx2x_ioctl,
  10560. .ndo_change_mtu = bnx2x_change_mtu,
  10561. .ndo_fix_features = bnx2x_fix_features,
  10562. .ndo_set_features = bnx2x_set_features,
  10563. .ndo_tx_timeout = bnx2x_tx_timeout,
  10564. #ifdef CONFIG_NET_POLL_CONTROLLER
  10565. .ndo_poll_controller = poll_bnx2x,
  10566. #endif
  10567. .ndo_setup_tc = bnx2x_setup_tc,
  10568. #ifdef CONFIG_BNX2X_SRIOV
  10569. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10570. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10571. .ndo_get_vf_config = bnx2x_get_vf_config,
  10572. #endif
  10573. #ifdef NETDEV_FCOE_WWNN
  10574. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10575. #endif
  10576. #ifdef CONFIG_NET_RX_BUSY_POLL
  10577. .ndo_busy_poll = bnx2x_low_latency_recv,
  10578. #endif
  10579. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10580. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10581. };
  10582. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10583. {
  10584. struct device *dev = &bp->pdev->dev;
  10585. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10586. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10587. dev_err(dev, "System does not support DMA, aborting\n");
  10588. return -EIO;
  10589. }
  10590. return 0;
  10591. }
  10592. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10593. {
  10594. if (bp->flags & AER_ENABLED) {
  10595. pci_disable_pcie_error_reporting(bp->pdev);
  10596. bp->flags &= ~AER_ENABLED;
  10597. }
  10598. }
  10599. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10600. struct net_device *dev, unsigned long board_type)
  10601. {
  10602. int rc;
  10603. u32 pci_cfg_dword;
  10604. bool chip_is_e1x = (board_type == BCM57710 ||
  10605. board_type == BCM57711 ||
  10606. board_type == BCM57711E);
  10607. SET_NETDEV_DEV(dev, &pdev->dev);
  10608. bp->dev = dev;
  10609. bp->pdev = pdev;
  10610. rc = pci_enable_device(pdev);
  10611. if (rc) {
  10612. dev_err(&bp->pdev->dev,
  10613. "Cannot enable PCI device, aborting\n");
  10614. goto err_out;
  10615. }
  10616. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10617. dev_err(&bp->pdev->dev,
  10618. "Cannot find PCI device base address, aborting\n");
  10619. rc = -ENODEV;
  10620. goto err_out_disable;
  10621. }
  10622. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10623. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10624. rc = -ENODEV;
  10625. goto err_out_disable;
  10626. }
  10627. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10628. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10629. PCICFG_REVESION_ID_ERROR_VAL) {
  10630. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10631. rc = -ENODEV;
  10632. goto err_out_disable;
  10633. }
  10634. if (atomic_read(&pdev->enable_cnt) == 1) {
  10635. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10636. if (rc) {
  10637. dev_err(&bp->pdev->dev,
  10638. "Cannot obtain PCI resources, aborting\n");
  10639. goto err_out_disable;
  10640. }
  10641. pci_set_master(pdev);
  10642. pci_save_state(pdev);
  10643. }
  10644. if (IS_PF(bp)) {
  10645. if (!pdev->pm_cap) {
  10646. dev_err(&bp->pdev->dev,
  10647. "Cannot find power management capability, aborting\n");
  10648. rc = -EIO;
  10649. goto err_out_release;
  10650. }
  10651. }
  10652. if (!pci_is_pcie(pdev)) {
  10653. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10654. rc = -EIO;
  10655. goto err_out_release;
  10656. }
  10657. rc = bnx2x_set_coherency_mask(bp);
  10658. if (rc)
  10659. goto err_out_release;
  10660. dev->mem_start = pci_resource_start(pdev, 0);
  10661. dev->base_addr = dev->mem_start;
  10662. dev->mem_end = pci_resource_end(pdev, 0);
  10663. dev->irq = pdev->irq;
  10664. bp->regview = pci_ioremap_bar(pdev, 0);
  10665. if (!bp->regview) {
  10666. dev_err(&bp->pdev->dev,
  10667. "Cannot map register space, aborting\n");
  10668. rc = -ENOMEM;
  10669. goto err_out_release;
  10670. }
  10671. /* In E1/E1H use pci device function given by kernel.
  10672. * In E2/E3 read physical function from ME register since these chips
  10673. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10674. * (depending on hypervisor).
  10675. */
  10676. if (chip_is_e1x) {
  10677. bp->pf_num = PCI_FUNC(pdev->devfn);
  10678. } else {
  10679. /* chip is E2/3*/
  10680. pci_read_config_dword(bp->pdev,
  10681. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10682. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10683. ME_REG_ABS_PF_NUM_SHIFT);
  10684. }
  10685. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10686. /* clean indirect addresses */
  10687. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10688. PCICFG_VENDOR_ID_OFFSET);
  10689. /* AER (Advanced Error reporting) configuration */
  10690. rc = pci_enable_pcie_error_reporting(pdev);
  10691. if (!rc)
  10692. bp->flags |= AER_ENABLED;
  10693. else
  10694. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10695. /*
  10696. * Clean the following indirect addresses for all functions since it
  10697. * is not used by the driver.
  10698. */
  10699. if (IS_PF(bp)) {
  10700. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10701. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10702. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10703. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10704. if (chip_is_e1x) {
  10705. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10706. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10707. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10708. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10709. }
  10710. /* Enable internal target-read (in case we are probed after PF
  10711. * FLR). Must be done prior to any BAR read access. Only for
  10712. * 57712 and up
  10713. */
  10714. if (!chip_is_e1x)
  10715. REG_WR(bp,
  10716. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10717. }
  10718. dev->watchdog_timeo = TX_TIMEOUT;
  10719. dev->netdev_ops = &bnx2x_netdev_ops;
  10720. bnx2x_set_ethtool_ops(bp, dev);
  10721. dev->priv_flags |= IFF_UNICAST_FLT;
  10722. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10723. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10724. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10725. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10726. if (!CHIP_IS_E1x(bp)) {
  10727. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10728. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10729. dev->hw_enc_features =
  10730. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10731. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10732. NETIF_F_GSO_IPIP |
  10733. NETIF_F_GSO_SIT |
  10734. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10735. }
  10736. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10737. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10738. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10739. dev->features |= NETIF_F_HIGHDMA;
  10740. /* Add Loopback capability to the device */
  10741. dev->hw_features |= NETIF_F_LOOPBACK;
  10742. #ifdef BCM_DCBNL
  10743. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10744. #endif
  10745. /* get_port_hwinfo() will set prtad and mmds properly */
  10746. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10747. bp->mdio.mmds = 0;
  10748. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10749. bp->mdio.dev = dev;
  10750. bp->mdio.mdio_read = bnx2x_mdio_read;
  10751. bp->mdio.mdio_write = bnx2x_mdio_write;
  10752. return 0;
  10753. err_out_release:
  10754. if (atomic_read(&pdev->enable_cnt) == 1)
  10755. pci_release_regions(pdev);
  10756. err_out_disable:
  10757. pci_disable_device(pdev);
  10758. err_out:
  10759. return rc;
  10760. }
  10761. static int bnx2x_check_firmware(struct bnx2x *bp)
  10762. {
  10763. const struct firmware *firmware = bp->firmware;
  10764. struct bnx2x_fw_file_hdr *fw_hdr;
  10765. struct bnx2x_fw_file_section *sections;
  10766. u32 offset, len, num_ops;
  10767. __be16 *ops_offsets;
  10768. int i;
  10769. const u8 *fw_ver;
  10770. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10771. BNX2X_ERR("Wrong FW size\n");
  10772. return -EINVAL;
  10773. }
  10774. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10775. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10776. /* Make sure none of the offsets and sizes make us read beyond
  10777. * the end of the firmware data */
  10778. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10779. offset = be32_to_cpu(sections[i].offset);
  10780. len = be32_to_cpu(sections[i].len);
  10781. if (offset + len > firmware->size) {
  10782. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10783. return -EINVAL;
  10784. }
  10785. }
  10786. /* Likewise for the init_ops offsets */
  10787. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10788. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10789. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10790. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10791. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10792. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10793. return -EINVAL;
  10794. }
  10795. }
  10796. /* Check FW version */
  10797. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10798. fw_ver = firmware->data + offset;
  10799. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10800. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10801. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10802. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10803. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10804. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10805. BCM_5710_FW_MAJOR_VERSION,
  10806. BCM_5710_FW_MINOR_VERSION,
  10807. BCM_5710_FW_REVISION_VERSION,
  10808. BCM_5710_FW_ENGINEERING_VERSION);
  10809. return -EINVAL;
  10810. }
  10811. return 0;
  10812. }
  10813. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10814. {
  10815. const __be32 *source = (const __be32 *)_source;
  10816. u32 *target = (u32 *)_target;
  10817. u32 i;
  10818. for (i = 0; i < n/4; i++)
  10819. target[i] = be32_to_cpu(source[i]);
  10820. }
  10821. /*
  10822. Ops array is stored in the following format:
  10823. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10824. */
  10825. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10826. {
  10827. const __be32 *source = (const __be32 *)_source;
  10828. struct raw_op *target = (struct raw_op *)_target;
  10829. u32 i, j, tmp;
  10830. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10831. tmp = be32_to_cpu(source[j]);
  10832. target[i].op = (tmp >> 24) & 0xff;
  10833. target[i].offset = tmp & 0xffffff;
  10834. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10835. }
  10836. }
  10837. /* IRO array is stored in the following format:
  10838. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10839. */
  10840. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10841. {
  10842. const __be32 *source = (const __be32 *)_source;
  10843. struct iro *target = (struct iro *)_target;
  10844. u32 i, j, tmp;
  10845. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10846. target[i].base = be32_to_cpu(source[j]);
  10847. j++;
  10848. tmp = be32_to_cpu(source[j]);
  10849. target[i].m1 = (tmp >> 16) & 0xffff;
  10850. target[i].m2 = tmp & 0xffff;
  10851. j++;
  10852. tmp = be32_to_cpu(source[j]);
  10853. target[i].m3 = (tmp >> 16) & 0xffff;
  10854. target[i].size = tmp & 0xffff;
  10855. j++;
  10856. }
  10857. }
  10858. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10859. {
  10860. const __be16 *source = (const __be16 *)_source;
  10861. u16 *target = (u16 *)_target;
  10862. u32 i;
  10863. for (i = 0; i < n/2; i++)
  10864. target[i] = be16_to_cpu(source[i]);
  10865. }
  10866. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10867. do { \
  10868. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10869. bp->arr = kmalloc(len, GFP_KERNEL); \
  10870. if (!bp->arr) \
  10871. goto lbl; \
  10872. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10873. (u8 *)bp->arr, len); \
  10874. } while (0)
  10875. static int bnx2x_init_firmware(struct bnx2x *bp)
  10876. {
  10877. const char *fw_file_name;
  10878. struct bnx2x_fw_file_hdr *fw_hdr;
  10879. int rc;
  10880. if (bp->firmware)
  10881. return 0;
  10882. if (CHIP_IS_E1(bp))
  10883. fw_file_name = FW_FILE_NAME_E1;
  10884. else if (CHIP_IS_E1H(bp))
  10885. fw_file_name = FW_FILE_NAME_E1H;
  10886. else if (!CHIP_IS_E1x(bp))
  10887. fw_file_name = FW_FILE_NAME_E2;
  10888. else {
  10889. BNX2X_ERR("Unsupported chip revision\n");
  10890. return -EINVAL;
  10891. }
  10892. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10893. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10894. if (rc) {
  10895. BNX2X_ERR("Can't load firmware file %s\n",
  10896. fw_file_name);
  10897. goto request_firmware_exit;
  10898. }
  10899. rc = bnx2x_check_firmware(bp);
  10900. if (rc) {
  10901. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10902. goto request_firmware_exit;
  10903. }
  10904. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10905. /* Initialize the pointers to the init arrays */
  10906. /* Blob */
  10907. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10908. /* Opcodes */
  10909. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10910. /* Offsets */
  10911. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10912. be16_to_cpu_n);
  10913. /* STORMs firmware */
  10914. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10915. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10916. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10917. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10918. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10919. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10920. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10921. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10922. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10923. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10924. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10925. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10926. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10927. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10928. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10929. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10930. /* IRO */
  10931. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10932. return 0;
  10933. iro_alloc_err:
  10934. kfree(bp->init_ops_offsets);
  10935. init_offsets_alloc_err:
  10936. kfree(bp->init_ops);
  10937. init_ops_alloc_err:
  10938. kfree(bp->init_data);
  10939. request_firmware_exit:
  10940. release_firmware(bp->firmware);
  10941. bp->firmware = NULL;
  10942. return rc;
  10943. }
  10944. static void bnx2x_release_firmware(struct bnx2x *bp)
  10945. {
  10946. kfree(bp->init_ops_offsets);
  10947. kfree(bp->init_ops);
  10948. kfree(bp->init_data);
  10949. release_firmware(bp->firmware);
  10950. bp->firmware = NULL;
  10951. }
  10952. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10953. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10954. .init_hw_cmn = bnx2x_init_hw_common,
  10955. .init_hw_port = bnx2x_init_hw_port,
  10956. .init_hw_func = bnx2x_init_hw_func,
  10957. .reset_hw_cmn = bnx2x_reset_common,
  10958. .reset_hw_port = bnx2x_reset_port,
  10959. .reset_hw_func = bnx2x_reset_func,
  10960. .gunzip_init = bnx2x_gunzip_init,
  10961. .gunzip_end = bnx2x_gunzip_end,
  10962. .init_fw = bnx2x_init_firmware,
  10963. .release_fw = bnx2x_release_firmware,
  10964. };
  10965. void bnx2x__init_func_obj(struct bnx2x *bp)
  10966. {
  10967. /* Prepare DMAE related driver resources */
  10968. bnx2x_setup_dmae(bp);
  10969. bnx2x_init_func_obj(bp, &bp->func_obj,
  10970. bnx2x_sp(bp, func_rdata),
  10971. bnx2x_sp_mapping(bp, func_rdata),
  10972. bnx2x_sp(bp, func_afex_rdata),
  10973. bnx2x_sp_mapping(bp, func_afex_rdata),
  10974. &bnx2x_func_sp_drv);
  10975. }
  10976. /* must be called after sriov-enable */
  10977. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10978. {
  10979. int cid_count = BNX2X_L2_MAX_CID(bp);
  10980. if (IS_SRIOV(bp))
  10981. cid_count += BNX2X_VF_CIDS;
  10982. if (CNIC_SUPPORT(bp))
  10983. cid_count += CNIC_CID_MAX;
  10984. return roundup(cid_count, QM_CID_ROUND);
  10985. }
  10986. /**
  10987. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10988. *
  10989. * @dev: pci device
  10990. *
  10991. */
  10992. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10993. {
  10994. int index;
  10995. u16 control = 0;
  10996. /*
  10997. * If MSI-X is not supported - return number of SBs needed to support
  10998. * one fast path queue: one FP queue + SB for CNIC
  10999. */
  11000. if (!pdev->msix_cap) {
  11001. dev_info(&pdev->dev, "no msix capability found\n");
  11002. return 1 + cnic_cnt;
  11003. }
  11004. dev_info(&pdev->dev, "msix capability found\n");
  11005. /*
  11006. * The value in the PCI configuration space is the index of the last
  11007. * entry, namely one less than the actual size of the table, which is
  11008. * exactly what we want to return from this function: number of all SBs
  11009. * without the default SB.
  11010. * For VFs there is no default SB, then we return (index+1).
  11011. */
  11012. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11013. index = control & PCI_MSIX_FLAGS_QSIZE;
  11014. return index;
  11015. }
  11016. static int set_max_cos_est(int chip_id)
  11017. {
  11018. switch (chip_id) {
  11019. case BCM57710:
  11020. case BCM57711:
  11021. case BCM57711E:
  11022. return BNX2X_MULTI_TX_COS_E1X;
  11023. case BCM57712:
  11024. case BCM57712_MF:
  11025. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11026. case BCM57800:
  11027. case BCM57800_MF:
  11028. case BCM57810:
  11029. case BCM57810_MF:
  11030. case BCM57840_4_10:
  11031. case BCM57840_2_20:
  11032. case BCM57840_O:
  11033. case BCM57840_MFO:
  11034. case BCM57840_MF:
  11035. case BCM57811:
  11036. case BCM57811_MF:
  11037. return BNX2X_MULTI_TX_COS_E3B0;
  11038. case BCM57712_VF:
  11039. case BCM57800_VF:
  11040. case BCM57810_VF:
  11041. case BCM57840_VF:
  11042. case BCM57811_VF:
  11043. return 1;
  11044. default:
  11045. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11046. return -ENODEV;
  11047. }
  11048. }
  11049. static int set_is_vf(int chip_id)
  11050. {
  11051. switch (chip_id) {
  11052. case BCM57712_VF:
  11053. case BCM57800_VF:
  11054. case BCM57810_VF:
  11055. case BCM57840_VF:
  11056. case BCM57811_VF:
  11057. return true;
  11058. default:
  11059. return false;
  11060. }
  11061. }
  11062. /* nig_tsgen registers relative address */
  11063. #define tsgen_ctrl 0x0
  11064. #define tsgen_freecount 0x10
  11065. #define tsgen_synctime_t0 0x20
  11066. #define tsgen_offset_t0 0x28
  11067. #define tsgen_drift_t0 0x30
  11068. #define tsgen_synctime_t1 0x58
  11069. #define tsgen_offset_t1 0x60
  11070. #define tsgen_drift_t1 0x68
  11071. /* FW workaround for setting drift */
  11072. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11073. int best_val, int best_period)
  11074. {
  11075. struct bnx2x_func_state_params func_params = {NULL};
  11076. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11077. &func_params.params.set_timesync;
  11078. /* Prepare parameters for function state transitions */
  11079. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11080. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11081. func_params.f_obj = &bp->func_obj;
  11082. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11083. /* Function parameters */
  11084. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11085. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11086. set_timesync_params->add_sub_drift_adjust_value =
  11087. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11088. set_timesync_params->drift_adjust_value = best_val;
  11089. set_timesync_params->drift_adjust_period = best_period;
  11090. return bnx2x_func_state_change(bp, &func_params);
  11091. }
  11092. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11093. {
  11094. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11095. int rc;
  11096. int drift_dir = 1;
  11097. int val, period, period1, period2, dif, dif1, dif2;
  11098. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11099. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11100. if (!netif_running(bp->dev)) {
  11101. DP(BNX2X_MSG_PTP,
  11102. "PTP adjfreq called while the interface is down\n");
  11103. return -EFAULT;
  11104. }
  11105. if (ppb < 0) {
  11106. ppb = -ppb;
  11107. drift_dir = 0;
  11108. }
  11109. if (ppb == 0) {
  11110. best_val = 1;
  11111. best_period = 0x1FFFFFF;
  11112. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11113. best_val = 31;
  11114. best_period = 1;
  11115. } else {
  11116. /* Changed not to allow val = 8, 16, 24 as these values
  11117. * are not supported in workaround.
  11118. */
  11119. for (val = 0; val <= 31; val++) {
  11120. if ((val & 0x7) == 0)
  11121. continue;
  11122. period1 = val * 1000000 / ppb;
  11123. period2 = period1 + 1;
  11124. if (period1 != 0)
  11125. dif1 = ppb - (val * 1000000 / period1);
  11126. else
  11127. dif1 = BNX2X_MAX_PHC_DRIFT;
  11128. if (dif1 < 0)
  11129. dif1 = -dif1;
  11130. dif2 = ppb - (val * 1000000 / period2);
  11131. if (dif2 < 0)
  11132. dif2 = -dif2;
  11133. dif = (dif1 < dif2) ? dif1 : dif2;
  11134. period = (dif1 < dif2) ? period1 : period2;
  11135. if (dif < best_dif) {
  11136. best_dif = dif;
  11137. best_val = val;
  11138. best_period = period;
  11139. }
  11140. }
  11141. }
  11142. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11143. best_period);
  11144. if (rc) {
  11145. BNX2X_ERR("Failed to set drift\n");
  11146. return -EFAULT;
  11147. }
  11148. DP(BNX2X_MSG_PTP, "Configrued val = %d, period = %d\n", best_val,
  11149. best_period);
  11150. return 0;
  11151. }
  11152. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11153. {
  11154. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11155. u64 now;
  11156. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11157. now = timecounter_read(&bp->timecounter);
  11158. now += delta;
  11159. /* Re-init the timecounter */
  11160. timecounter_init(&bp->timecounter, &bp->cyclecounter, now);
  11161. return 0;
  11162. }
  11163. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts)
  11164. {
  11165. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11166. u64 ns;
  11167. u32 remainder;
  11168. ns = timecounter_read(&bp->timecounter);
  11169. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11170. ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
  11171. ts->tv_nsec = remainder;
  11172. return 0;
  11173. }
  11174. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11175. const struct timespec *ts)
  11176. {
  11177. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11178. u64 ns;
  11179. ns = ts->tv_sec * 1000000000ULL;
  11180. ns += ts->tv_nsec;
  11181. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11182. /* Re-init the timecounter */
  11183. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11184. return 0;
  11185. }
  11186. /* Enable (or disable) ancillary features of the phc subsystem */
  11187. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11188. struct ptp_clock_request *rq, int on)
  11189. {
  11190. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11191. BNX2X_ERR("PHC ancillary features are not supported\n");
  11192. return -ENOTSUPP;
  11193. }
  11194. void bnx2x_register_phc(struct bnx2x *bp)
  11195. {
  11196. /* Fill the ptp_clock_info struct and register PTP clock*/
  11197. bp->ptp_clock_info.owner = THIS_MODULE;
  11198. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11199. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11200. bp->ptp_clock_info.n_alarm = 0;
  11201. bp->ptp_clock_info.n_ext_ts = 0;
  11202. bp->ptp_clock_info.n_per_out = 0;
  11203. bp->ptp_clock_info.pps = 0;
  11204. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11205. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11206. bp->ptp_clock_info.gettime = bnx2x_ptp_gettime;
  11207. bp->ptp_clock_info.settime = bnx2x_ptp_settime;
  11208. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11209. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11210. if (IS_ERR(bp->ptp_clock)) {
  11211. bp->ptp_clock = NULL;
  11212. BNX2X_ERR("PTP clock registeration failed\n");
  11213. }
  11214. }
  11215. static int bnx2x_init_one(struct pci_dev *pdev,
  11216. const struct pci_device_id *ent)
  11217. {
  11218. struct net_device *dev = NULL;
  11219. struct bnx2x *bp;
  11220. enum pcie_link_width pcie_width;
  11221. enum pci_bus_speed pcie_speed;
  11222. int rc, max_non_def_sbs;
  11223. int rx_count, tx_count, rss_count, doorbell_size;
  11224. int max_cos_est;
  11225. bool is_vf;
  11226. int cnic_cnt;
  11227. /* An estimated maximum supported CoS number according to the chip
  11228. * version.
  11229. * We will try to roughly estimate the maximum number of CoSes this chip
  11230. * may support in order to minimize the memory allocated for Tx
  11231. * netdev_queue's. This number will be accurately calculated during the
  11232. * initialization of bp->max_cos based on the chip versions AND chip
  11233. * revision in the bnx2x_init_bp().
  11234. */
  11235. max_cos_est = set_max_cos_est(ent->driver_data);
  11236. if (max_cos_est < 0)
  11237. return max_cos_est;
  11238. is_vf = set_is_vf(ent->driver_data);
  11239. cnic_cnt = is_vf ? 0 : 1;
  11240. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11241. /* add another SB for VF as it has no default SB */
  11242. max_non_def_sbs += is_vf ? 1 : 0;
  11243. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11244. rss_count = max_non_def_sbs - cnic_cnt;
  11245. if (rss_count < 1)
  11246. return -EINVAL;
  11247. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11248. rx_count = rss_count + cnic_cnt;
  11249. /* Maximum number of netdev Tx queues:
  11250. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11251. */
  11252. tx_count = rss_count * max_cos_est + cnic_cnt;
  11253. /* dev zeroed in init_etherdev */
  11254. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11255. if (!dev)
  11256. return -ENOMEM;
  11257. bp = netdev_priv(dev);
  11258. bp->flags = 0;
  11259. if (is_vf)
  11260. bp->flags |= IS_VF_FLAG;
  11261. bp->igu_sb_cnt = max_non_def_sbs;
  11262. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11263. bp->msg_enable = debug;
  11264. bp->cnic_support = cnic_cnt;
  11265. bp->cnic_probe = bnx2x_cnic_probe;
  11266. pci_set_drvdata(pdev, dev);
  11267. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11268. if (rc < 0) {
  11269. free_netdev(dev);
  11270. return rc;
  11271. }
  11272. BNX2X_DEV_INFO("This is a %s function\n",
  11273. IS_PF(bp) ? "physical" : "virtual");
  11274. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11275. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11276. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11277. tx_count, rx_count);
  11278. rc = bnx2x_init_bp(bp);
  11279. if (rc)
  11280. goto init_one_exit;
  11281. /* Map doorbells here as we need the real value of bp->max_cos which
  11282. * is initialized in bnx2x_init_bp() to determine the number of
  11283. * l2 connections.
  11284. */
  11285. if (IS_VF(bp)) {
  11286. bp->doorbells = bnx2x_vf_doorbells(bp);
  11287. rc = bnx2x_vf_pci_alloc(bp);
  11288. if (rc)
  11289. goto init_one_exit;
  11290. } else {
  11291. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11292. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11293. dev_err(&bp->pdev->dev,
  11294. "Cannot map doorbells, bar size too small, aborting\n");
  11295. rc = -ENOMEM;
  11296. goto init_one_exit;
  11297. }
  11298. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11299. doorbell_size);
  11300. }
  11301. if (!bp->doorbells) {
  11302. dev_err(&bp->pdev->dev,
  11303. "Cannot map doorbell space, aborting\n");
  11304. rc = -ENOMEM;
  11305. goto init_one_exit;
  11306. }
  11307. if (IS_VF(bp)) {
  11308. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11309. if (rc)
  11310. goto init_one_exit;
  11311. }
  11312. /* Enable SRIOV if capability found in configuration space */
  11313. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11314. if (rc)
  11315. goto init_one_exit;
  11316. /* calc qm_cid_count */
  11317. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11318. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11319. /* disable FCOE L2 queue for E1x*/
  11320. if (CHIP_IS_E1x(bp))
  11321. bp->flags |= NO_FCOE_FLAG;
  11322. /* Set bp->num_queues for MSI-X mode*/
  11323. bnx2x_set_num_queues(bp);
  11324. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11325. * needed.
  11326. */
  11327. rc = bnx2x_set_int_mode(bp);
  11328. if (rc) {
  11329. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11330. goto init_one_exit;
  11331. }
  11332. BNX2X_DEV_INFO("set interrupts successfully\n");
  11333. /* register the net device */
  11334. rc = register_netdev(dev);
  11335. if (rc) {
  11336. dev_err(&pdev->dev, "Cannot register net device\n");
  11337. goto init_one_exit;
  11338. }
  11339. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11340. if (!NO_FCOE(bp)) {
  11341. /* Add storage MAC address */
  11342. rtnl_lock();
  11343. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11344. rtnl_unlock();
  11345. }
  11346. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11347. pcie_speed == PCI_SPEED_UNKNOWN ||
  11348. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11349. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11350. else
  11351. BNX2X_DEV_INFO(
  11352. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11353. board_info[ent->driver_data].name,
  11354. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11355. pcie_width,
  11356. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11357. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11358. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11359. "Unknown",
  11360. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11361. bnx2x_register_phc(bp);
  11362. return 0;
  11363. init_one_exit:
  11364. bnx2x_disable_pcie_error_reporting(bp);
  11365. if (bp->regview)
  11366. iounmap(bp->regview);
  11367. if (IS_PF(bp) && bp->doorbells)
  11368. iounmap(bp->doorbells);
  11369. free_netdev(dev);
  11370. if (atomic_read(&pdev->enable_cnt) == 1)
  11371. pci_release_regions(pdev);
  11372. pci_disable_device(pdev);
  11373. return rc;
  11374. }
  11375. static void __bnx2x_remove(struct pci_dev *pdev,
  11376. struct net_device *dev,
  11377. struct bnx2x *bp,
  11378. bool remove_netdev)
  11379. {
  11380. if (bp->ptp_clock) {
  11381. ptp_clock_unregister(bp->ptp_clock);
  11382. bp->ptp_clock = NULL;
  11383. }
  11384. /* Delete storage MAC address */
  11385. if (!NO_FCOE(bp)) {
  11386. rtnl_lock();
  11387. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11388. rtnl_unlock();
  11389. }
  11390. #ifdef BCM_DCBNL
  11391. /* Delete app tlvs from dcbnl */
  11392. bnx2x_dcbnl_update_applist(bp, true);
  11393. #endif
  11394. if (IS_PF(bp) &&
  11395. !BP_NOMCP(bp) &&
  11396. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11397. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11398. /* Close the interface - either directly or implicitly */
  11399. if (remove_netdev) {
  11400. unregister_netdev(dev);
  11401. } else {
  11402. rtnl_lock();
  11403. dev_close(dev);
  11404. rtnl_unlock();
  11405. }
  11406. bnx2x_iov_remove_one(bp);
  11407. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11408. if (IS_PF(bp)) {
  11409. bnx2x_set_power_state(bp, PCI_D0);
  11410. /* Set endianity registers to reset values in case next driver
  11411. * boots in different endianty environment.
  11412. */
  11413. bnx2x_reset_endianity(bp);
  11414. }
  11415. /* Disable MSI/MSI-X */
  11416. bnx2x_disable_msi(bp);
  11417. /* Power off */
  11418. if (IS_PF(bp))
  11419. bnx2x_set_power_state(bp, PCI_D3hot);
  11420. /* Make sure RESET task is not scheduled before continuing */
  11421. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11422. /* send message via vfpf channel to release the resources of this vf */
  11423. if (IS_VF(bp))
  11424. bnx2x_vfpf_release(bp);
  11425. /* Assumes no further PCIe PM changes will occur */
  11426. if (system_state == SYSTEM_POWER_OFF) {
  11427. pci_wake_from_d3(pdev, bp->wol);
  11428. pci_set_power_state(pdev, PCI_D3hot);
  11429. }
  11430. bnx2x_disable_pcie_error_reporting(bp);
  11431. if (remove_netdev) {
  11432. if (bp->regview)
  11433. iounmap(bp->regview);
  11434. /* For vfs, doorbells are part of the regview and were unmapped
  11435. * along with it. FW is only loaded by PF.
  11436. */
  11437. if (IS_PF(bp)) {
  11438. if (bp->doorbells)
  11439. iounmap(bp->doorbells);
  11440. bnx2x_release_firmware(bp);
  11441. } else {
  11442. bnx2x_vf_pci_dealloc(bp);
  11443. }
  11444. bnx2x_free_mem_bp(bp);
  11445. free_netdev(dev);
  11446. if (atomic_read(&pdev->enable_cnt) == 1)
  11447. pci_release_regions(pdev);
  11448. pci_disable_device(pdev);
  11449. }
  11450. }
  11451. static void bnx2x_remove_one(struct pci_dev *pdev)
  11452. {
  11453. struct net_device *dev = pci_get_drvdata(pdev);
  11454. struct bnx2x *bp;
  11455. if (!dev) {
  11456. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11457. return;
  11458. }
  11459. bp = netdev_priv(dev);
  11460. __bnx2x_remove(pdev, dev, bp, true);
  11461. }
  11462. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11463. {
  11464. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11465. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11466. if (CNIC_LOADED(bp))
  11467. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11468. /* Stop Tx */
  11469. bnx2x_tx_disable(bp);
  11470. /* Delete all NAPI objects */
  11471. bnx2x_del_all_napi(bp);
  11472. if (CNIC_LOADED(bp))
  11473. bnx2x_del_all_napi_cnic(bp);
  11474. netdev_reset_tc(bp->dev);
  11475. del_timer_sync(&bp->timer);
  11476. cancel_delayed_work_sync(&bp->sp_task);
  11477. cancel_delayed_work_sync(&bp->period_task);
  11478. spin_lock_bh(&bp->stats_lock);
  11479. bp->stats_state = STATS_STATE_DISABLED;
  11480. spin_unlock_bh(&bp->stats_lock);
  11481. bnx2x_save_statistics(bp);
  11482. netif_carrier_off(bp->dev);
  11483. return 0;
  11484. }
  11485. /**
  11486. * bnx2x_io_error_detected - called when PCI error is detected
  11487. * @pdev: Pointer to PCI device
  11488. * @state: The current pci connection state
  11489. *
  11490. * This function is called after a PCI bus error affecting
  11491. * this device has been detected.
  11492. */
  11493. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11494. pci_channel_state_t state)
  11495. {
  11496. struct net_device *dev = pci_get_drvdata(pdev);
  11497. struct bnx2x *bp = netdev_priv(dev);
  11498. rtnl_lock();
  11499. BNX2X_ERR("IO error detected\n");
  11500. netif_device_detach(dev);
  11501. if (state == pci_channel_io_perm_failure) {
  11502. rtnl_unlock();
  11503. return PCI_ERS_RESULT_DISCONNECT;
  11504. }
  11505. if (netif_running(dev))
  11506. bnx2x_eeh_nic_unload(bp);
  11507. bnx2x_prev_path_mark_eeh(bp);
  11508. pci_disable_device(pdev);
  11509. rtnl_unlock();
  11510. /* Request a slot reset */
  11511. return PCI_ERS_RESULT_NEED_RESET;
  11512. }
  11513. /**
  11514. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11515. * @pdev: Pointer to PCI device
  11516. *
  11517. * Restart the card from scratch, as if from a cold-boot.
  11518. */
  11519. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11520. {
  11521. struct net_device *dev = pci_get_drvdata(pdev);
  11522. struct bnx2x *bp = netdev_priv(dev);
  11523. int i;
  11524. rtnl_lock();
  11525. BNX2X_ERR("IO slot reset initializing...\n");
  11526. if (pci_enable_device(pdev)) {
  11527. dev_err(&pdev->dev,
  11528. "Cannot re-enable PCI device after reset\n");
  11529. rtnl_unlock();
  11530. return PCI_ERS_RESULT_DISCONNECT;
  11531. }
  11532. pci_set_master(pdev);
  11533. pci_restore_state(pdev);
  11534. pci_save_state(pdev);
  11535. if (netif_running(dev))
  11536. bnx2x_set_power_state(bp, PCI_D0);
  11537. if (netif_running(dev)) {
  11538. BNX2X_ERR("IO slot reset --> driver unload\n");
  11539. /* MCP should have been reset; Need to wait for validity */
  11540. bnx2x_init_shmem(bp);
  11541. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11542. u32 v;
  11543. v = SHMEM2_RD(bp,
  11544. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11545. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11546. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11547. }
  11548. bnx2x_drain_tx_queues(bp);
  11549. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11550. bnx2x_netif_stop(bp, 1);
  11551. bnx2x_free_irq(bp);
  11552. /* Report UNLOAD_DONE to MCP */
  11553. bnx2x_send_unload_done(bp, true);
  11554. bp->sp_state = 0;
  11555. bp->port.pmf = 0;
  11556. bnx2x_prev_unload(bp);
  11557. /* We should have reseted the engine, so It's fair to
  11558. * assume the FW will no longer write to the bnx2x driver.
  11559. */
  11560. bnx2x_squeeze_objects(bp);
  11561. bnx2x_free_skbs(bp);
  11562. for_each_rx_queue(bp, i)
  11563. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11564. bnx2x_free_fp_mem(bp);
  11565. bnx2x_free_mem(bp);
  11566. bp->state = BNX2X_STATE_CLOSED;
  11567. }
  11568. rtnl_unlock();
  11569. /* If AER, perform cleanup of the PCIe registers */
  11570. if (bp->flags & AER_ENABLED) {
  11571. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11572. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11573. else
  11574. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11575. }
  11576. return PCI_ERS_RESULT_RECOVERED;
  11577. }
  11578. /**
  11579. * bnx2x_io_resume - called when traffic can start flowing again
  11580. * @pdev: Pointer to PCI device
  11581. *
  11582. * This callback is called when the error recovery driver tells us that
  11583. * its OK to resume normal operation.
  11584. */
  11585. static void bnx2x_io_resume(struct pci_dev *pdev)
  11586. {
  11587. struct net_device *dev = pci_get_drvdata(pdev);
  11588. struct bnx2x *bp = netdev_priv(dev);
  11589. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11590. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11591. return;
  11592. }
  11593. rtnl_lock();
  11594. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11595. DRV_MSG_SEQ_NUMBER_MASK;
  11596. if (netif_running(dev))
  11597. bnx2x_nic_load(bp, LOAD_NORMAL);
  11598. netif_device_attach(dev);
  11599. rtnl_unlock();
  11600. }
  11601. static const struct pci_error_handlers bnx2x_err_handler = {
  11602. .error_detected = bnx2x_io_error_detected,
  11603. .slot_reset = bnx2x_io_slot_reset,
  11604. .resume = bnx2x_io_resume,
  11605. };
  11606. static void bnx2x_shutdown(struct pci_dev *pdev)
  11607. {
  11608. struct net_device *dev = pci_get_drvdata(pdev);
  11609. struct bnx2x *bp;
  11610. if (!dev)
  11611. return;
  11612. bp = netdev_priv(dev);
  11613. if (!bp)
  11614. return;
  11615. rtnl_lock();
  11616. netif_device_detach(dev);
  11617. rtnl_unlock();
  11618. /* Don't remove the netdevice, as there are scenarios which will cause
  11619. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11620. * rootfs is mounted from SAN.
  11621. */
  11622. __bnx2x_remove(pdev, dev, bp, false);
  11623. }
  11624. static struct pci_driver bnx2x_pci_driver = {
  11625. .name = DRV_MODULE_NAME,
  11626. .id_table = bnx2x_pci_tbl,
  11627. .probe = bnx2x_init_one,
  11628. .remove = bnx2x_remove_one,
  11629. .suspend = bnx2x_suspend,
  11630. .resume = bnx2x_resume,
  11631. .err_handler = &bnx2x_err_handler,
  11632. #ifdef CONFIG_BNX2X_SRIOV
  11633. .sriov_configure = bnx2x_sriov_configure,
  11634. #endif
  11635. .shutdown = bnx2x_shutdown,
  11636. };
  11637. static int __init bnx2x_init(void)
  11638. {
  11639. int ret;
  11640. pr_info("%s", version);
  11641. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11642. if (bnx2x_wq == NULL) {
  11643. pr_err("Cannot create workqueue\n");
  11644. return -ENOMEM;
  11645. }
  11646. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11647. if (!bnx2x_iov_wq) {
  11648. pr_err("Cannot create iov workqueue\n");
  11649. destroy_workqueue(bnx2x_wq);
  11650. return -ENOMEM;
  11651. }
  11652. ret = pci_register_driver(&bnx2x_pci_driver);
  11653. if (ret) {
  11654. pr_err("Cannot register driver\n");
  11655. destroy_workqueue(bnx2x_wq);
  11656. destroy_workqueue(bnx2x_iov_wq);
  11657. }
  11658. return ret;
  11659. }
  11660. static void __exit bnx2x_cleanup(void)
  11661. {
  11662. struct list_head *pos, *q;
  11663. pci_unregister_driver(&bnx2x_pci_driver);
  11664. destroy_workqueue(bnx2x_wq);
  11665. destroy_workqueue(bnx2x_iov_wq);
  11666. /* Free globally allocated resources */
  11667. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11668. struct bnx2x_prev_path_list *tmp =
  11669. list_entry(pos, struct bnx2x_prev_path_list, list);
  11670. list_del(pos);
  11671. kfree(tmp);
  11672. }
  11673. }
  11674. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11675. {
  11676. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11677. }
  11678. module_init(bnx2x_init);
  11679. module_exit(bnx2x_cleanup);
  11680. /**
  11681. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11682. *
  11683. * @bp: driver handle
  11684. * @set: set or clear the CAM entry
  11685. *
  11686. * This function will wait until the ramrod completion returns.
  11687. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11688. */
  11689. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11690. {
  11691. unsigned long ramrod_flags = 0;
  11692. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11693. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11694. &bp->iscsi_l2_mac_obj, true,
  11695. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11696. }
  11697. /* count denotes the number of new completions we have seen */
  11698. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11699. {
  11700. struct eth_spe *spe;
  11701. int cxt_index, cxt_offset;
  11702. #ifdef BNX2X_STOP_ON_ERROR
  11703. if (unlikely(bp->panic))
  11704. return;
  11705. #endif
  11706. spin_lock_bh(&bp->spq_lock);
  11707. BUG_ON(bp->cnic_spq_pending < count);
  11708. bp->cnic_spq_pending -= count;
  11709. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11710. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11711. & SPE_HDR_CONN_TYPE) >>
  11712. SPE_HDR_CONN_TYPE_SHIFT;
  11713. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11714. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11715. /* Set validation for iSCSI L2 client before sending SETUP
  11716. * ramrod
  11717. */
  11718. if (type == ETH_CONNECTION_TYPE) {
  11719. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11720. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11721. ILT_PAGE_CIDS;
  11722. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11723. (cxt_index * ILT_PAGE_CIDS);
  11724. bnx2x_set_ctx_validation(bp,
  11725. &bp->context[cxt_index].
  11726. vcxt[cxt_offset].eth,
  11727. BNX2X_ISCSI_ETH_CID(bp));
  11728. }
  11729. }
  11730. /*
  11731. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11732. * and in the air. We also check that number of outstanding
  11733. * COMMON ramrods is not more than the EQ and SPQ can
  11734. * accommodate.
  11735. */
  11736. if (type == ETH_CONNECTION_TYPE) {
  11737. if (!atomic_read(&bp->cq_spq_left))
  11738. break;
  11739. else
  11740. atomic_dec(&bp->cq_spq_left);
  11741. } else if (type == NONE_CONNECTION_TYPE) {
  11742. if (!atomic_read(&bp->eq_spq_left))
  11743. break;
  11744. else
  11745. atomic_dec(&bp->eq_spq_left);
  11746. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11747. (type == FCOE_CONNECTION_TYPE)) {
  11748. if (bp->cnic_spq_pending >=
  11749. bp->cnic_eth_dev.max_kwqe_pending)
  11750. break;
  11751. else
  11752. bp->cnic_spq_pending++;
  11753. } else {
  11754. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11755. bnx2x_panic();
  11756. break;
  11757. }
  11758. spe = bnx2x_sp_get_next(bp);
  11759. *spe = *bp->cnic_kwq_cons;
  11760. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11761. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11762. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11763. bp->cnic_kwq_cons = bp->cnic_kwq;
  11764. else
  11765. bp->cnic_kwq_cons++;
  11766. }
  11767. bnx2x_sp_prod_update(bp);
  11768. spin_unlock_bh(&bp->spq_lock);
  11769. }
  11770. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11771. struct kwqe_16 *kwqes[], u32 count)
  11772. {
  11773. struct bnx2x *bp = netdev_priv(dev);
  11774. int i;
  11775. #ifdef BNX2X_STOP_ON_ERROR
  11776. if (unlikely(bp->panic)) {
  11777. BNX2X_ERR("Can't post to SP queue while panic\n");
  11778. return -EIO;
  11779. }
  11780. #endif
  11781. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11782. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11783. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11784. return -EAGAIN;
  11785. }
  11786. spin_lock_bh(&bp->spq_lock);
  11787. for (i = 0; i < count; i++) {
  11788. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11789. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11790. break;
  11791. *bp->cnic_kwq_prod = *spe;
  11792. bp->cnic_kwq_pending++;
  11793. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11794. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11795. spe->data.update_data_addr.hi,
  11796. spe->data.update_data_addr.lo,
  11797. bp->cnic_kwq_pending);
  11798. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11799. bp->cnic_kwq_prod = bp->cnic_kwq;
  11800. else
  11801. bp->cnic_kwq_prod++;
  11802. }
  11803. spin_unlock_bh(&bp->spq_lock);
  11804. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11805. bnx2x_cnic_sp_post(bp, 0);
  11806. return i;
  11807. }
  11808. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11809. {
  11810. struct cnic_ops *c_ops;
  11811. int rc = 0;
  11812. mutex_lock(&bp->cnic_mutex);
  11813. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11814. lockdep_is_held(&bp->cnic_mutex));
  11815. if (c_ops)
  11816. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11817. mutex_unlock(&bp->cnic_mutex);
  11818. return rc;
  11819. }
  11820. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11821. {
  11822. struct cnic_ops *c_ops;
  11823. int rc = 0;
  11824. rcu_read_lock();
  11825. c_ops = rcu_dereference(bp->cnic_ops);
  11826. if (c_ops)
  11827. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11828. rcu_read_unlock();
  11829. return rc;
  11830. }
  11831. /*
  11832. * for commands that have no data
  11833. */
  11834. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11835. {
  11836. struct cnic_ctl_info ctl = {0};
  11837. ctl.cmd = cmd;
  11838. return bnx2x_cnic_ctl_send(bp, &ctl);
  11839. }
  11840. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11841. {
  11842. struct cnic_ctl_info ctl = {0};
  11843. /* first we tell CNIC and only then we count this as a completion */
  11844. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11845. ctl.data.comp.cid = cid;
  11846. ctl.data.comp.error = err;
  11847. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11848. bnx2x_cnic_sp_post(bp, 0);
  11849. }
  11850. /* Called with netif_addr_lock_bh() taken.
  11851. * Sets an rx_mode config for an iSCSI ETH client.
  11852. * Doesn't block.
  11853. * Completion should be checked outside.
  11854. */
  11855. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11856. {
  11857. unsigned long accept_flags = 0, ramrod_flags = 0;
  11858. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11859. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11860. if (start) {
  11861. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11862. * because it's the only way for UIO Queue to accept
  11863. * multicasts (in non-promiscuous mode only one Queue per
  11864. * function will receive multicast packets (leading in our
  11865. * case).
  11866. */
  11867. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11868. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11869. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11870. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11871. /* Clear STOP_PENDING bit if START is requested */
  11872. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11873. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11874. } else
  11875. /* Clear START_PENDING bit if STOP is requested */
  11876. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11877. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11878. set_bit(sched_state, &bp->sp_state);
  11879. else {
  11880. __set_bit(RAMROD_RX, &ramrod_flags);
  11881. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11882. ramrod_flags);
  11883. }
  11884. }
  11885. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11886. {
  11887. struct bnx2x *bp = netdev_priv(dev);
  11888. int rc = 0;
  11889. switch (ctl->cmd) {
  11890. case DRV_CTL_CTXTBL_WR_CMD: {
  11891. u32 index = ctl->data.io.offset;
  11892. dma_addr_t addr = ctl->data.io.dma_addr;
  11893. bnx2x_ilt_wr(bp, index, addr);
  11894. break;
  11895. }
  11896. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11897. int count = ctl->data.credit.credit_count;
  11898. bnx2x_cnic_sp_post(bp, count);
  11899. break;
  11900. }
  11901. /* rtnl_lock is held. */
  11902. case DRV_CTL_START_L2_CMD: {
  11903. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11904. unsigned long sp_bits = 0;
  11905. /* Configure the iSCSI classification object */
  11906. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11907. cp->iscsi_l2_client_id,
  11908. cp->iscsi_l2_cid, BP_FUNC(bp),
  11909. bnx2x_sp(bp, mac_rdata),
  11910. bnx2x_sp_mapping(bp, mac_rdata),
  11911. BNX2X_FILTER_MAC_PENDING,
  11912. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11913. &bp->macs_pool);
  11914. /* Set iSCSI MAC address */
  11915. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11916. if (rc)
  11917. break;
  11918. mmiowb();
  11919. barrier();
  11920. /* Start accepting on iSCSI L2 ring */
  11921. netif_addr_lock_bh(dev);
  11922. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11923. netif_addr_unlock_bh(dev);
  11924. /* bits to wait on */
  11925. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11926. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11927. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11928. BNX2X_ERR("rx_mode completion timed out!\n");
  11929. break;
  11930. }
  11931. /* rtnl_lock is held. */
  11932. case DRV_CTL_STOP_L2_CMD: {
  11933. unsigned long sp_bits = 0;
  11934. /* Stop accepting on iSCSI L2 ring */
  11935. netif_addr_lock_bh(dev);
  11936. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11937. netif_addr_unlock_bh(dev);
  11938. /* bits to wait on */
  11939. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11940. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11941. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11942. BNX2X_ERR("rx_mode completion timed out!\n");
  11943. mmiowb();
  11944. barrier();
  11945. /* Unset iSCSI L2 MAC */
  11946. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11947. BNX2X_ISCSI_ETH_MAC, true);
  11948. break;
  11949. }
  11950. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11951. int count = ctl->data.credit.credit_count;
  11952. smp_mb__before_atomic();
  11953. atomic_add(count, &bp->cq_spq_left);
  11954. smp_mb__after_atomic();
  11955. break;
  11956. }
  11957. case DRV_CTL_ULP_REGISTER_CMD: {
  11958. int ulp_type = ctl->data.register_data.ulp_type;
  11959. if (CHIP_IS_E3(bp)) {
  11960. int idx = BP_FW_MB_IDX(bp);
  11961. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11962. int path = BP_PATH(bp);
  11963. int port = BP_PORT(bp);
  11964. int i;
  11965. u32 scratch_offset;
  11966. u32 *host_addr;
  11967. /* first write capability to shmem2 */
  11968. if (ulp_type == CNIC_ULP_ISCSI)
  11969. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11970. else if (ulp_type == CNIC_ULP_FCOE)
  11971. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11972. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11973. if ((ulp_type != CNIC_ULP_FCOE) ||
  11974. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11975. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11976. break;
  11977. /* if reached here - should write fcoe capabilities */
  11978. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11979. if (!scratch_offset)
  11980. break;
  11981. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11982. fcoe_features[path][port]);
  11983. host_addr = (u32 *) &(ctl->data.register_data.
  11984. fcoe_features);
  11985. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11986. i += 4)
  11987. REG_WR(bp, scratch_offset + i,
  11988. *(host_addr + i/4));
  11989. }
  11990. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11991. break;
  11992. }
  11993. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11994. int ulp_type = ctl->data.ulp_type;
  11995. if (CHIP_IS_E3(bp)) {
  11996. int idx = BP_FW_MB_IDX(bp);
  11997. u32 cap;
  11998. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11999. if (ulp_type == CNIC_ULP_ISCSI)
  12000. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12001. else if (ulp_type == CNIC_ULP_FCOE)
  12002. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12003. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12004. }
  12005. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12006. break;
  12007. }
  12008. default:
  12009. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12010. rc = -EINVAL;
  12011. }
  12012. return rc;
  12013. }
  12014. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12015. {
  12016. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12017. if (bp->flags & USING_MSIX_FLAG) {
  12018. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12019. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12020. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12021. } else {
  12022. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12023. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12024. }
  12025. if (!CHIP_IS_E1x(bp))
  12026. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12027. else
  12028. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12029. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12030. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12031. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12032. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12033. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12034. cp->num_irq = 2;
  12035. }
  12036. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12037. {
  12038. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12039. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12040. bnx2x_cid_ilt_lines(bp);
  12041. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12042. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12043. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12044. 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",
  12045. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12046. cp->iscsi_l2_cid);
  12047. if (NO_ISCSI_OOO(bp))
  12048. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12049. }
  12050. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12051. void *data)
  12052. {
  12053. struct bnx2x *bp = netdev_priv(dev);
  12054. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12055. int rc;
  12056. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12057. if (ops == NULL) {
  12058. BNX2X_ERR("NULL ops received\n");
  12059. return -EINVAL;
  12060. }
  12061. if (!CNIC_SUPPORT(bp)) {
  12062. BNX2X_ERR("Can't register CNIC when not supported\n");
  12063. return -EOPNOTSUPP;
  12064. }
  12065. if (!CNIC_LOADED(bp)) {
  12066. rc = bnx2x_load_cnic(bp);
  12067. if (rc) {
  12068. BNX2X_ERR("CNIC-related load failed\n");
  12069. return rc;
  12070. }
  12071. }
  12072. bp->cnic_enabled = true;
  12073. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12074. if (!bp->cnic_kwq)
  12075. return -ENOMEM;
  12076. bp->cnic_kwq_cons = bp->cnic_kwq;
  12077. bp->cnic_kwq_prod = bp->cnic_kwq;
  12078. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12079. bp->cnic_spq_pending = 0;
  12080. bp->cnic_kwq_pending = 0;
  12081. bp->cnic_data = data;
  12082. cp->num_irq = 0;
  12083. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12084. cp->iro_arr = bp->iro_arr;
  12085. bnx2x_setup_cnic_irq_info(bp);
  12086. rcu_assign_pointer(bp->cnic_ops, ops);
  12087. /* Schedule driver to read CNIC driver versions */
  12088. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12089. return 0;
  12090. }
  12091. static int bnx2x_unregister_cnic(struct net_device *dev)
  12092. {
  12093. struct bnx2x *bp = netdev_priv(dev);
  12094. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12095. mutex_lock(&bp->cnic_mutex);
  12096. cp->drv_state = 0;
  12097. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12098. mutex_unlock(&bp->cnic_mutex);
  12099. synchronize_rcu();
  12100. bp->cnic_enabled = false;
  12101. kfree(bp->cnic_kwq);
  12102. bp->cnic_kwq = NULL;
  12103. return 0;
  12104. }
  12105. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12106. {
  12107. struct bnx2x *bp = netdev_priv(dev);
  12108. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12109. /* If both iSCSI and FCoE are disabled - return NULL in
  12110. * order to indicate CNIC that it should not try to work
  12111. * with this device.
  12112. */
  12113. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12114. return NULL;
  12115. cp->drv_owner = THIS_MODULE;
  12116. cp->chip_id = CHIP_ID(bp);
  12117. cp->pdev = bp->pdev;
  12118. cp->io_base = bp->regview;
  12119. cp->io_base2 = bp->doorbells;
  12120. cp->max_kwqe_pending = 8;
  12121. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12122. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12123. bnx2x_cid_ilt_lines(bp);
  12124. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12125. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12126. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12127. cp->drv_ctl = bnx2x_drv_ctl;
  12128. cp->drv_register_cnic = bnx2x_register_cnic;
  12129. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12130. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12131. cp->iscsi_l2_client_id =
  12132. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12133. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12134. if (NO_ISCSI_OOO(bp))
  12135. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12136. if (NO_ISCSI(bp))
  12137. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12138. if (NO_FCOE(bp))
  12139. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12140. BNX2X_DEV_INFO(
  12141. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12142. cp->ctx_blk_size,
  12143. cp->ctx_tbl_offset,
  12144. cp->ctx_tbl_len,
  12145. cp->starting_cid);
  12146. return cp;
  12147. }
  12148. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12149. {
  12150. struct bnx2x *bp = fp->bp;
  12151. u32 offset = BAR_USTRORM_INTMEM;
  12152. if (IS_VF(bp))
  12153. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12154. else if (!CHIP_IS_E1x(bp))
  12155. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12156. else
  12157. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12158. return offset;
  12159. }
  12160. /* called only on E1H or E2.
  12161. * When pretending to be PF, the pretend value is the function number 0...7
  12162. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12163. * combination
  12164. */
  12165. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12166. {
  12167. u32 pretend_reg;
  12168. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12169. return -1;
  12170. /* get my own pretend register */
  12171. pretend_reg = bnx2x_get_pretend_reg(bp);
  12172. REG_WR(bp, pretend_reg, pretend_func_val);
  12173. REG_RD(bp, pretend_reg);
  12174. return 0;
  12175. }
  12176. static void bnx2x_ptp_task(struct work_struct *work)
  12177. {
  12178. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12179. int port = BP_PORT(bp);
  12180. u32 val_seq;
  12181. u64 timestamp, ns;
  12182. struct skb_shared_hwtstamps shhwtstamps;
  12183. /* Read Tx timestamp registers */
  12184. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12185. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12186. if (val_seq & 0x10000) {
  12187. /* There is a valid timestamp value */
  12188. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12189. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12190. timestamp <<= 32;
  12191. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12192. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12193. /* Reset timestamp register to allow new timestamp */
  12194. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12195. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12196. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12197. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12198. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12199. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12200. dev_kfree_skb_any(bp->ptp_tx_skb);
  12201. bp->ptp_tx_skb = NULL;
  12202. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12203. timestamp, ns);
  12204. } else {
  12205. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12206. /* Reschedule to keep checking for a valid timestamp value */
  12207. schedule_work(&bp->ptp_task);
  12208. }
  12209. }
  12210. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12211. {
  12212. int port = BP_PORT(bp);
  12213. u64 timestamp, ns;
  12214. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12215. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12216. timestamp <<= 32;
  12217. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12218. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12219. /* Reset timestamp register to allow new timestamp */
  12220. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12221. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12222. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12223. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12224. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12225. timestamp, ns);
  12226. }
  12227. /* Read the PHC */
  12228. static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12229. {
  12230. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12231. int port = BP_PORT(bp);
  12232. u32 wb_data[2];
  12233. u64 phc_cycles;
  12234. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12235. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12236. phc_cycles = wb_data[1];
  12237. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12238. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12239. return phc_cycles;
  12240. }
  12241. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12242. {
  12243. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12244. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12245. bp->cyclecounter.mask = CLOCKSOURCE_MASK(64);
  12246. bp->cyclecounter.shift = 1;
  12247. bp->cyclecounter.mult = 1;
  12248. }
  12249. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12250. {
  12251. struct bnx2x_func_state_params func_params = {NULL};
  12252. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12253. &func_params.params.set_timesync;
  12254. /* Prepare parameters for function state transitions */
  12255. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12256. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12257. func_params.f_obj = &bp->func_obj;
  12258. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12259. /* Function parameters */
  12260. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12261. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12262. return bnx2x_func_state_change(bp, &func_params);
  12263. }
  12264. int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12265. {
  12266. struct bnx2x_queue_state_params q_params;
  12267. int rc, i;
  12268. /* send queue update ramrod to enable PTP packets */
  12269. memset(&q_params, 0, sizeof(q_params));
  12270. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12271. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12272. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12273. &q_params.params.update.update_flags);
  12274. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12275. &q_params.params.update.update_flags);
  12276. /* send the ramrod on all the queues of the PF */
  12277. for_each_eth_queue(bp, i) {
  12278. struct bnx2x_fastpath *fp = &bp->fp[i];
  12279. /* Set the appropriate Queue object */
  12280. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12281. /* Update the Queue state */
  12282. rc = bnx2x_queue_state_change(bp, &q_params);
  12283. if (rc) {
  12284. BNX2X_ERR("Failed to enable PTP packets\n");
  12285. return rc;
  12286. }
  12287. }
  12288. return 0;
  12289. }
  12290. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12291. {
  12292. int port = BP_PORT(bp);
  12293. int rc;
  12294. if (!bp->hwtstamp_ioctl_called)
  12295. return 0;
  12296. switch (bp->tx_type) {
  12297. case HWTSTAMP_TX_ON:
  12298. bp->flags |= TX_TIMESTAMPING_EN;
  12299. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12300. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12301. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12302. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12303. break;
  12304. case HWTSTAMP_TX_ONESTEP_SYNC:
  12305. BNX2X_ERR("One-step timestamping is not supported\n");
  12306. return -ERANGE;
  12307. }
  12308. switch (bp->rx_filter) {
  12309. case HWTSTAMP_FILTER_NONE:
  12310. break;
  12311. case HWTSTAMP_FILTER_ALL:
  12312. case HWTSTAMP_FILTER_SOME:
  12313. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12314. break;
  12315. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12316. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12317. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12318. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12319. /* Initialize PTP detection for UDP/IPv4 events */
  12320. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12321. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12322. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12323. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12324. break;
  12325. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12326. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12327. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12328. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12329. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12330. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12331. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12332. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12333. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12334. break;
  12335. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12336. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12337. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12338. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12339. /* Initialize PTP detection L2 events */
  12340. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12341. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12342. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12343. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12344. break;
  12345. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12346. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12347. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12348. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12349. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12350. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12351. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12352. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12353. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12354. break;
  12355. }
  12356. /* Indicate to FW that this PF expects recorded PTP packets */
  12357. rc = bnx2x_enable_ptp_packets(bp);
  12358. if (rc)
  12359. return rc;
  12360. /* Enable sending PTP packets to host */
  12361. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12362. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12363. return 0;
  12364. }
  12365. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12366. {
  12367. struct hwtstamp_config config;
  12368. int rc;
  12369. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12370. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12371. return -EFAULT;
  12372. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12373. config.tx_type, config.rx_filter);
  12374. if (config.flags) {
  12375. BNX2X_ERR("config.flags is reserved for future use\n");
  12376. return -EINVAL;
  12377. }
  12378. bp->hwtstamp_ioctl_called = 1;
  12379. bp->tx_type = config.tx_type;
  12380. bp->rx_filter = config.rx_filter;
  12381. rc = bnx2x_configure_ptp_filters(bp);
  12382. if (rc)
  12383. return rc;
  12384. config.rx_filter = bp->rx_filter;
  12385. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12386. -EFAULT : 0;
  12387. }
  12388. /* Configrues HW for PTP */
  12389. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12390. {
  12391. int rc, port = BP_PORT(bp);
  12392. u32 wb_data[2];
  12393. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12394. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12395. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12396. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12397. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12398. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12399. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12400. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12401. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12402. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12403. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12404. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12405. /* Enable the PTP feature */
  12406. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12407. NIG_REG_P0_PTP_EN, 0x3F);
  12408. /* Enable the free-running counter */
  12409. wb_data[0] = 0;
  12410. wb_data[1] = 0;
  12411. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12412. /* Reset drift register (offset register is not reset) */
  12413. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12414. if (rc) {
  12415. BNX2X_ERR("Failed to reset PHC drift register\n");
  12416. return -EFAULT;
  12417. }
  12418. /* Reset possibly old timestamps */
  12419. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12420. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12421. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12422. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12423. return 0;
  12424. }
  12425. /* Called during load, to initialize PTP-related stuff */
  12426. void bnx2x_init_ptp(struct bnx2x *bp)
  12427. {
  12428. int rc;
  12429. /* Configure PTP in HW */
  12430. rc = bnx2x_configure_ptp(bp);
  12431. if (rc) {
  12432. BNX2X_ERR("Stopping PTP initialization\n");
  12433. return;
  12434. }
  12435. /* Init work queue for Tx timestamping */
  12436. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12437. /* Init cyclecounter and timecounter. This is done only in the first
  12438. * load. If done in every load, PTP application will fail when doing
  12439. * unload / load (e.g. MTU change) while it is running.
  12440. */
  12441. if (!bp->timecounter_init_done) {
  12442. bnx2x_init_cyclecounter(bp);
  12443. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  12444. ktime_to_ns(ktime_get_real()));
  12445. bp->timecounter_init_done = 1;
  12446. }
  12447. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  12448. }