ef10.c 194 KB

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