bnx2x_sp.c 167 KB

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