ef10.c 141 KB

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