ef10.c 128 KB

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