bnx2x_sp.c 181 KB

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