ef10.c 89 KB

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