bnx2x_sp.c 153 KB

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