bnx2x_sp.c 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952
  1. /* bnx2x_sp.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2011-2013 Broadcom Corporation
  4. *
  5. * Unless you and Broadcom execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Broadcom software provided under a
  12. * license other than the GPL, without Broadcom's express prior written
  13. * consent.
  14. *
  15. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  16. * Written by: Vladislav Zolotarov
  17. *
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/module.h>
  21. #include <linux/crc32.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/crc32c.h>
  25. #include "bnx2x.h"
  26. #include "bnx2x_cmn.h"
  27. #include "bnx2x_sp.h"
  28. #define BNX2X_MAX_EMUL_MULTI 16
  29. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  30. /**** Exe Queue interfaces ****/
  31. /**
  32. * bnx2x_exe_queue_init - init the Exe Queue object
  33. *
  34. * @o: poiter to the object
  35. * @exe_len: length
  36. * @owner: poiter to the owner
  37. * @validate: validate function pointer
  38. * @optimize: optimize function pointer
  39. * @exec: execute function pointer
  40. * @get: get function pointer
  41. */
  42. static inline void bnx2x_exe_queue_init(struct bnx2x *bp,
  43. struct bnx2x_exe_queue_obj *o,
  44. int exe_len,
  45. union bnx2x_qable_obj *owner,
  46. exe_q_validate validate,
  47. exe_q_remove remove,
  48. exe_q_optimize optimize,
  49. exe_q_execute exec,
  50. exe_q_get get)
  51. {
  52. memset(o, 0, sizeof(*o));
  53. INIT_LIST_HEAD(&o->exe_queue);
  54. INIT_LIST_HEAD(&o->pending_comp);
  55. spin_lock_init(&o->lock);
  56. o->exe_chunk_len = exe_len;
  57. o->owner = owner;
  58. /* Owner specific callbacks */
  59. o->validate = validate;
  60. o->remove = remove;
  61. o->optimize = optimize;
  62. o->execute = exec;
  63. o->get = get;
  64. DP(BNX2X_MSG_SP, "Setup the execution queue with the chunk length of %d\n",
  65. exe_len);
  66. }
  67. static inline void bnx2x_exe_queue_free_elem(struct bnx2x *bp,
  68. struct bnx2x_exeq_elem *elem)
  69. {
  70. DP(BNX2X_MSG_SP, "Deleting an exe_queue element\n");
  71. kfree(elem);
  72. }
  73. static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
  74. {
  75. struct bnx2x_exeq_elem *elem;
  76. int cnt = 0;
  77. spin_lock_bh(&o->lock);
  78. list_for_each_entry(elem, &o->exe_queue, link)
  79. cnt++;
  80. spin_unlock_bh(&o->lock);
  81. return cnt;
  82. }
  83. /**
  84. * bnx2x_exe_queue_add - add a new element to the execution queue
  85. *
  86. * @bp: driver handle
  87. * @o: queue
  88. * @cmd: new command to add
  89. * @restore: true - do not optimize the command
  90. *
  91. * If the element is optimized or is illegal, frees it.
  92. */
  93. static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
  94. struct bnx2x_exe_queue_obj *o,
  95. struct bnx2x_exeq_elem *elem,
  96. bool restore)
  97. {
  98. int rc;
  99. spin_lock_bh(&o->lock);
  100. if (!restore) {
  101. /* Try to cancel this element queue */
  102. rc = o->optimize(bp, o->owner, elem);
  103. if (rc)
  104. goto free_and_exit;
  105. /* Check if this request is ok */
  106. rc = o->validate(bp, o->owner, elem);
  107. if (rc) {
  108. DP(BNX2X_MSG_SP, "Preamble failed: %d\n", rc);
  109. goto free_and_exit;
  110. }
  111. }
  112. /* If so, add it to the execution queue */
  113. list_add_tail(&elem->link, &o->exe_queue);
  114. spin_unlock_bh(&o->lock);
  115. return 0;
  116. free_and_exit:
  117. bnx2x_exe_queue_free_elem(bp, elem);
  118. spin_unlock_bh(&o->lock);
  119. return rc;
  120. }
  121. static inline void __bnx2x_exe_queue_reset_pending(
  122. struct bnx2x *bp,
  123. struct bnx2x_exe_queue_obj *o)
  124. {
  125. struct bnx2x_exeq_elem *elem;
  126. while (!list_empty(&o->pending_comp)) {
  127. elem = list_first_entry(&o->pending_comp,
  128. struct bnx2x_exeq_elem, link);
  129. list_del(&elem->link);
  130. bnx2x_exe_queue_free_elem(bp, elem);
  131. }
  132. }
  133. static inline void bnx2x_exe_queue_reset_pending(struct bnx2x *bp,
  134. struct bnx2x_exe_queue_obj *o)
  135. {
  136. spin_lock_bh(&o->lock);
  137. __bnx2x_exe_queue_reset_pending(bp, o);
  138. spin_unlock_bh(&o->lock);
  139. }
  140. /**
  141. * bnx2x_exe_queue_step - execute one execution chunk atomically
  142. *
  143. * @bp: driver handle
  144. * @o: queue
  145. * @ramrod_flags: flags
  146. *
  147. * (Atomicy is ensured using the exe_queue->lock).
  148. */
  149. static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
  150. struct bnx2x_exe_queue_obj *o,
  151. unsigned long *ramrod_flags)
  152. {
  153. struct bnx2x_exeq_elem *elem, spacer;
  154. int cur_len = 0, rc;
  155. memset(&spacer, 0, sizeof(spacer));
  156. spin_lock_bh(&o->lock);
  157. /*
  158. * Next step should not be performed until the current is finished,
  159. * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
  160. * properly clear object internals without sending any command to the FW
  161. * which also implies there won't be any completion to clear the
  162. * 'pending' list.
  163. */
  164. if (!list_empty(&o->pending_comp)) {
  165. if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
  166. DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
  167. __bnx2x_exe_queue_reset_pending(bp, o);
  168. } else {
  169. spin_unlock_bh(&o->lock);
  170. return 1;
  171. }
  172. }
  173. /*
  174. * Run through the pending commands list and create a next
  175. * execution chunk.
  176. */
  177. while (!list_empty(&o->exe_queue)) {
  178. elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
  179. link);
  180. WARN_ON(!elem->cmd_len);
  181. if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
  182. cur_len += elem->cmd_len;
  183. /*
  184. * Prevent from both lists being empty when moving an
  185. * element. This will allow the call of
  186. * bnx2x_exe_queue_empty() without locking.
  187. */
  188. list_add_tail(&spacer.link, &o->pending_comp);
  189. mb();
  190. list_move_tail(&elem->link, &o->pending_comp);
  191. list_del(&spacer.link);
  192. } else
  193. break;
  194. }
  195. /* Sanity check */
  196. if (!cur_len) {
  197. spin_unlock_bh(&o->lock);
  198. return 0;
  199. }
  200. rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
  201. if (rc < 0)
  202. /*
  203. * In case of an error return the commands back to the queue
  204. * and reset the pending_comp.
  205. */
  206. list_splice_init(&o->pending_comp, &o->exe_queue);
  207. else if (!rc)
  208. /*
  209. * If zero is returned, means there are no outstanding pending
  210. * completions and we may dismiss the pending list.
  211. */
  212. __bnx2x_exe_queue_reset_pending(bp, o);
  213. spin_unlock_bh(&o->lock);
  214. return rc;
  215. }
  216. static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj *o)
  217. {
  218. bool empty = list_empty(&o->exe_queue);
  219. /* Don't reorder!!! */
  220. mb();
  221. return empty && list_empty(&o->pending_comp);
  222. }
  223. static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
  224. struct bnx2x *bp)
  225. {
  226. DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
  227. return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
  228. }
  229. /************************ raw_obj functions ***********************************/
  230. static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
  231. {
  232. return !!test_bit(o->state, o->pstate);
  233. }
  234. static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
  235. {
  236. smp_mb__before_clear_bit();
  237. clear_bit(o->state, o->pstate);
  238. smp_mb__after_clear_bit();
  239. }
  240. static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
  241. {
  242. smp_mb__before_clear_bit();
  243. set_bit(o->state, o->pstate);
  244. smp_mb__after_clear_bit();
  245. }
  246. /**
  247. * bnx2x_state_wait - wait until the given bit(state) is cleared
  248. *
  249. * @bp: device handle
  250. * @state: state which is to be cleared
  251. * @state_p: state buffer
  252. *
  253. */
  254. static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
  255. unsigned long *pstate)
  256. {
  257. /* can take a while if any port is running */
  258. int cnt = 5000;
  259. if (CHIP_REV_IS_EMUL(bp))
  260. cnt *= 20;
  261. DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
  262. might_sleep();
  263. while (cnt--) {
  264. if (!test_bit(state, pstate)) {
  265. #ifdef BNX2X_STOP_ON_ERROR
  266. DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt);
  267. #endif
  268. return 0;
  269. }
  270. usleep_range(1000, 2000);
  271. if (bp->panic)
  272. return -EIO;
  273. }
  274. /* timeout! */
  275. BNX2X_ERR("timeout waiting for state %d\n", state);
  276. #ifdef BNX2X_STOP_ON_ERROR
  277. bnx2x_panic();
  278. #endif
  279. return -EBUSY;
  280. }
  281. static int bnx2x_raw_wait(struct bnx2x *bp, struct bnx2x_raw_obj *raw)
  282. {
  283. return bnx2x_state_wait(bp, raw->state, raw->pstate);
  284. }
  285. /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
  286. /* credit handling callbacks */
  287. static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
  288. {
  289. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  290. WARN_ON(!mp);
  291. return mp->get_entry(mp, offset);
  292. }
  293. static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
  294. {
  295. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  296. WARN_ON(!mp);
  297. return mp->get(mp, 1);
  298. }
  299. static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
  300. {
  301. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  302. WARN_ON(!vp);
  303. return vp->get_entry(vp, offset);
  304. }
  305. static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
  306. {
  307. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  308. WARN_ON(!vp);
  309. return vp->get(vp, 1);
  310. }
  311. static bool bnx2x_get_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
  312. {
  313. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  314. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  315. if (!mp->get(mp, 1))
  316. return false;
  317. if (!vp->get(vp, 1)) {
  318. mp->put(mp, 1);
  319. return false;
  320. }
  321. return true;
  322. }
  323. static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int offset)
  324. {
  325. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  326. return mp->put_entry(mp, offset);
  327. }
  328. static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj *o)
  329. {
  330. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  331. return mp->put(mp, 1);
  332. }
  333. static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int offset)
  334. {
  335. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  336. return vp->put_entry(vp, offset);
  337. }
  338. static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj *o)
  339. {
  340. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  341. return vp->put(vp, 1);
  342. }
  343. static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
  344. {
  345. struct bnx2x_credit_pool_obj *mp = o->macs_pool;
  346. struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
  347. if (!mp->put(mp, 1))
  348. return false;
  349. if (!vp->put(vp, 1)) {
  350. mp->get(mp, 1);
  351. return false;
  352. }
  353. return true;
  354. }
  355. static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
  356. int n, u8 *buf)
  357. {
  358. struct bnx2x_vlan_mac_registry_elem *pos;
  359. u8 *next = buf;
  360. int counter = 0;
  361. /* traverse list */
  362. list_for_each_entry(pos, &o->head, link) {
  363. if (counter < n) {
  364. /* place leading zeroes in buffer */
  365. memset(next, 0, MAC_LEADING_ZERO_CNT);
  366. /* place mac after leading zeroes*/
  367. memcpy(next + MAC_LEADING_ZERO_CNT, pos->u.mac.mac,
  368. ETH_ALEN);
  369. /* calculate address of next element and
  370. * advance counter
  371. */
  372. counter++;
  373. next = buf + counter * ALIGN(ETH_ALEN, sizeof(u32));
  374. DP(BNX2X_MSG_SP, "copied element number %d to address %p element was %pM\n",
  375. counter, next, pos->u.mac.mac);
  376. }
  377. }
  378. return counter * ETH_ALEN;
  379. }
  380. /* check_add() callbacks */
  381. static int bnx2x_check_mac_add(struct bnx2x *bp,
  382. struct bnx2x_vlan_mac_obj *o,
  383. union bnx2x_classification_ramrod_data *data)
  384. {
  385. struct bnx2x_vlan_mac_registry_elem *pos;
  386. DP(BNX2X_MSG_SP, "Checking MAC %pM for ADD command\n", data->mac.mac);
  387. if (!is_valid_ether_addr(data->mac.mac))
  388. return -EINVAL;
  389. /* Check if a requested MAC already exists */
  390. list_for_each_entry(pos, &o->head, link)
  391. if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
  392. return -EEXIST;
  393. return 0;
  394. }
  395. static int bnx2x_check_vlan_add(struct bnx2x *bp,
  396. struct bnx2x_vlan_mac_obj *o,
  397. union bnx2x_classification_ramrod_data *data)
  398. {
  399. struct bnx2x_vlan_mac_registry_elem *pos;
  400. DP(BNX2X_MSG_SP, "Checking VLAN %d for ADD command\n", data->vlan.vlan);
  401. list_for_each_entry(pos, &o->head, link)
  402. if (data->vlan.vlan == pos->u.vlan.vlan)
  403. return -EEXIST;
  404. return 0;
  405. }
  406. static int bnx2x_check_vlan_mac_add(struct bnx2x *bp,
  407. struct bnx2x_vlan_mac_obj *o,
  408. union bnx2x_classification_ramrod_data *data)
  409. {
  410. struct bnx2x_vlan_mac_registry_elem *pos;
  411. DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for ADD command\n",
  412. data->vlan_mac.mac, data->vlan_mac.vlan);
  413. list_for_each_entry(pos, &o->head, link)
  414. if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
  415. (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
  416. ETH_ALEN)))
  417. return -EEXIST;
  418. return 0;
  419. }
  420. /* check_del() callbacks */
  421. static struct bnx2x_vlan_mac_registry_elem *
  422. bnx2x_check_mac_del(struct bnx2x *bp,
  423. struct bnx2x_vlan_mac_obj *o,
  424. union bnx2x_classification_ramrod_data *data)
  425. {
  426. struct bnx2x_vlan_mac_registry_elem *pos;
  427. DP(BNX2X_MSG_SP, "Checking MAC %pM for DEL command\n", data->mac.mac);
  428. list_for_each_entry(pos, &o->head, link)
  429. if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
  430. return pos;
  431. return NULL;
  432. }
  433. static struct bnx2x_vlan_mac_registry_elem *
  434. bnx2x_check_vlan_del(struct bnx2x *bp,
  435. struct bnx2x_vlan_mac_obj *o,
  436. union bnx2x_classification_ramrod_data *data)
  437. {
  438. struct bnx2x_vlan_mac_registry_elem *pos;
  439. DP(BNX2X_MSG_SP, "Checking VLAN %d for DEL command\n", data->vlan.vlan);
  440. list_for_each_entry(pos, &o->head, link)
  441. if (data->vlan.vlan == pos->u.vlan.vlan)
  442. return pos;
  443. return NULL;
  444. }
  445. static struct bnx2x_vlan_mac_registry_elem *
  446. bnx2x_check_vlan_mac_del(struct bnx2x *bp,
  447. struct bnx2x_vlan_mac_obj *o,
  448. union bnx2x_classification_ramrod_data *data)
  449. {
  450. struct bnx2x_vlan_mac_registry_elem *pos;
  451. DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for DEL command\n",
  452. data->vlan_mac.mac, data->vlan_mac.vlan);
  453. list_for_each_entry(pos, &o->head, link)
  454. if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
  455. (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
  456. ETH_ALEN)))
  457. return pos;
  458. return NULL;
  459. }
  460. /* check_move() callback */
  461. static bool bnx2x_check_move(struct bnx2x *bp,
  462. struct bnx2x_vlan_mac_obj *src_o,
  463. struct bnx2x_vlan_mac_obj *dst_o,
  464. union bnx2x_classification_ramrod_data *data)
  465. {
  466. struct bnx2x_vlan_mac_registry_elem *pos;
  467. int rc;
  468. /* Check if we can delete the requested configuration from the first
  469. * object.
  470. */
  471. pos = src_o->check_del(bp, src_o, data);
  472. /* check if configuration can be added */
  473. rc = dst_o->check_add(bp, dst_o, data);
  474. /* If this classification can not be added (is already set)
  475. * or can't be deleted - return an error.
  476. */
  477. if (rc || !pos)
  478. return false;
  479. return true;
  480. }
  481. static bool bnx2x_check_move_always_err(
  482. struct bnx2x *bp,
  483. struct bnx2x_vlan_mac_obj *src_o,
  484. struct bnx2x_vlan_mac_obj *dst_o,
  485. union bnx2x_classification_ramrod_data *data)
  486. {
  487. return false;
  488. }
  489. static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
  490. {
  491. struct bnx2x_raw_obj *raw = &o->raw;
  492. u8 rx_tx_flag = 0;
  493. if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
  494. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  495. rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
  496. if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
  497. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  498. rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
  499. return rx_tx_flag;
  500. }
  501. void bnx2x_set_mac_in_nig(struct bnx2x *bp,
  502. bool add, unsigned char *dev_addr, int index)
  503. {
  504. u32 wb_data[2];
  505. u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
  506. NIG_REG_LLH0_FUNC_MEM;
  507. if (!IS_MF_SI(bp) && !IS_MF_AFEX(bp))
  508. return;
  509. if (index > BNX2X_LLH_CAM_MAX_PF_LINE)
  510. return;
  511. DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
  512. (add ? "ADD" : "DELETE"), index);
  513. if (add) {
  514. /* LLH_FUNC_MEM is a u64 WB register */
  515. reg_offset += 8*index;
  516. wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
  517. (dev_addr[4] << 8) | dev_addr[5]);
  518. wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
  519. REG_WR_DMAE(bp, reg_offset, wb_data, 2);
  520. }
  521. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
  522. NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
  523. }
  524. /**
  525. * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
  526. *
  527. * @bp: device handle
  528. * @o: queue for which we want to configure this rule
  529. * @add: if true the command is an ADD command, DEL otherwise
  530. * @opcode: CLASSIFY_RULE_OPCODE_XXX
  531. * @hdr: pointer to a header to setup
  532. *
  533. */
  534. static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
  535. struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
  536. struct eth_classify_cmd_header *hdr)
  537. {
  538. struct bnx2x_raw_obj *raw = &o->raw;
  539. hdr->client_id = raw->cl_id;
  540. hdr->func_id = raw->func_id;
  541. /* Rx or/and Tx (internal switching) configuration ? */
  542. hdr->cmd_general_data |=
  543. bnx2x_vlan_mac_get_rx_tx_flag(o);
  544. if (add)
  545. hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
  546. hdr->cmd_general_data |=
  547. (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
  548. }
  549. /**
  550. * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
  551. *
  552. * @cid: connection id
  553. * @type: BNX2X_FILTER_XXX_PENDING
  554. * @hdr: poiter to header to setup
  555. * @rule_cnt:
  556. *
  557. * currently we always configure one rule and echo field to contain a CID and an
  558. * opcode type.
  559. */
  560. static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
  561. struct eth_classify_header *hdr, int rule_cnt)
  562. {
  563. hdr->echo = cpu_to_le32((cid & BNX2X_SWCID_MASK) |
  564. (type << BNX2X_SWCID_SHIFT));
  565. hdr->rule_cnt = (u8)rule_cnt;
  566. }
  567. /* hw_config() callbacks */
  568. static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
  569. struct bnx2x_vlan_mac_obj *o,
  570. struct bnx2x_exeq_elem *elem, int rule_idx,
  571. int cam_offset)
  572. {
  573. struct bnx2x_raw_obj *raw = &o->raw;
  574. struct eth_classify_rules_ramrod_data *data =
  575. (struct eth_classify_rules_ramrod_data *)(raw->rdata);
  576. int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
  577. union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
  578. bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
  579. unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
  580. u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
  581. /*
  582. * Set LLH CAM entry: currently only iSCSI and ETH macs are
  583. * relevant. In addition, current implementation is tuned for a
  584. * single ETH MAC.
  585. *
  586. * When multiple unicast ETH MACs PF configuration in switch
  587. * independent mode is required (NetQ, multiple netdev MACs,
  588. * etc.), consider better utilisation of 8 per function MAC
  589. * entries in the LLH register. There is also
  590. * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
  591. * total number of CAM entries to 16.
  592. *
  593. * Currently we won't configure NIG for MACs other than a primary ETH
  594. * MAC and iSCSI L2 MAC.
  595. *
  596. * If this MAC is moving from one Queue to another, no need to change
  597. * NIG configuration.
  598. */
  599. if (cmd != BNX2X_VLAN_MAC_MOVE) {
  600. if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
  601. bnx2x_set_mac_in_nig(bp, add, mac,
  602. BNX2X_LLH_CAM_ISCSI_ETH_LINE);
  603. else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
  604. bnx2x_set_mac_in_nig(bp, add, mac,
  605. BNX2X_LLH_CAM_ETH_LINE);
  606. }
  607. /* Reset the ramrod data buffer for the first rule */
  608. if (rule_idx == 0)
  609. memset(data, 0, sizeof(*data));
  610. /* Setup a command header */
  611. bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
  612. &rule_entry->mac.header);
  613. DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
  614. (add ? "add" : "delete"), mac, raw->cl_id);
  615. /* Set a MAC itself */
  616. bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
  617. &rule_entry->mac.mac_mid,
  618. &rule_entry->mac.mac_lsb, mac);
  619. /* MOVE: Add a rule that will add this MAC to the target Queue */
  620. if (cmd == BNX2X_VLAN_MAC_MOVE) {
  621. rule_entry++;
  622. rule_cnt++;
  623. /* Setup ramrod data */
  624. bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
  625. elem->cmd_data.vlan_mac.target_obj,
  626. true, CLASSIFY_RULE_OPCODE_MAC,
  627. &rule_entry->mac.header);
  628. /* Set a MAC itself */
  629. bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
  630. &rule_entry->mac.mac_mid,
  631. &rule_entry->mac.mac_lsb, mac);
  632. }
  633. /* Set the ramrod data header */
  634. /* TODO: take this to the higher level in order to prevent multiple
  635. writing */
  636. bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
  637. rule_cnt);
  638. }
  639. /**
  640. * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
  641. *
  642. * @bp: device handle
  643. * @o: queue
  644. * @type:
  645. * @cam_offset: offset in cam memory
  646. * @hdr: pointer to a header to setup
  647. *
  648. * E1/E1H
  649. */
  650. static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
  651. struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
  652. struct mac_configuration_hdr *hdr)
  653. {
  654. struct bnx2x_raw_obj *r = &o->raw;
  655. hdr->length = 1;
  656. hdr->offset = (u8)cam_offset;
  657. hdr->client_id = cpu_to_le16(0xff);
  658. hdr->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
  659. (type << BNX2X_SWCID_SHIFT));
  660. }
  661. static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
  662. struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
  663. u16 vlan_id, struct mac_configuration_entry *cfg_entry)
  664. {
  665. struct bnx2x_raw_obj *r = &o->raw;
  666. u32 cl_bit_vec = (1 << r->cl_id);
  667. cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
  668. cfg_entry->pf_id = r->func_id;
  669. cfg_entry->vlan_id = cpu_to_le16(vlan_id);
  670. if (add) {
  671. SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  672. T_ETH_MAC_COMMAND_SET);
  673. SET_FLAG(cfg_entry->flags,
  674. MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
  675. /* Set a MAC in a ramrod data */
  676. bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
  677. &cfg_entry->middle_mac_addr,
  678. &cfg_entry->lsb_mac_addr, mac);
  679. } else
  680. SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  681. T_ETH_MAC_COMMAND_INVALIDATE);
  682. }
  683. static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
  684. struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
  685. u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
  686. {
  687. struct mac_configuration_entry *cfg_entry = &config->config_table[0];
  688. struct bnx2x_raw_obj *raw = &o->raw;
  689. bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
  690. &config->hdr);
  691. bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
  692. cfg_entry);
  693. DP(BNX2X_MSG_SP, "%s MAC %pM CLID %d CAM offset %d\n",
  694. (add ? "setting" : "clearing"),
  695. mac, raw->cl_id, cam_offset);
  696. }
  697. /**
  698. * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
  699. *
  700. * @bp: device handle
  701. * @o: bnx2x_vlan_mac_obj
  702. * @elem: bnx2x_exeq_elem
  703. * @rule_idx: rule_idx
  704. * @cam_offset: cam_offset
  705. */
  706. static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
  707. struct bnx2x_vlan_mac_obj *o,
  708. struct bnx2x_exeq_elem *elem, int rule_idx,
  709. int cam_offset)
  710. {
  711. struct bnx2x_raw_obj *raw = &o->raw;
  712. struct mac_configuration_cmd *config =
  713. (struct mac_configuration_cmd *)(raw->rdata);
  714. /*
  715. * 57710 and 57711 do not support MOVE command,
  716. * so it's either ADD or DEL
  717. */
  718. bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
  719. true : false;
  720. /* Reset the ramrod data buffer */
  721. memset(config, 0, sizeof(*config));
  722. bnx2x_vlan_mac_set_rdata_e1x(bp, o, raw->state,
  723. cam_offset, add,
  724. elem->cmd_data.vlan_mac.u.mac.mac, 0,
  725. ETH_VLAN_FILTER_ANY_VLAN, config);
  726. }
  727. static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
  728. struct bnx2x_vlan_mac_obj *o,
  729. struct bnx2x_exeq_elem *elem, int rule_idx,
  730. int cam_offset)
  731. {
  732. struct bnx2x_raw_obj *raw = &o->raw;
  733. struct eth_classify_rules_ramrod_data *data =
  734. (struct eth_classify_rules_ramrod_data *)(raw->rdata);
  735. int rule_cnt = rule_idx + 1;
  736. union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
  737. enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
  738. bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
  739. u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
  740. /* Reset the ramrod data buffer for the first rule */
  741. if (rule_idx == 0)
  742. memset(data, 0, sizeof(*data));
  743. /* Set a rule header */
  744. bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
  745. &rule_entry->vlan.header);
  746. DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
  747. vlan);
  748. /* Set a VLAN itself */
  749. rule_entry->vlan.vlan = cpu_to_le16(vlan);
  750. /* MOVE: Add a rule that will add this MAC to the target Queue */
  751. if (cmd == BNX2X_VLAN_MAC_MOVE) {
  752. rule_entry++;
  753. rule_cnt++;
  754. /* Setup ramrod data */
  755. bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
  756. elem->cmd_data.vlan_mac.target_obj,
  757. true, CLASSIFY_RULE_OPCODE_VLAN,
  758. &rule_entry->vlan.header);
  759. /* Set a VLAN itself */
  760. rule_entry->vlan.vlan = cpu_to_le16(vlan);
  761. }
  762. /* Set the ramrod data header */
  763. /* TODO: take this to the higher level in order to prevent multiple
  764. writing */
  765. bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
  766. rule_cnt);
  767. }
  768. static void bnx2x_set_one_vlan_mac_e2(struct bnx2x *bp,
  769. struct bnx2x_vlan_mac_obj *o,
  770. struct bnx2x_exeq_elem *elem,
  771. int rule_idx, int cam_offset)
  772. {
  773. struct bnx2x_raw_obj *raw = &o->raw;
  774. struct eth_classify_rules_ramrod_data *data =
  775. (struct eth_classify_rules_ramrod_data *)(raw->rdata);
  776. int rule_cnt = rule_idx + 1;
  777. union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
  778. enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
  779. bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
  780. u16 vlan = elem->cmd_data.vlan_mac.u.vlan_mac.vlan;
  781. u8 *mac = elem->cmd_data.vlan_mac.u.vlan_mac.mac;
  782. /* Reset the ramrod data buffer for the first rule */
  783. if (rule_idx == 0)
  784. memset(data, 0, sizeof(*data));
  785. /* Set a rule header */
  786. bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
  787. &rule_entry->pair.header);
  788. /* Set VLAN and MAC themselvs */
  789. rule_entry->pair.vlan = cpu_to_le16(vlan);
  790. bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
  791. &rule_entry->pair.mac_mid,
  792. &rule_entry->pair.mac_lsb, mac);
  793. /* MOVE: Add a rule that will add this MAC to the target Queue */
  794. if (cmd == BNX2X_VLAN_MAC_MOVE) {
  795. rule_entry++;
  796. rule_cnt++;
  797. /* Setup ramrod data */
  798. bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
  799. elem->cmd_data.vlan_mac.target_obj,
  800. true, CLASSIFY_RULE_OPCODE_PAIR,
  801. &rule_entry->pair.header);
  802. /* Set a VLAN itself */
  803. rule_entry->pair.vlan = cpu_to_le16(vlan);
  804. bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
  805. &rule_entry->pair.mac_mid,
  806. &rule_entry->pair.mac_lsb, mac);
  807. }
  808. /* Set the ramrod data header */
  809. /* TODO: take this to the higher level in order to prevent multiple
  810. writing */
  811. bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
  812. rule_cnt);
  813. }
  814. /**
  815. * bnx2x_set_one_vlan_mac_e1h -
  816. *
  817. * @bp: device handle
  818. * @o: bnx2x_vlan_mac_obj
  819. * @elem: bnx2x_exeq_elem
  820. * @rule_idx: rule_idx
  821. * @cam_offset: cam_offset
  822. */
  823. static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
  824. struct bnx2x_vlan_mac_obj *o,
  825. struct bnx2x_exeq_elem *elem,
  826. int rule_idx, int cam_offset)
  827. {
  828. struct bnx2x_raw_obj *raw = &o->raw;
  829. struct mac_configuration_cmd *config =
  830. (struct mac_configuration_cmd *)(raw->rdata);
  831. /*
  832. * 57710 and 57711 do not support MOVE command,
  833. * so it's either ADD or DEL
  834. */
  835. bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
  836. true : false;
  837. /* Reset the ramrod data buffer */
  838. memset(config, 0, sizeof(*config));
  839. bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_VLAN_MAC_PENDING,
  840. cam_offset, add,
  841. elem->cmd_data.vlan_mac.u.vlan_mac.mac,
  842. elem->cmd_data.vlan_mac.u.vlan_mac.vlan,
  843. ETH_VLAN_FILTER_CLASSIFY, config);
  844. }
  845. #define list_next_entry(pos, member) \
  846. list_entry((pos)->member.next, typeof(*(pos)), member)
  847. /**
  848. * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
  849. *
  850. * @bp: device handle
  851. * @p: command parameters
  852. * @ppos: pointer to the cooky
  853. *
  854. * reconfigure next MAC/VLAN/VLAN-MAC element from the
  855. * previously configured elements list.
  856. *
  857. * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
  858. * into an account
  859. *
  860. * pointer to the cooky - that should be given back in the next call to make
  861. * function handle the next element. If *ppos is set to NULL it will restart the
  862. * iterator. If returned *ppos == NULL this means that the last element has been
  863. * handled.
  864. *
  865. */
  866. static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
  867. struct bnx2x_vlan_mac_ramrod_params *p,
  868. struct bnx2x_vlan_mac_registry_elem **ppos)
  869. {
  870. struct bnx2x_vlan_mac_registry_elem *pos;
  871. struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
  872. /* If list is empty - there is nothing to do here */
  873. if (list_empty(&o->head)) {
  874. *ppos = NULL;
  875. return 0;
  876. }
  877. /* make a step... */
  878. if (*ppos == NULL)
  879. *ppos = list_first_entry(&o->head,
  880. struct bnx2x_vlan_mac_registry_elem,
  881. link);
  882. else
  883. *ppos = list_next_entry(*ppos, link);
  884. pos = *ppos;
  885. /* If it's the last step - return NULL */
  886. if (list_is_last(&pos->link, &o->head))
  887. *ppos = NULL;
  888. /* Prepare a 'user_req' */
  889. memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
  890. /* Set the command */
  891. p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
  892. /* Set vlan_mac_flags */
  893. p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
  894. /* Set a restore bit */
  895. __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
  896. return bnx2x_config_vlan_mac(bp, p);
  897. }
  898. /*
  899. * bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
  900. * pointer to an element with a specific criteria and NULL if such an element
  901. * hasn't been found.
  902. */
  903. static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
  904. struct bnx2x_exe_queue_obj *o,
  905. struct bnx2x_exeq_elem *elem)
  906. {
  907. struct bnx2x_exeq_elem *pos;
  908. struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
  909. /* Check pending for execution commands */
  910. list_for_each_entry(pos, &o->exe_queue, link)
  911. if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
  912. sizeof(*data)) &&
  913. (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
  914. return pos;
  915. return NULL;
  916. }
  917. static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
  918. struct bnx2x_exe_queue_obj *o,
  919. struct bnx2x_exeq_elem *elem)
  920. {
  921. struct bnx2x_exeq_elem *pos;
  922. struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
  923. /* Check pending for execution commands */
  924. list_for_each_entry(pos, &o->exe_queue, link)
  925. if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
  926. sizeof(*data)) &&
  927. (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
  928. return pos;
  929. return NULL;
  930. }
  931. static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan_mac(
  932. struct bnx2x_exe_queue_obj *o,
  933. struct bnx2x_exeq_elem *elem)
  934. {
  935. struct bnx2x_exeq_elem *pos;
  936. struct bnx2x_vlan_mac_ramrod_data *data =
  937. &elem->cmd_data.vlan_mac.u.vlan_mac;
  938. /* Check pending for execution commands */
  939. list_for_each_entry(pos, &o->exe_queue, link)
  940. if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan_mac, data,
  941. sizeof(*data)) &&
  942. (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
  943. return pos;
  944. return NULL;
  945. }
  946. /**
  947. * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
  948. *
  949. * @bp: device handle
  950. * @qo: bnx2x_qable_obj
  951. * @elem: bnx2x_exeq_elem
  952. *
  953. * Checks that the requested configuration can be added. If yes and if
  954. * requested, consume CAM credit.
  955. *
  956. * The 'validate' is run after the 'optimize'.
  957. *
  958. */
  959. static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
  960. union bnx2x_qable_obj *qo,
  961. struct bnx2x_exeq_elem *elem)
  962. {
  963. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
  964. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  965. int rc;
  966. /* Check the registry */
  967. rc = o->check_add(bp, o, &elem->cmd_data.vlan_mac.u);
  968. if (rc) {
  969. DP(BNX2X_MSG_SP, "ADD command is not allowed considering current registry state.\n");
  970. return rc;
  971. }
  972. /*
  973. * Check if there is a pending ADD command for this
  974. * MAC/VLAN/VLAN-MAC. Return an error if there is.
  975. */
  976. if (exeq->get(exeq, elem)) {
  977. DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
  978. return -EEXIST;
  979. }
  980. /*
  981. * TODO: Check the pending MOVE from other objects where this
  982. * object is a destination object.
  983. */
  984. /* Consume the credit if not requested not to */
  985. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  986. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  987. o->get_credit(o)))
  988. return -EINVAL;
  989. return 0;
  990. }
  991. /**
  992. * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
  993. *
  994. * @bp: device handle
  995. * @qo: quable object to check
  996. * @elem: element that needs to be deleted
  997. *
  998. * Checks that the requested configuration can be deleted. If yes and if
  999. * requested, returns a CAM credit.
  1000. *
  1001. * The 'validate' is run after the 'optimize'.
  1002. */
  1003. static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
  1004. union bnx2x_qable_obj *qo,
  1005. struct bnx2x_exeq_elem *elem)
  1006. {
  1007. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
  1008. struct bnx2x_vlan_mac_registry_elem *pos;
  1009. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1010. struct bnx2x_exeq_elem query_elem;
  1011. /* If this classification can not be deleted (doesn't exist)
  1012. * - return a BNX2X_EXIST.
  1013. */
  1014. pos = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
  1015. if (!pos) {
  1016. DP(BNX2X_MSG_SP, "DEL command is not allowed considering current registry state\n");
  1017. return -EEXIST;
  1018. }
  1019. /*
  1020. * Check if there are pending DEL or MOVE commands for this
  1021. * MAC/VLAN/VLAN-MAC. Return an error if so.
  1022. */
  1023. memcpy(&query_elem, elem, sizeof(query_elem));
  1024. /* Check for MOVE commands */
  1025. query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
  1026. if (exeq->get(exeq, &query_elem)) {
  1027. BNX2X_ERR("There is a pending MOVE command already\n");
  1028. return -EINVAL;
  1029. }
  1030. /* Check for DEL commands */
  1031. if (exeq->get(exeq, elem)) {
  1032. DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
  1033. return -EEXIST;
  1034. }
  1035. /* Return the credit to the credit pool if not requested not to */
  1036. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  1037. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  1038. o->put_credit(o))) {
  1039. BNX2X_ERR("Failed to return a credit\n");
  1040. return -EINVAL;
  1041. }
  1042. return 0;
  1043. }
  1044. /**
  1045. * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
  1046. *
  1047. * @bp: device handle
  1048. * @qo: quable object to check (source)
  1049. * @elem: element that needs to be moved
  1050. *
  1051. * Checks that the requested configuration can be moved. If yes and if
  1052. * requested, returns a CAM credit.
  1053. *
  1054. * The 'validate' is run after the 'optimize'.
  1055. */
  1056. static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
  1057. union bnx2x_qable_obj *qo,
  1058. struct bnx2x_exeq_elem *elem)
  1059. {
  1060. struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
  1061. struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
  1062. struct bnx2x_exeq_elem query_elem;
  1063. struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
  1064. struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
  1065. /*
  1066. * Check if we can perform this operation based on the current registry
  1067. * state.
  1068. */
  1069. if (!src_o->check_move(bp, src_o, dest_o,
  1070. &elem->cmd_data.vlan_mac.u)) {
  1071. DP(BNX2X_MSG_SP, "MOVE command is not allowed considering current registry state\n");
  1072. return -EINVAL;
  1073. }
  1074. /*
  1075. * Check if there is an already pending DEL or MOVE command for the
  1076. * source object or ADD command for a destination object. Return an
  1077. * error if so.
  1078. */
  1079. memcpy(&query_elem, elem, sizeof(query_elem));
  1080. /* Check DEL on source */
  1081. query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
  1082. if (src_exeq->get(src_exeq, &query_elem)) {
  1083. BNX2X_ERR("There is a pending DEL command on the source queue already\n");
  1084. return -EINVAL;
  1085. }
  1086. /* Check MOVE on source */
  1087. if (src_exeq->get(src_exeq, elem)) {
  1088. DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
  1089. return -EEXIST;
  1090. }
  1091. /* Check ADD on destination */
  1092. query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
  1093. if (dest_exeq->get(dest_exeq, &query_elem)) {
  1094. BNX2X_ERR("There is a pending ADD command on the destination queue already\n");
  1095. return -EINVAL;
  1096. }
  1097. /* Consume the credit if not requested not to */
  1098. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
  1099. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  1100. dest_o->get_credit(dest_o)))
  1101. return -EINVAL;
  1102. if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  1103. &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
  1104. src_o->put_credit(src_o))) {
  1105. /* return the credit taken from dest... */
  1106. dest_o->put_credit(dest_o);
  1107. return -EINVAL;
  1108. }
  1109. return 0;
  1110. }
  1111. static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
  1112. union bnx2x_qable_obj *qo,
  1113. struct bnx2x_exeq_elem *elem)
  1114. {
  1115. switch (elem->cmd_data.vlan_mac.cmd) {
  1116. case BNX2X_VLAN_MAC_ADD:
  1117. return bnx2x_validate_vlan_mac_add(bp, qo, elem);
  1118. case BNX2X_VLAN_MAC_DEL:
  1119. return bnx2x_validate_vlan_mac_del(bp, qo, elem);
  1120. case BNX2X_VLAN_MAC_MOVE:
  1121. return bnx2x_validate_vlan_mac_move(bp, qo, elem);
  1122. default:
  1123. return -EINVAL;
  1124. }
  1125. }
  1126. static int bnx2x_remove_vlan_mac(struct bnx2x *bp,
  1127. union bnx2x_qable_obj *qo,
  1128. struct bnx2x_exeq_elem *elem)
  1129. {
  1130. int rc = 0;
  1131. /* If consumption wasn't required, nothing to do */
  1132. if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  1133. &elem->cmd_data.vlan_mac.vlan_mac_flags))
  1134. return 0;
  1135. switch (elem->cmd_data.vlan_mac.cmd) {
  1136. case BNX2X_VLAN_MAC_ADD:
  1137. case BNX2X_VLAN_MAC_MOVE:
  1138. rc = qo->vlan_mac.put_credit(&qo->vlan_mac);
  1139. break;
  1140. case BNX2X_VLAN_MAC_DEL:
  1141. rc = qo->vlan_mac.get_credit(&qo->vlan_mac);
  1142. break;
  1143. default:
  1144. return -EINVAL;
  1145. }
  1146. if (rc != true)
  1147. return -EINVAL;
  1148. return 0;
  1149. }
  1150. /**
  1151. * bnx2x_wait_vlan_mac - passivly wait for 5 seconds until all work completes.
  1152. *
  1153. * @bp: device handle
  1154. * @o: bnx2x_vlan_mac_obj
  1155. *
  1156. */
  1157. static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
  1158. struct bnx2x_vlan_mac_obj *o)
  1159. {
  1160. int cnt = 5000, rc;
  1161. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1162. struct bnx2x_raw_obj *raw = &o->raw;
  1163. while (cnt--) {
  1164. /* Wait for the current command to complete */
  1165. rc = raw->wait_comp(bp, raw);
  1166. if (rc)
  1167. return rc;
  1168. /* Wait until there are no pending commands */
  1169. if (!bnx2x_exe_queue_empty(exeq))
  1170. usleep_range(1000, 2000);
  1171. else
  1172. return 0;
  1173. }
  1174. return -EBUSY;
  1175. }
  1176. /**
  1177. * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
  1178. *
  1179. * @bp: device handle
  1180. * @o: bnx2x_vlan_mac_obj
  1181. * @cqe:
  1182. * @cont: if true schedule next execution chunk
  1183. *
  1184. */
  1185. static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
  1186. struct bnx2x_vlan_mac_obj *o,
  1187. union event_ring_elem *cqe,
  1188. unsigned long *ramrod_flags)
  1189. {
  1190. struct bnx2x_raw_obj *r = &o->raw;
  1191. int rc;
  1192. /* Reset pending list */
  1193. bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
  1194. /* Clear pending */
  1195. r->clear_pending(r);
  1196. /* If ramrod failed this is most likely a SW bug */
  1197. if (cqe->message.error)
  1198. return -EINVAL;
  1199. /* Run the next bulk of pending commands if requested */
  1200. if (test_bit(RAMROD_CONT, ramrod_flags)) {
  1201. rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
  1202. if (rc < 0)
  1203. return rc;
  1204. }
  1205. /* If there is more work to do return PENDING */
  1206. if (!bnx2x_exe_queue_empty(&o->exe_queue))
  1207. return 1;
  1208. return 0;
  1209. }
  1210. /**
  1211. * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
  1212. *
  1213. * @bp: device handle
  1214. * @o: bnx2x_qable_obj
  1215. * @elem: bnx2x_exeq_elem
  1216. */
  1217. static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
  1218. union bnx2x_qable_obj *qo,
  1219. struct bnx2x_exeq_elem *elem)
  1220. {
  1221. struct bnx2x_exeq_elem query, *pos;
  1222. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
  1223. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1224. memcpy(&query, elem, sizeof(query));
  1225. switch (elem->cmd_data.vlan_mac.cmd) {
  1226. case BNX2X_VLAN_MAC_ADD:
  1227. query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
  1228. break;
  1229. case BNX2X_VLAN_MAC_DEL:
  1230. query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
  1231. break;
  1232. default:
  1233. /* Don't handle anything other than ADD or DEL */
  1234. return 0;
  1235. }
  1236. /* If we found the appropriate element - delete it */
  1237. pos = exeq->get(exeq, &query);
  1238. if (pos) {
  1239. /* Return the credit of the optimized command */
  1240. if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
  1241. &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
  1242. if ((query.cmd_data.vlan_mac.cmd ==
  1243. BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
  1244. BNX2X_ERR("Failed to return the credit for the optimized ADD command\n");
  1245. return -EINVAL;
  1246. } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
  1247. BNX2X_ERR("Failed to recover the credit from the optimized DEL command\n");
  1248. return -EINVAL;
  1249. }
  1250. }
  1251. DP(BNX2X_MSG_SP, "Optimizing %s command\n",
  1252. (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
  1253. "ADD" : "DEL");
  1254. list_del(&pos->link);
  1255. bnx2x_exe_queue_free_elem(bp, pos);
  1256. return 1;
  1257. }
  1258. return 0;
  1259. }
  1260. /**
  1261. * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
  1262. *
  1263. * @bp: device handle
  1264. * @o:
  1265. * @elem:
  1266. * @restore:
  1267. * @re:
  1268. *
  1269. * prepare a registry element according to the current command request.
  1270. */
  1271. static inline int bnx2x_vlan_mac_get_registry_elem(
  1272. struct bnx2x *bp,
  1273. struct bnx2x_vlan_mac_obj *o,
  1274. struct bnx2x_exeq_elem *elem,
  1275. bool restore,
  1276. struct bnx2x_vlan_mac_registry_elem **re)
  1277. {
  1278. enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
  1279. struct bnx2x_vlan_mac_registry_elem *reg_elem;
  1280. /* Allocate a new registry element if needed. */
  1281. if (!restore &&
  1282. ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
  1283. reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
  1284. if (!reg_elem)
  1285. return -ENOMEM;
  1286. /* Get a new CAM offset */
  1287. if (!o->get_cam_offset(o, &reg_elem->cam_offset)) {
  1288. /*
  1289. * This shell never happen, because we have checked the
  1290. * CAM availiability in the 'validate'.
  1291. */
  1292. WARN_ON(1);
  1293. kfree(reg_elem);
  1294. return -EINVAL;
  1295. }
  1296. DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
  1297. /* Set a VLAN-MAC data */
  1298. memcpy(&reg_elem->u, &elem->cmd_data.vlan_mac.u,
  1299. sizeof(reg_elem->u));
  1300. /* Copy the flags (needed for DEL and RESTORE flows) */
  1301. reg_elem->vlan_mac_flags =
  1302. elem->cmd_data.vlan_mac.vlan_mac_flags;
  1303. } else /* DEL, RESTORE */
  1304. reg_elem = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
  1305. *re = reg_elem;
  1306. return 0;
  1307. }
  1308. /**
  1309. * bnx2x_execute_vlan_mac - execute vlan mac command
  1310. *
  1311. * @bp: device handle
  1312. * @qo:
  1313. * @exe_chunk:
  1314. * @ramrod_flags:
  1315. *
  1316. * go and send a ramrod!
  1317. */
  1318. static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
  1319. union bnx2x_qable_obj *qo,
  1320. struct list_head *exe_chunk,
  1321. unsigned long *ramrod_flags)
  1322. {
  1323. struct bnx2x_exeq_elem *elem;
  1324. struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
  1325. struct bnx2x_raw_obj *r = &o->raw;
  1326. int rc, idx = 0;
  1327. bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
  1328. bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
  1329. struct bnx2x_vlan_mac_registry_elem *reg_elem;
  1330. enum bnx2x_vlan_mac_cmd cmd;
  1331. /*
  1332. * If DRIVER_ONLY execution is requested, cleanup a registry
  1333. * and exit. Otherwise send a ramrod to FW.
  1334. */
  1335. if (!drv_only) {
  1336. WARN_ON(r->check_pending(r));
  1337. /* Set pending */
  1338. r->set_pending(r);
  1339. /* Fill tha ramrod data */
  1340. list_for_each_entry(elem, exe_chunk, link) {
  1341. cmd = elem->cmd_data.vlan_mac.cmd;
  1342. /*
  1343. * We will add to the target object in MOVE command, so
  1344. * change the object for a CAM search.
  1345. */
  1346. if (cmd == BNX2X_VLAN_MAC_MOVE)
  1347. cam_obj = elem->cmd_data.vlan_mac.target_obj;
  1348. else
  1349. cam_obj = o;
  1350. rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
  1351. elem, restore,
  1352. &reg_elem);
  1353. if (rc)
  1354. goto error_exit;
  1355. WARN_ON(!reg_elem);
  1356. /* Push a new entry into the registry */
  1357. if (!restore &&
  1358. ((cmd == BNX2X_VLAN_MAC_ADD) ||
  1359. (cmd == BNX2X_VLAN_MAC_MOVE)))
  1360. list_add(&reg_elem->link, &cam_obj->head);
  1361. /* Configure a single command in a ramrod data buffer */
  1362. o->set_one_rule(bp, o, elem, idx,
  1363. reg_elem->cam_offset);
  1364. /* MOVE command consumes 2 entries in the ramrod data */
  1365. if (cmd == BNX2X_VLAN_MAC_MOVE)
  1366. idx += 2;
  1367. else
  1368. idx++;
  1369. }
  1370. /*
  1371. * No need for an explicit memory barrier here as long we would
  1372. * need to ensure the ordering of writing to the SPQ element
  1373. * and updating of the SPQ producer which involves a memory
  1374. * read and we will have to put a full memory barrier there
  1375. * (inside bnx2x_sp_post()).
  1376. */
  1377. rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
  1378. U64_HI(r->rdata_mapping),
  1379. U64_LO(r->rdata_mapping),
  1380. ETH_CONNECTION_TYPE);
  1381. if (rc)
  1382. goto error_exit;
  1383. }
  1384. /* Now, when we are done with the ramrod - clean up the registry */
  1385. list_for_each_entry(elem, exe_chunk, link) {
  1386. cmd = elem->cmd_data.vlan_mac.cmd;
  1387. if ((cmd == BNX2X_VLAN_MAC_DEL) ||
  1388. (cmd == BNX2X_VLAN_MAC_MOVE)) {
  1389. reg_elem = o->check_del(bp, o,
  1390. &elem->cmd_data.vlan_mac.u);
  1391. WARN_ON(!reg_elem);
  1392. o->put_cam_offset(o, reg_elem->cam_offset);
  1393. list_del(&reg_elem->link);
  1394. kfree(reg_elem);
  1395. }
  1396. }
  1397. if (!drv_only)
  1398. return 1;
  1399. else
  1400. return 0;
  1401. error_exit:
  1402. r->clear_pending(r);
  1403. /* Cleanup a registry in case of a failure */
  1404. list_for_each_entry(elem, exe_chunk, link) {
  1405. cmd = elem->cmd_data.vlan_mac.cmd;
  1406. if (cmd == BNX2X_VLAN_MAC_MOVE)
  1407. cam_obj = elem->cmd_data.vlan_mac.target_obj;
  1408. else
  1409. cam_obj = o;
  1410. /* Delete all newly added above entries */
  1411. if (!restore &&
  1412. ((cmd == BNX2X_VLAN_MAC_ADD) ||
  1413. (cmd == BNX2X_VLAN_MAC_MOVE))) {
  1414. reg_elem = o->check_del(bp, cam_obj,
  1415. &elem->cmd_data.vlan_mac.u);
  1416. if (reg_elem) {
  1417. list_del(&reg_elem->link);
  1418. kfree(reg_elem);
  1419. }
  1420. }
  1421. }
  1422. return rc;
  1423. }
  1424. static inline int bnx2x_vlan_mac_push_new_cmd(
  1425. struct bnx2x *bp,
  1426. struct bnx2x_vlan_mac_ramrod_params *p)
  1427. {
  1428. struct bnx2x_exeq_elem *elem;
  1429. struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
  1430. bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
  1431. /* Allocate the execution queue element */
  1432. elem = bnx2x_exe_queue_alloc_elem(bp);
  1433. if (!elem)
  1434. return -ENOMEM;
  1435. /* Set the command 'length' */
  1436. switch (p->user_req.cmd) {
  1437. case BNX2X_VLAN_MAC_MOVE:
  1438. elem->cmd_len = 2;
  1439. break;
  1440. default:
  1441. elem->cmd_len = 1;
  1442. }
  1443. /* Fill the object specific info */
  1444. memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
  1445. /* Try to add a new command to the pending list */
  1446. return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
  1447. }
  1448. /**
  1449. * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
  1450. *
  1451. * @bp: device handle
  1452. * @p:
  1453. *
  1454. */
  1455. int bnx2x_config_vlan_mac(
  1456. struct bnx2x *bp,
  1457. struct bnx2x_vlan_mac_ramrod_params *p)
  1458. {
  1459. int rc = 0;
  1460. struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
  1461. unsigned long *ramrod_flags = &p->ramrod_flags;
  1462. bool cont = test_bit(RAMROD_CONT, ramrod_flags);
  1463. struct bnx2x_raw_obj *raw = &o->raw;
  1464. /*
  1465. * Add new elements to the execution list for commands that require it.
  1466. */
  1467. if (!cont) {
  1468. rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
  1469. if (rc)
  1470. return rc;
  1471. }
  1472. /*
  1473. * If nothing will be executed further in this iteration we want to
  1474. * return PENDING if there are pending commands
  1475. */
  1476. if (!bnx2x_exe_queue_empty(&o->exe_queue))
  1477. rc = 1;
  1478. if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
  1479. DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
  1480. raw->clear_pending(raw);
  1481. }
  1482. /* Execute commands if required */
  1483. if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
  1484. test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
  1485. rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
  1486. if (rc < 0)
  1487. return rc;
  1488. }
  1489. /*
  1490. * RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
  1491. * then user want to wait until the last command is done.
  1492. */
  1493. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
  1494. /*
  1495. * Wait maximum for the current exe_queue length iterations plus
  1496. * one (for the current pending command).
  1497. */
  1498. int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
  1499. while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
  1500. max_iterations--) {
  1501. /* Wait for the current command to complete */
  1502. rc = raw->wait_comp(bp, raw);
  1503. if (rc)
  1504. return rc;
  1505. /* Make a next step */
  1506. rc = bnx2x_exe_queue_step(bp, &o->exe_queue,
  1507. ramrod_flags);
  1508. if (rc < 0)
  1509. return rc;
  1510. }
  1511. return 0;
  1512. }
  1513. return rc;
  1514. }
  1515. /**
  1516. * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
  1517. *
  1518. * @bp: device handle
  1519. * @o:
  1520. * @vlan_mac_flags:
  1521. * @ramrod_flags: execution flags to be used for this deletion
  1522. *
  1523. * if the last operation has completed successfully and there are no
  1524. * moreelements left, positive value if the last operation has completed
  1525. * successfully and there are more previously configured elements, negative
  1526. * value is current operation has failed.
  1527. */
  1528. static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
  1529. struct bnx2x_vlan_mac_obj *o,
  1530. unsigned long *vlan_mac_flags,
  1531. unsigned long *ramrod_flags)
  1532. {
  1533. struct bnx2x_vlan_mac_registry_elem *pos = NULL;
  1534. int rc = 0;
  1535. struct bnx2x_vlan_mac_ramrod_params p;
  1536. struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
  1537. struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
  1538. /* Clear pending commands first */
  1539. spin_lock_bh(&exeq->lock);
  1540. list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
  1541. if (exeq_pos->cmd_data.vlan_mac.vlan_mac_flags ==
  1542. *vlan_mac_flags) {
  1543. rc = exeq->remove(bp, exeq->owner, exeq_pos);
  1544. if (rc) {
  1545. BNX2X_ERR("Failed to remove command\n");
  1546. spin_unlock_bh(&exeq->lock);
  1547. return rc;
  1548. }
  1549. list_del(&exeq_pos->link);
  1550. bnx2x_exe_queue_free_elem(bp, exeq_pos);
  1551. }
  1552. }
  1553. spin_unlock_bh(&exeq->lock);
  1554. /* Prepare a command request */
  1555. memset(&p, 0, sizeof(p));
  1556. p.vlan_mac_obj = o;
  1557. p.ramrod_flags = *ramrod_flags;
  1558. p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  1559. /*
  1560. * Add all but the last VLAN-MAC to the execution queue without actually
  1561. * execution anything.
  1562. */
  1563. __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
  1564. __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
  1565. __clear_bit(RAMROD_CONT, &p.ramrod_flags);
  1566. list_for_each_entry(pos, &o->head, link) {
  1567. if (pos->vlan_mac_flags == *vlan_mac_flags) {
  1568. p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
  1569. memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
  1570. rc = bnx2x_config_vlan_mac(bp, &p);
  1571. if (rc < 0) {
  1572. BNX2X_ERR("Failed to add a new DEL command\n");
  1573. return rc;
  1574. }
  1575. }
  1576. }
  1577. p.ramrod_flags = *ramrod_flags;
  1578. __set_bit(RAMROD_CONT, &p.ramrod_flags);
  1579. return bnx2x_config_vlan_mac(bp, &p);
  1580. }
  1581. static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
  1582. u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
  1583. unsigned long *pstate, bnx2x_obj_type type)
  1584. {
  1585. raw->func_id = func_id;
  1586. raw->cid = cid;
  1587. raw->cl_id = cl_id;
  1588. raw->rdata = rdata;
  1589. raw->rdata_mapping = rdata_mapping;
  1590. raw->state = state;
  1591. raw->pstate = pstate;
  1592. raw->obj_type = type;
  1593. raw->check_pending = bnx2x_raw_check_pending;
  1594. raw->clear_pending = bnx2x_raw_clear_pending;
  1595. raw->set_pending = bnx2x_raw_set_pending;
  1596. raw->wait_comp = bnx2x_raw_wait;
  1597. }
  1598. static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
  1599. u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
  1600. int state, unsigned long *pstate, bnx2x_obj_type type,
  1601. struct bnx2x_credit_pool_obj *macs_pool,
  1602. struct bnx2x_credit_pool_obj *vlans_pool)
  1603. {
  1604. INIT_LIST_HEAD(&o->head);
  1605. o->macs_pool = macs_pool;
  1606. o->vlans_pool = vlans_pool;
  1607. o->delete_all = bnx2x_vlan_mac_del_all;
  1608. o->restore = bnx2x_vlan_mac_restore;
  1609. o->complete = bnx2x_complete_vlan_mac;
  1610. o->wait = bnx2x_wait_vlan_mac;
  1611. bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
  1612. state, pstate, type);
  1613. }
  1614. void bnx2x_init_mac_obj(struct bnx2x *bp,
  1615. struct bnx2x_vlan_mac_obj *mac_obj,
  1616. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  1617. dma_addr_t rdata_mapping, int state,
  1618. unsigned long *pstate, bnx2x_obj_type type,
  1619. struct bnx2x_credit_pool_obj *macs_pool)
  1620. {
  1621. union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
  1622. bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
  1623. rdata_mapping, state, pstate, type,
  1624. macs_pool, NULL);
  1625. /* CAM credit pool handling */
  1626. mac_obj->get_credit = bnx2x_get_credit_mac;
  1627. mac_obj->put_credit = bnx2x_put_credit_mac;
  1628. mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
  1629. mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
  1630. if (CHIP_IS_E1x(bp)) {
  1631. mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
  1632. mac_obj->check_del = bnx2x_check_mac_del;
  1633. mac_obj->check_add = bnx2x_check_mac_add;
  1634. mac_obj->check_move = bnx2x_check_move_always_err;
  1635. mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
  1636. /* Exe Queue */
  1637. bnx2x_exe_queue_init(bp,
  1638. &mac_obj->exe_queue, 1, qable_obj,
  1639. bnx2x_validate_vlan_mac,
  1640. bnx2x_remove_vlan_mac,
  1641. bnx2x_optimize_vlan_mac,
  1642. bnx2x_execute_vlan_mac,
  1643. bnx2x_exeq_get_mac);
  1644. } else {
  1645. mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
  1646. mac_obj->check_del = bnx2x_check_mac_del;
  1647. mac_obj->check_add = bnx2x_check_mac_add;
  1648. mac_obj->check_move = bnx2x_check_move;
  1649. mac_obj->ramrod_cmd =
  1650. RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
  1651. mac_obj->get_n_elements = bnx2x_get_n_elements;
  1652. /* Exe Queue */
  1653. bnx2x_exe_queue_init(bp,
  1654. &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
  1655. qable_obj, bnx2x_validate_vlan_mac,
  1656. bnx2x_remove_vlan_mac,
  1657. bnx2x_optimize_vlan_mac,
  1658. bnx2x_execute_vlan_mac,
  1659. bnx2x_exeq_get_mac);
  1660. }
  1661. }
  1662. void bnx2x_init_vlan_obj(struct bnx2x *bp,
  1663. struct bnx2x_vlan_mac_obj *vlan_obj,
  1664. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  1665. dma_addr_t rdata_mapping, int state,
  1666. unsigned long *pstate, bnx2x_obj_type type,
  1667. struct bnx2x_credit_pool_obj *vlans_pool)
  1668. {
  1669. union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
  1670. bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
  1671. rdata_mapping, state, pstate, type, NULL,
  1672. vlans_pool);
  1673. vlan_obj->get_credit = bnx2x_get_credit_vlan;
  1674. vlan_obj->put_credit = bnx2x_put_credit_vlan;
  1675. vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
  1676. vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
  1677. if (CHIP_IS_E1x(bp)) {
  1678. BNX2X_ERR("Do not support chips others than E2 and newer\n");
  1679. BUG();
  1680. } else {
  1681. vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
  1682. vlan_obj->check_del = bnx2x_check_vlan_del;
  1683. vlan_obj->check_add = bnx2x_check_vlan_add;
  1684. vlan_obj->check_move = bnx2x_check_move;
  1685. vlan_obj->ramrod_cmd =
  1686. RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
  1687. /* Exe Queue */
  1688. bnx2x_exe_queue_init(bp,
  1689. &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
  1690. qable_obj, bnx2x_validate_vlan_mac,
  1691. bnx2x_remove_vlan_mac,
  1692. bnx2x_optimize_vlan_mac,
  1693. bnx2x_execute_vlan_mac,
  1694. bnx2x_exeq_get_vlan);
  1695. }
  1696. }
  1697. void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
  1698. struct bnx2x_vlan_mac_obj *vlan_mac_obj,
  1699. u8 cl_id, u32 cid, u8 func_id, void *rdata,
  1700. dma_addr_t rdata_mapping, int state,
  1701. unsigned long *pstate, bnx2x_obj_type type,
  1702. struct bnx2x_credit_pool_obj *macs_pool,
  1703. struct bnx2x_credit_pool_obj *vlans_pool)
  1704. {
  1705. union bnx2x_qable_obj *qable_obj =
  1706. (union bnx2x_qable_obj *)vlan_mac_obj;
  1707. bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
  1708. rdata_mapping, state, pstate, type,
  1709. macs_pool, vlans_pool);
  1710. /* CAM pool handling */
  1711. vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
  1712. vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac;
  1713. /*
  1714. * CAM offset is relevant for 57710 and 57711 chips only which have a
  1715. * single CAM for both MACs and VLAN-MAC pairs. So the offset
  1716. * will be taken from MACs' pool object only.
  1717. */
  1718. vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
  1719. vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
  1720. if (CHIP_IS_E1(bp)) {
  1721. BNX2X_ERR("Do not support chips others than E2\n");
  1722. BUG();
  1723. } else if (CHIP_IS_E1H(bp)) {
  1724. vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
  1725. vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
  1726. vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
  1727. vlan_mac_obj->check_move = bnx2x_check_move_always_err;
  1728. vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
  1729. /* Exe Queue */
  1730. bnx2x_exe_queue_init(bp,
  1731. &vlan_mac_obj->exe_queue, 1, qable_obj,
  1732. bnx2x_validate_vlan_mac,
  1733. bnx2x_remove_vlan_mac,
  1734. bnx2x_optimize_vlan_mac,
  1735. bnx2x_execute_vlan_mac,
  1736. bnx2x_exeq_get_vlan_mac);
  1737. } else {
  1738. vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e2;
  1739. vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
  1740. vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
  1741. vlan_mac_obj->check_move = bnx2x_check_move;
  1742. vlan_mac_obj->ramrod_cmd =
  1743. RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
  1744. /* Exe Queue */
  1745. bnx2x_exe_queue_init(bp,
  1746. &vlan_mac_obj->exe_queue,
  1747. CLASSIFY_RULES_COUNT,
  1748. qable_obj, bnx2x_validate_vlan_mac,
  1749. bnx2x_remove_vlan_mac,
  1750. bnx2x_optimize_vlan_mac,
  1751. bnx2x_execute_vlan_mac,
  1752. bnx2x_exeq_get_vlan_mac);
  1753. }
  1754. }
  1755. /* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
  1756. static inline void __storm_memset_mac_filters(struct bnx2x *bp,
  1757. struct tstorm_eth_mac_filter_config *mac_filters,
  1758. u16 pf_id)
  1759. {
  1760. size_t size = sizeof(struct tstorm_eth_mac_filter_config);
  1761. u32 addr = BAR_TSTRORM_INTMEM +
  1762. TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
  1763. __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
  1764. }
  1765. static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
  1766. struct bnx2x_rx_mode_ramrod_params *p)
  1767. {
  1768. /* update the bp MAC filter structure */
  1769. u32 mask = (1 << p->cl_id);
  1770. struct tstorm_eth_mac_filter_config *mac_filters =
  1771. (struct tstorm_eth_mac_filter_config *)p->rdata;
  1772. /* initial seeting is drop-all */
  1773. u8 drop_all_ucast = 1, drop_all_mcast = 1;
  1774. u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
  1775. u8 unmatched_unicast = 0;
  1776. /* In e1x there we only take into account rx acceot flag since tx switching
  1777. * isn't enabled. */
  1778. if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
  1779. /* accept matched ucast */
  1780. drop_all_ucast = 0;
  1781. if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
  1782. /* accept matched mcast */
  1783. drop_all_mcast = 0;
  1784. if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
  1785. /* accept all mcast */
  1786. drop_all_ucast = 0;
  1787. accp_all_ucast = 1;
  1788. }
  1789. if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
  1790. /* accept all mcast */
  1791. drop_all_mcast = 0;
  1792. accp_all_mcast = 1;
  1793. }
  1794. if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
  1795. /* accept (all) bcast */
  1796. accp_all_bcast = 1;
  1797. if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
  1798. /* accept unmatched unicasts */
  1799. unmatched_unicast = 1;
  1800. mac_filters->ucast_drop_all = drop_all_ucast ?
  1801. mac_filters->ucast_drop_all | mask :
  1802. mac_filters->ucast_drop_all & ~mask;
  1803. mac_filters->mcast_drop_all = drop_all_mcast ?
  1804. mac_filters->mcast_drop_all | mask :
  1805. mac_filters->mcast_drop_all & ~mask;
  1806. mac_filters->ucast_accept_all = accp_all_ucast ?
  1807. mac_filters->ucast_accept_all | mask :
  1808. mac_filters->ucast_accept_all & ~mask;
  1809. mac_filters->mcast_accept_all = accp_all_mcast ?
  1810. mac_filters->mcast_accept_all | mask :
  1811. mac_filters->mcast_accept_all & ~mask;
  1812. mac_filters->bcast_accept_all = accp_all_bcast ?
  1813. mac_filters->bcast_accept_all | mask :
  1814. mac_filters->bcast_accept_all & ~mask;
  1815. mac_filters->unmatched_unicast = unmatched_unicast ?
  1816. mac_filters->unmatched_unicast | mask :
  1817. mac_filters->unmatched_unicast & ~mask;
  1818. DP(BNX2X_MSG_SP, "drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
  1819. "accp_mcast 0x%x\naccp_bcast 0x%x\n",
  1820. mac_filters->ucast_drop_all, mac_filters->mcast_drop_all,
  1821. mac_filters->ucast_accept_all, mac_filters->mcast_accept_all,
  1822. mac_filters->bcast_accept_all);
  1823. /* write the MAC filter structure*/
  1824. __storm_memset_mac_filters(bp, mac_filters, p->func_id);
  1825. /* The operation is completed */
  1826. clear_bit(p->state, p->pstate);
  1827. smp_mb__after_clear_bit();
  1828. return 0;
  1829. }
  1830. /* Setup ramrod data */
  1831. static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
  1832. struct eth_classify_header *hdr,
  1833. u8 rule_cnt)
  1834. {
  1835. hdr->echo = cpu_to_le32(cid);
  1836. hdr->rule_cnt = rule_cnt;
  1837. }
  1838. static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
  1839. unsigned long *accept_flags,
  1840. struct eth_filter_rules_cmd *cmd,
  1841. bool clear_accept_all)
  1842. {
  1843. u16 state;
  1844. /* start with 'drop-all' */
  1845. state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
  1846. ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
  1847. if (test_bit(BNX2X_ACCEPT_UNICAST, accept_flags))
  1848. state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
  1849. if (test_bit(BNX2X_ACCEPT_MULTICAST, accept_flags))
  1850. state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
  1851. if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, accept_flags)) {
  1852. state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
  1853. state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
  1854. }
  1855. if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, accept_flags)) {
  1856. state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
  1857. state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
  1858. }
  1859. if (test_bit(BNX2X_ACCEPT_BROADCAST, accept_flags))
  1860. state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
  1861. if (test_bit(BNX2X_ACCEPT_UNMATCHED, accept_flags)) {
  1862. state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
  1863. state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
  1864. }
  1865. if (test_bit(BNX2X_ACCEPT_ANY_VLAN, accept_flags))
  1866. state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
  1867. /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
  1868. if (clear_accept_all) {
  1869. state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
  1870. state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
  1871. state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
  1872. state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
  1873. }
  1874. cmd->state = cpu_to_le16(state);
  1875. }
  1876. static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
  1877. struct bnx2x_rx_mode_ramrod_params *p)
  1878. {
  1879. struct eth_filter_rules_ramrod_data *data = p->rdata;
  1880. int rc;
  1881. u8 rule_idx = 0;
  1882. /* Reset the ramrod data buffer */
  1883. memset(data, 0, sizeof(*data));
  1884. /* Setup ramrod data */
  1885. /* Tx (internal switching) */
  1886. if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
  1887. data->rules[rule_idx].client_id = p->cl_id;
  1888. data->rules[rule_idx].func_id = p->func_id;
  1889. data->rules[rule_idx].cmd_general_data =
  1890. ETH_FILTER_RULES_CMD_TX_CMD;
  1891. bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
  1892. &(data->rules[rule_idx++]),
  1893. false);
  1894. }
  1895. /* Rx */
  1896. if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
  1897. data->rules[rule_idx].client_id = p->cl_id;
  1898. data->rules[rule_idx].func_id = p->func_id;
  1899. data->rules[rule_idx].cmd_general_data =
  1900. ETH_FILTER_RULES_CMD_RX_CMD;
  1901. bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
  1902. &(data->rules[rule_idx++]),
  1903. false);
  1904. }
  1905. /*
  1906. * If FCoE Queue configuration has been requested configure the Rx and
  1907. * internal switching modes for this queue in separate rules.
  1908. *
  1909. * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
  1910. * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
  1911. */
  1912. if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
  1913. /* Tx (internal switching) */
  1914. if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
  1915. data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
  1916. data->rules[rule_idx].func_id = p->func_id;
  1917. data->rules[rule_idx].cmd_general_data =
  1918. ETH_FILTER_RULES_CMD_TX_CMD;
  1919. bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
  1920. &(data->rules[rule_idx]),
  1921. true);
  1922. rule_idx++;
  1923. }
  1924. /* Rx */
  1925. if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
  1926. data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
  1927. data->rules[rule_idx].func_id = p->func_id;
  1928. data->rules[rule_idx].cmd_general_data =
  1929. ETH_FILTER_RULES_CMD_RX_CMD;
  1930. bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
  1931. &(data->rules[rule_idx]),
  1932. true);
  1933. rule_idx++;
  1934. }
  1935. }
  1936. /*
  1937. * Set the ramrod header (most importantly - number of rules to
  1938. * configure).
  1939. */
  1940. bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
  1941. DP(BNX2X_MSG_SP, "About to configure %d rules, rx_accept_flags 0x%lx, tx_accept_flags 0x%lx\n",
  1942. data->header.rule_cnt, p->rx_accept_flags,
  1943. p->tx_accept_flags);
  1944. /*
  1945. * No need for an explicit memory barrier here as long we would
  1946. * need to ensure the ordering of writing to the SPQ element
  1947. * and updating of the SPQ producer which involves a memory
  1948. * read and we will have to put a full memory barrier there
  1949. * (inside bnx2x_sp_post()).
  1950. */
  1951. /* Send a ramrod */
  1952. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
  1953. U64_HI(p->rdata_mapping),
  1954. U64_LO(p->rdata_mapping),
  1955. ETH_CONNECTION_TYPE);
  1956. if (rc)
  1957. return rc;
  1958. /* Ramrod completion is pending */
  1959. return 1;
  1960. }
  1961. static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
  1962. struct bnx2x_rx_mode_ramrod_params *p)
  1963. {
  1964. return bnx2x_state_wait(bp, p->state, p->pstate);
  1965. }
  1966. static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
  1967. struct bnx2x_rx_mode_ramrod_params *p)
  1968. {
  1969. /* Do nothing */
  1970. return 0;
  1971. }
  1972. int bnx2x_config_rx_mode(struct bnx2x *bp,
  1973. struct bnx2x_rx_mode_ramrod_params *p)
  1974. {
  1975. int rc;
  1976. /* Configure the new classification in the chip */
  1977. rc = p->rx_mode_obj->config_rx_mode(bp, p);
  1978. if (rc < 0)
  1979. return rc;
  1980. /* Wait for a ramrod completion if was requested */
  1981. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
  1982. rc = p->rx_mode_obj->wait_comp(bp, p);
  1983. if (rc)
  1984. return rc;
  1985. }
  1986. return rc;
  1987. }
  1988. void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
  1989. struct bnx2x_rx_mode_obj *o)
  1990. {
  1991. if (CHIP_IS_E1x(bp)) {
  1992. o->wait_comp = bnx2x_empty_rx_mode_wait;
  1993. o->config_rx_mode = bnx2x_set_rx_mode_e1x;
  1994. } else {
  1995. o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
  1996. o->config_rx_mode = bnx2x_set_rx_mode_e2;
  1997. }
  1998. }
  1999. /********************* Multicast verbs: SET, CLEAR ****************************/
  2000. static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
  2001. {
  2002. return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
  2003. }
  2004. struct bnx2x_mcast_mac_elem {
  2005. struct list_head link;
  2006. u8 mac[ETH_ALEN];
  2007. u8 pad[2]; /* For a natural alignment of the following buffer */
  2008. };
  2009. struct bnx2x_pending_mcast_cmd {
  2010. struct list_head link;
  2011. int type; /* BNX2X_MCAST_CMD_X */
  2012. union {
  2013. struct list_head macs_head;
  2014. u32 macs_num; /* Needed for DEL command */
  2015. int next_bin; /* Needed for RESTORE flow with aprox match */
  2016. } data;
  2017. bool done; /* set to true, when the command has been handled,
  2018. * practically used in 57712 handling only, where one pending
  2019. * command may be handled in a few operations. As long as for
  2020. * other chips every operation handling is completed in a
  2021. * single ramrod, there is no need to utilize this field.
  2022. */
  2023. };
  2024. static int bnx2x_mcast_wait(struct bnx2x *bp,
  2025. struct bnx2x_mcast_obj *o)
  2026. {
  2027. if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
  2028. o->raw.wait_comp(bp, &o->raw))
  2029. return -EBUSY;
  2030. return 0;
  2031. }
  2032. static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
  2033. struct bnx2x_mcast_obj *o,
  2034. struct bnx2x_mcast_ramrod_params *p,
  2035. enum bnx2x_mcast_cmd cmd)
  2036. {
  2037. int total_sz;
  2038. struct bnx2x_pending_mcast_cmd *new_cmd;
  2039. struct bnx2x_mcast_mac_elem *cur_mac = NULL;
  2040. struct bnx2x_mcast_list_elem *pos;
  2041. int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
  2042. p->mcast_list_len : 0);
  2043. /* If the command is empty ("handle pending commands only"), break */
  2044. if (!p->mcast_list_len)
  2045. return 0;
  2046. total_sz = sizeof(*new_cmd) +
  2047. macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
  2048. /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
  2049. new_cmd = kzalloc(total_sz, GFP_ATOMIC);
  2050. if (!new_cmd)
  2051. return -ENOMEM;
  2052. DP(BNX2X_MSG_SP, "About to enqueue a new %d command. macs_list_len=%d\n",
  2053. cmd, macs_list_len);
  2054. INIT_LIST_HEAD(&new_cmd->data.macs_head);
  2055. new_cmd->type = cmd;
  2056. new_cmd->done = false;
  2057. switch (cmd) {
  2058. case BNX2X_MCAST_CMD_ADD:
  2059. cur_mac = (struct bnx2x_mcast_mac_elem *)
  2060. ((u8 *)new_cmd + sizeof(*new_cmd));
  2061. /* Push the MACs of the current command into the pendig command
  2062. * MACs list: FIFO
  2063. */
  2064. list_for_each_entry(pos, &p->mcast_list, link) {
  2065. memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
  2066. list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
  2067. cur_mac++;
  2068. }
  2069. break;
  2070. case BNX2X_MCAST_CMD_DEL:
  2071. new_cmd->data.macs_num = p->mcast_list_len;
  2072. break;
  2073. case BNX2X_MCAST_CMD_RESTORE:
  2074. new_cmd->data.next_bin = 0;
  2075. break;
  2076. default:
  2077. kfree(new_cmd);
  2078. BNX2X_ERR("Unknown command: %d\n", cmd);
  2079. return -EINVAL;
  2080. }
  2081. /* Push the new pending command to the tail of the pending list: FIFO */
  2082. list_add_tail(&new_cmd->link, &o->pending_cmds_head);
  2083. o->set_sched(o);
  2084. return 1;
  2085. }
  2086. /**
  2087. * bnx2x_mcast_get_next_bin - get the next set bin (index)
  2088. *
  2089. * @o:
  2090. * @last: index to start looking from (including)
  2091. *
  2092. * returns the next found (set) bin or a negative value if none is found.
  2093. */
  2094. static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
  2095. {
  2096. int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
  2097. for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
  2098. if (o->registry.aprox_match.vec[i])
  2099. for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
  2100. int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
  2101. if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
  2102. vec, cur_bit)) {
  2103. return cur_bit;
  2104. }
  2105. }
  2106. inner_start = 0;
  2107. }
  2108. /* None found */
  2109. return -1;
  2110. }
  2111. /**
  2112. * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
  2113. *
  2114. * @o:
  2115. *
  2116. * returns the index of the found bin or -1 if none is found
  2117. */
  2118. static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
  2119. {
  2120. int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
  2121. if (cur_bit >= 0)
  2122. BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
  2123. return cur_bit;
  2124. }
  2125. static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
  2126. {
  2127. struct bnx2x_raw_obj *raw = &o->raw;
  2128. u8 rx_tx_flag = 0;
  2129. if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
  2130. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  2131. rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
  2132. if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
  2133. (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
  2134. rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
  2135. return rx_tx_flag;
  2136. }
  2137. static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
  2138. struct bnx2x_mcast_obj *o, int idx,
  2139. union bnx2x_mcast_config_data *cfg_data,
  2140. enum bnx2x_mcast_cmd cmd)
  2141. {
  2142. struct bnx2x_raw_obj *r = &o->raw;
  2143. struct eth_multicast_rules_ramrod_data *data =
  2144. (struct eth_multicast_rules_ramrod_data *)(r->rdata);
  2145. u8 func_id = r->func_id;
  2146. u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
  2147. int bin;
  2148. if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
  2149. rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
  2150. data->rules[idx].cmd_general_data |= rx_tx_add_flag;
  2151. /* Get a bin and update a bins' vector */
  2152. switch (cmd) {
  2153. case BNX2X_MCAST_CMD_ADD:
  2154. bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
  2155. BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
  2156. break;
  2157. case BNX2X_MCAST_CMD_DEL:
  2158. /* If there were no more bins to clear
  2159. * (bnx2x_mcast_clear_first_bin() returns -1) then we would
  2160. * clear any (0xff) bin.
  2161. * See bnx2x_mcast_validate_e2() for explanation when it may
  2162. * happen.
  2163. */
  2164. bin = bnx2x_mcast_clear_first_bin(o);
  2165. break;
  2166. case BNX2X_MCAST_CMD_RESTORE:
  2167. bin = cfg_data->bin;
  2168. break;
  2169. default:
  2170. BNX2X_ERR("Unknown command: %d\n", cmd);
  2171. return;
  2172. }
  2173. DP(BNX2X_MSG_SP, "%s bin %d\n",
  2174. ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
  2175. "Setting" : "Clearing"), bin);
  2176. data->rules[idx].bin_id = (u8)bin;
  2177. data->rules[idx].func_id = func_id;
  2178. data->rules[idx].engine_id = o->engine_id;
  2179. }
  2180. /**
  2181. * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
  2182. *
  2183. * @bp: device handle
  2184. * @o:
  2185. * @start_bin: index in the registry to start from (including)
  2186. * @rdata_idx: index in the ramrod data to start from
  2187. *
  2188. * returns last handled bin index or -1 if all bins have been handled
  2189. */
  2190. static inline int bnx2x_mcast_handle_restore_cmd_e2(
  2191. struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
  2192. int *rdata_idx)
  2193. {
  2194. int cur_bin, cnt = *rdata_idx;
  2195. union bnx2x_mcast_config_data cfg_data = {NULL};
  2196. /* go through the registry and configure the bins from it */
  2197. for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
  2198. cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
  2199. cfg_data.bin = (u8)cur_bin;
  2200. o->set_one_rule(bp, o, cnt, &cfg_data,
  2201. BNX2X_MCAST_CMD_RESTORE);
  2202. cnt++;
  2203. DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
  2204. /* Break if we reached the maximum number
  2205. * of rules.
  2206. */
  2207. if (cnt >= o->max_cmd_len)
  2208. break;
  2209. }
  2210. *rdata_idx = cnt;
  2211. return cur_bin;
  2212. }
  2213. static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
  2214. struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
  2215. int *line_idx)
  2216. {
  2217. struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
  2218. int cnt = *line_idx;
  2219. union bnx2x_mcast_config_data cfg_data = {NULL};
  2220. list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
  2221. link) {
  2222. cfg_data.mac = &pmac_pos->mac[0];
  2223. o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
  2224. cnt++;
  2225. DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
  2226. pmac_pos->mac);
  2227. list_del(&pmac_pos->link);
  2228. /* Break if we reached the maximum number
  2229. * of rules.
  2230. */
  2231. if (cnt >= o->max_cmd_len)
  2232. break;
  2233. }
  2234. *line_idx = cnt;
  2235. /* if no more MACs to configure - we are done */
  2236. if (list_empty(&cmd_pos->data.macs_head))
  2237. cmd_pos->done = true;
  2238. }
  2239. static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
  2240. struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
  2241. int *line_idx)
  2242. {
  2243. int cnt = *line_idx;
  2244. while (cmd_pos->data.macs_num) {
  2245. o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
  2246. cnt++;
  2247. cmd_pos->data.macs_num--;
  2248. DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
  2249. cmd_pos->data.macs_num, cnt);
  2250. /* Break if we reached the maximum
  2251. * number of rules.
  2252. */
  2253. if (cnt >= o->max_cmd_len)
  2254. break;
  2255. }
  2256. *line_idx = cnt;
  2257. /* If we cleared all bins - we are done */
  2258. if (!cmd_pos->data.macs_num)
  2259. cmd_pos->done = true;
  2260. }
  2261. static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
  2262. struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
  2263. int *line_idx)
  2264. {
  2265. cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
  2266. line_idx);
  2267. if (cmd_pos->data.next_bin < 0)
  2268. /* If o->set_restore returned -1 we are done */
  2269. cmd_pos->done = true;
  2270. else
  2271. /* Start from the next bin next time */
  2272. cmd_pos->data.next_bin++;
  2273. }
  2274. static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
  2275. struct bnx2x_mcast_ramrod_params *p)
  2276. {
  2277. struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
  2278. int cnt = 0;
  2279. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2280. list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
  2281. link) {
  2282. switch (cmd_pos->type) {
  2283. case BNX2X_MCAST_CMD_ADD:
  2284. bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
  2285. break;
  2286. case BNX2X_MCAST_CMD_DEL:
  2287. bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
  2288. break;
  2289. case BNX2X_MCAST_CMD_RESTORE:
  2290. bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
  2291. &cnt);
  2292. break;
  2293. default:
  2294. BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
  2295. return -EINVAL;
  2296. }
  2297. /* If the command has been completed - remove it from the list
  2298. * and free the memory
  2299. */
  2300. if (cmd_pos->done) {
  2301. list_del(&cmd_pos->link);
  2302. kfree(cmd_pos);
  2303. }
  2304. /* Break if we reached the maximum number of rules */
  2305. if (cnt >= o->max_cmd_len)
  2306. break;
  2307. }
  2308. return cnt;
  2309. }
  2310. static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
  2311. struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
  2312. int *line_idx)
  2313. {
  2314. struct bnx2x_mcast_list_elem *mlist_pos;
  2315. union bnx2x_mcast_config_data cfg_data = {NULL};
  2316. int cnt = *line_idx;
  2317. list_for_each_entry(mlist_pos, &p->mcast_list, link) {
  2318. cfg_data.mac = mlist_pos->mac;
  2319. o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
  2320. cnt++;
  2321. DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
  2322. mlist_pos->mac);
  2323. }
  2324. *line_idx = cnt;
  2325. }
  2326. static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
  2327. struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
  2328. int *line_idx)
  2329. {
  2330. int cnt = *line_idx, i;
  2331. for (i = 0; i < p->mcast_list_len; i++) {
  2332. o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
  2333. cnt++;
  2334. DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
  2335. p->mcast_list_len - i - 1);
  2336. }
  2337. *line_idx = cnt;
  2338. }
  2339. /**
  2340. * bnx2x_mcast_handle_current_cmd -
  2341. *
  2342. * @bp: device handle
  2343. * @p:
  2344. * @cmd:
  2345. * @start_cnt: first line in the ramrod data that may be used
  2346. *
  2347. * This function is called iff there is enough place for the current command in
  2348. * the ramrod data.
  2349. * Returns number of lines filled in the ramrod data in total.
  2350. */
  2351. static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
  2352. struct bnx2x_mcast_ramrod_params *p,
  2353. enum bnx2x_mcast_cmd cmd,
  2354. int start_cnt)
  2355. {
  2356. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2357. int cnt = start_cnt;
  2358. DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
  2359. switch (cmd) {
  2360. case BNX2X_MCAST_CMD_ADD:
  2361. bnx2x_mcast_hdl_add(bp, o, p, &cnt);
  2362. break;
  2363. case BNX2X_MCAST_CMD_DEL:
  2364. bnx2x_mcast_hdl_del(bp, o, p, &cnt);
  2365. break;
  2366. case BNX2X_MCAST_CMD_RESTORE:
  2367. o->hdl_restore(bp, o, 0, &cnt);
  2368. break;
  2369. default:
  2370. BNX2X_ERR("Unknown command: %d\n", cmd);
  2371. return -EINVAL;
  2372. }
  2373. /* The current command has been handled */
  2374. p->mcast_list_len = 0;
  2375. return cnt;
  2376. }
  2377. static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
  2378. struct bnx2x_mcast_ramrod_params *p,
  2379. enum bnx2x_mcast_cmd cmd)
  2380. {
  2381. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2382. int reg_sz = o->get_registry_size(o);
  2383. switch (cmd) {
  2384. /* DEL command deletes all currently configured MACs */
  2385. case BNX2X_MCAST_CMD_DEL:
  2386. o->set_registry_size(o, 0);
  2387. /* Don't break */
  2388. /* RESTORE command will restore the entire multicast configuration */
  2389. case BNX2X_MCAST_CMD_RESTORE:
  2390. /* Here we set the approximate amount of work to do, which in
  2391. * fact may be only less as some MACs in postponed ADD
  2392. * command(s) scheduled before this command may fall into
  2393. * the same bin and the actual number of bins set in the
  2394. * registry would be less than we estimated here. See
  2395. * bnx2x_mcast_set_one_rule_e2() for further details.
  2396. */
  2397. p->mcast_list_len = reg_sz;
  2398. break;
  2399. case BNX2X_MCAST_CMD_ADD:
  2400. case BNX2X_MCAST_CMD_CONT:
  2401. /* Here we assume that all new MACs will fall into new bins.
  2402. * However we will correct the real registry size after we
  2403. * handle all pending commands.
  2404. */
  2405. o->set_registry_size(o, reg_sz + p->mcast_list_len);
  2406. break;
  2407. default:
  2408. BNX2X_ERR("Unknown command: %d\n", cmd);
  2409. return -EINVAL;
  2410. }
  2411. /* Increase the total number of MACs pending to be configured */
  2412. o->total_pending_num += p->mcast_list_len;
  2413. return 0;
  2414. }
  2415. static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
  2416. struct bnx2x_mcast_ramrod_params *p,
  2417. int old_num_bins)
  2418. {
  2419. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2420. o->set_registry_size(o, old_num_bins);
  2421. o->total_pending_num -= p->mcast_list_len;
  2422. }
  2423. /**
  2424. * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
  2425. *
  2426. * @bp: device handle
  2427. * @p:
  2428. * @len: number of rules to handle
  2429. */
  2430. static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
  2431. struct bnx2x_mcast_ramrod_params *p,
  2432. u8 len)
  2433. {
  2434. struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
  2435. struct eth_multicast_rules_ramrod_data *data =
  2436. (struct eth_multicast_rules_ramrod_data *)(r->rdata);
  2437. data->header.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
  2438. (BNX2X_FILTER_MCAST_PENDING <<
  2439. BNX2X_SWCID_SHIFT));
  2440. data->header.rule_cnt = len;
  2441. }
  2442. /**
  2443. * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
  2444. *
  2445. * @bp: device handle
  2446. * @o:
  2447. *
  2448. * Recalculate the actual number of set bins in the registry using Brian
  2449. * Kernighan's algorithm: it's execution complexity is as a number of set bins.
  2450. *
  2451. * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
  2452. */
  2453. static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
  2454. struct bnx2x_mcast_obj *o)
  2455. {
  2456. int i, cnt = 0;
  2457. u64 elem;
  2458. for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
  2459. elem = o->registry.aprox_match.vec[i];
  2460. for (; elem; cnt++)
  2461. elem &= elem - 1;
  2462. }
  2463. o->set_registry_size(o, cnt);
  2464. return 0;
  2465. }
  2466. static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
  2467. struct bnx2x_mcast_ramrod_params *p,
  2468. enum bnx2x_mcast_cmd cmd)
  2469. {
  2470. struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
  2471. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2472. struct eth_multicast_rules_ramrod_data *data =
  2473. (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
  2474. int cnt = 0, rc;
  2475. /* Reset the ramrod data buffer */
  2476. memset(data, 0, sizeof(*data));
  2477. cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
  2478. /* If there are no more pending commands - clear SCHEDULED state */
  2479. if (list_empty(&o->pending_cmds_head))
  2480. o->clear_sched(o);
  2481. /* The below may be true iff there was enough room in ramrod
  2482. * data for all pending commands and for the current
  2483. * command. Otherwise the current command would have been added
  2484. * to the pending commands and p->mcast_list_len would have been
  2485. * zeroed.
  2486. */
  2487. if (p->mcast_list_len > 0)
  2488. cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
  2489. /* We've pulled out some MACs - update the total number of
  2490. * outstanding.
  2491. */
  2492. o->total_pending_num -= cnt;
  2493. /* send a ramrod */
  2494. WARN_ON(o->total_pending_num < 0);
  2495. WARN_ON(cnt > o->max_cmd_len);
  2496. bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
  2497. /* Update a registry size if there are no more pending operations.
  2498. *
  2499. * We don't want to change the value of the registry size if there are
  2500. * pending operations because we want it to always be equal to the
  2501. * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
  2502. * set bins after the last requested operation in order to properly
  2503. * evaluate the size of the next DEL/RESTORE operation.
  2504. *
  2505. * Note that we update the registry itself during command(s) handling
  2506. * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
  2507. * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
  2508. * with a limited amount of update commands (per MAC/bin) and we don't
  2509. * know in this scope what the actual state of bins configuration is
  2510. * going to be after this ramrod.
  2511. */
  2512. if (!o->total_pending_num)
  2513. bnx2x_mcast_refresh_registry_e2(bp, o);
  2514. /*
  2515. * If CLEAR_ONLY was requested - don't send a ramrod and clear
  2516. * RAMROD_PENDING status immediately.
  2517. */
  2518. if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
  2519. raw->clear_pending(raw);
  2520. return 0;
  2521. } else {
  2522. /*
  2523. * No need for an explicit memory barrier here as long we would
  2524. * need to ensure the ordering of writing to the SPQ element
  2525. * and updating of the SPQ producer which involves a memory
  2526. * read and we will have to put a full memory barrier there
  2527. * (inside bnx2x_sp_post()).
  2528. */
  2529. /* Send a ramrod */
  2530. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
  2531. raw->cid, U64_HI(raw->rdata_mapping),
  2532. U64_LO(raw->rdata_mapping),
  2533. ETH_CONNECTION_TYPE);
  2534. if (rc)
  2535. return rc;
  2536. /* Ramrod completion is pending */
  2537. return 1;
  2538. }
  2539. }
  2540. static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
  2541. struct bnx2x_mcast_ramrod_params *p,
  2542. enum bnx2x_mcast_cmd cmd)
  2543. {
  2544. /* Mark, that there is a work to do */
  2545. if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
  2546. p->mcast_list_len = 1;
  2547. return 0;
  2548. }
  2549. static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
  2550. struct bnx2x_mcast_ramrod_params *p,
  2551. int old_num_bins)
  2552. {
  2553. /* Do nothing */
  2554. }
  2555. #define BNX2X_57711_SET_MC_FILTER(filter, bit) \
  2556. do { \
  2557. (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
  2558. } while (0)
  2559. static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
  2560. struct bnx2x_mcast_obj *o,
  2561. struct bnx2x_mcast_ramrod_params *p,
  2562. u32 *mc_filter)
  2563. {
  2564. struct bnx2x_mcast_list_elem *mlist_pos;
  2565. int bit;
  2566. list_for_each_entry(mlist_pos, &p->mcast_list, link) {
  2567. bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
  2568. BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
  2569. DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC, bin %d\n",
  2570. mlist_pos->mac, bit);
  2571. /* bookkeeping... */
  2572. BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
  2573. bit);
  2574. }
  2575. }
  2576. static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
  2577. struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
  2578. u32 *mc_filter)
  2579. {
  2580. int bit;
  2581. for (bit = bnx2x_mcast_get_next_bin(o, 0);
  2582. bit >= 0;
  2583. bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
  2584. BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
  2585. DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
  2586. }
  2587. }
  2588. /* On 57711 we write the multicast MACs' aproximate match
  2589. * table by directly into the TSTORM's internal RAM. So we don't
  2590. * really need to handle any tricks to make it work.
  2591. */
  2592. static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
  2593. struct bnx2x_mcast_ramrod_params *p,
  2594. enum bnx2x_mcast_cmd cmd)
  2595. {
  2596. int i;
  2597. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2598. struct bnx2x_raw_obj *r = &o->raw;
  2599. /* If CLEAR_ONLY has been requested - clear the registry
  2600. * and clear a pending bit.
  2601. */
  2602. if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
  2603. u32 mc_filter[MC_HASH_SIZE] = {0};
  2604. /* Set the multicast filter bits before writing it into
  2605. * the internal memory.
  2606. */
  2607. switch (cmd) {
  2608. case BNX2X_MCAST_CMD_ADD:
  2609. bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
  2610. break;
  2611. case BNX2X_MCAST_CMD_DEL:
  2612. DP(BNX2X_MSG_SP,
  2613. "Invalidating multicast MACs configuration\n");
  2614. /* clear the registry */
  2615. memset(o->registry.aprox_match.vec, 0,
  2616. sizeof(o->registry.aprox_match.vec));
  2617. break;
  2618. case BNX2X_MCAST_CMD_RESTORE:
  2619. bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
  2620. break;
  2621. default:
  2622. BNX2X_ERR("Unknown command: %d\n", cmd);
  2623. return -EINVAL;
  2624. }
  2625. /* Set the mcast filter in the internal memory */
  2626. for (i = 0; i < MC_HASH_SIZE; i++)
  2627. REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
  2628. } else
  2629. /* clear the registry */
  2630. memset(o->registry.aprox_match.vec, 0,
  2631. sizeof(o->registry.aprox_match.vec));
  2632. /* We are done */
  2633. r->clear_pending(r);
  2634. return 0;
  2635. }
  2636. static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
  2637. struct bnx2x_mcast_ramrod_params *p,
  2638. enum bnx2x_mcast_cmd cmd)
  2639. {
  2640. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2641. int reg_sz = o->get_registry_size(o);
  2642. switch (cmd) {
  2643. /* DEL command deletes all currently configured MACs */
  2644. case BNX2X_MCAST_CMD_DEL:
  2645. o->set_registry_size(o, 0);
  2646. /* Don't break */
  2647. /* RESTORE command will restore the entire multicast configuration */
  2648. case BNX2X_MCAST_CMD_RESTORE:
  2649. p->mcast_list_len = reg_sz;
  2650. DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
  2651. cmd, p->mcast_list_len);
  2652. break;
  2653. case BNX2X_MCAST_CMD_ADD:
  2654. case BNX2X_MCAST_CMD_CONT:
  2655. /* Multicast MACs on 57710 are configured as unicast MACs and
  2656. * there is only a limited number of CAM entries for that
  2657. * matter.
  2658. */
  2659. if (p->mcast_list_len > o->max_cmd_len) {
  2660. BNX2X_ERR("Can't configure more than %d multicast MACs on 57710\n",
  2661. o->max_cmd_len);
  2662. return -EINVAL;
  2663. }
  2664. /* Every configured MAC should be cleared if DEL command is
  2665. * called. Only the last ADD command is relevant as long as
  2666. * every ADD commands overrides the previous configuration.
  2667. */
  2668. DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
  2669. if (p->mcast_list_len > 0)
  2670. o->set_registry_size(o, p->mcast_list_len);
  2671. break;
  2672. default:
  2673. BNX2X_ERR("Unknown command: %d\n", cmd);
  2674. return -EINVAL;
  2675. }
  2676. /* We want to ensure that commands are executed one by one for 57710.
  2677. * Therefore each none-empty command will consume o->max_cmd_len.
  2678. */
  2679. if (p->mcast_list_len)
  2680. o->total_pending_num += o->max_cmd_len;
  2681. return 0;
  2682. }
  2683. static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
  2684. struct bnx2x_mcast_ramrod_params *p,
  2685. int old_num_macs)
  2686. {
  2687. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2688. o->set_registry_size(o, old_num_macs);
  2689. /* If current command hasn't been handled yet and we are
  2690. * here means that it's meant to be dropped and we have to
  2691. * update the number of outstandling MACs accordingly.
  2692. */
  2693. if (p->mcast_list_len)
  2694. o->total_pending_num -= o->max_cmd_len;
  2695. }
  2696. static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
  2697. struct bnx2x_mcast_obj *o, int idx,
  2698. union bnx2x_mcast_config_data *cfg_data,
  2699. enum bnx2x_mcast_cmd cmd)
  2700. {
  2701. struct bnx2x_raw_obj *r = &o->raw;
  2702. struct mac_configuration_cmd *data =
  2703. (struct mac_configuration_cmd *)(r->rdata);
  2704. /* copy mac */
  2705. if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
  2706. bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
  2707. &data->config_table[idx].middle_mac_addr,
  2708. &data->config_table[idx].lsb_mac_addr,
  2709. cfg_data->mac);
  2710. data->config_table[idx].vlan_id = 0;
  2711. data->config_table[idx].pf_id = r->func_id;
  2712. data->config_table[idx].clients_bit_vector =
  2713. cpu_to_le32(1 << r->cl_id);
  2714. SET_FLAG(data->config_table[idx].flags,
  2715. MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  2716. T_ETH_MAC_COMMAND_SET);
  2717. }
  2718. }
  2719. /**
  2720. * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
  2721. *
  2722. * @bp: device handle
  2723. * @p:
  2724. * @len: number of rules to handle
  2725. */
  2726. static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
  2727. struct bnx2x_mcast_ramrod_params *p,
  2728. u8 len)
  2729. {
  2730. struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
  2731. struct mac_configuration_cmd *data =
  2732. (struct mac_configuration_cmd *)(r->rdata);
  2733. u8 offset = (CHIP_REV_IS_SLOW(bp) ?
  2734. BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
  2735. BNX2X_MAX_MULTICAST*(1 + r->func_id));
  2736. data->hdr.offset = offset;
  2737. data->hdr.client_id = cpu_to_le16(0xff);
  2738. data->hdr.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
  2739. (BNX2X_FILTER_MCAST_PENDING <<
  2740. BNX2X_SWCID_SHIFT));
  2741. data->hdr.length = len;
  2742. }
  2743. /**
  2744. * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
  2745. *
  2746. * @bp: device handle
  2747. * @o:
  2748. * @start_idx: index in the registry to start from
  2749. * @rdata_idx: index in the ramrod data to start from
  2750. *
  2751. * restore command for 57710 is like all other commands - always a stand alone
  2752. * command - start_idx and rdata_idx will always be 0. This function will always
  2753. * succeed.
  2754. * returns -1 to comply with 57712 variant.
  2755. */
  2756. static inline int bnx2x_mcast_handle_restore_cmd_e1(
  2757. struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
  2758. int *rdata_idx)
  2759. {
  2760. struct bnx2x_mcast_mac_elem *elem;
  2761. int i = 0;
  2762. union bnx2x_mcast_config_data cfg_data = {NULL};
  2763. /* go through the registry and configure the MACs from it. */
  2764. list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
  2765. cfg_data.mac = &elem->mac[0];
  2766. o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
  2767. i++;
  2768. DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
  2769. cfg_data.mac);
  2770. }
  2771. *rdata_idx = i;
  2772. return -1;
  2773. }
  2774. static inline int bnx2x_mcast_handle_pending_cmds_e1(
  2775. struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
  2776. {
  2777. struct bnx2x_pending_mcast_cmd *cmd_pos;
  2778. struct bnx2x_mcast_mac_elem *pmac_pos;
  2779. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2780. union bnx2x_mcast_config_data cfg_data = {NULL};
  2781. int cnt = 0;
  2782. /* If nothing to be done - return */
  2783. if (list_empty(&o->pending_cmds_head))
  2784. return 0;
  2785. /* Handle the first command */
  2786. cmd_pos = list_first_entry(&o->pending_cmds_head,
  2787. struct bnx2x_pending_mcast_cmd, link);
  2788. switch (cmd_pos->type) {
  2789. case BNX2X_MCAST_CMD_ADD:
  2790. list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
  2791. cfg_data.mac = &pmac_pos->mac[0];
  2792. o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
  2793. cnt++;
  2794. DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
  2795. pmac_pos->mac);
  2796. }
  2797. break;
  2798. case BNX2X_MCAST_CMD_DEL:
  2799. cnt = cmd_pos->data.macs_num;
  2800. DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
  2801. break;
  2802. case BNX2X_MCAST_CMD_RESTORE:
  2803. o->hdl_restore(bp, o, 0, &cnt);
  2804. break;
  2805. default:
  2806. BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
  2807. return -EINVAL;
  2808. }
  2809. list_del(&cmd_pos->link);
  2810. kfree(cmd_pos);
  2811. return cnt;
  2812. }
  2813. /**
  2814. * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
  2815. *
  2816. * @fw_hi:
  2817. * @fw_mid:
  2818. * @fw_lo:
  2819. * @mac:
  2820. */
  2821. static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
  2822. __le16 *fw_lo, u8 *mac)
  2823. {
  2824. mac[1] = ((u8 *)fw_hi)[0];
  2825. mac[0] = ((u8 *)fw_hi)[1];
  2826. mac[3] = ((u8 *)fw_mid)[0];
  2827. mac[2] = ((u8 *)fw_mid)[1];
  2828. mac[5] = ((u8 *)fw_lo)[0];
  2829. mac[4] = ((u8 *)fw_lo)[1];
  2830. }
  2831. /**
  2832. * bnx2x_mcast_refresh_registry_e1 -
  2833. *
  2834. * @bp: device handle
  2835. * @cnt:
  2836. *
  2837. * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
  2838. * and update the registry correspondingly: if ADD - allocate a memory and add
  2839. * the entries to the registry (list), if DELETE - clear the registry and free
  2840. * the memory.
  2841. */
  2842. static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
  2843. struct bnx2x_mcast_obj *o)
  2844. {
  2845. struct bnx2x_raw_obj *raw = &o->raw;
  2846. struct bnx2x_mcast_mac_elem *elem;
  2847. struct mac_configuration_cmd *data =
  2848. (struct mac_configuration_cmd *)(raw->rdata);
  2849. /* If first entry contains a SET bit - the command was ADD,
  2850. * otherwise - DEL_ALL
  2851. */
  2852. if (GET_FLAG(data->config_table[0].flags,
  2853. MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
  2854. int i, len = data->hdr.length;
  2855. /* Break if it was a RESTORE command */
  2856. if (!list_empty(&o->registry.exact_match.macs))
  2857. return 0;
  2858. elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
  2859. if (!elem) {
  2860. BNX2X_ERR("Failed to allocate registry memory\n");
  2861. return -ENOMEM;
  2862. }
  2863. for (i = 0; i < len; i++, elem++) {
  2864. bnx2x_get_fw_mac_addr(
  2865. &data->config_table[i].msb_mac_addr,
  2866. &data->config_table[i].middle_mac_addr,
  2867. &data->config_table[i].lsb_mac_addr,
  2868. elem->mac);
  2869. DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
  2870. elem->mac);
  2871. list_add_tail(&elem->link,
  2872. &o->registry.exact_match.macs);
  2873. }
  2874. } else {
  2875. elem = list_first_entry(&o->registry.exact_match.macs,
  2876. struct bnx2x_mcast_mac_elem, link);
  2877. DP(BNX2X_MSG_SP, "Deleting a registry\n");
  2878. kfree(elem);
  2879. INIT_LIST_HEAD(&o->registry.exact_match.macs);
  2880. }
  2881. return 0;
  2882. }
  2883. static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
  2884. struct bnx2x_mcast_ramrod_params *p,
  2885. enum bnx2x_mcast_cmd cmd)
  2886. {
  2887. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2888. struct bnx2x_raw_obj *raw = &o->raw;
  2889. struct mac_configuration_cmd *data =
  2890. (struct mac_configuration_cmd *)(raw->rdata);
  2891. int cnt = 0, i, rc;
  2892. /* Reset the ramrod data buffer */
  2893. memset(data, 0, sizeof(*data));
  2894. /* First set all entries as invalid */
  2895. for (i = 0; i < o->max_cmd_len ; i++)
  2896. SET_FLAG(data->config_table[i].flags,
  2897. MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
  2898. T_ETH_MAC_COMMAND_INVALIDATE);
  2899. /* Handle pending commands first */
  2900. cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
  2901. /* If there are no more pending commands - clear SCHEDULED state */
  2902. if (list_empty(&o->pending_cmds_head))
  2903. o->clear_sched(o);
  2904. /* The below may be true iff there were no pending commands */
  2905. if (!cnt)
  2906. cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
  2907. /* For 57710 every command has o->max_cmd_len length to ensure that
  2908. * commands are done one at a time.
  2909. */
  2910. o->total_pending_num -= o->max_cmd_len;
  2911. /* send a ramrod */
  2912. WARN_ON(cnt > o->max_cmd_len);
  2913. /* Set ramrod header (in particular, a number of entries to update) */
  2914. bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
  2915. /* update a registry: we need the registry contents to be always up
  2916. * to date in order to be able to execute a RESTORE opcode. Here
  2917. * we use the fact that for 57710 we sent one command at a time
  2918. * hence we may take the registry update out of the command handling
  2919. * and do it in a simpler way here.
  2920. */
  2921. rc = bnx2x_mcast_refresh_registry_e1(bp, o);
  2922. if (rc)
  2923. return rc;
  2924. /*
  2925. * If CLEAR_ONLY was requested - don't send a ramrod and clear
  2926. * RAMROD_PENDING status immediately.
  2927. */
  2928. if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
  2929. raw->clear_pending(raw);
  2930. return 0;
  2931. } else {
  2932. /*
  2933. * No need for an explicit memory barrier here as long we would
  2934. * need to ensure the ordering of writing to the SPQ element
  2935. * and updating of the SPQ producer which involves a memory
  2936. * read and we will have to put a full memory barrier there
  2937. * (inside bnx2x_sp_post()).
  2938. */
  2939. /* Send a ramrod */
  2940. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
  2941. U64_HI(raw->rdata_mapping),
  2942. U64_LO(raw->rdata_mapping),
  2943. ETH_CONNECTION_TYPE);
  2944. if (rc)
  2945. return rc;
  2946. /* Ramrod completion is pending */
  2947. return 1;
  2948. }
  2949. }
  2950. static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
  2951. {
  2952. return o->registry.exact_match.num_macs_set;
  2953. }
  2954. static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
  2955. {
  2956. return o->registry.aprox_match.num_bins_set;
  2957. }
  2958. static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
  2959. int n)
  2960. {
  2961. o->registry.exact_match.num_macs_set = n;
  2962. }
  2963. static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
  2964. int n)
  2965. {
  2966. o->registry.aprox_match.num_bins_set = n;
  2967. }
  2968. int bnx2x_config_mcast(struct bnx2x *bp,
  2969. struct bnx2x_mcast_ramrod_params *p,
  2970. enum bnx2x_mcast_cmd cmd)
  2971. {
  2972. struct bnx2x_mcast_obj *o = p->mcast_obj;
  2973. struct bnx2x_raw_obj *r = &o->raw;
  2974. int rc = 0, old_reg_size;
  2975. /* This is needed to recover number of currently configured mcast macs
  2976. * in case of failure.
  2977. */
  2978. old_reg_size = o->get_registry_size(o);
  2979. /* Do some calculations and checks */
  2980. rc = o->validate(bp, p, cmd);
  2981. if (rc)
  2982. return rc;
  2983. /* Return if there is no work to do */
  2984. if ((!p->mcast_list_len) && (!o->check_sched(o)))
  2985. return 0;
  2986. DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d o->max_cmd_len=%d\n",
  2987. o->total_pending_num, p->mcast_list_len, o->max_cmd_len);
  2988. /* Enqueue the current command to the pending list if we can't complete
  2989. * it in the current iteration
  2990. */
  2991. if (r->check_pending(r) ||
  2992. ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
  2993. rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
  2994. if (rc < 0)
  2995. goto error_exit1;
  2996. /* As long as the current command is in a command list we
  2997. * don't need to handle it separately.
  2998. */
  2999. p->mcast_list_len = 0;
  3000. }
  3001. if (!r->check_pending(r)) {
  3002. /* Set 'pending' state */
  3003. r->set_pending(r);
  3004. /* Configure the new classification in the chip */
  3005. rc = o->config_mcast(bp, p, cmd);
  3006. if (rc < 0)
  3007. goto error_exit2;
  3008. /* Wait for a ramrod completion if was requested */
  3009. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
  3010. rc = o->wait_comp(bp, o);
  3011. }
  3012. return rc;
  3013. error_exit2:
  3014. r->clear_pending(r);
  3015. error_exit1:
  3016. o->revert(bp, p, old_reg_size);
  3017. return rc;
  3018. }
  3019. static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
  3020. {
  3021. smp_mb__before_clear_bit();
  3022. clear_bit(o->sched_state, o->raw.pstate);
  3023. smp_mb__after_clear_bit();
  3024. }
  3025. static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
  3026. {
  3027. smp_mb__before_clear_bit();
  3028. set_bit(o->sched_state, o->raw.pstate);
  3029. smp_mb__after_clear_bit();
  3030. }
  3031. static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
  3032. {
  3033. return !!test_bit(o->sched_state, o->raw.pstate);
  3034. }
  3035. static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
  3036. {
  3037. return o->raw.check_pending(&o->raw) || o->check_sched(o);
  3038. }
  3039. void bnx2x_init_mcast_obj(struct bnx2x *bp,
  3040. struct bnx2x_mcast_obj *mcast_obj,
  3041. u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
  3042. u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
  3043. int state, unsigned long *pstate, bnx2x_obj_type type)
  3044. {
  3045. memset(mcast_obj, 0, sizeof(*mcast_obj));
  3046. bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
  3047. rdata, rdata_mapping, state, pstate, type);
  3048. mcast_obj->engine_id = engine_id;
  3049. INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
  3050. mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
  3051. mcast_obj->check_sched = bnx2x_mcast_check_sched;
  3052. mcast_obj->set_sched = bnx2x_mcast_set_sched;
  3053. mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
  3054. if (CHIP_IS_E1(bp)) {
  3055. mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
  3056. mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
  3057. mcast_obj->hdl_restore =
  3058. bnx2x_mcast_handle_restore_cmd_e1;
  3059. mcast_obj->check_pending = bnx2x_mcast_check_pending;
  3060. if (CHIP_REV_IS_SLOW(bp))
  3061. mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
  3062. else
  3063. mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
  3064. mcast_obj->wait_comp = bnx2x_mcast_wait;
  3065. mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
  3066. mcast_obj->validate = bnx2x_mcast_validate_e1;
  3067. mcast_obj->revert = bnx2x_mcast_revert_e1;
  3068. mcast_obj->get_registry_size =
  3069. bnx2x_mcast_get_registry_size_exact;
  3070. mcast_obj->set_registry_size =
  3071. bnx2x_mcast_set_registry_size_exact;
  3072. /* 57710 is the only chip that uses the exact match for mcast
  3073. * at the moment.
  3074. */
  3075. INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
  3076. } else if (CHIP_IS_E1H(bp)) {
  3077. mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
  3078. mcast_obj->enqueue_cmd = NULL;
  3079. mcast_obj->hdl_restore = NULL;
  3080. mcast_obj->check_pending = bnx2x_mcast_check_pending;
  3081. /* 57711 doesn't send a ramrod, so it has unlimited credit
  3082. * for one command.
  3083. */
  3084. mcast_obj->max_cmd_len = -1;
  3085. mcast_obj->wait_comp = bnx2x_mcast_wait;
  3086. mcast_obj->set_one_rule = NULL;
  3087. mcast_obj->validate = bnx2x_mcast_validate_e1h;
  3088. mcast_obj->revert = bnx2x_mcast_revert_e1h;
  3089. mcast_obj->get_registry_size =
  3090. bnx2x_mcast_get_registry_size_aprox;
  3091. mcast_obj->set_registry_size =
  3092. bnx2x_mcast_set_registry_size_aprox;
  3093. } else {
  3094. mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
  3095. mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
  3096. mcast_obj->hdl_restore =
  3097. bnx2x_mcast_handle_restore_cmd_e2;
  3098. mcast_obj->check_pending = bnx2x_mcast_check_pending;
  3099. /* TODO: There should be a proper HSI define for this number!!!
  3100. */
  3101. mcast_obj->max_cmd_len = 16;
  3102. mcast_obj->wait_comp = bnx2x_mcast_wait;
  3103. mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
  3104. mcast_obj->validate = bnx2x_mcast_validate_e2;
  3105. mcast_obj->revert = bnx2x_mcast_revert_e2;
  3106. mcast_obj->get_registry_size =
  3107. bnx2x_mcast_get_registry_size_aprox;
  3108. mcast_obj->set_registry_size =
  3109. bnx2x_mcast_set_registry_size_aprox;
  3110. }
  3111. }
  3112. /*************************** Credit handling **********************************/
  3113. /**
  3114. * atomic_add_ifless - add if the result is less than a given value.
  3115. *
  3116. * @v: pointer of type atomic_t
  3117. * @a: the amount to add to v...
  3118. * @u: ...if (v + a) is less than u.
  3119. *
  3120. * returns true if (v + a) was less than u, and false otherwise.
  3121. *
  3122. */
  3123. static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
  3124. {
  3125. int c, old;
  3126. c = atomic_read(v);
  3127. for (;;) {
  3128. if (unlikely(c + a >= u))
  3129. return false;
  3130. old = atomic_cmpxchg((v), c, c + a);
  3131. if (likely(old == c))
  3132. break;
  3133. c = old;
  3134. }
  3135. return true;
  3136. }
  3137. /**
  3138. * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
  3139. *
  3140. * @v: pointer of type atomic_t
  3141. * @a: the amount to dec from v...
  3142. * @u: ...if (v - a) is more or equal than u.
  3143. *
  3144. * returns true if (v - a) was more or equal than u, and false
  3145. * otherwise.
  3146. */
  3147. static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
  3148. {
  3149. int c, old;
  3150. c = atomic_read(v);
  3151. for (;;) {
  3152. if (unlikely(c - a < u))
  3153. return false;
  3154. old = atomic_cmpxchg((v), c, c - a);
  3155. if (likely(old == c))
  3156. break;
  3157. c = old;
  3158. }
  3159. return true;
  3160. }
  3161. static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
  3162. {
  3163. bool rc;
  3164. smp_mb();
  3165. rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
  3166. smp_mb();
  3167. return rc;
  3168. }
  3169. static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
  3170. {
  3171. bool rc;
  3172. smp_mb();
  3173. /* Don't let to refill if credit + cnt > pool_sz */
  3174. rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
  3175. smp_mb();
  3176. return rc;
  3177. }
  3178. static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
  3179. {
  3180. int cur_credit;
  3181. smp_mb();
  3182. cur_credit = atomic_read(&o->credit);
  3183. return cur_credit;
  3184. }
  3185. static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
  3186. int cnt)
  3187. {
  3188. return true;
  3189. }
  3190. static bool bnx2x_credit_pool_get_entry(
  3191. struct bnx2x_credit_pool_obj *o,
  3192. int *offset)
  3193. {
  3194. int idx, vec, i;
  3195. *offset = -1;
  3196. /* Find "internal cam-offset" then add to base for this object... */
  3197. for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
  3198. /* Skip the current vector if there are no free entries in it */
  3199. if (!o->pool_mirror[vec])
  3200. continue;
  3201. /* If we've got here we are going to find a free entry */
  3202. for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
  3203. i < BIT_VEC64_ELEM_SZ; idx++, i++)
  3204. if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
  3205. /* Got one!! */
  3206. BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
  3207. *offset = o->base_pool_offset + idx;
  3208. return true;
  3209. }
  3210. }
  3211. return false;
  3212. }
  3213. static bool bnx2x_credit_pool_put_entry(
  3214. struct bnx2x_credit_pool_obj *o,
  3215. int offset)
  3216. {
  3217. if (offset < o->base_pool_offset)
  3218. return false;
  3219. offset -= o->base_pool_offset;
  3220. if (offset >= o->pool_sz)
  3221. return false;
  3222. /* Return the entry to the pool */
  3223. BIT_VEC64_SET_BIT(o->pool_mirror, offset);
  3224. return true;
  3225. }
  3226. static bool bnx2x_credit_pool_put_entry_always_true(
  3227. struct bnx2x_credit_pool_obj *o,
  3228. int offset)
  3229. {
  3230. return true;
  3231. }
  3232. static bool bnx2x_credit_pool_get_entry_always_true(
  3233. struct bnx2x_credit_pool_obj *o,
  3234. int *offset)
  3235. {
  3236. *offset = -1;
  3237. return true;
  3238. }
  3239. /**
  3240. * bnx2x_init_credit_pool - initialize credit pool internals.
  3241. *
  3242. * @p:
  3243. * @base: Base entry in the CAM to use.
  3244. * @credit: pool size.
  3245. *
  3246. * If base is negative no CAM entries handling will be performed.
  3247. * If credit is negative pool operations will always succeed (unlimited pool).
  3248. *
  3249. */
  3250. static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
  3251. int base, int credit)
  3252. {
  3253. /* Zero the object first */
  3254. memset(p, 0, sizeof(*p));
  3255. /* Set the table to all 1s */
  3256. memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
  3257. /* Init a pool as full */
  3258. atomic_set(&p->credit, credit);
  3259. /* The total poll size */
  3260. p->pool_sz = credit;
  3261. p->base_pool_offset = base;
  3262. /* Commit the change */
  3263. smp_mb();
  3264. p->check = bnx2x_credit_pool_check;
  3265. /* if pool credit is negative - disable the checks */
  3266. if (credit >= 0) {
  3267. p->put = bnx2x_credit_pool_put;
  3268. p->get = bnx2x_credit_pool_get;
  3269. p->put_entry = bnx2x_credit_pool_put_entry;
  3270. p->get_entry = bnx2x_credit_pool_get_entry;
  3271. } else {
  3272. p->put = bnx2x_credit_pool_always_true;
  3273. p->get = bnx2x_credit_pool_always_true;
  3274. p->put_entry = bnx2x_credit_pool_put_entry_always_true;
  3275. p->get_entry = bnx2x_credit_pool_get_entry_always_true;
  3276. }
  3277. /* If base is negative - disable entries handling */
  3278. if (base < 0) {
  3279. p->put_entry = bnx2x_credit_pool_put_entry_always_true;
  3280. p->get_entry = bnx2x_credit_pool_get_entry_always_true;
  3281. }
  3282. }
  3283. void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
  3284. struct bnx2x_credit_pool_obj *p, u8 func_id,
  3285. u8 func_num)
  3286. {
  3287. /* TODO: this will be defined in consts as well... */
  3288. #define BNX2X_CAM_SIZE_EMUL 5
  3289. int cam_sz;
  3290. if (CHIP_IS_E1(bp)) {
  3291. /* In E1, Multicast is saved in cam... */
  3292. if (!CHIP_REV_IS_SLOW(bp))
  3293. cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
  3294. else
  3295. cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
  3296. bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
  3297. } else if (CHIP_IS_E1H(bp)) {
  3298. /* CAM credit is equaly divided between all active functions
  3299. * on the PORT!.
  3300. */
  3301. if ((func_num > 0)) {
  3302. if (!CHIP_REV_IS_SLOW(bp))
  3303. cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
  3304. else
  3305. cam_sz = BNX2X_CAM_SIZE_EMUL;
  3306. bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
  3307. } else {
  3308. /* this should never happen! Block MAC operations. */
  3309. bnx2x_init_credit_pool(p, 0, 0);
  3310. }
  3311. } else {
  3312. /*
  3313. * CAM credit is equaly divided between all active functions
  3314. * on the PATH.
  3315. */
  3316. if ((func_num > 0)) {
  3317. if (!CHIP_REV_IS_SLOW(bp))
  3318. cam_sz = (MAX_MAC_CREDIT_E2 / func_num);
  3319. else
  3320. cam_sz = BNX2X_CAM_SIZE_EMUL;
  3321. /*
  3322. * No need for CAM entries handling for 57712 and
  3323. * newer.
  3324. */
  3325. bnx2x_init_credit_pool(p, -1, cam_sz);
  3326. } else {
  3327. /* this should never happen! Block MAC operations. */
  3328. bnx2x_init_credit_pool(p, 0, 0);
  3329. }
  3330. }
  3331. }
  3332. void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
  3333. struct bnx2x_credit_pool_obj *p,
  3334. u8 func_id,
  3335. u8 func_num)
  3336. {
  3337. if (CHIP_IS_E1x(bp)) {
  3338. /*
  3339. * There is no VLAN credit in HW on 57710 and 57711 only
  3340. * MAC / MAC-VLAN can be set
  3341. */
  3342. bnx2x_init_credit_pool(p, 0, -1);
  3343. } else {
  3344. /*
  3345. * CAM credit is equaly divided between all active functions
  3346. * on the PATH.
  3347. */
  3348. if (func_num > 0) {
  3349. int credit = MAX_VLAN_CREDIT_E2 / func_num;
  3350. bnx2x_init_credit_pool(p, func_id * credit, credit);
  3351. } else
  3352. /* this should never happen! Block VLAN operations. */
  3353. bnx2x_init_credit_pool(p, 0, 0);
  3354. }
  3355. }
  3356. /****************** RSS Configuration ******************/
  3357. /**
  3358. * bnx2x_debug_print_ind_table - prints the indirection table configuration.
  3359. *
  3360. * @bp: driver hanlde
  3361. * @p: pointer to rss configuration
  3362. *
  3363. * Prints it when NETIF_MSG_IFUP debug level is configured.
  3364. */
  3365. static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
  3366. struct bnx2x_config_rss_params *p)
  3367. {
  3368. int i;
  3369. DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
  3370. DP(BNX2X_MSG_SP, "0x0000: ");
  3371. for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
  3372. DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
  3373. /* Print 4 bytes in a line */
  3374. if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
  3375. (((i + 1) & 0x3) == 0)) {
  3376. DP_CONT(BNX2X_MSG_SP, "\n");
  3377. DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
  3378. }
  3379. }
  3380. DP_CONT(BNX2X_MSG_SP, "\n");
  3381. }
  3382. /**
  3383. * bnx2x_setup_rss - configure RSS
  3384. *
  3385. * @bp: device handle
  3386. * @p: rss configuration
  3387. *
  3388. * sends on UPDATE ramrod for that matter.
  3389. */
  3390. static int bnx2x_setup_rss(struct bnx2x *bp,
  3391. struct bnx2x_config_rss_params *p)
  3392. {
  3393. struct bnx2x_rss_config_obj *o = p->rss_obj;
  3394. struct bnx2x_raw_obj *r = &o->raw;
  3395. struct eth_rss_update_ramrod_data *data =
  3396. (struct eth_rss_update_ramrod_data *)(r->rdata);
  3397. u8 rss_mode = 0;
  3398. int rc;
  3399. memset(data, 0, sizeof(*data));
  3400. DP(BNX2X_MSG_SP, "Configuring RSS\n");
  3401. /* Set an echo field */
  3402. data->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
  3403. (r->state << BNX2X_SWCID_SHIFT));
  3404. /* RSS mode */
  3405. if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
  3406. rss_mode = ETH_RSS_MODE_DISABLED;
  3407. else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
  3408. rss_mode = ETH_RSS_MODE_REGULAR;
  3409. data->rss_mode = rss_mode;
  3410. DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
  3411. /* RSS capabilities */
  3412. if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
  3413. data->capabilities |=
  3414. ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
  3415. if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
  3416. data->capabilities |=
  3417. ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
  3418. if (test_bit(BNX2X_RSS_IPV4_UDP, &p->rss_flags))
  3419. data->capabilities |=
  3420. ETH_RSS_UPDATE_RAMROD_DATA_IPV4_UDP_CAPABILITY;
  3421. if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
  3422. data->capabilities |=
  3423. ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
  3424. if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
  3425. data->capabilities |=
  3426. ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
  3427. if (test_bit(BNX2X_RSS_IPV6_UDP, &p->rss_flags))
  3428. data->capabilities |=
  3429. ETH_RSS_UPDATE_RAMROD_DATA_IPV6_UDP_CAPABILITY;
  3430. /* Hashing mask */
  3431. data->rss_result_mask = p->rss_result_mask;
  3432. /* RSS engine ID */
  3433. data->rss_engine_id = o->engine_id;
  3434. DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
  3435. /* Indirection table */
  3436. memcpy(data->indirection_table, p->ind_table,
  3437. T_ETH_INDIRECTION_TABLE_SIZE);
  3438. /* Remember the last configuration */
  3439. memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
  3440. /* Print the indirection table */
  3441. if (netif_msg_ifup(bp))
  3442. bnx2x_debug_print_ind_table(bp, p);
  3443. /* RSS keys */
  3444. if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
  3445. memcpy(&data->rss_key[0], &p->rss_key[0],
  3446. sizeof(data->rss_key));
  3447. data->capabilities |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
  3448. }
  3449. /*
  3450. * No need for an explicit memory barrier here as long we would
  3451. * need to ensure the ordering of writing to the SPQ element
  3452. * and updating of the SPQ producer which involves a memory
  3453. * read and we will have to put a full memory barrier there
  3454. * (inside bnx2x_sp_post()).
  3455. */
  3456. /* Send a ramrod */
  3457. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
  3458. U64_HI(r->rdata_mapping),
  3459. U64_LO(r->rdata_mapping),
  3460. ETH_CONNECTION_TYPE);
  3461. if (rc < 0)
  3462. return rc;
  3463. return 1;
  3464. }
  3465. void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
  3466. u8 *ind_table)
  3467. {
  3468. memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
  3469. }
  3470. int bnx2x_config_rss(struct bnx2x *bp,
  3471. struct bnx2x_config_rss_params *p)
  3472. {
  3473. int rc;
  3474. struct bnx2x_rss_config_obj *o = p->rss_obj;
  3475. struct bnx2x_raw_obj *r = &o->raw;
  3476. /* Do nothing if only driver cleanup was requested */
  3477. if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags))
  3478. return 0;
  3479. r->set_pending(r);
  3480. rc = o->config_rss(bp, p);
  3481. if (rc < 0) {
  3482. r->clear_pending(r);
  3483. return rc;
  3484. }
  3485. if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
  3486. rc = r->wait_comp(bp, r);
  3487. return rc;
  3488. }
  3489. void bnx2x_init_rss_config_obj(struct bnx2x *bp,
  3490. struct bnx2x_rss_config_obj *rss_obj,
  3491. u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
  3492. void *rdata, dma_addr_t rdata_mapping,
  3493. int state, unsigned long *pstate,
  3494. bnx2x_obj_type type)
  3495. {
  3496. bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
  3497. rdata_mapping, state, pstate, type);
  3498. rss_obj->engine_id = engine_id;
  3499. rss_obj->config_rss = bnx2x_setup_rss;
  3500. }
  3501. /********************** Queue state object ***********************************/
  3502. /**
  3503. * bnx2x_queue_state_change - perform Queue state change transition
  3504. *
  3505. * @bp: device handle
  3506. * @params: parameters to perform the transition
  3507. *
  3508. * returns 0 in case of successfully completed transition, negative error
  3509. * code in case of failure, positive (EBUSY) value if there is a completion
  3510. * to that is still pending (possible only if RAMROD_COMP_WAIT is
  3511. * not set in params->ramrod_flags for asynchronous commands).
  3512. *
  3513. */
  3514. int bnx2x_queue_state_change(struct bnx2x *bp,
  3515. struct bnx2x_queue_state_params *params)
  3516. {
  3517. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3518. int rc, pending_bit;
  3519. unsigned long *pending = &o->pending;
  3520. /* Check that the requested transition is legal */
  3521. rc = o->check_transition(bp, o, params);
  3522. if (rc) {
  3523. BNX2X_ERR("check transition returned an error. rc %d\n", rc);
  3524. return -EINVAL;
  3525. }
  3526. /* Set "pending" bit */
  3527. DP(BNX2X_MSG_SP, "pending bit was=%lx\n", o->pending);
  3528. pending_bit = o->set_pending(o, params);
  3529. DP(BNX2X_MSG_SP, "pending bit now=%lx\n", o->pending);
  3530. /* Don't send a command if only driver cleanup was requested */
  3531. if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags))
  3532. o->complete_cmd(bp, o, pending_bit);
  3533. else {
  3534. /* Send a ramrod */
  3535. rc = o->send_cmd(bp, params);
  3536. if (rc) {
  3537. o->next_state = BNX2X_Q_STATE_MAX;
  3538. clear_bit(pending_bit, pending);
  3539. smp_mb__after_clear_bit();
  3540. return rc;
  3541. }
  3542. if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
  3543. rc = o->wait_comp(bp, o, pending_bit);
  3544. if (rc)
  3545. return rc;
  3546. return 0;
  3547. }
  3548. }
  3549. return !!test_bit(pending_bit, pending);
  3550. }
  3551. static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
  3552. struct bnx2x_queue_state_params *params)
  3553. {
  3554. enum bnx2x_queue_cmd cmd = params->cmd, bit;
  3555. /* ACTIVATE and DEACTIVATE commands are implemented on top of
  3556. * UPDATE command.
  3557. */
  3558. if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
  3559. (cmd == BNX2X_Q_CMD_DEACTIVATE))
  3560. bit = BNX2X_Q_CMD_UPDATE;
  3561. else
  3562. bit = cmd;
  3563. set_bit(bit, &obj->pending);
  3564. return bit;
  3565. }
  3566. static int bnx2x_queue_wait_comp(struct bnx2x *bp,
  3567. struct bnx2x_queue_sp_obj *o,
  3568. enum bnx2x_queue_cmd cmd)
  3569. {
  3570. return bnx2x_state_wait(bp, cmd, &o->pending);
  3571. }
  3572. /**
  3573. * bnx2x_queue_comp_cmd - complete the state change command.
  3574. *
  3575. * @bp: device handle
  3576. * @o:
  3577. * @cmd:
  3578. *
  3579. * Checks that the arrived completion is expected.
  3580. */
  3581. static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
  3582. struct bnx2x_queue_sp_obj *o,
  3583. enum bnx2x_queue_cmd cmd)
  3584. {
  3585. unsigned long cur_pending = o->pending;
  3586. if (!test_and_clear_bit(cmd, &cur_pending)) {
  3587. BNX2X_ERR("Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
  3588. cmd, o->cids[BNX2X_PRIMARY_CID_INDEX],
  3589. o->state, cur_pending, o->next_state);
  3590. return -EINVAL;
  3591. }
  3592. if (o->next_tx_only >= o->max_cos)
  3593. /* >= becuase tx only must always be smaller than cos since the
  3594. * primary connection supports COS 0
  3595. */
  3596. BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
  3597. o->next_tx_only, o->max_cos);
  3598. DP(BNX2X_MSG_SP,
  3599. "Completing command %d for queue %d, setting state to %d\n",
  3600. cmd, o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
  3601. if (o->next_tx_only) /* print num tx-only if any exist */
  3602. DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
  3603. o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
  3604. o->state = o->next_state;
  3605. o->num_tx_only = o->next_tx_only;
  3606. o->next_state = BNX2X_Q_STATE_MAX;
  3607. /* It's important that o->state and o->next_state are
  3608. * updated before o->pending.
  3609. */
  3610. wmb();
  3611. clear_bit(cmd, &o->pending);
  3612. smp_mb__after_clear_bit();
  3613. return 0;
  3614. }
  3615. static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
  3616. struct bnx2x_queue_state_params *cmd_params,
  3617. struct client_init_ramrod_data *data)
  3618. {
  3619. struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
  3620. /* Rx data */
  3621. /* IPv6 TPA supported for E2 and above only */
  3622. data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA_IPV6, &params->flags) *
  3623. CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
  3624. }
  3625. static void bnx2x_q_fill_init_general_data(struct bnx2x *bp,
  3626. struct bnx2x_queue_sp_obj *o,
  3627. struct bnx2x_general_setup_params *params,
  3628. struct client_init_general_data *gen_data,
  3629. unsigned long *flags)
  3630. {
  3631. gen_data->client_id = o->cl_id;
  3632. if (test_bit(BNX2X_Q_FLG_STATS, flags)) {
  3633. gen_data->statistics_counter_id =
  3634. params->stat_id;
  3635. gen_data->statistics_en_flg = 1;
  3636. gen_data->statistics_zero_flg =
  3637. test_bit(BNX2X_Q_FLG_ZERO_STATS, flags);
  3638. } else
  3639. gen_data->statistics_counter_id =
  3640. DISABLE_STATISTIC_COUNTER_ID_VALUE;
  3641. gen_data->is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, flags);
  3642. gen_data->activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE, flags);
  3643. gen_data->sp_client_id = params->spcl_id;
  3644. gen_data->mtu = cpu_to_le16(params->mtu);
  3645. gen_data->func_id = o->func_id;
  3646. gen_data->cos = params->cos;
  3647. gen_data->traffic_type =
  3648. test_bit(BNX2X_Q_FLG_FCOE, flags) ?
  3649. LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
  3650. DP(BNX2X_MSG_SP, "flags: active %d, cos %d, stats en %d\n",
  3651. gen_data->activate_flg, gen_data->cos, gen_data->statistics_en_flg);
  3652. }
  3653. static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj *o,
  3654. struct bnx2x_txq_setup_params *params,
  3655. struct client_init_tx_data *tx_data,
  3656. unsigned long *flags)
  3657. {
  3658. tx_data->enforce_security_flg =
  3659. test_bit(BNX2X_Q_FLG_TX_SEC, flags);
  3660. tx_data->default_vlan =
  3661. cpu_to_le16(params->default_vlan);
  3662. tx_data->default_vlan_flg =
  3663. test_bit(BNX2X_Q_FLG_DEF_VLAN, flags);
  3664. tx_data->tx_switching_flg =
  3665. test_bit(BNX2X_Q_FLG_TX_SWITCH, flags);
  3666. tx_data->anti_spoofing_flg =
  3667. test_bit(BNX2X_Q_FLG_ANTI_SPOOF, flags);
  3668. tx_data->force_default_pri_flg =
  3669. test_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, flags);
  3670. tx_data->tx_status_block_id = params->fw_sb_id;
  3671. tx_data->tx_sb_index_number = params->sb_cq_index;
  3672. tx_data->tss_leading_client_id = params->tss_leading_cl_id;
  3673. tx_data->tx_bd_page_base.lo =
  3674. cpu_to_le32(U64_LO(params->dscr_map));
  3675. tx_data->tx_bd_page_base.hi =
  3676. cpu_to_le32(U64_HI(params->dscr_map));
  3677. /* Don't configure any Tx switching mode during queue SETUP */
  3678. tx_data->state = 0;
  3679. }
  3680. static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj *o,
  3681. struct rxq_pause_params *params,
  3682. struct client_init_rx_data *rx_data)
  3683. {
  3684. /* flow control data */
  3685. rx_data->cqe_pause_thr_low = cpu_to_le16(params->rcq_th_lo);
  3686. rx_data->cqe_pause_thr_high = cpu_to_le16(params->rcq_th_hi);
  3687. rx_data->bd_pause_thr_low = cpu_to_le16(params->bd_th_lo);
  3688. rx_data->bd_pause_thr_high = cpu_to_le16(params->bd_th_hi);
  3689. rx_data->sge_pause_thr_low = cpu_to_le16(params->sge_th_lo);
  3690. rx_data->sge_pause_thr_high = cpu_to_le16(params->sge_th_hi);
  3691. rx_data->rx_cos_mask = cpu_to_le16(params->pri_map);
  3692. }
  3693. static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj *o,
  3694. struct bnx2x_rxq_setup_params *params,
  3695. struct client_init_rx_data *rx_data,
  3696. unsigned long *flags)
  3697. {
  3698. rx_data->tpa_en = test_bit(BNX2X_Q_FLG_TPA, flags) *
  3699. CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
  3700. rx_data->tpa_en |= test_bit(BNX2X_Q_FLG_TPA_GRO, flags) *
  3701. CLIENT_INIT_RX_DATA_TPA_MODE;
  3702. rx_data->vmqueue_mode_en_flg = 0;
  3703. rx_data->cache_line_alignment_log_size =
  3704. params->cache_line_log;
  3705. rx_data->enable_dynamic_hc =
  3706. test_bit(BNX2X_Q_FLG_DHC, flags);
  3707. rx_data->max_sges_for_packet = params->max_sges_pkt;
  3708. rx_data->client_qzone_id = params->cl_qzone_id;
  3709. rx_data->max_agg_size = cpu_to_le16(params->tpa_agg_sz);
  3710. /* Always start in DROP_ALL mode */
  3711. rx_data->state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
  3712. CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
  3713. /* We don't set drop flags */
  3714. rx_data->drop_ip_cs_err_flg = 0;
  3715. rx_data->drop_tcp_cs_err_flg = 0;
  3716. rx_data->drop_ttl0_flg = 0;
  3717. rx_data->drop_udp_cs_err_flg = 0;
  3718. rx_data->inner_vlan_removal_enable_flg =
  3719. test_bit(BNX2X_Q_FLG_VLAN, flags);
  3720. rx_data->outer_vlan_removal_enable_flg =
  3721. test_bit(BNX2X_Q_FLG_OV, flags);
  3722. rx_data->status_block_id = params->fw_sb_id;
  3723. rx_data->rx_sb_index_number = params->sb_cq_index;
  3724. rx_data->max_tpa_queues = params->max_tpa_queues;
  3725. rx_data->max_bytes_on_bd = cpu_to_le16(params->buf_sz);
  3726. rx_data->sge_buff_size = cpu_to_le16(params->sge_buf_sz);
  3727. rx_data->bd_page_base.lo =
  3728. cpu_to_le32(U64_LO(params->dscr_map));
  3729. rx_data->bd_page_base.hi =
  3730. cpu_to_le32(U64_HI(params->dscr_map));
  3731. rx_data->sge_page_base.lo =
  3732. cpu_to_le32(U64_LO(params->sge_map));
  3733. rx_data->sge_page_base.hi =
  3734. cpu_to_le32(U64_HI(params->sge_map));
  3735. rx_data->cqe_page_base.lo =
  3736. cpu_to_le32(U64_LO(params->rcq_map));
  3737. rx_data->cqe_page_base.hi =
  3738. cpu_to_le32(U64_HI(params->rcq_map));
  3739. rx_data->is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS, flags);
  3740. if (test_bit(BNX2X_Q_FLG_MCAST, flags)) {
  3741. rx_data->approx_mcast_engine_id = params->mcast_engine_id;
  3742. rx_data->is_approx_mcast = 1;
  3743. }
  3744. rx_data->rss_engine_id = params->rss_engine_id;
  3745. /* silent vlan removal */
  3746. rx_data->silent_vlan_removal_flg =
  3747. test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, flags);
  3748. rx_data->silent_vlan_value =
  3749. cpu_to_le16(params->silent_removal_value);
  3750. rx_data->silent_vlan_mask =
  3751. cpu_to_le16(params->silent_removal_mask);
  3752. }
  3753. /* initialize the general, tx and rx parts of a queue object */
  3754. static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
  3755. struct bnx2x_queue_state_params *cmd_params,
  3756. struct client_init_ramrod_data *data)
  3757. {
  3758. bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
  3759. &cmd_params->params.setup.gen_params,
  3760. &data->general,
  3761. &cmd_params->params.setup.flags);
  3762. bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
  3763. &cmd_params->params.setup.txq_params,
  3764. &data->tx,
  3765. &cmd_params->params.setup.flags);
  3766. bnx2x_q_fill_init_rx_data(cmd_params->q_obj,
  3767. &cmd_params->params.setup.rxq_params,
  3768. &data->rx,
  3769. &cmd_params->params.setup.flags);
  3770. bnx2x_q_fill_init_pause_data(cmd_params->q_obj,
  3771. &cmd_params->params.setup.pause_params,
  3772. &data->rx);
  3773. }
  3774. /* initialize the general and tx parts of a tx-only queue object */
  3775. static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
  3776. struct bnx2x_queue_state_params *cmd_params,
  3777. struct tx_queue_init_ramrod_data *data)
  3778. {
  3779. bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
  3780. &cmd_params->params.tx_only.gen_params,
  3781. &data->general,
  3782. &cmd_params->params.tx_only.flags);
  3783. bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
  3784. &cmd_params->params.tx_only.txq_params,
  3785. &data->tx,
  3786. &cmd_params->params.tx_only.flags);
  3787. DP(BNX2X_MSG_SP, "cid %d, tx bd page lo %x hi %x",
  3788. cmd_params->q_obj->cids[0],
  3789. data->tx.tx_bd_page_base.lo,
  3790. data->tx.tx_bd_page_base.hi);
  3791. }
  3792. /**
  3793. * bnx2x_q_init - init HW/FW queue
  3794. *
  3795. * @bp: device handle
  3796. * @params:
  3797. *
  3798. * HW/FW initial Queue configuration:
  3799. * - HC: Rx and Tx
  3800. * - CDU context validation
  3801. *
  3802. */
  3803. static inline int bnx2x_q_init(struct bnx2x *bp,
  3804. struct bnx2x_queue_state_params *params)
  3805. {
  3806. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3807. struct bnx2x_queue_init_params *init = &params->params.init;
  3808. u16 hc_usec;
  3809. u8 cos;
  3810. /* Tx HC configuration */
  3811. if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
  3812. test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
  3813. hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
  3814. bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
  3815. init->tx.sb_cq_index,
  3816. !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
  3817. hc_usec);
  3818. }
  3819. /* Rx HC configuration */
  3820. if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
  3821. test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
  3822. hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
  3823. bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
  3824. init->rx.sb_cq_index,
  3825. !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
  3826. hc_usec);
  3827. }
  3828. /* Set CDU context validation values */
  3829. for (cos = 0; cos < o->max_cos; cos++) {
  3830. DP(BNX2X_MSG_SP, "setting context validation. cid %d, cos %d\n",
  3831. o->cids[cos], cos);
  3832. DP(BNX2X_MSG_SP, "context pointer %p\n", init->cxts[cos]);
  3833. bnx2x_set_ctx_validation(bp, init->cxts[cos], o->cids[cos]);
  3834. }
  3835. /* As no ramrod is sent, complete the command immediately */
  3836. o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
  3837. mmiowb();
  3838. smp_mb();
  3839. return 0;
  3840. }
  3841. static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
  3842. struct bnx2x_queue_state_params *params)
  3843. {
  3844. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3845. struct client_init_ramrod_data *rdata =
  3846. (struct client_init_ramrod_data *)o->rdata;
  3847. dma_addr_t data_mapping = o->rdata_mapping;
  3848. int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
  3849. /* Clear the ramrod data */
  3850. memset(rdata, 0, sizeof(*rdata));
  3851. /* Fill the ramrod data */
  3852. bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
  3853. /*
  3854. * No need for an explicit memory barrier here as long we would
  3855. * need to ensure the ordering of writing to the SPQ element
  3856. * and updating of the SPQ producer which involves a memory
  3857. * read and we will have to put a full memory barrier there
  3858. * (inside bnx2x_sp_post()).
  3859. */
  3860. return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
  3861. U64_HI(data_mapping),
  3862. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  3863. }
  3864. static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
  3865. struct bnx2x_queue_state_params *params)
  3866. {
  3867. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3868. struct client_init_ramrod_data *rdata =
  3869. (struct client_init_ramrod_data *)o->rdata;
  3870. dma_addr_t data_mapping = o->rdata_mapping;
  3871. int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
  3872. /* Clear the ramrod data */
  3873. memset(rdata, 0, sizeof(*rdata));
  3874. /* Fill the ramrod data */
  3875. bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
  3876. bnx2x_q_fill_setup_data_e2(bp, params, rdata);
  3877. /*
  3878. * No need for an explicit memory barrier here as long we would
  3879. * need to ensure the ordering of writing to the SPQ element
  3880. * and updating of the SPQ producer which involves a memory
  3881. * read and we will have to put a full memory barrier there
  3882. * (inside bnx2x_sp_post()).
  3883. */
  3884. return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
  3885. U64_HI(data_mapping),
  3886. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  3887. }
  3888. static inline int bnx2x_q_send_setup_tx_only(struct bnx2x *bp,
  3889. struct bnx2x_queue_state_params *params)
  3890. {
  3891. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3892. struct tx_queue_init_ramrod_data *rdata =
  3893. (struct tx_queue_init_ramrod_data *)o->rdata;
  3894. dma_addr_t data_mapping = o->rdata_mapping;
  3895. int ramrod = RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP;
  3896. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  3897. &params->params.tx_only;
  3898. u8 cid_index = tx_only_params->cid_index;
  3899. if (cid_index >= o->max_cos) {
  3900. BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
  3901. o->cl_id, cid_index);
  3902. return -EINVAL;
  3903. }
  3904. DP(BNX2X_MSG_SP, "parameters received: cos: %d sp-id: %d\n",
  3905. tx_only_params->gen_params.cos,
  3906. tx_only_params->gen_params.spcl_id);
  3907. /* Clear the ramrod data */
  3908. memset(rdata, 0, sizeof(*rdata));
  3909. /* Fill the ramrod data */
  3910. bnx2x_q_fill_setup_tx_only(bp, params, rdata);
  3911. DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
  3912. o->cids[cid_index], rdata->general.client_id,
  3913. rdata->general.sp_client_id, rdata->general.cos);
  3914. /*
  3915. * No need for an explicit memory barrier here as long we would
  3916. * need to ensure the ordering of writing to the SPQ element
  3917. * and updating of the SPQ producer which involves a memory
  3918. * read and we will have to put a full memory barrier there
  3919. * (inside bnx2x_sp_post()).
  3920. */
  3921. return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
  3922. U64_HI(data_mapping),
  3923. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  3924. }
  3925. static void bnx2x_q_fill_update_data(struct bnx2x *bp,
  3926. struct bnx2x_queue_sp_obj *obj,
  3927. struct bnx2x_queue_update_params *params,
  3928. struct client_update_ramrod_data *data)
  3929. {
  3930. /* Client ID of the client to update */
  3931. data->client_id = obj->cl_id;
  3932. /* Function ID of the client to update */
  3933. data->func_id = obj->func_id;
  3934. /* Default VLAN value */
  3935. data->default_vlan = cpu_to_le16(params->def_vlan);
  3936. /* Inner VLAN stripping */
  3937. data->inner_vlan_removal_enable_flg =
  3938. test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, &params->update_flags);
  3939. data->inner_vlan_removal_change_flg =
  3940. test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
  3941. &params->update_flags);
  3942. /* Outer VLAN sripping */
  3943. data->outer_vlan_removal_enable_flg =
  3944. test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, &params->update_flags);
  3945. data->outer_vlan_removal_change_flg =
  3946. test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
  3947. &params->update_flags);
  3948. /* Drop packets that have source MAC that doesn't belong to this
  3949. * Queue.
  3950. */
  3951. data->anti_spoofing_enable_flg =
  3952. test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, &params->update_flags);
  3953. data->anti_spoofing_change_flg =
  3954. test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, &params->update_flags);
  3955. /* Activate/Deactivate */
  3956. data->activate_flg =
  3957. test_bit(BNX2X_Q_UPDATE_ACTIVATE, &params->update_flags);
  3958. data->activate_change_flg =
  3959. test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &params->update_flags);
  3960. /* Enable default VLAN */
  3961. data->default_vlan_enable_flg =
  3962. test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, &params->update_flags);
  3963. data->default_vlan_change_flg =
  3964. test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
  3965. &params->update_flags);
  3966. /* silent vlan removal */
  3967. data->silent_vlan_change_flg =
  3968. test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3969. &params->update_flags);
  3970. data->silent_vlan_removal_flg =
  3971. test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, &params->update_flags);
  3972. data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
  3973. data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
  3974. }
  3975. static inline int bnx2x_q_send_update(struct bnx2x *bp,
  3976. struct bnx2x_queue_state_params *params)
  3977. {
  3978. struct bnx2x_queue_sp_obj *o = params->q_obj;
  3979. struct client_update_ramrod_data *rdata =
  3980. (struct client_update_ramrod_data *)o->rdata;
  3981. dma_addr_t data_mapping = o->rdata_mapping;
  3982. struct bnx2x_queue_update_params *update_params =
  3983. &params->params.update;
  3984. u8 cid_index = update_params->cid_index;
  3985. if (cid_index >= o->max_cos) {
  3986. BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
  3987. o->cl_id, cid_index);
  3988. return -EINVAL;
  3989. }
  3990. /* Clear the ramrod data */
  3991. memset(rdata, 0, sizeof(*rdata));
  3992. /* Fill the ramrod data */
  3993. bnx2x_q_fill_update_data(bp, o, update_params, rdata);
  3994. /*
  3995. * No need for an explicit memory barrier here as long we would
  3996. * need to ensure the ordering of writing to the SPQ element
  3997. * and updating of the SPQ producer which involves a memory
  3998. * read and we will have to put a full memory barrier there
  3999. * (inside bnx2x_sp_post()).
  4000. */
  4001. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
  4002. o->cids[cid_index], U64_HI(data_mapping),
  4003. U64_LO(data_mapping), ETH_CONNECTION_TYPE);
  4004. }
  4005. /**
  4006. * bnx2x_q_send_deactivate - send DEACTIVATE command
  4007. *
  4008. * @bp: device handle
  4009. * @params:
  4010. *
  4011. * implemented using the UPDATE command.
  4012. */
  4013. static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
  4014. struct bnx2x_queue_state_params *params)
  4015. {
  4016. struct bnx2x_queue_update_params *update = &params->params.update;
  4017. memset(update, 0, sizeof(*update));
  4018. __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
  4019. return bnx2x_q_send_update(bp, params);
  4020. }
  4021. /**
  4022. * bnx2x_q_send_activate - send ACTIVATE command
  4023. *
  4024. * @bp: device handle
  4025. * @params:
  4026. *
  4027. * implemented using the UPDATE command.
  4028. */
  4029. static inline int bnx2x_q_send_activate(struct bnx2x *bp,
  4030. struct bnx2x_queue_state_params *params)
  4031. {
  4032. struct bnx2x_queue_update_params *update = &params->params.update;
  4033. memset(update, 0, sizeof(*update));
  4034. __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
  4035. __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
  4036. return bnx2x_q_send_update(bp, params);
  4037. }
  4038. static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
  4039. struct bnx2x_queue_state_params *params)
  4040. {
  4041. /* TODO: Not implemented yet. */
  4042. return -1;
  4043. }
  4044. static inline int bnx2x_q_send_halt(struct bnx2x *bp,
  4045. struct bnx2x_queue_state_params *params)
  4046. {
  4047. struct bnx2x_queue_sp_obj *o = params->q_obj;
  4048. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT,
  4049. o->cids[BNX2X_PRIMARY_CID_INDEX], 0, o->cl_id,
  4050. ETH_CONNECTION_TYPE);
  4051. }
  4052. static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
  4053. struct bnx2x_queue_state_params *params)
  4054. {
  4055. struct bnx2x_queue_sp_obj *o = params->q_obj;
  4056. u8 cid_idx = params->params.cfc_del.cid_index;
  4057. if (cid_idx >= o->max_cos) {
  4058. BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
  4059. o->cl_id, cid_idx);
  4060. return -EINVAL;
  4061. }
  4062. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL,
  4063. o->cids[cid_idx], 0, 0, NONE_CONNECTION_TYPE);
  4064. }
  4065. static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
  4066. struct bnx2x_queue_state_params *params)
  4067. {
  4068. struct bnx2x_queue_sp_obj *o = params->q_obj;
  4069. u8 cid_index = params->params.terminate.cid_index;
  4070. if (cid_index >= o->max_cos) {
  4071. BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
  4072. o->cl_id, cid_index);
  4073. return -EINVAL;
  4074. }
  4075. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE,
  4076. o->cids[cid_index], 0, 0, ETH_CONNECTION_TYPE);
  4077. }
  4078. static inline int bnx2x_q_send_empty(struct bnx2x *bp,
  4079. struct bnx2x_queue_state_params *params)
  4080. {
  4081. struct bnx2x_queue_sp_obj *o = params->q_obj;
  4082. return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY,
  4083. o->cids[BNX2X_PRIMARY_CID_INDEX], 0, 0,
  4084. ETH_CONNECTION_TYPE);
  4085. }
  4086. static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
  4087. struct bnx2x_queue_state_params *params)
  4088. {
  4089. switch (params->cmd) {
  4090. case BNX2X_Q_CMD_INIT:
  4091. return bnx2x_q_init(bp, params);
  4092. case BNX2X_Q_CMD_SETUP_TX_ONLY:
  4093. return bnx2x_q_send_setup_tx_only(bp, params);
  4094. case BNX2X_Q_CMD_DEACTIVATE:
  4095. return bnx2x_q_send_deactivate(bp, params);
  4096. case BNX2X_Q_CMD_ACTIVATE:
  4097. return bnx2x_q_send_activate(bp, params);
  4098. case BNX2X_Q_CMD_UPDATE:
  4099. return bnx2x_q_send_update(bp, params);
  4100. case BNX2X_Q_CMD_UPDATE_TPA:
  4101. return bnx2x_q_send_update_tpa(bp, params);
  4102. case BNX2X_Q_CMD_HALT:
  4103. return bnx2x_q_send_halt(bp, params);
  4104. case BNX2X_Q_CMD_CFC_DEL:
  4105. return bnx2x_q_send_cfc_del(bp, params);
  4106. case BNX2X_Q_CMD_TERMINATE:
  4107. return bnx2x_q_send_terminate(bp, params);
  4108. case BNX2X_Q_CMD_EMPTY:
  4109. return bnx2x_q_send_empty(bp, params);
  4110. default:
  4111. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  4112. return -EINVAL;
  4113. }
  4114. }
  4115. static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
  4116. struct bnx2x_queue_state_params *params)
  4117. {
  4118. switch (params->cmd) {
  4119. case BNX2X_Q_CMD_SETUP:
  4120. return bnx2x_q_send_setup_e1x(bp, params);
  4121. case BNX2X_Q_CMD_INIT:
  4122. case BNX2X_Q_CMD_SETUP_TX_ONLY:
  4123. case BNX2X_Q_CMD_DEACTIVATE:
  4124. case BNX2X_Q_CMD_ACTIVATE:
  4125. case BNX2X_Q_CMD_UPDATE:
  4126. case BNX2X_Q_CMD_UPDATE_TPA:
  4127. case BNX2X_Q_CMD_HALT:
  4128. case BNX2X_Q_CMD_CFC_DEL:
  4129. case BNX2X_Q_CMD_TERMINATE:
  4130. case BNX2X_Q_CMD_EMPTY:
  4131. return bnx2x_queue_send_cmd_cmn(bp, params);
  4132. default:
  4133. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  4134. return -EINVAL;
  4135. }
  4136. }
  4137. static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
  4138. struct bnx2x_queue_state_params *params)
  4139. {
  4140. switch (params->cmd) {
  4141. case BNX2X_Q_CMD_SETUP:
  4142. return bnx2x_q_send_setup_e2(bp, params);
  4143. case BNX2X_Q_CMD_INIT:
  4144. case BNX2X_Q_CMD_SETUP_TX_ONLY:
  4145. case BNX2X_Q_CMD_DEACTIVATE:
  4146. case BNX2X_Q_CMD_ACTIVATE:
  4147. case BNX2X_Q_CMD_UPDATE:
  4148. case BNX2X_Q_CMD_UPDATE_TPA:
  4149. case BNX2X_Q_CMD_HALT:
  4150. case BNX2X_Q_CMD_CFC_DEL:
  4151. case BNX2X_Q_CMD_TERMINATE:
  4152. case BNX2X_Q_CMD_EMPTY:
  4153. return bnx2x_queue_send_cmd_cmn(bp, params);
  4154. default:
  4155. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  4156. return -EINVAL;
  4157. }
  4158. }
  4159. /**
  4160. * bnx2x_queue_chk_transition - check state machine of a regular Queue
  4161. *
  4162. * @bp: device handle
  4163. * @o:
  4164. * @params:
  4165. *
  4166. * (not Forwarding)
  4167. * It both checks if the requested command is legal in a current
  4168. * state and, if it's legal, sets a `next_state' in the object
  4169. * that will be used in the completion flow to set the `state'
  4170. * of the object.
  4171. *
  4172. * returns 0 if a requested command is a legal transition,
  4173. * -EINVAL otherwise.
  4174. */
  4175. static int bnx2x_queue_chk_transition(struct bnx2x *bp,
  4176. struct bnx2x_queue_sp_obj *o,
  4177. struct bnx2x_queue_state_params *params)
  4178. {
  4179. enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
  4180. enum bnx2x_queue_cmd cmd = params->cmd;
  4181. struct bnx2x_queue_update_params *update_params =
  4182. &params->params.update;
  4183. u8 next_tx_only = o->num_tx_only;
  4184. /*
  4185. * Forget all pending for completion commands if a driver only state
  4186. * transition has been requested.
  4187. */
  4188. if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
  4189. o->pending = 0;
  4190. o->next_state = BNX2X_Q_STATE_MAX;
  4191. }
  4192. /*
  4193. * Don't allow a next state transition if we are in the middle of
  4194. * the previous one.
  4195. */
  4196. if (o->pending) {
  4197. BNX2X_ERR("Blocking transition since pending was %lx\n",
  4198. o->pending);
  4199. return -EBUSY;
  4200. }
  4201. switch (state) {
  4202. case BNX2X_Q_STATE_RESET:
  4203. if (cmd == BNX2X_Q_CMD_INIT)
  4204. next_state = BNX2X_Q_STATE_INITIALIZED;
  4205. break;
  4206. case BNX2X_Q_STATE_INITIALIZED:
  4207. if (cmd == BNX2X_Q_CMD_SETUP) {
  4208. if (test_bit(BNX2X_Q_FLG_ACTIVE,
  4209. &params->params.setup.flags))
  4210. next_state = BNX2X_Q_STATE_ACTIVE;
  4211. else
  4212. next_state = BNX2X_Q_STATE_INACTIVE;
  4213. }
  4214. break;
  4215. case BNX2X_Q_STATE_ACTIVE:
  4216. if (cmd == BNX2X_Q_CMD_DEACTIVATE)
  4217. next_state = BNX2X_Q_STATE_INACTIVE;
  4218. else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
  4219. (cmd == BNX2X_Q_CMD_UPDATE_TPA))
  4220. next_state = BNX2X_Q_STATE_ACTIVE;
  4221. else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
  4222. next_state = BNX2X_Q_STATE_MULTI_COS;
  4223. next_tx_only = 1;
  4224. }
  4225. else if (cmd == BNX2X_Q_CMD_HALT)
  4226. next_state = BNX2X_Q_STATE_STOPPED;
  4227. else if (cmd == BNX2X_Q_CMD_UPDATE) {
  4228. /* If "active" state change is requested, update the
  4229. * state accordingly.
  4230. */
  4231. if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
  4232. &update_params->update_flags) &&
  4233. !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
  4234. &update_params->update_flags))
  4235. next_state = BNX2X_Q_STATE_INACTIVE;
  4236. else
  4237. next_state = BNX2X_Q_STATE_ACTIVE;
  4238. }
  4239. break;
  4240. case BNX2X_Q_STATE_MULTI_COS:
  4241. if (cmd == BNX2X_Q_CMD_TERMINATE)
  4242. next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
  4243. else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
  4244. next_state = BNX2X_Q_STATE_MULTI_COS;
  4245. next_tx_only = o->num_tx_only + 1;
  4246. }
  4247. else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
  4248. (cmd == BNX2X_Q_CMD_UPDATE_TPA))
  4249. next_state = BNX2X_Q_STATE_MULTI_COS;
  4250. else if (cmd == BNX2X_Q_CMD_UPDATE) {
  4251. /* If "active" state change is requested, update the
  4252. * state accordingly.
  4253. */
  4254. if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
  4255. &update_params->update_flags) &&
  4256. !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
  4257. &update_params->update_flags))
  4258. next_state = BNX2X_Q_STATE_INACTIVE;
  4259. else
  4260. next_state = BNX2X_Q_STATE_MULTI_COS;
  4261. }
  4262. break;
  4263. case BNX2X_Q_STATE_MCOS_TERMINATED:
  4264. if (cmd == BNX2X_Q_CMD_CFC_DEL) {
  4265. next_tx_only = o->num_tx_only - 1;
  4266. if (next_tx_only == 0)
  4267. next_state = BNX2X_Q_STATE_ACTIVE;
  4268. else
  4269. next_state = BNX2X_Q_STATE_MULTI_COS;
  4270. }
  4271. break;
  4272. case BNX2X_Q_STATE_INACTIVE:
  4273. if (cmd == BNX2X_Q_CMD_ACTIVATE)
  4274. next_state = BNX2X_Q_STATE_ACTIVE;
  4275. else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
  4276. (cmd == BNX2X_Q_CMD_UPDATE_TPA))
  4277. next_state = BNX2X_Q_STATE_INACTIVE;
  4278. else if (cmd == BNX2X_Q_CMD_HALT)
  4279. next_state = BNX2X_Q_STATE_STOPPED;
  4280. else if (cmd == BNX2X_Q_CMD_UPDATE) {
  4281. /* If "active" state change is requested, update the
  4282. * state accordingly.
  4283. */
  4284. if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
  4285. &update_params->update_flags) &&
  4286. test_bit(BNX2X_Q_UPDATE_ACTIVATE,
  4287. &update_params->update_flags)){
  4288. if (o->num_tx_only == 0)
  4289. next_state = BNX2X_Q_STATE_ACTIVE;
  4290. else /* tx only queues exist for this queue */
  4291. next_state = BNX2X_Q_STATE_MULTI_COS;
  4292. } else
  4293. next_state = BNX2X_Q_STATE_INACTIVE;
  4294. }
  4295. break;
  4296. case BNX2X_Q_STATE_STOPPED:
  4297. if (cmd == BNX2X_Q_CMD_TERMINATE)
  4298. next_state = BNX2X_Q_STATE_TERMINATED;
  4299. break;
  4300. case BNX2X_Q_STATE_TERMINATED:
  4301. if (cmd == BNX2X_Q_CMD_CFC_DEL)
  4302. next_state = BNX2X_Q_STATE_RESET;
  4303. break;
  4304. default:
  4305. BNX2X_ERR("Illegal state: %d\n", state);
  4306. }
  4307. /* Transition is assured */
  4308. if (next_state != BNX2X_Q_STATE_MAX) {
  4309. DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
  4310. state, cmd, next_state);
  4311. o->next_state = next_state;
  4312. o->next_tx_only = next_tx_only;
  4313. return 0;
  4314. }
  4315. DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
  4316. return -EINVAL;
  4317. }
  4318. void bnx2x_init_queue_obj(struct bnx2x *bp,
  4319. struct bnx2x_queue_sp_obj *obj,
  4320. u8 cl_id, u32 *cids, u8 cid_cnt, u8 func_id,
  4321. void *rdata,
  4322. dma_addr_t rdata_mapping, unsigned long type)
  4323. {
  4324. memset(obj, 0, sizeof(*obj));
  4325. /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
  4326. BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
  4327. memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
  4328. obj->max_cos = cid_cnt;
  4329. obj->cl_id = cl_id;
  4330. obj->func_id = func_id;
  4331. obj->rdata = rdata;
  4332. obj->rdata_mapping = rdata_mapping;
  4333. obj->type = type;
  4334. obj->next_state = BNX2X_Q_STATE_MAX;
  4335. if (CHIP_IS_E1x(bp))
  4336. obj->send_cmd = bnx2x_queue_send_cmd_e1x;
  4337. else
  4338. obj->send_cmd = bnx2x_queue_send_cmd_e2;
  4339. obj->check_transition = bnx2x_queue_chk_transition;
  4340. obj->complete_cmd = bnx2x_queue_comp_cmd;
  4341. obj->wait_comp = bnx2x_queue_wait_comp;
  4342. obj->set_pending = bnx2x_queue_set_pending;
  4343. }
  4344. /* return a queue object's logical state*/
  4345. int bnx2x_get_q_logical_state(struct bnx2x *bp,
  4346. struct bnx2x_queue_sp_obj *obj)
  4347. {
  4348. switch (obj->state) {
  4349. case BNX2X_Q_STATE_ACTIVE:
  4350. case BNX2X_Q_STATE_MULTI_COS:
  4351. return BNX2X_Q_LOGICAL_STATE_ACTIVE;
  4352. case BNX2X_Q_STATE_RESET:
  4353. case BNX2X_Q_STATE_INITIALIZED:
  4354. case BNX2X_Q_STATE_MCOS_TERMINATED:
  4355. case BNX2X_Q_STATE_INACTIVE:
  4356. case BNX2X_Q_STATE_STOPPED:
  4357. case BNX2X_Q_STATE_TERMINATED:
  4358. case BNX2X_Q_STATE_FLRED:
  4359. return BNX2X_Q_LOGICAL_STATE_STOPPED;
  4360. default:
  4361. return -EINVAL;
  4362. }
  4363. }
  4364. /********************** Function state object *********************************/
  4365. enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
  4366. struct bnx2x_func_sp_obj *o)
  4367. {
  4368. /* in the middle of transaction - return INVALID state */
  4369. if (o->pending)
  4370. return BNX2X_F_STATE_MAX;
  4371. /*
  4372. * unsure the order of reading of o->pending and o->state
  4373. * o->pending should be read first
  4374. */
  4375. rmb();
  4376. return o->state;
  4377. }
  4378. static int bnx2x_func_wait_comp(struct bnx2x *bp,
  4379. struct bnx2x_func_sp_obj *o,
  4380. enum bnx2x_func_cmd cmd)
  4381. {
  4382. return bnx2x_state_wait(bp, cmd, &o->pending);
  4383. }
  4384. /**
  4385. * bnx2x_func_state_change_comp - complete the state machine transition
  4386. *
  4387. * @bp: device handle
  4388. * @o:
  4389. * @cmd:
  4390. *
  4391. * Called on state change transition. Completes the state
  4392. * machine transition only - no HW interaction.
  4393. */
  4394. static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
  4395. struct bnx2x_func_sp_obj *o,
  4396. enum bnx2x_func_cmd cmd)
  4397. {
  4398. unsigned long cur_pending = o->pending;
  4399. if (!test_and_clear_bit(cmd, &cur_pending)) {
  4400. BNX2X_ERR("Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
  4401. cmd, BP_FUNC(bp), o->state,
  4402. cur_pending, o->next_state);
  4403. return -EINVAL;
  4404. }
  4405. DP(BNX2X_MSG_SP,
  4406. "Completing command %d for func %d, setting state to %d\n",
  4407. cmd, BP_FUNC(bp), o->next_state);
  4408. o->state = o->next_state;
  4409. o->next_state = BNX2X_F_STATE_MAX;
  4410. /* It's important that o->state and o->next_state are
  4411. * updated before o->pending.
  4412. */
  4413. wmb();
  4414. clear_bit(cmd, &o->pending);
  4415. smp_mb__after_clear_bit();
  4416. return 0;
  4417. }
  4418. /**
  4419. * bnx2x_func_comp_cmd - complete the state change command
  4420. *
  4421. * @bp: device handle
  4422. * @o:
  4423. * @cmd:
  4424. *
  4425. * Checks that the arrived completion is expected.
  4426. */
  4427. static int bnx2x_func_comp_cmd(struct bnx2x *bp,
  4428. struct bnx2x_func_sp_obj *o,
  4429. enum bnx2x_func_cmd cmd)
  4430. {
  4431. /* Complete the state machine part first, check if it's a
  4432. * legal completion.
  4433. */
  4434. int rc = bnx2x_func_state_change_comp(bp, o, cmd);
  4435. return rc;
  4436. }
  4437. /**
  4438. * bnx2x_func_chk_transition - perform function state machine transition
  4439. *
  4440. * @bp: device handle
  4441. * @o:
  4442. * @params:
  4443. *
  4444. * It both checks if the requested command is legal in a current
  4445. * state and, if it's legal, sets a `next_state' in the object
  4446. * that will be used in the completion flow to set the `state'
  4447. * of the object.
  4448. *
  4449. * returns 0 if a requested command is a legal transition,
  4450. * -EINVAL otherwise.
  4451. */
  4452. static int bnx2x_func_chk_transition(struct bnx2x *bp,
  4453. struct bnx2x_func_sp_obj *o,
  4454. struct bnx2x_func_state_params *params)
  4455. {
  4456. enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
  4457. enum bnx2x_func_cmd cmd = params->cmd;
  4458. /*
  4459. * Forget all pending for completion commands if a driver only state
  4460. * transition has been requested.
  4461. */
  4462. if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
  4463. o->pending = 0;
  4464. o->next_state = BNX2X_F_STATE_MAX;
  4465. }
  4466. /*
  4467. * Don't allow a next state transition if we are in the middle of
  4468. * the previous one.
  4469. */
  4470. if (o->pending)
  4471. return -EBUSY;
  4472. switch (state) {
  4473. case BNX2X_F_STATE_RESET:
  4474. if (cmd == BNX2X_F_CMD_HW_INIT)
  4475. next_state = BNX2X_F_STATE_INITIALIZED;
  4476. break;
  4477. case BNX2X_F_STATE_INITIALIZED:
  4478. if (cmd == BNX2X_F_CMD_START)
  4479. next_state = BNX2X_F_STATE_STARTED;
  4480. else if (cmd == BNX2X_F_CMD_HW_RESET)
  4481. next_state = BNX2X_F_STATE_RESET;
  4482. break;
  4483. case BNX2X_F_STATE_STARTED:
  4484. if (cmd == BNX2X_F_CMD_STOP)
  4485. next_state = BNX2X_F_STATE_INITIALIZED;
  4486. /* afex ramrods can be sent only in started mode, and only
  4487. * if not pending for function_stop ramrod completion
  4488. * for these events - next state remained STARTED.
  4489. */
  4490. else if ((cmd == BNX2X_F_CMD_AFEX_UPDATE) &&
  4491. (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
  4492. next_state = BNX2X_F_STATE_STARTED;
  4493. else if ((cmd == BNX2X_F_CMD_AFEX_VIFLISTS) &&
  4494. (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
  4495. next_state = BNX2X_F_STATE_STARTED;
  4496. /* Switch_update ramrod can be sent in either started or
  4497. * tx_stopped state, and it doesn't change the state.
  4498. */
  4499. else if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
  4500. (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
  4501. next_state = BNX2X_F_STATE_STARTED;
  4502. else if (cmd == BNX2X_F_CMD_TX_STOP)
  4503. next_state = BNX2X_F_STATE_TX_STOPPED;
  4504. break;
  4505. case BNX2X_F_STATE_TX_STOPPED:
  4506. if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
  4507. (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
  4508. next_state = BNX2X_F_STATE_TX_STOPPED;
  4509. else if (cmd == BNX2X_F_CMD_TX_START)
  4510. next_state = BNX2X_F_STATE_STARTED;
  4511. break;
  4512. default:
  4513. BNX2X_ERR("Unknown state: %d\n", state);
  4514. }
  4515. /* Transition is assured */
  4516. if (next_state != BNX2X_F_STATE_MAX) {
  4517. DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
  4518. state, cmd, next_state);
  4519. o->next_state = next_state;
  4520. return 0;
  4521. }
  4522. DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
  4523. state, cmd);
  4524. return -EINVAL;
  4525. }
  4526. /**
  4527. * bnx2x_func_init_func - performs HW init at function stage
  4528. *
  4529. * @bp: device handle
  4530. * @drv:
  4531. *
  4532. * Init HW when the current phase is
  4533. * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
  4534. * HW blocks.
  4535. */
  4536. static inline int bnx2x_func_init_func(struct bnx2x *bp,
  4537. const struct bnx2x_func_sp_drv_ops *drv)
  4538. {
  4539. return drv->init_hw_func(bp);
  4540. }
  4541. /**
  4542. * bnx2x_func_init_port - performs HW init at port stage
  4543. *
  4544. * @bp: device handle
  4545. * @drv:
  4546. *
  4547. * Init HW when the current phase is
  4548. * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
  4549. * FUNCTION-only HW blocks.
  4550. *
  4551. */
  4552. static inline int bnx2x_func_init_port(struct bnx2x *bp,
  4553. const struct bnx2x_func_sp_drv_ops *drv)
  4554. {
  4555. int rc = drv->init_hw_port(bp);
  4556. if (rc)
  4557. return rc;
  4558. return bnx2x_func_init_func(bp, drv);
  4559. }
  4560. /**
  4561. * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
  4562. *
  4563. * @bp: device handle
  4564. * @drv:
  4565. *
  4566. * Init HW when the current phase is
  4567. * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
  4568. * PORT-only and FUNCTION-only HW blocks.
  4569. */
  4570. static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
  4571. const struct bnx2x_func_sp_drv_ops *drv)
  4572. {
  4573. int rc = drv->init_hw_cmn_chip(bp);
  4574. if (rc)
  4575. return rc;
  4576. return bnx2x_func_init_port(bp, drv);
  4577. }
  4578. /**
  4579. * bnx2x_func_init_cmn - performs HW init at common stage
  4580. *
  4581. * @bp: device handle
  4582. * @drv:
  4583. *
  4584. * Init HW when the current phase is
  4585. * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
  4586. * PORT-only and FUNCTION-only HW blocks.
  4587. */
  4588. static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
  4589. const struct bnx2x_func_sp_drv_ops *drv)
  4590. {
  4591. int rc = drv->init_hw_cmn(bp);
  4592. if (rc)
  4593. return rc;
  4594. return bnx2x_func_init_port(bp, drv);
  4595. }
  4596. static int bnx2x_func_hw_init(struct bnx2x *bp,
  4597. struct bnx2x_func_state_params *params)
  4598. {
  4599. u32 load_code = params->params.hw_init.load_phase;
  4600. struct bnx2x_func_sp_obj *o = params->f_obj;
  4601. const struct bnx2x_func_sp_drv_ops *drv = o->drv;
  4602. int rc = 0;
  4603. DP(BNX2X_MSG_SP, "function %d load_code %x\n",
  4604. BP_ABS_FUNC(bp), load_code);
  4605. /* Prepare buffers for unzipping the FW */
  4606. rc = drv->gunzip_init(bp);
  4607. if (rc)
  4608. return rc;
  4609. /* Prepare FW */
  4610. rc = drv->init_fw(bp);
  4611. if (rc) {
  4612. BNX2X_ERR("Error loading firmware\n");
  4613. goto init_err;
  4614. }
  4615. /* Handle the beginning of COMMON_XXX pases separatelly... */
  4616. switch (load_code) {
  4617. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4618. rc = bnx2x_func_init_cmn_chip(bp, drv);
  4619. if (rc)
  4620. goto init_err;
  4621. break;
  4622. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4623. rc = bnx2x_func_init_cmn(bp, drv);
  4624. if (rc)
  4625. goto init_err;
  4626. break;
  4627. case FW_MSG_CODE_DRV_LOAD_PORT:
  4628. rc = bnx2x_func_init_port(bp, drv);
  4629. if (rc)
  4630. goto init_err;
  4631. break;
  4632. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4633. rc = bnx2x_func_init_func(bp, drv);
  4634. if (rc)
  4635. goto init_err;
  4636. break;
  4637. default:
  4638. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4639. rc = -EINVAL;
  4640. }
  4641. init_err:
  4642. drv->gunzip_end(bp);
  4643. /* In case of success, complete the comand immediatelly: no ramrods
  4644. * have been sent.
  4645. */
  4646. if (!rc)
  4647. o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
  4648. return rc;
  4649. }
  4650. /**
  4651. * bnx2x_func_reset_func - reset HW at function stage
  4652. *
  4653. * @bp: device handle
  4654. * @drv:
  4655. *
  4656. * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
  4657. * FUNCTION-only HW blocks.
  4658. */
  4659. static inline void bnx2x_func_reset_func(struct bnx2x *bp,
  4660. const struct bnx2x_func_sp_drv_ops *drv)
  4661. {
  4662. drv->reset_hw_func(bp);
  4663. }
  4664. /**
  4665. * bnx2x_func_reset_port - reser HW at port stage
  4666. *
  4667. * @bp: device handle
  4668. * @drv:
  4669. *
  4670. * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
  4671. * FUNCTION-only and PORT-only HW blocks.
  4672. *
  4673. * !!!IMPORTANT!!!
  4674. *
  4675. * It's important to call reset_port before reset_func() as the last thing
  4676. * reset_func does is pf_disable() thus disabling PGLUE_B, which
  4677. * makes impossible any DMAE transactions.
  4678. */
  4679. static inline void bnx2x_func_reset_port(struct bnx2x *bp,
  4680. const struct bnx2x_func_sp_drv_ops *drv)
  4681. {
  4682. drv->reset_hw_port(bp);
  4683. bnx2x_func_reset_func(bp, drv);
  4684. }
  4685. /**
  4686. * bnx2x_func_reset_cmn - reser HW at common stage
  4687. *
  4688. * @bp: device handle
  4689. * @drv:
  4690. *
  4691. * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
  4692. * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
  4693. * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
  4694. */
  4695. static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
  4696. const struct bnx2x_func_sp_drv_ops *drv)
  4697. {
  4698. bnx2x_func_reset_port(bp, drv);
  4699. drv->reset_hw_cmn(bp);
  4700. }
  4701. static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
  4702. struct bnx2x_func_state_params *params)
  4703. {
  4704. u32 reset_phase = params->params.hw_reset.reset_phase;
  4705. struct bnx2x_func_sp_obj *o = params->f_obj;
  4706. const struct bnx2x_func_sp_drv_ops *drv = o->drv;
  4707. DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
  4708. reset_phase);
  4709. switch (reset_phase) {
  4710. case FW_MSG_CODE_DRV_UNLOAD_COMMON:
  4711. bnx2x_func_reset_cmn(bp, drv);
  4712. break;
  4713. case FW_MSG_CODE_DRV_UNLOAD_PORT:
  4714. bnx2x_func_reset_port(bp, drv);
  4715. break;
  4716. case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
  4717. bnx2x_func_reset_func(bp, drv);
  4718. break;
  4719. default:
  4720. BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
  4721. reset_phase);
  4722. break;
  4723. }
  4724. /* Complete the comand immediatelly: no ramrods have been sent. */
  4725. o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
  4726. return 0;
  4727. }
  4728. static inline int bnx2x_func_send_start(struct bnx2x *bp,
  4729. struct bnx2x_func_state_params *params)
  4730. {
  4731. struct bnx2x_func_sp_obj *o = params->f_obj;
  4732. struct function_start_data *rdata =
  4733. (struct function_start_data *)o->rdata;
  4734. dma_addr_t data_mapping = o->rdata_mapping;
  4735. struct bnx2x_func_start_params *start_params = &params->params.start;
  4736. memset(rdata, 0, sizeof(*rdata));
  4737. /* Fill the ramrod data with provided parameters */
  4738. rdata->function_mode = (u8)start_params->mf_mode;
  4739. rdata->sd_vlan_tag = cpu_to_le16(start_params->sd_vlan_tag);
  4740. rdata->path_id = BP_PATH(bp);
  4741. rdata->network_cos_mode = start_params->network_cos_mode;
  4742. /*
  4743. * No need for an explicit memory barrier here as long we would
  4744. * need to ensure the ordering of writing to the SPQ element
  4745. * and updating of the SPQ producer which involves a memory
  4746. * read and we will have to put a full memory barrier there
  4747. * (inside bnx2x_sp_post()).
  4748. */
  4749. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
  4750. U64_HI(data_mapping),
  4751. U64_LO(data_mapping), NONE_CONNECTION_TYPE);
  4752. }
  4753. static inline int bnx2x_func_send_switch_update(struct bnx2x *bp,
  4754. struct bnx2x_func_state_params *params)
  4755. {
  4756. struct bnx2x_func_sp_obj *o = params->f_obj;
  4757. struct function_update_data *rdata =
  4758. (struct function_update_data *)o->rdata;
  4759. dma_addr_t data_mapping = o->rdata_mapping;
  4760. struct bnx2x_func_switch_update_params *switch_update_params =
  4761. &params->params.switch_update;
  4762. memset(rdata, 0, sizeof(*rdata));
  4763. /* Fill the ramrod data with provided parameters */
  4764. rdata->tx_switch_suspend_change_flg = 1;
  4765. rdata->tx_switch_suspend = switch_update_params->suspend;
  4766. rdata->echo = SWITCH_UPDATE;
  4767. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
  4768. U64_HI(data_mapping),
  4769. U64_LO(data_mapping), NONE_CONNECTION_TYPE);
  4770. }
  4771. static inline int bnx2x_func_send_afex_update(struct bnx2x *bp,
  4772. struct bnx2x_func_state_params *params)
  4773. {
  4774. struct bnx2x_func_sp_obj *o = params->f_obj;
  4775. struct function_update_data *rdata =
  4776. (struct function_update_data *)o->afex_rdata;
  4777. dma_addr_t data_mapping = o->afex_rdata_mapping;
  4778. struct bnx2x_func_afex_update_params *afex_update_params =
  4779. &params->params.afex_update;
  4780. memset(rdata, 0, sizeof(*rdata));
  4781. /* Fill the ramrod data with provided parameters */
  4782. rdata->vif_id_change_flg = 1;
  4783. rdata->vif_id = cpu_to_le16(afex_update_params->vif_id);
  4784. rdata->afex_default_vlan_change_flg = 1;
  4785. rdata->afex_default_vlan =
  4786. cpu_to_le16(afex_update_params->afex_default_vlan);
  4787. rdata->allowed_priorities_change_flg = 1;
  4788. rdata->allowed_priorities = afex_update_params->allowed_priorities;
  4789. rdata->echo = AFEX_UPDATE;
  4790. /* No need for an explicit memory barrier here as long we would
  4791. * need to ensure the ordering of writing to the SPQ element
  4792. * and updating of the SPQ producer which involves a memory
  4793. * read and we will have to put a full memory barrier there
  4794. * (inside bnx2x_sp_post()).
  4795. */
  4796. DP(BNX2X_MSG_SP,
  4797. "afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
  4798. rdata->vif_id,
  4799. rdata->afex_default_vlan, rdata->allowed_priorities);
  4800. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
  4801. U64_HI(data_mapping),
  4802. U64_LO(data_mapping), NONE_CONNECTION_TYPE);
  4803. }
  4804. static
  4805. inline int bnx2x_func_send_afex_viflists(struct bnx2x *bp,
  4806. struct bnx2x_func_state_params *params)
  4807. {
  4808. struct bnx2x_func_sp_obj *o = params->f_obj;
  4809. struct afex_vif_list_ramrod_data *rdata =
  4810. (struct afex_vif_list_ramrod_data *)o->afex_rdata;
  4811. struct bnx2x_func_afex_viflists_params *afex_vif_params =
  4812. &params->params.afex_viflists;
  4813. u64 *p_rdata = (u64 *)rdata;
  4814. memset(rdata, 0, sizeof(*rdata));
  4815. /* Fill the ramrod data with provided parameters */
  4816. rdata->vif_list_index = cpu_to_le16(afex_vif_params->vif_list_index);
  4817. rdata->func_bit_map = afex_vif_params->func_bit_map;
  4818. rdata->afex_vif_list_command = afex_vif_params->afex_vif_list_command;
  4819. rdata->func_to_clear = afex_vif_params->func_to_clear;
  4820. /* send in echo type of sub command */
  4821. rdata->echo = afex_vif_params->afex_vif_list_command;
  4822. /* No need for an explicit memory barrier here as long we would
  4823. * need to ensure the ordering of writing to the SPQ element
  4824. * and updating of the SPQ producer which involves a memory
  4825. * read and we will have to put a full memory barrier there
  4826. * (inside bnx2x_sp_post()).
  4827. */
  4828. DP(BNX2X_MSG_SP, "afex: ramrod lists, cmd 0x%x index 0x%x func_bit_map 0x%x func_to_clr 0x%x\n",
  4829. rdata->afex_vif_list_command, rdata->vif_list_index,
  4830. rdata->func_bit_map, rdata->func_to_clear);
  4831. /* this ramrod sends data directly and not through DMA mapping */
  4832. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_AFEX_VIF_LISTS, 0,
  4833. U64_HI(*p_rdata), U64_LO(*p_rdata),
  4834. NONE_CONNECTION_TYPE);
  4835. }
  4836. static inline int bnx2x_func_send_stop(struct bnx2x *bp,
  4837. struct bnx2x_func_state_params *params)
  4838. {
  4839. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
  4840. NONE_CONNECTION_TYPE);
  4841. }
  4842. static inline int bnx2x_func_send_tx_stop(struct bnx2x *bp,
  4843. struct bnx2x_func_state_params *params)
  4844. {
  4845. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC, 0, 0, 0,
  4846. NONE_CONNECTION_TYPE);
  4847. }
  4848. static inline int bnx2x_func_send_tx_start(struct bnx2x *bp,
  4849. struct bnx2x_func_state_params *params)
  4850. {
  4851. struct bnx2x_func_sp_obj *o = params->f_obj;
  4852. struct flow_control_configuration *rdata =
  4853. (struct flow_control_configuration *)o->rdata;
  4854. dma_addr_t data_mapping = o->rdata_mapping;
  4855. struct bnx2x_func_tx_start_params *tx_start_params =
  4856. &params->params.tx_start;
  4857. int i;
  4858. memset(rdata, 0, sizeof(*rdata));
  4859. rdata->dcb_enabled = tx_start_params->dcb_enabled;
  4860. rdata->dcb_version = tx_start_params->dcb_version;
  4861. rdata->dont_add_pri_0_en = tx_start_params->dont_add_pri_0_en;
  4862. for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
  4863. rdata->traffic_type_to_priority_cos[i] =
  4864. tx_start_params->traffic_type_to_priority_cos[i];
  4865. return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
  4866. U64_HI(data_mapping),
  4867. U64_LO(data_mapping), NONE_CONNECTION_TYPE);
  4868. }
  4869. static int bnx2x_func_send_cmd(struct bnx2x *bp,
  4870. struct bnx2x_func_state_params *params)
  4871. {
  4872. switch (params->cmd) {
  4873. case BNX2X_F_CMD_HW_INIT:
  4874. return bnx2x_func_hw_init(bp, params);
  4875. case BNX2X_F_CMD_START:
  4876. return bnx2x_func_send_start(bp, params);
  4877. case BNX2X_F_CMD_STOP:
  4878. return bnx2x_func_send_stop(bp, params);
  4879. case BNX2X_F_CMD_HW_RESET:
  4880. return bnx2x_func_hw_reset(bp, params);
  4881. case BNX2X_F_CMD_AFEX_UPDATE:
  4882. return bnx2x_func_send_afex_update(bp, params);
  4883. case BNX2X_F_CMD_AFEX_VIFLISTS:
  4884. return bnx2x_func_send_afex_viflists(bp, params);
  4885. case BNX2X_F_CMD_TX_STOP:
  4886. return bnx2x_func_send_tx_stop(bp, params);
  4887. case BNX2X_F_CMD_TX_START:
  4888. return bnx2x_func_send_tx_start(bp, params);
  4889. case BNX2X_F_CMD_SWITCH_UPDATE:
  4890. return bnx2x_func_send_switch_update(bp, params);
  4891. default:
  4892. BNX2X_ERR("Unknown command: %d\n", params->cmd);
  4893. return -EINVAL;
  4894. }
  4895. }
  4896. void bnx2x_init_func_obj(struct bnx2x *bp,
  4897. struct bnx2x_func_sp_obj *obj,
  4898. void *rdata, dma_addr_t rdata_mapping,
  4899. void *afex_rdata, dma_addr_t afex_rdata_mapping,
  4900. struct bnx2x_func_sp_drv_ops *drv_iface)
  4901. {
  4902. memset(obj, 0, sizeof(*obj));
  4903. mutex_init(&obj->one_pending_mutex);
  4904. obj->rdata = rdata;
  4905. obj->rdata_mapping = rdata_mapping;
  4906. obj->afex_rdata = afex_rdata;
  4907. obj->afex_rdata_mapping = afex_rdata_mapping;
  4908. obj->send_cmd = bnx2x_func_send_cmd;
  4909. obj->check_transition = bnx2x_func_chk_transition;
  4910. obj->complete_cmd = bnx2x_func_comp_cmd;
  4911. obj->wait_comp = bnx2x_func_wait_comp;
  4912. obj->drv = drv_iface;
  4913. }
  4914. /**
  4915. * bnx2x_func_state_change - perform Function state change transition
  4916. *
  4917. * @bp: device handle
  4918. * @params: parameters to perform the transaction
  4919. *
  4920. * returns 0 in case of successfully completed transition,
  4921. * negative error code in case of failure, positive
  4922. * (EBUSY) value if there is a completion to that is
  4923. * still pending (possible only if RAMROD_COMP_WAIT is
  4924. * not set in params->ramrod_flags for asynchronous
  4925. * commands).
  4926. */
  4927. int bnx2x_func_state_change(struct bnx2x *bp,
  4928. struct bnx2x_func_state_params *params)
  4929. {
  4930. struct bnx2x_func_sp_obj *o = params->f_obj;
  4931. int rc, cnt = 300;
  4932. enum bnx2x_func_cmd cmd = params->cmd;
  4933. unsigned long *pending = &o->pending;
  4934. mutex_lock(&o->one_pending_mutex);
  4935. /* Check that the requested transition is legal */
  4936. rc = o->check_transition(bp, o, params);
  4937. if ((rc == -EBUSY) &&
  4938. (test_bit(RAMROD_RETRY, &params->ramrod_flags))) {
  4939. while ((rc == -EBUSY) && (--cnt > 0)) {
  4940. mutex_unlock(&o->one_pending_mutex);
  4941. msleep(10);
  4942. mutex_lock(&o->one_pending_mutex);
  4943. rc = o->check_transition(bp, o, params);
  4944. }
  4945. if (rc == -EBUSY) {
  4946. mutex_unlock(&o->one_pending_mutex);
  4947. BNX2X_ERR("timeout waiting for previous ramrod completion\n");
  4948. return rc;
  4949. }
  4950. } else if (rc) {
  4951. mutex_unlock(&o->one_pending_mutex);
  4952. return rc;
  4953. }
  4954. /* Set "pending" bit */
  4955. set_bit(cmd, pending);
  4956. /* Don't send a command if only driver cleanup was requested */
  4957. if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
  4958. bnx2x_func_state_change_comp(bp, o, cmd);
  4959. mutex_unlock(&o->one_pending_mutex);
  4960. } else {
  4961. /* Send a ramrod */
  4962. rc = o->send_cmd(bp, params);
  4963. mutex_unlock(&o->one_pending_mutex);
  4964. if (rc) {
  4965. o->next_state = BNX2X_F_STATE_MAX;
  4966. clear_bit(cmd, pending);
  4967. smp_mb__after_clear_bit();
  4968. return rc;
  4969. }
  4970. if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
  4971. rc = o->wait_comp(bp, o, cmd);
  4972. if (rc)
  4973. return rc;
  4974. return 0;
  4975. }
  4976. }
  4977. return !!test_bit(cmd, pending);
  4978. }