ef10.c 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2012-2013 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include "net_driver.h"
  10. #include "ef10_regs.h"
  11. #include "io.h"
  12. #include "mcdi.h"
  13. #include "mcdi_pcol.h"
  14. #include "nic.h"
  15. #include "workarounds.h"
  16. #include "selftest.h"
  17. #include "ef10_sriov.h"
  18. #include <linux/in.h>
  19. #include <linux/jhash.h>
  20. #include <linux/wait.h>
  21. #include <linux/workqueue.h>
  22. /* Hardware control for EF10 architecture including 'Huntington'. */
  23. #define EFX_EF10_DRVGEN_EV 7
  24. enum {
  25. EFX_EF10_TEST = 1,
  26. EFX_EF10_REFILL,
  27. };
  28. /* The reserved RSS context value */
  29. #define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff
  30. /* The maximum size of a shared RSS context */
  31. /* TODO: this should really be from the mcdi protocol export */
  32. #define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL
  33. /* The filter table(s) are managed by firmware and we have write-only
  34. * access. When removing filters we must identify them to the
  35. * firmware by a 64-bit handle, but this is too wide for Linux kernel
  36. * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to
  37. * be able to tell in advance whether a requested insertion will
  38. * replace an existing filter. Therefore we maintain a software hash
  39. * table, which should be at least as large as the hardware hash
  40. * table.
  41. *
  42. * Huntington has a single 8K filter table shared between all filter
  43. * types and both ports.
  44. */
  45. #define HUNT_FILTER_TBL_ROWS 8192
  46. #define EFX_EF10_FILTER_ID_INVALID 0xffff
  47. #define EFX_EF10_FILTER_DEV_UC_MAX 32
  48. #define EFX_EF10_FILTER_DEV_MC_MAX 256
  49. /* VLAN list entry */
  50. struct efx_ef10_vlan {
  51. struct list_head list;
  52. u16 vid;
  53. };
  54. enum efx_ef10_default_filters {
  55. EFX_EF10_BCAST,
  56. EFX_EF10_UCDEF,
  57. EFX_EF10_MCDEF,
  58. EFX_EF10_VXLAN4_UCDEF,
  59. EFX_EF10_VXLAN4_MCDEF,
  60. EFX_EF10_VXLAN6_UCDEF,
  61. EFX_EF10_VXLAN6_MCDEF,
  62. EFX_EF10_NVGRE4_UCDEF,
  63. EFX_EF10_NVGRE4_MCDEF,
  64. EFX_EF10_NVGRE6_UCDEF,
  65. EFX_EF10_NVGRE6_MCDEF,
  66. EFX_EF10_GENEVE4_UCDEF,
  67. EFX_EF10_GENEVE4_MCDEF,
  68. EFX_EF10_GENEVE6_UCDEF,
  69. EFX_EF10_GENEVE6_MCDEF,
  70. EFX_EF10_NUM_DEFAULT_FILTERS
  71. };
  72. /* Per-VLAN filters information */
  73. struct efx_ef10_filter_vlan {
  74. struct list_head list;
  75. u16 vid;
  76. u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
  77. u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
  78. u16 default_filters[EFX_EF10_NUM_DEFAULT_FILTERS];
  79. };
  80. struct efx_ef10_dev_addr {
  81. u8 addr[ETH_ALEN];
  82. };
  83. struct efx_ef10_filter_table {
  84. /* The MCDI match masks supported by this fw & hw, in order of priority */
  85. u32 rx_match_mcdi_flags[
  86. MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2];
  87. unsigned int rx_match_count;
  88. struct {
  89. unsigned long spec; /* pointer to spec plus flag bits */
  90. /* BUSY flag indicates that an update is in progress. AUTO_OLD is
  91. * used to mark and sweep MAC filters for the device address lists.
  92. */
  93. #define EFX_EF10_FILTER_FLAG_BUSY 1UL
  94. #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
  95. #define EFX_EF10_FILTER_FLAGS 3UL
  96. u64 handle; /* firmware handle */
  97. } *entry;
  98. wait_queue_head_t waitq;
  99. /* Shadow of net_device address lists, guarded by mac_lock */
  100. struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
  101. struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
  102. int dev_uc_count;
  103. int dev_mc_count;
  104. bool uc_promisc;
  105. bool mc_promisc;
  106. /* Whether in multicast promiscuous mode when last changed */
  107. bool mc_promisc_last;
  108. bool mc_overflow; /* Too many MC addrs; should always imply mc_promisc */
  109. bool vlan_filter;
  110. struct list_head vlan_list;
  111. };
  112. /* An arbitrary search limit for the software hash table */
  113. #define EFX_EF10_FILTER_SEARCH_LIMIT 200
  114. static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
  115. static void efx_ef10_filter_table_remove(struct efx_nic *efx);
  116. static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
  117. static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
  118. struct efx_ef10_filter_vlan *vlan);
  119. static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
  120. static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading);
  121. static u32 efx_ef10_filter_get_unsafe_id(u32 filter_id)
  122. {
  123. WARN_ON_ONCE(filter_id == EFX_EF10_FILTER_ID_INVALID);
  124. return filter_id & (HUNT_FILTER_TBL_ROWS - 1);
  125. }
  126. static unsigned int efx_ef10_filter_get_unsafe_pri(u32 filter_id)
  127. {
  128. return filter_id / (HUNT_FILTER_TBL_ROWS * 2);
  129. }
  130. static u32 efx_ef10_make_filter_id(unsigned int pri, u16 idx)
  131. {
  132. return pri * HUNT_FILTER_TBL_ROWS * 2 + idx;
  133. }
  134. static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
  135. {
  136. efx_dword_t reg;
  137. efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
  138. return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
  139. EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
  140. }
  141. /* On all EF10s up to and including SFC9220 (Medford1), all PFs use BAR 0 for
  142. * I/O space and BAR 2(&3) for memory. On SFC9250 (Medford2), there is no I/O
  143. * bar; PFs use BAR 0/1 for memory.
  144. */
  145. static unsigned int efx_ef10_pf_mem_bar(struct efx_nic *efx)
  146. {
  147. switch (efx->pci_dev->device) {
  148. case 0x0b03: /* SFC9250 PF */
  149. return 0;
  150. default:
  151. return 2;
  152. }
  153. }
  154. /* All VFs use BAR 0/1 for memory */
  155. static unsigned int efx_ef10_vf_mem_bar(struct efx_nic *efx)
  156. {
  157. return 0;
  158. }
  159. static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
  160. {
  161. int bar;
  162. bar = efx->type->mem_bar(efx);
  163. return resource_size(&efx->pci_dev->resource[bar]);
  164. }
  165. static bool efx_ef10_is_vf(struct efx_nic *efx)
  166. {
  167. return efx->type->is_vf;
  168. }
  169. static int efx_ef10_get_pf_index(struct efx_nic *efx)
  170. {
  171. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
  172. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  173. size_t outlen;
  174. int rc;
  175. rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
  176. sizeof(outbuf), &outlen);
  177. if (rc)
  178. return rc;
  179. if (outlen < sizeof(outbuf))
  180. return -EIO;
  181. nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
  182. return 0;
  183. }
  184. #ifdef CONFIG_SFC_SRIOV
  185. static int efx_ef10_get_vf_index(struct efx_nic *efx)
  186. {
  187. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
  188. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  189. size_t outlen;
  190. int rc;
  191. rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
  192. sizeof(outbuf), &outlen);
  193. if (rc)
  194. return rc;
  195. if (outlen < sizeof(outbuf))
  196. return -EIO;
  197. nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
  198. return 0;
  199. }
  200. #endif
  201. static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
  202. {
  203. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V3_OUT_LEN);
  204. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  205. size_t outlen;
  206. int rc;
  207. BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
  208. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
  209. outbuf, sizeof(outbuf), &outlen);
  210. if (rc)
  211. return rc;
  212. if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
  213. netif_err(efx, drv, efx->net_dev,
  214. "unable to read datapath firmware capabilities\n");
  215. return -EIO;
  216. }
  217. nic_data->datapath_caps =
  218. MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
  219. if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
  220. nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
  221. GET_CAPABILITIES_V2_OUT_FLAGS2);
  222. nic_data->piobuf_size = MCDI_WORD(outbuf,
  223. GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
  224. } else {
  225. nic_data->datapath_caps2 = 0;
  226. nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
  227. }
  228. /* record the DPCPU firmware IDs to determine VEB vswitching support.
  229. */
  230. nic_data->rx_dpcpu_fw_id =
  231. MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
  232. nic_data->tx_dpcpu_fw_id =
  233. MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
  234. if (!(nic_data->datapath_caps &
  235. (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
  236. netif_err(efx, probe, efx->net_dev,
  237. "current firmware does not support an RX prefix\n");
  238. return -ENODEV;
  239. }
  240. if (outlen >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
  241. u8 vi_window_mode = MCDI_BYTE(outbuf,
  242. GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
  243. switch (vi_window_mode) {
  244. case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_8K:
  245. efx->vi_stride = 8192;
  246. break;
  247. case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_16K:
  248. efx->vi_stride = 16384;
  249. break;
  250. case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_64K:
  251. efx->vi_stride = 65536;
  252. break;
  253. default:
  254. netif_err(efx, probe, efx->net_dev,
  255. "Unrecognised VI window mode %d\n",
  256. vi_window_mode);
  257. return -EIO;
  258. }
  259. netif_dbg(efx, probe, efx->net_dev, "vi_stride = %u\n",
  260. efx->vi_stride);
  261. } else {
  262. /* keep default VI stride */
  263. netif_dbg(efx, probe, efx->net_dev,
  264. "firmware did not report VI window mode, assuming vi_stride = %u\n",
  265. efx->vi_stride);
  266. }
  267. return 0;
  268. }
  269. static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
  270. {
  271. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
  272. int rc;
  273. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
  274. outbuf, sizeof(outbuf), NULL);
  275. if (rc)
  276. return rc;
  277. rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
  278. return rc > 0 ? rc : -ERANGE;
  279. }
  280. static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
  281. {
  282. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  283. unsigned int implemented;
  284. unsigned int enabled;
  285. int rc;
  286. nic_data->workaround_35388 = false;
  287. nic_data->workaround_61265 = false;
  288. rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
  289. if (rc == -ENOSYS) {
  290. /* Firmware without GET_WORKAROUNDS - not a problem. */
  291. rc = 0;
  292. } else if (rc == 0) {
  293. /* Bug61265 workaround is always enabled if implemented. */
  294. if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
  295. nic_data->workaround_61265 = true;
  296. if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
  297. nic_data->workaround_35388 = true;
  298. } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
  299. /* Workaround is implemented but not enabled.
  300. * Try to enable it.
  301. */
  302. rc = efx_mcdi_set_workaround(efx,
  303. MC_CMD_WORKAROUND_BUG35388,
  304. true, NULL);
  305. if (rc == 0)
  306. nic_data->workaround_35388 = true;
  307. /* If we failed to set the workaround just carry on. */
  308. rc = 0;
  309. }
  310. }
  311. netif_dbg(efx, probe, efx->net_dev,
  312. "workaround for bug 35388 is %sabled\n",
  313. nic_data->workaround_35388 ? "en" : "dis");
  314. netif_dbg(efx, probe, efx->net_dev,
  315. "workaround for bug 61265 is %sabled\n",
  316. nic_data->workaround_61265 ? "en" : "dis");
  317. return rc;
  318. }
  319. static void efx_ef10_process_timer_config(struct efx_nic *efx,
  320. const efx_dword_t *data)
  321. {
  322. unsigned int max_count;
  323. if (EFX_EF10_WORKAROUND_61265(efx)) {
  324. efx->timer_quantum_ns = MCDI_DWORD(data,
  325. GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
  326. efx->timer_max_ns = MCDI_DWORD(data,
  327. GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
  328. } else if (EFX_EF10_WORKAROUND_35388(efx)) {
  329. efx->timer_quantum_ns = MCDI_DWORD(data,
  330. GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
  331. max_count = MCDI_DWORD(data,
  332. GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
  333. efx->timer_max_ns = max_count * efx->timer_quantum_ns;
  334. } else {
  335. efx->timer_quantum_ns = MCDI_DWORD(data,
  336. GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
  337. max_count = MCDI_DWORD(data,
  338. GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
  339. efx->timer_max_ns = max_count * efx->timer_quantum_ns;
  340. }
  341. netif_dbg(efx, probe, efx->net_dev,
  342. "got timer properties from MC: quantum %u ns; max %u ns\n",
  343. efx->timer_quantum_ns, efx->timer_max_ns);
  344. }
  345. static int efx_ef10_get_timer_config(struct efx_nic *efx)
  346. {
  347. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
  348. int rc;
  349. rc = efx_ef10_get_timer_workarounds(efx);
  350. if (rc)
  351. return rc;
  352. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
  353. outbuf, sizeof(outbuf), NULL);
  354. if (rc == 0) {
  355. efx_ef10_process_timer_config(efx, outbuf);
  356. } else if (rc == -ENOSYS || rc == -EPERM) {
  357. /* Not available - fall back to Huntington defaults. */
  358. unsigned int quantum;
  359. rc = efx_ef10_get_sysclk_freq(efx);
  360. if (rc < 0)
  361. return rc;
  362. quantum = 1536000 / rc; /* 1536 cycles */
  363. efx->timer_quantum_ns = quantum;
  364. efx->timer_max_ns = efx->type->timer_period_max * quantum;
  365. rc = 0;
  366. } else {
  367. efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
  368. MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
  369. NULL, 0, rc);
  370. }
  371. return rc;
  372. }
  373. static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
  374. {
  375. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
  376. size_t outlen;
  377. int rc;
  378. BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
  379. rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
  380. outbuf, sizeof(outbuf), &outlen);
  381. if (rc)
  382. return rc;
  383. if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
  384. return -EIO;
  385. ether_addr_copy(mac_address,
  386. MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
  387. return 0;
  388. }
  389. static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
  390. {
  391. MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
  392. MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
  393. size_t outlen;
  394. int num_addrs, rc;
  395. MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
  396. EVB_PORT_ID_ASSIGNED);
  397. rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
  398. sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
  399. if (rc)
  400. return rc;
  401. if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
  402. return -EIO;
  403. num_addrs = MCDI_DWORD(outbuf,
  404. VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
  405. WARN_ON(num_addrs != 1);
  406. ether_addr_copy(mac_address,
  407. MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
  408. return 0;
  409. }
  410. static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
  411. struct device_attribute *attr,
  412. char *buf)
  413. {
  414. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  415. return sprintf(buf, "%d\n",
  416. ((efx->mcdi->fn_flags) &
  417. (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
  418. ? 1 : 0);
  419. }
  420. static ssize_t efx_ef10_show_primary_flag(struct device *dev,
  421. struct device_attribute *attr,
  422. char *buf)
  423. {
  424. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  425. return sprintf(buf, "%d\n",
  426. ((efx->mcdi->fn_flags) &
  427. (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
  428. ? 1 : 0);
  429. }
  430. static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
  431. {
  432. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  433. struct efx_ef10_vlan *vlan;
  434. WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
  435. list_for_each_entry(vlan, &nic_data->vlan_list, list) {
  436. if (vlan->vid == vid)
  437. return vlan;
  438. }
  439. return NULL;
  440. }
  441. static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
  442. {
  443. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  444. struct efx_ef10_vlan *vlan;
  445. int rc;
  446. mutex_lock(&nic_data->vlan_lock);
  447. vlan = efx_ef10_find_vlan(efx, vid);
  448. if (vlan) {
  449. /* We add VID 0 on init. 8021q adds it on module init
  450. * for all interfaces with VLAN filtring feature.
  451. */
  452. if (vid == 0)
  453. goto done_unlock;
  454. netif_warn(efx, drv, efx->net_dev,
  455. "VLAN %u already added\n", vid);
  456. rc = -EALREADY;
  457. goto fail_exist;
  458. }
  459. rc = -ENOMEM;
  460. vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
  461. if (!vlan)
  462. goto fail_alloc;
  463. vlan->vid = vid;
  464. list_add_tail(&vlan->list, &nic_data->vlan_list);
  465. if (efx->filter_state) {
  466. mutex_lock(&efx->mac_lock);
  467. down_write(&efx->filter_sem);
  468. rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
  469. up_write(&efx->filter_sem);
  470. mutex_unlock(&efx->mac_lock);
  471. if (rc)
  472. goto fail_filter_add_vlan;
  473. }
  474. done_unlock:
  475. mutex_unlock(&nic_data->vlan_lock);
  476. return 0;
  477. fail_filter_add_vlan:
  478. list_del(&vlan->list);
  479. kfree(vlan);
  480. fail_alloc:
  481. fail_exist:
  482. mutex_unlock(&nic_data->vlan_lock);
  483. return rc;
  484. }
  485. static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
  486. struct efx_ef10_vlan *vlan)
  487. {
  488. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  489. WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
  490. if (efx->filter_state) {
  491. down_write(&efx->filter_sem);
  492. efx_ef10_filter_del_vlan(efx, vlan->vid);
  493. up_write(&efx->filter_sem);
  494. }
  495. list_del(&vlan->list);
  496. kfree(vlan);
  497. }
  498. static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
  499. {
  500. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  501. struct efx_ef10_vlan *vlan;
  502. int rc = 0;
  503. /* 8021q removes VID 0 on module unload for all interfaces
  504. * with VLAN filtering feature. We need to keep it to receive
  505. * untagged traffic.
  506. */
  507. if (vid == 0)
  508. return 0;
  509. mutex_lock(&nic_data->vlan_lock);
  510. vlan = efx_ef10_find_vlan(efx, vid);
  511. if (!vlan) {
  512. netif_err(efx, drv, efx->net_dev,
  513. "VLAN %u to be deleted not found\n", vid);
  514. rc = -ENOENT;
  515. } else {
  516. efx_ef10_del_vlan_internal(efx, vlan);
  517. }
  518. mutex_unlock(&nic_data->vlan_lock);
  519. return rc;
  520. }
  521. static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
  522. {
  523. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  524. struct efx_ef10_vlan *vlan, *next_vlan;
  525. mutex_lock(&nic_data->vlan_lock);
  526. list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
  527. efx_ef10_del_vlan_internal(efx, vlan);
  528. mutex_unlock(&nic_data->vlan_lock);
  529. }
  530. static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
  531. NULL);
  532. static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
  533. static int efx_ef10_probe(struct efx_nic *efx)
  534. {
  535. struct efx_ef10_nic_data *nic_data;
  536. int i, rc;
  537. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  538. if (!nic_data)
  539. return -ENOMEM;
  540. efx->nic_data = nic_data;
  541. /* we assume later that we can copy from this buffer in dwords */
  542. BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
  543. rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
  544. 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
  545. if (rc)
  546. goto fail1;
  547. /* Get the MC's warm boot count. In case it's rebooting right
  548. * now, be prepared to retry.
  549. */
  550. i = 0;
  551. for (;;) {
  552. rc = efx_ef10_get_warm_boot_count(efx);
  553. if (rc >= 0)
  554. break;
  555. if (++i == 5)
  556. goto fail2;
  557. ssleep(1);
  558. }
  559. nic_data->warm_boot_count = rc;
  560. nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
  561. nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
  562. /* In case we're recovering from a crash (kexec), we want to
  563. * cancel any outstanding request by the previous user of this
  564. * function. We send a special message using the least
  565. * significant bits of the 'high' (doorbell) register.
  566. */
  567. _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
  568. rc = efx_mcdi_init(efx);
  569. if (rc)
  570. goto fail2;
  571. mutex_init(&nic_data->udp_tunnels_lock);
  572. /* Reset (most) configuration for this function */
  573. rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
  574. if (rc)
  575. goto fail3;
  576. /* Enable event logging */
  577. rc = efx_mcdi_log_ctrl(efx, true, false, 0);
  578. if (rc)
  579. goto fail3;
  580. rc = device_create_file(&efx->pci_dev->dev,
  581. &dev_attr_link_control_flag);
  582. if (rc)
  583. goto fail3;
  584. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
  585. if (rc)
  586. goto fail4;
  587. rc = efx_ef10_get_pf_index(efx);
  588. if (rc)
  589. goto fail5;
  590. rc = efx_ef10_init_datapath_caps(efx);
  591. if (rc < 0)
  592. goto fail5;
  593. /* We can have one VI for each vi_stride-byte region.
  594. * However, until we use TX option descriptors we need two TX queues
  595. * per channel.
  596. */
  597. efx->max_channels = min_t(unsigned int,
  598. EFX_MAX_CHANNELS,
  599. efx_ef10_mem_map_size(efx) /
  600. (efx->vi_stride * EFX_TXQ_TYPES));
  601. efx->max_tx_channels = efx->max_channels;
  602. if (WARN_ON(efx->max_channels == 0)) {
  603. rc = -EIO;
  604. goto fail5;
  605. }
  606. efx->rx_packet_len_offset =
  607. ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
  608. if (nic_data->datapath_caps &
  609. (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_INCLUDE_FCS_LBN))
  610. efx->net_dev->hw_features |= NETIF_F_RXFCS;
  611. rc = efx_mcdi_port_get_number(efx);
  612. if (rc < 0)
  613. goto fail5;
  614. efx->port_num = rc;
  615. rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
  616. if (rc)
  617. goto fail5;
  618. rc = efx_ef10_get_timer_config(efx);
  619. if (rc < 0)
  620. goto fail5;
  621. rc = efx_mcdi_mon_probe(efx);
  622. if (rc && rc != -EPERM)
  623. goto fail5;
  624. rc = efx_ptp_probe(efx, NULL);
  625. /* Failure to probe PTP is not fatal.
  626. * In the case of EPERM, efx_ptp_probe will print its own message (in
  627. * efx_ptp_get_attributes()), so we don't need to.
  628. */
  629. if (rc && rc != -EPERM)
  630. netif_warn(efx, drv, efx->net_dev,
  631. "Failed to probe PTP, rc=%d\n", rc);
  632. #ifdef CONFIG_SFC_SRIOV
  633. if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
  634. struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
  635. struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
  636. efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
  637. } else
  638. #endif
  639. ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
  640. INIT_LIST_HEAD(&nic_data->vlan_list);
  641. mutex_init(&nic_data->vlan_lock);
  642. /* Add unspecified VID to support VLAN filtering being disabled */
  643. rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
  644. if (rc)
  645. goto fail_add_vid_unspec;
  646. /* If VLAN filtering is enabled, we need VID 0 to get untagged
  647. * traffic. It is added automatically if 8021q module is loaded,
  648. * but we can't rely on it since module may be not loaded.
  649. */
  650. rc = efx_ef10_add_vlan(efx, 0);
  651. if (rc)
  652. goto fail_add_vid_0;
  653. return 0;
  654. fail_add_vid_0:
  655. efx_ef10_cleanup_vlans(efx);
  656. fail_add_vid_unspec:
  657. mutex_destroy(&nic_data->vlan_lock);
  658. efx_ptp_remove(efx);
  659. efx_mcdi_mon_remove(efx);
  660. fail5:
  661. device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
  662. fail4:
  663. device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
  664. fail3:
  665. efx_mcdi_detach(efx);
  666. mutex_lock(&nic_data->udp_tunnels_lock);
  667. memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
  668. (void)efx_ef10_set_udp_tnl_ports(efx, true);
  669. mutex_unlock(&nic_data->udp_tunnels_lock);
  670. mutex_destroy(&nic_data->udp_tunnels_lock);
  671. efx_mcdi_fini(efx);
  672. fail2:
  673. efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
  674. fail1:
  675. kfree(nic_data);
  676. efx->nic_data = NULL;
  677. return rc;
  678. }
  679. static int efx_ef10_free_vis(struct efx_nic *efx)
  680. {
  681. MCDI_DECLARE_BUF_ERR(outbuf);
  682. size_t outlen;
  683. int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
  684. outbuf, sizeof(outbuf), &outlen);
  685. /* -EALREADY means nothing to free, so ignore */
  686. if (rc == -EALREADY)
  687. rc = 0;
  688. if (rc)
  689. efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
  690. rc);
  691. return rc;
  692. }
  693. #ifdef EFX_USE_PIO
  694. static void efx_ef10_free_piobufs(struct efx_nic *efx)
  695. {
  696. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  697. MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
  698. unsigned int i;
  699. int rc;
  700. BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
  701. for (i = 0; i < nic_data->n_piobufs; i++) {
  702. MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
  703. nic_data->piobuf_handle[i]);
  704. rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
  705. NULL, 0, NULL);
  706. WARN_ON(rc);
  707. }
  708. nic_data->n_piobufs = 0;
  709. }
  710. static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
  711. {
  712. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  713. MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
  714. unsigned int i;
  715. size_t outlen;
  716. int rc = 0;
  717. BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
  718. for (i = 0; i < n; i++) {
  719. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
  720. outbuf, sizeof(outbuf), &outlen);
  721. if (rc) {
  722. /* Don't display the MC error if we didn't have space
  723. * for a VF.
  724. */
  725. if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
  726. efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
  727. 0, outbuf, outlen, rc);
  728. break;
  729. }
  730. if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
  731. rc = -EIO;
  732. break;
  733. }
  734. nic_data->piobuf_handle[i] =
  735. MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
  736. netif_dbg(efx, probe, efx->net_dev,
  737. "allocated PIO buffer %u handle %x\n", i,
  738. nic_data->piobuf_handle[i]);
  739. }
  740. nic_data->n_piobufs = i;
  741. if (rc)
  742. efx_ef10_free_piobufs(efx);
  743. return rc;
  744. }
  745. static int efx_ef10_link_piobufs(struct efx_nic *efx)
  746. {
  747. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  748. MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_PIOBUF_IN_LEN);
  749. struct efx_channel *channel;
  750. struct efx_tx_queue *tx_queue;
  751. unsigned int offset, index;
  752. int rc;
  753. BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
  754. BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
  755. /* Link a buffer to each VI in the write-combining mapping */
  756. for (index = 0; index < nic_data->n_piobufs; ++index) {
  757. MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
  758. nic_data->piobuf_handle[index]);
  759. MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
  760. nic_data->pio_write_vi_base + index);
  761. rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
  762. inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
  763. NULL, 0, NULL);
  764. if (rc) {
  765. netif_err(efx, drv, efx->net_dev,
  766. "failed to link VI %u to PIO buffer %u (%d)\n",
  767. nic_data->pio_write_vi_base + index, index,
  768. rc);
  769. goto fail;
  770. }
  771. netif_dbg(efx, probe, efx->net_dev,
  772. "linked VI %u to PIO buffer %u\n",
  773. nic_data->pio_write_vi_base + index, index);
  774. }
  775. /* Link a buffer to each TX queue */
  776. efx_for_each_channel(channel, efx) {
  777. efx_for_each_channel_tx_queue(tx_queue, channel) {
  778. /* We assign the PIO buffers to queues in
  779. * reverse order to allow for the following
  780. * special case.
  781. */
  782. offset = ((efx->tx_channel_offset + efx->n_tx_channels -
  783. tx_queue->channel->channel - 1) *
  784. efx_piobuf_size);
  785. index = offset / nic_data->piobuf_size;
  786. offset = offset % nic_data->piobuf_size;
  787. /* When the host page size is 4K, the first
  788. * host page in the WC mapping may be within
  789. * the same VI page as the last TX queue. We
  790. * can only link one buffer to each VI.
  791. */
  792. if (tx_queue->queue == nic_data->pio_write_vi_base) {
  793. BUG_ON(index != 0);
  794. rc = 0;
  795. } else {
  796. MCDI_SET_DWORD(inbuf,
  797. LINK_PIOBUF_IN_PIOBUF_HANDLE,
  798. nic_data->piobuf_handle[index]);
  799. MCDI_SET_DWORD(inbuf,
  800. LINK_PIOBUF_IN_TXQ_INSTANCE,
  801. tx_queue->queue);
  802. rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
  803. inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
  804. NULL, 0, NULL);
  805. }
  806. if (rc) {
  807. /* This is non-fatal; the TX path just
  808. * won't use PIO for this queue
  809. */
  810. netif_err(efx, drv, efx->net_dev,
  811. "failed to link VI %u to PIO buffer %u (%d)\n",
  812. tx_queue->queue, index, rc);
  813. tx_queue->piobuf = NULL;
  814. } else {
  815. tx_queue->piobuf =
  816. nic_data->pio_write_base +
  817. index * efx->vi_stride + offset;
  818. tx_queue->piobuf_offset = offset;
  819. netif_dbg(efx, probe, efx->net_dev,
  820. "linked VI %u to PIO buffer %u offset %x addr %p\n",
  821. tx_queue->queue, index,
  822. tx_queue->piobuf_offset,
  823. tx_queue->piobuf);
  824. }
  825. }
  826. }
  827. return 0;
  828. fail:
  829. /* inbuf was defined for MC_CMD_LINK_PIOBUF. We can use the same
  830. * buffer for MC_CMD_UNLINK_PIOBUF because it's shorter.
  831. */
  832. BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_IN_LEN < MC_CMD_UNLINK_PIOBUF_IN_LEN);
  833. while (index--) {
  834. MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
  835. nic_data->pio_write_vi_base + index);
  836. efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
  837. inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
  838. NULL, 0, NULL);
  839. }
  840. return rc;
  841. }
  842. static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
  843. {
  844. struct efx_channel *channel;
  845. struct efx_tx_queue *tx_queue;
  846. /* All our existing PIO buffers went away */
  847. efx_for_each_channel(channel, efx)
  848. efx_for_each_channel_tx_queue(tx_queue, channel)
  849. tx_queue->piobuf = NULL;
  850. }
  851. #else /* !EFX_USE_PIO */
  852. static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
  853. {
  854. return n == 0 ? 0 : -ENOBUFS;
  855. }
  856. static int efx_ef10_link_piobufs(struct efx_nic *efx)
  857. {
  858. return 0;
  859. }
  860. static void efx_ef10_free_piobufs(struct efx_nic *efx)
  861. {
  862. }
  863. static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
  864. {
  865. }
  866. #endif /* EFX_USE_PIO */
  867. static void efx_ef10_remove(struct efx_nic *efx)
  868. {
  869. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  870. int rc;
  871. #ifdef CONFIG_SFC_SRIOV
  872. struct efx_ef10_nic_data *nic_data_pf;
  873. struct pci_dev *pci_dev_pf;
  874. struct efx_nic *efx_pf;
  875. struct ef10_vf *vf;
  876. if (efx->pci_dev->is_virtfn) {
  877. pci_dev_pf = efx->pci_dev->physfn;
  878. if (pci_dev_pf) {
  879. efx_pf = pci_get_drvdata(pci_dev_pf);
  880. nic_data_pf = efx_pf->nic_data;
  881. vf = nic_data_pf->vf + nic_data->vf_index;
  882. vf->efx = NULL;
  883. } else
  884. netif_info(efx, drv, efx->net_dev,
  885. "Could not get the PF id from VF\n");
  886. }
  887. #endif
  888. efx_ef10_cleanup_vlans(efx);
  889. mutex_destroy(&nic_data->vlan_lock);
  890. efx_ptp_remove(efx);
  891. efx_mcdi_mon_remove(efx);
  892. efx_ef10_rx_free_indir_table(efx);
  893. if (nic_data->wc_membase)
  894. iounmap(nic_data->wc_membase);
  895. rc = efx_ef10_free_vis(efx);
  896. WARN_ON(rc != 0);
  897. if (!nic_data->must_restore_piobufs)
  898. efx_ef10_free_piobufs(efx);
  899. device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
  900. device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
  901. efx_mcdi_detach(efx);
  902. memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
  903. mutex_lock(&nic_data->udp_tunnels_lock);
  904. (void)efx_ef10_set_udp_tnl_ports(efx, true);
  905. mutex_unlock(&nic_data->udp_tunnels_lock);
  906. mutex_destroy(&nic_data->udp_tunnels_lock);
  907. efx_mcdi_fini(efx);
  908. efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
  909. kfree(nic_data);
  910. }
  911. static int efx_ef10_probe_pf(struct efx_nic *efx)
  912. {
  913. return efx_ef10_probe(efx);
  914. }
  915. int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
  916. u32 *port_flags, u32 *vadaptor_flags,
  917. unsigned int *vlan_tags)
  918. {
  919. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  920. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
  921. MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
  922. size_t outlen;
  923. int rc;
  924. if (nic_data->datapath_caps &
  925. (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
  926. MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
  927. port_id);
  928. rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
  929. outbuf, sizeof(outbuf), &outlen);
  930. if (rc)
  931. return rc;
  932. if (outlen < sizeof(outbuf)) {
  933. rc = -EIO;
  934. return rc;
  935. }
  936. }
  937. if (port_flags)
  938. *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
  939. if (vadaptor_flags)
  940. *vadaptor_flags =
  941. MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
  942. if (vlan_tags)
  943. *vlan_tags =
  944. MCDI_DWORD(outbuf,
  945. VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
  946. return 0;
  947. }
  948. int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
  949. {
  950. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
  951. MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
  952. return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
  953. NULL, 0, NULL);
  954. }
  955. int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
  956. {
  957. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
  958. MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
  959. return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
  960. NULL, 0, NULL);
  961. }
  962. int efx_ef10_vport_add_mac(struct efx_nic *efx,
  963. unsigned int port_id, u8 *mac)
  964. {
  965. MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
  966. MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
  967. ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
  968. return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
  969. sizeof(inbuf), NULL, 0, NULL);
  970. }
  971. int efx_ef10_vport_del_mac(struct efx_nic *efx,
  972. unsigned int port_id, u8 *mac)
  973. {
  974. MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
  975. MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
  976. ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
  977. return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
  978. sizeof(inbuf), NULL, 0, NULL);
  979. }
  980. #ifdef CONFIG_SFC_SRIOV
  981. static int efx_ef10_probe_vf(struct efx_nic *efx)
  982. {
  983. int rc;
  984. struct pci_dev *pci_dev_pf;
  985. /* If the parent PF has no VF data structure, it doesn't know about this
  986. * VF so fail probe. The VF needs to be re-created. This can happen
  987. * if the PF driver is unloaded while the VF is assigned to a guest.
  988. */
  989. pci_dev_pf = efx->pci_dev->physfn;
  990. if (pci_dev_pf) {
  991. struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
  992. struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
  993. if (!nic_data_pf->vf) {
  994. netif_info(efx, drv, efx->net_dev,
  995. "The VF cannot link to its parent PF; "
  996. "please destroy and re-create the VF\n");
  997. return -EBUSY;
  998. }
  999. }
  1000. rc = efx_ef10_probe(efx);
  1001. if (rc)
  1002. return rc;
  1003. rc = efx_ef10_get_vf_index(efx);
  1004. if (rc)
  1005. goto fail;
  1006. if (efx->pci_dev->is_virtfn) {
  1007. if (efx->pci_dev->physfn) {
  1008. struct efx_nic *efx_pf =
  1009. pci_get_drvdata(efx->pci_dev->physfn);
  1010. struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
  1011. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1012. nic_data_p->vf[nic_data->vf_index].efx = efx;
  1013. nic_data_p->vf[nic_data->vf_index].pci_dev =
  1014. efx->pci_dev;
  1015. } else
  1016. netif_info(efx, drv, efx->net_dev,
  1017. "Could not get the PF id from VF\n");
  1018. }
  1019. return 0;
  1020. fail:
  1021. efx_ef10_remove(efx);
  1022. return rc;
  1023. }
  1024. #else
  1025. static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
  1026. {
  1027. return 0;
  1028. }
  1029. #endif
  1030. static int efx_ef10_alloc_vis(struct efx_nic *efx,
  1031. unsigned int min_vis, unsigned int max_vis)
  1032. {
  1033. MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
  1034. MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
  1035. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1036. size_t outlen;
  1037. int rc;
  1038. MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
  1039. MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
  1040. rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
  1041. outbuf, sizeof(outbuf), &outlen);
  1042. if (rc != 0)
  1043. return rc;
  1044. if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
  1045. return -EIO;
  1046. netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
  1047. MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
  1048. nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
  1049. nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
  1050. return 0;
  1051. }
  1052. /* Note that the failure path of this function does not free
  1053. * resources, as this will be done by efx_ef10_remove().
  1054. */
  1055. static int efx_ef10_dimension_resources(struct efx_nic *efx)
  1056. {
  1057. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1058. unsigned int uc_mem_map_size, wc_mem_map_size;
  1059. unsigned int min_vis = max(EFX_TXQ_TYPES,
  1060. efx_separate_tx_channels ? 2 : 1);
  1061. unsigned int channel_vis, pio_write_vi_base, max_vis;
  1062. void __iomem *membase;
  1063. int rc;
  1064. channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
  1065. #ifdef EFX_USE_PIO
  1066. /* Try to allocate PIO buffers if wanted and if the full
  1067. * number of PIO buffers would be sufficient to allocate one
  1068. * copy-buffer per TX channel. Failure is non-fatal, as there
  1069. * are only a small number of PIO buffers shared between all
  1070. * functions of the controller.
  1071. */
  1072. if (efx_piobuf_size != 0 &&
  1073. nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
  1074. efx->n_tx_channels) {
  1075. unsigned int n_piobufs =
  1076. DIV_ROUND_UP(efx->n_tx_channels,
  1077. nic_data->piobuf_size / efx_piobuf_size);
  1078. rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
  1079. if (rc == -ENOSPC)
  1080. netif_dbg(efx, probe, efx->net_dev,
  1081. "out of PIO buffers; cannot allocate more\n");
  1082. else if (rc == -EPERM)
  1083. netif_dbg(efx, probe, efx->net_dev,
  1084. "not permitted to allocate PIO buffers\n");
  1085. else if (rc)
  1086. netif_err(efx, probe, efx->net_dev,
  1087. "failed to allocate PIO buffers (%d)\n", rc);
  1088. else
  1089. netif_dbg(efx, probe, efx->net_dev,
  1090. "allocated %u PIO buffers\n", n_piobufs);
  1091. }
  1092. #else
  1093. nic_data->n_piobufs = 0;
  1094. #endif
  1095. /* PIO buffers should be mapped with write-combining enabled,
  1096. * and we want to make single UC and WC mappings rather than
  1097. * several of each (in fact that's the only option if host
  1098. * page size is >4K). So we may allocate some extra VIs just
  1099. * for writing PIO buffers through.
  1100. *
  1101. * The UC mapping contains (channel_vis - 1) complete VIs and the
  1102. * first 4K of the next VI. Then the WC mapping begins with
  1103. * the remainder of this last VI.
  1104. */
  1105. uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * efx->vi_stride +
  1106. ER_DZ_TX_PIOBUF);
  1107. if (nic_data->n_piobufs) {
  1108. /* pio_write_vi_base rounds down to give the number of complete
  1109. * VIs inside the UC mapping.
  1110. */
  1111. pio_write_vi_base = uc_mem_map_size / efx->vi_stride;
  1112. wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
  1113. nic_data->n_piobufs) *
  1114. efx->vi_stride) -
  1115. uc_mem_map_size);
  1116. max_vis = pio_write_vi_base + nic_data->n_piobufs;
  1117. } else {
  1118. pio_write_vi_base = 0;
  1119. wc_mem_map_size = 0;
  1120. max_vis = channel_vis;
  1121. }
  1122. /* In case the last attached driver failed to free VIs, do it now */
  1123. rc = efx_ef10_free_vis(efx);
  1124. if (rc != 0)
  1125. return rc;
  1126. rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
  1127. if (rc != 0)
  1128. return rc;
  1129. if (nic_data->n_allocated_vis < channel_vis) {
  1130. netif_info(efx, drv, efx->net_dev,
  1131. "Could not allocate enough VIs to satisfy RSS"
  1132. " requirements. Performance may not be optimal.\n");
  1133. /* We didn't get the VIs to populate our channels.
  1134. * We could keep what we got but then we'd have more
  1135. * interrupts than we need.
  1136. * Instead calculate new max_channels and restart
  1137. */
  1138. efx->max_channels = nic_data->n_allocated_vis;
  1139. efx->max_tx_channels =
  1140. nic_data->n_allocated_vis / EFX_TXQ_TYPES;
  1141. efx_ef10_free_vis(efx);
  1142. return -EAGAIN;
  1143. }
  1144. /* If we didn't get enough VIs to map all the PIO buffers, free the
  1145. * PIO buffers
  1146. */
  1147. if (nic_data->n_piobufs &&
  1148. nic_data->n_allocated_vis <
  1149. pio_write_vi_base + nic_data->n_piobufs) {
  1150. netif_dbg(efx, probe, efx->net_dev,
  1151. "%u VIs are not sufficient to map %u PIO buffers\n",
  1152. nic_data->n_allocated_vis, nic_data->n_piobufs);
  1153. efx_ef10_free_piobufs(efx);
  1154. }
  1155. /* Shrink the original UC mapping of the memory BAR */
  1156. membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
  1157. if (!membase) {
  1158. netif_err(efx, probe, efx->net_dev,
  1159. "could not shrink memory BAR to %x\n",
  1160. uc_mem_map_size);
  1161. return -ENOMEM;
  1162. }
  1163. iounmap(efx->membase);
  1164. efx->membase = membase;
  1165. /* Set up the WC mapping if needed */
  1166. if (wc_mem_map_size) {
  1167. nic_data->wc_membase = ioremap_wc(efx->membase_phys +
  1168. uc_mem_map_size,
  1169. wc_mem_map_size);
  1170. if (!nic_data->wc_membase) {
  1171. netif_err(efx, probe, efx->net_dev,
  1172. "could not allocate WC mapping of size %x\n",
  1173. wc_mem_map_size);
  1174. return -ENOMEM;
  1175. }
  1176. nic_data->pio_write_vi_base = pio_write_vi_base;
  1177. nic_data->pio_write_base =
  1178. nic_data->wc_membase +
  1179. (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
  1180. uc_mem_map_size);
  1181. rc = efx_ef10_link_piobufs(efx);
  1182. if (rc)
  1183. efx_ef10_free_piobufs(efx);
  1184. }
  1185. netif_dbg(efx, probe, efx->net_dev,
  1186. "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
  1187. &efx->membase_phys, efx->membase, uc_mem_map_size,
  1188. nic_data->wc_membase, wc_mem_map_size);
  1189. return 0;
  1190. }
  1191. static int efx_ef10_init_nic(struct efx_nic *efx)
  1192. {
  1193. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1194. int rc;
  1195. if (nic_data->must_check_datapath_caps) {
  1196. rc = efx_ef10_init_datapath_caps(efx);
  1197. if (rc)
  1198. return rc;
  1199. nic_data->must_check_datapath_caps = false;
  1200. }
  1201. if (nic_data->must_realloc_vis) {
  1202. /* We cannot let the number of VIs change now */
  1203. rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
  1204. nic_data->n_allocated_vis);
  1205. if (rc)
  1206. return rc;
  1207. nic_data->must_realloc_vis = false;
  1208. }
  1209. if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
  1210. rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
  1211. if (rc == 0) {
  1212. rc = efx_ef10_link_piobufs(efx);
  1213. if (rc)
  1214. efx_ef10_free_piobufs(efx);
  1215. }
  1216. /* Log an error on failure, but this is non-fatal.
  1217. * Permission errors are less important - we've presumably
  1218. * had the PIO buffer licence removed.
  1219. */
  1220. if (rc == -EPERM)
  1221. netif_dbg(efx, drv, efx->net_dev,
  1222. "not permitted to restore PIO buffers\n");
  1223. else if (rc)
  1224. netif_err(efx, drv, efx->net_dev,
  1225. "failed to restore PIO buffers (%d)\n", rc);
  1226. nic_data->must_restore_piobufs = false;
  1227. }
  1228. /* don't fail init if RSS setup doesn't work */
  1229. rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL);
  1230. efx->rss_active = (rc == 0);
  1231. return 0;
  1232. }
  1233. static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
  1234. {
  1235. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1236. #ifdef CONFIG_SFC_SRIOV
  1237. unsigned int i;
  1238. #endif
  1239. /* All our allocations have been reset */
  1240. nic_data->must_realloc_vis = true;
  1241. nic_data->must_restore_filters = true;
  1242. nic_data->must_restore_piobufs = true;
  1243. efx_ef10_forget_old_piobufs(efx);
  1244. nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
  1245. /* Driver-created vswitches and vports must be re-created */
  1246. nic_data->must_probe_vswitching = true;
  1247. nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
  1248. #ifdef CONFIG_SFC_SRIOV
  1249. if (nic_data->vf)
  1250. for (i = 0; i < efx->vf_count; i++)
  1251. nic_data->vf[i].vport_id = 0;
  1252. #endif
  1253. }
  1254. static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
  1255. {
  1256. if (reason == RESET_TYPE_MC_FAILURE)
  1257. return RESET_TYPE_DATAPATH;
  1258. return efx_mcdi_map_reset_reason(reason);
  1259. }
  1260. static int efx_ef10_map_reset_flags(u32 *flags)
  1261. {
  1262. enum {
  1263. EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
  1264. ETH_RESET_SHARED_SHIFT),
  1265. EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
  1266. ETH_RESET_OFFLOAD | ETH_RESET_MAC |
  1267. ETH_RESET_PHY | ETH_RESET_MGMT) <<
  1268. ETH_RESET_SHARED_SHIFT)
  1269. };
  1270. /* We assume for now that our PCI function is permitted to
  1271. * reset everything.
  1272. */
  1273. if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
  1274. *flags &= ~EF10_RESET_MC;
  1275. return RESET_TYPE_WORLD;
  1276. }
  1277. if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
  1278. *flags &= ~EF10_RESET_PORT;
  1279. return RESET_TYPE_ALL;
  1280. }
  1281. /* no invisible reset implemented */
  1282. return -EINVAL;
  1283. }
  1284. static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
  1285. {
  1286. int rc = efx_mcdi_reset(efx, reset_type);
  1287. /* Unprivileged functions return -EPERM, but need to return success
  1288. * here so that the datapath is brought back up.
  1289. */
  1290. if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
  1291. rc = 0;
  1292. /* If it was a port reset, trigger reallocation of MC resources.
  1293. * Note that on an MC reset nothing needs to be done now because we'll
  1294. * detect the MC reset later and handle it then.
  1295. * For an FLR, we never get an MC reset event, but the MC has reset all
  1296. * resources assigned to us, so we have to trigger reallocation now.
  1297. */
  1298. if ((reset_type == RESET_TYPE_ALL ||
  1299. reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
  1300. efx_ef10_reset_mc_allocations(efx);
  1301. return rc;
  1302. }
  1303. #define EF10_DMA_STAT(ext_name, mcdi_name) \
  1304. [EF10_STAT_ ## ext_name] = \
  1305. { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
  1306. #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
  1307. [EF10_STAT_ ## int_name] = \
  1308. { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
  1309. #define EF10_OTHER_STAT(ext_name) \
  1310. [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
  1311. #define GENERIC_SW_STAT(ext_name) \
  1312. [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
  1313. static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
  1314. EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
  1315. EF10_DMA_STAT(port_tx_packets, TX_PKTS),
  1316. EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
  1317. EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
  1318. EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
  1319. EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
  1320. EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
  1321. EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
  1322. EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
  1323. EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
  1324. EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
  1325. EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
  1326. EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
  1327. EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
  1328. EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
  1329. EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
  1330. EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
  1331. EF10_OTHER_STAT(port_rx_good_bytes),
  1332. EF10_OTHER_STAT(port_rx_bad_bytes),
  1333. EF10_DMA_STAT(port_rx_packets, RX_PKTS),
  1334. EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
  1335. EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
  1336. EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
  1337. EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
  1338. EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
  1339. EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
  1340. EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
  1341. EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
  1342. EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
  1343. EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
  1344. EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
  1345. EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
  1346. EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
  1347. EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
  1348. EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
  1349. EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
  1350. EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
  1351. EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
  1352. EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
  1353. EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
  1354. EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
  1355. GENERIC_SW_STAT(rx_nodesc_trunc),
  1356. GENERIC_SW_STAT(rx_noskb_drops),
  1357. EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
  1358. EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
  1359. EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
  1360. EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
  1361. EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
  1362. EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
  1363. EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
  1364. EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
  1365. EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
  1366. EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
  1367. EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
  1368. EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
  1369. EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
  1370. EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
  1371. EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
  1372. EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
  1373. EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
  1374. EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
  1375. EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
  1376. EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
  1377. EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
  1378. EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
  1379. EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
  1380. EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
  1381. EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
  1382. EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
  1383. EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
  1384. EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
  1385. EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
  1386. EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
  1387. };
  1388. #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
  1389. (1ULL << EF10_STAT_port_tx_packets) | \
  1390. (1ULL << EF10_STAT_port_tx_pause) | \
  1391. (1ULL << EF10_STAT_port_tx_unicast) | \
  1392. (1ULL << EF10_STAT_port_tx_multicast) | \
  1393. (1ULL << EF10_STAT_port_tx_broadcast) | \
  1394. (1ULL << EF10_STAT_port_rx_bytes) | \
  1395. (1ULL << \
  1396. EF10_STAT_port_rx_bytes_minus_good_bytes) | \
  1397. (1ULL << EF10_STAT_port_rx_good_bytes) | \
  1398. (1ULL << EF10_STAT_port_rx_bad_bytes) | \
  1399. (1ULL << EF10_STAT_port_rx_packets) | \
  1400. (1ULL << EF10_STAT_port_rx_good) | \
  1401. (1ULL << EF10_STAT_port_rx_bad) | \
  1402. (1ULL << EF10_STAT_port_rx_pause) | \
  1403. (1ULL << EF10_STAT_port_rx_control) | \
  1404. (1ULL << EF10_STAT_port_rx_unicast) | \
  1405. (1ULL << EF10_STAT_port_rx_multicast) | \
  1406. (1ULL << EF10_STAT_port_rx_broadcast) | \
  1407. (1ULL << EF10_STAT_port_rx_lt64) | \
  1408. (1ULL << EF10_STAT_port_rx_64) | \
  1409. (1ULL << EF10_STAT_port_rx_65_to_127) | \
  1410. (1ULL << EF10_STAT_port_rx_128_to_255) | \
  1411. (1ULL << EF10_STAT_port_rx_256_to_511) | \
  1412. (1ULL << EF10_STAT_port_rx_512_to_1023) |\
  1413. (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
  1414. (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
  1415. (1ULL << EF10_STAT_port_rx_gtjumbo) | \
  1416. (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
  1417. (1ULL << EF10_STAT_port_rx_overflow) | \
  1418. (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
  1419. (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
  1420. (1ULL << GENERIC_STAT_rx_noskb_drops))
  1421. /* On 7000 series NICs, these statistics are only provided by the 10G MAC.
  1422. * For a 10G/40G switchable port we do not expose these because they might
  1423. * not include all the packets they should.
  1424. * On 8000 series NICs these statistics are always provided.
  1425. */
  1426. #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
  1427. (1ULL << EF10_STAT_port_tx_lt64) | \
  1428. (1ULL << EF10_STAT_port_tx_64) | \
  1429. (1ULL << EF10_STAT_port_tx_65_to_127) |\
  1430. (1ULL << EF10_STAT_port_tx_128_to_255) |\
  1431. (1ULL << EF10_STAT_port_tx_256_to_511) |\
  1432. (1ULL << EF10_STAT_port_tx_512_to_1023) |\
  1433. (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
  1434. (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
  1435. /* These statistics are only provided by the 40G MAC. For a 10G/40G
  1436. * switchable port we do expose these because the errors will otherwise
  1437. * be silent.
  1438. */
  1439. #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
  1440. (1ULL << EF10_STAT_port_rx_length_error))
  1441. /* These statistics are only provided if the firmware supports the
  1442. * capability PM_AND_RXDP_COUNTERS.
  1443. */
  1444. #define HUNT_PM_AND_RXDP_STAT_MASK ( \
  1445. (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
  1446. (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
  1447. (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
  1448. (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
  1449. (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
  1450. (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
  1451. (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
  1452. (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
  1453. (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
  1454. (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
  1455. (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
  1456. (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
  1457. static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
  1458. {
  1459. u64 raw_mask = HUNT_COMMON_STAT_MASK;
  1460. u32 port_caps = efx_mcdi_phy_get_caps(efx);
  1461. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1462. if (!(efx->mcdi->fn_flags &
  1463. 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
  1464. return 0;
  1465. if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
  1466. raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
  1467. /* 8000 series have everything even at 40G */
  1468. if (nic_data->datapath_caps2 &
  1469. (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
  1470. raw_mask |= HUNT_10G_ONLY_STAT_MASK;
  1471. } else {
  1472. raw_mask |= HUNT_10G_ONLY_STAT_MASK;
  1473. }
  1474. if (nic_data->datapath_caps &
  1475. (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
  1476. raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
  1477. return raw_mask;
  1478. }
  1479. static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
  1480. {
  1481. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1482. u64 raw_mask[2];
  1483. raw_mask[0] = efx_ef10_raw_stat_mask(efx);
  1484. /* Only show vadaptor stats when EVB capability is present */
  1485. if (nic_data->datapath_caps &
  1486. (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
  1487. raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
  1488. raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1;
  1489. } else {
  1490. raw_mask[1] = 0;
  1491. }
  1492. #if BITS_PER_LONG == 64
  1493. BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
  1494. mask[0] = raw_mask[0];
  1495. mask[1] = raw_mask[1];
  1496. #else
  1497. BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
  1498. mask[0] = raw_mask[0] & 0xffffffff;
  1499. mask[1] = raw_mask[0] >> 32;
  1500. mask[2] = raw_mask[1] & 0xffffffff;
  1501. #endif
  1502. }
  1503. static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
  1504. {
  1505. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1506. efx_ef10_get_stat_mask(efx, mask);
  1507. return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
  1508. mask, names);
  1509. }
  1510. static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
  1511. struct rtnl_link_stats64 *core_stats)
  1512. {
  1513. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1514. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1515. u64 *stats = nic_data->stats;
  1516. size_t stats_count = 0, index;
  1517. efx_ef10_get_stat_mask(efx, mask);
  1518. if (full_stats) {
  1519. for_each_set_bit(index, mask, EF10_STAT_COUNT) {
  1520. if (efx_ef10_stat_desc[index].name) {
  1521. *full_stats++ = stats[index];
  1522. ++stats_count;
  1523. }
  1524. }
  1525. }
  1526. if (!core_stats)
  1527. return stats_count;
  1528. if (nic_data->datapath_caps &
  1529. 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
  1530. /* Use vadaptor stats. */
  1531. core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
  1532. stats[EF10_STAT_rx_multicast] +
  1533. stats[EF10_STAT_rx_broadcast];
  1534. core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
  1535. stats[EF10_STAT_tx_multicast] +
  1536. stats[EF10_STAT_tx_broadcast];
  1537. core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
  1538. stats[EF10_STAT_rx_multicast_bytes] +
  1539. stats[EF10_STAT_rx_broadcast_bytes];
  1540. core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
  1541. stats[EF10_STAT_tx_multicast_bytes] +
  1542. stats[EF10_STAT_tx_broadcast_bytes];
  1543. core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
  1544. stats[GENERIC_STAT_rx_noskb_drops];
  1545. core_stats->multicast = stats[EF10_STAT_rx_multicast];
  1546. core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
  1547. core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
  1548. core_stats->rx_errors = core_stats->rx_crc_errors;
  1549. core_stats->tx_errors = stats[EF10_STAT_tx_bad];
  1550. } else {
  1551. /* Use port stats. */
  1552. core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
  1553. core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
  1554. core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
  1555. core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
  1556. core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
  1557. stats[GENERIC_STAT_rx_nodesc_trunc] +
  1558. stats[GENERIC_STAT_rx_noskb_drops];
  1559. core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
  1560. core_stats->rx_length_errors =
  1561. stats[EF10_STAT_port_rx_gtjumbo] +
  1562. stats[EF10_STAT_port_rx_length_error];
  1563. core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
  1564. core_stats->rx_frame_errors =
  1565. stats[EF10_STAT_port_rx_align_error];
  1566. core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
  1567. core_stats->rx_errors = (core_stats->rx_length_errors +
  1568. core_stats->rx_crc_errors +
  1569. core_stats->rx_frame_errors);
  1570. }
  1571. return stats_count;
  1572. }
  1573. static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
  1574. {
  1575. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1576. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1577. __le64 generation_start, generation_end;
  1578. u64 *stats = nic_data->stats;
  1579. __le64 *dma_stats;
  1580. efx_ef10_get_stat_mask(efx, mask);
  1581. dma_stats = efx->stats_buffer.addr;
  1582. generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
  1583. if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
  1584. return 0;
  1585. rmb();
  1586. efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
  1587. stats, efx->stats_buffer.addr, false);
  1588. rmb();
  1589. generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
  1590. if (generation_end != generation_start)
  1591. return -EAGAIN;
  1592. /* Update derived statistics */
  1593. efx_nic_fix_nodesc_drop_stat(efx,
  1594. &stats[EF10_STAT_port_rx_nodesc_drops]);
  1595. stats[EF10_STAT_port_rx_good_bytes] =
  1596. stats[EF10_STAT_port_rx_bytes] -
  1597. stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
  1598. efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
  1599. stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
  1600. efx_update_sw_stats(efx, stats);
  1601. return 0;
  1602. }
  1603. static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
  1604. struct rtnl_link_stats64 *core_stats)
  1605. {
  1606. int retry;
  1607. /* If we're unlucky enough to read statistics during the DMA, wait
  1608. * up to 10ms for it to finish (typically takes <500us)
  1609. */
  1610. for (retry = 0; retry < 100; ++retry) {
  1611. if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
  1612. break;
  1613. udelay(100);
  1614. }
  1615. return efx_ef10_update_stats_common(efx, full_stats, core_stats);
  1616. }
  1617. static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
  1618. {
  1619. MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
  1620. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1621. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1622. __le64 generation_start, generation_end;
  1623. u64 *stats = nic_data->stats;
  1624. u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64);
  1625. struct efx_buffer stats_buf;
  1626. __le64 *dma_stats;
  1627. int rc;
  1628. spin_unlock_bh(&efx->stats_lock);
  1629. if (in_interrupt()) {
  1630. /* If in atomic context, cannot update stats. Just update the
  1631. * software stats and return so the caller can continue.
  1632. */
  1633. spin_lock_bh(&efx->stats_lock);
  1634. efx_update_sw_stats(efx, stats);
  1635. return 0;
  1636. }
  1637. efx_ef10_get_stat_mask(efx, mask);
  1638. rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
  1639. if (rc) {
  1640. spin_lock_bh(&efx->stats_lock);
  1641. return rc;
  1642. }
  1643. dma_stats = stats_buf.addr;
  1644. dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID;
  1645. MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
  1646. MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
  1647. MAC_STATS_IN_DMA, 1);
  1648. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
  1649. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
  1650. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
  1651. NULL, 0, NULL);
  1652. spin_lock_bh(&efx->stats_lock);
  1653. if (rc) {
  1654. /* Expect ENOENT if DMA queues have not been set up */
  1655. if (rc != -ENOENT || atomic_read(&efx->active_queues))
  1656. efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
  1657. sizeof(inbuf), NULL, 0, rc);
  1658. goto out;
  1659. }
  1660. generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
  1661. if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
  1662. WARN_ON_ONCE(1);
  1663. goto out;
  1664. }
  1665. rmb();
  1666. efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
  1667. stats, stats_buf.addr, false);
  1668. rmb();
  1669. generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
  1670. if (generation_end != generation_start) {
  1671. rc = -EAGAIN;
  1672. goto out;
  1673. }
  1674. efx_update_sw_stats(efx, stats);
  1675. out:
  1676. efx_nic_free_buffer(efx, &stats_buf);
  1677. return rc;
  1678. }
  1679. static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
  1680. struct rtnl_link_stats64 *core_stats)
  1681. {
  1682. if (efx_ef10_try_update_nic_stats_vf(efx))
  1683. return 0;
  1684. return efx_ef10_update_stats_common(efx, full_stats, core_stats);
  1685. }
  1686. static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
  1687. {
  1688. struct efx_nic *efx = channel->efx;
  1689. unsigned int mode, usecs;
  1690. efx_dword_t timer_cmd;
  1691. if (channel->irq_moderation_us) {
  1692. mode = 3;
  1693. usecs = channel->irq_moderation_us;
  1694. } else {
  1695. mode = 0;
  1696. usecs = 0;
  1697. }
  1698. if (EFX_EF10_WORKAROUND_61265(efx)) {
  1699. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
  1700. unsigned int ns = usecs * 1000;
  1701. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
  1702. channel->channel);
  1703. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
  1704. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
  1705. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
  1706. efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
  1707. inbuf, sizeof(inbuf), 0, NULL, 0);
  1708. } else if (EFX_EF10_WORKAROUND_35388(efx)) {
  1709. unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
  1710. EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
  1711. EFE_DD_EVQ_IND_TIMER_FLAGS,
  1712. ERF_DD_EVQ_IND_TIMER_MODE, mode,
  1713. ERF_DD_EVQ_IND_TIMER_VAL, ticks);
  1714. efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
  1715. channel->channel);
  1716. } else {
  1717. unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
  1718. EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
  1719. ERF_DZ_TC_TIMER_VAL, ticks);
  1720. efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
  1721. channel->channel);
  1722. }
  1723. }
  1724. static void efx_ef10_get_wol_vf(struct efx_nic *efx,
  1725. struct ethtool_wolinfo *wol) {}
  1726. static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
  1727. {
  1728. return -EOPNOTSUPP;
  1729. }
  1730. static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1731. {
  1732. wol->supported = 0;
  1733. wol->wolopts = 0;
  1734. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1735. }
  1736. static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
  1737. {
  1738. if (type != 0)
  1739. return -EINVAL;
  1740. return 0;
  1741. }
  1742. static void efx_ef10_mcdi_request(struct efx_nic *efx,
  1743. const efx_dword_t *hdr, size_t hdr_len,
  1744. const efx_dword_t *sdu, size_t sdu_len)
  1745. {
  1746. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1747. u8 *pdu = nic_data->mcdi_buf.addr;
  1748. memcpy(pdu, hdr, hdr_len);
  1749. memcpy(pdu + hdr_len, sdu, sdu_len);
  1750. wmb();
  1751. /* The hardware provides 'low' and 'high' (doorbell) registers
  1752. * for passing the 64-bit address of an MCDI request to
  1753. * firmware. However the dwords are swapped by firmware. The
  1754. * least significant bits of the doorbell are then 0 for all
  1755. * MCDI requests due to alignment.
  1756. */
  1757. _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
  1758. ER_DZ_MC_DB_LWRD);
  1759. _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
  1760. ER_DZ_MC_DB_HWRD);
  1761. }
  1762. static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
  1763. {
  1764. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1765. const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
  1766. rmb();
  1767. return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
  1768. }
  1769. static void
  1770. efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
  1771. size_t offset, size_t outlen)
  1772. {
  1773. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1774. const u8 *pdu = nic_data->mcdi_buf.addr;
  1775. memcpy(outbuf, pdu + offset, outlen);
  1776. }
  1777. static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
  1778. {
  1779. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1780. /* All our allocations have been reset */
  1781. efx_ef10_reset_mc_allocations(efx);
  1782. /* The datapath firmware might have been changed */
  1783. nic_data->must_check_datapath_caps = true;
  1784. /* MAC statistics have been cleared on the NIC; clear the local
  1785. * statistic that we update with efx_update_diff_stat().
  1786. */
  1787. nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
  1788. }
  1789. static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
  1790. {
  1791. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1792. int rc;
  1793. rc = efx_ef10_get_warm_boot_count(efx);
  1794. if (rc < 0) {
  1795. /* The firmware is presumably in the process of
  1796. * rebooting. However, we are supposed to report each
  1797. * reboot just once, so we must only do that once we
  1798. * can read and store the updated warm boot count.
  1799. */
  1800. return 0;
  1801. }
  1802. if (rc == nic_data->warm_boot_count)
  1803. return 0;
  1804. nic_data->warm_boot_count = rc;
  1805. efx_ef10_mcdi_reboot_detected(efx);
  1806. return -EIO;
  1807. }
  1808. /* Handle an MSI interrupt
  1809. *
  1810. * Handle an MSI hardware interrupt. This routine schedules event
  1811. * queue processing. No interrupt acknowledgement cycle is necessary.
  1812. * Also, we never need to check that the interrupt is for us, since
  1813. * MSI interrupts cannot be shared.
  1814. */
  1815. static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
  1816. {
  1817. struct efx_msi_context *context = dev_id;
  1818. struct efx_nic *efx = context->efx;
  1819. netif_vdbg(efx, intr, efx->net_dev,
  1820. "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
  1821. if (likely(READ_ONCE(efx->irq_soft_enabled))) {
  1822. /* Note test interrupts */
  1823. if (context->index == efx->irq_level)
  1824. efx->last_irq_cpu = raw_smp_processor_id();
  1825. /* Schedule processing of the channel */
  1826. efx_schedule_channel_irq(efx->channel[context->index]);
  1827. }
  1828. return IRQ_HANDLED;
  1829. }
  1830. static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
  1831. {
  1832. struct efx_nic *efx = dev_id;
  1833. bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
  1834. struct efx_channel *channel;
  1835. efx_dword_t reg;
  1836. u32 queues;
  1837. /* Read the ISR which also ACKs the interrupts */
  1838. efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
  1839. queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
  1840. if (queues == 0)
  1841. return IRQ_NONE;
  1842. if (likely(soft_enabled)) {
  1843. /* Note test interrupts */
  1844. if (queues & (1U << efx->irq_level))
  1845. efx->last_irq_cpu = raw_smp_processor_id();
  1846. efx_for_each_channel(channel, efx) {
  1847. if (queues & 1)
  1848. efx_schedule_channel_irq(channel);
  1849. queues >>= 1;
  1850. }
  1851. }
  1852. netif_vdbg(efx, intr, efx->net_dev,
  1853. "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1854. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1855. return IRQ_HANDLED;
  1856. }
  1857. static int efx_ef10_irq_test_generate(struct efx_nic *efx)
  1858. {
  1859. MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
  1860. if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
  1861. NULL) == 0)
  1862. return -ENOTSUPP;
  1863. BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
  1864. MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
  1865. return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
  1866. inbuf, sizeof(inbuf), NULL, 0, NULL);
  1867. }
  1868. static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
  1869. {
  1870. return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
  1871. (tx_queue->ptr_mask + 1) *
  1872. sizeof(efx_qword_t),
  1873. GFP_KERNEL);
  1874. }
  1875. /* This writes to the TX_DESC_WPTR and also pushes data */
  1876. static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
  1877. const efx_qword_t *txd)
  1878. {
  1879. unsigned int write_ptr;
  1880. efx_oword_t reg;
  1881. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  1882. EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
  1883. reg.qword[0] = *txd;
  1884. efx_writeo_page(tx_queue->efx, &reg,
  1885. ER_DZ_TX_DESC_UPD, tx_queue->queue);
  1886. }
  1887. /* Add Firmware-Assisted TSO v2 option descriptors to a queue.
  1888. */
  1889. static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
  1890. struct sk_buff *skb,
  1891. bool *data_mapped)
  1892. {
  1893. struct efx_tx_buffer *buffer;
  1894. struct tcphdr *tcp;
  1895. struct iphdr *ip;
  1896. u16 ipv4_id;
  1897. u32 seqnum;
  1898. u32 mss;
  1899. EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
  1900. mss = skb_shinfo(skb)->gso_size;
  1901. if (unlikely(mss < 4)) {
  1902. WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
  1903. return -EINVAL;
  1904. }
  1905. ip = ip_hdr(skb);
  1906. if (ip->version == 4) {
  1907. /* Modify IPv4 header if needed. */
  1908. ip->tot_len = 0;
  1909. ip->check = 0;
  1910. ipv4_id = ntohs(ip->id);
  1911. } else {
  1912. /* Modify IPv6 header if needed. */
  1913. struct ipv6hdr *ipv6 = ipv6_hdr(skb);
  1914. ipv6->payload_len = 0;
  1915. ipv4_id = 0;
  1916. }
  1917. tcp = tcp_hdr(skb);
  1918. seqnum = ntohl(tcp->seq);
  1919. buffer = efx_tx_queue_get_insert_buffer(tx_queue);
  1920. buffer->flags = EFX_TX_BUF_OPTION;
  1921. buffer->len = 0;
  1922. buffer->unmap_len = 0;
  1923. EFX_POPULATE_QWORD_5(buffer->option,
  1924. ESF_DZ_TX_DESC_IS_OPT, 1,
  1925. ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
  1926. ESF_DZ_TX_TSO_OPTION_TYPE,
  1927. ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
  1928. ESF_DZ_TX_TSO_IP_ID, ipv4_id,
  1929. ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
  1930. );
  1931. ++tx_queue->insert_count;
  1932. buffer = efx_tx_queue_get_insert_buffer(tx_queue);
  1933. buffer->flags = EFX_TX_BUF_OPTION;
  1934. buffer->len = 0;
  1935. buffer->unmap_len = 0;
  1936. EFX_POPULATE_QWORD_4(buffer->option,
  1937. ESF_DZ_TX_DESC_IS_OPT, 1,
  1938. ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
  1939. ESF_DZ_TX_TSO_OPTION_TYPE,
  1940. ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
  1941. ESF_DZ_TX_TSO_TCP_MSS, mss
  1942. );
  1943. ++tx_queue->insert_count;
  1944. return 0;
  1945. }
  1946. static u32 efx_ef10_tso_versions(struct efx_nic *efx)
  1947. {
  1948. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1949. u32 tso_versions = 0;
  1950. if (nic_data->datapath_caps &
  1951. (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
  1952. tso_versions |= BIT(1);
  1953. if (nic_data->datapath_caps2 &
  1954. (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
  1955. tso_versions |= BIT(2);
  1956. return tso_versions;
  1957. }
  1958. static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
  1959. {
  1960. MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
  1961. EFX_BUF_SIZE));
  1962. bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
  1963. size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
  1964. struct efx_channel *channel = tx_queue->channel;
  1965. struct efx_nic *efx = tx_queue->efx;
  1966. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1967. bool tso_v2 = false;
  1968. size_t inlen;
  1969. dma_addr_t dma_addr;
  1970. efx_qword_t *txd;
  1971. int rc;
  1972. int i;
  1973. BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
  1974. /* TSOv2 is a limited resource that can only be configured on a limited
  1975. * number of queues. TSO without checksum offload is not really a thing,
  1976. * so we only enable it for those queues.
  1977. */
  1978. if (csum_offload && (nic_data->datapath_caps2 &
  1979. (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))) {
  1980. tso_v2 = true;
  1981. netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
  1982. channel->channel);
  1983. }
  1984. MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
  1985. MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
  1986. MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
  1987. MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
  1988. MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
  1989. MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
  1990. dma_addr = tx_queue->txd.buf.dma_addr;
  1991. netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
  1992. tx_queue->queue, entries, (u64)dma_addr);
  1993. for (i = 0; i < entries; ++i) {
  1994. MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
  1995. dma_addr += EFX_BUF_SIZE;
  1996. }
  1997. inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
  1998. do {
  1999. MCDI_POPULATE_DWORD_3(inbuf, INIT_TXQ_IN_FLAGS,
  2000. /* This flag was removed from mcdi_pcol.h for
  2001. * the non-_EXT version of INIT_TXQ. However,
  2002. * firmware still honours it.
  2003. */
  2004. INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
  2005. INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
  2006. INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
  2007. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
  2008. NULL, 0, NULL);
  2009. if (rc == -ENOSPC && tso_v2) {
  2010. /* Retry without TSOv2 if we're short on contexts. */
  2011. tso_v2 = false;
  2012. netif_warn(efx, probe, efx->net_dev,
  2013. "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
  2014. } else if (rc) {
  2015. efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
  2016. MC_CMD_INIT_TXQ_EXT_IN_LEN,
  2017. NULL, 0, rc);
  2018. goto fail;
  2019. }
  2020. } while (rc);
  2021. /* A previous user of this TX queue might have set us up the
  2022. * bomb by writing a descriptor to the TX push collector but
  2023. * not the doorbell. (Each collector belongs to a port, not a
  2024. * queue or function, so cannot easily be reset.) We must
  2025. * attempt to push a no-op descriptor in its place.
  2026. */
  2027. tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
  2028. tx_queue->insert_count = 1;
  2029. txd = efx_tx_desc(tx_queue, 0);
  2030. EFX_POPULATE_QWORD_4(*txd,
  2031. ESF_DZ_TX_DESC_IS_OPT, true,
  2032. ESF_DZ_TX_OPTION_TYPE,
  2033. ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
  2034. ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
  2035. ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
  2036. tx_queue->write_count = 1;
  2037. if (tso_v2) {
  2038. tx_queue->handle_tso = efx_ef10_tx_tso_desc;
  2039. tx_queue->tso_version = 2;
  2040. } else if (nic_data->datapath_caps &
  2041. (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
  2042. tx_queue->tso_version = 1;
  2043. }
  2044. wmb();
  2045. efx_ef10_push_tx_desc(tx_queue, txd);
  2046. return;
  2047. fail:
  2048. netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
  2049. tx_queue->queue);
  2050. }
  2051. static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
  2052. {
  2053. MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
  2054. MCDI_DECLARE_BUF_ERR(outbuf);
  2055. struct efx_nic *efx = tx_queue->efx;
  2056. size_t outlen;
  2057. int rc;
  2058. MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
  2059. tx_queue->queue);
  2060. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
  2061. outbuf, sizeof(outbuf), &outlen);
  2062. if (rc && rc != -EALREADY)
  2063. goto fail;
  2064. return;
  2065. fail:
  2066. efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
  2067. outbuf, outlen, rc);
  2068. }
  2069. static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
  2070. {
  2071. efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
  2072. }
  2073. /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
  2074. static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
  2075. {
  2076. unsigned int write_ptr;
  2077. efx_dword_t reg;
  2078. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  2079. EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
  2080. efx_writed_page(tx_queue->efx, &reg,
  2081. ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
  2082. }
  2083. #define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
  2084. static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
  2085. dma_addr_t dma_addr, unsigned int len)
  2086. {
  2087. if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
  2088. /* If we need to break across multiple descriptors we should
  2089. * stop at a page boundary. This assumes the length limit is
  2090. * greater than the page size.
  2091. */
  2092. dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
  2093. BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
  2094. len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
  2095. }
  2096. return len;
  2097. }
  2098. static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
  2099. {
  2100. unsigned int old_write_count = tx_queue->write_count;
  2101. struct efx_tx_buffer *buffer;
  2102. unsigned int write_ptr;
  2103. efx_qword_t *txd;
  2104. tx_queue->xmit_more_available = false;
  2105. if (unlikely(tx_queue->write_count == tx_queue->insert_count))
  2106. return;
  2107. do {
  2108. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  2109. buffer = &tx_queue->buffer[write_ptr];
  2110. txd = efx_tx_desc(tx_queue, write_ptr);
  2111. ++tx_queue->write_count;
  2112. /* Create TX descriptor ring entry */
  2113. if (buffer->flags & EFX_TX_BUF_OPTION) {
  2114. *txd = buffer->option;
  2115. if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
  2116. /* PIO descriptor */
  2117. tx_queue->packet_write_count = tx_queue->write_count;
  2118. } else {
  2119. tx_queue->packet_write_count = tx_queue->write_count;
  2120. BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
  2121. EFX_POPULATE_QWORD_3(
  2122. *txd,
  2123. ESF_DZ_TX_KER_CONT,
  2124. buffer->flags & EFX_TX_BUF_CONT,
  2125. ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
  2126. ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
  2127. }
  2128. } while (tx_queue->write_count != tx_queue->insert_count);
  2129. wmb(); /* Ensure descriptors are written before they are fetched */
  2130. if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
  2131. txd = efx_tx_desc(tx_queue,
  2132. old_write_count & tx_queue->ptr_mask);
  2133. efx_ef10_push_tx_desc(tx_queue, txd);
  2134. ++tx_queue->pushes;
  2135. } else {
  2136. efx_ef10_notify_tx_desc(tx_queue);
  2137. }
  2138. }
  2139. #define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
  2140. 1 << RSS_MODE_HASH_DST_ADDR_LBN)
  2141. #define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
  2142. 1 << RSS_MODE_HASH_DST_PORT_LBN)
  2143. #define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
  2144. 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
  2145. 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
  2146. 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
  2147. (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
  2148. RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
  2149. RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
  2150. (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
  2151. RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
  2152. RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
  2153. static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
  2154. {
  2155. /* Firmware had a bug (sfc bug 61952) where it would not actually
  2156. * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
  2157. * This meant that it would always contain whatever was previously
  2158. * in the MCDI buffer. Fortunately, all firmware versions with
  2159. * this bug have the same default flags value for a newly-allocated
  2160. * RSS context, and the only time we want to get the flags is just
  2161. * after allocating. Moreover, the response has a 32-bit hole
  2162. * where the context ID would be in the request, so we can use an
  2163. * overlength buffer in the request and pre-fill the flags field
  2164. * with what we believe the default to be. Thus if the firmware
  2165. * has the bug, it will leave our pre-filled value in the flags
  2166. * field of the response, and we will get the right answer.
  2167. *
  2168. * However, this does mean that this function should NOT be used if
  2169. * the RSS context flags might not be their defaults - it is ONLY
  2170. * reliably correct for a newly-allocated RSS context.
  2171. */
  2172. MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
  2173. MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
  2174. size_t outlen;
  2175. int rc;
  2176. /* Check we have a hole for the context ID */
  2177. BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
  2178. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
  2179. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
  2180. RSS_CONTEXT_FLAGS_DEFAULT);
  2181. rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
  2182. sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
  2183. if (rc == 0) {
  2184. if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
  2185. rc = -EIO;
  2186. else
  2187. *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
  2188. }
  2189. return rc;
  2190. }
  2191. /* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
  2192. * If we fail, we just leave the RSS context at its default hash settings,
  2193. * which is safe but may slightly reduce performance.
  2194. * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
  2195. * just need to set the UDP ports flags (for both IP versions).
  2196. */
  2197. static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
  2198. {
  2199. MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
  2200. u32 flags;
  2201. BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
  2202. if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
  2203. return;
  2204. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
  2205. flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
  2206. flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
  2207. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
  2208. if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
  2209. NULL, 0, NULL))
  2210. /* Succeeded, so UDP 4-tuple is now enabled */
  2211. efx->rx_hash_udp_4tuple = true;
  2212. }
  2213. static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
  2214. bool exclusive, unsigned *context_size)
  2215. {
  2216. MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
  2217. MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
  2218. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2219. size_t outlen;
  2220. int rc;
  2221. u32 alloc_type = exclusive ?
  2222. MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
  2223. MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
  2224. unsigned rss_spread = exclusive ?
  2225. efx->rss_spread :
  2226. min(rounddown_pow_of_two(efx->rss_spread),
  2227. EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
  2228. if (!exclusive && rss_spread == 1) {
  2229. *context = EFX_EF10_RSS_CONTEXT_INVALID;
  2230. if (context_size)
  2231. *context_size = 1;
  2232. return 0;
  2233. }
  2234. if (nic_data->datapath_caps &
  2235. 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
  2236. return -EOPNOTSUPP;
  2237. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
  2238. nic_data->vport_id);
  2239. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
  2240. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
  2241. rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
  2242. outbuf, sizeof(outbuf), &outlen);
  2243. if (rc != 0)
  2244. return rc;
  2245. if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
  2246. return -EIO;
  2247. *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
  2248. if (context_size)
  2249. *context_size = rss_spread;
  2250. if (nic_data->datapath_caps &
  2251. 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
  2252. efx_ef10_set_rss_flags(efx, *context);
  2253. return 0;
  2254. }
  2255. static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
  2256. {
  2257. MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
  2258. int rc;
  2259. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
  2260. context);
  2261. rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
  2262. NULL, 0, NULL);
  2263. WARN_ON(rc != 0);
  2264. }
  2265. static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
  2266. const u32 *rx_indir_table, const u8 *key)
  2267. {
  2268. MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
  2269. MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
  2270. int i, rc;
  2271. MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
  2272. context);
  2273. BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
  2274. MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
  2275. /* This iterates over the length of efx->rx_indir_table, but copies
  2276. * bytes from rx_indir_table. That's because the latter is a pointer
  2277. * rather than an array, but should have the same length.
  2278. * The efx->rx_hash_key loop below is similar.
  2279. */
  2280. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
  2281. MCDI_PTR(tablebuf,
  2282. RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
  2283. (u8) rx_indir_table[i];
  2284. rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
  2285. sizeof(tablebuf), NULL, 0, NULL);
  2286. if (rc != 0)
  2287. return rc;
  2288. MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
  2289. context);
  2290. BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
  2291. MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
  2292. for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
  2293. MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
  2294. return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
  2295. sizeof(keybuf), NULL, 0, NULL);
  2296. }
  2297. static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
  2298. {
  2299. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2300. if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
  2301. efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
  2302. nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
  2303. }
  2304. static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
  2305. unsigned *context_size)
  2306. {
  2307. u32 new_rx_rss_context;
  2308. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2309. int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
  2310. false, context_size);
  2311. if (rc != 0)
  2312. return rc;
  2313. nic_data->rx_rss_context = new_rx_rss_context;
  2314. nic_data->rx_rss_context_exclusive = false;
  2315. efx_set_default_rx_indir_table(efx);
  2316. return 0;
  2317. }
  2318. static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
  2319. const u32 *rx_indir_table,
  2320. const u8 *key)
  2321. {
  2322. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2323. int rc;
  2324. u32 new_rx_rss_context;
  2325. if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
  2326. !nic_data->rx_rss_context_exclusive) {
  2327. rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
  2328. true, NULL);
  2329. if (rc == -EOPNOTSUPP)
  2330. return rc;
  2331. else if (rc != 0)
  2332. goto fail1;
  2333. } else {
  2334. new_rx_rss_context = nic_data->rx_rss_context;
  2335. }
  2336. rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
  2337. rx_indir_table, key);
  2338. if (rc != 0)
  2339. goto fail2;
  2340. if (nic_data->rx_rss_context != new_rx_rss_context)
  2341. efx_ef10_rx_free_indir_table(efx);
  2342. nic_data->rx_rss_context = new_rx_rss_context;
  2343. nic_data->rx_rss_context_exclusive = true;
  2344. if (rx_indir_table != efx->rx_indir_table)
  2345. memcpy(efx->rx_indir_table, rx_indir_table,
  2346. sizeof(efx->rx_indir_table));
  2347. if (key != efx->rx_hash_key)
  2348. memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
  2349. return 0;
  2350. fail2:
  2351. if (new_rx_rss_context != nic_data->rx_rss_context)
  2352. efx_ef10_free_rss_context(efx, new_rx_rss_context);
  2353. fail1:
  2354. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  2355. return rc;
  2356. }
  2357. static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
  2358. {
  2359. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2360. MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
  2361. MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
  2362. MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
  2363. size_t outlen;
  2364. int rc, i;
  2365. BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
  2366. MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
  2367. if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
  2368. return -ENOENT;
  2369. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
  2370. nic_data->rx_rss_context);
  2371. BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
  2372. MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
  2373. rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
  2374. tablebuf, sizeof(tablebuf), &outlen);
  2375. if (rc != 0)
  2376. return rc;
  2377. if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
  2378. return -EIO;
  2379. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  2380. efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
  2381. RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
  2382. MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
  2383. nic_data->rx_rss_context);
  2384. BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
  2385. MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
  2386. rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
  2387. keybuf, sizeof(keybuf), &outlen);
  2388. if (rc != 0)
  2389. return rc;
  2390. if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
  2391. return -EIO;
  2392. for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
  2393. efx->rx_hash_key[i] = MCDI_PTR(
  2394. keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
  2395. return 0;
  2396. }
  2397. static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
  2398. const u32 *rx_indir_table,
  2399. const u8 *key)
  2400. {
  2401. int rc;
  2402. if (efx->rss_spread == 1)
  2403. return 0;
  2404. if (!key)
  2405. key = efx->rx_hash_key;
  2406. rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
  2407. if (rc == -ENOBUFS && !user) {
  2408. unsigned context_size;
  2409. bool mismatch = false;
  2410. size_t i;
  2411. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
  2412. i++)
  2413. mismatch = rx_indir_table[i] !=
  2414. ethtool_rxfh_indir_default(i, efx->rss_spread);
  2415. rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
  2416. if (rc == 0) {
  2417. if (context_size != efx->rss_spread)
  2418. netif_warn(efx, probe, efx->net_dev,
  2419. "Could not allocate an exclusive RSS"
  2420. " context; allocated a shared one of"
  2421. " different size."
  2422. " Wanted %u, got %u.\n",
  2423. efx->rss_spread, context_size);
  2424. else if (mismatch)
  2425. netif_warn(efx, probe, efx->net_dev,
  2426. "Could not allocate an exclusive RSS"
  2427. " context; allocated a shared one but"
  2428. " could not apply custom"
  2429. " indirection.\n");
  2430. else
  2431. netif_info(efx, probe, efx->net_dev,
  2432. "Could not allocate an exclusive RSS"
  2433. " context; allocated a shared one.\n");
  2434. }
  2435. }
  2436. return rc;
  2437. }
  2438. static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
  2439. const u32 *rx_indir_table
  2440. __attribute__ ((unused)),
  2441. const u8 *key
  2442. __attribute__ ((unused)))
  2443. {
  2444. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2445. if (user)
  2446. return -EOPNOTSUPP;
  2447. if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
  2448. return 0;
  2449. return efx_ef10_rx_push_shared_rss_config(efx, NULL);
  2450. }
  2451. static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
  2452. {
  2453. return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
  2454. (rx_queue->ptr_mask + 1) *
  2455. sizeof(efx_qword_t),
  2456. GFP_KERNEL);
  2457. }
  2458. static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
  2459. {
  2460. MCDI_DECLARE_BUF(inbuf,
  2461. MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
  2462. EFX_BUF_SIZE));
  2463. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  2464. size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
  2465. struct efx_nic *efx = rx_queue->efx;
  2466. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2467. size_t inlen;
  2468. dma_addr_t dma_addr;
  2469. int rc;
  2470. int i;
  2471. BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
  2472. rx_queue->scatter_n = 0;
  2473. rx_queue->scatter_len = 0;
  2474. MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
  2475. MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
  2476. MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
  2477. MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
  2478. efx_rx_queue_index(rx_queue));
  2479. MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
  2480. INIT_RXQ_IN_FLAG_PREFIX, 1,
  2481. INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
  2482. MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
  2483. MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
  2484. dma_addr = rx_queue->rxd.buf.dma_addr;
  2485. netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
  2486. efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
  2487. for (i = 0; i < entries; ++i) {
  2488. MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
  2489. dma_addr += EFX_BUF_SIZE;
  2490. }
  2491. inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
  2492. rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
  2493. NULL, 0, NULL);
  2494. if (rc)
  2495. netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
  2496. efx_rx_queue_index(rx_queue));
  2497. }
  2498. static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
  2499. {
  2500. MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
  2501. MCDI_DECLARE_BUF_ERR(outbuf);
  2502. struct efx_nic *efx = rx_queue->efx;
  2503. size_t outlen;
  2504. int rc;
  2505. MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
  2506. efx_rx_queue_index(rx_queue));
  2507. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
  2508. outbuf, sizeof(outbuf), &outlen);
  2509. if (rc && rc != -EALREADY)
  2510. goto fail;
  2511. return;
  2512. fail:
  2513. efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
  2514. outbuf, outlen, rc);
  2515. }
  2516. static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
  2517. {
  2518. efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
  2519. }
  2520. /* This creates an entry in the RX descriptor queue */
  2521. static inline void
  2522. efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
  2523. {
  2524. struct efx_rx_buffer *rx_buf;
  2525. efx_qword_t *rxd;
  2526. rxd = efx_rx_desc(rx_queue, index);
  2527. rx_buf = efx_rx_buffer(rx_queue, index);
  2528. EFX_POPULATE_QWORD_2(*rxd,
  2529. ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
  2530. ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
  2531. }
  2532. static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
  2533. {
  2534. struct efx_nic *efx = rx_queue->efx;
  2535. unsigned int write_count;
  2536. efx_dword_t reg;
  2537. /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
  2538. write_count = rx_queue->added_count & ~7;
  2539. if (rx_queue->notified_count == write_count)
  2540. return;
  2541. do
  2542. efx_ef10_build_rx_desc(
  2543. rx_queue,
  2544. rx_queue->notified_count & rx_queue->ptr_mask);
  2545. while (++rx_queue->notified_count != write_count);
  2546. wmb();
  2547. EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
  2548. write_count & rx_queue->ptr_mask);
  2549. efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
  2550. efx_rx_queue_index(rx_queue));
  2551. }
  2552. static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
  2553. static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
  2554. {
  2555. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  2556. MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
  2557. efx_qword_t event;
  2558. EFX_POPULATE_QWORD_2(event,
  2559. ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
  2560. ESF_DZ_EV_DATA, EFX_EF10_REFILL);
  2561. MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
  2562. /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
  2563. * already swapped the data to little-endian order.
  2564. */
  2565. memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
  2566. sizeof(efx_qword_t));
  2567. efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
  2568. inbuf, sizeof(inbuf), 0,
  2569. efx_ef10_rx_defer_refill_complete, 0);
  2570. }
  2571. static void
  2572. efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
  2573. int rc, efx_dword_t *outbuf,
  2574. size_t outlen_actual)
  2575. {
  2576. /* nothing to do */
  2577. }
  2578. static int efx_ef10_ev_probe(struct efx_channel *channel)
  2579. {
  2580. return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
  2581. (channel->eventq_mask + 1) *
  2582. sizeof(efx_qword_t),
  2583. GFP_KERNEL);
  2584. }
  2585. static void efx_ef10_ev_fini(struct efx_channel *channel)
  2586. {
  2587. MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
  2588. MCDI_DECLARE_BUF_ERR(outbuf);
  2589. struct efx_nic *efx = channel->efx;
  2590. size_t outlen;
  2591. int rc;
  2592. MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
  2593. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
  2594. outbuf, sizeof(outbuf), &outlen);
  2595. if (rc && rc != -EALREADY)
  2596. goto fail;
  2597. return;
  2598. fail:
  2599. efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
  2600. outbuf, outlen, rc);
  2601. }
  2602. static int efx_ef10_ev_init(struct efx_channel *channel)
  2603. {
  2604. MCDI_DECLARE_BUF(inbuf,
  2605. MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
  2606. EFX_BUF_SIZE));
  2607. MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
  2608. size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
  2609. struct efx_nic *efx = channel->efx;
  2610. struct efx_ef10_nic_data *nic_data;
  2611. size_t inlen, outlen;
  2612. unsigned int enabled, implemented;
  2613. dma_addr_t dma_addr;
  2614. int rc;
  2615. int i;
  2616. nic_data = efx->nic_data;
  2617. /* Fill event queue with all ones (i.e. empty events) */
  2618. memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
  2619. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
  2620. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
  2621. /* INIT_EVQ expects index in vector table, not absolute */
  2622. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
  2623. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
  2624. MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
  2625. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
  2626. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
  2627. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
  2628. MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
  2629. MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
  2630. if (nic_data->datapath_caps2 &
  2631. 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
  2632. /* Use the new generic approach to specifying event queue
  2633. * configuration, requesting lower latency or higher throughput.
  2634. * The options that actually get used appear in the output.
  2635. */
  2636. MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
  2637. INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
  2638. INIT_EVQ_V2_IN_FLAG_TYPE,
  2639. MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
  2640. } else {
  2641. bool cut_thru = !(nic_data->datapath_caps &
  2642. 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
  2643. MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
  2644. INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
  2645. INIT_EVQ_IN_FLAG_RX_MERGE, 1,
  2646. INIT_EVQ_IN_FLAG_TX_MERGE, 1,
  2647. INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
  2648. }
  2649. dma_addr = channel->eventq.buf.dma_addr;
  2650. for (i = 0; i < entries; ++i) {
  2651. MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
  2652. dma_addr += EFX_BUF_SIZE;
  2653. }
  2654. inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
  2655. rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
  2656. outbuf, sizeof(outbuf), &outlen);
  2657. if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
  2658. netif_dbg(efx, drv, efx->net_dev,
  2659. "Channel %d using event queue flags %08x\n",
  2660. channel->channel,
  2661. MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
  2662. /* IRQ return is ignored */
  2663. if (channel->channel || rc)
  2664. return rc;
  2665. /* Successfully created event queue on channel 0 */
  2666. rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
  2667. if (rc == -ENOSYS) {
  2668. /* GET_WORKAROUNDS was implemented before this workaround,
  2669. * thus it must be unavailable in this firmware.
  2670. */
  2671. nic_data->workaround_26807 = false;
  2672. rc = 0;
  2673. } else if (rc) {
  2674. goto fail;
  2675. } else {
  2676. nic_data->workaround_26807 =
  2677. !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
  2678. if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
  2679. !nic_data->workaround_26807) {
  2680. unsigned int flags;
  2681. rc = efx_mcdi_set_workaround(efx,
  2682. MC_CMD_WORKAROUND_BUG26807,
  2683. true, &flags);
  2684. if (!rc) {
  2685. if (flags &
  2686. 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
  2687. netif_info(efx, drv, efx->net_dev,
  2688. "other functions on NIC have been reset\n");
  2689. /* With MCFW v4.6.x and earlier, the
  2690. * boot count will have incremented,
  2691. * so re-read the warm_boot_count
  2692. * value now to ensure this function
  2693. * doesn't think it has changed next
  2694. * time it checks.
  2695. */
  2696. rc = efx_ef10_get_warm_boot_count(efx);
  2697. if (rc >= 0) {
  2698. nic_data->warm_boot_count = rc;
  2699. rc = 0;
  2700. }
  2701. }
  2702. nic_data->workaround_26807 = true;
  2703. } else if (rc == -EPERM) {
  2704. rc = 0;
  2705. }
  2706. }
  2707. }
  2708. if (!rc)
  2709. return 0;
  2710. fail:
  2711. efx_ef10_ev_fini(channel);
  2712. return rc;
  2713. }
  2714. static void efx_ef10_ev_remove(struct efx_channel *channel)
  2715. {
  2716. efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
  2717. }
  2718. static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
  2719. unsigned int rx_queue_label)
  2720. {
  2721. struct efx_nic *efx = rx_queue->efx;
  2722. netif_info(efx, hw, efx->net_dev,
  2723. "rx event arrived on queue %d labeled as queue %u\n",
  2724. efx_rx_queue_index(rx_queue), rx_queue_label);
  2725. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  2726. }
  2727. static void
  2728. efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
  2729. unsigned int actual, unsigned int expected)
  2730. {
  2731. unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
  2732. struct efx_nic *efx = rx_queue->efx;
  2733. netif_info(efx, hw, efx->net_dev,
  2734. "dropped %d events (index=%d expected=%d)\n",
  2735. dropped, actual, expected);
  2736. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  2737. }
  2738. /* partially received RX was aborted. clean up. */
  2739. static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
  2740. {
  2741. unsigned int rx_desc_ptr;
  2742. netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
  2743. "scattered RX aborted (dropping %u buffers)\n",
  2744. rx_queue->scatter_n);
  2745. rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
  2746. efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
  2747. 0, EFX_RX_PKT_DISCARD);
  2748. rx_queue->removed_count += rx_queue->scatter_n;
  2749. rx_queue->scatter_n = 0;
  2750. rx_queue->scatter_len = 0;
  2751. ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
  2752. }
  2753. static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
  2754. unsigned int n_packets,
  2755. unsigned int rx_encap_hdr,
  2756. unsigned int rx_l3_class,
  2757. unsigned int rx_l4_class,
  2758. const efx_qword_t *event)
  2759. {
  2760. struct efx_nic *efx = channel->efx;
  2761. bool handled = false;
  2762. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
  2763. if (!(efx->net_dev->features & NETIF_F_RXALL)) {
  2764. if (!efx->loopback_selftest)
  2765. channel->n_rx_eth_crc_err += n_packets;
  2766. return EFX_RX_PKT_DISCARD;
  2767. }
  2768. handled = true;
  2769. }
  2770. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
  2771. if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
  2772. rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2773. rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
  2774. rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
  2775. rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
  2776. netdev_WARN(efx->net_dev,
  2777. "invalid class for RX_IPCKSUM_ERR: event="
  2778. EFX_QWORD_FMT "\n",
  2779. EFX_QWORD_VAL(*event));
  2780. if (!efx->loopback_selftest)
  2781. *(rx_encap_hdr ?
  2782. &channel->n_rx_outer_ip_hdr_chksum_err :
  2783. &channel->n_rx_ip_hdr_chksum_err) += n_packets;
  2784. return 0;
  2785. }
  2786. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
  2787. if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
  2788. ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2789. rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
  2790. (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
  2791. rx_l4_class != ESE_FZ_L4_CLASS_UDP))))
  2792. netdev_WARN(efx->net_dev,
  2793. "invalid class for RX_TCPUDP_CKSUM_ERR: event="
  2794. EFX_QWORD_FMT "\n",
  2795. EFX_QWORD_VAL(*event));
  2796. if (!efx->loopback_selftest)
  2797. *(rx_encap_hdr ?
  2798. &channel->n_rx_outer_tcp_udp_chksum_err :
  2799. &channel->n_rx_tcp_udp_chksum_err) += n_packets;
  2800. return 0;
  2801. }
  2802. if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
  2803. if (unlikely(!rx_encap_hdr))
  2804. netdev_WARN(efx->net_dev,
  2805. "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
  2806. EFX_QWORD_FMT "\n",
  2807. EFX_QWORD_VAL(*event));
  2808. else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2809. rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
  2810. rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
  2811. rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
  2812. netdev_WARN(efx->net_dev,
  2813. "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
  2814. EFX_QWORD_FMT "\n",
  2815. EFX_QWORD_VAL(*event));
  2816. if (!efx->loopback_selftest)
  2817. channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
  2818. return 0;
  2819. }
  2820. if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
  2821. if (unlikely(!rx_encap_hdr))
  2822. netdev_WARN(efx->net_dev,
  2823. "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
  2824. EFX_QWORD_FMT "\n",
  2825. EFX_QWORD_VAL(*event));
  2826. else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2827. rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
  2828. (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
  2829. rx_l4_class != ESE_FZ_L4_CLASS_UDP)))
  2830. netdev_WARN(efx->net_dev,
  2831. "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
  2832. EFX_QWORD_FMT "\n",
  2833. EFX_QWORD_VAL(*event));
  2834. if (!efx->loopback_selftest)
  2835. channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
  2836. return 0;
  2837. }
  2838. WARN_ON(!handled); /* No error bits were recognised */
  2839. return 0;
  2840. }
  2841. static int efx_ef10_handle_rx_event(struct efx_channel *channel,
  2842. const efx_qword_t *event)
  2843. {
  2844. unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
  2845. unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
  2846. unsigned int n_descs, n_packets, i;
  2847. struct efx_nic *efx = channel->efx;
  2848. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2849. struct efx_rx_queue *rx_queue;
  2850. efx_qword_t errors;
  2851. bool rx_cont;
  2852. u16 flags = 0;
  2853. if (unlikely(READ_ONCE(efx->reset_pending)))
  2854. return 0;
  2855. /* Basic packet information */
  2856. rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
  2857. next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
  2858. rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
  2859. rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
  2860. rx_l4_class = EFX_QWORD_FIELD(*event, ESF_FZ_RX_L4_CLASS);
  2861. rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
  2862. rx_encap_hdr =
  2863. nic_data->datapath_caps &
  2864. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
  2865. EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
  2866. ESE_EZ_ENCAP_HDR_NONE;
  2867. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
  2868. netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
  2869. EFX_QWORD_FMT "\n",
  2870. EFX_QWORD_VAL(*event));
  2871. rx_queue = efx_channel_get_rx_queue(channel);
  2872. if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
  2873. efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
  2874. n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
  2875. ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
  2876. if (n_descs != rx_queue->scatter_n + 1) {
  2877. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2878. /* detect rx abort */
  2879. if (unlikely(n_descs == rx_queue->scatter_n)) {
  2880. if (rx_queue->scatter_n == 0 || rx_bytes != 0)
  2881. netdev_WARN(efx->net_dev,
  2882. "invalid RX abort: scatter_n=%u event="
  2883. EFX_QWORD_FMT "\n",
  2884. rx_queue->scatter_n,
  2885. EFX_QWORD_VAL(*event));
  2886. efx_ef10_handle_rx_abort(rx_queue);
  2887. return 0;
  2888. }
  2889. /* Check that RX completion merging is valid, i.e.
  2890. * the current firmware supports it and this is a
  2891. * non-scattered packet.
  2892. */
  2893. if (!(nic_data->datapath_caps &
  2894. (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
  2895. rx_queue->scatter_n != 0 || rx_cont) {
  2896. efx_ef10_handle_rx_bad_lbits(
  2897. rx_queue, next_ptr_lbits,
  2898. (rx_queue->removed_count +
  2899. rx_queue->scatter_n + 1) &
  2900. ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
  2901. return 0;
  2902. }
  2903. /* Merged completion for multiple non-scattered packets */
  2904. rx_queue->scatter_n = 1;
  2905. rx_queue->scatter_len = 0;
  2906. n_packets = n_descs;
  2907. ++channel->n_rx_merge_events;
  2908. channel->n_rx_merge_packets += n_packets;
  2909. flags |= EFX_RX_PKT_PREFIX_LEN;
  2910. } else {
  2911. ++rx_queue->scatter_n;
  2912. rx_queue->scatter_len += rx_bytes;
  2913. if (rx_cont)
  2914. return 0;
  2915. n_packets = 1;
  2916. }
  2917. EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
  2918. ESF_DZ_RX_IPCKSUM_ERR, 1,
  2919. ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
  2920. ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
  2921. ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
  2922. EFX_AND_QWORD(errors, *event, errors);
  2923. if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
  2924. flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
  2925. rx_encap_hdr,
  2926. rx_l3_class, rx_l4_class,
  2927. event);
  2928. } else {
  2929. bool tcpudp = rx_l4_class == ESE_FZ_L4_CLASS_TCP ||
  2930. rx_l4_class == ESE_FZ_L4_CLASS_UDP;
  2931. switch (rx_encap_hdr) {
  2932. case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
  2933. flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
  2934. if (tcpudp)
  2935. flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
  2936. break;
  2937. case ESE_EZ_ENCAP_HDR_GRE:
  2938. case ESE_EZ_ENCAP_HDR_NONE:
  2939. if (tcpudp)
  2940. flags |= EFX_RX_PKT_CSUMMED;
  2941. break;
  2942. default:
  2943. netdev_WARN(efx->net_dev,
  2944. "unknown encapsulation type: event="
  2945. EFX_QWORD_FMT "\n",
  2946. EFX_QWORD_VAL(*event));
  2947. }
  2948. }
  2949. if (rx_l4_class == ESE_FZ_L4_CLASS_TCP)
  2950. flags |= EFX_RX_PKT_TCP;
  2951. channel->irq_mod_score += 2 * n_packets;
  2952. /* Handle received packet(s) */
  2953. for (i = 0; i < n_packets; i++) {
  2954. efx_rx_packet(rx_queue,
  2955. rx_queue->removed_count & rx_queue->ptr_mask,
  2956. rx_queue->scatter_n, rx_queue->scatter_len,
  2957. flags);
  2958. rx_queue->removed_count += rx_queue->scatter_n;
  2959. }
  2960. rx_queue->scatter_n = 0;
  2961. rx_queue->scatter_len = 0;
  2962. return n_packets;
  2963. }
  2964. static int
  2965. efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
  2966. {
  2967. struct efx_nic *efx = channel->efx;
  2968. struct efx_tx_queue *tx_queue;
  2969. unsigned int tx_ev_desc_ptr;
  2970. unsigned int tx_ev_q_label;
  2971. int tx_descs = 0;
  2972. if (unlikely(READ_ONCE(efx->reset_pending)))
  2973. return 0;
  2974. if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
  2975. return 0;
  2976. /* Transmit completion */
  2977. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
  2978. tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
  2979. tx_queue = efx_channel_get_tx_queue(channel,
  2980. tx_ev_q_label % EFX_TXQ_TYPES);
  2981. tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
  2982. tx_queue->ptr_mask);
  2983. efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
  2984. return tx_descs;
  2985. }
  2986. static void
  2987. efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
  2988. {
  2989. struct efx_nic *efx = channel->efx;
  2990. int subcode;
  2991. subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
  2992. switch (subcode) {
  2993. case ESE_DZ_DRV_TIMER_EV:
  2994. case ESE_DZ_DRV_WAKE_UP_EV:
  2995. break;
  2996. case ESE_DZ_DRV_START_UP_EV:
  2997. /* event queue init complete. ok. */
  2998. break;
  2999. default:
  3000. netif_err(efx, hw, efx->net_dev,
  3001. "channel %d unknown driver event type %d"
  3002. " (data " EFX_QWORD_FMT ")\n",
  3003. channel->channel, subcode,
  3004. EFX_QWORD_VAL(*event));
  3005. }
  3006. }
  3007. static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
  3008. efx_qword_t *event)
  3009. {
  3010. struct efx_nic *efx = channel->efx;
  3011. u32 subcode;
  3012. subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
  3013. switch (subcode) {
  3014. case EFX_EF10_TEST:
  3015. channel->event_test_cpu = raw_smp_processor_id();
  3016. break;
  3017. case EFX_EF10_REFILL:
  3018. /* The queue must be empty, so we won't receive any rx
  3019. * events, so efx_process_channel() won't refill the
  3020. * queue. Refill it here
  3021. */
  3022. efx_fast_push_rx_descriptors(&channel->rx_queue, true);
  3023. break;
  3024. default:
  3025. netif_err(efx, hw, efx->net_dev,
  3026. "channel %d unknown driver event type %u"
  3027. " (data " EFX_QWORD_FMT ")\n",
  3028. channel->channel, (unsigned) subcode,
  3029. EFX_QWORD_VAL(*event));
  3030. }
  3031. }
  3032. static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
  3033. {
  3034. struct efx_nic *efx = channel->efx;
  3035. efx_qword_t event, *p_event;
  3036. unsigned int read_ptr;
  3037. int ev_code;
  3038. int tx_descs = 0;
  3039. int spent = 0;
  3040. if (quota <= 0)
  3041. return spent;
  3042. read_ptr = channel->eventq_read_ptr;
  3043. for (;;) {
  3044. p_event = efx_event(channel, read_ptr);
  3045. event = *p_event;
  3046. if (!efx_event_present(&event))
  3047. break;
  3048. EFX_SET_QWORD(*p_event);
  3049. ++read_ptr;
  3050. ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
  3051. netif_vdbg(efx, drv, efx->net_dev,
  3052. "processing event on %d " EFX_QWORD_FMT "\n",
  3053. channel->channel, EFX_QWORD_VAL(event));
  3054. switch (ev_code) {
  3055. case ESE_DZ_EV_CODE_MCDI_EV:
  3056. efx_mcdi_process_event(channel, &event);
  3057. break;
  3058. case ESE_DZ_EV_CODE_RX_EV:
  3059. spent += efx_ef10_handle_rx_event(channel, &event);
  3060. if (spent >= quota) {
  3061. /* XXX can we split a merged event to
  3062. * avoid going over-quota?
  3063. */
  3064. spent = quota;
  3065. goto out;
  3066. }
  3067. break;
  3068. case ESE_DZ_EV_CODE_TX_EV:
  3069. tx_descs += efx_ef10_handle_tx_event(channel, &event);
  3070. if (tx_descs > efx->txq_entries) {
  3071. spent = quota;
  3072. goto out;
  3073. } else if (++spent == quota) {
  3074. goto out;
  3075. }
  3076. break;
  3077. case ESE_DZ_EV_CODE_DRIVER_EV:
  3078. efx_ef10_handle_driver_event(channel, &event);
  3079. if (++spent == quota)
  3080. goto out;
  3081. break;
  3082. case EFX_EF10_DRVGEN_EV:
  3083. efx_ef10_handle_driver_generated_event(channel, &event);
  3084. break;
  3085. default:
  3086. netif_err(efx, hw, efx->net_dev,
  3087. "channel %d unknown event type %d"
  3088. " (data " EFX_QWORD_FMT ")\n",
  3089. channel->channel, ev_code,
  3090. EFX_QWORD_VAL(event));
  3091. }
  3092. }
  3093. out:
  3094. channel->eventq_read_ptr = read_ptr;
  3095. return spent;
  3096. }
  3097. static void efx_ef10_ev_read_ack(struct efx_channel *channel)
  3098. {
  3099. struct efx_nic *efx = channel->efx;
  3100. efx_dword_t rptr;
  3101. if (EFX_EF10_WORKAROUND_35388(efx)) {
  3102. BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
  3103. (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
  3104. BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
  3105. (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
  3106. EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
  3107. EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
  3108. ERF_DD_EVQ_IND_RPTR,
  3109. (channel->eventq_read_ptr &
  3110. channel->eventq_mask) >>
  3111. ERF_DD_EVQ_IND_RPTR_WIDTH);
  3112. efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
  3113. channel->channel);
  3114. EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
  3115. EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
  3116. ERF_DD_EVQ_IND_RPTR,
  3117. channel->eventq_read_ptr &
  3118. ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
  3119. efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
  3120. channel->channel);
  3121. } else {
  3122. EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
  3123. channel->eventq_read_ptr &
  3124. channel->eventq_mask);
  3125. efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
  3126. }
  3127. }
  3128. static void efx_ef10_ev_test_generate(struct efx_channel *channel)
  3129. {
  3130. MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
  3131. struct efx_nic *efx = channel->efx;
  3132. efx_qword_t event;
  3133. int rc;
  3134. EFX_POPULATE_QWORD_2(event,
  3135. ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
  3136. ESF_DZ_EV_DATA, EFX_EF10_TEST);
  3137. MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
  3138. /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
  3139. * already swapped the data to little-endian order.
  3140. */
  3141. memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
  3142. sizeof(efx_qword_t));
  3143. rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
  3144. NULL, 0, NULL);
  3145. if (rc != 0)
  3146. goto fail;
  3147. return;
  3148. fail:
  3149. WARN_ON(true);
  3150. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  3151. }
  3152. void efx_ef10_handle_drain_event(struct efx_nic *efx)
  3153. {
  3154. if (atomic_dec_and_test(&efx->active_queues))
  3155. wake_up(&efx->flush_wq);
  3156. WARN_ON(atomic_read(&efx->active_queues) < 0);
  3157. }
  3158. static int efx_ef10_fini_dmaq(struct efx_nic *efx)
  3159. {
  3160. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3161. struct efx_channel *channel;
  3162. struct efx_tx_queue *tx_queue;
  3163. struct efx_rx_queue *rx_queue;
  3164. int pending;
  3165. /* If the MC has just rebooted, the TX/RX queues will have already been
  3166. * torn down, but efx->active_queues needs to be set to zero.
  3167. */
  3168. if (nic_data->must_realloc_vis) {
  3169. atomic_set(&efx->active_queues, 0);
  3170. return 0;
  3171. }
  3172. /* Do not attempt to write to the NIC during EEH recovery */
  3173. if (efx->state != STATE_RECOVERY) {
  3174. efx_for_each_channel(channel, efx) {
  3175. efx_for_each_channel_rx_queue(rx_queue, channel)
  3176. efx_ef10_rx_fini(rx_queue);
  3177. efx_for_each_channel_tx_queue(tx_queue, channel)
  3178. efx_ef10_tx_fini(tx_queue);
  3179. }
  3180. wait_event_timeout(efx->flush_wq,
  3181. atomic_read(&efx->active_queues) == 0,
  3182. msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
  3183. pending = atomic_read(&efx->active_queues);
  3184. if (pending) {
  3185. netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
  3186. pending);
  3187. return -ETIMEDOUT;
  3188. }
  3189. }
  3190. return 0;
  3191. }
  3192. static void efx_ef10_prepare_flr(struct efx_nic *efx)
  3193. {
  3194. atomic_set(&efx->active_queues, 0);
  3195. }
  3196. static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
  3197. const struct efx_filter_spec *right)
  3198. {
  3199. if ((left->match_flags ^ right->match_flags) |
  3200. ((left->flags ^ right->flags) &
  3201. (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
  3202. return false;
  3203. return memcmp(&left->outer_vid, &right->outer_vid,
  3204. sizeof(struct efx_filter_spec) -
  3205. offsetof(struct efx_filter_spec, outer_vid)) == 0;
  3206. }
  3207. static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
  3208. {
  3209. BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
  3210. return jhash2((const u32 *)&spec->outer_vid,
  3211. (sizeof(struct efx_filter_spec) -
  3212. offsetof(struct efx_filter_spec, outer_vid)) / 4,
  3213. 0);
  3214. /* XXX should we randomise the initval? */
  3215. }
  3216. /* Decide whether a filter should be exclusive or else should allow
  3217. * delivery to additional recipients. Currently we decide that
  3218. * filters for specific local unicast MAC and IP addresses are
  3219. * exclusive.
  3220. */
  3221. static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
  3222. {
  3223. if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
  3224. !is_multicast_ether_addr(spec->loc_mac))
  3225. return true;
  3226. if ((spec->match_flags &
  3227. (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
  3228. (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
  3229. if (spec->ether_type == htons(ETH_P_IP) &&
  3230. !ipv4_is_multicast(spec->loc_host[0]))
  3231. return true;
  3232. if (spec->ether_type == htons(ETH_P_IPV6) &&
  3233. ((const u8 *)spec->loc_host)[0] != 0xff)
  3234. return true;
  3235. }
  3236. return false;
  3237. }
  3238. static struct efx_filter_spec *
  3239. efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
  3240. unsigned int filter_idx)
  3241. {
  3242. return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
  3243. ~EFX_EF10_FILTER_FLAGS);
  3244. }
  3245. static unsigned int
  3246. efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
  3247. unsigned int filter_idx)
  3248. {
  3249. return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
  3250. }
  3251. static void
  3252. efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
  3253. unsigned int filter_idx,
  3254. const struct efx_filter_spec *spec,
  3255. unsigned int flags)
  3256. {
  3257. table->entry[filter_idx].spec = (unsigned long)spec | flags;
  3258. }
  3259. static void
  3260. efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
  3261. const struct efx_filter_spec *spec,
  3262. efx_dword_t *inbuf)
  3263. {
  3264. enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
  3265. u32 match_fields = 0, uc_match, mc_match;
  3266. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3267. efx_ef10_filter_is_exclusive(spec) ?
  3268. MC_CMD_FILTER_OP_IN_OP_INSERT :
  3269. MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
  3270. /* Convert match flags and values. Unlike almost
  3271. * everything else in MCDI, these fields are in
  3272. * network byte order.
  3273. */
  3274. #define COPY_VALUE(value, mcdi_field) \
  3275. do { \
  3276. match_fields |= \
  3277. 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
  3278. mcdi_field ## _LBN; \
  3279. BUILD_BUG_ON( \
  3280. MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
  3281. sizeof(value)); \
  3282. memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
  3283. &value, sizeof(value)); \
  3284. } while (0)
  3285. #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
  3286. if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
  3287. COPY_VALUE(spec->gen_field, mcdi_field); \
  3288. }
  3289. /* Handle encap filters first. They will always be mismatch
  3290. * (unknown UC or MC) filters
  3291. */
  3292. if (encap_type) {
  3293. /* ether_type and outer_ip_proto need to be variables
  3294. * because COPY_VALUE wants to memcpy them
  3295. */
  3296. __be16 ether_type =
  3297. htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
  3298. ETH_P_IPV6 : ETH_P_IP);
  3299. u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
  3300. u8 outer_ip_proto;
  3301. switch (encap_type & EFX_ENCAP_TYPES_MASK) {
  3302. case EFX_ENCAP_TYPE_VXLAN:
  3303. vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
  3304. /* fallthrough */
  3305. case EFX_ENCAP_TYPE_GENEVE:
  3306. COPY_VALUE(ether_type, ETHER_TYPE);
  3307. outer_ip_proto = IPPROTO_UDP;
  3308. COPY_VALUE(outer_ip_proto, IP_PROTO);
  3309. /* We always need to set the type field, even
  3310. * though we're not matching on the TNI.
  3311. */
  3312. MCDI_POPULATE_DWORD_1(inbuf,
  3313. FILTER_OP_EXT_IN_VNI_OR_VSID,
  3314. FILTER_OP_EXT_IN_VNI_TYPE,
  3315. vni_type);
  3316. break;
  3317. case EFX_ENCAP_TYPE_NVGRE:
  3318. COPY_VALUE(ether_type, ETHER_TYPE);
  3319. outer_ip_proto = IPPROTO_GRE;
  3320. COPY_VALUE(outer_ip_proto, IP_PROTO);
  3321. break;
  3322. default:
  3323. WARN_ON(1);
  3324. }
  3325. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
  3326. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
  3327. } else {
  3328. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
  3329. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
  3330. }
  3331. if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
  3332. match_fields |=
  3333. is_multicast_ether_addr(spec->loc_mac) ?
  3334. 1 << mc_match :
  3335. 1 << uc_match;
  3336. COPY_FIELD(REM_HOST, rem_host, SRC_IP);
  3337. COPY_FIELD(LOC_HOST, loc_host, DST_IP);
  3338. COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
  3339. COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
  3340. COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
  3341. COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
  3342. COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
  3343. COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
  3344. COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
  3345. COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
  3346. #undef COPY_FIELD
  3347. #undef COPY_VALUE
  3348. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
  3349. match_fields);
  3350. }
  3351. static void efx_ef10_filter_push_prep(struct efx_nic *efx,
  3352. const struct efx_filter_spec *spec,
  3353. efx_dword_t *inbuf, u64 handle,
  3354. bool replacing)
  3355. {
  3356. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3357. u32 flags = spec->flags;
  3358. memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3359. /* Remove RSS flag if we don't have an RSS context. */
  3360. if (flags & EFX_FILTER_FLAG_RX_RSS &&
  3361. spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
  3362. nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
  3363. flags &= ~EFX_FILTER_FLAG_RX_RSS;
  3364. if (replacing) {
  3365. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3366. MC_CMD_FILTER_OP_IN_OP_REPLACE);
  3367. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
  3368. } else {
  3369. efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
  3370. }
  3371. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
  3372. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
  3373. spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
  3374. MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
  3375. MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
  3376. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
  3377. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
  3378. MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
  3379. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
  3380. spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
  3381. 0 : spec->dmaq_id);
  3382. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
  3383. (flags & EFX_FILTER_FLAG_RX_RSS) ?
  3384. MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
  3385. MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
  3386. if (flags & EFX_FILTER_FLAG_RX_RSS)
  3387. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
  3388. spec->rss_context !=
  3389. EFX_FILTER_RSS_CONTEXT_DEFAULT ?
  3390. spec->rss_context : nic_data->rx_rss_context);
  3391. }
  3392. static int efx_ef10_filter_push(struct efx_nic *efx,
  3393. const struct efx_filter_spec *spec,
  3394. u64 *handle, bool replacing)
  3395. {
  3396. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3397. MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
  3398. int rc;
  3399. efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
  3400. rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
  3401. outbuf, sizeof(outbuf), NULL);
  3402. if (rc == 0)
  3403. *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
  3404. if (rc == -ENOSPC)
  3405. rc = -EBUSY; /* to match efx_farch_filter_insert() */
  3406. return rc;
  3407. }
  3408. static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
  3409. {
  3410. enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
  3411. unsigned int match_flags = spec->match_flags;
  3412. unsigned int uc_match, mc_match;
  3413. u32 mcdi_flags = 0;
  3414. #define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
  3415. unsigned int old_match_flags = match_flags; \
  3416. match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
  3417. if (match_flags != old_match_flags) \
  3418. mcdi_flags |= \
  3419. (1 << ((encap) ? \
  3420. MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
  3421. mcdi_field ## _LBN : \
  3422. MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
  3423. mcdi_field ## _LBN)); \
  3424. }
  3425. /* inner or outer based on encap type */
  3426. MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
  3427. MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
  3428. MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
  3429. MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
  3430. MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
  3431. MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
  3432. MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
  3433. MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
  3434. /* always outer */
  3435. MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
  3436. MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
  3437. #undef MAP_FILTER_TO_MCDI_FLAG
  3438. /* special handling for encap type, and mismatch */
  3439. if (encap_type) {
  3440. match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
  3441. mcdi_flags |=
  3442. (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
  3443. mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
  3444. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
  3445. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
  3446. } else {
  3447. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
  3448. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
  3449. }
  3450. if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
  3451. match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
  3452. mcdi_flags |=
  3453. is_multicast_ether_addr(spec->loc_mac) ?
  3454. 1 << mc_match :
  3455. 1 << uc_match;
  3456. }
  3457. /* Did we map them all? */
  3458. WARN_ON_ONCE(match_flags);
  3459. return mcdi_flags;
  3460. }
  3461. static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
  3462. const struct efx_filter_spec *spec)
  3463. {
  3464. u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
  3465. unsigned int match_pri;
  3466. for (match_pri = 0;
  3467. match_pri < table->rx_match_count;
  3468. match_pri++)
  3469. if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
  3470. return match_pri;
  3471. return -EPROTONOSUPPORT;
  3472. }
  3473. static s32 efx_ef10_filter_insert(struct efx_nic *efx,
  3474. struct efx_filter_spec *spec,
  3475. bool replace_equal)
  3476. {
  3477. struct efx_ef10_filter_table *table = efx->filter_state;
  3478. DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
  3479. struct efx_filter_spec *saved_spec;
  3480. unsigned int match_pri, hash;
  3481. unsigned int priv_flags;
  3482. bool replacing = false;
  3483. int ins_index = -1;
  3484. DEFINE_WAIT(wait);
  3485. bool is_mc_recip;
  3486. s32 rc;
  3487. /* For now, only support RX filters */
  3488. if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
  3489. EFX_FILTER_FLAG_RX)
  3490. return -EINVAL;
  3491. rc = efx_ef10_filter_pri(table, spec);
  3492. if (rc < 0)
  3493. return rc;
  3494. match_pri = rc;
  3495. hash = efx_ef10_filter_hash(spec);
  3496. is_mc_recip = efx_filter_is_mc_recipient(spec);
  3497. if (is_mc_recip)
  3498. bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
  3499. /* Find any existing filters with the same match tuple or
  3500. * else a free slot to insert at. If any of them are busy,
  3501. * we have to wait and retry.
  3502. */
  3503. for (;;) {
  3504. unsigned int depth = 1;
  3505. unsigned int i;
  3506. spin_lock_bh(&efx->filter_lock);
  3507. for (;;) {
  3508. i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
  3509. saved_spec = efx_ef10_filter_entry_spec(table, i);
  3510. if (!saved_spec) {
  3511. if (ins_index < 0)
  3512. ins_index = i;
  3513. } else if (efx_ef10_filter_equal(spec, saved_spec)) {
  3514. if (table->entry[i].spec &
  3515. EFX_EF10_FILTER_FLAG_BUSY)
  3516. break;
  3517. if (spec->priority < saved_spec->priority &&
  3518. spec->priority != EFX_FILTER_PRI_AUTO) {
  3519. rc = -EPERM;
  3520. goto out_unlock;
  3521. }
  3522. if (!is_mc_recip) {
  3523. /* This is the only one */
  3524. if (spec->priority ==
  3525. saved_spec->priority &&
  3526. !replace_equal) {
  3527. rc = -EEXIST;
  3528. goto out_unlock;
  3529. }
  3530. ins_index = i;
  3531. goto found;
  3532. } else if (spec->priority >
  3533. saved_spec->priority ||
  3534. (spec->priority ==
  3535. saved_spec->priority &&
  3536. replace_equal)) {
  3537. if (ins_index < 0)
  3538. ins_index = i;
  3539. else
  3540. __set_bit(depth, mc_rem_map);
  3541. }
  3542. }
  3543. /* Once we reach the maximum search depth, use
  3544. * the first suitable slot or return -EBUSY if
  3545. * there was none
  3546. */
  3547. if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
  3548. if (ins_index < 0) {
  3549. rc = -EBUSY;
  3550. goto out_unlock;
  3551. }
  3552. goto found;
  3553. }
  3554. ++depth;
  3555. }
  3556. prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
  3557. spin_unlock_bh(&efx->filter_lock);
  3558. schedule();
  3559. }
  3560. found:
  3561. /* Create a software table entry if necessary, and mark it
  3562. * busy. We might yet fail to insert, but any attempt to
  3563. * insert a conflicting filter while we're waiting for the
  3564. * firmware must find the busy entry.
  3565. */
  3566. saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
  3567. if (saved_spec) {
  3568. if (spec->priority == EFX_FILTER_PRI_AUTO &&
  3569. saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
  3570. /* Just make sure it won't be removed */
  3571. if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
  3572. saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
  3573. table->entry[ins_index].spec &=
  3574. ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
  3575. rc = ins_index;
  3576. goto out_unlock;
  3577. }
  3578. replacing = true;
  3579. priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
  3580. } else {
  3581. saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
  3582. if (!saved_spec) {
  3583. rc = -ENOMEM;
  3584. goto out_unlock;
  3585. }
  3586. *saved_spec = *spec;
  3587. priv_flags = 0;
  3588. }
  3589. efx_ef10_filter_set_entry(table, ins_index, saved_spec,
  3590. priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
  3591. /* Mark lower-priority multicast recipients busy prior to removal */
  3592. if (is_mc_recip) {
  3593. unsigned int depth, i;
  3594. for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
  3595. i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
  3596. if (test_bit(depth, mc_rem_map))
  3597. table->entry[i].spec |=
  3598. EFX_EF10_FILTER_FLAG_BUSY;
  3599. }
  3600. }
  3601. spin_unlock_bh(&efx->filter_lock);
  3602. rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
  3603. replacing);
  3604. /* Finalise the software table entry */
  3605. spin_lock_bh(&efx->filter_lock);
  3606. if (rc == 0) {
  3607. if (replacing) {
  3608. /* Update the fields that may differ */
  3609. if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
  3610. saved_spec->flags |=
  3611. EFX_FILTER_FLAG_RX_OVER_AUTO;
  3612. saved_spec->priority = spec->priority;
  3613. saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
  3614. saved_spec->flags |= spec->flags;
  3615. saved_spec->rss_context = spec->rss_context;
  3616. saved_spec->dmaq_id = spec->dmaq_id;
  3617. }
  3618. } else if (!replacing) {
  3619. kfree(saved_spec);
  3620. saved_spec = NULL;
  3621. }
  3622. efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
  3623. /* Remove and finalise entries for lower-priority multicast
  3624. * recipients
  3625. */
  3626. if (is_mc_recip) {
  3627. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3628. unsigned int depth, i;
  3629. memset(inbuf, 0, sizeof(inbuf));
  3630. for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
  3631. if (!test_bit(depth, mc_rem_map))
  3632. continue;
  3633. i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
  3634. saved_spec = efx_ef10_filter_entry_spec(table, i);
  3635. priv_flags = efx_ef10_filter_entry_flags(table, i);
  3636. if (rc == 0) {
  3637. spin_unlock_bh(&efx->filter_lock);
  3638. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3639. MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
  3640. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  3641. table->entry[i].handle);
  3642. rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
  3643. inbuf, sizeof(inbuf),
  3644. NULL, 0, NULL);
  3645. spin_lock_bh(&efx->filter_lock);
  3646. }
  3647. if (rc == 0) {
  3648. kfree(saved_spec);
  3649. saved_spec = NULL;
  3650. priv_flags = 0;
  3651. } else {
  3652. priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
  3653. }
  3654. efx_ef10_filter_set_entry(table, i, saved_spec,
  3655. priv_flags);
  3656. }
  3657. }
  3658. /* If successful, return the inserted filter ID */
  3659. if (rc == 0)
  3660. rc = efx_ef10_make_filter_id(match_pri, ins_index);
  3661. wake_up_all(&table->waitq);
  3662. out_unlock:
  3663. spin_unlock_bh(&efx->filter_lock);
  3664. finish_wait(&table->waitq, &wait);
  3665. return rc;
  3666. }
  3667. static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
  3668. {
  3669. /* no need to do anything here on EF10 */
  3670. }
  3671. /* Remove a filter.
  3672. * If !by_index, remove by ID
  3673. * If by_index, remove by index
  3674. * Filter ID may come from userland and must be range-checked.
  3675. */
  3676. static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
  3677. unsigned int priority_mask,
  3678. u32 filter_id, bool by_index)
  3679. {
  3680. unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
  3681. struct efx_ef10_filter_table *table = efx->filter_state;
  3682. MCDI_DECLARE_BUF(inbuf,
  3683. MC_CMD_FILTER_OP_IN_HANDLE_OFST +
  3684. MC_CMD_FILTER_OP_IN_HANDLE_LEN);
  3685. struct efx_filter_spec *spec;
  3686. DEFINE_WAIT(wait);
  3687. int rc;
  3688. /* Find the software table entry and mark it busy. Don't
  3689. * remove it yet; any attempt to update while we're waiting
  3690. * for the firmware must find the busy entry.
  3691. */
  3692. for (;;) {
  3693. spin_lock_bh(&efx->filter_lock);
  3694. if (!(table->entry[filter_idx].spec &
  3695. EFX_EF10_FILTER_FLAG_BUSY))
  3696. break;
  3697. prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
  3698. spin_unlock_bh(&efx->filter_lock);
  3699. schedule();
  3700. }
  3701. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  3702. if (!spec ||
  3703. (!by_index &&
  3704. efx_ef10_filter_pri(table, spec) !=
  3705. efx_ef10_filter_get_unsafe_pri(filter_id))) {
  3706. rc = -ENOENT;
  3707. goto out_unlock;
  3708. }
  3709. if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
  3710. priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
  3711. /* Just remove flags */
  3712. spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
  3713. table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
  3714. rc = 0;
  3715. goto out_unlock;
  3716. }
  3717. if (!(priority_mask & (1U << spec->priority))) {
  3718. rc = -ENOENT;
  3719. goto out_unlock;
  3720. }
  3721. table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
  3722. spin_unlock_bh(&efx->filter_lock);
  3723. if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
  3724. /* Reset to an automatic filter */
  3725. struct efx_filter_spec new_spec = *spec;
  3726. new_spec.priority = EFX_FILTER_PRI_AUTO;
  3727. new_spec.flags = (EFX_FILTER_FLAG_RX |
  3728. (efx_rss_enabled(efx) ?
  3729. EFX_FILTER_FLAG_RX_RSS : 0));
  3730. new_spec.dmaq_id = 0;
  3731. new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
  3732. rc = efx_ef10_filter_push(efx, &new_spec,
  3733. &table->entry[filter_idx].handle,
  3734. true);
  3735. spin_lock_bh(&efx->filter_lock);
  3736. if (rc == 0)
  3737. *spec = new_spec;
  3738. } else {
  3739. /* Really remove the filter */
  3740. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3741. efx_ef10_filter_is_exclusive(spec) ?
  3742. MC_CMD_FILTER_OP_IN_OP_REMOVE :
  3743. MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
  3744. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  3745. table->entry[filter_idx].handle);
  3746. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
  3747. inbuf, sizeof(inbuf), NULL, 0, NULL);
  3748. spin_lock_bh(&efx->filter_lock);
  3749. if ((rc == 0) || (rc == -ENOENT)) {
  3750. /* Filter removed OK or didn't actually exist */
  3751. kfree(spec);
  3752. efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
  3753. } else {
  3754. efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
  3755. MC_CMD_FILTER_OP_EXT_IN_LEN,
  3756. NULL, 0, rc);
  3757. }
  3758. }
  3759. table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
  3760. wake_up_all(&table->waitq);
  3761. out_unlock:
  3762. spin_unlock_bh(&efx->filter_lock);
  3763. finish_wait(&table->waitq, &wait);
  3764. return rc;
  3765. }
  3766. static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
  3767. enum efx_filter_priority priority,
  3768. u32 filter_id)
  3769. {
  3770. return efx_ef10_filter_remove_internal(efx, 1U << priority,
  3771. filter_id, false);
  3772. }
  3773. static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
  3774. enum efx_filter_priority priority,
  3775. u32 filter_id)
  3776. {
  3777. if (filter_id == EFX_EF10_FILTER_ID_INVALID)
  3778. return;
  3779. efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
  3780. }
  3781. static int efx_ef10_filter_get_safe(struct efx_nic *efx,
  3782. enum efx_filter_priority priority,
  3783. u32 filter_id, struct efx_filter_spec *spec)
  3784. {
  3785. unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
  3786. struct efx_ef10_filter_table *table = efx->filter_state;
  3787. const struct efx_filter_spec *saved_spec;
  3788. int rc;
  3789. spin_lock_bh(&efx->filter_lock);
  3790. saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
  3791. if (saved_spec && saved_spec->priority == priority &&
  3792. efx_ef10_filter_pri(table, saved_spec) ==
  3793. efx_ef10_filter_get_unsafe_pri(filter_id)) {
  3794. *spec = *saved_spec;
  3795. rc = 0;
  3796. } else {
  3797. rc = -ENOENT;
  3798. }
  3799. spin_unlock_bh(&efx->filter_lock);
  3800. return rc;
  3801. }
  3802. static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
  3803. enum efx_filter_priority priority)
  3804. {
  3805. unsigned int priority_mask;
  3806. unsigned int i;
  3807. int rc;
  3808. priority_mask = (((1U << (priority + 1)) - 1) &
  3809. ~(1U << EFX_FILTER_PRI_AUTO));
  3810. for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
  3811. rc = efx_ef10_filter_remove_internal(efx, priority_mask,
  3812. i, true);
  3813. if (rc && rc != -ENOENT)
  3814. return rc;
  3815. }
  3816. return 0;
  3817. }
  3818. static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
  3819. enum efx_filter_priority priority)
  3820. {
  3821. struct efx_ef10_filter_table *table = efx->filter_state;
  3822. unsigned int filter_idx;
  3823. s32 count = 0;
  3824. spin_lock_bh(&efx->filter_lock);
  3825. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  3826. if (table->entry[filter_idx].spec &&
  3827. efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
  3828. priority)
  3829. ++count;
  3830. }
  3831. spin_unlock_bh(&efx->filter_lock);
  3832. return count;
  3833. }
  3834. static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
  3835. {
  3836. struct efx_ef10_filter_table *table = efx->filter_state;
  3837. return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
  3838. }
  3839. static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
  3840. enum efx_filter_priority priority,
  3841. u32 *buf, u32 size)
  3842. {
  3843. struct efx_ef10_filter_table *table = efx->filter_state;
  3844. struct efx_filter_spec *spec;
  3845. unsigned int filter_idx;
  3846. s32 count = 0;
  3847. spin_lock_bh(&efx->filter_lock);
  3848. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  3849. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  3850. if (spec && spec->priority == priority) {
  3851. if (count == size) {
  3852. count = -EMSGSIZE;
  3853. break;
  3854. }
  3855. buf[count++] =
  3856. efx_ef10_make_filter_id(
  3857. efx_ef10_filter_pri(table, spec),
  3858. filter_idx);
  3859. }
  3860. }
  3861. spin_unlock_bh(&efx->filter_lock);
  3862. return count;
  3863. }
  3864. #ifdef CONFIG_RFS_ACCEL
  3865. static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
  3866. static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
  3867. struct efx_filter_spec *spec)
  3868. {
  3869. struct efx_ef10_filter_table *table = efx->filter_state;
  3870. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3871. struct efx_filter_spec *saved_spec;
  3872. unsigned int hash, i, depth = 1;
  3873. bool replacing = false;
  3874. int ins_index = -1;
  3875. u64 cookie;
  3876. s32 rc;
  3877. /* Must be an RX filter without RSS and not for a multicast
  3878. * destination address (RFS only works for connected sockets).
  3879. * These restrictions allow us to pass only a tiny amount of
  3880. * data through to the completion function.
  3881. */
  3882. EFX_WARN_ON_PARANOID(spec->flags !=
  3883. (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
  3884. EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
  3885. EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
  3886. hash = efx_ef10_filter_hash(spec);
  3887. spin_lock_bh(&efx->filter_lock);
  3888. /* Find any existing filter with the same match tuple or else
  3889. * a free slot to insert at. If an existing filter is busy,
  3890. * we have to give up.
  3891. */
  3892. for (;;) {
  3893. i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
  3894. saved_spec = efx_ef10_filter_entry_spec(table, i);
  3895. if (!saved_spec) {
  3896. if (ins_index < 0)
  3897. ins_index = i;
  3898. } else if (efx_ef10_filter_equal(spec, saved_spec)) {
  3899. if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
  3900. rc = -EBUSY;
  3901. goto fail_unlock;
  3902. }
  3903. if (spec->priority < saved_spec->priority) {
  3904. rc = -EPERM;
  3905. goto fail_unlock;
  3906. }
  3907. ins_index = i;
  3908. break;
  3909. }
  3910. /* Once we reach the maximum search depth, use the
  3911. * first suitable slot or return -EBUSY if there was
  3912. * none
  3913. */
  3914. if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
  3915. if (ins_index < 0) {
  3916. rc = -EBUSY;
  3917. goto fail_unlock;
  3918. }
  3919. break;
  3920. }
  3921. ++depth;
  3922. }
  3923. /* Create a software table entry if necessary, and mark it
  3924. * busy. We might yet fail to insert, but any attempt to
  3925. * insert a conflicting filter while we're waiting for the
  3926. * firmware must find the busy entry.
  3927. */
  3928. saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
  3929. if (saved_spec) {
  3930. replacing = true;
  3931. } else {
  3932. saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
  3933. if (!saved_spec) {
  3934. rc = -ENOMEM;
  3935. goto fail_unlock;
  3936. }
  3937. *saved_spec = *spec;
  3938. }
  3939. efx_ef10_filter_set_entry(table, ins_index, saved_spec,
  3940. EFX_EF10_FILTER_FLAG_BUSY);
  3941. spin_unlock_bh(&efx->filter_lock);
  3942. /* Pack up the variables needed on completion */
  3943. cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
  3944. efx_ef10_filter_push_prep(efx, spec, inbuf,
  3945. table->entry[ins_index].handle, replacing);
  3946. efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
  3947. MC_CMD_FILTER_OP_OUT_LEN,
  3948. efx_ef10_filter_rfs_insert_complete, cookie);
  3949. return ins_index;
  3950. fail_unlock:
  3951. spin_unlock_bh(&efx->filter_lock);
  3952. return rc;
  3953. }
  3954. static void
  3955. efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
  3956. int rc, efx_dword_t *outbuf,
  3957. size_t outlen_actual)
  3958. {
  3959. struct efx_ef10_filter_table *table = efx->filter_state;
  3960. unsigned int ins_index, dmaq_id;
  3961. struct efx_filter_spec *spec;
  3962. bool replacing;
  3963. /* Unpack the cookie */
  3964. replacing = cookie >> 31;
  3965. ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
  3966. dmaq_id = cookie & 0xffff;
  3967. spin_lock_bh(&efx->filter_lock);
  3968. spec = efx_ef10_filter_entry_spec(table, ins_index);
  3969. if (rc == 0) {
  3970. table->entry[ins_index].handle =
  3971. MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
  3972. if (replacing)
  3973. spec->dmaq_id = dmaq_id;
  3974. } else if (!replacing) {
  3975. kfree(spec);
  3976. spec = NULL;
  3977. }
  3978. efx_ef10_filter_set_entry(table, ins_index, spec, 0);
  3979. spin_unlock_bh(&efx->filter_lock);
  3980. wake_up_all(&table->waitq);
  3981. }
  3982. static void
  3983. efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
  3984. unsigned long filter_idx,
  3985. int rc, efx_dword_t *outbuf,
  3986. size_t outlen_actual);
  3987. static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
  3988. unsigned int filter_idx)
  3989. {
  3990. struct efx_ef10_filter_table *table = efx->filter_state;
  3991. struct efx_filter_spec *spec =
  3992. efx_ef10_filter_entry_spec(table, filter_idx);
  3993. MCDI_DECLARE_BUF(inbuf,
  3994. MC_CMD_FILTER_OP_IN_HANDLE_OFST +
  3995. MC_CMD_FILTER_OP_IN_HANDLE_LEN);
  3996. if (!spec ||
  3997. (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
  3998. spec->priority != EFX_FILTER_PRI_HINT ||
  3999. !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
  4000. flow_id, filter_idx))
  4001. return false;
  4002. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  4003. MC_CMD_FILTER_OP_IN_OP_REMOVE);
  4004. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  4005. table->entry[filter_idx].handle);
  4006. if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
  4007. efx_ef10_filter_rfs_expire_complete, filter_idx))
  4008. return false;
  4009. table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
  4010. return true;
  4011. }
  4012. static void
  4013. efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
  4014. unsigned long filter_idx,
  4015. int rc, efx_dword_t *outbuf,
  4016. size_t outlen_actual)
  4017. {
  4018. struct efx_ef10_filter_table *table = efx->filter_state;
  4019. struct efx_filter_spec *spec =
  4020. efx_ef10_filter_entry_spec(table, filter_idx);
  4021. spin_lock_bh(&efx->filter_lock);
  4022. if (rc == 0) {
  4023. kfree(spec);
  4024. efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
  4025. }
  4026. table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
  4027. wake_up_all(&table->waitq);
  4028. spin_unlock_bh(&efx->filter_lock);
  4029. }
  4030. #endif /* CONFIG_RFS_ACCEL */
  4031. static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
  4032. {
  4033. int match_flags = 0;
  4034. #define MAP_FLAG(gen_flag, mcdi_field) do { \
  4035. u32 old_mcdi_flags = mcdi_flags; \
  4036. mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
  4037. mcdi_field ## _LBN); \
  4038. if (mcdi_flags != old_mcdi_flags) \
  4039. match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
  4040. } while (0)
  4041. if (encap) {
  4042. /* encap filters must specify encap type */
  4043. match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
  4044. /* and imply ethertype and ip proto */
  4045. mcdi_flags &=
  4046. ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
  4047. mcdi_flags &=
  4048. ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
  4049. /* VLAN tags refer to the outer packet */
  4050. MAP_FLAG(INNER_VID, INNER_VLAN);
  4051. MAP_FLAG(OUTER_VID, OUTER_VLAN);
  4052. /* everything else refers to the inner packet */
  4053. MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
  4054. MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
  4055. MAP_FLAG(REM_HOST, IFRM_SRC_IP);
  4056. MAP_FLAG(LOC_HOST, IFRM_DST_IP);
  4057. MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
  4058. MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
  4059. MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
  4060. MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
  4061. MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
  4062. MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
  4063. } else {
  4064. MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
  4065. MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
  4066. MAP_FLAG(REM_HOST, SRC_IP);
  4067. MAP_FLAG(LOC_HOST, DST_IP);
  4068. MAP_FLAG(REM_MAC, SRC_MAC);
  4069. MAP_FLAG(REM_PORT, SRC_PORT);
  4070. MAP_FLAG(LOC_MAC, DST_MAC);
  4071. MAP_FLAG(LOC_PORT, DST_PORT);
  4072. MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
  4073. MAP_FLAG(INNER_VID, INNER_VLAN);
  4074. MAP_FLAG(OUTER_VID, OUTER_VLAN);
  4075. MAP_FLAG(IP_PROTO, IP_PROTO);
  4076. }
  4077. #undef MAP_FLAG
  4078. /* Did we map them all? */
  4079. if (mcdi_flags)
  4080. return -EINVAL;
  4081. return match_flags;
  4082. }
  4083. static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
  4084. {
  4085. struct efx_ef10_filter_table *table = efx->filter_state;
  4086. struct efx_ef10_filter_vlan *vlan, *next_vlan;
  4087. /* See comment in efx_ef10_filter_table_remove() */
  4088. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4089. return;
  4090. if (!table)
  4091. return;
  4092. list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
  4093. efx_ef10_filter_del_vlan_internal(efx, vlan);
  4094. }
  4095. static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
  4096. bool encap,
  4097. enum efx_filter_match_flags match_flags)
  4098. {
  4099. unsigned int match_pri;
  4100. int mf;
  4101. for (match_pri = 0;
  4102. match_pri < table->rx_match_count;
  4103. match_pri++) {
  4104. mf = efx_ef10_filter_match_flags_from_mcdi(encap,
  4105. table->rx_match_mcdi_flags[match_pri]);
  4106. if (mf == match_flags)
  4107. return true;
  4108. }
  4109. return false;
  4110. }
  4111. static int
  4112. efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
  4113. struct efx_ef10_filter_table *table,
  4114. bool encap)
  4115. {
  4116. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
  4117. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
  4118. unsigned int pd_match_pri, pd_match_count;
  4119. size_t outlen;
  4120. int rc;
  4121. /* Find out which RX filter types are supported, and their priorities */
  4122. MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
  4123. encap ?
  4124. MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
  4125. MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
  4126. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
  4127. inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
  4128. &outlen);
  4129. if (rc)
  4130. return rc;
  4131. pd_match_count = MCDI_VAR_ARRAY_LEN(
  4132. outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
  4133. for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
  4134. u32 mcdi_flags =
  4135. MCDI_ARRAY_DWORD(
  4136. outbuf,
  4137. GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
  4138. pd_match_pri);
  4139. rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
  4140. if (rc < 0) {
  4141. netif_dbg(efx, probe, efx->net_dev,
  4142. "%s: fw flags %#x pri %u not supported in driver\n",
  4143. __func__, mcdi_flags, pd_match_pri);
  4144. } else {
  4145. netif_dbg(efx, probe, efx->net_dev,
  4146. "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
  4147. __func__, mcdi_flags, pd_match_pri,
  4148. rc, table->rx_match_count);
  4149. table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
  4150. table->rx_match_count++;
  4151. }
  4152. }
  4153. return 0;
  4154. }
  4155. static int efx_ef10_filter_table_probe(struct efx_nic *efx)
  4156. {
  4157. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4158. struct net_device *net_dev = efx->net_dev;
  4159. struct efx_ef10_filter_table *table;
  4160. struct efx_ef10_vlan *vlan;
  4161. int rc;
  4162. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4163. return -EINVAL;
  4164. if (efx->filter_state) /* already probed */
  4165. return 0;
  4166. table = kzalloc(sizeof(*table), GFP_KERNEL);
  4167. if (!table)
  4168. return -ENOMEM;
  4169. table->rx_match_count = 0;
  4170. rc = efx_ef10_filter_table_probe_matches(efx, table, false);
  4171. if (rc)
  4172. goto fail;
  4173. if (nic_data->datapath_caps &
  4174. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
  4175. rc = efx_ef10_filter_table_probe_matches(efx, table, true);
  4176. if (rc)
  4177. goto fail;
  4178. if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
  4179. !(efx_ef10_filter_match_supported(table, false,
  4180. (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
  4181. efx_ef10_filter_match_supported(table, false,
  4182. (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
  4183. netif_info(efx, probe, net_dev,
  4184. "VLAN filters are not supported in this firmware variant\n");
  4185. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4186. efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4187. net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4188. }
  4189. table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
  4190. if (!table->entry) {
  4191. rc = -ENOMEM;
  4192. goto fail;
  4193. }
  4194. table->mc_promisc_last = false;
  4195. table->vlan_filter =
  4196. !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
  4197. INIT_LIST_HEAD(&table->vlan_list);
  4198. efx->filter_state = table;
  4199. init_waitqueue_head(&table->waitq);
  4200. list_for_each_entry(vlan, &nic_data->vlan_list, list) {
  4201. rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
  4202. if (rc)
  4203. goto fail_add_vlan;
  4204. }
  4205. return 0;
  4206. fail_add_vlan:
  4207. efx_ef10_filter_cleanup_vlans(efx);
  4208. efx->filter_state = NULL;
  4209. fail:
  4210. kfree(table);
  4211. return rc;
  4212. }
  4213. /* Caller must hold efx->filter_sem for read if race against
  4214. * efx_ef10_filter_table_remove() is possible
  4215. */
  4216. static void efx_ef10_filter_table_restore(struct efx_nic *efx)
  4217. {
  4218. struct efx_ef10_filter_table *table = efx->filter_state;
  4219. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4220. unsigned int invalid_filters = 0, failed = 0;
  4221. struct efx_ef10_filter_vlan *vlan;
  4222. struct efx_filter_spec *spec;
  4223. unsigned int filter_idx;
  4224. u32 mcdi_flags;
  4225. int match_pri;
  4226. int rc, i;
  4227. WARN_ON(!rwsem_is_locked(&efx->filter_sem));
  4228. if (!nic_data->must_restore_filters)
  4229. return;
  4230. if (!table)
  4231. return;
  4232. spin_lock_bh(&efx->filter_lock);
  4233. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  4234. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  4235. if (!spec)
  4236. continue;
  4237. mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
  4238. match_pri = 0;
  4239. while (match_pri < table->rx_match_count &&
  4240. table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
  4241. ++match_pri;
  4242. if (match_pri >= table->rx_match_count) {
  4243. invalid_filters++;
  4244. goto not_restored;
  4245. }
  4246. if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
  4247. spec->rss_context != nic_data->rx_rss_context)
  4248. netif_warn(efx, drv, efx->net_dev,
  4249. "Warning: unable to restore a filter with specific RSS context.\n");
  4250. table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
  4251. spin_unlock_bh(&efx->filter_lock);
  4252. rc = efx_ef10_filter_push(efx, spec,
  4253. &table->entry[filter_idx].handle,
  4254. false);
  4255. if (rc)
  4256. failed++;
  4257. spin_lock_bh(&efx->filter_lock);
  4258. if (rc) {
  4259. not_restored:
  4260. list_for_each_entry(vlan, &table->vlan_list, list)
  4261. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
  4262. if (vlan->default_filters[i] == filter_idx)
  4263. vlan->default_filters[i] =
  4264. EFX_EF10_FILTER_ID_INVALID;
  4265. kfree(spec);
  4266. efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
  4267. } else {
  4268. table->entry[filter_idx].spec &=
  4269. ~EFX_EF10_FILTER_FLAG_BUSY;
  4270. }
  4271. }
  4272. spin_unlock_bh(&efx->filter_lock);
  4273. /* This can happen validly if the MC's capabilities have changed, so
  4274. * is not an error.
  4275. */
  4276. if (invalid_filters)
  4277. netif_dbg(efx, drv, efx->net_dev,
  4278. "Did not restore %u filters that are now unsupported.\n",
  4279. invalid_filters);
  4280. if (failed)
  4281. netif_err(efx, hw, efx->net_dev,
  4282. "unable to restore %u filters\n", failed);
  4283. else
  4284. nic_data->must_restore_filters = false;
  4285. }
  4286. static void efx_ef10_filter_table_remove(struct efx_nic *efx)
  4287. {
  4288. struct efx_ef10_filter_table *table = efx->filter_state;
  4289. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  4290. struct efx_filter_spec *spec;
  4291. unsigned int filter_idx;
  4292. int rc;
  4293. efx_ef10_filter_cleanup_vlans(efx);
  4294. efx->filter_state = NULL;
  4295. /* If we were called without locking, then it's not safe to free
  4296. * the table as others might be using it. So we just WARN, leak
  4297. * the memory, and potentially get an inconsistent filter table
  4298. * state.
  4299. * This should never actually happen.
  4300. */
  4301. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4302. return;
  4303. if (!table)
  4304. return;
  4305. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  4306. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  4307. if (!spec)
  4308. continue;
  4309. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  4310. efx_ef10_filter_is_exclusive(spec) ?
  4311. MC_CMD_FILTER_OP_IN_OP_REMOVE :
  4312. MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
  4313. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  4314. table->entry[filter_idx].handle);
  4315. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
  4316. sizeof(inbuf), NULL, 0, NULL);
  4317. if (rc)
  4318. netif_info(efx, drv, efx->net_dev,
  4319. "%s: filter %04x remove failed\n",
  4320. __func__, filter_idx);
  4321. kfree(spec);
  4322. }
  4323. vfree(table->entry);
  4324. kfree(table);
  4325. }
  4326. static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
  4327. {
  4328. struct efx_ef10_filter_table *table = efx->filter_state;
  4329. unsigned int filter_idx;
  4330. if (*id != EFX_EF10_FILTER_ID_INVALID) {
  4331. filter_idx = efx_ef10_filter_get_unsafe_id(*id);
  4332. if (!table->entry[filter_idx].spec)
  4333. netif_dbg(efx, drv, efx->net_dev,
  4334. "marked null spec old %04x:%04x\n", *id,
  4335. filter_idx);
  4336. table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
  4337. *id = EFX_EF10_FILTER_ID_INVALID;
  4338. }
  4339. }
  4340. /* Mark old per-VLAN filters that may need to be removed */
  4341. static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
  4342. struct efx_ef10_filter_vlan *vlan)
  4343. {
  4344. struct efx_ef10_filter_table *table = efx->filter_state;
  4345. unsigned int i;
  4346. for (i = 0; i < table->dev_uc_count; i++)
  4347. efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
  4348. for (i = 0; i < table->dev_mc_count; i++)
  4349. efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
  4350. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
  4351. efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
  4352. }
  4353. /* Mark old filters that may need to be removed.
  4354. * Caller must hold efx->filter_sem for read if race against
  4355. * efx_ef10_filter_table_remove() is possible
  4356. */
  4357. static void efx_ef10_filter_mark_old(struct efx_nic *efx)
  4358. {
  4359. struct efx_ef10_filter_table *table = efx->filter_state;
  4360. struct efx_ef10_filter_vlan *vlan;
  4361. spin_lock_bh(&efx->filter_lock);
  4362. list_for_each_entry(vlan, &table->vlan_list, list)
  4363. _efx_ef10_filter_vlan_mark_old(efx, vlan);
  4364. spin_unlock_bh(&efx->filter_lock);
  4365. }
  4366. static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
  4367. {
  4368. struct efx_ef10_filter_table *table = efx->filter_state;
  4369. struct net_device *net_dev = efx->net_dev;
  4370. struct netdev_hw_addr *uc;
  4371. unsigned int i;
  4372. table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
  4373. ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
  4374. i = 1;
  4375. netdev_for_each_uc_addr(uc, net_dev) {
  4376. if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
  4377. table->uc_promisc = true;
  4378. break;
  4379. }
  4380. ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
  4381. i++;
  4382. }
  4383. table->dev_uc_count = i;
  4384. }
  4385. static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
  4386. {
  4387. struct efx_ef10_filter_table *table = efx->filter_state;
  4388. struct net_device *net_dev = efx->net_dev;
  4389. struct netdev_hw_addr *mc;
  4390. unsigned int i;
  4391. table->mc_overflow = false;
  4392. table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
  4393. i = 0;
  4394. netdev_for_each_mc_addr(mc, net_dev) {
  4395. if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
  4396. table->mc_promisc = true;
  4397. table->mc_overflow = true;
  4398. break;
  4399. }
  4400. ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
  4401. i++;
  4402. }
  4403. table->dev_mc_count = i;
  4404. }
  4405. static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
  4406. struct efx_ef10_filter_vlan *vlan,
  4407. bool multicast, bool rollback)
  4408. {
  4409. struct efx_ef10_filter_table *table = efx->filter_state;
  4410. struct efx_ef10_dev_addr *addr_list;
  4411. enum efx_filter_flags filter_flags;
  4412. struct efx_filter_spec spec;
  4413. u8 baddr[ETH_ALEN];
  4414. unsigned int i, j;
  4415. int addr_count;
  4416. u16 *ids;
  4417. int rc;
  4418. if (multicast) {
  4419. addr_list = table->dev_mc_list;
  4420. addr_count = table->dev_mc_count;
  4421. ids = vlan->mc;
  4422. } else {
  4423. addr_list = table->dev_uc_list;
  4424. addr_count = table->dev_uc_count;
  4425. ids = vlan->uc;
  4426. }
  4427. filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
  4428. /* Insert/renew filters */
  4429. for (i = 0; i < addr_count; i++) {
  4430. EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
  4431. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
  4432. efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
  4433. rc = efx_ef10_filter_insert(efx, &spec, true);
  4434. if (rc < 0) {
  4435. if (rollback) {
  4436. netif_info(efx, drv, efx->net_dev,
  4437. "efx_ef10_filter_insert failed rc=%d\n",
  4438. rc);
  4439. /* Fall back to promiscuous */
  4440. for (j = 0; j < i; j++) {
  4441. efx_ef10_filter_remove_unsafe(
  4442. efx, EFX_FILTER_PRI_AUTO,
  4443. ids[j]);
  4444. ids[j] = EFX_EF10_FILTER_ID_INVALID;
  4445. }
  4446. return rc;
  4447. } else {
  4448. /* keep invalid ID, and carry on */
  4449. }
  4450. } else {
  4451. ids[i] = efx_ef10_filter_get_unsafe_id(rc);
  4452. }
  4453. }
  4454. if (multicast && rollback) {
  4455. /* Also need an Ethernet broadcast filter */
  4456. EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
  4457. EFX_EF10_FILTER_ID_INVALID);
  4458. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
  4459. eth_broadcast_addr(baddr);
  4460. efx_filter_set_eth_local(&spec, vlan->vid, baddr);
  4461. rc = efx_ef10_filter_insert(efx, &spec, true);
  4462. if (rc < 0) {
  4463. netif_warn(efx, drv, efx->net_dev,
  4464. "Broadcast filter insert failed rc=%d\n", rc);
  4465. /* Fall back to promiscuous */
  4466. for (j = 0; j < i; j++) {
  4467. efx_ef10_filter_remove_unsafe(
  4468. efx, EFX_FILTER_PRI_AUTO,
  4469. ids[j]);
  4470. ids[j] = EFX_EF10_FILTER_ID_INVALID;
  4471. }
  4472. return rc;
  4473. } else {
  4474. vlan->default_filters[EFX_EF10_BCAST] =
  4475. efx_ef10_filter_get_unsafe_id(rc);
  4476. }
  4477. }
  4478. return 0;
  4479. }
  4480. static int efx_ef10_filter_insert_def(struct efx_nic *efx,
  4481. struct efx_ef10_filter_vlan *vlan,
  4482. enum efx_encap_type encap_type,
  4483. bool multicast, bool rollback)
  4484. {
  4485. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4486. enum efx_filter_flags filter_flags;
  4487. struct efx_filter_spec spec;
  4488. u8 baddr[ETH_ALEN];
  4489. int rc;
  4490. u16 *id;
  4491. filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
  4492. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
  4493. if (multicast)
  4494. efx_filter_set_mc_def(&spec);
  4495. else
  4496. efx_filter_set_uc_def(&spec);
  4497. if (encap_type) {
  4498. if (nic_data->datapath_caps &
  4499. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
  4500. efx_filter_set_encap_type(&spec, encap_type);
  4501. else
  4502. /* don't insert encap filters on non-supporting
  4503. * platforms. ID will be left as INVALID.
  4504. */
  4505. return 0;
  4506. }
  4507. if (vlan->vid != EFX_FILTER_VID_UNSPEC)
  4508. efx_filter_set_eth_local(&spec, vlan->vid, NULL);
  4509. rc = efx_ef10_filter_insert(efx, &spec, true);
  4510. if (rc < 0) {
  4511. const char *um = multicast ? "Multicast" : "Unicast";
  4512. const char *encap_name = "";
  4513. const char *encap_ipv = "";
  4514. if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
  4515. EFX_ENCAP_TYPE_VXLAN)
  4516. encap_name = "VXLAN ";
  4517. else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
  4518. EFX_ENCAP_TYPE_NVGRE)
  4519. encap_name = "NVGRE ";
  4520. else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
  4521. EFX_ENCAP_TYPE_GENEVE)
  4522. encap_name = "GENEVE ";
  4523. if (encap_type & EFX_ENCAP_FLAG_IPV6)
  4524. encap_ipv = "IPv6 ";
  4525. else if (encap_type)
  4526. encap_ipv = "IPv4 ";
  4527. /* unprivileged functions can't insert mismatch filters
  4528. * for encapsulated or unicast traffic, so downgrade
  4529. * those warnings to debug.
  4530. */
  4531. netif_cond_dbg(efx, drv, efx->net_dev,
  4532. rc == -EPERM && (encap_type || !multicast), warn,
  4533. "%s%s%s mismatch filter insert failed rc=%d\n",
  4534. encap_name, encap_ipv, um, rc);
  4535. } else if (multicast) {
  4536. /* mapping from encap types to default filter IDs (multicast) */
  4537. static enum efx_ef10_default_filters map[] = {
  4538. [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
  4539. [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
  4540. [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
  4541. [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
  4542. [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
  4543. EFX_EF10_VXLAN6_MCDEF,
  4544. [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
  4545. EFX_EF10_NVGRE6_MCDEF,
  4546. [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
  4547. EFX_EF10_GENEVE6_MCDEF,
  4548. };
  4549. /* quick bounds check (BCAST result impossible) */
  4550. BUILD_BUG_ON(EFX_EF10_BCAST != 0);
  4551. if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
  4552. WARN_ON(1);
  4553. return -EINVAL;
  4554. }
  4555. /* then follow map */
  4556. id = &vlan->default_filters[map[encap_type]];
  4557. EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
  4558. *id = efx_ef10_filter_get_unsafe_id(rc);
  4559. if (!nic_data->workaround_26807 && !encap_type) {
  4560. /* Also need an Ethernet broadcast filter */
  4561. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
  4562. filter_flags, 0);
  4563. eth_broadcast_addr(baddr);
  4564. efx_filter_set_eth_local(&spec, vlan->vid, baddr);
  4565. rc = efx_ef10_filter_insert(efx, &spec, true);
  4566. if (rc < 0) {
  4567. netif_warn(efx, drv, efx->net_dev,
  4568. "Broadcast filter insert failed rc=%d\n",
  4569. rc);
  4570. if (rollback) {
  4571. /* Roll back the mc_def filter */
  4572. efx_ef10_filter_remove_unsafe(
  4573. efx, EFX_FILTER_PRI_AUTO,
  4574. *id);
  4575. *id = EFX_EF10_FILTER_ID_INVALID;
  4576. return rc;
  4577. }
  4578. } else {
  4579. EFX_WARN_ON_PARANOID(
  4580. vlan->default_filters[EFX_EF10_BCAST] !=
  4581. EFX_EF10_FILTER_ID_INVALID);
  4582. vlan->default_filters[EFX_EF10_BCAST] =
  4583. efx_ef10_filter_get_unsafe_id(rc);
  4584. }
  4585. }
  4586. rc = 0;
  4587. } else {
  4588. /* mapping from encap types to default filter IDs (unicast) */
  4589. static enum efx_ef10_default_filters map[] = {
  4590. [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
  4591. [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
  4592. [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
  4593. [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
  4594. [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
  4595. EFX_EF10_VXLAN6_UCDEF,
  4596. [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
  4597. EFX_EF10_NVGRE6_UCDEF,
  4598. [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
  4599. EFX_EF10_GENEVE6_UCDEF,
  4600. };
  4601. /* quick bounds check (BCAST result impossible) */
  4602. BUILD_BUG_ON(EFX_EF10_BCAST != 0);
  4603. if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
  4604. WARN_ON(1);
  4605. return -EINVAL;
  4606. }
  4607. /* then follow map */
  4608. id = &vlan->default_filters[map[encap_type]];
  4609. EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
  4610. *id = rc;
  4611. rc = 0;
  4612. }
  4613. return rc;
  4614. }
  4615. /* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
  4616. * flag or removes these filters, we don't need to hold the filter_lock while
  4617. * scanning for these filters.
  4618. */
  4619. static void efx_ef10_filter_remove_old(struct efx_nic *efx)
  4620. {
  4621. struct efx_ef10_filter_table *table = efx->filter_state;
  4622. int remove_failed = 0;
  4623. int remove_noent = 0;
  4624. int rc;
  4625. int i;
  4626. for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
  4627. if (READ_ONCE(table->entry[i].spec) &
  4628. EFX_EF10_FILTER_FLAG_AUTO_OLD) {
  4629. rc = efx_ef10_filter_remove_internal(efx,
  4630. 1U << EFX_FILTER_PRI_AUTO, i, true);
  4631. if (rc == -ENOENT)
  4632. remove_noent++;
  4633. else if (rc)
  4634. remove_failed++;
  4635. }
  4636. }
  4637. if (remove_failed)
  4638. netif_info(efx, drv, efx->net_dev,
  4639. "%s: failed to remove %d filters\n",
  4640. __func__, remove_failed);
  4641. if (remove_noent)
  4642. netif_info(efx, drv, efx->net_dev,
  4643. "%s: failed to remove %d non-existent filters\n",
  4644. __func__, remove_noent);
  4645. }
  4646. static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
  4647. {
  4648. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4649. u8 mac_old[ETH_ALEN];
  4650. int rc, rc2;
  4651. /* Only reconfigure a PF-created vport */
  4652. if (is_zero_ether_addr(nic_data->vport_mac))
  4653. return 0;
  4654. efx_device_detach_sync(efx);
  4655. efx_net_stop(efx->net_dev);
  4656. down_write(&efx->filter_sem);
  4657. efx_ef10_filter_table_remove(efx);
  4658. up_write(&efx->filter_sem);
  4659. rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
  4660. if (rc)
  4661. goto restore_filters;
  4662. ether_addr_copy(mac_old, nic_data->vport_mac);
  4663. rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
  4664. nic_data->vport_mac);
  4665. if (rc)
  4666. goto restore_vadaptor;
  4667. rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
  4668. efx->net_dev->dev_addr);
  4669. if (!rc) {
  4670. ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
  4671. } else {
  4672. rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
  4673. if (rc2) {
  4674. /* Failed to add original MAC, so clear vport_mac */
  4675. eth_zero_addr(nic_data->vport_mac);
  4676. goto reset_nic;
  4677. }
  4678. }
  4679. restore_vadaptor:
  4680. rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
  4681. if (rc2)
  4682. goto reset_nic;
  4683. restore_filters:
  4684. down_write(&efx->filter_sem);
  4685. rc2 = efx_ef10_filter_table_probe(efx);
  4686. up_write(&efx->filter_sem);
  4687. if (rc2)
  4688. goto reset_nic;
  4689. rc2 = efx_net_open(efx->net_dev);
  4690. if (rc2)
  4691. goto reset_nic;
  4692. efx_device_attach_if_not_resetting(efx);
  4693. return rc;
  4694. reset_nic:
  4695. netif_err(efx, drv, efx->net_dev,
  4696. "Failed to restore when changing MAC address - scheduling reset\n");
  4697. efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
  4698. return rc ? rc : rc2;
  4699. }
  4700. /* Caller must hold efx->filter_sem for read if race against
  4701. * efx_ef10_filter_table_remove() is possible
  4702. */
  4703. static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
  4704. struct efx_ef10_filter_vlan *vlan)
  4705. {
  4706. struct efx_ef10_filter_table *table = efx->filter_state;
  4707. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4708. /* Do not install unspecified VID if VLAN filtering is enabled.
  4709. * Do not install all specified VIDs if VLAN filtering is disabled.
  4710. */
  4711. if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
  4712. return;
  4713. /* Insert/renew unicast filters */
  4714. if (table->uc_promisc) {
  4715. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
  4716. false, false);
  4717. efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
  4718. } else {
  4719. /* If any of the filters failed to insert, fall back to
  4720. * promiscuous mode - add in the uc_def filter. But keep
  4721. * our individual unicast filters.
  4722. */
  4723. if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
  4724. efx_ef10_filter_insert_def(efx, vlan,
  4725. EFX_ENCAP_TYPE_NONE,
  4726. false, false);
  4727. }
  4728. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
  4729. false, false);
  4730. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
  4731. EFX_ENCAP_FLAG_IPV6,
  4732. false, false);
  4733. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
  4734. false, false);
  4735. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
  4736. EFX_ENCAP_FLAG_IPV6,
  4737. false, false);
  4738. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
  4739. false, false);
  4740. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
  4741. EFX_ENCAP_FLAG_IPV6,
  4742. false, false);
  4743. /* Insert/renew multicast filters */
  4744. /* If changing promiscuous state with cascaded multicast filters, remove
  4745. * old filters first, so that packets are dropped rather than duplicated
  4746. */
  4747. if (nic_data->workaround_26807 &&
  4748. table->mc_promisc_last != table->mc_promisc)
  4749. efx_ef10_filter_remove_old(efx);
  4750. if (table->mc_promisc) {
  4751. if (nic_data->workaround_26807) {
  4752. /* If we failed to insert promiscuous filters, rollback
  4753. * and fall back to individual multicast filters
  4754. */
  4755. if (efx_ef10_filter_insert_def(efx, vlan,
  4756. EFX_ENCAP_TYPE_NONE,
  4757. true, true)) {
  4758. /* Changing promisc state, so remove old filters */
  4759. efx_ef10_filter_remove_old(efx);
  4760. efx_ef10_filter_insert_addr_list(efx, vlan,
  4761. true, false);
  4762. }
  4763. } else {
  4764. /* If we failed to insert promiscuous filters, don't
  4765. * rollback. Regardless, also insert the mc_list,
  4766. * unless it's incomplete due to overflow
  4767. */
  4768. efx_ef10_filter_insert_def(efx, vlan,
  4769. EFX_ENCAP_TYPE_NONE,
  4770. true, false);
  4771. if (!table->mc_overflow)
  4772. efx_ef10_filter_insert_addr_list(efx, vlan,
  4773. true, false);
  4774. }
  4775. } else {
  4776. /* If any filters failed to insert, rollback and fall back to
  4777. * promiscuous mode - mc_def filter and maybe broadcast. If
  4778. * that fails, roll back again and insert as many of our
  4779. * individual multicast filters as we can.
  4780. */
  4781. if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
  4782. /* Changing promisc state, so remove old filters */
  4783. if (nic_data->workaround_26807)
  4784. efx_ef10_filter_remove_old(efx);
  4785. if (efx_ef10_filter_insert_def(efx, vlan,
  4786. EFX_ENCAP_TYPE_NONE,
  4787. true, true))
  4788. efx_ef10_filter_insert_addr_list(efx, vlan,
  4789. true, false);
  4790. }
  4791. }
  4792. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
  4793. true, false);
  4794. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
  4795. EFX_ENCAP_FLAG_IPV6,
  4796. true, false);
  4797. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
  4798. true, false);
  4799. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
  4800. EFX_ENCAP_FLAG_IPV6,
  4801. true, false);
  4802. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
  4803. true, false);
  4804. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
  4805. EFX_ENCAP_FLAG_IPV6,
  4806. true, false);
  4807. }
  4808. /* Caller must hold efx->filter_sem for read if race against
  4809. * efx_ef10_filter_table_remove() is possible
  4810. */
  4811. static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
  4812. {
  4813. struct efx_ef10_filter_table *table = efx->filter_state;
  4814. struct net_device *net_dev = efx->net_dev;
  4815. struct efx_ef10_filter_vlan *vlan;
  4816. bool vlan_filter;
  4817. if (!efx_dev_registered(efx))
  4818. return;
  4819. if (!table)
  4820. return;
  4821. efx_ef10_filter_mark_old(efx);
  4822. /* Copy/convert the address lists; add the primary station
  4823. * address and broadcast address
  4824. */
  4825. netif_addr_lock_bh(net_dev);
  4826. efx_ef10_filter_uc_addr_list(efx);
  4827. efx_ef10_filter_mc_addr_list(efx);
  4828. netif_addr_unlock_bh(net_dev);
  4829. /* If VLAN filtering changes, all old filters are finally removed.
  4830. * Do it in advance to avoid conflicts for unicast untagged and
  4831. * VLAN 0 tagged filters.
  4832. */
  4833. vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
  4834. if (table->vlan_filter != vlan_filter) {
  4835. table->vlan_filter = vlan_filter;
  4836. efx_ef10_filter_remove_old(efx);
  4837. }
  4838. list_for_each_entry(vlan, &table->vlan_list, list)
  4839. efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
  4840. efx_ef10_filter_remove_old(efx);
  4841. table->mc_promisc_last = table->mc_promisc;
  4842. }
  4843. static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
  4844. {
  4845. struct efx_ef10_filter_table *table = efx->filter_state;
  4846. struct efx_ef10_filter_vlan *vlan;
  4847. WARN_ON(!rwsem_is_locked(&efx->filter_sem));
  4848. list_for_each_entry(vlan, &table->vlan_list, list) {
  4849. if (vlan->vid == vid)
  4850. return vlan;
  4851. }
  4852. return NULL;
  4853. }
  4854. static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
  4855. {
  4856. struct efx_ef10_filter_table *table = efx->filter_state;
  4857. struct efx_ef10_filter_vlan *vlan;
  4858. unsigned int i;
  4859. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4860. return -EINVAL;
  4861. vlan = efx_ef10_filter_find_vlan(efx, vid);
  4862. if (WARN_ON(vlan)) {
  4863. netif_err(efx, drv, efx->net_dev,
  4864. "VLAN %u already added\n", vid);
  4865. return -EALREADY;
  4866. }
  4867. vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
  4868. if (!vlan)
  4869. return -ENOMEM;
  4870. vlan->vid = vid;
  4871. for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
  4872. vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
  4873. for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
  4874. vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
  4875. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
  4876. vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
  4877. list_add_tail(&vlan->list, &table->vlan_list);
  4878. if (efx_dev_registered(efx))
  4879. efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
  4880. return 0;
  4881. }
  4882. static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
  4883. struct efx_ef10_filter_vlan *vlan)
  4884. {
  4885. unsigned int i;
  4886. /* See comment in efx_ef10_filter_table_remove() */
  4887. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4888. return;
  4889. list_del(&vlan->list);
  4890. for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
  4891. efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
  4892. vlan->uc[i]);
  4893. for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
  4894. efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
  4895. vlan->mc[i]);
  4896. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
  4897. if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
  4898. efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
  4899. vlan->default_filters[i]);
  4900. kfree(vlan);
  4901. }
  4902. static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
  4903. {
  4904. struct efx_ef10_filter_vlan *vlan;
  4905. /* See comment in efx_ef10_filter_table_remove() */
  4906. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4907. return;
  4908. vlan = efx_ef10_filter_find_vlan(efx, vid);
  4909. if (!vlan) {
  4910. netif_err(efx, drv, efx->net_dev,
  4911. "VLAN %u not found in filter state\n", vid);
  4912. return;
  4913. }
  4914. efx_ef10_filter_del_vlan_internal(efx, vlan);
  4915. }
  4916. static int efx_ef10_set_mac_address(struct efx_nic *efx)
  4917. {
  4918. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
  4919. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4920. bool was_enabled = efx->port_enabled;
  4921. int rc;
  4922. efx_device_detach_sync(efx);
  4923. efx_net_stop(efx->net_dev);
  4924. mutex_lock(&efx->mac_lock);
  4925. down_write(&efx->filter_sem);
  4926. efx_ef10_filter_table_remove(efx);
  4927. ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
  4928. efx->net_dev->dev_addr);
  4929. MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
  4930. nic_data->vport_id);
  4931. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
  4932. sizeof(inbuf), NULL, 0, NULL);
  4933. efx_ef10_filter_table_probe(efx);
  4934. up_write(&efx->filter_sem);
  4935. mutex_unlock(&efx->mac_lock);
  4936. if (was_enabled)
  4937. efx_net_open(efx->net_dev);
  4938. efx_device_attach_if_not_resetting(efx);
  4939. #ifdef CONFIG_SFC_SRIOV
  4940. if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
  4941. struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
  4942. if (rc == -EPERM) {
  4943. struct efx_nic *efx_pf;
  4944. /* Switch to PF and change MAC address on vport */
  4945. efx_pf = pci_get_drvdata(pci_dev_pf);
  4946. rc = efx_ef10_sriov_set_vf_mac(efx_pf,
  4947. nic_data->vf_index,
  4948. efx->net_dev->dev_addr);
  4949. } else if (!rc) {
  4950. struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
  4951. struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
  4952. unsigned int i;
  4953. /* MAC address successfully changed by VF (with MAC
  4954. * spoofing) so update the parent PF if possible.
  4955. */
  4956. for (i = 0; i < efx_pf->vf_count; ++i) {
  4957. struct ef10_vf *vf = nic_data->vf + i;
  4958. if (vf->efx == efx) {
  4959. ether_addr_copy(vf->mac,
  4960. efx->net_dev->dev_addr);
  4961. return 0;
  4962. }
  4963. }
  4964. }
  4965. } else
  4966. #endif
  4967. if (rc == -EPERM) {
  4968. netif_err(efx, drv, efx->net_dev,
  4969. "Cannot change MAC address; use sfboot to enable"
  4970. " mac-spoofing on this interface\n");
  4971. } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
  4972. /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
  4973. * fall-back to the method of changing the MAC address on the
  4974. * vport. This only applies to PFs because such versions of
  4975. * MCFW do not support VFs.
  4976. */
  4977. rc = efx_ef10_vport_set_mac_address(efx);
  4978. } else if (rc) {
  4979. efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
  4980. sizeof(inbuf), NULL, 0, rc);
  4981. }
  4982. return rc;
  4983. }
  4984. static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
  4985. {
  4986. efx_ef10_filter_sync_rx_mode(efx);
  4987. return efx_mcdi_set_mac(efx);
  4988. }
  4989. static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
  4990. {
  4991. efx_ef10_filter_sync_rx_mode(efx);
  4992. return 0;
  4993. }
  4994. static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
  4995. {
  4996. MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
  4997. MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
  4998. return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
  4999. NULL, 0, NULL);
  5000. }
  5001. /* MC BISTs follow a different poll mechanism to phy BISTs.
  5002. * The BIST is done in the poll handler on the MC, and the MCDI command
  5003. * will block until the BIST is done.
  5004. */
  5005. static int efx_ef10_poll_bist(struct efx_nic *efx)
  5006. {
  5007. int rc;
  5008. MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
  5009. size_t outlen;
  5010. u32 result;
  5011. rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
  5012. outbuf, sizeof(outbuf), &outlen);
  5013. if (rc != 0)
  5014. return rc;
  5015. if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
  5016. return -EIO;
  5017. result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
  5018. switch (result) {
  5019. case MC_CMD_POLL_BIST_PASSED:
  5020. netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
  5021. return 0;
  5022. case MC_CMD_POLL_BIST_TIMEOUT:
  5023. netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
  5024. return -EIO;
  5025. case MC_CMD_POLL_BIST_FAILED:
  5026. netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
  5027. return -EIO;
  5028. default:
  5029. netif_err(efx, hw, efx->net_dev,
  5030. "BIST returned unknown result %u", result);
  5031. return -EIO;
  5032. }
  5033. }
  5034. static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
  5035. {
  5036. int rc;
  5037. netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
  5038. rc = efx_ef10_start_bist(efx, bist_type);
  5039. if (rc != 0)
  5040. return rc;
  5041. return efx_ef10_poll_bist(efx);
  5042. }
  5043. static int
  5044. efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  5045. {
  5046. int rc, rc2;
  5047. efx_reset_down(efx, RESET_TYPE_WORLD);
  5048. rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
  5049. NULL, 0, NULL, 0, NULL);
  5050. if (rc != 0)
  5051. goto out;
  5052. tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
  5053. tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
  5054. rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
  5055. out:
  5056. if (rc == -EPERM)
  5057. rc = 0;
  5058. rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
  5059. return rc ? rc : rc2;
  5060. }
  5061. #ifdef CONFIG_SFC_MTD
  5062. struct efx_ef10_nvram_type_info {
  5063. u16 type, type_mask;
  5064. u8 port;
  5065. const char *name;
  5066. };
  5067. static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
  5068. { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
  5069. { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
  5070. { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
  5071. { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
  5072. { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
  5073. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
  5074. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
  5075. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
  5076. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
  5077. { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
  5078. { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
  5079. };
  5080. static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
  5081. struct efx_mcdi_mtd_partition *part,
  5082. unsigned int type)
  5083. {
  5084. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
  5085. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
  5086. const struct efx_ef10_nvram_type_info *info;
  5087. size_t size, erase_size, outlen;
  5088. bool protected;
  5089. int rc;
  5090. for (info = efx_ef10_nvram_types; ; info++) {
  5091. if (info ==
  5092. efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
  5093. return -ENODEV;
  5094. if ((type & ~info->type_mask) == info->type)
  5095. break;
  5096. }
  5097. if (info->port != efx_port_num(efx))
  5098. return -ENODEV;
  5099. rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
  5100. if (rc)
  5101. return rc;
  5102. if (protected)
  5103. return -ENODEV; /* hide it */
  5104. part->nvram_type = type;
  5105. MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
  5106. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
  5107. outbuf, sizeof(outbuf), &outlen);
  5108. if (rc)
  5109. return rc;
  5110. if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
  5111. return -EIO;
  5112. if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
  5113. (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
  5114. part->fw_subtype = MCDI_DWORD(outbuf,
  5115. NVRAM_METADATA_OUT_SUBTYPE);
  5116. part->common.dev_type_name = "EF10 NVRAM manager";
  5117. part->common.type_name = info->name;
  5118. part->common.mtd.type = MTD_NORFLASH;
  5119. part->common.mtd.flags = MTD_CAP_NORFLASH;
  5120. part->common.mtd.size = size;
  5121. part->common.mtd.erasesize = erase_size;
  5122. return 0;
  5123. }
  5124. static int efx_ef10_mtd_probe(struct efx_nic *efx)
  5125. {
  5126. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
  5127. struct efx_mcdi_mtd_partition *parts;
  5128. size_t outlen, n_parts_total, i, n_parts;
  5129. unsigned int type;
  5130. int rc;
  5131. ASSERT_RTNL();
  5132. BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
  5133. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
  5134. outbuf, sizeof(outbuf), &outlen);
  5135. if (rc)
  5136. return rc;
  5137. if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
  5138. return -EIO;
  5139. n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
  5140. if (n_parts_total >
  5141. MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
  5142. return -EIO;
  5143. parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
  5144. if (!parts)
  5145. return -ENOMEM;
  5146. n_parts = 0;
  5147. for (i = 0; i < n_parts_total; i++) {
  5148. type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
  5149. i);
  5150. rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
  5151. if (rc == 0)
  5152. n_parts++;
  5153. else if (rc != -ENODEV)
  5154. goto fail;
  5155. }
  5156. rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
  5157. fail:
  5158. if (rc)
  5159. kfree(parts);
  5160. return rc;
  5161. }
  5162. #endif /* CONFIG_SFC_MTD */
  5163. static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
  5164. {
  5165. _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
  5166. }
  5167. static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
  5168. u32 host_time) {}
  5169. static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
  5170. bool temp)
  5171. {
  5172. MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
  5173. int rc;
  5174. if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
  5175. channel->sync_events_state == SYNC_EVENTS_VALID ||
  5176. (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
  5177. return 0;
  5178. channel->sync_events_state = SYNC_EVENTS_REQUESTED;
  5179. MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
  5180. MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
  5181. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
  5182. channel->channel);
  5183. rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
  5184. inbuf, sizeof(inbuf), NULL, 0, NULL);
  5185. if (rc != 0)
  5186. channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
  5187. SYNC_EVENTS_DISABLED;
  5188. return rc;
  5189. }
  5190. static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
  5191. bool temp)
  5192. {
  5193. MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
  5194. int rc;
  5195. if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
  5196. (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
  5197. return 0;
  5198. if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
  5199. channel->sync_events_state = SYNC_EVENTS_DISABLED;
  5200. return 0;
  5201. }
  5202. channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
  5203. SYNC_EVENTS_DISABLED;
  5204. MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
  5205. MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
  5206. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
  5207. MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
  5208. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
  5209. channel->channel);
  5210. rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
  5211. inbuf, sizeof(inbuf), NULL, 0, NULL);
  5212. return rc;
  5213. }
  5214. static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
  5215. bool temp)
  5216. {
  5217. int (*set)(struct efx_channel *channel, bool temp);
  5218. struct efx_channel *channel;
  5219. set = en ?
  5220. efx_ef10_rx_enable_timestamping :
  5221. efx_ef10_rx_disable_timestamping;
  5222. efx_for_each_channel(channel, efx) {
  5223. int rc = set(channel, temp);
  5224. if (en && rc != 0) {
  5225. efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
  5226. return rc;
  5227. }
  5228. }
  5229. return 0;
  5230. }
  5231. static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
  5232. struct hwtstamp_config *init)
  5233. {
  5234. return -EOPNOTSUPP;
  5235. }
  5236. static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
  5237. struct hwtstamp_config *init)
  5238. {
  5239. int rc;
  5240. switch (init->rx_filter) {
  5241. case HWTSTAMP_FILTER_NONE:
  5242. efx_ef10_ptp_set_ts_sync_events(efx, false, false);
  5243. /* if TX timestamping is still requested then leave PTP on */
  5244. return efx_ptp_change_mode(efx,
  5245. init->tx_type != HWTSTAMP_TX_OFF, 0);
  5246. case HWTSTAMP_FILTER_ALL:
  5247. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  5248. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  5249. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  5250. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  5251. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5252. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5253. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  5254. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5255. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5256. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  5257. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5258. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5259. case HWTSTAMP_FILTER_NTP_ALL:
  5260. init->rx_filter = HWTSTAMP_FILTER_ALL;
  5261. rc = efx_ptp_change_mode(efx, true, 0);
  5262. if (!rc)
  5263. rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
  5264. if (rc)
  5265. efx_ptp_change_mode(efx, false, 0);
  5266. return rc;
  5267. default:
  5268. return -ERANGE;
  5269. }
  5270. }
  5271. static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
  5272. struct netdev_phys_item_id *ppid)
  5273. {
  5274. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5275. if (!is_valid_ether_addr(nic_data->port_id))
  5276. return -EOPNOTSUPP;
  5277. ppid->id_len = ETH_ALEN;
  5278. memcpy(ppid->id, nic_data->port_id, ppid->id_len);
  5279. return 0;
  5280. }
  5281. static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
  5282. {
  5283. if (proto != htons(ETH_P_8021Q))
  5284. return -EINVAL;
  5285. return efx_ef10_add_vlan(efx, vid);
  5286. }
  5287. static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
  5288. {
  5289. if (proto != htons(ETH_P_8021Q))
  5290. return -EINVAL;
  5291. return efx_ef10_del_vlan(efx, vid);
  5292. }
  5293. /* We rely on the MCDI wiping out our TX rings if it made any changes to the
  5294. * ports table, ensuring that any TSO descriptors that were made on a now-
  5295. * removed tunnel port will be blown away and won't break things when we try
  5296. * to transmit them using the new ports table.
  5297. */
  5298. static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
  5299. {
  5300. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5301. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
  5302. MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
  5303. bool will_reset = false;
  5304. size_t num_entries = 0;
  5305. size_t inlen, outlen;
  5306. size_t i;
  5307. int rc;
  5308. efx_dword_t flags_and_num_entries;
  5309. WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
  5310. nic_data->udp_tunnels_dirty = false;
  5311. if (!(nic_data->datapath_caps &
  5312. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
  5313. efx_device_attach_if_not_resetting(efx);
  5314. return 0;
  5315. }
  5316. BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
  5317. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
  5318. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
  5319. if (nic_data->udp_tunnels[i].count &&
  5320. nic_data->udp_tunnels[i].port) {
  5321. efx_dword_t entry;
  5322. EFX_POPULATE_DWORD_2(entry,
  5323. TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
  5324. ntohs(nic_data->udp_tunnels[i].port),
  5325. TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
  5326. nic_data->udp_tunnels[i].type);
  5327. *_MCDI_ARRAY_DWORD(inbuf,
  5328. SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
  5329. num_entries++) = entry;
  5330. }
  5331. }
  5332. BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
  5333. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
  5334. EFX_WORD_1_LBN);
  5335. BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
  5336. EFX_WORD_1_WIDTH);
  5337. EFX_POPULATE_DWORD_2(flags_and_num_entries,
  5338. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
  5339. !!unloading,
  5340. EFX_WORD_1, num_entries);
  5341. *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
  5342. flags_and_num_entries;
  5343. inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
  5344. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
  5345. inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
  5346. if (rc == -EIO) {
  5347. /* Most likely the MC rebooted due to another function also
  5348. * setting its tunnel port list. Mark the tunnel port list as
  5349. * dirty, so it will be pushed upon coming up from the reboot.
  5350. */
  5351. nic_data->udp_tunnels_dirty = true;
  5352. return 0;
  5353. }
  5354. if (rc) {
  5355. /* expected not available on unprivileged functions */
  5356. if (rc != -EPERM)
  5357. netif_warn(efx, drv, efx->net_dev,
  5358. "Unable to set UDP tunnel ports; rc=%d.\n", rc);
  5359. } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
  5360. (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
  5361. netif_info(efx, drv, efx->net_dev,
  5362. "Rebooting MC due to UDP tunnel port list change\n");
  5363. will_reset = true;
  5364. if (unloading)
  5365. /* Delay for the MC reset to complete. This will make
  5366. * unloading other functions a bit smoother. This is a
  5367. * race, but the other unload will work whichever way
  5368. * it goes, this just avoids an unnecessary error
  5369. * message.
  5370. */
  5371. msleep(100);
  5372. }
  5373. if (!will_reset && !unloading) {
  5374. /* The caller will have detached, relying on the MC reset to
  5375. * trigger a re-attach. Since there won't be an MC reset, we
  5376. * have to do the attach ourselves.
  5377. */
  5378. efx_device_attach_if_not_resetting(efx);
  5379. }
  5380. return rc;
  5381. }
  5382. static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
  5383. {
  5384. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5385. int rc = 0;
  5386. mutex_lock(&nic_data->udp_tunnels_lock);
  5387. if (nic_data->udp_tunnels_dirty) {
  5388. /* Make sure all TX are stopped while we modify the table, else
  5389. * we might race against an efx_features_check().
  5390. */
  5391. efx_device_detach_sync(efx);
  5392. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  5393. }
  5394. mutex_unlock(&nic_data->udp_tunnels_lock);
  5395. return rc;
  5396. }
  5397. static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
  5398. __be16 port)
  5399. {
  5400. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5401. size_t i;
  5402. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
  5403. if (!nic_data->udp_tunnels[i].count)
  5404. continue;
  5405. if (nic_data->udp_tunnels[i].port == port)
  5406. return &nic_data->udp_tunnels[i];
  5407. }
  5408. return NULL;
  5409. }
  5410. static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
  5411. struct efx_udp_tunnel tnl)
  5412. {
  5413. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5414. struct efx_udp_tunnel *match;
  5415. char typebuf[8];
  5416. size_t i;
  5417. int rc;
  5418. if (!(nic_data->datapath_caps &
  5419. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  5420. return 0;
  5421. efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
  5422. netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
  5423. typebuf, ntohs(tnl.port));
  5424. mutex_lock(&nic_data->udp_tunnels_lock);
  5425. /* Make sure all TX are stopped while we add to the table, else we
  5426. * might race against an efx_features_check().
  5427. */
  5428. efx_device_detach_sync(efx);
  5429. match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
  5430. if (match != NULL) {
  5431. if (match->type == tnl.type) {
  5432. netif_dbg(efx, drv, efx->net_dev,
  5433. "Referencing existing tunnel entry\n");
  5434. match->count++;
  5435. /* No need to cause an MCDI update */
  5436. rc = 0;
  5437. goto unlock_out;
  5438. }
  5439. efx_get_udp_tunnel_type_name(match->type,
  5440. typebuf, sizeof(typebuf));
  5441. netif_dbg(efx, drv, efx->net_dev,
  5442. "UDP port %d is already in use by %s\n",
  5443. ntohs(tnl.port), typebuf);
  5444. rc = -EEXIST;
  5445. goto unlock_out;
  5446. }
  5447. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
  5448. if (!nic_data->udp_tunnels[i].count) {
  5449. nic_data->udp_tunnels[i] = tnl;
  5450. nic_data->udp_tunnels[i].count = 1;
  5451. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  5452. goto unlock_out;
  5453. }
  5454. netif_dbg(efx, drv, efx->net_dev,
  5455. "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
  5456. typebuf, ntohs(tnl.port));
  5457. rc = -ENOMEM;
  5458. unlock_out:
  5459. mutex_unlock(&nic_data->udp_tunnels_lock);
  5460. return rc;
  5461. }
  5462. /* Called under the TX lock with the TX queue running, hence no-one can be
  5463. * in the middle of updating the UDP tunnels table. However, they could
  5464. * have tried and failed the MCDI, in which case they'll have set the dirty
  5465. * flag before dropping their locks.
  5466. */
  5467. static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
  5468. {
  5469. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5470. if (!(nic_data->datapath_caps &
  5471. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  5472. return false;
  5473. if (nic_data->udp_tunnels_dirty)
  5474. /* SW table may not match HW state, so just assume we can't
  5475. * use any UDP tunnel offloads.
  5476. */
  5477. return false;
  5478. return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
  5479. }
  5480. static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
  5481. struct efx_udp_tunnel tnl)
  5482. {
  5483. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5484. struct efx_udp_tunnel *match;
  5485. char typebuf[8];
  5486. int rc;
  5487. if (!(nic_data->datapath_caps &
  5488. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  5489. return 0;
  5490. efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
  5491. netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
  5492. typebuf, ntohs(tnl.port));
  5493. mutex_lock(&nic_data->udp_tunnels_lock);
  5494. /* Make sure all TX are stopped while we remove from the table, else we
  5495. * might race against an efx_features_check().
  5496. */
  5497. efx_device_detach_sync(efx);
  5498. match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
  5499. if (match != NULL) {
  5500. if (match->type == tnl.type) {
  5501. if (--match->count) {
  5502. /* Port is still in use, so nothing to do */
  5503. netif_dbg(efx, drv, efx->net_dev,
  5504. "UDP tunnel port %d remains active\n",
  5505. ntohs(tnl.port));
  5506. rc = 0;
  5507. goto out_unlock;
  5508. }
  5509. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  5510. goto out_unlock;
  5511. }
  5512. efx_get_udp_tunnel_type_name(match->type,
  5513. typebuf, sizeof(typebuf));
  5514. netif_warn(efx, drv, efx->net_dev,
  5515. "UDP port %d is actually in use by %s, not removing\n",
  5516. ntohs(tnl.port), typebuf);
  5517. }
  5518. rc = -ENOENT;
  5519. out_unlock:
  5520. mutex_unlock(&nic_data->udp_tunnels_lock);
  5521. return rc;
  5522. }
  5523. #define EF10_OFFLOAD_FEATURES \
  5524. (NETIF_F_IP_CSUM | \
  5525. NETIF_F_HW_VLAN_CTAG_FILTER | \
  5526. NETIF_F_IPV6_CSUM | \
  5527. NETIF_F_RXHASH | \
  5528. NETIF_F_NTUPLE)
  5529. const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
  5530. .is_vf = true,
  5531. .mem_bar = efx_ef10_vf_mem_bar,
  5532. .mem_map_size = efx_ef10_mem_map_size,
  5533. .probe = efx_ef10_probe_vf,
  5534. .remove = efx_ef10_remove,
  5535. .dimension_resources = efx_ef10_dimension_resources,
  5536. .init = efx_ef10_init_nic,
  5537. .fini = efx_port_dummy_op_void,
  5538. .map_reset_reason = efx_ef10_map_reset_reason,
  5539. .map_reset_flags = efx_ef10_map_reset_flags,
  5540. .reset = efx_ef10_reset,
  5541. .probe_port = efx_mcdi_port_probe,
  5542. .remove_port = efx_mcdi_port_remove,
  5543. .fini_dmaq = efx_ef10_fini_dmaq,
  5544. .prepare_flr = efx_ef10_prepare_flr,
  5545. .finish_flr = efx_port_dummy_op_void,
  5546. .describe_stats = efx_ef10_describe_stats,
  5547. .update_stats = efx_ef10_update_stats_vf,
  5548. .start_stats = efx_port_dummy_op_void,
  5549. .pull_stats = efx_port_dummy_op_void,
  5550. .stop_stats = efx_port_dummy_op_void,
  5551. .set_id_led = efx_mcdi_set_id_led,
  5552. .push_irq_moderation = efx_ef10_push_irq_moderation,
  5553. .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
  5554. .check_mac_fault = efx_mcdi_mac_check_fault,
  5555. .reconfigure_port = efx_mcdi_port_reconfigure,
  5556. .get_wol = efx_ef10_get_wol_vf,
  5557. .set_wol = efx_ef10_set_wol_vf,
  5558. .resume_wol = efx_port_dummy_op_void,
  5559. .mcdi_request = efx_ef10_mcdi_request,
  5560. .mcdi_poll_response = efx_ef10_mcdi_poll_response,
  5561. .mcdi_read_response = efx_ef10_mcdi_read_response,
  5562. .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
  5563. .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
  5564. .irq_enable_master = efx_port_dummy_op_void,
  5565. .irq_test_generate = efx_ef10_irq_test_generate,
  5566. .irq_disable_non_ev = efx_port_dummy_op_void,
  5567. .irq_handle_msi = efx_ef10_msi_interrupt,
  5568. .irq_handle_legacy = efx_ef10_legacy_interrupt,
  5569. .tx_probe = efx_ef10_tx_probe,
  5570. .tx_init = efx_ef10_tx_init,
  5571. .tx_remove = efx_ef10_tx_remove,
  5572. .tx_write = efx_ef10_tx_write,
  5573. .tx_limit_len = efx_ef10_tx_limit_len,
  5574. .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
  5575. .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
  5576. .rx_probe = efx_ef10_rx_probe,
  5577. .rx_init = efx_ef10_rx_init,
  5578. .rx_remove = efx_ef10_rx_remove,
  5579. .rx_write = efx_ef10_rx_write,
  5580. .rx_defer_refill = efx_ef10_rx_defer_refill,
  5581. .ev_probe = efx_ef10_ev_probe,
  5582. .ev_init = efx_ef10_ev_init,
  5583. .ev_fini = efx_ef10_ev_fini,
  5584. .ev_remove = efx_ef10_ev_remove,
  5585. .ev_process = efx_ef10_ev_process,
  5586. .ev_read_ack = efx_ef10_ev_read_ack,
  5587. .ev_test_generate = efx_ef10_ev_test_generate,
  5588. .filter_table_probe = efx_ef10_filter_table_probe,
  5589. .filter_table_restore = efx_ef10_filter_table_restore,
  5590. .filter_table_remove = efx_ef10_filter_table_remove,
  5591. .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
  5592. .filter_insert = efx_ef10_filter_insert,
  5593. .filter_remove_safe = efx_ef10_filter_remove_safe,
  5594. .filter_get_safe = efx_ef10_filter_get_safe,
  5595. .filter_clear_rx = efx_ef10_filter_clear_rx,
  5596. .filter_count_rx_used = efx_ef10_filter_count_rx_used,
  5597. .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
  5598. .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
  5599. #ifdef CONFIG_RFS_ACCEL
  5600. .filter_rfs_insert = efx_ef10_filter_rfs_insert,
  5601. .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
  5602. #endif
  5603. #ifdef CONFIG_SFC_MTD
  5604. .mtd_probe = efx_port_dummy_op_int,
  5605. #endif
  5606. .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
  5607. .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
  5608. .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
  5609. .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
  5610. #ifdef CONFIG_SFC_SRIOV
  5611. .vswitching_probe = efx_ef10_vswitching_probe_vf,
  5612. .vswitching_restore = efx_ef10_vswitching_restore_vf,
  5613. .vswitching_remove = efx_ef10_vswitching_remove_vf,
  5614. #endif
  5615. .get_mac_address = efx_ef10_get_mac_address_vf,
  5616. .set_mac_address = efx_ef10_set_mac_address,
  5617. .get_phys_port_id = efx_ef10_get_phys_port_id,
  5618. .revision = EFX_REV_HUNT_A0,
  5619. .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
  5620. .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
  5621. .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
  5622. .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
  5623. .can_rx_scatter = true,
  5624. .always_rx_scatter = true,
  5625. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  5626. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  5627. .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
  5628. .offload_features = EF10_OFFLOAD_FEATURES,
  5629. .mcdi_max_ver = 2,
  5630. .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
  5631. .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
  5632. 1 << HWTSTAMP_FILTER_ALL,
  5633. .rx_hash_key_size = 40,
  5634. };
  5635. const struct efx_nic_type efx_hunt_a0_nic_type = {
  5636. .is_vf = false,
  5637. .mem_bar = efx_ef10_pf_mem_bar,
  5638. .mem_map_size = efx_ef10_mem_map_size,
  5639. .probe = efx_ef10_probe_pf,
  5640. .remove = efx_ef10_remove,
  5641. .dimension_resources = efx_ef10_dimension_resources,
  5642. .init = efx_ef10_init_nic,
  5643. .fini = efx_port_dummy_op_void,
  5644. .map_reset_reason = efx_ef10_map_reset_reason,
  5645. .map_reset_flags = efx_ef10_map_reset_flags,
  5646. .reset = efx_ef10_reset,
  5647. .probe_port = efx_mcdi_port_probe,
  5648. .remove_port = efx_mcdi_port_remove,
  5649. .fini_dmaq = efx_ef10_fini_dmaq,
  5650. .prepare_flr = efx_ef10_prepare_flr,
  5651. .finish_flr = efx_port_dummy_op_void,
  5652. .describe_stats = efx_ef10_describe_stats,
  5653. .update_stats = efx_ef10_update_stats_pf,
  5654. .start_stats = efx_mcdi_mac_start_stats,
  5655. .pull_stats = efx_mcdi_mac_pull_stats,
  5656. .stop_stats = efx_mcdi_mac_stop_stats,
  5657. .set_id_led = efx_mcdi_set_id_led,
  5658. .push_irq_moderation = efx_ef10_push_irq_moderation,
  5659. .reconfigure_mac = efx_ef10_mac_reconfigure,
  5660. .check_mac_fault = efx_mcdi_mac_check_fault,
  5661. .reconfigure_port = efx_mcdi_port_reconfigure,
  5662. .get_wol = efx_ef10_get_wol,
  5663. .set_wol = efx_ef10_set_wol,
  5664. .resume_wol = efx_port_dummy_op_void,
  5665. .test_chip = efx_ef10_test_chip,
  5666. .test_nvram = efx_mcdi_nvram_test_all,
  5667. .mcdi_request = efx_ef10_mcdi_request,
  5668. .mcdi_poll_response = efx_ef10_mcdi_poll_response,
  5669. .mcdi_read_response = efx_ef10_mcdi_read_response,
  5670. .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
  5671. .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
  5672. .irq_enable_master = efx_port_dummy_op_void,
  5673. .irq_test_generate = efx_ef10_irq_test_generate,
  5674. .irq_disable_non_ev = efx_port_dummy_op_void,
  5675. .irq_handle_msi = efx_ef10_msi_interrupt,
  5676. .irq_handle_legacy = efx_ef10_legacy_interrupt,
  5677. .tx_probe = efx_ef10_tx_probe,
  5678. .tx_init = efx_ef10_tx_init,
  5679. .tx_remove = efx_ef10_tx_remove,
  5680. .tx_write = efx_ef10_tx_write,
  5681. .tx_limit_len = efx_ef10_tx_limit_len,
  5682. .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
  5683. .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
  5684. .rx_probe = efx_ef10_rx_probe,
  5685. .rx_init = efx_ef10_rx_init,
  5686. .rx_remove = efx_ef10_rx_remove,
  5687. .rx_write = efx_ef10_rx_write,
  5688. .rx_defer_refill = efx_ef10_rx_defer_refill,
  5689. .ev_probe = efx_ef10_ev_probe,
  5690. .ev_init = efx_ef10_ev_init,
  5691. .ev_fini = efx_ef10_ev_fini,
  5692. .ev_remove = efx_ef10_ev_remove,
  5693. .ev_process = efx_ef10_ev_process,
  5694. .ev_read_ack = efx_ef10_ev_read_ack,
  5695. .ev_test_generate = efx_ef10_ev_test_generate,
  5696. .filter_table_probe = efx_ef10_filter_table_probe,
  5697. .filter_table_restore = efx_ef10_filter_table_restore,
  5698. .filter_table_remove = efx_ef10_filter_table_remove,
  5699. .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
  5700. .filter_insert = efx_ef10_filter_insert,
  5701. .filter_remove_safe = efx_ef10_filter_remove_safe,
  5702. .filter_get_safe = efx_ef10_filter_get_safe,
  5703. .filter_clear_rx = efx_ef10_filter_clear_rx,
  5704. .filter_count_rx_used = efx_ef10_filter_count_rx_used,
  5705. .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
  5706. .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
  5707. #ifdef CONFIG_RFS_ACCEL
  5708. .filter_rfs_insert = efx_ef10_filter_rfs_insert,
  5709. .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
  5710. #endif
  5711. #ifdef CONFIG_SFC_MTD
  5712. .mtd_probe = efx_ef10_mtd_probe,
  5713. .mtd_rename = efx_mcdi_mtd_rename,
  5714. .mtd_read = efx_mcdi_mtd_read,
  5715. .mtd_erase = efx_mcdi_mtd_erase,
  5716. .mtd_write = efx_mcdi_mtd_write,
  5717. .mtd_sync = efx_mcdi_mtd_sync,
  5718. #endif
  5719. .ptp_write_host_time = efx_ef10_ptp_write_host_time,
  5720. .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
  5721. .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
  5722. .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
  5723. .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
  5724. .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
  5725. .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
  5726. .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
  5727. .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
  5728. #ifdef CONFIG_SFC_SRIOV
  5729. .sriov_configure = efx_ef10_sriov_configure,
  5730. .sriov_init = efx_ef10_sriov_init,
  5731. .sriov_fini = efx_ef10_sriov_fini,
  5732. .sriov_wanted = efx_ef10_sriov_wanted,
  5733. .sriov_reset = efx_ef10_sriov_reset,
  5734. .sriov_flr = efx_ef10_sriov_flr,
  5735. .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
  5736. .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
  5737. .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
  5738. .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
  5739. .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
  5740. .vswitching_probe = efx_ef10_vswitching_probe_pf,
  5741. .vswitching_restore = efx_ef10_vswitching_restore_pf,
  5742. .vswitching_remove = efx_ef10_vswitching_remove_pf,
  5743. #endif
  5744. .get_mac_address = efx_ef10_get_mac_address_pf,
  5745. .set_mac_address = efx_ef10_set_mac_address,
  5746. .tso_versions = efx_ef10_tso_versions,
  5747. .get_phys_port_id = efx_ef10_get_phys_port_id,
  5748. .revision = EFX_REV_HUNT_A0,
  5749. .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
  5750. .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
  5751. .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
  5752. .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
  5753. .can_rx_scatter = true,
  5754. .always_rx_scatter = true,
  5755. .option_descriptors = true,
  5756. .min_interrupt_mode = EFX_INT_MODE_LEGACY,
  5757. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  5758. .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
  5759. .offload_features = EF10_OFFLOAD_FEATURES,
  5760. .mcdi_max_ver = 2,
  5761. .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
  5762. .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
  5763. 1 << HWTSTAMP_FILTER_ALL,
  5764. .rx_hash_key_size = 40,
  5765. };