bnx2x_sp.c 156 KB

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