bnx2x_sp.c 146 KB

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