bnx2x_sp.c 150 KB

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