bnx2x_sp.c 152 KB

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