bnx2x_main.c 337 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 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/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. /* Time in jiffies before concluding the transmitter is hung */
  73. #define TX_TIMEOUT (5*HZ)
  74. static char version[] __devinitdata =
  75. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  76. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  77. MODULE_AUTHOR("Eliezer Tamir");
  78. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  79. "BCM57710/57711/57711E/"
  80. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  81. "57840/57840_MF Driver");
  82. MODULE_LICENSE("GPL");
  83. MODULE_VERSION(DRV_MODULE_VERSION);
  84. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  87. int num_queues;
  88. module_param(num_queues, int, 0);
  89. MODULE_PARM_DESC(num_queues,
  90. " Set number of queues (default is as a number of CPUs)");
  91. static int disable_tpa;
  92. module_param(disable_tpa, int, 0);
  93. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  94. #define INT_MODE_INTx 1
  95. #define INT_MODE_MSI 2
  96. static int int_mode;
  97. module_param(int_mode, int, 0);
  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, 0);
  102. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  103. static int mrrs = -1;
  104. module_param(mrrs, int, 0);
  105. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  106. static int debug;
  107. module_param(debug, int, 0);
  108. MODULE_PARM_DESC(debug, " Default debug msglevel");
  109. struct workqueue_struct *bnx2x_wq;
  110. enum bnx2x_board_type {
  111. BCM57710 = 0,
  112. BCM57711,
  113. BCM57711E,
  114. BCM57712,
  115. BCM57712_MF,
  116. BCM57800,
  117. BCM57800_MF,
  118. BCM57810,
  119. BCM57810_MF,
  120. BCM57840,
  121. BCM57840_MF,
  122. BCM57811,
  123. BCM57811_MF
  124. };
  125. /* indexed by board_type, above */
  126. static struct {
  127. char *name;
  128. } board_info[] __devinitdata = {
  129. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  130. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  131. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  132. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  133. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  134. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  135. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  136. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  140. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  141. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  142. };
  143. #ifndef PCI_DEVICE_ID_NX2_57710
  144. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  145. #endif
  146. #ifndef PCI_DEVICE_ID_NX2_57711
  147. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  148. #endif
  149. #ifndef PCI_DEVICE_ID_NX2_57711E
  150. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  151. #endif
  152. #ifndef PCI_DEVICE_ID_NX2_57712
  153. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  154. #endif
  155. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  156. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  157. #endif
  158. #ifndef PCI_DEVICE_ID_NX2_57800
  159. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  160. #endif
  161. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  162. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  163. #endif
  164. #ifndef PCI_DEVICE_ID_NX2_57810
  165. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  166. #endif
  167. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  168. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  169. #endif
  170. #ifndef PCI_DEVICE_ID_NX2_57840
  171. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  172. #endif
  173. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  174. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  175. #endif
  176. #ifndef PCI_DEVICE_ID_NX2_57811
  177. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  178. #endif
  179. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  180. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  181. #endif
  182. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  183. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  184. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  185. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  186. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  189. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  190. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  191. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  192. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  193. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  194. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  195. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  196. { 0 }
  197. };
  198. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  199. /* Global resources for unloading a previously loaded device */
  200. #define BNX2X_PREV_WAIT_NEEDED 1
  201. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  202. static LIST_HEAD(bnx2x_prev_list);
  203. /****************************************************************************
  204. * General service functions
  205. ****************************************************************************/
  206. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  207. u32 addr, dma_addr_t mapping)
  208. {
  209. REG_WR(bp, addr, U64_LO(mapping));
  210. REG_WR(bp, addr + 4, U64_HI(mapping));
  211. }
  212. static void storm_memset_spq_addr(struct bnx2x *bp,
  213. dma_addr_t mapping, u16 abs_fid)
  214. {
  215. u32 addr = XSEM_REG_FAST_MEMORY +
  216. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  217. __storm_memset_dma_mapping(bp, addr, mapping);
  218. }
  219. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  220. u16 pf_id)
  221. {
  222. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  223. pf_id);
  224. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  225. pf_id);
  226. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  227. pf_id);
  228. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  229. pf_id);
  230. }
  231. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  232. u8 enable)
  233. {
  234. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  235. enable);
  236. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  237. enable);
  238. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  239. enable);
  240. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  241. enable);
  242. }
  243. static void storm_memset_eq_data(struct bnx2x *bp,
  244. struct event_ring_data *eq_data,
  245. u16 pfid)
  246. {
  247. size_t size = sizeof(struct event_ring_data);
  248. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  249. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  250. }
  251. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  252. u16 pfid)
  253. {
  254. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  255. REG_WR16(bp, addr, eq_prod);
  256. }
  257. /* used only at init
  258. * locking is done by mcp
  259. */
  260. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  261. {
  262. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  263. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  264. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  265. PCICFG_VENDOR_ID_OFFSET);
  266. }
  267. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  268. {
  269. u32 val;
  270. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  271. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  272. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  273. PCICFG_VENDOR_ID_OFFSET);
  274. return val;
  275. }
  276. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  277. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  278. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  279. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  280. #define DMAE_DP_DST_NONE "dst_addr [none]"
  281. /* copy command into DMAE command memory and set DMAE command go */
  282. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  283. {
  284. u32 cmd_offset;
  285. int i;
  286. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  287. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  288. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  289. }
  290. REG_WR(bp, dmae_reg_go_c[idx], 1);
  291. }
  292. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  293. {
  294. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  295. DMAE_CMD_C_ENABLE);
  296. }
  297. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  298. {
  299. return opcode & ~DMAE_CMD_SRC_RESET;
  300. }
  301. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  302. bool with_comp, u8 comp_type)
  303. {
  304. u32 opcode = 0;
  305. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  306. (dst_type << DMAE_COMMAND_DST_SHIFT));
  307. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  308. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  309. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  310. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  311. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  312. #ifdef __BIG_ENDIAN
  313. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  314. #else
  315. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  316. #endif
  317. if (with_comp)
  318. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  319. return opcode;
  320. }
  321. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  322. struct dmae_command *dmae,
  323. u8 src_type, u8 dst_type)
  324. {
  325. memset(dmae, 0, sizeof(struct dmae_command));
  326. /* set the opcode */
  327. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  328. true, DMAE_COMP_PCI);
  329. /* fill in the completion parameters */
  330. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  331. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  332. dmae->comp_val = DMAE_COMP_VAL;
  333. }
  334. /* issue a dmae command over the init-channel and wailt for completion */
  335. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  336. struct dmae_command *dmae)
  337. {
  338. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  339. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  340. int rc = 0;
  341. /*
  342. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  343. * as long as this code is called both from syscall context and
  344. * from ndo_set_rx_mode() flow that may be called from BH.
  345. */
  346. spin_lock_bh(&bp->dmae_lock);
  347. /* reset completion */
  348. *wb_comp = 0;
  349. /* post the command on the channel used for initializations */
  350. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  351. /* wait for completion */
  352. udelay(5);
  353. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  354. if (!cnt ||
  355. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  356. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  357. BNX2X_ERR("DMAE timeout!\n");
  358. rc = DMAE_TIMEOUT;
  359. goto unlock;
  360. }
  361. cnt--;
  362. udelay(50);
  363. }
  364. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  365. BNX2X_ERR("DMAE PCI error!\n");
  366. rc = DMAE_PCI_ERROR;
  367. }
  368. unlock:
  369. spin_unlock_bh(&bp->dmae_lock);
  370. return rc;
  371. }
  372. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  373. u32 len32)
  374. {
  375. struct dmae_command dmae;
  376. if (!bp->dmae_ready) {
  377. u32 *data = bnx2x_sp(bp, wb_data[0]);
  378. if (CHIP_IS_E1(bp))
  379. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  380. else
  381. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  382. return;
  383. }
  384. /* set opcode and fixed command fields */
  385. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  386. /* fill in addresses and len */
  387. dmae.src_addr_lo = U64_LO(dma_addr);
  388. dmae.src_addr_hi = U64_HI(dma_addr);
  389. dmae.dst_addr_lo = dst_addr >> 2;
  390. dmae.dst_addr_hi = 0;
  391. dmae.len = len32;
  392. /* issue the command and wait for completion */
  393. bnx2x_issue_dmae_with_comp(bp, &dmae);
  394. }
  395. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  396. {
  397. struct dmae_command dmae;
  398. if (!bp->dmae_ready) {
  399. u32 *data = bnx2x_sp(bp, wb_data[0]);
  400. int i;
  401. if (CHIP_IS_E1(bp))
  402. for (i = 0; i < len32; i++)
  403. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  404. else
  405. for (i = 0; i < len32; i++)
  406. data[i] = REG_RD(bp, src_addr + i*4);
  407. return;
  408. }
  409. /* set opcode and fixed command fields */
  410. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  411. /* fill in addresses and len */
  412. dmae.src_addr_lo = src_addr >> 2;
  413. dmae.src_addr_hi = 0;
  414. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  415. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  416. dmae.len = len32;
  417. /* issue the command and wait for completion */
  418. bnx2x_issue_dmae_with_comp(bp, &dmae);
  419. }
  420. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  421. u32 addr, u32 len)
  422. {
  423. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  424. int offset = 0;
  425. while (len > dmae_wr_max) {
  426. bnx2x_write_dmae(bp, phys_addr + offset,
  427. addr + offset, dmae_wr_max);
  428. offset += dmae_wr_max * 4;
  429. len -= dmae_wr_max;
  430. }
  431. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  432. }
  433. static int bnx2x_mc_assert(struct bnx2x *bp)
  434. {
  435. char last_idx;
  436. int i, rc = 0;
  437. u32 row0, row1, row2, row3;
  438. /* XSTORM */
  439. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  440. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  441. if (last_idx)
  442. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  443. /* print the asserts */
  444. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  445. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  446. XSTORM_ASSERT_LIST_OFFSET(i));
  447. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  448. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  449. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  450. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  451. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  452. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  453. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  454. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  455. i, row3, row2, row1, row0);
  456. rc++;
  457. } else {
  458. break;
  459. }
  460. }
  461. /* TSTORM */
  462. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  463. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  464. if (last_idx)
  465. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  466. /* print the asserts */
  467. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  468. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  469. TSTORM_ASSERT_LIST_OFFSET(i));
  470. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  471. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  472. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  473. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  474. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  475. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  476. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  477. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  478. i, row3, row2, row1, row0);
  479. rc++;
  480. } else {
  481. break;
  482. }
  483. }
  484. /* CSTORM */
  485. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  486. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  487. if (last_idx)
  488. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  489. /* print the asserts */
  490. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  491. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  492. CSTORM_ASSERT_LIST_OFFSET(i));
  493. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  494. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  495. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  496. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  497. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  498. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  499. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  500. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  501. i, row3, row2, row1, row0);
  502. rc++;
  503. } else {
  504. break;
  505. }
  506. }
  507. /* USTORM */
  508. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  509. USTORM_ASSERT_LIST_INDEX_OFFSET);
  510. if (last_idx)
  511. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  512. /* print the asserts */
  513. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  514. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  515. USTORM_ASSERT_LIST_OFFSET(i));
  516. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  517. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  518. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  519. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  520. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  521. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  522. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  523. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  524. i, row3, row2, row1, row0);
  525. rc++;
  526. } else {
  527. break;
  528. }
  529. }
  530. return rc;
  531. }
  532. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  533. {
  534. u32 addr, val;
  535. u32 mark, offset;
  536. __be32 data[9];
  537. int word;
  538. u32 trace_shmem_base;
  539. if (BP_NOMCP(bp)) {
  540. BNX2X_ERR("NO MCP - can not dump\n");
  541. return;
  542. }
  543. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  544. (bp->common.bc_ver & 0xff0000) >> 16,
  545. (bp->common.bc_ver & 0xff00) >> 8,
  546. (bp->common.bc_ver & 0xff));
  547. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  548. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  549. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  550. if (BP_PATH(bp) == 0)
  551. trace_shmem_base = bp->common.shmem_base;
  552. else
  553. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  554. addr = trace_shmem_base - 0x800;
  555. /* validate TRCB signature */
  556. mark = REG_RD(bp, addr);
  557. if (mark != MFW_TRACE_SIGNATURE) {
  558. BNX2X_ERR("Trace buffer signature is missing.");
  559. return ;
  560. }
  561. /* read cyclic buffer pointer */
  562. addr += 4;
  563. mark = REG_RD(bp, addr);
  564. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  565. + ((mark + 0x3) & ~0x3) - 0x08000000;
  566. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  567. printk("%s", lvl);
  568. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  569. for (word = 0; word < 8; word++)
  570. data[word] = htonl(REG_RD(bp, offset + 4*word));
  571. data[8] = 0x0;
  572. pr_cont("%s", (char *)data);
  573. }
  574. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  575. for (word = 0; word < 8; word++)
  576. data[word] = htonl(REG_RD(bp, offset + 4*word));
  577. data[8] = 0x0;
  578. pr_cont("%s", (char *)data);
  579. }
  580. printk("%s" "end of fw dump\n", lvl);
  581. }
  582. static void bnx2x_fw_dump(struct bnx2x *bp)
  583. {
  584. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  585. }
  586. void bnx2x_panic_dump(struct bnx2x *bp)
  587. {
  588. int i;
  589. u16 j;
  590. struct hc_sp_status_block_data sp_sb_data;
  591. int func = BP_FUNC(bp);
  592. #ifdef BNX2X_STOP_ON_ERROR
  593. u16 start = 0, end = 0;
  594. u8 cos;
  595. #endif
  596. bp->stats_state = STATS_STATE_DISABLED;
  597. bp->eth_stats.unrecoverable_error++;
  598. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  599. BNX2X_ERR("begin crash dump -----------------\n");
  600. /* Indices */
  601. /* Common */
  602. 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",
  603. bp->def_idx, bp->def_att_idx, bp->attn_state,
  604. bp->spq_prod_idx, bp->stats_counter);
  605. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  606. bp->def_status_blk->atten_status_block.attn_bits,
  607. bp->def_status_blk->atten_status_block.attn_bits_ack,
  608. bp->def_status_blk->atten_status_block.status_block_id,
  609. bp->def_status_blk->atten_status_block.attn_bits_index);
  610. BNX2X_ERR(" def (");
  611. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  612. pr_cont("0x%x%s",
  613. bp->def_status_blk->sp_sb.index_values[i],
  614. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  615. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  616. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  617. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  618. i*sizeof(u32));
  619. 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",
  620. sp_sb_data.igu_sb_id,
  621. sp_sb_data.igu_seg_id,
  622. sp_sb_data.p_func.pf_id,
  623. sp_sb_data.p_func.vnic_id,
  624. sp_sb_data.p_func.vf_id,
  625. sp_sb_data.p_func.vf_valid,
  626. sp_sb_data.state);
  627. for_each_eth_queue(bp, i) {
  628. struct bnx2x_fastpath *fp = &bp->fp[i];
  629. int loop;
  630. struct hc_status_block_data_e2 sb_data_e2;
  631. struct hc_status_block_data_e1x sb_data_e1x;
  632. struct hc_status_block_sm *hc_sm_p =
  633. CHIP_IS_E1x(bp) ?
  634. sb_data_e1x.common.state_machine :
  635. sb_data_e2.common.state_machine;
  636. struct hc_index_data *hc_index_p =
  637. CHIP_IS_E1x(bp) ?
  638. sb_data_e1x.index_data :
  639. sb_data_e2.index_data;
  640. u8 data_size, cos;
  641. u32 *sb_data_p;
  642. struct bnx2x_fp_txdata txdata;
  643. /* Rx */
  644. 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",
  645. i, fp->rx_bd_prod, fp->rx_bd_cons,
  646. fp->rx_comp_prod,
  647. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  648. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  649. fp->rx_sge_prod, fp->last_max_sge,
  650. le16_to_cpu(fp->fp_hc_idx));
  651. /* Tx */
  652. for_each_cos_in_tx_queue(fp, cos)
  653. {
  654. txdata = fp->txdata[cos];
  655. 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",
  656. i, txdata.tx_pkt_prod,
  657. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  658. txdata.tx_bd_cons,
  659. le16_to_cpu(*txdata.tx_cons_sb));
  660. }
  661. loop = CHIP_IS_E1x(bp) ?
  662. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  663. /* host sb data */
  664. #ifdef BCM_CNIC
  665. if (IS_FCOE_FP(fp))
  666. continue;
  667. #endif
  668. BNX2X_ERR(" run indexes (");
  669. for (j = 0; j < HC_SB_MAX_SM; j++)
  670. pr_cont("0x%x%s",
  671. fp->sb_running_index[j],
  672. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  673. BNX2X_ERR(" indexes (");
  674. for (j = 0; j < loop; j++)
  675. pr_cont("0x%x%s",
  676. fp->sb_index_values[j],
  677. (j == loop - 1) ? ")" : " ");
  678. /* fw sb data */
  679. data_size = CHIP_IS_E1x(bp) ?
  680. sizeof(struct hc_status_block_data_e1x) :
  681. sizeof(struct hc_status_block_data_e2);
  682. data_size /= sizeof(u32);
  683. sb_data_p = CHIP_IS_E1x(bp) ?
  684. (u32 *)&sb_data_e1x :
  685. (u32 *)&sb_data_e2;
  686. /* copy sb data in here */
  687. for (j = 0; j < data_size; j++)
  688. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  689. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  690. j * sizeof(u32));
  691. if (!CHIP_IS_E1x(bp)) {
  692. 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",
  693. sb_data_e2.common.p_func.pf_id,
  694. sb_data_e2.common.p_func.vf_id,
  695. sb_data_e2.common.p_func.vf_valid,
  696. sb_data_e2.common.p_func.vnic_id,
  697. sb_data_e2.common.same_igu_sb_1b,
  698. sb_data_e2.common.state);
  699. } else {
  700. 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",
  701. sb_data_e1x.common.p_func.pf_id,
  702. sb_data_e1x.common.p_func.vf_id,
  703. sb_data_e1x.common.p_func.vf_valid,
  704. sb_data_e1x.common.p_func.vnic_id,
  705. sb_data_e1x.common.same_igu_sb_1b,
  706. sb_data_e1x.common.state);
  707. }
  708. /* SB_SMs data */
  709. for (j = 0; j < HC_SB_MAX_SM; j++) {
  710. 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",
  711. j, hc_sm_p[j].__flags,
  712. hc_sm_p[j].igu_sb_id,
  713. hc_sm_p[j].igu_seg_id,
  714. hc_sm_p[j].time_to_expire,
  715. hc_sm_p[j].timer_value);
  716. }
  717. /* Indecies data */
  718. for (j = 0; j < loop; j++) {
  719. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  720. hc_index_p[j].flags,
  721. hc_index_p[j].timeout);
  722. }
  723. }
  724. #ifdef BNX2X_STOP_ON_ERROR
  725. /* Rings */
  726. /* Rx */
  727. for_each_rx_queue(bp, i) {
  728. struct bnx2x_fastpath *fp = &bp->fp[i];
  729. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  730. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  731. for (j = start; j != end; j = RX_BD(j + 1)) {
  732. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  733. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  734. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  735. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  736. }
  737. start = RX_SGE(fp->rx_sge_prod);
  738. end = RX_SGE(fp->last_max_sge);
  739. for (j = start; j != end; j = RX_SGE(j + 1)) {
  740. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  741. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  742. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  743. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  744. }
  745. start = RCQ_BD(fp->rx_comp_cons - 10);
  746. end = RCQ_BD(fp->rx_comp_cons + 503);
  747. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  748. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  749. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  750. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  751. }
  752. }
  753. /* Tx */
  754. for_each_tx_queue(bp, i) {
  755. struct bnx2x_fastpath *fp = &bp->fp[i];
  756. for_each_cos_in_tx_queue(fp, cos) {
  757. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  758. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  759. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  760. for (j = start; j != end; j = TX_BD(j + 1)) {
  761. struct sw_tx_bd *sw_bd =
  762. &txdata->tx_buf_ring[j];
  763. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  764. i, cos, j, sw_bd->skb,
  765. sw_bd->first_bd);
  766. }
  767. start = TX_BD(txdata->tx_bd_cons - 10);
  768. end = TX_BD(txdata->tx_bd_cons + 254);
  769. for (j = start; j != end; j = TX_BD(j + 1)) {
  770. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  771. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  772. i, cos, j, tx_bd[0], tx_bd[1],
  773. tx_bd[2], tx_bd[3]);
  774. }
  775. }
  776. }
  777. #endif
  778. bnx2x_fw_dump(bp);
  779. bnx2x_mc_assert(bp);
  780. BNX2X_ERR("end crash dump -----------------\n");
  781. }
  782. /*
  783. * FLR Support for E2
  784. *
  785. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  786. * initialization.
  787. */
  788. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  789. #define FLR_WAIT_INTERVAL 50 /* usec */
  790. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  791. struct pbf_pN_buf_regs {
  792. int pN;
  793. u32 init_crd;
  794. u32 crd;
  795. u32 crd_freed;
  796. };
  797. struct pbf_pN_cmd_regs {
  798. int pN;
  799. u32 lines_occup;
  800. u32 lines_freed;
  801. };
  802. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  803. struct pbf_pN_buf_regs *regs,
  804. u32 poll_count)
  805. {
  806. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  807. u32 cur_cnt = poll_count;
  808. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  809. crd = crd_start = REG_RD(bp, regs->crd);
  810. init_crd = REG_RD(bp, regs->init_crd);
  811. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  812. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  813. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  814. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  815. (init_crd - crd_start))) {
  816. if (cur_cnt--) {
  817. udelay(FLR_WAIT_INTERVAL);
  818. crd = REG_RD(bp, regs->crd);
  819. crd_freed = REG_RD(bp, regs->crd_freed);
  820. } else {
  821. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  822. regs->pN);
  823. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  824. regs->pN, crd);
  825. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  826. regs->pN, crd_freed);
  827. break;
  828. }
  829. }
  830. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  831. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  832. }
  833. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  834. struct pbf_pN_cmd_regs *regs,
  835. u32 poll_count)
  836. {
  837. u32 occup, to_free, freed, freed_start;
  838. u32 cur_cnt = poll_count;
  839. occup = to_free = REG_RD(bp, regs->lines_occup);
  840. freed = freed_start = REG_RD(bp, regs->lines_freed);
  841. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  842. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  843. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  844. if (cur_cnt--) {
  845. udelay(FLR_WAIT_INTERVAL);
  846. occup = REG_RD(bp, regs->lines_occup);
  847. freed = REG_RD(bp, regs->lines_freed);
  848. } else {
  849. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  850. regs->pN);
  851. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  852. regs->pN, occup);
  853. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  854. regs->pN, freed);
  855. break;
  856. }
  857. }
  858. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  859. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  860. }
  861. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  862. u32 expected, u32 poll_count)
  863. {
  864. u32 cur_cnt = poll_count;
  865. u32 val;
  866. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  867. udelay(FLR_WAIT_INTERVAL);
  868. return val;
  869. }
  870. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  871. char *msg, u32 poll_cnt)
  872. {
  873. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  874. if (val != 0) {
  875. BNX2X_ERR("%s usage count=%d\n", msg, val);
  876. return 1;
  877. }
  878. return 0;
  879. }
  880. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  881. {
  882. /* adjust polling timeout */
  883. if (CHIP_REV_IS_EMUL(bp))
  884. return FLR_POLL_CNT * 2000;
  885. if (CHIP_REV_IS_FPGA(bp))
  886. return FLR_POLL_CNT * 120;
  887. return FLR_POLL_CNT;
  888. }
  889. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  890. {
  891. struct pbf_pN_cmd_regs cmd_regs[] = {
  892. {0, (CHIP_IS_E3B0(bp)) ?
  893. PBF_REG_TQ_OCCUPANCY_Q0 :
  894. PBF_REG_P0_TQ_OCCUPANCY,
  895. (CHIP_IS_E3B0(bp)) ?
  896. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  897. PBF_REG_P0_TQ_LINES_FREED_CNT},
  898. {1, (CHIP_IS_E3B0(bp)) ?
  899. PBF_REG_TQ_OCCUPANCY_Q1 :
  900. PBF_REG_P1_TQ_OCCUPANCY,
  901. (CHIP_IS_E3B0(bp)) ?
  902. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  903. PBF_REG_P1_TQ_LINES_FREED_CNT},
  904. {4, (CHIP_IS_E3B0(bp)) ?
  905. PBF_REG_TQ_OCCUPANCY_LB_Q :
  906. PBF_REG_P4_TQ_OCCUPANCY,
  907. (CHIP_IS_E3B0(bp)) ?
  908. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  909. PBF_REG_P4_TQ_LINES_FREED_CNT}
  910. };
  911. struct pbf_pN_buf_regs buf_regs[] = {
  912. {0, (CHIP_IS_E3B0(bp)) ?
  913. PBF_REG_INIT_CRD_Q0 :
  914. PBF_REG_P0_INIT_CRD ,
  915. (CHIP_IS_E3B0(bp)) ?
  916. PBF_REG_CREDIT_Q0 :
  917. PBF_REG_P0_CREDIT,
  918. (CHIP_IS_E3B0(bp)) ?
  919. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  920. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  921. {1, (CHIP_IS_E3B0(bp)) ?
  922. PBF_REG_INIT_CRD_Q1 :
  923. PBF_REG_P1_INIT_CRD,
  924. (CHIP_IS_E3B0(bp)) ?
  925. PBF_REG_CREDIT_Q1 :
  926. PBF_REG_P1_CREDIT,
  927. (CHIP_IS_E3B0(bp)) ?
  928. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  929. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  930. {4, (CHIP_IS_E3B0(bp)) ?
  931. PBF_REG_INIT_CRD_LB_Q :
  932. PBF_REG_P4_INIT_CRD,
  933. (CHIP_IS_E3B0(bp)) ?
  934. PBF_REG_CREDIT_LB_Q :
  935. PBF_REG_P4_CREDIT,
  936. (CHIP_IS_E3B0(bp)) ?
  937. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  938. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  939. };
  940. int i;
  941. /* Verify the command queues are flushed P0, P1, P4 */
  942. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  943. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  944. /* Verify the transmission buffers are flushed P0, P1, P4 */
  945. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  946. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  947. }
  948. #define OP_GEN_PARAM(param) \
  949. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  950. #define OP_GEN_TYPE(type) \
  951. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  952. #define OP_GEN_AGG_VECT(index) \
  953. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  954. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  955. u32 poll_cnt)
  956. {
  957. struct sdm_op_gen op_gen = {0};
  958. u32 comp_addr = BAR_CSTRORM_INTMEM +
  959. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  960. int ret = 0;
  961. if (REG_RD(bp, comp_addr)) {
  962. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  963. return 1;
  964. }
  965. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  966. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  967. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  968. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  969. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  970. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  971. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  972. BNX2X_ERR("FW final cleanup did not succeed\n");
  973. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  974. (REG_RD(bp, comp_addr)));
  975. ret = 1;
  976. }
  977. /* Zero completion for nxt FLR */
  978. REG_WR(bp, comp_addr, 0);
  979. return ret;
  980. }
  981. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  982. {
  983. int pos;
  984. u16 status;
  985. pos = pci_pcie_cap(dev);
  986. if (!pos)
  987. return false;
  988. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  989. return status & PCI_EXP_DEVSTA_TRPND;
  990. }
  991. /* PF FLR specific routines
  992. */
  993. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  994. {
  995. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  996. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  997. CFC_REG_NUM_LCIDS_INSIDE_PF,
  998. "CFC PF usage counter timed out",
  999. poll_cnt))
  1000. return 1;
  1001. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1002. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1003. DORQ_REG_PF_USAGE_CNT,
  1004. "DQ PF usage counter timed out",
  1005. poll_cnt))
  1006. return 1;
  1007. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1008. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1009. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1010. "QM PF usage counter timed out",
  1011. poll_cnt))
  1012. return 1;
  1013. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1014. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1015. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1016. "Timers VNIC usage counter timed out",
  1017. poll_cnt))
  1018. return 1;
  1019. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1020. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1021. "Timers NUM_SCANS usage counter timed out",
  1022. poll_cnt))
  1023. return 1;
  1024. /* Wait DMAE PF usage counter to zero */
  1025. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1026. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1027. "DMAE dommand register timed out",
  1028. poll_cnt))
  1029. return 1;
  1030. return 0;
  1031. }
  1032. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1033. {
  1034. u32 val;
  1035. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1036. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1037. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1038. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1039. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1040. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1041. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1042. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1043. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1044. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1045. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1046. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1047. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1048. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1049. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1050. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1051. val);
  1052. }
  1053. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1054. {
  1055. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1056. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1057. /* Re-enable PF target read access */
  1058. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1059. /* Poll HW usage counters */
  1060. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1061. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1062. return -EBUSY;
  1063. /* Zero the igu 'trailing edge' and 'leading edge' */
  1064. /* Send the FW cleanup command */
  1065. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1066. return -EBUSY;
  1067. /* ATC cleanup */
  1068. /* Verify TX hw is flushed */
  1069. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1070. /* Wait 100ms (not adjusted according to platform) */
  1071. msleep(100);
  1072. /* Verify no pending pci transactions */
  1073. if (bnx2x_is_pcie_pending(bp->pdev))
  1074. BNX2X_ERR("PCIE Transactions still pending\n");
  1075. /* Debug */
  1076. bnx2x_hw_enable_status(bp);
  1077. /*
  1078. * Master enable - Due to WB DMAE writes performed before this
  1079. * register is re-initialized as part of the regular function init
  1080. */
  1081. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1082. return 0;
  1083. }
  1084. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1085. {
  1086. int port = BP_PORT(bp);
  1087. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1088. u32 val = REG_RD(bp, addr);
  1089. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1090. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1091. if (msix) {
  1092. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1093. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1094. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1095. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1096. } else if (msi) {
  1097. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1098. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1099. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1100. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1101. } else {
  1102. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1103. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1104. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1105. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1106. if (!CHIP_IS_E1(bp)) {
  1107. DP(NETIF_MSG_IFUP,
  1108. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1109. REG_WR(bp, addr, val);
  1110. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1111. }
  1112. }
  1113. if (CHIP_IS_E1(bp))
  1114. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1115. DP(NETIF_MSG_IFUP,
  1116. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1117. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1118. REG_WR(bp, addr, val);
  1119. /*
  1120. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1121. */
  1122. mmiowb();
  1123. barrier();
  1124. if (!CHIP_IS_E1(bp)) {
  1125. /* init leading/trailing edge */
  1126. if (IS_MF(bp)) {
  1127. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1128. if (bp->port.pmf)
  1129. /* enable nig and gpio3 attention */
  1130. val |= 0x1100;
  1131. } else
  1132. val = 0xffff;
  1133. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1134. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1135. }
  1136. /* Make sure that interrupts are indeed enabled from here on */
  1137. mmiowb();
  1138. }
  1139. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1140. {
  1141. u32 val;
  1142. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1143. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1144. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1145. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1146. if (msix) {
  1147. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1148. IGU_PF_CONF_SINGLE_ISR_EN);
  1149. val |= (IGU_PF_CONF_FUNC_EN |
  1150. IGU_PF_CONF_MSI_MSIX_EN |
  1151. IGU_PF_CONF_ATTN_BIT_EN);
  1152. if (single_msix)
  1153. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1154. } else if (msi) {
  1155. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1156. val |= (IGU_PF_CONF_FUNC_EN |
  1157. IGU_PF_CONF_MSI_MSIX_EN |
  1158. IGU_PF_CONF_ATTN_BIT_EN |
  1159. IGU_PF_CONF_SINGLE_ISR_EN);
  1160. } else {
  1161. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1162. val |= (IGU_PF_CONF_FUNC_EN |
  1163. IGU_PF_CONF_INT_LINE_EN |
  1164. IGU_PF_CONF_ATTN_BIT_EN |
  1165. IGU_PF_CONF_SINGLE_ISR_EN);
  1166. }
  1167. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1168. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1169. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1170. if (val & IGU_PF_CONF_INT_LINE_EN)
  1171. pci_intx(bp->pdev, true);
  1172. barrier();
  1173. /* init leading/trailing edge */
  1174. if (IS_MF(bp)) {
  1175. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1176. if (bp->port.pmf)
  1177. /* enable nig and gpio3 attention */
  1178. val |= 0x1100;
  1179. } else
  1180. val = 0xffff;
  1181. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1182. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1183. /* Make sure that interrupts are indeed enabled from here on */
  1184. mmiowb();
  1185. }
  1186. void bnx2x_int_enable(struct bnx2x *bp)
  1187. {
  1188. if (bp->common.int_block == INT_BLOCK_HC)
  1189. bnx2x_hc_int_enable(bp);
  1190. else
  1191. bnx2x_igu_int_enable(bp);
  1192. }
  1193. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1194. {
  1195. int port = BP_PORT(bp);
  1196. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1197. u32 val = REG_RD(bp, addr);
  1198. /*
  1199. * in E1 we must use only PCI configuration space to disable
  1200. * MSI/MSIX capablility
  1201. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1202. */
  1203. if (CHIP_IS_E1(bp)) {
  1204. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1205. * Use mask register to prevent from HC sending interrupts
  1206. * after we exit the function
  1207. */
  1208. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1209. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1210. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1211. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1212. } else
  1213. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1214. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1215. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1216. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1217. DP(NETIF_MSG_IFDOWN,
  1218. "write %x to HC %d (addr 0x%x)\n",
  1219. val, port, addr);
  1220. /* flush all outstanding writes */
  1221. mmiowb();
  1222. REG_WR(bp, addr, val);
  1223. if (REG_RD(bp, addr) != val)
  1224. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1225. }
  1226. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1227. {
  1228. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1229. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1230. IGU_PF_CONF_INT_LINE_EN |
  1231. IGU_PF_CONF_ATTN_BIT_EN);
  1232. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1233. /* flush all outstanding writes */
  1234. mmiowb();
  1235. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1236. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1237. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1238. }
  1239. void bnx2x_int_disable(struct bnx2x *bp)
  1240. {
  1241. if (bp->common.int_block == INT_BLOCK_HC)
  1242. bnx2x_hc_int_disable(bp);
  1243. else
  1244. bnx2x_igu_int_disable(bp);
  1245. }
  1246. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1247. {
  1248. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1249. int i, offset;
  1250. if (disable_hw)
  1251. /* prevent the HW from sending interrupts */
  1252. bnx2x_int_disable(bp);
  1253. /* make sure all ISRs are done */
  1254. if (msix) {
  1255. synchronize_irq(bp->msix_table[0].vector);
  1256. offset = 1;
  1257. #ifdef BCM_CNIC
  1258. offset++;
  1259. #endif
  1260. for_each_eth_queue(bp, i)
  1261. synchronize_irq(bp->msix_table[offset++].vector);
  1262. } else
  1263. synchronize_irq(bp->pdev->irq);
  1264. /* make sure sp_task is not running */
  1265. cancel_delayed_work(&bp->sp_task);
  1266. cancel_delayed_work(&bp->period_task);
  1267. flush_workqueue(bnx2x_wq);
  1268. }
  1269. /* fast path */
  1270. /*
  1271. * General service functions
  1272. */
  1273. /* Return true if succeeded to acquire the lock */
  1274. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1275. {
  1276. u32 lock_status;
  1277. u32 resource_bit = (1 << resource);
  1278. int func = BP_FUNC(bp);
  1279. u32 hw_lock_control_reg;
  1280. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1281. "Trying to take a lock on resource %d\n", resource);
  1282. /* Validating that the resource is within range */
  1283. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1284. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1285. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1286. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1287. return false;
  1288. }
  1289. if (func <= 5)
  1290. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1291. else
  1292. hw_lock_control_reg =
  1293. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1294. /* Try to acquire the lock */
  1295. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1296. lock_status = REG_RD(bp, hw_lock_control_reg);
  1297. if (lock_status & resource_bit)
  1298. return true;
  1299. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1300. "Failed to get a lock on resource %d\n", resource);
  1301. return false;
  1302. }
  1303. /**
  1304. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1305. *
  1306. * @bp: driver handle
  1307. *
  1308. * Returns the recovery leader resource id according to the engine this function
  1309. * belongs to. Currently only only 2 engines is supported.
  1310. */
  1311. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1312. {
  1313. if (BP_PATH(bp))
  1314. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1315. else
  1316. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1317. }
  1318. /**
  1319. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1320. *
  1321. * @bp: driver handle
  1322. *
  1323. * Tries to aquire a leader lock for current engine.
  1324. */
  1325. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1326. {
  1327. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1328. }
  1329. #ifdef BCM_CNIC
  1330. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1331. #endif
  1332. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1333. {
  1334. struct bnx2x *bp = fp->bp;
  1335. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1336. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1337. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1338. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1339. DP(BNX2X_MSG_SP,
  1340. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1341. fp->index, cid, command, bp->state,
  1342. rr_cqe->ramrod_cqe.ramrod_type);
  1343. switch (command) {
  1344. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1345. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1346. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1347. break;
  1348. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1349. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1350. drv_cmd = BNX2X_Q_CMD_SETUP;
  1351. break;
  1352. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1353. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1354. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1355. break;
  1356. case (RAMROD_CMD_ID_ETH_HALT):
  1357. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1358. drv_cmd = BNX2X_Q_CMD_HALT;
  1359. break;
  1360. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1361. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1362. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1363. break;
  1364. case (RAMROD_CMD_ID_ETH_EMPTY):
  1365. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1366. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1367. break;
  1368. default:
  1369. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1370. command, fp->index);
  1371. return;
  1372. }
  1373. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1374. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1375. /* q_obj->complete_cmd() failure means that this was
  1376. * an unexpected completion.
  1377. *
  1378. * In this case we don't want to increase the bp->spq_left
  1379. * because apparently we haven't sent this command the first
  1380. * place.
  1381. */
  1382. #ifdef BNX2X_STOP_ON_ERROR
  1383. bnx2x_panic();
  1384. #else
  1385. return;
  1386. #endif
  1387. smp_mb__before_atomic_inc();
  1388. atomic_inc(&bp->cq_spq_left);
  1389. /* push the change in bp->spq_left and towards the memory */
  1390. smp_mb__after_atomic_inc();
  1391. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1392. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1393. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1394. /* if Q update ramrod is completed for last Q in AFEX vif set
  1395. * flow, then ACK MCP at the end
  1396. *
  1397. * mark pending ACK to MCP bit.
  1398. * prevent case that both bits are cleared.
  1399. * At the end of load/unload driver checks that
  1400. * sp_state is cleaerd, and this order prevents
  1401. * races
  1402. */
  1403. smp_mb__before_clear_bit();
  1404. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1405. wmb();
  1406. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1407. smp_mb__after_clear_bit();
  1408. /* schedule workqueue to send ack to MCP */
  1409. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1410. }
  1411. return;
  1412. }
  1413. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1414. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1415. {
  1416. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1417. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1418. start);
  1419. }
  1420. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1421. {
  1422. struct bnx2x *bp = netdev_priv(dev_instance);
  1423. u16 status = bnx2x_ack_int(bp);
  1424. u16 mask;
  1425. int i;
  1426. u8 cos;
  1427. /* Return here if interrupt is shared and it's not for us */
  1428. if (unlikely(status == 0)) {
  1429. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1430. return IRQ_NONE;
  1431. }
  1432. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1433. #ifdef BNX2X_STOP_ON_ERROR
  1434. if (unlikely(bp->panic))
  1435. return IRQ_HANDLED;
  1436. #endif
  1437. for_each_eth_queue(bp, i) {
  1438. struct bnx2x_fastpath *fp = &bp->fp[i];
  1439. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1440. if (status & mask) {
  1441. /* Handle Rx or Tx according to SB id */
  1442. prefetch(fp->rx_cons_sb);
  1443. for_each_cos_in_tx_queue(fp, cos)
  1444. prefetch(fp->txdata[cos].tx_cons_sb);
  1445. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1446. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1447. status &= ~mask;
  1448. }
  1449. }
  1450. #ifdef BCM_CNIC
  1451. mask = 0x2;
  1452. if (status & (mask | 0x1)) {
  1453. struct cnic_ops *c_ops = NULL;
  1454. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1455. rcu_read_lock();
  1456. c_ops = rcu_dereference(bp->cnic_ops);
  1457. if (c_ops)
  1458. c_ops->cnic_handler(bp->cnic_data, NULL);
  1459. rcu_read_unlock();
  1460. }
  1461. status &= ~mask;
  1462. }
  1463. #endif
  1464. if (unlikely(status & 0x1)) {
  1465. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1466. status &= ~0x1;
  1467. if (!status)
  1468. return IRQ_HANDLED;
  1469. }
  1470. if (unlikely(status))
  1471. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1472. status);
  1473. return IRQ_HANDLED;
  1474. }
  1475. /* Link */
  1476. /*
  1477. * General service functions
  1478. */
  1479. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1480. {
  1481. u32 lock_status;
  1482. u32 resource_bit = (1 << resource);
  1483. int func = BP_FUNC(bp);
  1484. u32 hw_lock_control_reg;
  1485. int cnt;
  1486. /* Validating that the resource is within range */
  1487. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1488. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1489. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1490. return -EINVAL;
  1491. }
  1492. if (func <= 5) {
  1493. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1494. } else {
  1495. hw_lock_control_reg =
  1496. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1497. }
  1498. /* Validating that the resource is not already taken */
  1499. lock_status = REG_RD(bp, hw_lock_control_reg);
  1500. if (lock_status & resource_bit) {
  1501. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1502. lock_status, resource_bit);
  1503. return -EEXIST;
  1504. }
  1505. /* Try for 5 second every 5ms */
  1506. for (cnt = 0; cnt < 1000; cnt++) {
  1507. /* Try to acquire the lock */
  1508. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1509. lock_status = REG_RD(bp, hw_lock_control_reg);
  1510. if (lock_status & resource_bit)
  1511. return 0;
  1512. msleep(5);
  1513. }
  1514. BNX2X_ERR("Timeout\n");
  1515. return -EAGAIN;
  1516. }
  1517. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1518. {
  1519. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1520. }
  1521. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1522. {
  1523. u32 lock_status;
  1524. u32 resource_bit = (1 << resource);
  1525. int func = BP_FUNC(bp);
  1526. u32 hw_lock_control_reg;
  1527. /* Validating that the resource is within range */
  1528. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1529. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1530. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1531. return -EINVAL;
  1532. }
  1533. if (func <= 5) {
  1534. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1535. } else {
  1536. hw_lock_control_reg =
  1537. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1538. }
  1539. /* Validating that the resource is currently taken */
  1540. lock_status = REG_RD(bp, hw_lock_control_reg);
  1541. if (!(lock_status & resource_bit)) {
  1542. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1543. lock_status, resource_bit);
  1544. return -EFAULT;
  1545. }
  1546. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1547. return 0;
  1548. }
  1549. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1550. {
  1551. /* The GPIO should be swapped if swap register is set and active */
  1552. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1553. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1554. int gpio_shift = gpio_num +
  1555. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1556. u32 gpio_mask = (1 << gpio_shift);
  1557. u32 gpio_reg;
  1558. int value;
  1559. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1560. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1561. return -EINVAL;
  1562. }
  1563. /* read GPIO value */
  1564. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1565. /* get the requested pin value */
  1566. if ((gpio_reg & gpio_mask) == gpio_mask)
  1567. value = 1;
  1568. else
  1569. value = 0;
  1570. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1571. return value;
  1572. }
  1573. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1574. {
  1575. /* The GPIO should be swapped if swap register is set and active */
  1576. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1577. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1578. int gpio_shift = gpio_num +
  1579. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1580. u32 gpio_mask = (1 << gpio_shift);
  1581. u32 gpio_reg;
  1582. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1583. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1584. return -EINVAL;
  1585. }
  1586. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1587. /* read GPIO and mask except the float bits */
  1588. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1589. switch (mode) {
  1590. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1591. DP(NETIF_MSG_LINK,
  1592. "Set GPIO %d (shift %d) -> output low\n",
  1593. gpio_num, gpio_shift);
  1594. /* clear FLOAT and set CLR */
  1595. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1596. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1597. break;
  1598. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1599. DP(NETIF_MSG_LINK,
  1600. "Set GPIO %d (shift %d) -> output high\n",
  1601. gpio_num, gpio_shift);
  1602. /* clear FLOAT and set SET */
  1603. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1604. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1605. break;
  1606. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1607. DP(NETIF_MSG_LINK,
  1608. "Set GPIO %d (shift %d) -> input\n",
  1609. gpio_num, gpio_shift);
  1610. /* set FLOAT */
  1611. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1612. break;
  1613. default:
  1614. break;
  1615. }
  1616. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1617. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1618. return 0;
  1619. }
  1620. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1621. {
  1622. u32 gpio_reg = 0;
  1623. int rc = 0;
  1624. /* Any port swapping should be handled by caller. */
  1625. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1626. /* read GPIO and mask except the float bits */
  1627. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1628. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1629. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1630. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1631. switch (mode) {
  1632. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1633. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1634. /* set CLR */
  1635. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1636. break;
  1637. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1638. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1639. /* set SET */
  1640. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1641. break;
  1642. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1643. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1644. /* set FLOAT */
  1645. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1646. break;
  1647. default:
  1648. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1649. rc = -EINVAL;
  1650. break;
  1651. }
  1652. if (rc == 0)
  1653. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1654. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1655. return rc;
  1656. }
  1657. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1658. {
  1659. /* The GPIO should be swapped if swap register is set and active */
  1660. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1661. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1662. int gpio_shift = gpio_num +
  1663. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1664. u32 gpio_mask = (1 << gpio_shift);
  1665. u32 gpio_reg;
  1666. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1667. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1668. return -EINVAL;
  1669. }
  1670. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1671. /* read GPIO int */
  1672. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1673. switch (mode) {
  1674. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1675. DP(NETIF_MSG_LINK,
  1676. "Clear GPIO INT %d (shift %d) -> output low\n",
  1677. gpio_num, gpio_shift);
  1678. /* clear SET and set CLR */
  1679. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1680. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1681. break;
  1682. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1683. DP(NETIF_MSG_LINK,
  1684. "Set GPIO INT %d (shift %d) -> output high\n",
  1685. gpio_num, gpio_shift);
  1686. /* clear CLR and set SET */
  1687. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1688. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1689. break;
  1690. default:
  1691. break;
  1692. }
  1693. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1694. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1695. return 0;
  1696. }
  1697. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1698. {
  1699. u32 spio_mask = (1 << spio_num);
  1700. u32 spio_reg;
  1701. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1702. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1703. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1704. return -EINVAL;
  1705. }
  1706. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1707. /* read SPIO and mask except the float bits */
  1708. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1709. switch (mode) {
  1710. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1711. DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
  1712. /* clear FLOAT and set CLR */
  1713. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1714. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1715. break;
  1716. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1717. DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
  1718. /* clear FLOAT and set SET */
  1719. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1720. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1721. break;
  1722. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1723. DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
  1724. /* set FLOAT */
  1725. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1726. break;
  1727. default:
  1728. break;
  1729. }
  1730. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1731. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1732. return 0;
  1733. }
  1734. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1735. {
  1736. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1737. switch (bp->link_vars.ieee_fc &
  1738. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1739. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1740. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1741. ADVERTISED_Pause);
  1742. break;
  1743. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1744. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1745. ADVERTISED_Pause);
  1746. break;
  1747. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1748. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1749. break;
  1750. default:
  1751. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1752. ADVERTISED_Pause);
  1753. break;
  1754. }
  1755. }
  1756. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1757. {
  1758. if (!BP_NOMCP(bp)) {
  1759. u8 rc;
  1760. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1761. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1762. /*
  1763. * Initialize link parameters structure variables
  1764. * It is recommended to turn off RX FC for jumbo frames
  1765. * for better performance
  1766. */
  1767. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1768. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1769. else
  1770. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1771. bnx2x_acquire_phy_lock(bp);
  1772. if (load_mode == LOAD_DIAG) {
  1773. struct link_params *lp = &bp->link_params;
  1774. lp->loopback_mode = LOOPBACK_XGXS;
  1775. /* do PHY loopback at 10G speed, if possible */
  1776. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1777. if (lp->speed_cap_mask[cfx_idx] &
  1778. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1779. lp->req_line_speed[cfx_idx] =
  1780. SPEED_10000;
  1781. else
  1782. lp->req_line_speed[cfx_idx] =
  1783. SPEED_1000;
  1784. }
  1785. }
  1786. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1787. bnx2x_release_phy_lock(bp);
  1788. bnx2x_calc_fc_adv(bp);
  1789. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1790. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1791. bnx2x_link_report(bp);
  1792. } else
  1793. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1794. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1795. return rc;
  1796. }
  1797. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1798. return -EINVAL;
  1799. }
  1800. void bnx2x_link_set(struct bnx2x *bp)
  1801. {
  1802. if (!BP_NOMCP(bp)) {
  1803. bnx2x_acquire_phy_lock(bp);
  1804. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1805. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1806. bnx2x_release_phy_lock(bp);
  1807. bnx2x_calc_fc_adv(bp);
  1808. } else
  1809. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1810. }
  1811. static void bnx2x__link_reset(struct bnx2x *bp)
  1812. {
  1813. if (!BP_NOMCP(bp)) {
  1814. bnx2x_acquire_phy_lock(bp);
  1815. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1816. bnx2x_release_phy_lock(bp);
  1817. } else
  1818. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1819. }
  1820. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1821. {
  1822. u8 rc = 0;
  1823. if (!BP_NOMCP(bp)) {
  1824. bnx2x_acquire_phy_lock(bp);
  1825. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1826. is_serdes);
  1827. bnx2x_release_phy_lock(bp);
  1828. } else
  1829. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1830. return rc;
  1831. }
  1832. /* Calculates the sum of vn_min_rates.
  1833. It's needed for further normalizing of the min_rates.
  1834. Returns:
  1835. sum of vn_min_rates.
  1836. or
  1837. 0 - if all the min_rates are 0.
  1838. In the later case fainess algorithm should be deactivated.
  1839. If not all min_rates are zero then those that are zeroes will be set to 1.
  1840. */
  1841. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1842. struct cmng_init_input *input)
  1843. {
  1844. int all_zero = 1;
  1845. int vn;
  1846. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1847. u32 vn_cfg = bp->mf_config[vn];
  1848. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1849. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1850. /* Skip hidden vns */
  1851. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1852. vn_min_rate = 0;
  1853. /* If min rate is zero - set it to 1 */
  1854. else if (!vn_min_rate)
  1855. vn_min_rate = DEF_MIN_RATE;
  1856. else
  1857. all_zero = 0;
  1858. input->vnic_min_rate[vn] = vn_min_rate;
  1859. }
  1860. /* if ETS or all min rates are zeros - disable fairness */
  1861. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1862. input->flags.cmng_enables &=
  1863. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1864. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1865. } else if (all_zero) {
  1866. input->flags.cmng_enables &=
  1867. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1868. DP(NETIF_MSG_IFUP,
  1869. "All MIN values are zeroes fairness will be disabled\n");
  1870. } else
  1871. input->flags.cmng_enables |=
  1872. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1873. }
  1874. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1875. struct cmng_init_input *input)
  1876. {
  1877. u16 vn_max_rate;
  1878. u32 vn_cfg = bp->mf_config[vn];
  1879. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1880. vn_max_rate = 0;
  1881. else {
  1882. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1883. if (IS_MF_SI(bp)) {
  1884. /* maxCfg in percents of linkspeed */
  1885. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1886. } else /* SD modes */
  1887. /* maxCfg is absolute in 100Mb units */
  1888. vn_max_rate = maxCfg * 100;
  1889. }
  1890. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1891. input->vnic_max_rate[vn] = vn_max_rate;
  1892. }
  1893. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1894. {
  1895. if (CHIP_REV_IS_SLOW(bp))
  1896. return CMNG_FNS_NONE;
  1897. if (IS_MF(bp))
  1898. return CMNG_FNS_MINMAX;
  1899. return CMNG_FNS_NONE;
  1900. }
  1901. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1902. {
  1903. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1904. if (BP_NOMCP(bp))
  1905. return; /* what should be the default bvalue in this case */
  1906. /* For 2 port configuration the absolute function number formula
  1907. * is:
  1908. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1909. *
  1910. * and there are 4 functions per port
  1911. *
  1912. * For 4 port configuration it is
  1913. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1914. *
  1915. * and there are 2 functions per port
  1916. */
  1917. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1918. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1919. if (func >= E1H_FUNC_MAX)
  1920. break;
  1921. bp->mf_config[vn] =
  1922. MF_CFG_RD(bp, func_mf_config[func].config);
  1923. }
  1924. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1925. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1926. bp->flags |= MF_FUNC_DIS;
  1927. } else {
  1928. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1929. bp->flags &= ~MF_FUNC_DIS;
  1930. }
  1931. }
  1932. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1933. {
  1934. struct cmng_init_input input;
  1935. memset(&input, 0, sizeof(struct cmng_init_input));
  1936. input.port_rate = bp->link_vars.line_speed;
  1937. if (cmng_type == CMNG_FNS_MINMAX) {
  1938. int vn;
  1939. /* read mf conf from shmem */
  1940. if (read_cfg)
  1941. bnx2x_read_mf_cfg(bp);
  1942. /* vn_weight_sum and enable fairness if not 0 */
  1943. bnx2x_calc_vn_min(bp, &input);
  1944. /* calculate and set min-max rate for each vn */
  1945. if (bp->port.pmf)
  1946. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1947. bnx2x_calc_vn_max(bp, vn, &input);
  1948. /* always enable rate shaping and fairness */
  1949. input.flags.cmng_enables |=
  1950. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1951. bnx2x_init_cmng(&input, &bp->cmng);
  1952. return;
  1953. }
  1954. /* rate shaping and fairness are disabled */
  1955. DP(NETIF_MSG_IFUP,
  1956. "rate shaping and fairness are disabled\n");
  1957. }
  1958. static void storm_memset_cmng(struct bnx2x *bp,
  1959. struct cmng_init *cmng,
  1960. u8 port)
  1961. {
  1962. int vn;
  1963. size_t size = sizeof(struct cmng_struct_per_port);
  1964. u32 addr = BAR_XSTRORM_INTMEM +
  1965. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  1966. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  1967. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1968. int func = func_by_vn(bp, vn);
  1969. addr = BAR_XSTRORM_INTMEM +
  1970. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  1971. size = sizeof(struct rate_shaping_vars_per_vn);
  1972. __storm_memset_struct(bp, addr, size,
  1973. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  1974. addr = BAR_XSTRORM_INTMEM +
  1975. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  1976. size = sizeof(struct fairness_vars_per_vn);
  1977. __storm_memset_struct(bp, addr, size,
  1978. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  1979. }
  1980. }
  1981. /* This function is called upon link interrupt */
  1982. static void bnx2x_link_attn(struct bnx2x *bp)
  1983. {
  1984. /* Make sure that we are synced with the current statistics */
  1985. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1986. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  1987. if (bp->link_vars.link_up) {
  1988. /* dropless flow control */
  1989. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  1990. int port = BP_PORT(bp);
  1991. u32 pause_enabled = 0;
  1992. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1993. pause_enabled = 1;
  1994. REG_WR(bp, BAR_USTRORM_INTMEM +
  1995. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  1996. pause_enabled);
  1997. }
  1998. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  1999. struct host_port_stats *pstats;
  2000. pstats = bnx2x_sp(bp, port_stats);
  2001. /* reset old mac stats */
  2002. memset(&(pstats->mac_stx[0]), 0,
  2003. sizeof(struct mac_stx));
  2004. }
  2005. if (bp->state == BNX2X_STATE_OPEN)
  2006. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2007. }
  2008. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2009. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2010. if (cmng_fns != CMNG_FNS_NONE) {
  2011. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2012. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2013. } else
  2014. /* rate shaping and fairness are disabled */
  2015. DP(NETIF_MSG_IFUP,
  2016. "single function mode without fairness\n");
  2017. }
  2018. __bnx2x_link_report(bp);
  2019. if (IS_MF(bp))
  2020. bnx2x_link_sync_notify(bp);
  2021. }
  2022. void bnx2x__link_status_update(struct bnx2x *bp)
  2023. {
  2024. if (bp->state != BNX2X_STATE_OPEN)
  2025. return;
  2026. /* read updated dcb configuration */
  2027. bnx2x_dcbx_pmf_update(bp);
  2028. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2029. if (bp->link_vars.link_up)
  2030. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2031. else
  2032. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2033. /* indicate link status */
  2034. bnx2x_link_report(bp);
  2035. }
  2036. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2037. u16 vlan_val, u8 allowed_prio)
  2038. {
  2039. struct bnx2x_func_state_params func_params = {0};
  2040. struct bnx2x_func_afex_update_params *f_update_params =
  2041. &func_params.params.afex_update;
  2042. func_params.f_obj = &bp->func_obj;
  2043. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2044. /* no need to wait for RAMROD completion, so don't
  2045. * set RAMROD_COMP_WAIT flag
  2046. */
  2047. f_update_params->vif_id = vifid;
  2048. f_update_params->afex_default_vlan = vlan_val;
  2049. f_update_params->allowed_priorities = allowed_prio;
  2050. /* if ramrod can not be sent, response to MCP immediately */
  2051. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2052. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2053. return 0;
  2054. }
  2055. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2056. u16 vif_index, u8 func_bit_map)
  2057. {
  2058. struct bnx2x_func_state_params func_params = {0};
  2059. struct bnx2x_func_afex_viflists_params *update_params =
  2060. &func_params.params.afex_viflists;
  2061. int rc;
  2062. u32 drv_msg_code;
  2063. /* validate only LIST_SET and LIST_GET are received from switch */
  2064. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2065. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2066. cmd_type);
  2067. func_params.f_obj = &bp->func_obj;
  2068. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2069. /* set parameters according to cmd_type */
  2070. update_params->afex_vif_list_command = cmd_type;
  2071. update_params->vif_list_index = cpu_to_le16(vif_index);
  2072. update_params->func_bit_map =
  2073. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2074. update_params->func_to_clear = 0;
  2075. drv_msg_code =
  2076. (cmd_type == VIF_LIST_RULE_GET) ?
  2077. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2078. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2079. /* if ramrod can not be sent, respond to MCP immediately for
  2080. * SET and GET requests (other are not triggered from MCP)
  2081. */
  2082. rc = bnx2x_func_state_change(bp, &func_params);
  2083. if (rc < 0)
  2084. bnx2x_fw_command(bp, drv_msg_code, 0);
  2085. return 0;
  2086. }
  2087. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2088. {
  2089. struct afex_stats afex_stats;
  2090. u32 func = BP_ABS_FUNC(bp);
  2091. u32 mf_config;
  2092. u16 vlan_val;
  2093. u32 vlan_prio;
  2094. u16 vif_id;
  2095. u8 allowed_prio;
  2096. u8 vlan_mode;
  2097. u32 addr_to_write, vifid, addrs, stats_type, i;
  2098. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2099. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2100. DP(BNX2X_MSG_MCP,
  2101. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2102. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2103. }
  2104. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2105. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2106. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2107. DP(BNX2X_MSG_MCP,
  2108. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2109. vifid, addrs);
  2110. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2111. addrs);
  2112. }
  2113. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2114. addr_to_write = SHMEM2_RD(bp,
  2115. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2116. stats_type = SHMEM2_RD(bp,
  2117. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2118. DP(BNX2X_MSG_MCP,
  2119. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2120. addr_to_write);
  2121. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2122. /* write response to scratchpad, for MCP */
  2123. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2124. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2125. *(((u32 *)(&afex_stats))+i));
  2126. /* send ack message to MCP */
  2127. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2128. }
  2129. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2130. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2131. bp->mf_config[BP_VN(bp)] = mf_config;
  2132. DP(BNX2X_MSG_MCP,
  2133. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2134. mf_config);
  2135. /* if VIF_SET is "enabled" */
  2136. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2137. /* set rate limit directly to internal RAM */
  2138. struct cmng_init_input cmng_input;
  2139. struct rate_shaping_vars_per_vn m_rs_vn;
  2140. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2141. u32 addr = BAR_XSTRORM_INTMEM +
  2142. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2143. bp->mf_config[BP_VN(bp)] = mf_config;
  2144. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2145. m_rs_vn.vn_counter.rate =
  2146. cmng_input.vnic_max_rate[BP_VN(bp)];
  2147. m_rs_vn.vn_counter.quota =
  2148. (m_rs_vn.vn_counter.rate *
  2149. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2150. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2151. /* read relevant values from mf_cfg struct in shmem */
  2152. vif_id =
  2153. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2154. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2155. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2156. vlan_val =
  2157. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2158. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2159. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2160. vlan_prio = (mf_config &
  2161. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2162. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2163. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2164. vlan_mode =
  2165. (MF_CFG_RD(bp,
  2166. func_mf_config[func].afex_config) &
  2167. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2168. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2169. allowed_prio =
  2170. (MF_CFG_RD(bp,
  2171. func_mf_config[func].afex_config) &
  2172. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2173. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2174. /* send ramrod to FW, return in case of failure */
  2175. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2176. allowed_prio))
  2177. return;
  2178. bp->afex_def_vlan_tag = vlan_val;
  2179. bp->afex_vlan_mode = vlan_mode;
  2180. } else {
  2181. /* notify link down because BP->flags is disabled */
  2182. bnx2x_link_report(bp);
  2183. /* send INVALID VIF ramrod to FW */
  2184. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2185. /* Reset the default afex VLAN */
  2186. bp->afex_def_vlan_tag = -1;
  2187. }
  2188. }
  2189. }
  2190. static void bnx2x_pmf_update(struct bnx2x *bp)
  2191. {
  2192. int port = BP_PORT(bp);
  2193. u32 val;
  2194. bp->port.pmf = 1;
  2195. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2196. /*
  2197. * We need the mb() to ensure the ordering between the writing to
  2198. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2199. */
  2200. smp_mb();
  2201. /* queue a periodic task */
  2202. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2203. bnx2x_dcbx_pmf_update(bp);
  2204. /* enable nig attention */
  2205. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2206. if (bp->common.int_block == INT_BLOCK_HC) {
  2207. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2208. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2209. } else if (!CHIP_IS_E1x(bp)) {
  2210. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2211. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2212. }
  2213. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2214. }
  2215. /* end of Link */
  2216. /* slow path */
  2217. /*
  2218. * General service functions
  2219. */
  2220. /* send the MCP a request, block until there is a reply */
  2221. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2222. {
  2223. int mb_idx = BP_FW_MB_IDX(bp);
  2224. u32 seq;
  2225. u32 rc = 0;
  2226. u32 cnt = 1;
  2227. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2228. mutex_lock(&bp->fw_mb_mutex);
  2229. seq = ++bp->fw_seq;
  2230. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2231. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2232. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2233. (command | seq), param);
  2234. do {
  2235. /* let the FW do it's magic ... */
  2236. msleep(delay);
  2237. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2238. /* Give the FW up to 5 second (500*10ms) */
  2239. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2240. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2241. cnt*delay, rc, seq);
  2242. /* is this a reply to our command? */
  2243. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2244. rc &= FW_MSG_CODE_MASK;
  2245. else {
  2246. /* FW BUG! */
  2247. BNX2X_ERR("FW failed to respond!\n");
  2248. bnx2x_fw_dump(bp);
  2249. rc = 0;
  2250. }
  2251. mutex_unlock(&bp->fw_mb_mutex);
  2252. return rc;
  2253. }
  2254. static void storm_memset_func_cfg(struct bnx2x *bp,
  2255. struct tstorm_eth_function_common_config *tcfg,
  2256. u16 abs_fid)
  2257. {
  2258. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2259. u32 addr = BAR_TSTRORM_INTMEM +
  2260. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2261. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2262. }
  2263. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2264. {
  2265. if (CHIP_IS_E1x(bp)) {
  2266. struct tstorm_eth_function_common_config tcfg = {0};
  2267. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2268. }
  2269. /* Enable the function in the FW */
  2270. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2271. storm_memset_func_en(bp, p->func_id, 1);
  2272. /* spq */
  2273. if (p->func_flgs & FUNC_FLG_SPQ) {
  2274. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2275. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2276. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2277. }
  2278. }
  2279. /**
  2280. * bnx2x_get_tx_only_flags - Return common flags
  2281. *
  2282. * @bp device handle
  2283. * @fp queue handle
  2284. * @zero_stats TRUE if statistics zeroing is needed
  2285. *
  2286. * Return the flags that are common for the Tx-only and not normal connections.
  2287. */
  2288. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2289. struct bnx2x_fastpath *fp,
  2290. bool zero_stats)
  2291. {
  2292. unsigned long flags = 0;
  2293. /* PF driver will always initialize the Queue to an ACTIVE state */
  2294. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2295. /* tx only connections collect statistics (on the same index as the
  2296. * parent connection). The statistics are zeroed when the parent
  2297. * connection is initialized.
  2298. */
  2299. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2300. if (zero_stats)
  2301. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2302. return flags;
  2303. }
  2304. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2305. struct bnx2x_fastpath *fp,
  2306. bool leading)
  2307. {
  2308. unsigned long flags = 0;
  2309. /* calculate other queue flags */
  2310. if (IS_MF_SD(bp))
  2311. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2312. if (IS_FCOE_FP(fp)) {
  2313. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2314. /* For FCoE - force usage of default priority (for afex) */
  2315. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2316. }
  2317. if (!fp->disable_tpa) {
  2318. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2319. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2320. if (fp->mode == TPA_MODE_GRO)
  2321. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2322. }
  2323. if (leading) {
  2324. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2325. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2326. }
  2327. /* Always set HW VLAN stripping */
  2328. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2329. /* configure silent vlan removal */
  2330. if (IS_MF_AFEX(bp))
  2331. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2332. return flags | bnx2x_get_common_flags(bp, fp, true);
  2333. }
  2334. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2335. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2336. u8 cos)
  2337. {
  2338. gen_init->stat_id = bnx2x_stats_id(fp);
  2339. gen_init->spcl_id = fp->cl_id;
  2340. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2341. if (IS_FCOE_FP(fp))
  2342. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2343. else
  2344. gen_init->mtu = bp->dev->mtu;
  2345. gen_init->cos = cos;
  2346. }
  2347. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2348. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2349. struct bnx2x_rxq_setup_params *rxq_init)
  2350. {
  2351. u8 max_sge = 0;
  2352. u16 sge_sz = 0;
  2353. u16 tpa_agg_size = 0;
  2354. if (!fp->disable_tpa) {
  2355. pause->sge_th_lo = SGE_TH_LO(bp);
  2356. pause->sge_th_hi = SGE_TH_HI(bp);
  2357. /* validate SGE ring has enough to cross high threshold */
  2358. WARN_ON(bp->dropless_fc &&
  2359. pause->sge_th_hi + FW_PREFETCH_CNT >
  2360. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2361. tpa_agg_size = min_t(u32,
  2362. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2363. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2364. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2365. SGE_PAGE_SHIFT;
  2366. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2367. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2368. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2369. 0xffff);
  2370. }
  2371. /* pause - not for e1 */
  2372. if (!CHIP_IS_E1(bp)) {
  2373. pause->bd_th_lo = BD_TH_LO(bp);
  2374. pause->bd_th_hi = BD_TH_HI(bp);
  2375. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2376. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2377. /*
  2378. * validate that rings have enough entries to cross
  2379. * high thresholds
  2380. */
  2381. WARN_ON(bp->dropless_fc &&
  2382. pause->bd_th_hi + FW_PREFETCH_CNT >
  2383. bp->rx_ring_size);
  2384. WARN_ON(bp->dropless_fc &&
  2385. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2386. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2387. pause->pri_map = 1;
  2388. }
  2389. /* rxq setup */
  2390. rxq_init->dscr_map = fp->rx_desc_mapping;
  2391. rxq_init->sge_map = fp->rx_sge_mapping;
  2392. rxq_init->rcq_map = fp->rx_comp_mapping;
  2393. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2394. /* This should be a maximum number of data bytes that may be
  2395. * placed on the BD (not including paddings).
  2396. */
  2397. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2398. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2399. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2400. rxq_init->tpa_agg_sz = tpa_agg_size;
  2401. rxq_init->sge_buf_sz = sge_sz;
  2402. rxq_init->max_sges_pkt = max_sge;
  2403. rxq_init->rss_engine_id = BP_FUNC(bp);
  2404. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2405. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2406. *
  2407. * For PF Clients it should be the maximum avaliable number.
  2408. * VF driver(s) may want to define it to a smaller value.
  2409. */
  2410. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2411. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2412. rxq_init->fw_sb_id = fp->fw_sb_id;
  2413. if (IS_FCOE_FP(fp))
  2414. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2415. else
  2416. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2417. /* configure silent vlan removal
  2418. * if multi function mode is afex, then mask default vlan
  2419. */
  2420. if (IS_MF_AFEX(bp)) {
  2421. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2422. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2423. }
  2424. }
  2425. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2426. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2427. u8 cos)
  2428. {
  2429. txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
  2430. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2431. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2432. txq_init->fw_sb_id = fp->fw_sb_id;
  2433. /*
  2434. * set the tss leading client id for TX classfication ==
  2435. * leading RSS client id
  2436. */
  2437. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2438. if (IS_FCOE_FP(fp)) {
  2439. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2440. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2441. }
  2442. }
  2443. static void bnx2x_pf_init(struct bnx2x *bp)
  2444. {
  2445. struct bnx2x_func_init_params func_init = {0};
  2446. struct event_ring_data eq_data = { {0} };
  2447. u16 flags;
  2448. if (!CHIP_IS_E1x(bp)) {
  2449. /* reset IGU PF statistics: MSIX + ATTN */
  2450. /* PF */
  2451. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2452. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2453. (CHIP_MODE_IS_4_PORT(bp) ?
  2454. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2455. /* ATTN */
  2456. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2457. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2458. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2459. (CHIP_MODE_IS_4_PORT(bp) ?
  2460. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2461. }
  2462. /* function setup flags */
  2463. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2464. /* This flag is relevant for E1x only.
  2465. * E2 doesn't have a TPA configuration in a function level.
  2466. */
  2467. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2468. func_init.func_flgs = flags;
  2469. func_init.pf_id = BP_FUNC(bp);
  2470. func_init.func_id = BP_FUNC(bp);
  2471. func_init.spq_map = bp->spq_mapping;
  2472. func_init.spq_prod = bp->spq_prod_idx;
  2473. bnx2x_func_init(bp, &func_init);
  2474. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2475. /*
  2476. * Congestion management values depend on the link rate
  2477. * There is no active link so initial link rate is set to 10 Gbps.
  2478. * When the link comes up The congestion management values are
  2479. * re-calculated according to the actual link rate.
  2480. */
  2481. bp->link_vars.line_speed = SPEED_10000;
  2482. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2483. /* Only the PMF sets the HW */
  2484. if (bp->port.pmf)
  2485. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2486. /* init Event Queue */
  2487. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2488. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2489. eq_data.producer = bp->eq_prod;
  2490. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2491. eq_data.sb_id = DEF_SB_ID;
  2492. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2493. }
  2494. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2495. {
  2496. int port = BP_PORT(bp);
  2497. bnx2x_tx_disable(bp);
  2498. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2499. }
  2500. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2501. {
  2502. int port = BP_PORT(bp);
  2503. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2504. /* Tx queue should be only reenabled */
  2505. netif_tx_wake_all_queues(bp->dev);
  2506. /*
  2507. * Should not call netif_carrier_on since it will be called if the link
  2508. * is up when checking for link state
  2509. */
  2510. }
  2511. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2512. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2513. {
  2514. struct eth_stats_info *ether_stat =
  2515. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2516. /* leave last char as NULL */
  2517. memcpy(ether_stat->version, DRV_MODULE_VERSION,
  2518. ETH_STAT_INFO_VERSION_LEN - 1);
  2519. bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
  2520. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2521. ether_stat->mac_local);
  2522. ether_stat->mtu_size = bp->dev->mtu;
  2523. if (bp->dev->features & NETIF_F_RXCSUM)
  2524. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2525. if (bp->dev->features & NETIF_F_TSO)
  2526. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2527. ether_stat->feature_flags |= bp->common.boot_mode;
  2528. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2529. ether_stat->txq_size = bp->tx_ring_size;
  2530. ether_stat->rxq_size = bp->rx_ring_size;
  2531. }
  2532. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2533. {
  2534. #ifdef BCM_CNIC
  2535. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2536. struct fcoe_stats_info *fcoe_stat =
  2537. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2538. memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
  2539. fcoe_stat->qos_priority =
  2540. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2541. /* insert FCoE stats from ramrod response */
  2542. if (!NO_FCOE(bp)) {
  2543. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2544. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2545. tstorm_queue_statistics;
  2546. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2547. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2548. xstorm_queue_statistics;
  2549. struct fcoe_statistics_params *fw_fcoe_stat =
  2550. &bp->fw_stats_data->fcoe;
  2551. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2552. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2553. ADD_64(fcoe_stat->rx_bytes_hi,
  2554. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2555. fcoe_stat->rx_bytes_lo,
  2556. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2557. ADD_64(fcoe_stat->rx_bytes_hi,
  2558. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2559. fcoe_stat->rx_bytes_lo,
  2560. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2561. ADD_64(fcoe_stat->rx_bytes_hi,
  2562. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2563. fcoe_stat->rx_bytes_lo,
  2564. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2565. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2566. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2567. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2568. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2569. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2570. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2571. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2572. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2573. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2574. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2575. ADD_64(fcoe_stat->tx_bytes_hi,
  2576. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2577. fcoe_stat->tx_bytes_lo,
  2578. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2579. ADD_64(fcoe_stat->tx_bytes_hi,
  2580. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2581. fcoe_stat->tx_bytes_lo,
  2582. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2583. ADD_64(fcoe_stat->tx_bytes_hi,
  2584. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2585. fcoe_stat->tx_bytes_lo,
  2586. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2587. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2588. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2589. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2590. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2591. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2592. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2593. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2594. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2595. }
  2596. /* ask L5 driver to add data to the struct */
  2597. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2598. #endif
  2599. }
  2600. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2601. {
  2602. #ifdef BCM_CNIC
  2603. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2604. struct iscsi_stats_info *iscsi_stat =
  2605. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2606. memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2607. iscsi_stat->qos_priority =
  2608. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2609. /* ask L5 driver to add data to the struct */
  2610. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2611. #endif
  2612. }
  2613. /* called due to MCP event (on pmf):
  2614. * reread new bandwidth configuration
  2615. * configure FW
  2616. * notify others function about the change
  2617. */
  2618. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2619. {
  2620. if (bp->link_vars.link_up) {
  2621. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2622. bnx2x_link_sync_notify(bp);
  2623. }
  2624. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2625. }
  2626. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2627. {
  2628. bnx2x_config_mf_bw(bp);
  2629. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2630. }
  2631. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2632. {
  2633. enum drv_info_opcode op_code;
  2634. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2635. /* if drv_info version supported by MFW doesn't match - send NACK */
  2636. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2637. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2638. return;
  2639. }
  2640. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2641. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2642. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2643. sizeof(union drv_info_to_mcp));
  2644. switch (op_code) {
  2645. case ETH_STATS_OPCODE:
  2646. bnx2x_drv_info_ether_stat(bp);
  2647. break;
  2648. case FCOE_STATS_OPCODE:
  2649. bnx2x_drv_info_fcoe_stat(bp);
  2650. break;
  2651. case ISCSI_STATS_OPCODE:
  2652. bnx2x_drv_info_iscsi_stat(bp);
  2653. break;
  2654. default:
  2655. /* if op code isn't supported - send NACK */
  2656. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2657. return;
  2658. }
  2659. /* if we got drv_info attn from MFW then these fields are defined in
  2660. * shmem2 for sure
  2661. */
  2662. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2663. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2664. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2665. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2666. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2667. }
  2668. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2669. {
  2670. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2671. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2672. /*
  2673. * This is the only place besides the function initialization
  2674. * where the bp->flags can change so it is done without any
  2675. * locks
  2676. */
  2677. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2678. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2679. bp->flags |= MF_FUNC_DIS;
  2680. bnx2x_e1h_disable(bp);
  2681. } else {
  2682. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2683. bp->flags &= ~MF_FUNC_DIS;
  2684. bnx2x_e1h_enable(bp);
  2685. }
  2686. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2687. }
  2688. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2689. bnx2x_config_mf_bw(bp);
  2690. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2691. }
  2692. /* Report results to MCP */
  2693. if (dcc_event)
  2694. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2695. else
  2696. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2697. }
  2698. /* must be called under the spq lock */
  2699. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2700. {
  2701. struct eth_spe *next_spe = bp->spq_prod_bd;
  2702. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2703. bp->spq_prod_bd = bp->spq;
  2704. bp->spq_prod_idx = 0;
  2705. DP(BNX2X_MSG_SP, "end of spq\n");
  2706. } else {
  2707. bp->spq_prod_bd++;
  2708. bp->spq_prod_idx++;
  2709. }
  2710. return next_spe;
  2711. }
  2712. /* must be called under the spq lock */
  2713. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2714. {
  2715. int func = BP_FUNC(bp);
  2716. /*
  2717. * Make sure that BD data is updated before writing the producer:
  2718. * BD data is written to the memory, the producer is read from the
  2719. * memory, thus we need a full memory barrier to ensure the ordering.
  2720. */
  2721. mb();
  2722. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2723. bp->spq_prod_idx);
  2724. mmiowb();
  2725. }
  2726. /**
  2727. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2728. *
  2729. * @cmd: command to check
  2730. * @cmd_type: command type
  2731. */
  2732. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2733. {
  2734. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2735. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2736. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2737. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2738. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2739. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2740. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2741. return true;
  2742. else
  2743. return false;
  2744. }
  2745. /**
  2746. * bnx2x_sp_post - place a single command on an SP ring
  2747. *
  2748. * @bp: driver handle
  2749. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2750. * @cid: SW CID the command is related to
  2751. * @data_hi: command private data address (high 32 bits)
  2752. * @data_lo: command private data address (low 32 bits)
  2753. * @cmd_type: command type (e.g. NONE, ETH)
  2754. *
  2755. * SP data is handled as if it's always an address pair, thus data fields are
  2756. * not swapped to little endian in upper functions. Instead this function swaps
  2757. * data as if it's two u32 fields.
  2758. */
  2759. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2760. u32 data_hi, u32 data_lo, int cmd_type)
  2761. {
  2762. struct eth_spe *spe;
  2763. u16 type;
  2764. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2765. #ifdef BNX2X_STOP_ON_ERROR
  2766. if (unlikely(bp->panic)) {
  2767. BNX2X_ERR("Can't post SP when there is panic\n");
  2768. return -EIO;
  2769. }
  2770. #endif
  2771. spin_lock_bh(&bp->spq_lock);
  2772. if (common) {
  2773. if (!atomic_read(&bp->eq_spq_left)) {
  2774. BNX2X_ERR("BUG! EQ ring full!\n");
  2775. spin_unlock_bh(&bp->spq_lock);
  2776. bnx2x_panic();
  2777. return -EBUSY;
  2778. }
  2779. } else if (!atomic_read(&bp->cq_spq_left)) {
  2780. BNX2X_ERR("BUG! SPQ ring full!\n");
  2781. spin_unlock_bh(&bp->spq_lock);
  2782. bnx2x_panic();
  2783. return -EBUSY;
  2784. }
  2785. spe = bnx2x_sp_get_next(bp);
  2786. /* CID needs port number to be encoded int it */
  2787. spe->hdr.conn_and_cmd_data =
  2788. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2789. HW_CID(bp, cid));
  2790. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2791. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2792. SPE_HDR_FUNCTION_ID);
  2793. spe->hdr.type = cpu_to_le16(type);
  2794. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2795. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2796. /*
  2797. * It's ok if the actual decrement is issued towards the memory
  2798. * somewhere between the spin_lock and spin_unlock. Thus no
  2799. * more explict memory barrier is needed.
  2800. */
  2801. if (common)
  2802. atomic_dec(&bp->eq_spq_left);
  2803. else
  2804. atomic_dec(&bp->cq_spq_left);
  2805. DP(BNX2X_MSG_SP,
  2806. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2807. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2808. (u32)(U64_LO(bp->spq_mapping) +
  2809. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2810. HW_CID(bp, cid), data_hi, data_lo, type,
  2811. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2812. bnx2x_sp_prod_update(bp);
  2813. spin_unlock_bh(&bp->spq_lock);
  2814. return 0;
  2815. }
  2816. /* acquire split MCP access lock register */
  2817. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2818. {
  2819. u32 j, val;
  2820. int rc = 0;
  2821. might_sleep();
  2822. for (j = 0; j < 1000; j++) {
  2823. val = (1UL << 31);
  2824. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2825. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2826. if (val & (1L << 31))
  2827. break;
  2828. msleep(5);
  2829. }
  2830. if (!(val & (1L << 31))) {
  2831. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2832. rc = -EBUSY;
  2833. }
  2834. return rc;
  2835. }
  2836. /* release split MCP access lock register */
  2837. static void bnx2x_release_alr(struct bnx2x *bp)
  2838. {
  2839. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2840. }
  2841. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2842. #define BNX2X_DEF_SB_IDX 0x0002
  2843. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2844. {
  2845. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2846. u16 rc = 0;
  2847. barrier(); /* status block is written to by the chip */
  2848. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2849. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2850. rc |= BNX2X_DEF_SB_ATT_IDX;
  2851. }
  2852. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2853. bp->def_idx = def_sb->sp_sb.running_index;
  2854. rc |= BNX2X_DEF_SB_IDX;
  2855. }
  2856. /* Do not reorder: indecies reading should complete before handling */
  2857. barrier();
  2858. return rc;
  2859. }
  2860. /*
  2861. * slow path service functions
  2862. */
  2863. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2864. {
  2865. int port = BP_PORT(bp);
  2866. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2867. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2868. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2869. NIG_REG_MASK_INTERRUPT_PORT0;
  2870. u32 aeu_mask;
  2871. u32 nig_mask = 0;
  2872. u32 reg_addr;
  2873. if (bp->attn_state & asserted)
  2874. BNX2X_ERR("IGU ERROR\n");
  2875. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2876. aeu_mask = REG_RD(bp, aeu_addr);
  2877. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2878. aeu_mask, asserted);
  2879. aeu_mask &= ~(asserted & 0x3ff);
  2880. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2881. REG_WR(bp, aeu_addr, aeu_mask);
  2882. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2883. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2884. bp->attn_state |= asserted;
  2885. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2886. if (asserted & ATTN_HARD_WIRED_MASK) {
  2887. if (asserted & ATTN_NIG_FOR_FUNC) {
  2888. bnx2x_acquire_phy_lock(bp);
  2889. /* save nig interrupt mask */
  2890. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2891. /* If nig_mask is not set, no need to call the update
  2892. * function.
  2893. */
  2894. if (nig_mask) {
  2895. REG_WR(bp, nig_int_mask_addr, 0);
  2896. bnx2x_link_attn(bp);
  2897. }
  2898. /* handle unicore attn? */
  2899. }
  2900. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2901. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2902. if (asserted & GPIO_2_FUNC)
  2903. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2904. if (asserted & GPIO_3_FUNC)
  2905. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2906. if (asserted & GPIO_4_FUNC)
  2907. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2908. if (port == 0) {
  2909. if (asserted & ATTN_GENERAL_ATTN_1) {
  2910. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2911. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2912. }
  2913. if (asserted & ATTN_GENERAL_ATTN_2) {
  2914. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2915. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2916. }
  2917. if (asserted & ATTN_GENERAL_ATTN_3) {
  2918. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2919. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2920. }
  2921. } else {
  2922. if (asserted & ATTN_GENERAL_ATTN_4) {
  2923. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2924. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2925. }
  2926. if (asserted & ATTN_GENERAL_ATTN_5) {
  2927. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2928. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2929. }
  2930. if (asserted & ATTN_GENERAL_ATTN_6) {
  2931. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2932. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2933. }
  2934. }
  2935. } /* if hardwired */
  2936. if (bp->common.int_block == INT_BLOCK_HC)
  2937. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2938. COMMAND_REG_ATTN_BITS_SET);
  2939. else
  2940. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2941. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2942. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2943. REG_WR(bp, reg_addr, asserted);
  2944. /* now set back the mask */
  2945. if (asserted & ATTN_NIG_FOR_FUNC) {
  2946. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2947. bnx2x_release_phy_lock(bp);
  2948. }
  2949. }
  2950. static void bnx2x_fan_failure(struct bnx2x *bp)
  2951. {
  2952. int port = BP_PORT(bp);
  2953. u32 ext_phy_config;
  2954. /* mark the failure */
  2955. ext_phy_config =
  2956. SHMEM_RD(bp,
  2957. dev_info.port_hw_config[port].external_phy_config);
  2958. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2959. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2960. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2961. ext_phy_config);
  2962. /* log the failure */
  2963. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2964. "Please contact OEM Support for assistance\n");
  2965. /*
  2966. * Scheudle device reset (unload)
  2967. * This is due to some boards consuming sufficient power when driver is
  2968. * up to overheat if fan fails.
  2969. */
  2970. smp_mb__before_clear_bit();
  2971. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  2972. smp_mb__after_clear_bit();
  2973. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  2974. }
  2975. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2976. {
  2977. int port = BP_PORT(bp);
  2978. int reg_offset;
  2979. u32 val;
  2980. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2981. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2982. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2983. val = REG_RD(bp, reg_offset);
  2984. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2985. REG_WR(bp, reg_offset, val);
  2986. BNX2X_ERR("SPIO5 hw attention\n");
  2987. /* Fan failure attention */
  2988. bnx2x_hw_reset_phy(&bp->link_params);
  2989. bnx2x_fan_failure(bp);
  2990. }
  2991. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  2992. bnx2x_acquire_phy_lock(bp);
  2993. bnx2x_handle_module_detect_int(&bp->link_params);
  2994. bnx2x_release_phy_lock(bp);
  2995. }
  2996. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2997. val = REG_RD(bp, reg_offset);
  2998. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2999. REG_WR(bp, reg_offset, val);
  3000. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3001. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3002. bnx2x_panic();
  3003. }
  3004. }
  3005. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3006. {
  3007. u32 val;
  3008. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3009. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3010. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3011. /* DORQ discard attention */
  3012. if (val & 0x2)
  3013. BNX2X_ERR("FATAL error from DORQ\n");
  3014. }
  3015. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3016. int port = BP_PORT(bp);
  3017. int reg_offset;
  3018. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3019. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3020. val = REG_RD(bp, reg_offset);
  3021. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3022. REG_WR(bp, reg_offset, val);
  3023. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3024. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3025. bnx2x_panic();
  3026. }
  3027. }
  3028. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3029. {
  3030. u32 val;
  3031. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3032. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3033. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3034. /* CFC error attention */
  3035. if (val & 0x2)
  3036. BNX2X_ERR("FATAL error from CFC\n");
  3037. }
  3038. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3039. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3040. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3041. /* RQ_USDMDP_FIFO_OVERFLOW */
  3042. if (val & 0x18000)
  3043. BNX2X_ERR("FATAL error from PXP\n");
  3044. if (!CHIP_IS_E1x(bp)) {
  3045. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3046. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3047. }
  3048. }
  3049. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3050. int port = BP_PORT(bp);
  3051. int reg_offset;
  3052. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3053. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3054. val = REG_RD(bp, reg_offset);
  3055. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3056. REG_WR(bp, reg_offset, val);
  3057. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3058. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3059. bnx2x_panic();
  3060. }
  3061. }
  3062. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3063. {
  3064. u32 val;
  3065. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3066. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3067. int func = BP_FUNC(bp);
  3068. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3069. bnx2x_read_mf_cfg(bp);
  3070. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3071. func_mf_config[BP_ABS_FUNC(bp)].config);
  3072. val = SHMEM_RD(bp,
  3073. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3074. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3075. bnx2x_dcc_event(bp,
  3076. (val & DRV_STATUS_DCC_EVENT_MASK));
  3077. if (val & DRV_STATUS_SET_MF_BW)
  3078. bnx2x_set_mf_bw(bp);
  3079. if (val & DRV_STATUS_DRV_INFO_REQ)
  3080. bnx2x_handle_drv_info_req(bp);
  3081. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3082. bnx2x_pmf_update(bp);
  3083. if (bp->port.pmf &&
  3084. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3085. bp->dcbx_enabled > 0)
  3086. /* start dcbx state machine */
  3087. bnx2x_dcbx_set_params(bp,
  3088. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3089. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3090. bnx2x_handle_afex_cmd(bp,
  3091. val & DRV_STATUS_AFEX_EVENT_MASK);
  3092. if (bp->link_vars.periodic_flags &
  3093. PERIODIC_FLAGS_LINK_EVENT) {
  3094. /* sync with link */
  3095. bnx2x_acquire_phy_lock(bp);
  3096. bp->link_vars.periodic_flags &=
  3097. ~PERIODIC_FLAGS_LINK_EVENT;
  3098. bnx2x_release_phy_lock(bp);
  3099. if (IS_MF(bp))
  3100. bnx2x_link_sync_notify(bp);
  3101. bnx2x_link_report(bp);
  3102. }
  3103. /* Always call it here: bnx2x_link_report() will
  3104. * prevent the link indication duplication.
  3105. */
  3106. bnx2x__link_status_update(bp);
  3107. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3108. BNX2X_ERR("MC assert!\n");
  3109. bnx2x_mc_assert(bp);
  3110. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3111. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3112. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3113. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3114. bnx2x_panic();
  3115. } else if (attn & BNX2X_MCP_ASSERT) {
  3116. BNX2X_ERR("MCP assert!\n");
  3117. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3118. bnx2x_fw_dump(bp);
  3119. } else
  3120. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3121. }
  3122. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3123. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3124. if (attn & BNX2X_GRC_TIMEOUT) {
  3125. val = CHIP_IS_E1(bp) ? 0 :
  3126. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3127. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3128. }
  3129. if (attn & BNX2X_GRC_RSV) {
  3130. val = CHIP_IS_E1(bp) ? 0 :
  3131. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3132. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3133. }
  3134. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3135. }
  3136. }
  3137. /*
  3138. * Bits map:
  3139. * 0-7 - Engine0 load counter.
  3140. * 8-15 - Engine1 load counter.
  3141. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3142. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3143. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3144. * on the engine
  3145. * 19 - Engine1 ONE_IS_LOADED.
  3146. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3147. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3148. * just the one belonging to its engine).
  3149. *
  3150. */
  3151. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3152. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3153. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3154. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3155. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3156. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3157. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3158. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3159. /*
  3160. * Set the GLOBAL_RESET bit.
  3161. *
  3162. * Should be run under rtnl lock
  3163. */
  3164. void bnx2x_set_reset_global(struct bnx2x *bp)
  3165. {
  3166. u32 val;
  3167. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3168. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3169. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3170. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3171. }
  3172. /*
  3173. * Clear the GLOBAL_RESET bit.
  3174. *
  3175. * Should be run under rtnl lock
  3176. */
  3177. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3178. {
  3179. u32 val;
  3180. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3181. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3182. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3183. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3184. }
  3185. /*
  3186. * Checks the GLOBAL_RESET bit.
  3187. *
  3188. * should be run under rtnl lock
  3189. */
  3190. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3191. {
  3192. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3193. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3194. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3195. }
  3196. /*
  3197. * Clear RESET_IN_PROGRESS bit for the current engine.
  3198. *
  3199. * Should be run under rtnl lock
  3200. */
  3201. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3202. {
  3203. u32 val;
  3204. u32 bit = BP_PATH(bp) ?
  3205. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3206. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3207. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3208. /* Clear the bit */
  3209. val &= ~bit;
  3210. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3211. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3212. }
  3213. /*
  3214. * Set RESET_IN_PROGRESS for the current engine.
  3215. *
  3216. * should be run under rtnl lock
  3217. */
  3218. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3219. {
  3220. u32 val;
  3221. u32 bit = BP_PATH(bp) ?
  3222. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3223. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3224. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3225. /* Set the bit */
  3226. val |= bit;
  3227. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3228. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3229. }
  3230. /*
  3231. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3232. * should be run under rtnl lock
  3233. */
  3234. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3235. {
  3236. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3237. u32 bit = engine ?
  3238. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3239. /* return false if bit is set */
  3240. return (val & bit) ? false : true;
  3241. }
  3242. /*
  3243. * set pf load for the current pf.
  3244. *
  3245. * should be run under rtnl lock
  3246. */
  3247. void bnx2x_set_pf_load(struct bnx2x *bp)
  3248. {
  3249. u32 val1, val;
  3250. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3251. BNX2X_PATH0_LOAD_CNT_MASK;
  3252. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3253. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3254. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3255. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3256. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3257. /* get the current counter value */
  3258. val1 = (val & mask) >> shift;
  3259. /* set bit of that PF */
  3260. val1 |= (1 << bp->pf_num);
  3261. /* clear the old value */
  3262. val &= ~mask;
  3263. /* set the new one */
  3264. val |= ((val1 << shift) & mask);
  3265. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3266. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3267. }
  3268. /**
  3269. * bnx2x_clear_pf_load - clear pf load mark
  3270. *
  3271. * @bp: driver handle
  3272. *
  3273. * Should be run under rtnl lock.
  3274. * Decrements the load counter for the current engine. Returns
  3275. * whether other functions are still loaded
  3276. */
  3277. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3278. {
  3279. u32 val1, val;
  3280. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3281. BNX2X_PATH0_LOAD_CNT_MASK;
  3282. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3283. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3284. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3285. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3286. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3287. /* get the current counter value */
  3288. val1 = (val & mask) >> shift;
  3289. /* clear bit of that PF */
  3290. val1 &= ~(1 << bp->pf_num);
  3291. /* clear the old value */
  3292. val &= ~mask;
  3293. /* set the new one */
  3294. val |= ((val1 << shift) & mask);
  3295. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3296. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3297. return val1 != 0;
  3298. }
  3299. /*
  3300. * Read the load status for the current engine.
  3301. *
  3302. * should be run under rtnl lock
  3303. */
  3304. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3305. {
  3306. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3307. BNX2X_PATH0_LOAD_CNT_MASK);
  3308. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3309. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3310. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3311. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3312. val = (val & mask) >> shift;
  3313. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3314. engine, val);
  3315. return val != 0;
  3316. }
  3317. /*
  3318. * Reset the load status for the current engine.
  3319. */
  3320. static void bnx2x_clear_load_status(struct bnx2x *bp)
  3321. {
  3322. u32 val;
  3323. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3324. BNX2X_PATH0_LOAD_CNT_MASK);
  3325. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3326. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3327. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3328. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3329. }
  3330. static void _print_next_block(int idx, const char *blk)
  3331. {
  3332. pr_cont("%s%s", idx ? ", " : "", blk);
  3333. }
  3334. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3335. bool print)
  3336. {
  3337. int i = 0;
  3338. u32 cur_bit = 0;
  3339. for (i = 0; sig; i++) {
  3340. cur_bit = ((u32)0x1 << i);
  3341. if (sig & cur_bit) {
  3342. switch (cur_bit) {
  3343. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3344. if (print)
  3345. _print_next_block(par_num++, "BRB");
  3346. break;
  3347. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3348. if (print)
  3349. _print_next_block(par_num++, "PARSER");
  3350. break;
  3351. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3352. if (print)
  3353. _print_next_block(par_num++, "TSDM");
  3354. break;
  3355. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3356. if (print)
  3357. _print_next_block(par_num++,
  3358. "SEARCHER");
  3359. break;
  3360. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3361. if (print)
  3362. _print_next_block(par_num++, "TCM");
  3363. break;
  3364. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3365. if (print)
  3366. _print_next_block(par_num++, "TSEMI");
  3367. break;
  3368. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3369. if (print)
  3370. _print_next_block(par_num++, "XPB");
  3371. break;
  3372. }
  3373. /* Clear the bit */
  3374. sig &= ~cur_bit;
  3375. }
  3376. }
  3377. return par_num;
  3378. }
  3379. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3380. bool *global, bool print)
  3381. {
  3382. int i = 0;
  3383. u32 cur_bit = 0;
  3384. for (i = 0; sig; i++) {
  3385. cur_bit = ((u32)0x1 << i);
  3386. if (sig & cur_bit) {
  3387. switch (cur_bit) {
  3388. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3389. if (print)
  3390. _print_next_block(par_num++, "PBF");
  3391. break;
  3392. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3393. if (print)
  3394. _print_next_block(par_num++, "QM");
  3395. break;
  3396. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3397. if (print)
  3398. _print_next_block(par_num++, "TM");
  3399. break;
  3400. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3401. if (print)
  3402. _print_next_block(par_num++, "XSDM");
  3403. break;
  3404. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3405. if (print)
  3406. _print_next_block(par_num++, "XCM");
  3407. break;
  3408. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3409. if (print)
  3410. _print_next_block(par_num++, "XSEMI");
  3411. break;
  3412. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3413. if (print)
  3414. _print_next_block(par_num++,
  3415. "DOORBELLQ");
  3416. break;
  3417. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3418. if (print)
  3419. _print_next_block(par_num++, "NIG");
  3420. break;
  3421. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3422. if (print)
  3423. _print_next_block(par_num++,
  3424. "VAUX PCI CORE");
  3425. *global = true;
  3426. break;
  3427. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3428. if (print)
  3429. _print_next_block(par_num++, "DEBUG");
  3430. break;
  3431. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3432. if (print)
  3433. _print_next_block(par_num++, "USDM");
  3434. break;
  3435. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3436. if (print)
  3437. _print_next_block(par_num++, "UCM");
  3438. break;
  3439. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3440. if (print)
  3441. _print_next_block(par_num++, "USEMI");
  3442. break;
  3443. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3444. if (print)
  3445. _print_next_block(par_num++, "UPB");
  3446. break;
  3447. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3448. if (print)
  3449. _print_next_block(par_num++, "CSDM");
  3450. break;
  3451. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3452. if (print)
  3453. _print_next_block(par_num++, "CCM");
  3454. break;
  3455. }
  3456. /* Clear the bit */
  3457. sig &= ~cur_bit;
  3458. }
  3459. }
  3460. return par_num;
  3461. }
  3462. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3463. bool print)
  3464. {
  3465. int i = 0;
  3466. u32 cur_bit = 0;
  3467. for (i = 0; sig; i++) {
  3468. cur_bit = ((u32)0x1 << i);
  3469. if (sig & cur_bit) {
  3470. switch (cur_bit) {
  3471. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3472. if (print)
  3473. _print_next_block(par_num++, "CSEMI");
  3474. break;
  3475. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3476. if (print)
  3477. _print_next_block(par_num++, "PXP");
  3478. break;
  3479. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3480. if (print)
  3481. _print_next_block(par_num++,
  3482. "PXPPCICLOCKCLIENT");
  3483. break;
  3484. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3485. if (print)
  3486. _print_next_block(par_num++, "CFC");
  3487. break;
  3488. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3489. if (print)
  3490. _print_next_block(par_num++, "CDU");
  3491. break;
  3492. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3493. if (print)
  3494. _print_next_block(par_num++, "DMAE");
  3495. break;
  3496. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3497. if (print)
  3498. _print_next_block(par_num++, "IGU");
  3499. break;
  3500. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3501. if (print)
  3502. _print_next_block(par_num++, "MISC");
  3503. break;
  3504. }
  3505. /* Clear the bit */
  3506. sig &= ~cur_bit;
  3507. }
  3508. }
  3509. return par_num;
  3510. }
  3511. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3512. bool *global, bool print)
  3513. {
  3514. int i = 0;
  3515. u32 cur_bit = 0;
  3516. for (i = 0; sig; i++) {
  3517. cur_bit = ((u32)0x1 << i);
  3518. if (sig & cur_bit) {
  3519. switch (cur_bit) {
  3520. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3521. if (print)
  3522. _print_next_block(par_num++, "MCP ROM");
  3523. *global = true;
  3524. break;
  3525. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3526. if (print)
  3527. _print_next_block(par_num++,
  3528. "MCP UMP RX");
  3529. *global = true;
  3530. break;
  3531. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3532. if (print)
  3533. _print_next_block(par_num++,
  3534. "MCP UMP TX");
  3535. *global = true;
  3536. break;
  3537. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3538. if (print)
  3539. _print_next_block(par_num++,
  3540. "MCP SCPAD");
  3541. *global = true;
  3542. break;
  3543. }
  3544. /* Clear the bit */
  3545. sig &= ~cur_bit;
  3546. }
  3547. }
  3548. return par_num;
  3549. }
  3550. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3551. bool print)
  3552. {
  3553. int i = 0;
  3554. u32 cur_bit = 0;
  3555. for (i = 0; sig; i++) {
  3556. cur_bit = ((u32)0x1 << i);
  3557. if (sig & cur_bit) {
  3558. switch (cur_bit) {
  3559. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3560. if (print)
  3561. _print_next_block(par_num++, "PGLUE_B");
  3562. break;
  3563. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3564. if (print)
  3565. _print_next_block(par_num++, "ATC");
  3566. break;
  3567. }
  3568. /* Clear the bit */
  3569. sig &= ~cur_bit;
  3570. }
  3571. }
  3572. return par_num;
  3573. }
  3574. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3575. u32 *sig)
  3576. {
  3577. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3578. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3579. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3580. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3581. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3582. int par_num = 0;
  3583. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3584. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3585. sig[0] & HW_PRTY_ASSERT_SET_0,
  3586. sig[1] & HW_PRTY_ASSERT_SET_1,
  3587. sig[2] & HW_PRTY_ASSERT_SET_2,
  3588. sig[3] & HW_PRTY_ASSERT_SET_3,
  3589. sig[4] & HW_PRTY_ASSERT_SET_4);
  3590. if (print)
  3591. netdev_err(bp->dev,
  3592. "Parity errors detected in blocks: ");
  3593. par_num = bnx2x_check_blocks_with_parity0(
  3594. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3595. par_num = bnx2x_check_blocks_with_parity1(
  3596. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3597. par_num = bnx2x_check_blocks_with_parity2(
  3598. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3599. par_num = bnx2x_check_blocks_with_parity3(
  3600. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3601. par_num = bnx2x_check_blocks_with_parity4(
  3602. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3603. if (print)
  3604. pr_cont("\n");
  3605. return true;
  3606. } else
  3607. return false;
  3608. }
  3609. /**
  3610. * bnx2x_chk_parity_attn - checks for parity attentions.
  3611. *
  3612. * @bp: driver handle
  3613. * @global: true if there was a global attention
  3614. * @print: show parity attention in syslog
  3615. */
  3616. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3617. {
  3618. struct attn_route attn = { {0} };
  3619. int port = BP_PORT(bp);
  3620. attn.sig[0] = REG_RD(bp,
  3621. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3622. port*4);
  3623. attn.sig[1] = REG_RD(bp,
  3624. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3625. port*4);
  3626. attn.sig[2] = REG_RD(bp,
  3627. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3628. port*4);
  3629. attn.sig[3] = REG_RD(bp,
  3630. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3631. port*4);
  3632. if (!CHIP_IS_E1x(bp))
  3633. attn.sig[4] = REG_RD(bp,
  3634. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3635. port*4);
  3636. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3637. }
  3638. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3639. {
  3640. u32 val;
  3641. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3642. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3643. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3644. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3645. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3646. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3647. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3648. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3649. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3650. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3651. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3652. if (val &
  3653. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3654. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3655. if (val &
  3656. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3657. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3658. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3659. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3660. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3661. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3662. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3663. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3664. }
  3665. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3666. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3667. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3668. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3669. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3670. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3671. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3672. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3673. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3674. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3675. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3676. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3677. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3678. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3679. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3680. }
  3681. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3682. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3683. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3684. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3685. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3686. }
  3687. }
  3688. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3689. {
  3690. struct attn_route attn, *group_mask;
  3691. int port = BP_PORT(bp);
  3692. int index;
  3693. u32 reg_addr;
  3694. u32 val;
  3695. u32 aeu_mask;
  3696. bool global = false;
  3697. /* need to take HW lock because MCP or other port might also
  3698. try to handle this event */
  3699. bnx2x_acquire_alr(bp);
  3700. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3701. #ifndef BNX2X_STOP_ON_ERROR
  3702. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3703. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3704. /* Disable HW interrupts */
  3705. bnx2x_int_disable(bp);
  3706. /* In case of parity errors don't handle attentions so that
  3707. * other function would "see" parity errors.
  3708. */
  3709. #else
  3710. bnx2x_panic();
  3711. #endif
  3712. bnx2x_release_alr(bp);
  3713. return;
  3714. }
  3715. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3716. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3717. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3718. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3719. if (!CHIP_IS_E1x(bp))
  3720. attn.sig[4] =
  3721. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3722. else
  3723. attn.sig[4] = 0;
  3724. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3725. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3726. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3727. if (deasserted & (1 << index)) {
  3728. group_mask = &bp->attn_group[index];
  3729. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3730. index,
  3731. group_mask->sig[0], group_mask->sig[1],
  3732. group_mask->sig[2], group_mask->sig[3],
  3733. group_mask->sig[4]);
  3734. bnx2x_attn_int_deasserted4(bp,
  3735. attn.sig[4] & group_mask->sig[4]);
  3736. bnx2x_attn_int_deasserted3(bp,
  3737. attn.sig[3] & group_mask->sig[3]);
  3738. bnx2x_attn_int_deasserted1(bp,
  3739. attn.sig[1] & group_mask->sig[1]);
  3740. bnx2x_attn_int_deasserted2(bp,
  3741. attn.sig[2] & group_mask->sig[2]);
  3742. bnx2x_attn_int_deasserted0(bp,
  3743. attn.sig[0] & group_mask->sig[0]);
  3744. }
  3745. }
  3746. bnx2x_release_alr(bp);
  3747. if (bp->common.int_block == INT_BLOCK_HC)
  3748. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3749. COMMAND_REG_ATTN_BITS_CLR);
  3750. else
  3751. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3752. val = ~deasserted;
  3753. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3754. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3755. REG_WR(bp, reg_addr, val);
  3756. if (~bp->attn_state & deasserted)
  3757. BNX2X_ERR("IGU ERROR\n");
  3758. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3759. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3760. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3761. aeu_mask = REG_RD(bp, reg_addr);
  3762. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3763. aeu_mask, deasserted);
  3764. aeu_mask |= (deasserted & 0x3ff);
  3765. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3766. REG_WR(bp, reg_addr, aeu_mask);
  3767. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3768. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3769. bp->attn_state &= ~deasserted;
  3770. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3771. }
  3772. static void bnx2x_attn_int(struct bnx2x *bp)
  3773. {
  3774. /* read local copy of bits */
  3775. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3776. attn_bits);
  3777. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3778. attn_bits_ack);
  3779. u32 attn_state = bp->attn_state;
  3780. /* look for changed bits */
  3781. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3782. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3783. DP(NETIF_MSG_HW,
  3784. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3785. attn_bits, attn_ack, asserted, deasserted);
  3786. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3787. BNX2X_ERR("BAD attention state\n");
  3788. /* handle bits that were raised */
  3789. if (asserted)
  3790. bnx2x_attn_int_asserted(bp, asserted);
  3791. if (deasserted)
  3792. bnx2x_attn_int_deasserted(bp, deasserted);
  3793. }
  3794. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3795. u16 index, u8 op, u8 update)
  3796. {
  3797. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3798. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3799. igu_addr);
  3800. }
  3801. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3802. {
  3803. /* No memory barriers */
  3804. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3805. mmiowb(); /* keep prod updates ordered */
  3806. }
  3807. #ifdef BCM_CNIC
  3808. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3809. union event_ring_elem *elem)
  3810. {
  3811. u8 err = elem->message.error;
  3812. if (!bp->cnic_eth_dev.starting_cid ||
  3813. (cid < bp->cnic_eth_dev.starting_cid &&
  3814. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3815. return 1;
  3816. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3817. if (unlikely(err)) {
  3818. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3819. cid);
  3820. bnx2x_panic_dump(bp);
  3821. }
  3822. bnx2x_cnic_cfc_comp(bp, cid, err);
  3823. return 0;
  3824. }
  3825. #endif
  3826. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3827. {
  3828. struct bnx2x_mcast_ramrod_params rparam;
  3829. int rc;
  3830. memset(&rparam, 0, sizeof(rparam));
  3831. rparam.mcast_obj = &bp->mcast_obj;
  3832. netif_addr_lock_bh(bp->dev);
  3833. /* Clear pending state for the last command */
  3834. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3835. /* If there are pending mcast commands - send them */
  3836. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3837. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3838. if (rc < 0)
  3839. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3840. rc);
  3841. }
  3842. netif_addr_unlock_bh(bp->dev);
  3843. }
  3844. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3845. union event_ring_elem *elem)
  3846. {
  3847. unsigned long ramrod_flags = 0;
  3848. int rc = 0;
  3849. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3850. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3851. /* Always push next commands out, don't wait here */
  3852. __set_bit(RAMROD_CONT, &ramrod_flags);
  3853. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3854. case BNX2X_FILTER_MAC_PENDING:
  3855. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3856. #ifdef BCM_CNIC
  3857. if (cid == BNX2X_ISCSI_ETH_CID)
  3858. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3859. else
  3860. #endif
  3861. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3862. break;
  3863. case BNX2X_FILTER_MCAST_PENDING:
  3864. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3865. /* This is only relevant for 57710 where multicast MACs are
  3866. * configured as unicast MACs using the same ramrod.
  3867. */
  3868. bnx2x_handle_mcast_eqe(bp);
  3869. return;
  3870. default:
  3871. BNX2X_ERR("Unsupported classification command: %d\n",
  3872. elem->message.data.eth_event.echo);
  3873. return;
  3874. }
  3875. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3876. if (rc < 0)
  3877. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3878. else if (rc > 0)
  3879. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3880. }
  3881. #ifdef BCM_CNIC
  3882. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3883. #endif
  3884. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3885. {
  3886. netif_addr_lock_bh(bp->dev);
  3887. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3888. /* Send rx_mode command again if was requested */
  3889. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3890. bnx2x_set_storm_rx_mode(bp);
  3891. #ifdef BCM_CNIC
  3892. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3893. &bp->sp_state))
  3894. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3895. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3896. &bp->sp_state))
  3897. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3898. #endif
  3899. netif_addr_unlock_bh(bp->dev);
  3900. }
  3901. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3902. union event_ring_elem *elem)
  3903. {
  3904. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3905. DP(BNX2X_MSG_SP,
  3906. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3907. elem->message.data.vif_list_event.func_bit_map);
  3908. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3909. elem->message.data.vif_list_event.func_bit_map);
  3910. } else if (elem->message.data.vif_list_event.echo ==
  3911. VIF_LIST_RULE_SET) {
  3912. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3913. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3914. }
  3915. }
  3916. /* called with rtnl_lock */
  3917. static void bnx2x_after_function_update(struct bnx2x *bp)
  3918. {
  3919. int q, rc;
  3920. struct bnx2x_fastpath *fp;
  3921. struct bnx2x_queue_state_params queue_params = {NULL};
  3922. struct bnx2x_queue_update_params *q_update_params =
  3923. &queue_params.params.update;
  3924. /* Send Q update command with afex vlan removal values for all Qs */
  3925. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3926. /* set silent vlan removal values according to vlan mode */
  3927. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3928. &q_update_params->update_flags);
  3929. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3930. &q_update_params->update_flags);
  3931. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3932. /* in access mode mark mask and value are 0 to strip all vlans */
  3933. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3934. q_update_params->silent_removal_value = 0;
  3935. q_update_params->silent_removal_mask = 0;
  3936. } else {
  3937. q_update_params->silent_removal_value =
  3938. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3939. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3940. }
  3941. for_each_eth_queue(bp, q) {
  3942. /* Set the appropriate Queue object */
  3943. fp = &bp->fp[q];
  3944. queue_params.q_obj = &fp->q_obj;
  3945. /* send the ramrod */
  3946. rc = bnx2x_queue_state_change(bp, &queue_params);
  3947. if (rc < 0)
  3948. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3949. q);
  3950. }
  3951. #ifdef BCM_CNIC
  3952. if (!NO_FCOE(bp)) {
  3953. fp = &bp->fp[FCOE_IDX];
  3954. queue_params.q_obj = &fp->q_obj;
  3955. /* clear pending completion bit */
  3956. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3957. /* mark latest Q bit */
  3958. smp_mb__before_clear_bit();
  3959. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3960. smp_mb__after_clear_bit();
  3961. /* send Q update ramrod for FCoE Q */
  3962. rc = bnx2x_queue_state_change(bp, &queue_params);
  3963. if (rc < 0)
  3964. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3965. q);
  3966. } else {
  3967. /* If no FCoE ring - ACK MCP now */
  3968. bnx2x_link_report(bp);
  3969. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3970. }
  3971. #else
  3972. /* If no FCoE ring - ACK MCP now */
  3973. bnx2x_link_report(bp);
  3974. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3975. #endif /* BCM_CNIC */
  3976. }
  3977. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3978. struct bnx2x *bp, u32 cid)
  3979. {
  3980. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  3981. #ifdef BCM_CNIC
  3982. if (cid == BNX2X_FCOE_ETH_CID)
  3983. return &bnx2x_fcoe(bp, q_obj);
  3984. else
  3985. #endif
  3986. return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
  3987. }
  3988. static void bnx2x_eq_int(struct bnx2x *bp)
  3989. {
  3990. u16 hw_cons, sw_cons, sw_prod;
  3991. union event_ring_elem *elem;
  3992. u32 cid;
  3993. u8 opcode;
  3994. int spqe_cnt = 0;
  3995. struct bnx2x_queue_sp_obj *q_obj;
  3996. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3997. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  3998. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  3999. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4000. * when we get the the next-page we nned to adjust so the loop
  4001. * condition below will be met. The next element is the size of a
  4002. * regular element and hence incrementing by 1
  4003. */
  4004. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4005. hw_cons++;
  4006. /* This function may never run in parallel with itself for a
  4007. * specific bp, thus there is no need in "paired" read memory
  4008. * barrier here.
  4009. */
  4010. sw_cons = bp->eq_cons;
  4011. sw_prod = bp->eq_prod;
  4012. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4013. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4014. for (; sw_cons != hw_cons;
  4015. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4016. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4017. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4018. opcode = elem->message.opcode;
  4019. /* handle eq element */
  4020. switch (opcode) {
  4021. case EVENT_RING_OPCODE_STAT_QUERY:
  4022. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4023. "got statistics comp event %d\n",
  4024. bp->stats_comp++);
  4025. /* nothing to do with stats comp */
  4026. goto next_spqe;
  4027. case EVENT_RING_OPCODE_CFC_DEL:
  4028. /* handle according to cid range */
  4029. /*
  4030. * we may want to verify here that the bp state is
  4031. * HALTING
  4032. */
  4033. DP(BNX2X_MSG_SP,
  4034. "got delete ramrod for MULTI[%d]\n", cid);
  4035. #ifdef BCM_CNIC
  4036. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4037. goto next_spqe;
  4038. #endif
  4039. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4040. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4041. break;
  4042. goto next_spqe;
  4043. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4044. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4045. if (f_obj->complete_cmd(bp, f_obj,
  4046. BNX2X_F_CMD_TX_STOP))
  4047. break;
  4048. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4049. goto next_spqe;
  4050. case EVENT_RING_OPCODE_START_TRAFFIC:
  4051. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4052. if (f_obj->complete_cmd(bp, f_obj,
  4053. BNX2X_F_CMD_TX_START))
  4054. break;
  4055. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4056. goto next_spqe;
  4057. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4058. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4059. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4060. f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_AFEX_UPDATE);
  4061. /* We will perform the Queues update from sp_rtnl task
  4062. * as all Queue SP operations should run under
  4063. * rtnl_lock.
  4064. */
  4065. smp_mb__before_clear_bit();
  4066. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4067. &bp->sp_rtnl_state);
  4068. smp_mb__after_clear_bit();
  4069. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4070. goto next_spqe;
  4071. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4072. f_obj->complete_cmd(bp, f_obj,
  4073. BNX2X_F_CMD_AFEX_VIFLISTS);
  4074. bnx2x_after_afex_vif_lists(bp, elem);
  4075. goto next_spqe;
  4076. case EVENT_RING_OPCODE_FUNCTION_START:
  4077. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4078. "got FUNC_START ramrod\n");
  4079. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4080. break;
  4081. goto next_spqe;
  4082. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4083. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4084. "got FUNC_STOP ramrod\n");
  4085. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4086. break;
  4087. goto next_spqe;
  4088. }
  4089. switch (opcode | bp->state) {
  4090. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4091. BNX2X_STATE_OPEN):
  4092. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4093. BNX2X_STATE_OPENING_WAIT4_PORT):
  4094. cid = elem->message.data.eth_event.echo &
  4095. BNX2X_SWCID_MASK;
  4096. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4097. cid);
  4098. rss_raw->clear_pending(rss_raw);
  4099. break;
  4100. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4101. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4102. case (EVENT_RING_OPCODE_SET_MAC |
  4103. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4104. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4105. BNX2X_STATE_OPEN):
  4106. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4107. BNX2X_STATE_DIAG):
  4108. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4109. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4110. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4111. bnx2x_handle_classification_eqe(bp, elem);
  4112. break;
  4113. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4114. BNX2X_STATE_OPEN):
  4115. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4116. BNX2X_STATE_DIAG):
  4117. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4118. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4119. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4120. bnx2x_handle_mcast_eqe(bp);
  4121. break;
  4122. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4123. BNX2X_STATE_OPEN):
  4124. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4125. BNX2X_STATE_DIAG):
  4126. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4127. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4128. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4129. bnx2x_handle_rx_mode_eqe(bp);
  4130. break;
  4131. default:
  4132. /* unknown event log error and continue */
  4133. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4134. elem->message.opcode, bp->state);
  4135. }
  4136. next_spqe:
  4137. spqe_cnt++;
  4138. } /* for */
  4139. smp_mb__before_atomic_inc();
  4140. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4141. bp->eq_cons = sw_cons;
  4142. bp->eq_prod = sw_prod;
  4143. /* Make sure that above mem writes were issued towards the memory */
  4144. smp_wmb();
  4145. /* update producer */
  4146. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4147. }
  4148. static void bnx2x_sp_task(struct work_struct *work)
  4149. {
  4150. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4151. u16 status;
  4152. status = bnx2x_update_dsb_idx(bp);
  4153. /* if (status == 0) */
  4154. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4155. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4156. /* HW attentions */
  4157. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4158. bnx2x_attn_int(bp);
  4159. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4160. }
  4161. /* SP events: STAT_QUERY and others */
  4162. if (status & BNX2X_DEF_SB_IDX) {
  4163. #ifdef BCM_CNIC
  4164. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4165. if ((!NO_FCOE(bp)) &&
  4166. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4167. /*
  4168. * Prevent local bottom-halves from running as
  4169. * we are going to change the local NAPI list.
  4170. */
  4171. local_bh_disable();
  4172. napi_schedule(&bnx2x_fcoe(bp, napi));
  4173. local_bh_enable();
  4174. }
  4175. #endif
  4176. /* Handle EQ completions */
  4177. bnx2x_eq_int(bp);
  4178. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4179. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4180. status &= ~BNX2X_DEF_SB_IDX;
  4181. }
  4182. if (unlikely(status))
  4183. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4184. status);
  4185. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4186. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4187. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4188. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4189. &bp->sp_state)) {
  4190. bnx2x_link_report(bp);
  4191. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4192. }
  4193. }
  4194. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4195. {
  4196. struct net_device *dev = dev_instance;
  4197. struct bnx2x *bp = netdev_priv(dev);
  4198. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4199. IGU_INT_DISABLE, 0);
  4200. #ifdef BNX2X_STOP_ON_ERROR
  4201. if (unlikely(bp->panic))
  4202. return IRQ_HANDLED;
  4203. #endif
  4204. #ifdef BCM_CNIC
  4205. {
  4206. struct cnic_ops *c_ops;
  4207. rcu_read_lock();
  4208. c_ops = rcu_dereference(bp->cnic_ops);
  4209. if (c_ops)
  4210. c_ops->cnic_handler(bp->cnic_data, NULL);
  4211. rcu_read_unlock();
  4212. }
  4213. #endif
  4214. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4215. return IRQ_HANDLED;
  4216. }
  4217. /* end of slow path */
  4218. void bnx2x_drv_pulse(struct bnx2x *bp)
  4219. {
  4220. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4221. bp->fw_drv_pulse_wr_seq);
  4222. }
  4223. static void bnx2x_timer(unsigned long data)
  4224. {
  4225. struct bnx2x *bp = (struct bnx2x *) data;
  4226. if (!netif_running(bp->dev))
  4227. return;
  4228. if (!BP_NOMCP(bp)) {
  4229. int mb_idx = BP_FW_MB_IDX(bp);
  4230. u32 drv_pulse;
  4231. u32 mcp_pulse;
  4232. ++bp->fw_drv_pulse_wr_seq;
  4233. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4234. /* TBD - add SYSTEM_TIME */
  4235. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4236. bnx2x_drv_pulse(bp);
  4237. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4238. MCP_PULSE_SEQ_MASK);
  4239. /* The delta between driver pulse and mcp response
  4240. * should be 1 (before mcp response) or 0 (after mcp response)
  4241. */
  4242. if ((drv_pulse != mcp_pulse) &&
  4243. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4244. /* someone lost a heartbeat... */
  4245. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4246. drv_pulse, mcp_pulse);
  4247. }
  4248. }
  4249. if (bp->state == BNX2X_STATE_OPEN)
  4250. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4251. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4252. }
  4253. /* end of Statistics */
  4254. /* nic init */
  4255. /*
  4256. * nic init service functions
  4257. */
  4258. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4259. {
  4260. u32 i;
  4261. if (!(len%4) && !(addr%4))
  4262. for (i = 0; i < len; i += 4)
  4263. REG_WR(bp, addr + i, fill);
  4264. else
  4265. for (i = 0; i < len; i++)
  4266. REG_WR8(bp, addr + i, fill);
  4267. }
  4268. /* helper: writes FP SP data to FW - data_size in dwords */
  4269. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4270. int fw_sb_id,
  4271. u32 *sb_data_p,
  4272. u32 data_size)
  4273. {
  4274. int index;
  4275. for (index = 0; index < data_size; index++)
  4276. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4277. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4278. sizeof(u32)*index,
  4279. *(sb_data_p + index));
  4280. }
  4281. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4282. {
  4283. u32 *sb_data_p;
  4284. u32 data_size = 0;
  4285. struct hc_status_block_data_e2 sb_data_e2;
  4286. struct hc_status_block_data_e1x sb_data_e1x;
  4287. /* disable the function first */
  4288. if (!CHIP_IS_E1x(bp)) {
  4289. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4290. sb_data_e2.common.state = SB_DISABLED;
  4291. sb_data_e2.common.p_func.vf_valid = false;
  4292. sb_data_p = (u32 *)&sb_data_e2;
  4293. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4294. } else {
  4295. memset(&sb_data_e1x, 0,
  4296. sizeof(struct hc_status_block_data_e1x));
  4297. sb_data_e1x.common.state = SB_DISABLED;
  4298. sb_data_e1x.common.p_func.vf_valid = false;
  4299. sb_data_p = (u32 *)&sb_data_e1x;
  4300. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4301. }
  4302. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4303. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4304. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4305. CSTORM_STATUS_BLOCK_SIZE);
  4306. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4307. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4308. CSTORM_SYNC_BLOCK_SIZE);
  4309. }
  4310. /* helper: writes SP SB data to FW */
  4311. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4312. struct hc_sp_status_block_data *sp_sb_data)
  4313. {
  4314. int func = BP_FUNC(bp);
  4315. int i;
  4316. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4317. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4318. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4319. i*sizeof(u32),
  4320. *((u32 *)sp_sb_data + i));
  4321. }
  4322. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4323. {
  4324. int func = BP_FUNC(bp);
  4325. struct hc_sp_status_block_data sp_sb_data;
  4326. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4327. sp_sb_data.state = SB_DISABLED;
  4328. sp_sb_data.p_func.vf_valid = false;
  4329. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4330. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4331. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4332. CSTORM_SP_STATUS_BLOCK_SIZE);
  4333. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4334. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4335. CSTORM_SP_SYNC_BLOCK_SIZE);
  4336. }
  4337. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4338. int igu_sb_id, int igu_seg_id)
  4339. {
  4340. hc_sm->igu_sb_id = igu_sb_id;
  4341. hc_sm->igu_seg_id = igu_seg_id;
  4342. hc_sm->timer_value = 0xFF;
  4343. hc_sm->time_to_expire = 0xFFFFFFFF;
  4344. }
  4345. /* allocates state machine ids. */
  4346. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4347. {
  4348. /* zero out state machine indices */
  4349. /* rx indices */
  4350. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4351. /* tx indices */
  4352. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4353. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4354. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4355. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4356. /* map indices */
  4357. /* rx indices */
  4358. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4359. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4360. /* tx indices */
  4361. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4362. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4363. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4364. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4365. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4366. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4367. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4368. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4369. }
  4370. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4371. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4372. {
  4373. int igu_seg_id;
  4374. struct hc_status_block_data_e2 sb_data_e2;
  4375. struct hc_status_block_data_e1x sb_data_e1x;
  4376. struct hc_status_block_sm *hc_sm_p;
  4377. int data_size;
  4378. u32 *sb_data_p;
  4379. if (CHIP_INT_MODE_IS_BC(bp))
  4380. igu_seg_id = HC_SEG_ACCESS_NORM;
  4381. else
  4382. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4383. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4384. if (!CHIP_IS_E1x(bp)) {
  4385. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4386. sb_data_e2.common.state = SB_ENABLED;
  4387. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4388. sb_data_e2.common.p_func.vf_id = vfid;
  4389. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4390. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4391. sb_data_e2.common.same_igu_sb_1b = true;
  4392. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4393. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4394. hc_sm_p = sb_data_e2.common.state_machine;
  4395. sb_data_p = (u32 *)&sb_data_e2;
  4396. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4397. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4398. } else {
  4399. memset(&sb_data_e1x, 0,
  4400. sizeof(struct hc_status_block_data_e1x));
  4401. sb_data_e1x.common.state = SB_ENABLED;
  4402. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4403. sb_data_e1x.common.p_func.vf_id = 0xff;
  4404. sb_data_e1x.common.p_func.vf_valid = false;
  4405. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4406. sb_data_e1x.common.same_igu_sb_1b = true;
  4407. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4408. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4409. hc_sm_p = sb_data_e1x.common.state_machine;
  4410. sb_data_p = (u32 *)&sb_data_e1x;
  4411. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4412. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4413. }
  4414. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4415. igu_sb_id, igu_seg_id);
  4416. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4417. igu_sb_id, igu_seg_id);
  4418. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4419. /* write indecies to HW */
  4420. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4421. }
  4422. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4423. u16 tx_usec, u16 rx_usec)
  4424. {
  4425. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4426. false, rx_usec);
  4427. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4428. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4429. tx_usec);
  4430. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4431. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4432. tx_usec);
  4433. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4434. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4435. tx_usec);
  4436. }
  4437. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4438. {
  4439. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4440. dma_addr_t mapping = bp->def_status_blk_mapping;
  4441. int igu_sp_sb_index;
  4442. int igu_seg_id;
  4443. int port = BP_PORT(bp);
  4444. int func = BP_FUNC(bp);
  4445. int reg_offset, reg_offset_en5;
  4446. u64 section;
  4447. int index;
  4448. struct hc_sp_status_block_data sp_sb_data;
  4449. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4450. if (CHIP_INT_MODE_IS_BC(bp)) {
  4451. igu_sp_sb_index = DEF_SB_IGU_ID;
  4452. igu_seg_id = HC_SEG_ACCESS_DEF;
  4453. } else {
  4454. igu_sp_sb_index = bp->igu_dsb_id;
  4455. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4456. }
  4457. /* ATTN */
  4458. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4459. atten_status_block);
  4460. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4461. bp->attn_state = 0;
  4462. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4463. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4464. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4465. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4466. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4467. int sindex;
  4468. /* take care of sig[0]..sig[4] */
  4469. for (sindex = 0; sindex < 4; sindex++)
  4470. bp->attn_group[index].sig[sindex] =
  4471. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4472. if (!CHIP_IS_E1x(bp))
  4473. /*
  4474. * enable5 is separate from the rest of the registers,
  4475. * and therefore the address skip is 4
  4476. * and not 16 between the different groups
  4477. */
  4478. bp->attn_group[index].sig[4] = REG_RD(bp,
  4479. reg_offset_en5 + 0x4*index);
  4480. else
  4481. bp->attn_group[index].sig[4] = 0;
  4482. }
  4483. if (bp->common.int_block == INT_BLOCK_HC) {
  4484. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4485. HC_REG_ATTN_MSG0_ADDR_L);
  4486. REG_WR(bp, reg_offset, U64_LO(section));
  4487. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4488. } else if (!CHIP_IS_E1x(bp)) {
  4489. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4490. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4491. }
  4492. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4493. sp_sb);
  4494. bnx2x_zero_sp_sb(bp);
  4495. sp_sb_data.state = SB_ENABLED;
  4496. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4497. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4498. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4499. sp_sb_data.igu_seg_id = igu_seg_id;
  4500. sp_sb_data.p_func.pf_id = func;
  4501. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4502. sp_sb_data.p_func.vf_id = 0xff;
  4503. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4504. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4505. }
  4506. void bnx2x_update_coalesce(struct bnx2x *bp)
  4507. {
  4508. int i;
  4509. for_each_eth_queue(bp, i)
  4510. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4511. bp->tx_ticks, bp->rx_ticks);
  4512. }
  4513. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4514. {
  4515. spin_lock_init(&bp->spq_lock);
  4516. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4517. bp->spq_prod_idx = 0;
  4518. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4519. bp->spq_prod_bd = bp->spq;
  4520. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4521. }
  4522. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4523. {
  4524. int i;
  4525. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4526. union event_ring_elem *elem =
  4527. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4528. elem->next_page.addr.hi =
  4529. cpu_to_le32(U64_HI(bp->eq_mapping +
  4530. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4531. elem->next_page.addr.lo =
  4532. cpu_to_le32(U64_LO(bp->eq_mapping +
  4533. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4534. }
  4535. bp->eq_cons = 0;
  4536. bp->eq_prod = NUM_EQ_DESC;
  4537. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4538. /* we want a warning message before it gets rought... */
  4539. atomic_set(&bp->eq_spq_left,
  4540. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4541. }
  4542. /* called with netif_addr_lock_bh() */
  4543. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4544. unsigned long rx_mode_flags,
  4545. unsigned long rx_accept_flags,
  4546. unsigned long tx_accept_flags,
  4547. unsigned long ramrod_flags)
  4548. {
  4549. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4550. int rc;
  4551. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4552. /* Prepare ramrod parameters */
  4553. ramrod_param.cid = 0;
  4554. ramrod_param.cl_id = cl_id;
  4555. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4556. ramrod_param.func_id = BP_FUNC(bp);
  4557. ramrod_param.pstate = &bp->sp_state;
  4558. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4559. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4560. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4561. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4562. ramrod_param.ramrod_flags = ramrod_flags;
  4563. ramrod_param.rx_mode_flags = rx_mode_flags;
  4564. ramrod_param.rx_accept_flags = rx_accept_flags;
  4565. ramrod_param.tx_accept_flags = tx_accept_flags;
  4566. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4567. if (rc < 0) {
  4568. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4569. return;
  4570. }
  4571. }
  4572. /* called with netif_addr_lock_bh() */
  4573. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4574. {
  4575. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4576. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4577. #ifdef BCM_CNIC
  4578. if (!NO_FCOE(bp))
  4579. /* Configure rx_mode of FCoE Queue */
  4580. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4581. #endif
  4582. switch (bp->rx_mode) {
  4583. case BNX2X_RX_MODE_NONE:
  4584. /*
  4585. * 'drop all' supersedes any accept flags that may have been
  4586. * passed to the function.
  4587. */
  4588. break;
  4589. case BNX2X_RX_MODE_NORMAL:
  4590. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4591. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4592. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4593. /* internal switching mode */
  4594. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4595. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4596. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4597. break;
  4598. case BNX2X_RX_MODE_ALLMULTI:
  4599. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4600. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4601. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4602. /* internal switching mode */
  4603. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4604. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4605. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4606. break;
  4607. case BNX2X_RX_MODE_PROMISC:
  4608. /* According to deffinition of SI mode, iface in promisc mode
  4609. * should receive matched and unmatched (in resolution of port)
  4610. * unicast packets.
  4611. */
  4612. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4613. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4614. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4615. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4616. /* internal switching mode */
  4617. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4618. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4619. if (IS_MF_SI(bp))
  4620. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4621. else
  4622. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4623. break;
  4624. default:
  4625. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4626. return;
  4627. }
  4628. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4629. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4630. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4631. }
  4632. __set_bit(RAMROD_RX, &ramrod_flags);
  4633. __set_bit(RAMROD_TX, &ramrod_flags);
  4634. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4635. tx_accept_flags, ramrod_flags);
  4636. }
  4637. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4638. {
  4639. int i;
  4640. if (IS_MF_SI(bp))
  4641. /*
  4642. * In switch independent mode, the TSTORM needs to accept
  4643. * packets that failed classification, since approximate match
  4644. * mac addresses aren't written to NIG LLH
  4645. */
  4646. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4647. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4648. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4649. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4650. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4651. /* Zero this manually as its initialization is
  4652. currently missing in the initTool */
  4653. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4654. REG_WR(bp, BAR_USTRORM_INTMEM +
  4655. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4656. if (!CHIP_IS_E1x(bp)) {
  4657. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4658. CHIP_INT_MODE_IS_BC(bp) ?
  4659. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4660. }
  4661. }
  4662. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4663. {
  4664. switch (load_code) {
  4665. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4666. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4667. bnx2x_init_internal_common(bp);
  4668. /* no break */
  4669. case FW_MSG_CODE_DRV_LOAD_PORT:
  4670. /* nothing to do */
  4671. /* no break */
  4672. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4673. /* internal memory per function is
  4674. initialized inside bnx2x_pf_init */
  4675. break;
  4676. default:
  4677. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4678. break;
  4679. }
  4680. }
  4681. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4682. {
  4683. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4684. }
  4685. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4686. {
  4687. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4688. }
  4689. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4690. {
  4691. if (CHIP_IS_E1x(fp->bp))
  4692. return BP_L_ID(fp->bp) + fp->index;
  4693. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4694. return bnx2x_fp_igu_sb_id(fp);
  4695. }
  4696. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4697. {
  4698. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4699. u8 cos;
  4700. unsigned long q_type = 0;
  4701. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4702. fp->rx_queue = fp_idx;
  4703. fp->cid = fp_idx;
  4704. fp->cl_id = bnx2x_fp_cl_id(fp);
  4705. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4706. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4707. /* qZone id equals to FW (per path) client id */
  4708. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4709. /* init shortcut */
  4710. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4711. /* Setup SB indicies */
  4712. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4713. /* Configure Queue State object */
  4714. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4715. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4716. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4717. /* init tx data */
  4718. for_each_cos_in_tx_queue(fp, cos) {
  4719. bnx2x_init_txdata(bp, &fp->txdata[cos],
  4720. CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
  4721. FP_COS_TO_TXQ(fp, cos),
  4722. BNX2X_TX_SB_INDEX_BASE + cos);
  4723. cids[cos] = fp->txdata[cos].cid;
  4724. }
  4725. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
  4726. BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4727. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4728. /**
  4729. * Configure classification DBs: Always enable Tx switching
  4730. */
  4731. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4732. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4733. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4734. fp->igu_sb_id);
  4735. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4736. fp->fw_sb_id, fp->igu_sb_id);
  4737. bnx2x_update_fpsb_idx(fp);
  4738. }
  4739. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4740. {
  4741. int i;
  4742. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4743. struct eth_tx_next_bd *tx_next_bd =
  4744. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4745. tx_next_bd->addr_hi =
  4746. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4747. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4748. tx_next_bd->addr_lo =
  4749. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4750. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4751. }
  4752. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4753. txdata->tx_db.data.zero_fill1 = 0;
  4754. txdata->tx_db.data.prod = 0;
  4755. txdata->tx_pkt_prod = 0;
  4756. txdata->tx_pkt_cons = 0;
  4757. txdata->tx_bd_prod = 0;
  4758. txdata->tx_bd_cons = 0;
  4759. txdata->tx_pkt = 0;
  4760. }
  4761. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4762. {
  4763. int i;
  4764. u8 cos;
  4765. for_each_tx_queue(bp, i)
  4766. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4767. bnx2x_init_tx_ring_one(&bp->fp[i].txdata[cos]);
  4768. }
  4769. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4770. {
  4771. int i;
  4772. for_each_eth_queue(bp, i)
  4773. bnx2x_init_eth_fp(bp, i);
  4774. #ifdef BCM_CNIC
  4775. if (!NO_FCOE(bp))
  4776. bnx2x_init_fcoe_fp(bp);
  4777. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4778. BNX2X_VF_ID_INVALID, false,
  4779. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4780. #endif
  4781. /* Initialize MOD_ABS interrupts */
  4782. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4783. bp->common.shmem_base, bp->common.shmem2_base,
  4784. BP_PORT(bp));
  4785. /* ensure status block indices were read */
  4786. rmb();
  4787. bnx2x_init_def_sb(bp);
  4788. bnx2x_update_dsb_idx(bp);
  4789. bnx2x_init_rx_rings(bp);
  4790. bnx2x_init_tx_rings(bp);
  4791. bnx2x_init_sp_ring(bp);
  4792. bnx2x_init_eq_ring(bp);
  4793. bnx2x_init_internal(bp, load_code);
  4794. bnx2x_pf_init(bp);
  4795. bnx2x_stats_init(bp);
  4796. /* flush all before enabling interrupts */
  4797. mb();
  4798. mmiowb();
  4799. bnx2x_int_enable(bp);
  4800. /* Check for SPIO5 */
  4801. bnx2x_attn_int_deasserted0(bp,
  4802. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4803. AEU_INPUTS_ATTN_BITS_SPIO5);
  4804. }
  4805. /* end of nic init */
  4806. /*
  4807. * gzip service functions
  4808. */
  4809. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4810. {
  4811. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4812. &bp->gunzip_mapping, GFP_KERNEL);
  4813. if (bp->gunzip_buf == NULL)
  4814. goto gunzip_nomem1;
  4815. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4816. if (bp->strm == NULL)
  4817. goto gunzip_nomem2;
  4818. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4819. if (bp->strm->workspace == NULL)
  4820. goto gunzip_nomem3;
  4821. return 0;
  4822. gunzip_nomem3:
  4823. kfree(bp->strm);
  4824. bp->strm = NULL;
  4825. gunzip_nomem2:
  4826. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4827. bp->gunzip_mapping);
  4828. bp->gunzip_buf = NULL;
  4829. gunzip_nomem1:
  4830. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4831. return -ENOMEM;
  4832. }
  4833. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4834. {
  4835. if (bp->strm) {
  4836. vfree(bp->strm->workspace);
  4837. kfree(bp->strm);
  4838. bp->strm = NULL;
  4839. }
  4840. if (bp->gunzip_buf) {
  4841. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4842. bp->gunzip_mapping);
  4843. bp->gunzip_buf = NULL;
  4844. }
  4845. }
  4846. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4847. {
  4848. int n, rc;
  4849. /* check gzip header */
  4850. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4851. BNX2X_ERR("Bad gzip header\n");
  4852. return -EINVAL;
  4853. }
  4854. n = 10;
  4855. #define FNAME 0x8
  4856. if (zbuf[3] & FNAME)
  4857. while ((zbuf[n++] != 0) && (n < len));
  4858. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4859. bp->strm->avail_in = len - n;
  4860. bp->strm->next_out = bp->gunzip_buf;
  4861. bp->strm->avail_out = FW_BUF_SIZE;
  4862. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4863. if (rc != Z_OK)
  4864. return rc;
  4865. rc = zlib_inflate(bp->strm, Z_FINISH);
  4866. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4867. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4868. bp->strm->msg);
  4869. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4870. if (bp->gunzip_outlen & 0x3)
  4871. netdev_err(bp->dev,
  4872. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4873. bp->gunzip_outlen);
  4874. bp->gunzip_outlen >>= 2;
  4875. zlib_inflateEnd(bp->strm);
  4876. if (rc == Z_STREAM_END)
  4877. return 0;
  4878. return rc;
  4879. }
  4880. /* nic load/unload */
  4881. /*
  4882. * General service functions
  4883. */
  4884. /* send a NIG loopback debug packet */
  4885. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4886. {
  4887. u32 wb_write[3];
  4888. /* Ethernet source and destination addresses */
  4889. wb_write[0] = 0x55555555;
  4890. wb_write[1] = 0x55555555;
  4891. wb_write[2] = 0x20; /* SOP */
  4892. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4893. /* NON-IP protocol */
  4894. wb_write[0] = 0x09000000;
  4895. wb_write[1] = 0x55555555;
  4896. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4897. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4898. }
  4899. /* some of the internal memories
  4900. * are not directly readable from the driver
  4901. * to test them we send debug packets
  4902. */
  4903. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4904. {
  4905. int factor;
  4906. int count, i;
  4907. u32 val = 0;
  4908. if (CHIP_REV_IS_FPGA(bp))
  4909. factor = 120;
  4910. else if (CHIP_REV_IS_EMUL(bp))
  4911. factor = 200;
  4912. else
  4913. factor = 1;
  4914. /* Disable inputs of parser neighbor blocks */
  4915. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4916. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4917. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4918. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4919. /* Write 0 to parser credits for CFC search request */
  4920. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4921. /* send Ethernet packet */
  4922. bnx2x_lb_pckt(bp);
  4923. /* TODO do i reset NIG statistic? */
  4924. /* Wait until NIG register shows 1 packet of size 0x10 */
  4925. count = 1000 * factor;
  4926. while (count) {
  4927. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4928. val = *bnx2x_sp(bp, wb_data[0]);
  4929. if (val == 0x10)
  4930. break;
  4931. msleep(10);
  4932. count--;
  4933. }
  4934. if (val != 0x10) {
  4935. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4936. return -1;
  4937. }
  4938. /* Wait until PRS register shows 1 packet */
  4939. count = 1000 * factor;
  4940. while (count) {
  4941. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4942. if (val == 1)
  4943. break;
  4944. msleep(10);
  4945. count--;
  4946. }
  4947. if (val != 0x1) {
  4948. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4949. return -2;
  4950. }
  4951. /* Reset and init BRB, PRS */
  4952. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4953. msleep(50);
  4954. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4955. msleep(50);
  4956. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4957. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4958. DP(NETIF_MSG_HW, "part2\n");
  4959. /* Disable inputs of parser neighbor blocks */
  4960. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4961. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4962. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4963. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4964. /* Write 0 to parser credits for CFC search request */
  4965. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4966. /* send 10 Ethernet packets */
  4967. for (i = 0; i < 10; i++)
  4968. bnx2x_lb_pckt(bp);
  4969. /* Wait until NIG register shows 10 + 1
  4970. packets of size 11*0x10 = 0xb0 */
  4971. count = 1000 * factor;
  4972. while (count) {
  4973. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4974. val = *bnx2x_sp(bp, wb_data[0]);
  4975. if (val == 0xb0)
  4976. break;
  4977. msleep(10);
  4978. count--;
  4979. }
  4980. if (val != 0xb0) {
  4981. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4982. return -3;
  4983. }
  4984. /* Wait until PRS register shows 2 packets */
  4985. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4986. if (val != 2)
  4987. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4988. /* Write 1 to parser credits for CFC search request */
  4989. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4990. /* Wait until PRS register shows 3 packets */
  4991. msleep(10 * factor);
  4992. /* Wait until NIG register shows 1 packet of size 0x10 */
  4993. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4994. if (val != 3)
  4995. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4996. /* clear NIG EOP FIFO */
  4997. for (i = 0; i < 11; i++)
  4998. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4999. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5000. if (val != 1) {
  5001. BNX2X_ERR("clear of NIG failed\n");
  5002. return -4;
  5003. }
  5004. /* Reset and init BRB, PRS, NIG */
  5005. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5006. msleep(50);
  5007. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5008. msleep(50);
  5009. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5010. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5011. #ifndef BCM_CNIC
  5012. /* set NIC mode */
  5013. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5014. #endif
  5015. /* Enable inputs of parser neighbor blocks */
  5016. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5017. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5018. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5019. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5020. DP(NETIF_MSG_HW, "done\n");
  5021. return 0; /* OK */
  5022. }
  5023. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5024. {
  5025. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5026. if (!CHIP_IS_E1x(bp))
  5027. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5028. else
  5029. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5030. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5031. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5032. /*
  5033. * mask read length error interrupts in brb for parser
  5034. * (parsing unit and 'checksum and crc' unit)
  5035. * these errors are legal (PU reads fixed length and CAC can cause
  5036. * read length error on truncated packets)
  5037. */
  5038. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5039. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5040. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5041. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5042. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5043. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5044. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5045. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5046. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5047. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5048. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5049. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5050. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5051. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5052. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5053. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5054. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5055. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5056. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5057. if (CHIP_REV_IS_FPGA(bp))
  5058. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  5059. else if (!CHIP_IS_E1x(bp))
  5060. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  5061. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  5062. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  5063. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  5064. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  5065. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  5066. else
  5067. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  5068. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5069. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5070. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5071. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5072. if (!CHIP_IS_E1x(bp))
  5073. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5074. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5075. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5076. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5077. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5078. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5079. }
  5080. static void bnx2x_reset_common(struct bnx2x *bp)
  5081. {
  5082. u32 val = 0x1400;
  5083. /* reset_common */
  5084. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5085. 0xd3ffff7f);
  5086. if (CHIP_IS_E3(bp)) {
  5087. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5088. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5089. }
  5090. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5091. }
  5092. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5093. {
  5094. bp->dmae_ready = 0;
  5095. spin_lock_init(&bp->dmae_lock);
  5096. }
  5097. static void bnx2x_init_pxp(struct bnx2x *bp)
  5098. {
  5099. u16 devctl;
  5100. int r_order, w_order;
  5101. pci_read_config_word(bp->pdev,
  5102. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  5103. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5104. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5105. if (bp->mrrs == -1)
  5106. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5107. else {
  5108. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5109. r_order = bp->mrrs;
  5110. }
  5111. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5112. }
  5113. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5114. {
  5115. int is_required;
  5116. u32 val;
  5117. int port;
  5118. if (BP_NOMCP(bp))
  5119. return;
  5120. is_required = 0;
  5121. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5122. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5123. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5124. is_required = 1;
  5125. /*
  5126. * The fan failure mechanism is usually related to the PHY type since
  5127. * the power consumption of the board is affected by the PHY. Currently,
  5128. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5129. */
  5130. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5131. for (port = PORT_0; port < PORT_MAX; port++) {
  5132. is_required |=
  5133. bnx2x_fan_failure_det_req(
  5134. bp,
  5135. bp->common.shmem_base,
  5136. bp->common.shmem2_base,
  5137. port);
  5138. }
  5139. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5140. if (is_required == 0)
  5141. return;
  5142. /* Fan failure is indicated by SPIO 5 */
  5143. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  5144. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  5145. /* set to active low mode */
  5146. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5147. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  5148. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  5149. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5150. /* enable interrupt to signal the IGU */
  5151. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5152. val |= (1 << MISC_REGISTERS_SPIO_5);
  5153. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5154. }
  5155. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5156. {
  5157. u32 offset = 0;
  5158. if (CHIP_IS_E1(bp))
  5159. return;
  5160. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5161. return;
  5162. switch (BP_ABS_FUNC(bp)) {
  5163. case 0:
  5164. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5165. break;
  5166. case 1:
  5167. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5168. break;
  5169. case 2:
  5170. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5171. break;
  5172. case 3:
  5173. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5174. break;
  5175. case 4:
  5176. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5177. break;
  5178. case 5:
  5179. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5180. break;
  5181. case 6:
  5182. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5183. break;
  5184. case 7:
  5185. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5186. break;
  5187. default:
  5188. return;
  5189. }
  5190. REG_WR(bp, offset, pretend_func_num);
  5191. REG_RD(bp, offset);
  5192. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5193. }
  5194. void bnx2x_pf_disable(struct bnx2x *bp)
  5195. {
  5196. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5197. val &= ~IGU_PF_CONF_FUNC_EN;
  5198. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5199. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5200. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5201. }
  5202. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5203. {
  5204. u32 shmem_base[2], shmem2_base[2];
  5205. shmem_base[0] = bp->common.shmem_base;
  5206. shmem2_base[0] = bp->common.shmem2_base;
  5207. if (!CHIP_IS_E1x(bp)) {
  5208. shmem_base[1] =
  5209. SHMEM2_RD(bp, other_shmem_base_addr);
  5210. shmem2_base[1] =
  5211. SHMEM2_RD(bp, other_shmem2_base_addr);
  5212. }
  5213. bnx2x_acquire_phy_lock(bp);
  5214. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5215. bp->common.chip_id);
  5216. bnx2x_release_phy_lock(bp);
  5217. }
  5218. /**
  5219. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5220. *
  5221. * @bp: driver handle
  5222. */
  5223. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5224. {
  5225. u32 val;
  5226. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5227. /*
  5228. * take the UNDI lock to protect undi_unload flow from accessing
  5229. * registers while we're resetting the chip
  5230. */
  5231. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5232. bnx2x_reset_common(bp);
  5233. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5234. val = 0xfffc;
  5235. if (CHIP_IS_E3(bp)) {
  5236. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5237. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5238. }
  5239. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5240. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5241. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5242. if (!CHIP_IS_E1x(bp)) {
  5243. u8 abs_func_id;
  5244. /**
  5245. * 4-port mode or 2-port mode we need to turn of master-enable
  5246. * for everyone, after that, turn it back on for self.
  5247. * so, we disregard multi-function or not, and always disable
  5248. * for all functions on the given path, this means 0,2,4,6 for
  5249. * path 0 and 1,3,5,7 for path 1
  5250. */
  5251. for (abs_func_id = BP_PATH(bp);
  5252. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5253. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5254. REG_WR(bp,
  5255. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5256. 1);
  5257. continue;
  5258. }
  5259. bnx2x_pretend_func(bp, abs_func_id);
  5260. /* clear pf enable */
  5261. bnx2x_pf_disable(bp);
  5262. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5263. }
  5264. }
  5265. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5266. if (CHIP_IS_E1(bp)) {
  5267. /* enable HW interrupt from PXP on USDM overflow
  5268. bit 16 on INT_MASK_0 */
  5269. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5270. }
  5271. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5272. bnx2x_init_pxp(bp);
  5273. #ifdef __BIG_ENDIAN
  5274. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5275. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5276. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5277. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5278. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5279. /* make sure this value is 0 */
  5280. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5281. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5282. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5283. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5284. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5285. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5286. #endif
  5287. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5288. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5289. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5290. /* let the HW do it's magic ... */
  5291. msleep(100);
  5292. /* finish PXP init */
  5293. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5294. if (val != 1) {
  5295. BNX2X_ERR("PXP2 CFG failed\n");
  5296. return -EBUSY;
  5297. }
  5298. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5299. if (val != 1) {
  5300. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5301. return -EBUSY;
  5302. }
  5303. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5304. * have entries with value "0" and valid bit on.
  5305. * This needs to be done by the first PF that is loaded in a path
  5306. * (i.e. common phase)
  5307. */
  5308. if (!CHIP_IS_E1x(bp)) {
  5309. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5310. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5311. * This occurs when a different function (func2,3) is being marked
  5312. * as "scan-off". Real-life scenario for example: if a driver is being
  5313. * load-unloaded while func6,7 are down. This will cause the timer to access
  5314. * the ilt, translate to a logical address and send a request to read/write.
  5315. * Since the ilt for the function that is down is not valid, this will cause
  5316. * a translation error which is unrecoverable.
  5317. * The Workaround is intended to make sure that when this happens nothing fatal
  5318. * will occur. The workaround:
  5319. * 1. First PF driver which loads on a path will:
  5320. * a. After taking the chip out of reset, by using pretend,
  5321. * it will write "0" to the following registers of
  5322. * the other vnics.
  5323. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5324. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5325. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5326. * And for itself it will write '1' to
  5327. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5328. * dmae-operations (writing to pram for example.)
  5329. * note: can be done for only function 6,7 but cleaner this
  5330. * way.
  5331. * b. Write zero+valid to the entire ILT.
  5332. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5333. * VNIC3 (of that port). The range allocated will be the
  5334. * entire ILT. This is needed to prevent ILT range error.
  5335. * 2. Any PF driver load flow:
  5336. * a. ILT update with the physical addresses of the allocated
  5337. * logical pages.
  5338. * b. Wait 20msec. - note that this timeout is needed to make
  5339. * sure there are no requests in one of the PXP internal
  5340. * queues with "old" ILT addresses.
  5341. * c. PF enable in the PGLC.
  5342. * d. Clear the was_error of the PF in the PGLC. (could have
  5343. * occured while driver was down)
  5344. * e. PF enable in the CFC (WEAK + STRONG)
  5345. * f. Timers scan enable
  5346. * 3. PF driver unload flow:
  5347. * a. Clear the Timers scan_en.
  5348. * b. Polling for scan_on=0 for that PF.
  5349. * c. Clear the PF enable bit in the PXP.
  5350. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5351. * e. Write zero+valid to all ILT entries (The valid bit must
  5352. * stay set)
  5353. * f. If this is VNIC 3 of a port then also init
  5354. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5355. * to the last enrty in the ILT.
  5356. *
  5357. * Notes:
  5358. * Currently the PF error in the PGLC is non recoverable.
  5359. * In the future the there will be a recovery routine for this error.
  5360. * Currently attention is masked.
  5361. * Having an MCP lock on the load/unload process does not guarantee that
  5362. * there is no Timer disable during Func6/7 enable. This is because the
  5363. * Timers scan is currently being cleared by the MCP on FLR.
  5364. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5365. * there is error before clearing it. But the flow above is simpler and
  5366. * more general.
  5367. * All ILT entries are written by zero+valid and not just PF6/7
  5368. * ILT entries since in the future the ILT entries allocation for
  5369. * PF-s might be dynamic.
  5370. */
  5371. struct ilt_client_info ilt_cli;
  5372. struct bnx2x_ilt ilt;
  5373. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5374. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5375. /* initialize dummy TM client */
  5376. ilt_cli.start = 0;
  5377. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5378. ilt_cli.client_num = ILT_CLIENT_TM;
  5379. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5380. * Step 2: set the timers first/last ilt entry to point
  5381. * to the entire range to prevent ILT range error for 3rd/4th
  5382. * vnic (this code assumes existance of the vnic)
  5383. *
  5384. * both steps performed by call to bnx2x_ilt_client_init_op()
  5385. * with dummy TM client
  5386. *
  5387. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5388. * and his brother are split registers
  5389. */
  5390. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5391. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5392. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5393. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5394. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5395. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5396. }
  5397. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5398. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5399. if (!CHIP_IS_E1x(bp)) {
  5400. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5401. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5402. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5403. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5404. /* let the HW do it's magic ... */
  5405. do {
  5406. msleep(200);
  5407. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5408. } while (factor-- && (val != 1));
  5409. if (val != 1) {
  5410. BNX2X_ERR("ATC_INIT failed\n");
  5411. return -EBUSY;
  5412. }
  5413. }
  5414. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5415. /* clean the DMAE memory */
  5416. bp->dmae_ready = 1;
  5417. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5418. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5419. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5420. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5421. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5422. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5423. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5424. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5425. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5426. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5427. /* QM queues pointers table */
  5428. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5429. /* soft reset pulse */
  5430. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5431. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5432. #ifdef BCM_CNIC
  5433. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5434. #endif
  5435. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5436. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5437. if (!CHIP_REV_IS_SLOW(bp))
  5438. /* enable hw interrupt from doorbell Q */
  5439. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5440. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5441. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5442. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5443. if (!CHIP_IS_E1(bp))
  5444. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5445. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5446. if (IS_MF_AFEX(bp)) {
  5447. /* configure that VNTag and VLAN headers must be
  5448. * received in afex mode
  5449. */
  5450. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5451. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5452. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5453. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5454. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5455. } else {
  5456. /* Bit-map indicating which L2 hdrs may appear
  5457. * after the basic Ethernet header
  5458. */
  5459. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5460. bp->path_has_ovlan ? 7 : 6);
  5461. }
  5462. }
  5463. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5464. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5465. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5466. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5467. if (!CHIP_IS_E1x(bp)) {
  5468. /* reset VFC memories */
  5469. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5470. VFC_MEMORIES_RST_REG_CAM_RST |
  5471. VFC_MEMORIES_RST_REG_RAM_RST);
  5472. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5473. VFC_MEMORIES_RST_REG_CAM_RST |
  5474. VFC_MEMORIES_RST_REG_RAM_RST);
  5475. msleep(20);
  5476. }
  5477. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5478. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5479. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5480. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5481. /* sync semi rtc */
  5482. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5483. 0x80000000);
  5484. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5485. 0x80000000);
  5486. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5487. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5488. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5489. if (!CHIP_IS_E1x(bp)) {
  5490. if (IS_MF_AFEX(bp)) {
  5491. /* configure that VNTag and VLAN headers must be
  5492. * sent in afex mode
  5493. */
  5494. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5495. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5496. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5497. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5498. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5499. } else {
  5500. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5501. bp->path_has_ovlan ? 7 : 6);
  5502. }
  5503. }
  5504. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5505. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5506. #ifdef BCM_CNIC
  5507. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5508. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5509. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5510. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5511. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5512. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5513. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5514. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5515. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5516. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5517. #endif
  5518. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5519. if (sizeof(union cdu_context) != 1024)
  5520. /* we currently assume that a context is 1024 bytes */
  5521. dev_alert(&bp->pdev->dev,
  5522. "please adjust the size of cdu_context(%ld)\n",
  5523. (long)sizeof(union cdu_context));
  5524. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5525. val = (4 << 24) + (0 << 12) + 1024;
  5526. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5527. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5528. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5529. /* enable context validation interrupt from CFC */
  5530. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5531. /* set the thresholds to prevent CFC/CDU race */
  5532. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5533. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5534. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5535. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5536. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5537. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5538. /* Reset PCIE errors for debug */
  5539. REG_WR(bp, 0x2814, 0xffffffff);
  5540. REG_WR(bp, 0x3820, 0xffffffff);
  5541. if (!CHIP_IS_E1x(bp)) {
  5542. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5543. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5544. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5545. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5546. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5547. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5548. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5549. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5550. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5551. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5552. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5553. }
  5554. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5555. if (!CHIP_IS_E1(bp)) {
  5556. /* in E3 this done in per-port section */
  5557. if (!CHIP_IS_E3(bp))
  5558. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5559. }
  5560. if (CHIP_IS_E1H(bp))
  5561. /* not applicable for E2 (and above ...) */
  5562. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5563. if (CHIP_REV_IS_SLOW(bp))
  5564. msleep(200);
  5565. /* finish CFC init */
  5566. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5567. if (val != 1) {
  5568. BNX2X_ERR("CFC LL_INIT failed\n");
  5569. return -EBUSY;
  5570. }
  5571. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5572. if (val != 1) {
  5573. BNX2X_ERR("CFC AC_INIT failed\n");
  5574. return -EBUSY;
  5575. }
  5576. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5577. if (val != 1) {
  5578. BNX2X_ERR("CFC CAM_INIT failed\n");
  5579. return -EBUSY;
  5580. }
  5581. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5582. if (CHIP_IS_E1(bp)) {
  5583. /* read NIG statistic
  5584. to see if this is our first up since powerup */
  5585. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5586. val = *bnx2x_sp(bp, wb_data[0]);
  5587. /* do internal memory self test */
  5588. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5589. BNX2X_ERR("internal mem self test failed\n");
  5590. return -EBUSY;
  5591. }
  5592. }
  5593. bnx2x_setup_fan_failure_detection(bp);
  5594. /* clear PXP2 attentions */
  5595. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5596. bnx2x_enable_blocks_attention(bp);
  5597. bnx2x_enable_blocks_parity(bp);
  5598. if (!BP_NOMCP(bp)) {
  5599. if (CHIP_IS_E1x(bp))
  5600. bnx2x__common_init_phy(bp);
  5601. } else
  5602. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5603. return 0;
  5604. }
  5605. /**
  5606. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5607. *
  5608. * @bp: driver handle
  5609. */
  5610. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5611. {
  5612. int rc = bnx2x_init_hw_common(bp);
  5613. if (rc)
  5614. return rc;
  5615. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5616. if (!BP_NOMCP(bp))
  5617. bnx2x__common_init_phy(bp);
  5618. return 0;
  5619. }
  5620. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5621. {
  5622. int port = BP_PORT(bp);
  5623. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5624. u32 low, high;
  5625. u32 val;
  5626. bnx2x__link_reset(bp);
  5627. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5628. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5629. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5630. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5631. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5632. /* Timers bug workaround: disables the pf_master bit in pglue at
  5633. * common phase, we need to enable it here before any dmae access are
  5634. * attempted. Therefore we manually added the enable-master to the
  5635. * port phase (it also happens in the function phase)
  5636. */
  5637. if (!CHIP_IS_E1x(bp))
  5638. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5639. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5640. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5641. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5642. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5643. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5644. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5645. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5646. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5647. /* QM cid (connection) count */
  5648. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5649. #ifdef BCM_CNIC
  5650. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5651. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5652. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5653. #endif
  5654. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5655. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5656. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5657. if (IS_MF(bp))
  5658. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5659. else if (bp->dev->mtu > 4096) {
  5660. if (bp->flags & ONE_PORT_FLAG)
  5661. low = 160;
  5662. else {
  5663. val = bp->dev->mtu;
  5664. /* (24*1024 + val*4)/256 */
  5665. low = 96 + (val/64) +
  5666. ((val % 64) ? 1 : 0);
  5667. }
  5668. } else
  5669. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5670. high = low + 56; /* 14*1024/256 */
  5671. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5672. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5673. }
  5674. if (CHIP_MODE_IS_4_PORT(bp))
  5675. REG_WR(bp, (BP_PORT(bp) ?
  5676. BRB1_REG_MAC_GUARANTIED_1 :
  5677. BRB1_REG_MAC_GUARANTIED_0), 40);
  5678. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5679. if (CHIP_IS_E3B0(bp)) {
  5680. if (IS_MF_AFEX(bp)) {
  5681. /* configure headers for AFEX mode */
  5682. REG_WR(bp, BP_PORT(bp) ?
  5683. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5684. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5685. REG_WR(bp, BP_PORT(bp) ?
  5686. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5687. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5688. REG_WR(bp, BP_PORT(bp) ?
  5689. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5690. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5691. } else {
  5692. /* Ovlan exists only if we are in multi-function +
  5693. * switch-dependent mode, in switch-independent there
  5694. * is no ovlan headers
  5695. */
  5696. REG_WR(bp, BP_PORT(bp) ?
  5697. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5698. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5699. (bp->path_has_ovlan ? 7 : 6));
  5700. }
  5701. }
  5702. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5703. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5704. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5705. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5706. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5707. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5708. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5709. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5710. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5711. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5712. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5713. if (CHIP_IS_E1x(bp)) {
  5714. /* configure PBF to work without PAUSE mtu 9000 */
  5715. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5716. /* update threshold */
  5717. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5718. /* update init credit */
  5719. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5720. /* probe changes */
  5721. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5722. udelay(50);
  5723. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5724. }
  5725. #ifdef BCM_CNIC
  5726. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5727. #endif
  5728. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5729. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5730. if (CHIP_IS_E1(bp)) {
  5731. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5732. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5733. }
  5734. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5735. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5736. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5737. /* init aeu_mask_attn_func_0/1:
  5738. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5739. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5740. * bits 4-7 are used for "per vn group attention" */
  5741. val = IS_MF(bp) ? 0xF7 : 0x7;
  5742. /* Enable DCBX attention for all but E1 */
  5743. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5744. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5745. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5746. if (!CHIP_IS_E1x(bp)) {
  5747. /* Bit-map indicating which L2 hdrs may appear after the
  5748. * basic Ethernet header
  5749. */
  5750. if (IS_MF_AFEX(bp))
  5751. REG_WR(bp, BP_PORT(bp) ?
  5752. NIG_REG_P1_HDRS_AFTER_BASIC :
  5753. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5754. else
  5755. REG_WR(bp, BP_PORT(bp) ?
  5756. NIG_REG_P1_HDRS_AFTER_BASIC :
  5757. NIG_REG_P0_HDRS_AFTER_BASIC,
  5758. IS_MF_SD(bp) ? 7 : 6);
  5759. if (CHIP_IS_E3(bp))
  5760. REG_WR(bp, BP_PORT(bp) ?
  5761. NIG_REG_LLH1_MF_MODE :
  5762. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5763. }
  5764. if (!CHIP_IS_E3(bp))
  5765. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5766. if (!CHIP_IS_E1(bp)) {
  5767. /* 0x2 disable mf_ov, 0x1 enable */
  5768. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5769. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5770. if (!CHIP_IS_E1x(bp)) {
  5771. val = 0;
  5772. switch (bp->mf_mode) {
  5773. case MULTI_FUNCTION_SD:
  5774. val = 1;
  5775. break;
  5776. case MULTI_FUNCTION_SI:
  5777. case MULTI_FUNCTION_AFEX:
  5778. val = 2;
  5779. break;
  5780. }
  5781. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5782. NIG_REG_LLH0_CLS_TYPE), val);
  5783. }
  5784. {
  5785. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5786. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5787. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5788. }
  5789. }
  5790. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5791. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5792. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5793. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5794. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5795. val = REG_RD(bp, reg_addr);
  5796. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5797. REG_WR(bp, reg_addr, val);
  5798. }
  5799. return 0;
  5800. }
  5801. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5802. {
  5803. int reg;
  5804. u32 wb_write[2];
  5805. if (CHIP_IS_E1(bp))
  5806. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5807. else
  5808. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5809. wb_write[0] = ONCHIP_ADDR1(addr);
  5810. wb_write[1] = ONCHIP_ADDR2(addr);
  5811. REG_WR_DMAE(bp, reg, wb_write, 2);
  5812. }
  5813. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5814. u8 idu_sb_id, bool is_Pf)
  5815. {
  5816. u32 data, ctl, cnt = 100;
  5817. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5818. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5819. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5820. u32 sb_bit = 1 << (idu_sb_id%32);
  5821. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5822. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5823. /* Not supported in BC mode */
  5824. if (CHIP_INT_MODE_IS_BC(bp))
  5825. return;
  5826. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5827. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5828. IGU_REGULAR_CLEANUP_SET |
  5829. IGU_REGULAR_BCLEANUP;
  5830. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5831. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5832. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5833. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5834. data, igu_addr_data);
  5835. REG_WR(bp, igu_addr_data, data);
  5836. mmiowb();
  5837. barrier();
  5838. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5839. ctl, igu_addr_ctl);
  5840. REG_WR(bp, igu_addr_ctl, ctl);
  5841. mmiowb();
  5842. barrier();
  5843. /* wait for clean up to finish */
  5844. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5845. msleep(20);
  5846. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5847. DP(NETIF_MSG_HW,
  5848. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5849. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5850. }
  5851. }
  5852. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5853. {
  5854. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5855. }
  5856. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5857. {
  5858. u32 i, base = FUNC_ILT_BASE(func);
  5859. for (i = base; i < base + ILT_PER_FUNC; i++)
  5860. bnx2x_ilt_wr(bp, i, 0);
  5861. }
  5862. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5863. {
  5864. int port = BP_PORT(bp);
  5865. int func = BP_FUNC(bp);
  5866. int init_phase = PHASE_PF0 + func;
  5867. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5868. u16 cdu_ilt_start;
  5869. u32 addr, val;
  5870. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5871. int i, main_mem_width, rc;
  5872. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5873. /* FLR cleanup - hmmm */
  5874. if (!CHIP_IS_E1x(bp)) {
  5875. rc = bnx2x_pf_flr_clnup(bp);
  5876. if (rc)
  5877. return rc;
  5878. }
  5879. /* set MSI reconfigure capability */
  5880. if (bp->common.int_block == INT_BLOCK_HC) {
  5881. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5882. val = REG_RD(bp, addr);
  5883. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5884. REG_WR(bp, addr, val);
  5885. }
  5886. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5887. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5888. ilt = BP_ILT(bp);
  5889. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5890. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5891. ilt->lines[cdu_ilt_start + i].page =
  5892. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5893. ilt->lines[cdu_ilt_start + i].page_mapping =
  5894. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5895. /* cdu ilt pages are allocated manually so there's no need to
  5896. set the size */
  5897. }
  5898. bnx2x_ilt_init_op(bp, INITOP_SET);
  5899. #ifdef BCM_CNIC
  5900. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5901. /* T1 hash bits value determines the T1 number of entries */
  5902. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5903. #endif
  5904. #ifndef BCM_CNIC
  5905. /* set NIC mode */
  5906. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5907. #endif /* BCM_CNIC */
  5908. if (!CHIP_IS_E1x(bp)) {
  5909. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5910. /* Turn on a single ISR mode in IGU if driver is going to use
  5911. * INT#x or MSI
  5912. */
  5913. if (!(bp->flags & USING_MSIX_FLAG))
  5914. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5915. /*
  5916. * Timers workaround bug: function init part.
  5917. * Need to wait 20msec after initializing ILT,
  5918. * needed to make sure there are no requests in
  5919. * one of the PXP internal queues with "old" ILT addresses
  5920. */
  5921. msleep(20);
  5922. /*
  5923. * Master enable - Due to WB DMAE writes performed before this
  5924. * register is re-initialized as part of the regular function
  5925. * init
  5926. */
  5927. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5928. /* Enable the function in IGU */
  5929. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5930. }
  5931. bp->dmae_ready = 1;
  5932. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5933. if (!CHIP_IS_E1x(bp))
  5934. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5935. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5936. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5937. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5938. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5939. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5940. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5941. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5942. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5943. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5944. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5945. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5946. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5947. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5948. if (!CHIP_IS_E1x(bp))
  5949. REG_WR(bp, QM_REG_PF_EN, 1);
  5950. if (!CHIP_IS_E1x(bp)) {
  5951. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5952. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5953. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5954. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5955. }
  5956. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5957. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5958. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5959. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5960. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5961. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5962. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5963. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5964. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5965. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5966. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5967. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5968. if (!CHIP_IS_E1x(bp))
  5969. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5970. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5971. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5972. if (!CHIP_IS_E1x(bp))
  5973. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5974. if (IS_MF(bp)) {
  5975. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5976. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5977. }
  5978. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5979. /* HC init per function */
  5980. if (bp->common.int_block == INT_BLOCK_HC) {
  5981. if (CHIP_IS_E1H(bp)) {
  5982. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5983. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5984. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5985. }
  5986. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5987. } else {
  5988. int num_segs, sb_idx, prod_offset;
  5989. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5990. if (!CHIP_IS_E1x(bp)) {
  5991. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5992. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5993. }
  5994. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5995. if (!CHIP_IS_E1x(bp)) {
  5996. int dsb_idx = 0;
  5997. /**
  5998. * Producer memory:
  5999. * E2 mode: address 0-135 match to the mapping memory;
  6000. * 136 - PF0 default prod; 137 - PF1 default prod;
  6001. * 138 - PF2 default prod; 139 - PF3 default prod;
  6002. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6003. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6004. * 144-147 reserved.
  6005. *
  6006. * E1.5 mode - In backward compatible mode;
  6007. * for non default SB; each even line in the memory
  6008. * holds the U producer and each odd line hold
  6009. * the C producer. The first 128 producers are for
  6010. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6011. * producers are for the DSB for each PF.
  6012. * Each PF has five segments: (the order inside each
  6013. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6014. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6015. * 144-147 attn prods;
  6016. */
  6017. /* non-default-status-blocks */
  6018. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6019. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6020. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6021. prod_offset = (bp->igu_base_sb + sb_idx) *
  6022. num_segs;
  6023. for (i = 0; i < num_segs; i++) {
  6024. addr = IGU_REG_PROD_CONS_MEMORY +
  6025. (prod_offset + i) * 4;
  6026. REG_WR(bp, addr, 0);
  6027. }
  6028. /* send consumer update with value 0 */
  6029. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6030. USTORM_ID, 0, IGU_INT_NOP, 1);
  6031. bnx2x_igu_clear_sb(bp,
  6032. bp->igu_base_sb + sb_idx);
  6033. }
  6034. /* default-status-blocks */
  6035. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6036. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6037. if (CHIP_MODE_IS_4_PORT(bp))
  6038. dsb_idx = BP_FUNC(bp);
  6039. else
  6040. dsb_idx = BP_VN(bp);
  6041. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6042. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6043. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6044. /*
  6045. * igu prods come in chunks of E1HVN_MAX (4) -
  6046. * does not matters what is the current chip mode
  6047. */
  6048. for (i = 0; i < (num_segs * E1HVN_MAX);
  6049. i += E1HVN_MAX) {
  6050. addr = IGU_REG_PROD_CONS_MEMORY +
  6051. (prod_offset + i)*4;
  6052. REG_WR(bp, addr, 0);
  6053. }
  6054. /* send consumer update with 0 */
  6055. if (CHIP_INT_MODE_IS_BC(bp)) {
  6056. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6057. USTORM_ID, 0, IGU_INT_NOP, 1);
  6058. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6059. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6060. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6061. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6062. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6063. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6064. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6065. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6066. } else {
  6067. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6068. USTORM_ID, 0, IGU_INT_NOP, 1);
  6069. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6070. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6071. }
  6072. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6073. /* !!! these should become driver const once
  6074. rf-tool supports split-68 const */
  6075. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6076. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6077. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6078. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6079. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6080. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6081. }
  6082. }
  6083. /* Reset PCIE errors for debug */
  6084. REG_WR(bp, 0x2114, 0xffffffff);
  6085. REG_WR(bp, 0x2120, 0xffffffff);
  6086. if (CHIP_IS_E1x(bp)) {
  6087. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6088. main_mem_base = HC_REG_MAIN_MEMORY +
  6089. BP_PORT(bp) * (main_mem_size * 4);
  6090. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6091. main_mem_width = 8;
  6092. val = REG_RD(bp, main_mem_prty_clr);
  6093. if (val)
  6094. DP(NETIF_MSG_HW,
  6095. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6096. val);
  6097. /* Clear "false" parity errors in MSI-X table */
  6098. for (i = main_mem_base;
  6099. i < main_mem_base + main_mem_size * 4;
  6100. i += main_mem_width) {
  6101. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6102. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6103. i, main_mem_width / 4);
  6104. }
  6105. /* Clear HC parity attention */
  6106. REG_RD(bp, main_mem_prty_clr);
  6107. }
  6108. #ifdef BNX2X_STOP_ON_ERROR
  6109. /* Enable STORMs SP logging */
  6110. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6111. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6112. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6113. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6114. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6115. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6116. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6117. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6118. #endif
  6119. bnx2x_phy_probe(&bp->link_params);
  6120. return 0;
  6121. }
  6122. void bnx2x_free_mem(struct bnx2x *bp)
  6123. {
  6124. /* fastpath */
  6125. bnx2x_free_fp_mem(bp);
  6126. /* end of fastpath */
  6127. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6128. sizeof(struct host_sp_status_block));
  6129. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6130. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6131. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6132. sizeof(struct bnx2x_slowpath));
  6133. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  6134. bp->context.size);
  6135. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6136. BNX2X_FREE(bp->ilt->lines);
  6137. #ifdef BCM_CNIC
  6138. if (!CHIP_IS_E1x(bp))
  6139. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6140. sizeof(struct host_hc_status_block_e2));
  6141. else
  6142. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6143. sizeof(struct host_hc_status_block_e1x));
  6144. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6145. #endif
  6146. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6147. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6148. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6149. }
  6150. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6151. {
  6152. int num_groups;
  6153. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6154. /* number of queues for statistics is number of eth queues + FCoE */
  6155. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6156. /* Total number of FW statistics requests =
  6157. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6158. * num of queues
  6159. */
  6160. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6161. /* Request is built from stats_query_header and an array of
  6162. * stats_query_cmd_group each of which contains
  6163. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6164. * configured in the stats_query_header.
  6165. */
  6166. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6167. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6168. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6169. num_groups * sizeof(struct stats_query_cmd_group);
  6170. /* Data for statistics requests + stats_conter
  6171. *
  6172. * stats_counter holds per-STORM counters that are incremented
  6173. * when STORM has finished with the current request.
  6174. *
  6175. * memory for FCoE offloaded statistics are counted anyway,
  6176. * even if they will not be sent.
  6177. */
  6178. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6179. sizeof(struct per_pf_stats) +
  6180. sizeof(struct fcoe_statistics_params) +
  6181. sizeof(struct per_queue_stats) * num_queue_stats +
  6182. sizeof(struct stats_counter);
  6183. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6184. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6185. /* Set shortcuts */
  6186. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6187. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6188. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6189. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6190. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6191. bp->fw_stats_req_sz;
  6192. return 0;
  6193. alloc_mem_err:
  6194. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6195. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6196. BNX2X_ERR("Can't allocate memory\n");
  6197. return -ENOMEM;
  6198. }
  6199. int bnx2x_alloc_mem(struct bnx2x *bp)
  6200. {
  6201. #ifdef BCM_CNIC
  6202. if (!CHIP_IS_E1x(bp))
  6203. /* size = the status block + ramrod buffers */
  6204. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6205. sizeof(struct host_hc_status_block_e2));
  6206. else
  6207. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  6208. sizeof(struct host_hc_status_block_e1x));
  6209. /* allocate searcher T2 table */
  6210. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6211. #endif
  6212. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6213. sizeof(struct host_sp_status_block));
  6214. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6215. sizeof(struct bnx2x_slowpath));
  6216. #ifdef BCM_CNIC
  6217. /* write address to which L5 should insert its values */
  6218. bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
  6219. #endif
  6220. /* Allocated memory for FW statistics */
  6221. if (bnx2x_alloc_fw_stats_mem(bp))
  6222. goto alloc_mem_err;
  6223. bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6224. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  6225. bp->context.size);
  6226. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6227. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6228. goto alloc_mem_err;
  6229. /* Slow path ring */
  6230. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6231. /* EQ */
  6232. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6233. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6234. /* fastpath */
  6235. /* need to be done at the end, since it's self adjusting to amount
  6236. * of memory available for RSS queues
  6237. */
  6238. if (bnx2x_alloc_fp_mem(bp))
  6239. goto alloc_mem_err;
  6240. return 0;
  6241. alloc_mem_err:
  6242. bnx2x_free_mem(bp);
  6243. BNX2X_ERR("Can't allocate memory\n");
  6244. return -ENOMEM;
  6245. }
  6246. /*
  6247. * Init service functions
  6248. */
  6249. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6250. struct bnx2x_vlan_mac_obj *obj, bool set,
  6251. int mac_type, unsigned long *ramrod_flags)
  6252. {
  6253. int rc;
  6254. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6255. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6256. /* Fill general parameters */
  6257. ramrod_param.vlan_mac_obj = obj;
  6258. ramrod_param.ramrod_flags = *ramrod_flags;
  6259. /* Fill a user request section if needed */
  6260. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6261. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6262. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6263. /* Set the command: ADD or DEL */
  6264. if (set)
  6265. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6266. else
  6267. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6268. }
  6269. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6270. if (rc < 0)
  6271. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6272. return rc;
  6273. }
  6274. int bnx2x_del_all_macs(struct bnx2x *bp,
  6275. struct bnx2x_vlan_mac_obj *mac_obj,
  6276. int mac_type, bool wait_for_comp)
  6277. {
  6278. int rc;
  6279. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6280. /* Wait for completion of requested */
  6281. if (wait_for_comp)
  6282. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6283. /* Set the mac type of addresses we want to clear */
  6284. __set_bit(mac_type, &vlan_mac_flags);
  6285. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6286. if (rc < 0)
  6287. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6288. return rc;
  6289. }
  6290. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6291. {
  6292. unsigned long ramrod_flags = 0;
  6293. #ifdef BCM_CNIC
  6294. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6295. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6296. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6297. "Ignoring Zero MAC for STORAGE SD mode\n");
  6298. return 0;
  6299. }
  6300. #endif
  6301. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6302. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6303. /* Eth MAC is set on RSS leading client (fp[0]) */
  6304. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  6305. BNX2X_ETH_MAC, &ramrod_flags);
  6306. }
  6307. int bnx2x_setup_leading(struct bnx2x *bp)
  6308. {
  6309. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6310. }
  6311. /**
  6312. * bnx2x_set_int_mode - configure interrupt mode
  6313. *
  6314. * @bp: driver handle
  6315. *
  6316. * In case of MSI-X it will also try to enable MSI-X.
  6317. */
  6318. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  6319. {
  6320. switch (int_mode) {
  6321. case INT_MODE_MSI:
  6322. bnx2x_enable_msi(bp);
  6323. /* falling through... */
  6324. case INT_MODE_INTx:
  6325. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6326. BNX2X_DEV_INFO("set number of queues to 1\n");
  6327. break;
  6328. default:
  6329. /* Set number of queues for MSI-X mode */
  6330. bnx2x_set_num_queues(bp);
  6331. BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
  6332. /* if we can't use MSI-X we only need one fp,
  6333. * so try to enable MSI-X with the requested number of fp's
  6334. * and fallback to MSI or legacy INTx with one fp
  6335. */
  6336. if (bnx2x_enable_msix(bp) ||
  6337. bp->flags & USING_SINGLE_MSIX_FLAG) {
  6338. /* failed to enable multiple MSI-X */
  6339. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6340. bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
  6341. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6342. /* Try to enable MSI */
  6343. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  6344. !(bp->flags & DISABLE_MSI_FLAG))
  6345. bnx2x_enable_msi(bp);
  6346. }
  6347. break;
  6348. }
  6349. }
  6350. /* must be called prioir to any HW initializations */
  6351. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6352. {
  6353. return L2_ILT_LINES(bp);
  6354. }
  6355. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6356. {
  6357. struct ilt_client_info *ilt_client;
  6358. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6359. u16 line = 0;
  6360. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6361. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6362. /* CDU */
  6363. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6364. ilt_client->client_num = ILT_CLIENT_CDU;
  6365. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6366. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6367. ilt_client->start = line;
  6368. line += bnx2x_cid_ilt_lines(bp);
  6369. #ifdef BCM_CNIC
  6370. line += CNIC_ILT_LINES;
  6371. #endif
  6372. ilt_client->end = line - 1;
  6373. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6374. ilt_client->start,
  6375. ilt_client->end,
  6376. ilt_client->page_size,
  6377. ilt_client->flags,
  6378. ilog2(ilt_client->page_size >> 12));
  6379. /* QM */
  6380. if (QM_INIT(bp->qm_cid_count)) {
  6381. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6382. ilt_client->client_num = ILT_CLIENT_QM;
  6383. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6384. ilt_client->flags = 0;
  6385. ilt_client->start = line;
  6386. /* 4 bytes for each cid */
  6387. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6388. QM_ILT_PAGE_SZ);
  6389. ilt_client->end = line - 1;
  6390. DP(NETIF_MSG_IFUP,
  6391. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6392. ilt_client->start,
  6393. ilt_client->end,
  6394. ilt_client->page_size,
  6395. ilt_client->flags,
  6396. ilog2(ilt_client->page_size >> 12));
  6397. }
  6398. /* SRC */
  6399. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6400. #ifdef BCM_CNIC
  6401. ilt_client->client_num = ILT_CLIENT_SRC;
  6402. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6403. ilt_client->flags = 0;
  6404. ilt_client->start = line;
  6405. line += SRC_ILT_LINES;
  6406. ilt_client->end = line - 1;
  6407. DP(NETIF_MSG_IFUP,
  6408. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6409. ilt_client->start,
  6410. ilt_client->end,
  6411. ilt_client->page_size,
  6412. ilt_client->flags,
  6413. ilog2(ilt_client->page_size >> 12));
  6414. #else
  6415. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6416. #endif
  6417. /* TM */
  6418. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6419. #ifdef BCM_CNIC
  6420. ilt_client->client_num = ILT_CLIENT_TM;
  6421. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6422. ilt_client->flags = 0;
  6423. ilt_client->start = line;
  6424. line += TM_ILT_LINES;
  6425. ilt_client->end = line - 1;
  6426. DP(NETIF_MSG_IFUP,
  6427. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6428. ilt_client->start,
  6429. ilt_client->end,
  6430. ilt_client->page_size,
  6431. ilt_client->flags,
  6432. ilog2(ilt_client->page_size >> 12));
  6433. #else
  6434. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6435. #endif
  6436. BUG_ON(line > ILT_MAX_LINES);
  6437. }
  6438. /**
  6439. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6440. *
  6441. * @bp: driver handle
  6442. * @fp: pointer to fastpath
  6443. * @init_params: pointer to parameters structure
  6444. *
  6445. * parameters configured:
  6446. * - HC configuration
  6447. * - Queue's CDU context
  6448. */
  6449. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6450. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6451. {
  6452. u8 cos;
  6453. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6454. if (!IS_FCOE_FP(fp)) {
  6455. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6456. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6457. /* If HC is supporterd, enable host coalescing in the transition
  6458. * to INIT state.
  6459. */
  6460. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6461. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6462. /* HC rate */
  6463. init_params->rx.hc_rate = bp->rx_ticks ?
  6464. (1000000 / bp->rx_ticks) : 0;
  6465. init_params->tx.hc_rate = bp->tx_ticks ?
  6466. (1000000 / bp->tx_ticks) : 0;
  6467. /* FW SB ID */
  6468. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6469. fp->fw_sb_id;
  6470. /*
  6471. * CQ index among the SB indices: FCoE clients uses the default
  6472. * SB, therefore it's different.
  6473. */
  6474. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6475. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6476. }
  6477. /* set maximum number of COSs supported by this queue */
  6478. init_params->max_cos = fp->max_cos;
  6479. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6480. fp->index, init_params->max_cos);
  6481. /* set the context pointers queue object */
  6482. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
  6483. init_params->cxts[cos] =
  6484. &bp->context.vcxt[fp->txdata[cos].cid].eth;
  6485. }
  6486. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6487. struct bnx2x_queue_state_params *q_params,
  6488. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6489. int tx_index, bool leading)
  6490. {
  6491. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6492. /* Set the command */
  6493. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6494. /* Set tx-only QUEUE flags: don't zero statistics */
  6495. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6496. /* choose the index of the cid to send the slow path on */
  6497. tx_only_params->cid_index = tx_index;
  6498. /* Set general TX_ONLY_SETUP parameters */
  6499. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6500. /* Set Tx TX_ONLY_SETUP parameters */
  6501. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6502. DP(NETIF_MSG_IFUP,
  6503. "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",
  6504. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6505. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6506. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6507. /* send the ramrod */
  6508. return bnx2x_queue_state_change(bp, q_params);
  6509. }
  6510. /**
  6511. * bnx2x_setup_queue - setup queue
  6512. *
  6513. * @bp: driver handle
  6514. * @fp: pointer to fastpath
  6515. * @leading: is leading
  6516. *
  6517. * This function performs 2 steps in a Queue state machine
  6518. * actually: 1) RESET->INIT 2) INIT->SETUP
  6519. */
  6520. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6521. bool leading)
  6522. {
  6523. struct bnx2x_queue_state_params q_params = {NULL};
  6524. struct bnx2x_queue_setup_params *setup_params =
  6525. &q_params.params.setup;
  6526. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6527. &q_params.params.tx_only;
  6528. int rc;
  6529. u8 tx_index;
  6530. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6531. /* reset IGU state skip FCoE L2 queue */
  6532. if (!IS_FCOE_FP(fp))
  6533. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6534. IGU_INT_ENABLE, 0);
  6535. q_params.q_obj = &fp->q_obj;
  6536. /* We want to wait for completion in this context */
  6537. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6538. /* Prepare the INIT parameters */
  6539. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6540. /* Set the command */
  6541. q_params.cmd = BNX2X_Q_CMD_INIT;
  6542. /* Change the state to INIT */
  6543. rc = bnx2x_queue_state_change(bp, &q_params);
  6544. if (rc) {
  6545. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6546. return rc;
  6547. }
  6548. DP(NETIF_MSG_IFUP, "init complete\n");
  6549. /* Now move the Queue to the SETUP state... */
  6550. memset(setup_params, 0, sizeof(*setup_params));
  6551. /* Set QUEUE flags */
  6552. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6553. /* Set general SETUP parameters */
  6554. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6555. FIRST_TX_COS_INDEX);
  6556. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6557. &setup_params->rxq_params);
  6558. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6559. FIRST_TX_COS_INDEX);
  6560. /* Set the command */
  6561. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6562. /* Change the state to SETUP */
  6563. rc = bnx2x_queue_state_change(bp, &q_params);
  6564. if (rc) {
  6565. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6566. return rc;
  6567. }
  6568. /* loop through the relevant tx-only indices */
  6569. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6570. tx_index < fp->max_cos;
  6571. tx_index++) {
  6572. /* prepare and send tx-only ramrod*/
  6573. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6574. tx_only_params, tx_index, leading);
  6575. if (rc) {
  6576. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6577. fp->index, tx_index);
  6578. return rc;
  6579. }
  6580. }
  6581. return rc;
  6582. }
  6583. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6584. {
  6585. struct bnx2x_fastpath *fp = &bp->fp[index];
  6586. struct bnx2x_fp_txdata *txdata;
  6587. struct bnx2x_queue_state_params q_params = {NULL};
  6588. int rc, tx_index;
  6589. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6590. q_params.q_obj = &fp->q_obj;
  6591. /* We want to wait for completion in this context */
  6592. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6593. /* close tx-only connections */
  6594. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6595. tx_index < fp->max_cos;
  6596. tx_index++){
  6597. /* ascertain this is a normal queue*/
  6598. txdata = &fp->txdata[tx_index];
  6599. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6600. txdata->txq_index);
  6601. /* send halt terminate on tx-only connection */
  6602. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6603. memset(&q_params.params.terminate, 0,
  6604. sizeof(q_params.params.terminate));
  6605. q_params.params.terminate.cid_index = tx_index;
  6606. rc = bnx2x_queue_state_change(bp, &q_params);
  6607. if (rc)
  6608. return rc;
  6609. /* send halt terminate on tx-only connection */
  6610. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6611. memset(&q_params.params.cfc_del, 0,
  6612. sizeof(q_params.params.cfc_del));
  6613. q_params.params.cfc_del.cid_index = tx_index;
  6614. rc = bnx2x_queue_state_change(bp, &q_params);
  6615. if (rc)
  6616. return rc;
  6617. }
  6618. /* Stop the primary connection: */
  6619. /* ...halt the connection */
  6620. q_params.cmd = BNX2X_Q_CMD_HALT;
  6621. rc = bnx2x_queue_state_change(bp, &q_params);
  6622. if (rc)
  6623. return rc;
  6624. /* ...terminate the connection */
  6625. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6626. memset(&q_params.params.terminate, 0,
  6627. sizeof(q_params.params.terminate));
  6628. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6629. rc = bnx2x_queue_state_change(bp, &q_params);
  6630. if (rc)
  6631. return rc;
  6632. /* ...delete cfc entry */
  6633. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6634. memset(&q_params.params.cfc_del, 0,
  6635. sizeof(q_params.params.cfc_del));
  6636. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6637. return bnx2x_queue_state_change(bp, &q_params);
  6638. }
  6639. static void bnx2x_reset_func(struct bnx2x *bp)
  6640. {
  6641. int port = BP_PORT(bp);
  6642. int func = BP_FUNC(bp);
  6643. int i;
  6644. /* Disable the function in the FW */
  6645. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6646. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6647. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6648. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6649. /* FP SBs */
  6650. for_each_eth_queue(bp, i) {
  6651. struct bnx2x_fastpath *fp = &bp->fp[i];
  6652. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6653. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6654. SB_DISABLED);
  6655. }
  6656. #ifdef BCM_CNIC
  6657. /* CNIC SB */
  6658. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6659. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6660. SB_DISABLED);
  6661. #endif
  6662. /* SP SB */
  6663. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6664. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6665. SB_DISABLED);
  6666. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6667. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6668. 0);
  6669. /* Configure IGU */
  6670. if (bp->common.int_block == INT_BLOCK_HC) {
  6671. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6672. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6673. } else {
  6674. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6675. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6676. }
  6677. #ifdef BCM_CNIC
  6678. /* Disable Timer scan */
  6679. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6680. /*
  6681. * Wait for at least 10ms and up to 2 second for the timers scan to
  6682. * complete
  6683. */
  6684. for (i = 0; i < 200; i++) {
  6685. msleep(10);
  6686. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6687. break;
  6688. }
  6689. #endif
  6690. /* Clear ILT */
  6691. bnx2x_clear_func_ilt(bp, func);
  6692. /* Timers workaround bug for E2: if this is vnic-3,
  6693. * we need to set the entire ilt range for this timers.
  6694. */
  6695. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6696. struct ilt_client_info ilt_cli;
  6697. /* use dummy TM client */
  6698. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6699. ilt_cli.start = 0;
  6700. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6701. ilt_cli.client_num = ILT_CLIENT_TM;
  6702. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6703. }
  6704. /* this assumes that reset_port() called before reset_func()*/
  6705. if (!CHIP_IS_E1x(bp))
  6706. bnx2x_pf_disable(bp);
  6707. bp->dmae_ready = 0;
  6708. }
  6709. static void bnx2x_reset_port(struct bnx2x *bp)
  6710. {
  6711. int port = BP_PORT(bp);
  6712. u32 val;
  6713. /* Reset physical Link */
  6714. bnx2x__link_reset(bp);
  6715. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6716. /* Do not rcv packets to BRB */
  6717. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6718. /* Do not direct rcv packets that are not for MCP to the BRB */
  6719. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6720. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6721. /* Configure AEU */
  6722. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6723. msleep(100);
  6724. /* Check for BRB port occupancy */
  6725. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6726. if (val)
  6727. DP(NETIF_MSG_IFDOWN,
  6728. "BRB1 is not empty %d blocks are occupied\n", val);
  6729. /* TODO: Close Doorbell port? */
  6730. }
  6731. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6732. {
  6733. struct bnx2x_func_state_params func_params = {NULL};
  6734. /* Prepare parameters for function state transitions */
  6735. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6736. func_params.f_obj = &bp->func_obj;
  6737. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6738. func_params.params.hw_init.load_phase = load_code;
  6739. return bnx2x_func_state_change(bp, &func_params);
  6740. }
  6741. static int bnx2x_func_stop(struct bnx2x *bp)
  6742. {
  6743. struct bnx2x_func_state_params func_params = {NULL};
  6744. int rc;
  6745. /* Prepare parameters for function state transitions */
  6746. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6747. func_params.f_obj = &bp->func_obj;
  6748. func_params.cmd = BNX2X_F_CMD_STOP;
  6749. /*
  6750. * Try to stop the function the 'good way'. If fails (in case
  6751. * of a parity error during bnx2x_chip_cleanup()) and we are
  6752. * not in a debug mode, perform a state transaction in order to
  6753. * enable further HW_RESET transaction.
  6754. */
  6755. rc = bnx2x_func_state_change(bp, &func_params);
  6756. if (rc) {
  6757. #ifdef BNX2X_STOP_ON_ERROR
  6758. return rc;
  6759. #else
  6760. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6761. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6762. return bnx2x_func_state_change(bp, &func_params);
  6763. #endif
  6764. }
  6765. return 0;
  6766. }
  6767. /**
  6768. * bnx2x_send_unload_req - request unload mode from the MCP.
  6769. *
  6770. * @bp: driver handle
  6771. * @unload_mode: requested function's unload mode
  6772. *
  6773. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6774. */
  6775. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6776. {
  6777. u32 reset_code = 0;
  6778. int port = BP_PORT(bp);
  6779. /* Select the UNLOAD request mode */
  6780. if (unload_mode == UNLOAD_NORMAL)
  6781. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6782. else if (bp->flags & NO_WOL_FLAG)
  6783. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6784. else if (bp->wol) {
  6785. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6786. u8 *mac_addr = bp->dev->dev_addr;
  6787. u32 val;
  6788. u16 pmc;
  6789. /* The mac address is written to entries 1-4 to
  6790. * preserve entry 0 which is used by the PMF
  6791. */
  6792. u8 entry = (BP_VN(bp) + 1)*8;
  6793. val = (mac_addr[0] << 8) | mac_addr[1];
  6794. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6795. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6796. (mac_addr[4] << 8) | mac_addr[5];
  6797. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6798. /* Enable the PME and clear the status */
  6799. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6800. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6801. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6802. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6803. } else
  6804. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6805. /* Send the request to the MCP */
  6806. if (!BP_NOMCP(bp))
  6807. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6808. else {
  6809. int path = BP_PATH(bp);
  6810. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6811. path, load_count[path][0], load_count[path][1],
  6812. load_count[path][2]);
  6813. load_count[path][0]--;
  6814. load_count[path][1 + port]--;
  6815. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6816. path, load_count[path][0], load_count[path][1],
  6817. load_count[path][2]);
  6818. if (load_count[path][0] == 0)
  6819. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6820. else if (load_count[path][1 + port] == 0)
  6821. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6822. else
  6823. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6824. }
  6825. return reset_code;
  6826. }
  6827. /**
  6828. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6829. *
  6830. * @bp: driver handle
  6831. */
  6832. void bnx2x_send_unload_done(struct bnx2x *bp)
  6833. {
  6834. /* Report UNLOAD_DONE to MCP */
  6835. if (!BP_NOMCP(bp))
  6836. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6837. }
  6838. static int bnx2x_func_wait_started(struct bnx2x *bp)
  6839. {
  6840. int tout = 50;
  6841. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6842. if (!bp->port.pmf)
  6843. return 0;
  6844. /*
  6845. * (assumption: No Attention from MCP at this stage)
  6846. * PMF probably in the middle of TXdisable/enable transaction
  6847. * 1. Sync IRS for default SB
  6848. * 2. Sync SP queue - this guarantes us that attention handling started
  6849. * 3. Wait, that TXdisable/enable transaction completes
  6850. *
  6851. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6852. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6853. * received complettion for the transaction the state is TX_STOPPED.
  6854. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6855. * transaction.
  6856. */
  6857. /* make sure default SB ISR is done */
  6858. if (msix)
  6859. synchronize_irq(bp->msix_table[0].vector);
  6860. else
  6861. synchronize_irq(bp->pdev->irq);
  6862. flush_workqueue(bnx2x_wq);
  6863. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6864. BNX2X_F_STATE_STARTED && tout--)
  6865. msleep(20);
  6866. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6867. BNX2X_F_STATE_STARTED) {
  6868. #ifdef BNX2X_STOP_ON_ERROR
  6869. BNX2X_ERR("Wrong function state\n");
  6870. return -EBUSY;
  6871. #else
  6872. /*
  6873. * Failed to complete the transaction in a "good way"
  6874. * Force both transactions with CLR bit
  6875. */
  6876. struct bnx2x_func_state_params func_params = {NULL};
  6877. DP(NETIF_MSG_IFDOWN,
  6878. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6879. func_params.f_obj = &bp->func_obj;
  6880. __set_bit(RAMROD_DRV_CLR_ONLY,
  6881. &func_params.ramrod_flags);
  6882. /* STARTED-->TX_ST0PPED */
  6883. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6884. bnx2x_func_state_change(bp, &func_params);
  6885. /* TX_ST0PPED-->STARTED */
  6886. func_params.cmd = BNX2X_F_CMD_TX_START;
  6887. return bnx2x_func_state_change(bp, &func_params);
  6888. #endif
  6889. }
  6890. return 0;
  6891. }
  6892. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6893. {
  6894. int port = BP_PORT(bp);
  6895. int i, rc = 0;
  6896. u8 cos;
  6897. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  6898. u32 reset_code;
  6899. /* Wait until tx fastpath tasks complete */
  6900. for_each_tx_queue(bp, i) {
  6901. struct bnx2x_fastpath *fp = &bp->fp[i];
  6902. for_each_cos_in_tx_queue(fp, cos)
  6903. rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
  6904. #ifdef BNX2X_STOP_ON_ERROR
  6905. if (rc)
  6906. return;
  6907. #endif
  6908. }
  6909. /* Give HW time to discard old tx messages */
  6910. usleep_range(1000, 1000);
  6911. /* Clean all ETH MACs */
  6912. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6913. if (rc < 0)
  6914. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6915. /* Clean up UC list */
  6916. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6917. true);
  6918. if (rc < 0)
  6919. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  6920. rc);
  6921. /* Disable LLH */
  6922. if (!CHIP_IS_E1(bp))
  6923. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6924. /* Set "drop all" (stop Rx).
  6925. * We need to take a netif_addr_lock() here in order to prevent
  6926. * a race between the completion code and this code.
  6927. */
  6928. netif_addr_lock_bh(bp->dev);
  6929. /* Schedule the rx_mode command */
  6930. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6931. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6932. else
  6933. bnx2x_set_storm_rx_mode(bp);
  6934. /* Cleanup multicast configuration */
  6935. rparam.mcast_obj = &bp->mcast_obj;
  6936. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6937. if (rc < 0)
  6938. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6939. netif_addr_unlock_bh(bp->dev);
  6940. /*
  6941. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6942. * this function should perform FUNC, PORT or COMMON HW
  6943. * reset.
  6944. */
  6945. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6946. /*
  6947. * (assumption: No Attention from MCP at this stage)
  6948. * PMF probably in the middle of TXdisable/enable transaction
  6949. */
  6950. rc = bnx2x_func_wait_started(bp);
  6951. if (rc) {
  6952. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6953. #ifdef BNX2X_STOP_ON_ERROR
  6954. return;
  6955. #endif
  6956. }
  6957. /* Close multi and leading connections
  6958. * Completions for ramrods are collected in a synchronous way
  6959. */
  6960. for_each_queue(bp, i)
  6961. if (bnx2x_stop_queue(bp, i))
  6962. #ifdef BNX2X_STOP_ON_ERROR
  6963. return;
  6964. #else
  6965. goto unload_error;
  6966. #endif
  6967. /* If SP settings didn't get completed so far - something
  6968. * very wrong has happen.
  6969. */
  6970. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6971. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6972. #ifndef BNX2X_STOP_ON_ERROR
  6973. unload_error:
  6974. #endif
  6975. rc = bnx2x_func_stop(bp);
  6976. if (rc) {
  6977. BNX2X_ERR("Function stop failed!\n");
  6978. #ifdef BNX2X_STOP_ON_ERROR
  6979. return;
  6980. #endif
  6981. }
  6982. /* Disable HW interrupts, NAPI */
  6983. bnx2x_netif_stop(bp, 1);
  6984. /* Release IRQs */
  6985. bnx2x_free_irq(bp);
  6986. /* Reset the chip */
  6987. rc = bnx2x_reset_hw(bp, reset_code);
  6988. if (rc)
  6989. BNX2X_ERR("HW_RESET failed\n");
  6990. /* Report UNLOAD_DONE to MCP */
  6991. bnx2x_send_unload_done(bp);
  6992. }
  6993. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  6994. {
  6995. u32 val;
  6996. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  6997. if (CHIP_IS_E1(bp)) {
  6998. int port = BP_PORT(bp);
  6999. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7000. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7001. val = REG_RD(bp, addr);
  7002. val &= ~(0x300);
  7003. REG_WR(bp, addr, val);
  7004. } else {
  7005. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7006. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7007. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7008. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7009. }
  7010. }
  7011. /* Close gates #2, #3 and #4: */
  7012. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7013. {
  7014. u32 val;
  7015. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7016. if (!CHIP_IS_E1(bp)) {
  7017. /* #4 */
  7018. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7019. /* #2 */
  7020. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7021. }
  7022. /* #3 */
  7023. if (CHIP_IS_E1x(bp)) {
  7024. /* Prevent interrupts from HC on both ports */
  7025. val = REG_RD(bp, HC_REG_CONFIG_1);
  7026. REG_WR(bp, HC_REG_CONFIG_1,
  7027. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7028. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7029. val = REG_RD(bp, HC_REG_CONFIG_0);
  7030. REG_WR(bp, HC_REG_CONFIG_0,
  7031. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7032. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7033. } else {
  7034. /* Prevent incomming interrupts in IGU */
  7035. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7036. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7037. (!close) ?
  7038. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7039. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7040. }
  7041. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7042. close ? "closing" : "opening");
  7043. mmiowb();
  7044. }
  7045. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7046. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7047. {
  7048. /* Do some magic... */
  7049. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7050. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7051. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7052. }
  7053. /**
  7054. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7055. *
  7056. * @bp: driver handle
  7057. * @magic_val: old value of the `magic' bit.
  7058. */
  7059. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7060. {
  7061. /* Restore the `magic' bit value... */
  7062. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7063. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7064. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7065. }
  7066. /**
  7067. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7068. *
  7069. * @bp: driver handle
  7070. * @magic_val: old value of 'magic' bit.
  7071. *
  7072. * Takes care of CLP configurations.
  7073. */
  7074. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7075. {
  7076. u32 shmem;
  7077. u32 validity_offset;
  7078. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7079. /* Set `magic' bit in order to save MF config */
  7080. if (!CHIP_IS_E1(bp))
  7081. bnx2x_clp_reset_prep(bp, magic_val);
  7082. /* Get shmem offset */
  7083. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7084. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  7085. /* Clear validity map flags */
  7086. if (shmem > 0)
  7087. REG_WR(bp, shmem + validity_offset, 0);
  7088. }
  7089. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7090. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7091. /**
  7092. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7093. *
  7094. * @bp: driver handle
  7095. */
  7096. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7097. {
  7098. /* special handling for emulation and FPGA,
  7099. wait 10 times longer */
  7100. if (CHIP_REV_IS_SLOW(bp))
  7101. msleep(MCP_ONE_TIMEOUT*10);
  7102. else
  7103. msleep(MCP_ONE_TIMEOUT);
  7104. }
  7105. /*
  7106. * initializes bp->common.shmem_base and waits for validity signature to appear
  7107. */
  7108. static int bnx2x_init_shmem(struct bnx2x *bp)
  7109. {
  7110. int cnt = 0;
  7111. u32 val = 0;
  7112. do {
  7113. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7114. if (bp->common.shmem_base) {
  7115. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7116. if (val & SHR_MEM_VALIDITY_MB)
  7117. return 0;
  7118. }
  7119. bnx2x_mcp_wait_one(bp);
  7120. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7121. BNX2X_ERR("BAD MCP validity signature\n");
  7122. return -ENODEV;
  7123. }
  7124. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7125. {
  7126. int rc = bnx2x_init_shmem(bp);
  7127. /* Restore the `magic' bit value */
  7128. if (!CHIP_IS_E1(bp))
  7129. bnx2x_clp_reset_done(bp, magic_val);
  7130. return rc;
  7131. }
  7132. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7133. {
  7134. if (!CHIP_IS_E1(bp)) {
  7135. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7136. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7137. mmiowb();
  7138. }
  7139. }
  7140. /*
  7141. * Reset the whole chip except for:
  7142. * - PCIE core
  7143. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7144. * one reset bit)
  7145. * - IGU
  7146. * - MISC (including AEU)
  7147. * - GRC
  7148. * - RBCN, RBCP
  7149. */
  7150. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7151. {
  7152. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7153. u32 global_bits2, stay_reset2;
  7154. /*
  7155. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7156. * (per chip) blocks.
  7157. */
  7158. global_bits2 =
  7159. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7160. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7161. /* Don't reset the following blocks */
  7162. not_reset_mask1 =
  7163. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7164. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7165. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7166. not_reset_mask2 =
  7167. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7168. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7169. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7170. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7171. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7172. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7173. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7174. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7175. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7176. MISC_REGISTERS_RESET_REG_2_PGLC;
  7177. /*
  7178. * Keep the following blocks in reset:
  7179. * - all xxMACs are handled by the bnx2x_link code.
  7180. */
  7181. stay_reset2 =
  7182. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7183. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7184. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7185. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7186. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7187. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  7188. MISC_REGISTERS_RESET_REG_2_XMAC |
  7189. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7190. /* Full reset masks according to the chip */
  7191. reset_mask1 = 0xffffffff;
  7192. if (CHIP_IS_E1(bp))
  7193. reset_mask2 = 0xffff;
  7194. else if (CHIP_IS_E1H(bp))
  7195. reset_mask2 = 0x1ffff;
  7196. else if (CHIP_IS_E2(bp))
  7197. reset_mask2 = 0xfffff;
  7198. else /* CHIP_IS_E3 */
  7199. reset_mask2 = 0x3ffffff;
  7200. /* Don't reset global blocks unless we need to */
  7201. if (!global)
  7202. reset_mask2 &= ~global_bits2;
  7203. /*
  7204. * In case of attention in the QM, we need to reset PXP
  7205. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7206. * because otherwise QM reset would release 'close the gates' shortly
  7207. * before resetting the PXP, then the PSWRQ would send a write
  7208. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7209. * read the payload data from PSWWR, but PSWWR would not
  7210. * respond. The write queue in PGLUE would stuck, dmae commands
  7211. * would not return. Therefore it's important to reset the second
  7212. * reset register (containing the
  7213. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7214. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7215. * bit).
  7216. */
  7217. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7218. reset_mask2 & (~not_reset_mask2));
  7219. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7220. reset_mask1 & (~not_reset_mask1));
  7221. barrier();
  7222. mmiowb();
  7223. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7224. reset_mask2 & (~stay_reset2));
  7225. barrier();
  7226. mmiowb();
  7227. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7228. mmiowb();
  7229. }
  7230. /**
  7231. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7232. * It should get cleared in no more than 1s.
  7233. *
  7234. * @bp: driver handle
  7235. *
  7236. * It should get cleared in no more than 1s. Returns 0 if
  7237. * pending writes bit gets cleared.
  7238. */
  7239. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7240. {
  7241. u32 cnt = 1000;
  7242. u32 pend_bits = 0;
  7243. do {
  7244. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7245. if (pend_bits == 0)
  7246. break;
  7247. usleep_range(1000, 1000);
  7248. } while (cnt-- > 0);
  7249. if (cnt <= 0) {
  7250. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7251. pend_bits);
  7252. return -EBUSY;
  7253. }
  7254. return 0;
  7255. }
  7256. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7257. {
  7258. int cnt = 1000;
  7259. u32 val = 0;
  7260. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7261. /* Empty the Tetris buffer, wait for 1s */
  7262. do {
  7263. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7264. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7265. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7266. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7267. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7268. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7269. ((port_is_idle_0 & 0x1) == 0x1) &&
  7270. ((port_is_idle_1 & 0x1) == 0x1) &&
  7271. (pgl_exp_rom2 == 0xffffffff))
  7272. break;
  7273. usleep_range(1000, 1000);
  7274. } while (cnt-- > 0);
  7275. if (cnt <= 0) {
  7276. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7277. 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",
  7278. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7279. pgl_exp_rom2);
  7280. return -EAGAIN;
  7281. }
  7282. barrier();
  7283. /* Close gates #2, #3 and #4 */
  7284. bnx2x_set_234_gates(bp, true);
  7285. /* Poll for IGU VQs for 57712 and newer chips */
  7286. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7287. return -EAGAIN;
  7288. /* TBD: Indicate that "process kill" is in progress to MCP */
  7289. /* Clear "unprepared" bit */
  7290. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7291. barrier();
  7292. /* Make sure all is written to the chip before the reset */
  7293. mmiowb();
  7294. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7295. * PSWHST, GRC and PSWRD Tetris buffer.
  7296. */
  7297. usleep_range(1000, 1000);
  7298. /* Prepare to chip reset: */
  7299. /* MCP */
  7300. if (global)
  7301. bnx2x_reset_mcp_prep(bp, &val);
  7302. /* PXP */
  7303. bnx2x_pxp_prep(bp);
  7304. barrier();
  7305. /* reset the chip */
  7306. bnx2x_process_kill_chip_reset(bp, global);
  7307. barrier();
  7308. /* Recover after reset: */
  7309. /* MCP */
  7310. if (global && bnx2x_reset_mcp_comp(bp, val))
  7311. return -EAGAIN;
  7312. /* TBD: Add resetting the NO_MCP mode DB here */
  7313. /* PXP */
  7314. bnx2x_pxp_prep(bp);
  7315. /* Open the gates #2, #3 and #4 */
  7316. bnx2x_set_234_gates(bp, false);
  7317. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7318. * reset state, re-enable attentions. */
  7319. return 0;
  7320. }
  7321. int bnx2x_leader_reset(struct bnx2x *bp)
  7322. {
  7323. int rc = 0;
  7324. bool global = bnx2x_reset_is_global(bp);
  7325. u32 load_code;
  7326. /* if not going to reset MCP - load "fake" driver to reset HW while
  7327. * driver is owner of the HW
  7328. */
  7329. if (!global && !BP_NOMCP(bp)) {
  7330. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  7331. if (!load_code) {
  7332. BNX2X_ERR("MCP response failure, aborting\n");
  7333. rc = -EAGAIN;
  7334. goto exit_leader_reset;
  7335. }
  7336. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7337. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7338. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7339. rc = -EAGAIN;
  7340. goto exit_leader_reset2;
  7341. }
  7342. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7343. if (!load_code) {
  7344. BNX2X_ERR("MCP response failure, aborting\n");
  7345. rc = -EAGAIN;
  7346. goto exit_leader_reset2;
  7347. }
  7348. }
  7349. /* Try to recover after the failure */
  7350. if (bnx2x_process_kill(bp, global)) {
  7351. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7352. BP_PATH(bp));
  7353. rc = -EAGAIN;
  7354. goto exit_leader_reset2;
  7355. }
  7356. /*
  7357. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7358. * state.
  7359. */
  7360. bnx2x_set_reset_done(bp);
  7361. if (global)
  7362. bnx2x_clear_reset_global(bp);
  7363. exit_leader_reset2:
  7364. /* unload "fake driver" if it was loaded */
  7365. if (!global && !BP_NOMCP(bp)) {
  7366. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7367. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7368. }
  7369. exit_leader_reset:
  7370. bp->is_leader = 0;
  7371. bnx2x_release_leader_lock(bp);
  7372. smp_mb();
  7373. return rc;
  7374. }
  7375. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7376. {
  7377. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7378. /* Disconnect this device */
  7379. netif_device_detach(bp->dev);
  7380. /*
  7381. * Block ifup for all function on this engine until "process kill"
  7382. * or power cycle.
  7383. */
  7384. bnx2x_set_reset_in_progress(bp);
  7385. /* Shut down the power */
  7386. bnx2x_set_power_state(bp, PCI_D3hot);
  7387. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7388. smp_mb();
  7389. }
  7390. /*
  7391. * Assumption: runs under rtnl lock. This together with the fact
  7392. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7393. * will never be called when netif_running(bp->dev) is false.
  7394. */
  7395. static void bnx2x_parity_recover(struct bnx2x *bp)
  7396. {
  7397. bool global = false;
  7398. u32 error_recovered, error_unrecovered;
  7399. bool is_parity;
  7400. DP(NETIF_MSG_HW, "Handling parity\n");
  7401. while (1) {
  7402. switch (bp->recovery_state) {
  7403. case BNX2X_RECOVERY_INIT:
  7404. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7405. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7406. WARN_ON(!is_parity);
  7407. /* Try to get a LEADER_LOCK HW lock */
  7408. if (bnx2x_trylock_leader_lock(bp)) {
  7409. bnx2x_set_reset_in_progress(bp);
  7410. /*
  7411. * Check if there is a global attention and if
  7412. * there was a global attention, set the global
  7413. * reset bit.
  7414. */
  7415. if (global)
  7416. bnx2x_set_reset_global(bp);
  7417. bp->is_leader = 1;
  7418. }
  7419. /* Stop the driver */
  7420. /* If interface has been removed - break */
  7421. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  7422. return;
  7423. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7424. /* Ensure "is_leader", MCP command sequence and
  7425. * "recovery_state" update values are seen on other
  7426. * CPUs.
  7427. */
  7428. smp_mb();
  7429. break;
  7430. case BNX2X_RECOVERY_WAIT:
  7431. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7432. if (bp->is_leader) {
  7433. int other_engine = BP_PATH(bp) ? 0 : 1;
  7434. bool other_load_status =
  7435. bnx2x_get_load_status(bp, other_engine);
  7436. bool load_status =
  7437. bnx2x_get_load_status(bp, BP_PATH(bp));
  7438. global = bnx2x_reset_is_global(bp);
  7439. /*
  7440. * In case of a parity in a global block, let
  7441. * the first leader that performs a
  7442. * leader_reset() reset the global blocks in
  7443. * order to clear global attentions. Otherwise
  7444. * the the gates will remain closed for that
  7445. * engine.
  7446. */
  7447. if (load_status ||
  7448. (global && other_load_status)) {
  7449. /* Wait until all other functions get
  7450. * down.
  7451. */
  7452. schedule_delayed_work(&bp->sp_rtnl_task,
  7453. HZ/10);
  7454. return;
  7455. } else {
  7456. /* If all other functions got down -
  7457. * try to bring the chip back to
  7458. * normal. In any case it's an exit
  7459. * point for a leader.
  7460. */
  7461. if (bnx2x_leader_reset(bp)) {
  7462. bnx2x_recovery_failed(bp);
  7463. return;
  7464. }
  7465. /* If we are here, means that the
  7466. * leader has succeeded and doesn't
  7467. * want to be a leader any more. Try
  7468. * to continue as a none-leader.
  7469. */
  7470. break;
  7471. }
  7472. } else { /* non-leader */
  7473. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7474. /* Try to get a LEADER_LOCK HW lock as
  7475. * long as a former leader may have
  7476. * been unloaded by the user or
  7477. * released a leadership by another
  7478. * reason.
  7479. */
  7480. if (bnx2x_trylock_leader_lock(bp)) {
  7481. /* I'm a leader now! Restart a
  7482. * switch case.
  7483. */
  7484. bp->is_leader = 1;
  7485. break;
  7486. }
  7487. schedule_delayed_work(&bp->sp_rtnl_task,
  7488. HZ/10);
  7489. return;
  7490. } else {
  7491. /*
  7492. * If there was a global attention, wait
  7493. * for it to be cleared.
  7494. */
  7495. if (bnx2x_reset_is_global(bp)) {
  7496. schedule_delayed_work(
  7497. &bp->sp_rtnl_task,
  7498. HZ/10);
  7499. return;
  7500. }
  7501. error_recovered =
  7502. bp->eth_stats.recoverable_error;
  7503. error_unrecovered =
  7504. bp->eth_stats.unrecoverable_error;
  7505. bp->recovery_state =
  7506. BNX2X_RECOVERY_NIC_LOADING;
  7507. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7508. error_unrecovered++;
  7509. netdev_err(bp->dev,
  7510. "Recovery failed. Power cycle needed\n");
  7511. /* Disconnect this device */
  7512. netif_device_detach(bp->dev);
  7513. /* Shut down the power */
  7514. bnx2x_set_power_state(
  7515. bp, PCI_D3hot);
  7516. smp_mb();
  7517. } else {
  7518. bp->recovery_state =
  7519. BNX2X_RECOVERY_DONE;
  7520. error_recovered++;
  7521. smp_mb();
  7522. }
  7523. bp->eth_stats.recoverable_error =
  7524. error_recovered;
  7525. bp->eth_stats.unrecoverable_error =
  7526. error_unrecovered;
  7527. return;
  7528. }
  7529. }
  7530. default:
  7531. return;
  7532. }
  7533. }
  7534. }
  7535. static int bnx2x_close(struct net_device *dev);
  7536. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7537. * scheduled on a general queue in order to prevent a dead lock.
  7538. */
  7539. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7540. {
  7541. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7542. rtnl_lock();
  7543. if (!netif_running(bp->dev))
  7544. goto sp_rtnl_exit;
  7545. /* if stop on error is defined no recovery flows should be executed */
  7546. #ifdef BNX2X_STOP_ON_ERROR
  7547. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7548. "you will need to reboot when done\n");
  7549. goto sp_rtnl_not_reset;
  7550. #endif
  7551. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7552. /*
  7553. * Clear all pending SP commands as we are going to reset the
  7554. * function anyway.
  7555. */
  7556. bp->sp_rtnl_state = 0;
  7557. smp_mb();
  7558. bnx2x_parity_recover(bp);
  7559. goto sp_rtnl_exit;
  7560. }
  7561. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7562. /*
  7563. * Clear all pending SP commands as we are going to reset the
  7564. * function anyway.
  7565. */
  7566. bp->sp_rtnl_state = 0;
  7567. smp_mb();
  7568. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7569. bnx2x_nic_load(bp, LOAD_NORMAL);
  7570. goto sp_rtnl_exit;
  7571. }
  7572. #ifdef BNX2X_STOP_ON_ERROR
  7573. sp_rtnl_not_reset:
  7574. #endif
  7575. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7576. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7577. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7578. bnx2x_after_function_update(bp);
  7579. /*
  7580. * in case of fan failure we need to reset id if the "stop on error"
  7581. * debug flag is set, since we trying to prevent permanent overheating
  7582. * damage
  7583. */
  7584. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7585. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7586. netif_device_detach(bp->dev);
  7587. bnx2x_close(bp->dev);
  7588. }
  7589. sp_rtnl_exit:
  7590. rtnl_unlock();
  7591. }
  7592. /* end of nic load/unload */
  7593. static void bnx2x_period_task(struct work_struct *work)
  7594. {
  7595. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7596. if (!netif_running(bp->dev))
  7597. goto period_task_exit;
  7598. if (CHIP_REV_IS_SLOW(bp)) {
  7599. BNX2X_ERR("period task called on emulation, ignoring\n");
  7600. goto period_task_exit;
  7601. }
  7602. bnx2x_acquire_phy_lock(bp);
  7603. /*
  7604. * The barrier is needed to ensure the ordering between the writing to
  7605. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7606. * the reading here.
  7607. */
  7608. smp_mb();
  7609. if (bp->port.pmf) {
  7610. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7611. /* Re-queue task in 1 sec */
  7612. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7613. }
  7614. bnx2x_release_phy_lock(bp);
  7615. period_task_exit:
  7616. return;
  7617. }
  7618. /*
  7619. * Init service functions
  7620. */
  7621. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7622. {
  7623. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7624. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7625. return base + (BP_ABS_FUNC(bp)) * stride;
  7626. }
  7627. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7628. {
  7629. u32 reg = bnx2x_get_pretend_reg(bp);
  7630. /* Flush all outstanding writes */
  7631. mmiowb();
  7632. /* Pretend to be function 0 */
  7633. REG_WR(bp, reg, 0);
  7634. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7635. /* From now we are in the "like-E1" mode */
  7636. bnx2x_int_disable(bp);
  7637. /* Flush all outstanding writes */
  7638. mmiowb();
  7639. /* Restore the original function */
  7640. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7641. REG_RD(bp, reg);
  7642. }
  7643. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7644. {
  7645. if (CHIP_IS_E1(bp))
  7646. bnx2x_int_disable(bp);
  7647. else
  7648. bnx2x_undi_int_disable_e1h(bp);
  7649. }
  7650. static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7651. {
  7652. u32 val, base_addr, offset, mask, reset_reg;
  7653. bool mac_stopped = false;
  7654. u8 port = BP_PORT(bp);
  7655. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7656. if (!CHIP_IS_E3(bp)) {
  7657. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7658. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7659. if ((mask & reset_reg) && val) {
  7660. u32 wb_data[2];
  7661. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7662. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7663. : NIG_REG_INGRESS_BMAC0_MEM;
  7664. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7665. : BIGMAC_REGISTER_BMAC_CONTROL;
  7666. /*
  7667. * use rd/wr since we cannot use dmae. This is safe
  7668. * since MCP won't access the bus due to the request
  7669. * to unload, and no function on the path can be
  7670. * loaded at this time.
  7671. */
  7672. wb_data[0] = REG_RD(bp, base_addr + offset);
  7673. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7674. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7675. REG_WR(bp, base_addr + offset, wb_data[0]);
  7676. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7677. }
  7678. BNX2X_DEV_INFO("Disable emac Rx\n");
  7679. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7680. mac_stopped = true;
  7681. } else {
  7682. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7683. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7684. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7685. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7686. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7687. val & ~(1 << 1));
  7688. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7689. val | (1 << 1));
  7690. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7691. mac_stopped = true;
  7692. }
  7693. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7694. if (mask & reset_reg) {
  7695. BNX2X_DEV_INFO("Disable umac Rx\n");
  7696. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7697. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7698. mac_stopped = true;
  7699. }
  7700. }
  7701. if (mac_stopped)
  7702. msleep(20);
  7703. }
  7704. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7705. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7706. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7707. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7708. static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
  7709. u8 inc)
  7710. {
  7711. u16 rcq, bd;
  7712. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7713. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7714. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7715. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7716. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7717. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7718. port, bd, rcq);
  7719. }
  7720. static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
  7721. {
  7722. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7723. if (!rc) {
  7724. BNX2X_ERR("MCP response failure, aborting\n");
  7725. return -EBUSY;
  7726. }
  7727. return 0;
  7728. }
  7729. static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7730. {
  7731. struct bnx2x_prev_path_list *tmp_list;
  7732. int rc = false;
  7733. if (down_trylock(&bnx2x_prev_sem))
  7734. return false;
  7735. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7736. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7737. bp->pdev->bus->number == tmp_list->bus &&
  7738. BP_PATH(bp) == tmp_list->path) {
  7739. rc = true;
  7740. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7741. BP_PATH(bp));
  7742. break;
  7743. }
  7744. }
  7745. up(&bnx2x_prev_sem);
  7746. return rc;
  7747. }
  7748. static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
  7749. {
  7750. struct bnx2x_prev_path_list *tmp_list;
  7751. int rc;
  7752. tmp_list = (struct bnx2x_prev_path_list *)
  7753. kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7754. if (!tmp_list) {
  7755. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7756. return -ENOMEM;
  7757. }
  7758. tmp_list->bus = bp->pdev->bus->number;
  7759. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7760. tmp_list->path = BP_PATH(bp);
  7761. rc = down_interruptible(&bnx2x_prev_sem);
  7762. if (rc) {
  7763. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7764. kfree(tmp_list);
  7765. } else {
  7766. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7767. BP_PATH(bp));
  7768. list_add(&tmp_list->list, &bnx2x_prev_list);
  7769. up(&bnx2x_prev_sem);
  7770. }
  7771. return rc;
  7772. }
  7773. static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
  7774. {
  7775. int pos;
  7776. u32 cap;
  7777. struct pci_dev *dev = bp->pdev;
  7778. pos = pci_pcie_cap(dev);
  7779. if (!pos)
  7780. return false;
  7781. pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
  7782. if (!(cap & PCI_EXP_DEVCAP_FLR))
  7783. return false;
  7784. return true;
  7785. }
  7786. static int __devinit bnx2x_do_flr(struct bnx2x *bp)
  7787. {
  7788. int i, pos;
  7789. u16 status;
  7790. struct pci_dev *dev = bp->pdev;
  7791. /* probe the capability first */
  7792. if (bnx2x_can_flr(bp))
  7793. return -ENOTTY;
  7794. pos = pci_pcie_cap(dev);
  7795. if (!pos)
  7796. return -ENOTTY;
  7797. /* Wait for Transaction Pending bit clean */
  7798. for (i = 0; i < 4; i++) {
  7799. if (i)
  7800. msleep((1 << (i - 1)) * 100);
  7801. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  7802. if (!(status & PCI_EXP_DEVSTA_TRPND))
  7803. goto clear;
  7804. }
  7805. dev_err(&dev->dev,
  7806. "transaction is not cleared; proceeding with reset anyway\n");
  7807. clear:
  7808. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  7809. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  7810. bp->common.bc_ver);
  7811. return -EINVAL;
  7812. }
  7813. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  7814. return 0;
  7815. }
  7816. static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  7817. {
  7818. int rc;
  7819. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  7820. /* Test if previous unload process was already finished for this path */
  7821. if (bnx2x_prev_is_path_marked(bp))
  7822. return bnx2x_prev_mcp_done(bp);
  7823. /* If function has FLR capabilities, and existing FW version matches
  7824. * the one required, then FLR will be sufficient to clean any residue
  7825. * left by previous driver
  7826. */
  7827. if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
  7828. return bnx2x_do_flr(bp);
  7829. /* Close the MCP request, return failure*/
  7830. rc = bnx2x_prev_mcp_done(bp);
  7831. if (!rc)
  7832. rc = BNX2X_PREV_WAIT_NEEDED;
  7833. return rc;
  7834. }
  7835. static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
  7836. {
  7837. u32 reset_reg, tmp_reg = 0, rc;
  7838. /* It is possible a previous function received 'common' answer,
  7839. * but hasn't loaded yet, therefore creating a scenario of
  7840. * multiple functions receiving 'common' on the same path.
  7841. */
  7842. BNX2X_DEV_INFO("Common unload Flow\n");
  7843. if (bnx2x_prev_is_path_marked(bp))
  7844. return bnx2x_prev_mcp_done(bp);
  7845. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7846. /* Reset should be performed after BRB is emptied */
  7847. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  7848. u32 timer_count = 1000;
  7849. bool prev_undi = false;
  7850. /* Close the MAC Rx to prevent BRB from filling up */
  7851. bnx2x_prev_unload_close_mac(bp);
  7852. /* Check if the UNDI driver was previously loaded
  7853. * UNDI driver initializes CID offset for normal bell to 0x7
  7854. */
  7855. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7856. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  7857. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7858. if (tmp_reg == 0x7) {
  7859. BNX2X_DEV_INFO("UNDI previously loaded\n");
  7860. prev_undi = true;
  7861. /* clear the UNDI indication */
  7862. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7863. }
  7864. }
  7865. /* wait until BRB is empty */
  7866. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7867. while (timer_count) {
  7868. u32 prev_brb = tmp_reg;
  7869. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7870. if (!tmp_reg)
  7871. break;
  7872. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  7873. /* reset timer as long as BRB actually gets emptied */
  7874. if (prev_brb > tmp_reg)
  7875. timer_count = 1000;
  7876. else
  7877. timer_count--;
  7878. /* If UNDI resides in memory, manually increment it */
  7879. if (prev_undi)
  7880. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  7881. udelay(10);
  7882. }
  7883. if (!timer_count)
  7884. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  7885. }
  7886. /* No packets are in the pipeline, path is ready for reset */
  7887. bnx2x_reset_common(bp);
  7888. rc = bnx2x_prev_mark_path(bp);
  7889. if (rc) {
  7890. bnx2x_prev_mcp_done(bp);
  7891. return rc;
  7892. }
  7893. return bnx2x_prev_mcp_done(bp);
  7894. }
  7895. static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
  7896. {
  7897. int time_counter = 10;
  7898. u32 rc, fw, hw_lock_reg, hw_lock_val;
  7899. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  7900. /* Release previously held locks */
  7901. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  7902. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  7903. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  7904. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  7905. if (hw_lock_val) {
  7906. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  7907. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  7908. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7909. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  7910. }
  7911. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  7912. REG_WR(bp, hw_lock_reg, 0xffffffff);
  7913. } else
  7914. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  7915. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  7916. BNX2X_DEV_INFO("Release previously held alr\n");
  7917. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  7918. }
  7919. do {
  7920. /* Lock MCP using an unload request */
  7921. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  7922. if (!fw) {
  7923. BNX2X_ERR("MCP response failure, aborting\n");
  7924. rc = -EBUSY;
  7925. break;
  7926. }
  7927. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7928. rc = bnx2x_prev_unload_common(bp);
  7929. break;
  7930. }
  7931. /* non-common reply from MCP night require looping */
  7932. rc = bnx2x_prev_unload_uncommon(bp);
  7933. if (rc != BNX2X_PREV_WAIT_NEEDED)
  7934. break;
  7935. msleep(20);
  7936. } while (--time_counter);
  7937. if (!time_counter || rc) {
  7938. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  7939. rc = -EBUSY;
  7940. }
  7941. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  7942. return rc;
  7943. }
  7944. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  7945. {
  7946. u32 val, val2, val3, val4, id, boot_mode;
  7947. u16 pmc;
  7948. /* Get the chip revision id and number. */
  7949. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  7950. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  7951. id = ((val & 0xffff) << 16);
  7952. val = REG_RD(bp, MISC_REG_CHIP_REV);
  7953. id |= ((val & 0xf) << 12);
  7954. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  7955. id |= ((val & 0xff) << 4);
  7956. val = REG_RD(bp, MISC_REG_BOND_ID);
  7957. id |= (val & 0xf);
  7958. bp->common.chip_id = id;
  7959. /* force 57811 according to MISC register */
  7960. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  7961. if (CHIP_IS_57810(bp))
  7962. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  7963. (bp->common.chip_id & 0x0000FFFF);
  7964. else if (CHIP_IS_57810_MF(bp))
  7965. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  7966. (bp->common.chip_id & 0x0000FFFF);
  7967. bp->common.chip_id |= 0x1;
  7968. }
  7969. /* Set doorbell size */
  7970. bp->db_size = (1 << BNX2X_DB_SHIFT);
  7971. if (!CHIP_IS_E1x(bp)) {
  7972. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  7973. if ((val & 1) == 0)
  7974. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  7975. else
  7976. val = (val >> 1) & 1;
  7977. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  7978. "2_PORT_MODE");
  7979. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  7980. CHIP_2_PORT_MODE;
  7981. if (CHIP_MODE_IS_4_PORT(bp))
  7982. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  7983. else
  7984. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  7985. } else {
  7986. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  7987. bp->pfid = bp->pf_num; /* 0..7 */
  7988. }
  7989. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  7990. bp->link_params.chip_id = bp->common.chip_id;
  7991. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  7992. val = (REG_RD(bp, 0x2874) & 0x55);
  7993. if ((bp->common.chip_id & 0x1) ||
  7994. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  7995. bp->flags |= ONE_PORT_FLAG;
  7996. BNX2X_DEV_INFO("single port device\n");
  7997. }
  7998. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  7999. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8000. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8001. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8002. bp->common.flash_size, bp->common.flash_size);
  8003. bnx2x_init_shmem(bp);
  8004. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8005. MISC_REG_GENERIC_CR_1 :
  8006. MISC_REG_GENERIC_CR_0));
  8007. bp->link_params.shmem_base = bp->common.shmem_base;
  8008. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8009. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8010. bp->common.shmem_base, bp->common.shmem2_base);
  8011. if (!bp->common.shmem_base) {
  8012. BNX2X_DEV_INFO("MCP not active\n");
  8013. bp->flags |= NO_MCP_FLAG;
  8014. return;
  8015. }
  8016. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8017. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8018. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8019. SHARED_HW_CFG_LED_MODE_MASK) >>
  8020. SHARED_HW_CFG_LED_MODE_SHIFT);
  8021. bp->link_params.feature_config_flags = 0;
  8022. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8023. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8024. bp->link_params.feature_config_flags |=
  8025. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8026. else
  8027. bp->link_params.feature_config_flags &=
  8028. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8029. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8030. bp->common.bc_ver = val;
  8031. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8032. if (val < BNX2X_BC_VER) {
  8033. /* for now only warn
  8034. * later we might need to enforce this */
  8035. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8036. BNX2X_BC_VER, val);
  8037. }
  8038. bp->link_params.feature_config_flags |=
  8039. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8040. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8041. bp->link_params.feature_config_flags |=
  8042. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8043. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8044. bp->link_params.feature_config_flags |=
  8045. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8046. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8047. bp->link_params.feature_config_flags |=
  8048. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8049. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8050. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8051. BC_SUPPORTS_PFC_STATS : 0;
  8052. boot_mode = SHMEM_RD(bp,
  8053. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8054. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8055. switch (boot_mode) {
  8056. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8057. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8058. break;
  8059. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8060. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8061. break;
  8062. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8063. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8064. break;
  8065. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8066. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8067. break;
  8068. }
  8069. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8070. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8071. BNX2X_DEV_INFO("%sWoL capable\n",
  8072. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8073. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8074. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8075. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8076. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8077. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8078. val, val2, val3, val4);
  8079. }
  8080. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8081. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8082. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8083. {
  8084. int pfid = BP_FUNC(bp);
  8085. int igu_sb_id;
  8086. u32 val;
  8087. u8 fid, igu_sb_cnt = 0;
  8088. bp->igu_base_sb = 0xff;
  8089. if (CHIP_INT_MODE_IS_BC(bp)) {
  8090. int vn = BP_VN(bp);
  8091. igu_sb_cnt = bp->igu_sb_cnt;
  8092. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8093. FP_SB_MAX_E1x;
  8094. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8095. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8096. return;
  8097. }
  8098. /* IGU in normal mode - read CAM */
  8099. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8100. igu_sb_id++) {
  8101. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8102. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8103. continue;
  8104. fid = IGU_FID(val);
  8105. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8106. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8107. continue;
  8108. if (IGU_VEC(val) == 0)
  8109. /* default status block */
  8110. bp->igu_dsb_id = igu_sb_id;
  8111. else {
  8112. if (bp->igu_base_sb == 0xff)
  8113. bp->igu_base_sb = igu_sb_id;
  8114. igu_sb_cnt++;
  8115. }
  8116. }
  8117. }
  8118. #ifdef CONFIG_PCI_MSI
  8119. /*
  8120. * It's expected that number of CAM entries for this functions is equal
  8121. * to the number evaluated based on the MSI-X table size. We want a
  8122. * harsh warning if these values are different!
  8123. */
  8124. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  8125. #endif
  8126. if (igu_sb_cnt == 0)
  8127. BNX2X_ERR("CAM configuration error\n");
  8128. }
  8129. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  8130. u32 switch_cfg)
  8131. {
  8132. int cfg_size = 0, idx, port = BP_PORT(bp);
  8133. /* Aggregation of supported attributes of all external phys */
  8134. bp->port.supported[0] = 0;
  8135. bp->port.supported[1] = 0;
  8136. switch (bp->link_params.num_phys) {
  8137. case 1:
  8138. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8139. cfg_size = 1;
  8140. break;
  8141. case 2:
  8142. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8143. cfg_size = 1;
  8144. break;
  8145. case 3:
  8146. if (bp->link_params.multi_phy_config &
  8147. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8148. bp->port.supported[1] =
  8149. bp->link_params.phy[EXT_PHY1].supported;
  8150. bp->port.supported[0] =
  8151. bp->link_params.phy[EXT_PHY2].supported;
  8152. } else {
  8153. bp->port.supported[0] =
  8154. bp->link_params.phy[EXT_PHY1].supported;
  8155. bp->port.supported[1] =
  8156. bp->link_params.phy[EXT_PHY2].supported;
  8157. }
  8158. cfg_size = 2;
  8159. break;
  8160. }
  8161. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8162. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8163. SHMEM_RD(bp,
  8164. dev_info.port_hw_config[port].external_phy_config),
  8165. SHMEM_RD(bp,
  8166. dev_info.port_hw_config[port].external_phy_config2));
  8167. return;
  8168. }
  8169. if (CHIP_IS_E3(bp))
  8170. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8171. else {
  8172. switch (switch_cfg) {
  8173. case SWITCH_CFG_1G:
  8174. bp->port.phy_addr = REG_RD(
  8175. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8176. break;
  8177. case SWITCH_CFG_10G:
  8178. bp->port.phy_addr = REG_RD(
  8179. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8180. break;
  8181. default:
  8182. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8183. bp->port.link_config[0]);
  8184. return;
  8185. }
  8186. }
  8187. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8188. /* mask what we support according to speed_cap_mask per configuration */
  8189. for (idx = 0; idx < cfg_size; idx++) {
  8190. if (!(bp->link_params.speed_cap_mask[idx] &
  8191. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8192. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8193. if (!(bp->link_params.speed_cap_mask[idx] &
  8194. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8195. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8196. if (!(bp->link_params.speed_cap_mask[idx] &
  8197. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8198. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8199. if (!(bp->link_params.speed_cap_mask[idx] &
  8200. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8201. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8202. if (!(bp->link_params.speed_cap_mask[idx] &
  8203. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8204. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8205. SUPPORTED_1000baseT_Full);
  8206. if (!(bp->link_params.speed_cap_mask[idx] &
  8207. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8208. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8209. if (!(bp->link_params.speed_cap_mask[idx] &
  8210. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8211. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8212. }
  8213. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8214. bp->port.supported[1]);
  8215. }
  8216. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  8217. {
  8218. u32 link_config, idx, cfg_size = 0;
  8219. bp->port.advertising[0] = 0;
  8220. bp->port.advertising[1] = 0;
  8221. switch (bp->link_params.num_phys) {
  8222. case 1:
  8223. case 2:
  8224. cfg_size = 1;
  8225. break;
  8226. case 3:
  8227. cfg_size = 2;
  8228. break;
  8229. }
  8230. for (idx = 0; idx < cfg_size; idx++) {
  8231. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8232. link_config = bp->port.link_config[idx];
  8233. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8234. case PORT_FEATURE_LINK_SPEED_AUTO:
  8235. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8236. bp->link_params.req_line_speed[idx] =
  8237. SPEED_AUTO_NEG;
  8238. bp->port.advertising[idx] |=
  8239. bp->port.supported[idx];
  8240. if (bp->link_params.phy[EXT_PHY1].type ==
  8241. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8242. bp->port.advertising[idx] |=
  8243. (SUPPORTED_100baseT_Half |
  8244. SUPPORTED_100baseT_Full);
  8245. } else {
  8246. /* force 10G, no AN */
  8247. bp->link_params.req_line_speed[idx] =
  8248. SPEED_10000;
  8249. bp->port.advertising[idx] |=
  8250. (ADVERTISED_10000baseT_Full |
  8251. ADVERTISED_FIBRE);
  8252. continue;
  8253. }
  8254. break;
  8255. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8256. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8257. bp->link_params.req_line_speed[idx] =
  8258. SPEED_10;
  8259. bp->port.advertising[idx] |=
  8260. (ADVERTISED_10baseT_Full |
  8261. ADVERTISED_TP);
  8262. } else {
  8263. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8264. link_config,
  8265. bp->link_params.speed_cap_mask[idx]);
  8266. return;
  8267. }
  8268. break;
  8269. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8270. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8271. bp->link_params.req_line_speed[idx] =
  8272. SPEED_10;
  8273. bp->link_params.req_duplex[idx] =
  8274. DUPLEX_HALF;
  8275. bp->port.advertising[idx] |=
  8276. (ADVERTISED_10baseT_Half |
  8277. ADVERTISED_TP);
  8278. } else {
  8279. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8280. link_config,
  8281. bp->link_params.speed_cap_mask[idx]);
  8282. return;
  8283. }
  8284. break;
  8285. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8286. if (bp->port.supported[idx] &
  8287. SUPPORTED_100baseT_Full) {
  8288. bp->link_params.req_line_speed[idx] =
  8289. SPEED_100;
  8290. bp->port.advertising[idx] |=
  8291. (ADVERTISED_100baseT_Full |
  8292. ADVERTISED_TP);
  8293. } else {
  8294. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8295. link_config,
  8296. bp->link_params.speed_cap_mask[idx]);
  8297. return;
  8298. }
  8299. break;
  8300. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8301. if (bp->port.supported[idx] &
  8302. SUPPORTED_100baseT_Half) {
  8303. bp->link_params.req_line_speed[idx] =
  8304. SPEED_100;
  8305. bp->link_params.req_duplex[idx] =
  8306. DUPLEX_HALF;
  8307. bp->port.advertising[idx] |=
  8308. (ADVERTISED_100baseT_Half |
  8309. ADVERTISED_TP);
  8310. } else {
  8311. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8312. link_config,
  8313. bp->link_params.speed_cap_mask[idx]);
  8314. return;
  8315. }
  8316. break;
  8317. case PORT_FEATURE_LINK_SPEED_1G:
  8318. if (bp->port.supported[idx] &
  8319. SUPPORTED_1000baseT_Full) {
  8320. bp->link_params.req_line_speed[idx] =
  8321. SPEED_1000;
  8322. bp->port.advertising[idx] |=
  8323. (ADVERTISED_1000baseT_Full |
  8324. ADVERTISED_TP);
  8325. } else {
  8326. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8327. link_config,
  8328. bp->link_params.speed_cap_mask[idx]);
  8329. return;
  8330. }
  8331. break;
  8332. case PORT_FEATURE_LINK_SPEED_2_5G:
  8333. if (bp->port.supported[idx] &
  8334. SUPPORTED_2500baseX_Full) {
  8335. bp->link_params.req_line_speed[idx] =
  8336. SPEED_2500;
  8337. bp->port.advertising[idx] |=
  8338. (ADVERTISED_2500baseX_Full |
  8339. ADVERTISED_TP);
  8340. } else {
  8341. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8342. link_config,
  8343. bp->link_params.speed_cap_mask[idx]);
  8344. return;
  8345. }
  8346. break;
  8347. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8348. if (bp->port.supported[idx] &
  8349. SUPPORTED_10000baseT_Full) {
  8350. bp->link_params.req_line_speed[idx] =
  8351. SPEED_10000;
  8352. bp->port.advertising[idx] |=
  8353. (ADVERTISED_10000baseT_Full |
  8354. ADVERTISED_FIBRE);
  8355. } else {
  8356. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8357. link_config,
  8358. bp->link_params.speed_cap_mask[idx]);
  8359. return;
  8360. }
  8361. break;
  8362. case PORT_FEATURE_LINK_SPEED_20G:
  8363. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8364. break;
  8365. default:
  8366. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8367. link_config);
  8368. bp->link_params.req_line_speed[idx] =
  8369. SPEED_AUTO_NEG;
  8370. bp->port.advertising[idx] =
  8371. bp->port.supported[idx];
  8372. break;
  8373. }
  8374. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8375. PORT_FEATURE_FLOW_CONTROL_MASK);
  8376. if ((bp->link_params.req_flow_ctrl[idx] ==
  8377. BNX2X_FLOW_CTRL_AUTO) &&
  8378. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  8379. bp->link_params.req_flow_ctrl[idx] =
  8380. BNX2X_FLOW_CTRL_NONE;
  8381. }
  8382. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8383. bp->link_params.req_line_speed[idx],
  8384. bp->link_params.req_duplex[idx],
  8385. bp->link_params.req_flow_ctrl[idx],
  8386. bp->port.advertising[idx]);
  8387. }
  8388. }
  8389. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8390. {
  8391. mac_hi = cpu_to_be16(mac_hi);
  8392. mac_lo = cpu_to_be32(mac_lo);
  8393. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8394. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8395. }
  8396. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8397. {
  8398. int port = BP_PORT(bp);
  8399. u32 config;
  8400. u32 ext_phy_type, ext_phy_config;
  8401. bp->link_params.bp = bp;
  8402. bp->link_params.port = port;
  8403. bp->link_params.lane_config =
  8404. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8405. bp->link_params.speed_cap_mask[0] =
  8406. SHMEM_RD(bp,
  8407. dev_info.port_hw_config[port].speed_capability_mask);
  8408. bp->link_params.speed_cap_mask[1] =
  8409. SHMEM_RD(bp,
  8410. dev_info.port_hw_config[port].speed_capability_mask2);
  8411. bp->port.link_config[0] =
  8412. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8413. bp->port.link_config[1] =
  8414. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8415. bp->link_params.multi_phy_config =
  8416. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8417. /* If the device is capable of WoL, set the default state according
  8418. * to the HW
  8419. */
  8420. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8421. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8422. (config & PORT_FEATURE_WOL_ENABLED));
  8423. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8424. bp->link_params.lane_config,
  8425. bp->link_params.speed_cap_mask[0],
  8426. bp->port.link_config[0]);
  8427. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8428. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8429. bnx2x_phy_probe(&bp->link_params);
  8430. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8431. bnx2x_link_settings_requested(bp);
  8432. /*
  8433. * If connected directly, work with the internal PHY, otherwise, work
  8434. * with the external PHY
  8435. */
  8436. ext_phy_config =
  8437. SHMEM_RD(bp,
  8438. dev_info.port_hw_config[port].external_phy_config);
  8439. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8440. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8441. bp->mdio.prtad = bp->port.phy_addr;
  8442. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8443. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8444. bp->mdio.prtad =
  8445. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8446. /*
  8447. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  8448. * In MF mode, it is set to cover self test cases
  8449. */
  8450. if (IS_MF(bp))
  8451. bp->port.need_hw_lock = 1;
  8452. else
  8453. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  8454. bp->common.shmem_base,
  8455. bp->common.shmem2_base);
  8456. }
  8457. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8458. {
  8459. u32 no_flags = NO_ISCSI_FLAG;
  8460. #ifdef BCM_CNIC
  8461. int port = BP_PORT(bp);
  8462. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8463. drv_lic_key[port].max_iscsi_conn);
  8464. /* Get the number of maximum allowed iSCSI connections */
  8465. bp->cnic_eth_dev.max_iscsi_conn =
  8466. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8467. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8468. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8469. bp->cnic_eth_dev.max_iscsi_conn);
  8470. /*
  8471. * If maximum allowed number of connections is zero -
  8472. * disable the feature.
  8473. */
  8474. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8475. bp->flags |= no_flags;
  8476. #else
  8477. bp->flags |= no_flags;
  8478. #endif
  8479. }
  8480. #ifdef BCM_CNIC
  8481. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8482. {
  8483. /* Port info */
  8484. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8485. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8486. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8487. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8488. /* Node info */
  8489. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8490. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8491. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8492. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8493. }
  8494. #endif
  8495. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  8496. {
  8497. #ifdef BCM_CNIC
  8498. int port = BP_PORT(bp);
  8499. int func = BP_ABS_FUNC(bp);
  8500. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8501. drv_lic_key[port].max_fcoe_conn);
  8502. /* Get the number of maximum allowed FCoE connections */
  8503. bp->cnic_eth_dev.max_fcoe_conn =
  8504. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8505. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8506. /* Read the WWN: */
  8507. if (!IS_MF(bp)) {
  8508. /* Port info */
  8509. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8510. SHMEM_RD(bp,
  8511. dev_info.port_hw_config[port].
  8512. fcoe_wwn_port_name_upper);
  8513. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8514. SHMEM_RD(bp,
  8515. dev_info.port_hw_config[port].
  8516. fcoe_wwn_port_name_lower);
  8517. /* Node info */
  8518. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8519. SHMEM_RD(bp,
  8520. dev_info.port_hw_config[port].
  8521. fcoe_wwn_node_name_upper);
  8522. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8523. SHMEM_RD(bp,
  8524. dev_info.port_hw_config[port].
  8525. fcoe_wwn_node_name_lower);
  8526. } else if (!IS_MF_SD(bp)) {
  8527. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8528. /*
  8529. * Read the WWN info only if the FCoE feature is enabled for
  8530. * this function.
  8531. */
  8532. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  8533. bnx2x_get_ext_wwn_info(bp, func);
  8534. } else if (IS_MF_FCOE_SD(bp))
  8535. bnx2x_get_ext_wwn_info(bp, func);
  8536. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8537. /*
  8538. * If maximum allowed number of connections is zero -
  8539. * disable the feature.
  8540. */
  8541. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8542. bp->flags |= NO_FCOE_FLAG;
  8543. #else
  8544. bp->flags |= NO_FCOE_FLAG;
  8545. #endif
  8546. }
  8547. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8548. {
  8549. /*
  8550. * iSCSI may be dynamically disabled but reading
  8551. * info here we will decrease memory usage by driver
  8552. * if the feature is disabled for good
  8553. */
  8554. bnx2x_get_iscsi_info(bp);
  8555. bnx2x_get_fcoe_info(bp);
  8556. }
  8557. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8558. {
  8559. u32 val, val2;
  8560. int func = BP_ABS_FUNC(bp);
  8561. int port = BP_PORT(bp);
  8562. #ifdef BCM_CNIC
  8563. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8564. u8 *fip_mac = bp->fip_mac;
  8565. #endif
  8566. /* Zero primary MAC configuration */
  8567. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8568. if (BP_NOMCP(bp)) {
  8569. BNX2X_ERROR("warning: random MAC workaround active\n");
  8570. eth_hw_addr_random(bp->dev);
  8571. } else if (IS_MF(bp)) {
  8572. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8573. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8574. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8575. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8576. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8577. #ifdef BCM_CNIC
  8578. /*
  8579. * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8580. * FCoE MAC then the appropriate feature should be disabled.
  8581. *
  8582. * In non SD mode features configuration comes from
  8583. * struct func_ext_config.
  8584. */
  8585. if (!IS_MF_SD(bp)) {
  8586. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8587. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8588. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8589. iscsi_mac_addr_upper);
  8590. val = MF_CFG_RD(bp, func_ext_config[func].
  8591. iscsi_mac_addr_lower);
  8592. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8593. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8594. iscsi_mac);
  8595. } else
  8596. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8597. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8598. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8599. fcoe_mac_addr_upper);
  8600. val = MF_CFG_RD(bp, func_ext_config[func].
  8601. fcoe_mac_addr_lower);
  8602. bnx2x_set_mac_buf(fip_mac, val, val2);
  8603. BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
  8604. fip_mac);
  8605. } else
  8606. bp->flags |= NO_FCOE_FLAG;
  8607. bp->mf_ext_config = cfg;
  8608. } else { /* SD MODE */
  8609. if (IS_MF_STORAGE_SD(bp)) {
  8610. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8611. /* use primary mac as iscsi mac */
  8612. memcpy(iscsi_mac, bp->dev->dev_addr,
  8613. ETH_ALEN);
  8614. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8615. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8616. iscsi_mac);
  8617. } else { /* FCoE */
  8618. memcpy(fip_mac, bp->dev->dev_addr,
  8619. ETH_ALEN);
  8620. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8621. BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
  8622. fip_mac);
  8623. }
  8624. /* Zero primary MAC configuration */
  8625. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8626. }
  8627. }
  8628. if (IS_MF_FCOE_AFEX(bp))
  8629. /* use FIP MAC as primary MAC */
  8630. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8631. #endif
  8632. } else {
  8633. /* in SF read MACs from port configuration */
  8634. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8635. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8636. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8637. #ifdef BCM_CNIC
  8638. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8639. iscsi_mac_upper);
  8640. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8641. iscsi_mac_lower);
  8642. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8643. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8644. fcoe_fip_mac_upper);
  8645. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8646. fcoe_fip_mac_lower);
  8647. bnx2x_set_mac_buf(fip_mac, val, val2);
  8648. #endif
  8649. }
  8650. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8651. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8652. #ifdef BCM_CNIC
  8653. /* Disable iSCSI if MAC configuration is
  8654. * invalid.
  8655. */
  8656. if (!is_valid_ether_addr(iscsi_mac)) {
  8657. bp->flags |= NO_ISCSI_FLAG;
  8658. memset(iscsi_mac, 0, ETH_ALEN);
  8659. }
  8660. /* Disable FCoE if MAC configuration is
  8661. * invalid.
  8662. */
  8663. if (!is_valid_ether_addr(fip_mac)) {
  8664. bp->flags |= NO_FCOE_FLAG;
  8665. memset(bp->fip_mac, 0, ETH_ALEN);
  8666. }
  8667. #endif
  8668. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8669. dev_err(&bp->pdev->dev,
  8670. "bad Ethernet MAC address configuration: %pM\n"
  8671. "change it manually before bringing up the appropriate network interface\n",
  8672. bp->dev->dev_addr);
  8673. }
  8674. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8675. {
  8676. int /*abs*/func = BP_ABS_FUNC(bp);
  8677. int vn;
  8678. u32 val = 0;
  8679. int rc = 0;
  8680. bnx2x_get_common_hwinfo(bp);
  8681. /*
  8682. * initialize IGU parameters
  8683. */
  8684. if (CHIP_IS_E1x(bp)) {
  8685. bp->common.int_block = INT_BLOCK_HC;
  8686. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8687. bp->igu_base_sb = 0;
  8688. } else {
  8689. bp->common.int_block = INT_BLOCK_IGU;
  8690. /* do not allow device reset during IGU info preocessing */
  8691. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8692. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8693. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8694. int tout = 5000;
  8695. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8696. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8697. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8698. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8699. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8700. tout--;
  8701. usleep_range(1000, 1000);
  8702. }
  8703. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8704. dev_err(&bp->pdev->dev,
  8705. "FORCING Normal Mode failed!!!\n");
  8706. return -EPERM;
  8707. }
  8708. }
  8709. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8710. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8711. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8712. } else
  8713. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8714. bnx2x_get_igu_cam_info(bp);
  8715. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8716. }
  8717. /*
  8718. * set base FW non-default (fast path) status block id, this value is
  8719. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8720. * determine the id used by the FW.
  8721. */
  8722. if (CHIP_IS_E1x(bp))
  8723. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8724. else /*
  8725. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8726. * the same queue are indicated on the same IGU SB). So we prefer
  8727. * FW and IGU SBs to be the same value.
  8728. */
  8729. bp->base_fw_ndsb = bp->igu_base_sb;
  8730. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8731. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8732. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8733. /*
  8734. * Initialize MF configuration
  8735. */
  8736. bp->mf_ov = 0;
  8737. bp->mf_mode = 0;
  8738. vn = BP_VN(bp);
  8739. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8740. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8741. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8742. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8743. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8744. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8745. else
  8746. bp->common.mf_cfg_base = bp->common.shmem_base +
  8747. offsetof(struct shmem_region, func_mb) +
  8748. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8749. /*
  8750. * get mf configuration:
  8751. * 1. existence of MF configuration
  8752. * 2. MAC address must be legal (check only upper bytes)
  8753. * for Switch-Independent mode;
  8754. * OVLAN must be legal for Switch-Dependent mode
  8755. * 3. SF_MODE configures specific MF mode
  8756. */
  8757. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8758. /* get mf configuration */
  8759. val = SHMEM_RD(bp,
  8760. dev_info.shared_feature_config.config);
  8761. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8762. switch (val) {
  8763. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8764. val = MF_CFG_RD(bp, func_mf_config[func].
  8765. mac_upper);
  8766. /* check for legal mac (upper bytes)*/
  8767. if (val != 0xffff) {
  8768. bp->mf_mode = MULTI_FUNCTION_SI;
  8769. bp->mf_config[vn] = MF_CFG_RD(bp,
  8770. func_mf_config[func].config);
  8771. } else
  8772. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  8773. break;
  8774. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  8775. if ((!CHIP_IS_E1x(bp)) &&
  8776. (MF_CFG_RD(bp, func_mf_config[func].
  8777. mac_upper) != 0xffff) &&
  8778. (SHMEM2_HAS(bp,
  8779. afex_driver_support))) {
  8780. bp->mf_mode = MULTI_FUNCTION_AFEX;
  8781. bp->mf_config[vn] = MF_CFG_RD(bp,
  8782. func_mf_config[func].config);
  8783. } else {
  8784. BNX2X_DEV_INFO("can not configure afex mode\n");
  8785. }
  8786. break;
  8787. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8788. /* get OV configuration */
  8789. val = MF_CFG_RD(bp,
  8790. func_mf_config[FUNC_0].e1hov_tag);
  8791. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8792. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8793. bp->mf_mode = MULTI_FUNCTION_SD;
  8794. bp->mf_config[vn] = MF_CFG_RD(bp,
  8795. func_mf_config[func].config);
  8796. } else
  8797. BNX2X_DEV_INFO("illegal OV for SD\n");
  8798. break;
  8799. default:
  8800. /* Unknown configuration: reset mf_config */
  8801. bp->mf_config[vn] = 0;
  8802. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  8803. }
  8804. }
  8805. BNX2X_DEV_INFO("%s function mode\n",
  8806. IS_MF(bp) ? "multi" : "single");
  8807. switch (bp->mf_mode) {
  8808. case MULTI_FUNCTION_SD:
  8809. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8810. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8811. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8812. bp->mf_ov = val;
  8813. bp->path_has_ovlan = true;
  8814. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  8815. func, bp->mf_ov, bp->mf_ov);
  8816. } else {
  8817. dev_err(&bp->pdev->dev,
  8818. "No valid MF OV for func %d, aborting\n",
  8819. func);
  8820. return -EPERM;
  8821. }
  8822. break;
  8823. case MULTI_FUNCTION_AFEX:
  8824. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  8825. break;
  8826. case MULTI_FUNCTION_SI:
  8827. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  8828. func);
  8829. break;
  8830. default:
  8831. if (vn) {
  8832. dev_err(&bp->pdev->dev,
  8833. "VN %d is in a single function mode, aborting\n",
  8834. vn);
  8835. return -EPERM;
  8836. }
  8837. break;
  8838. }
  8839. /* check if other port on the path needs ovlan:
  8840. * Since MF configuration is shared between ports
  8841. * Possible mixed modes are only
  8842. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8843. */
  8844. if (CHIP_MODE_IS_4_PORT(bp) &&
  8845. !bp->path_has_ovlan &&
  8846. !IS_MF(bp) &&
  8847. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8848. u8 other_port = !BP_PORT(bp);
  8849. u8 other_func = BP_PATH(bp) + 2*other_port;
  8850. val = MF_CFG_RD(bp,
  8851. func_mf_config[other_func].e1hov_tag);
  8852. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8853. bp->path_has_ovlan = true;
  8854. }
  8855. }
  8856. /* adjust igu_sb_cnt to MF for E1x */
  8857. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8858. bp->igu_sb_cnt /= E1HVN_MAX;
  8859. /* port info */
  8860. bnx2x_get_port_hwinfo(bp);
  8861. /* Get MAC addresses */
  8862. bnx2x_get_mac_hwinfo(bp);
  8863. bnx2x_get_cnic_info(bp);
  8864. return rc;
  8865. }
  8866. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8867. {
  8868. int cnt, i, block_end, rodi;
  8869. char vpd_start[BNX2X_VPD_LEN+1];
  8870. char str_id_reg[VENDOR_ID_LEN+1];
  8871. char str_id_cap[VENDOR_ID_LEN+1];
  8872. char *vpd_data;
  8873. char *vpd_extended_data = NULL;
  8874. u8 len;
  8875. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  8876. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8877. if (cnt < BNX2X_VPD_LEN)
  8878. goto out_not_found;
  8879. /* VPD RO tag should be first tag after identifier string, hence
  8880. * we should be able to find it in first BNX2X_VPD_LEN chars
  8881. */
  8882. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  8883. PCI_VPD_LRDT_RO_DATA);
  8884. if (i < 0)
  8885. goto out_not_found;
  8886. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8887. pci_vpd_lrdt_size(&vpd_start[i]);
  8888. i += PCI_VPD_LRDT_TAG_SIZE;
  8889. if (block_end > BNX2X_VPD_LEN) {
  8890. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  8891. if (vpd_extended_data == NULL)
  8892. goto out_not_found;
  8893. /* read rest of vpd image into vpd_extended_data */
  8894. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  8895. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  8896. block_end - BNX2X_VPD_LEN,
  8897. vpd_extended_data + BNX2X_VPD_LEN);
  8898. if (cnt < (block_end - BNX2X_VPD_LEN))
  8899. goto out_not_found;
  8900. vpd_data = vpd_extended_data;
  8901. } else
  8902. vpd_data = vpd_start;
  8903. /* now vpd_data holds full vpd content in both cases */
  8904. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8905. PCI_VPD_RO_KEYWORD_MFR_ID);
  8906. if (rodi < 0)
  8907. goto out_not_found;
  8908. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8909. if (len != VENDOR_ID_LEN)
  8910. goto out_not_found;
  8911. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8912. /* vendor specific info */
  8913. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8914. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8915. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8916. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8917. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8918. PCI_VPD_RO_KEYWORD_VENDOR0);
  8919. if (rodi >= 0) {
  8920. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8921. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8922. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  8923. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  8924. bp->fw_ver[len] = ' ';
  8925. }
  8926. }
  8927. kfree(vpd_extended_data);
  8928. return;
  8929. }
  8930. out_not_found:
  8931. kfree(vpd_extended_data);
  8932. return;
  8933. }
  8934. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  8935. {
  8936. u32 flags = 0;
  8937. if (CHIP_REV_IS_FPGA(bp))
  8938. SET_FLAGS(flags, MODE_FPGA);
  8939. else if (CHIP_REV_IS_EMUL(bp))
  8940. SET_FLAGS(flags, MODE_EMUL);
  8941. else
  8942. SET_FLAGS(flags, MODE_ASIC);
  8943. if (CHIP_MODE_IS_4_PORT(bp))
  8944. SET_FLAGS(flags, MODE_PORT4);
  8945. else
  8946. SET_FLAGS(flags, MODE_PORT2);
  8947. if (CHIP_IS_E2(bp))
  8948. SET_FLAGS(flags, MODE_E2);
  8949. else if (CHIP_IS_E3(bp)) {
  8950. SET_FLAGS(flags, MODE_E3);
  8951. if (CHIP_REV(bp) == CHIP_REV_Ax)
  8952. SET_FLAGS(flags, MODE_E3_A0);
  8953. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  8954. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  8955. }
  8956. if (IS_MF(bp)) {
  8957. SET_FLAGS(flags, MODE_MF);
  8958. switch (bp->mf_mode) {
  8959. case MULTI_FUNCTION_SD:
  8960. SET_FLAGS(flags, MODE_MF_SD);
  8961. break;
  8962. case MULTI_FUNCTION_SI:
  8963. SET_FLAGS(flags, MODE_MF_SI);
  8964. break;
  8965. case MULTI_FUNCTION_AFEX:
  8966. SET_FLAGS(flags, MODE_MF_AFEX);
  8967. break;
  8968. }
  8969. } else
  8970. SET_FLAGS(flags, MODE_SF);
  8971. #if defined(__LITTLE_ENDIAN)
  8972. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  8973. #else /*(__BIG_ENDIAN)*/
  8974. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  8975. #endif
  8976. INIT_MODE_FLAGS(bp) = flags;
  8977. }
  8978. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  8979. {
  8980. int func;
  8981. int rc;
  8982. mutex_init(&bp->port.phy_mutex);
  8983. mutex_init(&bp->fw_mb_mutex);
  8984. spin_lock_init(&bp->stats_lock);
  8985. #ifdef BCM_CNIC
  8986. mutex_init(&bp->cnic_mutex);
  8987. #endif
  8988. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  8989. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  8990. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  8991. rc = bnx2x_get_hwinfo(bp);
  8992. if (rc)
  8993. return rc;
  8994. bnx2x_set_modes_bitmap(bp);
  8995. rc = bnx2x_alloc_mem_bp(bp);
  8996. if (rc)
  8997. return rc;
  8998. bnx2x_read_fwinfo(bp);
  8999. func = BP_FUNC(bp);
  9000. /* need to reset chip if undi was active */
  9001. if (!BP_NOMCP(bp)) {
  9002. /* init fw_seq */
  9003. bp->fw_seq =
  9004. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9005. DRV_MSG_SEQ_NUMBER_MASK;
  9006. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9007. bnx2x_prev_unload(bp);
  9008. }
  9009. if (CHIP_REV_IS_FPGA(bp))
  9010. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9011. if (BP_NOMCP(bp) && (func == 0))
  9012. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9013. bp->disable_tpa = disable_tpa;
  9014. #ifdef BCM_CNIC
  9015. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9016. #endif
  9017. /* Set TPA flags */
  9018. if (bp->disable_tpa) {
  9019. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9020. bp->dev->features &= ~NETIF_F_LRO;
  9021. } else {
  9022. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9023. bp->dev->features |= NETIF_F_LRO;
  9024. }
  9025. if (CHIP_IS_E1(bp))
  9026. bp->dropless_fc = 0;
  9027. else
  9028. bp->dropless_fc = dropless_fc;
  9029. bp->mrrs = mrrs;
  9030. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9031. /* make sure that the numbers are in the right granularity */
  9032. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9033. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9034. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9035. init_timer(&bp->timer);
  9036. bp->timer.expires = jiffies + bp->current_interval;
  9037. bp->timer.data = (unsigned long) bp;
  9038. bp->timer.function = bnx2x_timer;
  9039. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9040. bnx2x_dcbx_init_params(bp);
  9041. #ifdef BCM_CNIC
  9042. if (CHIP_IS_E1x(bp))
  9043. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9044. else
  9045. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9046. #endif
  9047. /* multiple tx priority */
  9048. if (CHIP_IS_E1x(bp))
  9049. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9050. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9051. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9052. if (CHIP_IS_E3B0(bp))
  9053. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9054. return rc;
  9055. }
  9056. /****************************************************************************
  9057. * General service functions
  9058. ****************************************************************************/
  9059. /*
  9060. * net_device service functions
  9061. */
  9062. /* called with rtnl_lock */
  9063. static int bnx2x_open(struct net_device *dev)
  9064. {
  9065. struct bnx2x *bp = netdev_priv(dev);
  9066. bool global = false;
  9067. int other_engine = BP_PATH(bp) ? 0 : 1;
  9068. bool other_load_status, load_status;
  9069. bp->stats_init = true;
  9070. netif_carrier_off(dev);
  9071. bnx2x_set_power_state(bp, PCI_D0);
  9072. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9073. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9074. /*
  9075. * If parity had happen during the unload, then attentions
  9076. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9077. * want the first function loaded on the current engine to
  9078. * complete the recovery.
  9079. */
  9080. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9081. bnx2x_chk_parity_attn(bp, &global, true))
  9082. do {
  9083. /*
  9084. * If there are attentions and they are in a global
  9085. * blocks, set the GLOBAL_RESET bit regardless whether
  9086. * it will be this function that will complete the
  9087. * recovery or not.
  9088. */
  9089. if (global)
  9090. bnx2x_set_reset_global(bp);
  9091. /*
  9092. * Only the first function on the current engine should
  9093. * try to recover in open. In case of attentions in
  9094. * global blocks only the first in the chip should try
  9095. * to recover.
  9096. */
  9097. if ((!load_status &&
  9098. (!global || !other_load_status)) &&
  9099. bnx2x_trylock_leader_lock(bp) &&
  9100. !bnx2x_leader_reset(bp)) {
  9101. netdev_info(bp->dev, "Recovered in open\n");
  9102. break;
  9103. }
  9104. /* recovery has failed... */
  9105. bnx2x_set_power_state(bp, PCI_D3hot);
  9106. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9107. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9108. "If you still see this message after a few retries then power cycle is required.\n");
  9109. return -EAGAIN;
  9110. } while (0);
  9111. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9112. return bnx2x_nic_load(bp, LOAD_OPEN);
  9113. }
  9114. /* called with rtnl_lock */
  9115. static int bnx2x_close(struct net_device *dev)
  9116. {
  9117. struct bnx2x *bp = netdev_priv(dev);
  9118. /* Unload the driver, release IRQs */
  9119. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  9120. /* Power off */
  9121. bnx2x_set_power_state(bp, PCI_D3hot);
  9122. return 0;
  9123. }
  9124. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9125. struct bnx2x_mcast_ramrod_params *p)
  9126. {
  9127. int mc_count = netdev_mc_count(bp->dev);
  9128. struct bnx2x_mcast_list_elem *mc_mac =
  9129. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9130. struct netdev_hw_addr *ha;
  9131. if (!mc_mac)
  9132. return -ENOMEM;
  9133. INIT_LIST_HEAD(&p->mcast_list);
  9134. netdev_for_each_mc_addr(ha, bp->dev) {
  9135. mc_mac->mac = bnx2x_mc_addr(ha);
  9136. list_add_tail(&mc_mac->link, &p->mcast_list);
  9137. mc_mac++;
  9138. }
  9139. p->mcast_list_len = mc_count;
  9140. return 0;
  9141. }
  9142. static void bnx2x_free_mcast_macs_list(
  9143. struct bnx2x_mcast_ramrod_params *p)
  9144. {
  9145. struct bnx2x_mcast_list_elem *mc_mac =
  9146. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9147. link);
  9148. WARN_ON(!mc_mac);
  9149. kfree(mc_mac);
  9150. }
  9151. /**
  9152. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9153. *
  9154. * @bp: driver handle
  9155. *
  9156. * We will use zero (0) as a MAC type for these MACs.
  9157. */
  9158. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9159. {
  9160. int rc;
  9161. struct net_device *dev = bp->dev;
  9162. struct netdev_hw_addr *ha;
  9163. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  9164. unsigned long ramrod_flags = 0;
  9165. /* First schedule a cleanup up of old configuration */
  9166. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9167. if (rc < 0) {
  9168. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9169. return rc;
  9170. }
  9171. netdev_for_each_uc_addr(ha, dev) {
  9172. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9173. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9174. if (rc < 0) {
  9175. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9176. rc);
  9177. return rc;
  9178. }
  9179. }
  9180. /* Execute the pending commands */
  9181. __set_bit(RAMROD_CONT, &ramrod_flags);
  9182. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9183. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9184. }
  9185. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9186. {
  9187. struct net_device *dev = bp->dev;
  9188. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9189. int rc = 0;
  9190. rparam.mcast_obj = &bp->mcast_obj;
  9191. /* first, clear all configured multicast MACs */
  9192. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9193. if (rc < 0) {
  9194. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9195. return rc;
  9196. }
  9197. /* then, configure a new MACs list */
  9198. if (netdev_mc_count(dev)) {
  9199. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9200. if (rc) {
  9201. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9202. rc);
  9203. return rc;
  9204. }
  9205. /* Now add the new MACs */
  9206. rc = bnx2x_config_mcast(bp, &rparam,
  9207. BNX2X_MCAST_CMD_ADD);
  9208. if (rc < 0)
  9209. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9210. rc);
  9211. bnx2x_free_mcast_macs_list(&rparam);
  9212. }
  9213. return rc;
  9214. }
  9215. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9216. void bnx2x_set_rx_mode(struct net_device *dev)
  9217. {
  9218. struct bnx2x *bp = netdev_priv(dev);
  9219. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9220. if (bp->state != BNX2X_STATE_OPEN) {
  9221. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9222. return;
  9223. }
  9224. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9225. if (dev->flags & IFF_PROMISC)
  9226. rx_mode = BNX2X_RX_MODE_PROMISC;
  9227. else if ((dev->flags & IFF_ALLMULTI) ||
  9228. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9229. CHIP_IS_E1(bp)))
  9230. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9231. else {
  9232. /* some multicasts */
  9233. if (bnx2x_set_mc_list(bp) < 0)
  9234. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9235. if (bnx2x_set_uc_list(bp) < 0)
  9236. rx_mode = BNX2X_RX_MODE_PROMISC;
  9237. }
  9238. bp->rx_mode = rx_mode;
  9239. #ifdef BCM_CNIC
  9240. /* handle ISCSI SD mode */
  9241. if (IS_MF_ISCSI_SD(bp))
  9242. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9243. #endif
  9244. /* Schedule the rx_mode command */
  9245. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9246. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9247. return;
  9248. }
  9249. bnx2x_set_storm_rx_mode(bp);
  9250. }
  9251. /* called with rtnl_lock */
  9252. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9253. int devad, u16 addr)
  9254. {
  9255. struct bnx2x *bp = netdev_priv(netdev);
  9256. u16 value;
  9257. int rc;
  9258. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9259. prtad, devad, addr);
  9260. /* The HW expects different devad if CL22 is used */
  9261. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9262. bnx2x_acquire_phy_lock(bp);
  9263. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9264. bnx2x_release_phy_lock(bp);
  9265. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9266. if (!rc)
  9267. rc = value;
  9268. return rc;
  9269. }
  9270. /* called with rtnl_lock */
  9271. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9272. u16 addr, u16 value)
  9273. {
  9274. struct bnx2x *bp = netdev_priv(netdev);
  9275. int rc;
  9276. DP(NETIF_MSG_LINK,
  9277. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9278. prtad, devad, addr, value);
  9279. /* The HW expects different devad if CL22 is used */
  9280. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9281. bnx2x_acquire_phy_lock(bp);
  9282. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9283. bnx2x_release_phy_lock(bp);
  9284. return rc;
  9285. }
  9286. /* called with rtnl_lock */
  9287. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9288. {
  9289. struct bnx2x *bp = netdev_priv(dev);
  9290. struct mii_ioctl_data *mdio = if_mii(ifr);
  9291. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9292. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9293. if (!netif_running(dev))
  9294. return -EAGAIN;
  9295. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9296. }
  9297. #ifdef CONFIG_NET_POLL_CONTROLLER
  9298. static void poll_bnx2x(struct net_device *dev)
  9299. {
  9300. struct bnx2x *bp = netdev_priv(dev);
  9301. disable_irq(bp->pdev->irq);
  9302. bnx2x_interrupt(bp->pdev->irq, dev);
  9303. enable_irq(bp->pdev->irq);
  9304. }
  9305. #endif
  9306. static int bnx2x_validate_addr(struct net_device *dev)
  9307. {
  9308. struct bnx2x *bp = netdev_priv(dev);
  9309. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9310. BNX2X_ERR("Non-valid Ethernet address\n");
  9311. return -EADDRNOTAVAIL;
  9312. }
  9313. return 0;
  9314. }
  9315. static const struct net_device_ops bnx2x_netdev_ops = {
  9316. .ndo_open = bnx2x_open,
  9317. .ndo_stop = bnx2x_close,
  9318. .ndo_start_xmit = bnx2x_start_xmit,
  9319. .ndo_select_queue = bnx2x_select_queue,
  9320. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9321. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9322. .ndo_validate_addr = bnx2x_validate_addr,
  9323. .ndo_do_ioctl = bnx2x_ioctl,
  9324. .ndo_change_mtu = bnx2x_change_mtu,
  9325. .ndo_fix_features = bnx2x_fix_features,
  9326. .ndo_set_features = bnx2x_set_features,
  9327. .ndo_tx_timeout = bnx2x_tx_timeout,
  9328. #ifdef CONFIG_NET_POLL_CONTROLLER
  9329. .ndo_poll_controller = poll_bnx2x,
  9330. #endif
  9331. .ndo_setup_tc = bnx2x_setup_tc,
  9332. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  9333. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9334. #endif
  9335. };
  9336. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9337. {
  9338. struct device *dev = &bp->pdev->dev;
  9339. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9340. bp->flags |= USING_DAC_FLAG;
  9341. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9342. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9343. return -EIO;
  9344. }
  9345. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9346. dev_err(dev, "System does not support DMA, aborting\n");
  9347. return -EIO;
  9348. }
  9349. return 0;
  9350. }
  9351. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9352. struct net_device *dev,
  9353. unsigned long board_type)
  9354. {
  9355. struct bnx2x *bp;
  9356. int rc;
  9357. u32 pci_cfg_dword;
  9358. bool chip_is_e1x = (board_type == BCM57710 ||
  9359. board_type == BCM57711 ||
  9360. board_type == BCM57711E);
  9361. SET_NETDEV_DEV(dev, &pdev->dev);
  9362. bp = netdev_priv(dev);
  9363. bp->dev = dev;
  9364. bp->pdev = pdev;
  9365. bp->flags = 0;
  9366. rc = pci_enable_device(pdev);
  9367. if (rc) {
  9368. dev_err(&bp->pdev->dev,
  9369. "Cannot enable PCI device, aborting\n");
  9370. goto err_out;
  9371. }
  9372. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9373. dev_err(&bp->pdev->dev,
  9374. "Cannot find PCI device base address, aborting\n");
  9375. rc = -ENODEV;
  9376. goto err_out_disable;
  9377. }
  9378. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9379. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  9380. " base address, aborting\n");
  9381. rc = -ENODEV;
  9382. goto err_out_disable;
  9383. }
  9384. if (atomic_read(&pdev->enable_cnt) == 1) {
  9385. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9386. if (rc) {
  9387. dev_err(&bp->pdev->dev,
  9388. "Cannot obtain PCI resources, aborting\n");
  9389. goto err_out_disable;
  9390. }
  9391. pci_set_master(pdev);
  9392. pci_save_state(pdev);
  9393. }
  9394. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9395. if (bp->pm_cap == 0) {
  9396. dev_err(&bp->pdev->dev,
  9397. "Cannot find power management capability, aborting\n");
  9398. rc = -EIO;
  9399. goto err_out_release;
  9400. }
  9401. if (!pci_is_pcie(pdev)) {
  9402. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9403. rc = -EIO;
  9404. goto err_out_release;
  9405. }
  9406. rc = bnx2x_set_coherency_mask(bp);
  9407. if (rc)
  9408. goto err_out_release;
  9409. dev->mem_start = pci_resource_start(pdev, 0);
  9410. dev->base_addr = dev->mem_start;
  9411. dev->mem_end = pci_resource_end(pdev, 0);
  9412. dev->irq = pdev->irq;
  9413. bp->regview = pci_ioremap_bar(pdev, 0);
  9414. if (!bp->regview) {
  9415. dev_err(&bp->pdev->dev,
  9416. "Cannot map register space, aborting\n");
  9417. rc = -ENOMEM;
  9418. goto err_out_release;
  9419. }
  9420. /* In E1/E1H use pci device function given by kernel.
  9421. * In E2/E3 read physical function from ME register since these chips
  9422. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9423. * (depending on hypervisor).
  9424. */
  9425. if (chip_is_e1x)
  9426. bp->pf_num = PCI_FUNC(pdev->devfn);
  9427. else {/* chip is E2/3*/
  9428. pci_read_config_dword(bp->pdev,
  9429. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9430. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9431. ME_REG_ABS_PF_NUM_SHIFT);
  9432. }
  9433. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9434. bnx2x_set_power_state(bp, PCI_D0);
  9435. /* clean indirect addresses */
  9436. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9437. PCICFG_VENDOR_ID_OFFSET);
  9438. /*
  9439. * Clean the following indirect addresses for all functions since it
  9440. * is not used by the driver.
  9441. */
  9442. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9443. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9444. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9445. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9446. if (chip_is_e1x) {
  9447. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9448. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9449. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9450. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9451. }
  9452. /*
  9453. * Enable internal target-read (in case we are probed after PF FLR).
  9454. * Must be done prior to any BAR read access. Only for 57712 and up
  9455. */
  9456. if (!chip_is_e1x)
  9457. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9458. /* Reset the load counter */
  9459. bnx2x_clear_load_status(bp);
  9460. dev->watchdog_timeo = TX_TIMEOUT;
  9461. dev->netdev_ops = &bnx2x_netdev_ops;
  9462. bnx2x_set_ethtool_ops(dev);
  9463. dev->priv_flags |= IFF_UNICAST_FLT;
  9464. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9465. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9466. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9467. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9468. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9469. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9470. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9471. if (bp->flags & USING_DAC_FLAG)
  9472. dev->features |= NETIF_F_HIGHDMA;
  9473. /* Add Loopback capability to the device */
  9474. dev->hw_features |= NETIF_F_LOOPBACK;
  9475. #ifdef BCM_DCBNL
  9476. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9477. #endif
  9478. /* get_port_hwinfo() will set prtad and mmds properly */
  9479. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9480. bp->mdio.mmds = 0;
  9481. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9482. bp->mdio.dev = dev;
  9483. bp->mdio.mdio_read = bnx2x_mdio_read;
  9484. bp->mdio.mdio_write = bnx2x_mdio_write;
  9485. return 0;
  9486. err_out_release:
  9487. if (atomic_read(&pdev->enable_cnt) == 1)
  9488. pci_release_regions(pdev);
  9489. err_out_disable:
  9490. pci_disable_device(pdev);
  9491. pci_set_drvdata(pdev, NULL);
  9492. err_out:
  9493. return rc;
  9494. }
  9495. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9496. int *width, int *speed)
  9497. {
  9498. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9499. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9500. /* return value of 1=2.5GHz 2=5GHz */
  9501. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9502. }
  9503. static int bnx2x_check_firmware(struct bnx2x *bp)
  9504. {
  9505. const struct firmware *firmware = bp->firmware;
  9506. struct bnx2x_fw_file_hdr *fw_hdr;
  9507. struct bnx2x_fw_file_section *sections;
  9508. u32 offset, len, num_ops;
  9509. u16 *ops_offsets;
  9510. int i;
  9511. const u8 *fw_ver;
  9512. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9513. BNX2X_ERR("Wrong FW size\n");
  9514. return -EINVAL;
  9515. }
  9516. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9517. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9518. /* Make sure none of the offsets and sizes make us read beyond
  9519. * the end of the firmware data */
  9520. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9521. offset = be32_to_cpu(sections[i].offset);
  9522. len = be32_to_cpu(sections[i].len);
  9523. if (offset + len > firmware->size) {
  9524. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9525. return -EINVAL;
  9526. }
  9527. }
  9528. /* Likewise for the init_ops offsets */
  9529. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9530. ops_offsets = (u16 *)(firmware->data + offset);
  9531. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9532. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9533. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9534. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9535. return -EINVAL;
  9536. }
  9537. }
  9538. /* Check FW version */
  9539. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9540. fw_ver = firmware->data + offset;
  9541. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9542. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9543. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9544. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9545. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9546. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9547. BCM_5710_FW_MAJOR_VERSION,
  9548. BCM_5710_FW_MINOR_VERSION,
  9549. BCM_5710_FW_REVISION_VERSION,
  9550. BCM_5710_FW_ENGINEERING_VERSION);
  9551. return -EINVAL;
  9552. }
  9553. return 0;
  9554. }
  9555. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9556. {
  9557. const __be32 *source = (const __be32 *)_source;
  9558. u32 *target = (u32 *)_target;
  9559. u32 i;
  9560. for (i = 0; i < n/4; i++)
  9561. target[i] = be32_to_cpu(source[i]);
  9562. }
  9563. /*
  9564. Ops array is stored in the following format:
  9565. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9566. */
  9567. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9568. {
  9569. const __be32 *source = (const __be32 *)_source;
  9570. struct raw_op *target = (struct raw_op *)_target;
  9571. u32 i, j, tmp;
  9572. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9573. tmp = be32_to_cpu(source[j]);
  9574. target[i].op = (tmp >> 24) & 0xff;
  9575. target[i].offset = tmp & 0xffffff;
  9576. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9577. }
  9578. }
  9579. /**
  9580. * IRO array is stored in the following format:
  9581. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9582. */
  9583. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9584. {
  9585. const __be32 *source = (const __be32 *)_source;
  9586. struct iro *target = (struct iro *)_target;
  9587. u32 i, j, tmp;
  9588. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9589. target[i].base = be32_to_cpu(source[j]);
  9590. j++;
  9591. tmp = be32_to_cpu(source[j]);
  9592. target[i].m1 = (tmp >> 16) & 0xffff;
  9593. target[i].m2 = tmp & 0xffff;
  9594. j++;
  9595. tmp = be32_to_cpu(source[j]);
  9596. target[i].m3 = (tmp >> 16) & 0xffff;
  9597. target[i].size = tmp & 0xffff;
  9598. j++;
  9599. }
  9600. }
  9601. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9602. {
  9603. const __be16 *source = (const __be16 *)_source;
  9604. u16 *target = (u16 *)_target;
  9605. u32 i;
  9606. for (i = 0; i < n/2; i++)
  9607. target[i] = be16_to_cpu(source[i]);
  9608. }
  9609. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9610. do { \
  9611. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9612. bp->arr = kmalloc(len, GFP_KERNEL); \
  9613. if (!bp->arr) \
  9614. goto lbl; \
  9615. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9616. (u8 *)bp->arr, len); \
  9617. } while (0)
  9618. static int bnx2x_init_firmware(struct bnx2x *bp)
  9619. {
  9620. const char *fw_file_name;
  9621. struct bnx2x_fw_file_hdr *fw_hdr;
  9622. int rc;
  9623. if (bp->firmware)
  9624. return 0;
  9625. if (CHIP_IS_E1(bp))
  9626. fw_file_name = FW_FILE_NAME_E1;
  9627. else if (CHIP_IS_E1H(bp))
  9628. fw_file_name = FW_FILE_NAME_E1H;
  9629. else if (!CHIP_IS_E1x(bp))
  9630. fw_file_name = FW_FILE_NAME_E2;
  9631. else {
  9632. BNX2X_ERR("Unsupported chip revision\n");
  9633. return -EINVAL;
  9634. }
  9635. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9636. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9637. if (rc) {
  9638. BNX2X_ERR("Can't load firmware file %s\n",
  9639. fw_file_name);
  9640. goto request_firmware_exit;
  9641. }
  9642. rc = bnx2x_check_firmware(bp);
  9643. if (rc) {
  9644. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9645. goto request_firmware_exit;
  9646. }
  9647. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9648. /* Initialize the pointers to the init arrays */
  9649. /* Blob */
  9650. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9651. /* Opcodes */
  9652. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9653. /* Offsets */
  9654. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9655. be16_to_cpu_n);
  9656. /* STORMs firmware */
  9657. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9658. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9659. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9660. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9661. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9662. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9663. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9664. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9665. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9666. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9667. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9668. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9669. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9670. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9671. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9672. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9673. /* IRO */
  9674. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9675. return 0;
  9676. iro_alloc_err:
  9677. kfree(bp->init_ops_offsets);
  9678. init_offsets_alloc_err:
  9679. kfree(bp->init_ops);
  9680. init_ops_alloc_err:
  9681. kfree(bp->init_data);
  9682. request_firmware_exit:
  9683. release_firmware(bp->firmware);
  9684. bp->firmware = NULL;
  9685. return rc;
  9686. }
  9687. static void bnx2x_release_firmware(struct bnx2x *bp)
  9688. {
  9689. kfree(bp->init_ops_offsets);
  9690. kfree(bp->init_ops);
  9691. kfree(bp->init_data);
  9692. release_firmware(bp->firmware);
  9693. bp->firmware = NULL;
  9694. }
  9695. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9696. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9697. .init_hw_cmn = bnx2x_init_hw_common,
  9698. .init_hw_port = bnx2x_init_hw_port,
  9699. .init_hw_func = bnx2x_init_hw_func,
  9700. .reset_hw_cmn = bnx2x_reset_common,
  9701. .reset_hw_port = bnx2x_reset_port,
  9702. .reset_hw_func = bnx2x_reset_func,
  9703. .gunzip_init = bnx2x_gunzip_init,
  9704. .gunzip_end = bnx2x_gunzip_end,
  9705. .init_fw = bnx2x_init_firmware,
  9706. .release_fw = bnx2x_release_firmware,
  9707. };
  9708. void bnx2x__init_func_obj(struct bnx2x *bp)
  9709. {
  9710. /* Prepare DMAE related driver resources */
  9711. bnx2x_setup_dmae(bp);
  9712. bnx2x_init_func_obj(bp, &bp->func_obj,
  9713. bnx2x_sp(bp, func_rdata),
  9714. bnx2x_sp_mapping(bp, func_rdata),
  9715. bnx2x_sp(bp, func_afex_rdata),
  9716. bnx2x_sp_mapping(bp, func_afex_rdata),
  9717. &bnx2x_func_sp_drv);
  9718. }
  9719. /* must be called after sriov-enable */
  9720. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9721. {
  9722. int cid_count = BNX2X_L2_CID_COUNT(bp);
  9723. #ifdef BCM_CNIC
  9724. cid_count += CNIC_CID_MAX;
  9725. #endif
  9726. return roundup(cid_count, QM_CID_ROUND);
  9727. }
  9728. /**
  9729. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9730. *
  9731. * @dev: pci device
  9732. *
  9733. */
  9734. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  9735. {
  9736. int pos;
  9737. u16 control;
  9738. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9739. /*
  9740. * If MSI-X is not supported - return number of SBs needed to support
  9741. * one fast path queue: one FP queue + SB for CNIC
  9742. */
  9743. if (!pos)
  9744. return 1 + CNIC_PRESENT;
  9745. /*
  9746. * The value in the PCI configuration space is the index of the last
  9747. * entry, namely one less than the actual size of the table, which is
  9748. * exactly what we want to return from this function: number of all SBs
  9749. * without the default SB.
  9750. */
  9751. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9752. return control & PCI_MSIX_FLAGS_QSIZE;
  9753. }
  9754. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9755. const struct pci_device_id *ent)
  9756. {
  9757. struct net_device *dev = NULL;
  9758. struct bnx2x *bp;
  9759. int pcie_width, pcie_speed;
  9760. int rc, max_non_def_sbs;
  9761. int rx_count, tx_count, rss_count;
  9762. /*
  9763. * An estimated maximum supported CoS number according to the chip
  9764. * version.
  9765. * We will try to roughly estimate the maximum number of CoSes this chip
  9766. * may support in order to minimize the memory allocated for Tx
  9767. * netdev_queue's. This number will be accurately calculated during the
  9768. * initialization of bp->max_cos based on the chip versions AND chip
  9769. * revision in the bnx2x_init_bp().
  9770. */
  9771. u8 max_cos_est = 0;
  9772. switch (ent->driver_data) {
  9773. case BCM57710:
  9774. case BCM57711:
  9775. case BCM57711E:
  9776. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  9777. break;
  9778. case BCM57712:
  9779. case BCM57712_MF:
  9780. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  9781. break;
  9782. case BCM57800:
  9783. case BCM57800_MF:
  9784. case BCM57810:
  9785. case BCM57810_MF:
  9786. case BCM57840:
  9787. case BCM57840_MF:
  9788. case BCM57811:
  9789. case BCM57811_MF:
  9790. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  9791. break;
  9792. default:
  9793. pr_err("Unknown board_type (%ld), aborting\n",
  9794. ent->driver_data);
  9795. return -ENODEV;
  9796. }
  9797. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  9798. /* !!! FIXME !!!
  9799. * Do not allow the maximum SB count to grow above 16
  9800. * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
  9801. * We will use the FP_SB_MAX_E1x macro for this matter.
  9802. */
  9803. max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
  9804. WARN_ON(!max_non_def_sbs);
  9805. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  9806. rss_count = max_non_def_sbs - CNIC_PRESENT;
  9807. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  9808. rx_count = rss_count + FCOE_PRESENT;
  9809. /*
  9810. * Maximum number of netdev Tx queues:
  9811. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  9812. */
  9813. tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
  9814. /* dev zeroed in init_etherdev */
  9815. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  9816. if (!dev)
  9817. return -ENOMEM;
  9818. bp = netdev_priv(dev);
  9819. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  9820. tx_count, rx_count);
  9821. bp->igu_sb_cnt = max_non_def_sbs;
  9822. bp->msg_enable = debug;
  9823. pci_set_drvdata(pdev, dev);
  9824. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9825. if (rc < 0) {
  9826. free_netdev(dev);
  9827. return rc;
  9828. }
  9829. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  9830. rc = bnx2x_init_bp(bp);
  9831. if (rc)
  9832. goto init_one_exit;
  9833. /*
  9834. * Map doorbels here as we need the real value of bp->max_cos which
  9835. * is initialized in bnx2x_init_bp().
  9836. */
  9837. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9838. min_t(u64, BNX2X_DB_SIZE(bp),
  9839. pci_resource_len(pdev, 2)));
  9840. if (!bp->doorbells) {
  9841. dev_err(&bp->pdev->dev,
  9842. "Cannot map doorbell space, aborting\n");
  9843. rc = -ENOMEM;
  9844. goto init_one_exit;
  9845. }
  9846. /* calc qm_cid_count */
  9847. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9848. #ifdef BCM_CNIC
  9849. /* disable FCOE L2 queue for E1x */
  9850. if (CHIP_IS_E1x(bp))
  9851. bp->flags |= NO_FCOE_FLAG;
  9852. #endif
  9853. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9854. * needed, set bp->num_queues appropriately.
  9855. */
  9856. bnx2x_set_int_mode(bp);
  9857. /* Add all NAPI objects */
  9858. bnx2x_add_all_napi(bp);
  9859. rc = register_netdev(dev);
  9860. if (rc) {
  9861. dev_err(&pdev->dev, "Cannot register net device\n");
  9862. goto init_one_exit;
  9863. }
  9864. #ifdef BCM_CNIC
  9865. if (!NO_FCOE(bp)) {
  9866. /* Add storage MAC address */
  9867. rtnl_lock();
  9868. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9869. rtnl_unlock();
  9870. }
  9871. #endif
  9872. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9873. BNX2X_DEV_INFO(
  9874. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9875. board_info[ent->driver_data].name,
  9876. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9877. pcie_width,
  9878. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9879. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9880. "5GHz (Gen2)" : "2.5GHz",
  9881. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9882. return 0;
  9883. init_one_exit:
  9884. if (bp->regview)
  9885. iounmap(bp->regview);
  9886. if (bp->doorbells)
  9887. iounmap(bp->doorbells);
  9888. free_netdev(dev);
  9889. if (atomic_read(&pdev->enable_cnt) == 1)
  9890. pci_release_regions(pdev);
  9891. pci_disable_device(pdev);
  9892. pci_set_drvdata(pdev, NULL);
  9893. return rc;
  9894. }
  9895. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9896. {
  9897. struct net_device *dev = pci_get_drvdata(pdev);
  9898. struct bnx2x *bp;
  9899. if (!dev) {
  9900. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9901. return;
  9902. }
  9903. bp = netdev_priv(dev);
  9904. #ifdef BCM_CNIC
  9905. /* Delete storage MAC address */
  9906. if (!NO_FCOE(bp)) {
  9907. rtnl_lock();
  9908. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9909. rtnl_unlock();
  9910. }
  9911. #endif
  9912. #ifdef BCM_DCBNL
  9913. /* Delete app tlvs from dcbnl */
  9914. bnx2x_dcbnl_update_applist(bp, true);
  9915. #endif
  9916. unregister_netdev(dev);
  9917. /* Delete all NAPI objects */
  9918. bnx2x_del_all_napi(bp);
  9919. /* Power on: we can't let PCI layer write to us while we are in D3 */
  9920. bnx2x_set_power_state(bp, PCI_D0);
  9921. /* Disable MSI/MSI-X */
  9922. bnx2x_disable_msi(bp);
  9923. /* Power off */
  9924. bnx2x_set_power_state(bp, PCI_D3hot);
  9925. /* Make sure RESET task is not scheduled before continuing */
  9926. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  9927. if (bp->regview)
  9928. iounmap(bp->regview);
  9929. if (bp->doorbells)
  9930. iounmap(bp->doorbells);
  9931. bnx2x_release_firmware(bp);
  9932. bnx2x_free_mem_bp(bp);
  9933. free_netdev(dev);
  9934. if (atomic_read(&pdev->enable_cnt) == 1)
  9935. pci_release_regions(pdev);
  9936. pci_disable_device(pdev);
  9937. pci_set_drvdata(pdev, NULL);
  9938. }
  9939. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9940. {
  9941. int i;
  9942. bp->state = BNX2X_STATE_ERROR;
  9943. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9944. #ifdef BCM_CNIC
  9945. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  9946. #endif
  9947. /* Stop Tx */
  9948. bnx2x_tx_disable(bp);
  9949. bnx2x_netif_stop(bp, 0);
  9950. del_timer_sync(&bp->timer);
  9951. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  9952. /* Release IRQs */
  9953. bnx2x_free_irq(bp);
  9954. /* Free SKBs, SGEs, TPA pool and driver internals */
  9955. bnx2x_free_skbs(bp);
  9956. for_each_rx_queue(bp, i)
  9957. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  9958. bnx2x_free_mem(bp);
  9959. bp->state = BNX2X_STATE_CLOSED;
  9960. netif_carrier_off(bp->dev);
  9961. return 0;
  9962. }
  9963. static void bnx2x_eeh_recover(struct bnx2x *bp)
  9964. {
  9965. u32 val;
  9966. mutex_init(&bp->port.phy_mutex);
  9967. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  9968. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9969. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9970. BNX2X_ERR("BAD MCP validity signature\n");
  9971. }
  9972. /**
  9973. * bnx2x_io_error_detected - called when PCI error is detected
  9974. * @pdev: Pointer to PCI device
  9975. * @state: The current pci connection state
  9976. *
  9977. * This function is called after a PCI bus error affecting
  9978. * this device has been detected.
  9979. */
  9980. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  9981. pci_channel_state_t state)
  9982. {
  9983. struct net_device *dev = pci_get_drvdata(pdev);
  9984. struct bnx2x *bp = netdev_priv(dev);
  9985. rtnl_lock();
  9986. netif_device_detach(dev);
  9987. if (state == pci_channel_io_perm_failure) {
  9988. rtnl_unlock();
  9989. return PCI_ERS_RESULT_DISCONNECT;
  9990. }
  9991. if (netif_running(dev))
  9992. bnx2x_eeh_nic_unload(bp);
  9993. pci_disable_device(pdev);
  9994. rtnl_unlock();
  9995. /* Request a slot reset */
  9996. return PCI_ERS_RESULT_NEED_RESET;
  9997. }
  9998. /**
  9999. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10000. * @pdev: Pointer to PCI device
  10001. *
  10002. * Restart the card from scratch, as if from a cold-boot.
  10003. */
  10004. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10005. {
  10006. struct net_device *dev = pci_get_drvdata(pdev);
  10007. struct bnx2x *bp = netdev_priv(dev);
  10008. rtnl_lock();
  10009. if (pci_enable_device(pdev)) {
  10010. dev_err(&pdev->dev,
  10011. "Cannot re-enable PCI device after reset\n");
  10012. rtnl_unlock();
  10013. return PCI_ERS_RESULT_DISCONNECT;
  10014. }
  10015. pci_set_master(pdev);
  10016. pci_restore_state(pdev);
  10017. if (netif_running(dev))
  10018. bnx2x_set_power_state(bp, PCI_D0);
  10019. rtnl_unlock();
  10020. return PCI_ERS_RESULT_RECOVERED;
  10021. }
  10022. /**
  10023. * bnx2x_io_resume - called when traffic can start flowing again
  10024. * @pdev: Pointer to PCI device
  10025. *
  10026. * This callback is called when the error recovery driver tells us that
  10027. * its OK to resume normal operation.
  10028. */
  10029. static void bnx2x_io_resume(struct pci_dev *pdev)
  10030. {
  10031. struct net_device *dev = pci_get_drvdata(pdev);
  10032. struct bnx2x *bp = netdev_priv(dev);
  10033. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10034. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10035. return;
  10036. }
  10037. rtnl_lock();
  10038. bnx2x_eeh_recover(bp);
  10039. if (netif_running(dev))
  10040. bnx2x_nic_load(bp, LOAD_NORMAL);
  10041. netif_device_attach(dev);
  10042. rtnl_unlock();
  10043. }
  10044. static struct pci_error_handlers bnx2x_err_handler = {
  10045. .error_detected = bnx2x_io_error_detected,
  10046. .slot_reset = bnx2x_io_slot_reset,
  10047. .resume = bnx2x_io_resume,
  10048. };
  10049. static struct pci_driver bnx2x_pci_driver = {
  10050. .name = DRV_MODULE_NAME,
  10051. .id_table = bnx2x_pci_tbl,
  10052. .probe = bnx2x_init_one,
  10053. .remove = __devexit_p(bnx2x_remove_one),
  10054. .suspend = bnx2x_suspend,
  10055. .resume = bnx2x_resume,
  10056. .err_handler = &bnx2x_err_handler,
  10057. };
  10058. static int __init bnx2x_init(void)
  10059. {
  10060. int ret;
  10061. pr_info("%s", version);
  10062. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10063. if (bnx2x_wq == NULL) {
  10064. pr_err("Cannot create workqueue\n");
  10065. return -ENOMEM;
  10066. }
  10067. ret = pci_register_driver(&bnx2x_pci_driver);
  10068. if (ret) {
  10069. pr_err("Cannot register driver\n");
  10070. destroy_workqueue(bnx2x_wq);
  10071. }
  10072. return ret;
  10073. }
  10074. static void __exit bnx2x_cleanup(void)
  10075. {
  10076. struct list_head *pos, *q;
  10077. pci_unregister_driver(&bnx2x_pci_driver);
  10078. destroy_workqueue(bnx2x_wq);
  10079. /* Free globablly allocated resources */
  10080. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10081. struct bnx2x_prev_path_list *tmp =
  10082. list_entry(pos, struct bnx2x_prev_path_list, list);
  10083. list_del(pos);
  10084. kfree(tmp);
  10085. }
  10086. }
  10087. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10088. {
  10089. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10090. }
  10091. module_init(bnx2x_init);
  10092. module_exit(bnx2x_cleanup);
  10093. #ifdef BCM_CNIC
  10094. /**
  10095. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10096. *
  10097. * @bp: driver handle
  10098. * @set: set or clear the CAM entry
  10099. *
  10100. * This function will wait until the ramdord completion returns.
  10101. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10102. */
  10103. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10104. {
  10105. unsigned long ramrod_flags = 0;
  10106. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10107. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10108. &bp->iscsi_l2_mac_obj, true,
  10109. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10110. }
  10111. /* count denotes the number of new completions we have seen */
  10112. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10113. {
  10114. struct eth_spe *spe;
  10115. #ifdef BNX2X_STOP_ON_ERROR
  10116. if (unlikely(bp->panic))
  10117. return;
  10118. #endif
  10119. spin_lock_bh(&bp->spq_lock);
  10120. BUG_ON(bp->cnic_spq_pending < count);
  10121. bp->cnic_spq_pending -= count;
  10122. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10123. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10124. & SPE_HDR_CONN_TYPE) >>
  10125. SPE_HDR_CONN_TYPE_SHIFT;
  10126. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10127. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10128. /* Set validation for iSCSI L2 client before sending SETUP
  10129. * ramrod
  10130. */
  10131. if (type == ETH_CONNECTION_TYPE) {
  10132. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  10133. bnx2x_set_ctx_validation(bp, &bp->context.
  10134. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  10135. BNX2X_ISCSI_ETH_CID);
  10136. }
  10137. /*
  10138. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10139. * and in the air. We also check that number of outstanding
  10140. * COMMON ramrods is not more than the EQ and SPQ can
  10141. * accommodate.
  10142. */
  10143. if (type == ETH_CONNECTION_TYPE) {
  10144. if (!atomic_read(&bp->cq_spq_left))
  10145. break;
  10146. else
  10147. atomic_dec(&bp->cq_spq_left);
  10148. } else if (type == NONE_CONNECTION_TYPE) {
  10149. if (!atomic_read(&bp->eq_spq_left))
  10150. break;
  10151. else
  10152. atomic_dec(&bp->eq_spq_left);
  10153. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10154. (type == FCOE_CONNECTION_TYPE)) {
  10155. if (bp->cnic_spq_pending >=
  10156. bp->cnic_eth_dev.max_kwqe_pending)
  10157. break;
  10158. else
  10159. bp->cnic_spq_pending++;
  10160. } else {
  10161. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10162. bnx2x_panic();
  10163. break;
  10164. }
  10165. spe = bnx2x_sp_get_next(bp);
  10166. *spe = *bp->cnic_kwq_cons;
  10167. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10168. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10169. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10170. bp->cnic_kwq_cons = bp->cnic_kwq;
  10171. else
  10172. bp->cnic_kwq_cons++;
  10173. }
  10174. bnx2x_sp_prod_update(bp);
  10175. spin_unlock_bh(&bp->spq_lock);
  10176. }
  10177. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10178. struct kwqe_16 *kwqes[], u32 count)
  10179. {
  10180. struct bnx2x *bp = netdev_priv(dev);
  10181. int i;
  10182. #ifdef BNX2X_STOP_ON_ERROR
  10183. if (unlikely(bp->panic)) {
  10184. BNX2X_ERR("Can't post to SP queue while panic\n");
  10185. return -EIO;
  10186. }
  10187. #endif
  10188. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10189. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10190. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10191. return -EAGAIN;
  10192. }
  10193. spin_lock_bh(&bp->spq_lock);
  10194. for (i = 0; i < count; i++) {
  10195. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10196. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10197. break;
  10198. *bp->cnic_kwq_prod = *spe;
  10199. bp->cnic_kwq_pending++;
  10200. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10201. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10202. spe->data.update_data_addr.hi,
  10203. spe->data.update_data_addr.lo,
  10204. bp->cnic_kwq_pending);
  10205. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10206. bp->cnic_kwq_prod = bp->cnic_kwq;
  10207. else
  10208. bp->cnic_kwq_prod++;
  10209. }
  10210. spin_unlock_bh(&bp->spq_lock);
  10211. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10212. bnx2x_cnic_sp_post(bp, 0);
  10213. return i;
  10214. }
  10215. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10216. {
  10217. struct cnic_ops *c_ops;
  10218. int rc = 0;
  10219. mutex_lock(&bp->cnic_mutex);
  10220. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10221. lockdep_is_held(&bp->cnic_mutex));
  10222. if (c_ops)
  10223. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10224. mutex_unlock(&bp->cnic_mutex);
  10225. return rc;
  10226. }
  10227. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10228. {
  10229. struct cnic_ops *c_ops;
  10230. int rc = 0;
  10231. rcu_read_lock();
  10232. c_ops = rcu_dereference(bp->cnic_ops);
  10233. if (c_ops)
  10234. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10235. rcu_read_unlock();
  10236. return rc;
  10237. }
  10238. /*
  10239. * for commands that have no data
  10240. */
  10241. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10242. {
  10243. struct cnic_ctl_info ctl = {0};
  10244. ctl.cmd = cmd;
  10245. return bnx2x_cnic_ctl_send(bp, &ctl);
  10246. }
  10247. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10248. {
  10249. struct cnic_ctl_info ctl = {0};
  10250. /* first we tell CNIC and only then we count this as a completion */
  10251. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10252. ctl.data.comp.cid = cid;
  10253. ctl.data.comp.error = err;
  10254. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10255. bnx2x_cnic_sp_post(bp, 0);
  10256. }
  10257. /* Called with netif_addr_lock_bh() taken.
  10258. * Sets an rx_mode config for an iSCSI ETH client.
  10259. * Doesn't block.
  10260. * Completion should be checked outside.
  10261. */
  10262. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10263. {
  10264. unsigned long accept_flags = 0, ramrod_flags = 0;
  10265. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10266. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10267. if (start) {
  10268. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10269. * because it's the only way for UIO Queue to accept
  10270. * multicasts (in non-promiscuous mode only one Queue per
  10271. * function will receive multicast packets (leading in our
  10272. * case).
  10273. */
  10274. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10275. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10276. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10277. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10278. /* Clear STOP_PENDING bit if START is requested */
  10279. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10280. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10281. } else
  10282. /* Clear START_PENDING bit if STOP is requested */
  10283. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10284. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10285. set_bit(sched_state, &bp->sp_state);
  10286. else {
  10287. __set_bit(RAMROD_RX, &ramrod_flags);
  10288. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10289. ramrod_flags);
  10290. }
  10291. }
  10292. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10293. {
  10294. struct bnx2x *bp = netdev_priv(dev);
  10295. int rc = 0;
  10296. switch (ctl->cmd) {
  10297. case DRV_CTL_CTXTBL_WR_CMD: {
  10298. u32 index = ctl->data.io.offset;
  10299. dma_addr_t addr = ctl->data.io.dma_addr;
  10300. bnx2x_ilt_wr(bp, index, addr);
  10301. break;
  10302. }
  10303. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10304. int count = ctl->data.credit.credit_count;
  10305. bnx2x_cnic_sp_post(bp, count);
  10306. break;
  10307. }
  10308. /* rtnl_lock is held. */
  10309. case DRV_CTL_START_L2_CMD: {
  10310. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10311. unsigned long sp_bits = 0;
  10312. /* Configure the iSCSI classification object */
  10313. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10314. cp->iscsi_l2_client_id,
  10315. cp->iscsi_l2_cid, BP_FUNC(bp),
  10316. bnx2x_sp(bp, mac_rdata),
  10317. bnx2x_sp_mapping(bp, mac_rdata),
  10318. BNX2X_FILTER_MAC_PENDING,
  10319. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10320. &bp->macs_pool);
  10321. /* Set iSCSI MAC address */
  10322. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10323. if (rc)
  10324. break;
  10325. mmiowb();
  10326. barrier();
  10327. /* Start accepting on iSCSI L2 ring */
  10328. netif_addr_lock_bh(dev);
  10329. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10330. netif_addr_unlock_bh(dev);
  10331. /* bits to wait on */
  10332. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10333. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10334. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10335. BNX2X_ERR("rx_mode completion timed out!\n");
  10336. break;
  10337. }
  10338. /* rtnl_lock is held. */
  10339. case DRV_CTL_STOP_L2_CMD: {
  10340. unsigned long sp_bits = 0;
  10341. /* Stop accepting on iSCSI L2 ring */
  10342. netif_addr_lock_bh(dev);
  10343. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10344. netif_addr_unlock_bh(dev);
  10345. /* bits to wait on */
  10346. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10347. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10348. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10349. BNX2X_ERR("rx_mode completion timed out!\n");
  10350. mmiowb();
  10351. barrier();
  10352. /* Unset iSCSI L2 MAC */
  10353. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10354. BNX2X_ISCSI_ETH_MAC, true);
  10355. break;
  10356. }
  10357. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10358. int count = ctl->data.credit.credit_count;
  10359. smp_mb__before_atomic_inc();
  10360. atomic_add(count, &bp->cq_spq_left);
  10361. smp_mb__after_atomic_inc();
  10362. break;
  10363. }
  10364. case DRV_CTL_ULP_REGISTER_CMD: {
  10365. int ulp_type = ctl->data.ulp_type;
  10366. if (CHIP_IS_E3(bp)) {
  10367. int idx = BP_FW_MB_IDX(bp);
  10368. u32 cap;
  10369. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10370. if (ulp_type == CNIC_ULP_ISCSI)
  10371. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10372. else if (ulp_type == CNIC_ULP_FCOE)
  10373. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10374. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10375. }
  10376. break;
  10377. }
  10378. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10379. int ulp_type = ctl->data.ulp_type;
  10380. if (CHIP_IS_E3(bp)) {
  10381. int idx = BP_FW_MB_IDX(bp);
  10382. u32 cap;
  10383. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10384. if (ulp_type == CNIC_ULP_ISCSI)
  10385. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10386. else if (ulp_type == CNIC_ULP_FCOE)
  10387. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10388. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10389. }
  10390. break;
  10391. }
  10392. default:
  10393. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10394. rc = -EINVAL;
  10395. }
  10396. return rc;
  10397. }
  10398. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10399. {
  10400. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10401. if (bp->flags & USING_MSIX_FLAG) {
  10402. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10403. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10404. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10405. } else {
  10406. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10407. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10408. }
  10409. if (!CHIP_IS_E1x(bp))
  10410. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10411. else
  10412. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10413. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10414. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10415. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10416. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10417. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10418. cp->num_irq = 2;
  10419. }
  10420. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10421. void *data)
  10422. {
  10423. struct bnx2x *bp = netdev_priv(dev);
  10424. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10425. if (ops == NULL) {
  10426. BNX2X_ERR("NULL ops received\n");
  10427. return -EINVAL;
  10428. }
  10429. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10430. if (!bp->cnic_kwq)
  10431. return -ENOMEM;
  10432. bp->cnic_kwq_cons = bp->cnic_kwq;
  10433. bp->cnic_kwq_prod = bp->cnic_kwq;
  10434. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10435. bp->cnic_spq_pending = 0;
  10436. bp->cnic_kwq_pending = 0;
  10437. bp->cnic_data = data;
  10438. cp->num_irq = 0;
  10439. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10440. cp->iro_arr = bp->iro_arr;
  10441. bnx2x_setup_cnic_irq_info(bp);
  10442. rcu_assign_pointer(bp->cnic_ops, ops);
  10443. return 0;
  10444. }
  10445. static int bnx2x_unregister_cnic(struct net_device *dev)
  10446. {
  10447. struct bnx2x *bp = netdev_priv(dev);
  10448. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10449. mutex_lock(&bp->cnic_mutex);
  10450. cp->drv_state = 0;
  10451. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10452. mutex_unlock(&bp->cnic_mutex);
  10453. synchronize_rcu();
  10454. kfree(bp->cnic_kwq);
  10455. bp->cnic_kwq = NULL;
  10456. return 0;
  10457. }
  10458. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10459. {
  10460. struct bnx2x *bp = netdev_priv(dev);
  10461. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10462. /* If both iSCSI and FCoE are disabled - return NULL in
  10463. * order to indicate CNIC that it should not try to work
  10464. * with this device.
  10465. */
  10466. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10467. return NULL;
  10468. cp->drv_owner = THIS_MODULE;
  10469. cp->chip_id = CHIP_ID(bp);
  10470. cp->pdev = bp->pdev;
  10471. cp->io_base = bp->regview;
  10472. cp->io_base2 = bp->doorbells;
  10473. cp->max_kwqe_pending = 8;
  10474. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10475. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10476. bnx2x_cid_ilt_lines(bp);
  10477. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10478. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10479. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10480. cp->drv_ctl = bnx2x_drv_ctl;
  10481. cp->drv_register_cnic = bnx2x_register_cnic;
  10482. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10483. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  10484. cp->iscsi_l2_client_id =
  10485. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10486. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  10487. if (NO_ISCSI_OOO(bp))
  10488. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10489. if (NO_ISCSI(bp))
  10490. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10491. if (NO_FCOE(bp))
  10492. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10493. BNX2X_DEV_INFO(
  10494. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10495. cp->ctx_blk_size,
  10496. cp->ctx_tbl_offset,
  10497. cp->ctx_tbl_len,
  10498. cp->starting_cid);
  10499. return cp;
  10500. }
  10501. EXPORT_SYMBOL(bnx2x_cnic_probe);
  10502. #endif /* BCM_CNIC */