ef10.c 201 KB

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