bnx2x_sp.c 160 KB

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