bnx2x_main.c 380 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/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. struct workqueue_struct *bnx2x_wq;
  110. struct bnx2x_mac_vals {
  111. u32 xmac_addr;
  112. u32 xmac_val;
  113. u32 emac_addr;
  114. u32 emac_val;
  115. u32 umac_addr;
  116. u32 umac_val;
  117. u32 bmac_addr;
  118. u32 bmac_val[2];
  119. };
  120. enum bnx2x_board_type {
  121. BCM57710 = 0,
  122. BCM57711,
  123. BCM57711E,
  124. BCM57712,
  125. BCM57712_MF,
  126. BCM57712_VF,
  127. BCM57800,
  128. BCM57800_MF,
  129. BCM57800_VF,
  130. BCM57810,
  131. BCM57810_MF,
  132. BCM57810_VF,
  133. BCM57840_4_10,
  134. BCM57840_2_20,
  135. BCM57840_MF,
  136. BCM57840_VF,
  137. BCM57811,
  138. BCM57811_MF,
  139. BCM57840_O,
  140. BCM57840_MFO,
  141. BCM57811_VF
  142. };
  143. /* indexed by board_type, above */
  144. static struct {
  145. char *name;
  146. } board_info[] = {
  147. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  148. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  149. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  150. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  151. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  152. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  153. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  154. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  155. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  156. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  157. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  158. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  159. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  160. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  161. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  162. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  163. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  164. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  165. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  166. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  167. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  168. };
  169. #ifndef PCI_DEVICE_ID_NX2_57710
  170. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  171. #endif
  172. #ifndef PCI_DEVICE_ID_NX2_57711
  173. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  174. #endif
  175. #ifndef PCI_DEVICE_ID_NX2_57711E
  176. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  177. #endif
  178. #ifndef PCI_DEVICE_ID_NX2_57712
  179. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  180. #endif
  181. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  182. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  183. #endif
  184. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  185. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  186. #endif
  187. #ifndef PCI_DEVICE_ID_NX2_57800
  188. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  189. #endif
  190. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  191. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  192. #endif
  193. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  194. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  195. #endif
  196. #ifndef PCI_DEVICE_ID_NX2_57810
  197. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  198. #endif
  199. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  200. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  201. #endif
  202. #ifndef PCI_DEVICE_ID_NX2_57840_O
  203. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  204. #endif
  205. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  206. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  207. #endif
  208. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  209. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  210. #endif
  211. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  212. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  213. #endif
  214. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  215. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  216. #endif
  217. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  218. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  219. #endif
  220. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  221. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  222. #endif
  223. #ifndef PCI_DEVICE_ID_NX2_57811
  224. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  225. #endif
  226. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  227. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  228. #endif
  229. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  230. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  231. #endif
  232. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  233. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  254. { 0 }
  255. };
  256. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  257. /* Global resources for unloading a previously loaded device */
  258. #define BNX2X_PREV_WAIT_NEEDED 1
  259. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  260. static LIST_HEAD(bnx2x_prev_list);
  261. /* Forward declaration */
  262. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  263. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  264. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  265. /****************************************************************************
  266. * General service functions
  267. ****************************************************************************/
  268. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  269. u32 addr, dma_addr_t mapping)
  270. {
  271. REG_WR(bp, addr, U64_LO(mapping));
  272. REG_WR(bp, addr + 4, U64_HI(mapping));
  273. }
  274. static void storm_memset_spq_addr(struct bnx2x *bp,
  275. dma_addr_t mapping, u16 abs_fid)
  276. {
  277. u32 addr = XSEM_REG_FAST_MEMORY +
  278. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  279. __storm_memset_dma_mapping(bp, addr, mapping);
  280. }
  281. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  282. u16 pf_id)
  283. {
  284. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  285. pf_id);
  286. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  287. pf_id);
  288. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  291. pf_id);
  292. }
  293. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  294. u8 enable)
  295. {
  296. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  297. enable);
  298. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  299. enable);
  300. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  303. enable);
  304. }
  305. static void storm_memset_eq_data(struct bnx2x *bp,
  306. struct event_ring_data *eq_data,
  307. u16 pfid)
  308. {
  309. size_t size = sizeof(struct event_ring_data);
  310. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  311. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  312. }
  313. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  314. u16 pfid)
  315. {
  316. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  317. REG_WR16(bp, addr, eq_prod);
  318. }
  319. /* used only at init
  320. * locking is done by mcp
  321. */
  322. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  323. {
  324. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  325. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  326. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  327. PCICFG_VENDOR_ID_OFFSET);
  328. }
  329. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  330. {
  331. u32 val;
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  333. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  334. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  335. PCICFG_VENDOR_ID_OFFSET);
  336. return val;
  337. }
  338. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  339. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  340. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  341. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  342. #define DMAE_DP_DST_NONE "dst_addr [none]"
  343. static void bnx2x_dp_dmae(struct bnx2x *bp,
  344. struct dmae_command *dmae, int msglvl)
  345. {
  346. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  347. int i;
  348. switch (dmae->opcode & DMAE_COMMAND_DST) {
  349. case DMAE_CMD_DST_PCI:
  350. if (src_type == DMAE_CMD_SRC_PCI)
  351. DP(msglvl, "DMAE: opcode 0x%08x\n"
  352. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  353. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  354. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  355. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  356. dmae->comp_addr_hi, dmae->comp_addr_lo,
  357. dmae->comp_val);
  358. else
  359. DP(msglvl, "DMAE: opcode 0x%08x\n"
  360. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  361. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  362. dmae->opcode, dmae->src_addr_lo >> 2,
  363. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  364. dmae->comp_addr_hi, dmae->comp_addr_lo,
  365. dmae->comp_val);
  366. break;
  367. case DMAE_CMD_DST_GRC:
  368. if (src_type == DMAE_CMD_SRC_PCI)
  369. DP(msglvl, "DMAE: opcode 0x%08x\n"
  370. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  371. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  372. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  373. dmae->len, dmae->dst_addr_lo >> 2,
  374. dmae->comp_addr_hi, dmae->comp_addr_lo,
  375. dmae->comp_val);
  376. else
  377. DP(msglvl, "DMAE: opcode 0x%08x\n"
  378. "src [%08x], len [%d*4], dst [%08x]\n"
  379. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  380. dmae->opcode, dmae->src_addr_lo >> 2,
  381. dmae->len, dmae->dst_addr_lo >> 2,
  382. dmae->comp_addr_hi, dmae->comp_addr_lo,
  383. dmae->comp_val);
  384. break;
  385. default:
  386. if (src_type == DMAE_CMD_SRC_PCI)
  387. DP(msglvl, "DMAE: opcode 0x%08x\n"
  388. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  389. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  390. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  391. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  392. dmae->comp_val);
  393. else
  394. DP(msglvl, "DMAE: opcode 0x%08x\n"
  395. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  396. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  397. dmae->opcode, dmae->src_addr_lo >> 2,
  398. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  399. dmae->comp_val);
  400. break;
  401. }
  402. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  403. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  404. i, *(((u32 *)dmae) + i));
  405. }
  406. /* copy command into DMAE command memory and set DMAE command go */
  407. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  408. {
  409. u32 cmd_offset;
  410. int i;
  411. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  412. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  413. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  414. }
  415. REG_WR(bp, dmae_reg_go_c[idx], 1);
  416. }
  417. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  418. {
  419. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  420. DMAE_CMD_C_ENABLE);
  421. }
  422. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  423. {
  424. return opcode & ~DMAE_CMD_SRC_RESET;
  425. }
  426. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  427. bool with_comp, u8 comp_type)
  428. {
  429. u32 opcode = 0;
  430. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  431. (dst_type << DMAE_COMMAND_DST_SHIFT));
  432. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  433. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  434. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  435. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  436. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  437. #ifdef __BIG_ENDIAN
  438. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  439. #else
  440. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  441. #endif
  442. if (with_comp)
  443. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  444. return opcode;
  445. }
  446. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  447. struct dmae_command *dmae,
  448. u8 src_type, u8 dst_type)
  449. {
  450. memset(dmae, 0, sizeof(struct dmae_command));
  451. /* set the opcode */
  452. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  453. true, DMAE_COMP_PCI);
  454. /* fill in the completion parameters */
  455. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  456. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  457. dmae->comp_val = DMAE_COMP_VAL;
  458. }
  459. /* issue a dmae command over the init-channel and wait for completion */
  460. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  461. u32 *comp)
  462. {
  463. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  464. int rc = 0;
  465. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  466. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  467. * as long as this code is called both from syscall context and
  468. * from ndo_set_rx_mode() flow that may be called from BH.
  469. */
  470. spin_lock_bh(&bp->dmae_lock);
  471. /* reset completion */
  472. *comp = 0;
  473. /* post the command on the channel used for initializations */
  474. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  475. /* wait for completion */
  476. udelay(5);
  477. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  478. if (!cnt ||
  479. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  480. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  481. BNX2X_ERR("DMAE timeout!\n");
  482. rc = DMAE_TIMEOUT;
  483. goto unlock;
  484. }
  485. cnt--;
  486. udelay(50);
  487. }
  488. if (*comp & DMAE_PCI_ERR_FLAG) {
  489. BNX2X_ERR("DMAE PCI error!\n");
  490. rc = DMAE_PCI_ERROR;
  491. }
  492. unlock:
  493. spin_unlock_bh(&bp->dmae_lock);
  494. return rc;
  495. }
  496. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  497. u32 len32)
  498. {
  499. int rc;
  500. struct dmae_command dmae;
  501. if (!bp->dmae_ready) {
  502. u32 *data = bnx2x_sp(bp, wb_data[0]);
  503. if (CHIP_IS_E1(bp))
  504. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  505. else
  506. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  507. return;
  508. }
  509. /* set opcode and fixed command fields */
  510. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  511. /* fill in addresses and len */
  512. dmae.src_addr_lo = U64_LO(dma_addr);
  513. dmae.src_addr_hi = U64_HI(dma_addr);
  514. dmae.dst_addr_lo = dst_addr >> 2;
  515. dmae.dst_addr_hi = 0;
  516. dmae.len = len32;
  517. /* issue the command and wait for completion */
  518. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  519. if (rc) {
  520. BNX2X_ERR("DMAE returned failure %d\n", rc);
  521. #ifdef BNX2X_STOP_ON_ERROR
  522. bnx2x_panic();
  523. #endif
  524. }
  525. }
  526. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  527. {
  528. int rc;
  529. struct dmae_command dmae;
  530. if (!bp->dmae_ready) {
  531. u32 *data = bnx2x_sp(bp, wb_data[0]);
  532. int i;
  533. if (CHIP_IS_E1(bp))
  534. for (i = 0; i < len32; i++)
  535. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  536. else
  537. for (i = 0; i < len32; i++)
  538. data[i] = REG_RD(bp, src_addr + i*4);
  539. return;
  540. }
  541. /* set opcode and fixed command fields */
  542. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  543. /* fill in addresses and len */
  544. dmae.src_addr_lo = src_addr >> 2;
  545. dmae.src_addr_hi = 0;
  546. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  547. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  548. dmae.len = len32;
  549. /* issue the command and wait for completion */
  550. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  551. if (rc) {
  552. BNX2X_ERR("DMAE returned failure %d\n", rc);
  553. #ifdef BNX2X_STOP_ON_ERROR
  554. bnx2x_panic();
  555. #endif
  556. }
  557. }
  558. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  559. u32 addr, u32 len)
  560. {
  561. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  562. int offset = 0;
  563. while (len > dmae_wr_max) {
  564. bnx2x_write_dmae(bp, phys_addr + offset,
  565. addr + offset, dmae_wr_max);
  566. offset += dmae_wr_max * 4;
  567. len -= dmae_wr_max;
  568. }
  569. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  570. }
  571. static int bnx2x_mc_assert(struct bnx2x *bp)
  572. {
  573. char last_idx;
  574. int i, rc = 0;
  575. u32 row0, row1, row2, row3;
  576. /* XSTORM */
  577. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  578. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  579. if (last_idx)
  580. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  581. /* print the asserts */
  582. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  583. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  584. XSTORM_ASSERT_LIST_OFFSET(i));
  585. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  586. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  587. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  588. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  589. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  590. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  591. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  592. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  593. i, row3, row2, row1, row0);
  594. rc++;
  595. } else {
  596. break;
  597. }
  598. }
  599. /* TSTORM */
  600. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  601. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  602. if (last_idx)
  603. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  604. /* print the asserts */
  605. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  606. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  607. TSTORM_ASSERT_LIST_OFFSET(i));
  608. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  609. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  610. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  611. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  612. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  613. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  614. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  615. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  616. i, row3, row2, row1, row0);
  617. rc++;
  618. } else {
  619. break;
  620. }
  621. }
  622. /* CSTORM */
  623. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  624. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  625. if (last_idx)
  626. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  627. /* print the asserts */
  628. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  629. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  630. CSTORM_ASSERT_LIST_OFFSET(i));
  631. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  632. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  633. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  634. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  635. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  636. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  637. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  638. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  639. i, row3, row2, row1, row0);
  640. rc++;
  641. } else {
  642. break;
  643. }
  644. }
  645. /* USTORM */
  646. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  647. USTORM_ASSERT_LIST_INDEX_OFFSET);
  648. if (last_idx)
  649. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  650. /* print the asserts */
  651. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  652. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  653. USTORM_ASSERT_LIST_OFFSET(i));
  654. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  655. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  656. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  657. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  658. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  659. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  660. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  661. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  662. i, row3, row2, row1, row0);
  663. rc++;
  664. } else {
  665. break;
  666. }
  667. }
  668. return rc;
  669. }
  670. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  671. #define SCRATCH_BUFFER_SIZE(bp) \
  672. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  673. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  674. {
  675. u32 addr, val;
  676. u32 mark, offset;
  677. __be32 data[9];
  678. int word;
  679. u32 trace_shmem_base;
  680. if (BP_NOMCP(bp)) {
  681. BNX2X_ERR("NO MCP - can not dump\n");
  682. return;
  683. }
  684. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  685. (bp->common.bc_ver & 0xff0000) >> 16,
  686. (bp->common.bc_ver & 0xff00) >> 8,
  687. (bp->common.bc_ver & 0xff));
  688. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  689. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  690. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  691. if (BP_PATH(bp) == 0)
  692. trace_shmem_base = bp->common.shmem_base;
  693. else
  694. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  695. /* sanity */
  696. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  697. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  698. SCRATCH_BUFFER_SIZE(bp)) {
  699. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  700. trace_shmem_base);
  701. return;
  702. }
  703. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  704. /* validate TRCB signature */
  705. mark = REG_RD(bp, addr);
  706. if (mark != MFW_TRACE_SIGNATURE) {
  707. BNX2X_ERR("Trace buffer signature is missing.");
  708. return ;
  709. }
  710. /* read cyclic buffer pointer */
  711. addr += 4;
  712. mark = REG_RD(bp, addr);
  713. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  714. if (mark >= trace_shmem_base || mark < addr + 4) {
  715. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  716. return;
  717. }
  718. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  719. printk("%s", lvl);
  720. /* dump buffer after the mark */
  721. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  722. for (word = 0; word < 8; word++)
  723. data[word] = htonl(REG_RD(bp, offset + 4*word));
  724. data[8] = 0x0;
  725. pr_cont("%s", (char *)data);
  726. }
  727. /* dump buffer before the mark */
  728. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  729. for (word = 0; word < 8; word++)
  730. data[word] = htonl(REG_RD(bp, offset + 4*word));
  731. data[8] = 0x0;
  732. pr_cont("%s", (char *)data);
  733. }
  734. printk("%s" "end of fw dump\n", lvl);
  735. }
  736. static void bnx2x_fw_dump(struct bnx2x *bp)
  737. {
  738. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  739. }
  740. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  741. {
  742. int port = BP_PORT(bp);
  743. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  744. u32 val = REG_RD(bp, addr);
  745. /* in E1 we must use only PCI configuration space to disable
  746. * MSI/MSIX capability
  747. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  748. */
  749. if (CHIP_IS_E1(bp)) {
  750. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  751. * Use mask register to prevent from HC sending interrupts
  752. * after we exit the function
  753. */
  754. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  755. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  756. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  757. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  758. } else
  759. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  760. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  761. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  762. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  763. DP(NETIF_MSG_IFDOWN,
  764. "write %x to HC %d (addr 0x%x)\n",
  765. val, port, addr);
  766. /* flush all outstanding writes */
  767. mmiowb();
  768. REG_WR(bp, addr, val);
  769. if (REG_RD(bp, addr) != val)
  770. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  771. }
  772. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  773. {
  774. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  775. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  776. IGU_PF_CONF_INT_LINE_EN |
  777. IGU_PF_CONF_ATTN_BIT_EN);
  778. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  779. /* flush all outstanding writes */
  780. mmiowb();
  781. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  782. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  783. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  784. }
  785. static void bnx2x_int_disable(struct bnx2x *bp)
  786. {
  787. if (bp->common.int_block == INT_BLOCK_HC)
  788. bnx2x_hc_int_disable(bp);
  789. else
  790. bnx2x_igu_int_disable(bp);
  791. }
  792. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  793. {
  794. int i;
  795. u16 j;
  796. struct hc_sp_status_block_data sp_sb_data;
  797. int func = BP_FUNC(bp);
  798. #ifdef BNX2X_STOP_ON_ERROR
  799. u16 start = 0, end = 0;
  800. u8 cos;
  801. #endif
  802. if (disable_int)
  803. bnx2x_int_disable(bp);
  804. bp->stats_state = STATS_STATE_DISABLED;
  805. bp->eth_stats.unrecoverable_error++;
  806. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  807. BNX2X_ERR("begin crash dump -----------------\n");
  808. /* Indices */
  809. /* Common */
  810. 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",
  811. bp->def_idx, bp->def_att_idx, bp->attn_state,
  812. bp->spq_prod_idx, bp->stats_counter);
  813. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  814. bp->def_status_blk->atten_status_block.attn_bits,
  815. bp->def_status_blk->atten_status_block.attn_bits_ack,
  816. bp->def_status_blk->atten_status_block.status_block_id,
  817. bp->def_status_blk->atten_status_block.attn_bits_index);
  818. BNX2X_ERR(" def (");
  819. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  820. pr_cont("0x%x%s",
  821. bp->def_status_blk->sp_sb.index_values[i],
  822. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  823. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  824. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  825. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  826. i*sizeof(u32));
  827. 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",
  828. sp_sb_data.igu_sb_id,
  829. sp_sb_data.igu_seg_id,
  830. sp_sb_data.p_func.pf_id,
  831. sp_sb_data.p_func.vnic_id,
  832. sp_sb_data.p_func.vf_id,
  833. sp_sb_data.p_func.vf_valid,
  834. sp_sb_data.state);
  835. for_each_eth_queue(bp, i) {
  836. struct bnx2x_fastpath *fp = &bp->fp[i];
  837. int loop;
  838. struct hc_status_block_data_e2 sb_data_e2;
  839. struct hc_status_block_data_e1x sb_data_e1x;
  840. struct hc_status_block_sm *hc_sm_p =
  841. CHIP_IS_E1x(bp) ?
  842. sb_data_e1x.common.state_machine :
  843. sb_data_e2.common.state_machine;
  844. struct hc_index_data *hc_index_p =
  845. CHIP_IS_E1x(bp) ?
  846. sb_data_e1x.index_data :
  847. sb_data_e2.index_data;
  848. u8 data_size, cos;
  849. u32 *sb_data_p;
  850. struct bnx2x_fp_txdata txdata;
  851. /* Rx */
  852. 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",
  853. i, fp->rx_bd_prod, fp->rx_bd_cons,
  854. fp->rx_comp_prod,
  855. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  856. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  857. fp->rx_sge_prod, fp->last_max_sge,
  858. le16_to_cpu(fp->fp_hc_idx));
  859. /* Tx */
  860. for_each_cos_in_tx_queue(fp, cos)
  861. {
  862. txdata = *fp->txdata_ptr[cos];
  863. 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",
  864. i, txdata.tx_pkt_prod,
  865. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  866. txdata.tx_bd_cons,
  867. le16_to_cpu(*txdata.tx_cons_sb));
  868. }
  869. loop = CHIP_IS_E1x(bp) ?
  870. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  871. /* host sb data */
  872. if (IS_FCOE_FP(fp))
  873. continue;
  874. BNX2X_ERR(" run indexes (");
  875. for (j = 0; j < HC_SB_MAX_SM; j++)
  876. pr_cont("0x%x%s",
  877. fp->sb_running_index[j],
  878. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  879. BNX2X_ERR(" indexes (");
  880. for (j = 0; j < loop; j++)
  881. pr_cont("0x%x%s",
  882. fp->sb_index_values[j],
  883. (j == loop - 1) ? ")" : " ");
  884. /* fw sb data */
  885. data_size = CHIP_IS_E1x(bp) ?
  886. sizeof(struct hc_status_block_data_e1x) :
  887. sizeof(struct hc_status_block_data_e2);
  888. data_size /= sizeof(u32);
  889. sb_data_p = CHIP_IS_E1x(bp) ?
  890. (u32 *)&sb_data_e1x :
  891. (u32 *)&sb_data_e2;
  892. /* copy sb data in here */
  893. for (j = 0; j < data_size; j++)
  894. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  895. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  896. j * sizeof(u32));
  897. if (!CHIP_IS_E1x(bp)) {
  898. 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",
  899. sb_data_e2.common.p_func.pf_id,
  900. sb_data_e2.common.p_func.vf_id,
  901. sb_data_e2.common.p_func.vf_valid,
  902. sb_data_e2.common.p_func.vnic_id,
  903. sb_data_e2.common.same_igu_sb_1b,
  904. sb_data_e2.common.state);
  905. } else {
  906. 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",
  907. sb_data_e1x.common.p_func.pf_id,
  908. sb_data_e1x.common.p_func.vf_id,
  909. sb_data_e1x.common.p_func.vf_valid,
  910. sb_data_e1x.common.p_func.vnic_id,
  911. sb_data_e1x.common.same_igu_sb_1b,
  912. sb_data_e1x.common.state);
  913. }
  914. /* SB_SMs data */
  915. for (j = 0; j < HC_SB_MAX_SM; j++) {
  916. 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",
  917. j, hc_sm_p[j].__flags,
  918. hc_sm_p[j].igu_sb_id,
  919. hc_sm_p[j].igu_seg_id,
  920. hc_sm_p[j].time_to_expire,
  921. hc_sm_p[j].timer_value);
  922. }
  923. /* Indices data */
  924. for (j = 0; j < loop; j++) {
  925. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  926. hc_index_p[j].flags,
  927. hc_index_p[j].timeout);
  928. }
  929. }
  930. #ifdef BNX2X_STOP_ON_ERROR
  931. /* event queue */
  932. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  933. for (i = 0; i < NUM_EQ_DESC; i++) {
  934. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  935. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  936. i, bp->eq_ring[i].message.opcode,
  937. bp->eq_ring[i].message.error);
  938. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  939. }
  940. /* Rings */
  941. /* Rx */
  942. for_each_valid_rx_queue(bp, i) {
  943. struct bnx2x_fastpath *fp = &bp->fp[i];
  944. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  945. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  946. for (j = start; j != end; j = RX_BD(j + 1)) {
  947. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  948. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  949. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  950. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  951. }
  952. start = RX_SGE(fp->rx_sge_prod);
  953. end = RX_SGE(fp->last_max_sge);
  954. for (j = start; j != end; j = RX_SGE(j + 1)) {
  955. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  956. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  957. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  958. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  959. }
  960. start = RCQ_BD(fp->rx_comp_cons - 10);
  961. end = RCQ_BD(fp->rx_comp_cons + 503);
  962. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  963. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  964. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  965. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  966. }
  967. }
  968. /* Tx */
  969. for_each_valid_tx_queue(bp, i) {
  970. struct bnx2x_fastpath *fp = &bp->fp[i];
  971. for_each_cos_in_tx_queue(fp, cos) {
  972. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  973. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  974. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  975. for (j = start; j != end; j = TX_BD(j + 1)) {
  976. struct sw_tx_bd *sw_bd =
  977. &txdata->tx_buf_ring[j];
  978. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  979. i, cos, j, sw_bd->skb,
  980. sw_bd->first_bd);
  981. }
  982. start = TX_BD(txdata->tx_bd_cons - 10);
  983. end = TX_BD(txdata->tx_bd_cons + 254);
  984. for (j = start; j != end; j = TX_BD(j + 1)) {
  985. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  986. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  987. i, cos, j, tx_bd[0], tx_bd[1],
  988. tx_bd[2], tx_bd[3]);
  989. }
  990. }
  991. }
  992. #endif
  993. bnx2x_fw_dump(bp);
  994. bnx2x_mc_assert(bp);
  995. BNX2X_ERR("end crash dump -----------------\n");
  996. }
  997. /*
  998. * FLR Support for E2
  999. *
  1000. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1001. * initialization.
  1002. */
  1003. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1004. #define FLR_WAIT_INTERVAL 50 /* usec */
  1005. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1006. struct pbf_pN_buf_regs {
  1007. int pN;
  1008. u32 init_crd;
  1009. u32 crd;
  1010. u32 crd_freed;
  1011. };
  1012. struct pbf_pN_cmd_regs {
  1013. int pN;
  1014. u32 lines_occup;
  1015. u32 lines_freed;
  1016. };
  1017. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1018. struct pbf_pN_buf_regs *regs,
  1019. u32 poll_count)
  1020. {
  1021. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1022. u32 cur_cnt = poll_count;
  1023. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1024. crd = crd_start = REG_RD(bp, regs->crd);
  1025. init_crd = REG_RD(bp, regs->init_crd);
  1026. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1027. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1028. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1029. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1030. (init_crd - crd_start))) {
  1031. if (cur_cnt--) {
  1032. udelay(FLR_WAIT_INTERVAL);
  1033. crd = REG_RD(bp, regs->crd);
  1034. crd_freed = REG_RD(bp, regs->crd_freed);
  1035. } else {
  1036. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1037. regs->pN);
  1038. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1039. regs->pN, crd);
  1040. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1041. regs->pN, crd_freed);
  1042. break;
  1043. }
  1044. }
  1045. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1046. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1047. }
  1048. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1049. struct pbf_pN_cmd_regs *regs,
  1050. u32 poll_count)
  1051. {
  1052. u32 occup, to_free, freed, freed_start;
  1053. u32 cur_cnt = poll_count;
  1054. occup = to_free = REG_RD(bp, regs->lines_occup);
  1055. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1056. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1057. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1058. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1059. if (cur_cnt--) {
  1060. udelay(FLR_WAIT_INTERVAL);
  1061. occup = REG_RD(bp, regs->lines_occup);
  1062. freed = REG_RD(bp, regs->lines_freed);
  1063. } else {
  1064. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1065. regs->pN);
  1066. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1067. regs->pN, occup);
  1068. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1069. regs->pN, freed);
  1070. break;
  1071. }
  1072. }
  1073. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1074. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1075. }
  1076. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1077. u32 expected, u32 poll_count)
  1078. {
  1079. u32 cur_cnt = poll_count;
  1080. u32 val;
  1081. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1082. udelay(FLR_WAIT_INTERVAL);
  1083. return val;
  1084. }
  1085. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1086. char *msg, u32 poll_cnt)
  1087. {
  1088. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1089. if (val != 0) {
  1090. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1091. return 1;
  1092. }
  1093. return 0;
  1094. }
  1095. /* Common routines with VF FLR cleanup */
  1096. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1097. {
  1098. /* adjust polling timeout */
  1099. if (CHIP_REV_IS_EMUL(bp))
  1100. return FLR_POLL_CNT * 2000;
  1101. if (CHIP_REV_IS_FPGA(bp))
  1102. return FLR_POLL_CNT * 120;
  1103. return FLR_POLL_CNT;
  1104. }
  1105. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1106. {
  1107. struct pbf_pN_cmd_regs cmd_regs[] = {
  1108. {0, (CHIP_IS_E3B0(bp)) ?
  1109. PBF_REG_TQ_OCCUPANCY_Q0 :
  1110. PBF_REG_P0_TQ_OCCUPANCY,
  1111. (CHIP_IS_E3B0(bp)) ?
  1112. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1113. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1114. {1, (CHIP_IS_E3B0(bp)) ?
  1115. PBF_REG_TQ_OCCUPANCY_Q1 :
  1116. PBF_REG_P1_TQ_OCCUPANCY,
  1117. (CHIP_IS_E3B0(bp)) ?
  1118. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1119. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1120. {4, (CHIP_IS_E3B0(bp)) ?
  1121. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1122. PBF_REG_P4_TQ_OCCUPANCY,
  1123. (CHIP_IS_E3B0(bp)) ?
  1124. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1125. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1126. };
  1127. struct pbf_pN_buf_regs buf_regs[] = {
  1128. {0, (CHIP_IS_E3B0(bp)) ?
  1129. PBF_REG_INIT_CRD_Q0 :
  1130. PBF_REG_P0_INIT_CRD ,
  1131. (CHIP_IS_E3B0(bp)) ?
  1132. PBF_REG_CREDIT_Q0 :
  1133. PBF_REG_P0_CREDIT,
  1134. (CHIP_IS_E3B0(bp)) ?
  1135. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1136. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1137. {1, (CHIP_IS_E3B0(bp)) ?
  1138. PBF_REG_INIT_CRD_Q1 :
  1139. PBF_REG_P1_INIT_CRD,
  1140. (CHIP_IS_E3B0(bp)) ?
  1141. PBF_REG_CREDIT_Q1 :
  1142. PBF_REG_P1_CREDIT,
  1143. (CHIP_IS_E3B0(bp)) ?
  1144. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1145. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1146. {4, (CHIP_IS_E3B0(bp)) ?
  1147. PBF_REG_INIT_CRD_LB_Q :
  1148. PBF_REG_P4_INIT_CRD,
  1149. (CHIP_IS_E3B0(bp)) ?
  1150. PBF_REG_CREDIT_LB_Q :
  1151. PBF_REG_P4_CREDIT,
  1152. (CHIP_IS_E3B0(bp)) ?
  1153. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1154. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1155. };
  1156. int i;
  1157. /* Verify the command queues are flushed P0, P1, P4 */
  1158. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1159. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1160. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1161. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1162. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1163. }
  1164. #define OP_GEN_PARAM(param) \
  1165. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1166. #define OP_GEN_TYPE(type) \
  1167. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1168. #define OP_GEN_AGG_VECT(index) \
  1169. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1170. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1171. {
  1172. u32 op_gen_command = 0;
  1173. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1174. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1175. int ret = 0;
  1176. if (REG_RD(bp, comp_addr)) {
  1177. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1178. return 1;
  1179. }
  1180. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1181. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1182. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1183. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1184. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1185. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1186. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1187. BNX2X_ERR("FW final cleanup did not succeed\n");
  1188. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1189. (REG_RD(bp, comp_addr)));
  1190. bnx2x_panic();
  1191. return 1;
  1192. }
  1193. /* Zero completion for next FLR */
  1194. REG_WR(bp, comp_addr, 0);
  1195. return ret;
  1196. }
  1197. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1198. {
  1199. u16 status;
  1200. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1201. return status & PCI_EXP_DEVSTA_TRPND;
  1202. }
  1203. /* PF FLR specific routines
  1204. */
  1205. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1206. {
  1207. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1208. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1209. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1210. "CFC PF usage counter timed out",
  1211. poll_cnt))
  1212. return 1;
  1213. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1214. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1215. DORQ_REG_PF_USAGE_CNT,
  1216. "DQ PF usage counter timed out",
  1217. poll_cnt))
  1218. return 1;
  1219. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1220. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1221. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1222. "QM PF usage counter timed out",
  1223. poll_cnt))
  1224. return 1;
  1225. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1226. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1227. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1228. "Timers VNIC usage counter timed out",
  1229. poll_cnt))
  1230. return 1;
  1231. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1232. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1233. "Timers NUM_SCANS usage counter timed out",
  1234. poll_cnt))
  1235. return 1;
  1236. /* Wait DMAE PF usage counter to zero */
  1237. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1238. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1239. "DMAE command register timed out",
  1240. poll_cnt))
  1241. return 1;
  1242. return 0;
  1243. }
  1244. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1245. {
  1246. u32 val;
  1247. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1248. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1249. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1250. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1251. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1252. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1253. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1254. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1255. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1256. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1257. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1258. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1259. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1260. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1261. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1262. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1263. val);
  1264. }
  1265. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1266. {
  1267. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1268. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1269. /* Re-enable PF target read access */
  1270. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1271. /* Poll HW usage counters */
  1272. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1273. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1274. return -EBUSY;
  1275. /* Zero the igu 'trailing edge' and 'leading edge' */
  1276. /* Send the FW cleanup command */
  1277. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1278. return -EBUSY;
  1279. /* ATC cleanup */
  1280. /* Verify TX hw is flushed */
  1281. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1282. /* Wait 100ms (not adjusted according to platform) */
  1283. msleep(100);
  1284. /* Verify no pending pci transactions */
  1285. if (bnx2x_is_pcie_pending(bp->pdev))
  1286. BNX2X_ERR("PCIE Transactions still pending\n");
  1287. /* Debug */
  1288. bnx2x_hw_enable_status(bp);
  1289. /*
  1290. * Master enable - Due to WB DMAE writes performed before this
  1291. * register is re-initialized as part of the regular function init
  1292. */
  1293. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1294. return 0;
  1295. }
  1296. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1297. {
  1298. int port = BP_PORT(bp);
  1299. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1300. u32 val = REG_RD(bp, addr);
  1301. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1302. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1303. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1304. if (msix) {
  1305. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1306. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1307. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1308. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1309. if (single_msix)
  1310. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1311. } else if (msi) {
  1312. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1313. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1314. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1315. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1316. } else {
  1317. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1318. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1319. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1320. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1321. if (!CHIP_IS_E1(bp)) {
  1322. DP(NETIF_MSG_IFUP,
  1323. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1324. REG_WR(bp, addr, val);
  1325. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1326. }
  1327. }
  1328. if (CHIP_IS_E1(bp))
  1329. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1330. DP(NETIF_MSG_IFUP,
  1331. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1332. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1333. REG_WR(bp, addr, val);
  1334. /*
  1335. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1336. */
  1337. mmiowb();
  1338. barrier();
  1339. if (!CHIP_IS_E1(bp)) {
  1340. /* init leading/trailing edge */
  1341. if (IS_MF(bp)) {
  1342. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1343. if (bp->port.pmf)
  1344. /* enable nig and gpio3 attention */
  1345. val |= 0x1100;
  1346. } else
  1347. val = 0xffff;
  1348. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1349. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1350. }
  1351. /* Make sure that interrupts are indeed enabled from here on */
  1352. mmiowb();
  1353. }
  1354. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1355. {
  1356. u32 val;
  1357. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1358. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1359. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1360. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1361. if (msix) {
  1362. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1363. IGU_PF_CONF_SINGLE_ISR_EN);
  1364. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1365. IGU_PF_CONF_ATTN_BIT_EN);
  1366. if (single_msix)
  1367. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1368. } else if (msi) {
  1369. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1370. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1371. IGU_PF_CONF_ATTN_BIT_EN |
  1372. IGU_PF_CONF_SINGLE_ISR_EN);
  1373. } else {
  1374. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1375. val |= (IGU_PF_CONF_INT_LINE_EN |
  1376. IGU_PF_CONF_ATTN_BIT_EN |
  1377. IGU_PF_CONF_SINGLE_ISR_EN);
  1378. }
  1379. /* Clean previous status - need to configure igu prior to ack*/
  1380. if ((!msix) || single_msix) {
  1381. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1382. bnx2x_ack_int(bp);
  1383. }
  1384. val |= IGU_PF_CONF_FUNC_EN;
  1385. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1386. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1387. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1388. if (val & IGU_PF_CONF_INT_LINE_EN)
  1389. pci_intx(bp->pdev, true);
  1390. barrier();
  1391. /* init leading/trailing edge */
  1392. if (IS_MF(bp)) {
  1393. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1394. if (bp->port.pmf)
  1395. /* enable nig and gpio3 attention */
  1396. val |= 0x1100;
  1397. } else
  1398. val = 0xffff;
  1399. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1400. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1401. /* Make sure that interrupts are indeed enabled from here on */
  1402. mmiowb();
  1403. }
  1404. void bnx2x_int_enable(struct bnx2x *bp)
  1405. {
  1406. if (bp->common.int_block == INT_BLOCK_HC)
  1407. bnx2x_hc_int_enable(bp);
  1408. else
  1409. bnx2x_igu_int_enable(bp);
  1410. }
  1411. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1412. {
  1413. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1414. int i, offset;
  1415. if (disable_hw)
  1416. /* prevent the HW from sending interrupts */
  1417. bnx2x_int_disable(bp);
  1418. /* make sure all ISRs are done */
  1419. if (msix) {
  1420. synchronize_irq(bp->msix_table[0].vector);
  1421. offset = 1;
  1422. if (CNIC_SUPPORT(bp))
  1423. offset++;
  1424. for_each_eth_queue(bp, i)
  1425. synchronize_irq(bp->msix_table[offset++].vector);
  1426. } else
  1427. synchronize_irq(bp->pdev->irq);
  1428. /* make sure sp_task is not running */
  1429. cancel_delayed_work(&bp->sp_task);
  1430. cancel_delayed_work(&bp->period_task);
  1431. flush_workqueue(bnx2x_wq);
  1432. }
  1433. /* fast path */
  1434. /*
  1435. * General service functions
  1436. */
  1437. /* Return true if succeeded to acquire the lock */
  1438. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1439. {
  1440. u32 lock_status;
  1441. u32 resource_bit = (1 << resource);
  1442. int func = BP_FUNC(bp);
  1443. u32 hw_lock_control_reg;
  1444. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1445. "Trying to take a lock on resource %d\n", resource);
  1446. /* Validating that the resource is within range */
  1447. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1448. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1449. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1450. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1451. return false;
  1452. }
  1453. if (func <= 5)
  1454. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1455. else
  1456. hw_lock_control_reg =
  1457. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1458. /* Try to acquire the lock */
  1459. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1460. lock_status = REG_RD(bp, hw_lock_control_reg);
  1461. if (lock_status & resource_bit)
  1462. return true;
  1463. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1464. "Failed to get a lock on resource %d\n", resource);
  1465. return false;
  1466. }
  1467. /**
  1468. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1469. *
  1470. * @bp: driver handle
  1471. *
  1472. * Returns the recovery leader resource id according to the engine this function
  1473. * belongs to. Currently only only 2 engines is supported.
  1474. */
  1475. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1476. {
  1477. if (BP_PATH(bp))
  1478. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1479. else
  1480. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1481. }
  1482. /**
  1483. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1484. *
  1485. * @bp: driver handle
  1486. *
  1487. * Tries to acquire a leader lock for current engine.
  1488. */
  1489. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1490. {
  1491. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1492. }
  1493. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1494. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1495. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1496. {
  1497. /* Set the interrupt occurred bit for the sp-task to recognize it
  1498. * must ack the interrupt and transition according to the IGU
  1499. * state machine.
  1500. */
  1501. atomic_set(&bp->interrupt_occurred, 1);
  1502. /* The sp_task must execute only after this bit
  1503. * is set, otherwise we will get out of sync and miss all
  1504. * further interrupts. Hence, the barrier.
  1505. */
  1506. smp_wmb();
  1507. /* schedule sp_task to workqueue */
  1508. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1509. }
  1510. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1511. {
  1512. struct bnx2x *bp = fp->bp;
  1513. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1514. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1515. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1516. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1517. DP(BNX2X_MSG_SP,
  1518. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1519. fp->index, cid, command, bp->state,
  1520. rr_cqe->ramrod_cqe.ramrod_type);
  1521. /* If cid is within VF range, replace the slowpath object with the
  1522. * one corresponding to this VF
  1523. */
  1524. if (cid >= BNX2X_FIRST_VF_CID &&
  1525. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1526. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1527. switch (command) {
  1528. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1529. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1530. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1531. break;
  1532. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1533. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1534. drv_cmd = BNX2X_Q_CMD_SETUP;
  1535. break;
  1536. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1537. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1538. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1539. break;
  1540. case (RAMROD_CMD_ID_ETH_HALT):
  1541. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1542. drv_cmd = BNX2X_Q_CMD_HALT;
  1543. break;
  1544. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1545. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1546. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1547. break;
  1548. case (RAMROD_CMD_ID_ETH_EMPTY):
  1549. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1550. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1551. break;
  1552. default:
  1553. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1554. command, fp->index);
  1555. return;
  1556. }
  1557. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1558. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1559. /* q_obj->complete_cmd() failure means that this was
  1560. * an unexpected completion.
  1561. *
  1562. * In this case we don't want to increase the bp->spq_left
  1563. * because apparently we haven't sent this command the first
  1564. * place.
  1565. */
  1566. #ifdef BNX2X_STOP_ON_ERROR
  1567. bnx2x_panic();
  1568. #else
  1569. return;
  1570. #endif
  1571. /* SRIOV: reschedule any 'in_progress' operations */
  1572. bnx2x_iov_sp_event(bp, cid, true);
  1573. smp_mb__before_atomic_inc();
  1574. atomic_inc(&bp->cq_spq_left);
  1575. /* push the change in bp->spq_left and towards the memory */
  1576. smp_mb__after_atomic_inc();
  1577. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1578. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1579. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1580. /* if Q update ramrod is completed for last Q in AFEX vif set
  1581. * flow, then ACK MCP at the end
  1582. *
  1583. * mark pending ACK to MCP bit.
  1584. * prevent case that both bits are cleared.
  1585. * At the end of load/unload driver checks that
  1586. * sp_state is cleared, and this order prevents
  1587. * races
  1588. */
  1589. smp_mb__before_clear_bit();
  1590. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1591. wmb();
  1592. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1593. smp_mb__after_clear_bit();
  1594. /* schedule the sp task as mcp ack is required */
  1595. bnx2x_schedule_sp_task(bp);
  1596. }
  1597. return;
  1598. }
  1599. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1600. {
  1601. struct bnx2x *bp = netdev_priv(dev_instance);
  1602. u16 status = bnx2x_ack_int(bp);
  1603. u16 mask;
  1604. int i;
  1605. u8 cos;
  1606. /* Return here if interrupt is shared and it's not for us */
  1607. if (unlikely(status == 0)) {
  1608. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1609. return IRQ_NONE;
  1610. }
  1611. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1612. #ifdef BNX2X_STOP_ON_ERROR
  1613. if (unlikely(bp->panic))
  1614. return IRQ_HANDLED;
  1615. #endif
  1616. for_each_eth_queue(bp, i) {
  1617. struct bnx2x_fastpath *fp = &bp->fp[i];
  1618. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1619. if (status & mask) {
  1620. /* Handle Rx or Tx according to SB id */
  1621. for_each_cos_in_tx_queue(fp, cos)
  1622. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1623. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1624. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1625. status &= ~mask;
  1626. }
  1627. }
  1628. if (CNIC_SUPPORT(bp)) {
  1629. mask = 0x2;
  1630. if (status & (mask | 0x1)) {
  1631. struct cnic_ops *c_ops = NULL;
  1632. rcu_read_lock();
  1633. c_ops = rcu_dereference(bp->cnic_ops);
  1634. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1635. CNIC_DRV_STATE_HANDLES_IRQ))
  1636. c_ops->cnic_handler(bp->cnic_data, NULL);
  1637. rcu_read_unlock();
  1638. status &= ~mask;
  1639. }
  1640. }
  1641. if (unlikely(status & 0x1)) {
  1642. /* schedule sp task to perform default status block work, ack
  1643. * attentions and enable interrupts.
  1644. */
  1645. bnx2x_schedule_sp_task(bp);
  1646. status &= ~0x1;
  1647. if (!status)
  1648. return IRQ_HANDLED;
  1649. }
  1650. if (unlikely(status))
  1651. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1652. status);
  1653. return IRQ_HANDLED;
  1654. }
  1655. /* Link */
  1656. /*
  1657. * General service functions
  1658. */
  1659. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1660. {
  1661. u32 lock_status;
  1662. u32 resource_bit = (1 << resource);
  1663. int func = BP_FUNC(bp);
  1664. u32 hw_lock_control_reg;
  1665. int cnt;
  1666. /* Validating that the resource is within range */
  1667. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1668. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1669. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1670. return -EINVAL;
  1671. }
  1672. if (func <= 5) {
  1673. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1674. } else {
  1675. hw_lock_control_reg =
  1676. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1677. }
  1678. /* Validating that the resource is not already taken */
  1679. lock_status = REG_RD(bp, hw_lock_control_reg);
  1680. if (lock_status & resource_bit) {
  1681. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1682. lock_status, resource_bit);
  1683. return -EEXIST;
  1684. }
  1685. /* Try for 5 second every 5ms */
  1686. for (cnt = 0; cnt < 1000; cnt++) {
  1687. /* Try to acquire the lock */
  1688. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1689. lock_status = REG_RD(bp, hw_lock_control_reg);
  1690. if (lock_status & resource_bit)
  1691. return 0;
  1692. usleep_range(5000, 10000);
  1693. }
  1694. BNX2X_ERR("Timeout\n");
  1695. return -EAGAIN;
  1696. }
  1697. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1698. {
  1699. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1700. }
  1701. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1702. {
  1703. u32 lock_status;
  1704. u32 resource_bit = (1 << resource);
  1705. int func = BP_FUNC(bp);
  1706. u32 hw_lock_control_reg;
  1707. /* Validating that the resource is within range */
  1708. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1709. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1710. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1711. return -EINVAL;
  1712. }
  1713. if (func <= 5) {
  1714. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1715. } else {
  1716. hw_lock_control_reg =
  1717. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1718. }
  1719. /* Validating that the resource is currently taken */
  1720. lock_status = REG_RD(bp, hw_lock_control_reg);
  1721. if (!(lock_status & resource_bit)) {
  1722. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1723. lock_status, resource_bit);
  1724. return -EFAULT;
  1725. }
  1726. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1727. return 0;
  1728. }
  1729. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1730. {
  1731. /* The GPIO should be swapped if swap register is set and active */
  1732. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1733. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1734. int gpio_shift = gpio_num +
  1735. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1736. u32 gpio_mask = (1 << gpio_shift);
  1737. u32 gpio_reg;
  1738. int value;
  1739. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1740. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1741. return -EINVAL;
  1742. }
  1743. /* read GPIO value */
  1744. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1745. /* get the requested pin value */
  1746. if ((gpio_reg & gpio_mask) == gpio_mask)
  1747. value = 1;
  1748. else
  1749. value = 0;
  1750. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1751. return value;
  1752. }
  1753. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1754. {
  1755. /* The GPIO should be swapped if swap register is set and active */
  1756. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1757. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1758. int gpio_shift = gpio_num +
  1759. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1760. u32 gpio_mask = (1 << gpio_shift);
  1761. u32 gpio_reg;
  1762. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1763. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1764. return -EINVAL;
  1765. }
  1766. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1767. /* read GPIO and mask except the float bits */
  1768. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1769. switch (mode) {
  1770. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1771. DP(NETIF_MSG_LINK,
  1772. "Set GPIO %d (shift %d) -> output low\n",
  1773. gpio_num, gpio_shift);
  1774. /* clear FLOAT and set CLR */
  1775. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1776. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1777. break;
  1778. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1779. DP(NETIF_MSG_LINK,
  1780. "Set GPIO %d (shift %d) -> output high\n",
  1781. gpio_num, gpio_shift);
  1782. /* clear FLOAT and set SET */
  1783. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1784. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1785. break;
  1786. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1787. DP(NETIF_MSG_LINK,
  1788. "Set GPIO %d (shift %d) -> input\n",
  1789. gpio_num, gpio_shift);
  1790. /* set FLOAT */
  1791. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1792. break;
  1793. default:
  1794. break;
  1795. }
  1796. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1797. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1798. return 0;
  1799. }
  1800. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1801. {
  1802. u32 gpio_reg = 0;
  1803. int rc = 0;
  1804. /* Any port swapping should be handled by caller. */
  1805. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1806. /* read GPIO and mask except the float bits */
  1807. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1808. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1809. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1810. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1811. switch (mode) {
  1812. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1813. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1814. /* set CLR */
  1815. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1816. break;
  1817. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1818. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1819. /* set SET */
  1820. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1821. break;
  1822. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1823. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1824. /* set FLOAT */
  1825. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1826. break;
  1827. default:
  1828. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1829. rc = -EINVAL;
  1830. break;
  1831. }
  1832. if (rc == 0)
  1833. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1834. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1835. return rc;
  1836. }
  1837. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1838. {
  1839. /* The GPIO should be swapped if swap register is set and active */
  1840. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1841. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1842. int gpio_shift = gpio_num +
  1843. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1844. u32 gpio_mask = (1 << gpio_shift);
  1845. u32 gpio_reg;
  1846. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1847. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1848. return -EINVAL;
  1849. }
  1850. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1851. /* read GPIO int */
  1852. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1853. switch (mode) {
  1854. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1855. DP(NETIF_MSG_LINK,
  1856. "Clear GPIO INT %d (shift %d) -> output low\n",
  1857. gpio_num, gpio_shift);
  1858. /* clear SET and set CLR */
  1859. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1860. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1861. break;
  1862. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1863. DP(NETIF_MSG_LINK,
  1864. "Set GPIO INT %d (shift %d) -> output high\n",
  1865. gpio_num, gpio_shift);
  1866. /* clear CLR and set SET */
  1867. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1868. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1869. break;
  1870. default:
  1871. break;
  1872. }
  1873. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1874. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1875. return 0;
  1876. }
  1877. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1878. {
  1879. u32 spio_reg;
  1880. /* Only 2 SPIOs are configurable */
  1881. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1882. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1883. return -EINVAL;
  1884. }
  1885. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1886. /* read SPIO and mask except the float bits */
  1887. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1888. switch (mode) {
  1889. case MISC_SPIO_OUTPUT_LOW:
  1890. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1891. /* clear FLOAT and set CLR */
  1892. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1893. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1894. break;
  1895. case MISC_SPIO_OUTPUT_HIGH:
  1896. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1897. /* clear FLOAT and set SET */
  1898. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1899. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1900. break;
  1901. case MISC_SPIO_INPUT_HI_Z:
  1902. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1903. /* set FLOAT */
  1904. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1905. break;
  1906. default:
  1907. break;
  1908. }
  1909. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1910. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1911. return 0;
  1912. }
  1913. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1914. {
  1915. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1916. switch (bp->link_vars.ieee_fc &
  1917. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1918. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1919. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1920. ADVERTISED_Pause);
  1921. break;
  1922. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1923. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1924. ADVERTISED_Pause);
  1925. break;
  1926. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1927. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1928. break;
  1929. default:
  1930. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1931. ADVERTISED_Pause);
  1932. break;
  1933. }
  1934. }
  1935. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1936. {
  1937. /* Initialize link parameters structure variables
  1938. * It is recommended to turn off RX FC for jumbo frames
  1939. * for better performance
  1940. */
  1941. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1942. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1943. else
  1944. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1945. }
  1946. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1947. {
  1948. u32 pause_enabled = 0;
  1949. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1950. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1951. pause_enabled = 1;
  1952. REG_WR(bp, BAR_USTRORM_INTMEM +
  1953. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1954. pause_enabled);
  1955. }
  1956. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1957. pause_enabled ? "enabled" : "disabled");
  1958. }
  1959. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1960. {
  1961. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1962. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1963. if (!BP_NOMCP(bp)) {
  1964. bnx2x_set_requested_fc(bp);
  1965. bnx2x_acquire_phy_lock(bp);
  1966. if (load_mode == LOAD_DIAG) {
  1967. struct link_params *lp = &bp->link_params;
  1968. lp->loopback_mode = LOOPBACK_XGXS;
  1969. /* do PHY loopback at 10G speed, if possible */
  1970. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1971. if (lp->speed_cap_mask[cfx_idx] &
  1972. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1973. lp->req_line_speed[cfx_idx] =
  1974. SPEED_10000;
  1975. else
  1976. lp->req_line_speed[cfx_idx] =
  1977. SPEED_1000;
  1978. }
  1979. }
  1980. if (load_mode == LOAD_LOOPBACK_EXT) {
  1981. struct link_params *lp = &bp->link_params;
  1982. lp->loopback_mode = LOOPBACK_EXT;
  1983. }
  1984. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1985. bnx2x_release_phy_lock(bp);
  1986. bnx2x_init_dropless_fc(bp);
  1987. bnx2x_calc_fc_adv(bp);
  1988. if (bp->link_vars.link_up) {
  1989. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1990. bnx2x_link_report(bp);
  1991. }
  1992. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1993. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1994. return rc;
  1995. }
  1996. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1997. return -EINVAL;
  1998. }
  1999. void bnx2x_link_set(struct bnx2x *bp)
  2000. {
  2001. if (!BP_NOMCP(bp)) {
  2002. bnx2x_acquire_phy_lock(bp);
  2003. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2004. bnx2x_release_phy_lock(bp);
  2005. bnx2x_init_dropless_fc(bp);
  2006. bnx2x_calc_fc_adv(bp);
  2007. } else
  2008. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2009. }
  2010. static void bnx2x__link_reset(struct bnx2x *bp)
  2011. {
  2012. if (!BP_NOMCP(bp)) {
  2013. bnx2x_acquire_phy_lock(bp);
  2014. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2015. bnx2x_release_phy_lock(bp);
  2016. } else
  2017. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2018. }
  2019. void bnx2x_force_link_reset(struct bnx2x *bp)
  2020. {
  2021. bnx2x_acquire_phy_lock(bp);
  2022. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2023. bnx2x_release_phy_lock(bp);
  2024. }
  2025. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2026. {
  2027. u8 rc = 0;
  2028. if (!BP_NOMCP(bp)) {
  2029. bnx2x_acquire_phy_lock(bp);
  2030. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2031. is_serdes);
  2032. bnx2x_release_phy_lock(bp);
  2033. } else
  2034. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2035. return rc;
  2036. }
  2037. /* Calculates the sum of vn_min_rates.
  2038. It's needed for further normalizing of the min_rates.
  2039. Returns:
  2040. sum of vn_min_rates.
  2041. or
  2042. 0 - if all the min_rates are 0.
  2043. In the later case fairness algorithm should be deactivated.
  2044. If not all min_rates are zero then those that are zeroes will be set to 1.
  2045. */
  2046. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2047. struct cmng_init_input *input)
  2048. {
  2049. int all_zero = 1;
  2050. int vn;
  2051. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2052. u32 vn_cfg = bp->mf_config[vn];
  2053. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2054. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2055. /* Skip hidden vns */
  2056. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2057. vn_min_rate = 0;
  2058. /* If min rate is zero - set it to 1 */
  2059. else if (!vn_min_rate)
  2060. vn_min_rate = DEF_MIN_RATE;
  2061. else
  2062. all_zero = 0;
  2063. input->vnic_min_rate[vn] = vn_min_rate;
  2064. }
  2065. /* if ETS or all min rates are zeros - disable fairness */
  2066. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2067. input->flags.cmng_enables &=
  2068. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2069. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2070. } else if (all_zero) {
  2071. input->flags.cmng_enables &=
  2072. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2073. DP(NETIF_MSG_IFUP,
  2074. "All MIN values are zeroes fairness will be disabled\n");
  2075. } else
  2076. input->flags.cmng_enables |=
  2077. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2078. }
  2079. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2080. struct cmng_init_input *input)
  2081. {
  2082. u16 vn_max_rate;
  2083. u32 vn_cfg = bp->mf_config[vn];
  2084. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2085. vn_max_rate = 0;
  2086. else {
  2087. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2088. if (IS_MF_SI(bp)) {
  2089. /* maxCfg in percents of linkspeed */
  2090. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2091. } else /* SD modes */
  2092. /* maxCfg is absolute in 100Mb units */
  2093. vn_max_rate = maxCfg * 100;
  2094. }
  2095. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2096. input->vnic_max_rate[vn] = vn_max_rate;
  2097. }
  2098. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2099. {
  2100. if (CHIP_REV_IS_SLOW(bp))
  2101. return CMNG_FNS_NONE;
  2102. if (IS_MF(bp))
  2103. return CMNG_FNS_MINMAX;
  2104. return CMNG_FNS_NONE;
  2105. }
  2106. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2107. {
  2108. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2109. if (BP_NOMCP(bp))
  2110. return; /* what should be the default value in this case */
  2111. /* For 2 port configuration the absolute function number formula
  2112. * is:
  2113. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2114. *
  2115. * and there are 4 functions per port
  2116. *
  2117. * For 4 port configuration it is
  2118. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2119. *
  2120. * and there are 2 functions per port
  2121. */
  2122. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2123. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2124. if (func >= E1H_FUNC_MAX)
  2125. break;
  2126. bp->mf_config[vn] =
  2127. MF_CFG_RD(bp, func_mf_config[func].config);
  2128. }
  2129. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2130. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2131. bp->flags |= MF_FUNC_DIS;
  2132. } else {
  2133. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2134. bp->flags &= ~MF_FUNC_DIS;
  2135. }
  2136. }
  2137. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2138. {
  2139. struct cmng_init_input input;
  2140. memset(&input, 0, sizeof(struct cmng_init_input));
  2141. input.port_rate = bp->link_vars.line_speed;
  2142. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2143. int vn;
  2144. /* read mf conf from shmem */
  2145. if (read_cfg)
  2146. bnx2x_read_mf_cfg(bp);
  2147. /* vn_weight_sum and enable fairness if not 0 */
  2148. bnx2x_calc_vn_min(bp, &input);
  2149. /* calculate and set min-max rate for each vn */
  2150. if (bp->port.pmf)
  2151. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2152. bnx2x_calc_vn_max(bp, vn, &input);
  2153. /* always enable rate shaping and fairness */
  2154. input.flags.cmng_enables |=
  2155. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2156. bnx2x_init_cmng(&input, &bp->cmng);
  2157. return;
  2158. }
  2159. /* rate shaping and fairness are disabled */
  2160. DP(NETIF_MSG_IFUP,
  2161. "rate shaping and fairness are disabled\n");
  2162. }
  2163. static void storm_memset_cmng(struct bnx2x *bp,
  2164. struct cmng_init *cmng,
  2165. u8 port)
  2166. {
  2167. int vn;
  2168. size_t size = sizeof(struct cmng_struct_per_port);
  2169. u32 addr = BAR_XSTRORM_INTMEM +
  2170. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2171. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2172. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2173. int func = func_by_vn(bp, vn);
  2174. addr = BAR_XSTRORM_INTMEM +
  2175. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2176. size = sizeof(struct rate_shaping_vars_per_vn);
  2177. __storm_memset_struct(bp, addr, size,
  2178. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2179. addr = BAR_XSTRORM_INTMEM +
  2180. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2181. size = sizeof(struct fairness_vars_per_vn);
  2182. __storm_memset_struct(bp, addr, size,
  2183. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2184. }
  2185. }
  2186. /* init cmng mode in HW according to local configuration */
  2187. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2188. {
  2189. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2190. if (cmng_fns != CMNG_FNS_NONE) {
  2191. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2192. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2193. } else {
  2194. /* rate shaping and fairness are disabled */
  2195. DP(NETIF_MSG_IFUP,
  2196. "single function mode without fairness\n");
  2197. }
  2198. }
  2199. /* This function is called upon link interrupt */
  2200. static void bnx2x_link_attn(struct bnx2x *bp)
  2201. {
  2202. /* Make sure that we are synced with the current statistics */
  2203. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2204. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2205. bnx2x_init_dropless_fc(bp);
  2206. if (bp->link_vars.link_up) {
  2207. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2208. struct host_port_stats *pstats;
  2209. pstats = bnx2x_sp(bp, port_stats);
  2210. /* reset old mac stats */
  2211. memset(&(pstats->mac_stx[0]), 0,
  2212. sizeof(struct mac_stx));
  2213. }
  2214. if (bp->state == BNX2X_STATE_OPEN)
  2215. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2216. }
  2217. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2218. bnx2x_set_local_cmng(bp);
  2219. __bnx2x_link_report(bp);
  2220. if (IS_MF(bp))
  2221. bnx2x_link_sync_notify(bp);
  2222. }
  2223. void bnx2x__link_status_update(struct bnx2x *bp)
  2224. {
  2225. if (bp->state != BNX2X_STATE_OPEN)
  2226. return;
  2227. /* read updated dcb configuration */
  2228. if (IS_PF(bp)) {
  2229. bnx2x_dcbx_pmf_update(bp);
  2230. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2231. if (bp->link_vars.link_up)
  2232. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2233. else
  2234. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2235. /* indicate link status */
  2236. bnx2x_link_report(bp);
  2237. } else { /* VF */
  2238. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2239. SUPPORTED_10baseT_Full |
  2240. SUPPORTED_100baseT_Half |
  2241. SUPPORTED_100baseT_Full |
  2242. SUPPORTED_1000baseT_Full |
  2243. SUPPORTED_2500baseX_Full |
  2244. SUPPORTED_10000baseT_Full |
  2245. SUPPORTED_TP |
  2246. SUPPORTED_FIBRE |
  2247. SUPPORTED_Autoneg |
  2248. SUPPORTED_Pause |
  2249. SUPPORTED_Asym_Pause);
  2250. bp->port.advertising[0] = bp->port.supported[0];
  2251. bp->link_params.bp = bp;
  2252. bp->link_params.port = BP_PORT(bp);
  2253. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2254. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2255. bp->link_params.req_line_speed[0] = SPEED_10000;
  2256. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2257. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2258. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2259. bp->link_vars.line_speed = SPEED_10000;
  2260. bp->link_vars.link_status =
  2261. (LINK_STATUS_LINK_UP |
  2262. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2263. bp->link_vars.link_up = 1;
  2264. bp->link_vars.duplex = DUPLEX_FULL;
  2265. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2266. __bnx2x_link_report(bp);
  2267. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2268. }
  2269. }
  2270. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2271. u16 vlan_val, u8 allowed_prio)
  2272. {
  2273. struct bnx2x_func_state_params func_params = {NULL};
  2274. struct bnx2x_func_afex_update_params *f_update_params =
  2275. &func_params.params.afex_update;
  2276. func_params.f_obj = &bp->func_obj;
  2277. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2278. /* no need to wait for RAMROD completion, so don't
  2279. * set RAMROD_COMP_WAIT flag
  2280. */
  2281. f_update_params->vif_id = vifid;
  2282. f_update_params->afex_default_vlan = vlan_val;
  2283. f_update_params->allowed_priorities = allowed_prio;
  2284. /* if ramrod can not be sent, response to MCP immediately */
  2285. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2286. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2287. return 0;
  2288. }
  2289. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2290. u16 vif_index, u8 func_bit_map)
  2291. {
  2292. struct bnx2x_func_state_params func_params = {NULL};
  2293. struct bnx2x_func_afex_viflists_params *update_params =
  2294. &func_params.params.afex_viflists;
  2295. int rc;
  2296. u32 drv_msg_code;
  2297. /* validate only LIST_SET and LIST_GET are received from switch */
  2298. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2299. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2300. cmd_type);
  2301. func_params.f_obj = &bp->func_obj;
  2302. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2303. /* set parameters according to cmd_type */
  2304. update_params->afex_vif_list_command = cmd_type;
  2305. update_params->vif_list_index = vif_index;
  2306. update_params->func_bit_map =
  2307. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2308. update_params->func_to_clear = 0;
  2309. drv_msg_code =
  2310. (cmd_type == VIF_LIST_RULE_GET) ?
  2311. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2312. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2313. /* if ramrod can not be sent, respond to MCP immediately for
  2314. * SET and GET requests (other are not triggered from MCP)
  2315. */
  2316. rc = bnx2x_func_state_change(bp, &func_params);
  2317. if (rc < 0)
  2318. bnx2x_fw_command(bp, drv_msg_code, 0);
  2319. return 0;
  2320. }
  2321. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2322. {
  2323. struct afex_stats afex_stats;
  2324. u32 func = BP_ABS_FUNC(bp);
  2325. u32 mf_config;
  2326. u16 vlan_val;
  2327. u32 vlan_prio;
  2328. u16 vif_id;
  2329. u8 allowed_prio;
  2330. u8 vlan_mode;
  2331. u32 addr_to_write, vifid, addrs, stats_type, i;
  2332. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2333. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2334. DP(BNX2X_MSG_MCP,
  2335. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2336. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2337. }
  2338. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2339. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2340. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2341. DP(BNX2X_MSG_MCP,
  2342. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2343. vifid, addrs);
  2344. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2345. addrs);
  2346. }
  2347. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2348. addr_to_write = SHMEM2_RD(bp,
  2349. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2350. stats_type = SHMEM2_RD(bp,
  2351. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2352. DP(BNX2X_MSG_MCP,
  2353. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2354. addr_to_write);
  2355. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2356. /* write response to scratchpad, for MCP */
  2357. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2358. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2359. *(((u32 *)(&afex_stats))+i));
  2360. /* send ack message to MCP */
  2361. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2362. }
  2363. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2364. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2365. bp->mf_config[BP_VN(bp)] = mf_config;
  2366. DP(BNX2X_MSG_MCP,
  2367. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2368. mf_config);
  2369. /* if VIF_SET is "enabled" */
  2370. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2371. /* set rate limit directly to internal RAM */
  2372. struct cmng_init_input cmng_input;
  2373. struct rate_shaping_vars_per_vn m_rs_vn;
  2374. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2375. u32 addr = BAR_XSTRORM_INTMEM +
  2376. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2377. bp->mf_config[BP_VN(bp)] = mf_config;
  2378. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2379. m_rs_vn.vn_counter.rate =
  2380. cmng_input.vnic_max_rate[BP_VN(bp)];
  2381. m_rs_vn.vn_counter.quota =
  2382. (m_rs_vn.vn_counter.rate *
  2383. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2384. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2385. /* read relevant values from mf_cfg struct in shmem */
  2386. vif_id =
  2387. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2388. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2389. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2390. vlan_val =
  2391. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2392. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2393. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2394. vlan_prio = (mf_config &
  2395. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2396. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2397. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2398. vlan_mode =
  2399. (MF_CFG_RD(bp,
  2400. func_mf_config[func].afex_config) &
  2401. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2402. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2403. allowed_prio =
  2404. (MF_CFG_RD(bp,
  2405. func_mf_config[func].afex_config) &
  2406. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2407. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2408. /* send ramrod to FW, return in case of failure */
  2409. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2410. allowed_prio))
  2411. return;
  2412. bp->afex_def_vlan_tag = vlan_val;
  2413. bp->afex_vlan_mode = vlan_mode;
  2414. } else {
  2415. /* notify link down because BP->flags is disabled */
  2416. bnx2x_link_report(bp);
  2417. /* send INVALID VIF ramrod to FW */
  2418. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2419. /* Reset the default afex VLAN */
  2420. bp->afex_def_vlan_tag = -1;
  2421. }
  2422. }
  2423. }
  2424. static void bnx2x_pmf_update(struct bnx2x *bp)
  2425. {
  2426. int port = BP_PORT(bp);
  2427. u32 val;
  2428. bp->port.pmf = 1;
  2429. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2430. /*
  2431. * We need the mb() to ensure the ordering between the writing to
  2432. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2433. */
  2434. smp_mb();
  2435. /* queue a periodic task */
  2436. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2437. bnx2x_dcbx_pmf_update(bp);
  2438. /* enable nig attention */
  2439. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2440. if (bp->common.int_block == INT_BLOCK_HC) {
  2441. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2442. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2443. } else if (!CHIP_IS_E1x(bp)) {
  2444. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2445. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2446. }
  2447. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2448. }
  2449. /* end of Link */
  2450. /* slow path */
  2451. /*
  2452. * General service functions
  2453. */
  2454. /* send the MCP a request, block until there is a reply */
  2455. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2456. {
  2457. int mb_idx = BP_FW_MB_IDX(bp);
  2458. u32 seq;
  2459. u32 rc = 0;
  2460. u32 cnt = 1;
  2461. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2462. mutex_lock(&bp->fw_mb_mutex);
  2463. seq = ++bp->fw_seq;
  2464. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2465. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2466. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2467. (command | seq), param);
  2468. do {
  2469. /* let the FW do it's magic ... */
  2470. msleep(delay);
  2471. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2472. /* Give the FW up to 5 second (500*10ms) */
  2473. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2474. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2475. cnt*delay, rc, seq);
  2476. /* is this a reply to our command? */
  2477. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2478. rc &= FW_MSG_CODE_MASK;
  2479. else {
  2480. /* FW BUG! */
  2481. BNX2X_ERR("FW failed to respond!\n");
  2482. bnx2x_fw_dump(bp);
  2483. rc = 0;
  2484. }
  2485. mutex_unlock(&bp->fw_mb_mutex);
  2486. return rc;
  2487. }
  2488. static void storm_memset_func_cfg(struct bnx2x *bp,
  2489. struct tstorm_eth_function_common_config *tcfg,
  2490. u16 abs_fid)
  2491. {
  2492. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2493. u32 addr = BAR_TSTRORM_INTMEM +
  2494. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2495. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2496. }
  2497. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2498. {
  2499. if (CHIP_IS_E1x(bp)) {
  2500. struct tstorm_eth_function_common_config tcfg = {0};
  2501. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2502. }
  2503. /* Enable the function in the FW */
  2504. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2505. storm_memset_func_en(bp, p->func_id, 1);
  2506. /* spq */
  2507. if (p->func_flgs & FUNC_FLG_SPQ) {
  2508. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2509. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2510. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2511. }
  2512. }
  2513. /**
  2514. * bnx2x_get_common_flags - Return common flags
  2515. *
  2516. * @bp device handle
  2517. * @fp queue handle
  2518. * @zero_stats TRUE if statistics zeroing is needed
  2519. *
  2520. * Return the flags that are common for the Tx-only and not normal connections.
  2521. */
  2522. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2523. struct bnx2x_fastpath *fp,
  2524. bool zero_stats)
  2525. {
  2526. unsigned long flags = 0;
  2527. /* PF driver will always initialize the Queue to an ACTIVE state */
  2528. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2529. /* tx only connections collect statistics (on the same index as the
  2530. * parent connection). The statistics are zeroed when the parent
  2531. * connection is initialized.
  2532. */
  2533. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2534. if (zero_stats)
  2535. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2536. if (bp->flags & TX_SWITCHING)
  2537. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2538. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2539. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2540. #ifdef BNX2X_STOP_ON_ERROR
  2541. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2542. #endif
  2543. return flags;
  2544. }
  2545. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2546. struct bnx2x_fastpath *fp,
  2547. bool leading)
  2548. {
  2549. unsigned long flags = 0;
  2550. /* calculate other queue flags */
  2551. if (IS_MF_SD(bp))
  2552. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2553. if (IS_FCOE_FP(fp)) {
  2554. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2555. /* For FCoE - force usage of default priority (for afex) */
  2556. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2557. }
  2558. if (!fp->disable_tpa) {
  2559. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2560. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2561. if (fp->mode == TPA_MODE_GRO)
  2562. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2563. }
  2564. if (leading) {
  2565. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2566. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2567. }
  2568. /* Always set HW VLAN stripping */
  2569. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2570. /* configure silent vlan removal */
  2571. if (IS_MF_AFEX(bp))
  2572. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2573. return flags | bnx2x_get_common_flags(bp, fp, true);
  2574. }
  2575. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2576. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2577. u8 cos)
  2578. {
  2579. gen_init->stat_id = bnx2x_stats_id(fp);
  2580. gen_init->spcl_id = fp->cl_id;
  2581. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2582. if (IS_FCOE_FP(fp))
  2583. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2584. else
  2585. gen_init->mtu = bp->dev->mtu;
  2586. gen_init->cos = cos;
  2587. }
  2588. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2589. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2590. struct bnx2x_rxq_setup_params *rxq_init)
  2591. {
  2592. u8 max_sge = 0;
  2593. u16 sge_sz = 0;
  2594. u16 tpa_agg_size = 0;
  2595. if (!fp->disable_tpa) {
  2596. pause->sge_th_lo = SGE_TH_LO(bp);
  2597. pause->sge_th_hi = SGE_TH_HI(bp);
  2598. /* validate SGE ring has enough to cross high threshold */
  2599. WARN_ON(bp->dropless_fc &&
  2600. pause->sge_th_hi + FW_PREFETCH_CNT >
  2601. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2602. tpa_agg_size = TPA_AGG_SIZE;
  2603. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2604. SGE_PAGE_SHIFT;
  2605. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2606. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2607. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2608. }
  2609. /* pause - not for e1 */
  2610. if (!CHIP_IS_E1(bp)) {
  2611. pause->bd_th_lo = BD_TH_LO(bp);
  2612. pause->bd_th_hi = BD_TH_HI(bp);
  2613. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2614. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2615. /*
  2616. * validate that rings have enough entries to cross
  2617. * high thresholds
  2618. */
  2619. WARN_ON(bp->dropless_fc &&
  2620. pause->bd_th_hi + FW_PREFETCH_CNT >
  2621. bp->rx_ring_size);
  2622. WARN_ON(bp->dropless_fc &&
  2623. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2624. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2625. pause->pri_map = 1;
  2626. }
  2627. /* rxq setup */
  2628. rxq_init->dscr_map = fp->rx_desc_mapping;
  2629. rxq_init->sge_map = fp->rx_sge_mapping;
  2630. rxq_init->rcq_map = fp->rx_comp_mapping;
  2631. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2632. /* This should be a maximum number of data bytes that may be
  2633. * placed on the BD (not including paddings).
  2634. */
  2635. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2636. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2637. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2638. rxq_init->tpa_agg_sz = tpa_agg_size;
  2639. rxq_init->sge_buf_sz = sge_sz;
  2640. rxq_init->max_sges_pkt = max_sge;
  2641. rxq_init->rss_engine_id = BP_FUNC(bp);
  2642. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2643. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2644. *
  2645. * For PF Clients it should be the maximum available number.
  2646. * VF driver(s) may want to define it to a smaller value.
  2647. */
  2648. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2649. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2650. rxq_init->fw_sb_id = fp->fw_sb_id;
  2651. if (IS_FCOE_FP(fp))
  2652. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2653. else
  2654. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2655. /* configure silent vlan removal
  2656. * if multi function mode is afex, then mask default vlan
  2657. */
  2658. if (IS_MF_AFEX(bp)) {
  2659. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2660. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2661. }
  2662. }
  2663. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2664. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2665. u8 cos)
  2666. {
  2667. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2668. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2669. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2670. txq_init->fw_sb_id = fp->fw_sb_id;
  2671. /*
  2672. * set the tss leading client id for TX classification ==
  2673. * leading RSS client id
  2674. */
  2675. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2676. if (IS_FCOE_FP(fp)) {
  2677. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2678. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2679. }
  2680. }
  2681. static void bnx2x_pf_init(struct bnx2x *bp)
  2682. {
  2683. struct bnx2x_func_init_params func_init = {0};
  2684. struct event_ring_data eq_data = { {0} };
  2685. u16 flags;
  2686. if (!CHIP_IS_E1x(bp)) {
  2687. /* reset IGU PF statistics: MSIX + ATTN */
  2688. /* PF */
  2689. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2690. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2691. (CHIP_MODE_IS_4_PORT(bp) ?
  2692. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2693. /* ATTN */
  2694. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2695. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2696. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2697. (CHIP_MODE_IS_4_PORT(bp) ?
  2698. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2699. }
  2700. /* function setup flags */
  2701. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2702. /* This flag is relevant for E1x only.
  2703. * E2 doesn't have a TPA configuration in a function level.
  2704. */
  2705. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2706. func_init.func_flgs = flags;
  2707. func_init.pf_id = BP_FUNC(bp);
  2708. func_init.func_id = BP_FUNC(bp);
  2709. func_init.spq_map = bp->spq_mapping;
  2710. func_init.spq_prod = bp->spq_prod_idx;
  2711. bnx2x_func_init(bp, &func_init);
  2712. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2713. /*
  2714. * Congestion management values depend on the link rate
  2715. * There is no active link so initial link rate is set to 10 Gbps.
  2716. * When the link comes up The congestion management values are
  2717. * re-calculated according to the actual link rate.
  2718. */
  2719. bp->link_vars.line_speed = SPEED_10000;
  2720. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2721. /* Only the PMF sets the HW */
  2722. if (bp->port.pmf)
  2723. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2724. /* init Event Queue - PCI bus guarantees correct endianity*/
  2725. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2726. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2727. eq_data.producer = bp->eq_prod;
  2728. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2729. eq_data.sb_id = DEF_SB_ID;
  2730. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2731. }
  2732. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2733. {
  2734. int port = BP_PORT(bp);
  2735. bnx2x_tx_disable(bp);
  2736. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2737. }
  2738. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2739. {
  2740. int port = BP_PORT(bp);
  2741. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2742. /* Tx queue should be only re-enabled */
  2743. netif_tx_wake_all_queues(bp->dev);
  2744. /*
  2745. * Should not call netif_carrier_on since it will be called if the link
  2746. * is up when checking for link state
  2747. */
  2748. }
  2749. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2750. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2751. {
  2752. struct eth_stats_info *ether_stat =
  2753. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2754. struct bnx2x_vlan_mac_obj *mac_obj =
  2755. &bp->sp_objs->mac_obj;
  2756. int i;
  2757. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2758. ETH_STAT_INFO_VERSION_LEN);
  2759. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2760. * mac_local field in ether_stat struct. The base address is offset by 2
  2761. * bytes to account for the field being 8 bytes but a mac address is
  2762. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2763. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2764. * allocated by the ether_stat struct, so the macs will land in their
  2765. * proper positions.
  2766. */
  2767. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2768. memset(ether_stat->mac_local + i, 0,
  2769. sizeof(ether_stat->mac_local[0]));
  2770. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2771. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2772. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2773. ETH_ALEN);
  2774. ether_stat->mtu_size = bp->dev->mtu;
  2775. if (bp->dev->features & NETIF_F_RXCSUM)
  2776. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2777. if (bp->dev->features & NETIF_F_TSO)
  2778. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2779. ether_stat->feature_flags |= bp->common.boot_mode;
  2780. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2781. ether_stat->txq_size = bp->tx_ring_size;
  2782. ether_stat->rxq_size = bp->rx_ring_size;
  2783. #ifdef CONFIG_BNX2X_SRIOV
  2784. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2785. #endif
  2786. }
  2787. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2788. {
  2789. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2790. struct fcoe_stats_info *fcoe_stat =
  2791. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2792. if (!CNIC_LOADED(bp))
  2793. return;
  2794. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2795. fcoe_stat->qos_priority =
  2796. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2797. /* insert FCoE stats from ramrod response */
  2798. if (!NO_FCOE(bp)) {
  2799. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2800. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2801. tstorm_queue_statistics;
  2802. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2803. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2804. xstorm_queue_statistics;
  2805. struct fcoe_statistics_params *fw_fcoe_stat =
  2806. &bp->fw_stats_data->fcoe;
  2807. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2808. fcoe_stat->rx_bytes_lo,
  2809. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2810. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2811. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2812. fcoe_stat->rx_bytes_lo,
  2813. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2814. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2815. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2816. fcoe_stat->rx_bytes_lo,
  2817. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2818. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2819. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2820. fcoe_stat->rx_bytes_lo,
  2821. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2822. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2823. fcoe_stat->rx_frames_lo,
  2824. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2825. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2826. fcoe_stat->rx_frames_lo,
  2827. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2828. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2829. fcoe_stat->rx_frames_lo,
  2830. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2831. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2832. fcoe_stat->rx_frames_lo,
  2833. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2834. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2835. fcoe_stat->tx_bytes_lo,
  2836. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2837. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2838. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2839. fcoe_stat->tx_bytes_lo,
  2840. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2841. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2842. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2843. fcoe_stat->tx_bytes_lo,
  2844. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2845. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2846. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2847. fcoe_stat->tx_bytes_lo,
  2848. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2849. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2850. fcoe_stat->tx_frames_lo,
  2851. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2852. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2853. fcoe_stat->tx_frames_lo,
  2854. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2855. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2856. fcoe_stat->tx_frames_lo,
  2857. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2858. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2859. fcoe_stat->tx_frames_lo,
  2860. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2861. }
  2862. /* ask L5 driver to add data to the struct */
  2863. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2864. }
  2865. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2866. {
  2867. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2868. struct iscsi_stats_info *iscsi_stat =
  2869. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2870. if (!CNIC_LOADED(bp))
  2871. return;
  2872. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2873. ETH_ALEN);
  2874. iscsi_stat->qos_priority =
  2875. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2876. /* ask L5 driver to add data to the struct */
  2877. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2878. }
  2879. /* called due to MCP event (on pmf):
  2880. * reread new bandwidth configuration
  2881. * configure FW
  2882. * notify others function about the change
  2883. */
  2884. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2885. {
  2886. if (bp->link_vars.link_up) {
  2887. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2888. bnx2x_link_sync_notify(bp);
  2889. }
  2890. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2891. }
  2892. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2893. {
  2894. bnx2x_config_mf_bw(bp);
  2895. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2896. }
  2897. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2898. {
  2899. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2900. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2901. }
  2902. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2903. {
  2904. enum drv_info_opcode op_code;
  2905. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2906. /* if drv_info version supported by MFW doesn't match - send NACK */
  2907. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2908. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2909. return;
  2910. }
  2911. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2912. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2913. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2914. sizeof(union drv_info_to_mcp));
  2915. switch (op_code) {
  2916. case ETH_STATS_OPCODE:
  2917. bnx2x_drv_info_ether_stat(bp);
  2918. break;
  2919. case FCOE_STATS_OPCODE:
  2920. bnx2x_drv_info_fcoe_stat(bp);
  2921. break;
  2922. case ISCSI_STATS_OPCODE:
  2923. bnx2x_drv_info_iscsi_stat(bp);
  2924. break;
  2925. default:
  2926. /* if op code isn't supported - send NACK */
  2927. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2928. return;
  2929. }
  2930. /* if we got drv_info attn from MFW then these fields are defined in
  2931. * shmem2 for sure
  2932. */
  2933. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2934. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2935. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2936. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2937. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2938. }
  2939. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2940. {
  2941. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2942. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2943. /*
  2944. * This is the only place besides the function initialization
  2945. * where the bp->flags can change so it is done without any
  2946. * locks
  2947. */
  2948. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2949. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2950. bp->flags |= MF_FUNC_DIS;
  2951. bnx2x_e1h_disable(bp);
  2952. } else {
  2953. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2954. bp->flags &= ~MF_FUNC_DIS;
  2955. bnx2x_e1h_enable(bp);
  2956. }
  2957. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2958. }
  2959. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2960. bnx2x_config_mf_bw(bp);
  2961. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2962. }
  2963. /* Report results to MCP */
  2964. if (dcc_event)
  2965. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2966. else
  2967. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2968. }
  2969. /* must be called under the spq lock */
  2970. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2971. {
  2972. struct eth_spe *next_spe = bp->spq_prod_bd;
  2973. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2974. bp->spq_prod_bd = bp->spq;
  2975. bp->spq_prod_idx = 0;
  2976. DP(BNX2X_MSG_SP, "end of spq\n");
  2977. } else {
  2978. bp->spq_prod_bd++;
  2979. bp->spq_prod_idx++;
  2980. }
  2981. return next_spe;
  2982. }
  2983. /* must be called under the spq lock */
  2984. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2985. {
  2986. int func = BP_FUNC(bp);
  2987. /*
  2988. * Make sure that BD data is updated before writing the producer:
  2989. * BD data is written to the memory, the producer is read from the
  2990. * memory, thus we need a full memory barrier to ensure the ordering.
  2991. */
  2992. mb();
  2993. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2994. bp->spq_prod_idx);
  2995. mmiowb();
  2996. }
  2997. /**
  2998. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2999. *
  3000. * @cmd: command to check
  3001. * @cmd_type: command type
  3002. */
  3003. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3004. {
  3005. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3006. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3007. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3008. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3009. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3010. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3011. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3012. return true;
  3013. else
  3014. return false;
  3015. }
  3016. /**
  3017. * bnx2x_sp_post - place a single command on an SP ring
  3018. *
  3019. * @bp: driver handle
  3020. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3021. * @cid: SW CID the command is related to
  3022. * @data_hi: command private data address (high 32 bits)
  3023. * @data_lo: command private data address (low 32 bits)
  3024. * @cmd_type: command type (e.g. NONE, ETH)
  3025. *
  3026. * SP data is handled as if it's always an address pair, thus data fields are
  3027. * not swapped to little endian in upper functions. Instead this function swaps
  3028. * data as if it's two u32 fields.
  3029. */
  3030. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3031. u32 data_hi, u32 data_lo, int cmd_type)
  3032. {
  3033. struct eth_spe *spe;
  3034. u16 type;
  3035. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3036. #ifdef BNX2X_STOP_ON_ERROR
  3037. if (unlikely(bp->panic)) {
  3038. BNX2X_ERR("Can't post SP when there is panic\n");
  3039. return -EIO;
  3040. }
  3041. #endif
  3042. spin_lock_bh(&bp->spq_lock);
  3043. if (common) {
  3044. if (!atomic_read(&bp->eq_spq_left)) {
  3045. BNX2X_ERR("BUG! EQ ring full!\n");
  3046. spin_unlock_bh(&bp->spq_lock);
  3047. bnx2x_panic();
  3048. return -EBUSY;
  3049. }
  3050. } else if (!atomic_read(&bp->cq_spq_left)) {
  3051. BNX2X_ERR("BUG! SPQ ring full!\n");
  3052. spin_unlock_bh(&bp->spq_lock);
  3053. bnx2x_panic();
  3054. return -EBUSY;
  3055. }
  3056. spe = bnx2x_sp_get_next(bp);
  3057. /* CID needs port number to be encoded int it */
  3058. spe->hdr.conn_and_cmd_data =
  3059. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3060. HW_CID(bp, cid));
  3061. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3062. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3063. SPE_HDR_FUNCTION_ID);
  3064. spe->hdr.type = cpu_to_le16(type);
  3065. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3066. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3067. /*
  3068. * It's ok if the actual decrement is issued towards the memory
  3069. * somewhere between the spin_lock and spin_unlock. Thus no
  3070. * more explicit memory barrier is needed.
  3071. */
  3072. if (common)
  3073. atomic_dec(&bp->eq_spq_left);
  3074. else
  3075. atomic_dec(&bp->cq_spq_left);
  3076. DP(BNX2X_MSG_SP,
  3077. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3078. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3079. (u32)(U64_LO(bp->spq_mapping) +
  3080. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3081. HW_CID(bp, cid), data_hi, data_lo, type,
  3082. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3083. bnx2x_sp_prod_update(bp);
  3084. spin_unlock_bh(&bp->spq_lock);
  3085. return 0;
  3086. }
  3087. /* acquire split MCP access lock register */
  3088. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3089. {
  3090. u32 j, val;
  3091. int rc = 0;
  3092. might_sleep();
  3093. for (j = 0; j < 1000; j++) {
  3094. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3095. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3096. if (val & MCPR_ACCESS_LOCK_LOCK)
  3097. break;
  3098. usleep_range(5000, 10000);
  3099. }
  3100. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3101. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3102. rc = -EBUSY;
  3103. }
  3104. return rc;
  3105. }
  3106. /* release split MCP access lock register */
  3107. static void bnx2x_release_alr(struct bnx2x *bp)
  3108. {
  3109. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3110. }
  3111. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3112. #define BNX2X_DEF_SB_IDX 0x0002
  3113. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3114. {
  3115. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3116. u16 rc = 0;
  3117. barrier(); /* status block is written to by the chip */
  3118. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3119. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3120. rc |= BNX2X_DEF_SB_ATT_IDX;
  3121. }
  3122. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3123. bp->def_idx = def_sb->sp_sb.running_index;
  3124. rc |= BNX2X_DEF_SB_IDX;
  3125. }
  3126. /* Do not reorder: indices reading should complete before handling */
  3127. barrier();
  3128. return rc;
  3129. }
  3130. /*
  3131. * slow path service functions
  3132. */
  3133. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3134. {
  3135. int port = BP_PORT(bp);
  3136. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3137. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3138. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3139. NIG_REG_MASK_INTERRUPT_PORT0;
  3140. u32 aeu_mask;
  3141. u32 nig_mask = 0;
  3142. u32 reg_addr;
  3143. if (bp->attn_state & asserted)
  3144. BNX2X_ERR("IGU ERROR\n");
  3145. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3146. aeu_mask = REG_RD(bp, aeu_addr);
  3147. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3148. aeu_mask, asserted);
  3149. aeu_mask &= ~(asserted & 0x3ff);
  3150. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3151. REG_WR(bp, aeu_addr, aeu_mask);
  3152. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3153. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3154. bp->attn_state |= asserted;
  3155. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3156. if (asserted & ATTN_HARD_WIRED_MASK) {
  3157. if (asserted & ATTN_NIG_FOR_FUNC) {
  3158. bnx2x_acquire_phy_lock(bp);
  3159. /* save nig interrupt mask */
  3160. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3161. /* If nig_mask is not set, no need to call the update
  3162. * function.
  3163. */
  3164. if (nig_mask) {
  3165. REG_WR(bp, nig_int_mask_addr, 0);
  3166. bnx2x_link_attn(bp);
  3167. }
  3168. /* handle unicore attn? */
  3169. }
  3170. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3171. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3172. if (asserted & GPIO_2_FUNC)
  3173. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3174. if (asserted & GPIO_3_FUNC)
  3175. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3176. if (asserted & GPIO_4_FUNC)
  3177. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3178. if (port == 0) {
  3179. if (asserted & ATTN_GENERAL_ATTN_1) {
  3180. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3181. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3182. }
  3183. if (asserted & ATTN_GENERAL_ATTN_2) {
  3184. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3185. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3186. }
  3187. if (asserted & ATTN_GENERAL_ATTN_3) {
  3188. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3189. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3190. }
  3191. } else {
  3192. if (asserted & ATTN_GENERAL_ATTN_4) {
  3193. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3194. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3195. }
  3196. if (asserted & ATTN_GENERAL_ATTN_5) {
  3197. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3198. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3199. }
  3200. if (asserted & ATTN_GENERAL_ATTN_6) {
  3201. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3202. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3203. }
  3204. }
  3205. } /* if hardwired */
  3206. if (bp->common.int_block == INT_BLOCK_HC)
  3207. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3208. COMMAND_REG_ATTN_BITS_SET);
  3209. else
  3210. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3211. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3212. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3213. REG_WR(bp, reg_addr, asserted);
  3214. /* now set back the mask */
  3215. if (asserted & ATTN_NIG_FOR_FUNC) {
  3216. /* Verify that IGU ack through BAR was written before restoring
  3217. * NIG mask. This loop should exit after 2-3 iterations max.
  3218. */
  3219. if (bp->common.int_block != INT_BLOCK_HC) {
  3220. u32 cnt = 0, igu_acked;
  3221. do {
  3222. igu_acked = REG_RD(bp,
  3223. IGU_REG_ATTENTION_ACK_BITS);
  3224. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3225. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3226. if (!igu_acked)
  3227. DP(NETIF_MSG_HW,
  3228. "Failed to verify IGU ack on time\n");
  3229. barrier();
  3230. }
  3231. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3232. bnx2x_release_phy_lock(bp);
  3233. }
  3234. }
  3235. static void bnx2x_fan_failure(struct bnx2x *bp)
  3236. {
  3237. int port = BP_PORT(bp);
  3238. u32 ext_phy_config;
  3239. /* mark the failure */
  3240. ext_phy_config =
  3241. SHMEM_RD(bp,
  3242. dev_info.port_hw_config[port].external_phy_config);
  3243. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3244. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3245. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3246. ext_phy_config);
  3247. /* log the failure */
  3248. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3249. "Please contact OEM Support for assistance\n");
  3250. /* Schedule device reset (unload)
  3251. * This is due to some boards consuming sufficient power when driver is
  3252. * up to overheat if fan fails.
  3253. */
  3254. smp_mb__before_clear_bit();
  3255. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3256. smp_mb__after_clear_bit();
  3257. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3258. }
  3259. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3260. {
  3261. int port = BP_PORT(bp);
  3262. int reg_offset;
  3263. u32 val;
  3264. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3265. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3266. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3267. val = REG_RD(bp, reg_offset);
  3268. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3269. REG_WR(bp, reg_offset, val);
  3270. BNX2X_ERR("SPIO5 hw attention\n");
  3271. /* Fan failure attention */
  3272. bnx2x_hw_reset_phy(&bp->link_params);
  3273. bnx2x_fan_failure(bp);
  3274. }
  3275. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3276. bnx2x_acquire_phy_lock(bp);
  3277. bnx2x_handle_module_detect_int(&bp->link_params);
  3278. bnx2x_release_phy_lock(bp);
  3279. }
  3280. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3281. val = REG_RD(bp, reg_offset);
  3282. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3283. REG_WR(bp, reg_offset, val);
  3284. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3285. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3286. bnx2x_panic();
  3287. }
  3288. }
  3289. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3290. {
  3291. u32 val;
  3292. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3293. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3294. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3295. /* DORQ discard attention */
  3296. if (val & 0x2)
  3297. BNX2X_ERR("FATAL error from DORQ\n");
  3298. }
  3299. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3300. int port = BP_PORT(bp);
  3301. int reg_offset;
  3302. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3303. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3304. val = REG_RD(bp, reg_offset);
  3305. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3306. REG_WR(bp, reg_offset, val);
  3307. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3308. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3309. bnx2x_panic();
  3310. }
  3311. }
  3312. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3313. {
  3314. u32 val;
  3315. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3316. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3317. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3318. /* CFC error attention */
  3319. if (val & 0x2)
  3320. BNX2X_ERR("FATAL error from CFC\n");
  3321. }
  3322. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3323. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3324. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3325. /* RQ_USDMDP_FIFO_OVERFLOW */
  3326. if (val & 0x18000)
  3327. BNX2X_ERR("FATAL error from PXP\n");
  3328. if (!CHIP_IS_E1x(bp)) {
  3329. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3330. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3331. }
  3332. }
  3333. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3334. int port = BP_PORT(bp);
  3335. int reg_offset;
  3336. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3337. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3338. val = REG_RD(bp, reg_offset);
  3339. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3340. REG_WR(bp, reg_offset, val);
  3341. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3342. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3343. bnx2x_panic();
  3344. }
  3345. }
  3346. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3347. {
  3348. u32 val;
  3349. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3350. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3351. int func = BP_FUNC(bp);
  3352. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3353. bnx2x_read_mf_cfg(bp);
  3354. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3355. func_mf_config[BP_ABS_FUNC(bp)].config);
  3356. val = SHMEM_RD(bp,
  3357. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3358. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3359. bnx2x_dcc_event(bp,
  3360. (val & DRV_STATUS_DCC_EVENT_MASK));
  3361. if (val & DRV_STATUS_SET_MF_BW)
  3362. bnx2x_set_mf_bw(bp);
  3363. if (val & DRV_STATUS_DRV_INFO_REQ)
  3364. bnx2x_handle_drv_info_req(bp);
  3365. if (val & DRV_STATUS_VF_DISABLED)
  3366. bnx2x_vf_handle_flr_event(bp);
  3367. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3368. bnx2x_pmf_update(bp);
  3369. if (bp->port.pmf &&
  3370. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3371. bp->dcbx_enabled > 0)
  3372. /* start dcbx state machine */
  3373. bnx2x_dcbx_set_params(bp,
  3374. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3375. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3376. bnx2x_handle_afex_cmd(bp,
  3377. val & DRV_STATUS_AFEX_EVENT_MASK);
  3378. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3379. bnx2x_handle_eee_event(bp);
  3380. if (bp->link_vars.periodic_flags &
  3381. PERIODIC_FLAGS_LINK_EVENT) {
  3382. /* sync with link */
  3383. bnx2x_acquire_phy_lock(bp);
  3384. bp->link_vars.periodic_flags &=
  3385. ~PERIODIC_FLAGS_LINK_EVENT;
  3386. bnx2x_release_phy_lock(bp);
  3387. if (IS_MF(bp))
  3388. bnx2x_link_sync_notify(bp);
  3389. bnx2x_link_report(bp);
  3390. }
  3391. /* Always call it here: bnx2x_link_report() will
  3392. * prevent the link indication duplication.
  3393. */
  3394. bnx2x__link_status_update(bp);
  3395. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3396. BNX2X_ERR("MC assert!\n");
  3397. bnx2x_mc_assert(bp);
  3398. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3399. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3400. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3401. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3402. bnx2x_panic();
  3403. } else if (attn & BNX2X_MCP_ASSERT) {
  3404. BNX2X_ERR("MCP assert!\n");
  3405. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3406. bnx2x_fw_dump(bp);
  3407. } else
  3408. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3409. }
  3410. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3411. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3412. if (attn & BNX2X_GRC_TIMEOUT) {
  3413. val = CHIP_IS_E1(bp) ? 0 :
  3414. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3415. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3416. }
  3417. if (attn & BNX2X_GRC_RSV) {
  3418. val = CHIP_IS_E1(bp) ? 0 :
  3419. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3420. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3421. }
  3422. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3423. }
  3424. }
  3425. /*
  3426. * Bits map:
  3427. * 0-7 - Engine0 load counter.
  3428. * 8-15 - Engine1 load counter.
  3429. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3430. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3431. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3432. * on the engine
  3433. * 19 - Engine1 ONE_IS_LOADED.
  3434. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3435. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3436. * just the one belonging to its engine).
  3437. *
  3438. */
  3439. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3440. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3441. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3442. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3443. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3444. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3445. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3446. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3447. /*
  3448. * Set the GLOBAL_RESET bit.
  3449. *
  3450. * Should be run under rtnl lock
  3451. */
  3452. void bnx2x_set_reset_global(struct bnx2x *bp)
  3453. {
  3454. u32 val;
  3455. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3456. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3457. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3458. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3459. }
  3460. /*
  3461. * Clear the GLOBAL_RESET bit.
  3462. *
  3463. * Should be run under rtnl lock
  3464. */
  3465. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3466. {
  3467. u32 val;
  3468. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3469. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3470. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3471. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3472. }
  3473. /*
  3474. * Checks the GLOBAL_RESET bit.
  3475. *
  3476. * should be run under rtnl lock
  3477. */
  3478. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3479. {
  3480. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3481. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3482. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3483. }
  3484. /*
  3485. * Clear RESET_IN_PROGRESS bit for the current engine.
  3486. *
  3487. * Should be run under rtnl lock
  3488. */
  3489. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3490. {
  3491. u32 val;
  3492. u32 bit = BP_PATH(bp) ?
  3493. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3494. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3495. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3496. /* Clear the bit */
  3497. val &= ~bit;
  3498. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3499. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3500. }
  3501. /*
  3502. * Set RESET_IN_PROGRESS for the current engine.
  3503. *
  3504. * should be run under rtnl lock
  3505. */
  3506. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3507. {
  3508. u32 val;
  3509. u32 bit = BP_PATH(bp) ?
  3510. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3511. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3512. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3513. /* Set the bit */
  3514. val |= bit;
  3515. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3516. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3517. }
  3518. /*
  3519. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3520. * should be run under rtnl lock
  3521. */
  3522. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3523. {
  3524. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3525. u32 bit = engine ?
  3526. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3527. /* return false if bit is set */
  3528. return (val & bit) ? false : true;
  3529. }
  3530. /*
  3531. * set pf load for the current pf.
  3532. *
  3533. * should be run under rtnl lock
  3534. */
  3535. void bnx2x_set_pf_load(struct bnx2x *bp)
  3536. {
  3537. u32 val1, val;
  3538. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3539. BNX2X_PATH0_LOAD_CNT_MASK;
  3540. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3541. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3542. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3543. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3544. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3545. /* get the current counter value */
  3546. val1 = (val & mask) >> shift;
  3547. /* set bit of that PF */
  3548. val1 |= (1 << bp->pf_num);
  3549. /* clear the old value */
  3550. val &= ~mask;
  3551. /* set the new one */
  3552. val |= ((val1 << shift) & mask);
  3553. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3554. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3555. }
  3556. /**
  3557. * bnx2x_clear_pf_load - clear pf load mark
  3558. *
  3559. * @bp: driver handle
  3560. *
  3561. * Should be run under rtnl lock.
  3562. * Decrements the load counter for the current engine. Returns
  3563. * whether other functions are still loaded
  3564. */
  3565. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3566. {
  3567. u32 val1, val;
  3568. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3569. BNX2X_PATH0_LOAD_CNT_MASK;
  3570. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3571. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3572. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3573. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3574. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3575. /* get the current counter value */
  3576. val1 = (val & mask) >> shift;
  3577. /* clear bit of that PF */
  3578. val1 &= ~(1 << bp->pf_num);
  3579. /* clear the old value */
  3580. val &= ~mask;
  3581. /* set the new one */
  3582. val |= ((val1 << shift) & mask);
  3583. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3584. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3585. return val1 != 0;
  3586. }
  3587. /*
  3588. * Read the load status for the current engine.
  3589. *
  3590. * should be run under rtnl lock
  3591. */
  3592. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3593. {
  3594. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3595. BNX2X_PATH0_LOAD_CNT_MASK);
  3596. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3597. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3598. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3599. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3600. val = (val & mask) >> shift;
  3601. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3602. engine, val);
  3603. return val != 0;
  3604. }
  3605. static void _print_parity(struct bnx2x *bp, u32 reg)
  3606. {
  3607. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3608. }
  3609. static void _print_next_block(int idx, const char *blk)
  3610. {
  3611. pr_cont("%s%s", idx ? ", " : "", blk);
  3612. }
  3613. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3614. int *par_num, bool print)
  3615. {
  3616. u32 cur_bit;
  3617. bool res;
  3618. int i;
  3619. res = false;
  3620. for (i = 0; sig; i++) {
  3621. cur_bit = (0x1UL << i);
  3622. if (sig & cur_bit) {
  3623. res |= true; /* Each bit is real error! */
  3624. if (print) {
  3625. switch (cur_bit) {
  3626. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3627. _print_next_block((*par_num)++, "BRB");
  3628. _print_parity(bp,
  3629. BRB1_REG_BRB1_PRTY_STS);
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3632. _print_next_block((*par_num)++,
  3633. "PARSER");
  3634. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3635. break;
  3636. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3637. _print_next_block((*par_num)++, "TSDM");
  3638. _print_parity(bp,
  3639. TSDM_REG_TSDM_PRTY_STS);
  3640. break;
  3641. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3642. _print_next_block((*par_num)++,
  3643. "SEARCHER");
  3644. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3645. break;
  3646. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3647. _print_next_block((*par_num)++, "TCM");
  3648. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3649. break;
  3650. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3651. _print_next_block((*par_num)++,
  3652. "TSEMI");
  3653. _print_parity(bp,
  3654. TSEM_REG_TSEM_PRTY_STS_0);
  3655. _print_parity(bp,
  3656. TSEM_REG_TSEM_PRTY_STS_1);
  3657. break;
  3658. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3659. _print_next_block((*par_num)++, "XPB");
  3660. _print_parity(bp, GRCBASE_XPB +
  3661. PB_REG_PB_PRTY_STS);
  3662. break;
  3663. }
  3664. }
  3665. /* Clear the bit */
  3666. sig &= ~cur_bit;
  3667. }
  3668. }
  3669. return res;
  3670. }
  3671. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3672. int *par_num, bool *global,
  3673. bool print)
  3674. {
  3675. u32 cur_bit;
  3676. bool res;
  3677. int i;
  3678. res = false;
  3679. for (i = 0; sig; i++) {
  3680. cur_bit = (0x1UL << i);
  3681. if (sig & cur_bit) {
  3682. res |= true; /* Each bit is real error! */
  3683. switch (cur_bit) {
  3684. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3685. if (print) {
  3686. _print_next_block((*par_num)++, "PBF");
  3687. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3688. }
  3689. break;
  3690. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3691. if (print) {
  3692. _print_next_block((*par_num)++, "QM");
  3693. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3694. }
  3695. break;
  3696. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3697. if (print) {
  3698. _print_next_block((*par_num)++, "TM");
  3699. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3700. }
  3701. break;
  3702. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3703. if (print) {
  3704. _print_next_block((*par_num)++, "XSDM");
  3705. _print_parity(bp,
  3706. XSDM_REG_XSDM_PRTY_STS);
  3707. }
  3708. break;
  3709. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3710. if (print) {
  3711. _print_next_block((*par_num)++, "XCM");
  3712. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3713. }
  3714. break;
  3715. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3716. if (print) {
  3717. _print_next_block((*par_num)++,
  3718. "XSEMI");
  3719. _print_parity(bp,
  3720. XSEM_REG_XSEM_PRTY_STS_0);
  3721. _print_parity(bp,
  3722. XSEM_REG_XSEM_PRTY_STS_1);
  3723. }
  3724. break;
  3725. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3726. if (print) {
  3727. _print_next_block((*par_num)++,
  3728. "DOORBELLQ");
  3729. _print_parity(bp,
  3730. DORQ_REG_DORQ_PRTY_STS);
  3731. }
  3732. break;
  3733. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3734. if (print) {
  3735. _print_next_block((*par_num)++, "NIG");
  3736. if (CHIP_IS_E1x(bp)) {
  3737. _print_parity(bp,
  3738. NIG_REG_NIG_PRTY_STS);
  3739. } else {
  3740. _print_parity(bp,
  3741. NIG_REG_NIG_PRTY_STS_0);
  3742. _print_parity(bp,
  3743. NIG_REG_NIG_PRTY_STS_1);
  3744. }
  3745. }
  3746. break;
  3747. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3748. if (print)
  3749. _print_next_block((*par_num)++,
  3750. "VAUX PCI CORE");
  3751. *global = true;
  3752. break;
  3753. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3754. if (print) {
  3755. _print_next_block((*par_num)++,
  3756. "DEBUG");
  3757. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3758. }
  3759. break;
  3760. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3761. if (print) {
  3762. _print_next_block((*par_num)++, "USDM");
  3763. _print_parity(bp,
  3764. USDM_REG_USDM_PRTY_STS);
  3765. }
  3766. break;
  3767. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3768. if (print) {
  3769. _print_next_block((*par_num)++, "UCM");
  3770. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3771. }
  3772. break;
  3773. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3774. if (print) {
  3775. _print_next_block((*par_num)++,
  3776. "USEMI");
  3777. _print_parity(bp,
  3778. USEM_REG_USEM_PRTY_STS_0);
  3779. _print_parity(bp,
  3780. USEM_REG_USEM_PRTY_STS_1);
  3781. }
  3782. break;
  3783. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3784. if (print) {
  3785. _print_next_block((*par_num)++, "UPB");
  3786. _print_parity(bp, GRCBASE_UPB +
  3787. PB_REG_PB_PRTY_STS);
  3788. }
  3789. break;
  3790. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3791. if (print) {
  3792. _print_next_block((*par_num)++, "CSDM");
  3793. _print_parity(bp,
  3794. CSDM_REG_CSDM_PRTY_STS);
  3795. }
  3796. break;
  3797. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3798. if (print) {
  3799. _print_next_block((*par_num)++, "CCM");
  3800. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3801. }
  3802. break;
  3803. }
  3804. /* Clear the bit */
  3805. sig &= ~cur_bit;
  3806. }
  3807. }
  3808. return res;
  3809. }
  3810. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3811. int *par_num, bool print)
  3812. {
  3813. u32 cur_bit;
  3814. bool res;
  3815. int i;
  3816. res = false;
  3817. for (i = 0; sig; i++) {
  3818. cur_bit = (0x1UL << i);
  3819. if (sig & cur_bit) {
  3820. res |= true; /* Each bit is real error! */
  3821. if (print) {
  3822. switch (cur_bit) {
  3823. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3824. _print_next_block((*par_num)++,
  3825. "CSEMI");
  3826. _print_parity(bp,
  3827. CSEM_REG_CSEM_PRTY_STS_0);
  3828. _print_parity(bp,
  3829. CSEM_REG_CSEM_PRTY_STS_1);
  3830. break;
  3831. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3832. _print_next_block((*par_num)++, "PXP");
  3833. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3834. _print_parity(bp,
  3835. PXP2_REG_PXP2_PRTY_STS_0);
  3836. _print_parity(bp,
  3837. PXP2_REG_PXP2_PRTY_STS_1);
  3838. break;
  3839. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3840. _print_next_block((*par_num)++,
  3841. "PXPPCICLOCKCLIENT");
  3842. break;
  3843. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3844. _print_next_block((*par_num)++, "CFC");
  3845. _print_parity(bp,
  3846. CFC_REG_CFC_PRTY_STS);
  3847. break;
  3848. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3849. _print_next_block((*par_num)++, "CDU");
  3850. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3851. break;
  3852. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3853. _print_next_block((*par_num)++, "DMAE");
  3854. _print_parity(bp,
  3855. DMAE_REG_DMAE_PRTY_STS);
  3856. break;
  3857. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3858. _print_next_block((*par_num)++, "IGU");
  3859. if (CHIP_IS_E1x(bp))
  3860. _print_parity(bp,
  3861. HC_REG_HC_PRTY_STS);
  3862. else
  3863. _print_parity(bp,
  3864. IGU_REG_IGU_PRTY_STS);
  3865. break;
  3866. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3867. _print_next_block((*par_num)++, "MISC");
  3868. _print_parity(bp,
  3869. MISC_REG_MISC_PRTY_STS);
  3870. break;
  3871. }
  3872. }
  3873. /* Clear the bit */
  3874. sig &= ~cur_bit;
  3875. }
  3876. }
  3877. return res;
  3878. }
  3879. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  3880. int *par_num, bool *global,
  3881. bool print)
  3882. {
  3883. bool res = false;
  3884. u32 cur_bit;
  3885. int i;
  3886. for (i = 0; sig; i++) {
  3887. cur_bit = (0x1UL << i);
  3888. if (sig & cur_bit) {
  3889. switch (cur_bit) {
  3890. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3891. if (print)
  3892. _print_next_block((*par_num)++,
  3893. "MCP ROM");
  3894. *global = true;
  3895. res |= true;
  3896. break;
  3897. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3898. if (print)
  3899. _print_next_block((*par_num)++,
  3900. "MCP UMP RX");
  3901. *global = true;
  3902. res |= true;
  3903. break;
  3904. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3905. if (print)
  3906. _print_next_block((*par_num)++,
  3907. "MCP UMP TX");
  3908. *global = true;
  3909. res |= true;
  3910. break;
  3911. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3912. if (print)
  3913. _print_next_block((*par_num)++,
  3914. "MCP SCPAD");
  3915. /* clear latched SCPAD PATIRY from MCP */
  3916. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  3917. 1UL << 10);
  3918. break;
  3919. }
  3920. /* Clear the bit */
  3921. sig &= ~cur_bit;
  3922. }
  3923. }
  3924. return res;
  3925. }
  3926. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  3927. int *par_num, bool print)
  3928. {
  3929. u32 cur_bit;
  3930. bool res;
  3931. int i;
  3932. res = false;
  3933. for (i = 0; sig; i++) {
  3934. cur_bit = (0x1UL << i);
  3935. if (sig & cur_bit) {
  3936. res |= true; /* Each bit is real error! */
  3937. if (print) {
  3938. switch (cur_bit) {
  3939. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3940. _print_next_block((*par_num)++,
  3941. "PGLUE_B");
  3942. _print_parity(bp,
  3943. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  3944. break;
  3945. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3946. _print_next_block((*par_num)++, "ATC");
  3947. _print_parity(bp,
  3948. ATC_REG_ATC_PRTY_STS);
  3949. break;
  3950. }
  3951. }
  3952. /* Clear the bit */
  3953. sig &= ~cur_bit;
  3954. }
  3955. }
  3956. return res;
  3957. }
  3958. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3959. u32 *sig)
  3960. {
  3961. bool res = false;
  3962. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3963. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3964. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3965. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3966. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3967. int par_num = 0;
  3968. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3969. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3970. sig[0] & HW_PRTY_ASSERT_SET_0,
  3971. sig[1] & HW_PRTY_ASSERT_SET_1,
  3972. sig[2] & HW_PRTY_ASSERT_SET_2,
  3973. sig[3] & HW_PRTY_ASSERT_SET_3,
  3974. sig[4] & HW_PRTY_ASSERT_SET_4);
  3975. if (print)
  3976. netdev_err(bp->dev,
  3977. "Parity errors detected in blocks: ");
  3978. res |= bnx2x_check_blocks_with_parity0(bp,
  3979. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  3980. res |= bnx2x_check_blocks_with_parity1(bp,
  3981. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  3982. res |= bnx2x_check_blocks_with_parity2(bp,
  3983. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  3984. res |= bnx2x_check_blocks_with_parity3(bp,
  3985. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  3986. res |= bnx2x_check_blocks_with_parity4(bp,
  3987. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  3988. if (print)
  3989. pr_cont("\n");
  3990. }
  3991. return res;
  3992. }
  3993. /**
  3994. * bnx2x_chk_parity_attn - checks for parity attentions.
  3995. *
  3996. * @bp: driver handle
  3997. * @global: true if there was a global attention
  3998. * @print: show parity attention in syslog
  3999. */
  4000. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4001. {
  4002. struct attn_route attn = { {0} };
  4003. int port = BP_PORT(bp);
  4004. attn.sig[0] = REG_RD(bp,
  4005. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4006. port*4);
  4007. attn.sig[1] = REG_RD(bp,
  4008. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4009. port*4);
  4010. attn.sig[2] = REG_RD(bp,
  4011. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4012. port*4);
  4013. attn.sig[3] = REG_RD(bp,
  4014. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4015. port*4);
  4016. /* Since MCP attentions can't be disabled inside the block, we need to
  4017. * read AEU registers to see whether they're currently disabled
  4018. */
  4019. attn.sig[3] &= ((REG_RD(bp,
  4020. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4021. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4022. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4023. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4024. if (!CHIP_IS_E1x(bp))
  4025. attn.sig[4] = REG_RD(bp,
  4026. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4027. port*4);
  4028. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4029. }
  4030. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4031. {
  4032. u32 val;
  4033. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4034. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4035. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4036. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4037. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4038. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4039. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4040. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4041. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4042. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4043. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4044. if (val &
  4045. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4046. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4047. if (val &
  4048. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4049. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4050. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4051. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4052. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4053. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4054. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4055. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4056. }
  4057. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4058. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4059. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4060. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4061. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4062. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4063. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4064. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4065. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4066. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4067. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4068. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4069. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4070. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4071. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4072. }
  4073. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4074. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4075. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4076. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4077. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4078. }
  4079. }
  4080. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4081. {
  4082. struct attn_route attn, *group_mask;
  4083. int port = BP_PORT(bp);
  4084. int index;
  4085. u32 reg_addr;
  4086. u32 val;
  4087. u32 aeu_mask;
  4088. bool global = false;
  4089. /* need to take HW lock because MCP or other port might also
  4090. try to handle this event */
  4091. bnx2x_acquire_alr(bp);
  4092. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4093. #ifndef BNX2X_STOP_ON_ERROR
  4094. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4095. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4096. /* Disable HW interrupts */
  4097. bnx2x_int_disable(bp);
  4098. /* In case of parity errors don't handle attentions so that
  4099. * other function would "see" parity errors.
  4100. */
  4101. #else
  4102. bnx2x_panic();
  4103. #endif
  4104. bnx2x_release_alr(bp);
  4105. return;
  4106. }
  4107. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4108. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4109. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4110. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4111. if (!CHIP_IS_E1x(bp))
  4112. attn.sig[4] =
  4113. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4114. else
  4115. attn.sig[4] = 0;
  4116. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4117. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4118. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4119. if (deasserted & (1 << index)) {
  4120. group_mask = &bp->attn_group[index];
  4121. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4122. index,
  4123. group_mask->sig[0], group_mask->sig[1],
  4124. group_mask->sig[2], group_mask->sig[3],
  4125. group_mask->sig[4]);
  4126. bnx2x_attn_int_deasserted4(bp,
  4127. attn.sig[4] & group_mask->sig[4]);
  4128. bnx2x_attn_int_deasserted3(bp,
  4129. attn.sig[3] & group_mask->sig[3]);
  4130. bnx2x_attn_int_deasserted1(bp,
  4131. attn.sig[1] & group_mask->sig[1]);
  4132. bnx2x_attn_int_deasserted2(bp,
  4133. attn.sig[2] & group_mask->sig[2]);
  4134. bnx2x_attn_int_deasserted0(bp,
  4135. attn.sig[0] & group_mask->sig[0]);
  4136. }
  4137. }
  4138. bnx2x_release_alr(bp);
  4139. if (bp->common.int_block == INT_BLOCK_HC)
  4140. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4141. COMMAND_REG_ATTN_BITS_CLR);
  4142. else
  4143. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4144. val = ~deasserted;
  4145. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4146. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4147. REG_WR(bp, reg_addr, val);
  4148. if (~bp->attn_state & deasserted)
  4149. BNX2X_ERR("IGU ERROR\n");
  4150. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4151. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4152. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4153. aeu_mask = REG_RD(bp, reg_addr);
  4154. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4155. aeu_mask, deasserted);
  4156. aeu_mask |= (deasserted & 0x3ff);
  4157. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4158. REG_WR(bp, reg_addr, aeu_mask);
  4159. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4160. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4161. bp->attn_state &= ~deasserted;
  4162. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4163. }
  4164. static void bnx2x_attn_int(struct bnx2x *bp)
  4165. {
  4166. /* read local copy of bits */
  4167. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4168. attn_bits);
  4169. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4170. attn_bits_ack);
  4171. u32 attn_state = bp->attn_state;
  4172. /* look for changed bits */
  4173. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4174. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4175. DP(NETIF_MSG_HW,
  4176. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4177. attn_bits, attn_ack, asserted, deasserted);
  4178. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4179. BNX2X_ERR("BAD attention state\n");
  4180. /* handle bits that were raised */
  4181. if (asserted)
  4182. bnx2x_attn_int_asserted(bp, asserted);
  4183. if (deasserted)
  4184. bnx2x_attn_int_deasserted(bp, deasserted);
  4185. }
  4186. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4187. u16 index, u8 op, u8 update)
  4188. {
  4189. u32 igu_addr = bp->igu_base_addr;
  4190. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4191. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4192. igu_addr);
  4193. }
  4194. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4195. {
  4196. /* No memory barriers */
  4197. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4198. mmiowb(); /* keep prod updates ordered */
  4199. }
  4200. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4201. union event_ring_elem *elem)
  4202. {
  4203. u8 err = elem->message.error;
  4204. if (!bp->cnic_eth_dev.starting_cid ||
  4205. (cid < bp->cnic_eth_dev.starting_cid &&
  4206. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4207. return 1;
  4208. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4209. if (unlikely(err)) {
  4210. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4211. cid);
  4212. bnx2x_panic_dump(bp, false);
  4213. }
  4214. bnx2x_cnic_cfc_comp(bp, cid, err);
  4215. return 0;
  4216. }
  4217. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4218. {
  4219. struct bnx2x_mcast_ramrod_params rparam;
  4220. int rc;
  4221. memset(&rparam, 0, sizeof(rparam));
  4222. rparam.mcast_obj = &bp->mcast_obj;
  4223. netif_addr_lock_bh(bp->dev);
  4224. /* Clear pending state for the last command */
  4225. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4226. /* If there are pending mcast commands - send them */
  4227. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4228. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4229. if (rc < 0)
  4230. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4231. rc);
  4232. }
  4233. netif_addr_unlock_bh(bp->dev);
  4234. }
  4235. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4236. union event_ring_elem *elem)
  4237. {
  4238. unsigned long ramrod_flags = 0;
  4239. int rc = 0;
  4240. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4241. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4242. /* Always push next commands out, don't wait here */
  4243. __set_bit(RAMROD_CONT, &ramrod_flags);
  4244. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4245. >> BNX2X_SWCID_SHIFT) {
  4246. case BNX2X_FILTER_MAC_PENDING:
  4247. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4248. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4249. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4250. else
  4251. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4252. break;
  4253. case BNX2X_FILTER_MCAST_PENDING:
  4254. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4255. /* This is only relevant for 57710 where multicast MACs are
  4256. * configured as unicast MACs using the same ramrod.
  4257. */
  4258. bnx2x_handle_mcast_eqe(bp);
  4259. return;
  4260. default:
  4261. BNX2X_ERR("Unsupported classification command: %d\n",
  4262. elem->message.data.eth_event.echo);
  4263. return;
  4264. }
  4265. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4266. if (rc < 0)
  4267. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4268. else if (rc > 0)
  4269. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4270. }
  4271. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4272. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4273. {
  4274. netif_addr_lock_bh(bp->dev);
  4275. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4276. /* Send rx_mode command again if was requested */
  4277. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4278. bnx2x_set_storm_rx_mode(bp);
  4279. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4280. &bp->sp_state))
  4281. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4282. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4283. &bp->sp_state))
  4284. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4285. netif_addr_unlock_bh(bp->dev);
  4286. }
  4287. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4288. union event_ring_elem *elem)
  4289. {
  4290. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4291. DP(BNX2X_MSG_SP,
  4292. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4293. elem->message.data.vif_list_event.func_bit_map);
  4294. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4295. elem->message.data.vif_list_event.func_bit_map);
  4296. } else if (elem->message.data.vif_list_event.echo ==
  4297. VIF_LIST_RULE_SET) {
  4298. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4299. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4300. }
  4301. }
  4302. /* called with rtnl_lock */
  4303. static void bnx2x_after_function_update(struct bnx2x *bp)
  4304. {
  4305. int q, rc;
  4306. struct bnx2x_fastpath *fp;
  4307. struct bnx2x_queue_state_params queue_params = {NULL};
  4308. struct bnx2x_queue_update_params *q_update_params =
  4309. &queue_params.params.update;
  4310. /* Send Q update command with afex vlan removal values for all Qs */
  4311. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4312. /* set silent vlan removal values according to vlan mode */
  4313. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4314. &q_update_params->update_flags);
  4315. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4316. &q_update_params->update_flags);
  4317. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4318. /* in access mode mark mask and value are 0 to strip all vlans */
  4319. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4320. q_update_params->silent_removal_value = 0;
  4321. q_update_params->silent_removal_mask = 0;
  4322. } else {
  4323. q_update_params->silent_removal_value =
  4324. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4325. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4326. }
  4327. for_each_eth_queue(bp, q) {
  4328. /* Set the appropriate Queue object */
  4329. fp = &bp->fp[q];
  4330. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4331. /* send the ramrod */
  4332. rc = bnx2x_queue_state_change(bp, &queue_params);
  4333. if (rc < 0)
  4334. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4335. q);
  4336. }
  4337. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4338. fp = &bp->fp[FCOE_IDX(bp)];
  4339. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4340. /* clear pending completion bit */
  4341. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4342. /* mark latest Q bit */
  4343. smp_mb__before_clear_bit();
  4344. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4345. smp_mb__after_clear_bit();
  4346. /* send Q update ramrod for FCoE Q */
  4347. rc = bnx2x_queue_state_change(bp, &queue_params);
  4348. if (rc < 0)
  4349. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4350. q);
  4351. } else {
  4352. /* If no FCoE ring - ACK MCP now */
  4353. bnx2x_link_report(bp);
  4354. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4355. }
  4356. }
  4357. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4358. struct bnx2x *bp, u32 cid)
  4359. {
  4360. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4361. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4362. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4363. else
  4364. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4365. }
  4366. static void bnx2x_eq_int(struct bnx2x *bp)
  4367. {
  4368. u16 hw_cons, sw_cons, sw_prod;
  4369. union event_ring_elem *elem;
  4370. u8 echo;
  4371. u32 cid;
  4372. u8 opcode;
  4373. int rc, spqe_cnt = 0;
  4374. struct bnx2x_queue_sp_obj *q_obj;
  4375. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4376. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4377. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4378. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4379. * when we get the next-page we need to adjust so the loop
  4380. * condition below will be met. The next element is the size of a
  4381. * regular element and hence incrementing by 1
  4382. */
  4383. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4384. hw_cons++;
  4385. /* This function may never run in parallel with itself for a
  4386. * specific bp, thus there is no need in "paired" read memory
  4387. * barrier here.
  4388. */
  4389. sw_cons = bp->eq_cons;
  4390. sw_prod = bp->eq_prod;
  4391. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4392. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4393. for (; sw_cons != hw_cons;
  4394. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4395. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4396. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4397. if (!rc) {
  4398. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4399. rc);
  4400. goto next_spqe;
  4401. }
  4402. /* elem CID originates from FW; actually LE */
  4403. cid = SW_CID((__force __le32)
  4404. elem->message.data.cfc_del_event.cid);
  4405. opcode = elem->message.opcode;
  4406. /* handle eq element */
  4407. switch (opcode) {
  4408. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4409. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4410. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4411. continue;
  4412. case EVENT_RING_OPCODE_STAT_QUERY:
  4413. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4414. "got statistics comp event %d\n",
  4415. bp->stats_comp++);
  4416. /* nothing to do with stats comp */
  4417. goto next_spqe;
  4418. case EVENT_RING_OPCODE_CFC_DEL:
  4419. /* handle according to cid range */
  4420. /*
  4421. * we may want to verify here that the bp state is
  4422. * HALTING
  4423. */
  4424. DP(BNX2X_MSG_SP,
  4425. "got delete ramrod for MULTI[%d]\n", cid);
  4426. if (CNIC_LOADED(bp) &&
  4427. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4428. goto next_spqe;
  4429. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4430. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4431. break;
  4432. goto next_spqe;
  4433. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4434. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4435. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4436. if (f_obj->complete_cmd(bp, f_obj,
  4437. BNX2X_F_CMD_TX_STOP))
  4438. break;
  4439. goto next_spqe;
  4440. case EVENT_RING_OPCODE_START_TRAFFIC:
  4441. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4442. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4443. if (f_obj->complete_cmd(bp, f_obj,
  4444. BNX2X_F_CMD_TX_START))
  4445. break;
  4446. goto next_spqe;
  4447. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4448. echo = elem->message.data.function_update_event.echo;
  4449. if (echo == SWITCH_UPDATE) {
  4450. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4451. "got FUNC_SWITCH_UPDATE ramrod\n");
  4452. if (f_obj->complete_cmd(
  4453. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4454. break;
  4455. } else {
  4456. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4457. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4458. f_obj->complete_cmd(bp, f_obj,
  4459. BNX2X_F_CMD_AFEX_UPDATE);
  4460. /* We will perform the Queues update from
  4461. * sp_rtnl task as all Queue SP operations
  4462. * should run under rtnl_lock.
  4463. */
  4464. smp_mb__before_clear_bit();
  4465. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4466. &bp->sp_rtnl_state);
  4467. smp_mb__after_clear_bit();
  4468. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4469. }
  4470. goto next_spqe;
  4471. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4472. f_obj->complete_cmd(bp, f_obj,
  4473. BNX2X_F_CMD_AFEX_VIFLISTS);
  4474. bnx2x_after_afex_vif_lists(bp, elem);
  4475. goto next_spqe;
  4476. case EVENT_RING_OPCODE_FUNCTION_START:
  4477. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4478. "got FUNC_START ramrod\n");
  4479. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4480. break;
  4481. goto next_spqe;
  4482. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4483. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4484. "got FUNC_STOP ramrod\n");
  4485. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4486. break;
  4487. goto next_spqe;
  4488. }
  4489. switch (opcode | bp->state) {
  4490. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4491. BNX2X_STATE_OPEN):
  4492. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4493. BNX2X_STATE_OPENING_WAIT4_PORT):
  4494. cid = elem->message.data.eth_event.echo &
  4495. BNX2X_SWCID_MASK;
  4496. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4497. cid);
  4498. rss_raw->clear_pending(rss_raw);
  4499. break;
  4500. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4501. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4502. case (EVENT_RING_OPCODE_SET_MAC |
  4503. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4504. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4505. BNX2X_STATE_OPEN):
  4506. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4507. BNX2X_STATE_DIAG):
  4508. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4509. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4510. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4511. bnx2x_handle_classification_eqe(bp, elem);
  4512. break;
  4513. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4514. BNX2X_STATE_OPEN):
  4515. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4516. BNX2X_STATE_DIAG):
  4517. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4518. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4519. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4520. bnx2x_handle_mcast_eqe(bp);
  4521. break;
  4522. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4523. BNX2X_STATE_OPEN):
  4524. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4525. BNX2X_STATE_DIAG):
  4526. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4527. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4528. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4529. bnx2x_handle_rx_mode_eqe(bp);
  4530. break;
  4531. default:
  4532. /* unknown event log error and continue */
  4533. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4534. elem->message.opcode, bp->state);
  4535. }
  4536. next_spqe:
  4537. spqe_cnt++;
  4538. } /* for */
  4539. smp_mb__before_atomic_inc();
  4540. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4541. bp->eq_cons = sw_cons;
  4542. bp->eq_prod = sw_prod;
  4543. /* Make sure that above mem writes were issued towards the memory */
  4544. smp_wmb();
  4545. /* update producer */
  4546. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4547. }
  4548. static void bnx2x_sp_task(struct work_struct *work)
  4549. {
  4550. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4551. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4552. /* make sure the atomic interrupt_occurred has been written */
  4553. smp_rmb();
  4554. if (atomic_read(&bp->interrupt_occurred)) {
  4555. /* what work needs to be performed? */
  4556. u16 status = bnx2x_update_dsb_idx(bp);
  4557. DP(BNX2X_MSG_SP, "status %x\n", status);
  4558. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4559. atomic_set(&bp->interrupt_occurred, 0);
  4560. /* HW attentions */
  4561. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4562. bnx2x_attn_int(bp);
  4563. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4564. }
  4565. /* SP events: STAT_QUERY and others */
  4566. if (status & BNX2X_DEF_SB_IDX) {
  4567. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4568. if (FCOE_INIT(bp) &&
  4569. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4570. /* Prevent local bottom-halves from running as
  4571. * we are going to change the local NAPI list.
  4572. */
  4573. local_bh_disable();
  4574. napi_schedule(&bnx2x_fcoe(bp, napi));
  4575. local_bh_enable();
  4576. }
  4577. /* Handle EQ completions */
  4578. bnx2x_eq_int(bp);
  4579. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4580. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4581. status &= ~BNX2X_DEF_SB_IDX;
  4582. }
  4583. /* if status is non zero then perhaps something went wrong */
  4584. if (unlikely(status))
  4585. DP(BNX2X_MSG_SP,
  4586. "got an unknown interrupt! (status 0x%x)\n", status);
  4587. /* ack status block only if something was actually handled */
  4588. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4589. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4590. }
  4591. /* must be called after the EQ processing (since eq leads to sriov
  4592. * ramrod completion flows).
  4593. * This flow may have been scheduled by the arrival of a ramrod
  4594. * completion, or by the sriov code rescheduling itself.
  4595. */
  4596. bnx2x_iov_sp_task(bp);
  4597. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4598. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4599. &bp->sp_state)) {
  4600. bnx2x_link_report(bp);
  4601. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4602. }
  4603. }
  4604. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4605. {
  4606. struct net_device *dev = dev_instance;
  4607. struct bnx2x *bp = netdev_priv(dev);
  4608. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4609. IGU_INT_DISABLE, 0);
  4610. #ifdef BNX2X_STOP_ON_ERROR
  4611. if (unlikely(bp->panic))
  4612. return IRQ_HANDLED;
  4613. #endif
  4614. if (CNIC_LOADED(bp)) {
  4615. struct cnic_ops *c_ops;
  4616. rcu_read_lock();
  4617. c_ops = rcu_dereference(bp->cnic_ops);
  4618. if (c_ops)
  4619. c_ops->cnic_handler(bp->cnic_data, NULL);
  4620. rcu_read_unlock();
  4621. }
  4622. /* schedule sp task to perform default status block work, ack
  4623. * attentions and enable interrupts.
  4624. */
  4625. bnx2x_schedule_sp_task(bp);
  4626. return IRQ_HANDLED;
  4627. }
  4628. /* end of slow path */
  4629. void bnx2x_drv_pulse(struct bnx2x *bp)
  4630. {
  4631. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4632. bp->fw_drv_pulse_wr_seq);
  4633. }
  4634. static void bnx2x_timer(unsigned long data)
  4635. {
  4636. struct bnx2x *bp = (struct bnx2x *) data;
  4637. if (!netif_running(bp->dev))
  4638. return;
  4639. if (IS_PF(bp) &&
  4640. !BP_NOMCP(bp)) {
  4641. int mb_idx = BP_FW_MB_IDX(bp);
  4642. u16 drv_pulse;
  4643. u16 mcp_pulse;
  4644. ++bp->fw_drv_pulse_wr_seq;
  4645. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4646. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4647. bnx2x_drv_pulse(bp);
  4648. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4649. MCP_PULSE_SEQ_MASK);
  4650. /* The delta between driver pulse and mcp response
  4651. * should not get too big. If the MFW is more than 5 pulses
  4652. * behind, we should worry about it enough to generate an error
  4653. * log.
  4654. */
  4655. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4656. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4657. drv_pulse, mcp_pulse);
  4658. }
  4659. if (bp->state == BNX2X_STATE_OPEN)
  4660. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4661. /* sample pf vf bulletin board for new posts from pf */
  4662. if (IS_VF(bp))
  4663. bnx2x_timer_sriov(bp);
  4664. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4665. }
  4666. /* end of Statistics */
  4667. /* nic init */
  4668. /*
  4669. * nic init service functions
  4670. */
  4671. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4672. {
  4673. u32 i;
  4674. if (!(len%4) && !(addr%4))
  4675. for (i = 0; i < len; i += 4)
  4676. REG_WR(bp, addr + i, fill);
  4677. else
  4678. for (i = 0; i < len; i++)
  4679. REG_WR8(bp, addr + i, fill);
  4680. }
  4681. /* helper: writes FP SP data to FW - data_size in dwords */
  4682. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4683. int fw_sb_id,
  4684. u32 *sb_data_p,
  4685. u32 data_size)
  4686. {
  4687. int index;
  4688. for (index = 0; index < data_size; index++)
  4689. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4690. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4691. sizeof(u32)*index,
  4692. *(sb_data_p + index));
  4693. }
  4694. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4695. {
  4696. u32 *sb_data_p;
  4697. u32 data_size = 0;
  4698. struct hc_status_block_data_e2 sb_data_e2;
  4699. struct hc_status_block_data_e1x sb_data_e1x;
  4700. /* disable the function first */
  4701. if (!CHIP_IS_E1x(bp)) {
  4702. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4703. sb_data_e2.common.state = SB_DISABLED;
  4704. sb_data_e2.common.p_func.vf_valid = false;
  4705. sb_data_p = (u32 *)&sb_data_e2;
  4706. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4707. } else {
  4708. memset(&sb_data_e1x, 0,
  4709. sizeof(struct hc_status_block_data_e1x));
  4710. sb_data_e1x.common.state = SB_DISABLED;
  4711. sb_data_e1x.common.p_func.vf_valid = false;
  4712. sb_data_p = (u32 *)&sb_data_e1x;
  4713. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4714. }
  4715. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4716. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4717. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4718. CSTORM_STATUS_BLOCK_SIZE);
  4719. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4720. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4721. CSTORM_SYNC_BLOCK_SIZE);
  4722. }
  4723. /* helper: writes SP SB data to FW */
  4724. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4725. struct hc_sp_status_block_data *sp_sb_data)
  4726. {
  4727. int func = BP_FUNC(bp);
  4728. int i;
  4729. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4730. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4731. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4732. i*sizeof(u32),
  4733. *((u32 *)sp_sb_data + i));
  4734. }
  4735. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4736. {
  4737. int func = BP_FUNC(bp);
  4738. struct hc_sp_status_block_data sp_sb_data;
  4739. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4740. sp_sb_data.state = SB_DISABLED;
  4741. sp_sb_data.p_func.vf_valid = false;
  4742. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4743. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4744. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4745. CSTORM_SP_STATUS_BLOCK_SIZE);
  4746. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4747. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4748. CSTORM_SP_SYNC_BLOCK_SIZE);
  4749. }
  4750. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4751. int igu_sb_id, int igu_seg_id)
  4752. {
  4753. hc_sm->igu_sb_id = igu_sb_id;
  4754. hc_sm->igu_seg_id = igu_seg_id;
  4755. hc_sm->timer_value = 0xFF;
  4756. hc_sm->time_to_expire = 0xFFFFFFFF;
  4757. }
  4758. /* allocates state machine ids. */
  4759. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4760. {
  4761. /* zero out state machine indices */
  4762. /* rx indices */
  4763. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4764. /* tx indices */
  4765. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4766. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4767. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4768. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4769. /* map indices */
  4770. /* rx indices */
  4771. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4772. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4773. /* tx indices */
  4774. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4775. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4776. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4777. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4778. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4779. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4780. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4781. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4782. }
  4783. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4784. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4785. {
  4786. int igu_seg_id;
  4787. struct hc_status_block_data_e2 sb_data_e2;
  4788. struct hc_status_block_data_e1x sb_data_e1x;
  4789. struct hc_status_block_sm *hc_sm_p;
  4790. int data_size;
  4791. u32 *sb_data_p;
  4792. if (CHIP_INT_MODE_IS_BC(bp))
  4793. igu_seg_id = HC_SEG_ACCESS_NORM;
  4794. else
  4795. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4796. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4797. if (!CHIP_IS_E1x(bp)) {
  4798. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4799. sb_data_e2.common.state = SB_ENABLED;
  4800. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4801. sb_data_e2.common.p_func.vf_id = vfid;
  4802. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4803. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4804. sb_data_e2.common.same_igu_sb_1b = true;
  4805. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4806. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4807. hc_sm_p = sb_data_e2.common.state_machine;
  4808. sb_data_p = (u32 *)&sb_data_e2;
  4809. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4810. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4811. } else {
  4812. memset(&sb_data_e1x, 0,
  4813. sizeof(struct hc_status_block_data_e1x));
  4814. sb_data_e1x.common.state = SB_ENABLED;
  4815. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4816. sb_data_e1x.common.p_func.vf_id = 0xff;
  4817. sb_data_e1x.common.p_func.vf_valid = false;
  4818. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4819. sb_data_e1x.common.same_igu_sb_1b = true;
  4820. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4821. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4822. hc_sm_p = sb_data_e1x.common.state_machine;
  4823. sb_data_p = (u32 *)&sb_data_e1x;
  4824. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4825. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4826. }
  4827. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4828. igu_sb_id, igu_seg_id);
  4829. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4830. igu_sb_id, igu_seg_id);
  4831. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4832. /* write indices to HW - PCI guarantees endianity of regpairs */
  4833. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4834. }
  4835. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4836. u16 tx_usec, u16 rx_usec)
  4837. {
  4838. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4839. false, rx_usec);
  4840. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4841. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4842. tx_usec);
  4843. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4844. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4845. tx_usec);
  4846. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4847. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4848. tx_usec);
  4849. }
  4850. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4851. {
  4852. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4853. dma_addr_t mapping = bp->def_status_blk_mapping;
  4854. int igu_sp_sb_index;
  4855. int igu_seg_id;
  4856. int port = BP_PORT(bp);
  4857. int func = BP_FUNC(bp);
  4858. int reg_offset, reg_offset_en5;
  4859. u64 section;
  4860. int index;
  4861. struct hc_sp_status_block_data sp_sb_data;
  4862. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4863. if (CHIP_INT_MODE_IS_BC(bp)) {
  4864. igu_sp_sb_index = DEF_SB_IGU_ID;
  4865. igu_seg_id = HC_SEG_ACCESS_DEF;
  4866. } else {
  4867. igu_sp_sb_index = bp->igu_dsb_id;
  4868. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4869. }
  4870. /* ATTN */
  4871. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4872. atten_status_block);
  4873. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4874. bp->attn_state = 0;
  4875. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4876. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4877. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4878. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4879. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4880. int sindex;
  4881. /* take care of sig[0]..sig[4] */
  4882. for (sindex = 0; sindex < 4; sindex++)
  4883. bp->attn_group[index].sig[sindex] =
  4884. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4885. if (!CHIP_IS_E1x(bp))
  4886. /*
  4887. * enable5 is separate from the rest of the registers,
  4888. * and therefore the address skip is 4
  4889. * and not 16 between the different groups
  4890. */
  4891. bp->attn_group[index].sig[4] = REG_RD(bp,
  4892. reg_offset_en5 + 0x4*index);
  4893. else
  4894. bp->attn_group[index].sig[4] = 0;
  4895. }
  4896. if (bp->common.int_block == INT_BLOCK_HC) {
  4897. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4898. HC_REG_ATTN_MSG0_ADDR_L);
  4899. REG_WR(bp, reg_offset, U64_LO(section));
  4900. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4901. } else if (!CHIP_IS_E1x(bp)) {
  4902. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4903. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4904. }
  4905. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4906. sp_sb);
  4907. bnx2x_zero_sp_sb(bp);
  4908. /* PCI guarantees endianity of regpairs */
  4909. sp_sb_data.state = SB_ENABLED;
  4910. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4911. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4912. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4913. sp_sb_data.igu_seg_id = igu_seg_id;
  4914. sp_sb_data.p_func.pf_id = func;
  4915. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4916. sp_sb_data.p_func.vf_id = 0xff;
  4917. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4918. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4919. }
  4920. void bnx2x_update_coalesce(struct bnx2x *bp)
  4921. {
  4922. int i;
  4923. for_each_eth_queue(bp, i)
  4924. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4925. bp->tx_ticks, bp->rx_ticks);
  4926. }
  4927. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4928. {
  4929. spin_lock_init(&bp->spq_lock);
  4930. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4931. bp->spq_prod_idx = 0;
  4932. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4933. bp->spq_prod_bd = bp->spq;
  4934. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4935. }
  4936. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4937. {
  4938. int i;
  4939. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4940. union event_ring_elem *elem =
  4941. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4942. elem->next_page.addr.hi =
  4943. cpu_to_le32(U64_HI(bp->eq_mapping +
  4944. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4945. elem->next_page.addr.lo =
  4946. cpu_to_le32(U64_LO(bp->eq_mapping +
  4947. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4948. }
  4949. bp->eq_cons = 0;
  4950. bp->eq_prod = NUM_EQ_DESC;
  4951. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4952. /* we want a warning message before it gets wrought... */
  4953. atomic_set(&bp->eq_spq_left,
  4954. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4955. }
  4956. /* called with netif_addr_lock_bh() */
  4957. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4958. unsigned long rx_mode_flags,
  4959. unsigned long rx_accept_flags,
  4960. unsigned long tx_accept_flags,
  4961. unsigned long ramrod_flags)
  4962. {
  4963. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4964. int rc;
  4965. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4966. /* Prepare ramrod parameters */
  4967. ramrod_param.cid = 0;
  4968. ramrod_param.cl_id = cl_id;
  4969. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4970. ramrod_param.func_id = BP_FUNC(bp);
  4971. ramrod_param.pstate = &bp->sp_state;
  4972. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4973. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4974. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4975. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4976. ramrod_param.ramrod_flags = ramrod_flags;
  4977. ramrod_param.rx_mode_flags = rx_mode_flags;
  4978. ramrod_param.rx_accept_flags = rx_accept_flags;
  4979. ramrod_param.tx_accept_flags = tx_accept_flags;
  4980. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4981. if (rc < 0) {
  4982. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4983. return rc;
  4984. }
  4985. return 0;
  4986. }
  4987. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4988. unsigned long *rx_accept_flags,
  4989. unsigned long *tx_accept_flags)
  4990. {
  4991. /* Clear the flags first */
  4992. *rx_accept_flags = 0;
  4993. *tx_accept_flags = 0;
  4994. switch (rx_mode) {
  4995. case BNX2X_RX_MODE_NONE:
  4996. /*
  4997. * 'drop all' supersedes any accept flags that may have been
  4998. * passed to the function.
  4999. */
  5000. break;
  5001. case BNX2X_RX_MODE_NORMAL:
  5002. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5003. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5004. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5005. /* internal switching mode */
  5006. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5007. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5008. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5009. break;
  5010. case BNX2X_RX_MODE_ALLMULTI:
  5011. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5012. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5013. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5014. /* internal switching mode */
  5015. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5016. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5017. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5018. break;
  5019. case BNX2X_RX_MODE_PROMISC:
  5020. /* According to definition of SI mode, iface in promisc mode
  5021. * should receive matched and unmatched (in resolution of port)
  5022. * unicast packets.
  5023. */
  5024. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5025. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5026. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5027. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5028. /* internal switching mode */
  5029. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5030. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5031. if (IS_MF_SI(bp))
  5032. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5033. else
  5034. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5035. break;
  5036. default:
  5037. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5038. return -EINVAL;
  5039. }
  5040. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5041. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5042. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5043. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5044. }
  5045. return 0;
  5046. }
  5047. /* called with netif_addr_lock_bh() */
  5048. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5049. {
  5050. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5051. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5052. int rc;
  5053. if (!NO_FCOE(bp))
  5054. /* Configure rx_mode of FCoE Queue */
  5055. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5056. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5057. &tx_accept_flags);
  5058. if (rc)
  5059. return rc;
  5060. __set_bit(RAMROD_RX, &ramrod_flags);
  5061. __set_bit(RAMROD_TX, &ramrod_flags);
  5062. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5063. rx_accept_flags, tx_accept_flags,
  5064. ramrod_flags);
  5065. }
  5066. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5067. {
  5068. int i;
  5069. if (IS_MF_SI(bp))
  5070. /*
  5071. * In switch independent mode, the TSTORM needs to accept
  5072. * packets that failed classification, since approximate match
  5073. * mac addresses aren't written to NIG LLH
  5074. */
  5075. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5076. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  5077. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  5078. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5079. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  5080. /* Zero this manually as its initialization is
  5081. currently missing in the initTool */
  5082. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5083. REG_WR(bp, BAR_USTRORM_INTMEM +
  5084. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5085. if (!CHIP_IS_E1x(bp)) {
  5086. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5087. CHIP_INT_MODE_IS_BC(bp) ?
  5088. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5089. }
  5090. }
  5091. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5092. {
  5093. switch (load_code) {
  5094. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5095. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5096. bnx2x_init_internal_common(bp);
  5097. /* no break */
  5098. case FW_MSG_CODE_DRV_LOAD_PORT:
  5099. /* nothing to do */
  5100. /* no break */
  5101. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5102. /* internal memory per function is
  5103. initialized inside bnx2x_pf_init */
  5104. break;
  5105. default:
  5106. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5107. break;
  5108. }
  5109. }
  5110. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5111. {
  5112. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5113. }
  5114. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5115. {
  5116. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5117. }
  5118. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5119. {
  5120. if (CHIP_IS_E1x(fp->bp))
  5121. return BP_L_ID(fp->bp) + fp->index;
  5122. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5123. return bnx2x_fp_igu_sb_id(fp);
  5124. }
  5125. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5126. {
  5127. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5128. u8 cos;
  5129. unsigned long q_type = 0;
  5130. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5131. fp->rx_queue = fp_idx;
  5132. fp->cid = fp_idx;
  5133. fp->cl_id = bnx2x_fp_cl_id(fp);
  5134. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5135. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5136. /* qZone id equals to FW (per path) client id */
  5137. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5138. /* init shortcut */
  5139. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5140. /* Setup SB indices */
  5141. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5142. /* Configure Queue State object */
  5143. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5144. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5145. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5146. /* init tx data */
  5147. for_each_cos_in_tx_queue(fp, cos) {
  5148. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5149. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5150. FP_COS_TO_TXQ(fp, cos, bp),
  5151. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5152. cids[cos] = fp->txdata_ptr[cos]->cid;
  5153. }
  5154. /* nothing more for vf to do here */
  5155. if (IS_VF(bp))
  5156. return;
  5157. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5158. fp->fw_sb_id, fp->igu_sb_id);
  5159. bnx2x_update_fpsb_idx(fp);
  5160. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5161. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5162. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5163. /**
  5164. * Configure classification DBs: Always enable Tx switching
  5165. */
  5166. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5167. DP(NETIF_MSG_IFUP,
  5168. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5169. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5170. fp->igu_sb_id);
  5171. }
  5172. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5173. {
  5174. int i;
  5175. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5176. struct eth_tx_next_bd *tx_next_bd =
  5177. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5178. tx_next_bd->addr_hi =
  5179. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5180. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5181. tx_next_bd->addr_lo =
  5182. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5183. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5184. }
  5185. *txdata->tx_cons_sb = cpu_to_le16(0);
  5186. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5187. txdata->tx_db.data.zero_fill1 = 0;
  5188. txdata->tx_db.data.prod = 0;
  5189. txdata->tx_pkt_prod = 0;
  5190. txdata->tx_pkt_cons = 0;
  5191. txdata->tx_bd_prod = 0;
  5192. txdata->tx_bd_cons = 0;
  5193. txdata->tx_pkt = 0;
  5194. }
  5195. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5196. {
  5197. int i;
  5198. for_each_tx_queue_cnic(bp, i)
  5199. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5200. }
  5201. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5202. {
  5203. int i;
  5204. u8 cos;
  5205. for_each_eth_queue(bp, i)
  5206. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5207. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5208. }
  5209. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5210. {
  5211. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5212. unsigned long q_type = 0;
  5213. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5214. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5215. BNX2X_FCOE_ETH_CL_ID_IDX);
  5216. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5217. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5218. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5219. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5220. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5221. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5222. fp);
  5223. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5224. /* qZone id equals to FW (per path) client id */
  5225. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5226. /* init shortcut */
  5227. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5228. bnx2x_rx_ustorm_prods_offset(fp);
  5229. /* Configure Queue State object */
  5230. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5231. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5232. /* No multi-CoS for FCoE L2 client */
  5233. BUG_ON(fp->max_cos != 1);
  5234. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5235. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5236. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5237. DP(NETIF_MSG_IFUP,
  5238. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5239. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5240. fp->igu_sb_id);
  5241. }
  5242. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5243. {
  5244. if (!NO_FCOE(bp))
  5245. bnx2x_init_fcoe_fp(bp);
  5246. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5247. BNX2X_VF_ID_INVALID, false,
  5248. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5249. /* ensure status block indices were read */
  5250. rmb();
  5251. bnx2x_init_rx_rings_cnic(bp);
  5252. bnx2x_init_tx_rings_cnic(bp);
  5253. /* flush all */
  5254. mb();
  5255. mmiowb();
  5256. }
  5257. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5258. {
  5259. int i;
  5260. /* Setup NIC internals and enable interrupts */
  5261. for_each_eth_queue(bp, i)
  5262. bnx2x_init_eth_fp(bp, i);
  5263. /* ensure status block indices were read */
  5264. rmb();
  5265. bnx2x_init_rx_rings(bp);
  5266. bnx2x_init_tx_rings(bp);
  5267. if (IS_PF(bp)) {
  5268. /* Initialize MOD_ABS interrupts */
  5269. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5270. bp->common.shmem_base,
  5271. bp->common.shmem2_base, BP_PORT(bp));
  5272. /* initialize the default status block and sp ring */
  5273. bnx2x_init_def_sb(bp);
  5274. bnx2x_update_dsb_idx(bp);
  5275. bnx2x_init_sp_ring(bp);
  5276. } else {
  5277. bnx2x_memset_stats(bp);
  5278. }
  5279. }
  5280. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5281. {
  5282. bnx2x_init_eq_ring(bp);
  5283. bnx2x_init_internal(bp, load_code);
  5284. bnx2x_pf_init(bp);
  5285. bnx2x_stats_init(bp);
  5286. /* flush all before enabling interrupts */
  5287. mb();
  5288. mmiowb();
  5289. bnx2x_int_enable(bp);
  5290. /* Check for SPIO5 */
  5291. bnx2x_attn_int_deasserted0(bp,
  5292. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5293. AEU_INPUTS_ATTN_BITS_SPIO5);
  5294. }
  5295. /* gzip service functions */
  5296. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5297. {
  5298. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5299. &bp->gunzip_mapping, GFP_KERNEL);
  5300. if (bp->gunzip_buf == NULL)
  5301. goto gunzip_nomem1;
  5302. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5303. if (bp->strm == NULL)
  5304. goto gunzip_nomem2;
  5305. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5306. if (bp->strm->workspace == NULL)
  5307. goto gunzip_nomem3;
  5308. return 0;
  5309. gunzip_nomem3:
  5310. kfree(bp->strm);
  5311. bp->strm = NULL;
  5312. gunzip_nomem2:
  5313. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5314. bp->gunzip_mapping);
  5315. bp->gunzip_buf = NULL;
  5316. gunzip_nomem1:
  5317. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5318. return -ENOMEM;
  5319. }
  5320. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5321. {
  5322. if (bp->strm) {
  5323. vfree(bp->strm->workspace);
  5324. kfree(bp->strm);
  5325. bp->strm = NULL;
  5326. }
  5327. if (bp->gunzip_buf) {
  5328. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5329. bp->gunzip_mapping);
  5330. bp->gunzip_buf = NULL;
  5331. }
  5332. }
  5333. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5334. {
  5335. int n, rc;
  5336. /* check gzip header */
  5337. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5338. BNX2X_ERR("Bad gzip header\n");
  5339. return -EINVAL;
  5340. }
  5341. n = 10;
  5342. #define FNAME 0x8
  5343. if (zbuf[3] & FNAME)
  5344. while ((zbuf[n++] != 0) && (n < len));
  5345. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5346. bp->strm->avail_in = len - n;
  5347. bp->strm->next_out = bp->gunzip_buf;
  5348. bp->strm->avail_out = FW_BUF_SIZE;
  5349. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5350. if (rc != Z_OK)
  5351. return rc;
  5352. rc = zlib_inflate(bp->strm, Z_FINISH);
  5353. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5354. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5355. bp->strm->msg);
  5356. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5357. if (bp->gunzip_outlen & 0x3)
  5358. netdev_err(bp->dev,
  5359. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5360. bp->gunzip_outlen);
  5361. bp->gunzip_outlen >>= 2;
  5362. zlib_inflateEnd(bp->strm);
  5363. if (rc == Z_STREAM_END)
  5364. return 0;
  5365. return rc;
  5366. }
  5367. /* nic load/unload */
  5368. /*
  5369. * General service functions
  5370. */
  5371. /* send a NIG loopback debug packet */
  5372. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5373. {
  5374. u32 wb_write[3];
  5375. /* Ethernet source and destination addresses */
  5376. wb_write[0] = 0x55555555;
  5377. wb_write[1] = 0x55555555;
  5378. wb_write[2] = 0x20; /* SOP */
  5379. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5380. /* NON-IP protocol */
  5381. wb_write[0] = 0x09000000;
  5382. wb_write[1] = 0x55555555;
  5383. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5384. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5385. }
  5386. /* some of the internal memories
  5387. * are not directly readable from the driver
  5388. * to test them we send debug packets
  5389. */
  5390. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5391. {
  5392. int factor;
  5393. int count, i;
  5394. u32 val = 0;
  5395. if (CHIP_REV_IS_FPGA(bp))
  5396. factor = 120;
  5397. else if (CHIP_REV_IS_EMUL(bp))
  5398. factor = 200;
  5399. else
  5400. factor = 1;
  5401. /* Disable inputs of parser neighbor blocks */
  5402. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5403. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5404. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5405. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5406. /* Write 0 to parser credits for CFC search request */
  5407. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5408. /* send Ethernet packet */
  5409. bnx2x_lb_pckt(bp);
  5410. /* TODO do i reset NIG statistic? */
  5411. /* Wait until NIG register shows 1 packet of size 0x10 */
  5412. count = 1000 * factor;
  5413. while (count) {
  5414. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5415. val = *bnx2x_sp(bp, wb_data[0]);
  5416. if (val == 0x10)
  5417. break;
  5418. usleep_range(10000, 20000);
  5419. count--;
  5420. }
  5421. if (val != 0x10) {
  5422. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5423. return -1;
  5424. }
  5425. /* Wait until PRS register shows 1 packet */
  5426. count = 1000 * factor;
  5427. while (count) {
  5428. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5429. if (val == 1)
  5430. break;
  5431. usleep_range(10000, 20000);
  5432. count--;
  5433. }
  5434. if (val != 0x1) {
  5435. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5436. return -2;
  5437. }
  5438. /* Reset and init BRB, PRS */
  5439. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5440. msleep(50);
  5441. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5442. msleep(50);
  5443. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5444. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5445. DP(NETIF_MSG_HW, "part2\n");
  5446. /* Disable inputs of parser neighbor blocks */
  5447. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5448. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5449. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5450. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5451. /* Write 0 to parser credits for CFC search request */
  5452. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5453. /* send 10 Ethernet packets */
  5454. for (i = 0; i < 10; i++)
  5455. bnx2x_lb_pckt(bp);
  5456. /* Wait until NIG register shows 10 + 1
  5457. packets of size 11*0x10 = 0xb0 */
  5458. count = 1000 * factor;
  5459. while (count) {
  5460. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5461. val = *bnx2x_sp(bp, wb_data[0]);
  5462. if (val == 0xb0)
  5463. break;
  5464. usleep_range(10000, 20000);
  5465. count--;
  5466. }
  5467. if (val != 0xb0) {
  5468. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5469. return -3;
  5470. }
  5471. /* Wait until PRS register shows 2 packets */
  5472. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5473. if (val != 2)
  5474. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5475. /* Write 1 to parser credits for CFC search request */
  5476. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5477. /* Wait until PRS register shows 3 packets */
  5478. msleep(10 * factor);
  5479. /* Wait until NIG register shows 1 packet of size 0x10 */
  5480. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5481. if (val != 3)
  5482. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5483. /* clear NIG EOP FIFO */
  5484. for (i = 0; i < 11; i++)
  5485. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5486. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5487. if (val != 1) {
  5488. BNX2X_ERR("clear of NIG failed\n");
  5489. return -4;
  5490. }
  5491. /* Reset and init BRB, PRS, NIG */
  5492. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5493. msleep(50);
  5494. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5495. msleep(50);
  5496. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5497. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5498. if (!CNIC_SUPPORT(bp))
  5499. /* set NIC mode */
  5500. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5501. /* Enable inputs of parser neighbor blocks */
  5502. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5503. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5504. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5505. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5506. DP(NETIF_MSG_HW, "done\n");
  5507. return 0; /* OK */
  5508. }
  5509. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5510. {
  5511. u32 val;
  5512. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5513. if (!CHIP_IS_E1x(bp))
  5514. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5515. else
  5516. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5517. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5518. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5519. /*
  5520. * mask read length error interrupts in brb for parser
  5521. * (parsing unit and 'checksum and crc' unit)
  5522. * these errors are legal (PU reads fixed length and CAC can cause
  5523. * read length error on truncated packets)
  5524. */
  5525. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5526. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5527. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5528. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5529. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5530. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5531. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5532. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5533. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5534. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5535. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5536. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5537. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5538. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5539. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5540. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5541. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5542. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5543. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5544. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5545. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5546. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5547. if (!CHIP_IS_E1x(bp))
  5548. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5549. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5550. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5551. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5552. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5553. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5554. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5555. if (!CHIP_IS_E1x(bp))
  5556. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5557. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5558. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5559. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5560. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5561. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5562. }
  5563. static void bnx2x_reset_common(struct bnx2x *bp)
  5564. {
  5565. u32 val = 0x1400;
  5566. /* reset_common */
  5567. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5568. 0xd3ffff7f);
  5569. if (CHIP_IS_E3(bp)) {
  5570. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5571. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5572. }
  5573. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5574. }
  5575. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5576. {
  5577. bp->dmae_ready = 0;
  5578. spin_lock_init(&bp->dmae_lock);
  5579. }
  5580. static void bnx2x_init_pxp(struct bnx2x *bp)
  5581. {
  5582. u16 devctl;
  5583. int r_order, w_order;
  5584. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5585. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5586. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5587. if (bp->mrrs == -1)
  5588. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5589. else {
  5590. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5591. r_order = bp->mrrs;
  5592. }
  5593. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5594. }
  5595. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5596. {
  5597. int is_required;
  5598. u32 val;
  5599. int port;
  5600. if (BP_NOMCP(bp))
  5601. return;
  5602. is_required = 0;
  5603. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5604. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5605. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5606. is_required = 1;
  5607. /*
  5608. * The fan failure mechanism is usually related to the PHY type since
  5609. * the power consumption of the board is affected by the PHY. Currently,
  5610. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5611. */
  5612. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5613. for (port = PORT_0; port < PORT_MAX; port++) {
  5614. is_required |=
  5615. bnx2x_fan_failure_det_req(
  5616. bp,
  5617. bp->common.shmem_base,
  5618. bp->common.shmem2_base,
  5619. port);
  5620. }
  5621. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5622. if (is_required == 0)
  5623. return;
  5624. /* Fan failure is indicated by SPIO 5 */
  5625. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5626. /* set to active low mode */
  5627. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5628. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5629. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5630. /* enable interrupt to signal the IGU */
  5631. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5632. val |= MISC_SPIO_SPIO5;
  5633. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5634. }
  5635. void bnx2x_pf_disable(struct bnx2x *bp)
  5636. {
  5637. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5638. val &= ~IGU_PF_CONF_FUNC_EN;
  5639. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5640. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5641. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5642. }
  5643. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5644. {
  5645. u32 shmem_base[2], shmem2_base[2];
  5646. /* Avoid common init in case MFW supports LFA */
  5647. if (SHMEM2_RD(bp, size) >
  5648. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5649. return;
  5650. shmem_base[0] = bp->common.shmem_base;
  5651. shmem2_base[0] = bp->common.shmem2_base;
  5652. if (!CHIP_IS_E1x(bp)) {
  5653. shmem_base[1] =
  5654. SHMEM2_RD(bp, other_shmem_base_addr);
  5655. shmem2_base[1] =
  5656. SHMEM2_RD(bp, other_shmem2_base_addr);
  5657. }
  5658. bnx2x_acquire_phy_lock(bp);
  5659. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5660. bp->common.chip_id);
  5661. bnx2x_release_phy_lock(bp);
  5662. }
  5663. /**
  5664. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5665. *
  5666. * @bp: driver handle
  5667. */
  5668. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5669. {
  5670. u32 val;
  5671. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5672. /*
  5673. * take the RESET lock to protect undi_unload flow from accessing
  5674. * registers while we're resetting the chip
  5675. */
  5676. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5677. bnx2x_reset_common(bp);
  5678. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5679. val = 0xfffc;
  5680. if (CHIP_IS_E3(bp)) {
  5681. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5682. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5683. }
  5684. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5685. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5686. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5687. if (!CHIP_IS_E1x(bp)) {
  5688. u8 abs_func_id;
  5689. /**
  5690. * 4-port mode or 2-port mode we need to turn of master-enable
  5691. * for everyone, after that, turn it back on for self.
  5692. * so, we disregard multi-function or not, and always disable
  5693. * for all functions on the given path, this means 0,2,4,6 for
  5694. * path 0 and 1,3,5,7 for path 1
  5695. */
  5696. for (abs_func_id = BP_PATH(bp);
  5697. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5698. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5699. REG_WR(bp,
  5700. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5701. 1);
  5702. continue;
  5703. }
  5704. bnx2x_pretend_func(bp, abs_func_id);
  5705. /* clear pf enable */
  5706. bnx2x_pf_disable(bp);
  5707. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5708. }
  5709. }
  5710. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5711. if (CHIP_IS_E1(bp)) {
  5712. /* enable HW interrupt from PXP on USDM overflow
  5713. bit 16 on INT_MASK_0 */
  5714. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5715. }
  5716. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5717. bnx2x_init_pxp(bp);
  5718. #ifdef __BIG_ENDIAN
  5719. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5720. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5721. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5722. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5723. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5724. /* make sure this value is 0 */
  5725. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5726. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5727. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5728. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5729. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5730. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5731. #endif
  5732. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5733. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5734. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5735. /* let the HW do it's magic ... */
  5736. msleep(100);
  5737. /* finish PXP init */
  5738. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5739. if (val != 1) {
  5740. BNX2X_ERR("PXP2 CFG failed\n");
  5741. return -EBUSY;
  5742. }
  5743. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5744. if (val != 1) {
  5745. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5746. return -EBUSY;
  5747. }
  5748. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5749. * have entries with value "0" and valid bit on.
  5750. * This needs to be done by the first PF that is loaded in a path
  5751. * (i.e. common phase)
  5752. */
  5753. if (!CHIP_IS_E1x(bp)) {
  5754. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5755. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5756. * This occurs when a different function (func2,3) is being marked
  5757. * as "scan-off". Real-life scenario for example: if a driver is being
  5758. * load-unloaded while func6,7 are down. This will cause the timer to access
  5759. * the ilt, translate to a logical address and send a request to read/write.
  5760. * Since the ilt for the function that is down is not valid, this will cause
  5761. * a translation error which is unrecoverable.
  5762. * The Workaround is intended to make sure that when this happens nothing fatal
  5763. * will occur. The workaround:
  5764. * 1. First PF driver which loads on a path will:
  5765. * a. After taking the chip out of reset, by using pretend,
  5766. * it will write "0" to the following registers of
  5767. * the other vnics.
  5768. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5769. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5770. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5771. * And for itself it will write '1' to
  5772. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5773. * dmae-operations (writing to pram for example.)
  5774. * note: can be done for only function 6,7 but cleaner this
  5775. * way.
  5776. * b. Write zero+valid to the entire ILT.
  5777. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5778. * VNIC3 (of that port). The range allocated will be the
  5779. * entire ILT. This is needed to prevent ILT range error.
  5780. * 2. Any PF driver load flow:
  5781. * a. ILT update with the physical addresses of the allocated
  5782. * logical pages.
  5783. * b. Wait 20msec. - note that this timeout is needed to make
  5784. * sure there are no requests in one of the PXP internal
  5785. * queues with "old" ILT addresses.
  5786. * c. PF enable in the PGLC.
  5787. * d. Clear the was_error of the PF in the PGLC. (could have
  5788. * occurred while driver was down)
  5789. * e. PF enable in the CFC (WEAK + STRONG)
  5790. * f. Timers scan enable
  5791. * 3. PF driver unload flow:
  5792. * a. Clear the Timers scan_en.
  5793. * b. Polling for scan_on=0 for that PF.
  5794. * c. Clear the PF enable bit in the PXP.
  5795. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5796. * e. Write zero+valid to all ILT entries (The valid bit must
  5797. * stay set)
  5798. * f. If this is VNIC 3 of a port then also init
  5799. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5800. * to the last entry in the ILT.
  5801. *
  5802. * Notes:
  5803. * Currently the PF error in the PGLC is non recoverable.
  5804. * In the future the there will be a recovery routine for this error.
  5805. * Currently attention is masked.
  5806. * Having an MCP lock on the load/unload process does not guarantee that
  5807. * there is no Timer disable during Func6/7 enable. This is because the
  5808. * Timers scan is currently being cleared by the MCP on FLR.
  5809. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5810. * there is error before clearing it. But the flow above is simpler and
  5811. * more general.
  5812. * All ILT entries are written by zero+valid and not just PF6/7
  5813. * ILT entries since in the future the ILT entries allocation for
  5814. * PF-s might be dynamic.
  5815. */
  5816. struct ilt_client_info ilt_cli;
  5817. struct bnx2x_ilt ilt;
  5818. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5819. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5820. /* initialize dummy TM client */
  5821. ilt_cli.start = 0;
  5822. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5823. ilt_cli.client_num = ILT_CLIENT_TM;
  5824. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5825. * Step 2: set the timers first/last ilt entry to point
  5826. * to the entire range to prevent ILT range error for 3rd/4th
  5827. * vnic (this code assumes existence of the vnic)
  5828. *
  5829. * both steps performed by call to bnx2x_ilt_client_init_op()
  5830. * with dummy TM client
  5831. *
  5832. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5833. * and his brother are split registers
  5834. */
  5835. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5836. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5837. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5838. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5839. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5840. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5841. }
  5842. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5843. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5844. if (!CHIP_IS_E1x(bp)) {
  5845. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5846. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5847. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5848. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5849. /* let the HW do it's magic ... */
  5850. do {
  5851. msleep(200);
  5852. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5853. } while (factor-- && (val != 1));
  5854. if (val != 1) {
  5855. BNX2X_ERR("ATC_INIT failed\n");
  5856. return -EBUSY;
  5857. }
  5858. }
  5859. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5860. bnx2x_iov_init_dmae(bp);
  5861. /* clean the DMAE memory */
  5862. bp->dmae_ready = 1;
  5863. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5864. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5865. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5866. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5867. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5868. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5869. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5870. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5871. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5872. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5873. /* QM queues pointers table */
  5874. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5875. /* soft reset pulse */
  5876. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5877. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5878. if (CNIC_SUPPORT(bp))
  5879. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5880. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5881. if (!CHIP_REV_IS_SLOW(bp))
  5882. /* enable hw interrupt from doorbell Q */
  5883. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5884. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5885. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5886. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5887. if (!CHIP_IS_E1(bp))
  5888. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5889. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5890. if (IS_MF_AFEX(bp)) {
  5891. /* configure that VNTag and VLAN headers must be
  5892. * received in afex mode
  5893. */
  5894. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5895. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5896. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5897. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5898. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5899. } else {
  5900. /* Bit-map indicating which L2 hdrs may appear
  5901. * after the basic Ethernet header
  5902. */
  5903. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5904. bp->path_has_ovlan ? 7 : 6);
  5905. }
  5906. }
  5907. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5908. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5909. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5910. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5911. if (!CHIP_IS_E1x(bp)) {
  5912. /* reset VFC memories */
  5913. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5914. VFC_MEMORIES_RST_REG_CAM_RST |
  5915. VFC_MEMORIES_RST_REG_RAM_RST);
  5916. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5917. VFC_MEMORIES_RST_REG_CAM_RST |
  5918. VFC_MEMORIES_RST_REG_RAM_RST);
  5919. msleep(20);
  5920. }
  5921. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5922. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5923. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5924. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5925. /* sync semi rtc */
  5926. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5927. 0x80000000);
  5928. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5929. 0x80000000);
  5930. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5931. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5932. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5933. if (!CHIP_IS_E1x(bp)) {
  5934. if (IS_MF_AFEX(bp)) {
  5935. /* configure that VNTag and VLAN headers must be
  5936. * sent in afex mode
  5937. */
  5938. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5939. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5940. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5941. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5942. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5943. } else {
  5944. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5945. bp->path_has_ovlan ? 7 : 6);
  5946. }
  5947. }
  5948. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5949. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5950. if (CNIC_SUPPORT(bp)) {
  5951. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5952. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5953. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5954. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5955. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5956. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5957. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5958. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5959. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5960. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5961. }
  5962. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5963. if (sizeof(union cdu_context) != 1024)
  5964. /* we currently assume that a context is 1024 bytes */
  5965. dev_alert(&bp->pdev->dev,
  5966. "please adjust the size of cdu_context(%ld)\n",
  5967. (long)sizeof(union cdu_context));
  5968. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5969. val = (4 << 24) + (0 << 12) + 1024;
  5970. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5971. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5972. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5973. /* enable context validation interrupt from CFC */
  5974. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5975. /* set the thresholds to prevent CFC/CDU race */
  5976. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5977. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5978. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5979. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5980. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5981. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5982. /* Reset PCIE errors for debug */
  5983. REG_WR(bp, 0x2814, 0xffffffff);
  5984. REG_WR(bp, 0x3820, 0xffffffff);
  5985. if (!CHIP_IS_E1x(bp)) {
  5986. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5987. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5988. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5989. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5990. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5991. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5992. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5993. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5994. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5995. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5996. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5997. }
  5998. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5999. if (!CHIP_IS_E1(bp)) {
  6000. /* in E3 this done in per-port section */
  6001. if (!CHIP_IS_E3(bp))
  6002. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6003. }
  6004. if (CHIP_IS_E1H(bp))
  6005. /* not applicable for E2 (and above ...) */
  6006. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6007. if (CHIP_REV_IS_SLOW(bp))
  6008. msleep(200);
  6009. /* finish CFC init */
  6010. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6011. if (val != 1) {
  6012. BNX2X_ERR("CFC LL_INIT failed\n");
  6013. return -EBUSY;
  6014. }
  6015. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6016. if (val != 1) {
  6017. BNX2X_ERR("CFC AC_INIT failed\n");
  6018. return -EBUSY;
  6019. }
  6020. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6021. if (val != 1) {
  6022. BNX2X_ERR("CFC CAM_INIT failed\n");
  6023. return -EBUSY;
  6024. }
  6025. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6026. if (CHIP_IS_E1(bp)) {
  6027. /* read NIG statistic
  6028. to see if this is our first up since powerup */
  6029. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6030. val = *bnx2x_sp(bp, wb_data[0]);
  6031. /* do internal memory self test */
  6032. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6033. BNX2X_ERR("internal mem self test failed\n");
  6034. return -EBUSY;
  6035. }
  6036. }
  6037. bnx2x_setup_fan_failure_detection(bp);
  6038. /* clear PXP2 attentions */
  6039. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6040. bnx2x_enable_blocks_attention(bp);
  6041. bnx2x_enable_blocks_parity(bp);
  6042. if (!BP_NOMCP(bp)) {
  6043. if (CHIP_IS_E1x(bp))
  6044. bnx2x__common_init_phy(bp);
  6045. } else
  6046. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6047. return 0;
  6048. }
  6049. /**
  6050. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6051. *
  6052. * @bp: driver handle
  6053. */
  6054. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6055. {
  6056. int rc = bnx2x_init_hw_common(bp);
  6057. if (rc)
  6058. return rc;
  6059. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6060. if (!BP_NOMCP(bp))
  6061. bnx2x__common_init_phy(bp);
  6062. return 0;
  6063. }
  6064. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6065. {
  6066. int port = BP_PORT(bp);
  6067. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6068. u32 low, high;
  6069. u32 val, reg;
  6070. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6071. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6072. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6073. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6074. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6075. /* Timers bug workaround: disables the pf_master bit in pglue at
  6076. * common phase, we need to enable it here before any dmae access are
  6077. * attempted. Therefore we manually added the enable-master to the
  6078. * port phase (it also happens in the function phase)
  6079. */
  6080. if (!CHIP_IS_E1x(bp))
  6081. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6082. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6083. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6084. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6085. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6086. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6087. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6088. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6089. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6090. /* QM cid (connection) count */
  6091. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6092. if (CNIC_SUPPORT(bp)) {
  6093. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6094. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6095. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6096. }
  6097. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6098. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6099. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6100. if (IS_MF(bp))
  6101. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6102. else if (bp->dev->mtu > 4096) {
  6103. if (bp->flags & ONE_PORT_FLAG)
  6104. low = 160;
  6105. else {
  6106. val = bp->dev->mtu;
  6107. /* (24*1024 + val*4)/256 */
  6108. low = 96 + (val/64) +
  6109. ((val % 64) ? 1 : 0);
  6110. }
  6111. } else
  6112. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6113. high = low + 56; /* 14*1024/256 */
  6114. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6115. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6116. }
  6117. if (CHIP_MODE_IS_4_PORT(bp))
  6118. REG_WR(bp, (BP_PORT(bp) ?
  6119. BRB1_REG_MAC_GUARANTIED_1 :
  6120. BRB1_REG_MAC_GUARANTIED_0), 40);
  6121. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6122. if (CHIP_IS_E3B0(bp)) {
  6123. if (IS_MF_AFEX(bp)) {
  6124. /* configure headers for AFEX mode */
  6125. REG_WR(bp, BP_PORT(bp) ?
  6126. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6127. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6128. REG_WR(bp, BP_PORT(bp) ?
  6129. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6130. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6131. REG_WR(bp, BP_PORT(bp) ?
  6132. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6133. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6134. } else {
  6135. /* Ovlan exists only if we are in multi-function +
  6136. * switch-dependent mode, in switch-independent there
  6137. * is no ovlan headers
  6138. */
  6139. REG_WR(bp, BP_PORT(bp) ?
  6140. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6141. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6142. (bp->path_has_ovlan ? 7 : 6));
  6143. }
  6144. }
  6145. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6146. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6147. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6148. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6149. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6150. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6151. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6152. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6153. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6154. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6155. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6156. if (CHIP_IS_E1x(bp)) {
  6157. /* configure PBF to work without PAUSE mtu 9000 */
  6158. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6159. /* update threshold */
  6160. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6161. /* update init credit */
  6162. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6163. /* probe changes */
  6164. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6165. udelay(50);
  6166. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6167. }
  6168. if (CNIC_SUPPORT(bp))
  6169. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6170. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6171. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6172. if (CHIP_IS_E1(bp)) {
  6173. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6174. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6175. }
  6176. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6177. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6178. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6179. /* init aeu_mask_attn_func_0/1:
  6180. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6181. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6182. * bits 4-7 are used for "per vn group attention" */
  6183. val = IS_MF(bp) ? 0xF7 : 0x7;
  6184. /* Enable DCBX attention for all but E1 */
  6185. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6186. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6187. /* SCPAD_PARITY should NOT trigger close the gates */
  6188. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6189. REG_WR(bp, reg,
  6190. REG_RD(bp, reg) &
  6191. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6192. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6193. REG_WR(bp, reg,
  6194. REG_RD(bp, reg) &
  6195. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6196. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6197. if (!CHIP_IS_E1x(bp)) {
  6198. /* Bit-map indicating which L2 hdrs may appear after the
  6199. * basic Ethernet header
  6200. */
  6201. if (IS_MF_AFEX(bp))
  6202. REG_WR(bp, BP_PORT(bp) ?
  6203. NIG_REG_P1_HDRS_AFTER_BASIC :
  6204. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6205. else
  6206. REG_WR(bp, BP_PORT(bp) ?
  6207. NIG_REG_P1_HDRS_AFTER_BASIC :
  6208. NIG_REG_P0_HDRS_AFTER_BASIC,
  6209. IS_MF_SD(bp) ? 7 : 6);
  6210. if (CHIP_IS_E3(bp))
  6211. REG_WR(bp, BP_PORT(bp) ?
  6212. NIG_REG_LLH1_MF_MODE :
  6213. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6214. }
  6215. if (!CHIP_IS_E3(bp))
  6216. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6217. if (!CHIP_IS_E1(bp)) {
  6218. /* 0x2 disable mf_ov, 0x1 enable */
  6219. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6220. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6221. if (!CHIP_IS_E1x(bp)) {
  6222. val = 0;
  6223. switch (bp->mf_mode) {
  6224. case MULTI_FUNCTION_SD:
  6225. val = 1;
  6226. break;
  6227. case MULTI_FUNCTION_SI:
  6228. case MULTI_FUNCTION_AFEX:
  6229. val = 2;
  6230. break;
  6231. }
  6232. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6233. NIG_REG_LLH0_CLS_TYPE), val);
  6234. }
  6235. {
  6236. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6237. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6238. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6239. }
  6240. }
  6241. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6242. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6243. if (val & MISC_SPIO_SPIO5) {
  6244. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6245. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6246. val = REG_RD(bp, reg_addr);
  6247. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6248. REG_WR(bp, reg_addr, val);
  6249. }
  6250. return 0;
  6251. }
  6252. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6253. {
  6254. int reg;
  6255. u32 wb_write[2];
  6256. if (CHIP_IS_E1(bp))
  6257. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6258. else
  6259. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6260. wb_write[0] = ONCHIP_ADDR1(addr);
  6261. wb_write[1] = ONCHIP_ADDR2(addr);
  6262. REG_WR_DMAE(bp, reg, wb_write, 2);
  6263. }
  6264. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6265. {
  6266. u32 data, ctl, cnt = 100;
  6267. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6268. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6269. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6270. u32 sb_bit = 1 << (idu_sb_id%32);
  6271. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6272. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6273. /* Not supported in BC mode */
  6274. if (CHIP_INT_MODE_IS_BC(bp))
  6275. return;
  6276. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6277. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6278. IGU_REGULAR_CLEANUP_SET |
  6279. IGU_REGULAR_BCLEANUP;
  6280. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6281. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6282. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6283. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6284. data, igu_addr_data);
  6285. REG_WR(bp, igu_addr_data, data);
  6286. mmiowb();
  6287. barrier();
  6288. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6289. ctl, igu_addr_ctl);
  6290. REG_WR(bp, igu_addr_ctl, ctl);
  6291. mmiowb();
  6292. barrier();
  6293. /* wait for clean up to finish */
  6294. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6295. msleep(20);
  6296. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6297. DP(NETIF_MSG_HW,
  6298. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6299. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6300. }
  6301. }
  6302. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6303. {
  6304. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6305. }
  6306. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6307. {
  6308. u32 i, base = FUNC_ILT_BASE(func);
  6309. for (i = base; i < base + ILT_PER_FUNC; i++)
  6310. bnx2x_ilt_wr(bp, i, 0);
  6311. }
  6312. static void bnx2x_init_searcher(struct bnx2x *bp)
  6313. {
  6314. int port = BP_PORT(bp);
  6315. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6316. /* T1 hash bits value determines the T1 number of entries */
  6317. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6318. }
  6319. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6320. {
  6321. int rc;
  6322. struct bnx2x_func_state_params func_params = {NULL};
  6323. struct bnx2x_func_switch_update_params *switch_update_params =
  6324. &func_params.params.switch_update;
  6325. /* Prepare parameters for function state transitions */
  6326. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6327. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6328. func_params.f_obj = &bp->func_obj;
  6329. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6330. /* Function parameters */
  6331. switch_update_params->suspend = suspend;
  6332. rc = bnx2x_func_state_change(bp, &func_params);
  6333. return rc;
  6334. }
  6335. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6336. {
  6337. int rc, i, port = BP_PORT(bp);
  6338. int vlan_en = 0, mac_en[NUM_MACS];
  6339. /* Close input from network */
  6340. if (bp->mf_mode == SINGLE_FUNCTION) {
  6341. bnx2x_set_rx_filter(&bp->link_params, 0);
  6342. } else {
  6343. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6344. NIG_REG_LLH0_FUNC_EN);
  6345. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6346. NIG_REG_LLH0_FUNC_EN, 0);
  6347. for (i = 0; i < NUM_MACS; i++) {
  6348. mac_en[i] = REG_RD(bp, port ?
  6349. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6350. 4 * i) :
  6351. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6352. 4 * i));
  6353. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6354. 4 * i) :
  6355. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6356. }
  6357. }
  6358. /* Close BMC to host */
  6359. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6360. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6361. /* Suspend Tx switching to the PF. Completion of this ramrod
  6362. * further guarantees that all the packets of that PF / child
  6363. * VFs in BRB were processed by the Parser, so it is safe to
  6364. * change the NIC_MODE register.
  6365. */
  6366. rc = bnx2x_func_switch_update(bp, 1);
  6367. if (rc) {
  6368. BNX2X_ERR("Can't suspend tx-switching!\n");
  6369. return rc;
  6370. }
  6371. /* Change NIC_MODE register */
  6372. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6373. /* Open input from network */
  6374. if (bp->mf_mode == SINGLE_FUNCTION) {
  6375. bnx2x_set_rx_filter(&bp->link_params, 1);
  6376. } else {
  6377. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6378. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6379. for (i = 0; i < NUM_MACS; i++) {
  6380. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6381. 4 * i) :
  6382. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6383. mac_en[i]);
  6384. }
  6385. }
  6386. /* Enable BMC to host */
  6387. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6388. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6389. /* Resume Tx switching to the PF */
  6390. rc = bnx2x_func_switch_update(bp, 0);
  6391. if (rc) {
  6392. BNX2X_ERR("Can't resume tx-switching!\n");
  6393. return rc;
  6394. }
  6395. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6396. return 0;
  6397. }
  6398. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6399. {
  6400. int rc;
  6401. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6402. if (CONFIGURE_NIC_MODE(bp)) {
  6403. /* Configure searcher as part of function hw init */
  6404. bnx2x_init_searcher(bp);
  6405. /* Reset NIC mode */
  6406. rc = bnx2x_reset_nic_mode(bp);
  6407. if (rc)
  6408. BNX2X_ERR("Can't change NIC mode!\n");
  6409. return rc;
  6410. }
  6411. return 0;
  6412. }
  6413. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6414. {
  6415. int port = BP_PORT(bp);
  6416. int func = BP_FUNC(bp);
  6417. int init_phase = PHASE_PF0 + func;
  6418. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6419. u16 cdu_ilt_start;
  6420. u32 addr, val;
  6421. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6422. int i, main_mem_width, rc;
  6423. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6424. /* FLR cleanup - hmmm */
  6425. if (!CHIP_IS_E1x(bp)) {
  6426. rc = bnx2x_pf_flr_clnup(bp);
  6427. if (rc) {
  6428. bnx2x_fw_dump(bp);
  6429. return rc;
  6430. }
  6431. }
  6432. /* set MSI reconfigure capability */
  6433. if (bp->common.int_block == INT_BLOCK_HC) {
  6434. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6435. val = REG_RD(bp, addr);
  6436. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6437. REG_WR(bp, addr, val);
  6438. }
  6439. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6440. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6441. ilt = BP_ILT(bp);
  6442. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6443. if (IS_SRIOV(bp))
  6444. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6445. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6446. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6447. * those of the VFs, so start line should be reset
  6448. */
  6449. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6450. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6451. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6452. ilt->lines[cdu_ilt_start + i].page_mapping =
  6453. bp->context[i].cxt_mapping;
  6454. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6455. }
  6456. bnx2x_ilt_init_op(bp, INITOP_SET);
  6457. if (!CONFIGURE_NIC_MODE(bp)) {
  6458. bnx2x_init_searcher(bp);
  6459. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6460. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6461. } else {
  6462. /* Set NIC mode */
  6463. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6464. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6465. }
  6466. if (!CHIP_IS_E1x(bp)) {
  6467. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6468. /* Turn on a single ISR mode in IGU if driver is going to use
  6469. * INT#x or MSI
  6470. */
  6471. if (!(bp->flags & USING_MSIX_FLAG))
  6472. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6473. /*
  6474. * Timers workaround bug: function init part.
  6475. * Need to wait 20msec after initializing ILT,
  6476. * needed to make sure there are no requests in
  6477. * one of the PXP internal queues with "old" ILT addresses
  6478. */
  6479. msleep(20);
  6480. /*
  6481. * Master enable - Due to WB DMAE writes performed before this
  6482. * register is re-initialized as part of the regular function
  6483. * init
  6484. */
  6485. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6486. /* Enable the function in IGU */
  6487. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6488. }
  6489. bp->dmae_ready = 1;
  6490. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6491. if (!CHIP_IS_E1x(bp))
  6492. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6493. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6494. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6495. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6496. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6497. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6498. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6499. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6500. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6501. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6502. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6503. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6504. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6505. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6506. if (!CHIP_IS_E1x(bp))
  6507. REG_WR(bp, QM_REG_PF_EN, 1);
  6508. if (!CHIP_IS_E1x(bp)) {
  6509. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6510. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6511. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6512. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6513. }
  6514. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6515. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6516. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6517. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6518. bnx2x_iov_init_dq(bp);
  6519. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6520. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6521. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6522. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6523. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6524. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6525. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6526. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6527. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6528. if (!CHIP_IS_E1x(bp))
  6529. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6530. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6531. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6532. if (!CHIP_IS_E1x(bp))
  6533. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6534. if (IS_MF(bp)) {
  6535. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6536. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6537. }
  6538. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6539. /* HC init per function */
  6540. if (bp->common.int_block == INT_BLOCK_HC) {
  6541. if (CHIP_IS_E1H(bp)) {
  6542. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6543. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6544. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6545. }
  6546. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6547. } else {
  6548. int num_segs, sb_idx, prod_offset;
  6549. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6550. if (!CHIP_IS_E1x(bp)) {
  6551. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6552. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6553. }
  6554. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6555. if (!CHIP_IS_E1x(bp)) {
  6556. int dsb_idx = 0;
  6557. /**
  6558. * Producer memory:
  6559. * E2 mode: address 0-135 match to the mapping memory;
  6560. * 136 - PF0 default prod; 137 - PF1 default prod;
  6561. * 138 - PF2 default prod; 139 - PF3 default prod;
  6562. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6563. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6564. * 144-147 reserved.
  6565. *
  6566. * E1.5 mode - In backward compatible mode;
  6567. * for non default SB; each even line in the memory
  6568. * holds the U producer and each odd line hold
  6569. * the C producer. The first 128 producers are for
  6570. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6571. * producers are for the DSB for each PF.
  6572. * Each PF has five segments: (the order inside each
  6573. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6574. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6575. * 144-147 attn prods;
  6576. */
  6577. /* non-default-status-blocks */
  6578. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6579. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6580. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6581. prod_offset = (bp->igu_base_sb + sb_idx) *
  6582. num_segs;
  6583. for (i = 0; i < num_segs; i++) {
  6584. addr = IGU_REG_PROD_CONS_MEMORY +
  6585. (prod_offset + i) * 4;
  6586. REG_WR(bp, addr, 0);
  6587. }
  6588. /* send consumer update with value 0 */
  6589. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6590. USTORM_ID, 0, IGU_INT_NOP, 1);
  6591. bnx2x_igu_clear_sb(bp,
  6592. bp->igu_base_sb + sb_idx);
  6593. }
  6594. /* default-status-blocks */
  6595. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6596. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6597. if (CHIP_MODE_IS_4_PORT(bp))
  6598. dsb_idx = BP_FUNC(bp);
  6599. else
  6600. dsb_idx = BP_VN(bp);
  6601. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6602. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6603. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6604. /*
  6605. * igu prods come in chunks of E1HVN_MAX (4) -
  6606. * does not matters what is the current chip mode
  6607. */
  6608. for (i = 0; i < (num_segs * E1HVN_MAX);
  6609. i += E1HVN_MAX) {
  6610. addr = IGU_REG_PROD_CONS_MEMORY +
  6611. (prod_offset + i)*4;
  6612. REG_WR(bp, addr, 0);
  6613. }
  6614. /* send consumer update with 0 */
  6615. if (CHIP_INT_MODE_IS_BC(bp)) {
  6616. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6617. USTORM_ID, 0, IGU_INT_NOP, 1);
  6618. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6619. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6620. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6621. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6622. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6623. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6624. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6625. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6626. } else {
  6627. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6628. USTORM_ID, 0, IGU_INT_NOP, 1);
  6629. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6630. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6631. }
  6632. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6633. /* !!! These should become driver const once
  6634. rf-tool supports split-68 const */
  6635. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6636. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6637. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6638. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6639. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6640. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6641. }
  6642. }
  6643. /* Reset PCIE errors for debug */
  6644. REG_WR(bp, 0x2114, 0xffffffff);
  6645. REG_WR(bp, 0x2120, 0xffffffff);
  6646. if (CHIP_IS_E1x(bp)) {
  6647. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6648. main_mem_base = HC_REG_MAIN_MEMORY +
  6649. BP_PORT(bp) * (main_mem_size * 4);
  6650. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6651. main_mem_width = 8;
  6652. val = REG_RD(bp, main_mem_prty_clr);
  6653. if (val)
  6654. DP(NETIF_MSG_HW,
  6655. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6656. val);
  6657. /* Clear "false" parity errors in MSI-X table */
  6658. for (i = main_mem_base;
  6659. i < main_mem_base + main_mem_size * 4;
  6660. i += main_mem_width) {
  6661. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6662. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6663. i, main_mem_width / 4);
  6664. }
  6665. /* Clear HC parity attention */
  6666. REG_RD(bp, main_mem_prty_clr);
  6667. }
  6668. #ifdef BNX2X_STOP_ON_ERROR
  6669. /* Enable STORMs SP logging */
  6670. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6671. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6672. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6673. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6674. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6675. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6676. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6677. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6678. #endif
  6679. bnx2x_phy_probe(&bp->link_params);
  6680. return 0;
  6681. }
  6682. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6683. {
  6684. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6685. if (!CHIP_IS_E1x(bp))
  6686. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6687. sizeof(struct host_hc_status_block_e2));
  6688. else
  6689. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6690. sizeof(struct host_hc_status_block_e1x));
  6691. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6692. }
  6693. void bnx2x_free_mem(struct bnx2x *bp)
  6694. {
  6695. int i;
  6696. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6697. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6698. if (IS_VF(bp))
  6699. return;
  6700. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6701. sizeof(struct host_sp_status_block));
  6702. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6703. sizeof(struct bnx2x_slowpath));
  6704. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6705. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6706. bp->context[i].size);
  6707. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6708. BNX2X_FREE(bp->ilt->lines);
  6709. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6710. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6711. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6712. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6713. bnx2x_iov_free_mem(bp);
  6714. }
  6715. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6716. {
  6717. if (!CHIP_IS_E1x(bp))
  6718. /* size = the status block + ramrod buffers */
  6719. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6720. sizeof(struct host_hc_status_block_e2));
  6721. else
  6722. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6723. &bp->cnic_sb_mapping,
  6724. sizeof(struct
  6725. host_hc_status_block_e1x));
  6726. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6727. /* allocate searcher T2 table, as it wasn't allocated before */
  6728. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6729. /* write address to which L5 should insert its values */
  6730. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6731. &bp->slowpath->drv_info_to_mcp;
  6732. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6733. goto alloc_mem_err;
  6734. return 0;
  6735. alloc_mem_err:
  6736. bnx2x_free_mem_cnic(bp);
  6737. BNX2X_ERR("Can't allocate memory\n");
  6738. return -ENOMEM;
  6739. }
  6740. int bnx2x_alloc_mem(struct bnx2x *bp)
  6741. {
  6742. int i, allocated, context_size;
  6743. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6744. /* allocate searcher T2 table */
  6745. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6746. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6747. sizeof(struct host_sp_status_block));
  6748. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6749. sizeof(struct bnx2x_slowpath));
  6750. /* Allocate memory for CDU context:
  6751. * This memory is allocated separately and not in the generic ILT
  6752. * functions because CDU differs in few aspects:
  6753. * 1. There are multiple entities allocating memory for context -
  6754. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6755. * its own ILT lines.
  6756. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6757. * for the other ILT clients), to be efficient we want to support
  6758. * allocation of sub-page-size in the last entry.
  6759. * 3. Context pointers are used by the driver to pass to FW / update
  6760. * the context (for the other ILT clients the pointers are used just to
  6761. * free the memory during unload).
  6762. */
  6763. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6764. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6765. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6766. (context_size - allocated));
  6767. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6768. &bp->context[i].cxt_mapping,
  6769. bp->context[i].size);
  6770. allocated += bp->context[i].size;
  6771. }
  6772. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6773. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6774. goto alloc_mem_err;
  6775. if (bnx2x_iov_alloc_mem(bp))
  6776. goto alloc_mem_err;
  6777. /* Slow path ring */
  6778. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6779. /* EQ */
  6780. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6781. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6782. return 0;
  6783. alloc_mem_err:
  6784. bnx2x_free_mem(bp);
  6785. BNX2X_ERR("Can't allocate memory\n");
  6786. return -ENOMEM;
  6787. }
  6788. /*
  6789. * Init service functions
  6790. */
  6791. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6792. struct bnx2x_vlan_mac_obj *obj, bool set,
  6793. int mac_type, unsigned long *ramrod_flags)
  6794. {
  6795. int rc;
  6796. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6797. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6798. /* Fill general parameters */
  6799. ramrod_param.vlan_mac_obj = obj;
  6800. ramrod_param.ramrod_flags = *ramrod_flags;
  6801. /* Fill a user request section if needed */
  6802. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6803. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6804. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6805. /* Set the command: ADD or DEL */
  6806. if (set)
  6807. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6808. else
  6809. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6810. }
  6811. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6812. if (rc == -EEXIST) {
  6813. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6814. /* do not treat adding same MAC as error */
  6815. rc = 0;
  6816. } else if (rc < 0)
  6817. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6818. return rc;
  6819. }
  6820. int bnx2x_del_all_macs(struct bnx2x *bp,
  6821. struct bnx2x_vlan_mac_obj *mac_obj,
  6822. int mac_type, bool wait_for_comp)
  6823. {
  6824. int rc;
  6825. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6826. /* Wait for completion of requested */
  6827. if (wait_for_comp)
  6828. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6829. /* Set the mac type of addresses we want to clear */
  6830. __set_bit(mac_type, &vlan_mac_flags);
  6831. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6832. if (rc < 0)
  6833. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6834. return rc;
  6835. }
  6836. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6837. {
  6838. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6839. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6840. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6841. "Ignoring Zero MAC for STORAGE SD mode\n");
  6842. return 0;
  6843. }
  6844. if (IS_PF(bp)) {
  6845. unsigned long ramrod_flags = 0;
  6846. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6847. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6848. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6849. &bp->sp_objs->mac_obj, set,
  6850. BNX2X_ETH_MAC, &ramrod_flags);
  6851. } else { /* vf */
  6852. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6853. bp->fp->index, true);
  6854. }
  6855. }
  6856. int bnx2x_setup_leading(struct bnx2x *bp)
  6857. {
  6858. if (IS_PF(bp))
  6859. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6860. else /* VF */
  6861. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6862. }
  6863. /**
  6864. * bnx2x_set_int_mode - configure interrupt mode
  6865. *
  6866. * @bp: driver handle
  6867. *
  6868. * In case of MSI-X it will also try to enable MSI-X.
  6869. */
  6870. int bnx2x_set_int_mode(struct bnx2x *bp)
  6871. {
  6872. int rc = 0;
  6873. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  6874. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  6875. return -EINVAL;
  6876. }
  6877. switch (int_mode) {
  6878. case BNX2X_INT_MODE_MSIX:
  6879. /* attempt to enable msix */
  6880. rc = bnx2x_enable_msix(bp);
  6881. /* msix attained */
  6882. if (!rc)
  6883. return 0;
  6884. /* vfs use only msix */
  6885. if (rc && IS_VF(bp))
  6886. return rc;
  6887. /* failed to enable multiple MSI-X */
  6888. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6889. bp->num_queues,
  6890. 1 + bp->num_cnic_queues);
  6891. /* falling through... */
  6892. case BNX2X_INT_MODE_MSI:
  6893. bnx2x_enable_msi(bp);
  6894. /* falling through... */
  6895. case BNX2X_INT_MODE_INTX:
  6896. bp->num_ethernet_queues = 1;
  6897. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6898. BNX2X_DEV_INFO("set number of queues to 1\n");
  6899. break;
  6900. default:
  6901. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6902. return -EINVAL;
  6903. }
  6904. return 0;
  6905. }
  6906. /* must be called prior to any HW initializations */
  6907. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6908. {
  6909. if (IS_SRIOV(bp))
  6910. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6911. return L2_ILT_LINES(bp);
  6912. }
  6913. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6914. {
  6915. struct ilt_client_info *ilt_client;
  6916. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6917. u16 line = 0;
  6918. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6919. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6920. /* CDU */
  6921. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6922. ilt_client->client_num = ILT_CLIENT_CDU;
  6923. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6924. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6925. ilt_client->start = line;
  6926. line += bnx2x_cid_ilt_lines(bp);
  6927. if (CNIC_SUPPORT(bp))
  6928. line += CNIC_ILT_LINES;
  6929. ilt_client->end = line - 1;
  6930. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6931. ilt_client->start,
  6932. ilt_client->end,
  6933. ilt_client->page_size,
  6934. ilt_client->flags,
  6935. ilog2(ilt_client->page_size >> 12));
  6936. /* QM */
  6937. if (QM_INIT(bp->qm_cid_count)) {
  6938. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6939. ilt_client->client_num = ILT_CLIENT_QM;
  6940. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6941. ilt_client->flags = 0;
  6942. ilt_client->start = line;
  6943. /* 4 bytes for each cid */
  6944. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6945. QM_ILT_PAGE_SZ);
  6946. ilt_client->end = line - 1;
  6947. DP(NETIF_MSG_IFUP,
  6948. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6949. ilt_client->start,
  6950. ilt_client->end,
  6951. ilt_client->page_size,
  6952. ilt_client->flags,
  6953. ilog2(ilt_client->page_size >> 12));
  6954. }
  6955. if (CNIC_SUPPORT(bp)) {
  6956. /* SRC */
  6957. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6958. ilt_client->client_num = ILT_CLIENT_SRC;
  6959. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6960. ilt_client->flags = 0;
  6961. ilt_client->start = line;
  6962. line += SRC_ILT_LINES;
  6963. ilt_client->end = line - 1;
  6964. DP(NETIF_MSG_IFUP,
  6965. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6966. ilt_client->start,
  6967. ilt_client->end,
  6968. ilt_client->page_size,
  6969. ilt_client->flags,
  6970. ilog2(ilt_client->page_size >> 12));
  6971. /* TM */
  6972. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6973. ilt_client->client_num = ILT_CLIENT_TM;
  6974. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6975. ilt_client->flags = 0;
  6976. ilt_client->start = line;
  6977. line += TM_ILT_LINES;
  6978. ilt_client->end = line - 1;
  6979. DP(NETIF_MSG_IFUP,
  6980. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6981. ilt_client->start,
  6982. ilt_client->end,
  6983. ilt_client->page_size,
  6984. ilt_client->flags,
  6985. ilog2(ilt_client->page_size >> 12));
  6986. }
  6987. BUG_ON(line > ILT_MAX_LINES);
  6988. }
  6989. /**
  6990. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6991. *
  6992. * @bp: driver handle
  6993. * @fp: pointer to fastpath
  6994. * @init_params: pointer to parameters structure
  6995. *
  6996. * parameters configured:
  6997. * - HC configuration
  6998. * - Queue's CDU context
  6999. */
  7000. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7001. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7002. {
  7003. u8 cos;
  7004. int cxt_index, cxt_offset;
  7005. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7006. if (!IS_FCOE_FP(fp)) {
  7007. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7008. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7009. /* If HC is supported, enable host coalescing in the transition
  7010. * to INIT state.
  7011. */
  7012. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7013. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7014. /* HC rate */
  7015. init_params->rx.hc_rate = bp->rx_ticks ?
  7016. (1000000 / bp->rx_ticks) : 0;
  7017. init_params->tx.hc_rate = bp->tx_ticks ?
  7018. (1000000 / bp->tx_ticks) : 0;
  7019. /* FW SB ID */
  7020. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7021. fp->fw_sb_id;
  7022. /*
  7023. * CQ index among the SB indices: FCoE clients uses the default
  7024. * SB, therefore it's different.
  7025. */
  7026. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7027. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7028. }
  7029. /* set maximum number of COSs supported by this queue */
  7030. init_params->max_cos = fp->max_cos;
  7031. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7032. fp->index, init_params->max_cos);
  7033. /* set the context pointers queue object */
  7034. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7035. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7036. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7037. ILT_PAGE_CIDS);
  7038. init_params->cxts[cos] =
  7039. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7040. }
  7041. }
  7042. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7043. struct bnx2x_queue_state_params *q_params,
  7044. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7045. int tx_index, bool leading)
  7046. {
  7047. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7048. /* Set the command */
  7049. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7050. /* Set tx-only QUEUE flags: don't zero statistics */
  7051. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7052. /* choose the index of the cid to send the slow path on */
  7053. tx_only_params->cid_index = tx_index;
  7054. /* Set general TX_ONLY_SETUP parameters */
  7055. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7056. /* Set Tx TX_ONLY_SETUP parameters */
  7057. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7058. DP(NETIF_MSG_IFUP,
  7059. "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",
  7060. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7061. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7062. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7063. /* send the ramrod */
  7064. return bnx2x_queue_state_change(bp, q_params);
  7065. }
  7066. /**
  7067. * bnx2x_setup_queue - setup queue
  7068. *
  7069. * @bp: driver handle
  7070. * @fp: pointer to fastpath
  7071. * @leading: is leading
  7072. *
  7073. * This function performs 2 steps in a Queue state machine
  7074. * actually: 1) RESET->INIT 2) INIT->SETUP
  7075. */
  7076. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7077. bool leading)
  7078. {
  7079. struct bnx2x_queue_state_params q_params = {NULL};
  7080. struct bnx2x_queue_setup_params *setup_params =
  7081. &q_params.params.setup;
  7082. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7083. &q_params.params.tx_only;
  7084. int rc;
  7085. u8 tx_index;
  7086. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7087. /* reset IGU state skip FCoE L2 queue */
  7088. if (!IS_FCOE_FP(fp))
  7089. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7090. IGU_INT_ENABLE, 0);
  7091. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7092. /* We want to wait for completion in this context */
  7093. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7094. /* Prepare the INIT parameters */
  7095. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7096. /* Set the command */
  7097. q_params.cmd = BNX2X_Q_CMD_INIT;
  7098. /* Change the state to INIT */
  7099. rc = bnx2x_queue_state_change(bp, &q_params);
  7100. if (rc) {
  7101. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7102. return rc;
  7103. }
  7104. DP(NETIF_MSG_IFUP, "init complete\n");
  7105. /* Now move the Queue to the SETUP state... */
  7106. memset(setup_params, 0, sizeof(*setup_params));
  7107. /* Set QUEUE flags */
  7108. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7109. /* Set general SETUP parameters */
  7110. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7111. FIRST_TX_COS_INDEX);
  7112. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7113. &setup_params->rxq_params);
  7114. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7115. FIRST_TX_COS_INDEX);
  7116. /* Set the command */
  7117. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7118. if (IS_FCOE_FP(fp))
  7119. bp->fcoe_init = true;
  7120. /* Change the state to SETUP */
  7121. rc = bnx2x_queue_state_change(bp, &q_params);
  7122. if (rc) {
  7123. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7124. return rc;
  7125. }
  7126. /* loop through the relevant tx-only indices */
  7127. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7128. tx_index < fp->max_cos;
  7129. tx_index++) {
  7130. /* prepare and send tx-only ramrod*/
  7131. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7132. tx_only_params, tx_index, leading);
  7133. if (rc) {
  7134. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7135. fp->index, tx_index);
  7136. return rc;
  7137. }
  7138. }
  7139. return rc;
  7140. }
  7141. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7142. {
  7143. struct bnx2x_fastpath *fp = &bp->fp[index];
  7144. struct bnx2x_fp_txdata *txdata;
  7145. struct bnx2x_queue_state_params q_params = {NULL};
  7146. int rc, tx_index;
  7147. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7148. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7149. /* We want to wait for completion in this context */
  7150. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7151. /* close tx-only connections */
  7152. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7153. tx_index < fp->max_cos;
  7154. tx_index++){
  7155. /* ascertain this is a normal queue*/
  7156. txdata = fp->txdata_ptr[tx_index];
  7157. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7158. txdata->txq_index);
  7159. /* send halt terminate on tx-only connection */
  7160. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7161. memset(&q_params.params.terminate, 0,
  7162. sizeof(q_params.params.terminate));
  7163. q_params.params.terminate.cid_index = tx_index;
  7164. rc = bnx2x_queue_state_change(bp, &q_params);
  7165. if (rc)
  7166. return rc;
  7167. /* send halt terminate on tx-only connection */
  7168. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7169. memset(&q_params.params.cfc_del, 0,
  7170. sizeof(q_params.params.cfc_del));
  7171. q_params.params.cfc_del.cid_index = tx_index;
  7172. rc = bnx2x_queue_state_change(bp, &q_params);
  7173. if (rc)
  7174. return rc;
  7175. }
  7176. /* Stop the primary connection: */
  7177. /* ...halt the connection */
  7178. q_params.cmd = BNX2X_Q_CMD_HALT;
  7179. rc = bnx2x_queue_state_change(bp, &q_params);
  7180. if (rc)
  7181. return rc;
  7182. /* ...terminate the connection */
  7183. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7184. memset(&q_params.params.terminate, 0,
  7185. sizeof(q_params.params.terminate));
  7186. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7187. rc = bnx2x_queue_state_change(bp, &q_params);
  7188. if (rc)
  7189. return rc;
  7190. /* ...delete cfc entry */
  7191. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7192. memset(&q_params.params.cfc_del, 0,
  7193. sizeof(q_params.params.cfc_del));
  7194. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7195. return bnx2x_queue_state_change(bp, &q_params);
  7196. }
  7197. static void bnx2x_reset_func(struct bnx2x *bp)
  7198. {
  7199. int port = BP_PORT(bp);
  7200. int func = BP_FUNC(bp);
  7201. int i;
  7202. /* Disable the function in the FW */
  7203. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7204. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7205. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7206. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7207. /* FP SBs */
  7208. for_each_eth_queue(bp, i) {
  7209. struct bnx2x_fastpath *fp = &bp->fp[i];
  7210. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7211. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7212. SB_DISABLED);
  7213. }
  7214. if (CNIC_LOADED(bp))
  7215. /* CNIC SB */
  7216. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7217. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7218. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7219. /* SP SB */
  7220. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7221. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7222. SB_DISABLED);
  7223. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7224. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7225. 0);
  7226. /* Configure IGU */
  7227. if (bp->common.int_block == INT_BLOCK_HC) {
  7228. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7229. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7230. } else {
  7231. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7232. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7233. }
  7234. if (CNIC_LOADED(bp)) {
  7235. /* Disable Timer scan */
  7236. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7237. /*
  7238. * Wait for at least 10ms and up to 2 second for the timers
  7239. * scan to complete
  7240. */
  7241. for (i = 0; i < 200; i++) {
  7242. usleep_range(10000, 20000);
  7243. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7244. break;
  7245. }
  7246. }
  7247. /* Clear ILT */
  7248. bnx2x_clear_func_ilt(bp, func);
  7249. /* Timers workaround bug for E2: if this is vnic-3,
  7250. * we need to set the entire ilt range for this timers.
  7251. */
  7252. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7253. struct ilt_client_info ilt_cli;
  7254. /* use dummy TM client */
  7255. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7256. ilt_cli.start = 0;
  7257. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7258. ilt_cli.client_num = ILT_CLIENT_TM;
  7259. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7260. }
  7261. /* this assumes that reset_port() called before reset_func()*/
  7262. if (!CHIP_IS_E1x(bp))
  7263. bnx2x_pf_disable(bp);
  7264. bp->dmae_ready = 0;
  7265. }
  7266. static void bnx2x_reset_port(struct bnx2x *bp)
  7267. {
  7268. int port = BP_PORT(bp);
  7269. u32 val;
  7270. /* Reset physical Link */
  7271. bnx2x__link_reset(bp);
  7272. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7273. /* Do not rcv packets to BRB */
  7274. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7275. /* Do not direct rcv packets that are not for MCP to the BRB */
  7276. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7277. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7278. /* Configure AEU */
  7279. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7280. msleep(100);
  7281. /* Check for BRB port occupancy */
  7282. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7283. if (val)
  7284. DP(NETIF_MSG_IFDOWN,
  7285. "BRB1 is not empty %d blocks are occupied\n", val);
  7286. /* TODO: Close Doorbell port? */
  7287. }
  7288. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7289. {
  7290. struct bnx2x_func_state_params func_params = {NULL};
  7291. /* Prepare parameters for function state transitions */
  7292. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7293. func_params.f_obj = &bp->func_obj;
  7294. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7295. func_params.params.hw_init.load_phase = load_code;
  7296. return bnx2x_func_state_change(bp, &func_params);
  7297. }
  7298. static int bnx2x_func_stop(struct bnx2x *bp)
  7299. {
  7300. struct bnx2x_func_state_params func_params = {NULL};
  7301. int rc;
  7302. /* Prepare parameters for function state transitions */
  7303. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7304. func_params.f_obj = &bp->func_obj;
  7305. func_params.cmd = BNX2X_F_CMD_STOP;
  7306. /*
  7307. * Try to stop the function the 'good way'. If fails (in case
  7308. * of a parity error during bnx2x_chip_cleanup()) and we are
  7309. * not in a debug mode, perform a state transaction in order to
  7310. * enable further HW_RESET transaction.
  7311. */
  7312. rc = bnx2x_func_state_change(bp, &func_params);
  7313. if (rc) {
  7314. #ifdef BNX2X_STOP_ON_ERROR
  7315. return rc;
  7316. #else
  7317. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7318. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7319. return bnx2x_func_state_change(bp, &func_params);
  7320. #endif
  7321. }
  7322. return 0;
  7323. }
  7324. /**
  7325. * bnx2x_send_unload_req - request unload mode from the MCP.
  7326. *
  7327. * @bp: driver handle
  7328. * @unload_mode: requested function's unload mode
  7329. *
  7330. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7331. */
  7332. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7333. {
  7334. u32 reset_code = 0;
  7335. int port = BP_PORT(bp);
  7336. /* Select the UNLOAD request mode */
  7337. if (unload_mode == UNLOAD_NORMAL)
  7338. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7339. else if (bp->flags & NO_WOL_FLAG)
  7340. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7341. else if (bp->wol) {
  7342. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7343. u8 *mac_addr = bp->dev->dev_addr;
  7344. struct pci_dev *pdev = bp->pdev;
  7345. u32 val;
  7346. u16 pmc;
  7347. /* The mac address is written to entries 1-4 to
  7348. * preserve entry 0 which is used by the PMF
  7349. */
  7350. u8 entry = (BP_VN(bp) + 1)*8;
  7351. val = (mac_addr[0] << 8) | mac_addr[1];
  7352. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7353. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7354. (mac_addr[4] << 8) | mac_addr[5];
  7355. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7356. /* Enable the PME and clear the status */
  7357. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7358. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7359. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7360. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7361. } else
  7362. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7363. /* Send the request to the MCP */
  7364. if (!BP_NOMCP(bp))
  7365. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7366. else {
  7367. int path = BP_PATH(bp);
  7368. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7369. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7370. bnx2x_load_count[path][2]);
  7371. bnx2x_load_count[path][0]--;
  7372. bnx2x_load_count[path][1 + port]--;
  7373. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7374. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7375. bnx2x_load_count[path][2]);
  7376. if (bnx2x_load_count[path][0] == 0)
  7377. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7378. else if (bnx2x_load_count[path][1 + port] == 0)
  7379. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7380. else
  7381. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7382. }
  7383. return reset_code;
  7384. }
  7385. /**
  7386. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7387. *
  7388. * @bp: driver handle
  7389. * @keep_link: true iff link should be kept up
  7390. */
  7391. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7392. {
  7393. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7394. /* Report UNLOAD_DONE to MCP */
  7395. if (!BP_NOMCP(bp))
  7396. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7397. }
  7398. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7399. {
  7400. int tout = 50;
  7401. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7402. if (!bp->port.pmf)
  7403. return 0;
  7404. /*
  7405. * (assumption: No Attention from MCP at this stage)
  7406. * PMF probably in the middle of TX disable/enable transaction
  7407. * 1. Sync IRS for default SB
  7408. * 2. Sync SP queue - this guarantees us that attention handling started
  7409. * 3. Wait, that TX disable/enable transaction completes
  7410. *
  7411. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7412. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7413. * received completion for the transaction the state is TX_STOPPED.
  7414. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7415. * transaction.
  7416. */
  7417. /* make sure default SB ISR is done */
  7418. if (msix)
  7419. synchronize_irq(bp->msix_table[0].vector);
  7420. else
  7421. synchronize_irq(bp->pdev->irq);
  7422. flush_workqueue(bnx2x_wq);
  7423. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7424. BNX2X_F_STATE_STARTED && tout--)
  7425. msleep(20);
  7426. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7427. BNX2X_F_STATE_STARTED) {
  7428. #ifdef BNX2X_STOP_ON_ERROR
  7429. BNX2X_ERR("Wrong function state\n");
  7430. return -EBUSY;
  7431. #else
  7432. /*
  7433. * Failed to complete the transaction in a "good way"
  7434. * Force both transactions with CLR bit
  7435. */
  7436. struct bnx2x_func_state_params func_params = {NULL};
  7437. DP(NETIF_MSG_IFDOWN,
  7438. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7439. func_params.f_obj = &bp->func_obj;
  7440. __set_bit(RAMROD_DRV_CLR_ONLY,
  7441. &func_params.ramrod_flags);
  7442. /* STARTED-->TX_ST0PPED */
  7443. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7444. bnx2x_func_state_change(bp, &func_params);
  7445. /* TX_ST0PPED-->STARTED */
  7446. func_params.cmd = BNX2X_F_CMD_TX_START;
  7447. return bnx2x_func_state_change(bp, &func_params);
  7448. #endif
  7449. }
  7450. return 0;
  7451. }
  7452. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7453. {
  7454. int port = BP_PORT(bp);
  7455. int i, rc = 0;
  7456. u8 cos;
  7457. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7458. u32 reset_code;
  7459. /* Wait until tx fastpath tasks complete */
  7460. for_each_tx_queue(bp, i) {
  7461. struct bnx2x_fastpath *fp = &bp->fp[i];
  7462. for_each_cos_in_tx_queue(fp, cos)
  7463. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7464. #ifdef BNX2X_STOP_ON_ERROR
  7465. if (rc)
  7466. return;
  7467. #endif
  7468. }
  7469. /* Give HW time to discard old tx messages */
  7470. usleep_range(1000, 2000);
  7471. /* Clean all ETH MACs */
  7472. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7473. false);
  7474. if (rc < 0)
  7475. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7476. /* Clean up UC list */
  7477. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7478. true);
  7479. if (rc < 0)
  7480. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7481. rc);
  7482. /* Disable LLH */
  7483. if (!CHIP_IS_E1(bp))
  7484. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7485. /* Set "drop all" (stop Rx).
  7486. * We need to take a netif_addr_lock() here in order to prevent
  7487. * a race between the completion code and this code.
  7488. */
  7489. netif_addr_lock_bh(bp->dev);
  7490. /* Schedule the rx_mode command */
  7491. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7492. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7493. else
  7494. bnx2x_set_storm_rx_mode(bp);
  7495. /* Cleanup multicast configuration */
  7496. rparam.mcast_obj = &bp->mcast_obj;
  7497. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7498. if (rc < 0)
  7499. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7500. netif_addr_unlock_bh(bp->dev);
  7501. bnx2x_iov_chip_cleanup(bp);
  7502. /*
  7503. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7504. * this function should perform FUNC, PORT or COMMON HW
  7505. * reset.
  7506. */
  7507. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7508. /*
  7509. * (assumption: No Attention from MCP at this stage)
  7510. * PMF probably in the middle of TX disable/enable transaction
  7511. */
  7512. rc = bnx2x_func_wait_started(bp);
  7513. if (rc) {
  7514. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7515. #ifdef BNX2X_STOP_ON_ERROR
  7516. return;
  7517. #endif
  7518. }
  7519. /* Close multi and leading connections
  7520. * Completions for ramrods are collected in a synchronous way
  7521. */
  7522. for_each_eth_queue(bp, i)
  7523. if (bnx2x_stop_queue(bp, i))
  7524. #ifdef BNX2X_STOP_ON_ERROR
  7525. return;
  7526. #else
  7527. goto unload_error;
  7528. #endif
  7529. if (CNIC_LOADED(bp)) {
  7530. for_each_cnic_queue(bp, i)
  7531. if (bnx2x_stop_queue(bp, i))
  7532. #ifdef BNX2X_STOP_ON_ERROR
  7533. return;
  7534. #else
  7535. goto unload_error;
  7536. #endif
  7537. }
  7538. /* If SP settings didn't get completed so far - something
  7539. * very wrong has happen.
  7540. */
  7541. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7542. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7543. #ifndef BNX2X_STOP_ON_ERROR
  7544. unload_error:
  7545. #endif
  7546. rc = bnx2x_func_stop(bp);
  7547. if (rc) {
  7548. BNX2X_ERR("Function stop failed!\n");
  7549. #ifdef BNX2X_STOP_ON_ERROR
  7550. return;
  7551. #endif
  7552. }
  7553. /* Disable HW interrupts, NAPI */
  7554. bnx2x_netif_stop(bp, 1);
  7555. /* Delete all NAPI objects */
  7556. bnx2x_del_all_napi(bp);
  7557. if (CNIC_LOADED(bp))
  7558. bnx2x_del_all_napi_cnic(bp);
  7559. /* Release IRQs */
  7560. bnx2x_free_irq(bp);
  7561. /* Reset the chip */
  7562. rc = bnx2x_reset_hw(bp, reset_code);
  7563. if (rc)
  7564. BNX2X_ERR("HW_RESET failed\n");
  7565. /* Report UNLOAD_DONE to MCP */
  7566. bnx2x_send_unload_done(bp, keep_link);
  7567. }
  7568. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7569. {
  7570. u32 val;
  7571. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7572. if (CHIP_IS_E1(bp)) {
  7573. int port = BP_PORT(bp);
  7574. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7575. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7576. val = REG_RD(bp, addr);
  7577. val &= ~(0x300);
  7578. REG_WR(bp, addr, val);
  7579. } else {
  7580. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7581. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7582. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7583. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7584. }
  7585. }
  7586. /* Close gates #2, #3 and #4: */
  7587. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7588. {
  7589. u32 val;
  7590. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7591. if (!CHIP_IS_E1(bp)) {
  7592. /* #4 */
  7593. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7594. /* #2 */
  7595. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7596. }
  7597. /* #3 */
  7598. if (CHIP_IS_E1x(bp)) {
  7599. /* Prevent interrupts from HC on both ports */
  7600. val = REG_RD(bp, HC_REG_CONFIG_1);
  7601. REG_WR(bp, HC_REG_CONFIG_1,
  7602. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7603. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7604. val = REG_RD(bp, HC_REG_CONFIG_0);
  7605. REG_WR(bp, HC_REG_CONFIG_0,
  7606. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7607. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7608. } else {
  7609. /* Prevent incoming interrupts in IGU */
  7610. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7611. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7612. (!close) ?
  7613. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7614. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7615. }
  7616. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7617. close ? "closing" : "opening");
  7618. mmiowb();
  7619. }
  7620. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7621. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7622. {
  7623. /* Do some magic... */
  7624. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7625. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7626. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7627. }
  7628. /**
  7629. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7630. *
  7631. * @bp: driver handle
  7632. * @magic_val: old value of the `magic' bit.
  7633. */
  7634. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7635. {
  7636. /* Restore the `magic' bit value... */
  7637. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7638. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7639. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7640. }
  7641. /**
  7642. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7643. *
  7644. * @bp: driver handle
  7645. * @magic_val: old value of 'magic' bit.
  7646. *
  7647. * Takes care of CLP configurations.
  7648. */
  7649. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7650. {
  7651. u32 shmem;
  7652. u32 validity_offset;
  7653. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7654. /* Set `magic' bit in order to save MF config */
  7655. if (!CHIP_IS_E1(bp))
  7656. bnx2x_clp_reset_prep(bp, magic_val);
  7657. /* Get shmem offset */
  7658. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7659. validity_offset =
  7660. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7661. /* Clear validity map flags */
  7662. if (shmem > 0)
  7663. REG_WR(bp, shmem + validity_offset, 0);
  7664. }
  7665. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7666. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7667. /**
  7668. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7669. *
  7670. * @bp: driver handle
  7671. */
  7672. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7673. {
  7674. /* special handling for emulation and FPGA,
  7675. wait 10 times longer */
  7676. if (CHIP_REV_IS_SLOW(bp))
  7677. msleep(MCP_ONE_TIMEOUT*10);
  7678. else
  7679. msleep(MCP_ONE_TIMEOUT);
  7680. }
  7681. /*
  7682. * initializes bp->common.shmem_base and waits for validity signature to appear
  7683. */
  7684. static int bnx2x_init_shmem(struct bnx2x *bp)
  7685. {
  7686. int cnt = 0;
  7687. u32 val = 0;
  7688. do {
  7689. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7690. if (bp->common.shmem_base) {
  7691. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7692. if (val & SHR_MEM_VALIDITY_MB)
  7693. return 0;
  7694. }
  7695. bnx2x_mcp_wait_one(bp);
  7696. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7697. BNX2X_ERR("BAD MCP validity signature\n");
  7698. return -ENODEV;
  7699. }
  7700. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7701. {
  7702. int rc = bnx2x_init_shmem(bp);
  7703. /* Restore the `magic' bit value */
  7704. if (!CHIP_IS_E1(bp))
  7705. bnx2x_clp_reset_done(bp, magic_val);
  7706. return rc;
  7707. }
  7708. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7709. {
  7710. if (!CHIP_IS_E1(bp)) {
  7711. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7712. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7713. mmiowb();
  7714. }
  7715. }
  7716. /*
  7717. * Reset the whole chip except for:
  7718. * - PCIE core
  7719. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7720. * one reset bit)
  7721. * - IGU
  7722. * - MISC (including AEU)
  7723. * - GRC
  7724. * - RBCN, RBCP
  7725. */
  7726. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7727. {
  7728. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7729. u32 global_bits2, stay_reset2;
  7730. /*
  7731. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7732. * (per chip) blocks.
  7733. */
  7734. global_bits2 =
  7735. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7736. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7737. /* Don't reset the following blocks.
  7738. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7739. * reset, as in 4 port device they might still be owned
  7740. * by the MCP (there is only one leader per path).
  7741. */
  7742. not_reset_mask1 =
  7743. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7744. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7745. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7746. not_reset_mask2 =
  7747. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7748. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7749. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7750. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7751. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7752. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7753. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7754. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7755. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7756. MISC_REGISTERS_RESET_REG_2_PGLC |
  7757. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7758. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7759. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7760. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7761. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7762. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7763. /*
  7764. * Keep the following blocks in reset:
  7765. * - all xxMACs are handled by the bnx2x_link code.
  7766. */
  7767. stay_reset2 =
  7768. MISC_REGISTERS_RESET_REG_2_XMAC |
  7769. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7770. /* Full reset masks according to the chip */
  7771. reset_mask1 = 0xffffffff;
  7772. if (CHIP_IS_E1(bp))
  7773. reset_mask2 = 0xffff;
  7774. else if (CHIP_IS_E1H(bp))
  7775. reset_mask2 = 0x1ffff;
  7776. else if (CHIP_IS_E2(bp))
  7777. reset_mask2 = 0xfffff;
  7778. else /* CHIP_IS_E3 */
  7779. reset_mask2 = 0x3ffffff;
  7780. /* Don't reset global blocks unless we need to */
  7781. if (!global)
  7782. reset_mask2 &= ~global_bits2;
  7783. /*
  7784. * In case of attention in the QM, we need to reset PXP
  7785. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7786. * because otherwise QM reset would release 'close the gates' shortly
  7787. * before resetting the PXP, then the PSWRQ would send a write
  7788. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7789. * read the payload data from PSWWR, but PSWWR would not
  7790. * respond. The write queue in PGLUE would stuck, dmae commands
  7791. * would not return. Therefore it's important to reset the second
  7792. * reset register (containing the
  7793. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7794. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7795. * bit).
  7796. */
  7797. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7798. reset_mask2 & (~not_reset_mask2));
  7799. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7800. reset_mask1 & (~not_reset_mask1));
  7801. barrier();
  7802. mmiowb();
  7803. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7804. reset_mask2 & (~stay_reset2));
  7805. barrier();
  7806. mmiowb();
  7807. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7808. mmiowb();
  7809. }
  7810. /**
  7811. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7812. * It should get cleared in no more than 1s.
  7813. *
  7814. * @bp: driver handle
  7815. *
  7816. * It should get cleared in no more than 1s. Returns 0 if
  7817. * pending writes bit gets cleared.
  7818. */
  7819. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7820. {
  7821. u32 cnt = 1000;
  7822. u32 pend_bits = 0;
  7823. do {
  7824. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7825. if (pend_bits == 0)
  7826. break;
  7827. usleep_range(1000, 2000);
  7828. } while (cnt-- > 0);
  7829. if (cnt <= 0) {
  7830. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7831. pend_bits);
  7832. return -EBUSY;
  7833. }
  7834. return 0;
  7835. }
  7836. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7837. {
  7838. int cnt = 1000;
  7839. u32 val = 0;
  7840. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7841. u32 tags_63_32 = 0;
  7842. /* Empty the Tetris buffer, wait for 1s */
  7843. do {
  7844. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7845. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7846. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7847. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7848. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7849. if (CHIP_IS_E3(bp))
  7850. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7851. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7852. ((port_is_idle_0 & 0x1) == 0x1) &&
  7853. ((port_is_idle_1 & 0x1) == 0x1) &&
  7854. (pgl_exp_rom2 == 0xffffffff) &&
  7855. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7856. break;
  7857. usleep_range(1000, 2000);
  7858. } while (cnt-- > 0);
  7859. if (cnt <= 0) {
  7860. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7861. 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",
  7862. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7863. pgl_exp_rom2);
  7864. return -EAGAIN;
  7865. }
  7866. barrier();
  7867. /* Close gates #2, #3 and #4 */
  7868. bnx2x_set_234_gates(bp, true);
  7869. /* Poll for IGU VQs for 57712 and newer chips */
  7870. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7871. return -EAGAIN;
  7872. /* TBD: Indicate that "process kill" is in progress to MCP */
  7873. /* Clear "unprepared" bit */
  7874. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7875. barrier();
  7876. /* Make sure all is written to the chip before the reset */
  7877. mmiowb();
  7878. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7879. * PSWHST, GRC and PSWRD Tetris buffer.
  7880. */
  7881. usleep_range(1000, 2000);
  7882. /* Prepare to chip reset: */
  7883. /* MCP */
  7884. if (global)
  7885. bnx2x_reset_mcp_prep(bp, &val);
  7886. /* PXP */
  7887. bnx2x_pxp_prep(bp);
  7888. barrier();
  7889. /* reset the chip */
  7890. bnx2x_process_kill_chip_reset(bp, global);
  7891. barrier();
  7892. /* clear errors in PGB */
  7893. if (!CHIP_IS_E1x(bp))
  7894. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  7895. /* Recover after reset: */
  7896. /* MCP */
  7897. if (global && bnx2x_reset_mcp_comp(bp, val))
  7898. return -EAGAIN;
  7899. /* TBD: Add resetting the NO_MCP mode DB here */
  7900. /* Open the gates #2, #3 and #4 */
  7901. bnx2x_set_234_gates(bp, false);
  7902. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7903. * reset state, re-enable attentions. */
  7904. return 0;
  7905. }
  7906. static int bnx2x_leader_reset(struct bnx2x *bp)
  7907. {
  7908. int rc = 0;
  7909. bool global = bnx2x_reset_is_global(bp);
  7910. u32 load_code;
  7911. /* if not going to reset MCP - load "fake" driver to reset HW while
  7912. * driver is owner of the HW
  7913. */
  7914. if (!global && !BP_NOMCP(bp)) {
  7915. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7916. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7917. if (!load_code) {
  7918. BNX2X_ERR("MCP response failure, aborting\n");
  7919. rc = -EAGAIN;
  7920. goto exit_leader_reset;
  7921. }
  7922. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7923. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7924. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7925. rc = -EAGAIN;
  7926. goto exit_leader_reset2;
  7927. }
  7928. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7929. if (!load_code) {
  7930. BNX2X_ERR("MCP response failure, aborting\n");
  7931. rc = -EAGAIN;
  7932. goto exit_leader_reset2;
  7933. }
  7934. }
  7935. /* Try to recover after the failure */
  7936. if (bnx2x_process_kill(bp, global)) {
  7937. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7938. BP_PATH(bp));
  7939. rc = -EAGAIN;
  7940. goto exit_leader_reset2;
  7941. }
  7942. /*
  7943. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7944. * state.
  7945. */
  7946. bnx2x_set_reset_done(bp);
  7947. if (global)
  7948. bnx2x_clear_reset_global(bp);
  7949. exit_leader_reset2:
  7950. /* unload "fake driver" if it was loaded */
  7951. if (!global && !BP_NOMCP(bp)) {
  7952. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7953. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7954. }
  7955. exit_leader_reset:
  7956. bp->is_leader = 0;
  7957. bnx2x_release_leader_lock(bp);
  7958. smp_mb();
  7959. return rc;
  7960. }
  7961. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7962. {
  7963. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7964. /* Disconnect this device */
  7965. netif_device_detach(bp->dev);
  7966. /*
  7967. * Block ifup for all function on this engine until "process kill"
  7968. * or power cycle.
  7969. */
  7970. bnx2x_set_reset_in_progress(bp);
  7971. /* Shut down the power */
  7972. bnx2x_set_power_state(bp, PCI_D3hot);
  7973. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7974. smp_mb();
  7975. }
  7976. /*
  7977. * Assumption: runs under rtnl lock. This together with the fact
  7978. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7979. * will never be called when netif_running(bp->dev) is false.
  7980. */
  7981. static void bnx2x_parity_recover(struct bnx2x *bp)
  7982. {
  7983. bool global = false;
  7984. u32 error_recovered, error_unrecovered;
  7985. bool is_parity;
  7986. DP(NETIF_MSG_HW, "Handling parity\n");
  7987. while (1) {
  7988. switch (bp->recovery_state) {
  7989. case BNX2X_RECOVERY_INIT:
  7990. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7991. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7992. WARN_ON(!is_parity);
  7993. /* Try to get a LEADER_LOCK HW lock */
  7994. if (bnx2x_trylock_leader_lock(bp)) {
  7995. bnx2x_set_reset_in_progress(bp);
  7996. /*
  7997. * Check if there is a global attention and if
  7998. * there was a global attention, set the global
  7999. * reset bit.
  8000. */
  8001. if (global)
  8002. bnx2x_set_reset_global(bp);
  8003. bp->is_leader = 1;
  8004. }
  8005. /* Stop the driver */
  8006. /* If interface has been removed - break */
  8007. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8008. return;
  8009. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8010. /* Ensure "is_leader", MCP command sequence and
  8011. * "recovery_state" update values are seen on other
  8012. * CPUs.
  8013. */
  8014. smp_mb();
  8015. break;
  8016. case BNX2X_RECOVERY_WAIT:
  8017. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8018. if (bp->is_leader) {
  8019. int other_engine = BP_PATH(bp) ? 0 : 1;
  8020. bool other_load_status =
  8021. bnx2x_get_load_status(bp, other_engine);
  8022. bool load_status =
  8023. bnx2x_get_load_status(bp, BP_PATH(bp));
  8024. global = bnx2x_reset_is_global(bp);
  8025. /*
  8026. * In case of a parity in a global block, let
  8027. * the first leader that performs a
  8028. * leader_reset() reset the global blocks in
  8029. * order to clear global attentions. Otherwise
  8030. * the gates will remain closed for that
  8031. * engine.
  8032. */
  8033. if (load_status ||
  8034. (global && other_load_status)) {
  8035. /* Wait until all other functions get
  8036. * down.
  8037. */
  8038. schedule_delayed_work(&bp->sp_rtnl_task,
  8039. HZ/10);
  8040. return;
  8041. } else {
  8042. /* If all other functions got down -
  8043. * try to bring the chip back to
  8044. * normal. In any case it's an exit
  8045. * point for a leader.
  8046. */
  8047. if (bnx2x_leader_reset(bp)) {
  8048. bnx2x_recovery_failed(bp);
  8049. return;
  8050. }
  8051. /* If we are here, means that the
  8052. * leader has succeeded and doesn't
  8053. * want to be a leader any more. Try
  8054. * to continue as a none-leader.
  8055. */
  8056. break;
  8057. }
  8058. } else { /* non-leader */
  8059. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8060. /* Try to get a LEADER_LOCK HW lock as
  8061. * long as a former leader may have
  8062. * been unloaded by the user or
  8063. * released a leadership by another
  8064. * reason.
  8065. */
  8066. if (bnx2x_trylock_leader_lock(bp)) {
  8067. /* I'm a leader now! Restart a
  8068. * switch case.
  8069. */
  8070. bp->is_leader = 1;
  8071. break;
  8072. }
  8073. schedule_delayed_work(&bp->sp_rtnl_task,
  8074. HZ/10);
  8075. return;
  8076. } else {
  8077. /*
  8078. * If there was a global attention, wait
  8079. * for it to be cleared.
  8080. */
  8081. if (bnx2x_reset_is_global(bp)) {
  8082. schedule_delayed_work(
  8083. &bp->sp_rtnl_task,
  8084. HZ/10);
  8085. return;
  8086. }
  8087. error_recovered =
  8088. bp->eth_stats.recoverable_error;
  8089. error_unrecovered =
  8090. bp->eth_stats.unrecoverable_error;
  8091. bp->recovery_state =
  8092. BNX2X_RECOVERY_NIC_LOADING;
  8093. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8094. error_unrecovered++;
  8095. netdev_err(bp->dev,
  8096. "Recovery failed. Power cycle needed\n");
  8097. /* Disconnect this device */
  8098. netif_device_detach(bp->dev);
  8099. /* Shut down the power */
  8100. bnx2x_set_power_state(
  8101. bp, PCI_D3hot);
  8102. smp_mb();
  8103. } else {
  8104. bp->recovery_state =
  8105. BNX2X_RECOVERY_DONE;
  8106. error_recovered++;
  8107. smp_mb();
  8108. }
  8109. bp->eth_stats.recoverable_error =
  8110. error_recovered;
  8111. bp->eth_stats.unrecoverable_error =
  8112. error_unrecovered;
  8113. return;
  8114. }
  8115. }
  8116. default:
  8117. return;
  8118. }
  8119. }
  8120. }
  8121. static int bnx2x_close(struct net_device *dev);
  8122. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8123. * scheduled on a general queue in order to prevent a dead lock.
  8124. */
  8125. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8126. {
  8127. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8128. rtnl_lock();
  8129. if (!netif_running(bp->dev)) {
  8130. rtnl_unlock();
  8131. return;
  8132. }
  8133. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8134. #ifdef BNX2X_STOP_ON_ERROR
  8135. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8136. "you will need to reboot when done\n");
  8137. goto sp_rtnl_not_reset;
  8138. #endif
  8139. /*
  8140. * Clear all pending SP commands as we are going to reset the
  8141. * function anyway.
  8142. */
  8143. bp->sp_rtnl_state = 0;
  8144. smp_mb();
  8145. bnx2x_parity_recover(bp);
  8146. rtnl_unlock();
  8147. return;
  8148. }
  8149. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8150. #ifdef BNX2X_STOP_ON_ERROR
  8151. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8152. "you will need to reboot when done\n");
  8153. goto sp_rtnl_not_reset;
  8154. #endif
  8155. /*
  8156. * Clear all pending SP commands as we are going to reset the
  8157. * function anyway.
  8158. */
  8159. bp->sp_rtnl_state = 0;
  8160. smp_mb();
  8161. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8162. bnx2x_nic_load(bp, LOAD_NORMAL);
  8163. rtnl_unlock();
  8164. return;
  8165. }
  8166. #ifdef BNX2X_STOP_ON_ERROR
  8167. sp_rtnl_not_reset:
  8168. #endif
  8169. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8170. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8171. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8172. bnx2x_after_function_update(bp);
  8173. /*
  8174. * in case of fan failure we need to reset id if the "stop on error"
  8175. * debug flag is set, since we trying to prevent permanent overheating
  8176. * damage
  8177. */
  8178. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8179. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8180. netif_device_detach(bp->dev);
  8181. bnx2x_close(bp->dev);
  8182. rtnl_unlock();
  8183. return;
  8184. }
  8185. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8186. DP(BNX2X_MSG_SP,
  8187. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8188. bnx2x_vfpf_set_mcast(bp->dev);
  8189. }
  8190. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8191. &bp->sp_rtnl_state)){
  8192. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8193. bnx2x_tx_disable(bp);
  8194. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8195. }
  8196. }
  8197. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8198. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8199. bnx2x_set_rx_mode_inner(bp);
  8200. }
  8201. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8202. &bp->sp_rtnl_state))
  8203. bnx2x_pf_set_vfs_vlan(bp);
  8204. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8205. bnx2x_dcbx_stop_hw_tx(bp);
  8206. bnx2x_dcbx_resume_hw_tx(bp);
  8207. }
  8208. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8209. * can be called from other contexts as well)
  8210. */
  8211. rtnl_unlock();
  8212. /* enable SR-IOV if applicable */
  8213. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8214. &bp->sp_rtnl_state)) {
  8215. bnx2x_disable_sriov(bp);
  8216. bnx2x_enable_sriov(bp);
  8217. }
  8218. }
  8219. static void bnx2x_period_task(struct work_struct *work)
  8220. {
  8221. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8222. if (!netif_running(bp->dev))
  8223. goto period_task_exit;
  8224. if (CHIP_REV_IS_SLOW(bp)) {
  8225. BNX2X_ERR("period task called on emulation, ignoring\n");
  8226. goto period_task_exit;
  8227. }
  8228. bnx2x_acquire_phy_lock(bp);
  8229. /*
  8230. * The barrier is needed to ensure the ordering between the writing to
  8231. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8232. * the reading here.
  8233. */
  8234. smp_mb();
  8235. if (bp->port.pmf) {
  8236. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8237. /* Re-queue task in 1 sec */
  8238. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8239. }
  8240. bnx2x_release_phy_lock(bp);
  8241. period_task_exit:
  8242. return;
  8243. }
  8244. /*
  8245. * Init service functions
  8246. */
  8247. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8248. {
  8249. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8250. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8251. return base + (BP_ABS_FUNC(bp)) * stride;
  8252. }
  8253. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8254. struct bnx2x_mac_vals *vals)
  8255. {
  8256. u32 val, base_addr, offset, mask, reset_reg;
  8257. bool mac_stopped = false;
  8258. u8 port = BP_PORT(bp);
  8259. /* reset addresses as they also mark which values were changed */
  8260. vals->bmac_addr = 0;
  8261. vals->umac_addr = 0;
  8262. vals->xmac_addr = 0;
  8263. vals->emac_addr = 0;
  8264. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8265. if (!CHIP_IS_E3(bp)) {
  8266. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8267. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8268. if ((mask & reset_reg) && val) {
  8269. u32 wb_data[2];
  8270. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8271. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8272. : NIG_REG_INGRESS_BMAC0_MEM;
  8273. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8274. : BIGMAC_REGISTER_BMAC_CONTROL;
  8275. /*
  8276. * use rd/wr since we cannot use dmae. This is safe
  8277. * since MCP won't access the bus due to the request
  8278. * to unload, and no function on the path can be
  8279. * loaded at this time.
  8280. */
  8281. wb_data[0] = REG_RD(bp, base_addr + offset);
  8282. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8283. vals->bmac_addr = base_addr + offset;
  8284. vals->bmac_val[0] = wb_data[0];
  8285. vals->bmac_val[1] = wb_data[1];
  8286. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8287. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8288. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8289. }
  8290. BNX2X_DEV_INFO("Disable emac Rx\n");
  8291. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8292. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8293. REG_WR(bp, vals->emac_addr, 0);
  8294. mac_stopped = true;
  8295. } else {
  8296. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8297. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8298. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8299. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8300. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8301. val & ~(1 << 1));
  8302. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8303. val | (1 << 1));
  8304. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8305. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8306. REG_WR(bp, vals->xmac_addr, 0);
  8307. mac_stopped = true;
  8308. }
  8309. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8310. if (mask & reset_reg) {
  8311. BNX2X_DEV_INFO("Disable umac Rx\n");
  8312. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8313. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8314. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8315. REG_WR(bp, vals->umac_addr, 0);
  8316. mac_stopped = true;
  8317. }
  8318. }
  8319. if (mac_stopped)
  8320. msleep(20);
  8321. }
  8322. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8323. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8324. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8325. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8326. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8327. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8328. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8329. #define BNX2X_PREV_UNDI_MF_PORT(p) (0x1a150c + ((p) << 4))
  8330. #define BNX2X_PREV_UNDI_MF_FUNC(f) (0x1a184c + ((f) << 4))
  8331. static bool bnx2x_prev_unload_undi_fw_supports_mf(struct bnx2x *bp)
  8332. {
  8333. u8 major, minor, version;
  8334. u32 fw;
  8335. /* Must check that FW is loaded */
  8336. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8337. MISC_REGISTERS_RESET_REG_1_RST_XSEM)) {
  8338. BNX2X_DEV_INFO("XSEM is reset - UNDI MF FW is not loaded\n");
  8339. return false;
  8340. }
  8341. /* Read Currently loaded FW version */
  8342. fw = REG_RD(bp, XSEM_REG_PRAM);
  8343. major = fw & 0xff;
  8344. minor = (fw >> 0x8) & 0xff;
  8345. version = (fw >> 0x10) & 0xff;
  8346. BNX2X_DEV_INFO("Loaded FW: 0x%08x: Major 0x%02x Minor 0x%02x Version 0x%02x\n",
  8347. fw, major, minor, version);
  8348. if (major > BCM_5710_UNDI_FW_MF_MAJOR)
  8349. return true;
  8350. if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
  8351. (minor > BCM_5710_UNDI_FW_MF_MINOR))
  8352. return true;
  8353. if ((major == BCM_5710_UNDI_FW_MF_MAJOR) &&
  8354. (minor == BCM_5710_UNDI_FW_MF_MINOR) &&
  8355. (version >= BCM_5710_UNDI_FW_MF_VERS))
  8356. return true;
  8357. return false;
  8358. }
  8359. static void bnx2x_prev_unload_undi_mf(struct bnx2x *bp)
  8360. {
  8361. int i;
  8362. /* Due to legacy (FW) code, the first function on each engine has a
  8363. * different offset macro from the rest of the functions.
  8364. * Setting this for all 8 functions is harmless regardless of whether
  8365. * this is actually a multi-function device.
  8366. */
  8367. for (i = 0; i < 2; i++)
  8368. REG_WR(bp, BNX2X_PREV_UNDI_MF_PORT(i), 1);
  8369. for (i = 2; i < 8; i++)
  8370. REG_WR(bp, BNX2X_PREV_UNDI_MF_FUNC(i - 2), 1);
  8371. BNX2X_DEV_INFO("UNDI FW (MF) set to discard\n");
  8372. }
  8373. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8374. {
  8375. u16 rcq, bd;
  8376. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8377. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8378. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8379. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8380. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8381. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8382. port, bd, rcq);
  8383. }
  8384. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8385. {
  8386. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8387. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8388. if (!rc) {
  8389. BNX2X_ERR("MCP response failure, aborting\n");
  8390. return -EBUSY;
  8391. }
  8392. return 0;
  8393. }
  8394. static struct bnx2x_prev_path_list *
  8395. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8396. {
  8397. struct bnx2x_prev_path_list *tmp_list;
  8398. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8399. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8400. bp->pdev->bus->number == tmp_list->bus &&
  8401. BP_PATH(bp) == tmp_list->path)
  8402. return tmp_list;
  8403. return NULL;
  8404. }
  8405. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8406. {
  8407. struct bnx2x_prev_path_list *tmp_list;
  8408. int rc;
  8409. rc = down_interruptible(&bnx2x_prev_sem);
  8410. if (rc) {
  8411. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8412. return rc;
  8413. }
  8414. tmp_list = bnx2x_prev_path_get_entry(bp);
  8415. if (tmp_list) {
  8416. tmp_list->aer = 1;
  8417. rc = 0;
  8418. } else {
  8419. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8420. BP_PATH(bp));
  8421. }
  8422. up(&bnx2x_prev_sem);
  8423. return rc;
  8424. }
  8425. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8426. {
  8427. struct bnx2x_prev_path_list *tmp_list;
  8428. bool rc = false;
  8429. if (down_trylock(&bnx2x_prev_sem))
  8430. return false;
  8431. tmp_list = bnx2x_prev_path_get_entry(bp);
  8432. if (tmp_list) {
  8433. if (tmp_list->aer) {
  8434. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8435. BP_PATH(bp));
  8436. } else {
  8437. rc = true;
  8438. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8439. BP_PATH(bp));
  8440. }
  8441. }
  8442. up(&bnx2x_prev_sem);
  8443. return rc;
  8444. }
  8445. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8446. {
  8447. struct bnx2x_prev_path_list *entry;
  8448. bool val;
  8449. down(&bnx2x_prev_sem);
  8450. entry = bnx2x_prev_path_get_entry(bp);
  8451. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8452. up(&bnx2x_prev_sem);
  8453. return val;
  8454. }
  8455. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8456. {
  8457. struct bnx2x_prev_path_list *tmp_list;
  8458. int rc;
  8459. rc = down_interruptible(&bnx2x_prev_sem);
  8460. if (rc) {
  8461. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8462. return rc;
  8463. }
  8464. /* Check whether the entry for this path already exists */
  8465. tmp_list = bnx2x_prev_path_get_entry(bp);
  8466. if (tmp_list) {
  8467. if (!tmp_list->aer) {
  8468. BNX2X_ERR("Re-Marking the path.\n");
  8469. } else {
  8470. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8471. BP_PATH(bp));
  8472. tmp_list->aer = 0;
  8473. }
  8474. up(&bnx2x_prev_sem);
  8475. return 0;
  8476. }
  8477. up(&bnx2x_prev_sem);
  8478. /* Create an entry for this path and add it */
  8479. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8480. if (!tmp_list) {
  8481. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8482. return -ENOMEM;
  8483. }
  8484. tmp_list->bus = bp->pdev->bus->number;
  8485. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8486. tmp_list->path = BP_PATH(bp);
  8487. tmp_list->aer = 0;
  8488. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8489. rc = down_interruptible(&bnx2x_prev_sem);
  8490. if (rc) {
  8491. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8492. kfree(tmp_list);
  8493. } else {
  8494. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8495. BP_PATH(bp));
  8496. list_add(&tmp_list->list, &bnx2x_prev_list);
  8497. up(&bnx2x_prev_sem);
  8498. }
  8499. return rc;
  8500. }
  8501. static int bnx2x_do_flr(struct bnx2x *bp)
  8502. {
  8503. struct pci_dev *dev = bp->pdev;
  8504. if (CHIP_IS_E1x(bp)) {
  8505. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8506. return -EINVAL;
  8507. }
  8508. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8509. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8510. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8511. bp->common.bc_ver);
  8512. return -EINVAL;
  8513. }
  8514. if (!pci_wait_for_pending_transaction(dev))
  8515. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8516. BNX2X_DEV_INFO("Initiating FLR\n");
  8517. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8518. return 0;
  8519. }
  8520. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8521. {
  8522. int rc;
  8523. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8524. /* Test if previous unload process was already finished for this path */
  8525. if (bnx2x_prev_is_path_marked(bp))
  8526. return bnx2x_prev_mcp_done(bp);
  8527. BNX2X_DEV_INFO("Path is unmarked\n");
  8528. /* If function has FLR capabilities, and existing FW version matches
  8529. * the one required, then FLR will be sufficient to clean any residue
  8530. * left by previous driver
  8531. */
  8532. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8533. if (!rc) {
  8534. /* fw version is good */
  8535. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8536. rc = bnx2x_do_flr(bp);
  8537. }
  8538. if (!rc) {
  8539. /* FLR was performed */
  8540. BNX2X_DEV_INFO("FLR successful\n");
  8541. return 0;
  8542. }
  8543. BNX2X_DEV_INFO("Could not FLR\n");
  8544. /* Close the MCP request, return failure*/
  8545. rc = bnx2x_prev_mcp_done(bp);
  8546. if (!rc)
  8547. rc = BNX2X_PREV_WAIT_NEEDED;
  8548. return rc;
  8549. }
  8550. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8551. {
  8552. u32 reset_reg, tmp_reg = 0, rc;
  8553. bool prev_undi = false;
  8554. struct bnx2x_mac_vals mac_vals;
  8555. /* It is possible a previous function received 'common' answer,
  8556. * but hasn't loaded yet, therefore creating a scenario of
  8557. * multiple functions receiving 'common' on the same path.
  8558. */
  8559. BNX2X_DEV_INFO("Common unload Flow\n");
  8560. memset(&mac_vals, 0, sizeof(mac_vals));
  8561. if (bnx2x_prev_is_path_marked(bp))
  8562. return bnx2x_prev_mcp_done(bp);
  8563. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8564. /* Reset should be performed after BRB is emptied */
  8565. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8566. u32 timer_count = 1000;
  8567. /* Close the MAC Rx to prevent BRB from filling up */
  8568. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8569. /* close LLH filters towards the BRB */
  8570. bnx2x_set_rx_filter(&bp->link_params, 0);
  8571. /* Check if the UNDI driver was previously loaded
  8572. * UNDI driver initializes CID offset for normal bell to 0x7
  8573. */
  8574. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8575. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8576. if (tmp_reg == 0x7) {
  8577. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8578. prev_undi = true;
  8579. /* clear the UNDI indication */
  8580. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8581. /* clear possible idle check errors */
  8582. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8583. }
  8584. }
  8585. if (!CHIP_IS_E1x(bp))
  8586. /* block FW from writing to host */
  8587. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8588. /* wait until BRB is empty */
  8589. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8590. while (timer_count) {
  8591. u32 prev_brb = tmp_reg;
  8592. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8593. if (!tmp_reg)
  8594. break;
  8595. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8596. /* reset timer as long as BRB actually gets emptied */
  8597. if (prev_brb > tmp_reg)
  8598. timer_count = 1000;
  8599. else
  8600. timer_count--;
  8601. /* New UNDI FW supports MF and contains better
  8602. * cleaning methods - might be redundant but harmless.
  8603. */
  8604. if (bnx2x_prev_unload_undi_fw_supports_mf(bp)) {
  8605. bnx2x_prev_unload_undi_mf(bp);
  8606. } else if (prev_undi) {
  8607. /* If UNDI resides in memory,
  8608. * manually increment it
  8609. */
  8610. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8611. }
  8612. udelay(10);
  8613. }
  8614. if (!timer_count)
  8615. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8616. }
  8617. /* No packets are in the pipeline, path is ready for reset */
  8618. bnx2x_reset_common(bp);
  8619. if (mac_vals.xmac_addr)
  8620. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8621. if (mac_vals.umac_addr)
  8622. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8623. if (mac_vals.emac_addr)
  8624. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8625. if (mac_vals.bmac_addr) {
  8626. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8627. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8628. }
  8629. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8630. if (rc) {
  8631. bnx2x_prev_mcp_done(bp);
  8632. return rc;
  8633. }
  8634. return bnx2x_prev_mcp_done(bp);
  8635. }
  8636. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8637. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8638. * the addresses of the transaction, resulting in was-error bit set in the pci
  8639. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8640. * to clear the interrupt which detected this from the pglueb and the was done
  8641. * bit
  8642. */
  8643. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8644. {
  8645. if (!CHIP_IS_E1x(bp)) {
  8646. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8647. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8648. DP(BNX2X_MSG_SP,
  8649. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8650. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8651. 1 << BP_FUNC(bp));
  8652. }
  8653. }
  8654. }
  8655. static int bnx2x_prev_unload(struct bnx2x *bp)
  8656. {
  8657. int time_counter = 10;
  8658. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8659. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8660. /* clear hw from errors which may have resulted from an interrupted
  8661. * dmae transaction.
  8662. */
  8663. bnx2x_prev_interrupted_dmae(bp);
  8664. /* Release previously held locks */
  8665. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8666. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8667. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8668. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8669. if (hw_lock_val) {
  8670. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8671. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8672. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8673. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8674. }
  8675. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8676. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8677. } else
  8678. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8679. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8680. BNX2X_DEV_INFO("Release previously held alr\n");
  8681. bnx2x_release_alr(bp);
  8682. }
  8683. do {
  8684. int aer = 0;
  8685. /* Lock MCP using an unload request */
  8686. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8687. if (!fw) {
  8688. BNX2X_ERR("MCP response failure, aborting\n");
  8689. rc = -EBUSY;
  8690. break;
  8691. }
  8692. rc = down_interruptible(&bnx2x_prev_sem);
  8693. if (rc) {
  8694. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8695. rc);
  8696. } else {
  8697. /* If Path is marked by EEH, ignore unload status */
  8698. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8699. bnx2x_prev_path_get_entry(bp)->aer);
  8700. up(&bnx2x_prev_sem);
  8701. }
  8702. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8703. rc = bnx2x_prev_unload_common(bp);
  8704. break;
  8705. }
  8706. /* non-common reply from MCP might require looping */
  8707. rc = bnx2x_prev_unload_uncommon(bp);
  8708. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8709. break;
  8710. msleep(20);
  8711. } while (--time_counter);
  8712. if (!time_counter || rc) {
  8713. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8714. rc = -EPROBE_DEFER;
  8715. }
  8716. /* Mark function if its port was used to boot from SAN */
  8717. if (bnx2x_port_after_undi(bp))
  8718. bp->link_params.feature_config_flags |=
  8719. FEATURE_CONFIG_BOOT_FROM_SAN;
  8720. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8721. return rc;
  8722. }
  8723. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8724. {
  8725. u32 val, val2, val3, val4, id, boot_mode;
  8726. u16 pmc;
  8727. /* Get the chip revision id and number. */
  8728. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8729. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8730. id = ((val & 0xffff) << 16);
  8731. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8732. id |= ((val & 0xf) << 12);
  8733. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8734. * the configuration space (so we need to reg_rd)
  8735. */
  8736. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8737. id |= (((val >> 24) & 0xf) << 4);
  8738. val = REG_RD(bp, MISC_REG_BOND_ID);
  8739. id |= (val & 0xf);
  8740. bp->common.chip_id = id;
  8741. /* force 57811 according to MISC register */
  8742. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8743. if (CHIP_IS_57810(bp))
  8744. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8745. (bp->common.chip_id & 0x0000FFFF);
  8746. else if (CHIP_IS_57810_MF(bp))
  8747. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8748. (bp->common.chip_id & 0x0000FFFF);
  8749. bp->common.chip_id |= 0x1;
  8750. }
  8751. /* Set doorbell size */
  8752. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8753. if (!CHIP_IS_E1x(bp)) {
  8754. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8755. if ((val & 1) == 0)
  8756. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8757. else
  8758. val = (val >> 1) & 1;
  8759. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8760. "2_PORT_MODE");
  8761. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8762. CHIP_2_PORT_MODE;
  8763. if (CHIP_MODE_IS_4_PORT(bp))
  8764. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8765. else
  8766. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8767. } else {
  8768. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8769. bp->pfid = bp->pf_num; /* 0..7 */
  8770. }
  8771. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8772. bp->link_params.chip_id = bp->common.chip_id;
  8773. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8774. val = (REG_RD(bp, 0x2874) & 0x55);
  8775. if ((bp->common.chip_id & 0x1) ||
  8776. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8777. bp->flags |= ONE_PORT_FLAG;
  8778. BNX2X_DEV_INFO("single port device\n");
  8779. }
  8780. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8781. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8782. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8783. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8784. bp->common.flash_size, bp->common.flash_size);
  8785. bnx2x_init_shmem(bp);
  8786. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8787. MISC_REG_GENERIC_CR_1 :
  8788. MISC_REG_GENERIC_CR_0));
  8789. bp->link_params.shmem_base = bp->common.shmem_base;
  8790. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8791. if (SHMEM2_RD(bp, size) >
  8792. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8793. bp->link_params.lfa_base =
  8794. REG_RD(bp, bp->common.shmem2_base +
  8795. (u32)offsetof(struct shmem2_region,
  8796. lfa_host_addr[BP_PORT(bp)]));
  8797. else
  8798. bp->link_params.lfa_base = 0;
  8799. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8800. bp->common.shmem_base, bp->common.shmem2_base);
  8801. if (!bp->common.shmem_base) {
  8802. BNX2X_DEV_INFO("MCP not active\n");
  8803. bp->flags |= NO_MCP_FLAG;
  8804. return;
  8805. }
  8806. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8807. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8808. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8809. SHARED_HW_CFG_LED_MODE_MASK) >>
  8810. SHARED_HW_CFG_LED_MODE_SHIFT);
  8811. bp->link_params.feature_config_flags = 0;
  8812. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8813. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8814. bp->link_params.feature_config_flags |=
  8815. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8816. else
  8817. bp->link_params.feature_config_flags &=
  8818. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8819. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8820. bp->common.bc_ver = val;
  8821. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8822. if (val < BNX2X_BC_VER) {
  8823. /* for now only warn
  8824. * later we might need to enforce this */
  8825. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8826. BNX2X_BC_VER, val);
  8827. }
  8828. bp->link_params.feature_config_flags |=
  8829. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8830. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8831. bp->link_params.feature_config_flags |=
  8832. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8833. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8834. bp->link_params.feature_config_flags |=
  8835. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8836. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8837. bp->link_params.feature_config_flags |=
  8838. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8839. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8840. bp->link_params.feature_config_flags |=
  8841. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8842. FEATURE_CONFIG_MT_SUPPORT : 0;
  8843. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8844. BC_SUPPORTS_PFC_STATS : 0;
  8845. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8846. BC_SUPPORTS_FCOE_FEATURES : 0;
  8847. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8848. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8849. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8850. BC_SUPPORTS_RMMOD_CMD : 0;
  8851. boot_mode = SHMEM_RD(bp,
  8852. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8853. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8854. switch (boot_mode) {
  8855. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8856. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8857. break;
  8858. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8859. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8860. break;
  8861. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8862. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8863. break;
  8864. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8865. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8866. break;
  8867. }
  8868. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  8869. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8870. BNX2X_DEV_INFO("%sWoL capable\n",
  8871. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8872. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8873. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8874. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8875. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8876. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8877. val, val2, val3, val4);
  8878. }
  8879. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8880. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8881. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8882. {
  8883. int pfid = BP_FUNC(bp);
  8884. int igu_sb_id;
  8885. u32 val;
  8886. u8 fid, igu_sb_cnt = 0;
  8887. bp->igu_base_sb = 0xff;
  8888. if (CHIP_INT_MODE_IS_BC(bp)) {
  8889. int vn = BP_VN(bp);
  8890. igu_sb_cnt = bp->igu_sb_cnt;
  8891. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8892. FP_SB_MAX_E1x;
  8893. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8894. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8895. return 0;
  8896. }
  8897. /* IGU in normal mode - read CAM */
  8898. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8899. igu_sb_id++) {
  8900. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8901. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8902. continue;
  8903. fid = IGU_FID(val);
  8904. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8905. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8906. continue;
  8907. if (IGU_VEC(val) == 0)
  8908. /* default status block */
  8909. bp->igu_dsb_id = igu_sb_id;
  8910. else {
  8911. if (bp->igu_base_sb == 0xff)
  8912. bp->igu_base_sb = igu_sb_id;
  8913. igu_sb_cnt++;
  8914. }
  8915. }
  8916. }
  8917. #ifdef CONFIG_PCI_MSI
  8918. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8919. * optional that number of CAM entries will not be equal to the value
  8920. * advertised in PCI.
  8921. * Driver should use the minimal value of both as the actual status
  8922. * block count
  8923. */
  8924. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8925. #endif
  8926. if (igu_sb_cnt == 0) {
  8927. BNX2X_ERR("CAM configuration error\n");
  8928. return -EINVAL;
  8929. }
  8930. return 0;
  8931. }
  8932. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8933. {
  8934. int cfg_size = 0, idx, port = BP_PORT(bp);
  8935. /* Aggregation of supported attributes of all external phys */
  8936. bp->port.supported[0] = 0;
  8937. bp->port.supported[1] = 0;
  8938. switch (bp->link_params.num_phys) {
  8939. case 1:
  8940. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8941. cfg_size = 1;
  8942. break;
  8943. case 2:
  8944. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8945. cfg_size = 1;
  8946. break;
  8947. case 3:
  8948. if (bp->link_params.multi_phy_config &
  8949. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8950. bp->port.supported[1] =
  8951. bp->link_params.phy[EXT_PHY1].supported;
  8952. bp->port.supported[0] =
  8953. bp->link_params.phy[EXT_PHY2].supported;
  8954. } else {
  8955. bp->port.supported[0] =
  8956. bp->link_params.phy[EXT_PHY1].supported;
  8957. bp->port.supported[1] =
  8958. bp->link_params.phy[EXT_PHY2].supported;
  8959. }
  8960. cfg_size = 2;
  8961. break;
  8962. }
  8963. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8964. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8965. SHMEM_RD(bp,
  8966. dev_info.port_hw_config[port].external_phy_config),
  8967. SHMEM_RD(bp,
  8968. dev_info.port_hw_config[port].external_phy_config2));
  8969. return;
  8970. }
  8971. if (CHIP_IS_E3(bp))
  8972. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8973. else {
  8974. switch (switch_cfg) {
  8975. case SWITCH_CFG_1G:
  8976. bp->port.phy_addr = REG_RD(
  8977. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8978. break;
  8979. case SWITCH_CFG_10G:
  8980. bp->port.phy_addr = REG_RD(
  8981. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8982. break;
  8983. default:
  8984. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8985. bp->port.link_config[0]);
  8986. return;
  8987. }
  8988. }
  8989. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8990. /* mask what we support according to speed_cap_mask per configuration */
  8991. for (idx = 0; idx < cfg_size; idx++) {
  8992. if (!(bp->link_params.speed_cap_mask[idx] &
  8993. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8994. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8995. if (!(bp->link_params.speed_cap_mask[idx] &
  8996. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8997. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8998. if (!(bp->link_params.speed_cap_mask[idx] &
  8999. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9000. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9001. if (!(bp->link_params.speed_cap_mask[idx] &
  9002. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9003. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9004. if (!(bp->link_params.speed_cap_mask[idx] &
  9005. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9006. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9007. SUPPORTED_1000baseT_Full);
  9008. if (!(bp->link_params.speed_cap_mask[idx] &
  9009. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9010. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9011. if (!(bp->link_params.speed_cap_mask[idx] &
  9012. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9013. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9014. if (!(bp->link_params.speed_cap_mask[idx] &
  9015. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9016. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9017. }
  9018. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9019. bp->port.supported[1]);
  9020. }
  9021. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9022. {
  9023. u32 link_config, idx, cfg_size = 0;
  9024. bp->port.advertising[0] = 0;
  9025. bp->port.advertising[1] = 0;
  9026. switch (bp->link_params.num_phys) {
  9027. case 1:
  9028. case 2:
  9029. cfg_size = 1;
  9030. break;
  9031. case 3:
  9032. cfg_size = 2;
  9033. break;
  9034. }
  9035. for (idx = 0; idx < cfg_size; idx++) {
  9036. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9037. link_config = bp->port.link_config[idx];
  9038. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9039. case PORT_FEATURE_LINK_SPEED_AUTO:
  9040. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9041. bp->link_params.req_line_speed[idx] =
  9042. SPEED_AUTO_NEG;
  9043. bp->port.advertising[idx] |=
  9044. bp->port.supported[idx];
  9045. if (bp->link_params.phy[EXT_PHY1].type ==
  9046. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9047. bp->port.advertising[idx] |=
  9048. (SUPPORTED_100baseT_Half |
  9049. SUPPORTED_100baseT_Full);
  9050. } else {
  9051. /* force 10G, no AN */
  9052. bp->link_params.req_line_speed[idx] =
  9053. SPEED_10000;
  9054. bp->port.advertising[idx] |=
  9055. (ADVERTISED_10000baseT_Full |
  9056. ADVERTISED_FIBRE);
  9057. continue;
  9058. }
  9059. break;
  9060. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9061. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9062. bp->link_params.req_line_speed[idx] =
  9063. SPEED_10;
  9064. bp->port.advertising[idx] |=
  9065. (ADVERTISED_10baseT_Full |
  9066. ADVERTISED_TP);
  9067. } else {
  9068. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9069. link_config,
  9070. bp->link_params.speed_cap_mask[idx]);
  9071. return;
  9072. }
  9073. break;
  9074. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9075. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9076. bp->link_params.req_line_speed[idx] =
  9077. SPEED_10;
  9078. bp->link_params.req_duplex[idx] =
  9079. DUPLEX_HALF;
  9080. bp->port.advertising[idx] |=
  9081. (ADVERTISED_10baseT_Half |
  9082. ADVERTISED_TP);
  9083. } else {
  9084. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9085. link_config,
  9086. bp->link_params.speed_cap_mask[idx]);
  9087. return;
  9088. }
  9089. break;
  9090. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9091. if (bp->port.supported[idx] &
  9092. SUPPORTED_100baseT_Full) {
  9093. bp->link_params.req_line_speed[idx] =
  9094. SPEED_100;
  9095. bp->port.advertising[idx] |=
  9096. (ADVERTISED_100baseT_Full |
  9097. ADVERTISED_TP);
  9098. } else {
  9099. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9100. link_config,
  9101. bp->link_params.speed_cap_mask[idx]);
  9102. return;
  9103. }
  9104. break;
  9105. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9106. if (bp->port.supported[idx] &
  9107. SUPPORTED_100baseT_Half) {
  9108. bp->link_params.req_line_speed[idx] =
  9109. SPEED_100;
  9110. bp->link_params.req_duplex[idx] =
  9111. DUPLEX_HALF;
  9112. bp->port.advertising[idx] |=
  9113. (ADVERTISED_100baseT_Half |
  9114. ADVERTISED_TP);
  9115. } else {
  9116. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9117. link_config,
  9118. bp->link_params.speed_cap_mask[idx]);
  9119. return;
  9120. }
  9121. break;
  9122. case PORT_FEATURE_LINK_SPEED_1G:
  9123. if (bp->port.supported[idx] &
  9124. SUPPORTED_1000baseT_Full) {
  9125. bp->link_params.req_line_speed[idx] =
  9126. SPEED_1000;
  9127. bp->port.advertising[idx] |=
  9128. (ADVERTISED_1000baseT_Full |
  9129. ADVERTISED_TP);
  9130. } else {
  9131. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9132. link_config,
  9133. bp->link_params.speed_cap_mask[idx]);
  9134. return;
  9135. }
  9136. break;
  9137. case PORT_FEATURE_LINK_SPEED_2_5G:
  9138. if (bp->port.supported[idx] &
  9139. SUPPORTED_2500baseX_Full) {
  9140. bp->link_params.req_line_speed[idx] =
  9141. SPEED_2500;
  9142. bp->port.advertising[idx] |=
  9143. (ADVERTISED_2500baseX_Full |
  9144. ADVERTISED_TP);
  9145. } else {
  9146. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9147. link_config,
  9148. bp->link_params.speed_cap_mask[idx]);
  9149. return;
  9150. }
  9151. break;
  9152. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9153. if (bp->port.supported[idx] &
  9154. SUPPORTED_10000baseT_Full) {
  9155. bp->link_params.req_line_speed[idx] =
  9156. SPEED_10000;
  9157. bp->port.advertising[idx] |=
  9158. (ADVERTISED_10000baseT_Full |
  9159. ADVERTISED_FIBRE);
  9160. } else {
  9161. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9162. link_config,
  9163. bp->link_params.speed_cap_mask[idx]);
  9164. return;
  9165. }
  9166. break;
  9167. case PORT_FEATURE_LINK_SPEED_20G:
  9168. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9169. break;
  9170. default:
  9171. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9172. link_config);
  9173. bp->link_params.req_line_speed[idx] =
  9174. SPEED_AUTO_NEG;
  9175. bp->port.advertising[idx] =
  9176. bp->port.supported[idx];
  9177. break;
  9178. }
  9179. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9180. PORT_FEATURE_FLOW_CONTROL_MASK);
  9181. if (bp->link_params.req_flow_ctrl[idx] ==
  9182. BNX2X_FLOW_CTRL_AUTO) {
  9183. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9184. bp->link_params.req_flow_ctrl[idx] =
  9185. BNX2X_FLOW_CTRL_NONE;
  9186. else
  9187. bnx2x_set_requested_fc(bp);
  9188. }
  9189. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9190. bp->link_params.req_line_speed[idx],
  9191. bp->link_params.req_duplex[idx],
  9192. bp->link_params.req_flow_ctrl[idx],
  9193. bp->port.advertising[idx]);
  9194. }
  9195. }
  9196. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9197. {
  9198. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9199. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9200. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9201. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9202. }
  9203. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9204. {
  9205. int port = BP_PORT(bp);
  9206. u32 config;
  9207. u32 ext_phy_type, ext_phy_config, eee_mode;
  9208. bp->link_params.bp = bp;
  9209. bp->link_params.port = port;
  9210. bp->link_params.lane_config =
  9211. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9212. bp->link_params.speed_cap_mask[0] =
  9213. SHMEM_RD(bp,
  9214. dev_info.port_hw_config[port].speed_capability_mask) &
  9215. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9216. bp->link_params.speed_cap_mask[1] =
  9217. SHMEM_RD(bp,
  9218. dev_info.port_hw_config[port].speed_capability_mask2) &
  9219. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9220. bp->port.link_config[0] =
  9221. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9222. bp->port.link_config[1] =
  9223. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9224. bp->link_params.multi_phy_config =
  9225. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9226. /* If the device is capable of WoL, set the default state according
  9227. * to the HW
  9228. */
  9229. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9230. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9231. (config & PORT_FEATURE_WOL_ENABLED));
  9232. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9233. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9234. bp->flags |= NO_ISCSI_FLAG;
  9235. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9236. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9237. bp->flags |= NO_FCOE_FLAG;
  9238. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9239. bp->link_params.lane_config,
  9240. bp->link_params.speed_cap_mask[0],
  9241. bp->port.link_config[0]);
  9242. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9243. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9244. bnx2x_phy_probe(&bp->link_params);
  9245. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9246. bnx2x_link_settings_requested(bp);
  9247. /*
  9248. * If connected directly, work with the internal PHY, otherwise, work
  9249. * with the external PHY
  9250. */
  9251. ext_phy_config =
  9252. SHMEM_RD(bp,
  9253. dev_info.port_hw_config[port].external_phy_config);
  9254. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9255. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9256. bp->mdio.prtad = bp->port.phy_addr;
  9257. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9258. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9259. bp->mdio.prtad =
  9260. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9261. /* Configure link feature according to nvram value */
  9262. eee_mode = (((SHMEM_RD(bp, dev_info.
  9263. port_feature_config[port].eee_power_mode)) &
  9264. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9265. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9266. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9267. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9268. EEE_MODE_ENABLE_LPI |
  9269. EEE_MODE_OUTPUT_TIME;
  9270. } else {
  9271. bp->link_params.eee_mode = 0;
  9272. }
  9273. }
  9274. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9275. {
  9276. u32 no_flags = NO_ISCSI_FLAG;
  9277. int port = BP_PORT(bp);
  9278. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9279. drv_lic_key[port].max_iscsi_conn);
  9280. if (!CNIC_SUPPORT(bp)) {
  9281. bp->flags |= no_flags;
  9282. return;
  9283. }
  9284. /* Get the number of maximum allowed iSCSI connections */
  9285. bp->cnic_eth_dev.max_iscsi_conn =
  9286. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9287. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9288. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9289. bp->cnic_eth_dev.max_iscsi_conn);
  9290. /*
  9291. * If maximum allowed number of connections is zero -
  9292. * disable the feature.
  9293. */
  9294. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9295. bp->flags |= no_flags;
  9296. }
  9297. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9298. {
  9299. /* Port info */
  9300. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9301. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9302. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9303. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9304. /* Node info */
  9305. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9306. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9307. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9308. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9309. }
  9310. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9311. {
  9312. u8 count = 0;
  9313. if (IS_MF(bp)) {
  9314. u8 fid;
  9315. /* iterate over absolute function ids for this path: */
  9316. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9317. if (IS_MF_SD(bp)) {
  9318. u32 cfg = MF_CFG_RD(bp,
  9319. func_mf_config[fid].config);
  9320. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9321. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9322. FUNC_MF_CFG_PROTOCOL_FCOE))
  9323. count++;
  9324. } else {
  9325. u32 cfg = MF_CFG_RD(bp,
  9326. func_ext_config[fid].
  9327. func_cfg);
  9328. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9329. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9330. count++;
  9331. }
  9332. }
  9333. } else { /* SF */
  9334. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9335. for (port = 0; port < port_cnt; port++) {
  9336. u32 lic = SHMEM_RD(bp,
  9337. drv_lic_key[port].max_fcoe_conn) ^
  9338. FW_ENCODE_32BIT_PATTERN;
  9339. if (lic)
  9340. count++;
  9341. }
  9342. }
  9343. return count;
  9344. }
  9345. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9346. {
  9347. int port = BP_PORT(bp);
  9348. int func = BP_ABS_FUNC(bp);
  9349. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9350. drv_lic_key[port].max_fcoe_conn);
  9351. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9352. if (!CNIC_SUPPORT(bp)) {
  9353. bp->flags |= NO_FCOE_FLAG;
  9354. return;
  9355. }
  9356. /* Get the number of maximum allowed FCoE connections */
  9357. bp->cnic_eth_dev.max_fcoe_conn =
  9358. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9359. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9360. /* Calculate the number of maximum allowed FCoE tasks */
  9361. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9362. /* check if FCoE resources must be shared between different functions */
  9363. if (num_fcoe_func)
  9364. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9365. /* Read the WWN: */
  9366. if (!IS_MF(bp)) {
  9367. /* Port info */
  9368. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9369. SHMEM_RD(bp,
  9370. dev_info.port_hw_config[port].
  9371. fcoe_wwn_port_name_upper);
  9372. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9373. SHMEM_RD(bp,
  9374. dev_info.port_hw_config[port].
  9375. fcoe_wwn_port_name_lower);
  9376. /* Node info */
  9377. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9378. SHMEM_RD(bp,
  9379. dev_info.port_hw_config[port].
  9380. fcoe_wwn_node_name_upper);
  9381. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9382. SHMEM_RD(bp,
  9383. dev_info.port_hw_config[port].
  9384. fcoe_wwn_node_name_lower);
  9385. } else if (!IS_MF_SD(bp)) {
  9386. /*
  9387. * Read the WWN info only if the FCoE feature is enabled for
  9388. * this function.
  9389. */
  9390. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9391. bnx2x_get_ext_wwn_info(bp, func);
  9392. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9393. bnx2x_get_ext_wwn_info(bp, func);
  9394. }
  9395. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9396. /*
  9397. * If maximum allowed number of connections is zero -
  9398. * disable the feature.
  9399. */
  9400. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9401. bp->flags |= NO_FCOE_FLAG;
  9402. }
  9403. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9404. {
  9405. /*
  9406. * iSCSI may be dynamically disabled but reading
  9407. * info here we will decrease memory usage by driver
  9408. * if the feature is disabled for good
  9409. */
  9410. bnx2x_get_iscsi_info(bp);
  9411. bnx2x_get_fcoe_info(bp);
  9412. }
  9413. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9414. {
  9415. u32 val, val2;
  9416. int func = BP_ABS_FUNC(bp);
  9417. int port = BP_PORT(bp);
  9418. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9419. u8 *fip_mac = bp->fip_mac;
  9420. if (IS_MF(bp)) {
  9421. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9422. * FCoE MAC then the appropriate feature should be disabled.
  9423. * In non SD mode features configuration comes from struct
  9424. * func_ext_config.
  9425. */
  9426. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9427. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9428. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9429. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9430. iscsi_mac_addr_upper);
  9431. val = MF_CFG_RD(bp, func_ext_config[func].
  9432. iscsi_mac_addr_lower);
  9433. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9434. BNX2X_DEV_INFO
  9435. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9436. } else {
  9437. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9438. }
  9439. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9440. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9441. fcoe_mac_addr_upper);
  9442. val = MF_CFG_RD(bp, func_ext_config[func].
  9443. fcoe_mac_addr_lower);
  9444. bnx2x_set_mac_buf(fip_mac, val, val2);
  9445. BNX2X_DEV_INFO
  9446. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9447. } else {
  9448. bp->flags |= NO_FCOE_FLAG;
  9449. }
  9450. bp->mf_ext_config = cfg;
  9451. } else { /* SD MODE */
  9452. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9453. /* use primary mac as iscsi mac */
  9454. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9455. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9456. BNX2X_DEV_INFO
  9457. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9458. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9459. /* use primary mac as fip mac */
  9460. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9461. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9462. BNX2X_DEV_INFO
  9463. ("Read FIP MAC: %pM\n", fip_mac);
  9464. }
  9465. }
  9466. /* If this is a storage-only interface, use SAN mac as
  9467. * primary MAC. Notice that for SD this is already the case,
  9468. * as the SAN mac was copied from the primary MAC.
  9469. */
  9470. if (IS_MF_FCOE_AFEX(bp))
  9471. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9472. } else {
  9473. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9474. iscsi_mac_upper);
  9475. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9476. iscsi_mac_lower);
  9477. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9478. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9479. fcoe_fip_mac_upper);
  9480. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9481. fcoe_fip_mac_lower);
  9482. bnx2x_set_mac_buf(fip_mac, val, val2);
  9483. }
  9484. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9485. if (!is_valid_ether_addr(iscsi_mac)) {
  9486. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9487. memset(iscsi_mac, 0, ETH_ALEN);
  9488. }
  9489. /* Disable FCoE if MAC configuration is invalid. */
  9490. if (!is_valid_ether_addr(fip_mac)) {
  9491. bp->flags |= NO_FCOE_FLAG;
  9492. memset(bp->fip_mac, 0, ETH_ALEN);
  9493. }
  9494. }
  9495. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9496. {
  9497. u32 val, val2;
  9498. int func = BP_ABS_FUNC(bp);
  9499. int port = BP_PORT(bp);
  9500. /* Zero primary MAC configuration */
  9501. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9502. if (BP_NOMCP(bp)) {
  9503. BNX2X_ERROR("warning: random MAC workaround active\n");
  9504. eth_hw_addr_random(bp->dev);
  9505. } else if (IS_MF(bp)) {
  9506. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9507. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9508. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9509. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9510. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9511. if (CNIC_SUPPORT(bp))
  9512. bnx2x_get_cnic_mac_hwinfo(bp);
  9513. } else {
  9514. /* in SF read MACs from port configuration */
  9515. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9516. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9517. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9518. if (CNIC_SUPPORT(bp))
  9519. bnx2x_get_cnic_mac_hwinfo(bp);
  9520. }
  9521. if (!BP_NOMCP(bp)) {
  9522. /* Read physical port identifier from shmem */
  9523. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9524. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9525. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9526. bp->flags |= HAS_PHYS_PORT_ID;
  9527. }
  9528. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9529. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9530. dev_err(&bp->pdev->dev,
  9531. "bad Ethernet MAC address configuration: %pM\n"
  9532. "change it manually before bringing up the appropriate network interface\n",
  9533. bp->dev->dev_addr);
  9534. }
  9535. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9536. {
  9537. int tmp;
  9538. u32 cfg;
  9539. if (IS_VF(bp))
  9540. return 0;
  9541. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9542. /* Take function: tmp = func */
  9543. tmp = BP_ABS_FUNC(bp);
  9544. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9545. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9546. } else {
  9547. /* Take port: tmp = port */
  9548. tmp = BP_PORT(bp);
  9549. cfg = SHMEM_RD(bp,
  9550. dev_info.port_hw_config[tmp].generic_features);
  9551. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9552. }
  9553. return cfg;
  9554. }
  9555. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9556. {
  9557. int /*abs*/func = BP_ABS_FUNC(bp);
  9558. int vn;
  9559. u32 val = 0;
  9560. int rc = 0;
  9561. bnx2x_get_common_hwinfo(bp);
  9562. /*
  9563. * initialize IGU parameters
  9564. */
  9565. if (CHIP_IS_E1x(bp)) {
  9566. bp->common.int_block = INT_BLOCK_HC;
  9567. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9568. bp->igu_base_sb = 0;
  9569. } else {
  9570. bp->common.int_block = INT_BLOCK_IGU;
  9571. /* do not allow device reset during IGU info processing */
  9572. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9573. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9574. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9575. int tout = 5000;
  9576. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9577. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9578. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9579. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9580. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9581. tout--;
  9582. usleep_range(1000, 2000);
  9583. }
  9584. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9585. dev_err(&bp->pdev->dev,
  9586. "FORCING Normal Mode failed!!!\n");
  9587. bnx2x_release_hw_lock(bp,
  9588. HW_LOCK_RESOURCE_RESET);
  9589. return -EPERM;
  9590. }
  9591. }
  9592. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9593. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9594. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9595. } else
  9596. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9597. rc = bnx2x_get_igu_cam_info(bp);
  9598. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9599. if (rc)
  9600. return rc;
  9601. }
  9602. /*
  9603. * set base FW non-default (fast path) status block id, this value is
  9604. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9605. * determine the id used by the FW.
  9606. */
  9607. if (CHIP_IS_E1x(bp))
  9608. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9609. else /*
  9610. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9611. * the same queue are indicated on the same IGU SB). So we prefer
  9612. * FW and IGU SBs to be the same value.
  9613. */
  9614. bp->base_fw_ndsb = bp->igu_base_sb;
  9615. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9616. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9617. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9618. /*
  9619. * Initialize MF configuration
  9620. */
  9621. bp->mf_ov = 0;
  9622. bp->mf_mode = 0;
  9623. vn = BP_VN(bp);
  9624. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9625. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9626. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9627. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9628. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9629. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9630. else
  9631. bp->common.mf_cfg_base = bp->common.shmem_base +
  9632. offsetof(struct shmem_region, func_mb) +
  9633. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9634. /*
  9635. * get mf configuration:
  9636. * 1. Existence of MF configuration
  9637. * 2. MAC address must be legal (check only upper bytes)
  9638. * for Switch-Independent mode;
  9639. * OVLAN must be legal for Switch-Dependent mode
  9640. * 3. SF_MODE configures specific MF mode
  9641. */
  9642. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9643. /* get mf configuration */
  9644. val = SHMEM_RD(bp,
  9645. dev_info.shared_feature_config.config);
  9646. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9647. switch (val) {
  9648. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9649. val = MF_CFG_RD(bp, func_mf_config[func].
  9650. mac_upper);
  9651. /* check for legal mac (upper bytes)*/
  9652. if (val != 0xffff) {
  9653. bp->mf_mode = MULTI_FUNCTION_SI;
  9654. bp->mf_config[vn] = MF_CFG_RD(bp,
  9655. func_mf_config[func].config);
  9656. } else
  9657. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9658. break;
  9659. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9660. if ((!CHIP_IS_E1x(bp)) &&
  9661. (MF_CFG_RD(bp, func_mf_config[func].
  9662. mac_upper) != 0xffff) &&
  9663. (SHMEM2_HAS(bp,
  9664. afex_driver_support))) {
  9665. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9666. bp->mf_config[vn] = MF_CFG_RD(bp,
  9667. func_mf_config[func].config);
  9668. } else {
  9669. BNX2X_DEV_INFO("can not configure afex mode\n");
  9670. }
  9671. break;
  9672. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9673. /* get OV configuration */
  9674. val = MF_CFG_RD(bp,
  9675. func_mf_config[FUNC_0].e1hov_tag);
  9676. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9677. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9678. bp->mf_mode = MULTI_FUNCTION_SD;
  9679. bp->mf_config[vn] = MF_CFG_RD(bp,
  9680. func_mf_config[func].config);
  9681. } else
  9682. BNX2X_DEV_INFO("illegal OV for SD\n");
  9683. break;
  9684. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9685. bp->mf_config[vn] = 0;
  9686. break;
  9687. default:
  9688. /* Unknown configuration: reset mf_config */
  9689. bp->mf_config[vn] = 0;
  9690. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9691. }
  9692. }
  9693. BNX2X_DEV_INFO("%s function mode\n",
  9694. IS_MF(bp) ? "multi" : "single");
  9695. switch (bp->mf_mode) {
  9696. case MULTI_FUNCTION_SD:
  9697. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9698. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9699. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9700. bp->mf_ov = val;
  9701. bp->path_has_ovlan = true;
  9702. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9703. func, bp->mf_ov, bp->mf_ov);
  9704. } else {
  9705. dev_err(&bp->pdev->dev,
  9706. "No valid MF OV for func %d, aborting\n",
  9707. func);
  9708. return -EPERM;
  9709. }
  9710. break;
  9711. case MULTI_FUNCTION_AFEX:
  9712. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9713. break;
  9714. case MULTI_FUNCTION_SI:
  9715. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9716. func);
  9717. break;
  9718. default:
  9719. if (vn) {
  9720. dev_err(&bp->pdev->dev,
  9721. "VN %d is in a single function mode, aborting\n",
  9722. vn);
  9723. return -EPERM;
  9724. }
  9725. break;
  9726. }
  9727. /* check if other port on the path needs ovlan:
  9728. * Since MF configuration is shared between ports
  9729. * Possible mixed modes are only
  9730. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9731. */
  9732. if (CHIP_MODE_IS_4_PORT(bp) &&
  9733. !bp->path_has_ovlan &&
  9734. !IS_MF(bp) &&
  9735. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9736. u8 other_port = !BP_PORT(bp);
  9737. u8 other_func = BP_PATH(bp) + 2*other_port;
  9738. val = MF_CFG_RD(bp,
  9739. func_mf_config[other_func].e1hov_tag);
  9740. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9741. bp->path_has_ovlan = true;
  9742. }
  9743. }
  9744. /* adjust igu_sb_cnt to MF for E1H */
  9745. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  9746. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  9747. /* port info */
  9748. bnx2x_get_port_hwinfo(bp);
  9749. /* Get MAC addresses */
  9750. bnx2x_get_mac_hwinfo(bp);
  9751. bnx2x_get_cnic_info(bp);
  9752. return rc;
  9753. }
  9754. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9755. {
  9756. int cnt, i, block_end, rodi;
  9757. char vpd_start[BNX2X_VPD_LEN+1];
  9758. char str_id_reg[VENDOR_ID_LEN+1];
  9759. char str_id_cap[VENDOR_ID_LEN+1];
  9760. char *vpd_data;
  9761. char *vpd_extended_data = NULL;
  9762. u8 len;
  9763. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9764. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9765. if (cnt < BNX2X_VPD_LEN)
  9766. goto out_not_found;
  9767. /* VPD RO tag should be first tag after identifier string, hence
  9768. * we should be able to find it in first BNX2X_VPD_LEN chars
  9769. */
  9770. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9771. PCI_VPD_LRDT_RO_DATA);
  9772. if (i < 0)
  9773. goto out_not_found;
  9774. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9775. pci_vpd_lrdt_size(&vpd_start[i]);
  9776. i += PCI_VPD_LRDT_TAG_SIZE;
  9777. if (block_end > BNX2X_VPD_LEN) {
  9778. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9779. if (vpd_extended_data == NULL)
  9780. goto out_not_found;
  9781. /* read rest of vpd image into vpd_extended_data */
  9782. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9783. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9784. block_end - BNX2X_VPD_LEN,
  9785. vpd_extended_data + BNX2X_VPD_LEN);
  9786. if (cnt < (block_end - BNX2X_VPD_LEN))
  9787. goto out_not_found;
  9788. vpd_data = vpd_extended_data;
  9789. } else
  9790. vpd_data = vpd_start;
  9791. /* now vpd_data holds full vpd content in both cases */
  9792. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9793. PCI_VPD_RO_KEYWORD_MFR_ID);
  9794. if (rodi < 0)
  9795. goto out_not_found;
  9796. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9797. if (len != VENDOR_ID_LEN)
  9798. goto out_not_found;
  9799. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9800. /* vendor specific info */
  9801. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9802. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9803. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9804. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9805. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9806. PCI_VPD_RO_KEYWORD_VENDOR0);
  9807. if (rodi >= 0) {
  9808. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9809. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9810. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9811. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9812. bp->fw_ver[len] = ' ';
  9813. }
  9814. }
  9815. kfree(vpd_extended_data);
  9816. return;
  9817. }
  9818. out_not_found:
  9819. kfree(vpd_extended_data);
  9820. return;
  9821. }
  9822. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9823. {
  9824. u32 flags = 0;
  9825. if (CHIP_REV_IS_FPGA(bp))
  9826. SET_FLAGS(flags, MODE_FPGA);
  9827. else if (CHIP_REV_IS_EMUL(bp))
  9828. SET_FLAGS(flags, MODE_EMUL);
  9829. else
  9830. SET_FLAGS(flags, MODE_ASIC);
  9831. if (CHIP_MODE_IS_4_PORT(bp))
  9832. SET_FLAGS(flags, MODE_PORT4);
  9833. else
  9834. SET_FLAGS(flags, MODE_PORT2);
  9835. if (CHIP_IS_E2(bp))
  9836. SET_FLAGS(flags, MODE_E2);
  9837. else if (CHIP_IS_E3(bp)) {
  9838. SET_FLAGS(flags, MODE_E3);
  9839. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9840. SET_FLAGS(flags, MODE_E3_A0);
  9841. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9842. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9843. }
  9844. if (IS_MF(bp)) {
  9845. SET_FLAGS(flags, MODE_MF);
  9846. switch (bp->mf_mode) {
  9847. case MULTI_FUNCTION_SD:
  9848. SET_FLAGS(flags, MODE_MF_SD);
  9849. break;
  9850. case MULTI_FUNCTION_SI:
  9851. SET_FLAGS(flags, MODE_MF_SI);
  9852. break;
  9853. case MULTI_FUNCTION_AFEX:
  9854. SET_FLAGS(flags, MODE_MF_AFEX);
  9855. break;
  9856. }
  9857. } else
  9858. SET_FLAGS(flags, MODE_SF);
  9859. #if defined(__LITTLE_ENDIAN)
  9860. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9861. #else /*(__BIG_ENDIAN)*/
  9862. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9863. #endif
  9864. INIT_MODE_FLAGS(bp) = flags;
  9865. }
  9866. static int bnx2x_init_bp(struct bnx2x *bp)
  9867. {
  9868. int func;
  9869. int rc;
  9870. mutex_init(&bp->port.phy_mutex);
  9871. mutex_init(&bp->fw_mb_mutex);
  9872. spin_lock_init(&bp->stats_lock);
  9873. sema_init(&bp->stats_sema, 1);
  9874. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9875. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9876. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9877. if (IS_PF(bp)) {
  9878. rc = bnx2x_get_hwinfo(bp);
  9879. if (rc)
  9880. return rc;
  9881. } else {
  9882. eth_zero_addr(bp->dev->dev_addr);
  9883. }
  9884. bnx2x_set_modes_bitmap(bp);
  9885. rc = bnx2x_alloc_mem_bp(bp);
  9886. if (rc)
  9887. return rc;
  9888. bnx2x_read_fwinfo(bp);
  9889. func = BP_FUNC(bp);
  9890. /* need to reset chip if undi was active */
  9891. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9892. /* init fw_seq */
  9893. bp->fw_seq =
  9894. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9895. DRV_MSG_SEQ_NUMBER_MASK;
  9896. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9897. rc = bnx2x_prev_unload(bp);
  9898. if (rc) {
  9899. bnx2x_free_mem_bp(bp);
  9900. return rc;
  9901. }
  9902. }
  9903. if (CHIP_REV_IS_FPGA(bp))
  9904. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9905. if (BP_NOMCP(bp) && (func == 0))
  9906. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9907. bp->disable_tpa = disable_tpa;
  9908. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9909. /* Set TPA flags */
  9910. if (bp->disable_tpa) {
  9911. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9912. bp->dev->features &= ~NETIF_F_LRO;
  9913. } else {
  9914. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9915. bp->dev->features |= NETIF_F_LRO;
  9916. }
  9917. if (CHIP_IS_E1(bp))
  9918. bp->dropless_fc = 0;
  9919. else
  9920. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9921. bp->mrrs = mrrs;
  9922. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9923. if (IS_VF(bp))
  9924. bp->rx_ring_size = MAX_RX_AVAIL;
  9925. /* make sure that the numbers are in the right granularity */
  9926. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9927. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9928. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9929. init_timer(&bp->timer);
  9930. bp->timer.expires = jiffies + bp->current_interval;
  9931. bp->timer.data = (unsigned long) bp;
  9932. bp->timer.function = bnx2x_timer;
  9933. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9934. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9935. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9936. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9937. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9938. bnx2x_dcbx_init_params(bp);
  9939. } else {
  9940. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9941. }
  9942. if (CHIP_IS_E1x(bp))
  9943. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9944. else
  9945. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9946. /* multiple tx priority */
  9947. if (IS_VF(bp))
  9948. bp->max_cos = 1;
  9949. else if (CHIP_IS_E1x(bp))
  9950. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9951. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9952. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9953. else if (CHIP_IS_E3B0(bp))
  9954. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9955. else
  9956. BNX2X_ERR("unknown chip %x revision %x\n",
  9957. CHIP_NUM(bp), CHIP_REV(bp));
  9958. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9959. /* We need at least one default status block for slow-path events,
  9960. * second status block for the L2 queue, and a third status block for
  9961. * CNIC if supported.
  9962. */
  9963. if (IS_VF(bp))
  9964. bp->min_msix_vec_cnt = 1;
  9965. else if (CNIC_SUPPORT(bp))
  9966. bp->min_msix_vec_cnt = 3;
  9967. else /* PF w/o cnic */
  9968. bp->min_msix_vec_cnt = 2;
  9969. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9970. bp->dump_preset_idx = 1;
  9971. return rc;
  9972. }
  9973. /****************************************************************************
  9974. * General service functions
  9975. ****************************************************************************/
  9976. /*
  9977. * net_device service functions
  9978. */
  9979. /* called with rtnl_lock */
  9980. static int bnx2x_open(struct net_device *dev)
  9981. {
  9982. struct bnx2x *bp = netdev_priv(dev);
  9983. int rc;
  9984. bp->stats_init = true;
  9985. netif_carrier_off(dev);
  9986. bnx2x_set_power_state(bp, PCI_D0);
  9987. /* If parity had happen during the unload, then attentions
  9988. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9989. * want the first function loaded on the current engine to
  9990. * complete the recovery.
  9991. * Parity recovery is only relevant for PF driver.
  9992. */
  9993. if (IS_PF(bp)) {
  9994. int other_engine = BP_PATH(bp) ? 0 : 1;
  9995. bool other_load_status, load_status;
  9996. bool global = false;
  9997. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9998. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9999. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10000. bnx2x_chk_parity_attn(bp, &global, true)) {
  10001. do {
  10002. /* If there are attentions and they are in a
  10003. * global blocks, set the GLOBAL_RESET bit
  10004. * regardless whether it will be this function
  10005. * that will complete the recovery or not.
  10006. */
  10007. if (global)
  10008. bnx2x_set_reset_global(bp);
  10009. /* Only the first function on the current
  10010. * engine should try to recover in open. In case
  10011. * of attentions in global blocks only the first
  10012. * in the chip should try to recover.
  10013. */
  10014. if ((!load_status &&
  10015. (!global || !other_load_status)) &&
  10016. bnx2x_trylock_leader_lock(bp) &&
  10017. !bnx2x_leader_reset(bp)) {
  10018. netdev_info(bp->dev,
  10019. "Recovered in open\n");
  10020. break;
  10021. }
  10022. /* recovery has failed... */
  10023. bnx2x_set_power_state(bp, PCI_D3hot);
  10024. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10025. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10026. "If you still see this message after a few retries then power cycle is required.\n");
  10027. return -EAGAIN;
  10028. } while (0);
  10029. }
  10030. }
  10031. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10032. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10033. if (rc)
  10034. return rc;
  10035. return 0;
  10036. }
  10037. /* called with rtnl_lock */
  10038. static int bnx2x_close(struct net_device *dev)
  10039. {
  10040. struct bnx2x *bp = netdev_priv(dev);
  10041. /* Unload the driver, release IRQs */
  10042. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10043. return 0;
  10044. }
  10045. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10046. struct bnx2x_mcast_ramrod_params *p)
  10047. {
  10048. int mc_count = netdev_mc_count(bp->dev);
  10049. struct bnx2x_mcast_list_elem *mc_mac =
  10050. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  10051. struct netdev_hw_addr *ha;
  10052. if (!mc_mac)
  10053. return -ENOMEM;
  10054. INIT_LIST_HEAD(&p->mcast_list);
  10055. netdev_for_each_mc_addr(ha, bp->dev) {
  10056. mc_mac->mac = bnx2x_mc_addr(ha);
  10057. list_add_tail(&mc_mac->link, &p->mcast_list);
  10058. mc_mac++;
  10059. }
  10060. p->mcast_list_len = mc_count;
  10061. return 0;
  10062. }
  10063. static void bnx2x_free_mcast_macs_list(
  10064. struct bnx2x_mcast_ramrod_params *p)
  10065. {
  10066. struct bnx2x_mcast_list_elem *mc_mac =
  10067. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10068. link);
  10069. WARN_ON(!mc_mac);
  10070. kfree(mc_mac);
  10071. }
  10072. /**
  10073. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10074. *
  10075. * @bp: driver handle
  10076. *
  10077. * We will use zero (0) as a MAC type for these MACs.
  10078. */
  10079. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10080. {
  10081. int rc;
  10082. struct net_device *dev = bp->dev;
  10083. struct netdev_hw_addr *ha;
  10084. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10085. unsigned long ramrod_flags = 0;
  10086. /* First schedule a cleanup up of old configuration */
  10087. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10088. if (rc < 0) {
  10089. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10090. return rc;
  10091. }
  10092. netdev_for_each_uc_addr(ha, dev) {
  10093. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10094. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10095. if (rc == -EEXIST) {
  10096. DP(BNX2X_MSG_SP,
  10097. "Failed to schedule ADD operations: %d\n", rc);
  10098. /* do not treat adding same MAC as error */
  10099. rc = 0;
  10100. } else if (rc < 0) {
  10101. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10102. rc);
  10103. return rc;
  10104. }
  10105. }
  10106. /* Execute the pending commands */
  10107. __set_bit(RAMROD_CONT, &ramrod_flags);
  10108. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10109. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10110. }
  10111. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10112. {
  10113. struct net_device *dev = bp->dev;
  10114. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10115. int rc = 0;
  10116. rparam.mcast_obj = &bp->mcast_obj;
  10117. /* first, clear all configured multicast MACs */
  10118. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10119. if (rc < 0) {
  10120. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10121. return rc;
  10122. }
  10123. /* then, configure a new MACs list */
  10124. if (netdev_mc_count(dev)) {
  10125. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10126. if (rc) {
  10127. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10128. rc);
  10129. return rc;
  10130. }
  10131. /* Now add the new MACs */
  10132. rc = bnx2x_config_mcast(bp, &rparam,
  10133. BNX2X_MCAST_CMD_ADD);
  10134. if (rc < 0)
  10135. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10136. rc);
  10137. bnx2x_free_mcast_macs_list(&rparam);
  10138. }
  10139. return rc;
  10140. }
  10141. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10142. static void bnx2x_set_rx_mode(struct net_device *dev)
  10143. {
  10144. struct bnx2x *bp = netdev_priv(dev);
  10145. if (bp->state != BNX2X_STATE_OPEN) {
  10146. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10147. return;
  10148. } else {
  10149. /* Schedule an SP task to handle rest of change */
  10150. DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
  10151. smp_mb__before_clear_bit();
  10152. set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
  10153. smp_mb__after_clear_bit();
  10154. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10155. }
  10156. }
  10157. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10158. {
  10159. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10160. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10161. netif_addr_lock_bh(bp->dev);
  10162. if (bp->dev->flags & IFF_PROMISC) {
  10163. rx_mode = BNX2X_RX_MODE_PROMISC;
  10164. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10165. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10166. CHIP_IS_E1(bp))) {
  10167. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10168. } else {
  10169. if (IS_PF(bp)) {
  10170. /* some multicasts */
  10171. if (bnx2x_set_mc_list(bp) < 0)
  10172. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10173. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10174. netif_addr_unlock_bh(bp->dev);
  10175. if (bnx2x_set_uc_list(bp) < 0)
  10176. rx_mode = BNX2X_RX_MODE_PROMISC;
  10177. netif_addr_lock_bh(bp->dev);
  10178. } else {
  10179. /* configuring mcast to a vf involves sleeping (when we
  10180. * wait for the pf's response).
  10181. */
  10182. smp_mb__before_clear_bit();
  10183. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  10184. &bp->sp_rtnl_state);
  10185. smp_mb__after_clear_bit();
  10186. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10187. }
  10188. }
  10189. bp->rx_mode = rx_mode;
  10190. /* handle ISCSI SD mode */
  10191. if (IS_MF_ISCSI_SD(bp))
  10192. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10193. /* Schedule the rx_mode command */
  10194. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10195. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10196. netif_addr_unlock_bh(bp->dev);
  10197. return;
  10198. }
  10199. if (IS_PF(bp)) {
  10200. bnx2x_set_storm_rx_mode(bp);
  10201. netif_addr_unlock_bh(bp->dev);
  10202. } else {
  10203. /* VF will need to request the PF to make this change, and so
  10204. * the VF needs to release the bottom-half lock prior to the
  10205. * request (as it will likely require sleep on the VF side)
  10206. */
  10207. netif_addr_unlock_bh(bp->dev);
  10208. bnx2x_vfpf_storm_rx_mode(bp);
  10209. }
  10210. }
  10211. /* called with rtnl_lock */
  10212. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10213. int devad, u16 addr)
  10214. {
  10215. struct bnx2x *bp = netdev_priv(netdev);
  10216. u16 value;
  10217. int rc;
  10218. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10219. prtad, devad, addr);
  10220. /* The HW expects different devad if CL22 is used */
  10221. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10222. bnx2x_acquire_phy_lock(bp);
  10223. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10224. bnx2x_release_phy_lock(bp);
  10225. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10226. if (!rc)
  10227. rc = value;
  10228. return rc;
  10229. }
  10230. /* called with rtnl_lock */
  10231. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10232. u16 addr, u16 value)
  10233. {
  10234. struct bnx2x *bp = netdev_priv(netdev);
  10235. int rc;
  10236. DP(NETIF_MSG_LINK,
  10237. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10238. prtad, devad, addr, value);
  10239. /* The HW expects different devad if CL22 is used */
  10240. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10241. bnx2x_acquire_phy_lock(bp);
  10242. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10243. bnx2x_release_phy_lock(bp);
  10244. return rc;
  10245. }
  10246. /* called with rtnl_lock */
  10247. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10248. {
  10249. struct bnx2x *bp = netdev_priv(dev);
  10250. struct mii_ioctl_data *mdio = if_mii(ifr);
  10251. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10252. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10253. if (!netif_running(dev))
  10254. return -EAGAIN;
  10255. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10256. }
  10257. #ifdef CONFIG_NET_POLL_CONTROLLER
  10258. static void poll_bnx2x(struct net_device *dev)
  10259. {
  10260. struct bnx2x *bp = netdev_priv(dev);
  10261. int i;
  10262. for_each_eth_queue(bp, i) {
  10263. struct bnx2x_fastpath *fp = &bp->fp[i];
  10264. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10265. }
  10266. }
  10267. #endif
  10268. static int bnx2x_validate_addr(struct net_device *dev)
  10269. {
  10270. struct bnx2x *bp = netdev_priv(dev);
  10271. /* query the bulletin board for mac address configured by the PF */
  10272. if (IS_VF(bp))
  10273. bnx2x_sample_bulletin(bp);
  10274. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10275. BNX2X_ERR("Non-valid Ethernet address\n");
  10276. return -EADDRNOTAVAIL;
  10277. }
  10278. return 0;
  10279. }
  10280. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10281. struct netdev_phys_port_id *ppid)
  10282. {
  10283. struct bnx2x *bp = netdev_priv(netdev);
  10284. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10285. return -EOPNOTSUPP;
  10286. ppid->id_len = sizeof(bp->phys_port_id);
  10287. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10288. return 0;
  10289. }
  10290. static const struct net_device_ops bnx2x_netdev_ops = {
  10291. .ndo_open = bnx2x_open,
  10292. .ndo_stop = bnx2x_close,
  10293. .ndo_start_xmit = bnx2x_start_xmit,
  10294. .ndo_select_queue = bnx2x_select_queue,
  10295. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10296. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10297. .ndo_validate_addr = bnx2x_validate_addr,
  10298. .ndo_do_ioctl = bnx2x_ioctl,
  10299. .ndo_change_mtu = bnx2x_change_mtu,
  10300. .ndo_fix_features = bnx2x_fix_features,
  10301. .ndo_set_features = bnx2x_set_features,
  10302. .ndo_tx_timeout = bnx2x_tx_timeout,
  10303. #ifdef CONFIG_NET_POLL_CONTROLLER
  10304. .ndo_poll_controller = poll_bnx2x,
  10305. #endif
  10306. .ndo_setup_tc = bnx2x_setup_tc,
  10307. #ifdef CONFIG_BNX2X_SRIOV
  10308. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10309. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10310. .ndo_get_vf_config = bnx2x_get_vf_config,
  10311. #endif
  10312. #ifdef NETDEV_FCOE_WWNN
  10313. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10314. #endif
  10315. #ifdef CONFIG_NET_RX_BUSY_POLL
  10316. .ndo_busy_poll = bnx2x_low_latency_recv,
  10317. #endif
  10318. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10319. };
  10320. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10321. {
  10322. struct device *dev = &bp->pdev->dev;
  10323. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10324. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10325. dev_err(dev, "System does not support DMA, aborting\n");
  10326. return -EIO;
  10327. }
  10328. return 0;
  10329. }
  10330. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10331. {
  10332. if (bp->flags & AER_ENABLED) {
  10333. pci_disable_pcie_error_reporting(bp->pdev);
  10334. bp->flags &= ~AER_ENABLED;
  10335. }
  10336. }
  10337. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10338. struct net_device *dev, unsigned long board_type)
  10339. {
  10340. int rc;
  10341. u32 pci_cfg_dword;
  10342. bool chip_is_e1x = (board_type == BCM57710 ||
  10343. board_type == BCM57711 ||
  10344. board_type == BCM57711E);
  10345. SET_NETDEV_DEV(dev, &pdev->dev);
  10346. bp->dev = dev;
  10347. bp->pdev = pdev;
  10348. rc = pci_enable_device(pdev);
  10349. if (rc) {
  10350. dev_err(&bp->pdev->dev,
  10351. "Cannot enable PCI device, aborting\n");
  10352. goto err_out;
  10353. }
  10354. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10355. dev_err(&bp->pdev->dev,
  10356. "Cannot find PCI device base address, aborting\n");
  10357. rc = -ENODEV;
  10358. goto err_out_disable;
  10359. }
  10360. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10361. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10362. rc = -ENODEV;
  10363. goto err_out_disable;
  10364. }
  10365. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10366. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10367. PCICFG_REVESION_ID_ERROR_VAL) {
  10368. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10369. rc = -ENODEV;
  10370. goto err_out_disable;
  10371. }
  10372. if (atomic_read(&pdev->enable_cnt) == 1) {
  10373. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10374. if (rc) {
  10375. dev_err(&bp->pdev->dev,
  10376. "Cannot obtain PCI resources, aborting\n");
  10377. goto err_out_disable;
  10378. }
  10379. pci_set_master(pdev);
  10380. pci_save_state(pdev);
  10381. }
  10382. if (IS_PF(bp)) {
  10383. if (!pdev->pm_cap) {
  10384. dev_err(&bp->pdev->dev,
  10385. "Cannot find power management capability, aborting\n");
  10386. rc = -EIO;
  10387. goto err_out_release;
  10388. }
  10389. }
  10390. if (!pci_is_pcie(pdev)) {
  10391. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10392. rc = -EIO;
  10393. goto err_out_release;
  10394. }
  10395. rc = bnx2x_set_coherency_mask(bp);
  10396. if (rc)
  10397. goto err_out_release;
  10398. dev->mem_start = pci_resource_start(pdev, 0);
  10399. dev->base_addr = dev->mem_start;
  10400. dev->mem_end = pci_resource_end(pdev, 0);
  10401. dev->irq = pdev->irq;
  10402. bp->regview = pci_ioremap_bar(pdev, 0);
  10403. if (!bp->regview) {
  10404. dev_err(&bp->pdev->dev,
  10405. "Cannot map register space, aborting\n");
  10406. rc = -ENOMEM;
  10407. goto err_out_release;
  10408. }
  10409. /* In E1/E1H use pci device function given by kernel.
  10410. * In E2/E3 read physical function from ME register since these chips
  10411. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10412. * (depending on hypervisor).
  10413. */
  10414. if (chip_is_e1x) {
  10415. bp->pf_num = PCI_FUNC(pdev->devfn);
  10416. } else {
  10417. /* chip is E2/3*/
  10418. pci_read_config_dword(bp->pdev,
  10419. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10420. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10421. ME_REG_ABS_PF_NUM_SHIFT);
  10422. }
  10423. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10424. /* clean indirect addresses */
  10425. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10426. PCICFG_VENDOR_ID_OFFSET);
  10427. /* AER (Advanced Error reporting) configuration */
  10428. rc = pci_enable_pcie_error_reporting(pdev);
  10429. if (!rc)
  10430. bp->flags |= AER_ENABLED;
  10431. else
  10432. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10433. /*
  10434. * Clean the following indirect addresses for all functions since it
  10435. * is not used by the driver.
  10436. */
  10437. if (IS_PF(bp)) {
  10438. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10439. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10440. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10441. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10442. if (chip_is_e1x) {
  10443. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10444. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10445. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10446. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10447. }
  10448. /* Enable internal target-read (in case we are probed after PF
  10449. * FLR). Must be done prior to any BAR read access. Only for
  10450. * 57712 and up
  10451. */
  10452. if (!chip_is_e1x)
  10453. REG_WR(bp,
  10454. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10455. }
  10456. dev->watchdog_timeo = TX_TIMEOUT;
  10457. dev->netdev_ops = &bnx2x_netdev_ops;
  10458. bnx2x_set_ethtool_ops(bp, dev);
  10459. dev->priv_flags |= IFF_UNICAST_FLT;
  10460. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10461. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10462. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10463. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10464. if (!CHIP_IS_E1x(bp)) {
  10465. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10466. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10467. dev->hw_enc_features =
  10468. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10469. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10470. NETIF_F_GSO_IPIP |
  10471. NETIF_F_GSO_SIT |
  10472. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10473. }
  10474. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10475. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10476. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10477. dev->features |= NETIF_F_HIGHDMA;
  10478. /* Add Loopback capability to the device */
  10479. dev->hw_features |= NETIF_F_LOOPBACK;
  10480. #ifdef BCM_DCBNL
  10481. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10482. #endif
  10483. /* get_port_hwinfo() will set prtad and mmds properly */
  10484. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10485. bp->mdio.mmds = 0;
  10486. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10487. bp->mdio.dev = dev;
  10488. bp->mdio.mdio_read = bnx2x_mdio_read;
  10489. bp->mdio.mdio_write = bnx2x_mdio_write;
  10490. return 0;
  10491. err_out_release:
  10492. if (atomic_read(&pdev->enable_cnt) == 1)
  10493. pci_release_regions(pdev);
  10494. err_out_disable:
  10495. pci_disable_device(pdev);
  10496. err_out:
  10497. return rc;
  10498. }
  10499. static int bnx2x_check_firmware(struct bnx2x *bp)
  10500. {
  10501. const struct firmware *firmware = bp->firmware;
  10502. struct bnx2x_fw_file_hdr *fw_hdr;
  10503. struct bnx2x_fw_file_section *sections;
  10504. u32 offset, len, num_ops;
  10505. __be16 *ops_offsets;
  10506. int i;
  10507. const u8 *fw_ver;
  10508. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10509. BNX2X_ERR("Wrong FW size\n");
  10510. return -EINVAL;
  10511. }
  10512. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10513. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10514. /* Make sure none of the offsets and sizes make us read beyond
  10515. * the end of the firmware data */
  10516. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10517. offset = be32_to_cpu(sections[i].offset);
  10518. len = be32_to_cpu(sections[i].len);
  10519. if (offset + len > firmware->size) {
  10520. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10521. return -EINVAL;
  10522. }
  10523. }
  10524. /* Likewise for the init_ops offsets */
  10525. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10526. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10527. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10528. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10529. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10530. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10531. return -EINVAL;
  10532. }
  10533. }
  10534. /* Check FW version */
  10535. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10536. fw_ver = firmware->data + offset;
  10537. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10538. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10539. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10540. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10541. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10542. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10543. BCM_5710_FW_MAJOR_VERSION,
  10544. BCM_5710_FW_MINOR_VERSION,
  10545. BCM_5710_FW_REVISION_VERSION,
  10546. BCM_5710_FW_ENGINEERING_VERSION);
  10547. return -EINVAL;
  10548. }
  10549. return 0;
  10550. }
  10551. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10552. {
  10553. const __be32 *source = (const __be32 *)_source;
  10554. u32 *target = (u32 *)_target;
  10555. u32 i;
  10556. for (i = 0; i < n/4; i++)
  10557. target[i] = be32_to_cpu(source[i]);
  10558. }
  10559. /*
  10560. Ops array is stored in the following format:
  10561. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10562. */
  10563. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10564. {
  10565. const __be32 *source = (const __be32 *)_source;
  10566. struct raw_op *target = (struct raw_op *)_target;
  10567. u32 i, j, tmp;
  10568. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10569. tmp = be32_to_cpu(source[j]);
  10570. target[i].op = (tmp >> 24) & 0xff;
  10571. target[i].offset = tmp & 0xffffff;
  10572. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10573. }
  10574. }
  10575. /* IRO array is stored in the following format:
  10576. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10577. */
  10578. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10579. {
  10580. const __be32 *source = (const __be32 *)_source;
  10581. struct iro *target = (struct iro *)_target;
  10582. u32 i, j, tmp;
  10583. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10584. target[i].base = be32_to_cpu(source[j]);
  10585. j++;
  10586. tmp = be32_to_cpu(source[j]);
  10587. target[i].m1 = (tmp >> 16) & 0xffff;
  10588. target[i].m2 = tmp & 0xffff;
  10589. j++;
  10590. tmp = be32_to_cpu(source[j]);
  10591. target[i].m3 = (tmp >> 16) & 0xffff;
  10592. target[i].size = tmp & 0xffff;
  10593. j++;
  10594. }
  10595. }
  10596. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10597. {
  10598. const __be16 *source = (const __be16 *)_source;
  10599. u16 *target = (u16 *)_target;
  10600. u32 i;
  10601. for (i = 0; i < n/2; i++)
  10602. target[i] = be16_to_cpu(source[i]);
  10603. }
  10604. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10605. do { \
  10606. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10607. bp->arr = kmalloc(len, GFP_KERNEL); \
  10608. if (!bp->arr) \
  10609. goto lbl; \
  10610. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10611. (u8 *)bp->arr, len); \
  10612. } while (0)
  10613. static int bnx2x_init_firmware(struct bnx2x *bp)
  10614. {
  10615. const char *fw_file_name;
  10616. struct bnx2x_fw_file_hdr *fw_hdr;
  10617. int rc;
  10618. if (bp->firmware)
  10619. return 0;
  10620. if (CHIP_IS_E1(bp))
  10621. fw_file_name = FW_FILE_NAME_E1;
  10622. else if (CHIP_IS_E1H(bp))
  10623. fw_file_name = FW_FILE_NAME_E1H;
  10624. else if (!CHIP_IS_E1x(bp))
  10625. fw_file_name = FW_FILE_NAME_E2;
  10626. else {
  10627. BNX2X_ERR("Unsupported chip revision\n");
  10628. return -EINVAL;
  10629. }
  10630. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10631. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10632. if (rc) {
  10633. BNX2X_ERR("Can't load firmware file %s\n",
  10634. fw_file_name);
  10635. goto request_firmware_exit;
  10636. }
  10637. rc = bnx2x_check_firmware(bp);
  10638. if (rc) {
  10639. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10640. goto request_firmware_exit;
  10641. }
  10642. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10643. /* Initialize the pointers to the init arrays */
  10644. /* Blob */
  10645. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10646. /* Opcodes */
  10647. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10648. /* Offsets */
  10649. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10650. be16_to_cpu_n);
  10651. /* STORMs firmware */
  10652. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10653. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10654. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10655. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10656. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10657. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10658. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10659. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10660. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10661. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10662. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10663. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10664. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10665. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10666. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10667. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10668. /* IRO */
  10669. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10670. return 0;
  10671. iro_alloc_err:
  10672. kfree(bp->init_ops_offsets);
  10673. init_offsets_alloc_err:
  10674. kfree(bp->init_ops);
  10675. init_ops_alloc_err:
  10676. kfree(bp->init_data);
  10677. request_firmware_exit:
  10678. release_firmware(bp->firmware);
  10679. bp->firmware = NULL;
  10680. return rc;
  10681. }
  10682. static void bnx2x_release_firmware(struct bnx2x *bp)
  10683. {
  10684. kfree(bp->init_ops_offsets);
  10685. kfree(bp->init_ops);
  10686. kfree(bp->init_data);
  10687. release_firmware(bp->firmware);
  10688. bp->firmware = NULL;
  10689. }
  10690. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10691. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10692. .init_hw_cmn = bnx2x_init_hw_common,
  10693. .init_hw_port = bnx2x_init_hw_port,
  10694. .init_hw_func = bnx2x_init_hw_func,
  10695. .reset_hw_cmn = bnx2x_reset_common,
  10696. .reset_hw_port = bnx2x_reset_port,
  10697. .reset_hw_func = bnx2x_reset_func,
  10698. .gunzip_init = bnx2x_gunzip_init,
  10699. .gunzip_end = bnx2x_gunzip_end,
  10700. .init_fw = bnx2x_init_firmware,
  10701. .release_fw = bnx2x_release_firmware,
  10702. };
  10703. void bnx2x__init_func_obj(struct bnx2x *bp)
  10704. {
  10705. /* Prepare DMAE related driver resources */
  10706. bnx2x_setup_dmae(bp);
  10707. bnx2x_init_func_obj(bp, &bp->func_obj,
  10708. bnx2x_sp(bp, func_rdata),
  10709. bnx2x_sp_mapping(bp, func_rdata),
  10710. bnx2x_sp(bp, func_afex_rdata),
  10711. bnx2x_sp_mapping(bp, func_afex_rdata),
  10712. &bnx2x_func_sp_drv);
  10713. }
  10714. /* must be called after sriov-enable */
  10715. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10716. {
  10717. int cid_count = BNX2X_L2_MAX_CID(bp);
  10718. if (IS_SRIOV(bp))
  10719. cid_count += BNX2X_VF_CIDS;
  10720. if (CNIC_SUPPORT(bp))
  10721. cid_count += CNIC_CID_MAX;
  10722. return roundup(cid_count, QM_CID_ROUND);
  10723. }
  10724. /**
  10725. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10726. *
  10727. * @dev: pci device
  10728. *
  10729. */
  10730. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10731. {
  10732. int index;
  10733. u16 control = 0;
  10734. /*
  10735. * If MSI-X is not supported - return number of SBs needed to support
  10736. * one fast path queue: one FP queue + SB for CNIC
  10737. */
  10738. if (!pdev->msix_cap) {
  10739. dev_info(&pdev->dev, "no msix capability found\n");
  10740. return 1 + cnic_cnt;
  10741. }
  10742. dev_info(&pdev->dev, "msix capability found\n");
  10743. /*
  10744. * The value in the PCI configuration space is the index of the last
  10745. * entry, namely one less than the actual size of the table, which is
  10746. * exactly what we want to return from this function: number of all SBs
  10747. * without the default SB.
  10748. * For VFs there is no default SB, then we return (index+1).
  10749. */
  10750. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
  10751. index = control & PCI_MSIX_FLAGS_QSIZE;
  10752. return index;
  10753. }
  10754. static int set_max_cos_est(int chip_id)
  10755. {
  10756. switch (chip_id) {
  10757. case BCM57710:
  10758. case BCM57711:
  10759. case BCM57711E:
  10760. return BNX2X_MULTI_TX_COS_E1X;
  10761. case BCM57712:
  10762. case BCM57712_MF:
  10763. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10764. case BCM57800:
  10765. case BCM57800_MF:
  10766. case BCM57810:
  10767. case BCM57810_MF:
  10768. case BCM57840_4_10:
  10769. case BCM57840_2_20:
  10770. case BCM57840_O:
  10771. case BCM57840_MFO:
  10772. case BCM57840_MF:
  10773. case BCM57811:
  10774. case BCM57811_MF:
  10775. return BNX2X_MULTI_TX_COS_E3B0;
  10776. case BCM57712_VF:
  10777. case BCM57800_VF:
  10778. case BCM57810_VF:
  10779. case BCM57840_VF:
  10780. case BCM57811_VF:
  10781. return 1;
  10782. default:
  10783. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10784. return -ENODEV;
  10785. }
  10786. }
  10787. static int set_is_vf(int chip_id)
  10788. {
  10789. switch (chip_id) {
  10790. case BCM57712_VF:
  10791. case BCM57800_VF:
  10792. case BCM57810_VF:
  10793. case BCM57840_VF:
  10794. case BCM57811_VF:
  10795. return true;
  10796. default:
  10797. return false;
  10798. }
  10799. }
  10800. static int bnx2x_init_one(struct pci_dev *pdev,
  10801. const struct pci_device_id *ent)
  10802. {
  10803. struct net_device *dev = NULL;
  10804. struct bnx2x *bp;
  10805. enum pcie_link_width pcie_width;
  10806. enum pci_bus_speed pcie_speed;
  10807. int rc, max_non_def_sbs;
  10808. int rx_count, tx_count, rss_count, doorbell_size;
  10809. int max_cos_est;
  10810. bool is_vf;
  10811. int cnic_cnt;
  10812. /* An estimated maximum supported CoS number according to the chip
  10813. * version.
  10814. * We will try to roughly estimate the maximum number of CoSes this chip
  10815. * may support in order to minimize the memory allocated for Tx
  10816. * netdev_queue's. This number will be accurately calculated during the
  10817. * initialization of bp->max_cos based on the chip versions AND chip
  10818. * revision in the bnx2x_init_bp().
  10819. */
  10820. max_cos_est = set_max_cos_est(ent->driver_data);
  10821. if (max_cos_est < 0)
  10822. return max_cos_est;
  10823. is_vf = set_is_vf(ent->driver_data);
  10824. cnic_cnt = is_vf ? 0 : 1;
  10825. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10826. /* add another SB for VF as it has no default SB */
  10827. max_non_def_sbs += is_vf ? 1 : 0;
  10828. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10829. rss_count = max_non_def_sbs - cnic_cnt;
  10830. if (rss_count < 1)
  10831. return -EINVAL;
  10832. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10833. rx_count = rss_count + cnic_cnt;
  10834. /* Maximum number of netdev Tx queues:
  10835. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10836. */
  10837. tx_count = rss_count * max_cos_est + cnic_cnt;
  10838. /* dev zeroed in init_etherdev */
  10839. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10840. if (!dev)
  10841. return -ENOMEM;
  10842. bp = netdev_priv(dev);
  10843. bp->flags = 0;
  10844. if (is_vf)
  10845. bp->flags |= IS_VF_FLAG;
  10846. bp->igu_sb_cnt = max_non_def_sbs;
  10847. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10848. bp->msg_enable = debug;
  10849. bp->cnic_support = cnic_cnt;
  10850. bp->cnic_probe = bnx2x_cnic_probe;
  10851. pci_set_drvdata(pdev, dev);
  10852. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10853. if (rc < 0) {
  10854. free_netdev(dev);
  10855. return rc;
  10856. }
  10857. BNX2X_DEV_INFO("This is a %s function\n",
  10858. IS_PF(bp) ? "physical" : "virtual");
  10859. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10860. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10861. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10862. tx_count, rx_count);
  10863. rc = bnx2x_init_bp(bp);
  10864. if (rc)
  10865. goto init_one_exit;
  10866. /* Map doorbells here as we need the real value of bp->max_cos which
  10867. * is initialized in bnx2x_init_bp() to determine the number of
  10868. * l2 connections.
  10869. */
  10870. if (IS_VF(bp)) {
  10871. bp->doorbells = bnx2x_vf_doorbells(bp);
  10872. rc = bnx2x_vf_pci_alloc(bp);
  10873. if (rc)
  10874. goto init_one_exit;
  10875. } else {
  10876. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10877. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10878. dev_err(&bp->pdev->dev,
  10879. "Cannot map doorbells, bar size too small, aborting\n");
  10880. rc = -ENOMEM;
  10881. goto init_one_exit;
  10882. }
  10883. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10884. doorbell_size);
  10885. }
  10886. if (!bp->doorbells) {
  10887. dev_err(&bp->pdev->dev,
  10888. "Cannot map doorbell space, aborting\n");
  10889. rc = -ENOMEM;
  10890. goto init_one_exit;
  10891. }
  10892. if (IS_VF(bp)) {
  10893. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10894. if (rc)
  10895. goto init_one_exit;
  10896. }
  10897. /* Enable SRIOV if capability found in configuration space */
  10898. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10899. if (rc)
  10900. goto init_one_exit;
  10901. /* calc qm_cid_count */
  10902. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10903. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10904. /* disable FCOE L2 queue for E1x*/
  10905. if (CHIP_IS_E1x(bp))
  10906. bp->flags |= NO_FCOE_FLAG;
  10907. /* Set bp->num_queues for MSI-X mode*/
  10908. bnx2x_set_num_queues(bp);
  10909. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10910. * needed.
  10911. */
  10912. rc = bnx2x_set_int_mode(bp);
  10913. if (rc) {
  10914. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10915. goto init_one_exit;
  10916. }
  10917. BNX2X_DEV_INFO("set interrupts successfully\n");
  10918. /* register the net device */
  10919. rc = register_netdev(dev);
  10920. if (rc) {
  10921. dev_err(&pdev->dev, "Cannot register net device\n");
  10922. goto init_one_exit;
  10923. }
  10924. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10925. if (!NO_FCOE(bp)) {
  10926. /* Add storage MAC address */
  10927. rtnl_lock();
  10928. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10929. rtnl_unlock();
  10930. }
  10931. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  10932. pcie_speed == PCI_SPEED_UNKNOWN ||
  10933. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  10934. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  10935. else
  10936. BNX2X_DEV_INFO(
  10937. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10938. board_info[ent->driver_data].name,
  10939. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10940. pcie_width,
  10941. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  10942. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  10943. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  10944. "Unknown",
  10945. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10946. return 0;
  10947. init_one_exit:
  10948. bnx2x_disable_pcie_error_reporting(bp);
  10949. if (bp->regview)
  10950. iounmap(bp->regview);
  10951. if (IS_PF(bp) && bp->doorbells)
  10952. iounmap(bp->doorbells);
  10953. free_netdev(dev);
  10954. if (atomic_read(&pdev->enable_cnt) == 1)
  10955. pci_release_regions(pdev);
  10956. pci_disable_device(pdev);
  10957. return rc;
  10958. }
  10959. static void __bnx2x_remove(struct pci_dev *pdev,
  10960. struct net_device *dev,
  10961. struct bnx2x *bp,
  10962. bool remove_netdev)
  10963. {
  10964. /* Delete storage MAC address */
  10965. if (!NO_FCOE(bp)) {
  10966. rtnl_lock();
  10967. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10968. rtnl_unlock();
  10969. }
  10970. #ifdef BCM_DCBNL
  10971. /* Delete app tlvs from dcbnl */
  10972. bnx2x_dcbnl_update_applist(bp, true);
  10973. #endif
  10974. if (IS_PF(bp) &&
  10975. !BP_NOMCP(bp) &&
  10976. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  10977. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  10978. /* Close the interface - either directly or implicitly */
  10979. if (remove_netdev) {
  10980. unregister_netdev(dev);
  10981. } else {
  10982. rtnl_lock();
  10983. dev_close(dev);
  10984. rtnl_unlock();
  10985. }
  10986. bnx2x_iov_remove_one(bp);
  10987. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10988. if (IS_PF(bp))
  10989. bnx2x_set_power_state(bp, PCI_D0);
  10990. /* Disable MSI/MSI-X */
  10991. bnx2x_disable_msi(bp);
  10992. /* Power off */
  10993. if (IS_PF(bp))
  10994. bnx2x_set_power_state(bp, PCI_D3hot);
  10995. /* Make sure RESET task is not scheduled before continuing */
  10996. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10997. /* send message via vfpf channel to release the resources of this vf */
  10998. if (IS_VF(bp))
  10999. bnx2x_vfpf_release(bp);
  11000. /* Assumes no further PCIe PM changes will occur */
  11001. if (system_state == SYSTEM_POWER_OFF) {
  11002. pci_wake_from_d3(pdev, bp->wol);
  11003. pci_set_power_state(pdev, PCI_D3hot);
  11004. }
  11005. bnx2x_disable_pcie_error_reporting(bp);
  11006. if (remove_netdev) {
  11007. if (bp->regview)
  11008. iounmap(bp->regview);
  11009. /* For vfs, doorbells are part of the regview and were unmapped
  11010. * along with it. FW is only loaded by PF.
  11011. */
  11012. if (IS_PF(bp)) {
  11013. if (bp->doorbells)
  11014. iounmap(bp->doorbells);
  11015. bnx2x_release_firmware(bp);
  11016. }
  11017. bnx2x_free_mem_bp(bp);
  11018. free_netdev(dev);
  11019. if (atomic_read(&pdev->enable_cnt) == 1)
  11020. pci_release_regions(pdev);
  11021. pci_disable_device(pdev);
  11022. }
  11023. }
  11024. static void bnx2x_remove_one(struct pci_dev *pdev)
  11025. {
  11026. struct net_device *dev = pci_get_drvdata(pdev);
  11027. struct bnx2x *bp;
  11028. if (!dev) {
  11029. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11030. return;
  11031. }
  11032. bp = netdev_priv(dev);
  11033. __bnx2x_remove(pdev, dev, bp, true);
  11034. }
  11035. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11036. {
  11037. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11038. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11039. if (CNIC_LOADED(bp))
  11040. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11041. /* Stop Tx */
  11042. bnx2x_tx_disable(bp);
  11043. /* Delete all NAPI objects */
  11044. bnx2x_del_all_napi(bp);
  11045. if (CNIC_LOADED(bp))
  11046. bnx2x_del_all_napi_cnic(bp);
  11047. netdev_reset_tc(bp->dev);
  11048. del_timer_sync(&bp->timer);
  11049. cancel_delayed_work(&bp->sp_task);
  11050. cancel_delayed_work(&bp->period_task);
  11051. spin_lock_bh(&bp->stats_lock);
  11052. bp->stats_state = STATS_STATE_DISABLED;
  11053. spin_unlock_bh(&bp->stats_lock);
  11054. bnx2x_save_statistics(bp);
  11055. netif_carrier_off(bp->dev);
  11056. return 0;
  11057. }
  11058. /**
  11059. * bnx2x_io_error_detected - called when PCI error is detected
  11060. * @pdev: Pointer to PCI device
  11061. * @state: The current pci connection state
  11062. *
  11063. * This function is called after a PCI bus error affecting
  11064. * this device has been detected.
  11065. */
  11066. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11067. pci_channel_state_t state)
  11068. {
  11069. struct net_device *dev = pci_get_drvdata(pdev);
  11070. struct bnx2x *bp = netdev_priv(dev);
  11071. rtnl_lock();
  11072. BNX2X_ERR("IO error detected\n");
  11073. netif_device_detach(dev);
  11074. if (state == pci_channel_io_perm_failure) {
  11075. rtnl_unlock();
  11076. return PCI_ERS_RESULT_DISCONNECT;
  11077. }
  11078. if (netif_running(dev))
  11079. bnx2x_eeh_nic_unload(bp);
  11080. bnx2x_prev_path_mark_eeh(bp);
  11081. pci_disable_device(pdev);
  11082. rtnl_unlock();
  11083. /* Request a slot reset */
  11084. return PCI_ERS_RESULT_NEED_RESET;
  11085. }
  11086. /**
  11087. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11088. * @pdev: Pointer to PCI device
  11089. *
  11090. * Restart the card from scratch, as if from a cold-boot.
  11091. */
  11092. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11093. {
  11094. struct net_device *dev = pci_get_drvdata(pdev);
  11095. struct bnx2x *bp = netdev_priv(dev);
  11096. int i;
  11097. rtnl_lock();
  11098. BNX2X_ERR("IO slot reset initializing...\n");
  11099. if (pci_enable_device(pdev)) {
  11100. dev_err(&pdev->dev,
  11101. "Cannot re-enable PCI device after reset\n");
  11102. rtnl_unlock();
  11103. return PCI_ERS_RESULT_DISCONNECT;
  11104. }
  11105. pci_set_master(pdev);
  11106. pci_restore_state(pdev);
  11107. pci_save_state(pdev);
  11108. if (netif_running(dev))
  11109. bnx2x_set_power_state(bp, PCI_D0);
  11110. if (netif_running(dev)) {
  11111. BNX2X_ERR("IO slot reset --> driver unload\n");
  11112. /* MCP should have been reset; Need to wait for validity */
  11113. bnx2x_init_shmem(bp);
  11114. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11115. u32 v;
  11116. v = SHMEM2_RD(bp,
  11117. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11118. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11119. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11120. }
  11121. bnx2x_drain_tx_queues(bp);
  11122. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11123. bnx2x_netif_stop(bp, 1);
  11124. bnx2x_free_irq(bp);
  11125. /* Report UNLOAD_DONE to MCP */
  11126. bnx2x_send_unload_done(bp, true);
  11127. bp->sp_state = 0;
  11128. bp->port.pmf = 0;
  11129. bnx2x_prev_unload(bp);
  11130. /* We should have reseted the engine, so It's fair to
  11131. * assume the FW will no longer write to the bnx2x driver.
  11132. */
  11133. bnx2x_squeeze_objects(bp);
  11134. bnx2x_free_skbs(bp);
  11135. for_each_rx_queue(bp, i)
  11136. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11137. bnx2x_free_fp_mem(bp);
  11138. bnx2x_free_mem(bp);
  11139. bp->state = BNX2X_STATE_CLOSED;
  11140. }
  11141. rtnl_unlock();
  11142. /* If AER, perform cleanup of the PCIe registers */
  11143. if (bp->flags & AER_ENABLED) {
  11144. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11145. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11146. else
  11147. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11148. }
  11149. return PCI_ERS_RESULT_RECOVERED;
  11150. }
  11151. /**
  11152. * bnx2x_io_resume - called when traffic can start flowing again
  11153. * @pdev: Pointer to PCI device
  11154. *
  11155. * This callback is called when the error recovery driver tells us that
  11156. * its OK to resume normal operation.
  11157. */
  11158. static void bnx2x_io_resume(struct pci_dev *pdev)
  11159. {
  11160. struct net_device *dev = pci_get_drvdata(pdev);
  11161. struct bnx2x *bp = netdev_priv(dev);
  11162. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11163. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11164. return;
  11165. }
  11166. rtnl_lock();
  11167. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11168. DRV_MSG_SEQ_NUMBER_MASK;
  11169. if (netif_running(dev))
  11170. bnx2x_nic_load(bp, LOAD_NORMAL);
  11171. netif_device_attach(dev);
  11172. rtnl_unlock();
  11173. }
  11174. static const struct pci_error_handlers bnx2x_err_handler = {
  11175. .error_detected = bnx2x_io_error_detected,
  11176. .slot_reset = bnx2x_io_slot_reset,
  11177. .resume = bnx2x_io_resume,
  11178. };
  11179. static void bnx2x_shutdown(struct pci_dev *pdev)
  11180. {
  11181. struct net_device *dev = pci_get_drvdata(pdev);
  11182. struct bnx2x *bp;
  11183. if (!dev)
  11184. return;
  11185. bp = netdev_priv(dev);
  11186. if (!bp)
  11187. return;
  11188. rtnl_lock();
  11189. netif_device_detach(dev);
  11190. rtnl_unlock();
  11191. /* Don't remove the netdevice, as there are scenarios which will cause
  11192. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11193. * rootfs is mounted from SAN.
  11194. */
  11195. __bnx2x_remove(pdev, dev, bp, false);
  11196. }
  11197. static struct pci_driver bnx2x_pci_driver = {
  11198. .name = DRV_MODULE_NAME,
  11199. .id_table = bnx2x_pci_tbl,
  11200. .probe = bnx2x_init_one,
  11201. .remove = bnx2x_remove_one,
  11202. .suspend = bnx2x_suspend,
  11203. .resume = bnx2x_resume,
  11204. .err_handler = &bnx2x_err_handler,
  11205. #ifdef CONFIG_BNX2X_SRIOV
  11206. .sriov_configure = bnx2x_sriov_configure,
  11207. #endif
  11208. .shutdown = bnx2x_shutdown,
  11209. };
  11210. static int __init bnx2x_init(void)
  11211. {
  11212. int ret;
  11213. pr_info("%s", version);
  11214. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11215. if (bnx2x_wq == NULL) {
  11216. pr_err("Cannot create workqueue\n");
  11217. return -ENOMEM;
  11218. }
  11219. ret = pci_register_driver(&bnx2x_pci_driver);
  11220. if (ret) {
  11221. pr_err("Cannot register driver\n");
  11222. destroy_workqueue(bnx2x_wq);
  11223. }
  11224. return ret;
  11225. }
  11226. static void __exit bnx2x_cleanup(void)
  11227. {
  11228. struct list_head *pos, *q;
  11229. pci_unregister_driver(&bnx2x_pci_driver);
  11230. destroy_workqueue(bnx2x_wq);
  11231. /* Free globally allocated resources */
  11232. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11233. struct bnx2x_prev_path_list *tmp =
  11234. list_entry(pos, struct bnx2x_prev_path_list, list);
  11235. list_del(pos);
  11236. kfree(tmp);
  11237. }
  11238. }
  11239. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11240. {
  11241. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11242. }
  11243. module_init(bnx2x_init);
  11244. module_exit(bnx2x_cleanup);
  11245. /**
  11246. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11247. *
  11248. * @bp: driver handle
  11249. * @set: set or clear the CAM entry
  11250. *
  11251. * This function will wait until the ramrod completion returns.
  11252. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11253. */
  11254. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11255. {
  11256. unsigned long ramrod_flags = 0;
  11257. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11258. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11259. &bp->iscsi_l2_mac_obj, true,
  11260. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11261. }
  11262. /* count denotes the number of new completions we have seen */
  11263. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11264. {
  11265. struct eth_spe *spe;
  11266. int cxt_index, cxt_offset;
  11267. #ifdef BNX2X_STOP_ON_ERROR
  11268. if (unlikely(bp->panic))
  11269. return;
  11270. #endif
  11271. spin_lock_bh(&bp->spq_lock);
  11272. BUG_ON(bp->cnic_spq_pending < count);
  11273. bp->cnic_spq_pending -= count;
  11274. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11275. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11276. & SPE_HDR_CONN_TYPE) >>
  11277. SPE_HDR_CONN_TYPE_SHIFT;
  11278. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11279. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11280. /* Set validation for iSCSI L2 client before sending SETUP
  11281. * ramrod
  11282. */
  11283. if (type == ETH_CONNECTION_TYPE) {
  11284. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11285. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11286. ILT_PAGE_CIDS;
  11287. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11288. (cxt_index * ILT_PAGE_CIDS);
  11289. bnx2x_set_ctx_validation(bp,
  11290. &bp->context[cxt_index].
  11291. vcxt[cxt_offset].eth,
  11292. BNX2X_ISCSI_ETH_CID(bp));
  11293. }
  11294. }
  11295. /*
  11296. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11297. * and in the air. We also check that number of outstanding
  11298. * COMMON ramrods is not more than the EQ and SPQ can
  11299. * accommodate.
  11300. */
  11301. if (type == ETH_CONNECTION_TYPE) {
  11302. if (!atomic_read(&bp->cq_spq_left))
  11303. break;
  11304. else
  11305. atomic_dec(&bp->cq_spq_left);
  11306. } else if (type == NONE_CONNECTION_TYPE) {
  11307. if (!atomic_read(&bp->eq_spq_left))
  11308. break;
  11309. else
  11310. atomic_dec(&bp->eq_spq_left);
  11311. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11312. (type == FCOE_CONNECTION_TYPE)) {
  11313. if (bp->cnic_spq_pending >=
  11314. bp->cnic_eth_dev.max_kwqe_pending)
  11315. break;
  11316. else
  11317. bp->cnic_spq_pending++;
  11318. } else {
  11319. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11320. bnx2x_panic();
  11321. break;
  11322. }
  11323. spe = bnx2x_sp_get_next(bp);
  11324. *spe = *bp->cnic_kwq_cons;
  11325. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11326. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11327. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11328. bp->cnic_kwq_cons = bp->cnic_kwq;
  11329. else
  11330. bp->cnic_kwq_cons++;
  11331. }
  11332. bnx2x_sp_prod_update(bp);
  11333. spin_unlock_bh(&bp->spq_lock);
  11334. }
  11335. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11336. struct kwqe_16 *kwqes[], u32 count)
  11337. {
  11338. struct bnx2x *bp = netdev_priv(dev);
  11339. int i;
  11340. #ifdef BNX2X_STOP_ON_ERROR
  11341. if (unlikely(bp->panic)) {
  11342. BNX2X_ERR("Can't post to SP queue while panic\n");
  11343. return -EIO;
  11344. }
  11345. #endif
  11346. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11347. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11348. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11349. return -EAGAIN;
  11350. }
  11351. spin_lock_bh(&bp->spq_lock);
  11352. for (i = 0; i < count; i++) {
  11353. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11354. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11355. break;
  11356. *bp->cnic_kwq_prod = *spe;
  11357. bp->cnic_kwq_pending++;
  11358. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11359. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11360. spe->data.update_data_addr.hi,
  11361. spe->data.update_data_addr.lo,
  11362. bp->cnic_kwq_pending);
  11363. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11364. bp->cnic_kwq_prod = bp->cnic_kwq;
  11365. else
  11366. bp->cnic_kwq_prod++;
  11367. }
  11368. spin_unlock_bh(&bp->spq_lock);
  11369. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11370. bnx2x_cnic_sp_post(bp, 0);
  11371. return i;
  11372. }
  11373. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11374. {
  11375. struct cnic_ops *c_ops;
  11376. int rc = 0;
  11377. mutex_lock(&bp->cnic_mutex);
  11378. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11379. lockdep_is_held(&bp->cnic_mutex));
  11380. if (c_ops)
  11381. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11382. mutex_unlock(&bp->cnic_mutex);
  11383. return rc;
  11384. }
  11385. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11386. {
  11387. struct cnic_ops *c_ops;
  11388. int rc = 0;
  11389. rcu_read_lock();
  11390. c_ops = rcu_dereference(bp->cnic_ops);
  11391. if (c_ops)
  11392. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11393. rcu_read_unlock();
  11394. return rc;
  11395. }
  11396. /*
  11397. * for commands that have no data
  11398. */
  11399. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11400. {
  11401. struct cnic_ctl_info ctl = {0};
  11402. ctl.cmd = cmd;
  11403. return bnx2x_cnic_ctl_send(bp, &ctl);
  11404. }
  11405. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11406. {
  11407. struct cnic_ctl_info ctl = {0};
  11408. /* first we tell CNIC and only then we count this as a completion */
  11409. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11410. ctl.data.comp.cid = cid;
  11411. ctl.data.comp.error = err;
  11412. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11413. bnx2x_cnic_sp_post(bp, 0);
  11414. }
  11415. /* Called with netif_addr_lock_bh() taken.
  11416. * Sets an rx_mode config for an iSCSI ETH client.
  11417. * Doesn't block.
  11418. * Completion should be checked outside.
  11419. */
  11420. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11421. {
  11422. unsigned long accept_flags = 0, ramrod_flags = 0;
  11423. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11424. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11425. if (start) {
  11426. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11427. * because it's the only way for UIO Queue to accept
  11428. * multicasts (in non-promiscuous mode only one Queue per
  11429. * function will receive multicast packets (leading in our
  11430. * case).
  11431. */
  11432. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11433. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11434. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11435. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11436. /* Clear STOP_PENDING bit if START is requested */
  11437. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11438. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11439. } else
  11440. /* Clear START_PENDING bit if STOP is requested */
  11441. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11442. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11443. set_bit(sched_state, &bp->sp_state);
  11444. else {
  11445. __set_bit(RAMROD_RX, &ramrod_flags);
  11446. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11447. ramrod_flags);
  11448. }
  11449. }
  11450. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11451. {
  11452. struct bnx2x *bp = netdev_priv(dev);
  11453. int rc = 0;
  11454. switch (ctl->cmd) {
  11455. case DRV_CTL_CTXTBL_WR_CMD: {
  11456. u32 index = ctl->data.io.offset;
  11457. dma_addr_t addr = ctl->data.io.dma_addr;
  11458. bnx2x_ilt_wr(bp, index, addr);
  11459. break;
  11460. }
  11461. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11462. int count = ctl->data.credit.credit_count;
  11463. bnx2x_cnic_sp_post(bp, count);
  11464. break;
  11465. }
  11466. /* rtnl_lock is held. */
  11467. case DRV_CTL_START_L2_CMD: {
  11468. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11469. unsigned long sp_bits = 0;
  11470. /* Configure the iSCSI classification object */
  11471. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11472. cp->iscsi_l2_client_id,
  11473. cp->iscsi_l2_cid, BP_FUNC(bp),
  11474. bnx2x_sp(bp, mac_rdata),
  11475. bnx2x_sp_mapping(bp, mac_rdata),
  11476. BNX2X_FILTER_MAC_PENDING,
  11477. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11478. &bp->macs_pool);
  11479. /* Set iSCSI MAC address */
  11480. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11481. if (rc)
  11482. break;
  11483. mmiowb();
  11484. barrier();
  11485. /* Start accepting on iSCSI L2 ring */
  11486. netif_addr_lock_bh(dev);
  11487. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11488. netif_addr_unlock_bh(dev);
  11489. /* bits to wait on */
  11490. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11491. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11492. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11493. BNX2X_ERR("rx_mode completion timed out!\n");
  11494. break;
  11495. }
  11496. /* rtnl_lock is held. */
  11497. case DRV_CTL_STOP_L2_CMD: {
  11498. unsigned long sp_bits = 0;
  11499. /* Stop accepting on iSCSI L2 ring */
  11500. netif_addr_lock_bh(dev);
  11501. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11502. netif_addr_unlock_bh(dev);
  11503. /* bits to wait on */
  11504. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11505. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11506. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11507. BNX2X_ERR("rx_mode completion timed out!\n");
  11508. mmiowb();
  11509. barrier();
  11510. /* Unset iSCSI L2 MAC */
  11511. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11512. BNX2X_ISCSI_ETH_MAC, true);
  11513. break;
  11514. }
  11515. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11516. int count = ctl->data.credit.credit_count;
  11517. smp_mb__before_atomic_inc();
  11518. atomic_add(count, &bp->cq_spq_left);
  11519. smp_mb__after_atomic_inc();
  11520. break;
  11521. }
  11522. case DRV_CTL_ULP_REGISTER_CMD: {
  11523. int ulp_type = ctl->data.register_data.ulp_type;
  11524. if (CHIP_IS_E3(bp)) {
  11525. int idx = BP_FW_MB_IDX(bp);
  11526. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11527. int path = BP_PATH(bp);
  11528. int port = BP_PORT(bp);
  11529. int i;
  11530. u32 scratch_offset;
  11531. u32 *host_addr;
  11532. /* first write capability to shmem2 */
  11533. if (ulp_type == CNIC_ULP_ISCSI)
  11534. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11535. else if (ulp_type == CNIC_ULP_FCOE)
  11536. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11537. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11538. if ((ulp_type != CNIC_ULP_FCOE) ||
  11539. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11540. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11541. break;
  11542. /* if reached here - should write fcoe capabilities */
  11543. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11544. if (!scratch_offset)
  11545. break;
  11546. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11547. fcoe_features[path][port]);
  11548. host_addr = (u32 *) &(ctl->data.register_data.
  11549. fcoe_features);
  11550. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11551. i += 4)
  11552. REG_WR(bp, scratch_offset + i,
  11553. *(host_addr + i/4));
  11554. }
  11555. break;
  11556. }
  11557. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11558. int ulp_type = ctl->data.ulp_type;
  11559. if (CHIP_IS_E3(bp)) {
  11560. int idx = BP_FW_MB_IDX(bp);
  11561. u32 cap;
  11562. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11563. if (ulp_type == CNIC_ULP_ISCSI)
  11564. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11565. else if (ulp_type == CNIC_ULP_FCOE)
  11566. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11567. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11568. }
  11569. break;
  11570. }
  11571. default:
  11572. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11573. rc = -EINVAL;
  11574. }
  11575. return rc;
  11576. }
  11577. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11578. {
  11579. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11580. if (bp->flags & USING_MSIX_FLAG) {
  11581. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11582. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11583. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11584. } else {
  11585. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11586. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11587. }
  11588. if (!CHIP_IS_E1x(bp))
  11589. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11590. else
  11591. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11592. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11593. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11594. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11595. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11596. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11597. cp->num_irq = 2;
  11598. }
  11599. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11600. {
  11601. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11602. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11603. bnx2x_cid_ilt_lines(bp);
  11604. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11605. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11606. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11607. 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",
  11608. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11609. cp->iscsi_l2_cid);
  11610. if (NO_ISCSI_OOO(bp))
  11611. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11612. }
  11613. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11614. void *data)
  11615. {
  11616. struct bnx2x *bp = netdev_priv(dev);
  11617. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11618. int rc;
  11619. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11620. if (ops == NULL) {
  11621. BNX2X_ERR("NULL ops received\n");
  11622. return -EINVAL;
  11623. }
  11624. if (!CNIC_SUPPORT(bp)) {
  11625. BNX2X_ERR("Can't register CNIC when not supported\n");
  11626. return -EOPNOTSUPP;
  11627. }
  11628. if (!CNIC_LOADED(bp)) {
  11629. rc = bnx2x_load_cnic(bp);
  11630. if (rc) {
  11631. BNX2X_ERR("CNIC-related load failed\n");
  11632. return rc;
  11633. }
  11634. }
  11635. bp->cnic_enabled = true;
  11636. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11637. if (!bp->cnic_kwq)
  11638. return -ENOMEM;
  11639. bp->cnic_kwq_cons = bp->cnic_kwq;
  11640. bp->cnic_kwq_prod = bp->cnic_kwq;
  11641. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11642. bp->cnic_spq_pending = 0;
  11643. bp->cnic_kwq_pending = 0;
  11644. bp->cnic_data = data;
  11645. cp->num_irq = 0;
  11646. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11647. cp->iro_arr = bp->iro_arr;
  11648. bnx2x_setup_cnic_irq_info(bp);
  11649. rcu_assign_pointer(bp->cnic_ops, ops);
  11650. return 0;
  11651. }
  11652. static int bnx2x_unregister_cnic(struct net_device *dev)
  11653. {
  11654. struct bnx2x *bp = netdev_priv(dev);
  11655. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11656. mutex_lock(&bp->cnic_mutex);
  11657. cp->drv_state = 0;
  11658. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11659. mutex_unlock(&bp->cnic_mutex);
  11660. synchronize_rcu();
  11661. bp->cnic_enabled = false;
  11662. kfree(bp->cnic_kwq);
  11663. bp->cnic_kwq = NULL;
  11664. return 0;
  11665. }
  11666. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11667. {
  11668. struct bnx2x *bp = netdev_priv(dev);
  11669. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11670. /* If both iSCSI and FCoE are disabled - return NULL in
  11671. * order to indicate CNIC that it should not try to work
  11672. * with this device.
  11673. */
  11674. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11675. return NULL;
  11676. cp->drv_owner = THIS_MODULE;
  11677. cp->chip_id = CHIP_ID(bp);
  11678. cp->pdev = bp->pdev;
  11679. cp->io_base = bp->regview;
  11680. cp->io_base2 = bp->doorbells;
  11681. cp->max_kwqe_pending = 8;
  11682. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11683. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11684. bnx2x_cid_ilt_lines(bp);
  11685. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11686. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11687. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11688. cp->drv_ctl = bnx2x_drv_ctl;
  11689. cp->drv_register_cnic = bnx2x_register_cnic;
  11690. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11691. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11692. cp->iscsi_l2_client_id =
  11693. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11694. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11695. if (NO_ISCSI_OOO(bp))
  11696. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11697. if (NO_ISCSI(bp))
  11698. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11699. if (NO_FCOE(bp))
  11700. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11701. BNX2X_DEV_INFO(
  11702. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11703. cp->ctx_blk_size,
  11704. cp->ctx_tbl_offset,
  11705. cp->ctx_tbl_len,
  11706. cp->starting_cid);
  11707. return cp;
  11708. }
  11709. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11710. {
  11711. struct bnx2x *bp = fp->bp;
  11712. u32 offset = BAR_USTRORM_INTMEM;
  11713. if (IS_VF(bp))
  11714. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11715. else if (!CHIP_IS_E1x(bp))
  11716. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11717. else
  11718. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11719. return offset;
  11720. }
  11721. /* called only on E1H or E2.
  11722. * When pretending to be PF, the pretend value is the function number 0...7
  11723. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11724. * combination
  11725. */
  11726. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11727. {
  11728. u32 pretend_reg;
  11729. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11730. return -1;
  11731. /* get my own pretend register */
  11732. pretend_reg = bnx2x_get_pretend_reg(bp);
  11733. REG_WR(bp, pretend_reg, pretend_func_val);
  11734. REG_RD(bp, pretend_reg);
  11735. return 0;
  11736. }