bnx2x_main.c 384 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166
  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 <net/ip.h>
  43. #include <net/ipv6.h>
  44. #include <net/tcp.h>
  45. #include <net/checksum.h>
  46. #include <net/ip6_checksum.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/crc32.h>
  49. #include <linux/crc32c.h>
  50. #include <linux/prefetch.h>
  51. #include <linux/zlib.h>
  52. #include <linux/io.h>
  53. #include <linux/semaphore.h>
  54. #include <linux/stringify.h>
  55. #include <linux/vmalloc.h>
  56. #include "bnx2x.h"
  57. #include "bnx2x_init.h"
  58. #include "bnx2x_init_ops.h"
  59. #include "bnx2x_cmn.h"
  60. #include "bnx2x_vfpf.h"
  61. #include "bnx2x_dcb.h"
  62. #include "bnx2x_sp.h"
  63. #include <linux/firmware.h>
  64. #include "bnx2x_fw_file_hdr.h"
  65. /* FW files */
  66. #define FW_FILE_VERSION \
  67. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  69. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  70. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  71. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  73. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int bnx2x_num_queues;
  90. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, S_IRUGO);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. static int int_mode;
  97. module_param(int_mode, int, S_IRUGO);
  98. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  99. "(1 INT#x; 2 MSI)");
  100. static int dropless_fc;
  101. module_param(dropless_fc, int, S_IRUGO);
  102. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  103. static int mrrs = -1;
  104. module_param(mrrs, int, S_IRUGO);
  105. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  106. static int debug;
  107. module_param(debug, int, S_IRUGO);
  108. MODULE_PARM_DESC(debug, " Default debug msglevel");
  109. static struct workqueue_struct *bnx2x_wq;
  110. struct workqueue_struct *bnx2x_iov_wq;
  111. struct bnx2x_mac_vals {
  112. u32 xmac_addr;
  113. u32 xmac_val;
  114. u32 emac_addr;
  115. u32 emac_val;
  116. u32 umac_addr;
  117. u32 umac_val;
  118. u32 bmac_addr;
  119. u32 bmac_val[2];
  120. };
  121. enum bnx2x_board_type {
  122. BCM57710 = 0,
  123. BCM57711,
  124. BCM57711E,
  125. BCM57712,
  126. BCM57712_MF,
  127. BCM57712_VF,
  128. BCM57800,
  129. BCM57800_MF,
  130. BCM57800_VF,
  131. BCM57810,
  132. BCM57810_MF,
  133. BCM57810_VF,
  134. BCM57840_4_10,
  135. BCM57840_2_20,
  136. BCM57840_MF,
  137. BCM57840_VF,
  138. BCM57811,
  139. BCM57811_MF,
  140. BCM57840_O,
  141. BCM57840_MFO,
  142. BCM57811_VF
  143. };
  144. /* indexed by board_type, above */
  145. static struct {
  146. char *name;
  147. } board_info[] = {
  148. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  149. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  150. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  151. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  152. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  153. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  154. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  155. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  156. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  157. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  158. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  159. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  160. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  161. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  162. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  163. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  164. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  165. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  166. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  167. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  168. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  169. };
  170. #ifndef PCI_DEVICE_ID_NX2_57710
  171. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  172. #endif
  173. #ifndef PCI_DEVICE_ID_NX2_57711
  174. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  175. #endif
  176. #ifndef PCI_DEVICE_ID_NX2_57711E
  177. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  178. #endif
  179. #ifndef PCI_DEVICE_ID_NX2_57712
  180. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  181. #endif
  182. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  183. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  184. #endif
  185. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  186. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  187. #endif
  188. #ifndef PCI_DEVICE_ID_NX2_57800
  189. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  190. #endif
  191. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  192. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  193. #endif
  194. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  195. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  196. #endif
  197. #ifndef PCI_DEVICE_ID_NX2_57810
  198. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  199. #endif
  200. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  201. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  202. #endif
  203. #ifndef PCI_DEVICE_ID_NX2_57840_O
  204. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  205. #endif
  206. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  207. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  208. #endif
  209. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  210. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  211. #endif
  212. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  213. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  214. #endif
  215. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  216. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  217. #endif
  218. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  219. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  220. #endif
  221. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  222. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  223. #endif
  224. #ifndef PCI_DEVICE_ID_NX2_57811
  225. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  226. #endif
  227. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  228. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  229. #endif
  230. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  231. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  232. #endif
  233. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  255. { 0 }
  256. };
  257. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  258. /* Global resources for unloading a previously loaded device */
  259. #define BNX2X_PREV_WAIT_NEEDED 1
  260. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  261. static LIST_HEAD(bnx2x_prev_list);
  262. /* Forward declaration */
  263. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  264. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  265. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  266. /****************************************************************************
  267. * General service functions
  268. ****************************************************************************/
  269. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  270. u32 addr, dma_addr_t mapping)
  271. {
  272. REG_WR(bp, addr, U64_LO(mapping));
  273. REG_WR(bp, addr + 4, U64_HI(mapping));
  274. }
  275. static void storm_memset_spq_addr(struct bnx2x *bp,
  276. dma_addr_t mapping, u16 abs_fid)
  277. {
  278. u32 addr = XSEM_REG_FAST_MEMORY +
  279. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  280. __storm_memset_dma_mapping(bp, addr, mapping);
  281. }
  282. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  283. u16 pf_id)
  284. {
  285. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  290. pf_id);
  291. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  292. pf_id);
  293. }
  294. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  295. u8 enable)
  296. {
  297. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  302. enable);
  303. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  304. enable);
  305. }
  306. static void storm_memset_eq_data(struct bnx2x *bp,
  307. struct event_ring_data *eq_data,
  308. u16 pfid)
  309. {
  310. size_t size = sizeof(struct event_ring_data);
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  312. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  313. }
  314. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  315. u16 pfid)
  316. {
  317. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  318. REG_WR16(bp, addr, eq_prod);
  319. }
  320. /* used only at init
  321. * locking is done by mcp
  322. */
  323. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  324. {
  325. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  326. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  328. PCICFG_VENDOR_ID_OFFSET);
  329. }
  330. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  331. {
  332. u32 val;
  333. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  334. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  336. PCICFG_VENDOR_ID_OFFSET);
  337. return val;
  338. }
  339. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  340. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  341. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  342. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  343. #define DMAE_DP_DST_NONE "dst_addr [none]"
  344. static void bnx2x_dp_dmae(struct bnx2x *bp,
  345. struct dmae_command *dmae, int msglvl)
  346. {
  347. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  348. int i;
  349. switch (dmae->opcode & DMAE_COMMAND_DST) {
  350. case DMAE_CMD_DST_PCI:
  351. if (src_type == DMAE_CMD_SRC_PCI)
  352. DP(msglvl, "DMAE: opcode 0x%08x\n"
  353. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  354. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  355. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  356. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  357. dmae->comp_addr_hi, dmae->comp_addr_lo,
  358. dmae->comp_val);
  359. else
  360. DP(msglvl, "DMAE: opcode 0x%08x\n"
  361. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  362. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  363. dmae->opcode, dmae->src_addr_lo >> 2,
  364. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  365. dmae->comp_addr_hi, dmae->comp_addr_lo,
  366. dmae->comp_val);
  367. break;
  368. case DMAE_CMD_DST_GRC:
  369. if (src_type == DMAE_CMD_SRC_PCI)
  370. DP(msglvl, "DMAE: opcode 0x%08x\n"
  371. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  372. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  373. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  374. dmae->len, dmae->dst_addr_lo >> 2,
  375. dmae->comp_addr_hi, dmae->comp_addr_lo,
  376. dmae->comp_val);
  377. else
  378. DP(msglvl, "DMAE: opcode 0x%08x\n"
  379. "src [%08x], len [%d*4], dst [%08x]\n"
  380. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  381. dmae->opcode, dmae->src_addr_lo >> 2,
  382. dmae->len, dmae->dst_addr_lo >> 2,
  383. dmae->comp_addr_hi, dmae->comp_addr_lo,
  384. dmae->comp_val);
  385. break;
  386. default:
  387. if (src_type == DMAE_CMD_SRC_PCI)
  388. DP(msglvl, "DMAE: opcode 0x%08x\n"
  389. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  390. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  391. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  392. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  393. dmae->comp_val);
  394. else
  395. DP(msglvl, "DMAE: opcode 0x%08x\n"
  396. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  397. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  398. dmae->opcode, dmae->src_addr_lo >> 2,
  399. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  400. dmae->comp_val);
  401. break;
  402. }
  403. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  404. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  405. i, *(((u32 *)dmae) + i));
  406. }
  407. /* copy command into DMAE command memory and set DMAE command go */
  408. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  409. {
  410. u32 cmd_offset;
  411. int i;
  412. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  413. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  414. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  415. }
  416. REG_WR(bp, dmae_reg_go_c[idx], 1);
  417. }
  418. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  419. {
  420. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  421. DMAE_CMD_C_ENABLE);
  422. }
  423. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  424. {
  425. return opcode & ~DMAE_CMD_SRC_RESET;
  426. }
  427. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  428. bool with_comp, u8 comp_type)
  429. {
  430. u32 opcode = 0;
  431. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  432. (dst_type << DMAE_COMMAND_DST_SHIFT));
  433. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  434. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  435. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  436. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  437. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  438. #ifdef __BIG_ENDIAN
  439. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  440. #else
  441. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  442. #endif
  443. if (with_comp)
  444. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  445. return opcode;
  446. }
  447. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  448. struct dmae_command *dmae,
  449. u8 src_type, u8 dst_type)
  450. {
  451. memset(dmae, 0, sizeof(struct dmae_command));
  452. /* set the opcode */
  453. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  454. true, DMAE_COMP_PCI);
  455. /* fill in the completion parameters */
  456. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  457. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  458. dmae->comp_val = DMAE_COMP_VAL;
  459. }
  460. /* issue a dmae command over the init-channel and wait for completion */
  461. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  462. u32 *comp)
  463. {
  464. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  465. int rc = 0;
  466. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  467. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  468. * as long as this code is called both from syscall context and
  469. * from ndo_set_rx_mode() flow that may be called from BH.
  470. */
  471. spin_lock_bh(&bp->dmae_lock);
  472. /* reset completion */
  473. *comp = 0;
  474. /* post the command on the channel used for initializations */
  475. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  476. /* wait for completion */
  477. udelay(5);
  478. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  479. if (!cnt ||
  480. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  481. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  482. BNX2X_ERR("DMAE timeout!\n");
  483. rc = DMAE_TIMEOUT;
  484. goto unlock;
  485. }
  486. cnt--;
  487. udelay(50);
  488. }
  489. if (*comp & DMAE_PCI_ERR_FLAG) {
  490. BNX2X_ERR("DMAE PCI error!\n");
  491. rc = DMAE_PCI_ERROR;
  492. }
  493. unlock:
  494. spin_unlock_bh(&bp->dmae_lock);
  495. return rc;
  496. }
  497. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  498. u32 len32)
  499. {
  500. int rc;
  501. struct dmae_command dmae;
  502. if (!bp->dmae_ready) {
  503. u32 *data = bnx2x_sp(bp, wb_data[0]);
  504. if (CHIP_IS_E1(bp))
  505. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  506. else
  507. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  508. return;
  509. }
  510. /* set opcode and fixed command fields */
  511. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  512. /* fill in addresses and len */
  513. dmae.src_addr_lo = U64_LO(dma_addr);
  514. dmae.src_addr_hi = U64_HI(dma_addr);
  515. dmae.dst_addr_lo = dst_addr >> 2;
  516. dmae.dst_addr_hi = 0;
  517. dmae.len = len32;
  518. /* issue the command and wait for completion */
  519. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  520. if (rc) {
  521. BNX2X_ERR("DMAE returned failure %d\n", rc);
  522. #ifdef BNX2X_STOP_ON_ERROR
  523. bnx2x_panic();
  524. #endif
  525. }
  526. }
  527. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  528. {
  529. int rc;
  530. struct dmae_command dmae;
  531. if (!bp->dmae_ready) {
  532. u32 *data = bnx2x_sp(bp, wb_data[0]);
  533. int i;
  534. if (CHIP_IS_E1(bp))
  535. for (i = 0; i < len32; i++)
  536. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  537. else
  538. for (i = 0; i < len32; i++)
  539. data[i] = REG_RD(bp, src_addr + i*4);
  540. return;
  541. }
  542. /* set opcode and fixed command fields */
  543. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  544. /* fill in addresses and len */
  545. dmae.src_addr_lo = src_addr >> 2;
  546. dmae.src_addr_hi = 0;
  547. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  548. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  549. dmae.len = len32;
  550. /* issue the command and wait for completion */
  551. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  552. if (rc) {
  553. BNX2X_ERR("DMAE returned failure %d\n", rc);
  554. #ifdef BNX2X_STOP_ON_ERROR
  555. bnx2x_panic();
  556. #endif
  557. }
  558. }
  559. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  560. u32 addr, u32 len)
  561. {
  562. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  563. int offset = 0;
  564. while (len > dmae_wr_max) {
  565. bnx2x_write_dmae(bp, phys_addr + offset,
  566. addr + offset, dmae_wr_max);
  567. offset += dmae_wr_max * 4;
  568. len -= dmae_wr_max;
  569. }
  570. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  571. }
  572. static int bnx2x_mc_assert(struct bnx2x *bp)
  573. {
  574. char last_idx;
  575. int i, rc = 0;
  576. u32 row0, row1, row2, row3;
  577. /* XSTORM */
  578. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  580. if (last_idx)
  581. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  582. /* print the asserts */
  583. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  584. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  585. XSTORM_ASSERT_LIST_OFFSET(i));
  586. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  587. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  588. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  589. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  590. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  591. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  592. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  593. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  594. i, row3, row2, row1, row0);
  595. rc++;
  596. } else {
  597. break;
  598. }
  599. }
  600. /* TSTORM */
  601. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  603. if (last_idx)
  604. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  605. /* print the asserts */
  606. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  607. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  608. TSTORM_ASSERT_LIST_OFFSET(i));
  609. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  610. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  611. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  612. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  613. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  614. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  615. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  616. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  617. i, row3, row2, row1, row0);
  618. rc++;
  619. } else {
  620. break;
  621. }
  622. }
  623. /* CSTORM */
  624. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  626. if (last_idx)
  627. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  628. /* print the asserts */
  629. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  630. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  631. CSTORM_ASSERT_LIST_OFFSET(i));
  632. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  633. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  634. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  635. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  636. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  637. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  638. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  639. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  640. i, row3, row2, row1, row0);
  641. rc++;
  642. } else {
  643. break;
  644. }
  645. }
  646. /* USTORM */
  647. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_INDEX_OFFSET);
  649. if (last_idx)
  650. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  651. /* print the asserts */
  652. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  653. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  654. USTORM_ASSERT_LIST_OFFSET(i));
  655. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  656. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  657. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  658. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  659. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  660. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  661. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  662. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  663. i, row3, row2, row1, row0);
  664. rc++;
  665. } else {
  666. break;
  667. }
  668. }
  669. return rc;
  670. }
  671. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  672. #define SCRATCH_BUFFER_SIZE(bp) \
  673. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  674. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  675. {
  676. u32 addr, val;
  677. u32 mark, offset;
  678. __be32 data[9];
  679. int word;
  680. u32 trace_shmem_base;
  681. if (BP_NOMCP(bp)) {
  682. BNX2X_ERR("NO MCP - can not dump\n");
  683. return;
  684. }
  685. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  686. (bp->common.bc_ver & 0xff0000) >> 16,
  687. (bp->common.bc_ver & 0xff00) >> 8,
  688. (bp->common.bc_ver & 0xff));
  689. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  690. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  691. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  692. if (BP_PATH(bp) == 0)
  693. trace_shmem_base = bp->common.shmem_base;
  694. else
  695. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  696. /* sanity */
  697. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  698. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  699. SCRATCH_BUFFER_SIZE(bp)) {
  700. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  701. trace_shmem_base);
  702. return;
  703. }
  704. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  705. /* validate TRCB signature */
  706. mark = REG_RD(bp, addr);
  707. if (mark != MFW_TRACE_SIGNATURE) {
  708. BNX2X_ERR("Trace buffer signature is missing.");
  709. return ;
  710. }
  711. /* read cyclic buffer pointer */
  712. addr += 4;
  713. mark = REG_RD(bp, addr);
  714. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  715. if (mark >= trace_shmem_base || mark < addr + 4) {
  716. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  717. return;
  718. }
  719. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  720. printk("%s", lvl);
  721. /* dump buffer after the mark */
  722. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  723. for (word = 0; word < 8; word++)
  724. data[word] = htonl(REG_RD(bp, offset + 4*word));
  725. data[8] = 0x0;
  726. pr_cont("%s", (char *)data);
  727. }
  728. /* dump buffer before the mark */
  729. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  730. for (word = 0; word < 8; word++)
  731. data[word] = htonl(REG_RD(bp, offset + 4*word));
  732. data[8] = 0x0;
  733. pr_cont("%s", (char *)data);
  734. }
  735. printk("%s" "end of fw dump\n", lvl);
  736. }
  737. static void bnx2x_fw_dump(struct bnx2x *bp)
  738. {
  739. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  740. }
  741. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  742. {
  743. int port = BP_PORT(bp);
  744. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  745. u32 val = REG_RD(bp, addr);
  746. /* in E1 we must use only PCI configuration space to disable
  747. * MSI/MSIX capability
  748. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  749. */
  750. if (CHIP_IS_E1(bp)) {
  751. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  752. * Use mask register to prevent from HC sending interrupts
  753. * after we exit the function
  754. */
  755. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  756. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  757. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  758. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  759. } else
  760. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  761. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  762. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  763. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  764. DP(NETIF_MSG_IFDOWN,
  765. "write %x to HC %d (addr 0x%x)\n",
  766. val, port, addr);
  767. /* flush all outstanding writes */
  768. mmiowb();
  769. REG_WR(bp, addr, val);
  770. if (REG_RD(bp, addr) != val)
  771. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  772. }
  773. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  774. {
  775. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  776. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  777. IGU_PF_CONF_INT_LINE_EN |
  778. IGU_PF_CONF_ATTN_BIT_EN);
  779. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  780. /* flush all outstanding writes */
  781. mmiowb();
  782. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  783. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  784. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  785. }
  786. static void bnx2x_int_disable(struct bnx2x *bp)
  787. {
  788. if (bp->common.int_block == INT_BLOCK_HC)
  789. bnx2x_hc_int_disable(bp);
  790. else
  791. bnx2x_igu_int_disable(bp);
  792. }
  793. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  794. {
  795. int i;
  796. u16 j;
  797. struct hc_sp_status_block_data sp_sb_data;
  798. int func = BP_FUNC(bp);
  799. #ifdef BNX2X_STOP_ON_ERROR
  800. u16 start = 0, end = 0;
  801. u8 cos;
  802. #endif
  803. if (IS_PF(bp) && disable_int)
  804. bnx2x_int_disable(bp);
  805. bp->stats_state = STATS_STATE_DISABLED;
  806. bp->eth_stats.unrecoverable_error++;
  807. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  808. BNX2X_ERR("begin crash dump -----------------\n");
  809. /* Indices */
  810. /* Common */
  811. if (IS_PF(bp)) {
  812. struct host_sp_status_block *def_sb = bp->def_status_blk;
  813. int data_size, cstorm_offset;
  814. 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",
  815. bp->def_idx, bp->def_att_idx, bp->attn_state,
  816. bp->spq_prod_idx, bp->stats_counter);
  817. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  818. def_sb->atten_status_block.attn_bits,
  819. def_sb->atten_status_block.attn_bits_ack,
  820. def_sb->atten_status_block.status_block_id,
  821. def_sb->atten_status_block.attn_bits_index);
  822. BNX2X_ERR(" def (");
  823. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  824. pr_cont("0x%x%s",
  825. def_sb->sp_sb.index_values[i],
  826. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  827. data_size = sizeof(struct hc_sp_status_block_data) /
  828. sizeof(u32);
  829. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  830. for (i = 0; i < data_size; i++)
  831. *((u32 *)&sp_sb_data + i) =
  832. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  833. i * sizeof(u32));
  834. 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",
  835. sp_sb_data.igu_sb_id,
  836. sp_sb_data.igu_seg_id,
  837. sp_sb_data.p_func.pf_id,
  838. sp_sb_data.p_func.vnic_id,
  839. sp_sb_data.p_func.vf_id,
  840. sp_sb_data.p_func.vf_valid,
  841. sp_sb_data.state);
  842. }
  843. for_each_eth_queue(bp, i) {
  844. struct bnx2x_fastpath *fp = &bp->fp[i];
  845. int loop;
  846. struct hc_status_block_data_e2 sb_data_e2;
  847. struct hc_status_block_data_e1x sb_data_e1x;
  848. struct hc_status_block_sm *hc_sm_p =
  849. CHIP_IS_E1x(bp) ?
  850. sb_data_e1x.common.state_machine :
  851. sb_data_e2.common.state_machine;
  852. struct hc_index_data *hc_index_p =
  853. CHIP_IS_E1x(bp) ?
  854. sb_data_e1x.index_data :
  855. sb_data_e2.index_data;
  856. u8 data_size, cos;
  857. u32 *sb_data_p;
  858. struct bnx2x_fp_txdata txdata;
  859. /* Rx */
  860. 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",
  861. i, fp->rx_bd_prod, fp->rx_bd_cons,
  862. fp->rx_comp_prod,
  863. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  864. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  865. fp->rx_sge_prod, fp->last_max_sge,
  866. le16_to_cpu(fp->fp_hc_idx));
  867. /* Tx */
  868. for_each_cos_in_tx_queue(fp, cos)
  869. {
  870. txdata = *fp->txdata_ptr[cos];
  871. 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",
  872. i, txdata.tx_pkt_prod,
  873. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  874. txdata.tx_bd_cons,
  875. le16_to_cpu(*txdata.tx_cons_sb));
  876. }
  877. loop = CHIP_IS_E1x(bp) ?
  878. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  879. /* host sb data */
  880. if (IS_FCOE_FP(fp))
  881. continue;
  882. BNX2X_ERR(" run indexes (");
  883. for (j = 0; j < HC_SB_MAX_SM; j++)
  884. pr_cont("0x%x%s",
  885. fp->sb_running_index[j],
  886. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  887. BNX2X_ERR(" indexes (");
  888. for (j = 0; j < loop; j++)
  889. pr_cont("0x%x%s",
  890. fp->sb_index_values[j],
  891. (j == loop - 1) ? ")" : " ");
  892. /* VF cannot access FW refelection for status block */
  893. if (IS_VF(bp))
  894. continue;
  895. /* fw sb data */
  896. data_size = CHIP_IS_E1x(bp) ?
  897. sizeof(struct hc_status_block_data_e1x) :
  898. sizeof(struct hc_status_block_data_e2);
  899. data_size /= sizeof(u32);
  900. sb_data_p = CHIP_IS_E1x(bp) ?
  901. (u32 *)&sb_data_e1x :
  902. (u32 *)&sb_data_e2;
  903. /* copy sb data in here */
  904. for (j = 0; j < data_size; j++)
  905. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  906. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  907. j * sizeof(u32));
  908. if (!CHIP_IS_E1x(bp)) {
  909. 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",
  910. sb_data_e2.common.p_func.pf_id,
  911. sb_data_e2.common.p_func.vf_id,
  912. sb_data_e2.common.p_func.vf_valid,
  913. sb_data_e2.common.p_func.vnic_id,
  914. sb_data_e2.common.same_igu_sb_1b,
  915. sb_data_e2.common.state);
  916. } else {
  917. 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",
  918. sb_data_e1x.common.p_func.pf_id,
  919. sb_data_e1x.common.p_func.vf_id,
  920. sb_data_e1x.common.p_func.vf_valid,
  921. sb_data_e1x.common.p_func.vnic_id,
  922. sb_data_e1x.common.same_igu_sb_1b,
  923. sb_data_e1x.common.state);
  924. }
  925. /* SB_SMs data */
  926. for (j = 0; j < HC_SB_MAX_SM; j++) {
  927. 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",
  928. j, hc_sm_p[j].__flags,
  929. hc_sm_p[j].igu_sb_id,
  930. hc_sm_p[j].igu_seg_id,
  931. hc_sm_p[j].time_to_expire,
  932. hc_sm_p[j].timer_value);
  933. }
  934. /* Indices data */
  935. for (j = 0; j < loop; j++) {
  936. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  937. hc_index_p[j].flags,
  938. hc_index_p[j].timeout);
  939. }
  940. }
  941. #ifdef BNX2X_STOP_ON_ERROR
  942. if (IS_PF(bp)) {
  943. /* event queue */
  944. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  945. for (i = 0; i < NUM_EQ_DESC; i++) {
  946. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  947. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  948. i, bp->eq_ring[i].message.opcode,
  949. bp->eq_ring[i].message.error);
  950. BNX2X_ERR("data: %x %x %x\n",
  951. data[0], data[1], data[2]);
  952. }
  953. }
  954. /* Rings */
  955. /* Rx */
  956. for_each_valid_rx_queue(bp, i) {
  957. struct bnx2x_fastpath *fp = &bp->fp[i];
  958. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  959. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  960. for (j = start; j != end; j = RX_BD(j + 1)) {
  961. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  962. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  963. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  964. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  965. }
  966. start = RX_SGE(fp->rx_sge_prod);
  967. end = RX_SGE(fp->last_max_sge);
  968. for (j = start; j != end; j = RX_SGE(j + 1)) {
  969. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  970. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  971. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  972. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  973. }
  974. start = RCQ_BD(fp->rx_comp_cons - 10);
  975. end = RCQ_BD(fp->rx_comp_cons + 503);
  976. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  977. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  978. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  979. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  980. }
  981. }
  982. /* Tx */
  983. for_each_valid_tx_queue(bp, i) {
  984. struct bnx2x_fastpath *fp = &bp->fp[i];
  985. for_each_cos_in_tx_queue(fp, cos) {
  986. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  987. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  988. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  989. for (j = start; j != end; j = TX_BD(j + 1)) {
  990. struct sw_tx_bd *sw_bd =
  991. &txdata->tx_buf_ring[j];
  992. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  993. i, cos, j, sw_bd->skb,
  994. sw_bd->first_bd);
  995. }
  996. start = TX_BD(txdata->tx_bd_cons - 10);
  997. end = TX_BD(txdata->tx_bd_cons + 254);
  998. for (j = start; j != end; j = TX_BD(j + 1)) {
  999. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1000. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1001. i, cos, j, tx_bd[0], tx_bd[1],
  1002. tx_bd[2], tx_bd[3]);
  1003. }
  1004. }
  1005. }
  1006. #endif
  1007. if (IS_PF(bp)) {
  1008. bnx2x_fw_dump(bp);
  1009. bnx2x_mc_assert(bp);
  1010. }
  1011. BNX2X_ERR("end crash dump -----------------\n");
  1012. }
  1013. /*
  1014. * FLR Support for E2
  1015. *
  1016. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1017. * initialization.
  1018. */
  1019. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1020. #define FLR_WAIT_INTERVAL 50 /* usec */
  1021. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1022. struct pbf_pN_buf_regs {
  1023. int pN;
  1024. u32 init_crd;
  1025. u32 crd;
  1026. u32 crd_freed;
  1027. };
  1028. struct pbf_pN_cmd_regs {
  1029. int pN;
  1030. u32 lines_occup;
  1031. u32 lines_freed;
  1032. };
  1033. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1034. struct pbf_pN_buf_regs *regs,
  1035. u32 poll_count)
  1036. {
  1037. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1038. u32 cur_cnt = poll_count;
  1039. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1040. crd = crd_start = REG_RD(bp, regs->crd);
  1041. init_crd = REG_RD(bp, regs->init_crd);
  1042. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1043. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1044. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1045. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1046. (init_crd - crd_start))) {
  1047. if (cur_cnt--) {
  1048. udelay(FLR_WAIT_INTERVAL);
  1049. crd = REG_RD(bp, regs->crd);
  1050. crd_freed = REG_RD(bp, regs->crd_freed);
  1051. } else {
  1052. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1053. regs->pN);
  1054. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1055. regs->pN, crd);
  1056. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1057. regs->pN, crd_freed);
  1058. break;
  1059. }
  1060. }
  1061. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1062. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1063. }
  1064. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1065. struct pbf_pN_cmd_regs *regs,
  1066. u32 poll_count)
  1067. {
  1068. u32 occup, to_free, freed, freed_start;
  1069. u32 cur_cnt = poll_count;
  1070. occup = to_free = REG_RD(bp, regs->lines_occup);
  1071. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1072. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1073. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1074. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1075. if (cur_cnt--) {
  1076. udelay(FLR_WAIT_INTERVAL);
  1077. occup = REG_RD(bp, regs->lines_occup);
  1078. freed = REG_RD(bp, regs->lines_freed);
  1079. } else {
  1080. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1081. regs->pN);
  1082. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1083. regs->pN, occup);
  1084. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1085. regs->pN, freed);
  1086. break;
  1087. }
  1088. }
  1089. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1090. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1091. }
  1092. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1093. u32 expected, u32 poll_count)
  1094. {
  1095. u32 cur_cnt = poll_count;
  1096. u32 val;
  1097. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1098. udelay(FLR_WAIT_INTERVAL);
  1099. return val;
  1100. }
  1101. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1102. char *msg, u32 poll_cnt)
  1103. {
  1104. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1105. if (val != 0) {
  1106. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1107. return 1;
  1108. }
  1109. return 0;
  1110. }
  1111. /* Common routines with VF FLR cleanup */
  1112. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1113. {
  1114. /* adjust polling timeout */
  1115. if (CHIP_REV_IS_EMUL(bp))
  1116. return FLR_POLL_CNT * 2000;
  1117. if (CHIP_REV_IS_FPGA(bp))
  1118. return FLR_POLL_CNT * 120;
  1119. return FLR_POLL_CNT;
  1120. }
  1121. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1122. {
  1123. struct pbf_pN_cmd_regs cmd_regs[] = {
  1124. {0, (CHIP_IS_E3B0(bp)) ?
  1125. PBF_REG_TQ_OCCUPANCY_Q0 :
  1126. PBF_REG_P0_TQ_OCCUPANCY,
  1127. (CHIP_IS_E3B0(bp)) ?
  1128. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1129. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1130. {1, (CHIP_IS_E3B0(bp)) ?
  1131. PBF_REG_TQ_OCCUPANCY_Q1 :
  1132. PBF_REG_P1_TQ_OCCUPANCY,
  1133. (CHIP_IS_E3B0(bp)) ?
  1134. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1135. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1136. {4, (CHIP_IS_E3B0(bp)) ?
  1137. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1138. PBF_REG_P4_TQ_OCCUPANCY,
  1139. (CHIP_IS_E3B0(bp)) ?
  1140. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1141. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1142. };
  1143. struct pbf_pN_buf_regs buf_regs[] = {
  1144. {0, (CHIP_IS_E3B0(bp)) ?
  1145. PBF_REG_INIT_CRD_Q0 :
  1146. PBF_REG_P0_INIT_CRD ,
  1147. (CHIP_IS_E3B0(bp)) ?
  1148. PBF_REG_CREDIT_Q0 :
  1149. PBF_REG_P0_CREDIT,
  1150. (CHIP_IS_E3B0(bp)) ?
  1151. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1152. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1153. {1, (CHIP_IS_E3B0(bp)) ?
  1154. PBF_REG_INIT_CRD_Q1 :
  1155. PBF_REG_P1_INIT_CRD,
  1156. (CHIP_IS_E3B0(bp)) ?
  1157. PBF_REG_CREDIT_Q1 :
  1158. PBF_REG_P1_CREDIT,
  1159. (CHIP_IS_E3B0(bp)) ?
  1160. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1161. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1162. {4, (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INIT_CRD_LB_Q :
  1164. PBF_REG_P4_INIT_CRD,
  1165. (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_CREDIT_LB_Q :
  1167. PBF_REG_P4_CREDIT,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1170. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1171. };
  1172. int i;
  1173. /* Verify the command queues are flushed P0, P1, P4 */
  1174. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1175. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1176. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1177. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1178. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1179. }
  1180. #define OP_GEN_PARAM(param) \
  1181. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1182. #define OP_GEN_TYPE(type) \
  1183. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1184. #define OP_GEN_AGG_VECT(index) \
  1185. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1186. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1187. {
  1188. u32 op_gen_command = 0;
  1189. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1190. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1191. int ret = 0;
  1192. if (REG_RD(bp, comp_addr)) {
  1193. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1194. return 1;
  1195. }
  1196. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1197. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1198. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1199. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1200. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1201. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1202. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1203. BNX2X_ERR("FW final cleanup did not succeed\n");
  1204. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1205. (REG_RD(bp, comp_addr)));
  1206. bnx2x_panic();
  1207. return 1;
  1208. }
  1209. /* Zero completion for next FLR */
  1210. REG_WR(bp, comp_addr, 0);
  1211. return ret;
  1212. }
  1213. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1214. {
  1215. u16 status;
  1216. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1217. return status & PCI_EXP_DEVSTA_TRPND;
  1218. }
  1219. /* PF FLR specific routines
  1220. */
  1221. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1222. {
  1223. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1224. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1225. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1226. "CFC PF usage counter timed out",
  1227. poll_cnt))
  1228. return 1;
  1229. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1230. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1231. DORQ_REG_PF_USAGE_CNT,
  1232. "DQ PF usage counter timed out",
  1233. poll_cnt))
  1234. return 1;
  1235. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1236. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1237. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1238. "QM PF usage counter timed out",
  1239. poll_cnt))
  1240. return 1;
  1241. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1242. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1243. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1244. "Timers VNIC usage counter timed out",
  1245. poll_cnt))
  1246. return 1;
  1247. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1248. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1249. "Timers NUM_SCANS usage counter timed out",
  1250. poll_cnt))
  1251. return 1;
  1252. /* Wait DMAE PF usage counter to zero */
  1253. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1254. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1255. "DMAE command register timed out",
  1256. poll_cnt))
  1257. return 1;
  1258. return 0;
  1259. }
  1260. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1261. {
  1262. u32 val;
  1263. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1264. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1265. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1266. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1267. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1268. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1269. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1270. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1271. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1272. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1273. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1274. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1275. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1276. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1277. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1278. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1279. val);
  1280. }
  1281. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1282. {
  1283. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1284. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1285. /* Re-enable PF target read access */
  1286. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1287. /* Poll HW usage counters */
  1288. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1289. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1290. return -EBUSY;
  1291. /* Zero the igu 'trailing edge' and 'leading edge' */
  1292. /* Send the FW cleanup command */
  1293. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1294. return -EBUSY;
  1295. /* ATC cleanup */
  1296. /* Verify TX hw is flushed */
  1297. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1298. /* Wait 100ms (not adjusted according to platform) */
  1299. msleep(100);
  1300. /* Verify no pending pci transactions */
  1301. if (bnx2x_is_pcie_pending(bp->pdev))
  1302. BNX2X_ERR("PCIE Transactions still pending\n");
  1303. /* Debug */
  1304. bnx2x_hw_enable_status(bp);
  1305. /*
  1306. * Master enable - Due to WB DMAE writes performed before this
  1307. * register is re-initialized as part of the regular function init
  1308. */
  1309. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1310. return 0;
  1311. }
  1312. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1313. {
  1314. int port = BP_PORT(bp);
  1315. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1316. u32 val = REG_RD(bp, addr);
  1317. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1318. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1319. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1320. if (msix) {
  1321. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1322. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1323. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1324. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1325. if (single_msix)
  1326. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1327. } else if (msi) {
  1328. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1329. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1330. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1331. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1332. } else {
  1333. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1334. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1335. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1336. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1337. if (!CHIP_IS_E1(bp)) {
  1338. DP(NETIF_MSG_IFUP,
  1339. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1340. REG_WR(bp, addr, val);
  1341. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1342. }
  1343. }
  1344. if (CHIP_IS_E1(bp))
  1345. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1346. DP(NETIF_MSG_IFUP,
  1347. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1348. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1349. REG_WR(bp, addr, val);
  1350. /*
  1351. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1352. */
  1353. mmiowb();
  1354. barrier();
  1355. if (!CHIP_IS_E1(bp)) {
  1356. /* init leading/trailing edge */
  1357. if (IS_MF(bp)) {
  1358. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1359. if (bp->port.pmf)
  1360. /* enable nig and gpio3 attention */
  1361. val |= 0x1100;
  1362. } else
  1363. val = 0xffff;
  1364. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1365. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1366. }
  1367. /* Make sure that interrupts are indeed enabled from here on */
  1368. mmiowb();
  1369. }
  1370. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1371. {
  1372. u32 val;
  1373. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1374. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1375. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1376. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1377. if (msix) {
  1378. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1379. IGU_PF_CONF_SINGLE_ISR_EN);
  1380. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1381. IGU_PF_CONF_ATTN_BIT_EN);
  1382. if (single_msix)
  1383. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1384. } else if (msi) {
  1385. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1386. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1387. IGU_PF_CONF_ATTN_BIT_EN |
  1388. IGU_PF_CONF_SINGLE_ISR_EN);
  1389. } else {
  1390. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1391. val |= (IGU_PF_CONF_INT_LINE_EN |
  1392. IGU_PF_CONF_ATTN_BIT_EN |
  1393. IGU_PF_CONF_SINGLE_ISR_EN);
  1394. }
  1395. /* Clean previous status - need to configure igu prior to ack*/
  1396. if ((!msix) || single_msix) {
  1397. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1398. bnx2x_ack_int(bp);
  1399. }
  1400. val |= IGU_PF_CONF_FUNC_EN;
  1401. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1402. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1403. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1404. if (val & IGU_PF_CONF_INT_LINE_EN)
  1405. pci_intx(bp->pdev, true);
  1406. barrier();
  1407. /* init leading/trailing edge */
  1408. if (IS_MF(bp)) {
  1409. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1410. if (bp->port.pmf)
  1411. /* enable nig and gpio3 attention */
  1412. val |= 0x1100;
  1413. } else
  1414. val = 0xffff;
  1415. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1416. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1417. /* Make sure that interrupts are indeed enabled from here on */
  1418. mmiowb();
  1419. }
  1420. void bnx2x_int_enable(struct bnx2x *bp)
  1421. {
  1422. if (bp->common.int_block == INT_BLOCK_HC)
  1423. bnx2x_hc_int_enable(bp);
  1424. else
  1425. bnx2x_igu_int_enable(bp);
  1426. }
  1427. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1428. {
  1429. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1430. int i, offset;
  1431. if (disable_hw)
  1432. /* prevent the HW from sending interrupts */
  1433. bnx2x_int_disable(bp);
  1434. /* make sure all ISRs are done */
  1435. if (msix) {
  1436. synchronize_irq(bp->msix_table[0].vector);
  1437. offset = 1;
  1438. if (CNIC_SUPPORT(bp))
  1439. offset++;
  1440. for_each_eth_queue(bp, i)
  1441. synchronize_irq(bp->msix_table[offset++].vector);
  1442. } else
  1443. synchronize_irq(bp->pdev->irq);
  1444. /* make sure sp_task is not running */
  1445. cancel_delayed_work(&bp->sp_task);
  1446. cancel_delayed_work(&bp->period_task);
  1447. flush_workqueue(bnx2x_wq);
  1448. }
  1449. /* fast path */
  1450. /*
  1451. * General service functions
  1452. */
  1453. /* Return true if succeeded to acquire the lock */
  1454. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1455. {
  1456. u32 lock_status;
  1457. u32 resource_bit = (1 << resource);
  1458. int func = BP_FUNC(bp);
  1459. u32 hw_lock_control_reg;
  1460. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1461. "Trying to take a lock on resource %d\n", resource);
  1462. /* Validating that the resource is within range */
  1463. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1464. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1465. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1466. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1467. return false;
  1468. }
  1469. if (func <= 5)
  1470. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1471. else
  1472. hw_lock_control_reg =
  1473. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1474. /* Try to acquire the lock */
  1475. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1476. lock_status = REG_RD(bp, hw_lock_control_reg);
  1477. if (lock_status & resource_bit)
  1478. return true;
  1479. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1480. "Failed to get a lock on resource %d\n", resource);
  1481. return false;
  1482. }
  1483. /**
  1484. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1485. *
  1486. * @bp: driver handle
  1487. *
  1488. * Returns the recovery leader resource id according to the engine this function
  1489. * belongs to. Currently only only 2 engines is supported.
  1490. */
  1491. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1492. {
  1493. if (BP_PATH(bp))
  1494. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1495. else
  1496. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1497. }
  1498. /**
  1499. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1500. *
  1501. * @bp: driver handle
  1502. *
  1503. * Tries to acquire a leader lock for current engine.
  1504. */
  1505. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1506. {
  1507. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1508. }
  1509. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1510. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1511. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1512. {
  1513. /* Set the interrupt occurred bit for the sp-task to recognize it
  1514. * must ack the interrupt and transition according to the IGU
  1515. * state machine.
  1516. */
  1517. atomic_set(&bp->interrupt_occurred, 1);
  1518. /* The sp_task must execute only after this bit
  1519. * is set, otherwise we will get out of sync and miss all
  1520. * further interrupts. Hence, the barrier.
  1521. */
  1522. smp_wmb();
  1523. /* schedule sp_task to workqueue */
  1524. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1525. }
  1526. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1527. {
  1528. struct bnx2x *bp = fp->bp;
  1529. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1530. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1531. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1532. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1533. DP(BNX2X_MSG_SP,
  1534. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1535. fp->index, cid, command, bp->state,
  1536. rr_cqe->ramrod_cqe.ramrod_type);
  1537. /* If cid is within VF range, replace the slowpath object with the
  1538. * one corresponding to this VF
  1539. */
  1540. if (cid >= BNX2X_FIRST_VF_CID &&
  1541. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1542. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1543. switch (command) {
  1544. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1545. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1546. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1547. break;
  1548. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1549. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1550. drv_cmd = BNX2X_Q_CMD_SETUP;
  1551. break;
  1552. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1553. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1554. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1555. break;
  1556. case (RAMROD_CMD_ID_ETH_HALT):
  1557. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1558. drv_cmd = BNX2X_Q_CMD_HALT;
  1559. break;
  1560. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1561. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1562. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1563. break;
  1564. case (RAMROD_CMD_ID_ETH_EMPTY):
  1565. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1566. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1567. break;
  1568. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1569. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1570. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1571. break;
  1572. default:
  1573. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1574. command, fp->index);
  1575. return;
  1576. }
  1577. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1578. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1579. /* q_obj->complete_cmd() failure means that this was
  1580. * an unexpected completion.
  1581. *
  1582. * In this case we don't want to increase the bp->spq_left
  1583. * because apparently we haven't sent this command the first
  1584. * place.
  1585. */
  1586. #ifdef BNX2X_STOP_ON_ERROR
  1587. bnx2x_panic();
  1588. #else
  1589. return;
  1590. #endif
  1591. smp_mb__before_atomic();
  1592. atomic_inc(&bp->cq_spq_left);
  1593. /* push the change in bp->spq_left and towards the memory */
  1594. smp_mb__after_atomic();
  1595. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1596. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1597. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1598. /* if Q update ramrod is completed for last Q in AFEX vif set
  1599. * flow, then ACK MCP at the end
  1600. *
  1601. * mark pending ACK to MCP bit.
  1602. * prevent case that both bits are cleared.
  1603. * At the end of load/unload driver checks that
  1604. * sp_state is cleared, and this order prevents
  1605. * races
  1606. */
  1607. smp_mb__before_atomic();
  1608. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1609. wmb();
  1610. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1611. smp_mb__after_atomic();
  1612. /* schedule the sp task as mcp ack is required */
  1613. bnx2x_schedule_sp_task(bp);
  1614. }
  1615. return;
  1616. }
  1617. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1618. {
  1619. struct bnx2x *bp = netdev_priv(dev_instance);
  1620. u16 status = bnx2x_ack_int(bp);
  1621. u16 mask;
  1622. int i;
  1623. u8 cos;
  1624. /* Return here if interrupt is shared and it's not for us */
  1625. if (unlikely(status == 0)) {
  1626. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1627. return IRQ_NONE;
  1628. }
  1629. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1630. #ifdef BNX2X_STOP_ON_ERROR
  1631. if (unlikely(bp->panic))
  1632. return IRQ_HANDLED;
  1633. #endif
  1634. for_each_eth_queue(bp, i) {
  1635. struct bnx2x_fastpath *fp = &bp->fp[i];
  1636. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1637. if (status & mask) {
  1638. /* Handle Rx or Tx according to SB id */
  1639. for_each_cos_in_tx_queue(fp, cos)
  1640. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1641. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1642. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1643. status &= ~mask;
  1644. }
  1645. }
  1646. if (CNIC_SUPPORT(bp)) {
  1647. mask = 0x2;
  1648. if (status & (mask | 0x1)) {
  1649. struct cnic_ops *c_ops = NULL;
  1650. rcu_read_lock();
  1651. c_ops = rcu_dereference(bp->cnic_ops);
  1652. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1653. CNIC_DRV_STATE_HANDLES_IRQ))
  1654. c_ops->cnic_handler(bp->cnic_data, NULL);
  1655. rcu_read_unlock();
  1656. status &= ~mask;
  1657. }
  1658. }
  1659. if (unlikely(status & 0x1)) {
  1660. /* schedule sp task to perform default status block work, ack
  1661. * attentions and enable interrupts.
  1662. */
  1663. bnx2x_schedule_sp_task(bp);
  1664. status &= ~0x1;
  1665. if (!status)
  1666. return IRQ_HANDLED;
  1667. }
  1668. if (unlikely(status))
  1669. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1670. status);
  1671. return IRQ_HANDLED;
  1672. }
  1673. /* Link */
  1674. /*
  1675. * General service functions
  1676. */
  1677. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1678. {
  1679. u32 lock_status;
  1680. u32 resource_bit = (1 << resource);
  1681. int func = BP_FUNC(bp);
  1682. u32 hw_lock_control_reg;
  1683. int cnt;
  1684. /* Validating that the resource is within range */
  1685. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1686. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1687. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1688. return -EINVAL;
  1689. }
  1690. if (func <= 5) {
  1691. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1692. } else {
  1693. hw_lock_control_reg =
  1694. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1695. }
  1696. /* Validating that the resource is not already taken */
  1697. lock_status = REG_RD(bp, hw_lock_control_reg);
  1698. if (lock_status & resource_bit) {
  1699. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1700. lock_status, resource_bit);
  1701. return -EEXIST;
  1702. }
  1703. /* Try for 5 second every 5ms */
  1704. for (cnt = 0; cnt < 1000; cnt++) {
  1705. /* Try to acquire the lock */
  1706. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1707. lock_status = REG_RD(bp, hw_lock_control_reg);
  1708. if (lock_status & resource_bit)
  1709. return 0;
  1710. usleep_range(5000, 10000);
  1711. }
  1712. BNX2X_ERR("Timeout\n");
  1713. return -EAGAIN;
  1714. }
  1715. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1716. {
  1717. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1718. }
  1719. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1720. {
  1721. u32 lock_status;
  1722. u32 resource_bit = (1 << resource);
  1723. int func = BP_FUNC(bp);
  1724. u32 hw_lock_control_reg;
  1725. /* Validating that the resource is within range */
  1726. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1727. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1728. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1729. return -EINVAL;
  1730. }
  1731. if (func <= 5) {
  1732. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1733. } else {
  1734. hw_lock_control_reg =
  1735. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1736. }
  1737. /* Validating that the resource is currently taken */
  1738. lock_status = REG_RD(bp, hw_lock_control_reg);
  1739. if (!(lock_status & resource_bit)) {
  1740. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1741. lock_status, resource_bit);
  1742. return -EFAULT;
  1743. }
  1744. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1745. return 0;
  1746. }
  1747. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1748. {
  1749. /* The GPIO should be swapped if swap register is set and active */
  1750. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1751. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1752. int gpio_shift = gpio_num +
  1753. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1754. u32 gpio_mask = (1 << gpio_shift);
  1755. u32 gpio_reg;
  1756. int value;
  1757. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1758. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1759. return -EINVAL;
  1760. }
  1761. /* read GPIO value */
  1762. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1763. /* get the requested pin value */
  1764. if ((gpio_reg & gpio_mask) == gpio_mask)
  1765. value = 1;
  1766. else
  1767. value = 0;
  1768. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1769. return value;
  1770. }
  1771. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1772. {
  1773. /* The GPIO should be swapped if swap register is set and active */
  1774. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1775. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1776. int gpio_shift = gpio_num +
  1777. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1778. u32 gpio_mask = (1 << gpio_shift);
  1779. u32 gpio_reg;
  1780. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1781. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1782. return -EINVAL;
  1783. }
  1784. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1785. /* read GPIO and mask except the float bits */
  1786. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1787. switch (mode) {
  1788. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1789. DP(NETIF_MSG_LINK,
  1790. "Set GPIO %d (shift %d) -> output low\n",
  1791. gpio_num, gpio_shift);
  1792. /* clear FLOAT and set CLR */
  1793. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1794. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1795. break;
  1796. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1797. DP(NETIF_MSG_LINK,
  1798. "Set GPIO %d (shift %d) -> output high\n",
  1799. gpio_num, gpio_shift);
  1800. /* clear FLOAT and set SET */
  1801. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1802. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1803. break;
  1804. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1805. DP(NETIF_MSG_LINK,
  1806. "Set GPIO %d (shift %d) -> input\n",
  1807. gpio_num, gpio_shift);
  1808. /* set FLOAT */
  1809. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1810. break;
  1811. default:
  1812. break;
  1813. }
  1814. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1815. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1816. return 0;
  1817. }
  1818. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1819. {
  1820. u32 gpio_reg = 0;
  1821. int rc = 0;
  1822. /* Any port swapping should be handled by caller. */
  1823. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1824. /* read GPIO and mask except the float bits */
  1825. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1826. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1827. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1828. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1829. switch (mode) {
  1830. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1831. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1832. /* set CLR */
  1833. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1834. break;
  1835. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1836. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1837. /* set SET */
  1838. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1839. break;
  1840. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1841. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1842. /* set FLOAT */
  1843. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1844. break;
  1845. default:
  1846. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1847. rc = -EINVAL;
  1848. break;
  1849. }
  1850. if (rc == 0)
  1851. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1852. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1853. return rc;
  1854. }
  1855. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1856. {
  1857. /* The GPIO should be swapped if swap register is set and active */
  1858. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1859. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1860. int gpio_shift = gpio_num +
  1861. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1862. u32 gpio_mask = (1 << gpio_shift);
  1863. u32 gpio_reg;
  1864. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1865. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1866. return -EINVAL;
  1867. }
  1868. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1869. /* read GPIO int */
  1870. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1871. switch (mode) {
  1872. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1873. DP(NETIF_MSG_LINK,
  1874. "Clear GPIO INT %d (shift %d) -> output low\n",
  1875. gpio_num, gpio_shift);
  1876. /* clear SET and set CLR */
  1877. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1878. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1879. break;
  1880. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1881. DP(NETIF_MSG_LINK,
  1882. "Set GPIO INT %d (shift %d) -> output high\n",
  1883. gpio_num, gpio_shift);
  1884. /* clear CLR and set SET */
  1885. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1886. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1887. break;
  1888. default:
  1889. break;
  1890. }
  1891. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1892. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1893. return 0;
  1894. }
  1895. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1896. {
  1897. u32 spio_reg;
  1898. /* Only 2 SPIOs are configurable */
  1899. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1900. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1901. return -EINVAL;
  1902. }
  1903. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1904. /* read SPIO and mask except the float bits */
  1905. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1906. switch (mode) {
  1907. case MISC_SPIO_OUTPUT_LOW:
  1908. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1909. /* clear FLOAT and set CLR */
  1910. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1911. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1912. break;
  1913. case MISC_SPIO_OUTPUT_HIGH:
  1914. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1915. /* clear FLOAT and set SET */
  1916. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1917. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1918. break;
  1919. case MISC_SPIO_INPUT_HI_Z:
  1920. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1921. /* set FLOAT */
  1922. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1923. break;
  1924. default:
  1925. break;
  1926. }
  1927. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1928. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1929. return 0;
  1930. }
  1931. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1932. {
  1933. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1934. switch (bp->link_vars.ieee_fc &
  1935. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1936. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1937. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1938. ADVERTISED_Pause);
  1939. break;
  1940. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1941. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1942. ADVERTISED_Pause);
  1943. break;
  1944. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1945. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1946. break;
  1947. default:
  1948. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1949. ADVERTISED_Pause);
  1950. break;
  1951. }
  1952. }
  1953. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1954. {
  1955. /* Initialize link parameters structure variables
  1956. * It is recommended to turn off RX FC for jumbo frames
  1957. * for better performance
  1958. */
  1959. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1960. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1961. else
  1962. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1963. }
  1964. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1965. {
  1966. u32 pause_enabled = 0;
  1967. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1968. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1969. pause_enabled = 1;
  1970. REG_WR(bp, BAR_USTRORM_INTMEM +
  1971. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1972. pause_enabled);
  1973. }
  1974. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1975. pause_enabled ? "enabled" : "disabled");
  1976. }
  1977. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1978. {
  1979. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1980. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1981. if (!BP_NOMCP(bp)) {
  1982. bnx2x_set_requested_fc(bp);
  1983. bnx2x_acquire_phy_lock(bp);
  1984. if (load_mode == LOAD_DIAG) {
  1985. struct link_params *lp = &bp->link_params;
  1986. lp->loopback_mode = LOOPBACK_XGXS;
  1987. /* do PHY loopback at 10G speed, if possible */
  1988. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1989. if (lp->speed_cap_mask[cfx_idx] &
  1990. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1991. lp->req_line_speed[cfx_idx] =
  1992. SPEED_10000;
  1993. else
  1994. lp->req_line_speed[cfx_idx] =
  1995. SPEED_1000;
  1996. }
  1997. }
  1998. if (load_mode == LOAD_LOOPBACK_EXT) {
  1999. struct link_params *lp = &bp->link_params;
  2000. lp->loopback_mode = LOOPBACK_EXT;
  2001. }
  2002. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2003. bnx2x_release_phy_lock(bp);
  2004. bnx2x_init_dropless_fc(bp);
  2005. bnx2x_calc_fc_adv(bp);
  2006. if (bp->link_vars.link_up) {
  2007. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2008. bnx2x_link_report(bp);
  2009. }
  2010. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2011. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2012. return rc;
  2013. }
  2014. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2015. return -EINVAL;
  2016. }
  2017. void bnx2x_link_set(struct bnx2x *bp)
  2018. {
  2019. if (!BP_NOMCP(bp)) {
  2020. bnx2x_acquire_phy_lock(bp);
  2021. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2022. bnx2x_release_phy_lock(bp);
  2023. bnx2x_init_dropless_fc(bp);
  2024. bnx2x_calc_fc_adv(bp);
  2025. } else
  2026. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2027. }
  2028. static void bnx2x__link_reset(struct bnx2x *bp)
  2029. {
  2030. if (!BP_NOMCP(bp)) {
  2031. bnx2x_acquire_phy_lock(bp);
  2032. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2033. bnx2x_release_phy_lock(bp);
  2034. } else
  2035. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2036. }
  2037. void bnx2x_force_link_reset(struct bnx2x *bp)
  2038. {
  2039. bnx2x_acquire_phy_lock(bp);
  2040. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2041. bnx2x_release_phy_lock(bp);
  2042. }
  2043. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2044. {
  2045. u8 rc = 0;
  2046. if (!BP_NOMCP(bp)) {
  2047. bnx2x_acquire_phy_lock(bp);
  2048. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2049. is_serdes);
  2050. bnx2x_release_phy_lock(bp);
  2051. } else
  2052. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2053. return rc;
  2054. }
  2055. /* Calculates the sum of vn_min_rates.
  2056. It's needed for further normalizing of the min_rates.
  2057. Returns:
  2058. sum of vn_min_rates.
  2059. or
  2060. 0 - if all the min_rates are 0.
  2061. In the later case fairness algorithm should be deactivated.
  2062. If not all min_rates are zero then those that are zeroes will be set to 1.
  2063. */
  2064. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2065. struct cmng_init_input *input)
  2066. {
  2067. int all_zero = 1;
  2068. int vn;
  2069. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2070. u32 vn_cfg = bp->mf_config[vn];
  2071. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2072. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2073. /* Skip hidden vns */
  2074. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2075. vn_min_rate = 0;
  2076. /* If min rate is zero - set it to 1 */
  2077. else if (!vn_min_rate)
  2078. vn_min_rate = DEF_MIN_RATE;
  2079. else
  2080. all_zero = 0;
  2081. input->vnic_min_rate[vn] = vn_min_rate;
  2082. }
  2083. /* if ETS or all min rates are zeros - disable fairness */
  2084. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2085. input->flags.cmng_enables &=
  2086. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2087. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2088. } else if (all_zero) {
  2089. input->flags.cmng_enables &=
  2090. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2091. DP(NETIF_MSG_IFUP,
  2092. "All MIN values are zeroes fairness will be disabled\n");
  2093. } else
  2094. input->flags.cmng_enables |=
  2095. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2096. }
  2097. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2098. struct cmng_init_input *input)
  2099. {
  2100. u16 vn_max_rate;
  2101. u32 vn_cfg = bp->mf_config[vn];
  2102. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2103. vn_max_rate = 0;
  2104. else {
  2105. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2106. if (IS_MF_SI(bp)) {
  2107. /* maxCfg in percents of linkspeed */
  2108. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2109. } else /* SD modes */
  2110. /* maxCfg is absolute in 100Mb units */
  2111. vn_max_rate = maxCfg * 100;
  2112. }
  2113. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2114. input->vnic_max_rate[vn] = vn_max_rate;
  2115. }
  2116. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2117. {
  2118. if (CHIP_REV_IS_SLOW(bp))
  2119. return CMNG_FNS_NONE;
  2120. if (IS_MF(bp))
  2121. return CMNG_FNS_MINMAX;
  2122. return CMNG_FNS_NONE;
  2123. }
  2124. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2125. {
  2126. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2127. if (BP_NOMCP(bp))
  2128. return; /* what should be the default value in this case */
  2129. /* For 2 port configuration the absolute function number formula
  2130. * is:
  2131. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2132. *
  2133. * and there are 4 functions per port
  2134. *
  2135. * For 4 port configuration it is
  2136. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2137. *
  2138. * and there are 2 functions per port
  2139. */
  2140. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2141. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2142. if (func >= E1H_FUNC_MAX)
  2143. break;
  2144. bp->mf_config[vn] =
  2145. MF_CFG_RD(bp, func_mf_config[func].config);
  2146. }
  2147. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2148. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2149. bp->flags |= MF_FUNC_DIS;
  2150. } else {
  2151. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2152. bp->flags &= ~MF_FUNC_DIS;
  2153. }
  2154. }
  2155. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2156. {
  2157. struct cmng_init_input input;
  2158. memset(&input, 0, sizeof(struct cmng_init_input));
  2159. input.port_rate = bp->link_vars.line_speed;
  2160. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2161. int vn;
  2162. /* read mf conf from shmem */
  2163. if (read_cfg)
  2164. bnx2x_read_mf_cfg(bp);
  2165. /* vn_weight_sum and enable fairness if not 0 */
  2166. bnx2x_calc_vn_min(bp, &input);
  2167. /* calculate and set min-max rate for each vn */
  2168. if (bp->port.pmf)
  2169. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2170. bnx2x_calc_vn_max(bp, vn, &input);
  2171. /* always enable rate shaping and fairness */
  2172. input.flags.cmng_enables |=
  2173. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2174. bnx2x_init_cmng(&input, &bp->cmng);
  2175. return;
  2176. }
  2177. /* rate shaping and fairness are disabled */
  2178. DP(NETIF_MSG_IFUP,
  2179. "rate shaping and fairness are disabled\n");
  2180. }
  2181. static void storm_memset_cmng(struct bnx2x *bp,
  2182. struct cmng_init *cmng,
  2183. u8 port)
  2184. {
  2185. int vn;
  2186. size_t size = sizeof(struct cmng_struct_per_port);
  2187. u32 addr = BAR_XSTRORM_INTMEM +
  2188. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2189. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2190. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2191. int func = func_by_vn(bp, vn);
  2192. addr = BAR_XSTRORM_INTMEM +
  2193. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2194. size = sizeof(struct rate_shaping_vars_per_vn);
  2195. __storm_memset_struct(bp, addr, size,
  2196. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2197. addr = BAR_XSTRORM_INTMEM +
  2198. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2199. size = sizeof(struct fairness_vars_per_vn);
  2200. __storm_memset_struct(bp, addr, size,
  2201. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2202. }
  2203. }
  2204. /* init cmng mode in HW according to local configuration */
  2205. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2206. {
  2207. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2208. if (cmng_fns != CMNG_FNS_NONE) {
  2209. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2210. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2211. } else {
  2212. /* rate shaping and fairness are disabled */
  2213. DP(NETIF_MSG_IFUP,
  2214. "single function mode without fairness\n");
  2215. }
  2216. }
  2217. /* This function is called upon link interrupt */
  2218. static void bnx2x_link_attn(struct bnx2x *bp)
  2219. {
  2220. /* Make sure that we are synced with the current statistics */
  2221. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2222. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2223. bnx2x_init_dropless_fc(bp);
  2224. if (bp->link_vars.link_up) {
  2225. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2226. struct host_port_stats *pstats;
  2227. pstats = bnx2x_sp(bp, port_stats);
  2228. /* reset old mac stats */
  2229. memset(&(pstats->mac_stx[0]), 0,
  2230. sizeof(struct mac_stx));
  2231. }
  2232. if (bp->state == BNX2X_STATE_OPEN)
  2233. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2234. }
  2235. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2236. bnx2x_set_local_cmng(bp);
  2237. __bnx2x_link_report(bp);
  2238. if (IS_MF(bp))
  2239. bnx2x_link_sync_notify(bp);
  2240. }
  2241. void bnx2x__link_status_update(struct bnx2x *bp)
  2242. {
  2243. if (bp->state != BNX2X_STATE_OPEN)
  2244. return;
  2245. /* read updated dcb configuration */
  2246. if (IS_PF(bp)) {
  2247. bnx2x_dcbx_pmf_update(bp);
  2248. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2249. if (bp->link_vars.link_up)
  2250. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2251. else
  2252. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2253. /* indicate link status */
  2254. bnx2x_link_report(bp);
  2255. } else { /* VF */
  2256. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2257. SUPPORTED_10baseT_Full |
  2258. SUPPORTED_100baseT_Half |
  2259. SUPPORTED_100baseT_Full |
  2260. SUPPORTED_1000baseT_Full |
  2261. SUPPORTED_2500baseX_Full |
  2262. SUPPORTED_10000baseT_Full |
  2263. SUPPORTED_TP |
  2264. SUPPORTED_FIBRE |
  2265. SUPPORTED_Autoneg |
  2266. SUPPORTED_Pause |
  2267. SUPPORTED_Asym_Pause);
  2268. bp->port.advertising[0] = bp->port.supported[0];
  2269. bp->link_params.bp = bp;
  2270. bp->link_params.port = BP_PORT(bp);
  2271. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2272. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2273. bp->link_params.req_line_speed[0] = SPEED_10000;
  2274. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2275. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2276. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2277. bp->link_vars.line_speed = SPEED_10000;
  2278. bp->link_vars.link_status =
  2279. (LINK_STATUS_LINK_UP |
  2280. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2281. bp->link_vars.link_up = 1;
  2282. bp->link_vars.duplex = DUPLEX_FULL;
  2283. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2284. __bnx2x_link_report(bp);
  2285. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2286. }
  2287. }
  2288. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2289. u16 vlan_val, u8 allowed_prio)
  2290. {
  2291. struct bnx2x_func_state_params func_params = {NULL};
  2292. struct bnx2x_func_afex_update_params *f_update_params =
  2293. &func_params.params.afex_update;
  2294. func_params.f_obj = &bp->func_obj;
  2295. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2296. /* no need to wait for RAMROD completion, so don't
  2297. * set RAMROD_COMP_WAIT flag
  2298. */
  2299. f_update_params->vif_id = vifid;
  2300. f_update_params->afex_default_vlan = vlan_val;
  2301. f_update_params->allowed_priorities = allowed_prio;
  2302. /* if ramrod can not be sent, response to MCP immediately */
  2303. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2304. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2305. return 0;
  2306. }
  2307. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2308. u16 vif_index, u8 func_bit_map)
  2309. {
  2310. struct bnx2x_func_state_params func_params = {NULL};
  2311. struct bnx2x_func_afex_viflists_params *update_params =
  2312. &func_params.params.afex_viflists;
  2313. int rc;
  2314. u32 drv_msg_code;
  2315. /* validate only LIST_SET and LIST_GET are received from switch */
  2316. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2317. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2318. cmd_type);
  2319. func_params.f_obj = &bp->func_obj;
  2320. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2321. /* set parameters according to cmd_type */
  2322. update_params->afex_vif_list_command = cmd_type;
  2323. update_params->vif_list_index = vif_index;
  2324. update_params->func_bit_map =
  2325. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2326. update_params->func_to_clear = 0;
  2327. drv_msg_code =
  2328. (cmd_type == VIF_LIST_RULE_GET) ?
  2329. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2330. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2331. /* if ramrod can not be sent, respond to MCP immediately for
  2332. * SET and GET requests (other are not triggered from MCP)
  2333. */
  2334. rc = bnx2x_func_state_change(bp, &func_params);
  2335. if (rc < 0)
  2336. bnx2x_fw_command(bp, drv_msg_code, 0);
  2337. return 0;
  2338. }
  2339. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2340. {
  2341. struct afex_stats afex_stats;
  2342. u32 func = BP_ABS_FUNC(bp);
  2343. u32 mf_config;
  2344. u16 vlan_val;
  2345. u32 vlan_prio;
  2346. u16 vif_id;
  2347. u8 allowed_prio;
  2348. u8 vlan_mode;
  2349. u32 addr_to_write, vifid, addrs, stats_type, i;
  2350. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2351. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2352. DP(BNX2X_MSG_MCP,
  2353. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2354. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2355. }
  2356. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2357. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2358. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2359. DP(BNX2X_MSG_MCP,
  2360. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2361. vifid, addrs);
  2362. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2363. addrs);
  2364. }
  2365. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2366. addr_to_write = SHMEM2_RD(bp,
  2367. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2368. stats_type = SHMEM2_RD(bp,
  2369. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2370. DP(BNX2X_MSG_MCP,
  2371. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2372. addr_to_write);
  2373. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2374. /* write response to scratchpad, for MCP */
  2375. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2376. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2377. *(((u32 *)(&afex_stats))+i));
  2378. /* send ack message to MCP */
  2379. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2380. }
  2381. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2382. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2383. bp->mf_config[BP_VN(bp)] = mf_config;
  2384. DP(BNX2X_MSG_MCP,
  2385. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2386. mf_config);
  2387. /* if VIF_SET is "enabled" */
  2388. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2389. /* set rate limit directly to internal RAM */
  2390. struct cmng_init_input cmng_input;
  2391. struct rate_shaping_vars_per_vn m_rs_vn;
  2392. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2393. u32 addr = BAR_XSTRORM_INTMEM +
  2394. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2395. bp->mf_config[BP_VN(bp)] = mf_config;
  2396. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2397. m_rs_vn.vn_counter.rate =
  2398. cmng_input.vnic_max_rate[BP_VN(bp)];
  2399. m_rs_vn.vn_counter.quota =
  2400. (m_rs_vn.vn_counter.rate *
  2401. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2402. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2403. /* read relevant values from mf_cfg struct in shmem */
  2404. vif_id =
  2405. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2406. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2407. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2408. vlan_val =
  2409. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2410. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2411. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2412. vlan_prio = (mf_config &
  2413. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2414. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2415. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2416. vlan_mode =
  2417. (MF_CFG_RD(bp,
  2418. func_mf_config[func].afex_config) &
  2419. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2420. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2421. allowed_prio =
  2422. (MF_CFG_RD(bp,
  2423. func_mf_config[func].afex_config) &
  2424. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2425. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2426. /* send ramrod to FW, return in case of failure */
  2427. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2428. allowed_prio))
  2429. return;
  2430. bp->afex_def_vlan_tag = vlan_val;
  2431. bp->afex_vlan_mode = vlan_mode;
  2432. } else {
  2433. /* notify link down because BP->flags is disabled */
  2434. bnx2x_link_report(bp);
  2435. /* send INVALID VIF ramrod to FW */
  2436. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2437. /* Reset the default afex VLAN */
  2438. bp->afex_def_vlan_tag = -1;
  2439. }
  2440. }
  2441. }
  2442. static void bnx2x_pmf_update(struct bnx2x *bp)
  2443. {
  2444. int port = BP_PORT(bp);
  2445. u32 val;
  2446. bp->port.pmf = 1;
  2447. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2448. /*
  2449. * We need the mb() to ensure the ordering between the writing to
  2450. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2451. */
  2452. smp_mb();
  2453. /* queue a periodic task */
  2454. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2455. bnx2x_dcbx_pmf_update(bp);
  2456. /* enable nig attention */
  2457. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2458. if (bp->common.int_block == INT_BLOCK_HC) {
  2459. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2460. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2461. } else if (!CHIP_IS_E1x(bp)) {
  2462. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2463. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2464. }
  2465. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2466. }
  2467. /* end of Link */
  2468. /* slow path */
  2469. /*
  2470. * General service functions
  2471. */
  2472. /* send the MCP a request, block until there is a reply */
  2473. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2474. {
  2475. int mb_idx = BP_FW_MB_IDX(bp);
  2476. u32 seq;
  2477. u32 rc = 0;
  2478. u32 cnt = 1;
  2479. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2480. mutex_lock(&bp->fw_mb_mutex);
  2481. seq = ++bp->fw_seq;
  2482. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2483. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2484. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2485. (command | seq), param);
  2486. do {
  2487. /* let the FW do it's magic ... */
  2488. msleep(delay);
  2489. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2490. /* Give the FW up to 5 second (500*10ms) */
  2491. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2492. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2493. cnt*delay, rc, seq);
  2494. /* is this a reply to our command? */
  2495. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2496. rc &= FW_MSG_CODE_MASK;
  2497. else {
  2498. /* FW BUG! */
  2499. BNX2X_ERR("FW failed to respond!\n");
  2500. bnx2x_fw_dump(bp);
  2501. rc = 0;
  2502. }
  2503. mutex_unlock(&bp->fw_mb_mutex);
  2504. return rc;
  2505. }
  2506. static void storm_memset_func_cfg(struct bnx2x *bp,
  2507. struct tstorm_eth_function_common_config *tcfg,
  2508. u16 abs_fid)
  2509. {
  2510. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2511. u32 addr = BAR_TSTRORM_INTMEM +
  2512. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2513. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2514. }
  2515. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2516. {
  2517. if (CHIP_IS_E1x(bp)) {
  2518. struct tstorm_eth_function_common_config tcfg = {0};
  2519. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2520. }
  2521. /* Enable the function in the FW */
  2522. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2523. storm_memset_func_en(bp, p->func_id, 1);
  2524. /* spq */
  2525. if (p->func_flgs & FUNC_FLG_SPQ) {
  2526. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2527. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2528. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2529. }
  2530. }
  2531. /**
  2532. * bnx2x_get_common_flags - Return common flags
  2533. *
  2534. * @bp device handle
  2535. * @fp queue handle
  2536. * @zero_stats TRUE if statistics zeroing is needed
  2537. *
  2538. * Return the flags that are common for the Tx-only and not normal connections.
  2539. */
  2540. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2541. struct bnx2x_fastpath *fp,
  2542. bool zero_stats)
  2543. {
  2544. unsigned long flags = 0;
  2545. /* PF driver will always initialize the Queue to an ACTIVE state */
  2546. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2547. /* tx only connections collect statistics (on the same index as the
  2548. * parent connection). The statistics are zeroed when the parent
  2549. * connection is initialized.
  2550. */
  2551. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2552. if (zero_stats)
  2553. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2554. if (bp->flags & TX_SWITCHING)
  2555. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2556. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2557. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2558. #ifdef BNX2X_STOP_ON_ERROR
  2559. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2560. #endif
  2561. return flags;
  2562. }
  2563. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2564. struct bnx2x_fastpath *fp,
  2565. bool leading)
  2566. {
  2567. unsigned long flags = 0;
  2568. /* calculate other queue flags */
  2569. if (IS_MF_SD(bp))
  2570. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2571. if (IS_FCOE_FP(fp)) {
  2572. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2573. /* For FCoE - force usage of default priority (for afex) */
  2574. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2575. }
  2576. if (!fp->disable_tpa) {
  2577. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2578. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2579. if (fp->mode == TPA_MODE_GRO)
  2580. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2581. }
  2582. if (leading) {
  2583. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2584. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2585. }
  2586. /* Always set HW VLAN stripping */
  2587. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2588. /* configure silent vlan removal */
  2589. if (IS_MF_AFEX(bp))
  2590. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2591. return flags | bnx2x_get_common_flags(bp, fp, true);
  2592. }
  2593. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2594. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2595. u8 cos)
  2596. {
  2597. gen_init->stat_id = bnx2x_stats_id(fp);
  2598. gen_init->spcl_id = fp->cl_id;
  2599. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2600. if (IS_FCOE_FP(fp))
  2601. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2602. else
  2603. gen_init->mtu = bp->dev->mtu;
  2604. gen_init->cos = cos;
  2605. }
  2606. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2607. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2608. struct bnx2x_rxq_setup_params *rxq_init)
  2609. {
  2610. u8 max_sge = 0;
  2611. u16 sge_sz = 0;
  2612. u16 tpa_agg_size = 0;
  2613. if (!fp->disable_tpa) {
  2614. pause->sge_th_lo = SGE_TH_LO(bp);
  2615. pause->sge_th_hi = SGE_TH_HI(bp);
  2616. /* validate SGE ring has enough to cross high threshold */
  2617. WARN_ON(bp->dropless_fc &&
  2618. pause->sge_th_hi + FW_PREFETCH_CNT >
  2619. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2620. tpa_agg_size = TPA_AGG_SIZE;
  2621. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2622. SGE_PAGE_SHIFT;
  2623. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2624. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2625. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2626. }
  2627. /* pause - not for e1 */
  2628. if (!CHIP_IS_E1(bp)) {
  2629. pause->bd_th_lo = BD_TH_LO(bp);
  2630. pause->bd_th_hi = BD_TH_HI(bp);
  2631. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2632. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2633. /*
  2634. * validate that rings have enough entries to cross
  2635. * high thresholds
  2636. */
  2637. WARN_ON(bp->dropless_fc &&
  2638. pause->bd_th_hi + FW_PREFETCH_CNT >
  2639. bp->rx_ring_size);
  2640. WARN_ON(bp->dropless_fc &&
  2641. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2642. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2643. pause->pri_map = 1;
  2644. }
  2645. /* rxq setup */
  2646. rxq_init->dscr_map = fp->rx_desc_mapping;
  2647. rxq_init->sge_map = fp->rx_sge_mapping;
  2648. rxq_init->rcq_map = fp->rx_comp_mapping;
  2649. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2650. /* This should be a maximum number of data bytes that may be
  2651. * placed on the BD (not including paddings).
  2652. */
  2653. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2654. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2655. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2656. rxq_init->tpa_agg_sz = tpa_agg_size;
  2657. rxq_init->sge_buf_sz = sge_sz;
  2658. rxq_init->max_sges_pkt = max_sge;
  2659. rxq_init->rss_engine_id = BP_FUNC(bp);
  2660. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2661. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2662. *
  2663. * For PF Clients it should be the maximum available number.
  2664. * VF driver(s) may want to define it to a smaller value.
  2665. */
  2666. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2667. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2668. rxq_init->fw_sb_id = fp->fw_sb_id;
  2669. if (IS_FCOE_FP(fp))
  2670. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2671. else
  2672. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2673. /* configure silent vlan removal
  2674. * if multi function mode is afex, then mask default vlan
  2675. */
  2676. if (IS_MF_AFEX(bp)) {
  2677. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2678. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2679. }
  2680. }
  2681. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2682. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2683. u8 cos)
  2684. {
  2685. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2686. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2687. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2688. txq_init->fw_sb_id = fp->fw_sb_id;
  2689. /*
  2690. * set the tss leading client id for TX classification ==
  2691. * leading RSS client id
  2692. */
  2693. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2694. if (IS_FCOE_FP(fp)) {
  2695. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2696. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2697. }
  2698. }
  2699. static void bnx2x_pf_init(struct bnx2x *bp)
  2700. {
  2701. struct bnx2x_func_init_params func_init = {0};
  2702. struct event_ring_data eq_data = { {0} };
  2703. u16 flags;
  2704. if (!CHIP_IS_E1x(bp)) {
  2705. /* reset IGU PF statistics: MSIX + ATTN */
  2706. /* PF */
  2707. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2708. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2709. (CHIP_MODE_IS_4_PORT(bp) ?
  2710. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2711. /* ATTN */
  2712. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2713. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2714. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2715. (CHIP_MODE_IS_4_PORT(bp) ?
  2716. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2717. }
  2718. /* function setup flags */
  2719. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2720. /* This flag is relevant for E1x only.
  2721. * E2 doesn't have a TPA configuration in a function level.
  2722. */
  2723. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2724. func_init.func_flgs = flags;
  2725. func_init.pf_id = BP_FUNC(bp);
  2726. func_init.func_id = BP_FUNC(bp);
  2727. func_init.spq_map = bp->spq_mapping;
  2728. func_init.spq_prod = bp->spq_prod_idx;
  2729. bnx2x_func_init(bp, &func_init);
  2730. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2731. /*
  2732. * Congestion management values depend on the link rate
  2733. * There is no active link so initial link rate is set to 10 Gbps.
  2734. * When the link comes up The congestion management values are
  2735. * re-calculated according to the actual link rate.
  2736. */
  2737. bp->link_vars.line_speed = SPEED_10000;
  2738. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2739. /* Only the PMF sets the HW */
  2740. if (bp->port.pmf)
  2741. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2742. /* init Event Queue - PCI bus guarantees correct endianity*/
  2743. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2744. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2745. eq_data.producer = bp->eq_prod;
  2746. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2747. eq_data.sb_id = DEF_SB_ID;
  2748. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2749. }
  2750. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2751. {
  2752. int port = BP_PORT(bp);
  2753. bnx2x_tx_disable(bp);
  2754. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2755. }
  2756. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2757. {
  2758. int port = BP_PORT(bp);
  2759. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2760. /* Tx queue should be only re-enabled */
  2761. netif_tx_wake_all_queues(bp->dev);
  2762. /*
  2763. * Should not call netif_carrier_on since it will be called if the link
  2764. * is up when checking for link state
  2765. */
  2766. }
  2767. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2768. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2769. {
  2770. struct eth_stats_info *ether_stat =
  2771. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2772. struct bnx2x_vlan_mac_obj *mac_obj =
  2773. &bp->sp_objs->mac_obj;
  2774. int i;
  2775. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2776. ETH_STAT_INFO_VERSION_LEN);
  2777. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2778. * mac_local field in ether_stat struct. The base address is offset by 2
  2779. * bytes to account for the field being 8 bytes but a mac address is
  2780. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2781. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2782. * allocated by the ether_stat struct, so the macs will land in their
  2783. * proper positions.
  2784. */
  2785. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2786. memset(ether_stat->mac_local + i, 0,
  2787. sizeof(ether_stat->mac_local[0]));
  2788. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2789. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2790. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2791. ETH_ALEN);
  2792. ether_stat->mtu_size = bp->dev->mtu;
  2793. if (bp->dev->features & NETIF_F_RXCSUM)
  2794. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2795. if (bp->dev->features & NETIF_F_TSO)
  2796. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2797. ether_stat->feature_flags |= bp->common.boot_mode;
  2798. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2799. ether_stat->txq_size = bp->tx_ring_size;
  2800. ether_stat->rxq_size = bp->rx_ring_size;
  2801. #ifdef CONFIG_BNX2X_SRIOV
  2802. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2803. #endif
  2804. }
  2805. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2806. {
  2807. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2808. struct fcoe_stats_info *fcoe_stat =
  2809. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2810. if (!CNIC_LOADED(bp))
  2811. return;
  2812. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2813. fcoe_stat->qos_priority =
  2814. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2815. /* insert FCoE stats from ramrod response */
  2816. if (!NO_FCOE(bp)) {
  2817. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2818. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2819. tstorm_queue_statistics;
  2820. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2821. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2822. xstorm_queue_statistics;
  2823. struct fcoe_statistics_params *fw_fcoe_stat =
  2824. &bp->fw_stats_data->fcoe;
  2825. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2826. fcoe_stat->rx_bytes_lo,
  2827. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2828. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2829. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2830. fcoe_stat->rx_bytes_lo,
  2831. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2832. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2833. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2834. fcoe_stat->rx_bytes_lo,
  2835. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2836. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2837. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2838. fcoe_stat->rx_bytes_lo,
  2839. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2840. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2841. fcoe_stat->rx_frames_lo,
  2842. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2843. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2844. fcoe_stat->rx_frames_lo,
  2845. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2846. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2847. fcoe_stat->rx_frames_lo,
  2848. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2849. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2850. fcoe_stat->rx_frames_lo,
  2851. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2852. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2853. fcoe_stat->tx_bytes_lo,
  2854. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2855. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2856. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2857. fcoe_stat->tx_bytes_lo,
  2858. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2859. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2860. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2861. fcoe_stat->tx_bytes_lo,
  2862. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2863. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2864. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2865. fcoe_stat->tx_bytes_lo,
  2866. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2867. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2868. fcoe_stat->tx_frames_lo,
  2869. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2870. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2871. fcoe_stat->tx_frames_lo,
  2872. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2873. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2874. fcoe_stat->tx_frames_lo,
  2875. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2876. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2877. fcoe_stat->tx_frames_lo,
  2878. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2879. }
  2880. /* ask L5 driver to add data to the struct */
  2881. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2882. }
  2883. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2884. {
  2885. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2886. struct iscsi_stats_info *iscsi_stat =
  2887. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2888. if (!CNIC_LOADED(bp))
  2889. return;
  2890. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2891. ETH_ALEN);
  2892. iscsi_stat->qos_priority =
  2893. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2894. /* ask L5 driver to add data to the struct */
  2895. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2896. }
  2897. /* called due to MCP event (on pmf):
  2898. * reread new bandwidth configuration
  2899. * configure FW
  2900. * notify others function about the change
  2901. */
  2902. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2903. {
  2904. if (bp->link_vars.link_up) {
  2905. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2906. bnx2x_link_sync_notify(bp);
  2907. }
  2908. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2909. }
  2910. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2911. {
  2912. bnx2x_config_mf_bw(bp);
  2913. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2914. }
  2915. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2916. {
  2917. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2918. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2919. }
  2920. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2921. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2922. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2923. {
  2924. enum drv_info_opcode op_code;
  2925. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2926. bool release = false;
  2927. int wait;
  2928. /* if drv_info version supported by MFW doesn't match - send NACK */
  2929. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2930. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2931. return;
  2932. }
  2933. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2934. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2935. /* Must prevent other flows from accessing drv_info_to_mcp */
  2936. mutex_lock(&bp->drv_info_mutex);
  2937. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2938. sizeof(union drv_info_to_mcp));
  2939. switch (op_code) {
  2940. case ETH_STATS_OPCODE:
  2941. bnx2x_drv_info_ether_stat(bp);
  2942. break;
  2943. case FCOE_STATS_OPCODE:
  2944. bnx2x_drv_info_fcoe_stat(bp);
  2945. break;
  2946. case ISCSI_STATS_OPCODE:
  2947. bnx2x_drv_info_iscsi_stat(bp);
  2948. break;
  2949. default:
  2950. /* if op code isn't supported - send NACK */
  2951. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2952. goto out;
  2953. }
  2954. /* if we got drv_info attn from MFW then these fields are defined in
  2955. * shmem2 for sure
  2956. */
  2957. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2958. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2959. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2960. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2961. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2962. /* Since possible management wants both this and get_driver_version
  2963. * need to wait until management notifies us it finished utilizing
  2964. * the buffer.
  2965. */
  2966. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  2967. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  2968. } else if (!bp->drv_info_mng_owner) {
  2969. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  2970. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  2971. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  2972. /* Management is done; need to clear indication */
  2973. if (indication & bit) {
  2974. SHMEM2_WR(bp, mfw_drv_indication,
  2975. indication & ~bit);
  2976. release = true;
  2977. break;
  2978. }
  2979. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  2980. }
  2981. }
  2982. if (!release) {
  2983. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  2984. bp->drv_info_mng_owner = true;
  2985. }
  2986. out:
  2987. mutex_unlock(&bp->drv_info_mutex);
  2988. }
  2989. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  2990. {
  2991. u8 vals[4];
  2992. int i = 0;
  2993. if (bnx2x_format) {
  2994. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  2995. &vals[0], &vals[1], &vals[2], &vals[3]);
  2996. if (i > 0)
  2997. vals[0] -= '0';
  2998. } else {
  2999. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3000. &vals[0], &vals[1], &vals[2], &vals[3]);
  3001. }
  3002. while (i < 4)
  3003. vals[i++] = 0;
  3004. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3005. }
  3006. void bnx2x_update_mng_version(struct bnx2x *bp)
  3007. {
  3008. u32 iscsiver = DRV_VER_NOT_LOADED;
  3009. u32 fcoever = DRV_VER_NOT_LOADED;
  3010. u32 ethver = DRV_VER_NOT_LOADED;
  3011. int idx = BP_FW_MB_IDX(bp);
  3012. u8 *version;
  3013. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3014. return;
  3015. mutex_lock(&bp->drv_info_mutex);
  3016. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3017. if (bp->drv_info_mng_owner)
  3018. goto out;
  3019. if (bp->state != BNX2X_STATE_OPEN)
  3020. goto out;
  3021. /* Parse ethernet driver version */
  3022. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3023. if (!CNIC_LOADED(bp))
  3024. goto out;
  3025. /* Try getting storage driver version via cnic */
  3026. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3027. sizeof(union drv_info_to_mcp));
  3028. bnx2x_drv_info_iscsi_stat(bp);
  3029. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3030. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3031. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3032. sizeof(union drv_info_to_mcp));
  3033. bnx2x_drv_info_fcoe_stat(bp);
  3034. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3035. fcoever = bnx2x_update_mng_version_utility(version, false);
  3036. out:
  3037. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3038. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3039. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3040. mutex_unlock(&bp->drv_info_mutex);
  3041. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3042. ethver, iscsiver, fcoever);
  3043. }
  3044. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  3045. {
  3046. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  3047. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  3048. /*
  3049. * This is the only place besides the function initialization
  3050. * where the bp->flags can change so it is done without any
  3051. * locks
  3052. */
  3053. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3054. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3055. bp->flags |= MF_FUNC_DIS;
  3056. bnx2x_e1h_disable(bp);
  3057. } else {
  3058. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3059. bp->flags &= ~MF_FUNC_DIS;
  3060. bnx2x_e1h_enable(bp);
  3061. }
  3062. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  3063. }
  3064. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  3065. bnx2x_config_mf_bw(bp);
  3066. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  3067. }
  3068. /* Report results to MCP */
  3069. if (dcc_event)
  3070. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  3071. else
  3072. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  3073. }
  3074. /* must be called under the spq lock */
  3075. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3076. {
  3077. struct eth_spe *next_spe = bp->spq_prod_bd;
  3078. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3079. bp->spq_prod_bd = bp->spq;
  3080. bp->spq_prod_idx = 0;
  3081. DP(BNX2X_MSG_SP, "end of spq\n");
  3082. } else {
  3083. bp->spq_prod_bd++;
  3084. bp->spq_prod_idx++;
  3085. }
  3086. return next_spe;
  3087. }
  3088. /* must be called under the spq lock */
  3089. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3090. {
  3091. int func = BP_FUNC(bp);
  3092. /*
  3093. * Make sure that BD data is updated before writing the producer:
  3094. * BD data is written to the memory, the producer is read from the
  3095. * memory, thus we need a full memory barrier to ensure the ordering.
  3096. */
  3097. mb();
  3098. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3099. bp->spq_prod_idx);
  3100. mmiowb();
  3101. }
  3102. /**
  3103. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3104. *
  3105. * @cmd: command to check
  3106. * @cmd_type: command type
  3107. */
  3108. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3109. {
  3110. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3111. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3112. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3113. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3114. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3115. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3116. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3117. return true;
  3118. else
  3119. return false;
  3120. }
  3121. /**
  3122. * bnx2x_sp_post - place a single command on an SP ring
  3123. *
  3124. * @bp: driver handle
  3125. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3126. * @cid: SW CID the command is related to
  3127. * @data_hi: command private data address (high 32 bits)
  3128. * @data_lo: command private data address (low 32 bits)
  3129. * @cmd_type: command type (e.g. NONE, ETH)
  3130. *
  3131. * SP data is handled as if it's always an address pair, thus data fields are
  3132. * not swapped to little endian in upper functions. Instead this function swaps
  3133. * data as if it's two u32 fields.
  3134. */
  3135. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3136. u32 data_hi, u32 data_lo, int cmd_type)
  3137. {
  3138. struct eth_spe *spe;
  3139. u16 type;
  3140. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3141. #ifdef BNX2X_STOP_ON_ERROR
  3142. if (unlikely(bp->panic)) {
  3143. BNX2X_ERR("Can't post SP when there is panic\n");
  3144. return -EIO;
  3145. }
  3146. #endif
  3147. spin_lock_bh(&bp->spq_lock);
  3148. if (common) {
  3149. if (!atomic_read(&bp->eq_spq_left)) {
  3150. BNX2X_ERR("BUG! EQ ring full!\n");
  3151. spin_unlock_bh(&bp->spq_lock);
  3152. bnx2x_panic();
  3153. return -EBUSY;
  3154. }
  3155. } else if (!atomic_read(&bp->cq_spq_left)) {
  3156. BNX2X_ERR("BUG! SPQ ring full!\n");
  3157. spin_unlock_bh(&bp->spq_lock);
  3158. bnx2x_panic();
  3159. return -EBUSY;
  3160. }
  3161. spe = bnx2x_sp_get_next(bp);
  3162. /* CID needs port number to be encoded int it */
  3163. spe->hdr.conn_and_cmd_data =
  3164. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3165. HW_CID(bp, cid));
  3166. /* In some cases, type may already contain the func-id
  3167. * mainly in SRIOV related use cases, so we add it here only
  3168. * if it's not already set.
  3169. */
  3170. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3171. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3172. SPE_HDR_CONN_TYPE;
  3173. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3174. SPE_HDR_FUNCTION_ID);
  3175. } else {
  3176. type = cmd_type;
  3177. }
  3178. spe->hdr.type = cpu_to_le16(type);
  3179. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3180. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3181. /*
  3182. * It's ok if the actual decrement is issued towards the memory
  3183. * somewhere between the spin_lock and spin_unlock. Thus no
  3184. * more explicit memory barrier is needed.
  3185. */
  3186. if (common)
  3187. atomic_dec(&bp->eq_spq_left);
  3188. else
  3189. atomic_dec(&bp->cq_spq_left);
  3190. DP(BNX2X_MSG_SP,
  3191. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3192. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3193. (u32)(U64_LO(bp->spq_mapping) +
  3194. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3195. HW_CID(bp, cid), data_hi, data_lo, type,
  3196. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3197. bnx2x_sp_prod_update(bp);
  3198. spin_unlock_bh(&bp->spq_lock);
  3199. return 0;
  3200. }
  3201. /* acquire split MCP access lock register */
  3202. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3203. {
  3204. u32 j, val;
  3205. int rc = 0;
  3206. might_sleep();
  3207. for (j = 0; j < 1000; j++) {
  3208. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3209. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3210. if (val & MCPR_ACCESS_LOCK_LOCK)
  3211. break;
  3212. usleep_range(5000, 10000);
  3213. }
  3214. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3215. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3216. rc = -EBUSY;
  3217. }
  3218. return rc;
  3219. }
  3220. /* release split MCP access lock register */
  3221. static void bnx2x_release_alr(struct bnx2x *bp)
  3222. {
  3223. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3224. }
  3225. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3226. #define BNX2X_DEF_SB_IDX 0x0002
  3227. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3228. {
  3229. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3230. u16 rc = 0;
  3231. barrier(); /* status block is written to by the chip */
  3232. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3233. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3234. rc |= BNX2X_DEF_SB_ATT_IDX;
  3235. }
  3236. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3237. bp->def_idx = def_sb->sp_sb.running_index;
  3238. rc |= BNX2X_DEF_SB_IDX;
  3239. }
  3240. /* Do not reorder: indices reading should complete before handling */
  3241. barrier();
  3242. return rc;
  3243. }
  3244. /*
  3245. * slow path service functions
  3246. */
  3247. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3248. {
  3249. int port = BP_PORT(bp);
  3250. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3251. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3252. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3253. NIG_REG_MASK_INTERRUPT_PORT0;
  3254. u32 aeu_mask;
  3255. u32 nig_mask = 0;
  3256. u32 reg_addr;
  3257. if (bp->attn_state & asserted)
  3258. BNX2X_ERR("IGU ERROR\n");
  3259. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3260. aeu_mask = REG_RD(bp, aeu_addr);
  3261. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3262. aeu_mask, asserted);
  3263. aeu_mask &= ~(asserted & 0x3ff);
  3264. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3265. REG_WR(bp, aeu_addr, aeu_mask);
  3266. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3267. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3268. bp->attn_state |= asserted;
  3269. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3270. if (asserted & ATTN_HARD_WIRED_MASK) {
  3271. if (asserted & ATTN_NIG_FOR_FUNC) {
  3272. bnx2x_acquire_phy_lock(bp);
  3273. /* save nig interrupt mask */
  3274. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3275. /* If nig_mask is not set, no need to call the update
  3276. * function.
  3277. */
  3278. if (nig_mask) {
  3279. REG_WR(bp, nig_int_mask_addr, 0);
  3280. bnx2x_link_attn(bp);
  3281. }
  3282. /* handle unicore attn? */
  3283. }
  3284. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3285. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3286. if (asserted & GPIO_2_FUNC)
  3287. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3288. if (asserted & GPIO_3_FUNC)
  3289. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3290. if (asserted & GPIO_4_FUNC)
  3291. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3292. if (port == 0) {
  3293. if (asserted & ATTN_GENERAL_ATTN_1) {
  3294. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3295. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3296. }
  3297. if (asserted & ATTN_GENERAL_ATTN_2) {
  3298. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3299. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3300. }
  3301. if (asserted & ATTN_GENERAL_ATTN_3) {
  3302. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3303. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3304. }
  3305. } else {
  3306. if (asserted & ATTN_GENERAL_ATTN_4) {
  3307. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3308. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3309. }
  3310. if (asserted & ATTN_GENERAL_ATTN_5) {
  3311. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3312. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3313. }
  3314. if (asserted & ATTN_GENERAL_ATTN_6) {
  3315. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3316. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3317. }
  3318. }
  3319. } /* if hardwired */
  3320. if (bp->common.int_block == INT_BLOCK_HC)
  3321. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3322. COMMAND_REG_ATTN_BITS_SET);
  3323. else
  3324. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3325. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3326. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3327. REG_WR(bp, reg_addr, asserted);
  3328. /* now set back the mask */
  3329. if (asserted & ATTN_NIG_FOR_FUNC) {
  3330. /* Verify that IGU ack through BAR was written before restoring
  3331. * NIG mask. This loop should exit after 2-3 iterations max.
  3332. */
  3333. if (bp->common.int_block != INT_BLOCK_HC) {
  3334. u32 cnt = 0, igu_acked;
  3335. do {
  3336. igu_acked = REG_RD(bp,
  3337. IGU_REG_ATTENTION_ACK_BITS);
  3338. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3339. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3340. if (!igu_acked)
  3341. DP(NETIF_MSG_HW,
  3342. "Failed to verify IGU ack on time\n");
  3343. barrier();
  3344. }
  3345. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3346. bnx2x_release_phy_lock(bp);
  3347. }
  3348. }
  3349. static void bnx2x_fan_failure(struct bnx2x *bp)
  3350. {
  3351. int port = BP_PORT(bp);
  3352. u32 ext_phy_config;
  3353. /* mark the failure */
  3354. ext_phy_config =
  3355. SHMEM_RD(bp,
  3356. dev_info.port_hw_config[port].external_phy_config);
  3357. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3358. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3359. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3360. ext_phy_config);
  3361. /* log the failure */
  3362. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3363. "Please contact OEM Support for assistance\n");
  3364. /* Schedule device reset (unload)
  3365. * This is due to some boards consuming sufficient power when driver is
  3366. * up to overheat if fan fails.
  3367. */
  3368. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3369. }
  3370. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3371. {
  3372. int port = BP_PORT(bp);
  3373. int reg_offset;
  3374. u32 val;
  3375. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3376. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3377. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3378. val = REG_RD(bp, reg_offset);
  3379. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3380. REG_WR(bp, reg_offset, val);
  3381. BNX2X_ERR("SPIO5 hw attention\n");
  3382. /* Fan failure attention */
  3383. bnx2x_hw_reset_phy(&bp->link_params);
  3384. bnx2x_fan_failure(bp);
  3385. }
  3386. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3387. bnx2x_acquire_phy_lock(bp);
  3388. bnx2x_handle_module_detect_int(&bp->link_params);
  3389. bnx2x_release_phy_lock(bp);
  3390. }
  3391. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3392. val = REG_RD(bp, reg_offset);
  3393. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3394. REG_WR(bp, reg_offset, val);
  3395. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3396. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3397. bnx2x_panic();
  3398. }
  3399. }
  3400. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3401. {
  3402. u32 val;
  3403. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3404. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3405. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3406. /* DORQ discard attention */
  3407. if (val & 0x2)
  3408. BNX2X_ERR("FATAL error from DORQ\n");
  3409. }
  3410. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3411. int port = BP_PORT(bp);
  3412. int reg_offset;
  3413. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3414. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3415. val = REG_RD(bp, reg_offset);
  3416. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3417. REG_WR(bp, reg_offset, val);
  3418. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3419. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3420. bnx2x_panic();
  3421. }
  3422. }
  3423. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3424. {
  3425. u32 val;
  3426. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3427. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3428. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3429. /* CFC error attention */
  3430. if (val & 0x2)
  3431. BNX2X_ERR("FATAL error from CFC\n");
  3432. }
  3433. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3434. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3435. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3436. /* RQ_USDMDP_FIFO_OVERFLOW */
  3437. if (val & 0x18000)
  3438. BNX2X_ERR("FATAL error from PXP\n");
  3439. if (!CHIP_IS_E1x(bp)) {
  3440. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3441. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3442. }
  3443. }
  3444. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3445. int port = BP_PORT(bp);
  3446. int reg_offset;
  3447. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3448. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3449. val = REG_RD(bp, reg_offset);
  3450. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3451. REG_WR(bp, reg_offset, val);
  3452. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3453. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3454. bnx2x_panic();
  3455. }
  3456. }
  3457. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3458. {
  3459. u32 val;
  3460. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3461. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3462. int func = BP_FUNC(bp);
  3463. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3464. bnx2x_read_mf_cfg(bp);
  3465. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3466. func_mf_config[BP_ABS_FUNC(bp)].config);
  3467. val = SHMEM_RD(bp,
  3468. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3469. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3470. bnx2x_dcc_event(bp,
  3471. (val & DRV_STATUS_DCC_EVENT_MASK));
  3472. if (val & DRV_STATUS_SET_MF_BW)
  3473. bnx2x_set_mf_bw(bp);
  3474. if (val & DRV_STATUS_DRV_INFO_REQ)
  3475. bnx2x_handle_drv_info_req(bp);
  3476. if (val & DRV_STATUS_VF_DISABLED)
  3477. bnx2x_schedule_iov_task(bp,
  3478. BNX2X_IOV_HANDLE_FLR);
  3479. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3480. bnx2x_pmf_update(bp);
  3481. if (bp->port.pmf &&
  3482. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3483. bp->dcbx_enabled > 0)
  3484. /* start dcbx state machine */
  3485. bnx2x_dcbx_set_params(bp,
  3486. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3487. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3488. bnx2x_handle_afex_cmd(bp,
  3489. val & DRV_STATUS_AFEX_EVENT_MASK);
  3490. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3491. bnx2x_handle_eee_event(bp);
  3492. if (bp->link_vars.periodic_flags &
  3493. PERIODIC_FLAGS_LINK_EVENT) {
  3494. /* sync with link */
  3495. bnx2x_acquire_phy_lock(bp);
  3496. bp->link_vars.periodic_flags &=
  3497. ~PERIODIC_FLAGS_LINK_EVENT;
  3498. bnx2x_release_phy_lock(bp);
  3499. if (IS_MF(bp))
  3500. bnx2x_link_sync_notify(bp);
  3501. bnx2x_link_report(bp);
  3502. }
  3503. /* Always call it here: bnx2x_link_report() will
  3504. * prevent the link indication duplication.
  3505. */
  3506. bnx2x__link_status_update(bp);
  3507. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3508. BNX2X_ERR("MC assert!\n");
  3509. bnx2x_mc_assert(bp);
  3510. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3511. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3512. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3513. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3514. bnx2x_panic();
  3515. } else if (attn & BNX2X_MCP_ASSERT) {
  3516. BNX2X_ERR("MCP assert!\n");
  3517. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3518. bnx2x_fw_dump(bp);
  3519. } else
  3520. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3521. }
  3522. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3523. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3524. if (attn & BNX2X_GRC_TIMEOUT) {
  3525. val = CHIP_IS_E1(bp) ? 0 :
  3526. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3527. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3528. }
  3529. if (attn & BNX2X_GRC_RSV) {
  3530. val = CHIP_IS_E1(bp) ? 0 :
  3531. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3532. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3533. }
  3534. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3535. }
  3536. }
  3537. /*
  3538. * Bits map:
  3539. * 0-7 - Engine0 load counter.
  3540. * 8-15 - Engine1 load counter.
  3541. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3542. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3543. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3544. * on the engine
  3545. * 19 - Engine1 ONE_IS_LOADED.
  3546. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3547. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3548. * just the one belonging to its engine).
  3549. *
  3550. */
  3551. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3552. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3553. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3554. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3555. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3556. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3557. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3558. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3559. /*
  3560. * Set the GLOBAL_RESET bit.
  3561. *
  3562. * Should be run under rtnl lock
  3563. */
  3564. void bnx2x_set_reset_global(struct bnx2x *bp)
  3565. {
  3566. u32 val;
  3567. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3568. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3569. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3570. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3571. }
  3572. /*
  3573. * Clear the GLOBAL_RESET bit.
  3574. *
  3575. * Should be run under rtnl lock
  3576. */
  3577. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3578. {
  3579. u32 val;
  3580. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3581. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3582. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3583. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3584. }
  3585. /*
  3586. * Checks the GLOBAL_RESET bit.
  3587. *
  3588. * should be run under rtnl lock
  3589. */
  3590. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3591. {
  3592. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3593. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3594. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3595. }
  3596. /*
  3597. * Clear RESET_IN_PROGRESS bit for the current engine.
  3598. *
  3599. * Should be run under rtnl lock
  3600. */
  3601. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3602. {
  3603. u32 val;
  3604. u32 bit = BP_PATH(bp) ?
  3605. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3606. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3607. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3608. /* Clear the bit */
  3609. val &= ~bit;
  3610. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3611. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3612. }
  3613. /*
  3614. * Set RESET_IN_PROGRESS for the current engine.
  3615. *
  3616. * should be run under rtnl lock
  3617. */
  3618. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3619. {
  3620. u32 val;
  3621. u32 bit = BP_PATH(bp) ?
  3622. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3623. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3624. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3625. /* Set the bit */
  3626. val |= bit;
  3627. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3628. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3629. }
  3630. /*
  3631. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3632. * should be run under rtnl lock
  3633. */
  3634. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3635. {
  3636. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3637. u32 bit = engine ?
  3638. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3639. /* return false if bit is set */
  3640. return (val & bit) ? false : true;
  3641. }
  3642. /*
  3643. * set pf load for the current pf.
  3644. *
  3645. * should be run under rtnl lock
  3646. */
  3647. void bnx2x_set_pf_load(struct bnx2x *bp)
  3648. {
  3649. u32 val1, val;
  3650. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3651. BNX2X_PATH0_LOAD_CNT_MASK;
  3652. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3653. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3654. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3655. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3656. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3657. /* get the current counter value */
  3658. val1 = (val & mask) >> shift;
  3659. /* set bit of that PF */
  3660. val1 |= (1 << bp->pf_num);
  3661. /* clear the old value */
  3662. val &= ~mask;
  3663. /* set the new one */
  3664. val |= ((val1 << shift) & mask);
  3665. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3666. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3667. }
  3668. /**
  3669. * bnx2x_clear_pf_load - clear pf load mark
  3670. *
  3671. * @bp: driver handle
  3672. *
  3673. * Should be run under rtnl lock.
  3674. * Decrements the load counter for the current engine. Returns
  3675. * whether other functions are still loaded
  3676. */
  3677. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3678. {
  3679. u32 val1, val;
  3680. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3681. BNX2X_PATH0_LOAD_CNT_MASK;
  3682. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3683. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3684. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3685. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3686. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3687. /* get the current counter value */
  3688. val1 = (val & mask) >> shift;
  3689. /* clear bit of that PF */
  3690. val1 &= ~(1 << bp->pf_num);
  3691. /* clear the old value */
  3692. val &= ~mask;
  3693. /* set the new one */
  3694. val |= ((val1 << shift) & mask);
  3695. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3696. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3697. return val1 != 0;
  3698. }
  3699. /*
  3700. * Read the load status for the current engine.
  3701. *
  3702. * should be run under rtnl lock
  3703. */
  3704. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3705. {
  3706. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3707. BNX2X_PATH0_LOAD_CNT_MASK);
  3708. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3709. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3710. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3711. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3712. val = (val & mask) >> shift;
  3713. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3714. engine, val);
  3715. return val != 0;
  3716. }
  3717. static void _print_parity(struct bnx2x *bp, u32 reg)
  3718. {
  3719. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3720. }
  3721. static void _print_next_block(int idx, const char *blk)
  3722. {
  3723. pr_cont("%s%s", idx ? ", " : "", blk);
  3724. }
  3725. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3726. int *par_num, bool print)
  3727. {
  3728. u32 cur_bit;
  3729. bool res;
  3730. int i;
  3731. res = false;
  3732. for (i = 0; sig; i++) {
  3733. cur_bit = (0x1UL << i);
  3734. if (sig & cur_bit) {
  3735. res |= true; /* Each bit is real error! */
  3736. if (print) {
  3737. switch (cur_bit) {
  3738. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3739. _print_next_block((*par_num)++, "BRB");
  3740. _print_parity(bp,
  3741. BRB1_REG_BRB1_PRTY_STS);
  3742. break;
  3743. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3744. _print_next_block((*par_num)++,
  3745. "PARSER");
  3746. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3747. break;
  3748. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3749. _print_next_block((*par_num)++, "TSDM");
  3750. _print_parity(bp,
  3751. TSDM_REG_TSDM_PRTY_STS);
  3752. break;
  3753. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3754. _print_next_block((*par_num)++,
  3755. "SEARCHER");
  3756. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3757. break;
  3758. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3759. _print_next_block((*par_num)++, "TCM");
  3760. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3761. break;
  3762. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3763. _print_next_block((*par_num)++,
  3764. "TSEMI");
  3765. _print_parity(bp,
  3766. TSEM_REG_TSEM_PRTY_STS_0);
  3767. _print_parity(bp,
  3768. TSEM_REG_TSEM_PRTY_STS_1);
  3769. break;
  3770. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3771. _print_next_block((*par_num)++, "XPB");
  3772. _print_parity(bp, GRCBASE_XPB +
  3773. PB_REG_PB_PRTY_STS);
  3774. break;
  3775. }
  3776. }
  3777. /* Clear the bit */
  3778. sig &= ~cur_bit;
  3779. }
  3780. }
  3781. return res;
  3782. }
  3783. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3784. int *par_num, bool *global,
  3785. bool print)
  3786. {
  3787. u32 cur_bit;
  3788. bool res;
  3789. int i;
  3790. res = false;
  3791. for (i = 0; sig; i++) {
  3792. cur_bit = (0x1UL << i);
  3793. if (sig & cur_bit) {
  3794. res |= true; /* Each bit is real error! */
  3795. switch (cur_bit) {
  3796. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3797. if (print) {
  3798. _print_next_block((*par_num)++, "PBF");
  3799. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3800. }
  3801. break;
  3802. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3803. if (print) {
  3804. _print_next_block((*par_num)++, "QM");
  3805. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3806. }
  3807. break;
  3808. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3809. if (print) {
  3810. _print_next_block((*par_num)++, "TM");
  3811. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3812. }
  3813. break;
  3814. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3815. if (print) {
  3816. _print_next_block((*par_num)++, "XSDM");
  3817. _print_parity(bp,
  3818. XSDM_REG_XSDM_PRTY_STS);
  3819. }
  3820. break;
  3821. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3822. if (print) {
  3823. _print_next_block((*par_num)++, "XCM");
  3824. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3825. }
  3826. break;
  3827. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3828. if (print) {
  3829. _print_next_block((*par_num)++,
  3830. "XSEMI");
  3831. _print_parity(bp,
  3832. XSEM_REG_XSEM_PRTY_STS_0);
  3833. _print_parity(bp,
  3834. XSEM_REG_XSEM_PRTY_STS_1);
  3835. }
  3836. break;
  3837. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3838. if (print) {
  3839. _print_next_block((*par_num)++,
  3840. "DOORBELLQ");
  3841. _print_parity(bp,
  3842. DORQ_REG_DORQ_PRTY_STS);
  3843. }
  3844. break;
  3845. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3846. if (print) {
  3847. _print_next_block((*par_num)++, "NIG");
  3848. if (CHIP_IS_E1x(bp)) {
  3849. _print_parity(bp,
  3850. NIG_REG_NIG_PRTY_STS);
  3851. } else {
  3852. _print_parity(bp,
  3853. NIG_REG_NIG_PRTY_STS_0);
  3854. _print_parity(bp,
  3855. NIG_REG_NIG_PRTY_STS_1);
  3856. }
  3857. }
  3858. break;
  3859. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3860. if (print)
  3861. _print_next_block((*par_num)++,
  3862. "VAUX PCI CORE");
  3863. *global = true;
  3864. break;
  3865. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3866. if (print) {
  3867. _print_next_block((*par_num)++,
  3868. "DEBUG");
  3869. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3870. }
  3871. break;
  3872. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3873. if (print) {
  3874. _print_next_block((*par_num)++, "USDM");
  3875. _print_parity(bp,
  3876. USDM_REG_USDM_PRTY_STS);
  3877. }
  3878. break;
  3879. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3880. if (print) {
  3881. _print_next_block((*par_num)++, "UCM");
  3882. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3883. }
  3884. break;
  3885. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3886. if (print) {
  3887. _print_next_block((*par_num)++,
  3888. "USEMI");
  3889. _print_parity(bp,
  3890. USEM_REG_USEM_PRTY_STS_0);
  3891. _print_parity(bp,
  3892. USEM_REG_USEM_PRTY_STS_1);
  3893. }
  3894. break;
  3895. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3896. if (print) {
  3897. _print_next_block((*par_num)++, "UPB");
  3898. _print_parity(bp, GRCBASE_UPB +
  3899. PB_REG_PB_PRTY_STS);
  3900. }
  3901. break;
  3902. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3903. if (print) {
  3904. _print_next_block((*par_num)++, "CSDM");
  3905. _print_parity(bp,
  3906. CSDM_REG_CSDM_PRTY_STS);
  3907. }
  3908. break;
  3909. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3910. if (print) {
  3911. _print_next_block((*par_num)++, "CCM");
  3912. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3913. }
  3914. break;
  3915. }
  3916. /* Clear the bit */
  3917. sig &= ~cur_bit;
  3918. }
  3919. }
  3920. return res;
  3921. }
  3922. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3923. int *par_num, bool print)
  3924. {
  3925. u32 cur_bit;
  3926. bool res;
  3927. int i;
  3928. res = false;
  3929. for (i = 0; sig; i++) {
  3930. cur_bit = (0x1UL << i);
  3931. if (sig & cur_bit) {
  3932. res |= true; /* Each bit is real error! */
  3933. if (print) {
  3934. switch (cur_bit) {
  3935. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3936. _print_next_block((*par_num)++,
  3937. "CSEMI");
  3938. _print_parity(bp,
  3939. CSEM_REG_CSEM_PRTY_STS_0);
  3940. _print_parity(bp,
  3941. CSEM_REG_CSEM_PRTY_STS_1);
  3942. break;
  3943. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3944. _print_next_block((*par_num)++, "PXP");
  3945. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3946. _print_parity(bp,
  3947. PXP2_REG_PXP2_PRTY_STS_0);
  3948. _print_parity(bp,
  3949. PXP2_REG_PXP2_PRTY_STS_1);
  3950. break;
  3951. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3952. _print_next_block((*par_num)++,
  3953. "PXPPCICLOCKCLIENT");
  3954. break;
  3955. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3956. _print_next_block((*par_num)++, "CFC");
  3957. _print_parity(bp,
  3958. CFC_REG_CFC_PRTY_STS);
  3959. break;
  3960. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3961. _print_next_block((*par_num)++, "CDU");
  3962. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3963. break;
  3964. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3965. _print_next_block((*par_num)++, "DMAE");
  3966. _print_parity(bp,
  3967. DMAE_REG_DMAE_PRTY_STS);
  3968. break;
  3969. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3970. _print_next_block((*par_num)++, "IGU");
  3971. if (CHIP_IS_E1x(bp))
  3972. _print_parity(bp,
  3973. HC_REG_HC_PRTY_STS);
  3974. else
  3975. _print_parity(bp,
  3976. IGU_REG_IGU_PRTY_STS);
  3977. break;
  3978. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3979. _print_next_block((*par_num)++, "MISC");
  3980. _print_parity(bp,
  3981. MISC_REG_MISC_PRTY_STS);
  3982. break;
  3983. }
  3984. }
  3985. /* Clear the bit */
  3986. sig &= ~cur_bit;
  3987. }
  3988. }
  3989. return res;
  3990. }
  3991. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  3992. int *par_num, bool *global,
  3993. bool print)
  3994. {
  3995. bool res = false;
  3996. u32 cur_bit;
  3997. int i;
  3998. for (i = 0; sig; i++) {
  3999. cur_bit = (0x1UL << i);
  4000. if (sig & cur_bit) {
  4001. switch (cur_bit) {
  4002. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4003. if (print)
  4004. _print_next_block((*par_num)++,
  4005. "MCP ROM");
  4006. *global = true;
  4007. res |= true;
  4008. break;
  4009. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4010. if (print)
  4011. _print_next_block((*par_num)++,
  4012. "MCP UMP RX");
  4013. *global = true;
  4014. res |= true;
  4015. break;
  4016. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4017. if (print)
  4018. _print_next_block((*par_num)++,
  4019. "MCP UMP TX");
  4020. *global = true;
  4021. res |= true;
  4022. break;
  4023. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4024. if (print)
  4025. _print_next_block((*par_num)++,
  4026. "MCP SCPAD");
  4027. /* clear latched SCPAD PATIRY from MCP */
  4028. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4029. 1UL << 10);
  4030. break;
  4031. }
  4032. /* Clear the bit */
  4033. sig &= ~cur_bit;
  4034. }
  4035. }
  4036. return res;
  4037. }
  4038. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4039. int *par_num, bool print)
  4040. {
  4041. u32 cur_bit;
  4042. bool res;
  4043. int i;
  4044. res = false;
  4045. for (i = 0; sig; i++) {
  4046. cur_bit = (0x1UL << i);
  4047. if (sig & cur_bit) {
  4048. res |= true; /* Each bit is real error! */
  4049. if (print) {
  4050. switch (cur_bit) {
  4051. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4052. _print_next_block((*par_num)++,
  4053. "PGLUE_B");
  4054. _print_parity(bp,
  4055. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4056. break;
  4057. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4058. _print_next_block((*par_num)++, "ATC");
  4059. _print_parity(bp,
  4060. ATC_REG_ATC_PRTY_STS);
  4061. break;
  4062. }
  4063. }
  4064. /* Clear the bit */
  4065. sig &= ~cur_bit;
  4066. }
  4067. }
  4068. return res;
  4069. }
  4070. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4071. u32 *sig)
  4072. {
  4073. bool res = false;
  4074. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4075. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4076. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4077. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4078. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4079. int par_num = 0;
  4080. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4081. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4082. sig[0] & HW_PRTY_ASSERT_SET_0,
  4083. sig[1] & HW_PRTY_ASSERT_SET_1,
  4084. sig[2] & HW_PRTY_ASSERT_SET_2,
  4085. sig[3] & HW_PRTY_ASSERT_SET_3,
  4086. sig[4] & HW_PRTY_ASSERT_SET_4);
  4087. if (print)
  4088. netdev_err(bp->dev,
  4089. "Parity errors detected in blocks: ");
  4090. res |= bnx2x_check_blocks_with_parity0(bp,
  4091. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4092. res |= bnx2x_check_blocks_with_parity1(bp,
  4093. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4094. res |= bnx2x_check_blocks_with_parity2(bp,
  4095. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4096. res |= bnx2x_check_blocks_with_parity3(bp,
  4097. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4098. res |= bnx2x_check_blocks_with_parity4(bp,
  4099. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4100. if (print)
  4101. pr_cont("\n");
  4102. }
  4103. return res;
  4104. }
  4105. /**
  4106. * bnx2x_chk_parity_attn - checks for parity attentions.
  4107. *
  4108. * @bp: driver handle
  4109. * @global: true if there was a global attention
  4110. * @print: show parity attention in syslog
  4111. */
  4112. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4113. {
  4114. struct attn_route attn = { {0} };
  4115. int port = BP_PORT(bp);
  4116. attn.sig[0] = REG_RD(bp,
  4117. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4118. port*4);
  4119. attn.sig[1] = REG_RD(bp,
  4120. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4121. port*4);
  4122. attn.sig[2] = REG_RD(bp,
  4123. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4124. port*4);
  4125. attn.sig[3] = REG_RD(bp,
  4126. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4127. port*4);
  4128. /* Since MCP attentions can't be disabled inside the block, we need to
  4129. * read AEU registers to see whether they're currently disabled
  4130. */
  4131. attn.sig[3] &= ((REG_RD(bp,
  4132. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4133. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4134. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4135. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4136. if (!CHIP_IS_E1x(bp))
  4137. attn.sig[4] = REG_RD(bp,
  4138. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4139. port*4);
  4140. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4141. }
  4142. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4143. {
  4144. u32 val;
  4145. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4146. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4147. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4148. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4149. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4150. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4151. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4152. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4153. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4154. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4155. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4156. if (val &
  4157. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4158. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4159. if (val &
  4160. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4161. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4162. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4163. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4164. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4165. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4166. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4167. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4168. }
  4169. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4170. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4171. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4172. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4173. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4174. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4175. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4176. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4177. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4178. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4179. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4180. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4181. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4182. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4183. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4184. }
  4185. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4186. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4187. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4188. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4189. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4190. }
  4191. }
  4192. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4193. {
  4194. struct attn_route attn, *group_mask;
  4195. int port = BP_PORT(bp);
  4196. int index;
  4197. u32 reg_addr;
  4198. u32 val;
  4199. u32 aeu_mask;
  4200. bool global = false;
  4201. /* need to take HW lock because MCP or other port might also
  4202. try to handle this event */
  4203. bnx2x_acquire_alr(bp);
  4204. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4205. #ifndef BNX2X_STOP_ON_ERROR
  4206. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4207. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4208. /* Disable HW interrupts */
  4209. bnx2x_int_disable(bp);
  4210. /* In case of parity errors don't handle attentions so that
  4211. * other function would "see" parity errors.
  4212. */
  4213. #else
  4214. bnx2x_panic();
  4215. #endif
  4216. bnx2x_release_alr(bp);
  4217. return;
  4218. }
  4219. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4220. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4221. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4222. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4223. if (!CHIP_IS_E1x(bp))
  4224. attn.sig[4] =
  4225. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4226. else
  4227. attn.sig[4] = 0;
  4228. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4229. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4230. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4231. if (deasserted & (1 << index)) {
  4232. group_mask = &bp->attn_group[index];
  4233. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4234. index,
  4235. group_mask->sig[0], group_mask->sig[1],
  4236. group_mask->sig[2], group_mask->sig[3],
  4237. group_mask->sig[4]);
  4238. bnx2x_attn_int_deasserted4(bp,
  4239. attn.sig[4] & group_mask->sig[4]);
  4240. bnx2x_attn_int_deasserted3(bp,
  4241. attn.sig[3] & group_mask->sig[3]);
  4242. bnx2x_attn_int_deasserted1(bp,
  4243. attn.sig[1] & group_mask->sig[1]);
  4244. bnx2x_attn_int_deasserted2(bp,
  4245. attn.sig[2] & group_mask->sig[2]);
  4246. bnx2x_attn_int_deasserted0(bp,
  4247. attn.sig[0] & group_mask->sig[0]);
  4248. }
  4249. }
  4250. bnx2x_release_alr(bp);
  4251. if (bp->common.int_block == INT_BLOCK_HC)
  4252. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4253. COMMAND_REG_ATTN_BITS_CLR);
  4254. else
  4255. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4256. val = ~deasserted;
  4257. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4258. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4259. REG_WR(bp, reg_addr, val);
  4260. if (~bp->attn_state & deasserted)
  4261. BNX2X_ERR("IGU ERROR\n");
  4262. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4263. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4264. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4265. aeu_mask = REG_RD(bp, reg_addr);
  4266. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4267. aeu_mask, deasserted);
  4268. aeu_mask |= (deasserted & 0x3ff);
  4269. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4270. REG_WR(bp, reg_addr, aeu_mask);
  4271. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4272. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4273. bp->attn_state &= ~deasserted;
  4274. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4275. }
  4276. static void bnx2x_attn_int(struct bnx2x *bp)
  4277. {
  4278. /* read local copy of bits */
  4279. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4280. attn_bits);
  4281. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4282. attn_bits_ack);
  4283. u32 attn_state = bp->attn_state;
  4284. /* look for changed bits */
  4285. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4286. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4287. DP(NETIF_MSG_HW,
  4288. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4289. attn_bits, attn_ack, asserted, deasserted);
  4290. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4291. BNX2X_ERR("BAD attention state\n");
  4292. /* handle bits that were raised */
  4293. if (asserted)
  4294. bnx2x_attn_int_asserted(bp, asserted);
  4295. if (deasserted)
  4296. bnx2x_attn_int_deasserted(bp, deasserted);
  4297. }
  4298. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4299. u16 index, u8 op, u8 update)
  4300. {
  4301. u32 igu_addr = bp->igu_base_addr;
  4302. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4303. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4304. igu_addr);
  4305. }
  4306. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4307. {
  4308. /* No memory barriers */
  4309. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4310. mmiowb(); /* keep prod updates ordered */
  4311. }
  4312. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4313. union event_ring_elem *elem)
  4314. {
  4315. u8 err = elem->message.error;
  4316. if (!bp->cnic_eth_dev.starting_cid ||
  4317. (cid < bp->cnic_eth_dev.starting_cid &&
  4318. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4319. return 1;
  4320. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4321. if (unlikely(err)) {
  4322. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4323. cid);
  4324. bnx2x_panic_dump(bp, false);
  4325. }
  4326. bnx2x_cnic_cfc_comp(bp, cid, err);
  4327. return 0;
  4328. }
  4329. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4330. {
  4331. struct bnx2x_mcast_ramrod_params rparam;
  4332. int rc;
  4333. memset(&rparam, 0, sizeof(rparam));
  4334. rparam.mcast_obj = &bp->mcast_obj;
  4335. netif_addr_lock_bh(bp->dev);
  4336. /* Clear pending state for the last command */
  4337. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4338. /* If there are pending mcast commands - send them */
  4339. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4340. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4341. if (rc < 0)
  4342. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4343. rc);
  4344. }
  4345. netif_addr_unlock_bh(bp->dev);
  4346. }
  4347. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4348. union event_ring_elem *elem)
  4349. {
  4350. unsigned long ramrod_flags = 0;
  4351. int rc = 0;
  4352. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4353. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4354. /* Always push next commands out, don't wait here */
  4355. __set_bit(RAMROD_CONT, &ramrod_flags);
  4356. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4357. >> BNX2X_SWCID_SHIFT) {
  4358. case BNX2X_FILTER_MAC_PENDING:
  4359. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4360. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4361. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4362. else
  4363. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4364. break;
  4365. case BNX2X_FILTER_MCAST_PENDING:
  4366. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4367. /* This is only relevant for 57710 where multicast MACs are
  4368. * configured as unicast MACs using the same ramrod.
  4369. */
  4370. bnx2x_handle_mcast_eqe(bp);
  4371. return;
  4372. default:
  4373. BNX2X_ERR("Unsupported classification command: %d\n",
  4374. elem->message.data.eth_event.echo);
  4375. return;
  4376. }
  4377. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4378. if (rc < 0)
  4379. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4380. else if (rc > 0)
  4381. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4382. }
  4383. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4384. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4385. {
  4386. netif_addr_lock_bh(bp->dev);
  4387. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4388. /* Send rx_mode command again if was requested */
  4389. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4390. bnx2x_set_storm_rx_mode(bp);
  4391. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4392. &bp->sp_state))
  4393. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4394. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4395. &bp->sp_state))
  4396. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4397. netif_addr_unlock_bh(bp->dev);
  4398. }
  4399. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4400. union event_ring_elem *elem)
  4401. {
  4402. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4403. DP(BNX2X_MSG_SP,
  4404. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4405. elem->message.data.vif_list_event.func_bit_map);
  4406. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4407. elem->message.data.vif_list_event.func_bit_map);
  4408. } else if (elem->message.data.vif_list_event.echo ==
  4409. VIF_LIST_RULE_SET) {
  4410. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4411. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4412. }
  4413. }
  4414. /* called with rtnl_lock */
  4415. static void bnx2x_after_function_update(struct bnx2x *bp)
  4416. {
  4417. int q, rc;
  4418. struct bnx2x_fastpath *fp;
  4419. struct bnx2x_queue_state_params queue_params = {NULL};
  4420. struct bnx2x_queue_update_params *q_update_params =
  4421. &queue_params.params.update;
  4422. /* Send Q update command with afex vlan removal values for all Qs */
  4423. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4424. /* set silent vlan removal values according to vlan mode */
  4425. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4426. &q_update_params->update_flags);
  4427. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4428. &q_update_params->update_flags);
  4429. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4430. /* in access mode mark mask and value are 0 to strip all vlans */
  4431. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4432. q_update_params->silent_removal_value = 0;
  4433. q_update_params->silent_removal_mask = 0;
  4434. } else {
  4435. q_update_params->silent_removal_value =
  4436. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4437. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4438. }
  4439. for_each_eth_queue(bp, q) {
  4440. /* Set the appropriate Queue object */
  4441. fp = &bp->fp[q];
  4442. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4443. /* send the ramrod */
  4444. rc = bnx2x_queue_state_change(bp, &queue_params);
  4445. if (rc < 0)
  4446. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4447. q);
  4448. }
  4449. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4450. fp = &bp->fp[FCOE_IDX(bp)];
  4451. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4452. /* clear pending completion bit */
  4453. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4454. /* mark latest Q bit */
  4455. smp_mb__before_atomic();
  4456. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4457. smp_mb__after_atomic();
  4458. /* send Q update ramrod for FCoE Q */
  4459. rc = bnx2x_queue_state_change(bp, &queue_params);
  4460. if (rc < 0)
  4461. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4462. q);
  4463. } else {
  4464. /* If no FCoE ring - ACK MCP now */
  4465. bnx2x_link_report(bp);
  4466. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4467. }
  4468. }
  4469. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4470. struct bnx2x *bp, u32 cid)
  4471. {
  4472. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4473. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4474. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4475. else
  4476. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4477. }
  4478. static void bnx2x_eq_int(struct bnx2x *bp)
  4479. {
  4480. u16 hw_cons, sw_cons, sw_prod;
  4481. union event_ring_elem *elem;
  4482. u8 echo;
  4483. u32 cid;
  4484. u8 opcode;
  4485. int rc, spqe_cnt = 0;
  4486. struct bnx2x_queue_sp_obj *q_obj;
  4487. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4488. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4489. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4490. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4491. * when we get the next-page we need to adjust so the loop
  4492. * condition below will be met. The next element is the size of a
  4493. * regular element and hence incrementing by 1
  4494. */
  4495. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4496. hw_cons++;
  4497. /* This function may never run in parallel with itself for a
  4498. * specific bp, thus there is no need in "paired" read memory
  4499. * barrier here.
  4500. */
  4501. sw_cons = bp->eq_cons;
  4502. sw_prod = bp->eq_prod;
  4503. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4504. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4505. for (; sw_cons != hw_cons;
  4506. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4507. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4508. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4509. if (!rc) {
  4510. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4511. rc);
  4512. goto next_spqe;
  4513. }
  4514. /* elem CID originates from FW; actually LE */
  4515. cid = SW_CID((__force __le32)
  4516. elem->message.data.cfc_del_event.cid);
  4517. opcode = elem->message.opcode;
  4518. /* handle eq element */
  4519. switch (opcode) {
  4520. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4521. bnx2x_vf_mbx_schedule(bp,
  4522. &elem->message.data.vf_pf_event);
  4523. continue;
  4524. case EVENT_RING_OPCODE_STAT_QUERY:
  4525. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4526. "got statistics comp event %d\n",
  4527. bp->stats_comp++);
  4528. /* nothing to do with stats comp */
  4529. goto next_spqe;
  4530. case EVENT_RING_OPCODE_CFC_DEL:
  4531. /* handle according to cid range */
  4532. /*
  4533. * we may want to verify here that the bp state is
  4534. * HALTING
  4535. */
  4536. DP(BNX2X_MSG_SP,
  4537. "got delete ramrod for MULTI[%d]\n", cid);
  4538. if (CNIC_LOADED(bp) &&
  4539. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4540. goto next_spqe;
  4541. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4542. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4543. break;
  4544. goto next_spqe;
  4545. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4546. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4547. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4548. if (f_obj->complete_cmd(bp, f_obj,
  4549. BNX2X_F_CMD_TX_STOP))
  4550. break;
  4551. goto next_spqe;
  4552. case EVENT_RING_OPCODE_START_TRAFFIC:
  4553. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4554. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4555. if (f_obj->complete_cmd(bp, f_obj,
  4556. BNX2X_F_CMD_TX_START))
  4557. break;
  4558. goto next_spqe;
  4559. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4560. echo = elem->message.data.function_update_event.echo;
  4561. if (echo == SWITCH_UPDATE) {
  4562. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4563. "got FUNC_SWITCH_UPDATE ramrod\n");
  4564. if (f_obj->complete_cmd(
  4565. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4566. break;
  4567. } else {
  4568. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4569. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4570. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4571. f_obj->complete_cmd(bp, f_obj,
  4572. BNX2X_F_CMD_AFEX_UPDATE);
  4573. /* We will perform the Queues update from
  4574. * sp_rtnl task as all Queue SP operations
  4575. * should run under rtnl_lock.
  4576. */
  4577. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4578. }
  4579. goto next_spqe;
  4580. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4581. f_obj->complete_cmd(bp, f_obj,
  4582. BNX2X_F_CMD_AFEX_VIFLISTS);
  4583. bnx2x_after_afex_vif_lists(bp, elem);
  4584. goto next_spqe;
  4585. case EVENT_RING_OPCODE_FUNCTION_START:
  4586. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4587. "got FUNC_START ramrod\n");
  4588. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4589. break;
  4590. goto next_spqe;
  4591. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4592. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4593. "got FUNC_STOP ramrod\n");
  4594. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4595. break;
  4596. goto next_spqe;
  4597. }
  4598. switch (opcode | bp->state) {
  4599. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4600. BNX2X_STATE_OPEN):
  4601. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4602. BNX2X_STATE_OPENING_WAIT4_PORT):
  4603. cid = elem->message.data.eth_event.echo &
  4604. BNX2X_SWCID_MASK;
  4605. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4606. cid);
  4607. rss_raw->clear_pending(rss_raw);
  4608. break;
  4609. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4610. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4611. case (EVENT_RING_OPCODE_SET_MAC |
  4612. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4613. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4614. BNX2X_STATE_OPEN):
  4615. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4616. BNX2X_STATE_DIAG):
  4617. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4618. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4619. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4620. bnx2x_handle_classification_eqe(bp, elem);
  4621. break;
  4622. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4623. BNX2X_STATE_OPEN):
  4624. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4625. BNX2X_STATE_DIAG):
  4626. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4627. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4628. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4629. bnx2x_handle_mcast_eqe(bp);
  4630. break;
  4631. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4632. BNX2X_STATE_OPEN):
  4633. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4634. BNX2X_STATE_DIAG):
  4635. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4636. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4637. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4638. bnx2x_handle_rx_mode_eqe(bp);
  4639. break;
  4640. default:
  4641. /* unknown event log error and continue */
  4642. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4643. elem->message.opcode, bp->state);
  4644. }
  4645. next_spqe:
  4646. spqe_cnt++;
  4647. } /* for */
  4648. smp_mb__before_atomic();
  4649. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4650. bp->eq_cons = sw_cons;
  4651. bp->eq_prod = sw_prod;
  4652. /* Make sure that above mem writes were issued towards the memory */
  4653. smp_wmb();
  4654. /* update producer */
  4655. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4656. }
  4657. static void bnx2x_sp_task(struct work_struct *work)
  4658. {
  4659. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4660. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4661. /* make sure the atomic interrupt_occurred has been written */
  4662. smp_rmb();
  4663. if (atomic_read(&bp->interrupt_occurred)) {
  4664. /* what work needs to be performed? */
  4665. u16 status = bnx2x_update_dsb_idx(bp);
  4666. DP(BNX2X_MSG_SP, "status %x\n", status);
  4667. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4668. atomic_set(&bp->interrupt_occurred, 0);
  4669. /* HW attentions */
  4670. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4671. bnx2x_attn_int(bp);
  4672. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4673. }
  4674. /* SP events: STAT_QUERY and others */
  4675. if (status & BNX2X_DEF_SB_IDX) {
  4676. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4677. if (FCOE_INIT(bp) &&
  4678. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4679. /* Prevent local bottom-halves from running as
  4680. * we are going to change the local NAPI list.
  4681. */
  4682. local_bh_disable();
  4683. napi_schedule(&bnx2x_fcoe(bp, napi));
  4684. local_bh_enable();
  4685. }
  4686. /* Handle EQ completions */
  4687. bnx2x_eq_int(bp);
  4688. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4689. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4690. status &= ~BNX2X_DEF_SB_IDX;
  4691. }
  4692. /* if status is non zero then perhaps something went wrong */
  4693. if (unlikely(status))
  4694. DP(BNX2X_MSG_SP,
  4695. "got an unknown interrupt! (status 0x%x)\n", status);
  4696. /* ack status block only if something was actually handled */
  4697. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4698. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4699. }
  4700. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4701. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4702. &bp->sp_state)) {
  4703. bnx2x_link_report(bp);
  4704. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4705. }
  4706. }
  4707. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4708. {
  4709. struct net_device *dev = dev_instance;
  4710. struct bnx2x *bp = netdev_priv(dev);
  4711. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4712. IGU_INT_DISABLE, 0);
  4713. #ifdef BNX2X_STOP_ON_ERROR
  4714. if (unlikely(bp->panic))
  4715. return IRQ_HANDLED;
  4716. #endif
  4717. if (CNIC_LOADED(bp)) {
  4718. struct cnic_ops *c_ops;
  4719. rcu_read_lock();
  4720. c_ops = rcu_dereference(bp->cnic_ops);
  4721. if (c_ops)
  4722. c_ops->cnic_handler(bp->cnic_data, NULL);
  4723. rcu_read_unlock();
  4724. }
  4725. /* schedule sp task to perform default status block work, ack
  4726. * attentions and enable interrupts.
  4727. */
  4728. bnx2x_schedule_sp_task(bp);
  4729. return IRQ_HANDLED;
  4730. }
  4731. /* end of slow path */
  4732. void bnx2x_drv_pulse(struct bnx2x *bp)
  4733. {
  4734. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4735. bp->fw_drv_pulse_wr_seq);
  4736. }
  4737. static void bnx2x_timer(unsigned long data)
  4738. {
  4739. struct bnx2x *bp = (struct bnx2x *) data;
  4740. if (!netif_running(bp->dev))
  4741. return;
  4742. if (IS_PF(bp) &&
  4743. !BP_NOMCP(bp)) {
  4744. int mb_idx = BP_FW_MB_IDX(bp);
  4745. u16 drv_pulse;
  4746. u16 mcp_pulse;
  4747. ++bp->fw_drv_pulse_wr_seq;
  4748. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4749. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4750. bnx2x_drv_pulse(bp);
  4751. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4752. MCP_PULSE_SEQ_MASK);
  4753. /* The delta between driver pulse and mcp response
  4754. * should not get too big. If the MFW is more than 5 pulses
  4755. * behind, we should worry about it enough to generate an error
  4756. * log.
  4757. */
  4758. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4759. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4760. drv_pulse, mcp_pulse);
  4761. }
  4762. if (bp->state == BNX2X_STATE_OPEN)
  4763. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4764. /* sample pf vf bulletin board for new posts from pf */
  4765. if (IS_VF(bp))
  4766. bnx2x_timer_sriov(bp);
  4767. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4768. }
  4769. /* end of Statistics */
  4770. /* nic init */
  4771. /*
  4772. * nic init service functions
  4773. */
  4774. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4775. {
  4776. u32 i;
  4777. if (!(len%4) && !(addr%4))
  4778. for (i = 0; i < len; i += 4)
  4779. REG_WR(bp, addr + i, fill);
  4780. else
  4781. for (i = 0; i < len; i++)
  4782. REG_WR8(bp, addr + i, fill);
  4783. }
  4784. /* helper: writes FP SP data to FW - data_size in dwords */
  4785. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4786. int fw_sb_id,
  4787. u32 *sb_data_p,
  4788. u32 data_size)
  4789. {
  4790. int index;
  4791. for (index = 0; index < data_size; index++)
  4792. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4793. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4794. sizeof(u32)*index,
  4795. *(sb_data_p + index));
  4796. }
  4797. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4798. {
  4799. u32 *sb_data_p;
  4800. u32 data_size = 0;
  4801. struct hc_status_block_data_e2 sb_data_e2;
  4802. struct hc_status_block_data_e1x sb_data_e1x;
  4803. /* disable the function first */
  4804. if (!CHIP_IS_E1x(bp)) {
  4805. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4806. sb_data_e2.common.state = SB_DISABLED;
  4807. sb_data_e2.common.p_func.vf_valid = false;
  4808. sb_data_p = (u32 *)&sb_data_e2;
  4809. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4810. } else {
  4811. memset(&sb_data_e1x, 0,
  4812. sizeof(struct hc_status_block_data_e1x));
  4813. sb_data_e1x.common.state = SB_DISABLED;
  4814. sb_data_e1x.common.p_func.vf_valid = false;
  4815. sb_data_p = (u32 *)&sb_data_e1x;
  4816. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4817. }
  4818. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4819. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4820. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4821. CSTORM_STATUS_BLOCK_SIZE);
  4822. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4823. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4824. CSTORM_SYNC_BLOCK_SIZE);
  4825. }
  4826. /* helper: writes SP SB data to FW */
  4827. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4828. struct hc_sp_status_block_data *sp_sb_data)
  4829. {
  4830. int func = BP_FUNC(bp);
  4831. int i;
  4832. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4833. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4834. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4835. i*sizeof(u32),
  4836. *((u32 *)sp_sb_data + i));
  4837. }
  4838. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4839. {
  4840. int func = BP_FUNC(bp);
  4841. struct hc_sp_status_block_data sp_sb_data;
  4842. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4843. sp_sb_data.state = SB_DISABLED;
  4844. sp_sb_data.p_func.vf_valid = false;
  4845. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4846. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4847. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4848. CSTORM_SP_STATUS_BLOCK_SIZE);
  4849. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4850. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4851. CSTORM_SP_SYNC_BLOCK_SIZE);
  4852. }
  4853. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4854. int igu_sb_id, int igu_seg_id)
  4855. {
  4856. hc_sm->igu_sb_id = igu_sb_id;
  4857. hc_sm->igu_seg_id = igu_seg_id;
  4858. hc_sm->timer_value = 0xFF;
  4859. hc_sm->time_to_expire = 0xFFFFFFFF;
  4860. }
  4861. /* allocates state machine ids. */
  4862. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4863. {
  4864. /* zero out state machine indices */
  4865. /* rx indices */
  4866. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4867. /* tx indices */
  4868. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4869. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4870. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4871. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4872. /* map indices */
  4873. /* rx indices */
  4874. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4875. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4876. /* tx indices */
  4877. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4878. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4879. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4880. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4881. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4882. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4883. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4884. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4885. }
  4886. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4887. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4888. {
  4889. int igu_seg_id;
  4890. struct hc_status_block_data_e2 sb_data_e2;
  4891. struct hc_status_block_data_e1x sb_data_e1x;
  4892. struct hc_status_block_sm *hc_sm_p;
  4893. int data_size;
  4894. u32 *sb_data_p;
  4895. if (CHIP_INT_MODE_IS_BC(bp))
  4896. igu_seg_id = HC_SEG_ACCESS_NORM;
  4897. else
  4898. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4899. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4900. if (!CHIP_IS_E1x(bp)) {
  4901. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4902. sb_data_e2.common.state = SB_ENABLED;
  4903. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4904. sb_data_e2.common.p_func.vf_id = vfid;
  4905. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4906. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4907. sb_data_e2.common.same_igu_sb_1b = true;
  4908. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4909. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4910. hc_sm_p = sb_data_e2.common.state_machine;
  4911. sb_data_p = (u32 *)&sb_data_e2;
  4912. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4913. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4914. } else {
  4915. memset(&sb_data_e1x, 0,
  4916. sizeof(struct hc_status_block_data_e1x));
  4917. sb_data_e1x.common.state = SB_ENABLED;
  4918. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4919. sb_data_e1x.common.p_func.vf_id = 0xff;
  4920. sb_data_e1x.common.p_func.vf_valid = false;
  4921. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4922. sb_data_e1x.common.same_igu_sb_1b = true;
  4923. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4924. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4925. hc_sm_p = sb_data_e1x.common.state_machine;
  4926. sb_data_p = (u32 *)&sb_data_e1x;
  4927. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4928. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4929. }
  4930. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4931. igu_sb_id, igu_seg_id);
  4932. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4933. igu_sb_id, igu_seg_id);
  4934. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4935. /* write indices to HW - PCI guarantees endianity of regpairs */
  4936. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4937. }
  4938. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4939. u16 tx_usec, u16 rx_usec)
  4940. {
  4941. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4942. false, rx_usec);
  4943. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4944. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4945. tx_usec);
  4946. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4947. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4948. tx_usec);
  4949. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4950. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4951. tx_usec);
  4952. }
  4953. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4954. {
  4955. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4956. dma_addr_t mapping = bp->def_status_blk_mapping;
  4957. int igu_sp_sb_index;
  4958. int igu_seg_id;
  4959. int port = BP_PORT(bp);
  4960. int func = BP_FUNC(bp);
  4961. int reg_offset, reg_offset_en5;
  4962. u64 section;
  4963. int index;
  4964. struct hc_sp_status_block_data sp_sb_data;
  4965. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4966. if (CHIP_INT_MODE_IS_BC(bp)) {
  4967. igu_sp_sb_index = DEF_SB_IGU_ID;
  4968. igu_seg_id = HC_SEG_ACCESS_DEF;
  4969. } else {
  4970. igu_sp_sb_index = bp->igu_dsb_id;
  4971. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4972. }
  4973. /* ATTN */
  4974. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4975. atten_status_block);
  4976. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4977. bp->attn_state = 0;
  4978. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4979. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4980. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4981. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4982. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4983. int sindex;
  4984. /* take care of sig[0]..sig[4] */
  4985. for (sindex = 0; sindex < 4; sindex++)
  4986. bp->attn_group[index].sig[sindex] =
  4987. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4988. if (!CHIP_IS_E1x(bp))
  4989. /*
  4990. * enable5 is separate from the rest of the registers,
  4991. * and therefore the address skip is 4
  4992. * and not 16 between the different groups
  4993. */
  4994. bp->attn_group[index].sig[4] = REG_RD(bp,
  4995. reg_offset_en5 + 0x4*index);
  4996. else
  4997. bp->attn_group[index].sig[4] = 0;
  4998. }
  4999. if (bp->common.int_block == INT_BLOCK_HC) {
  5000. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5001. HC_REG_ATTN_MSG0_ADDR_L);
  5002. REG_WR(bp, reg_offset, U64_LO(section));
  5003. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5004. } else if (!CHIP_IS_E1x(bp)) {
  5005. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5006. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5007. }
  5008. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5009. sp_sb);
  5010. bnx2x_zero_sp_sb(bp);
  5011. /* PCI guarantees endianity of regpairs */
  5012. sp_sb_data.state = SB_ENABLED;
  5013. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5014. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5015. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5016. sp_sb_data.igu_seg_id = igu_seg_id;
  5017. sp_sb_data.p_func.pf_id = func;
  5018. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5019. sp_sb_data.p_func.vf_id = 0xff;
  5020. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5021. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5022. }
  5023. void bnx2x_update_coalesce(struct bnx2x *bp)
  5024. {
  5025. int i;
  5026. for_each_eth_queue(bp, i)
  5027. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5028. bp->tx_ticks, bp->rx_ticks);
  5029. }
  5030. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5031. {
  5032. spin_lock_init(&bp->spq_lock);
  5033. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5034. bp->spq_prod_idx = 0;
  5035. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5036. bp->spq_prod_bd = bp->spq;
  5037. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5038. }
  5039. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5040. {
  5041. int i;
  5042. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5043. union event_ring_elem *elem =
  5044. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5045. elem->next_page.addr.hi =
  5046. cpu_to_le32(U64_HI(bp->eq_mapping +
  5047. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5048. elem->next_page.addr.lo =
  5049. cpu_to_le32(U64_LO(bp->eq_mapping +
  5050. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5051. }
  5052. bp->eq_cons = 0;
  5053. bp->eq_prod = NUM_EQ_DESC;
  5054. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5055. /* we want a warning message before it gets wrought... */
  5056. atomic_set(&bp->eq_spq_left,
  5057. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5058. }
  5059. /* called with netif_addr_lock_bh() */
  5060. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5061. unsigned long rx_mode_flags,
  5062. unsigned long rx_accept_flags,
  5063. unsigned long tx_accept_flags,
  5064. unsigned long ramrod_flags)
  5065. {
  5066. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5067. int rc;
  5068. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5069. /* Prepare ramrod parameters */
  5070. ramrod_param.cid = 0;
  5071. ramrod_param.cl_id = cl_id;
  5072. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5073. ramrod_param.func_id = BP_FUNC(bp);
  5074. ramrod_param.pstate = &bp->sp_state;
  5075. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5076. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5077. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5078. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5079. ramrod_param.ramrod_flags = ramrod_flags;
  5080. ramrod_param.rx_mode_flags = rx_mode_flags;
  5081. ramrod_param.rx_accept_flags = rx_accept_flags;
  5082. ramrod_param.tx_accept_flags = tx_accept_flags;
  5083. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5084. if (rc < 0) {
  5085. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5086. return rc;
  5087. }
  5088. return 0;
  5089. }
  5090. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5091. unsigned long *rx_accept_flags,
  5092. unsigned long *tx_accept_flags)
  5093. {
  5094. /* Clear the flags first */
  5095. *rx_accept_flags = 0;
  5096. *tx_accept_flags = 0;
  5097. switch (rx_mode) {
  5098. case BNX2X_RX_MODE_NONE:
  5099. /*
  5100. * 'drop all' supersedes any accept flags that may have been
  5101. * passed to the function.
  5102. */
  5103. break;
  5104. case BNX2X_RX_MODE_NORMAL:
  5105. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5106. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5107. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5108. /* internal switching mode */
  5109. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5110. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5111. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5112. break;
  5113. case BNX2X_RX_MODE_ALLMULTI:
  5114. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5115. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5116. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5117. /* internal switching mode */
  5118. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5119. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5120. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5121. break;
  5122. case BNX2X_RX_MODE_PROMISC:
  5123. /* According to definition of SI mode, iface in promisc mode
  5124. * should receive matched and unmatched (in resolution of port)
  5125. * unicast packets.
  5126. */
  5127. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5128. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5129. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5130. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5131. /* internal switching mode */
  5132. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5133. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5134. if (IS_MF_SI(bp))
  5135. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5136. else
  5137. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5138. break;
  5139. default:
  5140. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5141. return -EINVAL;
  5142. }
  5143. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5144. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5145. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5146. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5147. }
  5148. return 0;
  5149. }
  5150. /* called with netif_addr_lock_bh() */
  5151. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5152. {
  5153. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5154. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5155. int rc;
  5156. if (!NO_FCOE(bp))
  5157. /* Configure rx_mode of FCoE Queue */
  5158. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5159. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5160. &tx_accept_flags);
  5161. if (rc)
  5162. return rc;
  5163. __set_bit(RAMROD_RX, &ramrod_flags);
  5164. __set_bit(RAMROD_TX, &ramrod_flags);
  5165. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5166. rx_accept_flags, tx_accept_flags,
  5167. ramrod_flags);
  5168. }
  5169. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5170. {
  5171. int i;
  5172. /* Zero this manually as its initialization is
  5173. currently missing in the initTool */
  5174. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5175. REG_WR(bp, BAR_USTRORM_INTMEM +
  5176. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5177. if (!CHIP_IS_E1x(bp)) {
  5178. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5179. CHIP_INT_MODE_IS_BC(bp) ?
  5180. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5181. }
  5182. }
  5183. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5184. {
  5185. switch (load_code) {
  5186. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5187. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5188. bnx2x_init_internal_common(bp);
  5189. /* no break */
  5190. case FW_MSG_CODE_DRV_LOAD_PORT:
  5191. /* nothing to do */
  5192. /* no break */
  5193. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5194. /* internal memory per function is
  5195. initialized inside bnx2x_pf_init */
  5196. break;
  5197. default:
  5198. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5199. break;
  5200. }
  5201. }
  5202. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5203. {
  5204. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5205. }
  5206. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5207. {
  5208. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5209. }
  5210. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5211. {
  5212. if (CHIP_IS_E1x(fp->bp))
  5213. return BP_L_ID(fp->bp) + fp->index;
  5214. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5215. return bnx2x_fp_igu_sb_id(fp);
  5216. }
  5217. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5218. {
  5219. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5220. u8 cos;
  5221. unsigned long q_type = 0;
  5222. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5223. fp->rx_queue = fp_idx;
  5224. fp->cid = fp_idx;
  5225. fp->cl_id = bnx2x_fp_cl_id(fp);
  5226. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5227. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5228. /* qZone id equals to FW (per path) client id */
  5229. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5230. /* init shortcut */
  5231. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5232. /* Setup SB indices */
  5233. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5234. /* Configure Queue State object */
  5235. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5236. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5237. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5238. /* init tx data */
  5239. for_each_cos_in_tx_queue(fp, cos) {
  5240. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5241. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5242. FP_COS_TO_TXQ(fp, cos, bp),
  5243. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5244. cids[cos] = fp->txdata_ptr[cos]->cid;
  5245. }
  5246. /* nothing more for vf to do here */
  5247. if (IS_VF(bp))
  5248. return;
  5249. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5250. fp->fw_sb_id, fp->igu_sb_id);
  5251. bnx2x_update_fpsb_idx(fp);
  5252. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5253. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5254. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5255. /**
  5256. * Configure classification DBs: Always enable Tx switching
  5257. */
  5258. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5259. DP(NETIF_MSG_IFUP,
  5260. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5261. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5262. fp->igu_sb_id);
  5263. }
  5264. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5265. {
  5266. int i;
  5267. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5268. struct eth_tx_next_bd *tx_next_bd =
  5269. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5270. tx_next_bd->addr_hi =
  5271. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5272. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5273. tx_next_bd->addr_lo =
  5274. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5275. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5276. }
  5277. *txdata->tx_cons_sb = cpu_to_le16(0);
  5278. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5279. txdata->tx_db.data.zero_fill1 = 0;
  5280. txdata->tx_db.data.prod = 0;
  5281. txdata->tx_pkt_prod = 0;
  5282. txdata->tx_pkt_cons = 0;
  5283. txdata->tx_bd_prod = 0;
  5284. txdata->tx_bd_cons = 0;
  5285. txdata->tx_pkt = 0;
  5286. }
  5287. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5288. {
  5289. int i;
  5290. for_each_tx_queue_cnic(bp, i)
  5291. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5292. }
  5293. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5294. {
  5295. int i;
  5296. u8 cos;
  5297. for_each_eth_queue(bp, i)
  5298. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5299. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5300. }
  5301. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5302. {
  5303. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5304. unsigned long q_type = 0;
  5305. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5306. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5307. BNX2X_FCOE_ETH_CL_ID_IDX);
  5308. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5309. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5310. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5311. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5312. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5313. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5314. fp);
  5315. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5316. /* qZone id equals to FW (per path) client id */
  5317. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5318. /* init shortcut */
  5319. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5320. bnx2x_rx_ustorm_prods_offset(fp);
  5321. /* Configure Queue State object */
  5322. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5323. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5324. /* No multi-CoS for FCoE L2 client */
  5325. BUG_ON(fp->max_cos != 1);
  5326. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5327. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5328. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5329. DP(NETIF_MSG_IFUP,
  5330. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5331. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5332. fp->igu_sb_id);
  5333. }
  5334. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5335. {
  5336. if (!NO_FCOE(bp))
  5337. bnx2x_init_fcoe_fp(bp);
  5338. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5339. BNX2X_VF_ID_INVALID, false,
  5340. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5341. /* ensure status block indices were read */
  5342. rmb();
  5343. bnx2x_init_rx_rings_cnic(bp);
  5344. bnx2x_init_tx_rings_cnic(bp);
  5345. /* flush all */
  5346. mb();
  5347. mmiowb();
  5348. }
  5349. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5350. {
  5351. int i;
  5352. /* Setup NIC internals and enable interrupts */
  5353. for_each_eth_queue(bp, i)
  5354. bnx2x_init_eth_fp(bp, i);
  5355. /* ensure status block indices were read */
  5356. rmb();
  5357. bnx2x_init_rx_rings(bp);
  5358. bnx2x_init_tx_rings(bp);
  5359. if (IS_PF(bp)) {
  5360. /* Initialize MOD_ABS interrupts */
  5361. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5362. bp->common.shmem_base,
  5363. bp->common.shmem2_base, BP_PORT(bp));
  5364. /* initialize the default status block and sp ring */
  5365. bnx2x_init_def_sb(bp);
  5366. bnx2x_update_dsb_idx(bp);
  5367. bnx2x_init_sp_ring(bp);
  5368. } else {
  5369. bnx2x_memset_stats(bp);
  5370. }
  5371. }
  5372. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5373. {
  5374. bnx2x_init_eq_ring(bp);
  5375. bnx2x_init_internal(bp, load_code);
  5376. bnx2x_pf_init(bp);
  5377. bnx2x_stats_init(bp);
  5378. /* flush all before enabling interrupts */
  5379. mb();
  5380. mmiowb();
  5381. bnx2x_int_enable(bp);
  5382. /* Check for SPIO5 */
  5383. bnx2x_attn_int_deasserted0(bp,
  5384. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5385. AEU_INPUTS_ATTN_BITS_SPIO5);
  5386. }
  5387. /* gzip service functions */
  5388. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5389. {
  5390. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5391. &bp->gunzip_mapping, GFP_KERNEL);
  5392. if (bp->gunzip_buf == NULL)
  5393. goto gunzip_nomem1;
  5394. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5395. if (bp->strm == NULL)
  5396. goto gunzip_nomem2;
  5397. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5398. if (bp->strm->workspace == NULL)
  5399. goto gunzip_nomem3;
  5400. return 0;
  5401. gunzip_nomem3:
  5402. kfree(bp->strm);
  5403. bp->strm = NULL;
  5404. gunzip_nomem2:
  5405. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5406. bp->gunzip_mapping);
  5407. bp->gunzip_buf = NULL;
  5408. gunzip_nomem1:
  5409. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5410. return -ENOMEM;
  5411. }
  5412. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5413. {
  5414. if (bp->strm) {
  5415. vfree(bp->strm->workspace);
  5416. kfree(bp->strm);
  5417. bp->strm = NULL;
  5418. }
  5419. if (bp->gunzip_buf) {
  5420. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5421. bp->gunzip_mapping);
  5422. bp->gunzip_buf = NULL;
  5423. }
  5424. }
  5425. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5426. {
  5427. int n, rc;
  5428. /* check gzip header */
  5429. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5430. BNX2X_ERR("Bad gzip header\n");
  5431. return -EINVAL;
  5432. }
  5433. n = 10;
  5434. #define FNAME 0x8
  5435. if (zbuf[3] & FNAME)
  5436. while ((zbuf[n++] != 0) && (n < len));
  5437. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5438. bp->strm->avail_in = len - n;
  5439. bp->strm->next_out = bp->gunzip_buf;
  5440. bp->strm->avail_out = FW_BUF_SIZE;
  5441. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5442. if (rc != Z_OK)
  5443. return rc;
  5444. rc = zlib_inflate(bp->strm, Z_FINISH);
  5445. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5446. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5447. bp->strm->msg);
  5448. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5449. if (bp->gunzip_outlen & 0x3)
  5450. netdev_err(bp->dev,
  5451. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5452. bp->gunzip_outlen);
  5453. bp->gunzip_outlen >>= 2;
  5454. zlib_inflateEnd(bp->strm);
  5455. if (rc == Z_STREAM_END)
  5456. return 0;
  5457. return rc;
  5458. }
  5459. /* nic load/unload */
  5460. /*
  5461. * General service functions
  5462. */
  5463. /* send a NIG loopback debug packet */
  5464. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5465. {
  5466. u32 wb_write[3];
  5467. /* Ethernet source and destination addresses */
  5468. wb_write[0] = 0x55555555;
  5469. wb_write[1] = 0x55555555;
  5470. wb_write[2] = 0x20; /* SOP */
  5471. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5472. /* NON-IP protocol */
  5473. wb_write[0] = 0x09000000;
  5474. wb_write[1] = 0x55555555;
  5475. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5476. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5477. }
  5478. /* some of the internal memories
  5479. * are not directly readable from the driver
  5480. * to test them we send debug packets
  5481. */
  5482. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5483. {
  5484. int factor;
  5485. int count, i;
  5486. u32 val = 0;
  5487. if (CHIP_REV_IS_FPGA(bp))
  5488. factor = 120;
  5489. else if (CHIP_REV_IS_EMUL(bp))
  5490. factor = 200;
  5491. else
  5492. factor = 1;
  5493. /* Disable inputs of parser neighbor blocks */
  5494. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5495. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5496. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5497. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5498. /* Write 0 to parser credits for CFC search request */
  5499. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5500. /* send Ethernet packet */
  5501. bnx2x_lb_pckt(bp);
  5502. /* TODO do i reset NIG statistic? */
  5503. /* Wait until NIG register shows 1 packet of size 0x10 */
  5504. count = 1000 * factor;
  5505. while (count) {
  5506. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5507. val = *bnx2x_sp(bp, wb_data[0]);
  5508. if (val == 0x10)
  5509. break;
  5510. usleep_range(10000, 20000);
  5511. count--;
  5512. }
  5513. if (val != 0x10) {
  5514. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5515. return -1;
  5516. }
  5517. /* Wait until PRS register shows 1 packet */
  5518. count = 1000 * factor;
  5519. while (count) {
  5520. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5521. if (val == 1)
  5522. break;
  5523. usleep_range(10000, 20000);
  5524. count--;
  5525. }
  5526. if (val != 0x1) {
  5527. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5528. return -2;
  5529. }
  5530. /* Reset and init BRB, PRS */
  5531. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5532. msleep(50);
  5533. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5534. msleep(50);
  5535. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5536. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5537. DP(NETIF_MSG_HW, "part2\n");
  5538. /* Disable inputs of parser neighbor blocks */
  5539. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5540. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5541. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5542. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5543. /* Write 0 to parser credits for CFC search request */
  5544. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5545. /* send 10 Ethernet packets */
  5546. for (i = 0; i < 10; i++)
  5547. bnx2x_lb_pckt(bp);
  5548. /* Wait until NIG register shows 10 + 1
  5549. packets of size 11*0x10 = 0xb0 */
  5550. count = 1000 * factor;
  5551. while (count) {
  5552. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5553. val = *bnx2x_sp(bp, wb_data[0]);
  5554. if (val == 0xb0)
  5555. break;
  5556. usleep_range(10000, 20000);
  5557. count--;
  5558. }
  5559. if (val != 0xb0) {
  5560. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5561. return -3;
  5562. }
  5563. /* Wait until PRS register shows 2 packets */
  5564. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5565. if (val != 2)
  5566. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5567. /* Write 1 to parser credits for CFC search request */
  5568. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5569. /* Wait until PRS register shows 3 packets */
  5570. msleep(10 * factor);
  5571. /* Wait until NIG register shows 1 packet of size 0x10 */
  5572. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5573. if (val != 3)
  5574. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5575. /* clear NIG EOP FIFO */
  5576. for (i = 0; i < 11; i++)
  5577. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5578. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5579. if (val != 1) {
  5580. BNX2X_ERR("clear of NIG failed\n");
  5581. return -4;
  5582. }
  5583. /* Reset and init BRB, PRS, NIG */
  5584. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5585. msleep(50);
  5586. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5587. msleep(50);
  5588. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5589. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5590. if (!CNIC_SUPPORT(bp))
  5591. /* set NIC mode */
  5592. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5593. /* Enable inputs of parser neighbor blocks */
  5594. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5595. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5596. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5597. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5598. DP(NETIF_MSG_HW, "done\n");
  5599. return 0; /* OK */
  5600. }
  5601. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5602. {
  5603. u32 val;
  5604. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5605. if (!CHIP_IS_E1x(bp))
  5606. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5607. else
  5608. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5609. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5610. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5611. /*
  5612. * mask read length error interrupts in brb for parser
  5613. * (parsing unit and 'checksum and crc' unit)
  5614. * these errors are legal (PU reads fixed length and CAC can cause
  5615. * read length error on truncated packets)
  5616. */
  5617. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5618. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5619. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5620. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5621. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5622. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5623. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5624. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5625. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5626. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5627. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5628. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5629. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5630. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5631. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5632. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5633. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5634. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5635. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5636. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5637. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5638. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5639. if (!CHIP_IS_E1x(bp))
  5640. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5641. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5642. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5643. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5644. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5645. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5646. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5647. if (!CHIP_IS_E1x(bp))
  5648. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5649. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5650. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5651. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5652. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5653. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5654. }
  5655. static void bnx2x_reset_common(struct bnx2x *bp)
  5656. {
  5657. u32 val = 0x1400;
  5658. /* reset_common */
  5659. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5660. 0xd3ffff7f);
  5661. if (CHIP_IS_E3(bp)) {
  5662. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5663. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5664. }
  5665. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5666. }
  5667. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5668. {
  5669. bp->dmae_ready = 0;
  5670. spin_lock_init(&bp->dmae_lock);
  5671. }
  5672. static void bnx2x_init_pxp(struct bnx2x *bp)
  5673. {
  5674. u16 devctl;
  5675. int r_order, w_order;
  5676. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5677. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5678. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5679. if (bp->mrrs == -1)
  5680. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5681. else {
  5682. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5683. r_order = bp->mrrs;
  5684. }
  5685. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5686. }
  5687. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5688. {
  5689. int is_required;
  5690. u32 val;
  5691. int port;
  5692. if (BP_NOMCP(bp))
  5693. return;
  5694. is_required = 0;
  5695. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5696. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5697. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5698. is_required = 1;
  5699. /*
  5700. * The fan failure mechanism is usually related to the PHY type since
  5701. * the power consumption of the board is affected by the PHY. Currently,
  5702. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5703. */
  5704. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5705. for (port = PORT_0; port < PORT_MAX; port++) {
  5706. is_required |=
  5707. bnx2x_fan_failure_det_req(
  5708. bp,
  5709. bp->common.shmem_base,
  5710. bp->common.shmem2_base,
  5711. port);
  5712. }
  5713. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5714. if (is_required == 0)
  5715. return;
  5716. /* Fan failure is indicated by SPIO 5 */
  5717. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5718. /* set to active low mode */
  5719. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5720. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5721. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5722. /* enable interrupt to signal the IGU */
  5723. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5724. val |= MISC_SPIO_SPIO5;
  5725. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5726. }
  5727. void bnx2x_pf_disable(struct bnx2x *bp)
  5728. {
  5729. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5730. val &= ~IGU_PF_CONF_FUNC_EN;
  5731. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5732. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5733. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5734. }
  5735. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5736. {
  5737. u32 shmem_base[2], shmem2_base[2];
  5738. /* Avoid common init in case MFW supports LFA */
  5739. if (SHMEM2_RD(bp, size) >
  5740. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5741. return;
  5742. shmem_base[0] = bp->common.shmem_base;
  5743. shmem2_base[0] = bp->common.shmem2_base;
  5744. if (!CHIP_IS_E1x(bp)) {
  5745. shmem_base[1] =
  5746. SHMEM2_RD(bp, other_shmem_base_addr);
  5747. shmem2_base[1] =
  5748. SHMEM2_RD(bp, other_shmem2_base_addr);
  5749. }
  5750. bnx2x_acquire_phy_lock(bp);
  5751. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5752. bp->common.chip_id);
  5753. bnx2x_release_phy_lock(bp);
  5754. }
  5755. /**
  5756. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5757. *
  5758. * @bp: driver handle
  5759. */
  5760. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5761. {
  5762. u32 val;
  5763. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5764. /*
  5765. * take the RESET lock to protect undi_unload flow from accessing
  5766. * registers while we're resetting the chip
  5767. */
  5768. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5769. bnx2x_reset_common(bp);
  5770. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5771. val = 0xfffc;
  5772. if (CHIP_IS_E3(bp)) {
  5773. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5774. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5775. }
  5776. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5777. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5778. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5779. if (!CHIP_IS_E1x(bp)) {
  5780. u8 abs_func_id;
  5781. /**
  5782. * 4-port mode or 2-port mode we need to turn of master-enable
  5783. * for everyone, after that, turn it back on for self.
  5784. * so, we disregard multi-function or not, and always disable
  5785. * for all functions on the given path, this means 0,2,4,6 for
  5786. * path 0 and 1,3,5,7 for path 1
  5787. */
  5788. for (abs_func_id = BP_PATH(bp);
  5789. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5790. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5791. REG_WR(bp,
  5792. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5793. 1);
  5794. continue;
  5795. }
  5796. bnx2x_pretend_func(bp, abs_func_id);
  5797. /* clear pf enable */
  5798. bnx2x_pf_disable(bp);
  5799. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5800. }
  5801. }
  5802. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5803. if (CHIP_IS_E1(bp)) {
  5804. /* enable HW interrupt from PXP on USDM overflow
  5805. bit 16 on INT_MASK_0 */
  5806. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5807. }
  5808. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5809. bnx2x_init_pxp(bp);
  5810. #ifdef __BIG_ENDIAN
  5811. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5812. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5813. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5814. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5815. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5816. /* make sure this value is 0 */
  5817. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5818. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5819. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5820. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5821. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5822. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5823. #endif
  5824. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5825. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5826. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5827. /* let the HW do it's magic ... */
  5828. msleep(100);
  5829. /* finish PXP init */
  5830. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5831. if (val != 1) {
  5832. BNX2X_ERR("PXP2 CFG failed\n");
  5833. return -EBUSY;
  5834. }
  5835. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5836. if (val != 1) {
  5837. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5838. return -EBUSY;
  5839. }
  5840. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5841. * have entries with value "0" and valid bit on.
  5842. * This needs to be done by the first PF that is loaded in a path
  5843. * (i.e. common phase)
  5844. */
  5845. if (!CHIP_IS_E1x(bp)) {
  5846. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5847. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5848. * This occurs when a different function (func2,3) is being marked
  5849. * as "scan-off". Real-life scenario for example: if a driver is being
  5850. * load-unloaded while func6,7 are down. This will cause the timer to access
  5851. * the ilt, translate to a logical address and send a request to read/write.
  5852. * Since the ilt for the function that is down is not valid, this will cause
  5853. * a translation error which is unrecoverable.
  5854. * The Workaround is intended to make sure that when this happens nothing fatal
  5855. * will occur. The workaround:
  5856. * 1. First PF driver which loads on a path will:
  5857. * a. After taking the chip out of reset, by using pretend,
  5858. * it will write "0" to the following registers of
  5859. * the other vnics.
  5860. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5861. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5862. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5863. * And for itself it will write '1' to
  5864. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5865. * dmae-operations (writing to pram for example.)
  5866. * note: can be done for only function 6,7 but cleaner this
  5867. * way.
  5868. * b. Write zero+valid to the entire ILT.
  5869. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5870. * VNIC3 (of that port). The range allocated will be the
  5871. * entire ILT. This is needed to prevent ILT range error.
  5872. * 2. Any PF driver load flow:
  5873. * a. ILT update with the physical addresses of the allocated
  5874. * logical pages.
  5875. * b. Wait 20msec. - note that this timeout is needed to make
  5876. * sure there are no requests in one of the PXP internal
  5877. * queues with "old" ILT addresses.
  5878. * c. PF enable in the PGLC.
  5879. * d. Clear the was_error of the PF in the PGLC. (could have
  5880. * occurred while driver was down)
  5881. * e. PF enable in the CFC (WEAK + STRONG)
  5882. * f. Timers scan enable
  5883. * 3. PF driver unload flow:
  5884. * a. Clear the Timers scan_en.
  5885. * b. Polling for scan_on=0 for that PF.
  5886. * c. Clear the PF enable bit in the PXP.
  5887. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5888. * e. Write zero+valid to all ILT entries (The valid bit must
  5889. * stay set)
  5890. * f. If this is VNIC 3 of a port then also init
  5891. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5892. * to the last entry in the ILT.
  5893. *
  5894. * Notes:
  5895. * Currently the PF error in the PGLC is non recoverable.
  5896. * In the future the there will be a recovery routine for this error.
  5897. * Currently attention is masked.
  5898. * Having an MCP lock on the load/unload process does not guarantee that
  5899. * there is no Timer disable during Func6/7 enable. This is because the
  5900. * Timers scan is currently being cleared by the MCP on FLR.
  5901. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5902. * there is error before clearing it. But the flow above is simpler and
  5903. * more general.
  5904. * All ILT entries are written by zero+valid and not just PF6/7
  5905. * ILT entries since in the future the ILT entries allocation for
  5906. * PF-s might be dynamic.
  5907. */
  5908. struct ilt_client_info ilt_cli;
  5909. struct bnx2x_ilt ilt;
  5910. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5911. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5912. /* initialize dummy TM client */
  5913. ilt_cli.start = 0;
  5914. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5915. ilt_cli.client_num = ILT_CLIENT_TM;
  5916. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5917. * Step 2: set the timers first/last ilt entry to point
  5918. * to the entire range to prevent ILT range error for 3rd/4th
  5919. * vnic (this code assumes existence of the vnic)
  5920. *
  5921. * both steps performed by call to bnx2x_ilt_client_init_op()
  5922. * with dummy TM client
  5923. *
  5924. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5925. * and his brother are split registers
  5926. */
  5927. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5928. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5929. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5930. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5931. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5932. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5933. }
  5934. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5935. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5936. if (!CHIP_IS_E1x(bp)) {
  5937. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5938. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5939. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5940. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5941. /* let the HW do it's magic ... */
  5942. do {
  5943. msleep(200);
  5944. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5945. } while (factor-- && (val != 1));
  5946. if (val != 1) {
  5947. BNX2X_ERR("ATC_INIT failed\n");
  5948. return -EBUSY;
  5949. }
  5950. }
  5951. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5952. bnx2x_iov_init_dmae(bp);
  5953. /* clean the DMAE memory */
  5954. bp->dmae_ready = 1;
  5955. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5956. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5957. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5958. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5959. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5960. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5961. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5962. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5963. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5964. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5965. /* QM queues pointers table */
  5966. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5967. /* soft reset pulse */
  5968. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5969. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5970. if (CNIC_SUPPORT(bp))
  5971. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5972. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5973. if (!CHIP_REV_IS_SLOW(bp))
  5974. /* enable hw interrupt from doorbell Q */
  5975. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5976. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5977. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5978. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5979. if (!CHIP_IS_E1(bp))
  5980. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5981. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5982. if (IS_MF_AFEX(bp)) {
  5983. /* configure that VNTag and VLAN headers must be
  5984. * received in afex mode
  5985. */
  5986. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5987. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5988. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5989. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5990. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5991. } else {
  5992. /* Bit-map indicating which L2 hdrs may appear
  5993. * after the basic Ethernet header
  5994. */
  5995. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5996. bp->path_has_ovlan ? 7 : 6);
  5997. }
  5998. }
  5999. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6000. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6001. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6002. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6003. if (!CHIP_IS_E1x(bp)) {
  6004. /* reset VFC memories */
  6005. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6006. VFC_MEMORIES_RST_REG_CAM_RST |
  6007. VFC_MEMORIES_RST_REG_RAM_RST);
  6008. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6009. VFC_MEMORIES_RST_REG_CAM_RST |
  6010. VFC_MEMORIES_RST_REG_RAM_RST);
  6011. msleep(20);
  6012. }
  6013. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6014. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6015. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6016. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6017. /* sync semi rtc */
  6018. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6019. 0x80000000);
  6020. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6021. 0x80000000);
  6022. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6023. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6024. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6025. if (!CHIP_IS_E1x(bp)) {
  6026. if (IS_MF_AFEX(bp)) {
  6027. /* configure that VNTag and VLAN headers must be
  6028. * sent in afex mode
  6029. */
  6030. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6031. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6032. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6033. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6034. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6035. } else {
  6036. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6037. bp->path_has_ovlan ? 7 : 6);
  6038. }
  6039. }
  6040. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6041. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6042. if (CNIC_SUPPORT(bp)) {
  6043. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6044. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6045. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6046. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6047. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6048. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6049. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6050. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6051. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6052. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6053. }
  6054. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6055. if (sizeof(union cdu_context) != 1024)
  6056. /* we currently assume that a context is 1024 bytes */
  6057. dev_alert(&bp->pdev->dev,
  6058. "please adjust the size of cdu_context(%ld)\n",
  6059. (long)sizeof(union cdu_context));
  6060. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6061. val = (4 << 24) + (0 << 12) + 1024;
  6062. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6063. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6064. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6065. /* enable context validation interrupt from CFC */
  6066. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6067. /* set the thresholds to prevent CFC/CDU race */
  6068. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6069. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6070. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6071. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6072. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6073. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6074. /* Reset PCIE errors for debug */
  6075. REG_WR(bp, 0x2814, 0xffffffff);
  6076. REG_WR(bp, 0x3820, 0xffffffff);
  6077. if (!CHIP_IS_E1x(bp)) {
  6078. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6079. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6080. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6081. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6082. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6083. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6084. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6085. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6086. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6087. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6088. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6089. }
  6090. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6091. if (!CHIP_IS_E1(bp)) {
  6092. /* in E3 this done in per-port section */
  6093. if (!CHIP_IS_E3(bp))
  6094. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6095. }
  6096. if (CHIP_IS_E1H(bp))
  6097. /* not applicable for E2 (and above ...) */
  6098. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6099. if (CHIP_REV_IS_SLOW(bp))
  6100. msleep(200);
  6101. /* finish CFC init */
  6102. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6103. if (val != 1) {
  6104. BNX2X_ERR("CFC LL_INIT failed\n");
  6105. return -EBUSY;
  6106. }
  6107. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6108. if (val != 1) {
  6109. BNX2X_ERR("CFC AC_INIT failed\n");
  6110. return -EBUSY;
  6111. }
  6112. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6113. if (val != 1) {
  6114. BNX2X_ERR("CFC CAM_INIT failed\n");
  6115. return -EBUSY;
  6116. }
  6117. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6118. if (CHIP_IS_E1(bp)) {
  6119. /* read NIG statistic
  6120. to see if this is our first up since powerup */
  6121. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6122. val = *bnx2x_sp(bp, wb_data[0]);
  6123. /* do internal memory self test */
  6124. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6125. BNX2X_ERR("internal mem self test failed\n");
  6126. return -EBUSY;
  6127. }
  6128. }
  6129. bnx2x_setup_fan_failure_detection(bp);
  6130. /* clear PXP2 attentions */
  6131. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6132. bnx2x_enable_blocks_attention(bp);
  6133. bnx2x_enable_blocks_parity(bp);
  6134. if (!BP_NOMCP(bp)) {
  6135. if (CHIP_IS_E1x(bp))
  6136. bnx2x__common_init_phy(bp);
  6137. } else
  6138. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6139. return 0;
  6140. }
  6141. /**
  6142. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6143. *
  6144. * @bp: driver handle
  6145. */
  6146. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6147. {
  6148. int rc = bnx2x_init_hw_common(bp);
  6149. if (rc)
  6150. return rc;
  6151. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6152. if (!BP_NOMCP(bp))
  6153. bnx2x__common_init_phy(bp);
  6154. return 0;
  6155. }
  6156. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6157. {
  6158. int port = BP_PORT(bp);
  6159. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6160. u32 low, high;
  6161. u32 val, reg;
  6162. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6163. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6164. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6165. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6166. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6167. /* Timers bug workaround: disables the pf_master bit in pglue at
  6168. * common phase, we need to enable it here before any dmae access are
  6169. * attempted. Therefore we manually added the enable-master to the
  6170. * port phase (it also happens in the function phase)
  6171. */
  6172. if (!CHIP_IS_E1x(bp))
  6173. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6174. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6175. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6176. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6177. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6178. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6179. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6180. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6181. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6182. /* QM cid (connection) count */
  6183. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6184. if (CNIC_SUPPORT(bp)) {
  6185. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6186. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6187. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6188. }
  6189. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6190. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6191. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6192. if (IS_MF(bp))
  6193. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6194. else if (bp->dev->mtu > 4096) {
  6195. if (bp->flags & ONE_PORT_FLAG)
  6196. low = 160;
  6197. else {
  6198. val = bp->dev->mtu;
  6199. /* (24*1024 + val*4)/256 */
  6200. low = 96 + (val/64) +
  6201. ((val % 64) ? 1 : 0);
  6202. }
  6203. } else
  6204. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6205. high = low + 56; /* 14*1024/256 */
  6206. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6207. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6208. }
  6209. if (CHIP_MODE_IS_4_PORT(bp))
  6210. REG_WR(bp, (BP_PORT(bp) ?
  6211. BRB1_REG_MAC_GUARANTIED_1 :
  6212. BRB1_REG_MAC_GUARANTIED_0), 40);
  6213. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6214. if (CHIP_IS_E3B0(bp)) {
  6215. if (IS_MF_AFEX(bp)) {
  6216. /* configure headers for AFEX mode */
  6217. REG_WR(bp, BP_PORT(bp) ?
  6218. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6219. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6220. REG_WR(bp, BP_PORT(bp) ?
  6221. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6222. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6223. REG_WR(bp, BP_PORT(bp) ?
  6224. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6225. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6226. } else {
  6227. /* Ovlan exists only if we are in multi-function +
  6228. * switch-dependent mode, in switch-independent there
  6229. * is no ovlan headers
  6230. */
  6231. REG_WR(bp, BP_PORT(bp) ?
  6232. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6233. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6234. (bp->path_has_ovlan ? 7 : 6));
  6235. }
  6236. }
  6237. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6238. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6239. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6240. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6241. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6242. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6243. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6244. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6245. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6246. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6247. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6248. if (CHIP_IS_E1x(bp)) {
  6249. /* configure PBF to work without PAUSE mtu 9000 */
  6250. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6251. /* update threshold */
  6252. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6253. /* update init credit */
  6254. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6255. /* probe changes */
  6256. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6257. udelay(50);
  6258. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6259. }
  6260. if (CNIC_SUPPORT(bp))
  6261. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6263. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6264. if (CHIP_IS_E1(bp)) {
  6265. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6266. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6267. }
  6268. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6269. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6270. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6271. /* init aeu_mask_attn_func_0/1:
  6272. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6273. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6274. * bits 4-7 are used for "per vn group attention" */
  6275. val = IS_MF(bp) ? 0xF7 : 0x7;
  6276. /* Enable DCBX attention for all but E1 */
  6277. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6278. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6279. /* SCPAD_PARITY should NOT trigger close the gates */
  6280. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6281. REG_WR(bp, reg,
  6282. REG_RD(bp, reg) &
  6283. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6284. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6285. REG_WR(bp, reg,
  6286. REG_RD(bp, reg) &
  6287. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6288. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6289. if (!CHIP_IS_E1x(bp)) {
  6290. /* Bit-map indicating which L2 hdrs may appear after the
  6291. * basic Ethernet header
  6292. */
  6293. if (IS_MF_AFEX(bp))
  6294. REG_WR(bp, BP_PORT(bp) ?
  6295. NIG_REG_P1_HDRS_AFTER_BASIC :
  6296. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6297. else
  6298. REG_WR(bp, BP_PORT(bp) ?
  6299. NIG_REG_P1_HDRS_AFTER_BASIC :
  6300. NIG_REG_P0_HDRS_AFTER_BASIC,
  6301. IS_MF_SD(bp) ? 7 : 6);
  6302. if (CHIP_IS_E3(bp))
  6303. REG_WR(bp, BP_PORT(bp) ?
  6304. NIG_REG_LLH1_MF_MODE :
  6305. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6306. }
  6307. if (!CHIP_IS_E3(bp))
  6308. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6309. if (!CHIP_IS_E1(bp)) {
  6310. /* 0x2 disable mf_ov, 0x1 enable */
  6311. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6312. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6313. if (!CHIP_IS_E1x(bp)) {
  6314. val = 0;
  6315. switch (bp->mf_mode) {
  6316. case MULTI_FUNCTION_SD:
  6317. val = 1;
  6318. break;
  6319. case MULTI_FUNCTION_SI:
  6320. case MULTI_FUNCTION_AFEX:
  6321. val = 2;
  6322. break;
  6323. }
  6324. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6325. NIG_REG_LLH0_CLS_TYPE), val);
  6326. }
  6327. {
  6328. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6329. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6330. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6331. }
  6332. }
  6333. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6334. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6335. if (val & MISC_SPIO_SPIO5) {
  6336. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6337. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6338. val = REG_RD(bp, reg_addr);
  6339. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6340. REG_WR(bp, reg_addr, val);
  6341. }
  6342. return 0;
  6343. }
  6344. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6345. {
  6346. int reg;
  6347. u32 wb_write[2];
  6348. if (CHIP_IS_E1(bp))
  6349. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6350. else
  6351. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6352. wb_write[0] = ONCHIP_ADDR1(addr);
  6353. wb_write[1] = ONCHIP_ADDR2(addr);
  6354. REG_WR_DMAE(bp, reg, wb_write, 2);
  6355. }
  6356. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6357. {
  6358. u32 data, ctl, cnt = 100;
  6359. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6360. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6361. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6362. u32 sb_bit = 1 << (idu_sb_id%32);
  6363. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6364. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6365. /* Not supported in BC mode */
  6366. if (CHIP_INT_MODE_IS_BC(bp))
  6367. return;
  6368. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6369. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6370. IGU_REGULAR_CLEANUP_SET |
  6371. IGU_REGULAR_BCLEANUP;
  6372. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6373. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6374. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6375. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6376. data, igu_addr_data);
  6377. REG_WR(bp, igu_addr_data, data);
  6378. mmiowb();
  6379. barrier();
  6380. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6381. ctl, igu_addr_ctl);
  6382. REG_WR(bp, igu_addr_ctl, ctl);
  6383. mmiowb();
  6384. barrier();
  6385. /* wait for clean up to finish */
  6386. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6387. msleep(20);
  6388. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6389. DP(NETIF_MSG_HW,
  6390. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6391. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6392. }
  6393. }
  6394. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6395. {
  6396. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6397. }
  6398. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6399. {
  6400. u32 i, base = FUNC_ILT_BASE(func);
  6401. for (i = base; i < base + ILT_PER_FUNC; i++)
  6402. bnx2x_ilt_wr(bp, i, 0);
  6403. }
  6404. static void bnx2x_init_searcher(struct bnx2x *bp)
  6405. {
  6406. int port = BP_PORT(bp);
  6407. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6408. /* T1 hash bits value determines the T1 number of entries */
  6409. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6410. }
  6411. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6412. {
  6413. int rc;
  6414. struct bnx2x_func_state_params func_params = {NULL};
  6415. struct bnx2x_func_switch_update_params *switch_update_params =
  6416. &func_params.params.switch_update;
  6417. /* Prepare parameters for function state transitions */
  6418. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6419. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6420. func_params.f_obj = &bp->func_obj;
  6421. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6422. /* Function parameters */
  6423. switch_update_params->suspend = suspend;
  6424. rc = bnx2x_func_state_change(bp, &func_params);
  6425. return rc;
  6426. }
  6427. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6428. {
  6429. int rc, i, port = BP_PORT(bp);
  6430. int vlan_en = 0, mac_en[NUM_MACS];
  6431. /* Close input from network */
  6432. if (bp->mf_mode == SINGLE_FUNCTION) {
  6433. bnx2x_set_rx_filter(&bp->link_params, 0);
  6434. } else {
  6435. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6436. NIG_REG_LLH0_FUNC_EN);
  6437. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6438. NIG_REG_LLH0_FUNC_EN, 0);
  6439. for (i = 0; i < NUM_MACS; i++) {
  6440. mac_en[i] = REG_RD(bp, port ?
  6441. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6442. 4 * i) :
  6443. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6444. 4 * i));
  6445. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6446. 4 * i) :
  6447. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6448. }
  6449. }
  6450. /* Close BMC to host */
  6451. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6452. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6453. /* Suspend Tx switching to the PF. Completion of this ramrod
  6454. * further guarantees that all the packets of that PF / child
  6455. * VFs in BRB were processed by the Parser, so it is safe to
  6456. * change the NIC_MODE register.
  6457. */
  6458. rc = bnx2x_func_switch_update(bp, 1);
  6459. if (rc) {
  6460. BNX2X_ERR("Can't suspend tx-switching!\n");
  6461. return rc;
  6462. }
  6463. /* Change NIC_MODE register */
  6464. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6465. /* Open input from network */
  6466. if (bp->mf_mode == SINGLE_FUNCTION) {
  6467. bnx2x_set_rx_filter(&bp->link_params, 1);
  6468. } else {
  6469. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6470. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6471. for (i = 0; i < NUM_MACS; i++) {
  6472. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6473. 4 * i) :
  6474. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6475. mac_en[i]);
  6476. }
  6477. }
  6478. /* Enable BMC to host */
  6479. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6480. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6481. /* Resume Tx switching to the PF */
  6482. rc = bnx2x_func_switch_update(bp, 0);
  6483. if (rc) {
  6484. BNX2X_ERR("Can't resume tx-switching!\n");
  6485. return rc;
  6486. }
  6487. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6488. return 0;
  6489. }
  6490. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6491. {
  6492. int rc;
  6493. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6494. if (CONFIGURE_NIC_MODE(bp)) {
  6495. /* Configure searcher as part of function hw init */
  6496. bnx2x_init_searcher(bp);
  6497. /* Reset NIC mode */
  6498. rc = bnx2x_reset_nic_mode(bp);
  6499. if (rc)
  6500. BNX2X_ERR("Can't change NIC mode!\n");
  6501. return rc;
  6502. }
  6503. return 0;
  6504. }
  6505. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6506. {
  6507. int port = BP_PORT(bp);
  6508. int func = BP_FUNC(bp);
  6509. int init_phase = PHASE_PF0 + func;
  6510. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6511. u16 cdu_ilt_start;
  6512. u32 addr, val;
  6513. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6514. int i, main_mem_width, rc;
  6515. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6516. /* FLR cleanup - hmmm */
  6517. if (!CHIP_IS_E1x(bp)) {
  6518. rc = bnx2x_pf_flr_clnup(bp);
  6519. if (rc) {
  6520. bnx2x_fw_dump(bp);
  6521. return rc;
  6522. }
  6523. }
  6524. /* set MSI reconfigure capability */
  6525. if (bp->common.int_block == INT_BLOCK_HC) {
  6526. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6527. val = REG_RD(bp, addr);
  6528. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6529. REG_WR(bp, addr, val);
  6530. }
  6531. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6532. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6533. ilt = BP_ILT(bp);
  6534. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6535. if (IS_SRIOV(bp))
  6536. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6537. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6538. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6539. * those of the VFs, so start line should be reset
  6540. */
  6541. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6542. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6543. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6544. ilt->lines[cdu_ilt_start + i].page_mapping =
  6545. bp->context[i].cxt_mapping;
  6546. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6547. }
  6548. bnx2x_ilt_init_op(bp, INITOP_SET);
  6549. if (!CONFIGURE_NIC_MODE(bp)) {
  6550. bnx2x_init_searcher(bp);
  6551. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6552. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6553. } else {
  6554. /* Set NIC mode */
  6555. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6556. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6557. }
  6558. if (!CHIP_IS_E1x(bp)) {
  6559. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6560. /* Turn on a single ISR mode in IGU if driver is going to use
  6561. * INT#x or MSI
  6562. */
  6563. if (!(bp->flags & USING_MSIX_FLAG))
  6564. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6565. /*
  6566. * Timers workaround bug: function init part.
  6567. * Need to wait 20msec after initializing ILT,
  6568. * needed to make sure there are no requests in
  6569. * one of the PXP internal queues with "old" ILT addresses
  6570. */
  6571. msleep(20);
  6572. /*
  6573. * Master enable - Due to WB DMAE writes performed before this
  6574. * register is re-initialized as part of the regular function
  6575. * init
  6576. */
  6577. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6578. /* Enable the function in IGU */
  6579. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6580. }
  6581. bp->dmae_ready = 1;
  6582. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6583. if (!CHIP_IS_E1x(bp))
  6584. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6585. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6586. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6587. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6588. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6589. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6590. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6591. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6592. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6593. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6594. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6595. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6596. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6597. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6598. if (!CHIP_IS_E1x(bp))
  6599. REG_WR(bp, QM_REG_PF_EN, 1);
  6600. if (!CHIP_IS_E1x(bp)) {
  6601. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6602. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6603. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6604. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6605. }
  6606. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6607. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6608. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6609. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6610. bnx2x_iov_init_dq(bp);
  6611. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6612. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6613. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6614. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6615. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6616. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6617. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6618. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6619. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6620. if (!CHIP_IS_E1x(bp))
  6621. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6622. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6623. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6624. if (!CHIP_IS_E1x(bp))
  6625. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6626. if (IS_MF(bp)) {
  6627. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6628. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6629. }
  6630. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6631. /* HC init per function */
  6632. if (bp->common.int_block == INT_BLOCK_HC) {
  6633. if (CHIP_IS_E1H(bp)) {
  6634. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6635. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6636. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6637. }
  6638. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6639. } else {
  6640. int num_segs, sb_idx, prod_offset;
  6641. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6642. if (!CHIP_IS_E1x(bp)) {
  6643. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6644. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6645. }
  6646. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6647. if (!CHIP_IS_E1x(bp)) {
  6648. int dsb_idx = 0;
  6649. /**
  6650. * Producer memory:
  6651. * E2 mode: address 0-135 match to the mapping memory;
  6652. * 136 - PF0 default prod; 137 - PF1 default prod;
  6653. * 138 - PF2 default prod; 139 - PF3 default prod;
  6654. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6655. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6656. * 144-147 reserved.
  6657. *
  6658. * E1.5 mode - In backward compatible mode;
  6659. * for non default SB; each even line in the memory
  6660. * holds the U producer and each odd line hold
  6661. * the C producer. The first 128 producers are for
  6662. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6663. * producers are for the DSB for each PF.
  6664. * Each PF has five segments: (the order inside each
  6665. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6666. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6667. * 144-147 attn prods;
  6668. */
  6669. /* non-default-status-blocks */
  6670. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6671. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6672. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6673. prod_offset = (bp->igu_base_sb + sb_idx) *
  6674. num_segs;
  6675. for (i = 0; i < num_segs; i++) {
  6676. addr = IGU_REG_PROD_CONS_MEMORY +
  6677. (prod_offset + i) * 4;
  6678. REG_WR(bp, addr, 0);
  6679. }
  6680. /* send consumer update with value 0 */
  6681. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6682. USTORM_ID, 0, IGU_INT_NOP, 1);
  6683. bnx2x_igu_clear_sb(bp,
  6684. bp->igu_base_sb + sb_idx);
  6685. }
  6686. /* default-status-blocks */
  6687. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6688. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6689. if (CHIP_MODE_IS_4_PORT(bp))
  6690. dsb_idx = BP_FUNC(bp);
  6691. else
  6692. dsb_idx = BP_VN(bp);
  6693. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6694. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6695. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6696. /*
  6697. * igu prods come in chunks of E1HVN_MAX (4) -
  6698. * does not matters what is the current chip mode
  6699. */
  6700. for (i = 0; i < (num_segs * E1HVN_MAX);
  6701. i += E1HVN_MAX) {
  6702. addr = IGU_REG_PROD_CONS_MEMORY +
  6703. (prod_offset + i)*4;
  6704. REG_WR(bp, addr, 0);
  6705. }
  6706. /* send consumer update with 0 */
  6707. if (CHIP_INT_MODE_IS_BC(bp)) {
  6708. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6709. USTORM_ID, 0, IGU_INT_NOP, 1);
  6710. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6711. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6712. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6713. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6714. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6715. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6716. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6717. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6718. } else {
  6719. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6720. USTORM_ID, 0, IGU_INT_NOP, 1);
  6721. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6722. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6723. }
  6724. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6725. /* !!! These should become driver const once
  6726. rf-tool supports split-68 const */
  6727. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6728. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6729. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6730. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6731. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6732. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6733. }
  6734. }
  6735. /* Reset PCIE errors for debug */
  6736. REG_WR(bp, 0x2114, 0xffffffff);
  6737. REG_WR(bp, 0x2120, 0xffffffff);
  6738. if (CHIP_IS_E1x(bp)) {
  6739. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6740. main_mem_base = HC_REG_MAIN_MEMORY +
  6741. BP_PORT(bp) * (main_mem_size * 4);
  6742. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6743. main_mem_width = 8;
  6744. val = REG_RD(bp, main_mem_prty_clr);
  6745. if (val)
  6746. DP(NETIF_MSG_HW,
  6747. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6748. val);
  6749. /* Clear "false" parity errors in MSI-X table */
  6750. for (i = main_mem_base;
  6751. i < main_mem_base + main_mem_size * 4;
  6752. i += main_mem_width) {
  6753. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6754. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6755. i, main_mem_width / 4);
  6756. }
  6757. /* Clear HC parity attention */
  6758. REG_RD(bp, main_mem_prty_clr);
  6759. }
  6760. #ifdef BNX2X_STOP_ON_ERROR
  6761. /* Enable STORMs SP logging */
  6762. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6763. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6764. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6765. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6766. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6767. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6768. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6769. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6770. #endif
  6771. bnx2x_phy_probe(&bp->link_params);
  6772. return 0;
  6773. }
  6774. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6775. {
  6776. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6777. if (!CHIP_IS_E1x(bp))
  6778. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6779. sizeof(struct host_hc_status_block_e2));
  6780. else
  6781. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6782. sizeof(struct host_hc_status_block_e1x));
  6783. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6784. }
  6785. void bnx2x_free_mem(struct bnx2x *bp)
  6786. {
  6787. int i;
  6788. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6789. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6790. if (IS_VF(bp))
  6791. return;
  6792. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6793. sizeof(struct host_sp_status_block));
  6794. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6795. sizeof(struct bnx2x_slowpath));
  6796. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6797. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6798. bp->context[i].size);
  6799. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6800. BNX2X_FREE(bp->ilt->lines);
  6801. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6802. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6803. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6804. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6805. bnx2x_iov_free_mem(bp);
  6806. }
  6807. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6808. {
  6809. if (!CHIP_IS_E1x(bp)) {
  6810. /* size = the status block + ramrod buffers */
  6811. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6812. sizeof(struct host_hc_status_block_e2));
  6813. if (!bp->cnic_sb.e2_sb)
  6814. goto alloc_mem_err;
  6815. } else {
  6816. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6817. sizeof(struct host_hc_status_block_e1x));
  6818. if (!bp->cnic_sb.e1x_sb)
  6819. goto alloc_mem_err;
  6820. }
  6821. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6822. /* allocate searcher T2 table, as it wasn't allocated before */
  6823. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6824. if (!bp->t2)
  6825. goto alloc_mem_err;
  6826. }
  6827. /* write address to which L5 should insert its values */
  6828. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6829. &bp->slowpath->drv_info_to_mcp;
  6830. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6831. goto alloc_mem_err;
  6832. return 0;
  6833. alloc_mem_err:
  6834. bnx2x_free_mem_cnic(bp);
  6835. BNX2X_ERR("Can't allocate memory\n");
  6836. return -ENOMEM;
  6837. }
  6838. int bnx2x_alloc_mem(struct bnx2x *bp)
  6839. {
  6840. int i, allocated, context_size;
  6841. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6842. /* allocate searcher T2 table */
  6843. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6844. if (!bp->t2)
  6845. goto alloc_mem_err;
  6846. }
  6847. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6848. sizeof(struct host_sp_status_block));
  6849. if (!bp->def_status_blk)
  6850. goto alloc_mem_err;
  6851. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6852. sizeof(struct bnx2x_slowpath));
  6853. if (!bp->slowpath)
  6854. goto alloc_mem_err;
  6855. /* Allocate memory for CDU context:
  6856. * This memory is allocated separately and not in the generic ILT
  6857. * functions because CDU differs in few aspects:
  6858. * 1. There are multiple entities allocating memory for context -
  6859. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6860. * its own ILT lines.
  6861. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6862. * for the other ILT clients), to be efficient we want to support
  6863. * allocation of sub-page-size in the last entry.
  6864. * 3. Context pointers are used by the driver to pass to FW / update
  6865. * the context (for the other ILT clients the pointers are used just to
  6866. * free the memory during unload).
  6867. */
  6868. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6869. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6870. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6871. (context_size - allocated));
  6872. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6873. bp->context[i].size);
  6874. if (!bp->context[i].vcxt)
  6875. goto alloc_mem_err;
  6876. allocated += bp->context[i].size;
  6877. }
  6878. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6879. GFP_KERNEL);
  6880. if (!bp->ilt->lines)
  6881. goto alloc_mem_err;
  6882. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6883. goto alloc_mem_err;
  6884. if (bnx2x_iov_alloc_mem(bp))
  6885. goto alloc_mem_err;
  6886. /* Slow path ring */
  6887. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  6888. if (!bp->spq)
  6889. goto alloc_mem_err;
  6890. /* EQ */
  6891. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  6892. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6893. if (!bp->eq_ring)
  6894. goto alloc_mem_err;
  6895. return 0;
  6896. alloc_mem_err:
  6897. bnx2x_free_mem(bp);
  6898. BNX2X_ERR("Can't allocate memory\n");
  6899. return -ENOMEM;
  6900. }
  6901. /*
  6902. * Init service functions
  6903. */
  6904. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6905. struct bnx2x_vlan_mac_obj *obj, bool set,
  6906. int mac_type, unsigned long *ramrod_flags)
  6907. {
  6908. int rc;
  6909. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6910. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6911. /* Fill general parameters */
  6912. ramrod_param.vlan_mac_obj = obj;
  6913. ramrod_param.ramrod_flags = *ramrod_flags;
  6914. /* Fill a user request section if needed */
  6915. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6916. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6917. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6918. /* Set the command: ADD or DEL */
  6919. if (set)
  6920. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6921. else
  6922. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6923. }
  6924. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6925. if (rc == -EEXIST) {
  6926. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6927. /* do not treat adding same MAC as error */
  6928. rc = 0;
  6929. } else if (rc < 0)
  6930. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6931. return rc;
  6932. }
  6933. int bnx2x_del_all_macs(struct bnx2x *bp,
  6934. struct bnx2x_vlan_mac_obj *mac_obj,
  6935. int mac_type, bool wait_for_comp)
  6936. {
  6937. int rc;
  6938. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6939. /* Wait for completion of requested */
  6940. if (wait_for_comp)
  6941. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6942. /* Set the mac type of addresses we want to clear */
  6943. __set_bit(mac_type, &vlan_mac_flags);
  6944. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6945. if (rc < 0)
  6946. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6947. return rc;
  6948. }
  6949. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6950. {
  6951. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6952. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6953. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6954. "Ignoring Zero MAC for STORAGE SD mode\n");
  6955. return 0;
  6956. }
  6957. if (IS_PF(bp)) {
  6958. unsigned long ramrod_flags = 0;
  6959. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6960. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6961. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6962. &bp->sp_objs->mac_obj, set,
  6963. BNX2X_ETH_MAC, &ramrod_flags);
  6964. } else { /* vf */
  6965. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6966. bp->fp->index, true);
  6967. }
  6968. }
  6969. int bnx2x_setup_leading(struct bnx2x *bp)
  6970. {
  6971. if (IS_PF(bp))
  6972. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6973. else /* VF */
  6974. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6975. }
  6976. /**
  6977. * bnx2x_set_int_mode - configure interrupt mode
  6978. *
  6979. * @bp: driver handle
  6980. *
  6981. * In case of MSI-X it will also try to enable MSI-X.
  6982. */
  6983. int bnx2x_set_int_mode(struct bnx2x *bp)
  6984. {
  6985. int rc = 0;
  6986. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  6987. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  6988. return -EINVAL;
  6989. }
  6990. switch (int_mode) {
  6991. case BNX2X_INT_MODE_MSIX:
  6992. /* attempt to enable msix */
  6993. rc = bnx2x_enable_msix(bp);
  6994. /* msix attained */
  6995. if (!rc)
  6996. return 0;
  6997. /* vfs use only msix */
  6998. if (rc && IS_VF(bp))
  6999. return rc;
  7000. /* failed to enable multiple MSI-X */
  7001. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7002. bp->num_queues,
  7003. 1 + bp->num_cnic_queues);
  7004. /* falling through... */
  7005. case BNX2X_INT_MODE_MSI:
  7006. bnx2x_enable_msi(bp);
  7007. /* falling through... */
  7008. case BNX2X_INT_MODE_INTX:
  7009. bp->num_ethernet_queues = 1;
  7010. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7011. BNX2X_DEV_INFO("set number of queues to 1\n");
  7012. break;
  7013. default:
  7014. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7015. return -EINVAL;
  7016. }
  7017. return 0;
  7018. }
  7019. /* must be called prior to any HW initializations */
  7020. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7021. {
  7022. if (IS_SRIOV(bp))
  7023. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7024. return L2_ILT_LINES(bp);
  7025. }
  7026. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7027. {
  7028. struct ilt_client_info *ilt_client;
  7029. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7030. u16 line = 0;
  7031. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7032. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7033. /* CDU */
  7034. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7035. ilt_client->client_num = ILT_CLIENT_CDU;
  7036. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7037. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7038. ilt_client->start = line;
  7039. line += bnx2x_cid_ilt_lines(bp);
  7040. if (CNIC_SUPPORT(bp))
  7041. line += CNIC_ILT_LINES;
  7042. ilt_client->end = line - 1;
  7043. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7044. ilt_client->start,
  7045. ilt_client->end,
  7046. ilt_client->page_size,
  7047. ilt_client->flags,
  7048. ilog2(ilt_client->page_size >> 12));
  7049. /* QM */
  7050. if (QM_INIT(bp->qm_cid_count)) {
  7051. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7052. ilt_client->client_num = ILT_CLIENT_QM;
  7053. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7054. ilt_client->flags = 0;
  7055. ilt_client->start = line;
  7056. /* 4 bytes for each cid */
  7057. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7058. QM_ILT_PAGE_SZ);
  7059. ilt_client->end = line - 1;
  7060. DP(NETIF_MSG_IFUP,
  7061. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7062. ilt_client->start,
  7063. ilt_client->end,
  7064. ilt_client->page_size,
  7065. ilt_client->flags,
  7066. ilog2(ilt_client->page_size >> 12));
  7067. }
  7068. if (CNIC_SUPPORT(bp)) {
  7069. /* SRC */
  7070. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7071. ilt_client->client_num = ILT_CLIENT_SRC;
  7072. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7073. ilt_client->flags = 0;
  7074. ilt_client->start = line;
  7075. line += SRC_ILT_LINES;
  7076. ilt_client->end = line - 1;
  7077. DP(NETIF_MSG_IFUP,
  7078. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7079. ilt_client->start,
  7080. ilt_client->end,
  7081. ilt_client->page_size,
  7082. ilt_client->flags,
  7083. ilog2(ilt_client->page_size >> 12));
  7084. /* TM */
  7085. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7086. ilt_client->client_num = ILT_CLIENT_TM;
  7087. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7088. ilt_client->flags = 0;
  7089. ilt_client->start = line;
  7090. line += TM_ILT_LINES;
  7091. ilt_client->end = line - 1;
  7092. DP(NETIF_MSG_IFUP,
  7093. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7094. ilt_client->start,
  7095. ilt_client->end,
  7096. ilt_client->page_size,
  7097. ilt_client->flags,
  7098. ilog2(ilt_client->page_size >> 12));
  7099. }
  7100. BUG_ON(line > ILT_MAX_LINES);
  7101. }
  7102. /**
  7103. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7104. *
  7105. * @bp: driver handle
  7106. * @fp: pointer to fastpath
  7107. * @init_params: pointer to parameters structure
  7108. *
  7109. * parameters configured:
  7110. * - HC configuration
  7111. * - Queue's CDU context
  7112. */
  7113. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7114. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7115. {
  7116. u8 cos;
  7117. int cxt_index, cxt_offset;
  7118. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7119. if (!IS_FCOE_FP(fp)) {
  7120. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7121. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7122. /* If HC is supported, enable host coalescing in the transition
  7123. * to INIT state.
  7124. */
  7125. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7126. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7127. /* HC rate */
  7128. init_params->rx.hc_rate = bp->rx_ticks ?
  7129. (1000000 / bp->rx_ticks) : 0;
  7130. init_params->tx.hc_rate = bp->tx_ticks ?
  7131. (1000000 / bp->tx_ticks) : 0;
  7132. /* FW SB ID */
  7133. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7134. fp->fw_sb_id;
  7135. /*
  7136. * CQ index among the SB indices: FCoE clients uses the default
  7137. * SB, therefore it's different.
  7138. */
  7139. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7140. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7141. }
  7142. /* set maximum number of COSs supported by this queue */
  7143. init_params->max_cos = fp->max_cos;
  7144. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7145. fp->index, init_params->max_cos);
  7146. /* set the context pointers queue object */
  7147. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7148. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7149. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7150. ILT_PAGE_CIDS);
  7151. init_params->cxts[cos] =
  7152. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7153. }
  7154. }
  7155. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7156. struct bnx2x_queue_state_params *q_params,
  7157. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7158. int tx_index, bool leading)
  7159. {
  7160. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7161. /* Set the command */
  7162. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7163. /* Set tx-only QUEUE flags: don't zero statistics */
  7164. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7165. /* choose the index of the cid to send the slow path on */
  7166. tx_only_params->cid_index = tx_index;
  7167. /* Set general TX_ONLY_SETUP parameters */
  7168. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7169. /* Set Tx TX_ONLY_SETUP parameters */
  7170. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7171. DP(NETIF_MSG_IFUP,
  7172. "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",
  7173. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7174. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7175. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7176. /* send the ramrod */
  7177. return bnx2x_queue_state_change(bp, q_params);
  7178. }
  7179. /**
  7180. * bnx2x_setup_queue - setup queue
  7181. *
  7182. * @bp: driver handle
  7183. * @fp: pointer to fastpath
  7184. * @leading: is leading
  7185. *
  7186. * This function performs 2 steps in a Queue state machine
  7187. * actually: 1) RESET->INIT 2) INIT->SETUP
  7188. */
  7189. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7190. bool leading)
  7191. {
  7192. struct bnx2x_queue_state_params q_params = {NULL};
  7193. struct bnx2x_queue_setup_params *setup_params =
  7194. &q_params.params.setup;
  7195. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7196. &q_params.params.tx_only;
  7197. int rc;
  7198. u8 tx_index;
  7199. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7200. /* reset IGU state skip FCoE L2 queue */
  7201. if (!IS_FCOE_FP(fp))
  7202. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7203. IGU_INT_ENABLE, 0);
  7204. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7205. /* We want to wait for completion in this context */
  7206. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7207. /* Prepare the INIT parameters */
  7208. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7209. /* Set the command */
  7210. q_params.cmd = BNX2X_Q_CMD_INIT;
  7211. /* Change the state to INIT */
  7212. rc = bnx2x_queue_state_change(bp, &q_params);
  7213. if (rc) {
  7214. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7215. return rc;
  7216. }
  7217. DP(NETIF_MSG_IFUP, "init complete\n");
  7218. /* Now move the Queue to the SETUP state... */
  7219. memset(setup_params, 0, sizeof(*setup_params));
  7220. /* Set QUEUE flags */
  7221. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7222. /* Set general SETUP parameters */
  7223. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7224. FIRST_TX_COS_INDEX);
  7225. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7226. &setup_params->rxq_params);
  7227. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7228. FIRST_TX_COS_INDEX);
  7229. /* Set the command */
  7230. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7231. if (IS_FCOE_FP(fp))
  7232. bp->fcoe_init = true;
  7233. /* Change the state to SETUP */
  7234. rc = bnx2x_queue_state_change(bp, &q_params);
  7235. if (rc) {
  7236. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7237. return rc;
  7238. }
  7239. /* loop through the relevant tx-only indices */
  7240. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7241. tx_index < fp->max_cos;
  7242. tx_index++) {
  7243. /* prepare and send tx-only ramrod*/
  7244. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7245. tx_only_params, tx_index, leading);
  7246. if (rc) {
  7247. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7248. fp->index, tx_index);
  7249. return rc;
  7250. }
  7251. }
  7252. return rc;
  7253. }
  7254. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7255. {
  7256. struct bnx2x_fastpath *fp = &bp->fp[index];
  7257. struct bnx2x_fp_txdata *txdata;
  7258. struct bnx2x_queue_state_params q_params = {NULL};
  7259. int rc, tx_index;
  7260. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7261. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7262. /* We want to wait for completion in this context */
  7263. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7264. /* close tx-only connections */
  7265. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7266. tx_index < fp->max_cos;
  7267. tx_index++){
  7268. /* ascertain this is a normal queue*/
  7269. txdata = fp->txdata_ptr[tx_index];
  7270. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7271. txdata->txq_index);
  7272. /* send halt terminate on tx-only connection */
  7273. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7274. memset(&q_params.params.terminate, 0,
  7275. sizeof(q_params.params.terminate));
  7276. q_params.params.terminate.cid_index = tx_index;
  7277. rc = bnx2x_queue_state_change(bp, &q_params);
  7278. if (rc)
  7279. return rc;
  7280. /* send halt terminate on tx-only connection */
  7281. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7282. memset(&q_params.params.cfc_del, 0,
  7283. sizeof(q_params.params.cfc_del));
  7284. q_params.params.cfc_del.cid_index = tx_index;
  7285. rc = bnx2x_queue_state_change(bp, &q_params);
  7286. if (rc)
  7287. return rc;
  7288. }
  7289. /* Stop the primary connection: */
  7290. /* ...halt the connection */
  7291. q_params.cmd = BNX2X_Q_CMD_HALT;
  7292. rc = bnx2x_queue_state_change(bp, &q_params);
  7293. if (rc)
  7294. return rc;
  7295. /* ...terminate the connection */
  7296. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7297. memset(&q_params.params.terminate, 0,
  7298. sizeof(q_params.params.terminate));
  7299. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7300. rc = bnx2x_queue_state_change(bp, &q_params);
  7301. if (rc)
  7302. return rc;
  7303. /* ...delete cfc entry */
  7304. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7305. memset(&q_params.params.cfc_del, 0,
  7306. sizeof(q_params.params.cfc_del));
  7307. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7308. return bnx2x_queue_state_change(bp, &q_params);
  7309. }
  7310. static void bnx2x_reset_func(struct bnx2x *bp)
  7311. {
  7312. int port = BP_PORT(bp);
  7313. int func = BP_FUNC(bp);
  7314. int i;
  7315. /* Disable the function in the FW */
  7316. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7317. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7318. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7319. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7320. /* FP SBs */
  7321. for_each_eth_queue(bp, i) {
  7322. struct bnx2x_fastpath *fp = &bp->fp[i];
  7323. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7324. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7325. SB_DISABLED);
  7326. }
  7327. if (CNIC_LOADED(bp))
  7328. /* CNIC SB */
  7329. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7330. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7331. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7332. /* SP SB */
  7333. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7334. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7335. SB_DISABLED);
  7336. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7337. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7338. 0);
  7339. /* Configure IGU */
  7340. if (bp->common.int_block == INT_BLOCK_HC) {
  7341. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7342. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7343. } else {
  7344. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7345. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7346. }
  7347. if (CNIC_LOADED(bp)) {
  7348. /* Disable Timer scan */
  7349. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7350. /*
  7351. * Wait for at least 10ms and up to 2 second for the timers
  7352. * scan to complete
  7353. */
  7354. for (i = 0; i < 200; i++) {
  7355. usleep_range(10000, 20000);
  7356. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7357. break;
  7358. }
  7359. }
  7360. /* Clear ILT */
  7361. bnx2x_clear_func_ilt(bp, func);
  7362. /* Timers workaround bug for E2: if this is vnic-3,
  7363. * we need to set the entire ilt range for this timers.
  7364. */
  7365. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7366. struct ilt_client_info ilt_cli;
  7367. /* use dummy TM client */
  7368. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7369. ilt_cli.start = 0;
  7370. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7371. ilt_cli.client_num = ILT_CLIENT_TM;
  7372. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7373. }
  7374. /* this assumes that reset_port() called before reset_func()*/
  7375. if (!CHIP_IS_E1x(bp))
  7376. bnx2x_pf_disable(bp);
  7377. bp->dmae_ready = 0;
  7378. }
  7379. static void bnx2x_reset_port(struct bnx2x *bp)
  7380. {
  7381. int port = BP_PORT(bp);
  7382. u32 val;
  7383. /* Reset physical Link */
  7384. bnx2x__link_reset(bp);
  7385. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7386. /* Do not rcv packets to BRB */
  7387. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7388. /* Do not direct rcv packets that are not for MCP to the BRB */
  7389. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7390. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7391. /* Configure AEU */
  7392. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7393. msleep(100);
  7394. /* Check for BRB port occupancy */
  7395. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7396. if (val)
  7397. DP(NETIF_MSG_IFDOWN,
  7398. "BRB1 is not empty %d blocks are occupied\n", val);
  7399. /* TODO: Close Doorbell port? */
  7400. }
  7401. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7402. {
  7403. struct bnx2x_func_state_params func_params = {NULL};
  7404. /* Prepare parameters for function state transitions */
  7405. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7406. func_params.f_obj = &bp->func_obj;
  7407. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7408. func_params.params.hw_init.load_phase = load_code;
  7409. return bnx2x_func_state_change(bp, &func_params);
  7410. }
  7411. static int bnx2x_func_stop(struct bnx2x *bp)
  7412. {
  7413. struct bnx2x_func_state_params func_params = {NULL};
  7414. int rc;
  7415. /* Prepare parameters for function state transitions */
  7416. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7417. func_params.f_obj = &bp->func_obj;
  7418. func_params.cmd = BNX2X_F_CMD_STOP;
  7419. /*
  7420. * Try to stop the function the 'good way'. If fails (in case
  7421. * of a parity error during bnx2x_chip_cleanup()) and we are
  7422. * not in a debug mode, perform a state transaction in order to
  7423. * enable further HW_RESET transaction.
  7424. */
  7425. rc = bnx2x_func_state_change(bp, &func_params);
  7426. if (rc) {
  7427. #ifdef BNX2X_STOP_ON_ERROR
  7428. return rc;
  7429. #else
  7430. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7431. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7432. return bnx2x_func_state_change(bp, &func_params);
  7433. #endif
  7434. }
  7435. return 0;
  7436. }
  7437. /**
  7438. * bnx2x_send_unload_req - request unload mode from the MCP.
  7439. *
  7440. * @bp: driver handle
  7441. * @unload_mode: requested function's unload mode
  7442. *
  7443. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7444. */
  7445. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7446. {
  7447. u32 reset_code = 0;
  7448. int port = BP_PORT(bp);
  7449. /* Select the UNLOAD request mode */
  7450. if (unload_mode == UNLOAD_NORMAL)
  7451. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7452. else if (bp->flags & NO_WOL_FLAG)
  7453. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7454. else if (bp->wol) {
  7455. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7456. u8 *mac_addr = bp->dev->dev_addr;
  7457. struct pci_dev *pdev = bp->pdev;
  7458. u32 val;
  7459. u16 pmc;
  7460. /* The mac address is written to entries 1-4 to
  7461. * preserve entry 0 which is used by the PMF
  7462. */
  7463. u8 entry = (BP_VN(bp) + 1)*8;
  7464. val = (mac_addr[0] << 8) | mac_addr[1];
  7465. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7466. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7467. (mac_addr[4] << 8) | mac_addr[5];
  7468. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7469. /* Enable the PME and clear the status */
  7470. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7471. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7472. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7473. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7474. } else
  7475. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7476. /* Send the request to the MCP */
  7477. if (!BP_NOMCP(bp))
  7478. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7479. else {
  7480. int path = BP_PATH(bp);
  7481. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7482. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7483. bnx2x_load_count[path][2]);
  7484. bnx2x_load_count[path][0]--;
  7485. bnx2x_load_count[path][1 + port]--;
  7486. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7487. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7488. bnx2x_load_count[path][2]);
  7489. if (bnx2x_load_count[path][0] == 0)
  7490. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7491. else if (bnx2x_load_count[path][1 + port] == 0)
  7492. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7493. else
  7494. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7495. }
  7496. return reset_code;
  7497. }
  7498. /**
  7499. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7500. *
  7501. * @bp: driver handle
  7502. * @keep_link: true iff link should be kept up
  7503. */
  7504. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7505. {
  7506. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7507. /* Report UNLOAD_DONE to MCP */
  7508. if (!BP_NOMCP(bp))
  7509. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7510. }
  7511. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7512. {
  7513. int tout = 50;
  7514. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7515. if (!bp->port.pmf)
  7516. return 0;
  7517. /*
  7518. * (assumption: No Attention from MCP at this stage)
  7519. * PMF probably in the middle of TX disable/enable transaction
  7520. * 1. Sync IRS for default SB
  7521. * 2. Sync SP queue - this guarantees us that attention handling started
  7522. * 3. Wait, that TX disable/enable transaction completes
  7523. *
  7524. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7525. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7526. * received completion for the transaction the state is TX_STOPPED.
  7527. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7528. * transaction.
  7529. */
  7530. /* make sure default SB ISR is done */
  7531. if (msix)
  7532. synchronize_irq(bp->msix_table[0].vector);
  7533. else
  7534. synchronize_irq(bp->pdev->irq);
  7535. flush_workqueue(bnx2x_wq);
  7536. flush_workqueue(bnx2x_iov_wq);
  7537. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7538. BNX2X_F_STATE_STARTED && tout--)
  7539. msleep(20);
  7540. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7541. BNX2X_F_STATE_STARTED) {
  7542. #ifdef BNX2X_STOP_ON_ERROR
  7543. BNX2X_ERR("Wrong function state\n");
  7544. return -EBUSY;
  7545. #else
  7546. /*
  7547. * Failed to complete the transaction in a "good way"
  7548. * Force both transactions with CLR bit
  7549. */
  7550. struct bnx2x_func_state_params func_params = {NULL};
  7551. DP(NETIF_MSG_IFDOWN,
  7552. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7553. func_params.f_obj = &bp->func_obj;
  7554. __set_bit(RAMROD_DRV_CLR_ONLY,
  7555. &func_params.ramrod_flags);
  7556. /* STARTED-->TX_ST0PPED */
  7557. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7558. bnx2x_func_state_change(bp, &func_params);
  7559. /* TX_ST0PPED-->STARTED */
  7560. func_params.cmd = BNX2X_F_CMD_TX_START;
  7561. return bnx2x_func_state_change(bp, &func_params);
  7562. #endif
  7563. }
  7564. return 0;
  7565. }
  7566. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7567. {
  7568. int port = BP_PORT(bp);
  7569. int i, rc = 0;
  7570. u8 cos;
  7571. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7572. u32 reset_code;
  7573. /* Wait until tx fastpath tasks complete */
  7574. for_each_tx_queue(bp, i) {
  7575. struct bnx2x_fastpath *fp = &bp->fp[i];
  7576. for_each_cos_in_tx_queue(fp, cos)
  7577. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7578. #ifdef BNX2X_STOP_ON_ERROR
  7579. if (rc)
  7580. return;
  7581. #endif
  7582. }
  7583. /* Give HW time to discard old tx messages */
  7584. usleep_range(1000, 2000);
  7585. /* Clean all ETH MACs */
  7586. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7587. false);
  7588. if (rc < 0)
  7589. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7590. /* Clean up UC list */
  7591. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7592. true);
  7593. if (rc < 0)
  7594. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7595. rc);
  7596. /* Disable LLH */
  7597. if (!CHIP_IS_E1(bp))
  7598. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7599. /* Set "drop all" (stop Rx).
  7600. * We need to take a netif_addr_lock() here in order to prevent
  7601. * a race between the completion code and this code.
  7602. */
  7603. netif_addr_lock_bh(bp->dev);
  7604. /* Schedule the rx_mode command */
  7605. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7606. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7607. else
  7608. bnx2x_set_storm_rx_mode(bp);
  7609. /* Cleanup multicast configuration */
  7610. rparam.mcast_obj = &bp->mcast_obj;
  7611. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7612. if (rc < 0)
  7613. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7614. netif_addr_unlock_bh(bp->dev);
  7615. bnx2x_iov_chip_cleanup(bp);
  7616. /*
  7617. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7618. * this function should perform FUNC, PORT or COMMON HW
  7619. * reset.
  7620. */
  7621. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7622. /*
  7623. * (assumption: No Attention from MCP at this stage)
  7624. * PMF probably in the middle of TX disable/enable transaction
  7625. */
  7626. rc = bnx2x_func_wait_started(bp);
  7627. if (rc) {
  7628. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7629. #ifdef BNX2X_STOP_ON_ERROR
  7630. return;
  7631. #endif
  7632. }
  7633. /* Close multi and leading connections
  7634. * Completions for ramrods are collected in a synchronous way
  7635. */
  7636. for_each_eth_queue(bp, i)
  7637. if (bnx2x_stop_queue(bp, i))
  7638. #ifdef BNX2X_STOP_ON_ERROR
  7639. return;
  7640. #else
  7641. goto unload_error;
  7642. #endif
  7643. if (CNIC_LOADED(bp)) {
  7644. for_each_cnic_queue(bp, i)
  7645. if (bnx2x_stop_queue(bp, i))
  7646. #ifdef BNX2X_STOP_ON_ERROR
  7647. return;
  7648. #else
  7649. goto unload_error;
  7650. #endif
  7651. }
  7652. /* If SP settings didn't get completed so far - something
  7653. * very wrong has happen.
  7654. */
  7655. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7656. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7657. #ifndef BNX2X_STOP_ON_ERROR
  7658. unload_error:
  7659. #endif
  7660. rc = bnx2x_func_stop(bp);
  7661. if (rc) {
  7662. BNX2X_ERR("Function stop failed!\n");
  7663. #ifdef BNX2X_STOP_ON_ERROR
  7664. return;
  7665. #endif
  7666. }
  7667. /* Disable HW interrupts, NAPI */
  7668. bnx2x_netif_stop(bp, 1);
  7669. /* Delete all NAPI objects */
  7670. bnx2x_del_all_napi(bp);
  7671. if (CNIC_LOADED(bp))
  7672. bnx2x_del_all_napi_cnic(bp);
  7673. /* Release IRQs */
  7674. bnx2x_free_irq(bp);
  7675. /* Reset the chip */
  7676. rc = bnx2x_reset_hw(bp, reset_code);
  7677. if (rc)
  7678. BNX2X_ERR("HW_RESET failed\n");
  7679. /* Report UNLOAD_DONE to MCP */
  7680. bnx2x_send_unload_done(bp, keep_link);
  7681. }
  7682. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7683. {
  7684. u32 val;
  7685. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7686. if (CHIP_IS_E1(bp)) {
  7687. int port = BP_PORT(bp);
  7688. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7689. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7690. val = REG_RD(bp, addr);
  7691. val &= ~(0x300);
  7692. REG_WR(bp, addr, val);
  7693. } else {
  7694. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7695. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7696. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7697. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7698. }
  7699. }
  7700. /* Close gates #2, #3 and #4: */
  7701. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7702. {
  7703. u32 val;
  7704. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7705. if (!CHIP_IS_E1(bp)) {
  7706. /* #4 */
  7707. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7708. /* #2 */
  7709. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7710. }
  7711. /* #3 */
  7712. if (CHIP_IS_E1x(bp)) {
  7713. /* Prevent interrupts from HC on both ports */
  7714. val = REG_RD(bp, HC_REG_CONFIG_1);
  7715. REG_WR(bp, HC_REG_CONFIG_1,
  7716. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7717. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7718. val = REG_RD(bp, HC_REG_CONFIG_0);
  7719. REG_WR(bp, HC_REG_CONFIG_0,
  7720. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7721. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7722. } else {
  7723. /* Prevent incoming interrupts in IGU */
  7724. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7725. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7726. (!close) ?
  7727. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7728. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7729. }
  7730. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7731. close ? "closing" : "opening");
  7732. mmiowb();
  7733. }
  7734. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7735. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7736. {
  7737. /* Do some magic... */
  7738. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7739. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7740. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7741. }
  7742. /**
  7743. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7744. *
  7745. * @bp: driver handle
  7746. * @magic_val: old value of the `magic' bit.
  7747. */
  7748. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7749. {
  7750. /* Restore the `magic' bit value... */
  7751. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7752. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7753. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7754. }
  7755. /**
  7756. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7757. *
  7758. * @bp: driver handle
  7759. * @magic_val: old value of 'magic' bit.
  7760. *
  7761. * Takes care of CLP configurations.
  7762. */
  7763. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7764. {
  7765. u32 shmem;
  7766. u32 validity_offset;
  7767. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7768. /* Set `magic' bit in order to save MF config */
  7769. if (!CHIP_IS_E1(bp))
  7770. bnx2x_clp_reset_prep(bp, magic_val);
  7771. /* Get shmem offset */
  7772. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7773. validity_offset =
  7774. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7775. /* Clear validity map flags */
  7776. if (shmem > 0)
  7777. REG_WR(bp, shmem + validity_offset, 0);
  7778. }
  7779. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7780. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7781. /**
  7782. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7783. *
  7784. * @bp: driver handle
  7785. */
  7786. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7787. {
  7788. /* special handling for emulation and FPGA,
  7789. wait 10 times longer */
  7790. if (CHIP_REV_IS_SLOW(bp))
  7791. msleep(MCP_ONE_TIMEOUT*10);
  7792. else
  7793. msleep(MCP_ONE_TIMEOUT);
  7794. }
  7795. /*
  7796. * initializes bp->common.shmem_base and waits for validity signature to appear
  7797. */
  7798. static int bnx2x_init_shmem(struct bnx2x *bp)
  7799. {
  7800. int cnt = 0;
  7801. u32 val = 0;
  7802. do {
  7803. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7804. if (bp->common.shmem_base) {
  7805. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7806. if (val & SHR_MEM_VALIDITY_MB)
  7807. return 0;
  7808. }
  7809. bnx2x_mcp_wait_one(bp);
  7810. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7811. BNX2X_ERR("BAD MCP validity signature\n");
  7812. return -ENODEV;
  7813. }
  7814. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7815. {
  7816. int rc = bnx2x_init_shmem(bp);
  7817. /* Restore the `magic' bit value */
  7818. if (!CHIP_IS_E1(bp))
  7819. bnx2x_clp_reset_done(bp, magic_val);
  7820. return rc;
  7821. }
  7822. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7823. {
  7824. if (!CHIP_IS_E1(bp)) {
  7825. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7826. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7827. mmiowb();
  7828. }
  7829. }
  7830. /*
  7831. * Reset the whole chip except for:
  7832. * - PCIE core
  7833. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7834. * one reset bit)
  7835. * - IGU
  7836. * - MISC (including AEU)
  7837. * - GRC
  7838. * - RBCN, RBCP
  7839. */
  7840. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7841. {
  7842. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7843. u32 global_bits2, stay_reset2;
  7844. /*
  7845. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7846. * (per chip) blocks.
  7847. */
  7848. global_bits2 =
  7849. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7850. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7851. /* Don't reset the following blocks.
  7852. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7853. * reset, as in 4 port device they might still be owned
  7854. * by the MCP (there is only one leader per path).
  7855. */
  7856. not_reset_mask1 =
  7857. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7858. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7859. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7860. not_reset_mask2 =
  7861. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7862. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7863. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7864. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7865. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7866. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7867. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7868. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7869. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7870. MISC_REGISTERS_RESET_REG_2_PGLC |
  7871. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7872. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7873. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7874. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7875. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7876. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7877. /*
  7878. * Keep the following blocks in reset:
  7879. * - all xxMACs are handled by the bnx2x_link code.
  7880. */
  7881. stay_reset2 =
  7882. MISC_REGISTERS_RESET_REG_2_XMAC |
  7883. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7884. /* Full reset masks according to the chip */
  7885. reset_mask1 = 0xffffffff;
  7886. if (CHIP_IS_E1(bp))
  7887. reset_mask2 = 0xffff;
  7888. else if (CHIP_IS_E1H(bp))
  7889. reset_mask2 = 0x1ffff;
  7890. else if (CHIP_IS_E2(bp))
  7891. reset_mask2 = 0xfffff;
  7892. else /* CHIP_IS_E3 */
  7893. reset_mask2 = 0x3ffffff;
  7894. /* Don't reset global blocks unless we need to */
  7895. if (!global)
  7896. reset_mask2 &= ~global_bits2;
  7897. /*
  7898. * In case of attention in the QM, we need to reset PXP
  7899. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7900. * because otherwise QM reset would release 'close the gates' shortly
  7901. * before resetting the PXP, then the PSWRQ would send a write
  7902. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7903. * read the payload data from PSWWR, but PSWWR would not
  7904. * respond. The write queue in PGLUE would stuck, dmae commands
  7905. * would not return. Therefore it's important to reset the second
  7906. * reset register (containing the
  7907. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7908. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7909. * bit).
  7910. */
  7911. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7912. reset_mask2 & (~not_reset_mask2));
  7913. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7914. reset_mask1 & (~not_reset_mask1));
  7915. barrier();
  7916. mmiowb();
  7917. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7918. reset_mask2 & (~stay_reset2));
  7919. barrier();
  7920. mmiowb();
  7921. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7922. mmiowb();
  7923. }
  7924. /**
  7925. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7926. * It should get cleared in no more than 1s.
  7927. *
  7928. * @bp: driver handle
  7929. *
  7930. * It should get cleared in no more than 1s. Returns 0 if
  7931. * pending writes bit gets cleared.
  7932. */
  7933. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7934. {
  7935. u32 cnt = 1000;
  7936. u32 pend_bits = 0;
  7937. do {
  7938. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7939. if (pend_bits == 0)
  7940. break;
  7941. usleep_range(1000, 2000);
  7942. } while (cnt-- > 0);
  7943. if (cnt <= 0) {
  7944. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7945. pend_bits);
  7946. return -EBUSY;
  7947. }
  7948. return 0;
  7949. }
  7950. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7951. {
  7952. int cnt = 1000;
  7953. u32 val = 0;
  7954. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7955. u32 tags_63_32 = 0;
  7956. /* Empty the Tetris buffer, wait for 1s */
  7957. do {
  7958. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7959. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7960. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7961. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7962. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7963. if (CHIP_IS_E3(bp))
  7964. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7965. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7966. ((port_is_idle_0 & 0x1) == 0x1) &&
  7967. ((port_is_idle_1 & 0x1) == 0x1) &&
  7968. (pgl_exp_rom2 == 0xffffffff) &&
  7969. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7970. break;
  7971. usleep_range(1000, 2000);
  7972. } while (cnt-- > 0);
  7973. if (cnt <= 0) {
  7974. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7975. 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",
  7976. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7977. pgl_exp_rom2);
  7978. return -EAGAIN;
  7979. }
  7980. barrier();
  7981. /* Close gates #2, #3 and #4 */
  7982. bnx2x_set_234_gates(bp, true);
  7983. /* Poll for IGU VQs for 57712 and newer chips */
  7984. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7985. return -EAGAIN;
  7986. /* TBD: Indicate that "process kill" is in progress to MCP */
  7987. /* Clear "unprepared" bit */
  7988. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7989. barrier();
  7990. /* Make sure all is written to the chip before the reset */
  7991. mmiowb();
  7992. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7993. * PSWHST, GRC and PSWRD Tetris buffer.
  7994. */
  7995. usleep_range(1000, 2000);
  7996. /* Prepare to chip reset: */
  7997. /* MCP */
  7998. if (global)
  7999. bnx2x_reset_mcp_prep(bp, &val);
  8000. /* PXP */
  8001. bnx2x_pxp_prep(bp);
  8002. barrier();
  8003. /* reset the chip */
  8004. bnx2x_process_kill_chip_reset(bp, global);
  8005. barrier();
  8006. /* clear errors in PGB */
  8007. if (!CHIP_IS_E1x(bp))
  8008. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8009. /* Recover after reset: */
  8010. /* MCP */
  8011. if (global && bnx2x_reset_mcp_comp(bp, val))
  8012. return -EAGAIN;
  8013. /* TBD: Add resetting the NO_MCP mode DB here */
  8014. /* Open the gates #2, #3 and #4 */
  8015. bnx2x_set_234_gates(bp, false);
  8016. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8017. * reset state, re-enable attentions. */
  8018. return 0;
  8019. }
  8020. static int bnx2x_leader_reset(struct bnx2x *bp)
  8021. {
  8022. int rc = 0;
  8023. bool global = bnx2x_reset_is_global(bp);
  8024. u32 load_code;
  8025. /* if not going to reset MCP - load "fake" driver to reset HW while
  8026. * driver is owner of the HW
  8027. */
  8028. if (!global && !BP_NOMCP(bp)) {
  8029. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8030. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8031. if (!load_code) {
  8032. BNX2X_ERR("MCP response failure, aborting\n");
  8033. rc = -EAGAIN;
  8034. goto exit_leader_reset;
  8035. }
  8036. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8037. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8038. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8039. rc = -EAGAIN;
  8040. goto exit_leader_reset2;
  8041. }
  8042. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8043. if (!load_code) {
  8044. BNX2X_ERR("MCP response failure, aborting\n");
  8045. rc = -EAGAIN;
  8046. goto exit_leader_reset2;
  8047. }
  8048. }
  8049. /* Try to recover after the failure */
  8050. if (bnx2x_process_kill(bp, global)) {
  8051. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8052. BP_PATH(bp));
  8053. rc = -EAGAIN;
  8054. goto exit_leader_reset2;
  8055. }
  8056. /*
  8057. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8058. * state.
  8059. */
  8060. bnx2x_set_reset_done(bp);
  8061. if (global)
  8062. bnx2x_clear_reset_global(bp);
  8063. exit_leader_reset2:
  8064. /* unload "fake driver" if it was loaded */
  8065. if (!global && !BP_NOMCP(bp)) {
  8066. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8067. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8068. }
  8069. exit_leader_reset:
  8070. bp->is_leader = 0;
  8071. bnx2x_release_leader_lock(bp);
  8072. smp_mb();
  8073. return rc;
  8074. }
  8075. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8076. {
  8077. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8078. /* Disconnect this device */
  8079. netif_device_detach(bp->dev);
  8080. /*
  8081. * Block ifup for all function on this engine until "process kill"
  8082. * or power cycle.
  8083. */
  8084. bnx2x_set_reset_in_progress(bp);
  8085. /* Shut down the power */
  8086. bnx2x_set_power_state(bp, PCI_D3hot);
  8087. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8088. smp_mb();
  8089. }
  8090. /*
  8091. * Assumption: runs under rtnl lock. This together with the fact
  8092. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8093. * will never be called when netif_running(bp->dev) is false.
  8094. */
  8095. static void bnx2x_parity_recover(struct bnx2x *bp)
  8096. {
  8097. bool global = false;
  8098. u32 error_recovered, error_unrecovered;
  8099. bool is_parity;
  8100. DP(NETIF_MSG_HW, "Handling parity\n");
  8101. while (1) {
  8102. switch (bp->recovery_state) {
  8103. case BNX2X_RECOVERY_INIT:
  8104. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8105. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8106. WARN_ON(!is_parity);
  8107. /* Try to get a LEADER_LOCK HW lock */
  8108. if (bnx2x_trylock_leader_lock(bp)) {
  8109. bnx2x_set_reset_in_progress(bp);
  8110. /*
  8111. * Check if there is a global attention and if
  8112. * there was a global attention, set the global
  8113. * reset bit.
  8114. */
  8115. if (global)
  8116. bnx2x_set_reset_global(bp);
  8117. bp->is_leader = 1;
  8118. }
  8119. /* Stop the driver */
  8120. /* If interface has been removed - break */
  8121. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8122. return;
  8123. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8124. /* Ensure "is_leader", MCP command sequence and
  8125. * "recovery_state" update values are seen on other
  8126. * CPUs.
  8127. */
  8128. smp_mb();
  8129. break;
  8130. case BNX2X_RECOVERY_WAIT:
  8131. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8132. if (bp->is_leader) {
  8133. int other_engine = BP_PATH(bp) ? 0 : 1;
  8134. bool other_load_status =
  8135. bnx2x_get_load_status(bp, other_engine);
  8136. bool load_status =
  8137. bnx2x_get_load_status(bp, BP_PATH(bp));
  8138. global = bnx2x_reset_is_global(bp);
  8139. /*
  8140. * In case of a parity in a global block, let
  8141. * the first leader that performs a
  8142. * leader_reset() reset the global blocks in
  8143. * order to clear global attentions. Otherwise
  8144. * the gates will remain closed for that
  8145. * engine.
  8146. */
  8147. if (load_status ||
  8148. (global && other_load_status)) {
  8149. /* Wait until all other functions get
  8150. * down.
  8151. */
  8152. schedule_delayed_work(&bp->sp_rtnl_task,
  8153. HZ/10);
  8154. return;
  8155. } else {
  8156. /* If all other functions got down -
  8157. * try to bring the chip back to
  8158. * normal. In any case it's an exit
  8159. * point for a leader.
  8160. */
  8161. if (bnx2x_leader_reset(bp)) {
  8162. bnx2x_recovery_failed(bp);
  8163. return;
  8164. }
  8165. /* If we are here, means that the
  8166. * leader has succeeded and doesn't
  8167. * want to be a leader any more. Try
  8168. * to continue as a none-leader.
  8169. */
  8170. break;
  8171. }
  8172. } else { /* non-leader */
  8173. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8174. /* Try to get a LEADER_LOCK HW lock as
  8175. * long as a former leader may have
  8176. * been unloaded by the user or
  8177. * released a leadership by another
  8178. * reason.
  8179. */
  8180. if (bnx2x_trylock_leader_lock(bp)) {
  8181. /* I'm a leader now! Restart a
  8182. * switch case.
  8183. */
  8184. bp->is_leader = 1;
  8185. break;
  8186. }
  8187. schedule_delayed_work(&bp->sp_rtnl_task,
  8188. HZ/10);
  8189. return;
  8190. } else {
  8191. /*
  8192. * If there was a global attention, wait
  8193. * for it to be cleared.
  8194. */
  8195. if (bnx2x_reset_is_global(bp)) {
  8196. schedule_delayed_work(
  8197. &bp->sp_rtnl_task,
  8198. HZ/10);
  8199. return;
  8200. }
  8201. error_recovered =
  8202. bp->eth_stats.recoverable_error;
  8203. error_unrecovered =
  8204. bp->eth_stats.unrecoverable_error;
  8205. bp->recovery_state =
  8206. BNX2X_RECOVERY_NIC_LOADING;
  8207. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8208. error_unrecovered++;
  8209. netdev_err(bp->dev,
  8210. "Recovery failed. Power cycle needed\n");
  8211. /* Disconnect this device */
  8212. netif_device_detach(bp->dev);
  8213. /* Shut down the power */
  8214. bnx2x_set_power_state(
  8215. bp, PCI_D3hot);
  8216. smp_mb();
  8217. } else {
  8218. bp->recovery_state =
  8219. BNX2X_RECOVERY_DONE;
  8220. error_recovered++;
  8221. smp_mb();
  8222. }
  8223. bp->eth_stats.recoverable_error =
  8224. error_recovered;
  8225. bp->eth_stats.unrecoverable_error =
  8226. error_unrecovered;
  8227. return;
  8228. }
  8229. }
  8230. default:
  8231. return;
  8232. }
  8233. }
  8234. }
  8235. static int bnx2x_close(struct net_device *dev);
  8236. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8237. * scheduled on a general queue in order to prevent a dead lock.
  8238. */
  8239. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8240. {
  8241. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8242. rtnl_lock();
  8243. if (!netif_running(bp->dev)) {
  8244. rtnl_unlock();
  8245. return;
  8246. }
  8247. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8248. #ifdef BNX2X_STOP_ON_ERROR
  8249. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8250. "you will need to reboot when done\n");
  8251. goto sp_rtnl_not_reset;
  8252. #endif
  8253. /*
  8254. * Clear all pending SP commands as we are going to reset the
  8255. * function anyway.
  8256. */
  8257. bp->sp_rtnl_state = 0;
  8258. smp_mb();
  8259. bnx2x_parity_recover(bp);
  8260. rtnl_unlock();
  8261. return;
  8262. }
  8263. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8264. #ifdef BNX2X_STOP_ON_ERROR
  8265. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8266. "you will need to reboot when done\n");
  8267. goto sp_rtnl_not_reset;
  8268. #endif
  8269. /*
  8270. * Clear all pending SP commands as we are going to reset the
  8271. * function anyway.
  8272. */
  8273. bp->sp_rtnl_state = 0;
  8274. smp_mb();
  8275. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8276. bnx2x_nic_load(bp, LOAD_NORMAL);
  8277. rtnl_unlock();
  8278. return;
  8279. }
  8280. #ifdef BNX2X_STOP_ON_ERROR
  8281. sp_rtnl_not_reset:
  8282. #endif
  8283. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8284. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8285. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8286. bnx2x_after_function_update(bp);
  8287. /*
  8288. * in case of fan failure we need to reset id if the "stop on error"
  8289. * debug flag is set, since we trying to prevent permanent overheating
  8290. * damage
  8291. */
  8292. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8293. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8294. netif_device_detach(bp->dev);
  8295. bnx2x_close(bp->dev);
  8296. rtnl_unlock();
  8297. return;
  8298. }
  8299. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8300. DP(BNX2X_MSG_SP,
  8301. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8302. bnx2x_vfpf_set_mcast(bp->dev);
  8303. }
  8304. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8305. &bp->sp_rtnl_state)){
  8306. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8307. bnx2x_tx_disable(bp);
  8308. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8309. }
  8310. }
  8311. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8312. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8313. bnx2x_set_rx_mode_inner(bp);
  8314. }
  8315. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8316. &bp->sp_rtnl_state))
  8317. bnx2x_pf_set_vfs_vlan(bp);
  8318. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8319. bnx2x_dcbx_stop_hw_tx(bp);
  8320. bnx2x_dcbx_resume_hw_tx(bp);
  8321. }
  8322. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8323. &bp->sp_rtnl_state))
  8324. bnx2x_update_mng_version(bp);
  8325. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8326. * can be called from other contexts as well)
  8327. */
  8328. rtnl_unlock();
  8329. /* enable SR-IOV if applicable */
  8330. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8331. &bp->sp_rtnl_state)) {
  8332. bnx2x_disable_sriov(bp);
  8333. bnx2x_enable_sriov(bp);
  8334. }
  8335. }
  8336. static void bnx2x_period_task(struct work_struct *work)
  8337. {
  8338. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8339. if (!netif_running(bp->dev))
  8340. goto period_task_exit;
  8341. if (CHIP_REV_IS_SLOW(bp)) {
  8342. BNX2X_ERR("period task called on emulation, ignoring\n");
  8343. goto period_task_exit;
  8344. }
  8345. bnx2x_acquire_phy_lock(bp);
  8346. /*
  8347. * The barrier is needed to ensure the ordering between the writing to
  8348. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8349. * the reading here.
  8350. */
  8351. smp_mb();
  8352. if (bp->port.pmf) {
  8353. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8354. /* Re-queue task in 1 sec */
  8355. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8356. }
  8357. bnx2x_release_phy_lock(bp);
  8358. period_task_exit:
  8359. return;
  8360. }
  8361. /*
  8362. * Init service functions
  8363. */
  8364. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8365. {
  8366. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8367. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8368. return base + (BP_ABS_FUNC(bp)) * stride;
  8369. }
  8370. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8371. struct bnx2x_mac_vals *vals)
  8372. {
  8373. u32 val, base_addr, offset, mask, reset_reg;
  8374. bool mac_stopped = false;
  8375. u8 port = BP_PORT(bp);
  8376. /* reset addresses as they also mark which values were changed */
  8377. vals->bmac_addr = 0;
  8378. vals->umac_addr = 0;
  8379. vals->xmac_addr = 0;
  8380. vals->emac_addr = 0;
  8381. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8382. if (!CHIP_IS_E3(bp)) {
  8383. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8384. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8385. if ((mask & reset_reg) && val) {
  8386. u32 wb_data[2];
  8387. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8388. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8389. : NIG_REG_INGRESS_BMAC0_MEM;
  8390. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8391. : BIGMAC_REGISTER_BMAC_CONTROL;
  8392. /*
  8393. * use rd/wr since we cannot use dmae. This is safe
  8394. * since MCP won't access the bus due to the request
  8395. * to unload, and no function on the path can be
  8396. * loaded at this time.
  8397. */
  8398. wb_data[0] = REG_RD(bp, base_addr + offset);
  8399. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8400. vals->bmac_addr = base_addr + offset;
  8401. vals->bmac_val[0] = wb_data[0];
  8402. vals->bmac_val[1] = wb_data[1];
  8403. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8404. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8405. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8406. }
  8407. BNX2X_DEV_INFO("Disable emac Rx\n");
  8408. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8409. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8410. REG_WR(bp, vals->emac_addr, 0);
  8411. mac_stopped = true;
  8412. } else {
  8413. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8414. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8415. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8416. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8417. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8418. val & ~(1 << 1));
  8419. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8420. val | (1 << 1));
  8421. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8422. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8423. REG_WR(bp, vals->xmac_addr, 0);
  8424. mac_stopped = true;
  8425. }
  8426. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8427. if (mask & reset_reg) {
  8428. BNX2X_DEV_INFO("Disable umac Rx\n");
  8429. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8430. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8431. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8432. REG_WR(bp, vals->umac_addr, 0);
  8433. mac_stopped = true;
  8434. }
  8435. }
  8436. if (mac_stopped)
  8437. msleep(20);
  8438. }
  8439. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8440. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8441. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8442. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8443. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8444. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8445. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8446. #define BNX2X_PREV_UNDI_MF_PORT(p) (BAR_TSTRORM_INTMEM + 0x150c + ((p) << 4))
  8447. #define BNX2X_PREV_UNDI_MF_FUNC(f) (BAR_TSTRORM_INTMEM + 0x184c + ((f) << 4))
  8448. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8449. {
  8450. /* UNDI marks its presence in DORQ -
  8451. * it initializes CID offset for normal bell to 0x7
  8452. */
  8453. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8454. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8455. return false;
  8456. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8457. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8458. return true;
  8459. }
  8460. return false;
  8461. }
  8462. static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
  8463. {
  8464. u8 major, minor, version;
  8465. u32 fw;
  8466. /* Must check that FW is loaded */
  8467. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8468. MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
  8469. BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
  8470. return false;
  8471. }
  8472. /* Read Currently loaded FW version */
  8473. fw = REG_RD(bp, XSEM_REG_PRAM);
  8474. major = fw & 0xff;
  8475. minor = (fw >> 0x8) & 0xff;
  8476. version = (fw >> 0x10) & 0xff;
  8477. BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
  8478. fw, major, minor, version);
  8479. if (major > BCM_5710_UNDI_FW_MF_MAJOR)
  8480. return true;
  8481. if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
  8482. (minor > BCM_5710_UNDI_FW_MF_MINOR))
  8483. return true;
  8484. if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
  8485. (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
  8486. (version >= BCM_5710_UNDI_FW_MF_VERS))
  8487. return true;
  8488. return false;
  8489. }
  8490. static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
  8491. {
  8492. int i;
  8493. /* Due to legacy (FW) code, the first function on each engine has a
  8494. * different offset macro from the rest of the functions.
  8495. * Setting this for all 8 functions is harmless regardless of whether
  8496. * this is actually a multi-function device.
  8497. */
  8498. for (i = 0; i < 2; i++)
  8499. REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
  8500. for (i = 2; i < 8; i++)
  8501. REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
  8502. BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
  8503. }
  8504. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8505. {
  8506. u16 rcq, bd;
  8507. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8508. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8509. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8510. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8511. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8512. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8513. port, bd, rcq);
  8514. }
  8515. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8516. {
  8517. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8518. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8519. if (!rc) {
  8520. BNX2X_ERR("MCP response failure, aborting\n");
  8521. return -EBUSY;
  8522. }
  8523. return 0;
  8524. }
  8525. static struct bnx2x_prev_path_list *
  8526. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8527. {
  8528. struct bnx2x_prev_path_list *tmp_list;
  8529. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8530. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8531. bp->pdev->bus->number == tmp_list->bus &&
  8532. BP_PATH(bp) == tmp_list->path)
  8533. return tmp_list;
  8534. return NULL;
  8535. }
  8536. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8537. {
  8538. struct bnx2x_prev_path_list *tmp_list;
  8539. int rc;
  8540. rc = down_interruptible(&bnx2x_prev_sem);
  8541. if (rc) {
  8542. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8543. return rc;
  8544. }
  8545. tmp_list = bnx2x_prev_path_get_entry(bp);
  8546. if (tmp_list) {
  8547. tmp_list->aer = 1;
  8548. rc = 0;
  8549. } else {
  8550. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8551. BP_PATH(bp));
  8552. }
  8553. up(&bnx2x_prev_sem);
  8554. return rc;
  8555. }
  8556. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8557. {
  8558. struct bnx2x_prev_path_list *tmp_list;
  8559. bool rc = false;
  8560. if (down_trylock(&bnx2x_prev_sem))
  8561. return false;
  8562. tmp_list = bnx2x_prev_path_get_entry(bp);
  8563. if (tmp_list) {
  8564. if (tmp_list->aer) {
  8565. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8566. BP_PATH(bp));
  8567. } else {
  8568. rc = true;
  8569. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8570. BP_PATH(bp));
  8571. }
  8572. }
  8573. up(&bnx2x_prev_sem);
  8574. return rc;
  8575. }
  8576. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8577. {
  8578. struct bnx2x_prev_path_list *entry;
  8579. bool val;
  8580. down(&bnx2x_prev_sem);
  8581. entry = bnx2x_prev_path_get_entry(bp);
  8582. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8583. up(&bnx2x_prev_sem);
  8584. return val;
  8585. }
  8586. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8587. {
  8588. struct bnx2x_prev_path_list *tmp_list;
  8589. int rc;
  8590. rc = down_interruptible(&bnx2x_prev_sem);
  8591. if (rc) {
  8592. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8593. return rc;
  8594. }
  8595. /* Check whether the entry for this path already exists */
  8596. tmp_list = bnx2x_prev_path_get_entry(bp);
  8597. if (tmp_list) {
  8598. if (!tmp_list->aer) {
  8599. BNX2X_ERR("Re-Marking the path.\n");
  8600. } else {
  8601. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8602. BP_PATH(bp));
  8603. tmp_list->aer = 0;
  8604. }
  8605. up(&bnx2x_prev_sem);
  8606. return 0;
  8607. }
  8608. up(&bnx2x_prev_sem);
  8609. /* Create an entry for this path and add it */
  8610. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8611. if (!tmp_list) {
  8612. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8613. return -ENOMEM;
  8614. }
  8615. tmp_list->bus = bp->pdev->bus->number;
  8616. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8617. tmp_list->path = BP_PATH(bp);
  8618. tmp_list->aer = 0;
  8619. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8620. rc = down_interruptible(&bnx2x_prev_sem);
  8621. if (rc) {
  8622. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8623. kfree(tmp_list);
  8624. } else {
  8625. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8626. BP_PATH(bp));
  8627. list_add(&tmp_list->list, &bnx2x_prev_list);
  8628. up(&bnx2x_prev_sem);
  8629. }
  8630. return rc;
  8631. }
  8632. static int bnx2x_do_flr(struct bnx2x *bp)
  8633. {
  8634. struct pci_dev *dev = bp->pdev;
  8635. if (CHIP_IS_E1x(bp)) {
  8636. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8637. return -EINVAL;
  8638. }
  8639. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8640. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8641. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8642. bp->common.bc_ver);
  8643. return -EINVAL;
  8644. }
  8645. if (!pci_wait_for_pending_transaction(dev))
  8646. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8647. BNX2X_DEV_INFO("Initiating FLR\n");
  8648. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8649. return 0;
  8650. }
  8651. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8652. {
  8653. int rc;
  8654. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8655. /* Test if previous unload process was already finished for this path */
  8656. if (bnx2x_prev_is_path_marked(bp))
  8657. return bnx2x_prev_mcp_done(bp);
  8658. BNX2X_DEV_INFO("Path is unmarked\n");
  8659. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8660. if (bnx2x_prev_is_after_undi(bp))
  8661. goto out;
  8662. /* If function has FLR capabilities, and existing FW version matches
  8663. * the one required, then FLR will be sufficient to clean any residue
  8664. * left by previous driver
  8665. */
  8666. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8667. if (!rc) {
  8668. /* fw version is good */
  8669. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8670. rc = bnx2x_do_flr(bp);
  8671. }
  8672. if (!rc) {
  8673. /* FLR was performed */
  8674. BNX2X_DEV_INFO("FLR successful\n");
  8675. return 0;
  8676. }
  8677. BNX2X_DEV_INFO("Could not FLR\n");
  8678. out:
  8679. /* Close the MCP request, return failure*/
  8680. rc = bnx2x_prev_mcp_done(bp);
  8681. if (!rc)
  8682. rc = BNX2X_PREV_WAIT_NEEDED;
  8683. return rc;
  8684. }
  8685. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8686. {
  8687. u32 reset_reg, tmp_reg = 0, rc;
  8688. bool prev_undi = false;
  8689. struct bnx2x_mac_vals mac_vals;
  8690. /* It is possible a previous function received 'common' answer,
  8691. * but hasn't loaded yet, therefore creating a scenario of
  8692. * multiple functions receiving 'common' on the same path.
  8693. */
  8694. BNX2X_DEV_INFO("Common unload Flow\n");
  8695. memset(&mac_vals, 0, sizeof(mac_vals));
  8696. if (bnx2x_prev_is_path_marked(bp))
  8697. return bnx2x_prev_mcp_done(bp);
  8698. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8699. /* Reset should be performed after BRB is emptied */
  8700. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8701. u32 timer_count = 1000;
  8702. bool need_write = true;
  8703. /* Close the MAC Rx to prevent BRB from filling up */
  8704. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8705. /* close LLH filters towards the BRB */
  8706. bnx2x_set_rx_filter(&bp->link_params, 0);
  8707. /* Check if the UNDI driver was previously loaded */
  8708. if (bnx2x_prev_is_after_undi(bp)) {
  8709. prev_undi = true;
  8710. /* clear the UNDI indication */
  8711. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8712. /* clear possible idle check errors */
  8713. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8714. }
  8715. if (!CHIP_IS_E1x(bp))
  8716. /* block FW from writing to host */
  8717. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8718. /* wait until BRB is empty */
  8719. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8720. while (timer_count) {
  8721. u32 prev_brb = tmp_reg;
  8722. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8723. if (!tmp_reg)
  8724. break;
  8725. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8726. /* reset timer as long as BRB actually gets emptied */
  8727. if (prev_brb > tmp_reg)
  8728. timer_count = 1000;
  8729. else
  8730. timer_count--;
  8731. /* New UNDI FW supports MF and contains better
  8732. * cleaning methods - might be redundant but harmless.
  8733. */
  8734. if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
  8735. if (need_write) {
  8736. bnx2x_prev_unload_undi_mf(bp);
  8737. need_write = false;
  8738. }
  8739. } else if (prev_undi) {
  8740. /* If UNDI resides in memory,
  8741. * manually increment it
  8742. */
  8743. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8744. }
  8745. udelay(10);
  8746. }
  8747. if (!timer_count)
  8748. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8749. }
  8750. /* No packets are in the pipeline, path is ready for reset */
  8751. bnx2x_reset_common(bp);
  8752. if (mac_vals.xmac_addr)
  8753. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8754. if (mac_vals.umac_addr)
  8755. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8756. if (mac_vals.emac_addr)
  8757. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8758. if (mac_vals.bmac_addr) {
  8759. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8760. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8761. }
  8762. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8763. if (rc) {
  8764. bnx2x_prev_mcp_done(bp);
  8765. return rc;
  8766. }
  8767. return bnx2x_prev_mcp_done(bp);
  8768. }
  8769. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8770. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8771. * the addresses of the transaction, resulting in was-error bit set in the pci
  8772. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8773. * to clear the interrupt which detected this from the pglueb and the was done
  8774. * bit
  8775. */
  8776. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8777. {
  8778. if (!CHIP_IS_E1x(bp)) {
  8779. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8780. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8781. DP(BNX2X_MSG_SP,
  8782. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8783. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8784. 1 << BP_FUNC(bp));
  8785. }
  8786. }
  8787. }
  8788. static int bnx2x_prev_unload(struct bnx2x *bp)
  8789. {
  8790. int time_counter = 10;
  8791. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8792. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8793. /* clear hw from errors which may have resulted from an interrupted
  8794. * dmae transaction.
  8795. */
  8796. bnx2x_prev_interrupted_dmae(bp);
  8797. /* Release previously held locks */
  8798. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8799. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8800. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8801. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8802. if (hw_lock_val) {
  8803. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8804. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8805. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8806. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8807. }
  8808. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8809. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8810. } else
  8811. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8812. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8813. BNX2X_DEV_INFO("Release previously held alr\n");
  8814. bnx2x_release_alr(bp);
  8815. }
  8816. do {
  8817. int aer = 0;
  8818. /* Lock MCP using an unload request */
  8819. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8820. if (!fw) {
  8821. BNX2X_ERR("MCP response failure, aborting\n");
  8822. rc = -EBUSY;
  8823. break;
  8824. }
  8825. rc = down_interruptible(&bnx2x_prev_sem);
  8826. if (rc) {
  8827. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8828. rc);
  8829. } else {
  8830. /* If Path is marked by EEH, ignore unload status */
  8831. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8832. bnx2x_prev_path_get_entry(bp)->aer);
  8833. up(&bnx2x_prev_sem);
  8834. }
  8835. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8836. rc = bnx2x_prev_unload_common(bp);
  8837. break;
  8838. }
  8839. /* non-common reply from MCP might require looping */
  8840. rc = bnx2x_prev_unload_uncommon(bp);
  8841. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8842. break;
  8843. msleep(20);
  8844. } while (--time_counter);
  8845. if (!time_counter || rc) {
  8846. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8847. rc = -EPROBE_DEFER;
  8848. }
  8849. /* Mark function if its port was used to boot from SAN */
  8850. if (bnx2x_port_after_undi(bp))
  8851. bp->link_params.feature_config_flags |=
  8852. FEATURE_CONFIG_BOOT_FROM_SAN;
  8853. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8854. return rc;
  8855. }
  8856. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8857. {
  8858. u32 val, val2, val3, val4, id, boot_mode;
  8859. u16 pmc;
  8860. /* Get the chip revision id and number. */
  8861. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8862. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8863. id = ((val & 0xffff) << 16);
  8864. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8865. id |= ((val & 0xf) << 12);
  8866. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8867. * the configuration space (so we need to reg_rd)
  8868. */
  8869. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8870. id |= (((val >> 24) & 0xf) << 4);
  8871. val = REG_RD(bp, MISC_REG_BOND_ID);
  8872. id |= (val & 0xf);
  8873. bp->common.chip_id = id;
  8874. /* force 57811 according to MISC register */
  8875. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8876. if (CHIP_IS_57810(bp))
  8877. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8878. (bp->common.chip_id & 0x0000FFFF);
  8879. else if (CHIP_IS_57810_MF(bp))
  8880. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8881. (bp->common.chip_id & 0x0000FFFF);
  8882. bp->common.chip_id |= 0x1;
  8883. }
  8884. /* Set doorbell size */
  8885. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8886. if (!CHIP_IS_E1x(bp)) {
  8887. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8888. if ((val & 1) == 0)
  8889. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8890. else
  8891. val = (val >> 1) & 1;
  8892. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8893. "2_PORT_MODE");
  8894. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8895. CHIP_2_PORT_MODE;
  8896. if (CHIP_MODE_IS_4_PORT(bp))
  8897. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8898. else
  8899. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8900. } else {
  8901. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8902. bp->pfid = bp->pf_num; /* 0..7 */
  8903. }
  8904. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8905. bp->link_params.chip_id = bp->common.chip_id;
  8906. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8907. val = (REG_RD(bp, 0x2874) & 0x55);
  8908. if ((bp->common.chip_id & 0x1) ||
  8909. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8910. bp->flags |= ONE_PORT_FLAG;
  8911. BNX2X_DEV_INFO("single port device\n");
  8912. }
  8913. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8914. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8915. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8916. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8917. bp->common.flash_size, bp->common.flash_size);
  8918. bnx2x_init_shmem(bp);
  8919. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8920. MISC_REG_GENERIC_CR_1 :
  8921. MISC_REG_GENERIC_CR_0));
  8922. bp->link_params.shmem_base = bp->common.shmem_base;
  8923. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8924. if (SHMEM2_RD(bp, size) >
  8925. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8926. bp->link_params.lfa_base =
  8927. REG_RD(bp, bp->common.shmem2_base +
  8928. (u32)offsetof(struct shmem2_region,
  8929. lfa_host_addr[BP_PORT(bp)]));
  8930. else
  8931. bp->link_params.lfa_base = 0;
  8932. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8933. bp->common.shmem_base, bp->common.shmem2_base);
  8934. if (!bp->common.shmem_base) {
  8935. BNX2X_DEV_INFO("MCP not active\n");
  8936. bp->flags |= NO_MCP_FLAG;
  8937. return;
  8938. }
  8939. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8940. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8941. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8942. SHARED_HW_CFG_LED_MODE_MASK) >>
  8943. SHARED_HW_CFG_LED_MODE_SHIFT);
  8944. bp->link_params.feature_config_flags = 0;
  8945. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8946. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8947. bp->link_params.feature_config_flags |=
  8948. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8949. else
  8950. bp->link_params.feature_config_flags &=
  8951. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8952. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8953. bp->common.bc_ver = val;
  8954. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8955. if (val < BNX2X_BC_VER) {
  8956. /* for now only warn
  8957. * later we might need to enforce this */
  8958. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8959. BNX2X_BC_VER, val);
  8960. }
  8961. bp->link_params.feature_config_flags |=
  8962. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8963. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8964. bp->link_params.feature_config_flags |=
  8965. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8966. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8967. bp->link_params.feature_config_flags |=
  8968. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8969. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8970. bp->link_params.feature_config_flags |=
  8971. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8972. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8973. bp->link_params.feature_config_flags |=
  8974. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8975. FEATURE_CONFIG_MT_SUPPORT : 0;
  8976. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8977. BC_SUPPORTS_PFC_STATS : 0;
  8978. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8979. BC_SUPPORTS_FCOE_FEATURES : 0;
  8980. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8981. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8982. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8983. BC_SUPPORTS_RMMOD_CMD : 0;
  8984. boot_mode = SHMEM_RD(bp,
  8985. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8986. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8987. switch (boot_mode) {
  8988. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8989. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8990. break;
  8991. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8992. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8993. break;
  8994. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8995. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8996. break;
  8997. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8998. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8999. break;
  9000. }
  9001. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9002. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9003. BNX2X_DEV_INFO("%sWoL capable\n",
  9004. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9005. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9006. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9007. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9008. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9009. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9010. val, val2, val3, val4);
  9011. }
  9012. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9013. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9014. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9015. {
  9016. int pfid = BP_FUNC(bp);
  9017. int igu_sb_id;
  9018. u32 val;
  9019. u8 fid, igu_sb_cnt = 0;
  9020. bp->igu_base_sb = 0xff;
  9021. if (CHIP_INT_MODE_IS_BC(bp)) {
  9022. int vn = BP_VN(bp);
  9023. igu_sb_cnt = bp->igu_sb_cnt;
  9024. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9025. FP_SB_MAX_E1x;
  9026. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9027. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9028. return 0;
  9029. }
  9030. /* IGU in normal mode - read CAM */
  9031. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9032. igu_sb_id++) {
  9033. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9034. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9035. continue;
  9036. fid = IGU_FID(val);
  9037. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9038. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9039. continue;
  9040. if (IGU_VEC(val) == 0)
  9041. /* default status block */
  9042. bp->igu_dsb_id = igu_sb_id;
  9043. else {
  9044. if (bp->igu_base_sb == 0xff)
  9045. bp->igu_base_sb = igu_sb_id;
  9046. igu_sb_cnt++;
  9047. }
  9048. }
  9049. }
  9050. #ifdef CONFIG_PCI_MSI
  9051. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9052. * optional that number of CAM entries will not be equal to the value
  9053. * advertised in PCI.
  9054. * Driver should use the minimal value of both as the actual status
  9055. * block count
  9056. */
  9057. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9058. #endif
  9059. if (igu_sb_cnt == 0) {
  9060. BNX2X_ERR("CAM configuration error\n");
  9061. return -EINVAL;
  9062. }
  9063. return 0;
  9064. }
  9065. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9066. {
  9067. int cfg_size = 0, idx, port = BP_PORT(bp);
  9068. /* Aggregation of supported attributes of all external phys */
  9069. bp->port.supported[0] = 0;
  9070. bp->port.supported[1] = 0;
  9071. switch (bp->link_params.num_phys) {
  9072. case 1:
  9073. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9074. cfg_size = 1;
  9075. break;
  9076. case 2:
  9077. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9078. cfg_size = 1;
  9079. break;
  9080. case 3:
  9081. if (bp->link_params.multi_phy_config &
  9082. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9083. bp->port.supported[1] =
  9084. bp->link_params.phy[EXT_PHY1].supported;
  9085. bp->port.supported[0] =
  9086. bp->link_params.phy[EXT_PHY2].supported;
  9087. } else {
  9088. bp->port.supported[0] =
  9089. bp->link_params.phy[EXT_PHY1].supported;
  9090. bp->port.supported[1] =
  9091. bp->link_params.phy[EXT_PHY2].supported;
  9092. }
  9093. cfg_size = 2;
  9094. break;
  9095. }
  9096. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9097. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9098. SHMEM_RD(bp,
  9099. dev_info.port_hw_config[port].external_phy_config),
  9100. SHMEM_RD(bp,
  9101. dev_info.port_hw_config[port].external_phy_config2));
  9102. return;
  9103. }
  9104. if (CHIP_IS_E3(bp))
  9105. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9106. else {
  9107. switch (switch_cfg) {
  9108. case SWITCH_CFG_1G:
  9109. bp->port.phy_addr = REG_RD(
  9110. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9111. break;
  9112. case SWITCH_CFG_10G:
  9113. bp->port.phy_addr = REG_RD(
  9114. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9115. break;
  9116. default:
  9117. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9118. bp->port.link_config[0]);
  9119. return;
  9120. }
  9121. }
  9122. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9123. /* mask what we support according to speed_cap_mask per configuration */
  9124. for (idx = 0; idx < cfg_size; idx++) {
  9125. if (!(bp->link_params.speed_cap_mask[idx] &
  9126. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9127. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9128. if (!(bp->link_params.speed_cap_mask[idx] &
  9129. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9130. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9131. if (!(bp->link_params.speed_cap_mask[idx] &
  9132. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9133. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9134. if (!(bp->link_params.speed_cap_mask[idx] &
  9135. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9136. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9137. if (!(bp->link_params.speed_cap_mask[idx] &
  9138. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9139. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9140. SUPPORTED_1000baseT_Full);
  9141. if (!(bp->link_params.speed_cap_mask[idx] &
  9142. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9143. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9144. if (!(bp->link_params.speed_cap_mask[idx] &
  9145. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9146. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9147. if (!(bp->link_params.speed_cap_mask[idx] &
  9148. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9149. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9150. }
  9151. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9152. bp->port.supported[1]);
  9153. }
  9154. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9155. {
  9156. u32 link_config, idx, cfg_size = 0;
  9157. bp->port.advertising[0] = 0;
  9158. bp->port.advertising[1] = 0;
  9159. switch (bp->link_params.num_phys) {
  9160. case 1:
  9161. case 2:
  9162. cfg_size = 1;
  9163. break;
  9164. case 3:
  9165. cfg_size = 2;
  9166. break;
  9167. }
  9168. for (idx = 0; idx < cfg_size; idx++) {
  9169. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9170. link_config = bp->port.link_config[idx];
  9171. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9172. case PORT_FEATURE_LINK_SPEED_AUTO:
  9173. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9174. bp->link_params.req_line_speed[idx] =
  9175. SPEED_AUTO_NEG;
  9176. bp->port.advertising[idx] |=
  9177. bp->port.supported[idx];
  9178. if (bp->link_params.phy[EXT_PHY1].type ==
  9179. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9180. bp->port.advertising[idx] |=
  9181. (SUPPORTED_100baseT_Half |
  9182. SUPPORTED_100baseT_Full);
  9183. } else {
  9184. /* force 10G, no AN */
  9185. bp->link_params.req_line_speed[idx] =
  9186. SPEED_10000;
  9187. bp->port.advertising[idx] |=
  9188. (ADVERTISED_10000baseT_Full |
  9189. ADVERTISED_FIBRE);
  9190. continue;
  9191. }
  9192. break;
  9193. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9194. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9195. bp->link_params.req_line_speed[idx] =
  9196. SPEED_10;
  9197. bp->port.advertising[idx] |=
  9198. (ADVERTISED_10baseT_Full |
  9199. ADVERTISED_TP);
  9200. } else {
  9201. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9202. link_config,
  9203. bp->link_params.speed_cap_mask[idx]);
  9204. return;
  9205. }
  9206. break;
  9207. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9208. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9209. bp->link_params.req_line_speed[idx] =
  9210. SPEED_10;
  9211. bp->link_params.req_duplex[idx] =
  9212. DUPLEX_HALF;
  9213. bp->port.advertising[idx] |=
  9214. (ADVERTISED_10baseT_Half |
  9215. ADVERTISED_TP);
  9216. } else {
  9217. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9218. link_config,
  9219. bp->link_params.speed_cap_mask[idx]);
  9220. return;
  9221. }
  9222. break;
  9223. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9224. if (bp->port.supported[idx] &
  9225. SUPPORTED_100baseT_Full) {
  9226. bp->link_params.req_line_speed[idx] =
  9227. SPEED_100;
  9228. bp->port.advertising[idx] |=
  9229. (ADVERTISED_100baseT_Full |
  9230. ADVERTISED_TP);
  9231. } else {
  9232. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9233. link_config,
  9234. bp->link_params.speed_cap_mask[idx]);
  9235. return;
  9236. }
  9237. break;
  9238. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9239. if (bp->port.supported[idx] &
  9240. SUPPORTED_100baseT_Half) {
  9241. bp->link_params.req_line_speed[idx] =
  9242. SPEED_100;
  9243. bp->link_params.req_duplex[idx] =
  9244. DUPLEX_HALF;
  9245. bp->port.advertising[idx] |=
  9246. (ADVERTISED_100baseT_Half |
  9247. ADVERTISED_TP);
  9248. } else {
  9249. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9250. link_config,
  9251. bp->link_params.speed_cap_mask[idx]);
  9252. return;
  9253. }
  9254. break;
  9255. case PORT_FEATURE_LINK_SPEED_1G:
  9256. if (bp->port.supported[idx] &
  9257. SUPPORTED_1000baseT_Full) {
  9258. bp->link_params.req_line_speed[idx] =
  9259. SPEED_1000;
  9260. bp->port.advertising[idx] |=
  9261. (ADVERTISED_1000baseT_Full |
  9262. ADVERTISED_TP);
  9263. } else {
  9264. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9265. link_config,
  9266. bp->link_params.speed_cap_mask[idx]);
  9267. return;
  9268. }
  9269. break;
  9270. case PORT_FEATURE_LINK_SPEED_2_5G:
  9271. if (bp->port.supported[idx] &
  9272. SUPPORTED_2500baseX_Full) {
  9273. bp->link_params.req_line_speed[idx] =
  9274. SPEED_2500;
  9275. bp->port.advertising[idx] |=
  9276. (ADVERTISED_2500baseX_Full |
  9277. ADVERTISED_TP);
  9278. } else {
  9279. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9280. link_config,
  9281. bp->link_params.speed_cap_mask[idx]);
  9282. return;
  9283. }
  9284. break;
  9285. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9286. if (bp->port.supported[idx] &
  9287. SUPPORTED_10000baseT_Full) {
  9288. bp->link_params.req_line_speed[idx] =
  9289. SPEED_10000;
  9290. bp->port.advertising[idx] |=
  9291. (ADVERTISED_10000baseT_Full |
  9292. ADVERTISED_FIBRE);
  9293. } else {
  9294. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9295. link_config,
  9296. bp->link_params.speed_cap_mask[idx]);
  9297. return;
  9298. }
  9299. break;
  9300. case PORT_FEATURE_LINK_SPEED_20G:
  9301. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9302. break;
  9303. default:
  9304. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9305. link_config);
  9306. bp->link_params.req_line_speed[idx] =
  9307. SPEED_AUTO_NEG;
  9308. bp->port.advertising[idx] =
  9309. bp->port.supported[idx];
  9310. break;
  9311. }
  9312. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9313. PORT_FEATURE_FLOW_CONTROL_MASK);
  9314. if (bp->link_params.req_flow_ctrl[idx] ==
  9315. BNX2X_FLOW_CTRL_AUTO) {
  9316. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9317. bp->link_params.req_flow_ctrl[idx] =
  9318. BNX2X_FLOW_CTRL_NONE;
  9319. else
  9320. bnx2x_set_requested_fc(bp);
  9321. }
  9322. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9323. bp->link_params.req_line_speed[idx],
  9324. bp->link_params.req_duplex[idx],
  9325. bp->link_params.req_flow_ctrl[idx],
  9326. bp->port.advertising[idx]);
  9327. }
  9328. }
  9329. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9330. {
  9331. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9332. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9333. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9334. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9335. }
  9336. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9337. {
  9338. int port = BP_PORT(bp);
  9339. u32 config;
  9340. u32 ext_phy_type, ext_phy_config, eee_mode;
  9341. bp->link_params.bp = bp;
  9342. bp->link_params.port = port;
  9343. bp->link_params.lane_config =
  9344. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9345. bp->link_params.speed_cap_mask[0] =
  9346. SHMEM_RD(bp,
  9347. dev_info.port_hw_config[port].speed_capability_mask) &
  9348. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9349. bp->link_params.speed_cap_mask[1] =
  9350. SHMEM_RD(bp,
  9351. dev_info.port_hw_config[port].speed_capability_mask2) &
  9352. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9353. bp->port.link_config[0] =
  9354. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9355. bp->port.link_config[1] =
  9356. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9357. bp->link_params.multi_phy_config =
  9358. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9359. /* If the device is capable of WoL, set the default state according
  9360. * to the HW
  9361. */
  9362. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9363. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9364. (config & PORT_FEATURE_WOL_ENABLED));
  9365. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9366. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9367. bp->flags |= NO_ISCSI_FLAG;
  9368. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9369. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9370. bp->flags |= NO_FCOE_FLAG;
  9371. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9372. bp->link_params.lane_config,
  9373. bp->link_params.speed_cap_mask[0],
  9374. bp->port.link_config[0]);
  9375. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9376. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9377. bnx2x_phy_probe(&bp->link_params);
  9378. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9379. bnx2x_link_settings_requested(bp);
  9380. /*
  9381. * If connected directly, work with the internal PHY, otherwise, work
  9382. * with the external PHY
  9383. */
  9384. ext_phy_config =
  9385. SHMEM_RD(bp,
  9386. dev_info.port_hw_config[port].external_phy_config);
  9387. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9388. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9389. bp->mdio.prtad = bp->port.phy_addr;
  9390. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9391. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9392. bp->mdio.prtad =
  9393. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9394. /* Configure link feature according to nvram value */
  9395. eee_mode = (((SHMEM_RD(bp, dev_info.
  9396. port_feature_config[port].eee_power_mode)) &
  9397. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9398. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9399. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9400. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9401. EEE_MODE_ENABLE_LPI |
  9402. EEE_MODE_OUTPUT_TIME;
  9403. } else {
  9404. bp->link_params.eee_mode = 0;
  9405. }
  9406. }
  9407. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9408. {
  9409. u32 no_flags = NO_ISCSI_FLAG;
  9410. int port = BP_PORT(bp);
  9411. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9412. drv_lic_key[port].max_iscsi_conn);
  9413. if (!CNIC_SUPPORT(bp)) {
  9414. bp->flags |= no_flags;
  9415. return;
  9416. }
  9417. /* Get the number of maximum allowed iSCSI connections */
  9418. bp->cnic_eth_dev.max_iscsi_conn =
  9419. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9420. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9421. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9422. bp->cnic_eth_dev.max_iscsi_conn);
  9423. /*
  9424. * If maximum allowed number of connections is zero -
  9425. * disable the feature.
  9426. */
  9427. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9428. bp->flags |= no_flags;
  9429. }
  9430. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9431. {
  9432. /* Port info */
  9433. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9434. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9435. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9436. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9437. /* Node info */
  9438. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9439. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9440. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9441. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9442. }
  9443. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9444. {
  9445. u8 count = 0;
  9446. if (IS_MF(bp)) {
  9447. u8 fid;
  9448. /* iterate over absolute function ids for this path: */
  9449. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9450. if (IS_MF_SD(bp)) {
  9451. u32 cfg = MF_CFG_RD(bp,
  9452. func_mf_config[fid].config);
  9453. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9454. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9455. FUNC_MF_CFG_PROTOCOL_FCOE))
  9456. count++;
  9457. } else {
  9458. u32 cfg = MF_CFG_RD(bp,
  9459. func_ext_config[fid].
  9460. func_cfg);
  9461. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9462. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9463. count++;
  9464. }
  9465. }
  9466. } else { /* SF */
  9467. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9468. for (port = 0; port < port_cnt; port++) {
  9469. u32 lic = SHMEM_RD(bp,
  9470. drv_lic_key[port].max_fcoe_conn) ^
  9471. FW_ENCODE_32BIT_PATTERN;
  9472. if (lic)
  9473. count++;
  9474. }
  9475. }
  9476. return count;
  9477. }
  9478. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9479. {
  9480. int port = BP_PORT(bp);
  9481. int func = BP_ABS_FUNC(bp);
  9482. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9483. drv_lic_key[port].max_fcoe_conn);
  9484. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9485. if (!CNIC_SUPPORT(bp)) {
  9486. bp->flags |= NO_FCOE_FLAG;
  9487. return;
  9488. }
  9489. /* Get the number of maximum allowed FCoE connections */
  9490. bp->cnic_eth_dev.max_fcoe_conn =
  9491. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9492. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9493. /* Calculate the number of maximum allowed FCoE tasks */
  9494. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9495. /* check if FCoE resources must be shared between different functions */
  9496. if (num_fcoe_func)
  9497. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9498. /* Read the WWN: */
  9499. if (!IS_MF(bp)) {
  9500. /* Port info */
  9501. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9502. SHMEM_RD(bp,
  9503. dev_info.port_hw_config[port].
  9504. fcoe_wwn_port_name_upper);
  9505. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9506. SHMEM_RD(bp,
  9507. dev_info.port_hw_config[port].
  9508. fcoe_wwn_port_name_lower);
  9509. /* Node info */
  9510. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9511. SHMEM_RD(bp,
  9512. dev_info.port_hw_config[port].
  9513. fcoe_wwn_node_name_upper);
  9514. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9515. SHMEM_RD(bp,
  9516. dev_info.port_hw_config[port].
  9517. fcoe_wwn_node_name_lower);
  9518. } else if (!IS_MF_SD(bp)) {
  9519. /*
  9520. * Read the WWN info only if the FCoE feature is enabled for
  9521. * this function.
  9522. */
  9523. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9524. bnx2x_get_ext_wwn_info(bp, func);
  9525. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9526. bnx2x_get_ext_wwn_info(bp, func);
  9527. }
  9528. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9529. /*
  9530. * If maximum allowed number of connections is zero -
  9531. * disable the feature.
  9532. */
  9533. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9534. bp->flags |= NO_FCOE_FLAG;
  9535. }
  9536. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9537. {
  9538. /*
  9539. * iSCSI may be dynamically disabled but reading
  9540. * info here we will decrease memory usage by driver
  9541. * if the feature is disabled for good
  9542. */
  9543. bnx2x_get_iscsi_info(bp);
  9544. bnx2x_get_fcoe_info(bp);
  9545. }
  9546. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9547. {
  9548. u32 val, val2;
  9549. int func = BP_ABS_FUNC(bp);
  9550. int port = BP_PORT(bp);
  9551. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9552. u8 *fip_mac = bp->fip_mac;
  9553. if (IS_MF(bp)) {
  9554. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9555. * FCoE MAC then the appropriate feature should be disabled.
  9556. * In non SD mode features configuration comes from struct
  9557. * func_ext_config.
  9558. */
  9559. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9560. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9561. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9562. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9563. iscsi_mac_addr_upper);
  9564. val = MF_CFG_RD(bp, func_ext_config[func].
  9565. iscsi_mac_addr_lower);
  9566. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9567. BNX2X_DEV_INFO
  9568. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9569. } else {
  9570. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9571. }
  9572. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9573. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9574. fcoe_mac_addr_upper);
  9575. val = MF_CFG_RD(bp, func_ext_config[func].
  9576. fcoe_mac_addr_lower);
  9577. bnx2x_set_mac_buf(fip_mac, val, val2);
  9578. BNX2X_DEV_INFO
  9579. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9580. } else {
  9581. bp->flags |= NO_FCOE_FLAG;
  9582. }
  9583. bp->mf_ext_config = cfg;
  9584. } else { /* SD MODE */
  9585. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9586. /* use primary mac as iscsi mac */
  9587. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9588. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9589. BNX2X_DEV_INFO
  9590. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9591. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9592. /* use primary mac as fip mac */
  9593. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9594. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9595. BNX2X_DEV_INFO
  9596. ("Read FIP MAC: %pM\n", fip_mac);
  9597. }
  9598. }
  9599. /* If this is a storage-only interface, use SAN mac as
  9600. * primary MAC. Notice that for SD this is already the case,
  9601. * as the SAN mac was copied from the primary MAC.
  9602. */
  9603. if (IS_MF_FCOE_AFEX(bp))
  9604. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9605. } else {
  9606. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9607. iscsi_mac_upper);
  9608. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9609. iscsi_mac_lower);
  9610. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9611. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9612. fcoe_fip_mac_upper);
  9613. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9614. fcoe_fip_mac_lower);
  9615. bnx2x_set_mac_buf(fip_mac, val, val2);
  9616. }
  9617. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9618. if (!is_valid_ether_addr(iscsi_mac)) {
  9619. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9620. memset(iscsi_mac, 0, ETH_ALEN);
  9621. }
  9622. /* Disable FCoE if MAC configuration is invalid. */
  9623. if (!is_valid_ether_addr(fip_mac)) {
  9624. bp->flags |= NO_FCOE_FLAG;
  9625. memset(bp->fip_mac, 0, ETH_ALEN);
  9626. }
  9627. }
  9628. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9629. {
  9630. u32 val, val2;
  9631. int func = BP_ABS_FUNC(bp);
  9632. int port = BP_PORT(bp);
  9633. /* Zero primary MAC configuration */
  9634. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9635. if (BP_NOMCP(bp)) {
  9636. BNX2X_ERROR("warning: random MAC workaround active\n");
  9637. eth_hw_addr_random(bp->dev);
  9638. } else if (IS_MF(bp)) {
  9639. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9640. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9641. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9642. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9643. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9644. if (CNIC_SUPPORT(bp))
  9645. bnx2x_get_cnic_mac_hwinfo(bp);
  9646. } else {
  9647. /* in SF read MACs from port configuration */
  9648. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9649. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9650. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9651. if (CNIC_SUPPORT(bp))
  9652. bnx2x_get_cnic_mac_hwinfo(bp);
  9653. }
  9654. if (!BP_NOMCP(bp)) {
  9655. /* Read physical port identifier from shmem */
  9656. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9657. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9658. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9659. bp->flags |= HAS_PHYS_PORT_ID;
  9660. }
  9661. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9662. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9663. dev_err(&bp->pdev->dev,
  9664. "bad Ethernet MAC address configuration: %pM\n"
  9665. "change it manually before bringing up the appropriate network interface\n",
  9666. bp->dev->dev_addr);
  9667. }
  9668. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9669. {
  9670. int tmp;
  9671. u32 cfg;
  9672. if (IS_VF(bp))
  9673. return 0;
  9674. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9675. /* Take function: tmp = func */
  9676. tmp = BP_ABS_FUNC(bp);
  9677. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9678. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9679. } else {
  9680. /* Take port: tmp = port */
  9681. tmp = BP_PORT(bp);
  9682. cfg = SHMEM_RD(bp,
  9683. dev_info.port_hw_config[tmp].generic_features);
  9684. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9685. }
  9686. return cfg;
  9687. }
  9688. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9689. {
  9690. int /*abs*/func = BP_ABS_FUNC(bp);
  9691. int vn;
  9692. u32 val = 0;
  9693. int rc = 0;
  9694. bnx2x_get_common_hwinfo(bp);
  9695. /*
  9696. * initialize IGU parameters
  9697. */
  9698. if (CHIP_IS_E1x(bp)) {
  9699. bp->common.int_block = INT_BLOCK_HC;
  9700. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9701. bp->igu_base_sb = 0;
  9702. } else {
  9703. bp->common.int_block = INT_BLOCK_IGU;
  9704. /* do not allow device reset during IGU info processing */
  9705. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9706. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9707. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9708. int tout = 5000;
  9709. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9710. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9711. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9712. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9713. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9714. tout--;
  9715. usleep_range(1000, 2000);
  9716. }
  9717. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9718. dev_err(&bp->pdev->dev,
  9719. "FORCING Normal Mode failed!!!\n");
  9720. bnx2x_release_hw_lock(bp,
  9721. HW_LOCK_RESOURCE_RESET);
  9722. return -EPERM;
  9723. }
  9724. }
  9725. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9726. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9727. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9728. } else
  9729. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9730. rc = bnx2x_get_igu_cam_info(bp);
  9731. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9732. if (rc)
  9733. return rc;
  9734. }
  9735. /*
  9736. * set base FW non-default (fast path) status block id, this value is
  9737. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9738. * determine the id used by the FW.
  9739. */
  9740. if (CHIP_IS_E1x(bp))
  9741. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9742. else /*
  9743. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9744. * the same queue are indicated on the same IGU SB). So we prefer
  9745. * FW and IGU SBs to be the same value.
  9746. */
  9747. bp->base_fw_ndsb = bp->igu_base_sb;
  9748. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9749. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9750. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9751. /*
  9752. * Initialize MF configuration
  9753. */
  9754. bp->mf_ov = 0;
  9755. bp->mf_mode = 0;
  9756. vn = BP_VN(bp);
  9757. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9758. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9759. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9760. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9761. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9762. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9763. else
  9764. bp->common.mf_cfg_base = bp->common.shmem_base +
  9765. offsetof(struct shmem_region, func_mb) +
  9766. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9767. /*
  9768. * get mf configuration:
  9769. * 1. Existence of MF configuration
  9770. * 2. MAC address must be legal (check only upper bytes)
  9771. * for Switch-Independent mode;
  9772. * OVLAN must be legal for Switch-Dependent mode
  9773. * 3. SF_MODE configures specific MF mode
  9774. */
  9775. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9776. /* get mf configuration */
  9777. val = SHMEM_RD(bp,
  9778. dev_info.shared_feature_config.config);
  9779. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9780. switch (val) {
  9781. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9782. val = MF_CFG_RD(bp, func_mf_config[func].
  9783. mac_upper);
  9784. /* check for legal mac (upper bytes)*/
  9785. if (val != 0xffff) {
  9786. bp->mf_mode = MULTI_FUNCTION_SI;
  9787. bp->mf_config[vn] = MF_CFG_RD(bp,
  9788. func_mf_config[func].config);
  9789. } else
  9790. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9791. break;
  9792. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9793. if ((!CHIP_IS_E1x(bp)) &&
  9794. (MF_CFG_RD(bp, func_mf_config[func].
  9795. mac_upper) != 0xffff) &&
  9796. (SHMEM2_HAS(bp,
  9797. afex_driver_support))) {
  9798. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9799. bp->mf_config[vn] = MF_CFG_RD(bp,
  9800. func_mf_config[func].config);
  9801. } else {
  9802. BNX2X_DEV_INFO("can not configure afex mode\n");
  9803. }
  9804. break;
  9805. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9806. /* get OV configuration */
  9807. val = MF_CFG_RD(bp,
  9808. func_mf_config[FUNC_0].e1hov_tag);
  9809. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9810. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9811. bp->mf_mode = MULTI_FUNCTION_SD;
  9812. bp->mf_config[vn] = MF_CFG_RD(bp,
  9813. func_mf_config[func].config);
  9814. } else
  9815. BNX2X_DEV_INFO("illegal OV for SD\n");
  9816. break;
  9817. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9818. bp->mf_config[vn] = 0;
  9819. break;
  9820. default:
  9821. /* Unknown configuration: reset mf_config */
  9822. bp->mf_config[vn] = 0;
  9823. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9824. }
  9825. }
  9826. BNX2X_DEV_INFO("%s function mode\n",
  9827. IS_MF(bp) ? "multi" : "single");
  9828. switch (bp->mf_mode) {
  9829. case MULTI_FUNCTION_SD:
  9830. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9831. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9832. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9833. bp->mf_ov = val;
  9834. bp->path_has_ovlan = true;
  9835. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9836. func, bp->mf_ov, bp->mf_ov);
  9837. } else {
  9838. dev_err(&bp->pdev->dev,
  9839. "No valid MF OV for func %d, aborting\n",
  9840. func);
  9841. return -EPERM;
  9842. }
  9843. break;
  9844. case MULTI_FUNCTION_AFEX:
  9845. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9846. break;
  9847. case MULTI_FUNCTION_SI:
  9848. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9849. func);
  9850. break;
  9851. default:
  9852. if (vn) {
  9853. dev_err(&bp->pdev->dev,
  9854. "VN %d is in a single function mode, aborting\n",
  9855. vn);
  9856. return -EPERM;
  9857. }
  9858. break;
  9859. }
  9860. /* check if other port on the path needs ovlan:
  9861. * Since MF configuration is shared between ports
  9862. * Possible mixed modes are only
  9863. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9864. */
  9865. if (CHIP_MODE_IS_4_PORT(bp) &&
  9866. !bp->path_has_ovlan &&
  9867. !IS_MF(bp) &&
  9868. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9869. u8 other_port = !BP_PORT(bp);
  9870. u8 other_func = BP_PATH(bp) + 2*other_port;
  9871. val = MF_CFG_RD(bp,
  9872. func_mf_config[other_func].e1hov_tag);
  9873. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9874. bp->path_has_ovlan = true;
  9875. }
  9876. }
  9877. /* adjust igu_sb_cnt to MF for E1H */
  9878. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  9879. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  9880. /* port info */
  9881. bnx2x_get_port_hwinfo(bp);
  9882. /* Get MAC addresses */
  9883. bnx2x_get_mac_hwinfo(bp);
  9884. bnx2x_get_cnic_info(bp);
  9885. return rc;
  9886. }
  9887. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9888. {
  9889. int cnt, i, block_end, rodi;
  9890. char vpd_start[BNX2X_VPD_LEN+1];
  9891. char str_id_reg[VENDOR_ID_LEN+1];
  9892. char str_id_cap[VENDOR_ID_LEN+1];
  9893. char *vpd_data;
  9894. char *vpd_extended_data = NULL;
  9895. u8 len;
  9896. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9897. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9898. if (cnt < BNX2X_VPD_LEN)
  9899. goto out_not_found;
  9900. /* VPD RO tag should be first tag after identifier string, hence
  9901. * we should be able to find it in first BNX2X_VPD_LEN chars
  9902. */
  9903. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9904. PCI_VPD_LRDT_RO_DATA);
  9905. if (i < 0)
  9906. goto out_not_found;
  9907. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9908. pci_vpd_lrdt_size(&vpd_start[i]);
  9909. i += PCI_VPD_LRDT_TAG_SIZE;
  9910. if (block_end > BNX2X_VPD_LEN) {
  9911. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9912. if (vpd_extended_data == NULL)
  9913. goto out_not_found;
  9914. /* read rest of vpd image into vpd_extended_data */
  9915. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9916. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9917. block_end - BNX2X_VPD_LEN,
  9918. vpd_extended_data + BNX2X_VPD_LEN);
  9919. if (cnt < (block_end - BNX2X_VPD_LEN))
  9920. goto out_not_found;
  9921. vpd_data = vpd_extended_data;
  9922. } else
  9923. vpd_data = vpd_start;
  9924. /* now vpd_data holds full vpd content in both cases */
  9925. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9926. PCI_VPD_RO_KEYWORD_MFR_ID);
  9927. if (rodi < 0)
  9928. goto out_not_found;
  9929. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9930. if (len != VENDOR_ID_LEN)
  9931. goto out_not_found;
  9932. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9933. /* vendor specific info */
  9934. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9935. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9936. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9937. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9938. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9939. PCI_VPD_RO_KEYWORD_VENDOR0);
  9940. if (rodi >= 0) {
  9941. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9942. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9943. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9944. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9945. bp->fw_ver[len] = ' ';
  9946. }
  9947. }
  9948. kfree(vpd_extended_data);
  9949. return;
  9950. }
  9951. out_not_found:
  9952. kfree(vpd_extended_data);
  9953. return;
  9954. }
  9955. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9956. {
  9957. u32 flags = 0;
  9958. if (CHIP_REV_IS_FPGA(bp))
  9959. SET_FLAGS(flags, MODE_FPGA);
  9960. else if (CHIP_REV_IS_EMUL(bp))
  9961. SET_FLAGS(flags, MODE_EMUL);
  9962. else
  9963. SET_FLAGS(flags, MODE_ASIC);
  9964. if (CHIP_MODE_IS_4_PORT(bp))
  9965. SET_FLAGS(flags, MODE_PORT4);
  9966. else
  9967. SET_FLAGS(flags, MODE_PORT2);
  9968. if (CHIP_IS_E2(bp))
  9969. SET_FLAGS(flags, MODE_E2);
  9970. else if (CHIP_IS_E3(bp)) {
  9971. SET_FLAGS(flags, MODE_E3);
  9972. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9973. SET_FLAGS(flags, MODE_E3_A0);
  9974. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9975. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9976. }
  9977. if (IS_MF(bp)) {
  9978. SET_FLAGS(flags, MODE_MF);
  9979. switch (bp->mf_mode) {
  9980. case MULTI_FUNCTION_SD:
  9981. SET_FLAGS(flags, MODE_MF_SD);
  9982. break;
  9983. case MULTI_FUNCTION_SI:
  9984. SET_FLAGS(flags, MODE_MF_SI);
  9985. break;
  9986. case MULTI_FUNCTION_AFEX:
  9987. SET_FLAGS(flags, MODE_MF_AFEX);
  9988. break;
  9989. }
  9990. } else
  9991. SET_FLAGS(flags, MODE_SF);
  9992. #if defined(__LITTLE_ENDIAN)
  9993. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9994. #else /*(__BIG_ENDIAN)*/
  9995. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9996. #endif
  9997. INIT_MODE_FLAGS(bp) = flags;
  9998. }
  9999. static int bnx2x_init_bp(struct bnx2x *bp)
  10000. {
  10001. int func;
  10002. int rc;
  10003. mutex_init(&bp->port.phy_mutex);
  10004. mutex_init(&bp->fw_mb_mutex);
  10005. mutex_init(&bp->drv_info_mutex);
  10006. bp->drv_info_mng_owner = false;
  10007. spin_lock_init(&bp->stats_lock);
  10008. sema_init(&bp->stats_sema, 1);
  10009. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10010. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10011. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10012. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10013. if (IS_PF(bp)) {
  10014. rc = bnx2x_get_hwinfo(bp);
  10015. if (rc)
  10016. return rc;
  10017. } else {
  10018. eth_zero_addr(bp->dev->dev_addr);
  10019. }
  10020. bnx2x_set_modes_bitmap(bp);
  10021. rc = bnx2x_alloc_mem_bp(bp);
  10022. if (rc)
  10023. return rc;
  10024. bnx2x_read_fwinfo(bp);
  10025. func = BP_FUNC(bp);
  10026. /* need to reset chip if undi was active */
  10027. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10028. /* init fw_seq */
  10029. bp->fw_seq =
  10030. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10031. DRV_MSG_SEQ_NUMBER_MASK;
  10032. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10033. rc = bnx2x_prev_unload(bp);
  10034. if (rc) {
  10035. bnx2x_free_mem_bp(bp);
  10036. return rc;
  10037. }
  10038. }
  10039. if (CHIP_REV_IS_FPGA(bp))
  10040. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10041. if (BP_NOMCP(bp) && (func == 0))
  10042. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10043. bp->disable_tpa = disable_tpa;
  10044. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  10045. /* Reduce memory usage in kdump environment by disabling TPA */
  10046. bp->disable_tpa |= reset_devices;
  10047. /* Set TPA flags */
  10048. if (bp->disable_tpa) {
  10049. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10050. bp->dev->features &= ~NETIF_F_LRO;
  10051. } else {
  10052. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10053. bp->dev->features |= NETIF_F_LRO;
  10054. }
  10055. if (CHIP_IS_E1(bp))
  10056. bp->dropless_fc = 0;
  10057. else
  10058. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10059. bp->mrrs = mrrs;
  10060. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  10061. if (IS_VF(bp))
  10062. bp->rx_ring_size = MAX_RX_AVAIL;
  10063. /* make sure that the numbers are in the right granularity */
  10064. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10065. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10066. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10067. init_timer(&bp->timer);
  10068. bp->timer.expires = jiffies + bp->current_interval;
  10069. bp->timer.data = (unsigned long) bp;
  10070. bp->timer.function = bnx2x_timer;
  10071. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10072. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10073. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10074. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10075. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10076. bnx2x_dcbx_init_params(bp);
  10077. } else {
  10078. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10079. }
  10080. if (CHIP_IS_E1x(bp))
  10081. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10082. else
  10083. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10084. /* multiple tx priority */
  10085. if (IS_VF(bp))
  10086. bp->max_cos = 1;
  10087. else if (CHIP_IS_E1x(bp))
  10088. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10089. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10090. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10091. else if (CHIP_IS_E3B0(bp))
  10092. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10093. else
  10094. BNX2X_ERR("unknown chip %x revision %x\n",
  10095. CHIP_NUM(bp), CHIP_REV(bp));
  10096. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10097. /* We need at least one default status block for slow-path events,
  10098. * second status block for the L2 queue, and a third status block for
  10099. * CNIC if supported.
  10100. */
  10101. if (IS_VF(bp))
  10102. bp->min_msix_vec_cnt = 1;
  10103. else if (CNIC_SUPPORT(bp))
  10104. bp->min_msix_vec_cnt = 3;
  10105. else /* PF w/o cnic */
  10106. bp->min_msix_vec_cnt = 2;
  10107. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10108. bp->dump_preset_idx = 1;
  10109. return rc;
  10110. }
  10111. /****************************************************************************
  10112. * General service functions
  10113. ****************************************************************************/
  10114. /*
  10115. * net_device service functions
  10116. */
  10117. /* called with rtnl_lock */
  10118. static int bnx2x_open(struct net_device *dev)
  10119. {
  10120. struct bnx2x *bp = netdev_priv(dev);
  10121. int rc;
  10122. bp->stats_init = true;
  10123. netif_carrier_off(dev);
  10124. bnx2x_set_power_state(bp, PCI_D0);
  10125. /* If parity had happen during the unload, then attentions
  10126. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10127. * want the first function loaded on the current engine to
  10128. * complete the recovery.
  10129. * Parity recovery is only relevant for PF driver.
  10130. */
  10131. if (IS_PF(bp)) {
  10132. int other_engine = BP_PATH(bp) ? 0 : 1;
  10133. bool other_load_status, load_status;
  10134. bool global = false;
  10135. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10136. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10137. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10138. bnx2x_chk_parity_attn(bp, &global, true)) {
  10139. do {
  10140. /* If there are attentions and they are in a
  10141. * global blocks, set the GLOBAL_RESET bit
  10142. * regardless whether it will be this function
  10143. * that will complete the recovery or not.
  10144. */
  10145. if (global)
  10146. bnx2x_set_reset_global(bp);
  10147. /* Only the first function on the current
  10148. * engine should try to recover in open. In case
  10149. * of attentions in global blocks only the first
  10150. * in the chip should try to recover.
  10151. */
  10152. if ((!load_status &&
  10153. (!global || !other_load_status)) &&
  10154. bnx2x_trylock_leader_lock(bp) &&
  10155. !bnx2x_leader_reset(bp)) {
  10156. netdev_info(bp->dev,
  10157. "Recovered in open\n");
  10158. break;
  10159. }
  10160. /* recovery has failed... */
  10161. bnx2x_set_power_state(bp, PCI_D3hot);
  10162. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10163. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10164. "If you still see this message after a few retries then power cycle is required.\n");
  10165. return -EAGAIN;
  10166. } while (0);
  10167. }
  10168. }
  10169. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10170. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10171. if (rc)
  10172. return rc;
  10173. return 0;
  10174. }
  10175. /* called with rtnl_lock */
  10176. static int bnx2x_close(struct net_device *dev)
  10177. {
  10178. struct bnx2x *bp = netdev_priv(dev);
  10179. /* Unload the driver, release IRQs */
  10180. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10181. return 0;
  10182. }
  10183. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10184. struct bnx2x_mcast_ramrod_params *p)
  10185. {
  10186. int mc_count = netdev_mc_count(bp->dev);
  10187. struct bnx2x_mcast_list_elem *mc_mac =
  10188. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10189. struct netdev_hw_addr *ha;
  10190. if (!mc_mac)
  10191. return -ENOMEM;
  10192. INIT_LIST_HEAD(&p->mcast_list);
  10193. netdev_for_each_mc_addr(ha, bp->dev) {
  10194. mc_mac->mac = bnx2x_mc_addr(ha);
  10195. list_add_tail(&mc_mac->link, &p->mcast_list);
  10196. mc_mac++;
  10197. }
  10198. p->mcast_list_len = mc_count;
  10199. return 0;
  10200. }
  10201. static void bnx2x_free_mcast_macs_list(
  10202. struct bnx2x_mcast_ramrod_params *p)
  10203. {
  10204. struct bnx2x_mcast_list_elem *mc_mac =
  10205. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10206. link);
  10207. WARN_ON(!mc_mac);
  10208. kfree(mc_mac);
  10209. }
  10210. /**
  10211. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10212. *
  10213. * @bp: driver handle
  10214. *
  10215. * We will use zero (0) as a MAC type for these MACs.
  10216. */
  10217. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10218. {
  10219. int rc;
  10220. struct net_device *dev = bp->dev;
  10221. struct netdev_hw_addr *ha;
  10222. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10223. unsigned long ramrod_flags = 0;
  10224. /* First schedule a cleanup up of old configuration */
  10225. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10226. if (rc < 0) {
  10227. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10228. return rc;
  10229. }
  10230. netdev_for_each_uc_addr(ha, dev) {
  10231. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10232. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10233. if (rc == -EEXIST) {
  10234. DP(BNX2X_MSG_SP,
  10235. "Failed to schedule ADD operations: %d\n", rc);
  10236. /* do not treat adding same MAC as error */
  10237. rc = 0;
  10238. } else if (rc < 0) {
  10239. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10240. rc);
  10241. return rc;
  10242. }
  10243. }
  10244. /* Execute the pending commands */
  10245. __set_bit(RAMROD_CONT, &ramrod_flags);
  10246. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10247. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10248. }
  10249. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10250. {
  10251. struct net_device *dev = bp->dev;
  10252. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10253. int rc = 0;
  10254. rparam.mcast_obj = &bp->mcast_obj;
  10255. /* first, clear all configured multicast MACs */
  10256. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10257. if (rc < 0) {
  10258. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10259. return rc;
  10260. }
  10261. /* then, configure a new MACs list */
  10262. if (netdev_mc_count(dev)) {
  10263. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10264. if (rc) {
  10265. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10266. rc);
  10267. return rc;
  10268. }
  10269. /* Now add the new MACs */
  10270. rc = bnx2x_config_mcast(bp, &rparam,
  10271. BNX2X_MCAST_CMD_ADD);
  10272. if (rc < 0)
  10273. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10274. rc);
  10275. bnx2x_free_mcast_macs_list(&rparam);
  10276. }
  10277. return rc;
  10278. }
  10279. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10280. static void bnx2x_set_rx_mode(struct net_device *dev)
  10281. {
  10282. struct bnx2x *bp = netdev_priv(dev);
  10283. if (bp->state != BNX2X_STATE_OPEN) {
  10284. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10285. return;
  10286. } else {
  10287. /* Schedule an SP task to handle rest of change */
  10288. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10289. NETIF_MSG_IFUP);
  10290. }
  10291. }
  10292. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10293. {
  10294. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10295. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10296. netif_addr_lock_bh(bp->dev);
  10297. if (bp->dev->flags & IFF_PROMISC) {
  10298. rx_mode = BNX2X_RX_MODE_PROMISC;
  10299. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10300. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10301. CHIP_IS_E1(bp))) {
  10302. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10303. } else {
  10304. if (IS_PF(bp)) {
  10305. /* some multicasts */
  10306. if (bnx2x_set_mc_list(bp) < 0)
  10307. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10308. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10309. netif_addr_unlock_bh(bp->dev);
  10310. if (bnx2x_set_uc_list(bp) < 0)
  10311. rx_mode = BNX2X_RX_MODE_PROMISC;
  10312. netif_addr_lock_bh(bp->dev);
  10313. } else {
  10314. /* configuring mcast to a vf involves sleeping (when we
  10315. * wait for the pf's response).
  10316. */
  10317. bnx2x_schedule_sp_rtnl(bp,
  10318. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10319. }
  10320. }
  10321. bp->rx_mode = rx_mode;
  10322. /* handle ISCSI SD mode */
  10323. if (IS_MF_ISCSI_SD(bp))
  10324. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10325. /* Schedule the rx_mode command */
  10326. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10327. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10328. netif_addr_unlock_bh(bp->dev);
  10329. return;
  10330. }
  10331. if (IS_PF(bp)) {
  10332. bnx2x_set_storm_rx_mode(bp);
  10333. netif_addr_unlock_bh(bp->dev);
  10334. } else {
  10335. /* VF will need to request the PF to make this change, and so
  10336. * the VF needs to release the bottom-half lock prior to the
  10337. * request (as it will likely require sleep on the VF side)
  10338. */
  10339. netif_addr_unlock_bh(bp->dev);
  10340. bnx2x_vfpf_storm_rx_mode(bp);
  10341. }
  10342. }
  10343. /* called with rtnl_lock */
  10344. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10345. int devad, u16 addr)
  10346. {
  10347. struct bnx2x *bp = netdev_priv(netdev);
  10348. u16 value;
  10349. int rc;
  10350. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10351. prtad, devad, addr);
  10352. /* The HW expects different devad if CL22 is used */
  10353. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10354. bnx2x_acquire_phy_lock(bp);
  10355. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10356. bnx2x_release_phy_lock(bp);
  10357. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10358. if (!rc)
  10359. rc = value;
  10360. return rc;
  10361. }
  10362. /* called with rtnl_lock */
  10363. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10364. u16 addr, u16 value)
  10365. {
  10366. struct bnx2x *bp = netdev_priv(netdev);
  10367. int rc;
  10368. DP(NETIF_MSG_LINK,
  10369. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10370. prtad, devad, addr, value);
  10371. /* The HW expects different devad if CL22 is used */
  10372. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10373. bnx2x_acquire_phy_lock(bp);
  10374. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10375. bnx2x_release_phy_lock(bp);
  10376. return rc;
  10377. }
  10378. /* called with rtnl_lock */
  10379. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10380. {
  10381. struct bnx2x *bp = netdev_priv(dev);
  10382. struct mii_ioctl_data *mdio = if_mii(ifr);
  10383. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10384. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10385. if (!netif_running(dev))
  10386. return -EAGAIN;
  10387. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10388. }
  10389. #ifdef CONFIG_NET_POLL_CONTROLLER
  10390. static void poll_bnx2x(struct net_device *dev)
  10391. {
  10392. struct bnx2x *bp = netdev_priv(dev);
  10393. int i;
  10394. for_each_eth_queue(bp, i) {
  10395. struct bnx2x_fastpath *fp = &bp->fp[i];
  10396. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10397. }
  10398. }
  10399. #endif
  10400. static int bnx2x_validate_addr(struct net_device *dev)
  10401. {
  10402. struct bnx2x *bp = netdev_priv(dev);
  10403. /* query the bulletin board for mac address configured by the PF */
  10404. if (IS_VF(bp))
  10405. bnx2x_sample_bulletin(bp);
  10406. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10407. BNX2X_ERR("Non-valid Ethernet address\n");
  10408. return -EADDRNOTAVAIL;
  10409. }
  10410. return 0;
  10411. }
  10412. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10413. struct netdev_phys_port_id *ppid)
  10414. {
  10415. struct bnx2x *bp = netdev_priv(netdev);
  10416. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10417. return -EOPNOTSUPP;
  10418. ppid->id_len = sizeof(bp->phys_port_id);
  10419. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10420. return 0;
  10421. }
  10422. static const struct net_device_ops bnx2x_netdev_ops = {
  10423. .ndo_open = bnx2x_open,
  10424. .ndo_stop = bnx2x_close,
  10425. .ndo_start_xmit = bnx2x_start_xmit,
  10426. .ndo_select_queue = bnx2x_select_queue,
  10427. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10428. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10429. .ndo_validate_addr = bnx2x_validate_addr,
  10430. .ndo_do_ioctl = bnx2x_ioctl,
  10431. .ndo_change_mtu = bnx2x_change_mtu,
  10432. .ndo_fix_features = bnx2x_fix_features,
  10433. .ndo_set_features = bnx2x_set_features,
  10434. .ndo_tx_timeout = bnx2x_tx_timeout,
  10435. #ifdef CONFIG_NET_POLL_CONTROLLER
  10436. .ndo_poll_controller = poll_bnx2x,
  10437. #endif
  10438. .ndo_setup_tc = bnx2x_setup_tc,
  10439. #ifdef CONFIG_BNX2X_SRIOV
  10440. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10441. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10442. .ndo_get_vf_config = bnx2x_get_vf_config,
  10443. #endif
  10444. #ifdef NETDEV_FCOE_WWNN
  10445. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10446. #endif
  10447. #ifdef CONFIG_NET_RX_BUSY_POLL
  10448. .ndo_busy_poll = bnx2x_low_latency_recv,
  10449. #endif
  10450. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10451. };
  10452. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10453. {
  10454. struct device *dev = &bp->pdev->dev;
  10455. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10456. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10457. dev_err(dev, "System does not support DMA, aborting\n");
  10458. return -EIO;
  10459. }
  10460. return 0;
  10461. }
  10462. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10463. {
  10464. if (bp->flags & AER_ENABLED) {
  10465. pci_disable_pcie_error_reporting(bp->pdev);
  10466. bp->flags &= ~AER_ENABLED;
  10467. }
  10468. }
  10469. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10470. struct net_device *dev, unsigned long board_type)
  10471. {
  10472. int rc;
  10473. u32 pci_cfg_dword;
  10474. bool chip_is_e1x = (board_type == BCM57710 ||
  10475. board_type == BCM57711 ||
  10476. board_type == BCM57711E);
  10477. SET_NETDEV_DEV(dev, &pdev->dev);
  10478. bp->dev = dev;
  10479. bp->pdev = pdev;
  10480. rc = pci_enable_device(pdev);
  10481. if (rc) {
  10482. dev_err(&bp->pdev->dev,
  10483. "Cannot enable PCI device, aborting\n");
  10484. goto err_out;
  10485. }
  10486. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10487. dev_err(&bp->pdev->dev,
  10488. "Cannot find PCI device base address, aborting\n");
  10489. rc = -ENODEV;
  10490. goto err_out_disable;
  10491. }
  10492. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10493. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10494. rc = -ENODEV;
  10495. goto err_out_disable;
  10496. }
  10497. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10498. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10499. PCICFG_REVESION_ID_ERROR_VAL) {
  10500. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10501. rc = -ENODEV;
  10502. goto err_out_disable;
  10503. }
  10504. if (atomic_read(&pdev->enable_cnt) == 1) {
  10505. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10506. if (rc) {
  10507. dev_err(&bp->pdev->dev,
  10508. "Cannot obtain PCI resources, aborting\n");
  10509. goto err_out_disable;
  10510. }
  10511. pci_set_master(pdev);
  10512. pci_save_state(pdev);
  10513. }
  10514. if (IS_PF(bp)) {
  10515. if (!pdev->pm_cap) {
  10516. dev_err(&bp->pdev->dev,
  10517. "Cannot find power management capability, aborting\n");
  10518. rc = -EIO;
  10519. goto err_out_release;
  10520. }
  10521. }
  10522. if (!pci_is_pcie(pdev)) {
  10523. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10524. rc = -EIO;
  10525. goto err_out_release;
  10526. }
  10527. rc = bnx2x_set_coherency_mask(bp);
  10528. if (rc)
  10529. goto err_out_release;
  10530. dev->mem_start = pci_resource_start(pdev, 0);
  10531. dev->base_addr = dev->mem_start;
  10532. dev->mem_end = pci_resource_end(pdev, 0);
  10533. dev->irq = pdev->irq;
  10534. bp->regview = pci_ioremap_bar(pdev, 0);
  10535. if (!bp->regview) {
  10536. dev_err(&bp->pdev->dev,
  10537. "Cannot map register space, aborting\n");
  10538. rc = -ENOMEM;
  10539. goto err_out_release;
  10540. }
  10541. /* In E1/E1H use pci device function given by kernel.
  10542. * In E2/E3 read physical function from ME register since these chips
  10543. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10544. * (depending on hypervisor).
  10545. */
  10546. if (chip_is_e1x) {
  10547. bp->pf_num = PCI_FUNC(pdev->devfn);
  10548. } else {
  10549. /* chip is E2/3*/
  10550. pci_read_config_dword(bp->pdev,
  10551. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10552. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10553. ME_REG_ABS_PF_NUM_SHIFT);
  10554. }
  10555. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10556. /* clean indirect addresses */
  10557. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10558. PCICFG_VENDOR_ID_OFFSET);
  10559. /* AER (Advanced Error reporting) configuration */
  10560. rc = pci_enable_pcie_error_reporting(pdev);
  10561. if (!rc)
  10562. bp->flags |= AER_ENABLED;
  10563. else
  10564. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10565. /*
  10566. * Clean the following indirect addresses for all functions since it
  10567. * is not used by the driver.
  10568. */
  10569. if (IS_PF(bp)) {
  10570. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10571. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10572. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10573. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10574. if (chip_is_e1x) {
  10575. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10576. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10577. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10578. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10579. }
  10580. /* Enable internal target-read (in case we are probed after PF
  10581. * FLR). Must be done prior to any BAR read access. Only for
  10582. * 57712 and up
  10583. */
  10584. if (!chip_is_e1x)
  10585. REG_WR(bp,
  10586. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10587. }
  10588. dev->watchdog_timeo = TX_TIMEOUT;
  10589. dev->netdev_ops = &bnx2x_netdev_ops;
  10590. bnx2x_set_ethtool_ops(bp, dev);
  10591. dev->priv_flags |= IFF_UNICAST_FLT;
  10592. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10593. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10594. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10595. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10596. if (!CHIP_IS_E1x(bp)) {
  10597. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10598. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10599. dev->hw_enc_features =
  10600. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10601. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10602. NETIF_F_GSO_IPIP |
  10603. NETIF_F_GSO_SIT |
  10604. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10605. }
  10606. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10607. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10608. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10609. dev->features |= NETIF_F_HIGHDMA;
  10610. /* Add Loopback capability to the device */
  10611. dev->hw_features |= NETIF_F_LOOPBACK;
  10612. #ifdef BCM_DCBNL
  10613. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10614. #endif
  10615. /* get_port_hwinfo() will set prtad and mmds properly */
  10616. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10617. bp->mdio.mmds = 0;
  10618. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10619. bp->mdio.dev = dev;
  10620. bp->mdio.mdio_read = bnx2x_mdio_read;
  10621. bp->mdio.mdio_write = bnx2x_mdio_write;
  10622. return 0;
  10623. err_out_release:
  10624. if (atomic_read(&pdev->enable_cnt) == 1)
  10625. pci_release_regions(pdev);
  10626. err_out_disable:
  10627. pci_disable_device(pdev);
  10628. err_out:
  10629. return rc;
  10630. }
  10631. static int bnx2x_check_firmware(struct bnx2x *bp)
  10632. {
  10633. const struct firmware *firmware = bp->firmware;
  10634. struct bnx2x_fw_file_hdr *fw_hdr;
  10635. struct bnx2x_fw_file_section *sections;
  10636. u32 offset, len, num_ops;
  10637. __be16 *ops_offsets;
  10638. int i;
  10639. const u8 *fw_ver;
  10640. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10641. BNX2X_ERR("Wrong FW size\n");
  10642. return -EINVAL;
  10643. }
  10644. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10645. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10646. /* Make sure none of the offsets and sizes make us read beyond
  10647. * the end of the firmware data */
  10648. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10649. offset = be32_to_cpu(sections[i].offset);
  10650. len = be32_to_cpu(sections[i].len);
  10651. if (offset + len > firmware->size) {
  10652. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10653. return -EINVAL;
  10654. }
  10655. }
  10656. /* Likewise for the init_ops offsets */
  10657. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10658. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10659. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10660. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10661. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10662. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10663. return -EINVAL;
  10664. }
  10665. }
  10666. /* Check FW version */
  10667. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10668. fw_ver = firmware->data + offset;
  10669. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10670. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10671. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10672. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10673. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10674. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10675. BCM_5710_FW_MAJOR_VERSION,
  10676. BCM_5710_FW_MINOR_VERSION,
  10677. BCM_5710_FW_REVISION_VERSION,
  10678. BCM_5710_FW_ENGINEERING_VERSION);
  10679. return -EINVAL;
  10680. }
  10681. return 0;
  10682. }
  10683. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10684. {
  10685. const __be32 *source = (const __be32 *)_source;
  10686. u32 *target = (u32 *)_target;
  10687. u32 i;
  10688. for (i = 0; i < n/4; i++)
  10689. target[i] = be32_to_cpu(source[i]);
  10690. }
  10691. /*
  10692. Ops array is stored in the following format:
  10693. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10694. */
  10695. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10696. {
  10697. const __be32 *source = (const __be32 *)_source;
  10698. struct raw_op *target = (struct raw_op *)_target;
  10699. u32 i, j, tmp;
  10700. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10701. tmp = be32_to_cpu(source[j]);
  10702. target[i].op = (tmp >> 24) & 0xff;
  10703. target[i].offset = tmp & 0xffffff;
  10704. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10705. }
  10706. }
  10707. /* IRO array is stored in the following format:
  10708. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10709. */
  10710. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10711. {
  10712. const __be32 *source = (const __be32 *)_source;
  10713. struct iro *target = (struct iro *)_target;
  10714. u32 i, j, tmp;
  10715. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10716. target[i].base = be32_to_cpu(source[j]);
  10717. j++;
  10718. tmp = be32_to_cpu(source[j]);
  10719. target[i].m1 = (tmp >> 16) & 0xffff;
  10720. target[i].m2 = tmp & 0xffff;
  10721. j++;
  10722. tmp = be32_to_cpu(source[j]);
  10723. target[i].m3 = (tmp >> 16) & 0xffff;
  10724. target[i].size = tmp & 0xffff;
  10725. j++;
  10726. }
  10727. }
  10728. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10729. {
  10730. const __be16 *source = (const __be16 *)_source;
  10731. u16 *target = (u16 *)_target;
  10732. u32 i;
  10733. for (i = 0; i < n/2; i++)
  10734. target[i] = be16_to_cpu(source[i]);
  10735. }
  10736. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10737. do { \
  10738. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10739. bp->arr = kmalloc(len, GFP_KERNEL); \
  10740. if (!bp->arr) \
  10741. goto lbl; \
  10742. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10743. (u8 *)bp->arr, len); \
  10744. } while (0)
  10745. static int bnx2x_init_firmware(struct bnx2x *bp)
  10746. {
  10747. const char *fw_file_name;
  10748. struct bnx2x_fw_file_hdr *fw_hdr;
  10749. int rc;
  10750. if (bp->firmware)
  10751. return 0;
  10752. if (CHIP_IS_E1(bp))
  10753. fw_file_name = FW_FILE_NAME_E1;
  10754. else if (CHIP_IS_E1H(bp))
  10755. fw_file_name = FW_FILE_NAME_E1H;
  10756. else if (!CHIP_IS_E1x(bp))
  10757. fw_file_name = FW_FILE_NAME_E2;
  10758. else {
  10759. BNX2X_ERR("Unsupported chip revision\n");
  10760. return -EINVAL;
  10761. }
  10762. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10763. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10764. if (rc) {
  10765. BNX2X_ERR("Can't load firmware file %s\n",
  10766. fw_file_name);
  10767. goto request_firmware_exit;
  10768. }
  10769. rc = bnx2x_check_firmware(bp);
  10770. if (rc) {
  10771. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10772. goto request_firmware_exit;
  10773. }
  10774. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10775. /* Initialize the pointers to the init arrays */
  10776. /* Blob */
  10777. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10778. /* Opcodes */
  10779. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10780. /* Offsets */
  10781. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10782. be16_to_cpu_n);
  10783. /* STORMs firmware */
  10784. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10785. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10786. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10787. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10788. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10789. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10790. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10791. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10792. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10793. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10794. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10795. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10796. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10797. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10798. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10799. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10800. /* IRO */
  10801. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10802. return 0;
  10803. iro_alloc_err:
  10804. kfree(bp->init_ops_offsets);
  10805. init_offsets_alloc_err:
  10806. kfree(bp->init_ops);
  10807. init_ops_alloc_err:
  10808. kfree(bp->init_data);
  10809. request_firmware_exit:
  10810. release_firmware(bp->firmware);
  10811. bp->firmware = NULL;
  10812. return rc;
  10813. }
  10814. static void bnx2x_release_firmware(struct bnx2x *bp)
  10815. {
  10816. kfree(bp->init_ops_offsets);
  10817. kfree(bp->init_ops);
  10818. kfree(bp->init_data);
  10819. release_firmware(bp->firmware);
  10820. bp->firmware = NULL;
  10821. }
  10822. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10823. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10824. .init_hw_cmn = bnx2x_init_hw_common,
  10825. .init_hw_port = bnx2x_init_hw_port,
  10826. .init_hw_func = bnx2x_init_hw_func,
  10827. .reset_hw_cmn = bnx2x_reset_common,
  10828. .reset_hw_port = bnx2x_reset_port,
  10829. .reset_hw_func = bnx2x_reset_func,
  10830. .gunzip_init = bnx2x_gunzip_init,
  10831. .gunzip_end = bnx2x_gunzip_end,
  10832. .init_fw = bnx2x_init_firmware,
  10833. .release_fw = bnx2x_release_firmware,
  10834. };
  10835. void bnx2x__init_func_obj(struct bnx2x *bp)
  10836. {
  10837. /* Prepare DMAE related driver resources */
  10838. bnx2x_setup_dmae(bp);
  10839. bnx2x_init_func_obj(bp, &bp->func_obj,
  10840. bnx2x_sp(bp, func_rdata),
  10841. bnx2x_sp_mapping(bp, func_rdata),
  10842. bnx2x_sp(bp, func_afex_rdata),
  10843. bnx2x_sp_mapping(bp, func_afex_rdata),
  10844. &bnx2x_func_sp_drv);
  10845. }
  10846. /* must be called after sriov-enable */
  10847. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10848. {
  10849. int cid_count = BNX2X_L2_MAX_CID(bp);
  10850. if (IS_SRIOV(bp))
  10851. cid_count += BNX2X_VF_CIDS;
  10852. if (CNIC_SUPPORT(bp))
  10853. cid_count += CNIC_CID_MAX;
  10854. return roundup(cid_count, QM_CID_ROUND);
  10855. }
  10856. /**
  10857. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10858. *
  10859. * @dev: pci device
  10860. *
  10861. */
  10862. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10863. {
  10864. int index;
  10865. u16 control = 0;
  10866. /*
  10867. * If MSI-X is not supported - return number of SBs needed to support
  10868. * one fast path queue: one FP queue + SB for CNIC
  10869. */
  10870. if (!pdev->msix_cap) {
  10871. dev_info(&pdev->dev, "no msix capability found\n");
  10872. return 1 + cnic_cnt;
  10873. }
  10874. dev_info(&pdev->dev, "msix capability found\n");
  10875. /*
  10876. * The value in the PCI configuration space is the index of the last
  10877. * entry, namely one less than the actual size of the table, which is
  10878. * exactly what we want to return from this function: number of all SBs
  10879. * without the default SB.
  10880. * For VFs there is no default SB, then we return (index+1).
  10881. */
  10882. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  10883. index = control & PCI_MSIX_FLAGS_QSIZE;
  10884. return index;
  10885. }
  10886. static int set_max_cos_est(int chip_id)
  10887. {
  10888. switch (chip_id) {
  10889. case BCM57710:
  10890. case BCM57711:
  10891. case BCM57711E:
  10892. return BNX2X_MULTI_TX_COS_E1X;
  10893. case BCM57712:
  10894. case BCM57712_MF:
  10895. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10896. case BCM57800:
  10897. case BCM57800_MF:
  10898. case BCM57810:
  10899. case BCM57810_MF:
  10900. case BCM57840_4_10:
  10901. case BCM57840_2_20:
  10902. case BCM57840_O:
  10903. case BCM57840_MFO:
  10904. case BCM57840_MF:
  10905. case BCM57811:
  10906. case BCM57811_MF:
  10907. return BNX2X_MULTI_TX_COS_E3B0;
  10908. case BCM57712_VF:
  10909. case BCM57800_VF:
  10910. case BCM57810_VF:
  10911. case BCM57840_VF:
  10912. case BCM57811_VF:
  10913. return 1;
  10914. default:
  10915. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10916. return -ENODEV;
  10917. }
  10918. }
  10919. static int set_is_vf(int chip_id)
  10920. {
  10921. switch (chip_id) {
  10922. case BCM57712_VF:
  10923. case BCM57800_VF:
  10924. case BCM57810_VF:
  10925. case BCM57840_VF:
  10926. case BCM57811_VF:
  10927. return true;
  10928. default:
  10929. return false;
  10930. }
  10931. }
  10932. static int bnx2x_init_one(struct pci_dev *pdev,
  10933. const struct pci_device_id *ent)
  10934. {
  10935. struct net_device *dev = NULL;
  10936. struct bnx2x *bp;
  10937. enum pcie_link_width pcie_width;
  10938. enum pci_bus_speed pcie_speed;
  10939. int rc, max_non_def_sbs;
  10940. int rx_count, tx_count, rss_count, doorbell_size;
  10941. int max_cos_est;
  10942. bool is_vf;
  10943. int cnic_cnt;
  10944. /* An estimated maximum supported CoS number according to the chip
  10945. * version.
  10946. * We will try to roughly estimate the maximum number of CoSes this chip
  10947. * may support in order to minimize the memory allocated for Tx
  10948. * netdev_queue's. This number will be accurately calculated during the
  10949. * initialization of bp->max_cos based on the chip versions AND chip
  10950. * revision in the bnx2x_init_bp().
  10951. */
  10952. max_cos_est = set_max_cos_est(ent->driver_data);
  10953. if (max_cos_est < 0)
  10954. return max_cos_est;
  10955. is_vf = set_is_vf(ent->driver_data);
  10956. cnic_cnt = is_vf ? 0 : 1;
  10957. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10958. /* add another SB for VF as it has no default SB */
  10959. max_non_def_sbs += is_vf ? 1 : 0;
  10960. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10961. rss_count = max_non_def_sbs - cnic_cnt;
  10962. if (rss_count < 1)
  10963. return -EINVAL;
  10964. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10965. rx_count = rss_count + cnic_cnt;
  10966. /* Maximum number of netdev Tx queues:
  10967. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10968. */
  10969. tx_count = rss_count * max_cos_est + cnic_cnt;
  10970. /* dev zeroed in init_etherdev */
  10971. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10972. if (!dev)
  10973. return -ENOMEM;
  10974. bp = netdev_priv(dev);
  10975. bp->flags = 0;
  10976. if (is_vf)
  10977. bp->flags |= IS_VF_FLAG;
  10978. bp->igu_sb_cnt = max_non_def_sbs;
  10979. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10980. bp->msg_enable = debug;
  10981. bp->cnic_support = cnic_cnt;
  10982. bp->cnic_probe = bnx2x_cnic_probe;
  10983. pci_set_drvdata(pdev, dev);
  10984. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10985. if (rc < 0) {
  10986. free_netdev(dev);
  10987. return rc;
  10988. }
  10989. BNX2X_DEV_INFO("This is a %s function\n",
  10990. IS_PF(bp) ? "physical" : "virtual");
  10991. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10992. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10993. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10994. tx_count, rx_count);
  10995. rc = bnx2x_init_bp(bp);
  10996. if (rc)
  10997. goto init_one_exit;
  10998. /* Map doorbells here as we need the real value of bp->max_cos which
  10999. * is initialized in bnx2x_init_bp() to determine the number of
  11000. * l2 connections.
  11001. */
  11002. if (IS_VF(bp)) {
  11003. bp->doorbells = bnx2x_vf_doorbells(bp);
  11004. rc = bnx2x_vf_pci_alloc(bp);
  11005. if (rc)
  11006. goto init_one_exit;
  11007. } else {
  11008. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11009. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11010. dev_err(&bp->pdev->dev,
  11011. "Cannot map doorbells, bar size too small, aborting\n");
  11012. rc = -ENOMEM;
  11013. goto init_one_exit;
  11014. }
  11015. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11016. doorbell_size);
  11017. }
  11018. if (!bp->doorbells) {
  11019. dev_err(&bp->pdev->dev,
  11020. "Cannot map doorbell space, aborting\n");
  11021. rc = -ENOMEM;
  11022. goto init_one_exit;
  11023. }
  11024. if (IS_VF(bp)) {
  11025. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11026. if (rc)
  11027. goto init_one_exit;
  11028. }
  11029. /* Enable SRIOV if capability found in configuration space */
  11030. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11031. if (rc)
  11032. goto init_one_exit;
  11033. /* calc qm_cid_count */
  11034. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11035. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11036. /* disable FCOE L2 queue for E1x*/
  11037. if (CHIP_IS_E1x(bp))
  11038. bp->flags |= NO_FCOE_FLAG;
  11039. /* Set bp->num_queues for MSI-X mode*/
  11040. bnx2x_set_num_queues(bp);
  11041. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11042. * needed.
  11043. */
  11044. rc = bnx2x_set_int_mode(bp);
  11045. if (rc) {
  11046. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11047. goto init_one_exit;
  11048. }
  11049. BNX2X_DEV_INFO("set interrupts successfully\n");
  11050. /* register the net device */
  11051. rc = register_netdev(dev);
  11052. if (rc) {
  11053. dev_err(&pdev->dev, "Cannot register net device\n");
  11054. goto init_one_exit;
  11055. }
  11056. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11057. if (!NO_FCOE(bp)) {
  11058. /* Add storage MAC address */
  11059. rtnl_lock();
  11060. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11061. rtnl_unlock();
  11062. }
  11063. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11064. pcie_speed == PCI_SPEED_UNKNOWN ||
  11065. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11066. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11067. else
  11068. BNX2X_DEV_INFO(
  11069. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11070. board_info[ent->driver_data].name,
  11071. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11072. pcie_width,
  11073. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11074. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11075. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11076. "Unknown",
  11077. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11078. return 0;
  11079. init_one_exit:
  11080. bnx2x_disable_pcie_error_reporting(bp);
  11081. if (bp->regview)
  11082. iounmap(bp->regview);
  11083. if (IS_PF(bp) && bp->doorbells)
  11084. iounmap(bp->doorbells);
  11085. free_netdev(dev);
  11086. if (atomic_read(&pdev->enable_cnt) == 1)
  11087. pci_release_regions(pdev);
  11088. pci_disable_device(pdev);
  11089. return rc;
  11090. }
  11091. static void __bnx2x_remove(struct pci_dev *pdev,
  11092. struct net_device *dev,
  11093. struct bnx2x *bp,
  11094. bool remove_netdev)
  11095. {
  11096. /* Delete storage MAC address */
  11097. if (!NO_FCOE(bp)) {
  11098. rtnl_lock();
  11099. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11100. rtnl_unlock();
  11101. }
  11102. #ifdef BCM_DCBNL
  11103. /* Delete app tlvs from dcbnl */
  11104. bnx2x_dcbnl_update_applist(bp, true);
  11105. #endif
  11106. if (IS_PF(bp) &&
  11107. !BP_NOMCP(bp) &&
  11108. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11109. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11110. /* Close the interface - either directly or implicitly */
  11111. if (remove_netdev) {
  11112. unregister_netdev(dev);
  11113. } else {
  11114. rtnl_lock();
  11115. dev_close(dev);
  11116. rtnl_unlock();
  11117. }
  11118. bnx2x_iov_remove_one(bp);
  11119. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11120. if (IS_PF(bp))
  11121. bnx2x_set_power_state(bp, PCI_D0);
  11122. /* Disable MSI/MSI-X */
  11123. bnx2x_disable_msi(bp);
  11124. /* Power off */
  11125. if (IS_PF(bp))
  11126. bnx2x_set_power_state(bp, PCI_D3hot);
  11127. /* Make sure RESET task is not scheduled before continuing */
  11128. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11129. /* send message via vfpf channel to release the resources of this vf */
  11130. if (IS_VF(bp))
  11131. bnx2x_vfpf_release(bp);
  11132. /* Assumes no further PCIe PM changes will occur */
  11133. if (system_state == SYSTEM_POWER_OFF) {
  11134. pci_wake_from_d3(pdev, bp->wol);
  11135. pci_set_power_state(pdev, PCI_D3hot);
  11136. }
  11137. bnx2x_disable_pcie_error_reporting(bp);
  11138. if (remove_netdev) {
  11139. if (bp->regview)
  11140. iounmap(bp->regview);
  11141. /* For vfs, doorbells are part of the regview and were unmapped
  11142. * along with it. FW is only loaded by PF.
  11143. */
  11144. if (IS_PF(bp)) {
  11145. if (bp->doorbells)
  11146. iounmap(bp->doorbells);
  11147. bnx2x_release_firmware(bp);
  11148. } else {
  11149. bnx2x_vf_pci_dealloc(bp);
  11150. }
  11151. bnx2x_free_mem_bp(bp);
  11152. free_netdev(dev);
  11153. if (atomic_read(&pdev->enable_cnt) == 1)
  11154. pci_release_regions(pdev);
  11155. pci_disable_device(pdev);
  11156. }
  11157. }
  11158. static void bnx2x_remove_one(struct pci_dev *pdev)
  11159. {
  11160. struct net_device *dev = pci_get_drvdata(pdev);
  11161. struct bnx2x *bp;
  11162. if (!dev) {
  11163. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11164. return;
  11165. }
  11166. bp = netdev_priv(dev);
  11167. __bnx2x_remove(pdev, dev, bp, true);
  11168. }
  11169. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11170. {
  11171. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11172. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11173. if (CNIC_LOADED(bp))
  11174. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11175. /* Stop Tx */
  11176. bnx2x_tx_disable(bp);
  11177. /* Delete all NAPI objects */
  11178. bnx2x_del_all_napi(bp);
  11179. if (CNIC_LOADED(bp))
  11180. bnx2x_del_all_napi_cnic(bp);
  11181. netdev_reset_tc(bp->dev);
  11182. del_timer_sync(&bp->timer);
  11183. cancel_delayed_work_sync(&bp->sp_task);
  11184. cancel_delayed_work_sync(&bp->period_task);
  11185. spin_lock_bh(&bp->stats_lock);
  11186. bp->stats_state = STATS_STATE_DISABLED;
  11187. spin_unlock_bh(&bp->stats_lock);
  11188. bnx2x_save_statistics(bp);
  11189. netif_carrier_off(bp->dev);
  11190. return 0;
  11191. }
  11192. /**
  11193. * bnx2x_io_error_detected - called when PCI error is detected
  11194. * @pdev: Pointer to PCI device
  11195. * @state: The current pci connection state
  11196. *
  11197. * This function is called after a PCI bus error affecting
  11198. * this device has been detected.
  11199. */
  11200. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11201. pci_channel_state_t state)
  11202. {
  11203. struct net_device *dev = pci_get_drvdata(pdev);
  11204. struct bnx2x *bp = netdev_priv(dev);
  11205. rtnl_lock();
  11206. BNX2X_ERR("IO error detected\n");
  11207. netif_device_detach(dev);
  11208. if (state == pci_channel_io_perm_failure) {
  11209. rtnl_unlock();
  11210. return PCI_ERS_RESULT_DISCONNECT;
  11211. }
  11212. if (netif_running(dev))
  11213. bnx2x_eeh_nic_unload(bp);
  11214. bnx2x_prev_path_mark_eeh(bp);
  11215. pci_disable_device(pdev);
  11216. rtnl_unlock();
  11217. /* Request a slot reset */
  11218. return PCI_ERS_RESULT_NEED_RESET;
  11219. }
  11220. /**
  11221. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11222. * @pdev: Pointer to PCI device
  11223. *
  11224. * Restart the card from scratch, as if from a cold-boot.
  11225. */
  11226. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11227. {
  11228. struct net_device *dev = pci_get_drvdata(pdev);
  11229. struct bnx2x *bp = netdev_priv(dev);
  11230. int i;
  11231. rtnl_lock();
  11232. BNX2X_ERR("IO slot reset initializing...\n");
  11233. if (pci_enable_device(pdev)) {
  11234. dev_err(&pdev->dev,
  11235. "Cannot re-enable PCI device after reset\n");
  11236. rtnl_unlock();
  11237. return PCI_ERS_RESULT_DISCONNECT;
  11238. }
  11239. pci_set_master(pdev);
  11240. pci_restore_state(pdev);
  11241. pci_save_state(pdev);
  11242. if (netif_running(dev))
  11243. bnx2x_set_power_state(bp, PCI_D0);
  11244. if (netif_running(dev)) {
  11245. BNX2X_ERR("IO slot reset --> driver unload\n");
  11246. /* MCP should have been reset; Need to wait for validity */
  11247. bnx2x_init_shmem(bp);
  11248. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11249. u32 v;
  11250. v = SHMEM2_RD(bp,
  11251. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11252. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11253. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11254. }
  11255. bnx2x_drain_tx_queues(bp);
  11256. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11257. bnx2x_netif_stop(bp, 1);
  11258. bnx2x_free_irq(bp);
  11259. /* Report UNLOAD_DONE to MCP */
  11260. bnx2x_send_unload_done(bp, true);
  11261. bp->sp_state = 0;
  11262. bp->port.pmf = 0;
  11263. bnx2x_prev_unload(bp);
  11264. /* We should have reseted the engine, so It's fair to
  11265. * assume the FW will no longer write to the bnx2x driver.
  11266. */
  11267. bnx2x_squeeze_objects(bp);
  11268. bnx2x_free_skbs(bp);
  11269. for_each_rx_queue(bp, i)
  11270. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11271. bnx2x_free_fp_mem(bp);
  11272. bnx2x_free_mem(bp);
  11273. bp->state = BNX2X_STATE_CLOSED;
  11274. }
  11275. rtnl_unlock();
  11276. /* If AER, perform cleanup of the PCIe registers */
  11277. if (bp->flags & AER_ENABLED) {
  11278. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11279. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11280. else
  11281. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11282. }
  11283. return PCI_ERS_RESULT_RECOVERED;
  11284. }
  11285. /**
  11286. * bnx2x_io_resume - called when traffic can start flowing again
  11287. * @pdev: Pointer to PCI device
  11288. *
  11289. * This callback is called when the error recovery driver tells us that
  11290. * its OK to resume normal operation.
  11291. */
  11292. static void bnx2x_io_resume(struct pci_dev *pdev)
  11293. {
  11294. struct net_device *dev = pci_get_drvdata(pdev);
  11295. struct bnx2x *bp = netdev_priv(dev);
  11296. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11297. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11298. return;
  11299. }
  11300. rtnl_lock();
  11301. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11302. DRV_MSG_SEQ_NUMBER_MASK;
  11303. if (netif_running(dev))
  11304. bnx2x_nic_load(bp, LOAD_NORMAL);
  11305. netif_device_attach(dev);
  11306. rtnl_unlock();
  11307. }
  11308. static const struct pci_error_handlers bnx2x_err_handler = {
  11309. .error_detected = bnx2x_io_error_detected,
  11310. .slot_reset = bnx2x_io_slot_reset,
  11311. .resume = bnx2x_io_resume,
  11312. };
  11313. static void bnx2x_shutdown(struct pci_dev *pdev)
  11314. {
  11315. struct net_device *dev = pci_get_drvdata(pdev);
  11316. struct bnx2x *bp;
  11317. if (!dev)
  11318. return;
  11319. bp = netdev_priv(dev);
  11320. if (!bp)
  11321. return;
  11322. rtnl_lock();
  11323. netif_device_detach(dev);
  11324. rtnl_unlock();
  11325. /* Don't remove the netdevice, as there are scenarios which will cause
  11326. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11327. * rootfs is mounted from SAN.
  11328. */
  11329. __bnx2x_remove(pdev, dev, bp, false);
  11330. }
  11331. static struct pci_driver bnx2x_pci_driver = {
  11332. .name = DRV_MODULE_NAME,
  11333. .id_table = bnx2x_pci_tbl,
  11334. .probe = bnx2x_init_one,
  11335. .remove = bnx2x_remove_one,
  11336. .suspend = bnx2x_suspend,
  11337. .resume = bnx2x_resume,
  11338. .err_handler = &bnx2x_err_handler,
  11339. #ifdef CONFIG_BNX2X_SRIOV
  11340. .sriov_configure = bnx2x_sriov_configure,
  11341. #endif
  11342. .shutdown = bnx2x_shutdown,
  11343. };
  11344. static int __init bnx2x_init(void)
  11345. {
  11346. int ret;
  11347. pr_info("%s", version);
  11348. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11349. if (bnx2x_wq == NULL) {
  11350. pr_err("Cannot create workqueue\n");
  11351. return -ENOMEM;
  11352. }
  11353. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11354. if (!bnx2x_iov_wq) {
  11355. pr_err("Cannot create iov workqueue\n");
  11356. destroy_workqueue(bnx2x_wq);
  11357. return -ENOMEM;
  11358. }
  11359. ret = pci_register_driver(&bnx2x_pci_driver);
  11360. if (ret) {
  11361. pr_err("Cannot register driver\n");
  11362. destroy_workqueue(bnx2x_wq);
  11363. destroy_workqueue(bnx2x_iov_wq);
  11364. }
  11365. return ret;
  11366. }
  11367. static void __exit bnx2x_cleanup(void)
  11368. {
  11369. struct list_head *pos, *q;
  11370. pci_unregister_driver(&bnx2x_pci_driver);
  11371. destroy_workqueue(bnx2x_wq);
  11372. destroy_workqueue(bnx2x_iov_wq);
  11373. /* Free globally allocated resources */
  11374. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11375. struct bnx2x_prev_path_list *tmp =
  11376. list_entry(pos, struct bnx2x_prev_path_list, list);
  11377. list_del(pos);
  11378. kfree(tmp);
  11379. }
  11380. }
  11381. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11382. {
  11383. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11384. }
  11385. module_init(bnx2x_init);
  11386. module_exit(bnx2x_cleanup);
  11387. /**
  11388. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11389. *
  11390. * @bp: driver handle
  11391. * @set: set or clear the CAM entry
  11392. *
  11393. * This function will wait until the ramrod completion returns.
  11394. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11395. */
  11396. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11397. {
  11398. unsigned long ramrod_flags = 0;
  11399. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11400. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11401. &bp->iscsi_l2_mac_obj, true,
  11402. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11403. }
  11404. /* count denotes the number of new completions we have seen */
  11405. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11406. {
  11407. struct eth_spe *spe;
  11408. int cxt_index, cxt_offset;
  11409. #ifdef BNX2X_STOP_ON_ERROR
  11410. if (unlikely(bp->panic))
  11411. return;
  11412. #endif
  11413. spin_lock_bh(&bp->spq_lock);
  11414. BUG_ON(bp->cnic_spq_pending < count);
  11415. bp->cnic_spq_pending -= count;
  11416. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11417. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11418. & SPE_HDR_CONN_TYPE) >>
  11419. SPE_HDR_CONN_TYPE_SHIFT;
  11420. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11421. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11422. /* Set validation for iSCSI L2 client before sending SETUP
  11423. * ramrod
  11424. */
  11425. if (type == ETH_CONNECTION_TYPE) {
  11426. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11427. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11428. ILT_PAGE_CIDS;
  11429. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11430. (cxt_index * ILT_PAGE_CIDS);
  11431. bnx2x_set_ctx_validation(bp,
  11432. &bp->context[cxt_index].
  11433. vcxt[cxt_offset].eth,
  11434. BNX2X_ISCSI_ETH_CID(bp));
  11435. }
  11436. }
  11437. /*
  11438. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11439. * and in the air. We also check that number of outstanding
  11440. * COMMON ramrods is not more than the EQ and SPQ can
  11441. * accommodate.
  11442. */
  11443. if (type == ETH_CONNECTION_TYPE) {
  11444. if (!atomic_read(&bp->cq_spq_left))
  11445. break;
  11446. else
  11447. atomic_dec(&bp->cq_spq_left);
  11448. } else if (type == NONE_CONNECTION_TYPE) {
  11449. if (!atomic_read(&bp->eq_spq_left))
  11450. break;
  11451. else
  11452. atomic_dec(&bp->eq_spq_left);
  11453. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11454. (type == FCOE_CONNECTION_TYPE)) {
  11455. if (bp->cnic_spq_pending >=
  11456. bp->cnic_eth_dev.max_kwqe_pending)
  11457. break;
  11458. else
  11459. bp->cnic_spq_pending++;
  11460. } else {
  11461. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11462. bnx2x_panic();
  11463. break;
  11464. }
  11465. spe = bnx2x_sp_get_next(bp);
  11466. *spe = *bp->cnic_kwq_cons;
  11467. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11468. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11469. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11470. bp->cnic_kwq_cons = bp->cnic_kwq;
  11471. else
  11472. bp->cnic_kwq_cons++;
  11473. }
  11474. bnx2x_sp_prod_update(bp);
  11475. spin_unlock_bh(&bp->spq_lock);
  11476. }
  11477. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11478. struct kwqe_16 *kwqes[], u32 count)
  11479. {
  11480. struct bnx2x *bp = netdev_priv(dev);
  11481. int i;
  11482. #ifdef BNX2X_STOP_ON_ERROR
  11483. if (unlikely(bp->panic)) {
  11484. BNX2X_ERR("Can't post to SP queue while panic\n");
  11485. return -EIO;
  11486. }
  11487. #endif
  11488. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11489. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11490. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11491. return -EAGAIN;
  11492. }
  11493. spin_lock_bh(&bp->spq_lock);
  11494. for (i = 0; i < count; i++) {
  11495. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11496. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11497. break;
  11498. *bp->cnic_kwq_prod = *spe;
  11499. bp->cnic_kwq_pending++;
  11500. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11501. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11502. spe->data.update_data_addr.hi,
  11503. spe->data.update_data_addr.lo,
  11504. bp->cnic_kwq_pending);
  11505. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11506. bp->cnic_kwq_prod = bp->cnic_kwq;
  11507. else
  11508. bp->cnic_kwq_prod++;
  11509. }
  11510. spin_unlock_bh(&bp->spq_lock);
  11511. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11512. bnx2x_cnic_sp_post(bp, 0);
  11513. return i;
  11514. }
  11515. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11516. {
  11517. struct cnic_ops *c_ops;
  11518. int rc = 0;
  11519. mutex_lock(&bp->cnic_mutex);
  11520. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11521. lockdep_is_held(&bp->cnic_mutex));
  11522. if (c_ops)
  11523. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11524. mutex_unlock(&bp->cnic_mutex);
  11525. return rc;
  11526. }
  11527. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11528. {
  11529. struct cnic_ops *c_ops;
  11530. int rc = 0;
  11531. rcu_read_lock();
  11532. c_ops = rcu_dereference(bp->cnic_ops);
  11533. if (c_ops)
  11534. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11535. rcu_read_unlock();
  11536. return rc;
  11537. }
  11538. /*
  11539. * for commands that have no data
  11540. */
  11541. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11542. {
  11543. struct cnic_ctl_info ctl = {0};
  11544. ctl.cmd = cmd;
  11545. return bnx2x_cnic_ctl_send(bp, &ctl);
  11546. }
  11547. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11548. {
  11549. struct cnic_ctl_info ctl = {0};
  11550. /* first we tell CNIC and only then we count this as a completion */
  11551. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11552. ctl.data.comp.cid = cid;
  11553. ctl.data.comp.error = err;
  11554. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11555. bnx2x_cnic_sp_post(bp, 0);
  11556. }
  11557. /* Called with netif_addr_lock_bh() taken.
  11558. * Sets an rx_mode config for an iSCSI ETH client.
  11559. * Doesn't block.
  11560. * Completion should be checked outside.
  11561. */
  11562. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11563. {
  11564. unsigned long accept_flags = 0, ramrod_flags = 0;
  11565. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11566. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11567. if (start) {
  11568. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11569. * because it's the only way for UIO Queue to accept
  11570. * multicasts (in non-promiscuous mode only one Queue per
  11571. * function will receive multicast packets (leading in our
  11572. * case).
  11573. */
  11574. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11575. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11576. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11577. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11578. /* Clear STOP_PENDING bit if START is requested */
  11579. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11580. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11581. } else
  11582. /* Clear START_PENDING bit if STOP is requested */
  11583. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11584. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11585. set_bit(sched_state, &bp->sp_state);
  11586. else {
  11587. __set_bit(RAMROD_RX, &ramrod_flags);
  11588. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11589. ramrod_flags);
  11590. }
  11591. }
  11592. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11593. {
  11594. struct bnx2x *bp = netdev_priv(dev);
  11595. int rc = 0;
  11596. switch (ctl->cmd) {
  11597. case DRV_CTL_CTXTBL_WR_CMD: {
  11598. u32 index = ctl->data.io.offset;
  11599. dma_addr_t addr = ctl->data.io.dma_addr;
  11600. bnx2x_ilt_wr(bp, index, addr);
  11601. break;
  11602. }
  11603. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11604. int count = ctl->data.credit.credit_count;
  11605. bnx2x_cnic_sp_post(bp, count);
  11606. break;
  11607. }
  11608. /* rtnl_lock is held. */
  11609. case DRV_CTL_START_L2_CMD: {
  11610. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11611. unsigned long sp_bits = 0;
  11612. /* Configure the iSCSI classification object */
  11613. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11614. cp->iscsi_l2_client_id,
  11615. cp->iscsi_l2_cid, BP_FUNC(bp),
  11616. bnx2x_sp(bp, mac_rdata),
  11617. bnx2x_sp_mapping(bp, mac_rdata),
  11618. BNX2X_FILTER_MAC_PENDING,
  11619. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11620. &bp->macs_pool);
  11621. /* Set iSCSI MAC address */
  11622. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11623. if (rc)
  11624. break;
  11625. mmiowb();
  11626. barrier();
  11627. /* Start accepting on iSCSI L2 ring */
  11628. netif_addr_lock_bh(dev);
  11629. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11630. netif_addr_unlock_bh(dev);
  11631. /* bits to wait on */
  11632. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11633. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11634. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11635. BNX2X_ERR("rx_mode completion timed out!\n");
  11636. break;
  11637. }
  11638. /* rtnl_lock is held. */
  11639. case DRV_CTL_STOP_L2_CMD: {
  11640. unsigned long sp_bits = 0;
  11641. /* Stop accepting on iSCSI L2 ring */
  11642. netif_addr_lock_bh(dev);
  11643. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11644. netif_addr_unlock_bh(dev);
  11645. /* bits to wait on */
  11646. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11647. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11648. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11649. BNX2X_ERR("rx_mode completion timed out!\n");
  11650. mmiowb();
  11651. barrier();
  11652. /* Unset iSCSI L2 MAC */
  11653. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11654. BNX2X_ISCSI_ETH_MAC, true);
  11655. break;
  11656. }
  11657. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11658. int count = ctl->data.credit.credit_count;
  11659. smp_mb__before_atomic();
  11660. atomic_add(count, &bp->cq_spq_left);
  11661. smp_mb__after_atomic();
  11662. break;
  11663. }
  11664. case DRV_CTL_ULP_REGISTER_CMD: {
  11665. int ulp_type = ctl->data.register_data.ulp_type;
  11666. if (CHIP_IS_E3(bp)) {
  11667. int idx = BP_FW_MB_IDX(bp);
  11668. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11669. int path = BP_PATH(bp);
  11670. int port = BP_PORT(bp);
  11671. int i;
  11672. u32 scratch_offset;
  11673. u32 *host_addr;
  11674. /* first write capability to shmem2 */
  11675. if (ulp_type == CNIC_ULP_ISCSI)
  11676. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11677. else if (ulp_type == CNIC_ULP_FCOE)
  11678. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11679. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11680. if ((ulp_type != CNIC_ULP_FCOE) ||
  11681. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11682. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11683. break;
  11684. /* if reached here - should write fcoe capabilities */
  11685. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11686. if (!scratch_offset)
  11687. break;
  11688. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11689. fcoe_features[path][port]);
  11690. host_addr = (u32 *) &(ctl->data.register_data.
  11691. fcoe_features);
  11692. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11693. i += 4)
  11694. REG_WR(bp, scratch_offset + i,
  11695. *(host_addr + i/4));
  11696. }
  11697. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11698. break;
  11699. }
  11700. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11701. int ulp_type = ctl->data.ulp_type;
  11702. if (CHIP_IS_E3(bp)) {
  11703. int idx = BP_FW_MB_IDX(bp);
  11704. u32 cap;
  11705. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11706. if (ulp_type == CNIC_ULP_ISCSI)
  11707. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11708. else if (ulp_type == CNIC_ULP_FCOE)
  11709. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11710. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11711. }
  11712. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11713. break;
  11714. }
  11715. default:
  11716. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11717. rc = -EINVAL;
  11718. }
  11719. return rc;
  11720. }
  11721. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11722. {
  11723. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11724. if (bp->flags & USING_MSIX_FLAG) {
  11725. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11726. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11727. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11728. } else {
  11729. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11730. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11731. }
  11732. if (!CHIP_IS_E1x(bp))
  11733. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11734. else
  11735. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11736. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11737. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11738. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11739. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11740. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11741. cp->num_irq = 2;
  11742. }
  11743. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11744. {
  11745. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11746. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11747. bnx2x_cid_ilt_lines(bp);
  11748. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11749. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11750. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11751. 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",
  11752. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11753. cp->iscsi_l2_cid);
  11754. if (NO_ISCSI_OOO(bp))
  11755. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11756. }
  11757. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11758. void *data)
  11759. {
  11760. struct bnx2x *bp = netdev_priv(dev);
  11761. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11762. int rc;
  11763. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11764. if (ops == NULL) {
  11765. BNX2X_ERR("NULL ops received\n");
  11766. return -EINVAL;
  11767. }
  11768. if (!CNIC_SUPPORT(bp)) {
  11769. BNX2X_ERR("Can't register CNIC when not supported\n");
  11770. return -EOPNOTSUPP;
  11771. }
  11772. if (!CNIC_LOADED(bp)) {
  11773. rc = bnx2x_load_cnic(bp);
  11774. if (rc) {
  11775. BNX2X_ERR("CNIC-related load failed\n");
  11776. return rc;
  11777. }
  11778. }
  11779. bp->cnic_enabled = true;
  11780. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11781. if (!bp->cnic_kwq)
  11782. return -ENOMEM;
  11783. bp->cnic_kwq_cons = bp->cnic_kwq;
  11784. bp->cnic_kwq_prod = bp->cnic_kwq;
  11785. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11786. bp->cnic_spq_pending = 0;
  11787. bp->cnic_kwq_pending = 0;
  11788. bp->cnic_data = data;
  11789. cp->num_irq = 0;
  11790. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11791. cp->iro_arr = bp->iro_arr;
  11792. bnx2x_setup_cnic_irq_info(bp);
  11793. rcu_assign_pointer(bp->cnic_ops, ops);
  11794. /* Schedule driver to read CNIC driver versions */
  11795. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11796. return 0;
  11797. }
  11798. static int bnx2x_unregister_cnic(struct net_device *dev)
  11799. {
  11800. struct bnx2x *bp = netdev_priv(dev);
  11801. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11802. mutex_lock(&bp->cnic_mutex);
  11803. cp->drv_state = 0;
  11804. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11805. mutex_unlock(&bp->cnic_mutex);
  11806. synchronize_rcu();
  11807. bp->cnic_enabled = false;
  11808. kfree(bp->cnic_kwq);
  11809. bp->cnic_kwq = NULL;
  11810. return 0;
  11811. }
  11812. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11813. {
  11814. struct bnx2x *bp = netdev_priv(dev);
  11815. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11816. /* If both iSCSI and FCoE are disabled - return NULL in
  11817. * order to indicate CNIC that it should not try to work
  11818. * with this device.
  11819. */
  11820. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11821. return NULL;
  11822. cp->drv_owner = THIS_MODULE;
  11823. cp->chip_id = CHIP_ID(bp);
  11824. cp->pdev = bp->pdev;
  11825. cp->io_base = bp->regview;
  11826. cp->io_base2 = bp->doorbells;
  11827. cp->max_kwqe_pending = 8;
  11828. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11829. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11830. bnx2x_cid_ilt_lines(bp);
  11831. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11832. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11833. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11834. cp->drv_ctl = bnx2x_drv_ctl;
  11835. cp->drv_register_cnic = bnx2x_register_cnic;
  11836. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11837. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11838. cp->iscsi_l2_client_id =
  11839. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11840. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11841. if (NO_ISCSI_OOO(bp))
  11842. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11843. if (NO_ISCSI(bp))
  11844. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11845. if (NO_FCOE(bp))
  11846. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11847. BNX2X_DEV_INFO(
  11848. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11849. cp->ctx_blk_size,
  11850. cp->ctx_tbl_offset,
  11851. cp->ctx_tbl_len,
  11852. cp->starting_cid);
  11853. return cp;
  11854. }
  11855. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11856. {
  11857. struct bnx2x *bp = fp->bp;
  11858. u32 offset = BAR_USTRORM_INTMEM;
  11859. if (IS_VF(bp))
  11860. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11861. else if (!CHIP_IS_E1x(bp))
  11862. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11863. else
  11864. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11865. return offset;
  11866. }
  11867. /* called only on E1H or E2.
  11868. * When pretending to be PF, the pretend value is the function number 0...7
  11869. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11870. * combination
  11871. */
  11872. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11873. {
  11874. u32 pretend_reg;
  11875. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11876. return -1;
  11877. /* get my own pretend register */
  11878. pretend_reg = bnx2x_get_pretend_reg(bp);
  11879. REG_WR(bp, pretend_reg, pretend_func_val);
  11880. REG_RD(bp, pretend_reg);
  11881. return 0;
  11882. }