ef10.c 168 KB

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