ef10.c 106 KB

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