ef10.c 106 KB

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