ef10.c 87 KB

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