bnx2x_sp.c 158 KB

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