bnx2x_sp.c 152 KB

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