ef10.c 133 KB

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