bnx2x_sp.c 160 KB

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