ef10.c 142 KB

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