ef10.c 200 KB

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