bnx2x_sp.c 150 KB

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