ef10.c 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2012-2013 Solarflare Communications Inc.
  5. */
  6. #include "net_driver.h"
  7. #include "rx_common.h"
  8. #include "tx_common.h"
  9. #include "ef10_regs.h"
  10. #include "io.h"
  11. #include "mcdi.h"
  12. #include "mcdi_pcol.h"
  13. #include "mcdi_port.h"
  14. #include "mcdi_port_common.h"
  15. #include "mcdi_functions.h"
  16. #include "nic.h"
  17. #include "mcdi_filters.h"
  18. #include "workarounds.h"
  19. #include "selftest.h"
  20. #include "ef10_sriov.h"
  21. #include <linux/in.h>
  22. #include <linux/jhash.h>
  23. #include <linux/wait.h>
  24. #include <linux/workqueue.h>
  25. #include <net/udp_tunnel.h>
  26. /* Hardware control for EF10 architecture including 'Huntington'. */
  27. #define EFX_EF10_DRVGEN_EV 7
  28. enum {
  29. EFX_EF10_TEST = 1,
  30. EFX_EF10_REFILL,
  31. };
  32. /* VLAN list entry */
  33. struct efx_ef10_vlan {
  34. struct list_head list;
  35. u16 vid;
  36. };
  37. static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading);
  38. static const struct udp_tunnel_nic_info efx_ef10_udp_tunnels;
  39. static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
  40. {
  41. efx_dword_t reg;
  42. efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
  43. return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
  44. EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
  45. }
  46. /* On all EF10s up to and including SFC9220 (Medford1), all PFs use BAR 0 for
  47. * I/O space and BAR 2(&3) for memory. On SFC9250 (Medford2), there is no I/O
  48. * bar; PFs use BAR 0/1 for memory.
  49. */
  50. static unsigned int efx_ef10_pf_mem_bar(struct efx_nic *efx)
  51. {
  52. switch (efx->pci_dev->device) {
  53. case 0x0b03: /* SFC9250 PF */
  54. return 0;
  55. default:
  56. return 2;
  57. }
  58. }
  59. /* All VFs use BAR 0/1 for memory */
  60. static unsigned int efx_ef10_vf_mem_bar(struct efx_nic *efx)
  61. {
  62. return 0;
  63. }
  64. static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
  65. {
  66. int bar;
  67. bar = efx->type->mem_bar(efx);
  68. return resource_size(&efx->pci_dev->resource[bar]);
  69. }
  70. static bool efx_ef10_is_vf(struct efx_nic *efx)
  71. {
  72. return efx->type->is_vf;
  73. }
  74. #ifdef CONFIG_SFC_SRIOV
  75. static int efx_ef10_get_vf_index(struct efx_nic *efx)
  76. {
  77. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
  78. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  79. size_t outlen;
  80. int rc;
  81. rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
  82. sizeof(outbuf), &outlen);
  83. if (rc)
  84. return rc;
  85. if (outlen < sizeof(outbuf))
  86. return -EIO;
  87. nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
  88. return 0;
  89. }
  90. #endif
  91. static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
  92. {
  93. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V4_OUT_LEN);
  94. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  95. size_t outlen;
  96. int rc;
  97. BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
  98. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
  99. outbuf, sizeof(outbuf), &outlen);
  100. if (rc)
  101. return rc;
  102. if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
  103. netif_err(efx, drv, efx->net_dev,
  104. "unable to read datapath firmware capabilities\n");
  105. return -EIO;
  106. }
  107. nic_data->datapath_caps =
  108. MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
  109. if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
  110. nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
  111. GET_CAPABILITIES_V2_OUT_FLAGS2);
  112. nic_data->piobuf_size = MCDI_WORD(outbuf,
  113. GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
  114. } else {
  115. nic_data->datapath_caps2 = 0;
  116. nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
  117. }
  118. /* record the DPCPU firmware IDs to determine VEB vswitching support.
  119. */
  120. nic_data->rx_dpcpu_fw_id =
  121. MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
  122. nic_data->tx_dpcpu_fw_id =
  123. MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
  124. if (!(nic_data->datapath_caps &
  125. (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
  126. netif_err(efx, probe, efx->net_dev,
  127. "current firmware does not support an RX prefix\n");
  128. return -ENODEV;
  129. }
  130. if (outlen >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
  131. u8 vi_window_mode = MCDI_BYTE(outbuf,
  132. GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
  133. rc = efx_mcdi_window_mode_to_stride(efx, vi_window_mode);
  134. if (rc)
  135. return rc;
  136. } else {
  137. /* keep default VI stride */
  138. netif_dbg(efx, probe, efx->net_dev,
  139. "firmware did not report VI window mode, assuming vi_stride = %u\n",
  140. efx->vi_stride);
  141. }
  142. if (outlen >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
  143. efx->num_mac_stats = MCDI_WORD(outbuf,
  144. GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
  145. netif_dbg(efx, probe, efx->net_dev,
  146. "firmware reports num_mac_stats = %u\n",
  147. efx->num_mac_stats);
  148. } else {
  149. /* leave num_mac_stats as the default value, MC_CMD_MAC_NSTATS */
  150. netif_dbg(efx, probe, efx->net_dev,
  151. "firmware did not report num_mac_stats, assuming %u\n",
  152. efx->num_mac_stats);
  153. }
  154. return 0;
  155. }
  156. static void efx_ef10_read_licensed_features(struct efx_nic *efx)
  157. {
  158. MCDI_DECLARE_BUF(inbuf, MC_CMD_LICENSING_V3_IN_LEN);
  159. MCDI_DECLARE_BUF(outbuf, MC_CMD_LICENSING_V3_OUT_LEN);
  160. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  161. size_t outlen;
  162. int rc;
  163. MCDI_SET_DWORD(inbuf, LICENSING_V3_IN_OP,
  164. MC_CMD_LICENSING_V3_IN_OP_REPORT_LICENSE);
  165. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_LICENSING_V3, inbuf, sizeof(inbuf),
  166. outbuf, sizeof(outbuf), &outlen);
  167. if (rc || (outlen < MC_CMD_LICENSING_V3_OUT_LEN))
  168. return;
  169. nic_data->licensed_features = MCDI_QWORD(outbuf,
  170. LICENSING_V3_OUT_LICENSED_FEATURES);
  171. }
  172. static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
  173. {
  174. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
  175. int rc;
  176. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
  177. outbuf, sizeof(outbuf), NULL);
  178. if (rc)
  179. return rc;
  180. rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
  181. return rc > 0 ? rc : -ERANGE;
  182. }
  183. static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
  184. {
  185. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  186. unsigned int implemented;
  187. unsigned int enabled;
  188. int rc;
  189. nic_data->workaround_35388 = false;
  190. nic_data->workaround_61265 = false;
  191. rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
  192. if (rc == -ENOSYS) {
  193. /* Firmware without GET_WORKAROUNDS - not a problem. */
  194. rc = 0;
  195. } else if (rc == 0) {
  196. /* Bug61265 workaround is always enabled if implemented. */
  197. if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
  198. nic_data->workaround_61265 = true;
  199. if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
  200. nic_data->workaround_35388 = true;
  201. } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
  202. /* Workaround is implemented but not enabled.
  203. * Try to enable it.
  204. */
  205. rc = efx_mcdi_set_workaround(efx,
  206. MC_CMD_WORKAROUND_BUG35388,
  207. true, NULL);
  208. if (rc == 0)
  209. nic_data->workaround_35388 = true;
  210. /* If we failed to set the workaround just carry on. */
  211. rc = 0;
  212. }
  213. }
  214. netif_dbg(efx, probe, efx->net_dev,
  215. "workaround for bug 35388 is %sabled\n",
  216. nic_data->workaround_35388 ? "en" : "dis");
  217. netif_dbg(efx, probe, efx->net_dev,
  218. "workaround for bug 61265 is %sabled\n",
  219. nic_data->workaround_61265 ? "en" : "dis");
  220. return rc;
  221. }
  222. static void efx_ef10_process_timer_config(struct efx_nic *efx,
  223. const efx_dword_t *data)
  224. {
  225. unsigned int max_count;
  226. if (EFX_EF10_WORKAROUND_61265(efx)) {
  227. efx->timer_quantum_ns = MCDI_DWORD(data,
  228. GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
  229. efx->timer_max_ns = MCDI_DWORD(data,
  230. GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
  231. } else if (EFX_EF10_WORKAROUND_35388(efx)) {
  232. efx->timer_quantum_ns = MCDI_DWORD(data,
  233. GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
  234. max_count = MCDI_DWORD(data,
  235. GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
  236. efx->timer_max_ns = max_count * efx->timer_quantum_ns;
  237. } else {
  238. efx->timer_quantum_ns = MCDI_DWORD(data,
  239. GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
  240. max_count = MCDI_DWORD(data,
  241. GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
  242. efx->timer_max_ns = max_count * efx->timer_quantum_ns;
  243. }
  244. netif_dbg(efx, probe, efx->net_dev,
  245. "got timer properties from MC: quantum %u ns; max %u ns\n",
  246. efx->timer_quantum_ns, efx->timer_max_ns);
  247. }
  248. static int efx_ef10_get_timer_config(struct efx_nic *efx)
  249. {
  250. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
  251. int rc;
  252. rc = efx_ef10_get_timer_workarounds(efx);
  253. if (rc)
  254. return rc;
  255. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
  256. outbuf, sizeof(outbuf), NULL);
  257. if (rc == 0) {
  258. efx_ef10_process_timer_config(efx, outbuf);
  259. } else if (rc == -ENOSYS || rc == -EPERM) {
  260. /* Not available - fall back to Huntington defaults. */
  261. unsigned int quantum;
  262. rc = efx_ef10_get_sysclk_freq(efx);
  263. if (rc < 0)
  264. return rc;
  265. quantum = 1536000 / rc; /* 1536 cycles */
  266. efx->timer_quantum_ns = quantum;
  267. efx->timer_max_ns = efx->type->timer_period_max * quantum;
  268. rc = 0;
  269. } else {
  270. efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
  271. MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
  272. NULL, 0, rc);
  273. }
  274. return rc;
  275. }
  276. static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
  277. {
  278. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
  279. size_t outlen;
  280. int rc;
  281. BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
  282. rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
  283. outbuf, sizeof(outbuf), &outlen);
  284. if (rc)
  285. return rc;
  286. if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
  287. return -EIO;
  288. ether_addr_copy(mac_address,
  289. MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
  290. return 0;
  291. }
  292. static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
  293. {
  294. MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
  295. MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
  296. size_t outlen;
  297. int num_addrs, rc;
  298. MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
  299. EVB_PORT_ID_ASSIGNED);
  300. rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
  301. sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
  302. if (rc)
  303. return rc;
  304. if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
  305. return -EIO;
  306. num_addrs = MCDI_DWORD(outbuf,
  307. VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
  308. WARN_ON(num_addrs != 1);
  309. ether_addr_copy(mac_address,
  310. MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
  311. return 0;
  312. }
  313. static ssize_t link_control_flag_show(struct device *dev,
  314. struct device_attribute *attr,
  315. char *buf)
  316. {
  317. struct efx_nic *efx = dev_get_drvdata(dev);
  318. return sprintf(buf, "%d\n",
  319. ((efx->mcdi->fn_flags) &
  320. (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
  321. ? 1 : 0);
  322. }
  323. static ssize_t primary_flag_show(struct device *dev,
  324. struct device_attribute *attr,
  325. char *buf)
  326. {
  327. struct efx_nic *efx = dev_get_drvdata(dev);
  328. return sprintf(buf, "%d\n",
  329. ((efx->mcdi->fn_flags) &
  330. (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
  331. ? 1 : 0);
  332. }
  333. static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
  334. {
  335. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  336. struct efx_ef10_vlan *vlan;
  337. WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
  338. list_for_each_entry(vlan, &nic_data->vlan_list, list) {
  339. if (vlan->vid == vid)
  340. return vlan;
  341. }
  342. return NULL;
  343. }
  344. static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
  345. {
  346. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  347. struct efx_ef10_vlan *vlan;
  348. int rc;
  349. mutex_lock(&nic_data->vlan_lock);
  350. vlan = efx_ef10_find_vlan(efx, vid);
  351. if (vlan) {
  352. /* We add VID 0 on init. 8021q adds it on module init
  353. * for all interfaces with VLAN filtring feature.
  354. */
  355. if (vid == 0)
  356. goto done_unlock;
  357. netif_warn(efx, drv, efx->net_dev,
  358. "VLAN %u already added\n", vid);
  359. rc = -EALREADY;
  360. goto fail_exist;
  361. }
  362. rc = -ENOMEM;
  363. vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
  364. if (!vlan)
  365. goto fail_alloc;
  366. vlan->vid = vid;
  367. list_add_tail(&vlan->list, &nic_data->vlan_list);
  368. if (efx->filter_state) {
  369. mutex_lock(&efx->mac_lock);
  370. down_write(&efx->filter_sem);
  371. rc = efx_mcdi_filter_add_vlan(efx, vlan->vid);
  372. up_write(&efx->filter_sem);
  373. mutex_unlock(&efx->mac_lock);
  374. if (rc)
  375. goto fail_filter_add_vlan;
  376. }
  377. done_unlock:
  378. mutex_unlock(&nic_data->vlan_lock);
  379. return 0;
  380. fail_filter_add_vlan:
  381. list_del(&vlan->list);
  382. kfree(vlan);
  383. fail_alloc:
  384. fail_exist:
  385. mutex_unlock(&nic_data->vlan_lock);
  386. return rc;
  387. }
  388. static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
  389. struct efx_ef10_vlan *vlan)
  390. {
  391. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  392. WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
  393. if (efx->filter_state) {
  394. down_write(&efx->filter_sem);
  395. efx_mcdi_filter_del_vlan(efx, vlan->vid);
  396. up_write(&efx->filter_sem);
  397. }
  398. list_del(&vlan->list);
  399. kfree(vlan);
  400. }
  401. static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
  402. {
  403. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  404. struct efx_ef10_vlan *vlan;
  405. int rc = 0;
  406. /* 8021q removes VID 0 on module unload for all interfaces
  407. * with VLAN filtering feature. We need to keep it to receive
  408. * untagged traffic.
  409. */
  410. if (vid == 0)
  411. return 0;
  412. mutex_lock(&nic_data->vlan_lock);
  413. vlan = efx_ef10_find_vlan(efx, vid);
  414. if (!vlan) {
  415. netif_err(efx, drv, efx->net_dev,
  416. "VLAN %u to be deleted not found\n", vid);
  417. rc = -ENOENT;
  418. } else {
  419. efx_ef10_del_vlan_internal(efx, vlan);
  420. }
  421. mutex_unlock(&nic_data->vlan_lock);
  422. return rc;
  423. }
  424. static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
  425. {
  426. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  427. struct efx_ef10_vlan *vlan, *next_vlan;
  428. mutex_lock(&nic_data->vlan_lock);
  429. list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
  430. efx_ef10_del_vlan_internal(efx, vlan);
  431. mutex_unlock(&nic_data->vlan_lock);
  432. }
  433. static DEVICE_ATTR_RO(link_control_flag);
  434. static DEVICE_ATTR_RO(primary_flag);
  435. static int efx_ef10_probe(struct efx_nic *efx)
  436. {
  437. struct efx_ef10_nic_data *nic_data;
  438. int i, rc;
  439. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  440. if (!nic_data)
  441. return -ENOMEM;
  442. efx->nic_data = nic_data;
  443. /* we assume later that we can copy from this buffer in dwords */
  444. BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
  445. rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
  446. 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
  447. if (rc)
  448. goto fail1;
  449. /* Get the MC's warm boot count. In case it's rebooting right
  450. * now, be prepared to retry.
  451. */
  452. i = 0;
  453. for (;;) {
  454. rc = efx_ef10_get_warm_boot_count(efx);
  455. if (rc >= 0)
  456. break;
  457. if (++i == 5)
  458. goto fail2;
  459. ssleep(1);
  460. }
  461. nic_data->warm_boot_count = rc;
  462. /* In case we're recovering from a crash (kexec), we want to
  463. * cancel any outstanding request by the previous user of this
  464. * function. We send a special message using the least
  465. * significant bits of the 'high' (doorbell) register.
  466. */
  467. _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
  468. rc = efx_mcdi_init(efx);
  469. if (rc)
  470. goto fail2;
  471. mutex_init(&nic_data->udp_tunnels_lock);
  472. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
  473. nic_data->udp_tunnels[i].type =
  474. TUNNEL_ENCAP_UDP_PORT_ENTRY_INVALID;
  475. /* Reset (most) configuration for this function */
  476. rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
  477. if (rc)
  478. goto fail3;
  479. /* Enable event logging */
  480. rc = efx_mcdi_log_ctrl(efx, true, false, 0);
  481. if (rc)
  482. goto fail3;
  483. rc = device_create_file(&efx->pci_dev->dev,
  484. &dev_attr_link_control_flag);
  485. if (rc)
  486. goto fail3;
  487. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
  488. if (rc)
  489. goto fail4;
  490. rc = efx_get_pf_index(efx, &nic_data->pf_index);
  491. if (rc)
  492. goto fail5;
  493. rc = efx_ef10_init_datapath_caps(efx);
  494. if (rc < 0)
  495. goto fail5;
  496. efx_ef10_read_licensed_features(efx);
  497. /* We can have one VI for each vi_stride-byte region.
  498. * However, until we use TX option descriptors we need up to four
  499. * TX queues per channel for different checksumming combinations.
  500. */
  501. if (nic_data->datapath_caps &
  502. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
  503. efx->tx_queues_per_channel = 4;
  504. else
  505. efx->tx_queues_per_channel = 2;
  506. efx->max_vis = efx_ef10_mem_map_size(efx) / efx->vi_stride;
  507. if (!efx->max_vis) {
  508. netif_err(efx, drv, efx->net_dev, "error determining max VIs\n");
  509. rc = -EIO;
  510. goto fail5;
  511. }
  512. efx->max_channels = min_t(unsigned int, EFX_MAX_CHANNELS,
  513. efx->max_vis / efx->tx_queues_per_channel);
  514. efx->max_tx_channels = efx->max_channels;
  515. if (WARN_ON(efx->max_channels == 0)) {
  516. rc = -EIO;
  517. goto fail5;
  518. }
  519. efx->rx_packet_len_offset =
  520. ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
  521. if (nic_data->datapath_caps &
  522. (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_INCLUDE_FCS_LBN))
  523. efx->net_dev->hw_features |= NETIF_F_RXFCS;
  524. rc = efx_mcdi_port_get_number(efx);
  525. if (rc < 0)
  526. goto fail5;
  527. efx->port_num = rc;
  528. rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
  529. if (rc)
  530. goto fail5;
  531. rc = efx_ef10_get_timer_config(efx);
  532. if (rc < 0)
  533. goto fail5;
  534. rc = efx_mcdi_mon_probe(efx);
  535. if (rc && rc != -EPERM)
  536. goto fail5;
  537. efx_ptp_defer_probe_with_channel(efx);
  538. #ifdef CONFIG_SFC_SRIOV
  539. if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
  540. struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
  541. struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
  542. efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
  543. } else
  544. #endif
  545. ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
  546. INIT_LIST_HEAD(&nic_data->vlan_list);
  547. mutex_init(&nic_data->vlan_lock);
  548. /* Add unspecified VID to support VLAN filtering being disabled */
  549. rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
  550. if (rc)
  551. goto fail_add_vid_unspec;
  552. /* If VLAN filtering is enabled, we need VID 0 to get untagged
  553. * traffic. It is added automatically if 8021q module is loaded,
  554. * but we can't rely on it since module may be not loaded.
  555. */
  556. rc = efx_ef10_add_vlan(efx, 0);
  557. if (rc)
  558. goto fail_add_vid_0;
  559. if (nic_data->datapath_caps &
  560. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) &&
  561. efx->mcdi->fn_flags &
  562. (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_TRUSTED))
  563. efx->net_dev->udp_tunnel_nic_info = &efx_ef10_udp_tunnels;
  564. return 0;
  565. fail_add_vid_0:
  566. efx_ef10_cleanup_vlans(efx);
  567. fail_add_vid_unspec:
  568. mutex_destroy(&nic_data->vlan_lock);
  569. efx_ptp_remove(efx);
  570. efx_mcdi_mon_remove(efx);
  571. fail5:
  572. device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
  573. fail4:
  574. device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
  575. fail3:
  576. efx_mcdi_detach(efx);
  577. mutex_lock(&nic_data->udp_tunnels_lock);
  578. memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
  579. (void)efx_ef10_set_udp_tnl_ports(efx, true);
  580. mutex_unlock(&nic_data->udp_tunnels_lock);
  581. mutex_destroy(&nic_data->udp_tunnels_lock);
  582. efx_mcdi_fini(efx);
  583. fail2:
  584. efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
  585. fail1:
  586. kfree(nic_data);
  587. efx->nic_data = NULL;
  588. return rc;
  589. }
  590. #ifdef EFX_USE_PIO
  591. static void efx_ef10_free_piobufs(struct efx_nic *efx)
  592. {
  593. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  594. MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
  595. unsigned int i;
  596. int rc;
  597. BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
  598. for (i = 0; i < nic_data->n_piobufs; i++) {
  599. MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
  600. nic_data->piobuf_handle[i]);
  601. rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
  602. NULL, 0, NULL);
  603. WARN_ON(rc);
  604. }
  605. nic_data->n_piobufs = 0;
  606. }
  607. static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
  608. {
  609. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  610. MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
  611. unsigned int i;
  612. size_t outlen;
  613. int rc = 0;
  614. BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
  615. for (i = 0; i < n; i++) {
  616. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
  617. outbuf, sizeof(outbuf), &outlen);
  618. if (rc) {
  619. /* Don't display the MC error if we didn't have space
  620. * for a VF.
  621. */
  622. if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
  623. efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
  624. 0, outbuf, outlen, rc);
  625. break;
  626. }
  627. if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
  628. rc = -EIO;
  629. break;
  630. }
  631. nic_data->piobuf_handle[i] =
  632. MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
  633. netif_dbg(efx, probe, efx->net_dev,
  634. "allocated PIO buffer %u handle %x\n", i,
  635. nic_data->piobuf_handle[i]);
  636. }
  637. nic_data->n_piobufs = i;
  638. if (rc)
  639. efx_ef10_free_piobufs(efx);
  640. return rc;
  641. }
  642. static int efx_ef10_link_piobufs(struct efx_nic *efx)
  643. {
  644. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  645. MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_PIOBUF_IN_LEN);
  646. struct efx_channel *channel;
  647. struct efx_tx_queue *tx_queue;
  648. unsigned int offset, index;
  649. int rc;
  650. BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
  651. BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
  652. /* Link a buffer to each VI in the write-combining mapping */
  653. for (index = 0; index < nic_data->n_piobufs; ++index) {
  654. MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
  655. nic_data->piobuf_handle[index]);
  656. MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
  657. nic_data->pio_write_vi_base + index);
  658. rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
  659. inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
  660. NULL, 0, NULL);
  661. if (rc) {
  662. netif_err(efx, drv, efx->net_dev,
  663. "failed to link VI %u to PIO buffer %u (%d)\n",
  664. nic_data->pio_write_vi_base + index, index,
  665. rc);
  666. goto fail;
  667. }
  668. netif_dbg(efx, probe, efx->net_dev,
  669. "linked VI %u to PIO buffer %u\n",
  670. nic_data->pio_write_vi_base + index, index);
  671. }
  672. /* Link a buffer to each TX queue */
  673. efx_for_each_channel(channel, efx) {
  674. /* Extra channels, even those with TXQs (PTP), do not require
  675. * PIO resources.
  676. */
  677. if (!channel->type->want_pio ||
  678. channel->channel >= efx->xdp_channel_offset)
  679. continue;
  680. efx_for_each_channel_tx_queue(tx_queue, channel) {
  681. /* We assign the PIO buffers to queues in
  682. * reverse order to allow for the following
  683. * special case.
  684. */
  685. offset = ((efx->tx_channel_offset + efx->n_tx_channels -
  686. tx_queue->channel->channel - 1) *
  687. efx_piobuf_size);
  688. index = offset / nic_data->piobuf_size;
  689. offset = offset % nic_data->piobuf_size;
  690. /* When the host page size is 4K, the first
  691. * host page in the WC mapping may be within
  692. * the same VI page as the last TX queue. We
  693. * can only link one buffer to each VI.
  694. */
  695. if (tx_queue->queue == nic_data->pio_write_vi_base) {
  696. BUG_ON(index != 0);
  697. rc = 0;
  698. } else {
  699. MCDI_SET_DWORD(inbuf,
  700. LINK_PIOBUF_IN_PIOBUF_HANDLE,
  701. nic_data->piobuf_handle[index]);
  702. MCDI_SET_DWORD(inbuf,
  703. LINK_PIOBUF_IN_TXQ_INSTANCE,
  704. tx_queue->queue);
  705. rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
  706. inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
  707. NULL, 0, NULL);
  708. }
  709. if (rc) {
  710. /* This is non-fatal; the TX path just
  711. * won't use PIO for this queue
  712. */
  713. netif_err(efx, drv, efx->net_dev,
  714. "failed to link VI %u to PIO buffer %u (%d)\n",
  715. tx_queue->queue, index, rc);
  716. tx_queue->piobuf = NULL;
  717. } else {
  718. tx_queue->piobuf =
  719. nic_data->pio_write_base +
  720. index * efx->vi_stride + offset;
  721. tx_queue->piobuf_offset = offset;
  722. netif_dbg(efx, probe, efx->net_dev,
  723. "linked VI %u to PIO buffer %u offset %x addr %p\n",
  724. tx_queue->queue, index,
  725. tx_queue->piobuf_offset,
  726. tx_queue->piobuf);
  727. }
  728. }
  729. }
  730. return 0;
  731. fail:
  732. /* inbuf was defined for MC_CMD_LINK_PIOBUF. We can use the same
  733. * buffer for MC_CMD_UNLINK_PIOBUF because it's shorter.
  734. */
  735. BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_IN_LEN < MC_CMD_UNLINK_PIOBUF_IN_LEN);
  736. while (index--) {
  737. MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
  738. nic_data->pio_write_vi_base + index);
  739. efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
  740. inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
  741. NULL, 0, NULL);
  742. }
  743. return rc;
  744. }
  745. static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
  746. {
  747. struct efx_channel *channel;
  748. struct efx_tx_queue *tx_queue;
  749. /* All our existing PIO buffers went away */
  750. efx_for_each_channel(channel, efx)
  751. efx_for_each_channel_tx_queue(tx_queue, channel)
  752. tx_queue->piobuf = NULL;
  753. }
  754. #else /* !EFX_USE_PIO */
  755. static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
  756. {
  757. return n == 0 ? 0 : -ENOBUFS;
  758. }
  759. static int efx_ef10_link_piobufs(struct efx_nic *efx)
  760. {
  761. return 0;
  762. }
  763. static void efx_ef10_free_piobufs(struct efx_nic *efx)
  764. {
  765. }
  766. static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
  767. {
  768. }
  769. #endif /* EFX_USE_PIO */
  770. static void efx_ef10_remove(struct efx_nic *efx)
  771. {
  772. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  773. int rc;
  774. #ifdef CONFIG_SFC_SRIOV
  775. struct efx_ef10_nic_data *nic_data_pf;
  776. struct pci_dev *pci_dev_pf;
  777. struct efx_nic *efx_pf;
  778. struct ef10_vf *vf;
  779. if (efx->pci_dev->is_virtfn) {
  780. pci_dev_pf = efx->pci_dev->physfn;
  781. if (pci_dev_pf) {
  782. efx_pf = pci_get_drvdata(pci_dev_pf);
  783. nic_data_pf = efx_pf->nic_data;
  784. vf = nic_data_pf->vf + nic_data->vf_index;
  785. vf->efx = NULL;
  786. } else
  787. netif_info(efx, drv, efx->net_dev,
  788. "Could not get the PF id from VF\n");
  789. }
  790. #endif
  791. efx_ef10_cleanup_vlans(efx);
  792. mutex_destroy(&nic_data->vlan_lock);
  793. efx_ptp_remove(efx);
  794. efx_mcdi_mon_remove(efx);
  795. efx_mcdi_rx_free_indir_table(efx);
  796. if (nic_data->wc_membase)
  797. iounmap(nic_data->wc_membase);
  798. rc = efx_mcdi_free_vis(efx);
  799. WARN_ON(rc != 0);
  800. if (!nic_data->must_restore_piobufs)
  801. efx_ef10_free_piobufs(efx);
  802. device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
  803. device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
  804. efx_mcdi_detach(efx);
  805. memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
  806. mutex_lock(&nic_data->udp_tunnels_lock);
  807. (void)efx_ef10_set_udp_tnl_ports(efx, true);
  808. mutex_unlock(&nic_data->udp_tunnels_lock);
  809. mutex_destroy(&nic_data->udp_tunnels_lock);
  810. efx_mcdi_fini(efx);
  811. efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
  812. kfree(nic_data);
  813. }
  814. static int efx_ef10_probe_pf(struct efx_nic *efx)
  815. {
  816. return efx_ef10_probe(efx);
  817. }
  818. int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
  819. u32 *port_flags, u32 *vadaptor_flags,
  820. unsigned int *vlan_tags)
  821. {
  822. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  823. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
  824. MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
  825. size_t outlen;
  826. int rc;
  827. if (nic_data->datapath_caps &
  828. (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
  829. MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
  830. port_id);
  831. rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
  832. outbuf, sizeof(outbuf), &outlen);
  833. if (rc)
  834. return rc;
  835. if (outlen < sizeof(outbuf)) {
  836. rc = -EIO;
  837. return rc;
  838. }
  839. }
  840. if (port_flags)
  841. *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
  842. if (vadaptor_flags)
  843. *vadaptor_flags =
  844. MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
  845. if (vlan_tags)
  846. *vlan_tags =
  847. MCDI_DWORD(outbuf,
  848. VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
  849. return 0;
  850. }
  851. int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
  852. {
  853. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
  854. MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
  855. return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
  856. NULL, 0, NULL);
  857. }
  858. int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
  859. {
  860. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
  861. MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
  862. return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
  863. NULL, 0, NULL);
  864. }
  865. int efx_ef10_vport_add_mac(struct efx_nic *efx,
  866. unsigned int port_id, const u8 *mac)
  867. {
  868. MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
  869. MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
  870. ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
  871. return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
  872. sizeof(inbuf), NULL, 0, NULL);
  873. }
  874. int efx_ef10_vport_del_mac(struct efx_nic *efx,
  875. unsigned int port_id, const u8 *mac)
  876. {
  877. MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
  878. MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
  879. ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
  880. return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
  881. sizeof(inbuf), NULL, 0, NULL);
  882. }
  883. #ifdef CONFIG_SFC_SRIOV
  884. static int efx_ef10_probe_vf(struct efx_nic *efx)
  885. {
  886. int rc;
  887. struct pci_dev *pci_dev_pf;
  888. /* If the parent PF has no VF data structure, it doesn't know about this
  889. * VF so fail probe. The VF needs to be re-created. This can happen
  890. * if the PF driver was unloaded while any VF was assigned to a guest
  891. * (using Xen, only).
  892. */
  893. pci_dev_pf = efx->pci_dev->physfn;
  894. if (pci_dev_pf) {
  895. struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
  896. struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
  897. if (!nic_data_pf->vf) {
  898. netif_info(efx, drv, efx->net_dev,
  899. "The VF cannot link to its parent PF; "
  900. "please destroy and re-create the VF\n");
  901. return -EBUSY;
  902. }
  903. }
  904. rc = efx_ef10_probe(efx);
  905. if (rc)
  906. return rc;
  907. rc = efx_ef10_get_vf_index(efx);
  908. if (rc)
  909. goto fail;
  910. if (efx->pci_dev->is_virtfn) {
  911. if (efx->pci_dev->physfn) {
  912. struct efx_nic *efx_pf =
  913. pci_get_drvdata(efx->pci_dev->physfn);
  914. struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
  915. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  916. nic_data_p->vf[nic_data->vf_index].efx = efx;
  917. nic_data_p->vf[nic_data->vf_index].pci_dev =
  918. efx->pci_dev;
  919. } else
  920. netif_info(efx, drv, efx->net_dev,
  921. "Could not get the PF id from VF\n");
  922. }
  923. return 0;
  924. fail:
  925. efx_ef10_remove(efx);
  926. return rc;
  927. }
  928. #else
  929. static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
  930. {
  931. return 0;
  932. }
  933. #endif
  934. static int efx_ef10_alloc_vis(struct efx_nic *efx,
  935. unsigned int min_vis, unsigned int max_vis)
  936. {
  937. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  938. return efx_mcdi_alloc_vis(efx, min_vis, max_vis, &nic_data->vi_base,
  939. &nic_data->n_allocated_vis);
  940. }
  941. /* Note that the failure path of this function does not free
  942. * resources, as this will be done by efx_ef10_remove().
  943. */
  944. static int efx_ef10_dimension_resources(struct efx_nic *efx)
  945. {
  946. unsigned int min_vis = max_t(unsigned int, efx->tx_queues_per_channel,
  947. efx_separate_tx_channels ? 2 : 1);
  948. unsigned int channel_vis, pio_write_vi_base, max_vis;
  949. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  950. unsigned int uc_mem_map_size, wc_mem_map_size;
  951. void __iomem *membase;
  952. int rc;
  953. channel_vis = max(efx->n_channels,
  954. ((efx->n_tx_channels + efx->n_extra_tx_channels) *
  955. efx->tx_queues_per_channel) +
  956. efx->n_xdp_channels * efx->xdp_tx_per_channel);
  957. if (efx->max_vis && efx->max_vis < channel_vis) {
  958. netif_dbg(efx, drv, efx->net_dev,
  959. "Reducing channel VIs from %u to %u\n",
  960. channel_vis, efx->max_vis);
  961. channel_vis = efx->max_vis;
  962. }
  963. #ifdef EFX_USE_PIO
  964. /* Try to allocate PIO buffers if wanted and if the full
  965. * number of PIO buffers would be sufficient to allocate one
  966. * copy-buffer per TX channel. Failure is non-fatal, as there
  967. * are only a small number of PIO buffers shared between all
  968. * functions of the controller.
  969. */
  970. if (efx_piobuf_size != 0 &&
  971. nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
  972. efx->n_tx_channels) {
  973. unsigned int n_piobufs =
  974. DIV_ROUND_UP(efx->n_tx_channels,
  975. nic_data->piobuf_size / efx_piobuf_size);
  976. rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
  977. if (rc == -ENOSPC)
  978. netif_dbg(efx, probe, efx->net_dev,
  979. "out of PIO buffers; cannot allocate more\n");
  980. else if (rc == -EPERM)
  981. netif_dbg(efx, probe, efx->net_dev,
  982. "not permitted to allocate PIO buffers\n");
  983. else if (rc)
  984. netif_err(efx, probe, efx->net_dev,
  985. "failed to allocate PIO buffers (%d)\n", rc);
  986. else
  987. netif_dbg(efx, probe, efx->net_dev,
  988. "allocated %u PIO buffers\n", n_piobufs);
  989. }
  990. #else
  991. nic_data->n_piobufs = 0;
  992. #endif
  993. /* PIO buffers should be mapped with write-combining enabled,
  994. * and we want to make single UC and WC mappings rather than
  995. * several of each (in fact that's the only option if host
  996. * page size is >4K). So we may allocate some extra VIs just
  997. * for writing PIO buffers through.
  998. *
  999. * The UC mapping contains (channel_vis - 1) complete VIs and the
  1000. * first 4K of the next VI. Then the WC mapping begins with
  1001. * the remainder of this last VI.
  1002. */
  1003. uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * efx->vi_stride +
  1004. ER_DZ_TX_PIOBUF);
  1005. if (nic_data->n_piobufs) {
  1006. /* pio_write_vi_base rounds down to give the number of complete
  1007. * VIs inside the UC mapping.
  1008. */
  1009. pio_write_vi_base = uc_mem_map_size / efx->vi_stride;
  1010. wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
  1011. nic_data->n_piobufs) *
  1012. efx->vi_stride) -
  1013. uc_mem_map_size);
  1014. max_vis = pio_write_vi_base + nic_data->n_piobufs;
  1015. } else {
  1016. pio_write_vi_base = 0;
  1017. wc_mem_map_size = 0;
  1018. max_vis = channel_vis;
  1019. }
  1020. /* In case the last attached driver failed to free VIs, do it now */
  1021. rc = efx_mcdi_free_vis(efx);
  1022. if (rc != 0)
  1023. return rc;
  1024. rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
  1025. if (rc != 0)
  1026. return rc;
  1027. if (nic_data->n_allocated_vis < channel_vis) {
  1028. netif_info(efx, drv, efx->net_dev,
  1029. "Could not allocate enough VIs to satisfy RSS"
  1030. " requirements. Performance may not be optimal.\n");
  1031. /* We didn't get the VIs to populate our channels.
  1032. * We could keep what we got but then we'd have more
  1033. * interrupts than we need.
  1034. * Instead calculate new max_channels and restart
  1035. */
  1036. efx->max_channels = nic_data->n_allocated_vis;
  1037. efx->max_tx_channels =
  1038. nic_data->n_allocated_vis / efx->tx_queues_per_channel;
  1039. efx_mcdi_free_vis(efx);
  1040. return -EAGAIN;
  1041. }
  1042. /* If we didn't get enough VIs to map all the PIO buffers, free the
  1043. * PIO buffers
  1044. */
  1045. if (nic_data->n_piobufs &&
  1046. nic_data->n_allocated_vis <
  1047. pio_write_vi_base + nic_data->n_piobufs) {
  1048. netif_dbg(efx, probe, efx->net_dev,
  1049. "%u VIs are not sufficient to map %u PIO buffers\n",
  1050. nic_data->n_allocated_vis, nic_data->n_piobufs);
  1051. efx_ef10_free_piobufs(efx);
  1052. }
  1053. /* Shrink the original UC mapping of the memory BAR */
  1054. membase = ioremap(efx->membase_phys, uc_mem_map_size);
  1055. if (!membase) {
  1056. netif_err(efx, probe, efx->net_dev,
  1057. "could not shrink memory BAR to %x\n",
  1058. uc_mem_map_size);
  1059. return -ENOMEM;
  1060. }
  1061. iounmap(efx->membase);
  1062. efx->membase = membase;
  1063. /* Set up the WC mapping if needed */
  1064. if (wc_mem_map_size) {
  1065. nic_data->wc_membase = ioremap_wc(efx->membase_phys +
  1066. uc_mem_map_size,
  1067. wc_mem_map_size);
  1068. if (!nic_data->wc_membase) {
  1069. netif_err(efx, probe, efx->net_dev,
  1070. "could not allocate WC mapping of size %x\n",
  1071. wc_mem_map_size);
  1072. return -ENOMEM;
  1073. }
  1074. nic_data->pio_write_vi_base = pio_write_vi_base;
  1075. nic_data->pio_write_base =
  1076. nic_data->wc_membase +
  1077. (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
  1078. uc_mem_map_size);
  1079. rc = efx_ef10_link_piobufs(efx);
  1080. if (rc)
  1081. efx_ef10_free_piobufs(efx);
  1082. }
  1083. netif_dbg(efx, probe, efx->net_dev,
  1084. "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
  1085. &efx->membase_phys, efx->membase, uc_mem_map_size,
  1086. nic_data->wc_membase, wc_mem_map_size);
  1087. return 0;
  1088. }
  1089. static void efx_ef10_fini_nic(struct efx_nic *efx)
  1090. {
  1091. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1092. spin_lock_bh(&efx->stats_lock);
  1093. kfree(nic_data->mc_stats);
  1094. nic_data->mc_stats = NULL;
  1095. spin_unlock_bh(&efx->stats_lock);
  1096. }
  1097. static int efx_ef10_init_nic(struct efx_nic *efx)
  1098. {
  1099. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1100. struct net_device *net_dev = efx->net_dev;
  1101. netdev_features_t tun_feats, tso_feats;
  1102. int rc;
  1103. if (nic_data->must_check_datapath_caps) {
  1104. rc = efx_ef10_init_datapath_caps(efx);
  1105. if (rc)
  1106. return rc;
  1107. nic_data->must_check_datapath_caps = false;
  1108. }
  1109. if (efx->must_realloc_vis) {
  1110. /* We cannot let the number of VIs change now */
  1111. rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
  1112. nic_data->n_allocated_vis);
  1113. if (rc)
  1114. return rc;
  1115. efx->must_realloc_vis = false;
  1116. }
  1117. nic_data->mc_stats = kmalloc(efx->num_mac_stats * sizeof(__le64),
  1118. GFP_KERNEL);
  1119. if (!nic_data->mc_stats)
  1120. return -ENOMEM;
  1121. if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
  1122. rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
  1123. if (rc == 0) {
  1124. rc = efx_ef10_link_piobufs(efx);
  1125. if (rc)
  1126. efx_ef10_free_piobufs(efx);
  1127. }
  1128. /* Log an error on failure, but this is non-fatal.
  1129. * Permission errors are less important - we've presumably
  1130. * had the PIO buffer licence removed.
  1131. */
  1132. if (rc == -EPERM)
  1133. netif_dbg(efx, drv, efx->net_dev,
  1134. "not permitted to restore PIO buffers\n");
  1135. else if (rc)
  1136. netif_err(efx, drv, efx->net_dev,
  1137. "failed to restore PIO buffers (%d)\n", rc);
  1138. nic_data->must_restore_piobufs = false;
  1139. }
  1140. /* encap features might change during reset if fw variant changed */
  1141. if (efx_has_cap(efx, VXLAN_NVGRE) && !efx_ef10_is_vf(efx))
  1142. net_dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  1143. else
  1144. net_dev->hw_enc_features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
  1145. tun_feats = NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE |
  1146. NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM;
  1147. tso_feats = NETIF_F_TSO | NETIF_F_TSO6;
  1148. if (efx_has_cap(efx, TX_TSO_V2_ENCAP)) {
  1149. /* If this is first nic_init, or if it is a reset and a new fw
  1150. * variant has added new features, enable them by default.
  1151. * If the features are not new, maintain their current value.
  1152. */
  1153. if (!(net_dev->hw_features & tun_feats))
  1154. net_dev->features |= tun_feats;
  1155. net_dev->hw_enc_features |= tun_feats | tso_feats;
  1156. net_dev->hw_features |= tun_feats;
  1157. } else {
  1158. net_dev->hw_enc_features &= ~(tun_feats | tso_feats);
  1159. net_dev->hw_features &= ~tun_feats;
  1160. net_dev->features &= ~tun_feats;
  1161. }
  1162. /* don't fail init if RSS setup doesn't work */
  1163. rc = efx->type->rx_push_rss_config(efx, false,
  1164. efx->rss_context.rx_indir_table, NULL);
  1165. return 0;
  1166. }
  1167. static void efx_ef10_table_reset_mc_allocations(struct efx_nic *efx)
  1168. {
  1169. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1170. #ifdef CONFIG_SFC_SRIOV
  1171. unsigned int i;
  1172. #endif
  1173. /* All our allocations have been reset */
  1174. efx->must_realloc_vis = true;
  1175. efx_mcdi_filter_table_reset_mc_allocations(efx);
  1176. nic_data->must_restore_piobufs = true;
  1177. efx_ef10_forget_old_piobufs(efx);
  1178. efx->rss_context.context_id = EFX_MCDI_RSS_CONTEXT_INVALID;
  1179. /* Driver-created vswitches and vports must be re-created */
  1180. nic_data->must_probe_vswitching = true;
  1181. efx->vport_id = EVB_PORT_ID_ASSIGNED;
  1182. #ifdef CONFIG_SFC_SRIOV
  1183. if (nic_data->vf)
  1184. for (i = 0; i < efx->vf_count; i++)
  1185. nic_data->vf[i].vport_id = 0;
  1186. #endif
  1187. }
  1188. static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
  1189. {
  1190. if (reason == RESET_TYPE_MC_FAILURE)
  1191. return RESET_TYPE_DATAPATH;
  1192. return efx_mcdi_map_reset_reason(reason);
  1193. }
  1194. static int efx_ef10_map_reset_flags(u32 *flags)
  1195. {
  1196. enum {
  1197. EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
  1198. ETH_RESET_SHARED_SHIFT),
  1199. EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
  1200. ETH_RESET_OFFLOAD | ETH_RESET_MAC |
  1201. ETH_RESET_PHY | ETH_RESET_MGMT) <<
  1202. ETH_RESET_SHARED_SHIFT)
  1203. };
  1204. /* We assume for now that our PCI function is permitted to
  1205. * reset everything.
  1206. */
  1207. if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
  1208. *flags &= ~EF10_RESET_MC;
  1209. return RESET_TYPE_WORLD;
  1210. }
  1211. if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
  1212. *flags &= ~EF10_RESET_PORT;
  1213. return RESET_TYPE_ALL;
  1214. }
  1215. /* no invisible reset implemented */
  1216. return -EINVAL;
  1217. }
  1218. static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
  1219. {
  1220. int rc = efx_mcdi_reset(efx, reset_type);
  1221. /* Unprivileged functions return -EPERM, but need to return success
  1222. * here so that the datapath is brought back up.
  1223. */
  1224. if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
  1225. rc = 0;
  1226. /* If it was a port reset, trigger reallocation of MC resources.
  1227. * Note that on an MC reset nothing needs to be done now because we'll
  1228. * detect the MC reset later and handle it then.
  1229. * For an FLR, we never get an MC reset event, but the MC has reset all
  1230. * resources assigned to us, so we have to trigger reallocation now.
  1231. */
  1232. if ((reset_type == RESET_TYPE_ALL ||
  1233. reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
  1234. efx_ef10_table_reset_mc_allocations(efx);
  1235. return rc;
  1236. }
  1237. #define EF10_DMA_STAT(ext_name, mcdi_name) \
  1238. [EF10_STAT_ ## ext_name] = \
  1239. { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
  1240. #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
  1241. [EF10_STAT_ ## int_name] = \
  1242. { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
  1243. #define EF10_OTHER_STAT(ext_name) \
  1244. [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
  1245. static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
  1246. EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
  1247. EF10_DMA_STAT(port_tx_packets, TX_PKTS),
  1248. EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
  1249. EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
  1250. EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
  1251. EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
  1252. EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
  1253. EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
  1254. EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
  1255. EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
  1256. EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
  1257. EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
  1258. EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
  1259. EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
  1260. EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
  1261. EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
  1262. EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
  1263. EF10_OTHER_STAT(port_rx_good_bytes),
  1264. EF10_OTHER_STAT(port_rx_bad_bytes),
  1265. EF10_DMA_STAT(port_rx_packets, RX_PKTS),
  1266. EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
  1267. EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
  1268. EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
  1269. EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
  1270. EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
  1271. EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
  1272. EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
  1273. EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
  1274. EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
  1275. EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
  1276. EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
  1277. EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
  1278. EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
  1279. EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
  1280. EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
  1281. EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
  1282. EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
  1283. EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
  1284. EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
  1285. EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
  1286. EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
  1287. EFX_GENERIC_SW_STAT(rx_nodesc_trunc),
  1288. EFX_GENERIC_SW_STAT(rx_noskb_drops),
  1289. EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
  1290. EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
  1291. EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
  1292. EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
  1293. EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
  1294. EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
  1295. EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
  1296. EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
  1297. EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
  1298. EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
  1299. EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
  1300. EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
  1301. EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
  1302. EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
  1303. EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
  1304. EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
  1305. EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
  1306. EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
  1307. EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
  1308. EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
  1309. EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
  1310. EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
  1311. EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
  1312. EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
  1313. EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
  1314. EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
  1315. EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
  1316. EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
  1317. EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
  1318. EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
  1319. EF10_DMA_STAT(fec_uncorrected_errors, FEC_UNCORRECTED_ERRORS),
  1320. EF10_DMA_STAT(fec_corrected_errors, FEC_CORRECTED_ERRORS),
  1321. EF10_DMA_STAT(fec_corrected_symbols_lane0, FEC_CORRECTED_SYMBOLS_LANE0),
  1322. EF10_DMA_STAT(fec_corrected_symbols_lane1, FEC_CORRECTED_SYMBOLS_LANE1),
  1323. EF10_DMA_STAT(fec_corrected_symbols_lane2, FEC_CORRECTED_SYMBOLS_LANE2),
  1324. EF10_DMA_STAT(fec_corrected_symbols_lane3, FEC_CORRECTED_SYMBOLS_LANE3),
  1325. EF10_DMA_STAT(ctpio_vi_busy_fallback, CTPIO_VI_BUSY_FALLBACK),
  1326. EF10_DMA_STAT(ctpio_long_write_success, CTPIO_LONG_WRITE_SUCCESS),
  1327. EF10_DMA_STAT(ctpio_missing_dbell_fail, CTPIO_MISSING_DBELL_FAIL),
  1328. EF10_DMA_STAT(ctpio_overflow_fail, CTPIO_OVERFLOW_FAIL),
  1329. EF10_DMA_STAT(ctpio_underflow_fail, CTPIO_UNDERFLOW_FAIL),
  1330. EF10_DMA_STAT(ctpio_timeout_fail, CTPIO_TIMEOUT_FAIL),
  1331. EF10_DMA_STAT(ctpio_noncontig_wr_fail, CTPIO_NONCONTIG_WR_FAIL),
  1332. EF10_DMA_STAT(ctpio_frm_clobber_fail, CTPIO_FRM_CLOBBER_FAIL),
  1333. EF10_DMA_STAT(ctpio_invalid_wr_fail, CTPIO_INVALID_WR_FAIL),
  1334. EF10_DMA_STAT(ctpio_vi_clobber_fallback, CTPIO_VI_CLOBBER_FALLBACK),
  1335. EF10_DMA_STAT(ctpio_unqualified_fallback, CTPIO_UNQUALIFIED_FALLBACK),
  1336. EF10_DMA_STAT(ctpio_runt_fallback, CTPIO_RUNT_FALLBACK),
  1337. EF10_DMA_STAT(ctpio_success, CTPIO_SUCCESS),
  1338. EF10_DMA_STAT(ctpio_fallback, CTPIO_FALLBACK),
  1339. EF10_DMA_STAT(ctpio_poison, CTPIO_POISON),
  1340. EF10_DMA_STAT(ctpio_erase, CTPIO_ERASE),
  1341. };
  1342. #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
  1343. (1ULL << EF10_STAT_port_tx_packets) | \
  1344. (1ULL << EF10_STAT_port_tx_pause) | \
  1345. (1ULL << EF10_STAT_port_tx_unicast) | \
  1346. (1ULL << EF10_STAT_port_tx_multicast) | \
  1347. (1ULL << EF10_STAT_port_tx_broadcast) | \
  1348. (1ULL << EF10_STAT_port_rx_bytes) | \
  1349. (1ULL << \
  1350. EF10_STAT_port_rx_bytes_minus_good_bytes) | \
  1351. (1ULL << EF10_STAT_port_rx_good_bytes) | \
  1352. (1ULL << EF10_STAT_port_rx_bad_bytes) | \
  1353. (1ULL << EF10_STAT_port_rx_packets) | \
  1354. (1ULL << EF10_STAT_port_rx_good) | \
  1355. (1ULL << EF10_STAT_port_rx_bad) | \
  1356. (1ULL << EF10_STAT_port_rx_pause) | \
  1357. (1ULL << EF10_STAT_port_rx_control) | \
  1358. (1ULL << EF10_STAT_port_rx_unicast) | \
  1359. (1ULL << EF10_STAT_port_rx_multicast) | \
  1360. (1ULL << EF10_STAT_port_rx_broadcast) | \
  1361. (1ULL << EF10_STAT_port_rx_lt64) | \
  1362. (1ULL << EF10_STAT_port_rx_64) | \
  1363. (1ULL << EF10_STAT_port_rx_65_to_127) | \
  1364. (1ULL << EF10_STAT_port_rx_128_to_255) | \
  1365. (1ULL << EF10_STAT_port_rx_256_to_511) | \
  1366. (1ULL << EF10_STAT_port_rx_512_to_1023) |\
  1367. (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
  1368. (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
  1369. (1ULL << EF10_STAT_port_rx_gtjumbo) | \
  1370. (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
  1371. (1ULL << EF10_STAT_port_rx_overflow) | \
  1372. (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
  1373. (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
  1374. (1ULL << GENERIC_STAT_rx_noskb_drops))
  1375. /* On 7000 series NICs, these statistics are only provided by the 10G MAC.
  1376. * For a 10G/40G switchable port we do not expose these because they might
  1377. * not include all the packets they should.
  1378. * On 8000 series NICs these statistics are always provided.
  1379. */
  1380. #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
  1381. (1ULL << EF10_STAT_port_tx_lt64) | \
  1382. (1ULL << EF10_STAT_port_tx_64) | \
  1383. (1ULL << EF10_STAT_port_tx_65_to_127) |\
  1384. (1ULL << EF10_STAT_port_tx_128_to_255) |\
  1385. (1ULL << EF10_STAT_port_tx_256_to_511) |\
  1386. (1ULL << EF10_STAT_port_tx_512_to_1023) |\
  1387. (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
  1388. (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
  1389. /* These statistics are only provided by the 40G MAC. For a 10G/40G
  1390. * switchable port we do expose these because the errors will otherwise
  1391. * be silent.
  1392. */
  1393. #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
  1394. (1ULL << EF10_STAT_port_rx_length_error))
  1395. /* These statistics are only provided if the firmware supports the
  1396. * capability PM_AND_RXDP_COUNTERS.
  1397. */
  1398. #define HUNT_PM_AND_RXDP_STAT_MASK ( \
  1399. (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
  1400. (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
  1401. (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
  1402. (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
  1403. (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
  1404. (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
  1405. (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
  1406. (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
  1407. (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
  1408. (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
  1409. (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
  1410. (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
  1411. /* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V2,
  1412. * indicated by returning a value >= MC_CMD_MAC_NSTATS_V2 in
  1413. * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
  1414. * These bits are in the second u64 of the raw mask.
  1415. */
  1416. #define EF10_FEC_STAT_MASK ( \
  1417. (1ULL << (EF10_STAT_fec_uncorrected_errors - 64)) | \
  1418. (1ULL << (EF10_STAT_fec_corrected_errors - 64)) | \
  1419. (1ULL << (EF10_STAT_fec_corrected_symbols_lane0 - 64)) | \
  1420. (1ULL << (EF10_STAT_fec_corrected_symbols_lane1 - 64)) | \
  1421. (1ULL << (EF10_STAT_fec_corrected_symbols_lane2 - 64)) | \
  1422. (1ULL << (EF10_STAT_fec_corrected_symbols_lane3 - 64)))
  1423. /* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V3,
  1424. * indicated by returning a value >= MC_CMD_MAC_NSTATS_V3 in
  1425. * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
  1426. * These bits are in the second u64 of the raw mask.
  1427. */
  1428. #define EF10_CTPIO_STAT_MASK ( \
  1429. (1ULL << (EF10_STAT_ctpio_vi_busy_fallback - 64)) | \
  1430. (1ULL << (EF10_STAT_ctpio_long_write_success - 64)) | \
  1431. (1ULL << (EF10_STAT_ctpio_missing_dbell_fail - 64)) | \
  1432. (1ULL << (EF10_STAT_ctpio_overflow_fail - 64)) | \
  1433. (1ULL << (EF10_STAT_ctpio_underflow_fail - 64)) | \
  1434. (1ULL << (EF10_STAT_ctpio_timeout_fail - 64)) | \
  1435. (1ULL << (EF10_STAT_ctpio_noncontig_wr_fail - 64)) | \
  1436. (1ULL << (EF10_STAT_ctpio_frm_clobber_fail - 64)) | \
  1437. (1ULL << (EF10_STAT_ctpio_invalid_wr_fail - 64)) | \
  1438. (1ULL << (EF10_STAT_ctpio_vi_clobber_fallback - 64)) | \
  1439. (1ULL << (EF10_STAT_ctpio_unqualified_fallback - 64)) | \
  1440. (1ULL << (EF10_STAT_ctpio_runt_fallback - 64)) | \
  1441. (1ULL << (EF10_STAT_ctpio_success - 64)) | \
  1442. (1ULL << (EF10_STAT_ctpio_fallback - 64)) | \
  1443. (1ULL << (EF10_STAT_ctpio_poison - 64)) | \
  1444. (1ULL << (EF10_STAT_ctpio_erase - 64)))
  1445. static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
  1446. {
  1447. u64 raw_mask = HUNT_COMMON_STAT_MASK;
  1448. u32 port_caps = efx_mcdi_phy_get_caps(efx);
  1449. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1450. if (!(efx->mcdi->fn_flags &
  1451. 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
  1452. return 0;
  1453. if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
  1454. raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
  1455. /* 8000 series have everything even at 40G */
  1456. if (nic_data->datapath_caps2 &
  1457. (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
  1458. raw_mask |= HUNT_10G_ONLY_STAT_MASK;
  1459. } else {
  1460. raw_mask |= HUNT_10G_ONLY_STAT_MASK;
  1461. }
  1462. if (nic_data->datapath_caps &
  1463. (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
  1464. raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
  1465. return raw_mask;
  1466. }
  1467. static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
  1468. {
  1469. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1470. u64 raw_mask[2];
  1471. raw_mask[0] = efx_ef10_raw_stat_mask(efx);
  1472. /* Only show vadaptor stats when EVB capability is present */
  1473. if (nic_data->datapath_caps &
  1474. (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
  1475. raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
  1476. raw_mask[1] = (1ULL << (EF10_STAT_V1_COUNT - 64)) - 1;
  1477. } else {
  1478. raw_mask[1] = 0;
  1479. }
  1480. /* Only show FEC stats when NIC supports MC_CMD_MAC_STATS_V2 */
  1481. if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V2)
  1482. raw_mask[1] |= EF10_FEC_STAT_MASK;
  1483. /* CTPIO stats appear in V3. Only show them on devices that actually
  1484. * support CTPIO. Although this driver doesn't use CTPIO others might,
  1485. * and we may be reporting the stats for the underlying port.
  1486. */
  1487. if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V3 &&
  1488. (nic_data->datapath_caps2 &
  1489. (1 << MC_CMD_GET_CAPABILITIES_V4_OUT_CTPIO_LBN)))
  1490. raw_mask[1] |= EF10_CTPIO_STAT_MASK;
  1491. #if BITS_PER_LONG == 64
  1492. BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
  1493. mask[0] = raw_mask[0];
  1494. mask[1] = raw_mask[1];
  1495. #else
  1496. BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
  1497. mask[0] = raw_mask[0] & 0xffffffff;
  1498. mask[1] = raw_mask[0] >> 32;
  1499. mask[2] = raw_mask[1] & 0xffffffff;
  1500. #endif
  1501. }
  1502. static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
  1503. {
  1504. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1505. efx_ef10_get_stat_mask(efx, mask);
  1506. return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
  1507. mask, names);
  1508. }
  1509. static void efx_ef10_get_fec_stats(struct efx_nic *efx,
  1510. struct ethtool_fec_stats *fec_stats)
  1511. {
  1512. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1513. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1514. u64 *stats = nic_data->stats;
  1515. efx_ef10_get_stat_mask(efx, mask);
  1516. if (test_bit(EF10_STAT_fec_corrected_errors, mask))
  1517. fec_stats->corrected_blocks.total =
  1518. stats[EF10_STAT_fec_corrected_errors];
  1519. if (test_bit(EF10_STAT_fec_uncorrected_errors, mask))
  1520. fec_stats->uncorrectable_blocks.total =
  1521. stats[EF10_STAT_fec_uncorrected_errors];
  1522. }
  1523. static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
  1524. struct rtnl_link_stats64 *core_stats)
  1525. {
  1526. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1527. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1528. u64 *stats = nic_data->stats;
  1529. size_t stats_count = 0, index;
  1530. efx_ef10_get_stat_mask(efx, mask);
  1531. if (full_stats) {
  1532. for_each_set_bit(index, mask, EF10_STAT_COUNT) {
  1533. if (efx_ef10_stat_desc[index].name) {
  1534. *full_stats++ = stats[index];
  1535. ++stats_count;
  1536. }
  1537. }
  1538. }
  1539. if (!core_stats)
  1540. return stats_count;
  1541. if (nic_data->datapath_caps &
  1542. 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
  1543. /* Use vadaptor stats. */
  1544. core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
  1545. stats[EF10_STAT_rx_multicast] +
  1546. stats[EF10_STAT_rx_broadcast];
  1547. core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
  1548. stats[EF10_STAT_tx_multicast] +
  1549. stats[EF10_STAT_tx_broadcast];
  1550. core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
  1551. stats[EF10_STAT_rx_multicast_bytes] +
  1552. stats[EF10_STAT_rx_broadcast_bytes];
  1553. core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
  1554. stats[EF10_STAT_tx_multicast_bytes] +
  1555. stats[EF10_STAT_tx_broadcast_bytes];
  1556. core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
  1557. stats[GENERIC_STAT_rx_noskb_drops];
  1558. core_stats->multicast = stats[EF10_STAT_rx_multicast];
  1559. core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
  1560. core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
  1561. core_stats->rx_errors = core_stats->rx_crc_errors;
  1562. core_stats->tx_errors = stats[EF10_STAT_tx_bad];
  1563. } else {
  1564. /* Use port stats. */
  1565. core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
  1566. core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
  1567. core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
  1568. core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
  1569. core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
  1570. stats[GENERIC_STAT_rx_nodesc_trunc] +
  1571. stats[GENERIC_STAT_rx_noskb_drops];
  1572. core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
  1573. core_stats->rx_length_errors =
  1574. stats[EF10_STAT_port_rx_gtjumbo] +
  1575. stats[EF10_STAT_port_rx_length_error];
  1576. core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
  1577. core_stats->rx_frame_errors =
  1578. stats[EF10_STAT_port_rx_align_error];
  1579. core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
  1580. core_stats->rx_errors = (core_stats->rx_length_errors +
  1581. core_stats->rx_crc_errors +
  1582. core_stats->rx_frame_errors);
  1583. }
  1584. return stats_count;
  1585. }
  1586. static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
  1587. struct rtnl_link_stats64 *core_stats)
  1588. {
  1589. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1590. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1591. u64 *stats = nic_data->stats;
  1592. efx_ef10_get_stat_mask(efx, mask);
  1593. /* If NIC was fini'd (probably resetting), then we can't read
  1594. * updated stats right now.
  1595. */
  1596. if (nic_data->mc_stats) {
  1597. efx_nic_copy_stats(efx, nic_data->mc_stats);
  1598. efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
  1599. mask, stats, nic_data->mc_stats, false);
  1600. }
  1601. /* Update derived statistics */
  1602. efx_nic_fix_nodesc_drop_stat(efx,
  1603. &stats[EF10_STAT_port_rx_nodesc_drops]);
  1604. /* MC Firmware reads RX_BYTES and RX_GOOD_BYTES from the MAC.
  1605. * It then calculates RX_BAD_BYTES and DMAs it to us with RX_BYTES.
  1606. * We report these as port_rx_ stats. We are not given RX_GOOD_BYTES.
  1607. * Here we calculate port_rx_good_bytes.
  1608. */
  1609. stats[EF10_STAT_port_rx_good_bytes] =
  1610. stats[EF10_STAT_port_rx_bytes] -
  1611. stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
  1612. /* The asynchronous reads used to calculate RX_BAD_BYTES in
  1613. * MC Firmware are done such that we should not see an increase in
  1614. * RX_BAD_BYTES when a good packet has arrived. Unfortunately this
  1615. * does mean that the stat can decrease at times. Here we do not
  1616. * update the stat unless it has increased or has gone to zero
  1617. * (In the case of the NIC rebooting).
  1618. * Please see Bug 33781 for a discussion of why things work this way.
  1619. */
  1620. efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
  1621. stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
  1622. efx_update_sw_stats(efx, stats);
  1623. return efx_ef10_update_stats_common(efx, full_stats, core_stats);
  1624. }
  1625. static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
  1626. __must_hold(&efx->stats_lock)
  1627. {
  1628. MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
  1629. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1630. DECLARE_BITMAP(mask, EF10_STAT_COUNT);
  1631. __le64 generation_start, generation_end;
  1632. u64 *stats = nic_data->stats;
  1633. u32 dma_len = efx->num_mac_stats * sizeof(u64);
  1634. struct efx_buffer stats_buf;
  1635. __le64 *dma_stats;
  1636. int rc;
  1637. spin_unlock_bh(&efx->stats_lock);
  1638. efx_ef10_get_stat_mask(efx, mask);
  1639. rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_KERNEL);
  1640. if (rc) {
  1641. spin_lock_bh(&efx->stats_lock);
  1642. return rc;
  1643. }
  1644. dma_stats = stats_buf.addr;
  1645. dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
  1646. MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
  1647. MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
  1648. MAC_STATS_IN_DMA, 1);
  1649. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
  1650. MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
  1651. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
  1652. NULL, 0, NULL);
  1653. spin_lock_bh(&efx->stats_lock);
  1654. if (rc) {
  1655. /* Expect ENOENT if DMA queues have not been set up */
  1656. if (rc != -ENOENT || atomic_read(&efx->active_queues))
  1657. efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
  1658. sizeof(inbuf), NULL, 0, rc);
  1659. goto out;
  1660. }
  1661. generation_end = dma_stats[efx->num_mac_stats - 1];
  1662. if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
  1663. WARN_ON_ONCE(1);
  1664. goto out;
  1665. }
  1666. rmb();
  1667. efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
  1668. stats, stats_buf.addr, false);
  1669. rmb();
  1670. generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
  1671. if (generation_end != generation_start) {
  1672. rc = -EAGAIN;
  1673. goto out;
  1674. }
  1675. efx_update_sw_stats(efx, stats);
  1676. out:
  1677. /* releasing a DMA coherent buffer with BH disabled can panic */
  1678. spin_unlock_bh(&efx->stats_lock);
  1679. efx_nic_free_buffer(efx, &stats_buf);
  1680. spin_lock_bh(&efx->stats_lock);
  1681. return rc;
  1682. }
  1683. static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
  1684. struct rtnl_link_stats64 *core_stats)
  1685. {
  1686. if (efx_ef10_try_update_nic_stats_vf(efx))
  1687. return 0;
  1688. return efx_ef10_update_stats_common(efx, full_stats, core_stats);
  1689. }
  1690. static size_t efx_ef10_update_stats_atomic_vf(struct efx_nic *efx, u64 *full_stats,
  1691. struct rtnl_link_stats64 *core_stats)
  1692. {
  1693. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1694. /* In atomic context, cannot update HW stats. Just update the
  1695. * software stats and return so the caller can continue.
  1696. */
  1697. efx_update_sw_stats(efx, nic_data->stats);
  1698. return efx_ef10_update_stats_common(efx, full_stats, core_stats);
  1699. }
  1700. static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
  1701. {
  1702. struct efx_nic *efx = channel->efx;
  1703. unsigned int mode, usecs;
  1704. efx_dword_t timer_cmd;
  1705. if (channel->irq_moderation_us) {
  1706. mode = 3;
  1707. usecs = channel->irq_moderation_us;
  1708. } else {
  1709. mode = 0;
  1710. usecs = 0;
  1711. }
  1712. if (EFX_EF10_WORKAROUND_61265(efx)) {
  1713. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
  1714. unsigned int ns = usecs * 1000;
  1715. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
  1716. channel->channel);
  1717. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
  1718. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
  1719. MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
  1720. efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
  1721. inbuf, sizeof(inbuf), 0, NULL, 0);
  1722. } else if (EFX_EF10_WORKAROUND_35388(efx)) {
  1723. unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
  1724. EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
  1725. EFE_DD_EVQ_IND_TIMER_FLAGS,
  1726. ERF_DD_EVQ_IND_TIMER_MODE, mode,
  1727. ERF_DD_EVQ_IND_TIMER_VAL, ticks);
  1728. efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
  1729. channel->channel);
  1730. } else {
  1731. unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
  1732. EFX_POPULATE_DWORD_3(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
  1733. ERF_DZ_TC_TIMER_VAL, ticks,
  1734. ERF_FZ_TC_TMR_REL_VAL, ticks);
  1735. efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
  1736. channel->channel);
  1737. }
  1738. }
  1739. static void efx_ef10_get_wol_vf(struct efx_nic *efx,
  1740. struct ethtool_wolinfo *wol) {}
  1741. static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
  1742. {
  1743. return -EOPNOTSUPP;
  1744. }
  1745. static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
  1746. {
  1747. wol->supported = 0;
  1748. wol->wolopts = 0;
  1749. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1750. }
  1751. static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
  1752. {
  1753. if (type != 0)
  1754. return -EINVAL;
  1755. return 0;
  1756. }
  1757. static void efx_ef10_mcdi_request(struct efx_nic *efx,
  1758. const efx_dword_t *hdr, size_t hdr_len,
  1759. const efx_dword_t *sdu, size_t sdu_len)
  1760. {
  1761. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1762. u8 *pdu = nic_data->mcdi_buf.addr;
  1763. memcpy(pdu, hdr, hdr_len);
  1764. memcpy(pdu + hdr_len, sdu, sdu_len);
  1765. wmb();
  1766. /* The hardware provides 'low' and 'high' (doorbell) registers
  1767. * for passing the 64-bit address of an MCDI request to
  1768. * firmware. However the dwords are swapped by firmware. The
  1769. * least significant bits of the doorbell are then 0 for all
  1770. * MCDI requests due to alignment.
  1771. */
  1772. _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
  1773. ER_DZ_MC_DB_LWRD);
  1774. _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
  1775. ER_DZ_MC_DB_HWRD);
  1776. }
  1777. static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
  1778. {
  1779. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1780. const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
  1781. rmb();
  1782. return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
  1783. }
  1784. static void
  1785. efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
  1786. size_t offset, size_t outlen)
  1787. {
  1788. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1789. const u8 *pdu = nic_data->mcdi_buf.addr;
  1790. memcpy(outbuf, pdu + offset, outlen);
  1791. }
  1792. static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
  1793. {
  1794. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1795. /* All our allocations have been reset */
  1796. efx_ef10_table_reset_mc_allocations(efx);
  1797. /* The datapath firmware might have been changed */
  1798. nic_data->must_check_datapath_caps = true;
  1799. /* MAC statistics have been cleared on the NIC; clear the local
  1800. * statistic that we update with efx_update_diff_stat().
  1801. */
  1802. nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
  1803. }
  1804. static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
  1805. {
  1806. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1807. int rc;
  1808. rc = efx_ef10_get_warm_boot_count(efx);
  1809. if (rc < 0) {
  1810. /* The firmware is presumably in the process of
  1811. * rebooting. However, we are supposed to report each
  1812. * reboot just once, so we must only do that once we
  1813. * can read and store the updated warm boot count.
  1814. */
  1815. return 0;
  1816. }
  1817. if (rc == nic_data->warm_boot_count)
  1818. return 0;
  1819. nic_data->warm_boot_count = rc;
  1820. efx_ef10_mcdi_reboot_detected(efx);
  1821. return -EIO;
  1822. }
  1823. /* Handle an MSI interrupt
  1824. *
  1825. * Handle an MSI hardware interrupt. This routine schedules event
  1826. * queue processing. No interrupt acknowledgement cycle is necessary.
  1827. * Also, we never need to check that the interrupt is for us, since
  1828. * MSI interrupts cannot be shared.
  1829. */
  1830. static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
  1831. {
  1832. struct efx_msi_context *context = dev_id;
  1833. struct efx_nic *efx = context->efx;
  1834. netif_vdbg(efx, intr, efx->net_dev,
  1835. "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
  1836. if (likely(READ_ONCE(efx->irq_soft_enabled))) {
  1837. /* Note test interrupts */
  1838. if (context->index == efx->irq_level)
  1839. efx->last_irq_cpu = raw_smp_processor_id();
  1840. /* Schedule processing of the channel */
  1841. efx_schedule_channel_irq(efx->channel[context->index]);
  1842. }
  1843. return IRQ_HANDLED;
  1844. }
  1845. static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
  1846. {
  1847. struct efx_nic *efx = dev_id;
  1848. bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
  1849. struct efx_channel *channel;
  1850. efx_dword_t reg;
  1851. u32 queues;
  1852. /* Read the ISR which also ACKs the interrupts */
  1853. efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
  1854. queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
  1855. if (queues == 0)
  1856. return IRQ_NONE;
  1857. if (likely(soft_enabled)) {
  1858. /* Note test interrupts */
  1859. if (queues & (1U << efx->irq_level))
  1860. efx->last_irq_cpu = raw_smp_processor_id();
  1861. efx_for_each_channel(channel, efx) {
  1862. if (queues & 1)
  1863. efx_schedule_channel_irq(channel);
  1864. queues >>= 1;
  1865. }
  1866. }
  1867. netif_vdbg(efx, intr, efx->net_dev,
  1868. "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1869. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1870. return IRQ_HANDLED;
  1871. }
  1872. static int efx_ef10_irq_test_generate(struct efx_nic *efx)
  1873. {
  1874. MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
  1875. if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
  1876. NULL) == 0)
  1877. return -ENOTSUPP;
  1878. BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
  1879. MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
  1880. return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
  1881. inbuf, sizeof(inbuf), NULL, 0, NULL);
  1882. }
  1883. static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
  1884. {
  1885. /* low two bits of label are what we want for type */
  1886. BUILD_BUG_ON((EFX_TXQ_TYPE_OUTER_CSUM | EFX_TXQ_TYPE_INNER_CSUM) != 3);
  1887. tx_queue->type = tx_queue->label & 3;
  1888. return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
  1889. (tx_queue->ptr_mask + 1) *
  1890. sizeof(efx_qword_t),
  1891. GFP_KERNEL);
  1892. }
  1893. /* This writes to the TX_DESC_WPTR and also pushes data */
  1894. static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
  1895. const efx_qword_t *txd)
  1896. {
  1897. unsigned int write_ptr;
  1898. efx_oword_t reg;
  1899. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  1900. EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
  1901. reg.qword[0] = *txd;
  1902. efx_writeo_page(tx_queue->efx, &reg,
  1903. ER_DZ_TX_DESC_UPD, tx_queue->queue);
  1904. }
  1905. /* Add Firmware-Assisted TSO v2 option descriptors to a queue.
  1906. */
  1907. int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue, struct sk_buff *skb,
  1908. bool *data_mapped)
  1909. {
  1910. struct efx_tx_buffer *buffer;
  1911. u16 inner_ipv4_id = 0;
  1912. u16 outer_ipv4_id = 0;
  1913. struct tcphdr *tcp;
  1914. struct iphdr *ip;
  1915. u16 ip_tot_len;
  1916. u32 seqnum;
  1917. u32 mss;
  1918. EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
  1919. mss = skb_shinfo(skb)->gso_size;
  1920. if (unlikely(mss < 4)) {
  1921. WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
  1922. return -EINVAL;
  1923. }
  1924. if (skb->encapsulation) {
  1925. if (!tx_queue->tso_encap)
  1926. return -EINVAL;
  1927. ip = ip_hdr(skb);
  1928. if (ip->version == 4)
  1929. outer_ipv4_id = ntohs(ip->id);
  1930. ip = inner_ip_hdr(skb);
  1931. tcp = inner_tcp_hdr(skb);
  1932. } else {
  1933. ip = ip_hdr(skb);
  1934. tcp = tcp_hdr(skb);
  1935. }
  1936. /* 8000-series EF10 hardware requires that IP Total Length be
  1937. * greater than or equal to the value it will have in each segment
  1938. * (which is at most mss + 208 + TCP header length), but also less
  1939. * than (0x10000 - inner_network_header). Otherwise the TCP
  1940. * checksum calculation will be broken for encapsulated packets.
  1941. * We fill in ip->tot_len with 0xff30, which should satisfy the
  1942. * first requirement unless the MSS is ridiculously large (which
  1943. * should be impossible as the driver max MTU is 9216); it is
  1944. * guaranteed to satisfy the second as we only attempt TSO if
  1945. * inner_network_header <= 208.
  1946. */
  1947. ip_tot_len = 0x10000 - EFX_TSO2_MAX_HDRLEN;
  1948. EFX_WARN_ON_ONCE_PARANOID(mss + EFX_TSO2_MAX_HDRLEN +
  1949. (tcp->doff << 2u) > ip_tot_len);
  1950. if (ip->version == 4) {
  1951. ip->tot_len = htons(ip_tot_len);
  1952. ip->check = 0;
  1953. inner_ipv4_id = ntohs(ip->id);
  1954. } else {
  1955. ((struct ipv6hdr *)ip)->payload_len = htons(ip_tot_len);
  1956. }
  1957. seqnum = ntohl(tcp->seq);
  1958. buffer = efx_tx_queue_get_insert_buffer(tx_queue);
  1959. buffer->flags = EFX_TX_BUF_OPTION;
  1960. buffer->len = 0;
  1961. buffer->unmap_len = 0;
  1962. EFX_POPULATE_QWORD_5(buffer->option,
  1963. ESF_DZ_TX_DESC_IS_OPT, 1,
  1964. ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
  1965. ESF_DZ_TX_TSO_OPTION_TYPE,
  1966. ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
  1967. ESF_DZ_TX_TSO_IP_ID, inner_ipv4_id,
  1968. ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
  1969. );
  1970. ++tx_queue->insert_count;
  1971. buffer = efx_tx_queue_get_insert_buffer(tx_queue);
  1972. buffer->flags = EFX_TX_BUF_OPTION;
  1973. buffer->len = 0;
  1974. buffer->unmap_len = 0;
  1975. EFX_POPULATE_QWORD_5(buffer->option,
  1976. ESF_DZ_TX_DESC_IS_OPT, 1,
  1977. ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
  1978. ESF_DZ_TX_TSO_OPTION_TYPE,
  1979. ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
  1980. ESF_DZ_TX_TSO_OUTER_IPID, outer_ipv4_id,
  1981. ESF_DZ_TX_TSO_TCP_MSS, mss
  1982. );
  1983. ++tx_queue->insert_count;
  1984. return 0;
  1985. }
  1986. static u32 efx_ef10_tso_versions(struct efx_nic *efx)
  1987. {
  1988. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  1989. u32 tso_versions = 0;
  1990. if (nic_data->datapath_caps &
  1991. (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
  1992. tso_versions |= BIT(1);
  1993. if (nic_data->datapath_caps2 &
  1994. (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
  1995. tso_versions |= BIT(2);
  1996. return tso_versions;
  1997. }
  1998. static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
  1999. {
  2000. bool csum_offload = tx_queue->type & EFX_TXQ_TYPE_OUTER_CSUM;
  2001. bool inner_csum = tx_queue->type & EFX_TXQ_TYPE_INNER_CSUM;
  2002. struct efx_channel *channel = tx_queue->channel;
  2003. struct efx_nic *efx = tx_queue->efx;
  2004. struct efx_ef10_nic_data *nic_data;
  2005. efx_qword_t *txd;
  2006. int rc;
  2007. nic_data = efx->nic_data;
  2008. /* Only attempt to enable TX timestamping if we have the license for it,
  2009. * otherwise TXQ init will fail
  2010. */
  2011. if (!(nic_data->licensed_features &
  2012. (1 << LICENSED_V3_FEATURES_TX_TIMESTAMPS_LBN))) {
  2013. tx_queue->timestamping = false;
  2014. /* Disable sync events on this channel. */
  2015. if (efx->type->ptp_set_ts_sync_events)
  2016. efx->type->ptp_set_ts_sync_events(efx, false, false);
  2017. }
  2018. /* TSOv2 is a limited resource that can only be configured on a limited
  2019. * number of queues. TSO without checksum offload is not really a thing,
  2020. * so we only enable it for those queues.
  2021. * TSOv2 cannot be used with Hardware timestamping, and is never needed
  2022. * for XDP tx.
  2023. */
  2024. if (efx_has_cap(efx, TX_TSO_V2)) {
  2025. if ((csum_offload || inner_csum) &&
  2026. !tx_queue->timestamping && !tx_queue->xdp_tx) {
  2027. tx_queue->tso_version = 2;
  2028. netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
  2029. channel->channel);
  2030. }
  2031. } else if (efx_has_cap(efx, TX_TSO)) {
  2032. tx_queue->tso_version = 1;
  2033. }
  2034. rc = efx_mcdi_tx_init(tx_queue);
  2035. if (rc)
  2036. goto fail;
  2037. /* A previous user of this TX queue might have set us up the
  2038. * bomb by writing a descriptor to the TX push collector but
  2039. * not the doorbell. (Each collector belongs to a port, not a
  2040. * queue or function, so cannot easily be reset.) We must
  2041. * attempt to push a no-op descriptor in its place.
  2042. */
  2043. tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
  2044. tx_queue->insert_count = 1;
  2045. txd = efx_tx_desc(tx_queue, 0);
  2046. EFX_POPULATE_QWORD_7(*txd,
  2047. ESF_DZ_TX_DESC_IS_OPT, true,
  2048. ESF_DZ_TX_OPTION_TYPE,
  2049. ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
  2050. ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
  2051. ESF_DZ_TX_OPTION_IP_CSUM, csum_offload && tx_queue->tso_version != 2,
  2052. ESF_DZ_TX_OPTION_INNER_UDP_TCP_CSUM, inner_csum,
  2053. ESF_DZ_TX_OPTION_INNER_IP_CSUM, inner_csum && tx_queue->tso_version != 2,
  2054. ESF_DZ_TX_TIMESTAMP, tx_queue->timestamping);
  2055. tx_queue->write_count = 1;
  2056. if (tx_queue->tso_version == 2 && efx_has_cap(efx, TX_TSO_V2_ENCAP))
  2057. tx_queue->tso_encap = true;
  2058. wmb();
  2059. efx_ef10_push_tx_desc(tx_queue, txd);
  2060. return;
  2061. fail:
  2062. netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
  2063. tx_queue->queue);
  2064. }
  2065. /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
  2066. static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
  2067. {
  2068. unsigned int write_ptr;
  2069. efx_dword_t reg;
  2070. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  2071. EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
  2072. efx_writed_page(tx_queue->efx, &reg,
  2073. ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
  2074. }
  2075. #define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
  2076. static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
  2077. dma_addr_t dma_addr, unsigned int len)
  2078. {
  2079. if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
  2080. /* If we need to break across multiple descriptors we should
  2081. * stop at a page boundary. This assumes the length limit is
  2082. * greater than the page size.
  2083. */
  2084. dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
  2085. BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
  2086. len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
  2087. }
  2088. return len;
  2089. }
  2090. static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
  2091. {
  2092. unsigned int old_write_count = tx_queue->write_count;
  2093. struct efx_tx_buffer *buffer;
  2094. unsigned int write_ptr;
  2095. efx_qword_t *txd;
  2096. tx_queue->xmit_pending = false;
  2097. if (unlikely(tx_queue->write_count == tx_queue->insert_count))
  2098. return;
  2099. do {
  2100. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  2101. buffer = &tx_queue->buffer[write_ptr];
  2102. txd = efx_tx_desc(tx_queue, write_ptr);
  2103. ++tx_queue->write_count;
  2104. /* Create TX descriptor ring entry */
  2105. if (buffer->flags & EFX_TX_BUF_OPTION) {
  2106. *txd = buffer->option;
  2107. if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
  2108. /* PIO descriptor */
  2109. tx_queue->packet_write_count = tx_queue->write_count;
  2110. } else {
  2111. tx_queue->packet_write_count = tx_queue->write_count;
  2112. BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
  2113. EFX_POPULATE_QWORD_3(
  2114. *txd,
  2115. ESF_DZ_TX_KER_CONT,
  2116. buffer->flags & EFX_TX_BUF_CONT,
  2117. ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
  2118. ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
  2119. }
  2120. } while (tx_queue->write_count != tx_queue->insert_count);
  2121. wmb(); /* Ensure descriptors are written before they are fetched */
  2122. if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
  2123. txd = efx_tx_desc(tx_queue,
  2124. old_write_count & tx_queue->ptr_mask);
  2125. efx_ef10_push_tx_desc(tx_queue, txd);
  2126. ++tx_queue->pushes;
  2127. } else {
  2128. efx_ef10_notify_tx_desc(tx_queue);
  2129. }
  2130. }
  2131. static int efx_ef10_probe_multicast_chaining(struct efx_nic *efx)
  2132. {
  2133. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2134. unsigned int enabled, implemented;
  2135. bool want_workaround_26807;
  2136. int rc;
  2137. rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
  2138. if (rc == -ENOSYS) {
  2139. /* GET_WORKAROUNDS was implemented before this workaround,
  2140. * thus it must be unavailable in this firmware.
  2141. */
  2142. nic_data->workaround_26807 = false;
  2143. return 0;
  2144. }
  2145. if (rc)
  2146. return rc;
  2147. want_workaround_26807 =
  2148. implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807;
  2149. nic_data->workaround_26807 =
  2150. !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
  2151. if (want_workaround_26807 && !nic_data->workaround_26807) {
  2152. unsigned int flags;
  2153. rc = efx_mcdi_set_workaround(efx,
  2154. MC_CMD_WORKAROUND_BUG26807,
  2155. true, &flags);
  2156. if (!rc) {
  2157. if (flags &
  2158. 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
  2159. netif_info(efx, drv, efx->net_dev,
  2160. "other functions on NIC have been reset\n");
  2161. /* With MCFW v4.6.x and earlier, the
  2162. * boot count will have incremented,
  2163. * so re-read the warm_boot_count
  2164. * value now to ensure this function
  2165. * doesn't think it has changed next
  2166. * time it checks.
  2167. */
  2168. rc = efx_ef10_get_warm_boot_count(efx);
  2169. if (rc >= 0) {
  2170. nic_data->warm_boot_count = rc;
  2171. rc = 0;
  2172. }
  2173. }
  2174. nic_data->workaround_26807 = true;
  2175. } else if (rc == -EPERM) {
  2176. rc = 0;
  2177. }
  2178. }
  2179. return rc;
  2180. }
  2181. static int efx_ef10_filter_table_probe(struct efx_nic *efx)
  2182. {
  2183. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2184. int rc = efx_ef10_probe_multicast_chaining(efx);
  2185. struct efx_mcdi_filter_vlan *vlan;
  2186. if (rc)
  2187. return rc;
  2188. down_write(&efx->filter_sem);
  2189. rc = efx_mcdi_filter_table_probe(efx, nic_data->workaround_26807);
  2190. if (rc)
  2191. goto out_unlock;
  2192. list_for_each_entry(vlan, &nic_data->vlan_list, list) {
  2193. rc = efx_mcdi_filter_add_vlan(efx, vlan->vid);
  2194. if (rc)
  2195. goto fail_add_vlan;
  2196. }
  2197. goto out_unlock;
  2198. fail_add_vlan:
  2199. efx_mcdi_filter_table_remove(efx);
  2200. out_unlock:
  2201. up_write(&efx->filter_sem);
  2202. return rc;
  2203. }
  2204. static void efx_ef10_filter_table_remove(struct efx_nic *efx)
  2205. {
  2206. down_write(&efx->filter_sem);
  2207. efx_mcdi_filter_table_remove(efx);
  2208. up_write(&efx->filter_sem);
  2209. }
  2210. /* This creates an entry in the RX descriptor queue */
  2211. static inline void
  2212. efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
  2213. {
  2214. struct efx_rx_buffer *rx_buf;
  2215. efx_qword_t *rxd;
  2216. rxd = efx_rx_desc(rx_queue, index);
  2217. rx_buf = efx_rx_buffer(rx_queue, index);
  2218. EFX_POPULATE_QWORD_2(*rxd,
  2219. ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
  2220. ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
  2221. }
  2222. static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
  2223. {
  2224. struct efx_nic *efx = rx_queue->efx;
  2225. unsigned int write_count;
  2226. efx_dword_t reg;
  2227. /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
  2228. write_count = rx_queue->added_count & ~7;
  2229. if (rx_queue->notified_count == write_count)
  2230. return;
  2231. do
  2232. efx_ef10_build_rx_desc(
  2233. rx_queue,
  2234. rx_queue->notified_count & rx_queue->ptr_mask);
  2235. while (++rx_queue->notified_count != write_count);
  2236. wmb();
  2237. EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
  2238. write_count & rx_queue->ptr_mask);
  2239. efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
  2240. efx_rx_queue_index(rx_queue));
  2241. }
  2242. static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
  2243. static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
  2244. {
  2245. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  2246. MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
  2247. efx_qword_t event;
  2248. EFX_POPULATE_QWORD_2(event,
  2249. ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
  2250. ESF_DZ_EV_DATA, EFX_EF10_REFILL);
  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. efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
  2258. inbuf, sizeof(inbuf), 0,
  2259. efx_ef10_rx_defer_refill_complete, 0);
  2260. }
  2261. static void
  2262. efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
  2263. int rc, efx_dword_t *outbuf,
  2264. size_t outlen_actual)
  2265. {
  2266. /* nothing to do */
  2267. }
  2268. static int efx_ef10_ev_init(struct efx_channel *channel)
  2269. {
  2270. struct efx_nic *efx = channel->efx;
  2271. struct efx_ef10_nic_data *nic_data;
  2272. bool use_v2, cut_thru;
  2273. nic_data = efx->nic_data;
  2274. use_v2 = nic_data->datapath_caps2 &
  2275. 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN;
  2276. cut_thru = !(nic_data->datapath_caps &
  2277. 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
  2278. return efx_mcdi_ev_init(channel, cut_thru, use_v2);
  2279. }
  2280. static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
  2281. unsigned int rx_queue_label)
  2282. {
  2283. struct efx_nic *efx = rx_queue->efx;
  2284. netif_info(efx, hw, efx->net_dev,
  2285. "rx event arrived on queue %d labeled as queue %u\n",
  2286. efx_rx_queue_index(rx_queue), rx_queue_label);
  2287. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  2288. }
  2289. static void
  2290. efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
  2291. unsigned int actual, unsigned int expected)
  2292. {
  2293. unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
  2294. struct efx_nic *efx = rx_queue->efx;
  2295. netif_info(efx, hw, efx->net_dev,
  2296. "dropped %d events (index=%d expected=%d)\n",
  2297. dropped, actual, expected);
  2298. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  2299. }
  2300. /* partially received RX was aborted. clean up. */
  2301. static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
  2302. {
  2303. unsigned int rx_desc_ptr;
  2304. netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
  2305. "scattered RX aborted (dropping %u buffers)\n",
  2306. rx_queue->scatter_n);
  2307. rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
  2308. efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
  2309. 0, EFX_RX_PKT_DISCARD);
  2310. rx_queue->removed_count += rx_queue->scatter_n;
  2311. rx_queue->scatter_n = 0;
  2312. rx_queue->scatter_len = 0;
  2313. ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
  2314. }
  2315. static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
  2316. unsigned int n_packets,
  2317. unsigned int rx_encap_hdr,
  2318. unsigned int rx_l3_class,
  2319. unsigned int rx_l4_class,
  2320. const efx_qword_t *event)
  2321. {
  2322. struct efx_nic *efx = channel->efx;
  2323. bool handled = false;
  2324. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
  2325. if (!(efx->net_dev->features & NETIF_F_RXALL)) {
  2326. if (!efx->loopback_selftest)
  2327. channel->n_rx_eth_crc_err += n_packets;
  2328. return EFX_RX_PKT_DISCARD;
  2329. }
  2330. handled = true;
  2331. }
  2332. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
  2333. if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
  2334. rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2335. rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
  2336. rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
  2337. rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
  2338. netdev_WARN(efx->net_dev,
  2339. "invalid class for RX_IPCKSUM_ERR: event="
  2340. EFX_QWORD_FMT "\n",
  2341. EFX_QWORD_VAL(*event));
  2342. if (!efx->loopback_selftest)
  2343. *(rx_encap_hdr ?
  2344. &channel->n_rx_outer_ip_hdr_chksum_err :
  2345. &channel->n_rx_ip_hdr_chksum_err) += n_packets;
  2346. return 0;
  2347. }
  2348. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
  2349. if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
  2350. ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2351. rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
  2352. (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
  2353. rx_l4_class != ESE_FZ_L4_CLASS_UDP))))
  2354. netdev_WARN(efx->net_dev,
  2355. "invalid class for RX_TCPUDP_CKSUM_ERR: event="
  2356. EFX_QWORD_FMT "\n",
  2357. EFX_QWORD_VAL(*event));
  2358. if (!efx->loopback_selftest)
  2359. *(rx_encap_hdr ?
  2360. &channel->n_rx_outer_tcp_udp_chksum_err :
  2361. &channel->n_rx_tcp_udp_chksum_err) += n_packets;
  2362. return 0;
  2363. }
  2364. if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
  2365. if (unlikely(!rx_encap_hdr))
  2366. netdev_WARN(efx->net_dev,
  2367. "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
  2368. EFX_QWORD_FMT "\n",
  2369. EFX_QWORD_VAL(*event));
  2370. else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2371. rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
  2372. rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
  2373. rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
  2374. netdev_WARN(efx->net_dev,
  2375. "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
  2376. EFX_QWORD_FMT "\n",
  2377. EFX_QWORD_VAL(*event));
  2378. if (!efx->loopback_selftest)
  2379. channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
  2380. return 0;
  2381. }
  2382. if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
  2383. if (unlikely(!rx_encap_hdr))
  2384. netdev_WARN(efx->net_dev,
  2385. "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
  2386. EFX_QWORD_FMT "\n",
  2387. EFX_QWORD_VAL(*event));
  2388. else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
  2389. rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
  2390. (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
  2391. rx_l4_class != ESE_FZ_L4_CLASS_UDP)))
  2392. netdev_WARN(efx->net_dev,
  2393. "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
  2394. EFX_QWORD_FMT "\n",
  2395. EFX_QWORD_VAL(*event));
  2396. if (!efx->loopback_selftest)
  2397. channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
  2398. return 0;
  2399. }
  2400. WARN_ON(!handled); /* No error bits were recognised */
  2401. return 0;
  2402. }
  2403. static int efx_ef10_handle_rx_event(struct efx_channel *channel,
  2404. const efx_qword_t *event)
  2405. {
  2406. unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
  2407. unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
  2408. unsigned int n_descs, n_packets, i;
  2409. struct efx_nic *efx = channel->efx;
  2410. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2411. struct efx_rx_queue *rx_queue;
  2412. efx_qword_t errors;
  2413. bool rx_cont;
  2414. u16 flags = 0;
  2415. if (unlikely(READ_ONCE(efx->reset_pending)))
  2416. return 0;
  2417. /* Basic packet information */
  2418. rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
  2419. next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
  2420. rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
  2421. rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
  2422. rx_l4_class = EFX_QWORD_FIELD(*event, ESF_FZ_RX_L4_CLASS);
  2423. rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
  2424. rx_encap_hdr =
  2425. nic_data->datapath_caps &
  2426. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
  2427. EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
  2428. ESE_EZ_ENCAP_HDR_NONE;
  2429. if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
  2430. netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
  2431. EFX_QWORD_FMT "\n",
  2432. EFX_QWORD_VAL(*event));
  2433. rx_queue = efx_channel_get_rx_queue(channel);
  2434. if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
  2435. efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
  2436. n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
  2437. ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
  2438. if (n_descs != rx_queue->scatter_n + 1) {
  2439. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2440. /* detect rx abort */
  2441. if (unlikely(n_descs == rx_queue->scatter_n)) {
  2442. if (rx_queue->scatter_n == 0 || rx_bytes != 0)
  2443. netdev_WARN(efx->net_dev,
  2444. "invalid RX abort: scatter_n=%u event="
  2445. EFX_QWORD_FMT "\n",
  2446. rx_queue->scatter_n,
  2447. EFX_QWORD_VAL(*event));
  2448. efx_ef10_handle_rx_abort(rx_queue);
  2449. return 0;
  2450. }
  2451. /* Check that RX completion merging is valid, i.e.
  2452. * the current firmware supports it and this is a
  2453. * non-scattered packet.
  2454. */
  2455. if (!(nic_data->datapath_caps &
  2456. (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
  2457. rx_queue->scatter_n != 0 || rx_cont) {
  2458. efx_ef10_handle_rx_bad_lbits(
  2459. rx_queue, next_ptr_lbits,
  2460. (rx_queue->removed_count +
  2461. rx_queue->scatter_n + 1) &
  2462. ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
  2463. return 0;
  2464. }
  2465. /* Merged completion for multiple non-scattered packets */
  2466. rx_queue->scatter_n = 1;
  2467. rx_queue->scatter_len = 0;
  2468. n_packets = n_descs;
  2469. ++channel->n_rx_merge_events;
  2470. channel->n_rx_merge_packets += n_packets;
  2471. flags |= EFX_RX_PKT_PREFIX_LEN;
  2472. } else {
  2473. ++rx_queue->scatter_n;
  2474. rx_queue->scatter_len += rx_bytes;
  2475. if (rx_cont)
  2476. return 0;
  2477. n_packets = 1;
  2478. }
  2479. EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
  2480. ESF_DZ_RX_IPCKSUM_ERR, 1,
  2481. ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
  2482. ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
  2483. ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
  2484. EFX_AND_QWORD(errors, *event, errors);
  2485. if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
  2486. flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
  2487. rx_encap_hdr,
  2488. rx_l3_class, rx_l4_class,
  2489. event);
  2490. } else {
  2491. bool tcpudp = rx_l4_class == ESE_FZ_L4_CLASS_TCP ||
  2492. rx_l4_class == ESE_FZ_L4_CLASS_UDP;
  2493. switch (rx_encap_hdr) {
  2494. case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
  2495. flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
  2496. if (tcpudp)
  2497. flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
  2498. break;
  2499. case ESE_EZ_ENCAP_HDR_GRE:
  2500. case ESE_EZ_ENCAP_HDR_NONE:
  2501. if (tcpudp)
  2502. flags |= EFX_RX_PKT_CSUMMED;
  2503. break;
  2504. default:
  2505. netdev_WARN(efx->net_dev,
  2506. "unknown encapsulation type: event="
  2507. EFX_QWORD_FMT "\n",
  2508. EFX_QWORD_VAL(*event));
  2509. }
  2510. }
  2511. if (rx_l4_class == ESE_FZ_L4_CLASS_TCP)
  2512. flags |= EFX_RX_PKT_TCP;
  2513. channel->irq_mod_score += 2 * n_packets;
  2514. /* Handle received packet(s) */
  2515. for (i = 0; i < n_packets; i++) {
  2516. efx_rx_packet(rx_queue,
  2517. rx_queue->removed_count & rx_queue->ptr_mask,
  2518. rx_queue->scatter_n, rx_queue->scatter_len,
  2519. flags);
  2520. rx_queue->removed_count += rx_queue->scatter_n;
  2521. }
  2522. rx_queue->scatter_n = 0;
  2523. rx_queue->scatter_len = 0;
  2524. return n_packets;
  2525. }
  2526. static u32 efx_ef10_extract_event_ts(efx_qword_t *event)
  2527. {
  2528. u32 tstamp;
  2529. tstamp = EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_HI);
  2530. tstamp <<= 16;
  2531. tstamp |= EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_LO);
  2532. return tstamp;
  2533. }
  2534. static int
  2535. efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
  2536. {
  2537. struct efx_nic *efx = channel->efx;
  2538. struct efx_tx_queue *tx_queue;
  2539. unsigned int tx_ev_desc_ptr;
  2540. unsigned int tx_ev_q_label;
  2541. unsigned int tx_ev_type;
  2542. int work_done;
  2543. u64 ts_part;
  2544. if (unlikely(READ_ONCE(efx->reset_pending)))
  2545. return 0;
  2546. if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
  2547. return 0;
  2548. /* Get the transmit queue */
  2549. tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
  2550. tx_queue = channel->tx_queue + (tx_ev_q_label % EFX_MAX_TXQ_PER_CHANNEL);
  2551. if (!tx_queue->timestamping) {
  2552. /* Transmit completion */
  2553. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
  2554. return efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
  2555. }
  2556. /* Transmit timestamps are only available for 8XXX series. They result
  2557. * in up to three events per packet. These occur in order, and are:
  2558. * - the normal completion event (may be omitted)
  2559. * - the low part of the timestamp
  2560. * - the high part of the timestamp
  2561. *
  2562. * It's possible for multiple completion events to appear before the
  2563. * corresponding timestamps. So we can for example get:
  2564. * COMP N
  2565. * COMP N+1
  2566. * TS_LO N
  2567. * TS_HI N
  2568. * TS_LO N+1
  2569. * TS_HI N+1
  2570. *
  2571. * In addition it's also possible for the adjacent completions to be
  2572. * merged, so we may not see COMP N above. As such, the completion
  2573. * events are not very useful here.
  2574. *
  2575. * Each part of the timestamp is itself split across two 16 bit
  2576. * fields in the event.
  2577. */
  2578. tx_ev_type = EFX_QWORD_FIELD(*event, ESF_EZ_TX_SOFT1);
  2579. work_done = 0;
  2580. switch (tx_ev_type) {
  2581. case TX_TIMESTAMP_EVENT_TX_EV_COMPLETION:
  2582. /* Ignore this event - see above. */
  2583. break;
  2584. case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_LO:
  2585. ts_part = efx_ef10_extract_event_ts(event);
  2586. tx_queue->completed_timestamp_minor = ts_part;
  2587. break;
  2588. case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_HI:
  2589. ts_part = efx_ef10_extract_event_ts(event);
  2590. tx_queue->completed_timestamp_major = ts_part;
  2591. efx_xmit_done_single(tx_queue);
  2592. work_done = 1;
  2593. break;
  2594. default:
  2595. netif_err(efx, hw, efx->net_dev,
  2596. "channel %d unknown tx event type %d (data "
  2597. EFX_QWORD_FMT ")\n",
  2598. channel->channel, tx_ev_type,
  2599. EFX_QWORD_VAL(*event));
  2600. break;
  2601. }
  2602. return work_done;
  2603. }
  2604. static void
  2605. efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
  2606. {
  2607. struct efx_nic *efx = channel->efx;
  2608. int subcode;
  2609. subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
  2610. switch (subcode) {
  2611. case ESE_DZ_DRV_TIMER_EV:
  2612. case ESE_DZ_DRV_WAKE_UP_EV:
  2613. break;
  2614. case ESE_DZ_DRV_START_UP_EV:
  2615. /* event queue init complete. ok. */
  2616. break;
  2617. default:
  2618. netif_err(efx, hw, efx->net_dev,
  2619. "channel %d unknown driver event type %d"
  2620. " (data " EFX_QWORD_FMT ")\n",
  2621. channel->channel, subcode,
  2622. EFX_QWORD_VAL(*event));
  2623. }
  2624. }
  2625. static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
  2626. efx_qword_t *event)
  2627. {
  2628. struct efx_nic *efx = channel->efx;
  2629. u32 subcode;
  2630. subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
  2631. switch (subcode) {
  2632. case EFX_EF10_TEST:
  2633. channel->event_test_cpu = raw_smp_processor_id();
  2634. break;
  2635. case EFX_EF10_REFILL:
  2636. /* The queue must be empty, so we won't receive any rx
  2637. * events, so efx_process_channel() won't refill the
  2638. * queue. Refill it here
  2639. */
  2640. efx_fast_push_rx_descriptors(&channel->rx_queue, true);
  2641. break;
  2642. default:
  2643. netif_err(efx, hw, efx->net_dev,
  2644. "channel %d unknown driver event type %u"
  2645. " (data " EFX_QWORD_FMT ")\n",
  2646. channel->channel, (unsigned) subcode,
  2647. EFX_QWORD_VAL(*event));
  2648. }
  2649. }
  2650. #define EFX_NAPI_MAX_TX 512
  2651. static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
  2652. {
  2653. struct efx_nic *efx = channel->efx;
  2654. efx_qword_t event, *p_event;
  2655. unsigned int read_ptr;
  2656. int spent_tx = 0;
  2657. int spent = 0;
  2658. int ev_code;
  2659. if (quota <= 0)
  2660. return spent;
  2661. read_ptr = channel->eventq_read_ptr;
  2662. for (;;) {
  2663. p_event = efx_event(channel, read_ptr);
  2664. event = *p_event;
  2665. if (!efx_event_present(&event))
  2666. break;
  2667. EFX_SET_QWORD(*p_event);
  2668. ++read_ptr;
  2669. ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
  2670. netif_vdbg(efx, drv, efx->net_dev,
  2671. "processing event on %d " EFX_QWORD_FMT "\n",
  2672. channel->channel, EFX_QWORD_VAL(event));
  2673. switch (ev_code) {
  2674. case ESE_DZ_EV_CODE_MCDI_EV:
  2675. efx_mcdi_process_event(channel, &event);
  2676. break;
  2677. case ESE_DZ_EV_CODE_RX_EV:
  2678. spent += efx_ef10_handle_rx_event(channel, &event);
  2679. if (spent >= quota) {
  2680. /* XXX can we split a merged event to
  2681. * avoid going over-quota?
  2682. */
  2683. spent = quota;
  2684. goto out;
  2685. }
  2686. break;
  2687. case ESE_DZ_EV_CODE_TX_EV:
  2688. spent_tx += efx_ef10_handle_tx_event(channel, &event);
  2689. if (spent_tx >= EFX_NAPI_MAX_TX) {
  2690. spent = quota;
  2691. goto out;
  2692. }
  2693. break;
  2694. case ESE_DZ_EV_CODE_DRIVER_EV:
  2695. efx_ef10_handle_driver_event(channel, &event);
  2696. if (++spent == quota)
  2697. goto out;
  2698. break;
  2699. case EFX_EF10_DRVGEN_EV:
  2700. efx_ef10_handle_driver_generated_event(channel, &event);
  2701. break;
  2702. default:
  2703. netif_err(efx, hw, efx->net_dev,
  2704. "channel %d unknown event type %d"
  2705. " (data " EFX_QWORD_FMT ")\n",
  2706. channel->channel, ev_code,
  2707. EFX_QWORD_VAL(event));
  2708. }
  2709. }
  2710. out:
  2711. channel->eventq_read_ptr = read_ptr;
  2712. return spent;
  2713. }
  2714. static void efx_ef10_ev_read_ack(struct efx_channel *channel)
  2715. {
  2716. struct efx_nic *efx = channel->efx;
  2717. efx_dword_t rptr;
  2718. if (EFX_EF10_WORKAROUND_35388(efx)) {
  2719. BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
  2720. (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
  2721. BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
  2722. (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
  2723. EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
  2724. EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
  2725. ERF_DD_EVQ_IND_RPTR,
  2726. (channel->eventq_read_ptr &
  2727. channel->eventq_mask) >>
  2728. ERF_DD_EVQ_IND_RPTR_WIDTH);
  2729. efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
  2730. channel->channel);
  2731. EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
  2732. EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
  2733. ERF_DD_EVQ_IND_RPTR,
  2734. channel->eventq_read_ptr &
  2735. ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
  2736. efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
  2737. channel->channel);
  2738. } else {
  2739. EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
  2740. channel->eventq_read_ptr &
  2741. channel->eventq_mask);
  2742. efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
  2743. }
  2744. }
  2745. static void efx_ef10_ev_test_generate(struct efx_channel *channel)
  2746. {
  2747. MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
  2748. struct efx_nic *efx = channel->efx;
  2749. efx_qword_t event;
  2750. int rc;
  2751. EFX_POPULATE_QWORD_2(event,
  2752. ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
  2753. ESF_DZ_EV_DATA, EFX_EF10_TEST);
  2754. MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
  2755. /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
  2756. * already swapped the data to little-endian order.
  2757. */
  2758. memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
  2759. sizeof(efx_qword_t));
  2760. rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
  2761. NULL, 0, NULL);
  2762. if (rc != 0)
  2763. goto fail;
  2764. return;
  2765. fail:
  2766. WARN_ON(true);
  2767. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  2768. }
  2769. static void efx_ef10_prepare_flr(struct efx_nic *efx)
  2770. {
  2771. atomic_set(&efx->active_queues, 0);
  2772. }
  2773. static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
  2774. {
  2775. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2776. u8 mac_old[ETH_ALEN];
  2777. int rc, rc2;
  2778. /* Only reconfigure a PF-created vport */
  2779. if (is_zero_ether_addr(nic_data->vport_mac))
  2780. return 0;
  2781. efx_device_detach_sync(efx);
  2782. efx_net_stop(efx->net_dev);
  2783. efx_ef10_filter_table_remove(efx);
  2784. rc = efx_ef10_vadaptor_free(efx, efx->vport_id);
  2785. if (rc)
  2786. goto restore_filters;
  2787. ether_addr_copy(mac_old, nic_data->vport_mac);
  2788. rc = efx_ef10_vport_del_mac(efx, efx->vport_id,
  2789. nic_data->vport_mac);
  2790. if (rc)
  2791. goto restore_vadaptor;
  2792. rc = efx_ef10_vport_add_mac(efx, efx->vport_id,
  2793. efx->net_dev->dev_addr);
  2794. if (!rc) {
  2795. ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
  2796. } else {
  2797. rc2 = efx_ef10_vport_add_mac(efx, efx->vport_id, mac_old);
  2798. if (rc2) {
  2799. /* Failed to add original MAC, so clear vport_mac */
  2800. eth_zero_addr(nic_data->vport_mac);
  2801. goto reset_nic;
  2802. }
  2803. }
  2804. restore_vadaptor:
  2805. rc2 = efx_ef10_vadaptor_alloc(efx, efx->vport_id);
  2806. if (rc2)
  2807. goto reset_nic;
  2808. restore_filters:
  2809. rc2 = efx_ef10_filter_table_probe(efx);
  2810. if (rc2)
  2811. goto reset_nic;
  2812. rc2 = efx_net_open(efx->net_dev);
  2813. if (rc2)
  2814. goto reset_nic;
  2815. efx_device_attach_if_not_resetting(efx);
  2816. return rc;
  2817. reset_nic:
  2818. netif_err(efx, drv, efx->net_dev,
  2819. "Failed to restore when changing MAC address - scheduling reset\n");
  2820. efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
  2821. return rc ? rc : rc2;
  2822. }
  2823. static int efx_ef10_set_mac_address(struct efx_nic *efx)
  2824. {
  2825. MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
  2826. bool was_enabled = efx->port_enabled;
  2827. int rc;
  2828. #ifdef CONFIG_SFC_SRIOV
  2829. /* If this function is a VF and we have access to the parent PF,
  2830. * then use the PF control path to attempt to change the VF MAC address.
  2831. */
  2832. if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
  2833. struct efx_nic *efx_pf = pci_get_drvdata(efx->pci_dev->physfn);
  2834. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  2835. u8 mac[ETH_ALEN];
  2836. /* net_dev->dev_addr can be zeroed by efx_net_stop in
  2837. * efx_ef10_sriov_set_vf_mac, so pass in a copy.
  2838. */
  2839. ether_addr_copy(mac, efx->net_dev->dev_addr);
  2840. rc = efx_ef10_sriov_set_vf_mac(efx_pf, nic_data->vf_index, mac);
  2841. if (!rc)
  2842. return 0;
  2843. netif_dbg(efx, drv, efx->net_dev,
  2844. "Updating VF mac via PF failed (%d), setting directly\n",
  2845. rc);
  2846. }
  2847. #endif
  2848. efx_device_detach_sync(efx);
  2849. efx_net_stop(efx->net_dev);
  2850. mutex_lock(&efx->mac_lock);
  2851. efx_ef10_filter_table_remove(efx);
  2852. ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
  2853. efx->net_dev->dev_addr);
  2854. MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
  2855. efx->vport_id);
  2856. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
  2857. sizeof(inbuf), NULL, 0, NULL);
  2858. efx_ef10_filter_table_probe(efx);
  2859. mutex_unlock(&efx->mac_lock);
  2860. if (was_enabled)
  2861. efx_net_open(efx->net_dev);
  2862. efx_device_attach_if_not_resetting(efx);
  2863. if (rc == -EPERM) {
  2864. netif_err(efx, drv, efx->net_dev,
  2865. "Cannot change MAC address; use sfboot to enable"
  2866. " mac-spoofing on this interface\n");
  2867. } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
  2868. /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
  2869. * fall-back to the method of changing the MAC address on the
  2870. * vport. This only applies to PFs because such versions of
  2871. * MCFW do not support VFs.
  2872. */
  2873. rc = efx_ef10_vport_set_mac_address(efx);
  2874. } else if (rc) {
  2875. efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
  2876. sizeof(inbuf), NULL, 0, rc);
  2877. }
  2878. return rc;
  2879. }
  2880. static int efx_ef10_mac_reconfigure(struct efx_nic *efx, bool mtu_only)
  2881. {
  2882. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  2883. efx_mcdi_filter_sync_rx_mode(efx);
  2884. if (mtu_only && efx_has_cap(efx, SET_MAC_ENHANCED))
  2885. return efx_mcdi_set_mtu(efx);
  2886. return efx_mcdi_set_mac(efx);
  2887. }
  2888. static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
  2889. {
  2890. MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
  2891. MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
  2892. return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
  2893. NULL, 0, NULL);
  2894. }
  2895. /* MC BISTs follow a different poll mechanism to phy BISTs.
  2896. * The BIST is done in the poll handler on the MC, and the MCDI command
  2897. * will block until the BIST is done.
  2898. */
  2899. static int efx_ef10_poll_bist(struct efx_nic *efx)
  2900. {
  2901. int rc;
  2902. MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
  2903. size_t outlen;
  2904. u32 result;
  2905. rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
  2906. outbuf, sizeof(outbuf), &outlen);
  2907. if (rc != 0)
  2908. return rc;
  2909. if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
  2910. return -EIO;
  2911. result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
  2912. switch (result) {
  2913. case MC_CMD_POLL_BIST_PASSED:
  2914. netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
  2915. return 0;
  2916. case MC_CMD_POLL_BIST_TIMEOUT:
  2917. netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
  2918. return -EIO;
  2919. case MC_CMD_POLL_BIST_FAILED:
  2920. netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
  2921. return -EIO;
  2922. default:
  2923. netif_err(efx, hw, efx->net_dev,
  2924. "BIST returned unknown result %u", result);
  2925. return -EIO;
  2926. }
  2927. }
  2928. static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
  2929. {
  2930. int rc;
  2931. netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
  2932. rc = efx_ef10_start_bist(efx, bist_type);
  2933. if (rc != 0)
  2934. return rc;
  2935. return efx_ef10_poll_bist(efx);
  2936. }
  2937. static int
  2938. efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
  2939. {
  2940. int rc, rc2;
  2941. efx_reset_down(efx, RESET_TYPE_WORLD);
  2942. rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
  2943. NULL, 0, NULL, 0, NULL);
  2944. if (rc != 0)
  2945. goto out;
  2946. tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
  2947. tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
  2948. rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
  2949. out:
  2950. if (rc == -EPERM)
  2951. rc = 0;
  2952. rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
  2953. return rc ? rc : rc2;
  2954. }
  2955. #ifdef CONFIG_SFC_MTD
  2956. struct efx_ef10_nvram_type_info {
  2957. u16 type, type_mask;
  2958. u8 port;
  2959. const char *name;
  2960. };
  2961. static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
  2962. { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
  2963. { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
  2964. { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
  2965. { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
  2966. { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
  2967. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
  2968. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
  2969. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
  2970. { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
  2971. { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
  2972. { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
  2973. { NVRAM_PARTITION_TYPE_MUM_FIRMWARE, 0, 0, "sfc_mumfw" },
  2974. { NVRAM_PARTITION_TYPE_EXPANSION_UEFI, 0, 0, "sfc_uefi" },
  2975. { NVRAM_PARTITION_TYPE_DYNCONFIG_DEFAULTS, 0, 0, "sfc_dynamic_cfg_dflt" },
  2976. { NVRAM_PARTITION_TYPE_ROMCONFIG_DEFAULTS, 0, 0, "sfc_exp_rom_cfg_dflt" },
  2977. { NVRAM_PARTITION_TYPE_STATUS, 0, 0, "sfc_status" },
  2978. { NVRAM_PARTITION_TYPE_BUNDLE, 0, 0, "sfc_bundle" },
  2979. { NVRAM_PARTITION_TYPE_BUNDLE_METADATA, 0, 0, "sfc_bundle_metadata" },
  2980. };
  2981. #define EF10_NVRAM_PARTITION_COUNT ARRAY_SIZE(efx_ef10_nvram_types)
  2982. static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
  2983. struct efx_mcdi_mtd_partition *part,
  2984. unsigned int type,
  2985. unsigned long *found)
  2986. {
  2987. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
  2988. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
  2989. const struct efx_ef10_nvram_type_info *info;
  2990. size_t size, erase_size, outlen;
  2991. int type_idx = 0;
  2992. bool protected;
  2993. int rc;
  2994. for (type_idx = 0; ; type_idx++) {
  2995. if (type_idx == EF10_NVRAM_PARTITION_COUNT)
  2996. return -ENODEV;
  2997. info = efx_ef10_nvram_types + type_idx;
  2998. if ((type & ~info->type_mask) == info->type)
  2999. break;
  3000. }
  3001. if (info->port != efx_port_num(efx))
  3002. return -ENODEV;
  3003. rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
  3004. if (rc)
  3005. return rc;
  3006. if (protected &&
  3007. (type != NVRAM_PARTITION_TYPE_DYNCONFIG_DEFAULTS &&
  3008. type != NVRAM_PARTITION_TYPE_ROMCONFIG_DEFAULTS))
  3009. /* Hide protected partitions that don't provide defaults. */
  3010. return -ENODEV;
  3011. if (protected)
  3012. /* Protected partitions are read only. */
  3013. erase_size = 0;
  3014. /* If we've already exposed a partition of this type, hide this
  3015. * duplicate. All operations on MTDs are keyed by the type anyway,
  3016. * so we can't act on the duplicate.
  3017. */
  3018. if (__test_and_set_bit(type_idx, found))
  3019. return -EEXIST;
  3020. part->nvram_type = type;
  3021. MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
  3022. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
  3023. outbuf, sizeof(outbuf), &outlen);
  3024. if (rc)
  3025. return rc;
  3026. if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
  3027. return -EIO;
  3028. if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
  3029. (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
  3030. part->fw_subtype = MCDI_DWORD(outbuf,
  3031. NVRAM_METADATA_OUT_SUBTYPE);
  3032. part->common.dev_type_name = "EF10 NVRAM manager";
  3033. part->common.type_name = info->name;
  3034. part->common.mtd.type = MTD_NORFLASH;
  3035. part->common.mtd.flags = MTD_CAP_NORFLASH;
  3036. part->common.mtd.size = size;
  3037. part->common.mtd.erasesize = erase_size;
  3038. /* sfc_status is read-only */
  3039. if (!erase_size)
  3040. part->common.mtd.flags |= MTD_NO_ERASE;
  3041. return 0;
  3042. }
  3043. static int efx_ef10_mtd_probe(struct efx_nic *efx)
  3044. {
  3045. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
  3046. DECLARE_BITMAP(found, EF10_NVRAM_PARTITION_COUNT) = { 0 };
  3047. struct efx_mcdi_mtd_partition *parts;
  3048. size_t outlen, n_parts_total, i, n_parts;
  3049. unsigned int type;
  3050. int rc;
  3051. ASSERT_RTNL();
  3052. BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
  3053. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
  3054. outbuf, sizeof(outbuf), &outlen);
  3055. if (rc)
  3056. return rc;
  3057. if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
  3058. return -EIO;
  3059. n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
  3060. if (n_parts_total >
  3061. MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
  3062. return -EIO;
  3063. parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
  3064. if (!parts)
  3065. return -ENOMEM;
  3066. n_parts = 0;
  3067. for (i = 0; i < n_parts_total; i++) {
  3068. type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
  3069. i);
  3070. rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type,
  3071. found);
  3072. if (rc == -EEXIST || rc == -ENODEV)
  3073. continue;
  3074. if (rc)
  3075. goto fail;
  3076. n_parts++;
  3077. }
  3078. if (!n_parts) {
  3079. kfree(parts);
  3080. return 0;
  3081. }
  3082. rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
  3083. fail:
  3084. if (rc)
  3085. kfree(parts);
  3086. return rc;
  3087. }
  3088. #endif /* CONFIG_SFC_MTD */
  3089. static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
  3090. {
  3091. _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
  3092. }
  3093. static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
  3094. u32 host_time) {}
  3095. static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
  3096. bool temp)
  3097. {
  3098. MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
  3099. int rc;
  3100. if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
  3101. channel->sync_events_state == SYNC_EVENTS_VALID ||
  3102. (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
  3103. return 0;
  3104. channel->sync_events_state = SYNC_EVENTS_REQUESTED;
  3105. MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
  3106. MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
  3107. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
  3108. channel->channel);
  3109. rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
  3110. inbuf, sizeof(inbuf), NULL, 0, NULL);
  3111. if (rc != 0)
  3112. channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
  3113. SYNC_EVENTS_DISABLED;
  3114. return rc;
  3115. }
  3116. static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
  3117. bool temp)
  3118. {
  3119. MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
  3120. int rc;
  3121. if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
  3122. (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
  3123. return 0;
  3124. if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
  3125. channel->sync_events_state = SYNC_EVENTS_DISABLED;
  3126. return 0;
  3127. }
  3128. channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
  3129. SYNC_EVENTS_DISABLED;
  3130. MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
  3131. MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
  3132. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
  3133. MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
  3134. MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
  3135. channel->channel);
  3136. rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
  3137. inbuf, sizeof(inbuf), NULL, 0, NULL);
  3138. return rc;
  3139. }
  3140. static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
  3141. bool temp)
  3142. {
  3143. int (*set)(struct efx_channel *channel, bool temp);
  3144. struct efx_channel *channel;
  3145. set = en ?
  3146. efx_ef10_rx_enable_timestamping :
  3147. efx_ef10_rx_disable_timestamping;
  3148. channel = efx_ptp_channel(efx);
  3149. if (channel) {
  3150. int rc = set(channel, temp);
  3151. if (en && rc != 0) {
  3152. efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
  3153. return rc;
  3154. }
  3155. }
  3156. return 0;
  3157. }
  3158. static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
  3159. struct hwtstamp_config *init)
  3160. {
  3161. return -EOPNOTSUPP;
  3162. }
  3163. static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
  3164. struct hwtstamp_config *init)
  3165. {
  3166. int rc;
  3167. switch (init->rx_filter) {
  3168. case HWTSTAMP_FILTER_NONE:
  3169. efx_ef10_ptp_set_ts_sync_events(efx, false, false);
  3170. /* if TX timestamping is still requested then leave PTP on */
  3171. return efx_ptp_change_mode(efx,
  3172. init->tx_type != HWTSTAMP_TX_OFF, 0);
  3173. case HWTSTAMP_FILTER_ALL:
  3174. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  3175. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  3176. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  3177. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  3178. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  3179. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  3180. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  3181. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  3182. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  3183. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  3184. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  3185. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  3186. case HWTSTAMP_FILTER_NTP_ALL:
  3187. init->rx_filter = HWTSTAMP_FILTER_ALL;
  3188. rc = efx_ptp_change_mode(efx, true, 0);
  3189. if (!rc)
  3190. rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
  3191. if (rc)
  3192. efx_ptp_change_mode(efx, false, 0);
  3193. return rc;
  3194. default:
  3195. return -ERANGE;
  3196. }
  3197. }
  3198. static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
  3199. struct netdev_phys_item_id *ppid)
  3200. {
  3201. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3202. if (!is_valid_ether_addr(nic_data->port_id))
  3203. return -EOPNOTSUPP;
  3204. ppid->id_len = ETH_ALEN;
  3205. memcpy(ppid->id, nic_data->port_id, ppid->id_len);
  3206. return 0;
  3207. }
  3208. static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
  3209. {
  3210. if (proto != htons(ETH_P_8021Q))
  3211. return -EINVAL;
  3212. return efx_ef10_add_vlan(efx, vid);
  3213. }
  3214. static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
  3215. {
  3216. if (proto != htons(ETH_P_8021Q))
  3217. return -EINVAL;
  3218. return efx_ef10_del_vlan(efx, vid);
  3219. }
  3220. /* We rely on the MCDI wiping out our TX rings if it made any changes to the
  3221. * ports table, ensuring that any TSO descriptors that were made on a now-
  3222. * removed tunnel port will be blown away and won't break things when we try
  3223. * to transmit them using the new ports table.
  3224. */
  3225. static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
  3226. {
  3227. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3228. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
  3229. MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
  3230. bool will_reset = false;
  3231. size_t num_entries = 0;
  3232. size_t inlen, outlen;
  3233. size_t i;
  3234. int rc;
  3235. efx_dword_t flags_and_num_entries;
  3236. WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
  3237. nic_data->udp_tunnels_dirty = false;
  3238. if (!(nic_data->datapath_caps &
  3239. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
  3240. efx_device_attach_if_not_resetting(efx);
  3241. return 0;
  3242. }
  3243. BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
  3244. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
  3245. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
  3246. if (nic_data->udp_tunnels[i].type !=
  3247. TUNNEL_ENCAP_UDP_PORT_ENTRY_INVALID) {
  3248. efx_dword_t entry;
  3249. EFX_POPULATE_DWORD_2(entry,
  3250. TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
  3251. ntohs(nic_data->udp_tunnels[i].port),
  3252. TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
  3253. nic_data->udp_tunnels[i].type);
  3254. *_MCDI_ARRAY_DWORD(inbuf,
  3255. SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
  3256. num_entries++) = entry;
  3257. }
  3258. }
  3259. BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
  3260. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
  3261. EFX_WORD_1_LBN);
  3262. BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
  3263. EFX_WORD_1_WIDTH);
  3264. EFX_POPULATE_DWORD_2(flags_and_num_entries,
  3265. MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
  3266. !!unloading,
  3267. EFX_WORD_1, num_entries);
  3268. *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
  3269. flags_and_num_entries;
  3270. inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
  3271. rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
  3272. inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
  3273. if (rc == -EIO) {
  3274. /* Most likely the MC rebooted due to another function also
  3275. * setting its tunnel port list. Mark the tunnel port list as
  3276. * dirty, so it will be pushed upon coming up from the reboot.
  3277. */
  3278. nic_data->udp_tunnels_dirty = true;
  3279. return 0;
  3280. }
  3281. if (rc) {
  3282. /* expected not available on unprivileged functions */
  3283. if (rc != -EPERM)
  3284. netif_warn(efx, drv, efx->net_dev,
  3285. "Unable to set UDP tunnel ports; rc=%d.\n", rc);
  3286. } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
  3287. (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
  3288. netif_info(efx, drv, efx->net_dev,
  3289. "Rebooting MC due to UDP tunnel port list change\n");
  3290. will_reset = true;
  3291. if (unloading)
  3292. /* Delay for the MC reset to complete. This will make
  3293. * unloading other functions a bit smoother. This is a
  3294. * race, but the other unload will work whichever way
  3295. * it goes, this just avoids an unnecessary error
  3296. * message.
  3297. */
  3298. msleep(100);
  3299. }
  3300. if (!will_reset && !unloading) {
  3301. /* The caller will have detached, relying on the MC reset to
  3302. * trigger a re-attach. Since there won't be an MC reset, we
  3303. * have to do the attach ourselves.
  3304. */
  3305. efx_device_attach_if_not_resetting(efx);
  3306. }
  3307. return rc;
  3308. }
  3309. static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
  3310. {
  3311. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3312. int rc = 0;
  3313. mutex_lock(&nic_data->udp_tunnels_lock);
  3314. if (nic_data->udp_tunnels_dirty) {
  3315. /* Make sure all TX are stopped while we modify the table, else
  3316. * we might race against an efx_features_check().
  3317. */
  3318. efx_device_detach_sync(efx);
  3319. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  3320. }
  3321. mutex_unlock(&nic_data->udp_tunnels_lock);
  3322. return rc;
  3323. }
  3324. static int efx_ef10_udp_tnl_set_port(struct net_device *dev,
  3325. unsigned int table, unsigned int entry,
  3326. struct udp_tunnel_info *ti)
  3327. {
  3328. struct efx_nic *efx = efx_netdev_priv(dev);
  3329. struct efx_ef10_nic_data *nic_data;
  3330. int efx_tunnel_type, rc;
  3331. if (ti->type == UDP_TUNNEL_TYPE_VXLAN)
  3332. efx_tunnel_type = TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
  3333. else
  3334. efx_tunnel_type = TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
  3335. nic_data = efx->nic_data;
  3336. if (!(nic_data->datapath_caps &
  3337. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  3338. return -EOPNOTSUPP;
  3339. mutex_lock(&nic_data->udp_tunnels_lock);
  3340. /* Make sure all TX are stopped while we add to the table, else we
  3341. * might race against an efx_features_check().
  3342. */
  3343. efx_device_detach_sync(efx);
  3344. nic_data->udp_tunnels[entry].type = efx_tunnel_type;
  3345. nic_data->udp_tunnels[entry].port = ti->port;
  3346. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  3347. mutex_unlock(&nic_data->udp_tunnels_lock);
  3348. return rc;
  3349. }
  3350. /* Called under the TX lock with the TX queue running, hence no-one can be
  3351. * in the middle of updating the UDP tunnels table. However, they could
  3352. * have tried and failed the MCDI, in which case they'll have set the dirty
  3353. * flag before dropping their locks.
  3354. */
  3355. static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
  3356. {
  3357. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3358. size_t i;
  3359. if (!(nic_data->datapath_caps &
  3360. (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
  3361. return false;
  3362. if (nic_data->udp_tunnels_dirty)
  3363. /* SW table may not match HW state, so just assume we can't
  3364. * use any UDP tunnel offloads.
  3365. */
  3366. return false;
  3367. for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
  3368. if (nic_data->udp_tunnels[i].type !=
  3369. TUNNEL_ENCAP_UDP_PORT_ENTRY_INVALID &&
  3370. nic_data->udp_tunnels[i].port == port)
  3371. return true;
  3372. return false;
  3373. }
  3374. static int efx_ef10_udp_tnl_unset_port(struct net_device *dev,
  3375. unsigned int table, unsigned int entry,
  3376. struct udp_tunnel_info *ti)
  3377. {
  3378. struct efx_nic *efx = efx_netdev_priv(dev);
  3379. struct efx_ef10_nic_data *nic_data;
  3380. int rc;
  3381. nic_data = efx->nic_data;
  3382. mutex_lock(&nic_data->udp_tunnels_lock);
  3383. /* Make sure all TX are stopped while we remove from the table, else we
  3384. * might race against an efx_features_check().
  3385. */
  3386. efx_device_detach_sync(efx);
  3387. nic_data->udp_tunnels[entry].type = TUNNEL_ENCAP_UDP_PORT_ENTRY_INVALID;
  3388. nic_data->udp_tunnels[entry].port = 0;
  3389. rc = efx_ef10_set_udp_tnl_ports(efx, false);
  3390. mutex_unlock(&nic_data->udp_tunnels_lock);
  3391. return rc;
  3392. }
  3393. static const struct udp_tunnel_nic_info efx_ef10_udp_tunnels = {
  3394. .set_port = efx_ef10_udp_tnl_set_port,
  3395. .unset_port = efx_ef10_udp_tnl_unset_port,
  3396. .flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP,
  3397. .tables = {
  3398. {
  3399. .n_entries = 16,
  3400. .tunnel_types = UDP_TUNNEL_TYPE_VXLAN |
  3401. UDP_TUNNEL_TYPE_GENEVE,
  3402. },
  3403. },
  3404. };
  3405. /* EF10 may have multiple datapath firmware variants within a
  3406. * single version. Report which variants are running.
  3407. */
  3408. static size_t efx_ef10_print_additional_fwver(struct efx_nic *efx, char *buf,
  3409. size_t len)
  3410. {
  3411. struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3412. return scnprintf(buf, len, " rx%x tx%x",
  3413. nic_data->rx_dpcpu_fw_id,
  3414. nic_data->tx_dpcpu_fw_id);
  3415. }
  3416. static unsigned int ef10_check_caps(const struct efx_nic *efx,
  3417. u8 flag,
  3418. u32 offset)
  3419. {
  3420. const struct efx_ef10_nic_data *nic_data = efx->nic_data;
  3421. switch (offset) {
  3422. case(MC_CMD_GET_CAPABILITIES_V4_OUT_FLAGS1_OFST):
  3423. return nic_data->datapath_caps & BIT_ULL(flag);
  3424. case(MC_CMD_GET_CAPABILITIES_V4_OUT_FLAGS2_OFST):
  3425. return nic_data->datapath_caps2 & BIT_ULL(flag);
  3426. default:
  3427. return 0;
  3428. }
  3429. }
  3430. static unsigned int efx_ef10_recycle_ring_size(const struct efx_nic *efx)
  3431. {
  3432. unsigned int ret = EFX_RECYCLE_RING_SIZE_10G;
  3433. /* There is no difference between PFs and VFs. The side is based on
  3434. * the maximum link speed of a given NIC.
  3435. */
  3436. switch (efx->pci_dev->device & 0xfff) {
  3437. case 0x0903: /* Farmingdale can do up to 10G */
  3438. break;
  3439. case 0x0923: /* Greenport can do up to 40G */
  3440. case 0x0a03: /* Medford can do up to 40G */
  3441. ret *= 4;
  3442. break;
  3443. default: /* Medford2 can do up to 100G */
  3444. ret *= 10;
  3445. }
  3446. if (IS_ENABLED(CONFIG_PPC64))
  3447. ret *= 4;
  3448. return ret;
  3449. }
  3450. #define EF10_OFFLOAD_FEATURES \
  3451. (NETIF_F_IP_CSUM | \
  3452. NETIF_F_HW_VLAN_CTAG_FILTER | \
  3453. NETIF_F_IPV6_CSUM | \
  3454. NETIF_F_RXHASH | \
  3455. NETIF_F_NTUPLE | \
  3456. NETIF_F_SG | \
  3457. NETIF_F_RXCSUM | \
  3458. NETIF_F_RXALL)
  3459. const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
  3460. .is_vf = true,
  3461. .mem_bar = efx_ef10_vf_mem_bar,
  3462. .mem_map_size = efx_ef10_mem_map_size,
  3463. .probe = efx_ef10_probe_vf,
  3464. .remove = efx_ef10_remove,
  3465. .dimension_resources = efx_ef10_dimension_resources,
  3466. .init = efx_ef10_init_nic,
  3467. .fini = efx_ef10_fini_nic,
  3468. .map_reset_reason = efx_ef10_map_reset_reason,
  3469. .map_reset_flags = efx_ef10_map_reset_flags,
  3470. .reset = efx_ef10_reset,
  3471. .probe_port = efx_mcdi_port_probe,
  3472. .remove_port = efx_mcdi_port_remove,
  3473. .fini_dmaq = efx_fini_dmaq,
  3474. .prepare_flr = efx_ef10_prepare_flr,
  3475. .finish_flr = efx_port_dummy_op_void,
  3476. .describe_stats = efx_ef10_describe_stats,
  3477. .update_stats = efx_ef10_update_stats_vf,
  3478. .update_stats_atomic = efx_ef10_update_stats_atomic_vf,
  3479. .start_stats = efx_port_dummy_op_void,
  3480. .pull_stats = efx_port_dummy_op_void,
  3481. .stop_stats = efx_port_dummy_op_void,
  3482. .push_irq_moderation = efx_ef10_push_irq_moderation,
  3483. .reconfigure_mac = efx_ef10_mac_reconfigure,
  3484. .check_mac_fault = efx_mcdi_mac_check_fault,
  3485. .reconfigure_port = efx_mcdi_port_reconfigure,
  3486. .get_wol = efx_ef10_get_wol_vf,
  3487. .set_wol = efx_ef10_set_wol_vf,
  3488. .resume_wol = efx_port_dummy_op_void,
  3489. .mcdi_request = efx_ef10_mcdi_request,
  3490. .mcdi_poll_response = efx_ef10_mcdi_poll_response,
  3491. .mcdi_read_response = efx_ef10_mcdi_read_response,
  3492. .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
  3493. .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
  3494. .irq_enable_master = efx_port_dummy_op_void,
  3495. .irq_test_generate = efx_ef10_irq_test_generate,
  3496. .irq_disable_non_ev = efx_port_dummy_op_void,
  3497. .irq_handle_msi = efx_ef10_msi_interrupt,
  3498. .irq_handle_legacy = efx_ef10_legacy_interrupt,
  3499. .tx_probe = efx_ef10_tx_probe,
  3500. .tx_init = efx_ef10_tx_init,
  3501. .tx_remove = efx_mcdi_tx_remove,
  3502. .tx_write = efx_ef10_tx_write,
  3503. .tx_limit_len = efx_ef10_tx_limit_len,
  3504. .tx_enqueue = __efx_enqueue_skb,
  3505. .rx_push_rss_config = efx_mcdi_vf_rx_push_rss_config,
  3506. .rx_pull_rss_config = efx_mcdi_rx_pull_rss_config,
  3507. .rx_probe = efx_mcdi_rx_probe,
  3508. .rx_init = efx_mcdi_rx_init,
  3509. .rx_remove = efx_mcdi_rx_remove,
  3510. .rx_write = efx_ef10_rx_write,
  3511. .rx_defer_refill = efx_ef10_rx_defer_refill,
  3512. .rx_packet = __efx_rx_packet,
  3513. .ev_probe = efx_mcdi_ev_probe,
  3514. .ev_init = efx_ef10_ev_init,
  3515. .ev_fini = efx_mcdi_ev_fini,
  3516. .ev_remove = efx_mcdi_ev_remove,
  3517. .ev_process = efx_ef10_ev_process,
  3518. .ev_read_ack = efx_ef10_ev_read_ack,
  3519. .ev_test_generate = efx_ef10_ev_test_generate,
  3520. .filter_table_probe = efx_ef10_filter_table_probe,
  3521. .filter_table_restore = efx_mcdi_filter_table_restore,
  3522. .filter_table_remove = efx_ef10_filter_table_remove,
  3523. .filter_update_rx_scatter = efx_mcdi_update_rx_scatter,
  3524. .filter_insert = efx_mcdi_filter_insert,
  3525. .filter_remove_safe = efx_mcdi_filter_remove_safe,
  3526. .filter_get_safe = efx_mcdi_filter_get_safe,
  3527. .filter_clear_rx = efx_mcdi_filter_clear_rx,
  3528. .filter_count_rx_used = efx_mcdi_filter_count_rx_used,
  3529. .filter_get_rx_id_limit = efx_mcdi_filter_get_rx_id_limit,
  3530. .filter_get_rx_ids = efx_mcdi_filter_get_rx_ids,
  3531. #ifdef CONFIG_RFS_ACCEL
  3532. .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
  3533. #endif
  3534. #ifdef CONFIG_SFC_MTD
  3535. .mtd_probe = efx_port_dummy_op_int,
  3536. #endif
  3537. .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
  3538. .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
  3539. .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
  3540. .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
  3541. #ifdef CONFIG_SFC_SRIOV
  3542. .vswitching_probe = efx_ef10_vswitching_probe_vf,
  3543. .vswitching_restore = efx_ef10_vswitching_restore_vf,
  3544. .vswitching_remove = efx_ef10_vswitching_remove_vf,
  3545. #endif
  3546. .get_mac_address = efx_ef10_get_mac_address_vf,
  3547. .set_mac_address = efx_ef10_set_mac_address,
  3548. .get_phys_port_id = efx_ef10_get_phys_port_id,
  3549. .revision = EFX_REV_HUNT_A0,
  3550. .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
  3551. .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
  3552. .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
  3553. .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
  3554. .can_rx_scatter = true,
  3555. .always_rx_scatter = true,
  3556. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  3557. .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
  3558. .offload_features = EF10_OFFLOAD_FEATURES,
  3559. .mcdi_max_ver = 2,
  3560. .max_rx_ip_filters = EFX_MCDI_FILTER_TBL_ROWS,
  3561. .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
  3562. 1 << HWTSTAMP_FILTER_ALL,
  3563. .rx_hash_key_size = 40,
  3564. .check_caps = ef10_check_caps,
  3565. .print_additional_fwver = efx_ef10_print_additional_fwver,
  3566. .sensor_event = efx_mcdi_sensor_event,
  3567. .rx_recycle_ring_size = efx_ef10_recycle_ring_size,
  3568. };
  3569. const struct efx_nic_type efx_hunt_a0_nic_type = {
  3570. .is_vf = false,
  3571. .mem_bar = efx_ef10_pf_mem_bar,
  3572. .mem_map_size = efx_ef10_mem_map_size,
  3573. .probe = efx_ef10_probe_pf,
  3574. .remove = efx_ef10_remove,
  3575. .dimension_resources = efx_ef10_dimension_resources,
  3576. .init = efx_ef10_init_nic,
  3577. .fini = efx_ef10_fini_nic,
  3578. .map_reset_reason = efx_ef10_map_reset_reason,
  3579. .map_reset_flags = efx_ef10_map_reset_flags,
  3580. .reset = efx_ef10_reset,
  3581. .probe_port = efx_mcdi_port_probe,
  3582. .remove_port = efx_mcdi_port_remove,
  3583. .fini_dmaq = efx_fini_dmaq,
  3584. .prepare_flr = efx_ef10_prepare_flr,
  3585. .finish_flr = efx_port_dummy_op_void,
  3586. .describe_stats = efx_ef10_describe_stats,
  3587. .update_stats = efx_ef10_update_stats_pf,
  3588. .start_stats = efx_mcdi_mac_start_stats,
  3589. .pull_stats = efx_mcdi_mac_pull_stats,
  3590. .stop_stats = efx_mcdi_mac_stop_stats,
  3591. .push_irq_moderation = efx_ef10_push_irq_moderation,
  3592. .reconfigure_mac = efx_ef10_mac_reconfigure,
  3593. .check_mac_fault = efx_mcdi_mac_check_fault,
  3594. .reconfigure_port = efx_mcdi_port_reconfigure,
  3595. .get_wol = efx_ef10_get_wol,
  3596. .set_wol = efx_ef10_set_wol,
  3597. .resume_wol = efx_port_dummy_op_void,
  3598. .get_fec_stats = efx_ef10_get_fec_stats,
  3599. .test_chip = efx_ef10_test_chip,
  3600. .test_nvram = efx_mcdi_nvram_test_all,
  3601. .mcdi_request = efx_ef10_mcdi_request,
  3602. .mcdi_poll_response = efx_ef10_mcdi_poll_response,
  3603. .mcdi_read_response = efx_ef10_mcdi_read_response,
  3604. .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
  3605. .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
  3606. .irq_enable_master = efx_port_dummy_op_void,
  3607. .irq_test_generate = efx_ef10_irq_test_generate,
  3608. .irq_disable_non_ev = efx_port_dummy_op_void,
  3609. .irq_handle_msi = efx_ef10_msi_interrupt,
  3610. .irq_handle_legacy = efx_ef10_legacy_interrupt,
  3611. .tx_probe = efx_ef10_tx_probe,
  3612. .tx_init = efx_ef10_tx_init,
  3613. .tx_remove = efx_mcdi_tx_remove,
  3614. .tx_write = efx_ef10_tx_write,
  3615. .tx_limit_len = efx_ef10_tx_limit_len,
  3616. .tx_enqueue = __efx_enqueue_skb,
  3617. .rx_push_rss_config = efx_mcdi_pf_rx_push_rss_config,
  3618. .rx_pull_rss_config = efx_mcdi_rx_pull_rss_config,
  3619. .rx_push_rss_context_config = efx_mcdi_rx_push_rss_context_config,
  3620. .rx_pull_rss_context_config = efx_mcdi_rx_pull_rss_context_config,
  3621. .rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
  3622. .rx_probe = efx_mcdi_rx_probe,
  3623. .rx_init = efx_mcdi_rx_init,
  3624. .rx_remove = efx_mcdi_rx_remove,
  3625. .rx_write = efx_ef10_rx_write,
  3626. .rx_defer_refill = efx_ef10_rx_defer_refill,
  3627. .rx_packet = __efx_rx_packet,
  3628. .ev_probe = efx_mcdi_ev_probe,
  3629. .ev_init = efx_ef10_ev_init,
  3630. .ev_fini = efx_mcdi_ev_fini,
  3631. .ev_remove = efx_mcdi_ev_remove,
  3632. .ev_process = efx_ef10_ev_process,
  3633. .ev_read_ack = efx_ef10_ev_read_ack,
  3634. .ev_test_generate = efx_ef10_ev_test_generate,
  3635. .filter_table_probe = efx_ef10_filter_table_probe,
  3636. .filter_table_restore = efx_mcdi_filter_table_restore,
  3637. .filter_table_remove = efx_ef10_filter_table_remove,
  3638. .filter_update_rx_scatter = efx_mcdi_update_rx_scatter,
  3639. .filter_insert = efx_mcdi_filter_insert,
  3640. .filter_remove_safe = efx_mcdi_filter_remove_safe,
  3641. .filter_get_safe = efx_mcdi_filter_get_safe,
  3642. .filter_clear_rx = efx_mcdi_filter_clear_rx,
  3643. .filter_count_rx_used = efx_mcdi_filter_count_rx_used,
  3644. .filter_get_rx_id_limit = efx_mcdi_filter_get_rx_id_limit,
  3645. .filter_get_rx_ids = efx_mcdi_filter_get_rx_ids,
  3646. #ifdef CONFIG_RFS_ACCEL
  3647. .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
  3648. #endif
  3649. #ifdef CONFIG_SFC_MTD
  3650. .mtd_probe = efx_ef10_mtd_probe,
  3651. .mtd_rename = efx_mcdi_mtd_rename,
  3652. .mtd_read = efx_mcdi_mtd_read,
  3653. .mtd_erase = efx_mcdi_mtd_erase,
  3654. .mtd_write = efx_mcdi_mtd_write,
  3655. .mtd_sync = efx_mcdi_mtd_sync,
  3656. #endif
  3657. .ptp_write_host_time = efx_ef10_ptp_write_host_time,
  3658. .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
  3659. .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
  3660. .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
  3661. .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
  3662. .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
  3663. .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
  3664. #ifdef CONFIG_SFC_SRIOV
  3665. .sriov_configure = efx_ef10_sriov_configure,
  3666. .sriov_init = efx_ef10_sriov_init,
  3667. .sriov_fini = efx_ef10_sriov_fini,
  3668. .sriov_wanted = efx_ef10_sriov_wanted,
  3669. .sriov_reset = efx_ef10_sriov_reset,
  3670. .sriov_flr = efx_ef10_sriov_flr,
  3671. .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
  3672. .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
  3673. .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
  3674. .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
  3675. .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
  3676. .vswitching_probe = efx_ef10_vswitching_probe_pf,
  3677. .vswitching_restore = efx_ef10_vswitching_restore_pf,
  3678. .vswitching_remove = efx_ef10_vswitching_remove_pf,
  3679. #endif
  3680. .get_mac_address = efx_ef10_get_mac_address_pf,
  3681. .set_mac_address = efx_ef10_set_mac_address,
  3682. .tso_versions = efx_ef10_tso_versions,
  3683. .get_phys_port_id = efx_ef10_get_phys_port_id,
  3684. .revision = EFX_REV_HUNT_A0,
  3685. .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
  3686. .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
  3687. .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
  3688. .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
  3689. .can_rx_scatter = true,
  3690. .always_rx_scatter = true,
  3691. .option_descriptors = true,
  3692. .min_interrupt_mode = EFX_INT_MODE_LEGACY,
  3693. .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
  3694. .offload_features = EF10_OFFLOAD_FEATURES,
  3695. .mcdi_max_ver = 2,
  3696. .max_rx_ip_filters = EFX_MCDI_FILTER_TBL_ROWS,
  3697. .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
  3698. 1 << HWTSTAMP_FILTER_ALL,
  3699. .rx_hash_key_size = 40,
  3700. .check_caps = ef10_check_caps,
  3701. .print_additional_fwver = efx_ef10_print_additional_fwver,
  3702. .sensor_event = efx_mcdi_sensor_event,
  3703. .rx_recycle_ring_size = efx_ef10_recycle_ring_size,
  3704. };