ef10.c 194 KB

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