ef10.c 87 KB

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