ef10.c 87 KB

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