ef10.c 194 KB

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