ef10.c 106 KB

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