ef10.c 201 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804
  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. /* Decide whether a filter should be exclusive or else should allow
  3407. * delivery to additional recipients. Currently we decide that
  3408. * filters for specific local unicast MAC and IP addresses are
  3409. * exclusive.
  3410. */
  3411. static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
  3412. {
  3413. if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
  3414. !is_multicast_ether_addr(spec->loc_mac))
  3415. return true;
  3416. if ((spec->match_flags &
  3417. (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
  3418. (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
  3419. if (spec->ether_type == htons(ETH_P_IP) &&
  3420. !ipv4_is_multicast(spec->loc_host[0]))
  3421. return true;
  3422. if (spec->ether_type == htons(ETH_P_IPV6) &&
  3423. ((const u8 *)spec->loc_host)[0] != 0xff)
  3424. return true;
  3425. }
  3426. return false;
  3427. }
  3428. static struct efx_filter_spec *
  3429. efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
  3430. unsigned int filter_idx)
  3431. {
  3432. return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
  3433. ~EFX_EF10_FILTER_FLAGS);
  3434. }
  3435. static unsigned int
  3436. efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
  3437. unsigned int filter_idx)
  3438. {
  3439. return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
  3440. }
  3441. static void
  3442. efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
  3443. unsigned int filter_idx,
  3444. const struct efx_filter_spec *spec,
  3445. unsigned int flags)
  3446. {
  3447. table->entry[filter_idx].spec = (unsigned long)spec | flags;
  3448. }
  3449. static void
  3450. efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
  3451. const struct efx_filter_spec *spec,
  3452. efx_dword_t *inbuf)
  3453. {
  3454. enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
  3455. u32 match_fields = 0, uc_match, mc_match;
  3456. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3457. efx_ef10_filter_is_exclusive(spec) ?
  3458. MC_CMD_FILTER_OP_IN_OP_INSERT :
  3459. MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
  3460. /* Convert match flags and values. Unlike almost
  3461. * everything else in MCDI, these fields are in
  3462. * network byte order.
  3463. */
  3464. #define COPY_VALUE(value, mcdi_field) \
  3465. do { \
  3466. match_fields |= \
  3467. 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
  3468. mcdi_field ## _LBN; \
  3469. BUILD_BUG_ON( \
  3470. MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
  3471. sizeof(value)); \
  3472. memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
  3473. &value, sizeof(value)); \
  3474. } while (0)
  3475. #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
  3476. if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
  3477. COPY_VALUE(spec->gen_field, mcdi_field); \
  3478. }
  3479. /* Handle encap filters first. They will always be mismatch
  3480. * (unknown UC or MC) filters
  3481. */
  3482. if (encap_type) {
  3483. /* ether_type and outer_ip_proto need to be variables
  3484. * because COPY_VALUE wants to memcpy them
  3485. */
  3486. __be16 ether_type =
  3487. htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
  3488. ETH_P_IPV6 : ETH_P_IP);
  3489. u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
  3490. u8 outer_ip_proto;
  3491. switch (encap_type & EFX_ENCAP_TYPES_MASK) {
  3492. case EFX_ENCAP_TYPE_VXLAN:
  3493. vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
  3494. /* fallthrough */
  3495. case EFX_ENCAP_TYPE_GENEVE:
  3496. COPY_VALUE(ether_type, ETHER_TYPE);
  3497. outer_ip_proto = IPPROTO_UDP;
  3498. COPY_VALUE(outer_ip_proto, IP_PROTO);
  3499. /* We always need to set the type field, even
  3500. * though we're not matching on the TNI.
  3501. */
  3502. MCDI_POPULATE_DWORD_1(inbuf,
  3503. FILTER_OP_EXT_IN_VNI_OR_VSID,
  3504. FILTER_OP_EXT_IN_VNI_TYPE,
  3505. vni_type);
  3506. break;
  3507. case EFX_ENCAP_TYPE_NVGRE:
  3508. COPY_VALUE(ether_type, ETHER_TYPE);
  3509. outer_ip_proto = IPPROTO_GRE;
  3510. COPY_VALUE(outer_ip_proto, IP_PROTO);
  3511. break;
  3512. default:
  3513. WARN_ON(1);
  3514. }
  3515. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
  3516. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
  3517. } else {
  3518. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
  3519. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
  3520. }
  3521. if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
  3522. match_fields |=
  3523. is_multicast_ether_addr(spec->loc_mac) ?
  3524. 1 << mc_match :
  3525. 1 << uc_match;
  3526. COPY_FIELD(REM_HOST, rem_host, SRC_IP);
  3527. COPY_FIELD(LOC_HOST, loc_host, DST_IP);
  3528. COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
  3529. COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
  3530. COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
  3531. COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
  3532. COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
  3533. COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
  3534. COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
  3535. COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
  3536. #undef COPY_FIELD
  3537. #undef COPY_VALUE
  3538. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
  3539. match_fields);
  3540. }
  3541. static void efx_ef10_filter_push_prep(struct efx_nic *efx,
  3542. const struct efx_filter_spec *spec,
  3543. efx_dword_t *inbuf, u64 handle,
  3544. struct efx_rss_context *ctx,
  3545. bool replacing)
  3546. {
  3547. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3548. u32 flags = spec->flags;
  3549. memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3550. /* If RSS filter, caller better have given us an RSS context */
  3551. if (flags & EFX_FILTER_FLAG_RX_RSS) {
  3552. /* We don't have the ability to return an error, so we'll just
  3553. * log a warning and disable RSS for the filter.
  3554. */
  3555. if (WARN_ON_ONCE(!ctx))
  3556. flags &= ~EFX_FILTER_FLAG_RX_RSS;
  3557. else if (WARN_ON_ONCE(ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID))
  3558. flags &= ~EFX_FILTER_FLAG_RX_RSS;
  3559. }
  3560. if (replacing) {
  3561. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3562. MC_CMD_FILTER_OP_IN_OP_REPLACE);
  3563. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
  3564. } else {
  3565. efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
  3566. }
  3567. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
  3568. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
  3569. spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
  3570. MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
  3571. MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
  3572. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
  3573. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
  3574. MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
  3575. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
  3576. spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
  3577. 0 : spec->dmaq_id);
  3578. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
  3579. (flags & EFX_FILTER_FLAG_RX_RSS) ?
  3580. MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
  3581. MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
  3582. if (flags & EFX_FILTER_FLAG_RX_RSS)
  3583. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, ctx->context_id);
  3584. }
  3585. static int efx_ef10_filter_push(struct efx_nic *efx,
  3586. const struct efx_filter_spec *spec, u64 *handle,
  3587. struct efx_rss_context *ctx, bool replacing)
  3588. {
  3589. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3590. MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
  3591. int rc;
  3592. efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, ctx, replacing);
  3593. rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
  3594. outbuf, sizeof(outbuf), NULL);
  3595. if (rc == 0)
  3596. *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
  3597. if (rc == -ENOSPC)
  3598. rc = -EBUSY; /* to match efx_farch_filter_insert() */
  3599. return rc;
  3600. }
  3601. static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
  3602. {
  3603. enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
  3604. unsigned int match_flags = spec->match_flags;
  3605. unsigned int uc_match, mc_match;
  3606. u32 mcdi_flags = 0;
  3607. #define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
  3608. unsigned int old_match_flags = match_flags; \
  3609. match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
  3610. if (match_flags != old_match_flags) \
  3611. mcdi_flags |= \
  3612. (1 << ((encap) ? \
  3613. MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
  3614. mcdi_field ## _LBN : \
  3615. MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
  3616. mcdi_field ## _LBN)); \
  3617. }
  3618. /* inner or outer based on encap type */
  3619. MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
  3620. MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
  3621. MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
  3622. MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
  3623. MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
  3624. MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
  3625. MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
  3626. MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
  3627. /* always outer */
  3628. MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
  3629. MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
  3630. #undef MAP_FILTER_TO_MCDI_FLAG
  3631. /* special handling for encap type, and mismatch */
  3632. if (encap_type) {
  3633. match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
  3634. mcdi_flags |=
  3635. (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
  3636. mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
  3637. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
  3638. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
  3639. } else {
  3640. uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
  3641. mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
  3642. }
  3643. if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
  3644. match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
  3645. mcdi_flags |=
  3646. is_multicast_ether_addr(spec->loc_mac) ?
  3647. 1 << mc_match :
  3648. 1 << uc_match;
  3649. }
  3650. /* Did we map them all? */
  3651. WARN_ON_ONCE(match_flags);
  3652. return mcdi_flags;
  3653. }
  3654. static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
  3655. const struct efx_filter_spec *spec)
  3656. {
  3657. u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
  3658. unsigned int match_pri;
  3659. for (match_pri = 0;
  3660. match_pri < table->rx_match_count;
  3661. match_pri++)
  3662. if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
  3663. return match_pri;
  3664. return -EPROTONOSUPPORT;
  3665. }
  3666. static s32 efx_ef10_filter_insert(struct efx_nic *efx,
  3667. struct efx_filter_spec *spec,
  3668. bool replace_equal)
  3669. {
  3670. DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
  3671. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3672. struct efx_ef10_filter_table *table;
  3673. struct efx_filter_spec *saved_spec;
  3674. struct efx_rss_context *ctx = NULL;
  3675. unsigned int match_pri, hash;
  3676. unsigned int priv_flags;
  3677. bool rss_locked = false;
  3678. bool replacing = false;
  3679. unsigned int depth, i;
  3680. int ins_index = -1;
  3681. DEFINE_WAIT(wait);
  3682. bool is_mc_recip;
  3683. s32 rc;
  3684. down_read(&efx->filter_sem);
  3685. table = efx->filter_state;
  3686. down_write(&table->lock);
  3687. /* For now, only support RX filters */
  3688. if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
  3689. EFX_FILTER_FLAG_RX) {
  3690. rc = -EINVAL;
  3691. goto out_unlock;
  3692. }
  3693. rc = efx_ef10_filter_pri(table, spec);
  3694. if (rc < 0)
  3695. goto out_unlock;
  3696. match_pri = rc;
  3697. hash = efx_filter_spec_hash(spec);
  3698. is_mc_recip = efx_filter_is_mc_recipient(spec);
  3699. if (is_mc_recip)
  3700. bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
  3701. if (spec->flags & EFX_FILTER_FLAG_RX_RSS) {
  3702. mutex_lock(&efx->rss_lock);
  3703. rss_locked = true;
  3704. if (spec->rss_context)
  3705. ctx = efx_find_rss_context_entry(efx, spec->rss_context);
  3706. else
  3707. ctx = &efx->rss_context;
  3708. if (!ctx) {
  3709. rc = -ENOENT;
  3710. goto out_unlock;
  3711. }
  3712. if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) {
  3713. rc = -EOPNOTSUPP;
  3714. goto out_unlock;
  3715. }
  3716. }
  3717. /* Find any existing filters with the same match tuple or
  3718. * else a free slot to insert at.
  3719. */
  3720. for (depth = 1; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
  3721. i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
  3722. saved_spec = efx_ef10_filter_entry_spec(table, i);
  3723. if (!saved_spec) {
  3724. if (ins_index < 0)
  3725. ins_index = i;
  3726. } else if (efx_filter_spec_equal(spec, saved_spec)) {
  3727. if (spec->priority < saved_spec->priority &&
  3728. spec->priority != EFX_FILTER_PRI_AUTO) {
  3729. rc = -EPERM;
  3730. goto out_unlock;
  3731. }
  3732. if (!is_mc_recip) {
  3733. /* This is the only one */
  3734. if (spec->priority ==
  3735. saved_spec->priority &&
  3736. !replace_equal) {
  3737. rc = -EEXIST;
  3738. goto out_unlock;
  3739. }
  3740. ins_index = i;
  3741. break;
  3742. } else if (spec->priority >
  3743. saved_spec->priority ||
  3744. (spec->priority ==
  3745. saved_spec->priority &&
  3746. replace_equal)) {
  3747. if (ins_index < 0)
  3748. ins_index = i;
  3749. else
  3750. __set_bit(depth, mc_rem_map);
  3751. }
  3752. }
  3753. }
  3754. /* Once we reach the maximum search depth, use the first suitable
  3755. * slot, or return -EBUSY if there was none
  3756. */
  3757. if (ins_index < 0) {
  3758. rc = -EBUSY;
  3759. goto out_unlock;
  3760. }
  3761. /* Create a software table entry if necessary. */
  3762. saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
  3763. if (saved_spec) {
  3764. if (spec->priority == EFX_FILTER_PRI_AUTO &&
  3765. saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
  3766. /* Just make sure it won't be removed */
  3767. if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
  3768. saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
  3769. table->entry[ins_index].spec &=
  3770. ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
  3771. rc = ins_index;
  3772. goto out_unlock;
  3773. }
  3774. replacing = true;
  3775. priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
  3776. } else {
  3777. saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
  3778. if (!saved_spec) {
  3779. rc = -ENOMEM;
  3780. goto out_unlock;
  3781. }
  3782. *saved_spec = *spec;
  3783. priv_flags = 0;
  3784. }
  3785. efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
  3786. /* Actually insert the filter on the HW */
  3787. rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
  3788. ctx, replacing);
  3789. if (rc == -EINVAL && nic_data->must_realloc_vis)
  3790. /* The MC rebooted under us, causing it to reject our filter
  3791. * insertion as pointing to an invalid VI (spec->dmaq_id).
  3792. */
  3793. rc = -EAGAIN;
  3794. /* Finalise the software table entry */
  3795. if (rc == 0) {
  3796. if (replacing) {
  3797. /* Update the fields that may differ */
  3798. if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
  3799. saved_spec->flags |=
  3800. EFX_FILTER_FLAG_RX_OVER_AUTO;
  3801. saved_spec->priority = spec->priority;
  3802. saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
  3803. saved_spec->flags |= spec->flags;
  3804. saved_spec->rss_context = spec->rss_context;
  3805. saved_spec->dmaq_id = spec->dmaq_id;
  3806. }
  3807. } else if (!replacing) {
  3808. kfree(saved_spec);
  3809. saved_spec = NULL;
  3810. } else {
  3811. /* We failed to replace, so the old filter is still present.
  3812. * Roll back the software table to reflect this. In fact the
  3813. * efx_ef10_filter_set_entry() call below will do the right
  3814. * thing, so nothing extra is needed here.
  3815. */
  3816. }
  3817. efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
  3818. /* Remove and finalise entries for lower-priority multicast
  3819. * recipients
  3820. */
  3821. if (is_mc_recip) {
  3822. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  3823. unsigned int depth, i;
  3824. memset(inbuf, 0, sizeof(inbuf));
  3825. for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
  3826. if (!test_bit(depth, mc_rem_map))
  3827. continue;
  3828. i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
  3829. saved_spec = efx_ef10_filter_entry_spec(table, i);
  3830. priv_flags = efx_ef10_filter_entry_flags(table, i);
  3831. if (rc == 0) {
  3832. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3833. MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
  3834. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  3835. table->entry[i].handle);
  3836. rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
  3837. inbuf, sizeof(inbuf),
  3838. NULL, 0, NULL);
  3839. }
  3840. if (rc == 0) {
  3841. kfree(saved_spec);
  3842. saved_spec = NULL;
  3843. priv_flags = 0;
  3844. }
  3845. efx_ef10_filter_set_entry(table, i, saved_spec,
  3846. priv_flags);
  3847. }
  3848. }
  3849. /* If successful, return the inserted filter ID */
  3850. if (rc == 0)
  3851. rc = efx_ef10_make_filter_id(match_pri, ins_index);
  3852. out_unlock:
  3853. if (rss_locked)
  3854. mutex_unlock(&efx->rss_lock);
  3855. up_write(&table->lock);
  3856. up_read(&efx->filter_sem);
  3857. return rc;
  3858. }
  3859. static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
  3860. {
  3861. /* no need to do anything here on EF10 */
  3862. }
  3863. /* Remove a filter.
  3864. * If !by_index, remove by ID
  3865. * If by_index, remove by index
  3866. * Filter ID may come from userland and must be range-checked.
  3867. * Caller must hold efx->filter_sem for read, and efx->filter_state->lock
  3868. * for write.
  3869. */
  3870. static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
  3871. unsigned int priority_mask,
  3872. u32 filter_id, bool by_index)
  3873. {
  3874. unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
  3875. struct efx_ef10_filter_table *table = efx->filter_state;
  3876. MCDI_DECLARE_BUF(inbuf,
  3877. MC_CMD_FILTER_OP_IN_HANDLE_OFST +
  3878. MC_CMD_FILTER_OP_IN_HANDLE_LEN);
  3879. struct efx_filter_spec *spec;
  3880. DEFINE_WAIT(wait);
  3881. int rc;
  3882. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  3883. if (!spec ||
  3884. (!by_index &&
  3885. efx_ef10_filter_pri(table, spec) !=
  3886. efx_ef10_filter_get_unsafe_pri(filter_id)))
  3887. return -ENOENT;
  3888. if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
  3889. priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
  3890. /* Just remove flags */
  3891. spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
  3892. table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
  3893. return 0;
  3894. }
  3895. if (!(priority_mask & (1U << spec->priority)))
  3896. return -ENOENT;
  3897. if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
  3898. /* Reset to an automatic filter */
  3899. struct efx_filter_spec new_spec = *spec;
  3900. new_spec.priority = EFX_FILTER_PRI_AUTO;
  3901. new_spec.flags = (EFX_FILTER_FLAG_RX |
  3902. (efx_rss_active(&efx->rss_context) ?
  3903. EFX_FILTER_FLAG_RX_RSS : 0));
  3904. new_spec.dmaq_id = 0;
  3905. new_spec.rss_context = 0;
  3906. rc = efx_ef10_filter_push(efx, &new_spec,
  3907. &table->entry[filter_idx].handle,
  3908. &efx->rss_context,
  3909. true);
  3910. if (rc == 0)
  3911. *spec = new_spec;
  3912. } else {
  3913. /* Really remove the filter */
  3914. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  3915. efx_ef10_filter_is_exclusive(spec) ?
  3916. MC_CMD_FILTER_OP_IN_OP_REMOVE :
  3917. MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
  3918. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  3919. table->entry[filter_idx].handle);
  3920. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
  3921. inbuf, sizeof(inbuf), NULL, 0, NULL);
  3922. if ((rc == 0) || (rc == -ENOENT)) {
  3923. /* Filter removed OK or didn't actually exist */
  3924. kfree(spec);
  3925. efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
  3926. } else {
  3927. efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
  3928. MC_CMD_FILTER_OP_EXT_IN_LEN,
  3929. NULL, 0, rc);
  3930. }
  3931. }
  3932. return rc;
  3933. }
  3934. static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
  3935. enum efx_filter_priority priority,
  3936. u32 filter_id)
  3937. {
  3938. struct efx_ef10_filter_table *table;
  3939. int rc;
  3940. down_read(&efx->filter_sem);
  3941. table = efx->filter_state;
  3942. down_write(&table->lock);
  3943. rc = efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id,
  3944. false);
  3945. up_write(&table->lock);
  3946. up_read(&efx->filter_sem);
  3947. return rc;
  3948. }
  3949. /* Caller must hold efx->filter_sem for read */
  3950. static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
  3951. enum efx_filter_priority priority,
  3952. u32 filter_id)
  3953. {
  3954. struct efx_ef10_filter_table *table = efx->filter_state;
  3955. if (filter_id == EFX_EF10_FILTER_ID_INVALID)
  3956. return;
  3957. down_write(&table->lock);
  3958. efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id,
  3959. true);
  3960. up_write(&table->lock);
  3961. }
  3962. static int efx_ef10_filter_get_safe(struct efx_nic *efx,
  3963. enum efx_filter_priority priority,
  3964. u32 filter_id, struct efx_filter_spec *spec)
  3965. {
  3966. unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
  3967. const struct efx_filter_spec *saved_spec;
  3968. struct efx_ef10_filter_table *table;
  3969. int rc;
  3970. down_read(&efx->filter_sem);
  3971. table = efx->filter_state;
  3972. down_read(&table->lock);
  3973. saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
  3974. if (saved_spec && saved_spec->priority == priority &&
  3975. efx_ef10_filter_pri(table, saved_spec) ==
  3976. efx_ef10_filter_get_unsafe_pri(filter_id)) {
  3977. *spec = *saved_spec;
  3978. rc = 0;
  3979. } else {
  3980. rc = -ENOENT;
  3981. }
  3982. up_read(&table->lock);
  3983. up_read(&efx->filter_sem);
  3984. return rc;
  3985. }
  3986. static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
  3987. enum efx_filter_priority priority)
  3988. {
  3989. struct efx_ef10_filter_table *table;
  3990. unsigned int priority_mask;
  3991. unsigned int i;
  3992. int rc;
  3993. priority_mask = (((1U << (priority + 1)) - 1) &
  3994. ~(1U << EFX_FILTER_PRI_AUTO));
  3995. down_read(&efx->filter_sem);
  3996. table = efx->filter_state;
  3997. down_write(&table->lock);
  3998. for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
  3999. rc = efx_ef10_filter_remove_internal(efx, priority_mask,
  4000. i, true);
  4001. if (rc && rc != -ENOENT)
  4002. break;
  4003. rc = 0;
  4004. }
  4005. up_write(&table->lock);
  4006. up_read(&efx->filter_sem);
  4007. return rc;
  4008. }
  4009. static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
  4010. enum efx_filter_priority priority)
  4011. {
  4012. struct efx_ef10_filter_table *table;
  4013. unsigned int filter_idx;
  4014. s32 count = 0;
  4015. down_read(&efx->filter_sem);
  4016. table = efx->filter_state;
  4017. down_read(&table->lock);
  4018. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  4019. if (table->entry[filter_idx].spec &&
  4020. efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
  4021. priority)
  4022. ++count;
  4023. }
  4024. up_read(&table->lock);
  4025. up_read(&efx->filter_sem);
  4026. return count;
  4027. }
  4028. static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
  4029. {
  4030. struct efx_ef10_filter_table *table = efx->filter_state;
  4031. return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
  4032. }
  4033. static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
  4034. enum efx_filter_priority priority,
  4035. u32 *buf, u32 size)
  4036. {
  4037. struct efx_ef10_filter_table *table;
  4038. struct efx_filter_spec *spec;
  4039. unsigned int filter_idx;
  4040. s32 count = 0;
  4041. down_read(&efx->filter_sem);
  4042. table = efx->filter_state;
  4043. down_read(&table->lock);
  4044. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  4045. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  4046. if (spec && spec->priority == priority) {
  4047. if (count == size) {
  4048. count = -EMSGSIZE;
  4049. break;
  4050. }
  4051. buf[count++] =
  4052. efx_ef10_make_filter_id(
  4053. efx_ef10_filter_pri(table, spec),
  4054. filter_idx);
  4055. }
  4056. }
  4057. up_read(&table->lock);
  4058. up_read(&efx->filter_sem);
  4059. return count;
  4060. }
  4061. #ifdef CONFIG_RFS_ACCEL
  4062. static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
  4063. unsigned int filter_idx)
  4064. {
  4065. struct efx_filter_spec *spec, saved_spec;
  4066. struct efx_ef10_filter_table *table;
  4067. struct efx_arfs_rule *rule = NULL;
  4068. bool ret = true, force = false;
  4069. u16 arfs_id;
  4070. down_read(&efx->filter_sem);
  4071. table = efx->filter_state;
  4072. down_write(&table->lock);
  4073. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  4074. if (!spec || spec->priority != EFX_FILTER_PRI_HINT)
  4075. goto out_unlock;
  4076. spin_lock_bh(&efx->rps_hash_lock);
  4077. if (!efx->rps_hash_table) {
  4078. /* In the absence of the table, we always return 0 to ARFS. */
  4079. arfs_id = 0;
  4080. } else {
  4081. rule = efx_rps_hash_find(efx, spec);
  4082. if (!rule)
  4083. /* ARFS table doesn't know of this filter, so remove it */
  4084. goto expire;
  4085. arfs_id = rule->arfs_id;
  4086. ret = efx_rps_check_rule(rule, filter_idx, &force);
  4087. if (force)
  4088. goto expire;
  4089. if (!ret) {
  4090. spin_unlock_bh(&efx->rps_hash_lock);
  4091. goto out_unlock;
  4092. }
  4093. }
  4094. if (!rps_may_expire_flow(efx->net_dev, spec->dmaq_id, flow_id, arfs_id))
  4095. ret = false;
  4096. else if (rule)
  4097. rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING;
  4098. expire:
  4099. saved_spec = *spec; /* remove operation will kfree spec */
  4100. spin_unlock_bh(&efx->rps_hash_lock);
  4101. /* At this point (since we dropped the lock), another thread might queue
  4102. * up a fresh insertion request (but the actual insertion will be held
  4103. * up by our possession of the filter table lock). In that case, it
  4104. * will set rule->filter_id to EFX_ARFS_FILTER_ID_PENDING, meaning that
  4105. * the rule is not removed by efx_rps_hash_del() below.
  4106. */
  4107. if (ret)
  4108. ret = efx_ef10_filter_remove_internal(efx, 1U << spec->priority,
  4109. filter_idx, true) == 0;
  4110. /* While we can't safely dereference rule (we dropped the lock), we can
  4111. * still test it for NULL.
  4112. */
  4113. if (ret && rule) {
  4114. /* Expiring, so remove entry from ARFS table */
  4115. spin_lock_bh(&efx->rps_hash_lock);
  4116. efx_rps_hash_del(efx, &saved_spec);
  4117. spin_unlock_bh(&efx->rps_hash_lock);
  4118. }
  4119. out_unlock:
  4120. up_write(&table->lock);
  4121. up_read(&efx->filter_sem);
  4122. return ret;
  4123. }
  4124. #endif /* CONFIG_RFS_ACCEL */
  4125. static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
  4126. {
  4127. int match_flags = 0;
  4128. #define MAP_FLAG(gen_flag, mcdi_field) do { \
  4129. u32 old_mcdi_flags = mcdi_flags; \
  4130. mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
  4131. mcdi_field ## _LBN); \
  4132. if (mcdi_flags != old_mcdi_flags) \
  4133. match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
  4134. } while (0)
  4135. if (encap) {
  4136. /* encap filters must specify encap type */
  4137. match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
  4138. /* and imply ethertype and ip proto */
  4139. mcdi_flags &=
  4140. ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
  4141. mcdi_flags &=
  4142. ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
  4143. /* VLAN tags refer to the outer packet */
  4144. MAP_FLAG(INNER_VID, INNER_VLAN);
  4145. MAP_FLAG(OUTER_VID, OUTER_VLAN);
  4146. /* everything else refers to the inner packet */
  4147. MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
  4148. MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
  4149. MAP_FLAG(REM_HOST, IFRM_SRC_IP);
  4150. MAP_FLAG(LOC_HOST, IFRM_DST_IP);
  4151. MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
  4152. MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
  4153. MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
  4154. MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
  4155. MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
  4156. MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
  4157. } else {
  4158. MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
  4159. MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
  4160. MAP_FLAG(REM_HOST, SRC_IP);
  4161. MAP_FLAG(LOC_HOST, DST_IP);
  4162. MAP_FLAG(REM_MAC, SRC_MAC);
  4163. MAP_FLAG(REM_PORT, SRC_PORT);
  4164. MAP_FLAG(LOC_MAC, DST_MAC);
  4165. MAP_FLAG(LOC_PORT, DST_PORT);
  4166. MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
  4167. MAP_FLAG(INNER_VID, INNER_VLAN);
  4168. MAP_FLAG(OUTER_VID, OUTER_VLAN);
  4169. MAP_FLAG(IP_PROTO, IP_PROTO);
  4170. }
  4171. #undef MAP_FLAG
  4172. /* Did we map them all? */
  4173. if (mcdi_flags)
  4174. return -EINVAL;
  4175. return match_flags;
  4176. }
  4177. static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
  4178. {
  4179. struct efx_ef10_filter_table *table = efx->filter_state;
  4180. struct efx_ef10_filter_vlan *vlan, *next_vlan;
  4181. /* See comment in efx_ef10_filter_table_remove() */
  4182. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4183. return;
  4184. if (!table)
  4185. return;
  4186. list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
  4187. efx_ef10_filter_del_vlan_internal(efx, vlan);
  4188. }
  4189. static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
  4190. bool encap,
  4191. enum efx_filter_match_flags match_flags)
  4192. {
  4193. unsigned int match_pri;
  4194. int mf;
  4195. for (match_pri = 0;
  4196. match_pri < table->rx_match_count;
  4197. match_pri++) {
  4198. mf = efx_ef10_filter_match_flags_from_mcdi(encap,
  4199. table->rx_match_mcdi_flags[match_pri]);
  4200. if (mf == match_flags)
  4201. return true;
  4202. }
  4203. return false;
  4204. }
  4205. static int
  4206. efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
  4207. struct efx_ef10_filter_table *table,
  4208. bool encap)
  4209. {
  4210. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
  4211. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
  4212. unsigned int pd_match_pri, pd_match_count;
  4213. size_t outlen;
  4214. int rc;
  4215. /* Find out which RX filter types are supported, and their priorities */
  4216. MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
  4217. encap ?
  4218. MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
  4219. MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
  4220. rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
  4221. inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
  4222. &outlen);
  4223. if (rc)
  4224. return rc;
  4225. pd_match_count = MCDI_VAR_ARRAY_LEN(
  4226. outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
  4227. for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
  4228. u32 mcdi_flags =
  4229. MCDI_ARRAY_DWORD(
  4230. outbuf,
  4231. GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
  4232. pd_match_pri);
  4233. rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
  4234. if (rc < 0) {
  4235. netif_dbg(efx, probe, efx->net_dev,
  4236. "%s: fw flags %#x pri %u not supported in driver\n",
  4237. __func__, mcdi_flags, pd_match_pri);
  4238. } else {
  4239. netif_dbg(efx, probe, efx->net_dev,
  4240. "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
  4241. __func__, mcdi_flags, pd_match_pri,
  4242. rc, table->rx_match_count);
  4243. table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
  4244. table->rx_match_count++;
  4245. }
  4246. }
  4247. return 0;
  4248. }
  4249. static int efx_ef10_filter_table_probe(struct efx_nic *efx)
  4250. {
  4251. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4252. struct net_device *net_dev = efx->net_dev;
  4253. struct efx_ef10_filter_table *table;
  4254. struct efx_ef10_vlan *vlan;
  4255. int rc;
  4256. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4257. return -EINVAL;
  4258. if (efx->filter_state) /* already probed */
  4259. return 0;
  4260. table = kzalloc(sizeof(*table), GFP_KERNEL);
  4261. if (!table)
  4262. return -ENOMEM;
  4263. table->rx_match_count = 0;
  4264. rc = efx_ef10_filter_table_probe_matches(efx, table, false);
  4265. if (rc)
  4266. goto fail;
  4267. if (nic_data->datapath_caps &
  4268. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
  4269. rc = efx_ef10_filter_table_probe_matches(efx, table, true);
  4270. if (rc)
  4271. goto fail;
  4272. if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
  4273. !(efx_ef10_filter_match_supported(table, false,
  4274. (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
  4275. efx_ef10_filter_match_supported(table, false,
  4276. (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
  4277. netif_info(efx, probe, net_dev,
  4278. "VLAN filters are not supported in this firmware variant\n");
  4279. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4280. efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4281. net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4282. }
  4283. table->entry = vzalloc(array_size(HUNT_FILTER_TBL_ROWS,
  4284. sizeof(*table->entry)));
  4285. if (!table->entry) {
  4286. rc = -ENOMEM;
  4287. goto fail;
  4288. }
  4289. table->mc_promisc_last = false;
  4290. table->vlan_filter =
  4291. !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
  4292. INIT_LIST_HEAD(&table->vlan_list);
  4293. init_rwsem(&table->lock);
  4294. efx->filter_state = table;
  4295. list_for_each_entry(vlan, &nic_data->vlan_list, list) {
  4296. rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
  4297. if (rc)
  4298. goto fail_add_vlan;
  4299. }
  4300. return 0;
  4301. fail_add_vlan:
  4302. efx_ef10_filter_cleanup_vlans(efx);
  4303. efx->filter_state = NULL;
  4304. fail:
  4305. kfree(table);
  4306. return rc;
  4307. }
  4308. /* Caller must hold efx->filter_sem for read if race against
  4309. * efx_ef10_filter_table_remove() is possible
  4310. */
  4311. static void efx_ef10_filter_table_restore(struct efx_nic *efx)
  4312. {
  4313. struct efx_ef10_filter_table *table = efx->filter_state;
  4314. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4315. unsigned int invalid_filters = 0, failed = 0;
  4316. struct efx_ef10_filter_vlan *vlan;
  4317. struct efx_filter_spec *spec;
  4318. struct efx_rss_context *ctx;
  4319. unsigned int filter_idx;
  4320. u32 mcdi_flags;
  4321. int match_pri;
  4322. int rc, i;
  4323. WARN_ON(!rwsem_is_locked(&efx->filter_sem));
  4324. if (!nic_data->must_restore_filters)
  4325. return;
  4326. if (!table)
  4327. return;
  4328. down_write(&table->lock);
  4329. mutex_lock(&efx->rss_lock);
  4330. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  4331. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  4332. if (!spec)
  4333. continue;
  4334. mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
  4335. match_pri = 0;
  4336. while (match_pri < table->rx_match_count &&
  4337. table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
  4338. ++match_pri;
  4339. if (match_pri >= table->rx_match_count) {
  4340. invalid_filters++;
  4341. goto not_restored;
  4342. }
  4343. if (spec->rss_context)
  4344. ctx = efx_find_rss_context_entry(efx, spec->rss_context);
  4345. else
  4346. ctx = &efx->rss_context;
  4347. if (spec->flags & EFX_FILTER_FLAG_RX_RSS) {
  4348. if (!ctx) {
  4349. netif_warn(efx, drv, efx->net_dev,
  4350. "Warning: unable to restore a filter with nonexistent RSS context %u.\n",
  4351. spec->rss_context);
  4352. invalid_filters++;
  4353. goto not_restored;
  4354. }
  4355. if (ctx->context_id == EFX_EF10_RSS_CONTEXT_INVALID) {
  4356. netif_warn(efx, drv, efx->net_dev,
  4357. "Warning: unable to restore a filter with RSS context %u as it was not created.\n",
  4358. spec->rss_context);
  4359. invalid_filters++;
  4360. goto not_restored;
  4361. }
  4362. }
  4363. rc = efx_ef10_filter_push(efx, spec,
  4364. &table->entry[filter_idx].handle,
  4365. ctx, false);
  4366. if (rc)
  4367. failed++;
  4368. if (rc) {
  4369. not_restored:
  4370. list_for_each_entry(vlan, &table->vlan_list, list)
  4371. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
  4372. if (vlan->default_filters[i] == filter_idx)
  4373. vlan->default_filters[i] =
  4374. EFX_EF10_FILTER_ID_INVALID;
  4375. kfree(spec);
  4376. efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
  4377. }
  4378. }
  4379. mutex_unlock(&efx->rss_lock);
  4380. up_write(&table->lock);
  4381. /* This can happen validly if the MC's capabilities have changed, so
  4382. * is not an error.
  4383. */
  4384. if (invalid_filters)
  4385. netif_dbg(efx, drv, efx->net_dev,
  4386. "Did not restore %u filters that are now unsupported.\n",
  4387. invalid_filters);
  4388. if (failed)
  4389. netif_err(efx, hw, efx->net_dev,
  4390. "unable to restore %u filters\n", failed);
  4391. else
  4392. nic_data->must_restore_filters = false;
  4393. }
  4394. static void efx_ef10_filter_table_remove(struct efx_nic *efx)
  4395. {
  4396. struct efx_ef10_filter_table *table = efx->filter_state;
  4397. MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
  4398. struct efx_filter_spec *spec;
  4399. unsigned int filter_idx;
  4400. int rc;
  4401. efx_ef10_filter_cleanup_vlans(efx);
  4402. efx->filter_state = NULL;
  4403. /* If we were called without locking, then it's not safe to free
  4404. * the table as others might be using it. So we just WARN, leak
  4405. * the memory, and potentially get an inconsistent filter table
  4406. * state.
  4407. * This should never actually happen.
  4408. */
  4409. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4410. return;
  4411. if (!table)
  4412. return;
  4413. for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
  4414. spec = efx_ef10_filter_entry_spec(table, filter_idx);
  4415. if (!spec)
  4416. continue;
  4417. MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
  4418. efx_ef10_filter_is_exclusive(spec) ?
  4419. MC_CMD_FILTER_OP_IN_OP_REMOVE :
  4420. MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
  4421. MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
  4422. table->entry[filter_idx].handle);
  4423. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
  4424. sizeof(inbuf), NULL, 0, NULL);
  4425. if (rc)
  4426. netif_info(efx, drv, efx->net_dev,
  4427. "%s: filter %04x remove failed\n",
  4428. __func__, filter_idx);
  4429. kfree(spec);
  4430. }
  4431. vfree(table->entry);
  4432. kfree(table);
  4433. }
  4434. static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
  4435. {
  4436. struct efx_ef10_filter_table *table = efx->filter_state;
  4437. unsigned int filter_idx;
  4438. efx_rwsem_assert_write_locked(&table->lock);
  4439. if (*id != EFX_EF10_FILTER_ID_INVALID) {
  4440. filter_idx = efx_ef10_filter_get_unsafe_id(*id);
  4441. if (!table->entry[filter_idx].spec)
  4442. netif_dbg(efx, drv, efx->net_dev,
  4443. "marked null spec old %04x:%04x\n", *id,
  4444. filter_idx);
  4445. table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
  4446. *id = EFX_EF10_FILTER_ID_INVALID;
  4447. }
  4448. }
  4449. /* Mark old per-VLAN filters that may need to be removed */
  4450. static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
  4451. struct efx_ef10_filter_vlan *vlan)
  4452. {
  4453. struct efx_ef10_filter_table *table = efx->filter_state;
  4454. unsigned int i;
  4455. for (i = 0; i < table->dev_uc_count; i++)
  4456. efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
  4457. for (i = 0; i < table->dev_mc_count; i++)
  4458. efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
  4459. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
  4460. efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
  4461. }
  4462. /* Mark old filters that may need to be removed.
  4463. * Caller must hold efx->filter_sem for read if race against
  4464. * efx_ef10_filter_table_remove() is possible
  4465. */
  4466. static void efx_ef10_filter_mark_old(struct efx_nic *efx)
  4467. {
  4468. struct efx_ef10_filter_table *table = efx->filter_state;
  4469. struct efx_ef10_filter_vlan *vlan;
  4470. down_write(&table->lock);
  4471. list_for_each_entry(vlan, &table->vlan_list, list)
  4472. _efx_ef10_filter_vlan_mark_old(efx, vlan);
  4473. up_write(&table->lock);
  4474. }
  4475. static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
  4476. {
  4477. struct efx_ef10_filter_table *table = efx->filter_state;
  4478. struct net_device *net_dev = efx->net_dev;
  4479. struct netdev_hw_addr *uc;
  4480. unsigned int i;
  4481. table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
  4482. ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
  4483. i = 1;
  4484. netdev_for_each_uc_addr(uc, net_dev) {
  4485. if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
  4486. table->uc_promisc = true;
  4487. break;
  4488. }
  4489. ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
  4490. i++;
  4491. }
  4492. table->dev_uc_count = i;
  4493. }
  4494. static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
  4495. {
  4496. struct efx_ef10_filter_table *table = efx->filter_state;
  4497. struct net_device *net_dev = efx->net_dev;
  4498. struct netdev_hw_addr *mc;
  4499. unsigned int i;
  4500. table->mc_overflow = false;
  4501. table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
  4502. i = 0;
  4503. netdev_for_each_mc_addr(mc, net_dev) {
  4504. if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
  4505. table->mc_promisc = true;
  4506. table->mc_overflow = true;
  4507. break;
  4508. }
  4509. ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
  4510. i++;
  4511. }
  4512. table->dev_mc_count = i;
  4513. }
  4514. static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
  4515. struct efx_ef10_filter_vlan *vlan,
  4516. bool multicast, bool rollback)
  4517. {
  4518. struct efx_ef10_filter_table *table = efx->filter_state;
  4519. struct efx_ef10_dev_addr *addr_list;
  4520. enum efx_filter_flags filter_flags;
  4521. struct efx_filter_spec spec;
  4522. u8 baddr[ETH_ALEN];
  4523. unsigned int i, j;
  4524. int addr_count;
  4525. u16 *ids;
  4526. int rc;
  4527. if (multicast) {
  4528. addr_list = table->dev_mc_list;
  4529. addr_count = table->dev_mc_count;
  4530. ids = vlan->mc;
  4531. } else {
  4532. addr_list = table->dev_uc_list;
  4533. addr_count = table->dev_uc_count;
  4534. ids = vlan->uc;
  4535. }
  4536. filter_flags = efx_rss_active(&efx->rss_context) ? EFX_FILTER_FLAG_RX_RSS : 0;
  4537. /* Insert/renew filters */
  4538. for (i = 0; i < addr_count; i++) {
  4539. EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
  4540. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
  4541. efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
  4542. rc = efx_ef10_filter_insert(efx, &spec, true);
  4543. if (rc < 0) {
  4544. if (rollback) {
  4545. netif_info(efx, drv, efx->net_dev,
  4546. "efx_ef10_filter_insert failed rc=%d\n",
  4547. rc);
  4548. /* Fall back to promiscuous */
  4549. for (j = 0; j < i; j++) {
  4550. efx_ef10_filter_remove_unsafe(
  4551. efx, EFX_FILTER_PRI_AUTO,
  4552. ids[j]);
  4553. ids[j] = EFX_EF10_FILTER_ID_INVALID;
  4554. }
  4555. return rc;
  4556. } else {
  4557. /* keep invalid ID, and carry on */
  4558. }
  4559. } else {
  4560. ids[i] = efx_ef10_filter_get_unsafe_id(rc);
  4561. }
  4562. }
  4563. if (multicast && rollback) {
  4564. /* Also need an Ethernet broadcast filter */
  4565. EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
  4566. EFX_EF10_FILTER_ID_INVALID);
  4567. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
  4568. eth_broadcast_addr(baddr);
  4569. efx_filter_set_eth_local(&spec, vlan->vid, baddr);
  4570. rc = efx_ef10_filter_insert(efx, &spec, true);
  4571. if (rc < 0) {
  4572. netif_warn(efx, drv, efx->net_dev,
  4573. "Broadcast filter insert failed rc=%d\n", rc);
  4574. /* Fall back to promiscuous */
  4575. for (j = 0; j < i; j++) {
  4576. efx_ef10_filter_remove_unsafe(
  4577. efx, EFX_FILTER_PRI_AUTO,
  4578. ids[j]);
  4579. ids[j] = EFX_EF10_FILTER_ID_INVALID;
  4580. }
  4581. return rc;
  4582. } else {
  4583. vlan->default_filters[EFX_EF10_BCAST] =
  4584. efx_ef10_filter_get_unsafe_id(rc);
  4585. }
  4586. }
  4587. return 0;
  4588. }
  4589. static int efx_ef10_filter_insert_def(struct efx_nic *efx,
  4590. struct efx_ef10_filter_vlan *vlan,
  4591. enum efx_encap_type encap_type,
  4592. bool multicast, bool rollback)
  4593. {
  4594. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4595. enum efx_filter_flags filter_flags;
  4596. struct efx_filter_spec spec;
  4597. u8 baddr[ETH_ALEN];
  4598. int rc;
  4599. u16 *id;
  4600. filter_flags = efx_rss_active(&efx->rss_context) ? EFX_FILTER_FLAG_RX_RSS : 0;
  4601. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
  4602. if (multicast)
  4603. efx_filter_set_mc_def(&spec);
  4604. else
  4605. efx_filter_set_uc_def(&spec);
  4606. if (encap_type) {
  4607. if (nic_data->datapath_caps &
  4608. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
  4609. efx_filter_set_encap_type(&spec, encap_type);
  4610. else
  4611. /* don't insert encap filters on non-supporting
  4612. * platforms. ID will be left as INVALID.
  4613. */
  4614. return 0;
  4615. }
  4616. if (vlan->vid != EFX_FILTER_VID_UNSPEC)
  4617. efx_filter_set_eth_local(&spec, vlan->vid, NULL);
  4618. rc = efx_ef10_filter_insert(efx, &spec, true);
  4619. if (rc < 0) {
  4620. const char *um = multicast ? "Multicast" : "Unicast";
  4621. const char *encap_name = "";
  4622. const char *encap_ipv = "";
  4623. if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
  4624. EFX_ENCAP_TYPE_VXLAN)
  4625. encap_name = "VXLAN ";
  4626. else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
  4627. EFX_ENCAP_TYPE_NVGRE)
  4628. encap_name = "NVGRE ";
  4629. else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
  4630. EFX_ENCAP_TYPE_GENEVE)
  4631. encap_name = "GENEVE ";
  4632. if (encap_type & EFX_ENCAP_FLAG_IPV6)
  4633. encap_ipv = "IPv6 ";
  4634. else if (encap_type)
  4635. encap_ipv = "IPv4 ";
  4636. /* unprivileged functions can't insert mismatch filters
  4637. * for encapsulated or unicast traffic, so downgrade
  4638. * those warnings to debug.
  4639. */
  4640. netif_cond_dbg(efx, drv, efx->net_dev,
  4641. rc == -EPERM && (encap_type || !multicast), warn,
  4642. "%s%s%s mismatch filter insert failed rc=%d\n",
  4643. encap_name, encap_ipv, um, rc);
  4644. } else if (multicast) {
  4645. /* mapping from encap types to default filter IDs (multicast) */
  4646. static enum efx_ef10_default_filters map[] = {
  4647. [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
  4648. [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
  4649. [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
  4650. [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
  4651. [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
  4652. EFX_EF10_VXLAN6_MCDEF,
  4653. [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
  4654. EFX_EF10_NVGRE6_MCDEF,
  4655. [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
  4656. EFX_EF10_GENEVE6_MCDEF,
  4657. };
  4658. /* quick bounds check (BCAST result impossible) */
  4659. BUILD_BUG_ON(EFX_EF10_BCAST != 0);
  4660. if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
  4661. WARN_ON(1);
  4662. return -EINVAL;
  4663. }
  4664. /* then follow map */
  4665. id = &vlan->default_filters[map[encap_type]];
  4666. EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
  4667. *id = efx_ef10_filter_get_unsafe_id(rc);
  4668. if (!nic_data->workaround_26807 && !encap_type) {
  4669. /* Also need an Ethernet broadcast filter */
  4670. efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
  4671. filter_flags, 0);
  4672. eth_broadcast_addr(baddr);
  4673. efx_filter_set_eth_local(&spec, vlan->vid, baddr);
  4674. rc = efx_ef10_filter_insert(efx, &spec, true);
  4675. if (rc < 0) {
  4676. netif_warn(efx, drv, efx->net_dev,
  4677. "Broadcast filter insert failed rc=%d\n",
  4678. rc);
  4679. if (rollback) {
  4680. /* Roll back the mc_def filter */
  4681. efx_ef10_filter_remove_unsafe(
  4682. efx, EFX_FILTER_PRI_AUTO,
  4683. *id);
  4684. *id = EFX_EF10_FILTER_ID_INVALID;
  4685. return rc;
  4686. }
  4687. } else {
  4688. EFX_WARN_ON_PARANOID(
  4689. vlan->default_filters[EFX_EF10_BCAST] !=
  4690. EFX_EF10_FILTER_ID_INVALID);
  4691. vlan->default_filters[EFX_EF10_BCAST] =
  4692. efx_ef10_filter_get_unsafe_id(rc);
  4693. }
  4694. }
  4695. rc = 0;
  4696. } else {
  4697. /* mapping from encap types to default filter IDs (unicast) */
  4698. static enum efx_ef10_default_filters map[] = {
  4699. [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
  4700. [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
  4701. [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
  4702. [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
  4703. [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
  4704. EFX_EF10_VXLAN6_UCDEF,
  4705. [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
  4706. EFX_EF10_NVGRE6_UCDEF,
  4707. [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
  4708. EFX_EF10_GENEVE6_UCDEF,
  4709. };
  4710. /* quick bounds check (BCAST result impossible) */
  4711. BUILD_BUG_ON(EFX_EF10_BCAST != 0);
  4712. if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
  4713. WARN_ON(1);
  4714. return -EINVAL;
  4715. }
  4716. /* then follow map */
  4717. id = &vlan->default_filters[map[encap_type]];
  4718. EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
  4719. *id = rc;
  4720. rc = 0;
  4721. }
  4722. return rc;
  4723. }
  4724. /* Remove filters that weren't renewed. */
  4725. static void efx_ef10_filter_remove_old(struct efx_nic *efx)
  4726. {
  4727. struct efx_ef10_filter_table *table = efx->filter_state;
  4728. int remove_failed = 0;
  4729. int remove_noent = 0;
  4730. int rc;
  4731. int i;
  4732. down_write(&table->lock);
  4733. for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
  4734. if (READ_ONCE(table->entry[i].spec) &
  4735. EFX_EF10_FILTER_FLAG_AUTO_OLD) {
  4736. rc = efx_ef10_filter_remove_internal(efx,
  4737. 1U << EFX_FILTER_PRI_AUTO, i, true);
  4738. if (rc == -ENOENT)
  4739. remove_noent++;
  4740. else if (rc)
  4741. remove_failed++;
  4742. }
  4743. }
  4744. up_write(&table->lock);
  4745. if (remove_failed)
  4746. netif_info(efx, drv, efx->net_dev,
  4747. "%s: failed to remove %d filters\n",
  4748. __func__, remove_failed);
  4749. if (remove_noent)
  4750. netif_info(efx, drv, efx->net_dev,
  4751. "%s: failed to remove %d non-existent filters\n",
  4752. __func__, remove_noent);
  4753. }
  4754. static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
  4755. {
  4756. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4757. u8 mac_old[ETH_ALEN];
  4758. int rc, rc2;
  4759. /* Only reconfigure a PF-created vport */
  4760. if (is_zero_ether_addr(nic_data->vport_mac))
  4761. return 0;
  4762. efx_device_detach_sync(efx);
  4763. efx_net_stop(efx->net_dev);
  4764. down_write(&efx->filter_sem);
  4765. efx_ef10_filter_table_remove(efx);
  4766. up_write(&efx->filter_sem);
  4767. rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
  4768. if (rc)
  4769. goto restore_filters;
  4770. ether_addr_copy(mac_old, nic_data->vport_mac);
  4771. rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
  4772. nic_data->vport_mac);
  4773. if (rc)
  4774. goto restore_vadaptor;
  4775. rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
  4776. efx->net_dev->dev_addr);
  4777. if (!rc) {
  4778. ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
  4779. } else {
  4780. rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
  4781. if (rc2) {
  4782. /* Failed to add original MAC, so clear vport_mac */
  4783. eth_zero_addr(nic_data->vport_mac);
  4784. goto reset_nic;
  4785. }
  4786. }
  4787. restore_vadaptor:
  4788. rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
  4789. if (rc2)
  4790. goto reset_nic;
  4791. restore_filters:
  4792. down_write(&efx->filter_sem);
  4793. rc2 = efx_ef10_filter_table_probe(efx);
  4794. up_write(&efx->filter_sem);
  4795. if (rc2)
  4796. goto reset_nic;
  4797. rc2 = efx_net_open(efx->net_dev);
  4798. if (rc2)
  4799. goto reset_nic;
  4800. efx_device_attach_if_not_resetting(efx);
  4801. return rc;
  4802. reset_nic:
  4803. netif_err(efx, drv, efx->net_dev,
  4804. "Failed to restore when changing MAC address - scheduling reset\n");
  4805. efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
  4806. return rc ? rc : rc2;
  4807. }
  4808. /* Caller must hold efx->filter_sem for read if race against
  4809. * efx_ef10_filter_table_remove() is possible
  4810. */
  4811. static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
  4812. struct efx_ef10_filter_vlan *vlan)
  4813. {
  4814. struct efx_ef10_filter_table *table = efx->filter_state;
  4815. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  4816. /* Do not install unspecified VID if VLAN filtering is enabled.
  4817. * Do not install all specified VIDs if VLAN filtering is disabled.
  4818. */
  4819. if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
  4820. return;
  4821. /* Insert/renew unicast filters */
  4822. if (table->uc_promisc) {
  4823. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
  4824. false, false);
  4825. efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
  4826. } else {
  4827. /* If any of the filters failed to insert, fall back to
  4828. * promiscuous mode - add in the uc_def filter. But keep
  4829. * our individual unicast filters.
  4830. */
  4831. if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
  4832. efx_ef10_filter_insert_def(efx, vlan,
  4833. EFX_ENCAP_TYPE_NONE,
  4834. false, false);
  4835. }
  4836. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
  4837. false, false);
  4838. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
  4839. EFX_ENCAP_FLAG_IPV6,
  4840. false, false);
  4841. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
  4842. false, false);
  4843. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
  4844. EFX_ENCAP_FLAG_IPV6,
  4845. false, false);
  4846. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
  4847. false, false);
  4848. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
  4849. EFX_ENCAP_FLAG_IPV6,
  4850. false, false);
  4851. /* Insert/renew multicast filters */
  4852. /* If changing promiscuous state with cascaded multicast filters, remove
  4853. * old filters first, so that packets are dropped rather than duplicated
  4854. */
  4855. if (nic_data->workaround_26807 &&
  4856. table->mc_promisc_last != table->mc_promisc)
  4857. efx_ef10_filter_remove_old(efx);
  4858. if (table->mc_promisc) {
  4859. if (nic_data->workaround_26807) {
  4860. /* If we failed to insert promiscuous filters, rollback
  4861. * and fall back to individual multicast filters
  4862. */
  4863. if (efx_ef10_filter_insert_def(efx, vlan,
  4864. EFX_ENCAP_TYPE_NONE,
  4865. true, true)) {
  4866. /* Changing promisc state, so remove old filters */
  4867. efx_ef10_filter_remove_old(efx);
  4868. efx_ef10_filter_insert_addr_list(efx, vlan,
  4869. true, false);
  4870. }
  4871. } else {
  4872. /* If we failed to insert promiscuous filters, don't
  4873. * rollback. Regardless, also insert the mc_list,
  4874. * unless it's incomplete due to overflow
  4875. */
  4876. efx_ef10_filter_insert_def(efx, vlan,
  4877. EFX_ENCAP_TYPE_NONE,
  4878. true, false);
  4879. if (!table->mc_overflow)
  4880. efx_ef10_filter_insert_addr_list(efx, vlan,
  4881. true, false);
  4882. }
  4883. } else {
  4884. /* If any filters failed to insert, rollback and fall back to
  4885. * promiscuous mode - mc_def filter and maybe broadcast. If
  4886. * that fails, roll back again and insert as many of our
  4887. * individual multicast filters as we can.
  4888. */
  4889. if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
  4890. /* Changing promisc state, so remove old filters */
  4891. if (nic_data->workaround_26807)
  4892. efx_ef10_filter_remove_old(efx);
  4893. if (efx_ef10_filter_insert_def(efx, vlan,
  4894. EFX_ENCAP_TYPE_NONE,
  4895. true, true))
  4896. efx_ef10_filter_insert_addr_list(efx, vlan,
  4897. true, false);
  4898. }
  4899. }
  4900. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
  4901. true, false);
  4902. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
  4903. EFX_ENCAP_FLAG_IPV6,
  4904. true, false);
  4905. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
  4906. true, false);
  4907. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
  4908. EFX_ENCAP_FLAG_IPV6,
  4909. true, false);
  4910. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
  4911. true, false);
  4912. efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
  4913. EFX_ENCAP_FLAG_IPV6,
  4914. true, false);
  4915. }
  4916. /* Caller must hold efx->filter_sem for read if race against
  4917. * efx_ef10_filter_table_remove() is possible
  4918. */
  4919. static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
  4920. {
  4921. struct efx_ef10_filter_table *table = efx->filter_state;
  4922. struct net_device *net_dev = efx->net_dev;
  4923. struct efx_ef10_filter_vlan *vlan;
  4924. bool vlan_filter;
  4925. if (!efx_dev_registered(efx))
  4926. return;
  4927. if (!table)
  4928. return;
  4929. efx_ef10_filter_mark_old(efx);
  4930. /* Copy/convert the address lists; add the primary station
  4931. * address and broadcast address
  4932. */
  4933. netif_addr_lock_bh(net_dev);
  4934. efx_ef10_filter_uc_addr_list(efx);
  4935. efx_ef10_filter_mc_addr_list(efx);
  4936. netif_addr_unlock_bh(net_dev);
  4937. /* If VLAN filtering changes, all old filters are finally removed.
  4938. * Do it in advance to avoid conflicts for unicast untagged and
  4939. * VLAN 0 tagged filters.
  4940. */
  4941. vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
  4942. if (table->vlan_filter != vlan_filter) {
  4943. table->vlan_filter = vlan_filter;
  4944. efx_ef10_filter_remove_old(efx);
  4945. }
  4946. list_for_each_entry(vlan, &table->vlan_list, list)
  4947. efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
  4948. efx_ef10_filter_remove_old(efx);
  4949. table->mc_promisc_last = table->mc_promisc;
  4950. }
  4951. static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
  4952. {
  4953. struct efx_ef10_filter_table *table = efx->filter_state;
  4954. struct efx_ef10_filter_vlan *vlan;
  4955. WARN_ON(!rwsem_is_locked(&efx->filter_sem));
  4956. list_for_each_entry(vlan, &table->vlan_list, list) {
  4957. if (vlan->vid == vid)
  4958. return vlan;
  4959. }
  4960. return NULL;
  4961. }
  4962. static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
  4963. {
  4964. struct efx_ef10_filter_table *table = efx->filter_state;
  4965. struct efx_ef10_filter_vlan *vlan;
  4966. unsigned int i;
  4967. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4968. return -EINVAL;
  4969. vlan = efx_ef10_filter_find_vlan(efx, vid);
  4970. if (WARN_ON(vlan)) {
  4971. netif_err(efx, drv, efx->net_dev,
  4972. "VLAN %u already added\n", vid);
  4973. return -EALREADY;
  4974. }
  4975. vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
  4976. if (!vlan)
  4977. return -ENOMEM;
  4978. vlan->vid = vid;
  4979. for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
  4980. vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
  4981. for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
  4982. vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
  4983. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
  4984. vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
  4985. list_add_tail(&vlan->list, &table->vlan_list);
  4986. if (efx_dev_registered(efx))
  4987. efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
  4988. return 0;
  4989. }
  4990. static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
  4991. struct efx_ef10_filter_vlan *vlan)
  4992. {
  4993. unsigned int i;
  4994. /* See comment in efx_ef10_filter_table_remove() */
  4995. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  4996. return;
  4997. list_del(&vlan->list);
  4998. for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
  4999. efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
  5000. vlan->uc[i]);
  5001. for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
  5002. efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
  5003. vlan->mc[i]);
  5004. for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
  5005. if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
  5006. efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
  5007. vlan->default_filters[i]);
  5008. kfree(vlan);
  5009. }
  5010. static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
  5011. {
  5012. struct efx_ef10_filter_vlan *vlan;
  5013. /* See comment in efx_ef10_filter_table_remove() */
  5014. if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
  5015. return;
  5016. vlan = efx_ef10_filter_find_vlan(efx, vid);
  5017. if (!vlan) {
  5018. netif_err(efx, drv, efx->net_dev,
  5019. "VLAN %u not found in filter state\n", vid);
  5020. return;
  5021. }
  5022. efx_ef10_filter_del_vlan_internal(efx, vlan);
  5023. }
  5024. static int efx_ef10_set_mac_address(struct efx_nic *efx)
  5025. {
  5026. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
  5027. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5028. bool was_enabled = efx->port_enabled;
  5029. int rc;
  5030. efx_device_detach_sync(efx);
  5031. efx_net_stop(efx->net_dev);
  5032. mutex_lock(&efx->mac_lock);
  5033. down_write(&efx->filter_sem);
  5034. efx_ef10_filter_table_remove(efx);
  5035. ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
  5036. efx->net_dev->dev_addr);
  5037. MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
  5038. nic_data->vport_id);
  5039. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
  5040. sizeof(inbuf), NULL, 0, NULL);
  5041. efx_ef10_filter_table_probe(efx);
  5042. up_write(&efx->filter_sem);
  5043. mutex_unlock(&efx->mac_lock);
  5044. if (was_enabled)
  5045. efx_net_open(efx->net_dev);
  5046. efx_device_attach_if_not_resetting(efx);
  5047. #ifdef CONFIG_SFC_SRIOV
  5048. if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
  5049. struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
  5050. if (rc == -EPERM) {
  5051. struct efx_nic *efx_pf;
  5052. /* Switch to PF and change MAC address on vport */
  5053. efx_pf = pci_get_drvdata(pci_dev_pf);
  5054. rc = efx_ef10_sriov_set_vf_mac(efx_pf,
  5055. nic_data->vf_index,
  5056. efx->net_dev->dev_addr);
  5057. } else if (!rc) {
  5058. struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
  5059. struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
  5060. unsigned int i;
  5061. /* MAC address successfully changed by VF (with MAC
  5062. * spoofing) so update the parent PF if possible.
  5063. */
  5064. for (i = 0; i < efx_pf->vf_count; ++i) {
  5065. struct ef10_vf *vf = nic_data->vf + i;
  5066. if (vf->efx == efx) {
  5067. ether_addr_copy(vf->mac,
  5068. efx->net_dev->dev_addr);
  5069. return 0;
  5070. }
  5071. }
  5072. }
  5073. } else
  5074. #endif
  5075. if (rc == -EPERM) {
  5076. netif_err(efx, drv, efx->net_dev,
  5077. "Cannot change MAC address; use sfboot to enable"
  5078. " mac-spoofing on this interface\n");
  5079. } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
  5080. /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
  5081. * fall-back to the method of changing the MAC address on the
  5082. * vport. This only applies to PFs because such versions of
  5083. * MCFW do not support VFs.
  5084. */
  5085. rc = efx_ef10_vport_set_mac_address(efx);
  5086. } else if (rc) {
  5087. efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
  5088. sizeof(inbuf), NULL, 0, rc);
  5089. }
  5090. return rc;
  5091. }
  5092. static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
  5093. {
  5094. efx_ef10_filter_sync_rx_mode(efx);
  5095. return efx_mcdi_set_mac(efx);
  5096. }
  5097. static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
  5098. {
  5099. efx_ef10_filter_sync_rx_mode(efx);
  5100. return 0;
  5101. }
  5102. static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
  5103. {
  5104. MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
  5105. MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
  5106. return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
  5107. NULL, 0, NULL);
  5108. }
  5109. /* MC BISTs follow a different poll mechanism to phy BISTs.
  5110. * The BIST is done in the poll handler on the MC, and the MCDI command
  5111. * will block until the BIST is done.
  5112. */
  5113. static int efx_ef10_poll_bist(struct efx_nic *efx)
  5114. {
  5115. int rc;
  5116. MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
  5117. size_t outlen;
  5118. u32 result;
  5119. rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
  5120. outbuf, sizeof(outbuf), &outlen);
  5121. if (rc != 0)
  5122. return rc;
  5123. if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
  5124. return -EIO;
  5125. result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
  5126. switch (result) {
  5127. case MC_CMD_POLL_BIST_PASSED:
  5128. netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
  5129. return 0;
  5130. case MC_CMD_POLL_BIST_TIMEOUT:
  5131. netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
  5132. return -EIO;
  5133. case MC_CMD_POLL_BIST_FAILED:
  5134. netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
  5135. return -EIO;
  5136. default:
  5137. netif_err(efx, hw, efx->net_dev,
  5138. "BIST returned unknown result %u", result);
  5139. return -EIO;
  5140. }
  5141. }
  5142. static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
  5143. {
  5144. int rc;
  5145. netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
  5146. rc = efx_ef10_start_bist(efx, bist_type);
  5147. if (rc != 0)
  5148. return rc;
  5149. return efx_ef10_poll_bist(efx);
  5150. }
  5151. static int
  5152. efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  5153. {
  5154. int rc, rc2;
  5155. efx_reset_down(efx, RESET_TYPE_WORLD);
  5156. rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
  5157. NULL, 0, NULL, 0, NULL);
  5158. if (rc != 0)
  5159. goto out;
  5160. tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
  5161. tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
  5162. rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
  5163. out:
  5164. if (rc == -EPERM)
  5165. rc = 0;
  5166. rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
  5167. return rc ? rc : rc2;
  5168. }
  5169. #ifdef CONFIG_SFC_MTD
  5170. struct efx_ef10_nvram_type_info {
  5171. u16 type, type_mask;
  5172. u8 port;
  5173. const char *name;
  5174. };
  5175. static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
  5176. { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
  5177. { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
  5178. { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
  5179. { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
  5180. { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
  5181. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
  5182. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
  5183. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
  5184. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
  5185. { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
  5186. { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
  5187. };
  5188. static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
  5189. struct efx_mcdi_mtd_partition *part,
  5190. unsigned int type)
  5191. {
  5192. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
  5193. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
  5194. const struct efx_ef10_nvram_type_info *info;
  5195. size_t size, erase_size, outlen;
  5196. bool protected;
  5197. int rc;
  5198. for (info = efx_ef10_nvram_types; ; info++) {
  5199. if (info ==
  5200. efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
  5201. return -ENODEV;
  5202. if ((type & ~info->type_mask) == info->type)
  5203. break;
  5204. }
  5205. if (info->port != efx_port_num(efx))
  5206. return -ENODEV;
  5207. rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
  5208. if (rc)
  5209. return rc;
  5210. if (protected)
  5211. return -ENODEV; /* hide it */
  5212. part->nvram_type = type;
  5213. MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
  5214. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
  5215. outbuf, sizeof(outbuf), &outlen);
  5216. if (rc)
  5217. return rc;
  5218. if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
  5219. return -EIO;
  5220. if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
  5221. (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
  5222. part->fw_subtype = MCDI_DWORD(outbuf,
  5223. NVRAM_METADATA_OUT_SUBTYPE);
  5224. part->common.dev_type_name = "EF10 NVRAM manager";
  5225. part->common.type_name = info->name;
  5226. part->common.mtd.type = MTD_NORFLASH;
  5227. part->common.mtd.flags = MTD_CAP_NORFLASH;
  5228. part->common.mtd.size = size;
  5229. part->common.mtd.erasesize = erase_size;
  5230. return 0;
  5231. }
  5232. static int efx_ef10_mtd_probe(struct efx_nic *efx)
  5233. {
  5234. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
  5235. struct efx_mcdi_mtd_partition *parts;
  5236. size_t outlen, n_parts_total, i, n_parts;
  5237. unsigned int type;
  5238. int rc;
  5239. ASSERT_RTNL();
  5240. BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
  5241. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
  5242. outbuf, sizeof(outbuf), &outlen);
  5243. if (rc)
  5244. return rc;
  5245. if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
  5246. return -EIO;
  5247. n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
  5248. if (n_parts_total >
  5249. MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
  5250. return -EIO;
  5251. parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
  5252. if (!parts)
  5253. return -ENOMEM;
  5254. n_parts = 0;
  5255. for (i = 0; i < n_parts_total; i++) {
  5256. type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
  5257. i);
  5258. rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
  5259. if (rc == 0)
  5260. n_parts++;
  5261. else if (rc != -ENODEV)
  5262. goto fail;
  5263. }
  5264. rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
  5265. fail:
  5266. if (rc)
  5267. kfree(parts);
  5268. return rc;
  5269. }
  5270. #endif /* CONFIG_SFC_MTD */
  5271. static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
  5272. {
  5273. _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
  5274. }
  5275. static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
  5276. u32 host_time) {}
  5277. static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
  5278. bool temp)
  5279. {
  5280. MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
  5281. int rc;
  5282. if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
  5283. channel->sync_events_state == SYNC_EVENTS_VALID ||
  5284. (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
  5285. return 0;
  5286. channel->sync_events_state = SYNC_EVENTS_REQUESTED;
  5287. MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
  5288. MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
  5289. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
  5290. channel->channel);
  5291. rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
  5292. inbuf, sizeof(inbuf), NULL, 0, NULL);
  5293. if (rc != 0)
  5294. channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
  5295. SYNC_EVENTS_DISABLED;
  5296. return rc;
  5297. }
  5298. static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
  5299. bool temp)
  5300. {
  5301. MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
  5302. int rc;
  5303. if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
  5304. (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
  5305. return 0;
  5306. if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
  5307. channel->sync_events_state = SYNC_EVENTS_DISABLED;
  5308. return 0;
  5309. }
  5310. channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
  5311. SYNC_EVENTS_DISABLED;
  5312. MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
  5313. MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
  5314. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
  5315. MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
  5316. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
  5317. channel->channel);
  5318. rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
  5319. inbuf, sizeof(inbuf), NULL, 0, NULL);
  5320. return rc;
  5321. }
  5322. static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
  5323. bool temp)
  5324. {
  5325. int (*set)(struct efx_channel *channel, bool temp);
  5326. struct efx_channel *channel;
  5327. set = en ?
  5328. efx_ef10_rx_enable_timestamping :
  5329. efx_ef10_rx_disable_timestamping;
  5330. channel = efx_ptp_channel(efx);
  5331. if (channel) {
  5332. int rc = set(channel, temp);
  5333. if (en && rc != 0) {
  5334. efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
  5335. return rc;
  5336. }
  5337. }
  5338. return 0;
  5339. }
  5340. static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
  5341. struct hwtstamp_config *init)
  5342. {
  5343. return -EOPNOTSUPP;
  5344. }
  5345. static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
  5346. struct hwtstamp_config *init)
  5347. {
  5348. int rc;
  5349. switch (init->rx_filter) {
  5350. case HWTSTAMP_FILTER_NONE:
  5351. efx_ef10_ptp_set_ts_sync_events(efx, false, false);
  5352. /* if TX timestamping is still requested then leave PTP on */
  5353. return efx_ptp_change_mode(efx,
  5354. init->tx_type != HWTSTAMP_TX_OFF, 0);
  5355. case HWTSTAMP_FILTER_ALL:
  5356. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  5357. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  5358. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  5359. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  5360. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5361. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5362. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  5363. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5364. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5365. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  5366. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5367. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5368. case HWTSTAMP_FILTER_NTP_ALL:
  5369. init->rx_filter = HWTSTAMP_FILTER_ALL;
  5370. rc = efx_ptp_change_mode(efx, true, 0);
  5371. if (!rc)
  5372. rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
  5373. if (rc)
  5374. efx_ptp_change_mode(efx, false, 0);
  5375. return rc;
  5376. default:
  5377. return -ERANGE;
  5378. }
  5379. }
  5380. static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
  5381. struct netdev_phys_item_id *ppid)
  5382. {
  5383. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5384. if (!is_valid_ether_addr(nic_data->port_id))
  5385. return -EOPNOTSUPP;
  5386. ppid->id_len = ETH_ALEN;
  5387. memcpy(ppid->id, nic_data->port_id, ppid->id_len);
  5388. return 0;
  5389. }
  5390. static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
  5391. {
  5392. if (proto != htons(ETH_P_8021Q))
  5393. return -EINVAL;
  5394. return efx_ef10_add_vlan(efx, vid);
  5395. }
  5396. static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
  5397. {
  5398. if (proto != htons(ETH_P_8021Q))
  5399. return -EINVAL;
  5400. return efx_ef10_del_vlan(efx, vid);
  5401. }
  5402. /* We rely on the MCDI wiping out our TX rings if it made any changes to the
  5403. * ports table, ensuring that any TSO descriptors that were made on a now-
  5404. * removed tunnel port will be blown away and won't break things when we try
  5405. * to transmit them using the new ports table.
  5406. */
  5407. static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
  5408. {
  5409. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5410. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
  5411. MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
  5412. bool will_reset = false;
  5413. size_t num_entries = 0;
  5414. size_t inlen, outlen;
  5415. size_t i;
  5416. int rc;
  5417. efx_dword_t flags_and_num_entries;
  5418. WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
  5419. nic_data->udp_tunnels_dirty = false;
  5420. if (!(nic_data->datapath_caps &
  5421. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
  5422. efx_device_attach_if_not_resetting(efx);
  5423. return 0;
  5424. }
  5425. BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
  5426. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
  5427. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
  5428. if (nic_data->udp_tunnels[i].count &&
  5429. nic_data->udp_tunnels[i].port) {
  5430. efx_dword_t entry;
  5431. EFX_POPULATE_DWORD_2(entry,
  5432. TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
  5433. ntohs(nic_data->udp_tunnels[i].port),
  5434. TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
  5435. nic_data->udp_tunnels[i].type);
  5436. *_MCDI_ARRAY_DWORD(inbuf,
  5437. SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
  5438. num_entries++) = entry;
  5439. }
  5440. }
  5441. BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
  5442. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
  5443. EFX_WORD_1_LBN);
  5444. BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
  5445. EFX_WORD_1_WIDTH);
  5446. EFX_POPULATE_DWORD_2(flags_and_num_entries,
  5447. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
  5448. !!unloading,
  5449. EFX_WORD_1, num_entries);
  5450. *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
  5451. flags_and_num_entries;
  5452. inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
  5453. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
  5454. inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
  5455. if (rc == -EIO) {
  5456. /* Most likely the MC rebooted due to another function also
  5457. * setting its tunnel port list. Mark the tunnel port list as
  5458. * dirty, so it will be pushed upon coming up from the reboot.
  5459. */
  5460. nic_data->udp_tunnels_dirty = true;
  5461. return 0;
  5462. }
  5463. if (rc) {
  5464. /* expected not available on unprivileged functions */
  5465. if (rc != -EPERM)
  5466. netif_warn(efx, drv, efx->net_dev,
  5467. "Unable to set UDP tunnel ports; rc=%d.\n", rc);
  5468. } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
  5469. (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
  5470. netif_info(efx, drv, efx->net_dev,
  5471. "Rebooting MC due to UDP tunnel port list change\n");
  5472. will_reset = true;
  5473. if (unloading)
  5474. /* Delay for the MC reset to complete. This will make
  5475. * unloading other functions a bit smoother. This is a
  5476. * race, but the other unload will work whichever way
  5477. * it goes, this just avoids an unnecessary error
  5478. * message.
  5479. */
  5480. msleep(100);
  5481. }
  5482. if (!will_reset && !unloading) {
  5483. /* The caller will have detached, relying on the MC reset to
  5484. * trigger a re-attach. Since there won't be an MC reset, we
  5485. * have to do the attach ourselves.
  5486. */
  5487. efx_device_attach_if_not_resetting(efx);
  5488. }
  5489. return rc;
  5490. }
  5491. static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
  5492. {
  5493. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5494. int rc = 0;
  5495. mutex_lock(&nic_data->udp_tunnels_lock);
  5496. if (nic_data->udp_tunnels_dirty) {
  5497. /* Make sure all TX are stopped while we modify the table, else
  5498. * we might race against an efx_features_check().
  5499. */
  5500. efx_device_detach_sync(efx);
  5501. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  5502. }
  5503. mutex_unlock(&nic_data->udp_tunnels_lock);
  5504. return rc;
  5505. }
  5506. static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
  5507. __be16 port)
  5508. {
  5509. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5510. size_t i;
  5511. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
  5512. if (!nic_data->udp_tunnels[i].count)
  5513. continue;
  5514. if (nic_data->udp_tunnels[i].port == port)
  5515. return &nic_data->udp_tunnels[i];
  5516. }
  5517. return NULL;
  5518. }
  5519. static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
  5520. struct efx_udp_tunnel tnl)
  5521. {
  5522. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5523. struct efx_udp_tunnel *match;
  5524. char typebuf[8];
  5525. size_t i;
  5526. int rc;
  5527. if (!(nic_data->datapath_caps &
  5528. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  5529. return 0;
  5530. efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
  5531. netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
  5532. typebuf, ntohs(tnl.port));
  5533. mutex_lock(&nic_data->udp_tunnels_lock);
  5534. /* Make sure all TX are stopped while we add to the table, else we
  5535. * might race against an efx_features_check().
  5536. */
  5537. efx_device_detach_sync(efx);
  5538. match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
  5539. if (match != NULL) {
  5540. if (match->type == tnl.type) {
  5541. netif_dbg(efx, drv, efx->net_dev,
  5542. "Referencing existing tunnel entry\n");
  5543. match->count++;
  5544. /* No need to cause an MCDI update */
  5545. rc = 0;
  5546. goto unlock_out;
  5547. }
  5548. efx_get_udp_tunnel_type_name(match->type,
  5549. typebuf, sizeof(typebuf));
  5550. netif_dbg(efx, drv, efx->net_dev,
  5551. "UDP port %d is already in use by %s\n",
  5552. ntohs(tnl.port), typebuf);
  5553. rc = -EEXIST;
  5554. goto unlock_out;
  5555. }
  5556. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
  5557. if (!nic_data->udp_tunnels[i].count) {
  5558. nic_data->udp_tunnels[i] = tnl;
  5559. nic_data->udp_tunnels[i].count = 1;
  5560. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  5561. goto unlock_out;
  5562. }
  5563. netif_dbg(efx, drv, efx->net_dev,
  5564. "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
  5565. typebuf, ntohs(tnl.port));
  5566. rc = -ENOMEM;
  5567. unlock_out:
  5568. mutex_unlock(&nic_data->udp_tunnels_lock);
  5569. return rc;
  5570. }
  5571. /* Called under the TX lock with the TX queue running, hence no-one can be
  5572. * in the middle of updating the UDP tunnels table. However, they could
  5573. * have tried and failed the MCDI, in which case they'll have set the dirty
  5574. * flag before dropping their locks.
  5575. */
  5576. static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
  5577. {
  5578. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5579. if (!(nic_data->datapath_caps &
  5580. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  5581. return false;
  5582. if (nic_data->udp_tunnels_dirty)
  5583. /* SW table may not match HW state, so just assume we can't
  5584. * use any UDP tunnel offloads.
  5585. */
  5586. return false;
  5587. return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
  5588. }
  5589. static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
  5590. struct efx_udp_tunnel tnl)
  5591. {
  5592. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  5593. struct efx_udp_tunnel *match;
  5594. char typebuf[8];
  5595. int rc;
  5596. if (!(nic_data->datapath_caps &
  5597. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  5598. return 0;
  5599. efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
  5600. netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
  5601. typebuf, ntohs(tnl.port));
  5602. mutex_lock(&nic_data->udp_tunnels_lock);
  5603. /* Make sure all TX are stopped while we remove from the table, else we
  5604. * might race against an efx_features_check().
  5605. */
  5606. efx_device_detach_sync(efx);
  5607. match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
  5608. if (match != NULL) {
  5609. if (match->type == tnl.type) {
  5610. if (--match->count) {
  5611. /* Port is still in use, so nothing to do */
  5612. netif_dbg(efx, drv, efx->net_dev,
  5613. "UDP tunnel port %d remains active\n",
  5614. ntohs(tnl.port));
  5615. rc = 0;
  5616. goto out_unlock;
  5617. }
  5618. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  5619. goto out_unlock;
  5620. }
  5621. efx_get_udp_tunnel_type_name(match->type,
  5622. typebuf, sizeof(typebuf));
  5623. netif_warn(efx, drv, efx->net_dev,
  5624. "UDP port %d is actually in use by %s, not removing\n",
  5625. ntohs(tnl.port), typebuf);
  5626. }
  5627. rc = -ENOENT;
  5628. out_unlock:
  5629. mutex_unlock(&nic_data->udp_tunnels_lock);
  5630. return rc;
  5631. }
  5632. #define EF10_OFFLOAD_FEATURES \
  5633. (NETIF_F_IP_CSUM | \
  5634. NETIF_F_HW_VLAN_CTAG_FILTER | \
  5635. NETIF_F_IPV6_CSUM | \
  5636. NETIF_F_RXHASH | \
  5637. NETIF_F_NTUPLE)
  5638. const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
  5639. .is_vf = true,
  5640. .mem_bar = efx_ef10_vf_mem_bar,
  5641. .mem_map_size = efx_ef10_mem_map_size,
  5642. .probe = efx_ef10_probe_vf,
  5643. .remove = efx_ef10_remove,
  5644. .dimension_resources = efx_ef10_dimension_resources,
  5645. .init = efx_ef10_init_nic,
  5646. .fini = efx_port_dummy_op_void,
  5647. .map_reset_reason = efx_ef10_map_reset_reason,
  5648. .map_reset_flags = efx_ef10_map_reset_flags,
  5649. .reset = efx_ef10_reset,
  5650. .probe_port = efx_mcdi_port_probe,
  5651. .remove_port = efx_mcdi_port_remove,
  5652. .fini_dmaq = efx_ef10_fini_dmaq,
  5653. .prepare_flr = efx_ef10_prepare_flr,
  5654. .finish_flr = efx_port_dummy_op_void,
  5655. .describe_stats = efx_ef10_describe_stats,
  5656. .update_stats = efx_ef10_update_stats_vf,
  5657. .start_stats = efx_port_dummy_op_void,
  5658. .pull_stats = efx_port_dummy_op_void,
  5659. .stop_stats = efx_port_dummy_op_void,
  5660. .set_id_led = efx_mcdi_set_id_led,
  5661. .push_irq_moderation = efx_ef10_push_irq_moderation,
  5662. .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
  5663. .check_mac_fault = efx_mcdi_mac_check_fault,
  5664. .reconfigure_port = efx_mcdi_port_reconfigure,
  5665. .get_wol = efx_ef10_get_wol_vf,
  5666. .set_wol = efx_ef10_set_wol_vf,
  5667. .resume_wol = efx_port_dummy_op_void,
  5668. .mcdi_request = efx_ef10_mcdi_request,
  5669. .mcdi_poll_response = efx_ef10_mcdi_poll_response,
  5670. .mcdi_read_response = efx_ef10_mcdi_read_response,
  5671. .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
  5672. .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
  5673. .irq_enable_master = efx_port_dummy_op_void,
  5674. .irq_test_generate = efx_ef10_irq_test_generate,
  5675. .irq_disable_non_ev = efx_port_dummy_op_void,
  5676. .irq_handle_msi = efx_ef10_msi_interrupt,
  5677. .irq_handle_legacy = efx_ef10_legacy_interrupt,
  5678. .tx_probe = efx_ef10_tx_probe,
  5679. .tx_init = efx_ef10_tx_init,
  5680. .tx_remove = efx_ef10_tx_remove,
  5681. .tx_write = efx_ef10_tx_write,
  5682. .tx_limit_len = efx_ef10_tx_limit_len,
  5683. .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
  5684. .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
  5685. .rx_probe = efx_ef10_rx_probe,
  5686. .rx_init = efx_ef10_rx_init,
  5687. .rx_remove = efx_ef10_rx_remove,
  5688. .rx_write = efx_ef10_rx_write,
  5689. .rx_defer_refill = efx_ef10_rx_defer_refill,
  5690. .ev_probe = efx_ef10_ev_probe,
  5691. .ev_init = efx_ef10_ev_init,
  5692. .ev_fini = efx_ef10_ev_fini,
  5693. .ev_remove = efx_ef10_ev_remove,
  5694. .ev_process = efx_ef10_ev_process,
  5695. .ev_read_ack = efx_ef10_ev_read_ack,
  5696. .ev_test_generate = efx_ef10_ev_test_generate,
  5697. .filter_table_probe = efx_ef10_filter_table_probe,
  5698. .filter_table_restore = efx_ef10_filter_table_restore,
  5699. .filter_table_remove = efx_ef10_filter_table_remove,
  5700. .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
  5701. .filter_insert = efx_ef10_filter_insert,
  5702. .filter_remove_safe = efx_ef10_filter_remove_safe,
  5703. .filter_get_safe = efx_ef10_filter_get_safe,
  5704. .filter_clear_rx = efx_ef10_filter_clear_rx,
  5705. .filter_count_rx_used = efx_ef10_filter_count_rx_used,
  5706. .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
  5707. .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
  5708. #ifdef CONFIG_RFS_ACCEL
  5709. .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
  5710. #endif
  5711. #ifdef CONFIG_SFC_MTD
  5712. .mtd_probe = efx_port_dummy_op_int,
  5713. #endif
  5714. .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
  5715. .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
  5716. .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
  5717. .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
  5718. #ifdef CONFIG_SFC_SRIOV
  5719. .vswitching_probe = efx_ef10_vswitching_probe_vf,
  5720. .vswitching_restore = efx_ef10_vswitching_restore_vf,
  5721. .vswitching_remove = efx_ef10_vswitching_remove_vf,
  5722. #endif
  5723. .get_mac_address = efx_ef10_get_mac_address_vf,
  5724. .set_mac_address = efx_ef10_set_mac_address,
  5725. .get_phys_port_id = efx_ef10_get_phys_port_id,
  5726. .revision = EFX_REV_HUNT_A0,
  5727. .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
  5728. .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
  5729. .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
  5730. .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
  5731. .can_rx_scatter = true,
  5732. .always_rx_scatter = true,
  5733. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  5734. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  5735. .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
  5736. .offload_features = EF10_OFFLOAD_FEATURES,
  5737. .mcdi_max_ver = 2,
  5738. .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
  5739. .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
  5740. 1 << HWTSTAMP_FILTER_ALL,
  5741. .rx_hash_key_size = 40,
  5742. };
  5743. const struct efx_nic_type efx_hunt_a0_nic_type = {
  5744. .is_vf = false,
  5745. .mem_bar = efx_ef10_pf_mem_bar,
  5746. .mem_map_size = efx_ef10_mem_map_size,
  5747. .probe = efx_ef10_probe_pf,
  5748. .remove = efx_ef10_remove,
  5749. .dimension_resources = efx_ef10_dimension_resources,
  5750. .init = efx_ef10_init_nic,
  5751. .fini = efx_port_dummy_op_void,
  5752. .map_reset_reason = efx_ef10_map_reset_reason,
  5753. .map_reset_flags = efx_ef10_map_reset_flags,
  5754. .reset = efx_ef10_reset,
  5755. .probe_port = efx_mcdi_port_probe,
  5756. .remove_port = efx_mcdi_port_remove,
  5757. .fini_dmaq = efx_ef10_fini_dmaq,
  5758. .prepare_flr = efx_ef10_prepare_flr,
  5759. .finish_flr = efx_port_dummy_op_void,
  5760. .describe_stats = efx_ef10_describe_stats,
  5761. .update_stats = efx_ef10_update_stats_pf,
  5762. .start_stats = efx_mcdi_mac_start_stats,
  5763. .pull_stats = efx_mcdi_mac_pull_stats,
  5764. .stop_stats = efx_mcdi_mac_stop_stats,
  5765. .set_id_led = efx_mcdi_set_id_led,
  5766. .push_irq_moderation = efx_ef10_push_irq_moderation,
  5767. .reconfigure_mac = efx_ef10_mac_reconfigure,
  5768. .check_mac_fault = efx_mcdi_mac_check_fault,
  5769. .reconfigure_port = efx_mcdi_port_reconfigure,
  5770. .get_wol = efx_ef10_get_wol,
  5771. .set_wol = efx_ef10_set_wol,
  5772. .resume_wol = efx_port_dummy_op_void,
  5773. .test_chip = efx_ef10_test_chip,
  5774. .test_nvram = efx_mcdi_nvram_test_all,
  5775. .mcdi_request = efx_ef10_mcdi_request,
  5776. .mcdi_poll_response = efx_ef10_mcdi_poll_response,
  5777. .mcdi_read_response = efx_ef10_mcdi_read_response,
  5778. .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
  5779. .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
  5780. .irq_enable_master = efx_port_dummy_op_void,
  5781. .irq_test_generate = efx_ef10_irq_test_generate,
  5782. .irq_disable_non_ev = efx_port_dummy_op_void,
  5783. .irq_handle_msi = efx_ef10_msi_interrupt,
  5784. .irq_handle_legacy = efx_ef10_legacy_interrupt,
  5785. .tx_probe = efx_ef10_tx_probe,
  5786. .tx_init = efx_ef10_tx_init,
  5787. .tx_remove = efx_ef10_tx_remove,
  5788. .tx_write = efx_ef10_tx_write,
  5789. .tx_limit_len = efx_ef10_tx_limit_len,
  5790. .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
  5791. .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
  5792. .rx_push_rss_context_config = efx_ef10_rx_push_rss_context_config,
  5793. .rx_pull_rss_context_config = efx_ef10_rx_pull_rss_context_config,
  5794. .rx_restore_rss_contexts = efx_ef10_rx_restore_rss_contexts,
  5795. .rx_probe = efx_ef10_rx_probe,
  5796. .rx_init = efx_ef10_rx_init,
  5797. .rx_remove = efx_ef10_rx_remove,
  5798. .rx_write = efx_ef10_rx_write,
  5799. .rx_defer_refill = efx_ef10_rx_defer_refill,
  5800. .ev_probe = efx_ef10_ev_probe,
  5801. .ev_init = efx_ef10_ev_init,
  5802. .ev_fini = efx_ef10_ev_fini,
  5803. .ev_remove = efx_ef10_ev_remove,
  5804. .ev_process = efx_ef10_ev_process,
  5805. .ev_read_ack = efx_ef10_ev_read_ack,
  5806. .ev_test_generate = efx_ef10_ev_test_generate,
  5807. .filter_table_probe = efx_ef10_filter_table_probe,
  5808. .filter_table_restore = efx_ef10_filter_table_restore,
  5809. .filter_table_remove = efx_ef10_filter_table_remove,
  5810. .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
  5811. .filter_insert = efx_ef10_filter_insert,
  5812. .filter_remove_safe = efx_ef10_filter_remove_safe,
  5813. .filter_get_safe = efx_ef10_filter_get_safe,
  5814. .filter_clear_rx = efx_ef10_filter_clear_rx,
  5815. .filter_count_rx_used = efx_ef10_filter_count_rx_used,
  5816. .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
  5817. .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
  5818. #ifdef CONFIG_RFS_ACCEL
  5819. .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
  5820. #endif
  5821. #ifdef CONFIG_SFC_MTD
  5822. .mtd_probe = efx_ef10_mtd_probe,
  5823. .mtd_rename = efx_mcdi_mtd_rename,
  5824. .mtd_read = efx_mcdi_mtd_read,
  5825. .mtd_erase = efx_mcdi_mtd_erase,
  5826. .mtd_write = efx_mcdi_mtd_write,
  5827. .mtd_sync = efx_mcdi_mtd_sync,
  5828. #endif
  5829. .ptp_write_host_time = efx_ef10_ptp_write_host_time,
  5830. .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
  5831. .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
  5832. .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
  5833. .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
  5834. .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
  5835. .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
  5836. .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
  5837. .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
  5838. #ifdef CONFIG_SFC_SRIOV
  5839. .sriov_configure = efx_ef10_sriov_configure,
  5840. .sriov_init = efx_ef10_sriov_init,
  5841. .sriov_fini = efx_ef10_sriov_fini,
  5842. .sriov_wanted = efx_ef10_sriov_wanted,
  5843. .sriov_reset = efx_ef10_sriov_reset,
  5844. .sriov_flr = efx_ef10_sriov_flr,
  5845. .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
  5846. .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
  5847. .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
  5848. .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
  5849. .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
  5850. .vswitching_probe = efx_ef10_vswitching_probe_pf,
  5851. .vswitching_restore = efx_ef10_vswitching_restore_pf,
  5852. .vswitching_remove = efx_ef10_vswitching_remove_pf,
  5853. #endif
  5854. .get_mac_address = efx_ef10_get_mac_address_pf,
  5855. .set_mac_address = efx_ef10_set_mac_address,
  5856. .tso_versions = efx_ef10_tso_versions,
  5857. .get_phys_port_id = efx_ef10_get_phys_port_id,
  5858. .revision = EFX_REV_HUNT_A0,
  5859. .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
  5860. .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
  5861. .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
  5862. .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
  5863. .can_rx_scatter = true,
  5864. .always_rx_scatter = true,
  5865. .option_descriptors = true,
  5866. .min_interrupt_mode = EFX_INT_MODE_LEGACY,
  5867. .max_interrupt_mode = EFX_INT_MODE_MSIX,
  5868. .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
  5869. .offload_features = EF10_OFFLOAD_FEATURES,
  5870. .mcdi_max_ver = 2,
  5871. .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
  5872. .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
  5873. 1 << HWTSTAMP_FILTER_ALL,
  5874. .rx_hash_key_size = 40,
  5875. };