bnx2x_sp.c 160 KB

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