bnx2x_sp.c 151 KB

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