bnx2x_sp.c 182 KB

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