ef10.c 87 KB

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