ef10.c 160 KB

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