bnx2x_sp.c 167 KB

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