bnx2x_sp.c 159 KB

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