bnx2x_sp.c 181 KB

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