ef10.c 87 KB

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