bnx2x_main.c 384 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175
  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 const struct pci_device_id 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_sample_bulletin(bp);
  2286. /* if bulletin board did not have an update for link status
  2287. * __bnx2x_link_report will report current status
  2288. * but it will NOT duplicate report in case of already reported
  2289. * during sampling bulletin board.
  2290. */
  2291. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2292. }
  2293. }
  2294. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2295. u16 vlan_val, u8 allowed_prio)
  2296. {
  2297. struct bnx2x_func_state_params func_params = {NULL};
  2298. struct bnx2x_func_afex_update_params *f_update_params =
  2299. &func_params.params.afex_update;
  2300. func_params.f_obj = &bp->func_obj;
  2301. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2302. /* no need to wait for RAMROD completion, so don't
  2303. * set RAMROD_COMP_WAIT flag
  2304. */
  2305. f_update_params->vif_id = vifid;
  2306. f_update_params->afex_default_vlan = vlan_val;
  2307. f_update_params->allowed_priorities = allowed_prio;
  2308. /* if ramrod can not be sent, response to MCP immediately */
  2309. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2310. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2311. return 0;
  2312. }
  2313. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2314. u16 vif_index, u8 func_bit_map)
  2315. {
  2316. struct bnx2x_func_state_params func_params = {NULL};
  2317. struct bnx2x_func_afex_viflists_params *update_params =
  2318. &func_params.params.afex_viflists;
  2319. int rc;
  2320. u32 drv_msg_code;
  2321. /* validate only LIST_SET and LIST_GET are received from switch */
  2322. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2323. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2324. cmd_type);
  2325. func_params.f_obj = &bp->func_obj;
  2326. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2327. /* set parameters according to cmd_type */
  2328. update_params->afex_vif_list_command = cmd_type;
  2329. update_params->vif_list_index = vif_index;
  2330. update_params->func_bit_map =
  2331. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2332. update_params->func_to_clear = 0;
  2333. drv_msg_code =
  2334. (cmd_type == VIF_LIST_RULE_GET) ?
  2335. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2336. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2337. /* if ramrod can not be sent, respond to MCP immediately for
  2338. * SET and GET requests (other are not triggered from MCP)
  2339. */
  2340. rc = bnx2x_func_state_change(bp, &func_params);
  2341. if (rc < 0)
  2342. bnx2x_fw_command(bp, drv_msg_code, 0);
  2343. return 0;
  2344. }
  2345. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2346. {
  2347. struct afex_stats afex_stats;
  2348. u32 func = BP_ABS_FUNC(bp);
  2349. u32 mf_config;
  2350. u16 vlan_val;
  2351. u32 vlan_prio;
  2352. u16 vif_id;
  2353. u8 allowed_prio;
  2354. u8 vlan_mode;
  2355. u32 addr_to_write, vifid, addrs, stats_type, i;
  2356. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2357. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2358. DP(BNX2X_MSG_MCP,
  2359. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2360. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2361. }
  2362. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2363. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2364. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2365. DP(BNX2X_MSG_MCP,
  2366. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2367. vifid, addrs);
  2368. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2369. addrs);
  2370. }
  2371. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2372. addr_to_write = SHMEM2_RD(bp,
  2373. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2374. stats_type = SHMEM2_RD(bp,
  2375. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2376. DP(BNX2X_MSG_MCP,
  2377. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2378. addr_to_write);
  2379. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2380. /* write response to scratchpad, for MCP */
  2381. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2382. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2383. *(((u32 *)(&afex_stats))+i));
  2384. /* send ack message to MCP */
  2385. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2386. }
  2387. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2388. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2389. bp->mf_config[BP_VN(bp)] = mf_config;
  2390. DP(BNX2X_MSG_MCP,
  2391. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2392. mf_config);
  2393. /* if VIF_SET is "enabled" */
  2394. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2395. /* set rate limit directly to internal RAM */
  2396. struct cmng_init_input cmng_input;
  2397. struct rate_shaping_vars_per_vn m_rs_vn;
  2398. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2399. u32 addr = BAR_XSTRORM_INTMEM +
  2400. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2401. bp->mf_config[BP_VN(bp)] = mf_config;
  2402. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2403. m_rs_vn.vn_counter.rate =
  2404. cmng_input.vnic_max_rate[BP_VN(bp)];
  2405. m_rs_vn.vn_counter.quota =
  2406. (m_rs_vn.vn_counter.rate *
  2407. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2408. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2409. /* read relevant values from mf_cfg struct in shmem */
  2410. vif_id =
  2411. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2412. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2413. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2414. vlan_val =
  2415. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2416. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2417. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2418. vlan_prio = (mf_config &
  2419. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2420. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2421. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2422. vlan_mode =
  2423. (MF_CFG_RD(bp,
  2424. func_mf_config[func].afex_config) &
  2425. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2426. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2427. allowed_prio =
  2428. (MF_CFG_RD(bp,
  2429. func_mf_config[func].afex_config) &
  2430. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2431. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2432. /* send ramrod to FW, return in case of failure */
  2433. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2434. allowed_prio))
  2435. return;
  2436. bp->afex_def_vlan_tag = vlan_val;
  2437. bp->afex_vlan_mode = vlan_mode;
  2438. } else {
  2439. /* notify link down because BP->flags is disabled */
  2440. bnx2x_link_report(bp);
  2441. /* send INVALID VIF ramrod to FW */
  2442. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2443. /* Reset the default afex VLAN */
  2444. bp->afex_def_vlan_tag = -1;
  2445. }
  2446. }
  2447. }
  2448. static void bnx2x_pmf_update(struct bnx2x *bp)
  2449. {
  2450. int port = BP_PORT(bp);
  2451. u32 val;
  2452. bp->port.pmf = 1;
  2453. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2454. /*
  2455. * We need the mb() to ensure the ordering between the writing to
  2456. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2457. */
  2458. smp_mb();
  2459. /* queue a periodic task */
  2460. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2461. bnx2x_dcbx_pmf_update(bp);
  2462. /* enable nig attention */
  2463. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2464. if (bp->common.int_block == INT_BLOCK_HC) {
  2465. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2466. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2467. } else if (!CHIP_IS_E1x(bp)) {
  2468. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2469. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2470. }
  2471. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2472. }
  2473. /* end of Link */
  2474. /* slow path */
  2475. /*
  2476. * General service functions
  2477. */
  2478. /* send the MCP a request, block until there is a reply */
  2479. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2480. {
  2481. int mb_idx = BP_FW_MB_IDX(bp);
  2482. u32 seq;
  2483. u32 rc = 0;
  2484. u32 cnt = 1;
  2485. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2486. mutex_lock(&bp->fw_mb_mutex);
  2487. seq = ++bp->fw_seq;
  2488. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2489. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2490. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2491. (command | seq), param);
  2492. do {
  2493. /* let the FW do it's magic ... */
  2494. msleep(delay);
  2495. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2496. /* Give the FW up to 5 second (500*10ms) */
  2497. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2498. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2499. cnt*delay, rc, seq);
  2500. /* is this a reply to our command? */
  2501. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2502. rc &= FW_MSG_CODE_MASK;
  2503. else {
  2504. /* FW BUG! */
  2505. BNX2X_ERR("FW failed to respond!\n");
  2506. bnx2x_fw_dump(bp);
  2507. rc = 0;
  2508. }
  2509. mutex_unlock(&bp->fw_mb_mutex);
  2510. return rc;
  2511. }
  2512. static void storm_memset_func_cfg(struct bnx2x *bp,
  2513. struct tstorm_eth_function_common_config *tcfg,
  2514. u16 abs_fid)
  2515. {
  2516. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2517. u32 addr = BAR_TSTRORM_INTMEM +
  2518. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2519. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2520. }
  2521. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2522. {
  2523. if (CHIP_IS_E1x(bp)) {
  2524. struct tstorm_eth_function_common_config tcfg = {0};
  2525. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2526. }
  2527. /* Enable the function in the FW */
  2528. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2529. storm_memset_func_en(bp, p->func_id, 1);
  2530. /* spq */
  2531. if (p->func_flgs & FUNC_FLG_SPQ) {
  2532. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2533. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2534. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2535. }
  2536. }
  2537. /**
  2538. * bnx2x_get_common_flags - Return common flags
  2539. *
  2540. * @bp device handle
  2541. * @fp queue handle
  2542. * @zero_stats TRUE if statistics zeroing is needed
  2543. *
  2544. * Return the flags that are common for the Tx-only and not normal connections.
  2545. */
  2546. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2547. struct bnx2x_fastpath *fp,
  2548. bool zero_stats)
  2549. {
  2550. unsigned long flags = 0;
  2551. /* PF driver will always initialize the Queue to an ACTIVE state */
  2552. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2553. /* tx only connections collect statistics (on the same index as the
  2554. * parent connection). The statistics are zeroed when the parent
  2555. * connection is initialized.
  2556. */
  2557. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2558. if (zero_stats)
  2559. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2560. if (bp->flags & TX_SWITCHING)
  2561. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2562. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2563. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2564. #ifdef BNX2X_STOP_ON_ERROR
  2565. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2566. #endif
  2567. return flags;
  2568. }
  2569. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2570. struct bnx2x_fastpath *fp,
  2571. bool leading)
  2572. {
  2573. unsigned long flags = 0;
  2574. /* calculate other queue flags */
  2575. if (IS_MF_SD(bp))
  2576. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2577. if (IS_FCOE_FP(fp)) {
  2578. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2579. /* For FCoE - force usage of default priority (for afex) */
  2580. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2581. }
  2582. if (!fp->disable_tpa) {
  2583. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2584. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2585. if (fp->mode == TPA_MODE_GRO)
  2586. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2587. }
  2588. if (leading) {
  2589. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2590. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2591. }
  2592. /* Always set HW VLAN stripping */
  2593. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2594. /* configure silent vlan removal */
  2595. if (IS_MF_AFEX(bp))
  2596. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2597. return flags | bnx2x_get_common_flags(bp, fp, true);
  2598. }
  2599. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2600. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2601. u8 cos)
  2602. {
  2603. gen_init->stat_id = bnx2x_stats_id(fp);
  2604. gen_init->spcl_id = fp->cl_id;
  2605. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2606. if (IS_FCOE_FP(fp))
  2607. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2608. else
  2609. gen_init->mtu = bp->dev->mtu;
  2610. gen_init->cos = cos;
  2611. }
  2612. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2613. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2614. struct bnx2x_rxq_setup_params *rxq_init)
  2615. {
  2616. u8 max_sge = 0;
  2617. u16 sge_sz = 0;
  2618. u16 tpa_agg_size = 0;
  2619. if (!fp->disable_tpa) {
  2620. pause->sge_th_lo = SGE_TH_LO(bp);
  2621. pause->sge_th_hi = SGE_TH_HI(bp);
  2622. /* validate SGE ring has enough to cross high threshold */
  2623. WARN_ON(bp->dropless_fc &&
  2624. pause->sge_th_hi + FW_PREFETCH_CNT >
  2625. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2626. tpa_agg_size = TPA_AGG_SIZE;
  2627. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2628. SGE_PAGE_SHIFT;
  2629. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2630. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2631. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2632. }
  2633. /* pause - not for e1 */
  2634. if (!CHIP_IS_E1(bp)) {
  2635. pause->bd_th_lo = BD_TH_LO(bp);
  2636. pause->bd_th_hi = BD_TH_HI(bp);
  2637. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2638. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2639. /*
  2640. * validate that rings have enough entries to cross
  2641. * high thresholds
  2642. */
  2643. WARN_ON(bp->dropless_fc &&
  2644. pause->bd_th_hi + FW_PREFETCH_CNT >
  2645. bp->rx_ring_size);
  2646. WARN_ON(bp->dropless_fc &&
  2647. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2648. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2649. pause->pri_map = 1;
  2650. }
  2651. /* rxq setup */
  2652. rxq_init->dscr_map = fp->rx_desc_mapping;
  2653. rxq_init->sge_map = fp->rx_sge_mapping;
  2654. rxq_init->rcq_map = fp->rx_comp_mapping;
  2655. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2656. /* This should be a maximum number of data bytes that may be
  2657. * placed on the BD (not including paddings).
  2658. */
  2659. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2660. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2661. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2662. rxq_init->tpa_agg_sz = tpa_agg_size;
  2663. rxq_init->sge_buf_sz = sge_sz;
  2664. rxq_init->max_sges_pkt = max_sge;
  2665. rxq_init->rss_engine_id = BP_FUNC(bp);
  2666. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2667. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2668. *
  2669. * For PF Clients it should be the maximum available number.
  2670. * VF driver(s) may want to define it to a smaller value.
  2671. */
  2672. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2673. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2674. rxq_init->fw_sb_id = fp->fw_sb_id;
  2675. if (IS_FCOE_FP(fp))
  2676. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2677. else
  2678. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2679. /* configure silent vlan removal
  2680. * if multi function mode is afex, then mask default vlan
  2681. */
  2682. if (IS_MF_AFEX(bp)) {
  2683. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2684. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2685. }
  2686. }
  2687. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2688. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2689. u8 cos)
  2690. {
  2691. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2692. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2693. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2694. txq_init->fw_sb_id = fp->fw_sb_id;
  2695. /*
  2696. * set the tss leading client id for TX classification ==
  2697. * leading RSS client id
  2698. */
  2699. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2700. if (IS_FCOE_FP(fp)) {
  2701. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2702. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2703. }
  2704. }
  2705. static void bnx2x_pf_init(struct bnx2x *bp)
  2706. {
  2707. struct bnx2x_func_init_params func_init = {0};
  2708. struct event_ring_data eq_data = { {0} };
  2709. u16 flags;
  2710. if (!CHIP_IS_E1x(bp)) {
  2711. /* reset IGU PF statistics: MSIX + ATTN */
  2712. /* PF */
  2713. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2714. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2715. (CHIP_MODE_IS_4_PORT(bp) ?
  2716. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2717. /* ATTN */
  2718. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2719. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2720. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2721. (CHIP_MODE_IS_4_PORT(bp) ?
  2722. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2723. }
  2724. /* function setup flags */
  2725. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2726. /* This flag is relevant for E1x only.
  2727. * E2 doesn't have a TPA configuration in a function level.
  2728. */
  2729. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2730. func_init.func_flgs = flags;
  2731. func_init.pf_id = BP_FUNC(bp);
  2732. func_init.func_id = BP_FUNC(bp);
  2733. func_init.spq_map = bp->spq_mapping;
  2734. func_init.spq_prod = bp->spq_prod_idx;
  2735. bnx2x_func_init(bp, &func_init);
  2736. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2737. /*
  2738. * Congestion management values depend on the link rate
  2739. * There is no active link so initial link rate is set to 10 Gbps.
  2740. * When the link comes up The congestion management values are
  2741. * re-calculated according to the actual link rate.
  2742. */
  2743. bp->link_vars.line_speed = SPEED_10000;
  2744. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2745. /* Only the PMF sets the HW */
  2746. if (bp->port.pmf)
  2747. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2748. /* init Event Queue - PCI bus guarantees correct endianity*/
  2749. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2750. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2751. eq_data.producer = bp->eq_prod;
  2752. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2753. eq_data.sb_id = DEF_SB_ID;
  2754. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2755. }
  2756. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2757. {
  2758. int port = BP_PORT(bp);
  2759. bnx2x_tx_disable(bp);
  2760. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2761. }
  2762. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2763. {
  2764. int port = BP_PORT(bp);
  2765. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2766. /* Tx queue should be only re-enabled */
  2767. netif_tx_wake_all_queues(bp->dev);
  2768. /*
  2769. * Should not call netif_carrier_on since it will be called if the link
  2770. * is up when checking for link state
  2771. */
  2772. }
  2773. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2774. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2775. {
  2776. struct eth_stats_info *ether_stat =
  2777. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2778. struct bnx2x_vlan_mac_obj *mac_obj =
  2779. &bp->sp_objs->mac_obj;
  2780. int i;
  2781. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2782. ETH_STAT_INFO_VERSION_LEN);
  2783. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2784. * mac_local field in ether_stat struct. The base address is offset by 2
  2785. * bytes to account for the field being 8 bytes but a mac address is
  2786. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2787. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2788. * allocated by the ether_stat struct, so the macs will land in their
  2789. * proper positions.
  2790. */
  2791. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2792. memset(ether_stat->mac_local + i, 0,
  2793. sizeof(ether_stat->mac_local[0]));
  2794. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2795. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2796. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2797. ETH_ALEN);
  2798. ether_stat->mtu_size = bp->dev->mtu;
  2799. if (bp->dev->features & NETIF_F_RXCSUM)
  2800. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2801. if (bp->dev->features & NETIF_F_TSO)
  2802. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2803. ether_stat->feature_flags |= bp->common.boot_mode;
  2804. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2805. ether_stat->txq_size = bp->tx_ring_size;
  2806. ether_stat->rxq_size = bp->rx_ring_size;
  2807. #ifdef CONFIG_BNX2X_SRIOV
  2808. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2809. #endif
  2810. }
  2811. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2812. {
  2813. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2814. struct fcoe_stats_info *fcoe_stat =
  2815. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2816. if (!CNIC_LOADED(bp))
  2817. return;
  2818. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2819. fcoe_stat->qos_priority =
  2820. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2821. /* insert FCoE stats from ramrod response */
  2822. if (!NO_FCOE(bp)) {
  2823. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2824. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2825. tstorm_queue_statistics;
  2826. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2827. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2828. xstorm_queue_statistics;
  2829. struct fcoe_statistics_params *fw_fcoe_stat =
  2830. &bp->fw_stats_data->fcoe;
  2831. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2832. fcoe_stat->rx_bytes_lo,
  2833. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2834. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2835. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2836. fcoe_stat->rx_bytes_lo,
  2837. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2838. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2839. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2840. fcoe_stat->rx_bytes_lo,
  2841. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2842. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2843. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2844. fcoe_stat->rx_bytes_lo,
  2845. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2846. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2847. fcoe_stat->rx_frames_lo,
  2848. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2849. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2850. fcoe_stat->rx_frames_lo,
  2851. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2852. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2853. fcoe_stat->rx_frames_lo,
  2854. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2855. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2856. fcoe_stat->rx_frames_lo,
  2857. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2858. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2859. fcoe_stat->tx_bytes_lo,
  2860. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2861. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2862. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2863. fcoe_stat->tx_bytes_lo,
  2864. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2865. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2866. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2867. fcoe_stat->tx_bytes_lo,
  2868. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2869. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2870. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2871. fcoe_stat->tx_bytes_lo,
  2872. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2873. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2874. fcoe_stat->tx_frames_lo,
  2875. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2876. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2877. fcoe_stat->tx_frames_lo,
  2878. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2879. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2880. fcoe_stat->tx_frames_lo,
  2881. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2882. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2883. fcoe_stat->tx_frames_lo,
  2884. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2885. }
  2886. /* ask L5 driver to add data to the struct */
  2887. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2888. }
  2889. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2890. {
  2891. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2892. struct iscsi_stats_info *iscsi_stat =
  2893. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2894. if (!CNIC_LOADED(bp))
  2895. return;
  2896. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2897. ETH_ALEN);
  2898. iscsi_stat->qos_priority =
  2899. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2900. /* ask L5 driver to add data to the struct */
  2901. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2902. }
  2903. /* called due to MCP event (on pmf):
  2904. * reread new bandwidth configuration
  2905. * configure FW
  2906. * notify others function about the change
  2907. */
  2908. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2909. {
  2910. if (bp->link_vars.link_up) {
  2911. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2912. bnx2x_link_sync_notify(bp);
  2913. }
  2914. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2915. }
  2916. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2917. {
  2918. bnx2x_config_mf_bw(bp);
  2919. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2920. }
  2921. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2922. {
  2923. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2924. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2925. }
  2926. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2927. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2928. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2929. {
  2930. enum drv_info_opcode op_code;
  2931. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2932. bool release = false;
  2933. int wait;
  2934. /* if drv_info version supported by MFW doesn't match - send NACK */
  2935. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2936. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2937. return;
  2938. }
  2939. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2940. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2941. /* Must prevent other flows from accessing drv_info_to_mcp */
  2942. mutex_lock(&bp->drv_info_mutex);
  2943. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2944. sizeof(union drv_info_to_mcp));
  2945. switch (op_code) {
  2946. case ETH_STATS_OPCODE:
  2947. bnx2x_drv_info_ether_stat(bp);
  2948. break;
  2949. case FCOE_STATS_OPCODE:
  2950. bnx2x_drv_info_fcoe_stat(bp);
  2951. break;
  2952. case ISCSI_STATS_OPCODE:
  2953. bnx2x_drv_info_iscsi_stat(bp);
  2954. break;
  2955. default:
  2956. /* if op code isn't supported - send NACK */
  2957. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2958. goto out;
  2959. }
  2960. /* if we got drv_info attn from MFW then these fields are defined in
  2961. * shmem2 for sure
  2962. */
  2963. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2964. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2965. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2966. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2967. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2968. /* Since possible management wants both this and get_driver_version
  2969. * need to wait until management notifies us it finished utilizing
  2970. * the buffer.
  2971. */
  2972. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  2973. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  2974. } else if (!bp->drv_info_mng_owner) {
  2975. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  2976. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  2977. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  2978. /* Management is done; need to clear indication */
  2979. if (indication & bit) {
  2980. SHMEM2_WR(bp, mfw_drv_indication,
  2981. indication & ~bit);
  2982. release = true;
  2983. break;
  2984. }
  2985. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  2986. }
  2987. }
  2988. if (!release) {
  2989. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  2990. bp->drv_info_mng_owner = true;
  2991. }
  2992. out:
  2993. mutex_unlock(&bp->drv_info_mutex);
  2994. }
  2995. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  2996. {
  2997. u8 vals[4];
  2998. int i = 0;
  2999. if (bnx2x_format) {
  3000. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3001. &vals[0], &vals[1], &vals[2], &vals[3]);
  3002. if (i > 0)
  3003. vals[0] -= '0';
  3004. } else {
  3005. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3006. &vals[0], &vals[1], &vals[2], &vals[3]);
  3007. }
  3008. while (i < 4)
  3009. vals[i++] = 0;
  3010. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3011. }
  3012. void bnx2x_update_mng_version(struct bnx2x *bp)
  3013. {
  3014. u32 iscsiver = DRV_VER_NOT_LOADED;
  3015. u32 fcoever = DRV_VER_NOT_LOADED;
  3016. u32 ethver = DRV_VER_NOT_LOADED;
  3017. int idx = BP_FW_MB_IDX(bp);
  3018. u8 *version;
  3019. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3020. return;
  3021. mutex_lock(&bp->drv_info_mutex);
  3022. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3023. if (bp->drv_info_mng_owner)
  3024. goto out;
  3025. if (bp->state != BNX2X_STATE_OPEN)
  3026. goto out;
  3027. /* Parse ethernet driver version */
  3028. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3029. if (!CNIC_LOADED(bp))
  3030. goto out;
  3031. /* Try getting storage driver version via cnic */
  3032. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3033. sizeof(union drv_info_to_mcp));
  3034. bnx2x_drv_info_iscsi_stat(bp);
  3035. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3036. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3037. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3038. sizeof(union drv_info_to_mcp));
  3039. bnx2x_drv_info_fcoe_stat(bp);
  3040. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3041. fcoever = bnx2x_update_mng_version_utility(version, false);
  3042. out:
  3043. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3044. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3045. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3046. mutex_unlock(&bp->drv_info_mutex);
  3047. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3048. ethver, iscsiver, fcoever);
  3049. }
  3050. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  3051. {
  3052. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  3053. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  3054. /*
  3055. * This is the only place besides the function initialization
  3056. * where the bp->flags can change so it is done without any
  3057. * locks
  3058. */
  3059. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3060. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3061. bp->flags |= MF_FUNC_DIS;
  3062. bnx2x_e1h_disable(bp);
  3063. } else {
  3064. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3065. bp->flags &= ~MF_FUNC_DIS;
  3066. bnx2x_e1h_enable(bp);
  3067. }
  3068. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  3069. }
  3070. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  3071. bnx2x_config_mf_bw(bp);
  3072. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  3073. }
  3074. /* Report results to MCP */
  3075. if (dcc_event)
  3076. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  3077. else
  3078. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  3079. }
  3080. /* must be called under the spq lock */
  3081. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3082. {
  3083. struct eth_spe *next_spe = bp->spq_prod_bd;
  3084. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3085. bp->spq_prod_bd = bp->spq;
  3086. bp->spq_prod_idx = 0;
  3087. DP(BNX2X_MSG_SP, "end of spq\n");
  3088. } else {
  3089. bp->spq_prod_bd++;
  3090. bp->spq_prod_idx++;
  3091. }
  3092. return next_spe;
  3093. }
  3094. /* must be called under the spq lock */
  3095. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3096. {
  3097. int func = BP_FUNC(bp);
  3098. /*
  3099. * Make sure that BD data is updated before writing the producer:
  3100. * BD data is written to the memory, the producer is read from the
  3101. * memory, thus we need a full memory barrier to ensure the ordering.
  3102. */
  3103. mb();
  3104. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3105. bp->spq_prod_idx);
  3106. mmiowb();
  3107. }
  3108. /**
  3109. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3110. *
  3111. * @cmd: command to check
  3112. * @cmd_type: command type
  3113. */
  3114. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3115. {
  3116. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3117. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3118. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3119. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3120. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3121. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3122. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3123. return true;
  3124. else
  3125. return false;
  3126. }
  3127. /**
  3128. * bnx2x_sp_post - place a single command on an SP ring
  3129. *
  3130. * @bp: driver handle
  3131. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3132. * @cid: SW CID the command is related to
  3133. * @data_hi: command private data address (high 32 bits)
  3134. * @data_lo: command private data address (low 32 bits)
  3135. * @cmd_type: command type (e.g. NONE, ETH)
  3136. *
  3137. * SP data is handled as if it's always an address pair, thus data fields are
  3138. * not swapped to little endian in upper functions. Instead this function swaps
  3139. * data as if it's two u32 fields.
  3140. */
  3141. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3142. u32 data_hi, u32 data_lo, int cmd_type)
  3143. {
  3144. struct eth_spe *spe;
  3145. u16 type;
  3146. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3147. #ifdef BNX2X_STOP_ON_ERROR
  3148. if (unlikely(bp->panic)) {
  3149. BNX2X_ERR("Can't post SP when there is panic\n");
  3150. return -EIO;
  3151. }
  3152. #endif
  3153. spin_lock_bh(&bp->spq_lock);
  3154. if (common) {
  3155. if (!atomic_read(&bp->eq_spq_left)) {
  3156. BNX2X_ERR("BUG! EQ ring full!\n");
  3157. spin_unlock_bh(&bp->spq_lock);
  3158. bnx2x_panic();
  3159. return -EBUSY;
  3160. }
  3161. } else if (!atomic_read(&bp->cq_spq_left)) {
  3162. BNX2X_ERR("BUG! SPQ ring full!\n");
  3163. spin_unlock_bh(&bp->spq_lock);
  3164. bnx2x_panic();
  3165. return -EBUSY;
  3166. }
  3167. spe = bnx2x_sp_get_next(bp);
  3168. /* CID needs port number to be encoded int it */
  3169. spe->hdr.conn_and_cmd_data =
  3170. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3171. HW_CID(bp, cid));
  3172. /* In some cases, type may already contain the func-id
  3173. * mainly in SRIOV related use cases, so we add it here only
  3174. * if it's not already set.
  3175. */
  3176. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3177. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3178. SPE_HDR_CONN_TYPE;
  3179. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3180. SPE_HDR_FUNCTION_ID);
  3181. } else {
  3182. type = cmd_type;
  3183. }
  3184. spe->hdr.type = cpu_to_le16(type);
  3185. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3186. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3187. /*
  3188. * It's ok if the actual decrement is issued towards the memory
  3189. * somewhere between the spin_lock and spin_unlock. Thus no
  3190. * more explicit memory barrier is needed.
  3191. */
  3192. if (common)
  3193. atomic_dec(&bp->eq_spq_left);
  3194. else
  3195. atomic_dec(&bp->cq_spq_left);
  3196. DP(BNX2X_MSG_SP,
  3197. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3198. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3199. (u32)(U64_LO(bp->spq_mapping) +
  3200. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3201. HW_CID(bp, cid), data_hi, data_lo, type,
  3202. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3203. bnx2x_sp_prod_update(bp);
  3204. spin_unlock_bh(&bp->spq_lock);
  3205. return 0;
  3206. }
  3207. /* acquire split MCP access lock register */
  3208. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3209. {
  3210. u32 j, val;
  3211. int rc = 0;
  3212. might_sleep();
  3213. for (j = 0; j < 1000; j++) {
  3214. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3215. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3216. if (val & MCPR_ACCESS_LOCK_LOCK)
  3217. break;
  3218. usleep_range(5000, 10000);
  3219. }
  3220. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3221. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3222. rc = -EBUSY;
  3223. }
  3224. return rc;
  3225. }
  3226. /* release split MCP access lock register */
  3227. static void bnx2x_release_alr(struct bnx2x *bp)
  3228. {
  3229. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3230. }
  3231. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3232. #define BNX2X_DEF_SB_IDX 0x0002
  3233. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3234. {
  3235. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3236. u16 rc = 0;
  3237. barrier(); /* status block is written to by the chip */
  3238. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3239. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3240. rc |= BNX2X_DEF_SB_ATT_IDX;
  3241. }
  3242. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3243. bp->def_idx = def_sb->sp_sb.running_index;
  3244. rc |= BNX2X_DEF_SB_IDX;
  3245. }
  3246. /* Do not reorder: indices reading should complete before handling */
  3247. barrier();
  3248. return rc;
  3249. }
  3250. /*
  3251. * slow path service functions
  3252. */
  3253. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3254. {
  3255. int port = BP_PORT(bp);
  3256. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3257. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3258. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3259. NIG_REG_MASK_INTERRUPT_PORT0;
  3260. u32 aeu_mask;
  3261. u32 nig_mask = 0;
  3262. u32 reg_addr;
  3263. if (bp->attn_state & asserted)
  3264. BNX2X_ERR("IGU ERROR\n");
  3265. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3266. aeu_mask = REG_RD(bp, aeu_addr);
  3267. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3268. aeu_mask, asserted);
  3269. aeu_mask &= ~(asserted & 0x3ff);
  3270. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3271. REG_WR(bp, aeu_addr, aeu_mask);
  3272. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3273. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3274. bp->attn_state |= asserted;
  3275. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3276. if (asserted & ATTN_HARD_WIRED_MASK) {
  3277. if (asserted & ATTN_NIG_FOR_FUNC) {
  3278. bnx2x_acquire_phy_lock(bp);
  3279. /* save nig interrupt mask */
  3280. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3281. /* If nig_mask is not set, no need to call the update
  3282. * function.
  3283. */
  3284. if (nig_mask) {
  3285. REG_WR(bp, nig_int_mask_addr, 0);
  3286. bnx2x_link_attn(bp);
  3287. }
  3288. /* handle unicore attn? */
  3289. }
  3290. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3291. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3292. if (asserted & GPIO_2_FUNC)
  3293. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3294. if (asserted & GPIO_3_FUNC)
  3295. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3296. if (asserted & GPIO_4_FUNC)
  3297. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3298. if (port == 0) {
  3299. if (asserted & ATTN_GENERAL_ATTN_1) {
  3300. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3301. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3302. }
  3303. if (asserted & ATTN_GENERAL_ATTN_2) {
  3304. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3305. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3306. }
  3307. if (asserted & ATTN_GENERAL_ATTN_3) {
  3308. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3309. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3310. }
  3311. } else {
  3312. if (asserted & ATTN_GENERAL_ATTN_4) {
  3313. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3314. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3315. }
  3316. if (asserted & ATTN_GENERAL_ATTN_5) {
  3317. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3318. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3319. }
  3320. if (asserted & ATTN_GENERAL_ATTN_6) {
  3321. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3322. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3323. }
  3324. }
  3325. } /* if hardwired */
  3326. if (bp->common.int_block == INT_BLOCK_HC)
  3327. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3328. COMMAND_REG_ATTN_BITS_SET);
  3329. else
  3330. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3331. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3332. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3333. REG_WR(bp, reg_addr, asserted);
  3334. /* now set back the mask */
  3335. if (asserted & ATTN_NIG_FOR_FUNC) {
  3336. /* Verify that IGU ack through BAR was written before restoring
  3337. * NIG mask. This loop should exit after 2-3 iterations max.
  3338. */
  3339. if (bp->common.int_block != INT_BLOCK_HC) {
  3340. u32 cnt = 0, igu_acked;
  3341. do {
  3342. igu_acked = REG_RD(bp,
  3343. IGU_REG_ATTENTION_ACK_BITS);
  3344. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3345. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3346. if (!igu_acked)
  3347. DP(NETIF_MSG_HW,
  3348. "Failed to verify IGU ack on time\n");
  3349. barrier();
  3350. }
  3351. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3352. bnx2x_release_phy_lock(bp);
  3353. }
  3354. }
  3355. static void bnx2x_fan_failure(struct bnx2x *bp)
  3356. {
  3357. int port = BP_PORT(bp);
  3358. u32 ext_phy_config;
  3359. /* mark the failure */
  3360. ext_phy_config =
  3361. SHMEM_RD(bp,
  3362. dev_info.port_hw_config[port].external_phy_config);
  3363. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3364. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3365. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3366. ext_phy_config);
  3367. /* log the failure */
  3368. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3369. "Please contact OEM Support for assistance\n");
  3370. /* Schedule device reset (unload)
  3371. * This is due to some boards consuming sufficient power when driver is
  3372. * up to overheat if fan fails.
  3373. */
  3374. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3375. }
  3376. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3377. {
  3378. int port = BP_PORT(bp);
  3379. int reg_offset;
  3380. u32 val;
  3381. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3382. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3383. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3384. val = REG_RD(bp, reg_offset);
  3385. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3386. REG_WR(bp, reg_offset, val);
  3387. BNX2X_ERR("SPIO5 hw attention\n");
  3388. /* Fan failure attention */
  3389. bnx2x_hw_reset_phy(&bp->link_params);
  3390. bnx2x_fan_failure(bp);
  3391. }
  3392. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3393. bnx2x_acquire_phy_lock(bp);
  3394. bnx2x_handle_module_detect_int(&bp->link_params);
  3395. bnx2x_release_phy_lock(bp);
  3396. }
  3397. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3398. val = REG_RD(bp, reg_offset);
  3399. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3400. REG_WR(bp, reg_offset, val);
  3401. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3402. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3403. bnx2x_panic();
  3404. }
  3405. }
  3406. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3407. {
  3408. u32 val;
  3409. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3410. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3411. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3412. /* DORQ discard attention */
  3413. if (val & 0x2)
  3414. BNX2X_ERR("FATAL error from DORQ\n");
  3415. }
  3416. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3417. int port = BP_PORT(bp);
  3418. int reg_offset;
  3419. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3420. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3421. val = REG_RD(bp, reg_offset);
  3422. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3423. REG_WR(bp, reg_offset, val);
  3424. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3425. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3426. bnx2x_panic();
  3427. }
  3428. }
  3429. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3430. {
  3431. u32 val;
  3432. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3433. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3434. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3435. /* CFC error attention */
  3436. if (val & 0x2)
  3437. BNX2X_ERR("FATAL error from CFC\n");
  3438. }
  3439. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3440. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3441. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3442. /* RQ_USDMDP_FIFO_OVERFLOW */
  3443. if (val & 0x18000)
  3444. BNX2X_ERR("FATAL error from PXP\n");
  3445. if (!CHIP_IS_E1x(bp)) {
  3446. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3447. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3448. }
  3449. }
  3450. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3451. int port = BP_PORT(bp);
  3452. int reg_offset;
  3453. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3454. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3455. val = REG_RD(bp, reg_offset);
  3456. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3457. REG_WR(bp, reg_offset, val);
  3458. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3459. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3460. bnx2x_panic();
  3461. }
  3462. }
  3463. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3464. {
  3465. u32 val;
  3466. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3467. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3468. int func = BP_FUNC(bp);
  3469. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3470. bnx2x_read_mf_cfg(bp);
  3471. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3472. func_mf_config[BP_ABS_FUNC(bp)].config);
  3473. val = SHMEM_RD(bp,
  3474. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3475. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3476. bnx2x_dcc_event(bp,
  3477. (val & DRV_STATUS_DCC_EVENT_MASK));
  3478. if (val & DRV_STATUS_SET_MF_BW)
  3479. bnx2x_set_mf_bw(bp);
  3480. if (val & DRV_STATUS_DRV_INFO_REQ)
  3481. bnx2x_handle_drv_info_req(bp);
  3482. if (val & DRV_STATUS_VF_DISABLED)
  3483. bnx2x_schedule_iov_task(bp,
  3484. BNX2X_IOV_HANDLE_FLR);
  3485. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3486. bnx2x_pmf_update(bp);
  3487. if (bp->port.pmf &&
  3488. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3489. bp->dcbx_enabled > 0)
  3490. /* start dcbx state machine */
  3491. bnx2x_dcbx_set_params(bp,
  3492. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3493. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3494. bnx2x_handle_afex_cmd(bp,
  3495. val & DRV_STATUS_AFEX_EVENT_MASK);
  3496. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3497. bnx2x_handle_eee_event(bp);
  3498. if (bp->link_vars.periodic_flags &
  3499. PERIODIC_FLAGS_LINK_EVENT) {
  3500. /* sync with link */
  3501. bnx2x_acquire_phy_lock(bp);
  3502. bp->link_vars.periodic_flags &=
  3503. ~PERIODIC_FLAGS_LINK_EVENT;
  3504. bnx2x_release_phy_lock(bp);
  3505. if (IS_MF(bp))
  3506. bnx2x_link_sync_notify(bp);
  3507. bnx2x_link_report(bp);
  3508. }
  3509. /* Always call it here: bnx2x_link_report() will
  3510. * prevent the link indication duplication.
  3511. */
  3512. bnx2x__link_status_update(bp);
  3513. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3514. BNX2X_ERR("MC assert!\n");
  3515. bnx2x_mc_assert(bp);
  3516. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3517. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3518. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3519. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3520. bnx2x_panic();
  3521. } else if (attn & BNX2X_MCP_ASSERT) {
  3522. BNX2X_ERR("MCP assert!\n");
  3523. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3524. bnx2x_fw_dump(bp);
  3525. } else
  3526. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3527. }
  3528. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3529. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3530. if (attn & BNX2X_GRC_TIMEOUT) {
  3531. val = CHIP_IS_E1(bp) ? 0 :
  3532. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3533. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3534. }
  3535. if (attn & BNX2X_GRC_RSV) {
  3536. val = CHIP_IS_E1(bp) ? 0 :
  3537. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3538. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3539. }
  3540. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3541. }
  3542. }
  3543. /*
  3544. * Bits map:
  3545. * 0-7 - Engine0 load counter.
  3546. * 8-15 - Engine1 load counter.
  3547. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3548. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3549. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3550. * on the engine
  3551. * 19 - Engine1 ONE_IS_LOADED.
  3552. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3553. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3554. * just the one belonging to its engine).
  3555. *
  3556. */
  3557. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3558. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3559. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3560. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3561. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3562. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3563. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3564. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3565. /*
  3566. * Set the GLOBAL_RESET bit.
  3567. *
  3568. * Should be run under rtnl lock
  3569. */
  3570. void bnx2x_set_reset_global(struct bnx2x *bp)
  3571. {
  3572. u32 val;
  3573. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3574. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3575. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3576. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3577. }
  3578. /*
  3579. * Clear the GLOBAL_RESET bit.
  3580. *
  3581. * Should be run under rtnl lock
  3582. */
  3583. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3584. {
  3585. u32 val;
  3586. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3587. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3588. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3589. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3590. }
  3591. /*
  3592. * Checks the GLOBAL_RESET bit.
  3593. *
  3594. * should be run under rtnl lock
  3595. */
  3596. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3597. {
  3598. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3599. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3600. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3601. }
  3602. /*
  3603. * Clear RESET_IN_PROGRESS bit for the current engine.
  3604. *
  3605. * Should be run under rtnl lock
  3606. */
  3607. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3608. {
  3609. u32 val;
  3610. u32 bit = BP_PATH(bp) ?
  3611. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3612. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3613. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3614. /* Clear the bit */
  3615. val &= ~bit;
  3616. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3617. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3618. }
  3619. /*
  3620. * Set RESET_IN_PROGRESS for the current engine.
  3621. *
  3622. * should be run under rtnl lock
  3623. */
  3624. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3625. {
  3626. u32 val;
  3627. u32 bit = BP_PATH(bp) ?
  3628. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3629. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3630. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3631. /* Set the bit */
  3632. val |= bit;
  3633. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3634. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3635. }
  3636. /*
  3637. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3638. * should be run under rtnl lock
  3639. */
  3640. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3641. {
  3642. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3643. u32 bit = engine ?
  3644. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3645. /* return false if bit is set */
  3646. return (val & bit) ? false : true;
  3647. }
  3648. /*
  3649. * set pf load for the current pf.
  3650. *
  3651. * should be run under rtnl lock
  3652. */
  3653. void bnx2x_set_pf_load(struct bnx2x *bp)
  3654. {
  3655. u32 val1, val;
  3656. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3657. BNX2X_PATH0_LOAD_CNT_MASK;
  3658. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3659. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3660. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3661. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3662. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3663. /* get the current counter value */
  3664. val1 = (val & mask) >> shift;
  3665. /* set bit of that PF */
  3666. val1 |= (1 << bp->pf_num);
  3667. /* clear the old value */
  3668. val &= ~mask;
  3669. /* set the new one */
  3670. val |= ((val1 << shift) & mask);
  3671. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3672. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3673. }
  3674. /**
  3675. * bnx2x_clear_pf_load - clear pf load mark
  3676. *
  3677. * @bp: driver handle
  3678. *
  3679. * Should be run under rtnl lock.
  3680. * Decrements the load counter for the current engine. Returns
  3681. * whether other functions are still loaded
  3682. */
  3683. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3684. {
  3685. u32 val1, val;
  3686. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3687. BNX2X_PATH0_LOAD_CNT_MASK;
  3688. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3689. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3690. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3691. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3692. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3693. /* get the current counter value */
  3694. val1 = (val & mask) >> shift;
  3695. /* clear bit of that PF */
  3696. val1 &= ~(1 << bp->pf_num);
  3697. /* clear the old value */
  3698. val &= ~mask;
  3699. /* set the new one */
  3700. val |= ((val1 << shift) & mask);
  3701. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3702. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3703. return val1 != 0;
  3704. }
  3705. /*
  3706. * Read the load status for the current engine.
  3707. *
  3708. * should be run under rtnl lock
  3709. */
  3710. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3711. {
  3712. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3713. BNX2X_PATH0_LOAD_CNT_MASK);
  3714. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3715. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3716. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3717. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3718. val = (val & mask) >> shift;
  3719. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3720. engine, val);
  3721. return val != 0;
  3722. }
  3723. static void _print_parity(struct bnx2x *bp, u32 reg)
  3724. {
  3725. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3726. }
  3727. static void _print_next_block(int idx, const char *blk)
  3728. {
  3729. pr_cont("%s%s", idx ? ", " : "", blk);
  3730. }
  3731. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3732. int *par_num, bool print)
  3733. {
  3734. u32 cur_bit;
  3735. bool res;
  3736. int i;
  3737. res = false;
  3738. for (i = 0; sig; i++) {
  3739. cur_bit = (0x1UL << i);
  3740. if (sig & cur_bit) {
  3741. res |= true; /* Each bit is real error! */
  3742. if (print) {
  3743. switch (cur_bit) {
  3744. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3745. _print_next_block((*par_num)++, "BRB");
  3746. _print_parity(bp,
  3747. BRB1_REG_BRB1_PRTY_STS);
  3748. break;
  3749. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3750. _print_next_block((*par_num)++,
  3751. "PARSER");
  3752. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3753. break;
  3754. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3755. _print_next_block((*par_num)++, "TSDM");
  3756. _print_parity(bp,
  3757. TSDM_REG_TSDM_PRTY_STS);
  3758. break;
  3759. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3760. _print_next_block((*par_num)++,
  3761. "SEARCHER");
  3762. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3763. break;
  3764. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3765. _print_next_block((*par_num)++, "TCM");
  3766. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3767. break;
  3768. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3769. _print_next_block((*par_num)++,
  3770. "TSEMI");
  3771. _print_parity(bp,
  3772. TSEM_REG_TSEM_PRTY_STS_0);
  3773. _print_parity(bp,
  3774. TSEM_REG_TSEM_PRTY_STS_1);
  3775. break;
  3776. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3777. _print_next_block((*par_num)++, "XPB");
  3778. _print_parity(bp, GRCBASE_XPB +
  3779. PB_REG_PB_PRTY_STS);
  3780. break;
  3781. }
  3782. }
  3783. /* Clear the bit */
  3784. sig &= ~cur_bit;
  3785. }
  3786. }
  3787. return res;
  3788. }
  3789. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3790. int *par_num, bool *global,
  3791. bool print)
  3792. {
  3793. u32 cur_bit;
  3794. bool res;
  3795. int i;
  3796. res = false;
  3797. for (i = 0; sig; i++) {
  3798. cur_bit = (0x1UL << i);
  3799. if (sig & cur_bit) {
  3800. res |= true; /* Each bit is real error! */
  3801. switch (cur_bit) {
  3802. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3803. if (print) {
  3804. _print_next_block((*par_num)++, "PBF");
  3805. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3806. }
  3807. break;
  3808. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3809. if (print) {
  3810. _print_next_block((*par_num)++, "QM");
  3811. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3812. }
  3813. break;
  3814. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3815. if (print) {
  3816. _print_next_block((*par_num)++, "TM");
  3817. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3818. }
  3819. break;
  3820. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3821. if (print) {
  3822. _print_next_block((*par_num)++, "XSDM");
  3823. _print_parity(bp,
  3824. XSDM_REG_XSDM_PRTY_STS);
  3825. }
  3826. break;
  3827. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3828. if (print) {
  3829. _print_next_block((*par_num)++, "XCM");
  3830. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3831. }
  3832. break;
  3833. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3834. if (print) {
  3835. _print_next_block((*par_num)++,
  3836. "XSEMI");
  3837. _print_parity(bp,
  3838. XSEM_REG_XSEM_PRTY_STS_0);
  3839. _print_parity(bp,
  3840. XSEM_REG_XSEM_PRTY_STS_1);
  3841. }
  3842. break;
  3843. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3844. if (print) {
  3845. _print_next_block((*par_num)++,
  3846. "DOORBELLQ");
  3847. _print_parity(bp,
  3848. DORQ_REG_DORQ_PRTY_STS);
  3849. }
  3850. break;
  3851. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3852. if (print) {
  3853. _print_next_block((*par_num)++, "NIG");
  3854. if (CHIP_IS_E1x(bp)) {
  3855. _print_parity(bp,
  3856. NIG_REG_NIG_PRTY_STS);
  3857. } else {
  3858. _print_parity(bp,
  3859. NIG_REG_NIG_PRTY_STS_0);
  3860. _print_parity(bp,
  3861. NIG_REG_NIG_PRTY_STS_1);
  3862. }
  3863. }
  3864. break;
  3865. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3866. if (print)
  3867. _print_next_block((*par_num)++,
  3868. "VAUX PCI CORE");
  3869. *global = true;
  3870. break;
  3871. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3872. if (print) {
  3873. _print_next_block((*par_num)++,
  3874. "DEBUG");
  3875. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3876. }
  3877. break;
  3878. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3879. if (print) {
  3880. _print_next_block((*par_num)++, "USDM");
  3881. _print_parity(bp,
  3882. USDM_REG_USDM_PRTY_STS);
  3883. }
  3884. break;
  3885. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3886. if (print) {
  3887. _print_next_block((*par_num)++, "UCM");
  3888. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3889. }
  3890. break;
  3891. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3892. if (print) {
  3893. _print_next_block((*par_num)++,
  3894. "USEMI");
  3895. _print_parity(bp,
  3896. USEM_REG_USEM_PRTY_STS_0);
  3897. _print_parity(bp,
  3898. USEM_REG_USEM_PRTY_STS_1);
  3899. }
  3900. break;
  3901. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3902. if (print) {
  3903. _print_next_block((*par_num)++, "UPB");
  3904. _print_parity(bp, GRCBASE_UPB +
  3905. PB_REG_PB_PRTY_STS);
  3906. }
  3907. break;
  3908. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3909. if (print) {
  3910. _print_next_block((*par_num)++, "CSDM");
  3911. _print_parity(bp,
  3912. CSDM_REG_CSDM_PRTY_STS);
  3913. }
  3914. break;
  3915. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3916. if (print) {
  3917. _print_next_block((*par_num)++, "CCM");
  3918. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3919. }
  3920. break;
  3921. }
  3922. /* Clear the bit */
  3923. sig &= ~cur_bit;
  3924. }
  3925. }
  3926. return res;
  3927. }
  3928. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3929. int *par_num, bool print)
  3930. {
  3931. u32 cur_bit;
  3932. bool res;
  3933. int i;
  3934. res = false;
  3935. for (i = 0; sig; i++) {
  3936. cur_bit = (0x1UL << i);
  3937. if (sig & cur_bit) {
  3938. res |= true; /* Each bit is real error! */
  3939. if (print) {
  3940. switch (cur_bit) {
  3941. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3942. _print_next_block((*par_num)++,
  3943. "CSEMI");
  3944. _print_parity(bp,
  3945. CSEM_REG_CSEM_PRTY_STS_0);
  3946. _print_parity(bp,
  3947. CSEM_REG_CSEM_PRTY_STS_1);
  3948. break;
  3949. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3950. _print_next_block((*par_num)++, "PXP");
  3951. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3952. _print_parity(bp,
  3953. PXP2_REG_PXP2_PRTY_STS_0);
  3954. _print_parity(bp,
  3955. PXP2_REG_PXP2_PRTY_STS_1);
  3956. break;
  3957. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3958. _print_next_block((*par_num)++,
  3959. "PXPPCICLOCKCLIENT");
  3960. break;
  3961. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3962. _print_next_block((*par_num)++, "CFC");
  3963. _print_parity(bp,
  3964. CFC_REG_CFC_PRTY_STS);
  3965. break;
  3966. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3967. _print_next_block((*par_num)++, "CDU");
  3968. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3969. break;
  3970. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3971. _print_next_block((*par_num)++, "DMAE");
  3972. _print_parity(bp,
  3973. DMAE_REG_DMAE_PRTY_STS);
  3974. break;
  3975. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3976. _print_next_block((*par_num)++, "IGU");
  3977. if (CHIP_IS_E1x(bp))
  3978. _print_parity(bp,
  3979. HC_REG_HC_PRTY_STS);
  3980. else
  3981. _print_parity(bp,
  3982. IGU_REG_IGU_PRTY_STS);
  3983. break;
  3984. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3985. _print_next_block((*par_num)++, "MISC");
  3986. _print_parity(bp,
  3987. MISC_REG_MISC_PRTY_STS);
  3988. break;
  3989. }
  3990. }
  3991. /* Clear the bit */
  3992. sig &= ~cur_bit;
  3993. }
  3994. }
  3995. return res;
  3996. }
  3997. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  3998. int *par_num, bool *global,
  3999. bool print)
  4000. {
  4001. bool res = false;
  4002. u32 cur_bit;
  4003. int i;
  4004. for (i = 0; sig; i++) {
  4005. cur_bit = (0x1UL << i);
  4006. if (sig & cur_bit) {
  4007. switch (cur_bit) {
  4008. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4009. if (print)
  4010. _print_next_block((*par_num)++,
  4011. "MCP ROM");
  4012. *global = true;
  4013. res |= true;
  4014. break;
  4015. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4016. if (print)
  4017. _print_next_block((*par_num)++,
  4018. "MCP UMP RX");
  4019. *global = true;
  4020. res |= true;
  4021. break;
  4022. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4023. if (print)
  4024. _print_next_block((*par_num)++,
  4025. "MCP UMP TX");
  4026. *global = true;
  4027. res |= true;
  4028. break;
  4029. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4030. if (print)
  4031. _print_next_block((*par_num)++,
  4032. "MCP SCPAD");
  4033. /* clear latched SCPAD PATIRY from MCP */
  4034. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4035. 1UL << 10);
  4036. break;
  4037. }
  4038. /* Clear the bit */
  4039. sig &= ~cur_bit;
  4040. }
  4041. }
  4042. return res;
  4043. }
  4044. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4045. int *par_num, bool print)
  4046. {
  4047. u32 cur_bit;
  4048. bool res;
  4049. int i;
  4050. res = false;
  4051. for (i = 0; sig; i++) {
  4052. cur_bit = (0x1UL << i);
  4053. if (sig & cur_bit) {
  4054. res |= true; /* Each bit is real error! */
  4055. if (print) {
  4056. switch (cur_bit) {
  4057. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4058. _print_next_block((*par_num)++,
  4059. "PGLUE_B");
  4060. _print_parity(bp,
  4061. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4062. break;
  4063. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4064. _print_next_block((*par_num)++, "ATC");
  4065. _print_parity(bp,
  4066. ATC_REG_ATC_PRTY_STS);
  4067. break;
  4068. }
  4069. }
  4070. /* Clear the bit */
  4071. sig &= ~cur_bit;
  4072. }
  4073. }
  4074. return res;
  4075. }
  4076. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4077. u32 *sig)
  4078. {
  4079. bool res = false;
  4080. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4081. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4082. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4083. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4084. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4085. int par_num = 0;
  4086. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4087. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4088. sig[0] & HW_PRTY_ASSERT_SET_0,
  4089. sig[1] & HW_PRTY_ASSERT_SET_1,
  4090. sig[2] & HW_PRTY_ASSERT_SET_2,
  4091. sig[3] & HW_PRTY_ASSERT_SET_3,
  4092. sig[4] & HW_PRTY_ASSERT_SET_4);
  4093. if (print)
  4094. netdev_err(bp->dev,
  4095. "Parity errors detected in blocks: ");
  4096. res |= bnx2x_check_blocks_with_parity0(bp,
  4097. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4098. res |= bnx2x_check_blocks_with_parity1(bp,
  4099. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4100. res |= bnx2x_check_blocks_with_parity2(bp,
  4101. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4102. res |= bnx2x_check_blocks_with_parity3(bp,
  4103. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4104. res |= bnx2x_check_blocks_with_parity4(bp,
  4105. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4106. if (print)
  4107. pr_cont("\n");
  4108. }
  4109. return res;
  4110. }
  4111. /**
  4112. * bnx2x_chk_parity_attn - checks for parity attentions.
  4113. *
  4114. * @bp: driver handle
  4115. * @global: true if there was a global attention
  4116. * @print: show parity attention in syslog
  4117. */
  4118. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4119. {
  4120. struct attn_route attn = { {0} };
  4121. int port = BP_PORT(bp);
  4122. attn.sig[0] = REG_RD(bp,
  4123. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4124. port*4);
  4125. attn.sig[1] = REG_RD(bp,
  4126. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4127. port*4);
  4128. attn.sig[2] = REG_RD(bp,
  4129. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4130. port*4);
  4131. attn.sig[3] = REG_RD(bp,
  4132. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4133. port*4);
  4134. /* Since MCP attentions can't be disabled inside the block, we need to
  4135. * read AEU registers to see whether they're currently disabled
  4136. */
  4137. attn.sig[3] &= ((REG_RD(bp,
  4138. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4139. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4140. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4141. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4142. if (!CHIP_IS_E1x(bp))
  4143. attn.sig[4] = REG_RD(bp,
  4144. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4145. port*4);
  4146. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4147. }
  4148. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4149. {
  4150. u32 val;
  4151. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4152. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4153. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4154. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4155. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4156. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4157. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4158. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4159. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4160. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4161. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4162. if (val &
  4163. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4164. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4165. if (val &
  4166. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4167. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4168. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4169. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4170. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4171. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4172. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4173. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4174. }
  4175. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4176. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4177. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4178. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4179. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4180. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4181. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4182. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4183. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4184. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4185. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4186. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4187. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4188. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4189. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4190. }
  4191. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4192. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4193. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4194. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4195. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4196. }
  4197. }
  4198. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4199. {
  4200. struct attn_route attn, *group_mask;
  4201. int port = BP_PORT(bp);
  4202. int index;
  4203. u32 reg_addr;
  4204. u32 val;
  4205. u32 aeu_mask;
  4206. bool global = false;
  4207. /* need to take HW lock because MCP or other port might also
  4208. try to handle this event */
  4209. bnx2x_acquire_alr(bp);
  4210. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4211. #ifndef BNX2X_STOP_ON_ERROR
  4212. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4213. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4214. /* Disable HW interrupts */
  4215. bnx2x_int_disable(bp);
  4216. /* In case of parity errors don't handle attentions so that
  4217. * other function would "see" parity errors.
  4218. */
  4219. #else
  4220. bnx2x_panic();
  4221. #endif
  4222. bnx2x_release_alr(bp);
  4223. return;
  4224. }
  4225. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4226. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4227. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4228. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4229. if (!CHIP_IS_E1x(bp))
  4230. attn.sig[4] =
  4231. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4232. else
  4233. attn.sig[4] = 0;
  4234. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4235. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4236. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4237. if (deasserted & (1 << index)) {
  4238. group_mask = &bp->attn_group[index];
  4239. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4240. index,
  4241. group_mask->sig[0], group_mask->sig[1],
  4242. group_mask->sig[2], group_mask->sig[3],
  4243. group_mask->sig[4]);
  4244. bnx2x_attn_int_deasserted4(bp,
  4245. attn.sig[4] & group_mask->sig[4]);
  4246. bnx2x_attn_int_deasserted3(bp,
  4247. attn.sig[3] & group_mask->sig[3]);
  4248. bnx2x_attn_int_deasserted1(bp,
  4249. attn.sig[1] & group_mask->sig[1]);
  4250. bnx2x_attn_int_deasserted2(bp,
  4251. attn.sig[2] & group_mask->sig[2]);
  4252. bnx2x_attn_int_deasserted0(bp,
  4253. attn.sig[0] & group_mask->sig[0]);
  4254. }
  4255. }
  4256. bnx2x_release_alr(bp);
  4257. if (bp->common.int_block == INT_BLOCK_HC)
  4258. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4259. COMMAND_REG_ATTN_BITS_CLR);
  4260. else
  4261. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4262. val = ~deasserted;
  4263. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4264. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4265. REG_WR(bp, reg_addr, val);
  4266. if (~bp->attn_state & deasserted)
  4267. BNX2X_ERR("IGU ERROR\n");
  4268. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4269. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4270. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4271. aeu_mask = REG_RD(bp, reg_addr);
  4272. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4273. aeu_mask, deasserted);
  4274. aeu_mask |= (deasserted & 0x3ff);
  4275. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4276. REG_WR(bp, reg_addr, aeu_mask);
  4277. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4278. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4279. bp->attn_state &= ~deasserted;
  4280. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4281. }
  4282. static void bnx2x_attn_int(struct bnx2x *bp)
  4283. {
  4284. /* read local copy of bits */
  4285. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4286. attn_bits);
  4287. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4288. attn_bits_ack);
  4289. u32 attn_state = bp->attn_state;
  4290. /* look for changed bits */
  4291. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4292. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4293. DP(NETIF_MSG_HW,
  4294. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4295. attn_bits, attn_ack, asserted, deasserted);
  4296. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4297. BNX2X_ERR("BAD attention state\n");
  4298. /* handle bits that were raised */
  4299. if (asserted)
  4300. bnx2x_attn_int_asserted(bp, asserted);
  4301. if (deasserted)
  4302. bnx2x_attn_int_deasserted(bp, deasserted);
  4303. }
  4304. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4305. u16 index, u8 op, u8 update)
  4306. {
  4307. u32 igu_addr = bp->igu_base_addr;
  4308. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4309. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4310. igu_addr);
  4311. }
  4312. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4313. {
  4314. /* No memory barriers */
  4315. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4316. mmiowb(); /* keep prod updates ordered */
  4317. }
  4318. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4319. union event_ring_elem *elem)
  4320. {
  4321. u8 err = elem->message.error;
  4322. if (!bp->cnic_eth_dev.starting_cid ||
  4323. (cid < bp->cnic_eth_dev.starting_cid &&
  4324. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4325. return 1;
  4326. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4327. if (unlikely(err)) {
  4328. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4329. cid);
  4330. bnx2x_panic_dump(bp, false);
  4331. }
  4332. bnx2x_cnic_cfc_comp(bp, cid, err);
  4333. return 0;
  4334. }
  4335. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4336. {
  4337. struct bnx2x_mcast_ramrod_params rparam;
  4338. int rc;
  4339. memset(&rparam, 0, sizeof(rparam));
  4340. rparam.mcast_obj = &bp->mcast_obj;
  4341. netif_addr_lock_bh(bp->dev);
  4342. /* Clear pending state for the last command */
  4343. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4344. /* If there are pending mcast commands - send them */
  4345. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4346. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4347. if (rc < 0)
  4348. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4349. rc);
  4350. }
  4351. netif_addr_unlock_bh(bp->dev);
  4352. }
  4353. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4354. union event_ring_elem *elem)
  4355. {
  4356. unsigned long ramrod_flags = 0;
  4357. int rc = 0;
  4358. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4359. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4360. /* Always push next commands out, don't wait here */
  4361. __set_bit(RAMROD_CONT, &ramrod_flags);
  4362. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4363. >> BNX2X_SWCID_SHIFT) {
  4364. case BNX2X_FILTER_MAC_PENDING:
  4365. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4366. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4367. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4368. else
  4369. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4370. break;
  4371. case BNX2X_FILTER_MCAST_PENDING:
  4372. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4373. /* This is only relevant for 57710 where multicast MACs are
  4374. * configured as unicast MACs using the same ramrod.
  4375. */
  4376. bnx2x_handle_mcast_eqe(bp);
  4377. return;
  4378. default:
  4379. BNX2X_ERR("Unsupported classification command: %d\n",
  4380. elem->message.data.eth_event.echo);
  4381. return;
  4382. }
  4383. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4384. if (rc < 0)
  4385. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4386. else if (rc > 0)
  4387. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4388. }
  4389. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4390. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4391. {
  4392. netif_addr_lock_bh(bp->dev);
  4393. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4394. /* Send rx_mode command again if was requested */
  4395. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4396. bnx2x_set_storm_rx_mode(bp);
  4397. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4398. &bp->sp_state))
  4399. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4400. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4401. &bp->sp_state))
  4402. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4403. netif_addr_unlock_bh(bp->dev);
  4404. }
  4405. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4406. union event_ring_elem *elem)
  4407. {
  4408. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4409. DP(BNX2X_MSG_SP,
  4410. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4411. elem->message.data.vif_list_event.func_bit_map);
  4412. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4413. elem->message.data.vif_list_event.func_bit_map);
  4414. } else if (elem->message.data.vif_list_event.echo ==
  4415. VIF_LIST_RULE_SET) {
  4416. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4417. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4418. }
  4419. }
  4420. /* called with rtnl_lock */
  4421. static void bnx2x_after_function_update(struct bnx2x *bp)
  4422. {
  4423. int q, rc;
  4424. struct bnx2x_fastpath *fp;
  4425. struct bnx2x_queue_state_params queue_params = {NULL};
  4426. struct bnx2x_queue_update_params *q_update_params =
  4427. &queue_params.params.update;
  4428. /* Send Q update command with afex vlan removal values for all Qs */
  4429. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4430. /* set silent vlan removal values according to vlan mode */
  4431. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4432. &q_update_params->update_flags);
  4433. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4434. &q_update_params->update_flags);
  4435. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4436. /* in access mode mark mask and value are 0 to strip all vlans */
  4437. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4438. q_update_params->silent_removal_value = 0;
  4439. q_update_params->silent_removal_mask = 0;
  4440. } else {
  4441. q_update_params->silent_removal_value =
  4442. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4443. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4444. }
  4445. for_each_eth_queue(bp, q) {
  4446. /* Set the appropriate Queue object */
  4447. fp = &bp->fp[q];
  4448. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4449. /* send the ramrod */
  4450. rc = bnx2x_queue_state_change(bp, &queue_params);
  4451. if (rc < 0)
  4452. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4453. q);
  4454. }
  4455. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4456. fp = &bp->fp[FCOE_IDX(bp)];
  4457. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4458. /* clear pending completion bit */
  4459. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4460. /* mark latest Q bit */
  4461. smp_mb__before_atomic();
  4462. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4463. smp_mb__after_atomic();
  4464. /* send Q update ramrod for FCoE Q */
  4465. rc = bnx2x_queue_state_change(bp, &queue_params);
  4466. if (rc < 0)
  4467. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4468. q);
  4469. } else {
  4470. /* If no FCoE ring - ACK MCP now */
  4471. bnx2x_link_report(bp);
  4472. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4473. }
  4474. }
  4475. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4476. struct bnx2x *bp, u32 cid)
  4477. {
  4478. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4479. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4480. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4481. else
  4482. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4483. }
  4484. static void bnx2x_eq_int(struct bnx2x *bp)
  4485. {
  4486. u16 hw_cons, sw_cons, sw_prod;
  4487. union event_ring_elem *elem;
  4488. u8 echo;
  4489. u32 cid;
  4490. u8 opcode;
  4491. int rc, spqe_cnt = 0;
  4492. struct bnx2x_queue_sp_obj *q_obj;
  4493. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4494. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4495. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4496. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4497. * when we get the next-page we need to adjust so the loop
  4498. * condition below will be met. The next element is the size of a
  4499. * regular element and hence incrementing by 1
  4500. */
  4501. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4502. hw_cons++;
  4503. /* This function may never run in parallel with itself for a
  4504. * specific bp, thus there is no need in "paired" read memory
  4505. * barrier here.
  4506. */
  4507. sw_cons = bp->eq_cons;
  4508. sw_prod = bp->eq_prod;
  4509. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4510. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4511. for (; sw_cons != hw_cons;
  4512. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4513. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4514. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4515. if (!rc) {
  4516. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4517. rc);
  4518. goto next_spqe;
  4519. }
  4520. /* elem CID originates from FW; actually LE */
  4521. cid = SW_CID((__force __le32)
  4522. elem->message.data.cfc_del_event.cid);
  4523. opcode = elem->message.opcode;
  4524. /* handle eq element */
  4525. switch (opcode) {
  4526. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4527. bnx2x_vf_mbx_schedule(bp,
  4528. &elem->message.data.vf_pf_event);
  4529. continue;
  4530. case EVENT_RING_OPCODE_STAT_QUERY:
  4531. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4532. "got statistics comp event %d\n",
  4533. bp->stats_comp++);
  4534. /* nothing to do with stats comp */
  4535. goto next_spqe;
  4536. case EVENT_RING_OPCODE_CFC_DEL:
  4537. /* handle according to cid range */
  4538. /*
  4539. * we may want to verify here that the bp state is
  4540. * HALTING
  4541. */
  4542. DP(BNX2X_MSG_SP,
  4543. "got delete ramrod for MULTI[%d]\n", cid);
  4544. if (CNIC_LOADED(bp) &&
  4545. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4546. goto next_spqe;
  4547. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4548. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4549. break;
  4550. goto next_spqe;
  4551. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4552. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4553. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4554. if (f_obj->complete_cmd(bp, f_obj,
  4555. BNX2X_F_CMD_TX_STOP))
  4556. break;
  4557. goto next_spqe;
  4558. case EVENT_RING_OPCODE_START_TRAFFIC:
  4559. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4560. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4561. if (f_obj->complete_cmd(bp, f_obj,
  4562. BNX2X_F_CMD_TX_START))
  4563. break;
  4564. goto next_spqe;
  4565. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4566. echo = elem->message.data.function_update_event.echo;
  4567. if (echo == SWITCH_UPDATE) {
  4568. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4569. "got FUNC_SWITCH_UPDATE ramrod\n");
  4570. if (f_obj->complete_cmd(
  4571. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4572. break;
  4573. } else {
  4574. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4575. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4576. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4577. f_obj->complete_cmd(bp, f_obj,
  4578. BNX2X_F_CMD_AFEX_UPDATE);
  4579. /* We will perform the Queues update from
  4580. * sp_rtnl task as all Queue SP operations
  4581. * should run under rtnl_lock.
  4582. */
  4583. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4584. }
  4585. goto next_spqe;
  4586. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4587. f_obj->complete_cmd(bp, f_obj,
  4588. BNX2X_F_CMD_AFEX_VIFLISTS);
  4589. bnx2x_after_afex_vif_lists(bp, elem);
  4590. goto next_spqe;
  4591. case EVENT_RING_OPCODE_FUNCTION_START:
  4592. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4593. "got FUNC_START ramrod\n");
  4594. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4595. break;
  4596. goto next_spqe;
  4597. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4598. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4599. "got FUNC_STOP ramrod\n");
  4600. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4601. break;
  4602. goto next_spqe;
  4603. }
  4604. switch (opcode | bp->state) {
  4605. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4606. BNX2X_STATE_OPEN):
  4607. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4608. BNX2X_STATE_OPENING_WAIT4_PORT):
  4609. cid = elem->message.data.eth_event.echo &
  4610. BNX2X_SWCID_MASK;
  4611. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4612. cid);
  4613. rss_raw->clear_pending(rss_raw);
  4614. break;
  4615. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4616. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4617. case (EVENT_RING_OPCODE_SET_MAC |
  4618. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4619. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4620. BNX2X_STATE_OPEN):
  4621. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4622. BNX2X_STATE_DIAG):
  4623. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4624. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4625. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4626. bnx2x_handle_classification_eqe(bp, elem);
  4627. break;
  4628. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4629. BNX2X_STATE_OPEN):
  4630. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4631. BNX2X_STATE_DIAG):
  4632. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4633. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4634. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4635. bnx2x_handle_mcast_eqe(bp);
  4636. break;
  4637. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4638. BNX2X_STATE_OPEN):
  4639. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4640. BNX2X_STATE_DIAG):
  4641. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4642. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4643. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4644. bnx2x_handle_rx_mode_eqe(bp);
  4645. break;
  4646. default:
  4647. /* unknown event log error and continue */
  4648. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4649. elem->message.opcode, bp->state);
  4650. }
  4651. next_spqe:
  4652. spqe_cnt++;
  4653. } /* for */
  4654. smp_mb__before_atomic();
  4655. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4656. bp->eq_cons = sw_cons;
  4657. bp->eq_prod = sw_prod;
  4658. /* Make sure that above mem writes were issued towards the memory */
  4659. smp_wmb();
  4660. /* update producer */
  4661. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4662. }
  4663. static void bnx2x_sp_task(struct work_struct *work)
  4664. {
  4665. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4666. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4667. /* make sure the atomic interrupt_occurred has been written */
  4668. smp_rmb();
  4669. if (atomic_read(&bp->interrupt_occurred)) {
  4670. /* what work needs to be performed? */
  4671. u16 status = bnx2x_update_dsb_idx(bp);
  4672. DP(BNX2X_MSG_SP, "status %x\n", status);
  4673. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4674. atomic_set(&bp->interrupt_occurred, 0);
  4675. /* HW attentions */
  4676. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4677. bnx2x_attn_int(bp);
  4678. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4679. }
  4680. /* SP events: STAT_QUERY and others */
  4681. if (status & BNX2X_DEF_SB_IDX) {
  4682. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4683. if (FCOE_INIT(bp) &&
  4684. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4685. /* Prevent local bottom-halves from running as
  4686. * we are going to change the local NAPI list.
  4687. */
  4688. local_bh_disable();
  4689. napi_schedule(&bnx2x_fcoe(bp, napi));
  4690. local_bh_enable();
  4691. }
  4692. /* Handle EQ completions */
  4693. bnx2x_eq_int(bp);
  4694. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4695. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4696. status &= ~BNX2X_DEF_SB_IDX;
  4697. }
  4698. /* if status is non zero then perhaps something went wrong */
  4699. if (unlikely(status))
  4700. DP(BNX2X_MSG_SP,
  4701. "got an unknown interrupt! (status 0x%x)\n", status);
  4702. /* ack status block only if something was actually handled */
  4703. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4704. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4705. }
  4706. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4707. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4708. &bp->sp_state)) {
  4709. bnx2x_link_report(bp);
  4710. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4711. }
  4712. }
  4713. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4714. {
  4715. struct net_device *dev = dev_instance;
  4716. struct bnx2x *bp = netdev_priv(dev);
  4717. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4718. IGU_INT_DISABLE, 0);
  4719. #ifdef BNX2X_STOP_ON_ERROR
  4720. if (unlikely(bp->panic))
  4721. return IRQ_HANDLED;
  4722. #endif
  4723. if (CNIC_LOADED(bp)) {
  4724. struct cnic_ops *c_ops;
  4725. rcu_read_lock();
  4726. c_ops = rcu_dereference(bp->cnic_ops);
  4727. if (c_ops)
  4728. c_ops->cnic_handler(bp->cnic_data, NULL);
  4729. rcu_read_unlock();
  4730. }
  4731. /* schedule sp task to perform default status block work, ack
  4732. * attentions and enable interrupts.
  4733. */
  4734. bnx2x_schedule_sp_task(bp);
  4735. return IRQ_HANDLED;
  4736. }
  4737. /* end of slow path */
  4738. void bnx2x_drv_pulse(struct bnx2x *bp)
  4739. {
  4740. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4741. bp->fw_drv_pulse_wr_seq);
  4742. }
  4743. static void bnx2x_timer(unsigned long data)
  4744. {
  4745. struct bnx2x *bp = (struct bnx2x *) data;
  4746. if (!netif_running(bp->dev))
  4747. return;
  4748. if (IS_PF(bp) &&
  4749. !BP_NOMCP(bp)) {
  4750. int mb_idx = BP_FW_MB_IDX(bp);
  4751. u16 drv_pulse;
  4752. u16 mcp_pulse;
  4753. ++bp->fw_drv_pulse_wr_seq;
  4754. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4755. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4756. bnx2x_drv_pulse(bp);
  4757. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4758. MCP_PULSE_SEQ_MASK);
  4759. /* The delta between driver pulse and mcp response
  4760. * should not get too big. If the MFW is more than 5 pulses
  4761. * behind, we should worry about it enough to generate an error
  4762. * log.
  4763. */
  4764. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4765. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4766. drv_pulse, mcp_pulse);
  4767. }
  4768. if (bp->state == BNX2X_STATE_OPEN)
  4769. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4770. /* sample pf vf bulletin board for new posts from pf */
  4771. if (IS_VF(bp))
  4772. bnx2x_timer_sriov(bp);
  4773. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4774. }
  4775. /* end of Statistics */
  4776. /* nic init */
  4777. /*
  4778. * nic init service functions
  4779. */
  4780. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4781. {
  4782. u32 i;
  4783. if (!(len%4) && !(addr%4))
  4784. for (i = 0; i < len; i += 4)
  4785. REG_WR(bp, addr + i, fill);
  4786. else
  4787. for (i = 0; i < len; i++)
  4788. REG_WR8(bp, addr + i, fill);
  4789. }
  4790. /* helper: writes FP SP data to FW - data_size in dwords */
  4791. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4792. int fw_sb_id,
  4793. u32 *sb_data_p,
  4794. u32 data_size)
  4795. {
  4796. int index;
  4797. for (index = 0; index < data_size; index++)
  4798. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4799. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4800. sizeof(u32)*index,
  4801. *(sb_data_p + index));
  4802. }
  4803. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4804. {
  4805. u32 *sb_data_p;
  4806. u32 data_size = 0;
  4807. struct hc_status_block_data_e2 sb_data_e2;
  4808. struct hc_status_block_data_e1x sb_data_e1x;
  4809. /* disable the function first */
  4810. if (!CHIP_IS_E1x(bp)) {
  4811. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4812. sb_data_e2.common.state = SB_DISABLED;
  4813. sb_data_e2.common.p_func.vf_valid = false;
  4814. sb_data_p = (u32 *)&sb_data_e2;
  4815. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4816. } else {
  4817. memset(&sb_data_e1x, 0,
  4818. sizeof(struct hc_status_block_data_e1x));
  4819. sb_data_e1x.common.state = SB_DISABLED;
  4820. sb_data_e1x.common.p_func.vf_valid = false;
  4821. sb_data_p = (u32 *)&sb_data_e1x;
  4822. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4823. }
  4824. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4825. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4826. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4827. CSTORM_STATUS_BLOCK_SIZE);
  4828. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4829. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4830. CSTORM_SYNC_BLOCK_SIZE);
  4831. }
  4832. /* helper: writes SP SB data to FW */
  4833. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4834. struct hc_sp_status_block_data *sp_sb_data)
  4835. {
  4836. int func = BP_FUNC(bp);
  4837. int i;
  4838. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4839. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4840. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4841. i*sizeof(u32),
  4842. *((u32 *)sp_sb_data + i));
  4843. }
  4844. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4845. {
  4846. int func = BP_FUNC(bp);
  4847. struct hc_sp_status_block_data sp_sb_data;
  4848. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4849. sp_sb_data.state = SB_DISABLED;
  4850. sp_sb_data.p_func.vf_valid = false;
  4851. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4852. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4853. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4854. CSTORM_SP_STATUS_BLOCK_SIZE);
  4855. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4856. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4857. CSTORM_SP_SYNC_BLOCK_SIZE);
  4858. }
  4859. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4860. int igu_sb_id, int igu_seg_id)
  4861. {
  4862. hc_sm->igu_sb_id = igu_sb_id;
  4863. hc_sm->igu_seg_id = igu_seg_id;
  4864. hc_sm->timer_value = 0xFF;
  4865. hc_sm->time_to_expire = 0xFFFFFFFF;
  4866. }
  4867. /* allocates state machine ids. */
  4868. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4869. {
  4870. /* zero out state machine indices */
  4871. /* rx indices */
  4872. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4873. /* tx indices */
  4874. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4875. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4876. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4877. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4878. /* map indices */
  4879. /* rx indices */
  4880. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4881. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4882. /* tx indices */
  4883. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4884. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4885. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4886. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4887. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4888. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4889. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4890. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4891. }
  4892. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4893. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4894. {
  4895. int igu_seg_id;
  4896. struct hc_status_block_data_e2 sb_data_e2;
  4897. struct hc_status_block_data_e1x sb_data_e1x;
  4898. struct hc_status_block_sm *hc_sm_p;
  4899. int data_size;
  4900. u32 *sb_data_p;
  4901. if (CHIP_INT_MODE_IS_BC(bp))
  4902. igu_seg_id = HC_SEG_ACCESS_NORM;
  4903. else
  4904. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4905. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4906. if (!CHIP_IS_E1x(bp)) {
  4907. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4908. sb_data_e2.common.state = SB_ENABLED;
  4909. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4910. sb_data_e2.common.p_func.vf_id = vfid;
  4911. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4912. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4913. sb_data_e2.common.same_igu_sb_1b = true;
  4914. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4915. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4916. hc_sm_p = sb_data_e2.common.state_machine;
  4917. sb_data_p = (u32 *)&sb_data_e2;
  4918. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4919. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4920. } else {
  4921. memset(&sb_data_e1x, 0,
  4922. sizeof(struct hc_status_block_data_e1x));
  4923. sb_data_e1x.common.state = SB_ENABLED;
  4924. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4925. sb_data_e1x.common.p_func.vf_id = 0xff;
  4926. sb_data_e1x.common.p_func.vf_valid = false;
  4927. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4928. sb_data_e1x.common.same_igu_sb_1b = true;
  4929. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4930. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4931. hc_sm_p = sb_data_e1x.common.state_machine;
  4932. sb_data_p = (u32 *)&sb_data_e1x;
  4933. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4934. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4935. }
  4936. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4937. igu_sb_id, igu_seg_id);
  4938. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4939. igu_sb_id, igu_seg_id);
  4940. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4941. /* write indices to HW - PCI guarantees endianity of regpairs */
  4942. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4943. }
  4944. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4945. u16 tx_usec, u16 rx_usec)
  4946. {
  4947. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4948. false, rx_usec);
  4949. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4950. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4951. tx_usec);
  4952. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4953. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4954. tx_usec);
  4955. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4956. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4957. tx_usec);
  4958. }
  4959. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4960. {
  4961. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4962. dma_addr_t mapping = bp->def_status_blk_mapping;
  4963. int igu_sp_sb_index;
  4964. int igu_seg_id;
  4965. int port = BP_PORT(bp);
  4966. int func = BP_FUNC(bp);
  4967. int reg_offset, reg_offset_en5;
  4968. u64 section;
  4969. int index;
  4970. struct hc_sp_status_block_data sp_sb_data;
  4971. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4972. if (CHIP_INT_MODE_IS_BC(bp)) {
  4973. igu_sp_sb_index = DEF_SB_IGU_ID;
  4974. igu_seg_id = HC_SEG_ACCESS_DEF;
  4975. } else {
  4976. igu_sp_sb_index = bp->igu_dsb_id;
  4977. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4978. }
  4979. /* ATTN */
  4980. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4981. atten_status_block);
  4982. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4983. bp->attn_state = 0;
  4984. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4985. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4986. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4987. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4988. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4989. int sindex;
  4990. /* take care of sig[0]..sig[4] */
  4991. for (sindex = 0; sindex < 4; sindex++)
  4992. bp->attn_group[index].sig[sindex] =
  4993. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4994. if (!CHIP_IS_E1x(bp))
  4995. /*
  4996. * enable5 is separate from the rest of the registers,
  4997. * and therefore the address skip is 4
  4998. * and not 16 between the different groups
  4999. */
  5000. bp->attn_group[index].sig[4] = REG_RD(bp,
  5001. reg_offset_en5 + 0x4*index);
  5002. else
  5003. bp->attn_group[index].sig[4] = 0;
  5004. }
  5005. if (bp->common.int_block == INT_BLOCK_HC) {
  5006. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5007. HC_REG_ATTN_MSG0_ADDR_L);
  5008. REG_WR(bp, reg_offset, U64_LO(section));
  5009. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5010. } else if (!CHIP_IS_E1x(bp)) {
  5011. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5012. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5013. }
  5014. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5015. sp_sb);
  5016. bnx2x_zero_sp_sb(bp);
  5017. /* PCI guarantees endianity of regpairs */
  5018. sp_sb_data.state = SB_ENABLED;
  5019. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5020. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5021. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5022. sp_sb_data.igu_seg_id = igu_seg_id;
  5023. sp_sb_data.p_func.pf_id = func;
  5024. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5025. sp_sb_data.p_func.vf_id = 0xff;
  5026. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5027. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5028. }
  5029. void bnx2x_update_coalesce(struct bnx2x *bp)
  5030. {
  5031. int i;
  5032. for_each_eth_queue(bp, i)
  5033. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5034. bp->tx_ticks, bp->rx_ticks);
  5035. }
  5036. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5037. {
  5038. spin_lock_init(&bp->spq_lock);
  5039. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5040. bp->spq_prod_idx = 0;
  5041. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5042. bp->spq_prod_bd = bp->spq;
  5043. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5044. }
  5045. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5046. {
  5047. int i;
  5048. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5049. union event_ring_elem *elem =
  5050. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5051. elem->next_page.addr.hi =
  5052. cpu_to_le32(U64_HI(bp->eq_mapping +
  5053. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5054. elem->next_page.addr.lo =
  5055. cpu_to_le32(U64_LO(bp->eq_mapping +
  5056. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5057. }
  5058. bp->eq_cons = 0;
  5059. bp->eq_prod = NUM_EQ_DESC;
  5060. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5061. /* we want a warning message before it gets wrought... */
  5062. atomic_set(&bp->eq_spq_left,
  5063. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5064. }
  5065. /* called with netif_addr_lock_bh() */
  5066. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5067. unsigned long rx_mode_flags,
  5068. unsigned long rx_accept_flags,
  5069. unsigned long tx_accept_flags,
  5070. unsigned long ramrod_flags)
  5071. {
  5072. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5073. int rc;
  5074. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5075. /* Prepare ramrod parameters */
  5076. ramrod_param.cid = 0;
  5077. ramrod_param.cl_id = cl_id;
  5078. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5079. ramrod_param.func_id = BP_FUNC(bp);
  5080. ramrod_param.pstate = &bp->sp_state;
  5081. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5082. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5083. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5084. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5085. ramrod_param.ramrod_flags = ramrod_flags;
  5086. ramrod_param.rx_mode_flags = rx_mode_flags;
  5087. ramrod_param.rx_accept_flags = rx_accept_flags;
  5088. ramrod_param.tx_accept_flags = tx_accept_flags;
  5089. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5090. if (rc < 0) {
  5091. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5092. return rc;
  5093. }
  5094. return 0;
  5095. }
  5096. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5097. unsigned long *rx_accept_flags,
  5098. unsigned long *tx_accept_flags)
  5099. {
  5100. /* Clear the flags first */
  5101. *rx_accept_flags = 0;
  5102. *tx_accept_flags = 0;
  5103. switch (rx_mode) {
  5104. case BNX2X_RX_MODE_NONE:
  5105. /*
  5106. * 'drop all' supersedes any accept flags that may have been
  5107. * passed to the function.
  5108. */
  5109. break;
  5110. case BNX2X_RX_MODE_NORMAL:
  5111. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5112. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5113. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5114. /* internal switching mode */
  5115. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5116. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5117. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5118. break;
  5119. case BNX2X_RX_MODE_ALLMULTI:
  5120. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5121. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5122. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5123. /* internal switching mode */
  5124. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5125. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5126. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5127. break;
  5128. case BNX2X_RX_MODE_PROMISC:
  5129. /* According to definition of SI mode, iface in promisc mode
  5130. * should receive matched and unmatched (in resolution of port)
  5131. * unicast packets.
  5132. */
  5133. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5134. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5135. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5136. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5137. /* internal switching mode */
  5138. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5139. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5140. if (IS_MF_SI(bp))
  5141. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5142. else
  5143. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5144. break;
  5145. default:
  5146. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5147. return -EINVAL;
  5148. }
  5149. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5150. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5151. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5152. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5153. }
  5154. return 0;
  5155. }
  5156. /* called with netif_addr_lock_bh() */
  5157. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5158. {
  5159. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5160. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5161. int rc;
  5162. if (!NO_FCOE(bp))
  5163. /* Configure rx_mode of FCoE Queue */
  5164. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5165. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5166. &tx_accept_flags);
  5167. if (rc)
  5168. return rc;
  5169. __set_bit(RAMROD_RX, &ramrod_flags);
  5170. __set_bit(RAMROD_TX, &ramrod_flags);
  5171. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5172. rx_accept_flags, tx_accept_flags,
  5173. ramrod_flags);
  5174. }
  5175. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5176. {
  5177. int i;
  5178. /* Zero this manually as its initialization is
  5179. currently missing in the initTool */
  5180. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5181. REG_WR(bp, BAR_USTRORM_INTMEM +
  5182. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5183. if (!CHIP_IS_E1x(bp)) {
  5184. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5185. CHIP_INT_MODE_IS_BC(bp) ?
  5186. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5187. }
  5188. }
  5189. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5190. {
  5191. switch (load_code) {
  5192. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5193. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5194. bnx2x_init_internal_common(bp);
  5195. /* no break */
  5196. case FW_MSG_CODE_DRV_LOAD_PORT:
  5197. /* nothing to do */
  5198. /* no break */
  5199. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5200. /* internal memory per function is
  5201. initialized inside bnx2x_pf_init */
  5202. break;
  5203. default:
  5204. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5205. break;
  5206. }
  5207. }
  5208. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5209. {
  5210. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5211. }
  5212. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5213. {
  5214. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5215. }
  5216. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5217. {
  5218. if (CHIP_IS_E1x(fp->bp))
  5219. return BP_L_ID(fp->bp) + fp->index;
  5220. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5221. return bnx2x_fp_igu_sb_id(fp);
  5222. }
  5223. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5224. {
  5225. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5226. u8 cos;
  5227. unsigned long q_type = 0;
  5228. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5229. fp->rx_queue = fp_idx;
  5230. fp->cid = fp_idx;
  5231. fp->cl_id = bnx2x_fp_cl_id(fp);
  5232. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5233. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5234. /* qZone id equals to FW (per path) client id */
  5235. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5236. /* init shortcut */
  5237. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5238. /* Setup SB indices */
  5239. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5240. /* Configure Queue State object */
  5241. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5242. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5243. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5244. /* init tx data */
  5245. for_each_cos_in_tx_queue(fp, cos) {
  5246. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5247. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5248. FP_COS_TO_TXQ(fp, cos, bp),
  5249. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5250. cids[cos] = fp->txdata_ptr[cos]->cid;
  5251. }
  5252. /* nothing more for vf to do here */
  5253. if (IS_VF(bp))
  5254. return;
  5255. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5256. fp->fw_sb_id, fp->igu_sb_id);
  5257. bnx2x_update_fpsb_idx(fp);
  5258. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5259. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5260. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5261. /**
  5262. * Configure classification DBs: Always enable Tx switching
  5263. */
  5264. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5265. DP(NETIF_MSG_IFUP,
  5266. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5267. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5268. fp->igu_sb_id);
  5269. }
  5270. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5271. {
  5272. int i;
  5273. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5274. struct eth_tx_next_bd *tx_next_bd =
  5275. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5276. tx_next_bd->addr_hi =
  5277. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5278. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5279. tx_next_bd->addr_lo =
  5280. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5281. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5282. }
  5283. *txdata->tx_cons_sb = cpu_to_le16(0);
  5284. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5285. txdata->tx_db.data.zero_fill1 = 0;
  5286. txdata->tx_db.data.prod = 0;
  5287. txdata->tx_pkt_prod = 0;
  5288. txdata->tx_pkt_cons = 0;
  5289. txdata->tx_bd_prod = 0;
  5290. txdata->tx_bd_cons = 0;
  5291. txdata->tx_pkt = 0;
  5292. }
  5293. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5294. {
  5295. int i;
  5296. for_each_tx_queue_cnic(bp, i)
  5297. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5298. }
  5299. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5300. {
  5301. int i;
  5302. u8 cos;
  5303. for_each_eth_queue(bp, i)
  5304. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5305. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5306. }
  5307. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5308. {
  5309. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5310. unsigned long q_type = 0;
  5311. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5312. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5313. BNX2X_FCOE_ETH_CL_ID_IDX);
  5314. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5315. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5316. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5317. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5318. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5319. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5320. fp);
  5321. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5322. /* qZone id equals to FW (per path) client id */
  5323. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5324. /* init shortcut */
  5325. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5326. bnx2x_rx_ustorm_prods_offset(fp);
  5327. /* Configure Queue State object */
  5328. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5329. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5330. /* No multi-CoS for FCoE L2 client */
  5331. BUG_ON(fp->max_cos != 1);
  5332. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5333. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5334. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5335. DP(NETIF_MSG_IFUP,
  5336. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5337. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5338. fp->igu_sb_id);
  5339. }
  5340. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5341. {
  5342. if (!NO_FCOE(bp))
  5343. bnx2x_init_fcoe_fp(bp);
  5344. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5345. BNX2X_VF_ID_INVALID, false,
  5346. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5347. /* ensure status block indices were read */
  5348. rmb();
  5349. bnx2x_init_rx_rings_cnic(bp);
  5350. bnx2x_init_tx_rings_cnic(bp);
  5351. /* flush all */
  5352. mb();
  5353. mmiowb();
  5354. }
  5355. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5356. {
  5357. int i;
  5358. /* Setup NIC internals and enable interrupts */
  5359. for_each_eth_queue(bp, i)
  5360. bnx2x_init_eth_fp(bp, i);
  5361. /* ensure status block indices were read */
  5362. rmb();
  5363. bnx2x_init_rx_rings(bp);
  5364. bnx2x_init_tx_rings(bp);
  5365. if (IS_PF(bp)) {
  5366. /* Initialize MOD_ABS interrupts */
  5367. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5368. bp->common.shmem_base,
  5369. bp->common.shmem2_base, BP_PORT(bp));
  5370. /* initialize the default status block and sp ring */
  5371. bnx2x_init_def_sb(bp);
  5372. bnx2x_update_dsb_idx(bp);
  5373. bnx2x_init_sp_ring(bp);
  5374. } else {
  5375. bnx2x_memset_stats(bp);
  5376. }
  5377. }
  5378. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5379. {
  5380. bnx2x_init_eq_ring(bp);
  5381. bnx2x_init_internal(bp, load_code);
  5382. bnx2x_pf_init(bp);
  5383. bnx2x_stats_init(bp);
  5384. /* flush all before enabling interrupts */
  5385. mb();
  5386. mmiowb();
  5387. bnx2x_int_enable(bp);
  5388. /* Check for SPIO5 */
  5389. bnx2x_attn_int_deasserted0(bp,
  5390. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5391. AEU_INPUTS_ATTN_BITS_SPIO5);
  5392. }
  5393. /* gzip service functions */
  5394. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5395. {
  5396. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5397. &bp->gunzip_mapping, GFP_KERNEL);
  5398. if (bp->gunzip_buf == NULL)
  5399. goto gunzip_nomem1;
  5400. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5401. if (bp->strm == NULL)
  5402. goto gunzip_nomem2;
  5403. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5404. if (bp->strm->workspace == NULL)
  5405. goto gunzip_nomem3;
  5406. return 0;
  5407. gunzip_nomem3:
  5408. kfree(bp->strm);
  5409. bp->strm = NULL;
  5410. gunzip_nomem2:
  5411. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5412. bp->gunzip_mapping);
  5413. bp->gunzip_buf = NULL;
  5414. gunzip_nomem1:
  5415. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5416. return -ENOMEM;
  5417. }
  5418. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5419. {
  5420. if (bp->strm) {
  5421. vfree(bp->strm->workspace);
  5422. kfree(bp->strm);
  5423. bp->strm = NULL;
  5424. }
  5425. if (bp->gunzip_buf) {
  5426. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5427. bp->gunzip_mapping);
  5428. bp->gunzip_buf = NULL;
  5429. }
  5430. }
  5431. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5432. {
  5433. int n, rc;
  5434. /* check gzip header */
  5435. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5436. BNX2X_ERR("Bad gzip header\n");
  5437. return -EINVAL;
  5438. }
  5439. n = 10;
  5440. #define FNAME 0x8
  5441. if (zbuf[3] & FNAME)
  5442. while ((zbuf[n++] != 0) && (n < len));
  5443. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5444. bp->strm->avail_in = len - n;
  5445. bp->strm->next_out = bp->gunzip_buf;
  5446. bp->strm->avail_out = FW_BUF_SIZE;
  5447. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5448. if (rc != Z_OK)
  5449. return rc;
  5450. rc = zlib_inflate(bp->strm, Z_FINISH);
  5451. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5452. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5453. bp->strm->msg);
  5454. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5455. if (bp->gunzip_outlen & 0x3)
  5456. netdev_err(bp->dev,
  5457. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5458. bp->gunzip_outlen);
  5459. bp->gunzip_outlen >>= 2;
  5460. zlib_inflateEnd(bp->strm);
  5461. if (rc == Z_STREAM_END)
  5462. return 0;
  5463. return rc;
  5464. }
  5465. /* nic load/unload */
  5466. /*
  5467. * General service functions
  5468. */
  5469. /* send a NIG loopback debug packet */
  5470. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5471. {
  5472. u32 wb_write[3];
  5473. /* Ethernet source and destination addresses */
  5474. wb_write[0] = 0x55555555;
  5475. wb_write[1] = 0x55555555;
  5476. wb_write[2] = 0x20; /* SOP */
  5477. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5478. /* NON-IP protocol */
  5479. wb_write[0] = 0x09000000;
  5480. wb_write[1] = 0x55555555;
  5481. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5482. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5483. }
  5484. /* some of the internal memories
  5485. * are not directly readable from the driver
  5486. * to test them we send debug packets
  5487. */
  5488. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5489. {
  5490. int factor;
  5491. int count, i;
  5492. u32 val = 0;
  5493. if (CHIP_REV_IS_FPGA(bp))
  5494. factor = 120;
  5495. else if (CHIP_REV_IS_EMUL(bp))
  5496. factor = 200;
  5497. else
  5498. factor = 1;
  5499. /* Disable inputs of parser neighbor blocks */
  5500. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5501. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5502. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5503. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5504. /* Write 0 to parser credits for CFC search request */
  5505. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5506. /* send Ethernet packet */
  5507. bnx2x_lb_pckt(bp);
  5508. /* TODO do i reset NIG statistic? */
  5509. /* Wait until NIG register shows 1 packet of size 0x10 */
  5510. count = 1000 * factor;
  5511. while (count) {
  5512. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5513. val = *bnx2x_sp(bp, wb_data[0]);
  5514. if (val == 0x10)
  5515. break;
  5516. usleep_range(10000, 20000);
  5517. count--;
  5518. }
  5519. if (val != 0x10) {
  5520. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5521. return -1;
  5522. }
  5523. /* Wait until PRS register shows 1 packet */
  5524. count = 1000 * factor;
  5525. while (count) {
  5526. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5527. if (val == 1)
  5528. break;
  5529. usleep_range(10000, 20000);
  5530. count--;
  5531. }
  5532. if (val != 0x1) {
  5533. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5534. return -2;
  5535. }
  5536. /* Reset and init BRB, PRS */
  5537. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5538. msleep(50);
  5539. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5540. msleep(50);
  5541. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5542. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5543. DP(NETIF_MSG_HW, "part2\n");
  5544. /* Disable inputs of parser neighbor blocks */
  5545. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5546. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5547. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5548. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5549. /* Write 0 to parser credits for CFC search request */
  5550. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5551. /* send 10 Ethernet packets */
  5552. for (i = 0; i < 10; i++)
  5553. bnx2x_lb_pckt(bp);
  5554. /* Wait until NIG register shows 10 + 1
  5555. packets of size 11*0x10 = 0xb0 */
  5556. count = 1000 * factor;
  5557. while (count) {
  5558. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5559. val = *bnx2x_sp(bp, wb_data[0]);
  5560. if (val == 0xb0)
  5561. break;
  5562. usleep_range(10000, 20000);
  5563. count--;
  5564. }
  5565. if (val != 0xb0) {
  5566. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5567. return -3;
  5568. }
  5569. /* Wait until PRS register shows 2 packets */
  5570. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5571. if (val != 2)
  5572. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5573. /* Write 1 to parser credits for CFC search request */
  5574. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5575. /* Wait until PRS register shows 3 packets */
  5576. msleep(10 * factor);
  5577. /* Wait until NIG register shows 1 packet of size 0x10 */
  5578. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5579. if (val != 3)
  5580. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5581. /* clear NIG EOP FIFO */
  5582. for (i = 0; i < 11; i++)
  5583. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5584. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5585. if (val != 1) {
  5586. BNX2X_ERR("clear of NIG failed\n");
  5587. return -4;
  5588. }
  5589. /* Reset and init BRB, PRS, NIG */
  5590. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5591. msleep(50);
  5592. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5593. msleep(50);
  5594. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5595. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5596. if (!CNIC_SUPPORT(bp))
  5597. /* set NIC mode */
  5598. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5599. /* Enable inputs of parser neighbor blocks */
  5600. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5601. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5602. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5603. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5604. DP(NETIF_MSG_HW, "done\n");
  5605. return 0; /* OK */
  5606. }
  5607. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5608. {
  5609. u32 val;
  5610. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5611. if (!CHIP_IS_E1x(bp))
  5612. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5613. else
  5614. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5615. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5616. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5617. /*
  5618. * mask read length error interrupts in brb for parser
  5619. * (parsing unit and 'checksum and crc' unit)
  5620. * these errors are legal (PU reads fixed length and CAC can cause
  5621. * read length error on truncated packets)
  5622. */
  5623. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5624. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5625. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5626. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5627. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5628. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5629. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5630. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5631. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5632. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5633. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5634. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5635. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5636. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5637. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5638. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5639. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5640. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5641. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5642. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5643. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5644. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5645. if (!CHIP_IS_E1x(bp))
  5646. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5647. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5648. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5649. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5650. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5651. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5652. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5653. if (!CHIP_IS_E1x(bp))
  5654. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5655. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5656. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5657. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5658. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5659. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5660. }
  5661. static void bnx2x_reset_common(struct bnx2x *bp)
  5662. {
  5663. u32 val = 0x1400;
  5664. /* reset_common */
  5665. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5666. 0xd3ffff7f);
  5667. if (CHIP_IS_E3(bp)) {
  5668. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5669. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5670. }
  5671. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5672. }
  5673. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5674. {
  5675. bp->dmae_ready = 0;
  5676. spin_lock_init(&bp->dmae_lock);
  5677. }
  5678. static void bnx2x_init_pxp(struct bnx2x *bp)
  5679. {
  5680. u16 devctl;
  5681. int r_order, w_order;
  5682. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5683. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5684. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5685. if (bp->mrrs == -1)
  5686. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5687. else {
  5688. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5689. r_order = bp->mrrs;
  5690. }
  5691. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5692. }
  5693. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5694. {
  5695. int is_required;
  5696. u32 val;
  5697. int port;
  5698. if (BP_NOMCP(bp))
  5699. return;
  5700. is_required = 0;
  5701. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5702. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5703. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5704. is_required = 1;
  5705. /*
  5706. * The fan failure mechanism is usually related to the PHY type since
  5707. * the power consumption of the board is affected by the PHY. Currently,
  5708. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5709. */
  5710. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5711. for (port = PORT_0; port < PORT_MAX; port++) {
  5712. is_required |=
  5713. bnx2x_fan_failure_det_req(
  5714. bp,
  5715. bp->common.shmem_base,
  5716. bp->common.shmem2_base,
  5717. port);
  5718. }
  5719. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5720. if (is_required == 0)
  5721. return;
  5722. /* Fan failure is indicated by SPIO 5 */
  5723. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5724. /* set to active low mode */
  5725. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5726. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5727. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5728. /* enable interrupt to signal the IGU */
  5729. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5730. val |= MISC_SPIO_SPIO5;
  5731. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5732. }
  5733. void bnx2x_pf_disable(struct bnx2x *bp)
  5734. {
  5735. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5736. val &= ~IGU_PF_CONF_FUNC_EN;
  5737. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5738. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5739. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5740. }
  5741. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5742. {
  5743. u32 shmem_base[2], shmem2_base[2];
  5744. /* Avoid common init in case MFW supports LFA */
  5745. if (SHMEM2_RD(bp, size) >
  5746. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5747. return;
  5748. shmem_base[0] = bp->common.shmem_base;
  5749. shmem2_base[0] = bp->common.shmem2_base;
  5750. if (!CHIP_IS_E1x(bp)) {
  5751. shmem_base[1] =
  5752. SHMEM2_RD(bp, other_shmem_base_addr);
  5753. shmem2_base[1] =
  5754. SHMEM2_RD(bp, other_shmem2_base_addr);
  5755. }
  5756. bnx2x_acquire_phy_lock(bp);
  5757. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5758. bp->common.chip_id);
  5759. bnx2x_release_phy_lock(bp);
  5760. }
  5761. /**
  5762. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5763. *
  5764. * @bp: driver handle
  5765. */
  5766. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5767. {
  5768. u32 val;
  5769. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5770. /*
  5771. * take the RESET lock to protect undi_unload flow from accessing
  5772. * registers while we're resetting the chip
  5773. */
  5774. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5775. bnx2x_reset_common(bp);
  5776. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5777. val = 0xfffc;
  5778. if (CHIP_IS_E3(bp)) {
  5779. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5780. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5781. }
  5782. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5783. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5784. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5785. if (!CHIP_IS_E1x(bp)) {
  5786. u8 abs_func_id;
  5787. /**
  5788. * 4-port mode or 2-port mode we need to turn of master-enable
  5789. * for everyone, after that, turn it back on for self.
  5790. * so, we disregard multi-function or not, and always disable
  5791. * for all functions on the given path, this means 0,2,4,6 for
  5792. * path 0 and 1,3,5,7 for path 1
  5793. */
  5794. for (abs_func_id = BP_PATH(bp);
  5795. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5796. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5797. REG_WR(bp,
  5798. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5799. 1);
  5800. continue;
  5801. }
  5802. bnx2x_pretend_func(bp, abs_func_id);
  5803. /* clear pf enable */
  5804. bnx2x_pf_disable(bp);
  5805. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5806. }
  5807. }
  5808. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5809. if (CHIP_IS_E1(bp)) {
  5810. /* enable HW interrupt from PXP on USDM overflow
  5811. bit 16 on INT_MASK_0 */
  5812. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5813. }
  5814. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5815. bnx2x_init_pxp(bp);
  5816. #ifdef __BIG_ENDIAN
  5817. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5818. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5819. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5820. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5821. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5822. /* make sure this value is 0 */
  5823. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5824. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5825. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5826. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5827. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5828. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5829. #endif
  5830. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5831. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5832. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5833. /* let the HW do it's magic ... */
  5834. msleep(100);
  5835. /* finish PXP init */
  5836. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5837. if (val != 1) {
  5838. BNX2X_ERR("PXP2 CFG failed\n");
  5839. return -EBUSY;
  5840. }
  5841. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5842. if (val != 1) {
  5843. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5844. return -EBUSY;
  5845. }
  5846. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5847. * have entries with value "0" and valid bit on.
  5848. * This needs to be done by the first PF that is loaded in a path
  5849. * (i.e. common phase)
  5850. */
  5851. if (!CHIP_IS_E1x(bp)) {
  5852. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5853. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5854. * This occurs when a different function (func2,3) is being marked
  5855. * as "scan-off". Real-life scenario for example: if a driver is being
  5856. * load-unloaded while func6,7 are down. This will cause the timer to access
  5857. * the ilt, translate to a logical address and send a request to read/write.
  5858. * Since the ilt for the function that is down is not valid, this will cause
  5859. * a translation error which is unrecoverable.
  5860. * The Workaround is intended to make sure that when this happens nothing fatal
  5861. * will occur. The workaround:
  5862. * 1. First PF driver which loads on a path will:
  5863. * a. After taking the chip out of reset, by using pretend,
  5864. * it will write "0" to the following registers of
  5865. * the other vnics.
  5866. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5867. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5868. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5869. * And for itself it will write '1' to
  5870. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5871. * dmae-operations (writing to pram for example.)
  5872. * note: can be done for only function 6,7 but cleaner this
  5873. * way.
  5874. * b. Write zero+valid to the entire ILT.
  5875. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5876. * VNIC3 (of that port). The range allocated will be the
  5877. * entire ILT. This is needed to prevent ILT range error.
  5878. * 2. Any PF driver load flow:
  5879. * a. ILT update with the physical addresses of the allocated
  5880. * logical pages.
  5881. * b. Wait 20msec. - note that this timeout is needed to make
  5882. * sure there are no requests in one of the PXP internal
  5883. * queues with "old" ILT addresses.
  5884. * c. PF enable in the PGLC.
  5885. * d. Clear the was_error of the PF in the PGLC. (could have
  5886. * occurred while driver was down)
  5887. * e. PF enable in the CFC (WEAK + STRONG)
  5888. * f. Timers scan enable
  5889. * 3. PF driver unload flow:
  5890. * a. Clear the Timers scan_en.
  5891. * b. Polling for scan_on=0 for that PF.
  5892. * c. Clear the PF enable bit in the PXP.
  5893. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5894. * e. Write zero+valid to all ILT entries (The valid bit must
  5895. * stay set)
  5896. * f. If this is VNIC 3 of a port then also init
  5897. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5898. * to the last entry in the ILT.
  5899. *
  5900. * Notes:
  5901. * Currently the PF error in the PGLC is non recoverable.
  5902. * In the future the there will be a recovery routine for this error.
  5903. * Currently attention is masked.
  5904. * Having an MCP lock on the load/unload process does not guarantee that
  5905. * there is no Timer disable during Func6/7 enable. This is because the
  5906. * Timers scan is currently being cleared by the MCP on FLR.
  5907. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5908. * there is error before clearing it. But the flow above is simpler and
  5909. * more general.
  5910. * All ILT entries are written by zero+valid and not just PF6/7
  5911. * ILT entries since in the future the ILT entries allocation for
  5912. * PF-s might be dynamic.
  5913. */
  5914. struct ilt_client_info ilt_cli;
  5915. struct bnx2x_ilt ilt;
  5916. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5917. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5918. /* initialize dummy TM client */
  5919. ilt_cli.start = 0;
  5920. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5921. ilt_cli.client_num = ILT_CLIENT_TM;
  5922. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5923. * Step 2: set the timers first/last ilt entry to point
  5924. * to the entire range to prevent ILT range error for 3rd/4th
  5925. * vnic (this code assumes existence of the vnic)
  5926. *
  5927. * both steps performed by call to bnx2x_ilt_client_init_op()
  5928. * with dummy TM client
  5929. *
  5930. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5931. * and his brother are split registers
  5932. */
  5933. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5934. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5935. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5936. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5937. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5938. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5939. }
  5940. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5941. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5942. if (!CHIP_IS_E1x(bp)) {
  5943. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5944. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5945. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5946. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5947. /* let the HW do it's magic ... */
  5948. do {
  5949. msleep(200);
  5950. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5951. } while (factor-- && (val != 1));
  5952. if (val != 1) {
  5953. BNX2X_ERR("ATC_INIT failed\n");
  5954. return -EBUSY;
  5955. }
  5956. }
  5957. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5958. bnx2x_iov_init_dmae(bp);
  5959. /* clean the DMAE memory */
  5960. bp->dmae_ready = 1;
  5961. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5962. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5963. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5964. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5965. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5966. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5967. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5968. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5969. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5970. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5971. /* QM queues pointers table */
  5972. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5973. /* soft reset pulse */
  5974. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5975. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5976. if (CNIC_SUPPORT(bp))
  5977. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5978. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5979. if (!CHIP_REV_IS_SLOW(bp))
  5980. /* enable hw interrupt from doorbell Q */
  5981. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5982. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5983. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5984. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5985. if (!CHIP_IS_E1(bp))
  5986. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5987. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5988. if (IS_MF_AFEX(bp)) {
  5989. /* configure that VNTag and VLAN headers must be
  5990. * received in afex mode
  5991. */
  5992. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5993. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5994. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5995. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5996. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5997. } else {
  5998. /* Bit-map indicating which L2 hdrs may appear
  5999. * after the basic Ethernet header
  6000. */
  6001. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6002. bp->path_has_ovlan ? 7 : 6);
  6003. }
  6004. }
  6005. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6006. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6007. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6008. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6009. if (!CHIP_IS_E1x(bp)) {
  6010. /* reset VFC memories */
  6011. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6012. VFC_MEMORIES_RST_REG_CAM_RST |
  6013. VFC_MEMORIES_RST_REG_RAM_RST);
  6014. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6015. VFC_MEMORIES_RST_REG_CAM_RST |
  6016. VFC_MEMORIES_RST_REG_RAM_RST);
  6017. msleep(20);
  6018. }
  6019. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6020. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6021. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6022. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6023. /* sync semi rtc */
  6024. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6025. 0x80000000);
  6026. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6027. 0x80000000);
  6028. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6029. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6030. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6031. if (!CHIP_IS_E1x(bp)) {
  6032. if (IS_MF_AFEX(bp)) {
  6033. /* configure that VNTag and VLAN headers must be
  6034. * sent in afex mode
  6035. */
  6036. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6037. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6038. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6039. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6040. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6041. } else {
  6042. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6043. bp->path_has_ovlan ? 7 : 6);
  6044. }
  6045. }
  6046. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6047. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6048. if (CNIC_SUPPORT(bp)) {
  6049. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6050. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6051. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6052. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6053. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6054. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6055. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6056. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6057. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6058. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6059. }
  6060. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6061. if (sizeof(union cdu_context) != 1024)
  6062. /* we currently assume that a context is 1024 bytes */
  6063. dev_alert(&bp->pdev->dev,
  6064. "please adjust the size of cdu_context(%ld)\n",
  6065. (long)sizeof(union cdu_context));
  6066. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6067. val = (4 << 24) + (0 << 12) + 1024;
  6068. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6069. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6070. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6071. /* enable context validation interrupt from CFC */
  6072. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6073. /* set the thresholds to prevent CFC/CDU race */
  6074. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6075. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6076. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6077. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6078. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6079. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6080. /* Reset PCIE errors for debug */
  6081. REG_WR(bp, 0x2814, 0xffffffff);
  6082. REG_WR(bp, 0x3820, 0xffffffff);
  6083. if (!CHIP_IS_E1x(bp)) {
  6084. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6085. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6086. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6087. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6088. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6089. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6090. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6091. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6092. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6093. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6094. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6095. }
  6096. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6097. if (!CHIP_IS_E1(bp)) {
  6098. /* in E3 this done in per-port section */
  6099. if (!CHIP_IS_E3(bp))
  6100. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6101. }
  6102. if (CHIP_IS_E1H(bp))
  6103. /* not applicable for E2 (and above ...) */
  6104. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6105. if (CHIP_REV_IS_SLOW(bp))
  6106. msleep(200);
  6107. /* finish CFC init */
  6108. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6109. if (val != 1) {
  6110. BNX2X_ERR("CFC LL_INIT failed\n");
  6111. return -EBUSY;
  6112. }
  6113. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6114. if (val != 1) {
  6115. BNX2X_ERR("CFC AC_INIT failed\n");
  6116. return -EBUSY;
  6117. }
  6118. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6119. if (val != 1) {
  6120. BNX2X_ERR("CFC CAM_INIT failed\n");
  6121. return -EBUSY;
  6122. }
  6123. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6124. if (CHIP_IS_E1(bp)) {
  6125. /* read NIG statistic
  6126. to see if this is our first up since powerup */
  6127. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6128. val = *bnx2x_sp(bp, wb_data[0]);
  6129. /* do internal memory self test */
  6130. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6131. BNX2X_ERR("internal mem self test failed\n");
  6132. return -EBUSY;
  6133. }
  6134. }
  6135. bnx2x_setup_fan_failure_detection(bp);
  6136. /* clear PXP2 attentions */
  6137. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6138. bnx2x_enable_blocks_attention(bp);
  6139. bnx2x_enable_blocks_parity(bp);
  6140. if (!BP_NOMCP(bp)) {
  6141. if (CHIP_IS_E1x(bp))
  6142. bnx2x__common_init_phy(bp);
  6143. } else
  6144. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6145. return 0;
  6146. }
  6147. /**
  6148. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6149. *
  6150. * @bp: driver handle
  6151. */
  6152. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6153. {
  6154. int rc = bnx2x_init_hw_common(bp);
  6155. if (rc)
  6156. return rc;
  6157. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6158. if (!BP_NOMCP(bp))
  6159. bnx2x__common_init_phy(bp);
  6160. return 0;
  6161. }
  6162. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6163. {
  6164. int port = BP_PORT(bp);
  6165. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6166. u32 low, high;
  6167. u32 val, reg;
  6168. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6169. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6170. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6171. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6172. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6173. /* Timers bug workaround: disables the pf_master bit in pglue at
  6174. * common phase, we need to enable it here before any dmae access are
  6175. * attempted. Therefore we manually added the enable-master to the
  6176. * port phase (it also happens in the function phase)
  6177. */
  6178. if (!CHIP_IS_E1x(bp))
  6179. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6180. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6181. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6182. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6183. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6184. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6185. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6186. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6187. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6188. /* QM cid (connection) count */
  6189. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6190. if (CNIC_SUPPORT(bp)) {
  6191. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6192. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6193. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6194. }
  6195. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6196. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6197. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6198. if (IS_MF(bp))
  6199. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6200. else if (bp->dev->mtu > 4096) {
  6201. if (bp->flags & ONE_PORT_FLAG)
  6202. low = 160;
  6203. else {
  6204. val = bp->dev->mtu;
  6205. /* (24*1024 + val*4)/256 */
  6206. low = 96 + (val/64) +
  6207. ((val % 64) ? 1 : 0);
  6208. }
  6209. } else
  6210. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6211. high = low + 56; /* 14*1024/256 */
  6212. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6213. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6214. }
  6215. if (CHIP_MODE_IS_4_PORT(bp))
  6216. REG_WR(bp, (BP_PORT(bp) ?
  6217. BRB1_REG_MAC_GUARANTIED_1 :
  6218. BRB1_REG_MAC_GUARANTIED_0), 40);
  6219. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6220. if (CHIP_IS_E3B0(bp)) {
  6221. if (IS_MF_AFEX(bp)) {
  6222. /* configure headers for AFEX mode */
  6223. REG_WR(bp, BP_PORT(bp) ?
  6224. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6225. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6226. REG_WR(bp, BP_PORT(bp) ?
  6227. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6228. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6229. REG_WR(bp, BP_PORT(bp) ?
  6230. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6231. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6232. } else {
  6233. /* Ovlan exists only if we are in multi-function +
  6234. * switch-dependent mode, in switch-independent there
  6235. * is no ovlan headers
  6236. */
  6237. REG_WR(bp, BP_PORT(bp) ?
  6238. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6239. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6240. (bp->path_has_ovlan ? 7 : 6));
  6241. }
  6242. }
  6243. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6244. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6245. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6246. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6247. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6248. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6249. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6250. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6251. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6252. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6253. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6254. if (CHIP_IS_E1x(bp)) {
  6255. /* configure PBF to work without PAUSE mtu 9000 */
  6256. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6257. /* update threshold */
  6258. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6259. /* update init credit */
  6260. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6261. /* probe changes */
  6262. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6263. udelay(50);
  6264. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6265. }
  6266. if (CNIC_SUPPORT(bp))
  6267. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6268. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6269. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6270. if (CHIP_IS_E1(bp)) {
  6271. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6272. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6273. }
  6274. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6275. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6276. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6277. /* init aeu_mask_attn_func_0/1:
  6278. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6279. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6280. * bits 4-7 are used for "per vn group attention" */
  6281. val = IS_MF(bp) ? 0xF7 : 0x7;
  6282. /* Enable DCBX attention for all but E1 */
  6283. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6284. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6285. /* SCPAD_PARITY should NOT trigger close the gates */
  6286. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6287. REG_WR(bp, reg,
  6288. REG_RD(bp, reg) &
  6289. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6290. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6291. REG_WR(bp, reg,
  6292. REG_RD(bp, reg) &
  6293. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6294. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6295. if (!CHIP_IS_E1x(bp)) {
  6296. /* Bit-map indicating which L2 hdrs may appear after the
  6297. * basic Ethernet header
  6298. */
  6299. if (IS_MF_AFEX(bp))
  6300. REG_WR(bp, BP_PORT(bp) ?
  6301. NIG_REG_P1_HDRS_AFTER_BASIC :
  6302. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6303. else
  6304. REG_WR(bp, BP_PORT(bp) ?
  6305. NIG_REG_P1_HDRS_AFTER_BASIC :
  6306. NIG_REG_P0_HDRS_AFTER_BASIC,
  6307. IS_MF_SD(bp) ? 7 : 6);
  6308. if (CHIP_IS_E3(bp))
  6309. REG_WR(bp, BP_PORT(bp) ?
  6310. NIG_REG_LLH1_MF_MODE :
  6311. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6312. }
  6313. if (!CHIP_IS_E3(bp))
  6314. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6315. if (!CHIP_IS_E1(bp)) {
  6316. /* 0x2 disable mf_ov, 0x1 enable */
  6317. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6318. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6319. if (!CHIP_IS_E1x(bp)) {
  6320. val = 0;
  6321. switch (bp->mf_mode) {
  6322. case MULTI_FUNCTION_SD:
  6323. val = 1;
  6324. break;
  6325. case MULTI_FUNCTION_SI:
  6326. case MULTI_FUNCTION_AFEX:
  6327. val = 2;
  6328. break;
  6329. }
  6330. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6331. NIG_REG_LLH0_CLS_TYPE), val);
  6332. }
  6333. {
  6334. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6335. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6336. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6337. }
  6338. }
  6339. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6340. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6341. if (val & MISC_SPIO_SPIO5) {
  6342. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6343. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6344. val = REG_RD(bp, reg_addr);
  6345. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6346. REG_WR(bp, reg_addr, val);
  6347. }
  6348. return 0;
  6349. }
  6350. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6351. {
  6352. int reg;
  6353. u32 wb_write[2];
  6354. if (CHIP_IS_E1(bp))
  6355. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6356. else
  6357. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6358. wb_write[0] = ONCHIP_ADDR1(addr);
  6359. wb_write[1] = ONCHIP_ADDR2(addr);
  6360. REG_WR_DMAE(bp, reg, wb_write, 2);
  6361. }
  6362. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6363. {
  6364. u32 data, ctl, cnt = 100;
  6365. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6366. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6367. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6368. u32 sb_bit = 1 << (idu_sb_id%32);
  6369. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6370. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6371. /* Not supported in BC mode */
  6372. if (CHIP_INT_MODE_IS_BC(bp))
  6373. return;
  6374. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6375. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6376. IGU_REGULAR_CLEANUP_SET |
  6377. IGU_REGULAR_BCLEANUP;
  6378. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6379. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6380. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6381. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6382. data, igu_addr_data);
  6383. REG_WR(bp, igu_addr_data, data);
  6384. mmiowb();
  6385. barrier();
  6386. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6387. ctl, igu_addr_ctl);
  6388. REG_WR(bp, igu_addr_ctl, ctl);
  6389. mmiowb();
  6390. barrier();
  6391. /* wait for clean up to finish */
  6392. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6393. msleep(20);
  6394. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6395. DP(NETIF_MSG_HW,
  6396. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6397. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6398. }
  6399. }
  6400. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6401. {
  6402. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6403. }
  6404. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6405. {
  6406. u32 i, base = FUNC_ILT_BASE(func);
  6407. for (i = base; i < base + ILT_PER_FUNC; i++)
  6408. bnx2x_ilt_wr(bp, i, 0);
  6409. }
  6410. static void bnx2x_init_searcher(struct bnx2x *bp)
  6411. {
  6412. int port = BP_PORT(bp);
  6413. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6414. /* T1 hash bits value determines the T1 number of entries */
  6415. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6416. }
  6417. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6418. {
  6419. int rc;
  6420. struct bnx2x_func_state_params func_params = {NULL};
  6421. struct bnx2x_func_switch_update_params *switch_update_params =
  6422. &func_params.params.switch_update;
  6423. /* Prepare parameters for function state transitions */
  6424. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6425. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6426. func_params.f_obj = &bp->func_obj;
  6427. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6428. /* Function parameters */
  6429. switch_update_params->suspend = suspend;
  6430. rc = bnx2x_func_state_change(bp, &func_params);
  6431. return rc;
  6432. }
  6433. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6434. {
  6435. int rc, i, port = BP_PORT(bp);
  6436. int vlan_en = 0, mac_en[NUM_MACS];
  6437. /* Close input from network */
  6438. if (bp->mf_mode == SINGLE_FUNCTION) {
  6439. bnx2x_set_rx_filter(&bp->link_params, 0);
  6440. } else {
  6441. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6442. NIG_REG_LLH0_FUNC_EN);
  6443. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6444. NIG_REG_LLH0_FUNC_EN, 0);
  6445. for (i = 0; i < NUM_MACS; i++) {
  6446. mac_en[i] = REG_RD(bp, port ?
  6447. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6448. 4 * i) :
  6449. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6450. 4 * i));
  6451. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6452. 4 * i) :
  6453. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6454. }
  6455. }
  6456. /* Close BMC to host */
  6457. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6458. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6459. /* Suspend Tx switching to the PF. Completion of this ramrod
  6460. * further guarantees that all the packets of that PF / child
  6461. * VFs in BRB were processed by the Parser, so it is safe to
  6462. * change the NIC_MODE register.
  6463. */
  6464. rc = bnx2x_func_switch_update(bp, 1);
  6465. if (rc) {
  6466. BNX2X_ERR("Can't suspend tx-switching!\n");
  6467. return rc;
  6468. }
  6469. /* Change NIC_MODE register */
  6470. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6471. /* Open input from network */
  6472. if (bp->mf_mode == SINGLE_FUNCTION) {
  6473. bnx2x_set_rx_filter(&bp->link_params, 1);
  6474. } else {
  6475. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6476. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6477. for (i = 0; i < NUM_MACS; i++) {
  6478. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6479. 4 * i) :
  6480. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6481. mac_en[i]);
  6482. }
  6483. }
  6484. /* Enable BMC to host */
  6485. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6486. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6487. /* Resume Tx switching to the PF */
  6488. rc = bnx2x_func_switch_update(bp, 0);
  6489. if (rc) {
  6490. BNX2X_ERR("Can't resume tx-switching!\n");
  6491. return rc;
  6492. }
  6493. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6494. return 0;
  6495. }
  6496. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6497. {
  6498. int rc;
  6499. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6500. if (CONFIGURE_NIC_MODE(bp)) {
  6501. /* Configure searcher as part of function hw init */
  6502. bnx2x_init_searcher(bp);
  6503. /* Reset NIC mode */
  6504. rc = bnx2x_reset_nic_mode(bp);
  6505. if (rc)
  6506. BNX2X_ERR("Can't change NIC mode!\n");
  6507. return rc;
  6508. }
  6509. return 0;
  6510. }
  6511. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6512. {
  6513. int port = BP_PORT(bp);
  6514. int func = BP_FUNC(bp);
  6515. int init_phase = PHASE_PF0 + func;
  6516. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6517. u16 cdu_ilt_start;
  6518. u32 addr, val;
  6519. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6520. int i, main_mem_width, rc;
  6521. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6522. /* FLR cleanup - hmmm */
  6523. if (!CHIP_IS_E1x(bp)) {
  6524. rc = bnx2x_pf_flr_clnup(bp);
  6525. if (rc) {
  6526. bnx2x_fw_dump(bp);
  6527. return rc;
  6528. }
  6529. }
  6530. /* set MSI reconfigure capability */
  6531. if (bp->common.int_block == INT_BLOCK_HC) {
  6532. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6533. val = REG_RD(bp, addr);
  6534. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6535. REG_WR(bp, addr, val);
  6536. }
  6537. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6538. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6539. ilt = BP_ILT(bp);
  6540. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6541. if (IS_SRIOV(bp))
  6542. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6543. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6544. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6545. * those of the VFs, so start line should be reset
  6546. */
  6547. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6548. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6549. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6550. ilt->lines[cdu_ilt_start + i].page_mapping =
  6551. bp->context[i].cxt_mapping;
  6552. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6553. }
  6554. bnx2x_ilt_init_op(bp, INITOP_SET);
  6555. if (!CONFIGURE_NIC_MODE(bp)) {
  6556. bnx2x_init_searcher(bp);
  6557. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6558. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6559. } else {
  6560. /* Set NIC mode */
  6561. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6562. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6563. }
  6564. if (!CHIP_IS_E1x(bp)) {
  6565. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6566. /* Turn on a single ISR mode in IGU if driver is going to use
  6567. * INT#x or MSI
  6568. */
  6569. if (!(bp->flags & USING_MSIX_FLAG))
  6570. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6571. /*
  6572. * Timers workaround bug: function init part.
  6573. * Need to wait 20msec after initializing ILT,
  6574. * needed to make sure there are no requests in
  6575. * one of the PXP internal queues with "old" ILT addresses
  6576. */
  6577. msleep(20);
  6578. /*
  6579. * Master enable - Due to WB DMAE writes performed before this
  6580. * register is re-initialized as part of the regular function
  6581. * init
  6582. */
  6583. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6584. /* Enable the function in IGU */
  6585. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6586. }
  6587. bp->dmae_ready = 1;
  6588. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6589. if (!CHIP_IS_E1x(bp))
  6590. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6591. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6592. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6593. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6594. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6595. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6596. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6597. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6598. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6599. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6600. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6601. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6602. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6603. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6604. if (!CHIP_IS_E1x(bp))
  6605. REG_WR(bp, QM_REG_PF_EN, 1);
  6606. if (!CHIP_IS_E1x(bp)) {
  6607. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6608. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6609. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6610. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6611. }
  6612. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6613. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6614. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6615. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6616. bnx2x_iov_init_dq(bp);
  6617. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6618. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6619. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6620. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6621. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6622. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6623. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6624. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6625. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6626. if (!CHIP_IS_E1x(bp))
  6627. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6628. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6629. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6630. if (!CHIP_IS_E1x(bp))
  6631. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6632. if (IS_MF(bp)) {
  6633. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6634. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6635. }
  6636. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6637. /* HC init per function */
  6638. if (bp->common.int_block == INT_BLOCK_HC) {
  6639. if (CHIP_IS_E1H(bp)) {
  6640. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6641. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6642. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6643. }
  6644. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6645. } else {
  6646. int num_segs, sb_idx, prod_offset;
  6647. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6648. if (!CHIP_IS_E1x(bp)) {
  6649. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6650. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6651. }
  6652. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6653. if (!CHIP_IS_E1x(bp)) {
  6654. int dsb_idx = 0;
  6655. /**
  6656. * Producer memory:
  6657. * E2 mode: address 0-135 match to the mapping memory;
  6658. * 136 - PF0 default prod; 137 - PF1 default prod;
  6659. * 138 - PF2 default prod; 139 - PF3 default prod;
  6660. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6661. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6662. * 144-147 reserved.
  6663. *
  6664. * E1.5 mode - In backward compatible mode;
  6665. * for non default SB; each even line in the memory
  6666. * holds the U producer and each odd line hold
  6667. * the C producer. The first 128 producers are for
  6668. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6669. * producers are for the DSB for each PF.
  6670. * Each PF has five segments: (the order inside each
  6671. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6672. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6673. * 144-147 attn prods;
  6674. */
  6675. /* non-default-status-blocks */
  6676. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6677. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6678. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6679. prod_offset = (bp->igu_base_sb + sb_idx) *
  6680. num_segs;
  6681. for (i = 0; i < num_segs; i++) {
  6682. addr = IGU_REG_PROD_CONS_MEMORY +
  6683. (prod_offset + i) * 4;
  6684. REG_WR(bp, addr, 0);
  6685. }
  6686. /* send consumer update with value 0 */
  6687. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6688. USTORM_ID, 0, IGU_INT_NOP, 1);
  6689. bnx2x_igu_clear_sb(bp,
  6690. bp->igu_base_sb + sb_idx);
  6691. }
  6692. /* default-status-blocks */
  6693. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6694. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6695. if (CHIP_MODE_IS_4_PORT(bp))
  6696. dsb_idx = BP_FUNC(bp);
  6697. else
  6698. dsb_idx = BP_VN(bp);
  6699. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6700. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6701. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6702. /*
  6703. * igu prods come in chunks of E1HVN_MAX (4) -
  6704. * does not matters what is the current chip mode
  6705. */
  6706. for (i = 0; i < (num_segs * E1HVN_MAX);
  6707. i += E1HVN_MAX) {
  6708. addr = IGU_REG_PROD_CONS_MEMORY +
  6709. (prod_offset + i)*4;
  6710. REG_WR(bp, addr, 0);
  6711. }
  6712. /* send consumer update with 0 */
  6713. if (CHIP_INT_MODE_IS_BC(bp)) {
  6714. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6715. USTORM_ID, 0, IGU_INT_NOP, 1);
  6716. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6717. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6718. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6719. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6720. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6721. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6722. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6723. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6724. } else {
  6725. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6726. USTORM_ID, 0, IGU_INT_NOP, 1);
  6727. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6728. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6729. }
  6730. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6731. /* !!! These should become driver const once
  6732. rf-tool supports split-68 const */
  6733. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6734. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6735. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6736. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6737. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6738. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6739. }
  6740. }
  6741. /* Reset PCIE errors for debug */
  6742. REG_WR(bp, 0x2114, 0xffffffff);
  6743. REG_WR(bp, 0x2120, 0xffffffff);
  6744. if (CHIP_IS_E1x(bp)) {
  6745. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6746. main_mem_base = HC_REG_MAIN_MEMORY +
  6747. BP_PORT(bp) * (main_mem_size * 4);
  6748. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6749. main_mem_width = 8;
  6750. val = REG_RD(bp, main_mem_prty_clr);
  6751. if (val)
  6752. DP(NETIF_MSG_HW,
  6753. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6754. val);
  6755. /* Clear "false" parity errors in MSI-X table */
  6756. for (i = main_mem_base;
  6757. i < main_mem_base + main_mem_size * 4;
  6758. i += main_mem_width) {
  6759. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6760. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6761. i, main_mem_width / 4);
  6762. }
  6763. /* Clear HC parity attention */
  6764. REG_RD(bp, main_mem_prty_clr);
  6765. }
  6766. #ifdef BNX2X_STOP_ON_ERROR
  6767. /* Enable STORMs SP logging */
  6768. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6769. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6770. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6771. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6772. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6773. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6774. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6775. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6776. #endif
  6777. bnx2x_phy_probe(&bp->link_params);
  6778. return 0;
  6779. }
  6780. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6781. {
  6782. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6783. if (!CHIP_IS_E1x(bp))
  6784. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6785. sizeof(struct host_hc_status_block_e2));
  6786. else
  6787. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6788. sizeof(struct host_hc_status_block_e1x));
  6789. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6790. }
  6791. void bnx2x_free_mem(struct bnx2x *bp)
  6792. {
  6793. int i;
  6794. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6795. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6796. if (IS_VF(bp))
  6797. return;
  6798. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6799. sizeof(struct host_sp_status_block));
  6800. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6801. sizeof(struct bnx2x_slowpath));
  6802. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6803. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6804. bp->context[i].size);
  6805. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6806. BNX2X_FREE(bp->ilt->lines);
  6807. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6808. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6809. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6810. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6811. bnx2x_iov_free_mem(bp);
  6812. }
  6813. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6814. {
  6815. if (!CHIP_IS_E1x(bp)) {
  6816. /* size = the status block + ramrod buffers */
  6817. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6818. sizeof(struct host_hc_status_block_e2));
  6819. if (!bp->cnic_sb.e2_sb)
  6820. goto alloc_mem_err;
  6821. } else {
  6822. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6823. sizeof(struct host_hc_status_block_e1x));
  6824. if (!bp->cnic_sb.e1x_sb)
  6825. goto alloc_mem_err;
  6826. }
  6827. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6828. /* allocate searcher T2 table, as it wasn't allocated before */
  6829. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6830. if (!bp->t2)
  6831. goto alloc_mem_err;
  6832. }
  6833. /* write address to which L5 should insert its values */
  6834. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6835. &bp->slowpath->drv_info_to_mcp;
  6836. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6837. goto alloc_mem_err;
  6838. return 0;
  6839. alloc_mem_err:
  6840. bnx2x_free_mem_cnic(bp);
  6841. BNX2X_ERR("Can't allocate memory\n");
  6842. return -ENOMEM;
  6843. }
  6844. int bnx2x_alloc_mem(struct bnx2x *bp)
  6845. {
  6846. int i, allocated, context_size;
  6847. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6848. /* allocate searcher T2 table */
  6849. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6850. if (!bp->t2)
  6851. goto alloc_mem_err;
  6852. }
  6853. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6854. sizeof(struct host_sp_status_block));
  6855. if (!bp->def_status_blk)
  6856. goto alloc_mem_err;
  6857. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6858. sizeof(struct bnx2x_slowpath));
  6859. if (!bp->slowpath)
  6860. goto alloc_mem_err;
  6861. /* Allocate memory for CDU context:
  6862. * This memory is allocated separately and not in the generic ILT
  6863. * functions because CDU differs in few aspects:
  6864. * 1. There are multiple entities allocating memory for context -
  6865. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6866. * its own ILT lines.
  6867. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6868. * for the other ILT clients), to be efficient we want to support
  6869. * allocation of sub-page-size in the last entry.
  6870. * 3. Context pointers are used by the driver to pass to FW / update
  6871. * the context (for the other ILT clients the pointers are used just to
  6872. * free the memory during unload).
  6873. */
  6874. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6875. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6876. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6877. (context_size - allocated));
  6878. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6879. bp->context[i].size);
  6880. if (!bp->context[i].vcxt)
  6881. goto alloc_mem_err;
  6882. allocated += bp->context[i].size;
  6883. }
  6884. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6885. GFP_KERNEL);
  6886. if (!bp->ilt->lines)
  6887. goto alloc_mem_err;
  6888. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6889. goto alloc_mem_err;
  6890. if (bnx2x_iov_alloc_mem(bp))
  6891. goto alloc_mem_err;
  6892. /* Slow path ring */
  6893. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  6894. if (!bp->spq)
  6895. goto alloc_mem_err;
  6896. /* EQ */
  6897. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  6898. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6899. if (!bp->eq_ring)
  6900. goto alloc_mem_err;
  6901. return 0;
  6902. alloc_mem_err:
  6903. bnx2x_free_mem(bp);
  6904. BNX2X_ERR("Can't allocate memory\n");
  6905. return -ENOMEM;
  6906. }
  6907. /*
  6908. * Init service functions
  6909. */
  6910. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6911. struct bnx2x_vlan_mac_obj *obj, bool set,
  6912. int mac_type, unsigned long *ramrod_flags)
  6913. {
  6914. int rc;
  6915. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6916. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6917. /* Fill general parameters */
  6918. ramrod_param.vlan_mac_obj = obj;
  6919. ramrod_param.ramrod_flags = *ramrod_flags;
  6920. /* Fill a user request section if needed */
  6921. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6922. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6923. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6924. /* Set the command: ADD or DEL */
  6925. if (set)
  6926. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6927. else
  6928. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6929. }
  6930. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6931. if (rc == -EEXIST) {
  6932. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6933. /* do not treat adding same MAC as error */
  6934. rc = 0;
  6935. } else if (rc < 0)
  6936. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6937. return rc;
  6938. }
  6939. int bnx2x_del_all_macs(struct bnx2x *bp,
  6940. struct bnx2x_vlan_mac_obj *mac_obj,
  6941. int mac_type, bool wait_for_comp)
  6942. {
  6943. int rc;
  6944. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6945. /* Wait for completion of requested */
  6946. if (wait_for_comp)
  6947. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6948. /* Set the mac type of addresses we want to clear */
  6949. __set_bit(mac_type, &vlan_mac_flags);
  6950. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6951. if (rc < 0)
  6952. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6953. return rc;
  6954. }
  6955. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6956. {
  6957. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6958. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6959. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6960. "Ignoring Zero MAC for STORAGE SD mode\n");
  6961. return 0;
  6962. }
  6963. if (IS_PF(bp)) {
  6964. unsigned long ramrod_flags = 0;
  6965. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6966. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6967. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6968. &bp->sp_objs->mac_obj, set,
  6969. BNX2X_ETH_MAC, &ramrod_flags);
  6970. } else { /* vf */
  6971. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6972. bp->fp->index, true);
  6973. }
  6974. }
  6975. int bnx2x_setup_leading(struct bnx2x *bp)
  6976. {
  6977. if (IS_PF(bp))
  6978. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6979. else /* VF */
  6980. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6981. }
  6982. /**
  6983. * bnx2x_set_int_mode - configure interrupt mode
  6984. *
  6985. * @bp: driver handle
  6986. *
  6987. * In case of MSI-X it will also try to enable MSI-X.
  6988. */
  6989. int bnx2x_set_int_mode(struct bnx2x *bp)
  6990. {
  6991. int rc = 0;
  6992. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  6993. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  6994. return -EINVAL;
  6995. }
  6996. switch (int_mode) {
  6997. case BNX2X_INT_MODE_MSIX:
  6998. /* attempt to enable msix */
  6999. rc = bnx2x_enable_msix(bp);
  7000. /* msix attained */
  7001. if (!rc)
  7002. return 0;
  7003. /* vfs use only msix */
  7004. if (rc && IS_VF(bp))
  7005. return rc;
  7006. /* failed to enable multiple MSI-X */
  7007. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7008. bp->num_queues,
  7009. 1 + bp->num_cnic_queues);
  7010. /* falling through... */
  7011. case BNX2X_INT_MODE_MSI:
  7012. bnx2x_enable_msi(bp);
  7013. /* falling through... */
  7014. case BNX2X_INT_MODE_INTX:
  7015. bp->num_ethernet_queues = 1;
  7016. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7017. BNX2X_DEV_INFO("set number of queues to 1\n");
  7018. break;
  7019. default:
  7020. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7021. return -EINVAL;
  7022. }
  7023. return 0;
  7024. }
  7025. /* must be called prior to any HW initializations */
  7026. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7027. {
  7028. if (IS_SRIOV(bp))
  7029. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7030. return L2_ILT_LINES(bp);
  7031. }
  7032. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7033. {
  7034. struct ilt_client_info *ilt_client;
  7035. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7036. u16 line = 0;
  7037. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7038. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7039. /* CDU */
  7040. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7041. ilt_client->client_num = ILT_CLIENT_CDU;
  7042. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7043. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7044. ilt_client->start = line;
  7045. line += bnx2x_cid_ilt_lines(bp);
  7046. if (CNIC_SUPPORT(bp))
  7047. line += CNIC_ILT_LINES;
  7048. ilt_client->end = line - 1;
  7049. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7050. ilt_client->start,
  7051. ilt_client->end,
  7052. ilt_client->page_size,
  7053. ilt_client->flags,
  7054. ilog2(ilt_client->page_size >> 12));
  7055. /* QM */
  7056. if (QM_INIT(bp->qm_cid_count)) {
  7057. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7058. ilt_client->client_num = ILT_CLIENT_QM;
  7059. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7060. ilt_client->flags = 0;
  7061. ilt_client->start = line;
  7062. /* 4 bytes for each cid */
  7063. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7064. QM_ILT_PAGE_SZ);
  7065. ilt_client->end = line - 1;
  7066. DP(NETIF_MSG_IFUP,
  7067. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7068. ilt_client->start,
  7069. ilt_client->end,
  7070. ilt_client->page_size,
  7071. ilt_client->flags,
  7072. ilog2(ilt_client->page_size >> 12));
  7073. }
  7074. if (CNIC_SUPPORT(bp)) {
  7075. /* SRC */
  7076. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7077. ilt_client->client_num = ILT_CLIENT_SRC;
  7078. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7079. ilt_client->flags = 0;
  7080. ilt_client->start = line;
  7081. line += SRC_ILT_LINES;
  7082. ilt_client->end = line - 1;
  7083. DP(NETIF_MSG_IFUP,
  7084. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7085. ilt_client->start,
  7086. ilt_client->end,
  7087. ilt_client->page_size,
  7088. ilt_client->flags,
  7089. ilog2(ilt_client->page_size >> 12));
  7090. /* TM */
  7091. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7092. ilt_client->client_num = ILT_CLIENT_TM;
  7093. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7094. ilt_client->flags = 0;
  7095. ilt_client->start = line;
  7096. line += TM_ILT_LINES;
  7097. ilt_client->end = line - 1;
  7098. DP(NETIF_MSG_IFUP,
  7099. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7100. ilt_client->start,
  7101. ilt_client->end,
  7102. ilt_client->page_size,
  7103. ilt_client->flags,
  7104. ilog2(ilt_client->page_size >> 12));
  7105. }
  7106. BUG_ON(line > ILT_MAX_LINES);
  7107. }
  7108. /**
  7109. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7110. *
  7111. * @bp: driver handle
  7112. * @fp: pointer to fastpath
  7113. * @init_params: pointer to parameters structure
  7114. *
  7115. * parameters configured:
  7116. * - HC configuration
  7117. * - Queue's CDU context
  7118. */
  7119. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7120. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7121. {
  7122. u8 cos;
  7123. int cxt_index, cxt_offset;
  7124. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7125. if (!IS_FCOE_FP(fp)) {
  7126. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7127. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7128. /* If HC is supported, enable host coalescing in the transition
  7129. * to INIT state.
  7130. */
  7131. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7132. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7133. /* HC rate */
  7134. init_params->rx.hc_rate = bp->rx_ticks ?
  7135. (1000000 / bp->rx_ticks) : 0;
  7136. init_params->tx.hc_rate = bp->tx_ticks ?
  7137. (1000000 / bp->tx_ticks) : 0;
  7138. /* FW SB ID */
  7139. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7140. fp->fw_sb_id;
  7141. /*
  7142. * CQ index among the SB indices: FCoE clients uses the default
  7143. * SB, therefore it's different.
  7144. */
  7145. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7146. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7147. }
  7148. /* set maximum number of COSs supported by this queue */
  7149. init_params->max_cos = fp->max_cos;
  7150. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7151. fp->index, init_params->max_cos);
  7152. /* set the context pointers queue object */
  7153. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7154. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7155. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7156. ILT_PAGE_CIDS);
  7157. init_params->cxts[cos] =
  7158. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7159. }
  7160. }
  7161. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7162. struct bnx2x_queue_state_params *q_params,
  7163. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7164. int tx_index, bool leading)
  7165. {
  7166. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7167. /* Set the command */
  7168. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7169. /* Set tx-only QUEUE flags: don't zero statistics */
  7170. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7171. /* choose the index of the cid to send the slow path on */
  7172. tx_only_params->cid_index = tx_index;
  7173. /* Set general TX_ONLY_SETUP parameters */
  7174. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7175. /* Set Tx TX_ONLY_SETUP parameters */
  7176. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7177. DP(NETIF_MSG_IFUP,
  7178. "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",
  7179. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7180. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7181. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7182. /* send the ramrod */
  7183. return bnx2x_queue_state_change(bp, q_params);
  7184. }
  7185. /**
  7186. * bnx2x_setup_queue - setup queue
  7187. *
  7188. * @bp: driver handle
  7189. * @fp: pointer to fastpath
  7190. * @leading: is leading
  7191. *
  7192. * This function performs 2 steps in a Queue state machine
  7193. * actually: 1) RESET->INIT 2) INIT->SETUP
  7194. */
  7195. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7196. bool leading)
  7197. {
  7198. struct bnx2x_queue_state_params q_params = {NULL};
  7199. struct bnx2x_queue_setup_params *setup_params =
  7200. &q_params.params.setup;
  7201. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7202. &q_params.params.tx_only;
  7203. int rc;
  7204. u8 tx_index;
  7205. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7206. /* reset IGU state skip FCoE L2 queue */
  7207. if (!IS_FCOE_FP(fp))
  7208. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7209. IGU_INT_ENABLE, 0);
  7210. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7211. /* We want to wait for completion in this context */
  7212. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7213. /* Prepare the INIT parameters */
  7214. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7215. /* Set the command */
  7216. q_params.cmd = BNX2X_Q_CMD_INIT;
  7217. /* Change the state to INIT */
  7218. rc = bnx2x_queue_state_change(bp, &q_params);
  7219. if (rc) {
  7220. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7221. return rc;
  7222. }
  7223. DP(NETIF_MSG_IFUP, "init complete\n");
  7224. /* Now move the Queue to the SETUP state... */
  7225. memset(setup_params, 0, sizeof(*setup_params));
  7226. /* Set QUEUE flags */
  7227. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7228. /* Set general SETUP parameters */
  7229. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7230. FIRST_TX_COS_INDEX);
  7231. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7232. &setup_params->rxq_params);
  7233. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7234. FIRST_TX_COS_INDEX);
  7235. /* Set the command */
  7236. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7237. if (IS_FCOE_FP(fp))
  7238. bp->fcoe_init = true;
  7239. /* Change the state to SETUP */
  7240. rc = bnx2x_queue_state_change(bp, &q_params);
  7241. if (rc) {
  7242. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7243. return rc;
  7244. }
  7245. /* loop through the relevant tx-only indices */
  7246. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7247. tx_index < fp->max_cos;
  7248. tx_index++) {
  7249. /* prepare and send tx-only ramrod*/
  7250. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7251. tx_only_params, tx_index, leading);
  7252. if (rc) {
  7253. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7254. fp->index, tx_index);
  7255. return rc;
  7256. }
  7257. }
  7258. return rc;
  7259. }
  7260. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7261. {
  7262. struct bnx2x_fastpath *fp = &bp->fp[index];
  7263. struct bnx2x_fp_txdata *txdata;
  7264. struct bnx2x_queue_state_params q_params = {NULL};
  7265. int rc, tx_index;
  7266. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7267. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7268. /* We want to wait for completion in this context */
  7269. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7270. /* close tx-only connections */
  7271. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7272. tx_index < fp->max_cos;
  7273. tx_index++){
  7274. /* ascertain this is a normal queue*/
  7275. txdata = fp->txdata_ptr[tx_index];
  7276. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7277. txdata->txq_index);
  7278. /* send halt terminate on tx-only connection */
  7279. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7280. memset(&q_params.params.terminate, 0,
  7281. sizeof(q_params.params.terminate));
  7282. q_params.params.terminate.cid_index = tx_index;
  7283. rc = bnx2x_queue_state_change(bp, &q_params);
  7284. if (rc)
  7285. return rc;
  7286. /* send halt terminate on tx-only connection */
  7287. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7288. memset(&q_params.params.cfc_del, 0,
  7289. sizeof(q_params.params.cfc_del));
  7290. q_params.params.cfc_del.cid_index = tx_index;
  7291. rc = bnx2x_queue_state_change(bp, &q_params);
  7292. if (rc)
  7293. return rc;
  7294. }
  7295. /* Stop the primary connection: */
  7296. /* ...halt the connection */
  7297. q_params.cmd = BNX2X_Q_CMD_HALT;
  7298. rc = bnx2x_queue_state_change(bp, &q_params);
  7299. if (rc)
  7300. return rc;
  7301. /* ...terminate the connection */
  7302. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7303. memset(&q_params.params.terminate, 0,
  7304. sizeof(q_params.params.terminate));
  7305. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7306. rc = bnx2x_queue_state_change(bp, &q_params);
  7307. if (rc)
  7308. return rc;
  7309. /* ...delete cfc entry */
  7310. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7311. memset(&q_params.params.cfc_del, 0,
  7312. sizeof(q_params.params.cfc_del));
  7313. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7314. return bnx2x_queue_state_change(bp, &q_params);
  7315. }
  7316. static void bnx2x_reset_func(struct bnx2x *bp)
  7317. {
  7318. int port = BP_PORT(bp);
  7319. int func = BP_FUNC(bp);
  7320. int i;
  7321. /* Disable the function in the FW */
  7322. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7323. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7324. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7325. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7326. /* FP SBs */
  7327. for_each_eth_queue(bp, i) {
  7328. struct bnx2x_fastpath *fp = &bp->fp[i];
  7329. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7330. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7331. SB_DISABLED);
  7332. }
  7333. if (CNIC_LOADED(bp))
  7334. /* CNIC SB */
  7335. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7336. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7337. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7338. /* SP SB */
  7339. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7340. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7341. SB_DISABLED);
  7342. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7343. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7344. 0);
  7345. /* Configure IGU */
  7346. if (bp->common.int_block == INT_BLOCK_HC) {
  7347. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7348. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7349. } else {
  7350. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7351. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7352. }
  7353. if (CNIC_LOADED(bp)) {
  7354. /* Disable Timer scan */
  7355. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7356. /*
  7357. * Wait for at least 10ms and up to 2 second for the timers
  7358. * scan to complete
  7359. */
  7360. for (i = 0; i < 200; i++) {
  7361. usleep_range(10000, 20000);
  7362. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7363. break;
  7364. }
  7365. }
  7366. /* Clear ILT */
  7367. bnx2x_clear_func_ilt(bp, func);
  7368. /* Timers workaround bug for E2: if this is vnic-3,
  7369. * we need to set the entire ilt range for this timers.
  7370. */
  7371. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7372. struct ilt_client_info ilt_cli;
  7373. /* use dummy TM client */
  7374. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7375. ilt_cli.start = 0;
  7376. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7377. ilt_cli.client_num = ILT_CLIENT_TM;
  7378. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7379. }
  7380. /* this assumes that reset_port() called before reset_func()*/
  7381. if (!CHIP_IS_E1x(bp))
  7382. bnx2x_pf_disable(bp);
  7383. bp->dmae_ready = 0;
  7384. }
  7385. static void bnx2x_reset_port(struct bnx2x *bp)
  7386. {
  7387. int port = BP_PORT(bp);
  7388. u32 val;
  7389. /* Reset physical Link */
  7390. bnx2x__link_reset(bp);
  7391. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7392. /* Do not rcv packets to BRB */
  7393. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7394. /* Do not direct rcv packets that are not for MCP to the BRB */
  7395. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7396. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7397. /* Configure AEU */
  7398. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7399. msleep(100);
  7400. /* Check for BRB port occupancy */
  7401. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7402. if (val)
  7403. DP(NETIF_MSG_IFDOWN,
  7404. "BRB1 is not empty %d blocks are occupied\n", val);
  7405. /* TODO: Close Doorbell port? */
  7406. }
  7407. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7408. {
  7409. struct bnx2x_func_state_params func_params = {NULL};
  7410. /* Prepare parameters for function state transitions */
  7411. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7412. func_params.f_obj = &bp->func_obj;
  7413. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7414. func_params.params.hw_init.load_phase = load_code;
  7415. return bnx2x_func_state_change(bp, &func_params);
  7416. }
  7417. static int bnx2x_func_stop(struct bnx2x *bp)
  7418. {
  7419. struct bnx2x_func_state_params func_params = {NULL};
  7420. int rc;
  7421. /* Prepare parameters for function state transitions */
  7422. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7423. func_params.f_obj = &bp->func_obj;
  7424. func_params.cmd = BNX2X_F_CMD_STOP;
  7425. /*
  7426. * Try to stop the function the 'good way'. If fails (in case
  7427. * of a parity error during bnx2x_chip_cleanup()) and we are
  7428. * not in a debug mode, perform a state transaction in order to
  7429. * enable further HW_RESET transaction.
  7430. */
  7431. rc = bnx2x_func_state_change(bp, &func_params);
  7432. if (rc) {
  7433. #ifdef BNX2X_STOP_ON_ERROR
  7434. return rc;
  7435. #else
  7436. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7437. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7438. return bnx2x_func_state_change(bp, &func_params);
  7439. #endif
  7440. }
  7441. return 0;
  7442. }
  7443. /**
  7444. * bnx2x_send_unload_req - request unload mode from the MCP.
  7445. *
  7446. * @bp: driver handle
  7447. * @unload_mode: requested function's unload mode
  7448. *
  7449. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7450. */
  7451. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7452. {
  7453. u32 reset_code = 0;
  7454. int port = BP_PORT(bp);
  7455. /* Select the UNLOAD request mode */
  7456. if (unload_mode == UNLOAD_NORMAL)
  7457. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7458. else if (bp->flags & NO_WOL_FLAG)
  7459. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7460. else if (bp->wol) {
  7461. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7462. u8 *mac_addr = bp->dev->dev_addr;
  7463. struct pci_dev *pdev = bp->pdev;
  7464. u32 val;
  7465. u16 pmc;
  7466. /* The mac address is written to entries 1-4 to
  7467. * preserve entry 0 which is used by the PMF
  7468. */
  7469. u8 entry = (BP_VN(bp) + 1)*8;
  7470. val = (mac_addr[0] << 8) | mac_addr[1];
  7471. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7472. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7473. (mac_addr[4] << 8) | mac_addr[5];
  7474. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7475. /* Enable the PME and clear the status */
  7476. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7477. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7478. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7479. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7480. } else
  7481. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7482. /* Send the request to the MCP */
  7483. if (!BP_NOMCP(bp))
  7484. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7485. else {
  7486. int path = BP_PATH(bp);
  7487. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7488. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7489. bnx2x_load_count[path][2]);
  7490. bnx2x_load_count[path][0]--;
  7491. bnx2x_load_count[path][1 + port]--;
  7492. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7493. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7494. bnx2x_load_count[path][2]);
  7495. if (bnx2x_load_count[path][0] == 0)
  7496. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7497. else if (bnx2x_load_count[path][1 + port] == 0)
  7498. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7499. else
  7500. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7501. }
  7502. return reset_code;
  7503. }
  7504. /**
  7505. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7506. *
  7507. * @bp: driver handle
  7508. * @keep_link: true iff link should be kept up
  7509. */
  7510. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7511. {
  7512. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7513. /* Report UNLOAD_DONE to MCP */
  7514. if (!BP_NOMCP(bp))
  7515. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7516. }
  7517. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7518. {
  7519. int tout = 50;
  7520. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7521. if (!bp->port.pmf)
  7522. return 0;
  7523. /*
  7524. * (assumption: No Attention from MCP at this stage)
  7525. * PMF probably in the middle of TX disable/enable transaction
  7526. * 1. Sync IRS for default SB
  7527. * 2. Sync SP queue - this guarantees us that attention handling started
  7528. * 3. Wait, that TX disable/enable transaction completes
  7529. *
  7530. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7531. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7532. * received completion for the transaction the state is TX_STOPPED.
  7533. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7534. * transaction.
  7535. */
  7536. /* make sure default SB ISR is done */
  7537. if (msix)
  7538. synchronize_irq(bp->msix_table[0].vector);
  7539. else
  7540. synchronize_irq(bp->pdev->irq);
  7541. flush_workqueue(bnx2x_wq);
  7542. flush_workqueue(bnx2x_iov_wq);
  7543. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7544. BNX2X_F_STATE_STARTED && tout--)
  7545. msleep(20);
  7546. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7547. BNX2X_F_STATE_STARTED) {
  7548. #ifdef BNX2X_STOP_ON_ERROR
  7549. BNX2X_ERR("Wrong function state\n");
  7550. return -EBUSY;
  7551. #else
  7552. /*
  7553. * Failed to complete the transaction in a "good way"
  7554. * Force both transactions with CLR bit
  7555. */
  7556. struct bnx2x_func_state_params func_params = {NULL};
  7557. DP(NETIF_MSG_IFDOWN,
  7558. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7559. func_params.f_obj = &bp->func_obj;
  7560. __set_bit(RAMROD_DRV_CLR_ONLY,
  7561. &func_params.ramrod_flags);
  7562. /* STARTED-->TX_ST0PPED */
  7563. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7564. bnx2x_func_state_change(bp, &func_params);
  7565. /* TX_ST0PPED-->STARTED */
  7566. func_params.cmd = BNX2X_F_CMD_TX_START;
  7567. return bnx2x_func_state_change(bp, &func_params);
  7568. #endif
  7569. }
  7570. return 0;
  7571. }
  7572. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7573. {
  7574. int port = BP_PORT(bp);
  7575. int i, rc = 0;
  7576. u8 cos;
  7577. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7578. u32 reset_code;
  7579. /* Wait until tx fastpath tasks complete */
  7580. for_each_tx_queue(bp, i) {
  7581. struct bnx2x_fastpath *fp = &bp->fp[i];
  7582. for_each_cos_in_tx_queue(fp, cos)
  7583. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7584. #ifdef BNX2X_STOP_ON_ERROR
  7585. if (rc)
  7586. return;
  7587. #endif
  7588. }
  7589. /* Give HW time to discard old tx messages */
  7590. usleep_range(1000, 2000);
  7591. /* Clean all ETH MACs */
  7592. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7593. false);
  7594. if (rc < 0)
  7595. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7596. /* Clean up UC list */
  7597. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7598. true);
  7599. if (rc < 0)
  7600. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7601. rc);
  7602. /* Disable LLH */
  7603. if (!CHIP_IS_E1(bp))
  7604. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7605. /* Set "drop all" (stop Rx).
  7606. * We need to take a netif_addr_lock() here in order to prevent
  7607. * a race between the completion code and this code.
  7608. */
  7609. netif_addr_lock_bh(bp->dev);
  7610. /* Schedule the rx_mode command */
  7611. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7612. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7613. else
  7614. bnx2x_set_storm_rx_mode(bp);
  7615. /* Cleanup multicast configuration */
  7616. rparam.mcast_obj = &bp->mcast_obj;
  7617. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7618. if (rc < 0)
  7619. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7620. netif_addr_unlock_bh(bp->dev);
  7621. bnx2x_iov_chip_cleanup(bp);
  7622. /*
  7623. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7624. * this function should perform FUNC, PORT or COMMON HW
  7625. * reset.
  7626. */
  7627. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7628. /*
  7629. * (assumption: No Attention from MCP at this stage)
  7630. * PMF probably in the middle of TX disable/enable transaction
  7631. */
  7632. rc = bnx2x_func_wait_started(bp);
  7633. if (rc) {
  7634. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7635. #ifdef BNX2X_STOP_ON_ERROR
  7636. return;
  7637. #endif
  7638. }
  7639. /* Close multi and leading connections
  7640. * Completions for ramrods are collected in a synchronous way
  7641. */
  7642. for_each_eth_queue(bp, i)
  7643. if (bnx2x_stop_queue(bp, i))
  7644. #ifdef BNX2X_STOP_ON_ERROR
  7645. return;
  7646. #else
  7647. goto unload_error;
  7648. #endif
  7649. if (CNIC_LOADED(bp)) {
  7650. for_each_cnic_queue(bp, i)
  7651. if (bnx2x_stop_queue(bp, i))
  7652. #ifdef BNX2X_STOP_ON_ERROR
  7653. return;
  7654. #else
  7655. goto unload_error;
  7656. #endif
  7657. }
  7658. /* If SP settings didn't get completed so far - something
  7659. * very wrong has happen.
  7660. */
  7661. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7662. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7663. #ifndef BNX2X_STOP_ON_ERROR
  7664. unload_error:
  7665. #endif
  7666. rc = bnx2x_func_stop(bp);
  7667. if (rc) {
  7668. BNX2X_ERR("Function stop failed!\n");
  7669. #ifdef BNX2X_STOP_ON_ERROR
  7670. return;
  7671. #endif
  7672. }
  7673. /* Disable HW interrupts, NAPI */
  7674. bnx2x_netif_stop(bp, 1);
  7675. /* Delete all NAPI objects */
  7676. bnx2x_del_all_napi(bp);
  7677. if (CNIC_LOADED(bp))
  7678. bnx2x_del_all_napi_cnic(bp);
  7679. /* Release IRQs */
  7680. bnx2x_free_irq(bp);
  7681. /* Reset the chip */
  7682. rc = bnx2x_reset_hw(bp, reset_code);
  7683. if (rc)
  7684. BNX2X_ERR("HW_RESET failed\n");
  7685. /* Report UNLOAD_DONE to MCP */
  7686. bnx2x_send_unload_done(bp, keep_link);
  7687. }
  7688. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7689. {
  7690. u32 val;
  7691. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7692. if (CHIP_IS_E1(bp)) {
  7693. int port = BP_PORT(bp);
  7694. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7695. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7696. val = REG_RD(bp, addr);
  7697. val &= ~(0x300);
  7698. REG_WR(bp, addr, val);
  7699. } else {
  7700. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7701. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7702. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7703. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7704. }
  7705. }
  7706. /* Close gates #2, #3 and #4: */
  7707. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7708. {
  7709. u32 val;
  7710. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7711. if (!CHIP_IS_E1(bp)) {
  7712. /* #4 */
  7713. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7714. /* #2 */
  7715. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7716. }
  7717. /* #3 */
  7718. if (CHIP_IS_E1x(bp)) {
  7719. /* Prevent interrupts from HC on both ports */
  7720. val = REG_RD(bp, HC_REG_CONFIG_1);
  7721. REG_WR(bp, HC_REG_CONFIG_1,
  7722. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7723. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7724. val = REG_RD(bp, HC_REG_CONFIG_0);
  7725. REG_WR(bp, HC_REG_CONFIG_0,
  7726. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7727. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7728. } else {
  7729. /* Prevent incoming interrupts in IGU */
  7730. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7731. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7732. (!close) ?
  7733. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7734. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7735. }
  7736. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7737. close ? "closing" : "opening");
  7738. mmiowb();
  7739. }
  7740. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7741. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7742. {
  7743. /* Do some magic... */
  7744. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7745. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7746. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7747. }
  7748. /**
  7749. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7750. *
  7751. * @bp: driver handle
  7752. * @magic_val: old value of the `magic' bit.
  7753. */
  7754. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7755. {
  7756. /* Restore the `magic' bit value... */
  7757. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7758. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7759. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7760. }
  7761. /**
  7762. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7763. *
  7764. * @bp: driver handle
  7765. * @magic_val: old value of 'magic' bit.
  7766. *
  7767. * Takes care of CLP configurations.
  7768. */
  7769. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7770. {
  7771. u32 shmem;
  7772. u32 validity_offset;
  7773. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7774. /* Set `magic' bit in order to save MF config */
  7775. if (!CHIP_IS_E1(bp))
  7776. bnx2x_clp_reset_prep(bp, magic_val);
  7777. /* Get shmem offset */
  7778. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7779. validity_offset =
  7780. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7781. /* Clear validity map flags */
  7782. if (shmem > 0)
  7783. REG_WR(bp, shmem + validity_offset, 0);
  7784. }
  7785. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7786. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7787. /**
  7788. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7789. *
  7790. * @bp: driver handle
  7791. */
  7792. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7793. {
  7794. /* special handling for emulation and FPGA,
  7795. wait 10 times longer */
  7796. if (CHIP_REV_IS_SLOW(bp))
  7797. msleep(MCP_ONE_TIMEOUT*10);
  7798. else
  7799. msleep(MCP_ONE_TIMEOUT);
  7800. }
  7801. /*
  7802. * initializes bp->common.shmem_base and waits for validity signature to appear
  7803. */
  7804. static int bnx2x_init_shmem(struct bnx2x *bp)
  7805. {
  7806. int cnt = 0;
  7807. u32 val = 0;
  7808. do {
  7809. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7810. if (bp->common.shmem_base) {
  7811. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7812. if (val & SHR_MEM_VALIDITY_MB)
  7813. return 0;
  7814. }
  7815. bnx2x_mcp_wait_one(bp);
  7816. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7817. BNX2X_ERR("BAD MCP validity signature\n");
  7818. return -ENODEV;
  7819. }
  7820. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7821. {
  7822. int rc = bnx2x_init_shmem(bp);
  7823. /* Restore the `magic' bit value */
  7824. if (!CHIP_IS_E1(bp))
  7825. bnx2x_clp_reset_done(bp, magic_val);
  7826. return rc;
  7827. }
  7828. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7829. {
  7830. if (!CHIP_IS_E1(bp)) {
  7831. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7832. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7833. mmiowb();
  7834. }
  7835. }
  7836. /*
  7837. * Reset the whole chip except for:
  7838. * - PCIE core
  7839. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7840. * one reset bit)
  7841. * - IGU
  7842. * - MISC (including AEU)
  7843. * - GRC
  7844. * - RBCN, RBCP
  7845. */
  7846. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7847. {
  7848. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7849. u32 global_bits2, stay_reset2;
  7850. /*
  7851. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7852. * (per chip) blocks.
  7853. */
  7854. global_bits2 =
  7855. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7856. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7857. /* Don't reset the following blocks.
  7858. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7859. * reset, as in 4 port device they might still be owned
  7860. * by the MCP (there is only one leader per path).
  7861. */
  7862. not_reset_mask1 =
  7863. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7864. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7865. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7866. not_reset_mask2 =
  7867. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7868. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7869. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7870. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7871. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7872. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7873. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7874. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7875. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7876. MISC_REGISTERS_RESET_REG_2_PGLC |
  7877. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7878. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7879. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7880. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7881. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7882. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7883. /*
  7884. * Keep the following blocks in reset:
  7885. * - all xxMACs are handled by the bnx2x_link code.
  7886. */
  7887. stay_reset2 =
  7888. MISC_REGISTERS_RESET_REG_2_XMAC |
  7889. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7890. /* Full reset masks according to the chip */
  7891. reset_mask1 = 0xffffffff;
  7892. if (CHIP_IS_E1(bp))
  7893. reset_mask2 = 0xffff;
  7894. else if (CHIP_IS_E1H(bp))
  7895. reset_mask2 = 0x1ffff;
  7896. else if (CHIP_IS_E2(bp))
  7897. reset_mask2 = 0xfffff;
  7898. else /* CHIP_IS_E3 */
  7899. reset_mask2 = 0x3ffffff;
  7900. /* Don't reset global blocks unless we need to */
  7901. if (!global)
  7902. reset_mask2 &= ~global_bits2;
  7903. /*
  7904. * In case of attention in the QM, we need to reset PXP
  7905. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7906. * because otherwise QM reset would release 'close the gates' shortly
  7907. * before resetting the PXP, then the PSWRQ would send a write
  7908. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7909. * read the payload data from PSWWR, but PSWWR would not
  7910. * respond. The write queue in PGLUE would stuck, dmae commands
  7911. * would not return. Therefore it's important to reset the second
  7912. * reset register (containing the
  7913. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7914. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7915. * bit).
  7916. */
  7917. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7918. reset_mask2 & (~not_reset_mask2));
  7919. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7920. reset_mask1 & (~not_reset_mask1));
  7921. barrier();
  7922. mmiowb();
  7923. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7924. reset_mask2 & (~stay_reset2));
  7925. barrier();
  7926. mmiowb();
  7927. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7928. mmiowb();
  7929. }
  7930. /**
  7931. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7932. * It should get cleared in no more than 1s.
  7933. *
  7934. * @bp: driver handle
  7935. *
  7936. * It should get cleared in no more than 1s. Returns 0 if
  7937. * pending writes bit gets cleared.
  7938. */
  7939. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7940. {
  7941. u32 cnt = 1000;
  7942. u32 pend_bits = 0;
  7943. do {
  7944. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7945. if (pend_bits == 0)
  7946. break;
  7947. usleep_range(1000, 2000);
  7948. } while (cnt-- > 0);
  7949. if (cnt <= 0) {
  7950. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7951. pend_bits);
  7952. return -EBUSY;
  7953. }
  7954. return 0;
  7955. }
  7956. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7957. {
  7958. int cnt = 1000;
  7959. u32 val = 0;
  7960. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7961. u32 tags_63_32 = 0;
  7962. /* Empty the Tetris buffer, wait for 1s */
  7963. do {
  7964. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7965. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7966. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7967. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7968. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7969. if (CHIP_IS_E3(bp))
  7970. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7971. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7972. ((port_is_idle_0 & 0x1) == 0x1) &&
  7973. ((port_is_idle_1 & 0x1) == 0x1) &&
  7974. (pgl_exp_rom2 == 0xffffffff) &&
  7975. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7976. break;
  7977. usleep_range(1000, 2000);
  7978. } while (cnt-- > 0);
  7979. if (cnt <= 0) {
  7980. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7981. 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",
  7982. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7983. pgl_exp_rom2);
  7984. return -EAGAIN;
  7985. }
  7986. barrier();
  7987. /* Close gates #2, #3 and #4 */
  7988. bnx2x_set_234_gates(bp, true);
  7989. /* Poll for IGU VQs for 57712 and newer chips */
  7990. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7991. return -EAGAIN;
  7992. /* TBD: Indicate that "process kill" is in progress to MCP */
  7993. /* Clear "unprepared" bit */
  7994. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7995. barrier();
  7996. /* Make sure all is written to the chip before the reset */
  7997. mmiowb();
  7998. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7999. * PSWHST, GRC and PSWRD Tetris buffer.
  8000. */
  8001. usleep_range(1000, 2000);
  8002. /* Prepare to chip reset: */
  8003. /* MCP */
  8004. if (global)
  8005. bnx2x_reset_mcp_prep(bp, &val);
  8006. /* PXP */
  8007. bnx2x_pxp_prep(bp);
  8008. barrier();
  8009. /* reset the chip */
  8010. bnx2x_process_kill_chip_reset(bp, global);
  8011. barrier();
  8012. /* clear errors in PGB */
  8013. if (!CHIP_IS_E1x(bp))
  8014. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8015. /* Recover after reset: */
  8016. /* MCP */
  8017. if (global && bnx2x_reset_mcp_comp(bp, val))
  8018. return -EAGAIN;
  8019. /* TBD: Add resetting the NO_MCP mode DB here */
  8020. /* Open the gates #2, #3 and #4 */
  8021. bnx2x_set_234_gates(bp, false);
  8022. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8023. * reset state, re-enable attentions. */
  8024. return 0;
  8025. }
  8026. static int bnx2x_leader_reset(struct bnx2x *bp)
  8027. {
  8028. int rc = 0;
  8029. bool global = bnx2x_reset_is_global(bp);
  8030. u32 load_code;
  8031. /* if not going to reset MCP - load "fake" driver to reset HW while
  8032. * driver is owner of the HW
  8033. */
  8034. if (!global && !BP_NOMCP(bp)) {
  8035. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8036. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8037. if (!load_code) {
  8038. BNX2X_ERR("MCP response failure, aborting\n");
  8039. rc = -EAGAIN;
  8040. goto exit_leader_reset;
  8041. }
  8042. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8043. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8044. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8045. rc = -EAGAIN;
  8046. goto exit_leader_reset2;
  8047. }
  8048. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8049. if (!load_code) {
  8050. BNX2X_ERR("MCP response failure, aborting\n");
  8051. rc = -EAGAIN;
  8052. goto exit_leader_reset2;
  8053. }
  8054. }
  8055. /* Try to recover after the failure */
  8056. if (bnx2x_process_kill(bp, global)) {
  8057. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8058. BP_PATH(bp));
  8059. rc = -EAGAIN;
  8060. goto exit_leader_reset2;
  8061. }
  8062. /*
  8063. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8064. * state.
  8065. */
  8066. bnx2x_set_reset_done(bp);
  8067. if (global)
  8068. bnx2x_clear_reset_global(bp);
  8069. exit_leader_reset2:
  8070. /* unload "fake driver" if it was loaded */
  8071. if (!global && !BP_NOMCP(bp)) {
  8072. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8073. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8074. }
  8075. exit_leader_reset:
  8076. bp->is_leader = 0;
  8077. bnx2x_release_leader_lock(bp);
  8078. smp_mb();
  8079. return rc;
  8080. }
  8081. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8082. {
  8083. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8084. /* Disconnect this device */
  8085. netif_device_detach(bp->dev);
  8086. /*
  8087. * Block ifup for all function on this engine until "process kill"
  8088. * or power cycle.
  8089. */
  8090. bnx2x_set_reset_in_progress(bp);
  8091. /* Shut down the power */
  8092. bnx2x_set_power_state(bp, PCI_D3hot);
  8093. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8094. smp_mb();
  8095. }
  8096. /*
  8097. * Assumption: runs under rtnl lock. This together with the fact
  8098. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8099. * will never be called when netif_running(bp->dev) is false.
  8100. */
  8101. static void bnx2x_parity_recover(struct bnx2x *bp)
  8102. {
  8103. bool global = false;
  8104. u32 error_recovered, error_unrecovered;
  8105. bool is_parity;
  8106. DP(NETIF_MSG_HW, "Handling parity\n");
  8107. while (1) {
  8108. switch (bp->recovery_state) {
  8109. case BNX2X_RECOVERY_INIT:
  8110. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8111. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8112. WARN_ON(!is_parity);
  8113. /* Try to get a LEADER_LOCK HW lock */
  8114. if (bnx2x_trylock_leader_lock(bp)) {
  8115. bnx2x_set_reset_in_progress(bp);
  8116. /*
  8117. * Check if there is a global attention and if
  8118. * there was a global attention, set the global
  8119. * reset bit.
  8120. */
  8121. if (global)
  8122. bnx2x_set_reset_global(bp);
  8123. bp->is_leader = 1;
  8124. }
  8125. /* Stop the driver */
  8126. /* If interface has been removed - break */
  8127. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8128. return;
  8129. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8130. /* Ensure "is_leader", MCP command sequence and
  8131. * "recovery_state" update values are seen on other
  8132. * CPUs.
  8133. */
  8134. smp_mb();
  8135. break;
  8136. case BNX2X_RECOVERY_WAIT:
  8137. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8138. if (bp->is_leader) {
  8139. int other_engine = BP_PATH(bp) ? 0 : 1;
  8140. bool other_load_status =
  8141. bnx2x_get_load_status(bp, other_engine);
  8142. bool load_status =
  8143. bnx2x_get_load_status(bp, BP_PATH(bp));
  8144. global = bnx2x_reset_is_global(bp);
  8145. /*
  8146. * In case of a parity in a global block, let
  8147. * the first leader that performs a
  8148. * leader_reset() reset the global blocks in
  8149. * order to clear global attentions. Otherwise
  8150. * the gates will remain closed for that
  8151. * engine.
  8152. */
  8153. if (load_status ||
  8154. (global && other_load_status)) {
  8155. /* Wait until all other functions get
  8156. * down.
  8157. */
  8158. schedule_delayed_work(&bp->sp_rtnl_task,
  8159. HZ/10);
  8160. return;
  8161. } else {
  8162. /* If all other functions got down -
  8163. * try to bring the chip back to
  8164. * normal. In any case it's an exit
  8165. * point for a leader.
  8166. */
  8167. if (bnx2x_leader_reset(bp)) {
  8168. bnx2x_recovery_failed(bp);
  8169. return;
  8170. }
  8171. /* If we are here, means that the
  8172. * leader has succeeded and doesn't
  8173. * want to be a leader any more. Try
  8174. * to continue as a none-leader.
  8175. */
  8176. break;
  8177. }
  8178. } else { /* non-leader */
  8179. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8180. /* Try to get a LEADER_LOCK HW lock as
  8181. * long as a former leader may have
  8182. * been unloaded by the user or
  8183. * released a leadership by another
  8184. * reason.
  8185. */
  8186. if (bnx2x_trylock_leader_lock(bp)) {
  8187. /* I'm a leader now! Restart a
  8188. * switch case.
  8189. */
  8190. bp->is_leader = 1;
  8191. break;
  8192. }
  8193. schedule_delayed_work(&bp->sp_rtnl_task,
  8194. HZ/10);
  8195. return;
  8196. } else {
  8197. /*
  8198. * If there was a global attention, wait
  8199. * for it to be cleared.
  8200. */
  8201. if (bnx2x_reset_is_global(bp)) {
  8202. schedule_delayed_work(
  8203. &bp->sp_rtnl_task,
  8204. HZ/10);
  8205. return;
  8206. }
  8207. error_recovered =
  8208. bp->eth_stats.recoverable_error;
  8209. error_unrecovered =
  8210. bp->eth_stats.unrecoverable_error;
  8211. bp->recovery_state =
  8212. BNX2X_RECOVERY_NIC_LOADING;
  8213. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8214. error_unrecovered++;
  8215. netdev_err(bp->dev,
  8216. "Recovery failed. Power cycle needed\n");
  8217. /* Disconnect this device */
  8218. netif_device_detach(bp->dev);
  8219. /* Shut down the power */
  8220. bnx2x_set_power_state(
  8221. bp, PCI_D3hot);
  8222. smp_mb();
  8223. } else {
  8224. bp->recovery_state =
  8225. BNX2X_RECOVERY_DONE;
  8226. error_recovered++;
  8227. smp_mb();
  8228. }
  8229. bp->eth_stats.recoverable_error =
  8230. error_recovered;
  8231. bp->eth_stats.unrecoverable_error =
  8232. error_unrecovered;
  8233. return;
  8234. }
  8235. }
  8236. default:
  8237. return;
  8238. }
  8239. }
  8240. }
  8241. static int bnx2x_close(struct net_device *dev);
  8242. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8243. * scheduled on a general queue in order to prevent a dead lock.
  8244. */
  8245. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8246. {
  8247. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8248. rtnl_lock();
  8249. if (!netif_running(bp->dev)) {
  8250. rtnl_unlock();
  8251. return;
  8252. }
  8253. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8254. #ifdef BNX2X_STOP_ON_ERROR
  8255. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8256. "you will need to reboot when done\n");
  8257. goto sp_rtnl_not_reset;
  8258. #endif
  8259. /*
  8260. * Clear all pending SP commands as we are going to reset the
  8261. * function anyway.
  8262. */
  8263. bp->sp_rtnl_state = 0;
  8264. smp_mb();
  8265. bnx2x_parity_recover(bp);
  8266. rtnl_unlock();
  8267. return;
  8268. }
  8269. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8270. #ifdef BNX2X_STOP_ON_ERROR
  8271. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8272. "you will need to reboot when done\n");
  8273. goto sp_rtnl_not_reset;
  8274. #endif
  8275. /*
  8276. * Clear all pending SP commands as we are going to reset the
  8277. * function anyway.
  8278. */
  8279. bp->sp_rtnl_state = 0;
  8280. smp_mb();
  8281. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8282. bnx2x_nic_load(bp, LOAD_NORMAL);
  8283. rtnl_unlock();
  8284. return;
  8285. }
  8286. #ifdef BNX2X_STOP_ON_ERROR
  8287. sp_rtnl_not_reset:
  8288. #endif
  8289. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8290. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8291. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8292. bnx2x_after_function_update(bp);
  8293. /*
  8294. * in case of fan failure we need to reset id if the "stop on error"
  8295. * debug flag is set, since we trying to prevent permanent overheating
  8296. * damage
  8297. */
  8298. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8299. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8300. netif_device_detach(bp->dev);
  8301. bnx2x_close(bp->dev);
  8302. rtnl_unlock();
  8303. return;
  8304. }
  8305. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8306. DP(BNX2X_MSG_SP,
  8307. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8308. bnx2x_vfpf_set_mcast(bp->dev);
  8309. }
  8310. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8311. &bp->sp_rtnl_state)){
  8312. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8313. bnx2x_tx_disable(bp);
  8314. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8315. }
  8316. }
  8317. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8318. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8319. bnx2x_set_rx_mode_inner(bp);
  8320. }
  8321. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8322. &bp->sp_rtnl_state))
  8323. bnx2x_pf_set_vfs_vlan(bp);
  8324. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8325. bnx2x_dcbx_stop_hw_tx(bp);
  8326. bnx2x_dcbx_resume_hw_tx(bp);
  8327. }
  8328. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8329. &bp->sp_rtnl_state))
  8330. bnx2x_update_mng_version(bp);
  8331. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8332. * can be called from other contexts as well)
  8333. */
  8334. rtnl_unlock();
  8335. /* enable SR-IOV if applicable */
  8336. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8337. &bp->sp_rtnl_state)) {
  8338. bnx2x_disable_sriov(bp);
  8339. bnx2x_enable_sriov(bp);
  8340. }
  8341. }
  8342. static void bnx2x_period_task(struct work_struct *work)
  8343. {
  8344. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8345. if (!netif_running(bp->dev))
  8346. goto period_task_exit;
  8347. if (CHIP_REV_IS_SLOW(bp)) {
  8348. BNX2X_ERR("period task called on emulation, ignoring\n");
  8349. goto period_task_exit;
  8350. }
  8351. bnx2x_acquire_phy_lock(bp);
  8352. /*
  8353. * The barrier is needed to ensure the ordering between the writing to
  8354. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8355. * the reading here.
  8356. */
  8357. smp_mb();
  8358. if (bp->port.pmf) {
  8359. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8360. /* Re-queue task in 1 sec */
  8361. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8362. }
  8363. bnx2x_release_phy_lock(bp);
  8364. period_task_exit:
  8365. return;
  8366. }
  8367. /*
  8368. * Init service functions
  8369. */
  8370. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8371. {
  8372. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8373. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8374. return base + (BP_ABS_FUNC(bp)) * stride;
  8375. }
  8376. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8377. struct bnx2x_mac_vals *vals)
  8378. {
  8379. u32 val, base_addr, offset, mask, reset_reg;
  8380. bool mac_stopped = false;
  8381. u8 port = BP_PORT(bp);
  8382. /* reset addresses as they also mark which values were changed */
  8383. vals->bmac_addr = 0;
  8384. vals->umac_addr = 0;
  8385. vals->xmac_addr = 0;
  8386. vals->emac_addr = 0;
  8387. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8388. if (!CHIP_IS_E3(bp)) {
  8389. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8390. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8391. if ((mask & reset_reg) && val) {
  8392. u32 wb_data[2];
  8393. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8394. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8395. : NIG_REG_INGRESS_BMAC0_MEM;
  8396. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8397. : BIGMAC_REGISTER_BMAC_CONTROL;
  8398. /*
  8399. * use rd/wr since we cannot use dmae. This is safe
  8400. * since MCP won't access the bus due to the request
  8401. * to unload, and no function on the path can be
  8402. * loaded at this time.
  8403. */
  8404. wb_data[0] = REG_RD(bp, base_addr + offset);
  8405. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8406. vals->bmac_addr = base_addr + offset;
  8407. vals->bmac_val[0] = wb_data[0];
  8408. vals->bmac_val[1] = wb_data[1];
  8409. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8410. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8411. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8412. }
  8413. BNX2X_DEV_INFO("Disable emac Rx\n");
  8414. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8415. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8416. REG_WR(bp, vals->emac_addr, 0);
  8417. mac_stopped = true;
  8418. } else {
  8419. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8420. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8421. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8422. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8423. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8424. val & ~(1 << 1));
  8425. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8426. val | (1 << 1));
  8427. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8428. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8429. REG_WR(bp, vals->xmac_addr, 0);
  8430. mac_stopped = true;
  8431. }
  8432. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8433. if (mask & reset_reg) {
  8434. BNX2X_DEV_INFO("Disable umac Rx\n");
  8435. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8436. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8437. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8438. REG_WR(bp, vals->umac_addr, 0);
  8439. mac_stopped = true;
  8440. }
  8441. }
  8442. if (mac_stopped)
  8443. msleep(20);
  8444. }
  8445. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8446. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8447. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8448. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8449. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8450. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8451. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8452. #define BNX2X_PREV_UNDI_MF_PORT(p) (BAR_TSTRORM_INTMEM + 0x150c + ((p) << 4))
  8453. #define BNX2X_PREV_UNDI_MF_FUNC(f) (BAR_TSTRORM_INTMEM + 0x184c + ((f) << 4))
  8454. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8455. {
  8456. /* UNDI marks its presence in DORQ -
  8457. * it initializes CID offset for normal bell to 0x7
  8458. */
  8459. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8460. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8461. return false;
  8462. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8463. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8464. return true;
  8465. }
  8466. return false;
  8467. }
  8468. static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
  8469. {
  8470. u8 major, minor, version;
  8471. u32 fw;
  8472. /* Must check that FW is loaded */
  8473. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8474. MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
  8475. BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
  8476. return false;
  8477. }
  8478. /* Read Currently loaded FW version */
  8479. fw = REG_RD(bp, XSEM_REG_PRAM);
  8480. major = fw & 0xff;
  8481. minor = (fw >> 0x8) & 0xff;
  8482. version = (fw >> 0x10) & 0xff;
  8483. BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
  8484. fw, major, minor, version);
  8485. if (major > BCM_5710_UNDI_FW_MF_MAJOR)
  8486. return true;
  8487. if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
  8488. (minor > BCM_5710_UNDI_FW_MF_MINOR))
  8489. return true;
  8490. if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
  8491. (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
  8492. (version >= BCM_5710_UNDI_FW_MF_VERS))
  8493. return true;
  8494. return false;
  8495. }
  8496. static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
  8497. {
  8498. int i;
  8499. /* Due to legacy (FW) code, the first function on each engine has a
  8500. * different offset macro from the rest of the functions.
  8501. * Setting this for all 8 functions is harmless regardless of whether
  8502. * this is actually a multi-function device.
  8503. */
  8504. for (i = 0; i < 2; i++)
  8505. REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
  8506. for (i = 2; i < 8; i++)
  8507. REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
  8508. BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
  8509. }
  8510. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8511. {
  8512. u16 rcq, bd;
  8513. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8514. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8515. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8516. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8517. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8518. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8519. port, bd, rcq);
  8520. }
  8521. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8522. {
  8523. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8524. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8525. if (!rc) {
  8526. BNX2X_ERR("MCP response failure, aborting\n");
  8527. return -EBUSY;
  8528. }
  8529. return 0;
  8530. }
  8531. static struct bnx2x_prev_path_list *
  8532. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8533. {
  8534. struct bnx2x_prev_path_list *tmp_list;
  8535. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8536. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8537. bp->pdev->bus->number == tmp_list->bus &&
  8538. BP_PATH(bp) == tmp_list->path)
  8539. return tmp_list;
  8540. return NULL;
  8541. }
  8542. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8543. {
  8544. struct bnx2x_prev_path_list *tmp_list;
  8545. int rc;
  8546. rc = down_interruptible(&bnx2x_prev_sem);
  8547. if (rc) {
  8548. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8549. return rc;
  8550. }
  8551. tmp_list = bnx2x_prev_path_get_entry(bp);
  8552. if (tmp_list) {
  8553. tmp_list->aer = 1;
  8554. rc = 0;
  8555. } else {
  8556. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8557. BP_PATH(bp));
  8558. }
  8559. up(&bnx2x_prev_sem);
  8560. return rc;
  8561. }
  8562. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8563. {
  8564. struct bnx2x_prev_path_list *tmp_list;
  8565. bool rc = false;
  8566. if (down_trylock(&bnx2x_prev_sem))
  8567. return false;
  8568. tmp_list = bnx2x_prev_path_get_entry(bp);
  8569. if (tmp_list) {
  8570. if (tmp_list->aer) {
  8571. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8572. BP_PATH(bp));
  8573. } else {
  8574. rc = true;
  8575. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8576. BP_PATH(bp));
  8577. }
  8578. }
  8579. up(&bnx2x_prev_sem);
  8580. return rc;
  8581. }
  8582. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8583. {
  8584. struct bnx2x_prev_path_list *entry;
  8585. bool val;
  8586. down(&bnx2x_prev_sem);
  8587. entry = bnx2x_prev_path_get_entry(bp);
  8588. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8589. up(&bnx2x_prev_sem);
  8590. return val;
  8591. }
  8592. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8593. {
  8594. struct bnx2x_prev_path_list *tmp_list;
  8595. int rc;
  8596. rc = down_interruptible(&bnx2x_prev_sem);
  8597. if (rc) {
  8598. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8599. return rc;
  8600. }
  8601. /* Check whether the entry for this path already exists */
  8602. tmp_list = bnx2x_prev_path_get_entry(bp);
  8603. if (tmp_list) {
  8604. if (!tmp_list->aer) {
  8605. BNX2X_ERR("Re-Marking the path.\n");
  8606. } else {
  8607. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8608. BP_PATH(bp));
  8609. tmp_list->aer = 0;
  8610. }
  8611. up(&bnx2x_prev_sem);
  8612. return 0;
  8613. }
  8614. up(&bnx2x_prev_sem);
  8615. /* Create an entry for this path and add it */
  8616. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8617. if (!tmp_list) {
  8618. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8619. return -ENOMEM;
  8620. }
  8621. tmp_list->bus = bp->pdev->bus->number;
  8622. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8623. tmp_list->path = BP_PATH(bp);
  8624. tmp_list->aer = 0;
  8625. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8626. rc = down_interruptible(&bnx2x_prev_sem);
  8627. if (rc) {
  8628. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8629. kfree(tmp_list);
  8630. } else {
  8631. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8632. BP_PATH(bp));
  8633. list_add(&tmp_list->list, &bnx2x_prev_list);
  8634. up(&bnx2x_prev_sem);
  8635. }
  8636. return rc;
  8637. }
  8638. static int bnx2x_do_flr(struct bnx2x *bp)
  8639. {
  8640. struct pci_dev *dev = bp->pdev;
  8641. if (CHIP_IS_E1x(bp)) {
  8642. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8643. return -EINVAL;
  8644. }
  8645. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8646. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8647. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8648. bp->common.bc_ver);
  8649. return -EINVAL;
  8650. }
  8651. if (!pci_wait_for_pending_transaction(dev))
  8652. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8653. BNX2X_DEV_INFO("Initiating FLR\n");
  8654. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8655. return 0;
  8656. }
  8657. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8658. {
  8659. int rc;
  8660. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8661. /* Test if previous unload process was already finished for this path */
  8662. if (bnx2x_prev_is_path_marked(bp))
  8663. return bnx2x_prev_mcp_done(bp);
  8664. BNX2X_DEV_INFO("Path is unmarked\n");
  8665. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8666. if (bnx2x_prev_is_after_undi(bp))
  8667. goto out;
  8668. /* If function has FLR capabilities, and existing FW version matches
  8669. * the one required, then FLR will be sufficient to clean any residue
  8670. * left by previous driver
  8671. */
  8672. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8673. if (!rc) {
  8674. /* fw version is good */
  8675. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8676. rc = bnx2x_do_flr(bp);
  8677. }
  8678. if (!rc) {
  8679. /* FLR was performed */
  8680. BNX2X_DEV_INFO("FLR successful\n");
  8681. return 0;
  8682. }
  8683. BNX2X_DEV_INFO("Could not FLR\n");
  8684. out:
  8685. /* Close the MCP request, return failure*/
  8686. rc = bnx2x_prev_mcp_done(bp);
  8687. if (!rc)
  8688. rc = BNX2X_PREV_WAIT_NEEDED;
  8689. return rc;
  8690. }
  8691. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8692. {
  8693. u32 reset_reg, tmp_reg = 0, rc;
  8694. bool prev_undi = false;
  8695. struct bnx2x_mac_vals mac_vals;
  8696. /* It is possible a previous function received 'common' answer,
  8697. * but hasn't loaded yet, therefore creating a scenario of
  8698. * multiple functions receiving 'common' on the same path.
  8699. */
  8700. BNX2X_DEV_INFO("Common unload Flow\n");
  8701. memset(&mac_vals, 0, sizeof(mac_vals));
  8702. if (bnx2x_prev_is_path_marked(bp))
  8703. return bnx2x_prev_mcp_done(bp);
  8704. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8705. /* Reset should be performed after BRB is emptied */
  8706. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8707. u32 timer_count = 1000;
  8708. bool need_write = true;
  8709. /* Close the MAC Rx to prevent BRB from filling up */
  8710. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8711. /* close LLH filters towards the BRB */
  8712. bnx2x_set_rx_filter(&bp->link_params, 0);
  8713. /* Check if the UNDI driver was previously loaded */
  8714. if (bnx2x_prev_is_after_undi(bp)) {
  8715. prev_undi = true;
  8716. /* clear the UNDI indication */
  8717. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8718. /* clear possible idle check errors */
  8719. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8720. }
  8721. if (!CHIP_IS_E1x(bp))
  8722. /* block FW from writing to host */
  8723. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8724. /* wait until BRB is empty */
  8725. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8726. while (timer_count) {
  8727. u32 prev_brb = tmp_reg;
  8728. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8729. if (!tmp_reg)
  8730. break;
  8731. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8732. /* reset timer as long as BRB actually gets emptied */
  8733. if (prev_brb > tmp_reg)
  8734. timer_count = 1000;
  8735. else
  8736. timer_count--;
  8737. /* New UNDI FW supports MF and contains better
  8738. * cleaning methods - might be redundant but harmless.
  8739. */
  8740. if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
  8741. if (need_write) {
  8742. bnx2x_prev_unload_undi_mf(bp);
  8743. need_write = false;
  8744. }
  8745. } else if (prev_undi) {
  8746. /* If UNDI resides in memory,
  8747. * manually increment it
  8748. */
  8749. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8750. }
  8751. udelay(10);
  8752. }
  8753. if (!timer_count)
  8754. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8755. }
  8756. /* No packets are in the pipeline, path is ready for reset */
  8757. bnx2x_reset_common(bp);
  8758. if (mac_vals.xmac_addr)
  8759. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8760. if (mac_vals.umac_addr)
  8761. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8762. if (mac_vals.emac_addr)
  8763. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8764. if (mac_vals.bmac_addr) {
  8765. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8766. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8767. }
  8768. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8769. if (rc) {
  8770. bnx2x_prev_mcp_done(bp);
  8771. return rc;
  8772. }
  8773. return bnx2x_prev_mcp_done(bp);
  8774. }
  8775. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8776. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8777. * the addresses of the transaction, resulting in was-error bit set in the pci
  8778. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8779. * to clear the interrupt which detected this from the pglueb and the was done
  8780. * bit
  8781. */
  8782. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8783. {
  8784. if (!CHIP_IS_E1x(bp)) {
  8785. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8786. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8787. DP(BNX2X_MSG_SP,
  8788. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8789. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8790. 1 << BP_FUNC(bp));
  8791. }
  8792. }
  8793. }
  8794. static int bnx2x_prev_unload(struct bnx2x *bp)
  8795. {
  8796. int time_counter = 10;
  8797. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8798. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8799. /* clear hw from errors which may have resulted from an interrupted
  8800. * dmae transaction.
  8801. */
  8802. bnx2x_prev_interrupted_dmae(bp);
  8803. /* Release previously held locks */
  8804. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8805. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8806. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8807. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8808. if (hw_lock_val) {
  8809. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8810. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8811. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8812. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8813. }
  8814. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8815. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8816. } else
  8817. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8818. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8819. BNX2X_DEV_INFO("Release previously held alr\n");
  8820. bnx2x_release_alr(bp);
  8821. }
  8822. do {
  8823. int aer = 0;
  8824. /* Lock MCP using an unload request */
  8825. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8826. if (!fw) {
  8827. BNX2X_ERR("MCP response failure, aborting\n");
  8828. rc = -EBUSY;
  8829. break;
  8830. }
  8831. rc = down_interruptible(&bnx2x_prev_sem);
  8832. if (rc) {
  8833. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8834. rc);
  8835. } else {
  8836. /* If Path is marked by EEH, ignore unload status */
  8837. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8838. bnx2x_prev_path_get_entry(bp)->aer);
  8839. up(&bnx2x_prev_sem);
  8840. }
  8841. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8842. rc = bnx2x_prev_unload_common(bp);
  8843. break;
  8844. }
  8845. /* non-common reply from MCP might require looping */
  8846. rc = bnx2x_prev_unload_uncommon(bp);
  8847. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8848. break;
  8849. msleep(20);
  8850. } while (--time_counter);
  8851. if (!time_counter || rc) {
  8852. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8853. rc = -EPROBE_DEFER;
  8854. }
  8855. /* Mark function if its port was used to boot from SAN */
  8856. if (bnx2x_port_after_undi(bp))
  8857. bp->link_params.feature_config_flags |=
  8858. FEATURE_CONFIG_BOOT_FROM_SAN;
  8859. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8860. return rc;
  8861. }
  8862. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8863. {
  8864. u32 val, val2, val3, val4, id, boot_mode;
  8865. u16 pmc;
  8866. /* Get the chip revision id and number. */
  8867. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8868. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8869. id = ((val & 0xffff) << 16);
  8870. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8871. id |= ((val & 0xf) << 12);
  8872. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8873. * the configuration space (so we need to reg_rd)
  8874. */
  8875. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8876. id |= (((val >> 24) & 0xf) << 4);
  8877. val = REG_RD(bp, MISC_REG_BOND_ID);
  8878. id |= (val & 0xf);
  8879. bp->common.chip_id = id;
  8880. /* force 57811 according to MISC register */
  8881. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8882. if (CHIP_IS_57810(bp))
  8883. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8884. (bp->common.chip_id & 0x0000FFFF);
  8885. else if (CHIP_IS_57810_MF(bp))
  8886. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8887. (bp->common.chip_id & 0x0000FFFF);
  8888. bp->common.chip_id |= 0x1;
  8889. }
  8890. /* Set doorbell size */
  8891. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8892. if (!CHIP_IS_E1x(bp)) {
  8893. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8894. if ((val & 1) == 0)
  8895. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8896. else
  8897. val = (val >> 1) & 1;
  8898. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8899. "2_PORT_MODE");
  8900. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8901. CHIP_2_PORT_MODE;
  8902. if (CHIP_MODE_IS_4_PORT(bp))
  8903. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8904. else
  8905. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8906. } else {
  8907. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8908. bp->pfid = bp->pf_num; /* 0..7 */
  8909. }
  8910. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8911. bp->link_params.chip_id = bp->common.chip_id;
  8912. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8913. val = (REG_RD(bp, 0x2874) & 0x55);
  8914. if ((bp->common.chip_id & 0x1) ||
  8915. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8916. bp->flags |= ONE_PORT_FLAG;
  8917. BNX2X_DEV_INFO("single port device\n");
  8918. }
  8919. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8920. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8921. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8922. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8923. bp->common.flash_size, bp->common.flash_size);
  8924. bnx2x_init_shmem(bp);
  8925. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8926. MISC_REG_GENERIC_CR_1 :
  8927. MISC_REG_GENERIC_CR_0));
  8928. bp->link_params.shmem_base = bp->common.shmem_base;
  8929. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8930. if (SHMEM2_RD(bp, size) >
  8931. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8932. bp->link_params.lfa_base =
  8933. REG_RD(bp, bp->common.shmem2_base +
  8934. (u32)offsetof(struct shmem2_region,
  8935. lfa_host_addr[BP_PORT(bp)]));
  8936. else
  8937. bp->link_params.lfa_base = 0;
  8938. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8939. bp->common.shmem_base, bp->common.shmem2_base);
  8940. if (!bp->common.shmem_base) {
  8941. BNX2X_DEV_INFO("MCP not active\n");
  8942. bp->flags |= NO_MCP_FLAG;
  8943. return;
  8944. }
  8945. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8946. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8947. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8948. SHARED_HW_CFG_LED_MODE_MASK) >>
  8949. SHARED_HW_CFG_LED_MODE_SHIFT);
  8950. bp->link_params.feature_config_flags = 0;
  8951. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8952. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8953. bp->link_params.feature_config_flags |=
  8954. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8955. else
  8956. bp->link_params.feature_config_flags &=
  8957. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8958. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8959. bp->common.bc_ver = val;
  8960. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8961. if (val < BNX2X_BC_VER) {
  8962. /* for now only warn
  8963. * later we might need to enforce this */
  8964. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8965. BNX2X_BC_VER, val);
  8966. }
  8967. bp->link_params.feature_config_flags |=
  8968. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8969. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8970. bp->link_params.feature_config_flags |=
  8971. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8972. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8973. bp->link_params.feature_config_flags |=
  8974. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8975. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8976. bp->link_params.feature_config_flags |=
  8977. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8978. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8979. bp->link_params.feature_config_flags |=
  8980. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8981. FEATURE_CONFIG_MT_SUPPORT : 0;
  8982. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8983. BC_SUPPORTS_PFC_STATS : 0;
  8984. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8985. BC_SUPPORTS_FCOE_FEATURES : 0;
  8986. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8987. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8988. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8989. BC_SUPPORTS_RMMOD_CMD : 0;
  8990. boot_mode = SHMEM_RD(bp,
  8991. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8992. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8993. switch (boot_mode) {
  8994. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8995. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8996. break;
  8997. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8998. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8999. break;
  9000. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9001. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9002. break;
  9003. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9004. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9005. break;
  9006. }
  9007. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9008. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9009. BNX2X_DEV_INFO("%sWoL capable\n",
  9010. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9011. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9012. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9013. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9014. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9015. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9016. val, val2, val3, val4);
  9017. }
  9018. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9019. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9020. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9021. {
  9022. int pfid = BP_FUNC(bp);
  9023. int igu_sb_id;
  9024. u32 val;
  9025. u8 fid, igu_sb_cnt = 0;
  9026. bp->igu_base_sb = 0xff;
  9027. if (CHIP_INT_MODE_IS_BC(bp)) {
  9028. int vn = BP_VN(bp);
  9029. igu_sb_cnt = bp->igu_sb_cnt;
  9030. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9031. FP_SB_MAX_E1x;
  9032. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9033. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9034. return 0;
  9035. }
  9036. /* IGU in normal mode - read CAM */
  9037. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9038. igu_sb_id++) {
  9039. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9040. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9041. continue;
  9042. fid = IGU_FID(val);
  9043. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9044. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9045. continue;
  9046. if (IGU_VEC(val) == 0)
  9047. /* default status block */
  9048. bp->igu_dsb_id = igu_sb_id;
  9049. else {
  9050. if (bp->igu_base_sb == 0xff)
  9051. bp->igu_base_sb = igu_sb_id;
  9052. igu_sb_cnt++;
  9053. }
  9054. }
  9055. }
  9056. #ifdef CONFIG_PCI_MSI
  9057. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9058. * optional that number of CAM entries will not be equal to the value
  9059. * advertised in PCI.
  9060. * Driver should use the minimal value of both as the actual status
  9061. * block count
  9062. */
  9063. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9064. #endif
  9065. if (igu_sb_cnt == 0) {
  9066. BNX2X_ERR("CAM configuration error\n");
  9067. return -EINVAL;
  9068. }
  9069. return 0;
  9070. }
  9071. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9072. {
  9073. int cfg_size = 0, idx, port = BP_PORT(bp);
  9074. /* Aggregation of supported attributes of all external phys */
  9075. bp->port.supported[0] = 0;
  9076. bp->port.supported[1] = 0;
  9077. switch (bp->link_params.num_phys) {
  9078. case 1:
  9079. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9080. cfg_size = 1;
  9081. break;
  9082. case 2:
  9083. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9084. cfg_size = 1;
  9085. break;
  9086. case 3:
  9087. if (bp->link_params.multi_phy_config &
  9088. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9089. bp->port.supported[1] =
  9090. bp->link_params.phy[EXT_PHY1].supported;
  9091. bp->port.supported[0] =
  9092. bp->link_params.phy[EXT_PHY2].supported;
  9093. } else {
  9094. bp->port.supported[0] =
  9095. bp->link_params.phy[EXT_PHY1].supported;
  9096. bp->port.supported[1] =
  9097. bp->link_params.phy[EXT_PHY2].supported;
  9098. }
  9099. cfg_size = 2;
  9100. break;
  9101. }
  9102. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9103. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9104. SHMEM_RD(bp,
  9105. dev_info.port_hw_config[port].external_phy_config),
  9106. SHMEM_RD(bp,
  9107. dev_info.port_hw_config[port].external_phy_config2));
  9108. return;
  9109. }
  9110. if (CHIP_IS_E3(bp))
  9111. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9112. else {
  9113. switch (switch_cfg) {
  9114. case SWITCH_CFG_1G:
  9115. bp->port.phy_addr = REG_RD(
  9116. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9117. break;
  9118. case SWITCH_CFG_10G:
  9119. bp->port.phy_addr = REG_RD(
  9120. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9121. break;
  9122. default:
  9123. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9124. bp->port.link_config[0]);
  9125. return;
  9126. }
  9127. }
  9128. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9129. /* mask what we support according to speed_cap_mask per configuration */
  9130. for (idx = 0; idx < cfg_size; idx++) {
  9131. if (!(bp->link_params.speed_cap_mask[idx] &
  9132. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9133. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9134. if (!(bp->link_params.speed_cap_mask[idx] &
  9135. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9136. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9137. if (!(bp->link_params.speed_cap_mask[idx] &
  9138. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9139. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9140. if (!(bp->link_params.speed_cap_mask[idx] &
  9141. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9142. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9143. if (!(bp->link_params.speed_cap_mask[idx] &
  9144. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9145. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9146. SUPPORTED_1000baseT_Full);
  9147. if (!(bp->link_params.speed_cap_mask[idx] &
  9148. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9149. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9150. if (!(bp->link_params.speed_cap_mask[idx] &
  9151. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9152. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9153. if (!(bp->link_params.speed_cap_mask[idx] &
  9154. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9155. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9156. }
  9157. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9158. bp->port.supported[1]);
  9159. }
  9160. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9161. {
  9162. u32 link_config, idx, cfg_size = 0;
  9163. bp->port.advertising[0] = 0;
  9164. bp->port.advertising[1] = 0;
  9165. switch (bp->link_params.num_phys) {
  9166. case 1:
  9167. case 2:
  9168. cfg_size = 1;
  9169. break;
  9170. case 3:
  9171. cfg_size = 2;
  9172. break;
  9173. }
  9174. for (idx = 0; idx < cfg_size; idx++) {
  9175. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9176. link_config = bp->port.link_config[idx];
  9177. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9178. case PORT_FEATURE_LINK_SPEED_AUTO:
  9179. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9180. bp->link_params.req_line_speed[idx] =
  9181. SPEED_AUTO_NEG;
  9182. bp->port.advertising[idx] |=
  9183. bp->port.supported[idx];
  9184. if (bp->link_params.phy[EXT_PHY1].type ==
  9185. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9186. bp->port.advertising[idx] |=
  9187. (SUPPORTED_100baseT_Half |
  9188. SUPPORTED_100baseT_Full);
  9189. } else {
  9190. /* force 10G, no AN */
  9191. bp->link_params.req_line_speed[idx] =
  9192. SPEED_10000;
  9193. bp->port.advertising[idx] |=
  9194. (ADVERTISED_10000baseT_Full |
  9195. ADVERTISED_FIBRE);
  9196. continue;
  9197. }
  9198. break;
  9199. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9200. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9201. bp->link_params.req_line_speed[idx] =
  9202. SPEED_10;
  9203. bp->port.advertising[idx] |=
  9204. (ADVERTISED_10baseT_Full |
  9205. ADVERTISED_TP);
  9206. } else {
  9207. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9208. link_config,
  9209. bp->link_params.speed_cap_mask[idx]);
  9210. return;
  9211. }
  9212. break;
  9213. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9214. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9215. bp->link_params.req_line_speed[idx] =
  9216. SPEED_10;
  9217. bp->link_params.req_duplex[idx] =
  9218. DUPLEX_HALF;
  9219. bp->port.advertising[idx] |=
  9220. (ADVERTISED_10baseT_Half |
  9221. ADVERTISED_TP);
  9222. } else {
  9223. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9224. link_config,
  9225. bp->link_params.speed_cap_mask[idx]);
  9226. return;
  9227. }
  9228. break;
  9229. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9230. if (bp->port.supported[idx] &
  9231. SUPPORTED_100baseT_Full) {
  9232. bp->link_params.req_line_speed[idx] =
  9233. SPEED_100;
  9234. bp->port.advertising[idx] |=
  9235. (ADVERTISED_100baseT_Full |
  9236. ADVERTISED_TP);
  9237. } else {
  9238. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9239. link_config,
  9240. bp->link_params.speed_cap_mask[idx]);
  9241. return;
  9242. }
  9243. break;
  9244. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9245. if (bp->port.supported[idx] &
  9246. SUPPORTED_100baseT_Half) {
  9247. bp->link_params.req_line_speed[idx] =
  9248. SPEED_100;
  9249. bp->link_params.req_duplex[idx] =
  9250. DUPLEX_HALF;
  9251. bp->port.advertising[idx] |=
  9252. (ADVERTISED_100baseT_Half |
  9253. ADVERTISED_TP);
  9254. } else {
  9255. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9256. link_config,
  9257. bp->link_params.speed_cap_mask[idx]);
  9258. return;
  9259. }
  9260. break;
  9261. case PORT_FEATURE_LINK_SPEED_1G:
  9262. if (bp->port.supported[idx] &
  9263. SUPPORTED_1000baseT_Full) {
  9264. bp->link_params.req_line_speed[idx] =
  9265. SPEED_1000;
  9266. bp->port.advertising[idx] |=
  9267. (ADVERTISED_1000baseT_Full |
  9268. ADVERTISED_TP);
  9269. } else {
  9270. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9271. link_config,
  9272. bp->link_params.speed_cap_mask[idx]);
  9273. return;
  9274. }
  9275. break;
  9276. case PORT_FEATURE_LINK_SPEED_2_5G:
  9277. if (bp->port.supported[idx] &
  9278. SUPPORTED_2500baseX_Full) {
  9279. bp->link_params.req_line_speed[idx] =
  9280. SPEED_2500;
  9281. bp->port.advertising[idx] |=
  9282. (ADVERTISED_2500baseX_Full |
  9283. ADVERTISED_TP);
  9284. } else {
  9285. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9286. link_config,
  9287. bp->link_params.speed_cap_mask[idx]);
  9288. return;
  9289. }
  9290. break;
  9291. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9292. if (bp->port.supported[idx] &
  9293. SUPPORTED_10000baseT_Full) {
  9294. bp->link_params.req_line_speed[idx] =
  9295. SPEED_10000;
  9296. bp->port.advertising[idx] |=
  9297. (ADVERTISED_10000baseT_Full |
  9298. ADVERTISED_FIBRE);
  9299. } else {
  9300. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9301. link_config,
  9302. bp->link_params.speed_cap_mask[idx]);
  9303. return;
  9304. }
  9305. break;
  9306. case PORT_FEATURE_LINK_SPEED_20G:
  9307. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9308. break;
  9309. default:
  9310. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9311. link_config);
  9312. bp->link_params.req_line_speed[idx] =
  9313. SPEED_AUTO_NEG;
  9314. bp->port.advertising[idx] =
  9315. bp->port.supported[idx];
  9316. break;
  9317. }
  9318. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9319. PORT_FEATURE_FLOW_CONTROL_MASK);
  9320. if (bp->link_params.req_flow_ctrl[idx] ==
  9321. BNX2X_FLOW_CTRL_AUTO) {
  9322. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9323. bp->link_params.req_flow_ctrl[idx] =
  9324. BNX2X_FLOW_CTRL_NONE;
  9325. else
  9326. bnx2x_set_requested_fc(bp);
  9327. }
  9328. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9329. bp->link_params.req_line_speed[idx],
  9330. bp->link_params.req_duplex[idx],
  9331. bp->link_params.req_flow_ctrl[idx],
  9332. bp->port.advertising[idx]);
  9333. }
  9334. }
  9335. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9336. {
  9337. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9338. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9339. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9340. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9341. }
  9342. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9343. {
  9344. int port = BP_PORT(bp);
  9345. u32 config;
  9346. u32 ext_phy_type, ext_phy_config, eee_mode;
  9347. bp->link_params.bp = bp;
  9348. bp->link_params.port = port;
  9349. bp->link_params.lane_config =
  9350. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9351. bp->link_params.speed_cap_mask[0] =
  9352. SHMEM_RD(bp,
  9353. dev_info.port_hw_config[port].speed_capability_mask) &
  9354. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9355. bp->link_params.speed_cap_mask[1] =
  9356. SHMEM_RD(bp,
  9357. dev_info.port_hw_config[port].speed_capability_mask2) &
  9358. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9359. bp->port.link_config[0] =
  9360. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9361. bp->port.link_config[1] =
  9362. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9363. bp->link_params.multi_phy_config =
  9364. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9365. /* If the device is capable of WoL, set the default state according
  9366. * to the HW
  9367. */
  9368. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9369. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9370. (config & PORT_FEATURE_WOL_ENABLED));
  9371. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9372. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9373. bp->flags |= NO_ISCSI_FLAG;
  9374. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9375. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9376. bp->flags |= NO_FCOE_FLAG;
  9377. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9378. bp->link_params.lane_config,
  9379. bp->link_params.speed_cap_mask[0],
  9380. bp->port.link_config[0]);
  9381. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9382. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9383. bnx2x_phy_probe(&bp->link_params);
  9384. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9385. bnx2x_link_settings_requested(bp);
  9386. /*
  9387. * If connected directly, work with the internal PHY, otherwise, work
  9388. * with the external PHY
  9389. */
  9390. ext_phy_config =
  9391. SHMEM_RD(bp,
  9392. dev_info.port_hw_config[port].external_phy_config);
  9393. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9394. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9395. bp->mdio.prtad = bp->port.phy_addr;
  9396. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9397. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9398. bp->mdio.prtad =
  9399. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9400. /* Configure link feature according to nvram value */
  9401. eee_mode = (((SHMEM_RD(bp, dev_info.
  9402. port_feature_config[port].eee_power_mode)) &
  9403. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9404. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9405. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9406. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9407. EEE_MODE_ENABLE_LPI |
  9408. EEE_MODE_OUTPUT_TIME;
  9409. } else {
  9410. bp->link_params.eee_mode = 0;
  9411. }
  9412. }
  9413. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9414. {
  9415. u32 no_flags = NO_ISCSI_FLAG;
  9416. int port = BP_PORT(bp);
  9417. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9418. drv_lic_key[port].max_iscsi_conn);
  9419. if (!CNIC_SUPPORT(bp)) {
  9420. bp->flags |= no_flags;
  9421. return;
  9422. }
  9423. /* Get the number of maximum allowed iSCSI connections */
  9424. bp->cnic_eth_dev.max_iscsi_conn =
  9425. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9426. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9427. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9428. bp->cnic_eth_dev.max_iscsi_conn);
  9429. /*
  9430. * If maximum allowed number of connections is zero -
  9431. * disable the feature.
  9432. */
  9433. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9434. bp->flags |= no_flags;
  9435. }
  9436. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9437. {
  9438. /* Port info */
  9439. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9440. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9441. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9442. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9443. /* Node info */
  9444. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9445. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9446. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9447. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9448. }
  9449. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9450. {
  9451. u8 count = 0;
  9452. if (IS_MF(bp)) {
  9453. u8 fid;
  9454. /* iterate over absolute function ids for this path: */
  9455. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9456. if (IS_MF_SD(bp)) {
  9457. u32 cfg = MF_CFG_RD(bp,
  9458. func_mf_config[fid].config);
  9459. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9460. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9461. FUNC_MF_CFG_PROTOCOL_FCOE))
  9462. count++;
  9463. } else {
  9464. u32 cfg = MF_CFG_RD(bp,
  9465. func_ext_config[fid].
  9466. func_cfg);
  9467. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9468. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9469. count++;
  9470. }
  9471. }
  9472. } else { /* SF */
  9473. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9474. for (port = 0; port < port_cnt; port++) {
  9475. u32 lic = SHMEM_RD(bp,
  9476. drv_lic_key[port].max_fcoe_conn) ^
  9477. FW_ENCODE_32BIT_PATTERN;
  9478. if (lic)
  9479. count++;
  9480. }
  9481. }
  9482. return count;
  9483. }
  9484. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9485. {
  9486. int port = BP_PORT(bp);
  9487. int func = BP_ABS_FUNC(bp);
  9488. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9489. drv_lic_key[port].max_fcoe_conn);
  9490. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9491. if (!CNIC_SUPPORT(bp)) {
  9492. bp->flags |= NO_FCOE_FLAG;
  9493. return;
  9494. }
  9495. /* Get the number of maximum allowed FCoE connections */
  9496. bp->cnic_eth_dev.max_fcoe_conn =
  9497. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9498. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9499. /* Calculate the number of maximum allowed FCoE tasks */
  9500. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9501. /* check if FCoE resources must be shared between different functions */
  9502. if (num_fcoe_func)
  9503. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9504. /* Read the WWN: */
  9505. if (!IS_MF(bp)) {
  9506. /* Port info */
  9507. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9508. SHMEM_RD(bp,
  9509. dev_info.port_hw_config[port].
  9510. fcoe_wwn_port_name_upper);
  9511. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9512. SHMEM_RD(bp,
  9513. dev_info.port_hw_config[port].
  9514. fcoe_wwn_port_name_lower);
  9515. /* Node info */
  9516. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9517. SHMEM_RD(bp,
  9518. dev_info.port_hw_config[port].
  9519. fcoe_wwn_node_name_upper);
  9520. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9521. SHMEM_RD(bp,
  9522. dev_info.port_hw_config[port].
  9523. fcoe_wwn_node_name_lower);
  9524. } else if (!IS_MF_SD(bp)) {
  9525. /*
  9526. * Read the WWN info only if the FCoE feature is enabled for
  9527. * this function.
  9528. */
  9529. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9530. bnx2x_get_ext_wwn_info(bp, func);
  9531. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9532. bnx2x_get_ext_wwn_info(bp, func);
  9533. }
  9534. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9535. /*
  9536. * If maximum allowed number of connections is zero -
  9537. * disable the feature.
  9538. */
  9539. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9540. bp->flags |= NO_FCOE_FLAG;
  9541. }
  9542. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9543. {
  9544. /*
  9545. * iSCSI may be dynamically disabled but reading
  9546. * info here we will decrease memory usage by driver
  9547. * if the feature is disabled for good
  9548. */
  9549. bnx2x_get_iscsi_info(bp);
  9550. bnx2x_get_fcoe_info(bp);
  9551. }
  9552. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9553. {
  9554. u32 val, val2;
  9555. int func = BP_ABS_FUNC(bp);
  9556. int port = BP_PORT(bp);
  9557. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9558. u8 *fip_mac = bp->fip_mac;
  9559. if (IS_MF(bp)) {
  9560. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9561. * FCoE MAC then the appropriate feature should be disabled.
  9562. * In non SD mode features configuration comes from struct
  9563. * func_ext_config.
  9564. */
  9565. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9566. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9567. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9568. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9569. iscsi_mac_addr_upper);
  9570. val = MF_CFG_RD(bp, func_ext_config[func].
  9571. iscsi_mac_addr_lower);
  9572. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9573. BNX2X_DEV_INFO
  9574. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9575. } else {
  9576. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9577. }
  9578. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9579. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9580. fcoe_mac_addr_upper);
  9581. val = MF_CFG_RD(bp, func_ext_config[func].
  9582. fcoe_mac_addr_lower);
  9583. bnx2x_set_mac_buf(fip_mac, val, val2);
  9584. BNX2X_DEV_INFO
  9585. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9586. } else {
  9587. bp->flags |= NO_FCOE_FLAG;
  9588. }
  9589. bp->mf_ext_config = cfg;
  9590. } else { /* SD MODE */
  9591. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9592. /* use primary mac as iscsi mac */
  9593. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9594. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9595. BNX2X_DEV_INFO
  9596. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9597. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9598. /* use primary mac as fip mac */
  9599. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9600. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9601. BNX2X_DEV_INFO
  9602. ("Read FIP MAC: %pM\n", fip_mac);
  9603. }
  9604. }
  9605. /* If this is a storage-only interface, use SAN mac as
  9606. * primary MAC. Notice that for SD this is already the case,
  9607. * as the SAN mac was copied from the primary MAC.
  9608. */
  9609. if (IS_MF_FCOE_AFEX(bp))
  9610. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9611. } else {
  9612. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9613. iscsi_mac_upper);
  9614. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9615. iscsi_mac_lower);
  9616. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9617. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9618. fcoe_fip_mac_upper);
  9619. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9620. fcoe_fip_mac_lower);
  9621. bnx2x_set_mac_buf(fip_mac, val, val2);
  9622. }
  9623. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9624. if (!is_valid_ether_addr(iscsi_mac)) {
  9625. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9626. memset(iscsi_mac, 0, ETH_ALEN);
  9627. }
  9628. /* Disable FCoE if MAC configuration is invalid. */
  9629. if (!is_valid_ether_addr(fip_mac)) {
  9630. bp->flags |= NO_FCOE_FLAG;
  9631. memset(bp->fip_mac, 0, ETH_ALEN);
  9632. }
  9633. }
  9634. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9635. {
  9636. u32 val, val2;
  9637. int func = BP_ABS_FUNC(bp);
  9638. int port = BP_PORT(bp);
  9639. /* Zero primary MAC configuration */
  9640. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9641. if (BP_NOMCP(bp)) {
  9642. BNX2X_ERROR("warning: random MAC workaround active\n");
  9643. eth_hw_addr_random(bp->dev);
  9644. } else if (IS_MF(bp)) {
  9645. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9646. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9647. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9648. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9649. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9650. if (CNIC_SUPPORT(bp))
  9651. bnx2x_get_cnic_mac_hwinfo(bp);
  9652. } else {
  9653. /* in SF read MACs from port configuration */
  9654. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9655. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9656. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9657. if (CNIC_SUPPORT(bp))
  9658. bnx2x_get_cnic_mac_hwinfo(bp);
  9659. }
  9660. if (!BP_NOMCP(bp)) {
  9661. /* Read physical port identifier from shmem */
  9662. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9663. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9664. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9665. bp->flags |= HAS_PHYS_PORT_ID;
  9666. }
  9667. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9668. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9669. dev_err(&bp->pdev->dev,
  9670. "bad Ethernet MAC address configuration: %pM\n"
  9671. "change it manually before bringing up the appropriate network interface\n",
  9672. bp->dev->dev_addr);
  9673. }
  9674. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9675. {
  9676. int tmp;
  9677. u32 cfg;
  9678. if (IS_VF(bp))
  9679. return 0;
  9680. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9681. /* Take function: tmp = func */
  9682. tmp = BP_ABS_FUNC(bp);
  9683. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9684. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9685. } else {
  9686. /* Take port: tmp = port */
  9687. tmp = BP_PORT(bp);
  9688. cfg = SHMEM_RD(bp,
  9689. dev_info.port_hw_config[tmp].generic_features);
  9690. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9691. }
  9692. return cfg;
  9693. }
  9694. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9695. {
  9696. int /*abs*/func = BP_ABS_FUNC(bp);
  9697. int vn;
  9698. u32 val = 0;
  9699. int rc = 0;
  9700. bnx2x_get_common_hwinfo(bp);
  9701. /*
  9702. * initialize IGU parameters
  9703. */
  9704. if (CHIP_IS_E1x(bp)) {
  9705. bp->common.int_block = INT_BLOCK_HC;
  9706. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9707. bp->igu_base_sb = 0;
  9708. } else {
  9709. bp->common.int_block = INT_BLOCK_IGU;
  9710. /* do not allow device reset during IGU info processing */
  9711. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9712. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9713. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9714. int tout = 5000;
  9715. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9716. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9717. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9718. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9719. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9720. tout--;
  9721. usleep_range(1000, 2000);
  9722. }
  9723. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9724. dev_err(&bp->pdev->dev,
  9725. "FORCING Normal Mode failed!!!\n");
  9726. bnx2x_release_hw_lock(bp,
  9727. HW_LOCK_RESOURCE_RESET);
  9728. return -EPERM;
  9729. }
  9730. }
  9731. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9732. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9733. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9734. } else
  9735. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9736. rc = bnx2x_get_igu_cam_info(bp);
  9737. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9738. if (rc)
  9739. return rc;
  9740. }
  9741. /*
  9742. * set base FW non-default (fast path) status block id, this value is
  9743. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9744. * determine the id used by the FW.
  9745. */
  9746. if (CHIP_IS_E1x(bp))
  9747. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9748. else /*
  9749. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9750. * the same queue are indicated on the same IGU SB). So we prefer
  9751. * FW and IGU SBs to be the same value.
  9752. */
  9753. bp->base_fw_ndsb = bp->igu_base_sb;
  9754. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9755. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9756. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9757. /*
  9758. * Initialize MF configuration
  9759. */
  9760. bp->mf_ov = 0;
  9761. bp->mf_mode = 0;
  9762. vn = BP_VN(bp);
  9763. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9764. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9765. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9766. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9767. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9768. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9769. else
  9770. bp->common.mf_cfg_base = bp->common.shmem_base +
  9771. offsetof(struct shmem_region, func_mb) +
  9772. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9773. /*
  9774. * get mf configuration:
  9775. * 1. Existence of MF configuration
  9776. * 2. MAC address must be legal (check only upper bytes)
  9777. * for Switch-Independent mode;
  9778. * OVLAN must be legal for Switch-Dependent mode
  9779. * 3. SF_MODE configures specific MF mode
  9780. */
  9781. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9782. /* get mf configuration */
  9783. val = SHMEM_RD(bp,
  9784. dev_info.shared_feature_config.config);
  9785. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9786. switch (val) {
  9787. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9788. val = MF_CFG_RD(bp, func_mf_config[func].
  9789. mac_upper);
  9790. /* check for legal mac (upper bytes)*/
  9791. if (val != 0xffff) {
  9792. bp->mf_mode = MULTI_FUNCTION_SI;
  9793. bp->mf_config[vn] = MF_CFG_RD(bp,
  9794. func_mf_config[func].config);
  9795. } else
  9796. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9797. break;
  9798. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9799. if ((!CHIP_IS_E1x(bp)) &&
  9800. (MF_CFG_RD(bp, func_mf_config[func].
  9801. mac_upper) != 0xffff) &&
  9802. (SHMEM2_HAS(bp,
  9803. afex_driver_support))) {
  9804. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9805. bp->mf_config[vn] = MF_CFG_RD(bp,
  9806. func_mf_config[func].config);
  9807. } else {
  9808. BNX2X_DEV_INFO("can not configure afex mode\n");
  9809. }
  9810. break;
  9811. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9812. /* get OV configuration */
  9813. val = MF_CFG_RD(bp,
  9814. func_mf_config[FUNC_0].e1hov_tag);
  9815. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9816. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9817. bp->mf_mode = MULTI_FUNCTION_SD;
  9818. bp->mf_config[vn] = MF_CFG_RD(bp,
  9819. func_mf_config[func].config);
  9820. } else
  9821. BNX2X_DEV_INFO("illegal OV for SD\n");
  9822. break;
  9823. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9824. bp->mf_config[vn] = 0;
  9825. break;
  9826. default:
  9827. /* Unknown configuration: reset mf_config */
  9828. bp->mf_config[vn] = 0;
  9829. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9830. }
  9831. }
  9832. BNX2X_DEV_INFO("%s function mode\n",
  9833. IS_MF(bp) ? "multi" : "single");
  9834. switch (bp->mf_mode) {
  9835. case MULTI_FUNCTION_SD:
  9836. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9837. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9838. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9839. bp->mf_ov = val;
  9840. bp->path_has_ovlan = true;
  9841. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9842. func, bp->mf_ov, bp->mf_ov);
  9843. } else {
  9844. dev_err(&bp->pdev->dev,
  9845. "No valid MF OV for func %d, aborting\n",
  9846. func);
  9847. return -EPERM;
  9848. }
  9849. break;
  9850. case MULTI_FUNCTION_AFEX:
  9851. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9852. break;
  9853. case MULTI_FUNCTION_SI:
  9854. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9855. func);
  9856. break;
  9857. default:
  9858. if (vn) {
  9859. dev_err(&bp->pdev->dev,
  9860. "VN %d is in a single function mode, aborting\n",
  9861. vn);
  9862. return -EPERM;
  9863. }
  9864. break;
  9865. }
  9866. /* check if other port on the path needs ovlan:
  9867. * Since MF configuration is shared between ports
  9868. * Possible mixed modes are only
  9869. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9870. */
  9871. if (CHIP_MODE_IS_4_PORT(bp) &&
  9872. !bp->path_has_ovlan &&
  9873. !IS_MF(bp) &&
  9874. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9875. u8 other_port = !BP_PORT(bp);
  9876. u8 other_func = BP_PATH(bp) + 2*other_port;
  9877. val = MF_CFG_RD(bp,
  9878. func_mf_config[other_func].e1hov_tag);
  9879. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9880. bp->path_has_ovlan = true;
  9881. }
  9882. }
  9883. /* adjust igu_sb_cnt to MF for E1H */
  9884. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  9885. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  9886. /* port info */
  9887. bnx2x_get_port_hwinfo(bp);
  9888. /* Get MAC addresses */
  9889. bnx2x_get_mac_hwinfo(bp);
  9890. bnx2x_get_cnic_info(bp);
  9891. return rc;
  9892. }
  9893. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9894. {
  9895. int cnt, i, block_end, rodi;
  9896. char vpd_start[BNX2X_VPD_LEN+1];
  9897. char str_id_reg[VENDOR_ID_LEN+1];
  9898. char str_id_cap[VENDOR_ID_LEN+1];
  9899. char *vpd_data;
  9900. char *vpd_extended_data = NULL;
  9901. u8 len;
  9902. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9903. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9904. if (cnt < BNX2X_VPD_LEN)
  9905. goto out_not_found;
  9906. /* VPD RO tag should be first tag after identifier string, hence
  9907. * we should be able to find it in first BNX2X_VPD_LEN chars
  9908. */
  9909. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9910. PCI_VPD_LRDT_RO_DATA);
  9911. if (i < 0)
  9912. goto out_not_found;
  9913. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9914. pci_vpd_lrdt_size(&vpd_start[i]);
  9915. i += PCI_VPD_LRDT_TAG_SIZE;
  9916. if (block_end > BNX2X_VPD_LEN) {
  9917. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9918. if (vpd_extended_data == NULL)
  9919. goto out_not_found;
  9920. /* read rest of vpd image into vpd_extended_data */
  9921. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9922. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9923. block_end - BNX2X_VPD_LEN,
  9924. vpd_extended_data + BNX2X_VPD_LEN);
  9925. if (cnt < (block_end - BNX2X_VPD_LEN))
  9926. goto out_not_found;
  9927. vpd_data = vpd_extended_data;
  9928. } else
  9929. vpd_data = vpd_start;
  9930. /* now vpd_data holds full vpd content in both cases */
  9931. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9932. PCI_VPD_RO_KEYWORD_MFR_ID);
  9933. if (rodi < 0)
  9934. goto out_not_found;
  9935. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9936. if (len != VENDOR_ID_LEN)
  9937. goto out_not_found;
  9938. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9939. /* vendor specific info */
  9940. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9941. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9942. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9943. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9944. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9945. PCI_VPD_RO_KEYWORD_VENDOR0);
  9946. if (rodi >= 0) {
  9947. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9948. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9949. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9950. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9951. bp->fw_ver[len] = ' ';
  9952. }
  9953. }
  9954. kfree(vpd_extended_data);
  9955. return;
  9956. }
  9957. out_not_found:
  9958. kfree(vpd_extended_data);
  9959. return;
  9960. }
  9961. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9962. {
  9963. u32 flags = 0;
  9964. if (CHIP_REV_IS_FPGA(bp))
  9965. SET_FLAGS(flags, MODE_FPGA);
  9966. else if (CHIP_REV_IS_EMUL(bp))
  9967. SET_FLAGS(flags, MODE_EMUL);
  9968. else
  9969. SET_FLAGS(flags, MODE_ASIC);
  9970. if (CHIP_MODE_IS_4_PORT(bp))
  9971. SET_FLAGS(flags, MODE_PORT4);
  9972. else
  9973. SET_FLAGS(flags, MODE_PORT2);
  9974. if (CHIP_IS_E2(bp))
  9975. SET_FLAGS(flags, MODE_E2);
  9976. else if (CHIP_IS_E3(bp)) {
  9977. SET_FLAGS(flags, MODE_E3);
  9978. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9979. SET_FLAGS(flags, MODE_E3_A0);
  9980. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9981. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9982. }
  9983. if (IS_MF(bp)) {
  9984. SET_FLAGS(flags, MODE_MF);
  9985. switch (bp->mf_mode) {
  9986. case MULTI_FUNCTION_SD:
  9987. SET_FLAGS(flags, MODE_MF_SD);
  9988. break;
  9989. case MULTI_FUNCTION_SI:
  9990. SET_FLAGS(flags, MODE_MF_SI);
  9991. break;
  9992. case MULTI_FUNCTION_AFEX:
  9993. SET_FLAGS(flags, MODE_MF_AFEX);
  9994. break;
  9995. }
  9996. } else
  9997. SET_FLAGS(flags, MODE_SF);
  9998. #if defined(__LITTLE_ENDIAN)
  9999. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10000. #else /*(__BIG_ENDIAN)*/
  10001. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10002. #endif
  10003. INIT_MODE_FLAGS(bp) = flags;
  10004. }
  10005. static int bnx2x_init_bp(struct bnx2x *bp)
  10006. {
  10007. int func;
  10008. int rc;
  10009. mutex_init(&bp->port.phy_mutex);
  10010. mutex_init(&bp->fw_mb_mutex);
  10011. mutex_init(&bp->drv_info_mutex);
  10012. bp->drv_info_mng_owner = false;
  10013. spin_lock_init(&bp->stats_lock);
  10014. sema_init(&bp->stats_sema, 1);
  10015. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10016. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10017. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10018. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10019. if (IS_PF(bp)) {
  10020. rc = bnx2x_get_hwinfo(bp);
  10021. if (rc)
  10022. return rc;
  10023. } else {
  10024. eth_zero_addr(bp->dev->dev_addr);
  10025. }
  10026. bnx2x_set_modes_bitmap(bp);
  10027. rc = bnx2x_alloc_mem_bp(bp);
  10028. if (rc)
  10029. return rc;
  10030. bnx2x_read_fwinfo(bp);
  10031. func = BP_FUNC(bp);
  10032. /* need to reset chip if undi was active */
  10033. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10034. /* init fw_seq */
  10035. bp->fw_seq =
  10036. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10037. DRV_MSG_SEQ_NUMBER_MASK;
  10038. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10039. rc = bnx2x_prev_unload(bp);
  10040. if (rc) {
  10041. bnx2x_free_mem_bp(bp);
  10042. return rc;
  10043. }
  10044. }
  10045. if (CHIP_REV_IS_FPGA(bp))
  10046. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10047. if (BP_NOMCP(bp) && (func == 0))
  10048. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10049. bp->disable_tpa = disable_tpa;
  10050. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  10051. /* Reduce memory usage in kdump environment by disabling TPA */
  10052. bp->disable_tpa |= reset_devices;
  10053. /* Set TPA flags */
  10054. if (bp->disable_tpa) {
  10055. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10056. bp->dev->features &= ~NETIF_F_LRO;
  10057. } else {
  10058. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10059. bp->dev->features |= NETIF_F_LRO;
  10060. }
  10061. if (CHIP_IS_E1(bp))
  10062. bp->dropless_fc = 0;
  10063. else
  10064. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10065. bp->mrrs = mrrs;
  10066. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  10067. if (IS_VF(bp))
  10068. bp->rx_ring_size = MAX_RX_AVAIL;
  10069. /* make sure that the numbers are in the right granularity */
  10070. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10071. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10072. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10073. init_timer(&bp->timer);
  10074. bp->timer.expires = jiffies + bp->current_interval;
  10075. bp->timer.data = (unsigned long) bp;
  10076. bp->timer.function = bnx2x_timer;
  10077. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10078. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10079. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10080. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10081. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10082. bnx2x_dcbx_init_params(bp);
  10083. } else {
  10084. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10085. }
  10086. if (CHIP_IS_E1x(bp))
  10087. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10088. else
  10089. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10090. /* multiple tx priority */
  10091. if (IS_VF(bp))
  10092. bp->max_cos = 1;
  10093. else if (CHIP_IS_E1x(bp))
  10094. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10095. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10096. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10097. else if (CHIP_IS_E3B0(bp))
  10098. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10099. else
  10100. BNX2X_ERR("unknown chip %x revision %x\n",
  10101. CHIP_NUM(bp), CHIP_REV(bp));
  10102. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10103. /* We need at least one default status block for slow-path events,
  10104. * second status block for the L2 queue, and a third status block for
  10105. * CNIC if supported.
  10106. */
  10107. if (IS_VF(bp))
  10108. bp->min_msix_vec_cnt = 1;
  10109. else if (CNIC_SUPPORT(bp))
  10110. bp->min_msix_vec_cnt = 3;
  10111. else /* PF w/o cnic */
  10112. bp->min_msix_vec_cnt = 2;
  10113. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10114. bp->dump_preset_idx = 1;
  10115. return rc;
  10116. }
  10117. /****************************************************************************
  10118. * General service functions
  10119. ****************************************************************************/
  10120. /*
  10121. * net_device service functions
  10122. */
  10123. /* called with rtnl_lock */
  10124. static int bnx2x_open(struct net_device *dev)
  10125. {
  10126. struct bnx2x *bp = netdev_priv(dev);
  10127. int rc;
  10128. bp->stats_init = true;
  10129. netif_carrier_off(dev);
  10130. bnx2x_set_power_state(bp, PCI_D0);
  10131. /* If parity had happen during the unload, then attentions
  10132. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10133. * want the first function loaded on the current engine to
  10134. * complete the recovery.
  10135. * Parity recovery is only relevant for PF driver.
  10136. */
  10137. if (IS_PF(bp)) {
  10138. int other_engine = BP_PATH(bp) ? 0 : 1;
  10139. bool other_load_status, load_status;
  10140. bool global = false;
  10141. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10142. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10143. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10144. bnx2x_chk_parity_attn(bp, &global, true)) {
  10145. do {
  10146. /* If there are attentions and they are in a
  10147. * global blocks, set the GLOBAL_RESET bit
  10148. * regardless whether it will be this function
  10149. * that will complete the recovery or not.
  10150. */
  10151. if (global)
  10152. bnx2x_set_reset_global(bp);
  10153. /* Only the first function on the current
  10154. * engine should try to recover in open. In case
  10155. * of attentions in global blocks only the first
  10156. * in the chip should try to recover.
  10157. */
  10158. if ((!load_status &&
  10159. (!global || !other_load_status)) &&
  10160. bnx2x_trylock_leader_lock(bp) &&
  10161. !bnx2x_leader_reset(bp)) {
  10162. netdev_info(bp->dev,
  10163. "Recovered in open\n");
  10164. break;
  10165. }
  10166. /* recovery has failed... */
  10167. bnx2x_set_power_state(bp, PCI_D3hot);
  10168. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10169. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10170. "If you still see this message after a few retries then power cycle is required.\n");
  10171. return -EAGAIN;
  10172. } while (0);
  10173. }
  10174. }
  10175. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10176. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10177. if (rc)
  10178. return rc;
  10179. return 0;
  10180. }
  10181. /* called with rtnl_lock */
  10182. static int bnx2x_close(struct net_device *dev)
  10183. {
  10184. struct bnx2x *bp = netdev_priv(dev);
  10185. /* Unload the driver, release IRQs */
  10186. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10187. return 0;
  10188. }
  10189. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10190. struct bnx2x_mcast_ramrod_params *p)
  10191. {
  10192. int mc_count = netdev_mc_count(bp->dev);
  10193. struct bnx2x_mcast_list_elem *mc_mac =
  10194. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10195. struct netdev_hw_addr *ha;
  10196. if (!mc_mac)
  10197. return -ENOMEM;
  10198. INIT_LIST_HEAD(&p->mcast_list);
  10199. netdev_for_each_mc_addr(ha, bp->dev) {
  10200. mc_mac->mac = bnx2x_mc_addr(ha);
  10201. list_add_tail(&mc_mac->link, &p->mcast_list);
  10202. mc_mac++;
  10203. }
  10204. p->mcast_list_len = mc_count;
  10205. return 0;
  10206. }
  10207. static void bnx2x_free_mcast_macs_list(
  10208. struct bnx2x_mcast_ramrod_params *p)
  10209. {
  10210. struct bnx2x_mcast_list_elem *mc_mac =
  10211. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10212. link);
  10213. WARN_ON(!mc_mac);
  10214. kfree(mc_mac);
  10215. }
  10216. /**
  10217. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10218. *
  10219. * @bp: driver handle
  10220. *
  10221. * We will use zero (0) as a MAC type for these MACs.
  10222. */
  10223. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10224. {
  10225. int rc;
  10226. struct net_device *dev = bp->dev;
  10227. struct netdev_hw_addr *ha;
  10228. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10229. unsigned long ramrod_flags = 0;
  10230. /* First schedule a cleanup up of old configuration */
  10231. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10232. if (rc < 0) {
  10233. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10234. return rc;
  10235. }
  10236. netdev_for_each_uc_addr(ha, dev) {
  10237. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10238. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10239. if (rc == -EEXIST) {
  10240. DP(BNX2X_MSG_SP,
  10241. "Failed to schedule ADD operations: %d\n", rc);
  10242. /* do not treat adding same MAC as error */
  10243. rc = 0;
  10244. } else if (rc < 0) {
  10245. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10246. rc);
  10247. return rc;
  10248. }
  10249. }
  10250. /* Execute the pending commands */
  10251. __set_bit(RAMROD_CONT, &ramrod_flags);
  10252. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10253. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10254. }
  10255. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10256. {
  10257. struct net_device *dev = bp->dev;
  10258. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10259. int rc = 0;
  10260. rparam.mcast_obj = &bp->mcast_obj;
  10261. /* first, clear all configured multicast MACs */
  10262. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10263. if (rc < 0) {
  10264. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10265. return rc;
  10266. }
  10267. /* then, configure a new MACs list */
  10268. if (netdev_mc_count(dev)) {
  10269. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10270. if (rc) {
  10271. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10272. rc);
  10273. return rc;
  10274. }
  10275. /* Now add the new MACs */
  10276. rc = bnx2x_config_mcast(bp, &rparam,
  10277. BNX2X_MCAST_CMD_ADD);
  10278. if (rc < 0)
  10279. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10280. rc);
  10281. bnx2x_free_mcast_macs_list(&rparam);
  10282. }
  10283. return rc;
  10284. }
  10285. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10286. static void bnx2x_set_rx_mode(struct net_device *dev)
  10287. {
  10288. struct bnx2x *bp = netdev_priv(dev);
  10289. if (bp->state != BNX2X_STATE_OPEN) {
  10290. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10291. return;
  10292. } else {
  10293. /* Schedule an SP task to handle rest of change */
  10294. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10295. NETIF_MSG_IFUP);
  10296. }
  10297. }
  10298. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10299. {
  10300. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10301. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10302. netif_addr_lock_bh(bp->dev);
  10303. if (bp->dev->flags & IFF_PROMISC) {
  10304. rx_mode = BNX2X_RX_MODE_PROMISC;
  10305. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10306. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10307. CHIP_IS_E1(bp))) {
  10308. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10309. } else {
  10310. if (IS_PF(bp)) {
  10311. /* some multicasts */
  10312. if (bnx2x_set_mc_list(bp) < 0)
  10313. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10314. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10315. netif_addr_unlock_bh(bp->dev);
  10316. if (bnx2x_set_uc_list(bp) < 0)
  10317. rx_mode = BNX2X_RX_MODE_PROMISC;
  10318. netif_addr_lock_bh(bp->dev);
  10319. } else {
  10320. /* configuring mcast to a vf involves sleeping (when we
  10321. * wait for the pf's response).
  10322. */
  10323. bnx2x_schedule_sp_rtnl(bp,
  10324. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10325. }
  10326. }
  10327. bp->rx_mode = rx_mode;
  10328. /* handle ISCSI SD mode */
  10329. if (IS_MF_ISCSI_SD(bp))
  10330. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10331. /* Schedule the rx_mode command */
  10332. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10333. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10334. netif_addr_unlock_bh(bp->dev);
  10335. return;
  10336. }
  10337. if (IS_PF(bp)) {
  10338. bnx2x_set_storm_rx_mode(bp);
  10339. netif_addr_unlock_bh(bp->dev);
  10340. } else {
  10341. /* VF will need to request the PF to make this change, and so
  10342. * the VF needs to release the bottom-half lock prior to the
  10343. * request (as it will likely require sleep on the VF side)
  10344. */
  10345. netif_addr_unlock_bh(bp->dev);
  10346. bnx2x_vfpf_storm_rx_mode(bp);
  10347. }
  10348. }
  10349. /* called with rtnl_lock */
  10350. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10351. int devad, u16 addr)
  10352. {
  10353. struct bnx2x *bp = netdev_priv(netdev);
  10354. u16 value;
  10355. int rc;
  10356. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10357. prtad, devad, addr);
  10358. /* The HW expects different devad if CL22 is used */
  10359. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10360. bnx2x_acquire_phy_lock(bp);
  10361. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10362. bnx2x_release_phy_lock(bp);
  10363. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10364. if (!rc)
  10365. rc = value;
  10366. return rc;
  10367. }
  10368. /* called with rtnl_lock */
  10369. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10370. u16 addr, u16 value)
  10371. {
  10372. struct bnx2x *bp = netdev_priv(netdev);
  10373. int rc;
  10374. DP(NETIF_MSG_LINK,
  10375. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10376. prtad, devad, addr, value);
  10377. /* The HW expects different devad if CL22 is used */
  10378. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10379. bnx2x_acquire_phy_lock(bp);
  10380. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10381. bnx2x_release_phy_lock(bp);
  10382. return rc;
  10383. }
  10384. /* called with rtnl_lock */
  10385. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10386. {
  10387. struct bnx2x *bp = netdev_priv(dev);
  10388. struct mii_ioctl_data *mdio = if_mii(ifr);
  10389. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10390. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10391. if (!netif_running(dev))
  10392. return -EAGAIN;
  10393. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10394. }
  10395. #ifdef CONFIG_NET_POLL_CONTROLLER
  10396. static void poll_bnx2x(struct net_device *dev)
  10397. {
  10398. struct bnx2x *bp = netdev_priv(dev);
  10399. int i;
  10400. for_each_eth_queue(bp, i) {
  10401. struct bnx2x_fastpath *fp = &bp->fp[i];
  10402. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10403. }
  10404. }
  10405. #endif
  10406. static int bnx2x_validate_addr(struct net_device *dev)
  10407. {
  10408. struct bnx2x *bp = netdev_priv(dev);
  10409. /* query the bulletin board for mac address configured by the PF */
  10410. if (IS_VF(bp))
  10411. bnx2x_sample_bulletin(bp);
  10412. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10413. BNX2X_ERR("Non-valid Ethernet address\n");
  10414. return -EADDRNOTAVAIL;
  10415. }
  10416. return 0;
  10417. }
  10418. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10419. struct netdev_phys_port_id *ppid)
  10420. {
  10421. struct bnx2x *bp = netdev_priv(netdev);
  10422. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10423. return -EOPNOTSUPP;
  10424. ppid->id_len = sizeof(bp->phys_port_id);
  10425. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10426. return 0;
  10427. }
  10428. static const struct net_device_ops bnx2x_netdev_ops = {
  10429. .ndo_open = bnx2x_open,
  10430. .ndo_stop = bnx2x_close,
  10431. .ndo_start_xmit = bnx2x_start_xmit,
  10432. .ndo_select_queue = bnx2x_select_queue,
  10433. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10434. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10435. .ndo_validate_addr = bnx2x_validate_addr,
  10436. .ndo_do_ioctl = bnx2x_ioctl,
  10437. .ndo_change_mtu = bnx2x_change_mtu,
  10438. .ndo_fix_features = bnx2x_fix_features,
  10439. .ndo_set_features = bnx2x_set_features,
  10440. .ndo_tx_timeout = bnx2x_tx_timeout,
  10441. #ifdef CONFIG_NET_POLL_CONTROLLER
  10442. .ndo_poll_controller = poll_bnx2x,
  10443. #endif
  10444. .ndo_setup_tc = bnx2x_setup_tc,
  10445. #ifdef CONFIG_BNX2X_SRIOV
  10446. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10447. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10448. .ndo_get_vf_config = bnx2x_get_vf_config,
  10449. #endif
  10450. #ifdef NETDEV_FCOE_WWNN
  10451. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10452. #endif
  10453. #ifdef CONFIG_NET_RX_BUSY_POLL
  10454. .ndo_busy_poll = bnx2x_low_latency_recv,
  10455. #endif
  10456. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10457. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10458. };
  10459. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10460. {
  10461. struct device *dev = &bp->pdev->dev;
  10462. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10463. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10464. dev_err(dev, "System does not support DMA, aborting\n");
  10465. return -EIO;
  10466. }
  10467. return 0;
  10468. }
  10469. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10470. {
  10471. if (bp->flags & AER_ENABLED) {
  10472. pci_disable_pcie_error_reporting(bp->pdev);
  10473. bp->flags &= ~AER_ENABLED;
  10474. }
  10475. }
  10476. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10477. struct net_device *dev, unsigned long board_type)
  10478. {
  10479. int rc;
  10480. u32 pci_cfg_dword;
  10481. bool chip_is_e1x = (board_type == BCM57710 ||
  10482. board_type == BCM57711 ||
  10483. board_type == BCM57711E);
  10484. SET_NETDEV_DEV(dev, &pdev->dev);
  10485. bp->dev = dev;
  10486. bp->pdev = pdev;
  10487. rc = pci_enable_device(pdev);
  10488. if (rc) {
  10489. dev_err(&bp->pdev->dev,
  10490. "Cannot enable PCI device, aborting\n");
  10491. goto err_out;
  10492. }
  10493. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10494. dev_err(&bp->pdev->dev,
  10495. "Cannot find PCI device base address, aborting\n");
  10496. rc = -ENODEV;
  10497. goto err_out_disable;
  10498. }
  10499. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10500. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10501. rc = -ENODEV;
  10502. goto err_out_disable;
  10503. }
  10504. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10505. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10506. PCICFG_REVESION_ID_ERROR_VAL) {
  10507. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10508. rc = -ENODEV;
  10509. goto err_out_disable;
  10510. }
  10511. if (atomic_read(&pdev->enable_cnt) == 1) {
  10512. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10513. if (rc) {
  10514. dev_err(&bp->pdev->dev,
  10515. "Cannot obtain PCI resources, aborting\n");
  10516. goto err_out_disable;
  10517. }
  10518. pci_set_master(pdev);
  10519. pci_save_state(pdev);
  10520. }
  10521. if (IS_PF(bp)) {
  10522. if (!pdev->pm_cap) {
  10523. dev_err(&bp->pdev->dev,
  10524. "Cannot find power management capability, aborting\n");
  10525. rc = -EIO;
  10526. goto err_out_release;
  10527. }
  10528. }
  10529. if (!pci_is_pcie(pdev)) {
  10530. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10531. rc = -EIO;
  10532. goto err_out_release;
  10533. }
  10534. rc = bnx2x_set_coherency_mask(bp);
  10535. if (rc)
  10536. goto err_out_release;
  10537. dev->mem_start = pci_resource_start(pdev, 0);
  10538. dev->base_addr = dev->mem_start;
  10539. dev->mem_end = pci_resource_end(pdev, 0);
  10540. dev->irq = pdev->irq;
  10541. bp->regview = pci_ioremap_bar(pdev, 0);
  10542. if (!bp->regview) {
  10543. dev_err(&bp->pdev->dev,
  10544. "Cannot map register space, aborting\n");
  10545. rc = -ENOMEM;
  10546. goto err_out_release;
  10547. }
  10548. /* In E1/E1H use pci device function given by kernel.
  10549. * In E2/E3 read physical function from ME register since these chips
  10550. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10551. * (depending on hypervisor).
  10552. */
  10553. if (chip_is_e1x) {
  10554. bp->pf_num = PCI_FUNC(pdev->devfn);
  10555. } else {
  10556. /* chip is E2/3*/
  10557. pci_read_config_dword(bp->pdev,
  10558. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10559. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10560. ME_REG_ABS_PF_NUM_SHIFT);
  10561. }
  10562. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10563. /* clean indirect addresses */
  10564. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10565. PCICFG_VENDOR_ID_OFFSET);
  10566. /* AER (Advanced Error reporting) configuration */
  10567. rc = pci_enable_pcie_error_reporting(pdev);
  10568. if (!rc)
  10569. bp->flags |= AER_ENABLED;
  10570. else
  10571. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10572. /*
  10573. * Clean the following indirect addresses for all functions since it
  10574. * is not used by the driver.
  10575. */
  10576. if (IS_PF(bp)) {
  10577. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10578. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10579. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10580. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10581. if (chip_is_e1x) {
  10582. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10583. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10584. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10585. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10586. }
  10587. /* Enable internal target-read (in case we are probed after PF
  10588. * FLR). Must be done prior to any BAR read access. Only for
  10589. * 57712 and up
  10590. */
  10591. if (!chip_is_e1x)
  10592. REG_WR(bp,
  10593. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10594. }
  10595. dev->watchdog_timeo = TX_TIMEOUT;
  10596. dev->netdev_ops = &bnx2x_netdev_ops;
  10597. bnx2x_set_ethtool_ops(bp, dev);
  10598. dev->priv_flags |= IFF_UNICAST_FLT;
  10599. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10600. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10601. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10602. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10603. if (!CHIP_IS_E1x(bp)) {
  10604. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10605. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10606. dev->hw_enc_features =
  10607. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10608. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10609. NETIF_F_GSO_IPIP |
  10610. NETIF_F_GSO_SIT |
  10611. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10612. }
  10613. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10614. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10615. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10616. dev->features |= NETIF_F_HIGHDMA;
  10617. /* Add Loopback capability to the device */
  10618. dev->hw_features |= NETIF_F_LOOPBACK;
  10619. #ifdef BCM_DCBNL
  10620. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10621. #endif
  10622. /* get_port_hwinfo() will set prtad and mmds properly */
  10623. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10624. bp->mdio.mmds = 0;
  10625. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10626. bp->mdio.dev = dev;
  10627. bp->mdio.mdio_read = bnx2x_mdio_read;
  10628. bp->mdio.mdio_write = bnx2x_mdio_write;
  10629. return 0;
  10630. err_out_release:
  10631. if (atomic_read(&pdev->enable_cnt) == 1)
  10632. pci_release_regions(pdev);
  10633. err_out_disable:
  10634. pci_disable_device(pdev);
  10635. err_out:
  10636. return rc;
  10637. }
  10638. static int bnx2x_check_firmware(struct bnx2x *bp)
  10639. {
  10640. const struct firmware *firmware = bp->firmware;
  10641. struct bnx2x_fw_file_hdr *fw_hdr;
  10642. struct bnx2x_fw_file_section *sections;
  10643. u32 offset, len, num_ops;
  10644. __be16 *ops_offsets;
  10645. int i;
  10646. const u8 *fw_ver;
  10647. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10648. BNX2X_ERR("Wrong FW size\n");
  10649. return -EINVAL;
  10650. }
  10651. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10652. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10653. /* Make sure none of the offsets and sizes make us read beyond
  10654. * the end of the firmware data */
  10655. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10656. offset = be32_to_cpu(sections[i].offset);
  10657. len = be32_to_cpu(sections[i].len);
  10658. if (offset + len > firmware->size) {
  10659. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10660. return -EINVAL;
  10661. }
  10662. }
  10663. /* Likewise for the init_ops offsets */
  10664. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10665. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10666. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10667. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10668. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10669. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10670. return -EINVAL;
  10671. }
  10672. }
  10673. /* Check FW version */
  10674. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10675. fw_ver = firmware->data + offset;
  10676. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10677. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10678. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10679. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10680. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10681. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10682. BCM_5710_FW_MAJOR_VERSION,
  10683. BCM_5710_FW_MINOR_VERSION,
  10684. BCM_5710_FW_REVISION_VERSION,
  10685. BCM_5710_FW_ENGINEERING_VERSION);
  10686. return -EINVAL;
  10687. }
  10688. return 0;
  10689. }
  10690. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10691. {
  10692. const __be32 *source = (const __be32 *)_source;
  10693. u32 *target = (u32 *)_target;
  10694. u32 i;
  10695. for (i = 0; i < n/4; i++)
  10696. target[i] = be32_to_cpu(source[i]);
  10697. }
  10698. /*
  10699. Ops array is stored in the following format:
  10700. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10701. */
  10702. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10703. {
  10704. const __be32 *source = (const __be32 *)_source;
  10705. struct raw_op *target = (struct raw_op *)_target;
  10706. u32 i, j, tmp;
  10707. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10708. tmp = be32_to_cpu(source[j]);
  10709. target[i].op = (tmp >> 24) & 0xff;
  10710. target[i].offset = tmp & 0xffffff;
  10711. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10712. }
  10713. }
  10714. /* IRO array is stored in the following format:
  10715. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10716. */
  10717. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10718. {
  10719. const __be32 *source = (const __be32 *)_source;
  10720. struct iro *target = (struct iro *)_target;
  10721. u32 i, j, tmp;
  10722. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10723. target[i].base = be32_to_cpu(source[j]);
  10724. j++;
  10725. tmp = be32_to_cpu(source[j]);
  10726. target[i].m1 = (tmp >> 16) & 0xffff;
  10727. target[i].m2 = tmp & 0xffff;
  10728. j++;
  10729. tmp = be32_to_cpu(source[j]);
  10730. target[i].m3 = (tmp >> 16) & 0xffff;
  10731. target[i].size = tmp & 0xffff;
  10732. j++;
  10733. }
  10734. }
  10735. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10736. {
  10737. const __be16 *source = (const __be16 *)_source;
  10738. u16 *target = (u16 *)_target;
  10739. u32 i;
  10740. for (i = 0; i < n/2; i++)
  10741. target[i] = be16_to_cpu(source[i]);
  10742. }
  10743. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10744. do { \
  10745. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10746. bp->arr = kmalloc(len, GFP_KERNEL); \
  10747. if (!bp->arr) \
  10748. goto lbl; \
  10749. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10750. (u8 *)bp->arr, len); \
  10751. } while (0)
  10752. static int bnx2x_init_firmware(struct bnx2x *bp)
  10753. {
  10754. const char *fw_file_name;
  10755. struct bnx2x_fw_file_hdr *fw_hdr;
  10756. int rc;
  10757. if (bp->firmware)
  10758. return 0;
  10759. if (CHIP_IS_E1(bp))
  10760. fw_file_name = FW_FILE_NAME_E1;
  10761. else if (CHIP_IS_E1H(bp))
  10762. fw_file_name = FW_FILE_NAME_E1H;
  10763. else if (!CHIP_IS_E1x(bp))
  10764. fw_file_name = FW_FILE_NAME_E2;
  10765. else {
  10766. BNX2X_ERR("Unsupported chip revision\n");
  10767. return -EINVAL;
  10768. }
  10769. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10770. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10771. if (rc) {
  10772. BNX2X_ERR("Can't load firmware file %s\n",
  10773. fw_file_name);
  10774. goto request_firmware_exit;
  10775. }
  10776. rc = bnx2x_check_firmware(bp);
  10777. if (rc) {
  10778. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10779. goto request_firmware_exit;
  10780. }
  10781. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10782. /* Initialize the pointers to the init arrays */
  10783. /* Blob */
  10784. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10785. /* Opcodes */
  10786. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10787. /* Offsets */
  10788. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10789. be16_to_cpu_n);
  10790. /* STORMs firmware */
  10791. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10792. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10793. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10794. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10795. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10796. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10797. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10798. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10799. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10800. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10801. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10802. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10803. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10804. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10805. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10806. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10807. /* IRO */
  10808. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10809. return 0;
  10810. iro_alloc_err:
  10811. kfree(bp->init_ops_offsets);
  10812. init_offsets_alloc_err:
  10813. kfree(bp->init_ops);
  10814. init_ops_alloc_err:
  10815. kfree(bp->init_data);
  10816. request_firmware_exit:
  10817. release_firmware(bp->firmware);
  10818. bp->firmware = NULL;
  10819. return rc;
  10820. }
  10821. static void bnx2x_release_firmware(struct bnx2x *bp)
  10822. {
  10823. kfree(bp->init_ops_offsets);
  10824. kfree(bp->init_ops);
  10825. kfree(bp->init_data);
  10826. release_firmware(bp->firmware);
  10827. bp->firmware = NULL;
  10828. }
  10829. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10830. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10831. .init_hw_cmn = bnx2x_init_hw_common,
  10832. .init_hw_port = bnx2x_init_hw_port,
  10833. .init_hw_func = bnx2x_init_hw_func,
  10834. .reset_hw_cmn = bnx2x_reset_common,
  10835. .reset_hw_port = bnx2x_reset_port,
  10836. .reset_hw_func = bnx2x_reset_func,
  10837. .gunzip_init = bnx2x_gunzip_init,
  10838. .gunzip_end = bnx2x_gunzip_end,
  10839. .init_fw = bnx2x_init_firmware,
  10840. .release_fw = bnx2x_release_firmware,
  10841. };
  10842. void bnx2x__init_func_obj(struct bnx2x *bp)
  10843. {
  10844. /* Prepare DMAE related driver resources */
  10845. bnx2x_setup_dmae(bp);
  10846. bnx2x_init_func_obj(bp, &bp->func_obj,
  10847. bnx2x_sp(bp, func_rdata),
  10848. bnx2x_sp_mapping(bp, func_rdata),
  10849. bnx2x_sp(bp, func_afex_rdata),
  10850. bnx2x_sp_mapping(bp, func_afex_rdata),
  10851. &bnx2x_func_sp_drv);
  10852. }
  10853. /* must be called after sriov-enable */
  10854. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10855. {
  10856. int cid_count = BNX2X_L2_MAX_CID(bp);
  10857. if (IS_SRIOV(bp))
  10858. cid_count += BNX2X_VF_CIDS;
  10859. if (CNIC_SUPPORT(bp))
  10860. cid_count += CNIC_CID_MAX;
  10861. return roundup(cid_count, QM_CID_ROUND);
  10862. }
  10863. /**
  10864. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10865. *
  10866. * @dev: pci device
  10867. *
  10868. */
  10869. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10870. {
  10871. int index;
  10872. u16 control = 0;
  10873. /*
  10874. * If MSI-X is not supported - return number of SBs needed to support
  10875. * one fast path queue: one FP queue + SB for CNIC
  10876. */
  10877. if (!pdev->msix_cap) {
  10878. dev_info(&pdev->dev, "no msix capability found\n");
  10879. return 1 + cnic_cnt;
  10880. }
  10881. dev_info(&pdev->dev, "msix capability found\n");
  10882. /*
  10883. * The value in the PCI configuration space is the index of the last
  10884. * entry, namely one less than the actual size of the table, which is
  10885. * exactly what we want to return from this function: number of all SBs
  10886. * without the default SB.
  10887. * For VFs there is no default SB, then we return (index+1).
  10888. */
  10889. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  10890. index = control & PCI_MSIX_FLAGS_QSIZE;
  10891. return index;
  10892. }
  10893. static int set_max_cos_est(int chip_id)
  10894. {
  10895. switch (chip_id) {
  10896. case BCM57710:
  10897. case BCM57711:
  10898. case BCM57711E:
  10899. return BNX2X_MULTI_TX_COS_E1X;
  10900. case BCM57712:
  10901. case BCM57712_MF:
  10902. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10903. case BCM57800:
  10904. case BCM57800_MF:
  10905. case BCM57810:
  10906. case BCM57810_MF:
  10907. case BCM57840_4_10:
  10908. case BCM57840_2_20:
  10909. case BCM57840_O:
  10910. case BCM57840_MFO:
  10911. case BCM57840_MF:
  10912. case BCM57811:
  10913. case BCM57811_MF:
  10914. return BNX2X_MULTI_TX_COS_E3B0;
  10915. case BCM57712_VF:
  10916. case BCM57800_VF:
  10917. case BCM57810_VF:
  10918. case BCM57840_VF:
  10919. case BCM57811_VF:
  10920. return 1;
  10921. default:
  10922. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10923. return -ENODEV;
  10924. }
  10925. }
  10926. static int set_is_vf(int chip_id)
  10927. {
  10928. switch (chip_id) {
  10929. case BCM57712_VF:
  10930. case BCM57800_VF:
  10931. case BCM57810_VF:
  10932. case BCM57840_VF:
  10933. case BCM57811_VF:
  10934. return true;
  10935. default:
  10936. return false;
  10937. }
  10938. }
  10939. static int bnx2x_init_one(struct pci_dev *pdev,
  10940. const struct pci_device_id *ent)
  10941. {
  10942. struct net_device *dev = NULL;
  10943. struct bnx2x *bp;
  10944. enum pcie_link_width pcie_width;
  10945. enum pci_bus_speed pcie_speed;
  10946. int rc, max_non_def_sbs;
  10947. int rx_count, tx_count, rss_count, doorbell_size;
  10948. int max_cos_est;
  10949. bool is_vf;
  10950. int cnic_cnt;
  10951. /* An estimated maximum supported CoS number according to the chip
  10952. * version.
  10953. * We will try to roughly estimate the maximum number of CoSes this chip
  10954. * may support in order to minimize the memory allocated for Tx
  10955. * netdev_queue's. This number will be accurately calculated during the
  10956. * initialization of bp->max_cos based on the chip versions AND chip
  10957. * revision in the bnx2x_init_bp().
  10958. */
  10959. max_cos_est = set_max_cos_est(ent->driver_data);
  10960. if (max_cos_est < 0)
  10961. return max_cos_est;
  10962. is_vf = set_is_vf(ent->driver_data);
  10963. cnic_cnt = is_vf ? 0 : 1;
  10964. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10965. /* add another SB for VF as it has no default SB */
  10966. max_non_def_sbs += is_vf ? 1 : 0;
  10967. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10968. rss_count = max_non_def_sbs - cnic_cnt;
  10969. if (rss_count < 1)
  10970. return -EINVAL;
  10971. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10972. rx_count = rss_count + cnic_cnt;
  10973. /* Maximum number of netdev Tx queues:
  10974. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10975. */
  10976. tx_count = rss_count * max_cos_est + cnic_cnt;
  10977. /* dev zeroed in init_etherdev */
  10978. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10979. if (!dev)
  10980. return -ENOMEM;
  10981. bp = netdev_priv(dev);
  10982. bp->flags = 0;
  10983. if (is_vf)
  10984. bp->flags |= IS_VF_FLAG;
  10985. bp->igu_sb_cnt = max_non_def_sbs;
  10986. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10987. bp->msg_enable = debug;
  10988. bp->cnic_support = cnic_cnt;
  10989. bp->cnic_probe = bnx2x_cnic_probe;
  10990. pci_set_drvdata(pdev, dev);
  10991. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10992. if (rc < 0) {
  10993. free_netdev(dev);
  10994. return rc;
  10995. }
  10996. BNX2X_DEV_INFO("This is a %s function\n",
  10997. IS_PF(bp) ? "physical" : "virtual");
  10998. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10999. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11000. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11001. tx_count, rx_count);
  11002. rc = bnx2x_init_bp(bp);
  11003. if (rc)
  11004. goto init_one_exit;
  11005. /* Map doorbells here as we need the real value of bp->max_cos which
  11006. * is initialized in bnx2x_init_bp() to determine the number of
  11007. * l2 connections.
  11008. */
  11009. if (IS_VF(bp)) {
  11010. bp->doorbells = bnx2x_vf_doorbells(bp);
  11011. rc = bnx2x_vf_pci_alloc(bp);
  11012. if (rc)
  11013. goto init_one_exit;
  11014. } else {
  11015. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11016. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11017. dev_err(&bp->pdev->dev,
  11018. "Cannot map doorbells, bar size too small, aborting\n");
  11019. rc = -ENOMEM;
  11020. goto init_one_exit;
  11021. }
  11022. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11023. doorbell_size);
  11024. }
  11025. if (!bp->doorbells) {
  11026. dev_err(&bp->pdev->dev,
  11027. "Cannot map doorbell space, aborting\n");
  11028. rc = -ENOMEM;
  11029. goto init_one_exit;
  11030. }
  11031. if (IS_VF(bp)) {
  11032. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11033. if (rc)
  11034. goto init_one_exit;
  11035. }
  11036. /* Enable SRIOV if capability found in configuration space */
  11037. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11038. if (rc)
  11039. goto init_one_exit;
  11040. /* calc qm_cid_count */
  11041. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11042. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11043. /* disable FCOE L2 queue for E1x*/
  11044. if (CHIP_IS_E1x(bp))
  11045. bp->flags |= NO_FCOE_FLAG;
  11046. /* Set bp->num_queues for MSI-X mode*/
  11047. bnx2x_set_num_queues(bp);
  11048. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11049. * needed.
  11050. */
  11051. rc = bnx2x_set_int_mode(bp);
  11052. if (rc) {
  11053. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11054. goto init_one_exit;
  11055. }
  11056. BNX2X_DEV_INFO("set interrupts successfully\n");
  11057. /* register the net device */
  11058. rc = register_netdev(dev);
  11059. if (rc) {
  11060. dev_err(&pdev->dev, "Cannot register net device\n");
  11061. goto init_one_exit;
  11062. }
  11063. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11064. if (!NO_FCOE(bp)) {
  11065. /* Add storage MAC address */
  11066. rtnl_lock();
  11067. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11068. rtnl_unlock();
  11069. }
  11070. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11071. pcie_speed == PCI_SPEED_UNKNOWN ||
  11072. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11073. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11074. else
  11075. BNX2X_DEV_INFO(
  11076. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11077. board_info[ent->driver_data].name,
  11078. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11079. pcie_width,
  11080. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11081. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11082. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11083. "Unknown",
  11084. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11085. return 0;
  11086. init_one_exit:
  11087. bnx2x_disable_pcie_error_reporting(bp);
  11088. if (bp->regview)
  11089. iounmap(bp->regview);
  11090. if (IS_PF(bp) && bp->doorbells)
  11091. iounmap(bp->doorbells);
  11092. free_netdev(dev);
  11093. if (atomic_read(&pdev->enable_cnt) == 1)
  11094. pci_release_regions(pdev);
  11095. pci_disable_device(pdev);
  11096. return rc;
  11097. }
  11098. static void __bnx2x_remove(struct pci_dev *pdev,
  11099. struct net_device *dev,
  11100. struct bnx2x *bp,
  11101. bool remove_netdev)
  11102. {
  11103. /* Delete storage MAC address */
  11104. if (!NO_FCOE(bp)) {
  11105. rtnl_lock();
  11106. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11107. rtnl_unlock();
  11108. }
  11109. #ifdef BCM_DCBNL
  11110. /* Delete app tlvs from dcbnl */
  11111. bnx2x_dcbnl_update_applist(bp, true);
  11112. #endif
  11113. if (IS_PF(bp) &&
  11114. !BP_NOMCP(bp) &&
  11115. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11116. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11117. /* Close the interface - either directly or implicitly */
  11118. if (remove_netdev) {
  11119. unregister_netdev(dev);
  11120. } else {
  11121. rtnl_lock();
  11122. dev_close(dev);
  11123. rtnl_unlock();
  11124. }
  11125. bnx2x_iov_remove_one(bp);
  11126. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11127. if (IS_PF(bp))
  11128. bnx2x_set_power_state(bp, PCI_D0);
  11129. /* Disable MSI/MSI-X */
  11130. bnx2x_disable_msi(bp);
  11131. /* Power off */
  11132. if (IS_PF(bp))
  11133. bnx2x_set_power_state(bp, PCI_D3hot);
  11134. /* Make sure RESET task is not scheduled before continuing */
  11135. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11136. /* send message via vfpf channel to release the resources of this vf */
  11137. if (IS_VF(bp))
  11138. bnx2x_vfpf_release(bp);
  11139. /* Assumes no further PCIe PM changes will occur */
  11140. if (system_state == SYSTEM_POWER_OFF) {
  11141. pci_wake_from_d3(pdev, bp->wol);
  11142. pci_set_power_state(pdev, PCI_D3hot);
  11143. }
  11144. bnx2x_disable_pcie_error_reporting(bp);
  11145. if (remove_netdev) {
  11146. if (bp->regview)
  11147. iounmap(bp->regview);
  11148. /* For vfs, doorbells are part of the regview and were unmapped
  11149. * along with it. FW is only loaded by PF.
  11150. */
  11151. if (IS_PF(bp)) {
  11152. if (bp->doorbells)
  11153. iounmap(bp->doorbells);
  11154. bnx2x_release_firmware(bp);
  11155. } else {
  11156. bnx2x_vf_pci_dealloc(bp);
  11157. }
  11158. bnx2x_free_mem_bp(bp);
  11159. free_netdev(dev);
  11160. if (atomic_read(&pdev->enable_cnt) == 1)
  11161. pci_release_regions(pdev);
  11162. pci_disable_device(pdev);
  11163. }
  11164. }
  11165. static void bnx2x_remove_one(struct pci_dev *pdev)
  11166. {
  11167. struct net_device *dev = pci_get_drvdata(pdev);
  11168. struct bnx2x *bp;
  11169. if (!dev) {
  11170. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11171. return;
  11172. }
  11173. bp = netdev_priv(dev);
  11174. __bnx2x_remove(pdev, dev, bp, true);
  11175. }
  11176. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11177. {
  11178. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11179. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11180. if (CNIC_LOADED(bp))
  11181. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11182. /* Stop Tx */
  11183. bnx2x_tx_disable(bp);
  11184. /* Delete all NAPI objects */
  11185. bnx2x_del_all_napi(bp);
  11186. if (CNIC_LOADED(bp))
  11187. bnx2x_del_all_napi_cnic(bp);
  11188. netdev_reset_tc(bp->dev);
  11189. del_timer_sync(&bp->timer);
  11190. cancel_delayed_work_sync(&bp->sp_task);
  11191. cancel_delayed_work_sync(&bp->period_task);
  11192. spin_lock_bh(&bp->stats_lock);
  11193. bp->stats_state = STATS_STATE_DISABLED;
  11194. spin_unlock_bh(&bp->stats_lock);
  11195. bnx2x_save_statistics(bp);
  11196. netif_carrier_off(bp->dev);
  11197. return 0;
  11198. }
  11199. /**
  11200. * bnx2x_io_error_detected - called when PCI error is detected
  11201. * @pdev: Pointer to PCI device
  11202. * @state: The current pci connection state
  11203. *
  11204. * This function is called after a PCI bus error affecting
  11205. * this device has been detected.
  11206. */
  11207. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11208. pci_channel_state_t state)
  11209. {
  11210. struct net_device *dev = pci_get_drvdata(pdev);
  11211. struct bnx2x *bp = netdev_priv(dev);
  11212. rtnl_lock();
  11213. BNX2X_ERR("IO error detected\n");
  11214. netif_device_detach(dev);
  11215. if (state == pci_channel_io_perm_failure) {
  11216. rtnl_unlock();
  11217. return PCI_ERS_RESULT_DISCONNECT;
  11218. }
  11219. if (netif_running(dev))
  11220. bnx2x_eeh_nic_unload(bp);
  11221. bnx2x_prev_path_mark_eeh(bp);
  11222. pci_disable_device(pdev);
  11223. rtnl_unlock();
  11224. /* Request a slot reset */
  11225. return PCI_ERS_RESULT_NEED_RESET;
  11226. }
  11227. /**
  11228. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11229. * @pdev: Pointer to PCI device
  11230. *
  11231. * Restart the card from scratch, as if from a cold-boot.
  11232. */
  11233. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11234. {
  11235. struct net_device *dev = pci_get_drvdata(pdev);
  11236. struct bnx2x *bp = netdev_priv(dev);
  11237. int i;
  11238. rtnl_lock();
  11239. BNX2X_ERR("IO slot reset initializing...\n");
  11240. if (pci_enable_device(pdev)) {
  11241. dev_err(&pdev->dev,
  11242. "Cannot re-enable PCI device after reset\n");
  11243. rtnl_unlock();
  11244. return PCI_ERS_RESULT_DISCONNECT;
  11245. }
  11246. pci_set_master(pdev);
  11247. pci_restore_state(pdev);
  11248. pci_save_state(pdev);
  11249. if (netif_running(dev))
  11250. bnx2x_set_power_state(bp, PCI_D0);
  11251. if (netif_running(dev)) {
  11252. BNX2X_ERR("IO slot reset --> driver unload\n");
  11253. /* MCP should have been reset; Need to wait for validity */
  11254. bnx2x_init_shmem(bp);
  11255. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11256. u32 v;
  11257. v = SHMEM2_RD(bp,
  11258. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11259. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11260. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11261. }
  11262. bnx2x_drain_tx_queues(bp);
  11263. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11264. bnx2x_netif_stop(bp, 1);
  11265. bnx2x_free_irq(bp);
  11266. /* Report UNLOAD_DONE to MCP */
  11267. bnx2x_send_unload_done(bp, true);
  11268. bp->sp_state = 0;
  11269. bp->port.pmf = 0;
  11270. bnx2x_prev_unload(bp);
  11271. /* We should have reseted the engine, so It's fair to
  11272. * assume the FW will no longer write to the bnx2x driver.
  11273. */
  11274. bnx2x_squeeze_objects(bp);
  11275. bnx2x_free_skbs(bp);
  11276. for_each_rx_queue(bp, i)
  11277. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11278. bnx2x_free_fp_mem(bp);
  11279. bnx2x_free_mem(bp);
  11280. bp->state = BNX2X_STATE_CLOSED;
  11281. }
  11282. rtnl_unlock();
  11283. /* If AER, perform cleanup of the PCIe registers */
  11284. if (bp->flags & AER_ENABLED) {
  11285. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11286. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11287. else
  11288. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11289. }
  11290. return PCI_ERS_RESULT_RECOVERED;
  11291. }
  11292. /**
  11293. * bnx2x_io_resume - called when traffic can start flowing again
  11294. * @pdev: Pointer to PCI device
  11295. *
  11296. * This callback is called when the error recovery driver tells us that
  11297. * its OK to resume normal operation.
  11298. */
  11299. static void bnx2x_io_resume(struct pci_dev *pdev)
  11300. {
  11301. struct net_device *dev = pci_get_drvdata(pdev);
  11302. struct bnx2x *bp = netdev_priv(dev);
  11303. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11304. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11305. return;
  11306. }
  11307. rtnl_lock();
  11308. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11309. DRV_MSG_SEQ_NUMBER_MASK;
  11310. if (netif_running(dev))
  11311. bnx2x_nic_load(bp, LOAD_NORMAL);
  11312. netif_device_attach(dev);
  11313. rtnl_unlock();
  11314. }
  11315. static const struct pci_error_handlers bnx2x_err_handler = {
  11316. .error_detected = bnx2x_io_error_detected,
  11317. .slot_reset = bnx2x_io_slot_reset,
  11318. .resume = bnx2x_io_resume,
  11319. };
  11320. static void bnx2x_shutdown(struct pci_dev *pdev)
  11321. {
  11322. struct net_device *dev = pci_get_drvdata(pdev);
  11323. struct bnx2x *bp;
  11324. if (!dev)
  11325. return;
  11326. bp = netdev_priv(dev);
  11327. if (!bp)
  11328. return;
  11329. rtnl_lock();
  11330. netif_device_detach(dev);
  11331. rtnl_unlock();
  11332. /* Don't remove the netdevice, as there are scenarios which will cause
  11333. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11334. * rootfs is mounted from SAN.
  11335. */
  11336. __bnx2x_remove(pdev, dev, bp, false);
  11337. }
  11338. static struct pci_driver bnx2x_pci_driver = {
  11339. .name = DRV_MODULE_NAME,
  11340. .id_table = bnx2x_pci_tbl,
  11341. .probe = bnx2x_init_one,
  11342. .remove = bnx2x_remove_one,
  11343. .suspend = bnx2x_suspend,
  11344. .resume = bnx2x_resume,
  11345. .err_handler = &bnx2x_err_handler,
  11346. #ifdef CONFIG_BNX2X_SRIOV
  11347. .sriov_configure = bnx2x_sriov_configure,
  11348. #endif
  11349. .shutdown = bnx2x_shutdown,
  11350. };
  11351. static int __init bnx2x_init(void)
  11352. {
  11353. int ret;
  11354. pr_info("%s", version);
  11355. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11356. if (bnx2x_wq == NULL) {
  11357. pr_err("Cannot create workqueue\n");
  11358. return -ENOMEM;
  11359. }
  11360. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11361. if (!bnx2x_iov_wq) {
  11362. pr_err("Cannot create iov workqueue\n");
  11363. destroy_workqueue(bnx2x_wq);
  11364. return -ENOMEM;
  11365. }
  11366. ret = pci_register_driver(&bnx2x_pci_driver);
  11367. if (ret) {
  11368. pr_err("Cannot register driver\n");
  11369. destroy_workqueue(bnx2x_wq);
  11370. destroy_workqueue(bnx2x_iov_wq);
  11371. }
  11372. return ret;
  11373. }
  11374. static void __exit bnx2x_cleanup(void)
  11375. {
  11376. struct list_head *pos, *q;
  11377. pci_unregister_driver(&bnx2x_pci_driver);
  11378. destroy_workqueue(bnx2x_wq);
  11379. destroy_workqueue(bnx2x_iov_wq);
  11380. /* Free globally allocated resources */
  11381. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11382. struct bnx2x_prev_path_list *tmp =
  11383. list_entry(pos, struct bnx2x_prev_path_list, list);
  11384. list_del(pos);
  11385. kfree(tmp);
  11386. }
  11387. }
  11388. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11389. {
  11390. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11391. }
  11392. module_init(bnx2x_init);
  11393. module_exit(bnx2x_cleanup);
  11394. /**
  11395. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11396. *
  11397. * @bp: driver handle
  11398. * @set: set or clear the CAM entry
  11399. *
  11400. * This function will wait until the ramrod completion returns.
  11401. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11402. */
  11403. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11404. {
  11405. unsigned long ramrod_flags = 0;
  11406. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11407. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11408. &bp->iscsi_l2_mac_obj, true,
  11409. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11410. }
  11411. /* count denotes the number of new completions we have seen */
  11412. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11413. {
  11414. struct eth_spe *spe;
  11415. int cxt_index, cxt_offset;
  11416. #ifdef BNX2X_STOP_ON_ERROR
  11417. if (unlikely(bp->panic))
  11418. return;
  11419. #endif
  11420. spin_lock_bh(&bp->spq_lock);
  11421. BUG_ON(bp->cnic_spq_pending < count);
  11422. bp->cnic_spq_pending -= count;
  11423. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11424. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11425. & SPE_HDR_CONN_TYPE) >>
  11426. SPE_HDR_CONN_TYPE_SHIFT;
  11427. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11428. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11429. /* Set validation for iSCSI L2 client before sending SETUP
  11430. * ramrod
  11431. */
  11432. if (type == ETH_CONNECTION_TYPE) {
  11433. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11434. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11435. ILT_PAGE_CIDS;
  11436. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11437. (cxt_index * ILT_PAGE_CIDS);
  11438. bnx2x_set_ctx_validation(bp,
  11439. &bp->context[cxt_index].
  11440. vcxt[cxt_offset].eth,
  11441. BNX2X_ISCSI_ETH_CID(bp));
  11442. }
  11443. }
  11444. /*
  11445. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11446. * and in the air. We also check that number of outstanding
  11447. * COMMON ramrods is not more than the EQ and SPQ can
  11448. * accommodate.
  11449. */
  11450. if (type == ETH_CONNECTION_TYPE) {
  11451. if (!atomic_read(&bp->cq_spq_left))
  11452. break;
  11453. else
  11454. atomic_dec(&bp->cq_spq_left);
  11455. } else if (type == NONE_CONNECTION_TYPE) {
  11456. if (!atomic_read(&bp->eq_spq_left))
  11457. break;
  11458. else
  11459. atomic_dec(&bp->eq_spq_left);
  11460. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11461. (type == FCOE_CONNECTION_TYPE)) {
  11462. if (bp->cnic_spq_pending >=
  11463. bp->cnic_eth_dev.max_kwqe_pending)
  11464. break;
  11465. else
  11466. bp->cnic_spq_pending++;
  11467. } else {
  11468. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11469. bnx2x_panic();
  11470. break;
  11471. }
  11472. spe = bnx2x_sp_get_next(bp);
  11473. *spe = *bp->cnic_kwq_cons;
  11474. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11475. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11476. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11477. bp->cnic_kwq_cons = bp->cnic_kwq;
  11478. else
  11479. bp->cnic_kwq_cons++;
  11480. }
  11481. bnx2x_sp_prod_update(bp);
  11482. spin_unlock_bh(&bp->spq_lock);
  11483. }
  11484. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11485. struct kwqe_16 *kwqes[], u32 count)
  11486. {
  11487. struct bnx2x *bp = netdev_priv(dev);
  11488. int i;
  11489. #ifdef BNX2X_STOP_ON_ERROR
  11490. if (unlikely(bp->panic)) {
  11491. BNX2X_ERR("Can't post to SP queue while panic\n");
  11492. return -EIO;
  11493. }
  11494. #endif
  11495. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11496. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11497. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11498. return -EAGAIN;
  11499. }
  11500. spin_lock_bh(&bp->spq_lock);
  11501. for (i = 0; i < count; i++) {
  11502. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11503. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11504. break;
  11505. *bp->cnic_kwq_prod = *spe;
  11506. bp->cnic_kwq_pending++;
  11507. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11508. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11509. spe->data.update_data_addr.hi,
  11510. spe->data.update_data_addr.lo,
  11511. bp->cnic_kwq_pending);
  11512. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11513. bp->cnic_kwq_prod = bp->cnic_kwq;
  11514. else
  11515. bp->cnic_kwq_prod++;
  11516. }
  11517. spin_unlock_bh(&bp->spq_lock);
  11518. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11519. bnx2x_cnic_sp_post(bp, 0);
  11520. return i;
  11521. }
  11522. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11523. {
  11524. struct cnic_ops *c_ops;
  11525. int rc = 0;
  11526. mutex_lock(&bp->cnic_mutex);
  11527. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11528. lockdep_is_held(&bp->cnic_mutex));
  11529. if (c_ops)
  11530. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11531. mutex_unlock(&bp->cnic_mutex);
  11532. return rc;
  11533. }
  11534. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11535. {
  11536. struct cnic_ops *c_ops;
  11537. int rc = 0;
  11538. rcu_read_lock();
  11539. c_ops = rcu_dereference(bp->cnic_ops);
  11540. if (c_ops)
  11541. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11542. rcu_read_unlock();
  11543. return rc;
  11544. }
  11545. /*
  11546. * for commands that have no data
  11547. */
  11548. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11549. {
  11550. struct cnic_ctl_info ctl = {0};
  11551. ctl.cmd = cmd;
  11552. return bnx2x_cnic_ctl_send(bp, &ctl);
  11553. }
  11554. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11555. {
  11556. struct cnic_ctl_info ctl = {0};
  11557. /* first we tell CNIC and only then we count this as a completion */
  11558. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11559. ctl.data.comp.cid = cid;
  11560. ctl.data.comp.error = err;
  11561. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11562. bnx2x_cnic_sp_post(bp, 0);
  11563. }
  11564. /* Called with netif_addr_lock_bh() taken.
  11565. * Sets an rx_mode config for an iSCSI ETH client.
  11566. * Doesn't block.
  11567. * Completion should be checked outside.
  11568. */
  11569. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11570. {
  11571. unsigned long accept_flags = 0, ramrod_flags = 0;
  11572. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11573. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11574. if (start) {
  11575. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11576. * because it's the only way for UIO Queue to accept
  11577. * multicasts (in non-promiscuous mode only one Queue per
  11578. * function will receive multicast packets (leading in our
  11579. * case).
  11580. */
  11581. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11582. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11583. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11584. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11585. /* Clear STOP_PENDING bit if START is requested */
  11586. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11587. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11588. } else
  11589. /* Clear START_PENDING bit if STOP is requested */
  11590. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11591. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11592. set_bit(sched_state, &bp->sp_state);
  11593. else {
  11594. __set_bit(RAMROD_RX, &ramrod_flags);
  11595. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11596. ramrod_flags);
  11597. }
  11598. }
  11599. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11600. {
  11601. struct bnx2x *bp = netdev_priv(dev);
  11602. int rc = 0;
  11603. switch (ctl->cmd) {
  11604. case DRV_CTL_CTXTBL_WR_CMD: {
  11605. u32 index = ctl->data.io.offset;
  11606. dma_addr_t addr = ctl->data.io.dma_addr;
  11607. bnx2x_ilt_wr(bp, index, addr);
  11608. break;
  11609. }
  11610. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11611. int count = ctl->data.credit.credit_count;
  11612. bnx2x_cnic_sp_post(bp, count);
  11613. break;
  11614. }
  11615. /* rtnl_lock is held. */
  11616. case DRV_CTL_START_L2_CMD: {
  11617. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11618. unsigned long sp_bits = 0;
  11619. /* Configure the iSCSI classification object */
  11620. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11621. cp->iscsi_l2_client_id,
  11622. cp->iscsi_l2_cid, BP_FUNC(bp),
  11623. bnx2x_sp(bp, mac_rdata),
  11624. bnx2x_sp_mapping(bp, mac_rdata),
  11625. BNX2X_FILTER_MAC_PENDING,
  11626. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11627. &bp->macs_pool);
  11628. /* Set iSCSI MAC address */
  11629. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11630. if (rc)
  11631. break;
  11632. mmiowb();
  11633. barrier();
  11634. /* Start accepting on iSCSI L2 ring */
  11635. netif_addr_lock_bh(dev);
  11636. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11637. netif_addr_unlock_bh(dev);
  11638. /* bits to wait on */
  11639. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11640. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11641. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11642. BNX2X_ERR("rx_mode completion timed out!\n");
  11643. break;
  11644. }
  11645. /* rtnl_lock is held. */
  11646. case DRV_CTL_STOP_L2_CMD: {
  11647. unsigned long sp_bits = 0;
  11648. /* Stop accepting on iSCSI L2 ring */
  11649. netif_addr_lock_bh(dev);
  11650. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11651. netif_addr_unlock_bh(dev);
  11652. /* bits to wait on */
  11653. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11654. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11655. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11656. BNX2X_ERR("rx_mode completion timed out!\n");
  11657. mmiowb();
  11658. barrier();
  11659. /* Unset iSCSI L2 MAC */
  11660. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11661. BNX2X_ISCSI_ETH_MAC, true);
  11662. break;
  11663. }
  11664. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11665. int count = ctl->data.credit.credit_count;
  11666. smp_mb__before_atomic();
  11667. atomic_add(count, &bp->cq_spq_left);
  11668. smp_mb__after_atomic();
  11669. break;
  11670. }
  11671. case DRV_CTL_ULP_REGISTER_CMD: {
  11672. int ulp_type = ctl->data.register_data.ulp_type;
  11673. if (CHIP_IS_E3(bp)) {
  11674. int idx = BP_FW_MB_IDX(bp);
  11675. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11676. int path = BP_PATH(bp);
  11677. int port = BP_PORT(bp);
  11678. int i;
  11679. u32 scratch_offset;
  11680. u32 *host_addr;
  11681. /* first write capability to shmem2 */
  11682. if (ulp_type == CNIC_ULP_ISCSI)
  11683. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11684. else if (ulp_type == CNIC_ULP_FCOE)
  11685. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11686. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11687. if ((ulp_type != CNIC_ULP_FCOE) ||
  11688. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11689. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11690. break;
  11691. /* if reached here - should write fcoe capabilities */
  11692. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11693. if (!scratch_offset)
  11694. break;
  11695. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11696. fcoe_features[path][port]);
  11697. host_addr = (u32 *) &(ctl->data.register_data.
  11698. fcoe_features);
  11699. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11700. i += 4)
  11701. REG_WR(bp, scratch_offset + i,
  11702. *(host_addr + i/4));
  11703. }
  11704. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11705. break;
  11706. }
  11707. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11708. int ulp_type = ctl->data.ulp_type;
  11709. if (CHIP_IS_E3(bp)) {
  11710. int idx = BP_FW_MB_IDX(bp);
  11711. u32 cap;
  11712. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11713. if (ulp_type == CNIC_ULP_ISCSI)
  11714. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11715. else if (ulp_type == CNIC_ULP_FCOE)
  11716. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11717. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11718. }
  11719. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11720. break;
  11721. }
  11722. default:
  11723. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11724. rc = -EINVAL;
  11725. }
  11726. return rc;
  11727. }
  11728. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11729. {
  11730. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11731. if (bp->flags & USING_MSIX_FLAG) {
  11732. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11733. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11734. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11735. } else {
  11736. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11737. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11738. }
  11739. if (!CHIP_IS_E1x(bp))
  11740. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11741. else
  11742. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11743. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11744. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11745. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11746. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11747. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11748. cp->num_irq = 2;
  11749. }
  11750. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11751. {
  11752. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11753. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11754. bnx2x_cid_ilt_lines(bp);
  11755. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11756. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11757. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11758. 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",
  11759. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11760. cp->iscsi_l2_cid);
  11761. if (NO_ISCSI_OOO(bp))
  11762. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11763. }
  11764. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11765. void *data)
  11766. {
  11767. struct bnx2x *bp = netdev_priv(dev);
  11768. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11769. int rc;
  11770. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11771. if (ops == NULL) {
  11772. BNX2X_ERR("NULL ops received\n");
  11773. return -EINVAL;
  11774. }
  11775. if (!CNIC_SUPPORT(bp)) {
  11776. BNX2X_ERR("Can't register CNIC when not supported\n");
  11777. return -EOPNOTSUPP;
  11778. }
  11779. if (!CNIC_LOADED(bp)) {
  11780. rc = bnx2x_load_cnic(bp);
  11781. if (rc) {
  11782. BNX2X_ERR("CNIC-related load failed\n");
  11783. return rc;
  11784. }
  11785. }
  11786. bp->cnic_enabled = true;
  11787. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11788. if (!bp->cnic_kwq)
  11789. return -ENOMEM;
  11790. bp->cnic_kwq_cons = bp->cnic_kwq;
  11791. bp->cnic_kwq_prod = bp->cnic_kwq;
  11792. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11793. bp->cnic_spq_pending = 0;
  11794. bp->cnic_kwq_pending = 0;
  11795. bp->cnic_data = data;
  11796. cp->num_irq = 0;
  11797. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11798. cp->iro_arr = bp->iro_arr;
  11799. bnx2x_setup_cnic_irq_info(bp);
  11800. rcu_assign_pointer(bp->cnic_ops, ops);
  11801. /* Schedule driver to read CNIC driver versions */
  11802. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  11803. return 0;
  11804. }
  11805. static int bnx2x_unregister_cnic(struct net_device *dev)
  11806. {
  11807. struct bnx2x *bp = netdev_priv(dev);
  11808. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11809. mutex_lock(&bp->cnic_mutex);
  11810. cp->drv_state = 0;
  11811. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11812. mutex_unlock(&bp->cnic_mutex);
  11813. synchronize_rcu();
  11814. bp->cnic_enabled = false;
  11815. kfree(bp->cnic_kwq);
  11816. bp->cnic_kwq = NULL;
  11817. return 0;
  11818. }
  11819. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11820. {
  11821. struct bnx2x *bp = netdev_priv(dev);
  11822. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11823. /* If both iSCSI and FCoE are disabled - return NULL in
  11824. * order to indicate CNIC that it should not try to work
  11825. * with this device.
  11826. */
  11827. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11828. return NULL;
  11829. cp->drv_owner = THIS_MODULE;
  11830. cp->chip_id = CHIP_ID(bp);
  11831. cp->pdev = bp->pdev;
  11832. cp->io_base = bp->regview;
  11833. cp->io_base2 = bp->doorbells;
  11834. cp->max_kwqe_pending = 8;
  11835. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11836. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11837. bnx2x_cid_ilt_lines(bp);
  11838. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11839. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11840. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11841. cp->drv_ctl = bnx2x_drv_ctl;
  11842. cp->drv_register_cnic = bnx2x_register_cnic;
  11843. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11844. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11845. cp->iscsi_l2_client_id =
  11846. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11847. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11848. if (NO_ISCSI_OOO(bp))
  11849. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11850. if (NO_ISCSI(bp))
  11851. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11852. if (NO_FCOE(bp))
  11853. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11854. BNX2X_DEV_INFO(
  11855. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11856. cp->ctx_blk_size,
  11857. cp->ctx_tbl_offset,
  11858. cp->ctx_tbl_len,
  11859. cp->starting_cid);
  11860. return cp;
  11861. }
  11862. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11863. {
  11864. struct bnx2x *bp = fp->bp;
  11865. u32 offset = BAR_USTRORM_INTMEM;
  11866. if (IS_VF(bp))
  11867. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11868. else if (!CHIP_IS_E1x(bp))
  11869. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11870. else
  11871. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11872. return offset;
  11873. }
  11874. /* called only on E1H or E2.
  11875. * When pretending to be PF, the pretend value is the function number 0...7
  11876. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11877. * combination
  11878. */
  11879. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11880. {
  11881. u32 pretend_reg;
  11882. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11883. return -1;
  11884. /* get my own pretend register */
  11885. pretend_reg = bnx2x_get_pretend_reg(bp);
  11886. REG_WR(bp, pretend_reg, pretend_func_val);
  11887. REG_RD(bp, pretend_reg);
  11888. return 0;
  11889. }