ef10.c 105 KB

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