bnx2x_sp.c 150 KB

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