bnx2x_sp.c 151 KB

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