efx.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2013 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/pci.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/delay.h>
  15. #include <linux/notifier.h>
  16. #include <linux/ip.h>
  17. #include <linux/tcp.h>
  18. #include <linux/in.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/topology.h>
  21. #include <linux/gfp.h>
  22. #include <linux/aer.h>
  23. #include <linux/interrupt.h>
  24. #include "net_driver.h"
  25. #include <net/gre.h>
  26. #include <net/udp_tunnel.h>
  27. #include "efx.h"
  28. #include "nic.h"
  29. #include "selftest.h"
  30. #include "sriov.h"
  31. #include "mcdi.h"
  32. #include "mcdi_pcol.h"
  33. #include "workarounds.h"
  34. /**************************************************************************
  35. *
  36. * Type name strings
  37. *
  38. **************************************************************************
  39. */
  40. /* Loopback mode names (see LOOPBACK_MODE()) */
  41. const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
  42. const char *const efx_loopback_mode_names[] = {
  43. [LOOPBACK_NONE] = "NONE",
  44. [LOOPBACK_DATA] = "DATAPATH",
  45. [LOOPBACK_GMAC] = "GMAC",
  46. [LOOPBACK_XGMII] = "XGMII",
  47. [LOOPBACK_XGXS] = "XGXS",
  48. [LOOPBACK_XAUI] = "XAUI",
  49. [LOOPBACK_GMII] = "GMII",
  50. [LOOPBACK_SGMII] = "SGMII",
  51. [LOOPBACK_XGBR] = "XGBR",
  52. [LOOPBACK_XFI] = "XFI",
  53. [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
  54. [LOOPBACK_GMII_FAR] = "GMII_FAR",
  55. [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
  56. [LOOPBACK_XFI_FAR] = "XFI_FAR",
  57. [LOOPBACK_GPHY] = "GPHY",
  58. [LOOPBACK_PHYXS] = "PHYXS",
  59. [LOOPBACK_PCS] = "PCS",
  60. [LOOPBACK_PMAPMD] = "PMA/PMD",
  61. [LOOPBACK_XPORT] = "XPORT",
  62. [LOOPBACK_XGMII_WS] = "XGMII_WS",
  63. [LOOPBACK_XAUI_WS] = "XAUI_WS",
  64. [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
  65. [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
  66. [LOOPBACK_GMII_WS] = "GMII_WS",
  67. [LOOPBACK_XFI_WS] = "XFI_WS",
  68. [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
  69. [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
  70. };
  71. const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
  72. const char *const efx_reset_type_names[] = {
  73. [RESET_TYPE_INVISIBLE] = "INVISIBLE",
  74. [RESET_TYPE_ALL] = "ALL",
  75. [RESET_TYPE_RECOVER_OR_ALL] = "RECOVER_OR_ALL",
  76. [RESET_TYPE_WORLD] = "WORLD",
  77. [RESET_TYPE_RECOVER_OR_DISABLE] = "RECOVER_OR_DISABLE",
  78. [RESET_TYPE_DATAPATH] = "DATAPATH",
  79. [RESET_TYPE_MC_BIST] = "MC_BIST",
  80. [RESET_TYPE_DISABLE] = "DISABLE",
  81. [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
  82. [RESET_TYPE_INT_ERROR] = "INT_ERROR",
  83. [RESET_TYPE_DMA_ERROR] = "DMA_ERROR",
  84. [RESET_TYPE_TX_SKIP] = "TX_SKIP",
  85. [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
  86. [RESET_TYPE_MCDI_TIMEOUT] = "MCDI_TIMEOUT (FLR)",
  87. };
  88. /* UDP tunnel type names */
  89. static const char *const efx_udp_tunnel_type_names[] = {
  90. [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan",
  91. [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve",
  92. };
  93. void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen)
  94. {
  95. if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) &&
  96. efx_udp_tunnel_type_names[type] != NULL)
  97. snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]);
  98. else
  99. snprintf(buf, buflen, "type %d", type);
  100. }
  101. /* Reset workqueue. If any NIC has a hardware failure then a reset will be
  102. * queued onto this work queue. This is not a per-nic work queue, because
  103. * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
  104. */
  105. static struct workqueue_struct *reset_workqueue;
  106. /* How often and how many times to poll for a reset while waiting for a
  107. * BIST that another function started to complete.
  108. */
  109. #define BIST_WAIT_DELAY_MS 100
  110. #define BIST_WAIT_DELAY_COUNT 100
  111. /**************************************************************************
  112. *
  113. * Configurable values
  114. *
  115. *************************************************************************/
  116. /*
  117. * Use separate channels for TX and RX events
  118. *
  119. * Set this to 1 to use separate channels for TX and RX. It allows us
  120. * to control interrupt affinity separately for TX and RX.
  121. *
  122. * This is only used in MSI-X interrupt mode
  123. */
  124. bool efx_separate_tx_channels;
  125. module_param(efx_separate_tx_channels, bool, 0444);
  126. MODULE_PARM_DESC(efx_separate_tx_channels,
  127. "Use separate channels for TX and RX");
  128. /* This is the weight assigned to each of the (per-channel) virtual
  129. * NAPI devices.
  130. */
  131. static int napi_weight = 64;
  132. /* This is the time (in jiffies) between invocations of the hardware
  133. * monitor.
  134. * On Falcon-based NICs, this will:
  135. * - Check the on-board hardware monitor;
  136. * - Poll the link state and reconfigure the hardware as necessary.
  137. * On Siena-based NICs for power systems with EEH support, this will give EEH a
  138. * chance to start.
  139. */
  140. static unsigned int efx_monitor_interval = 1 * HZ;
  141. /* Initial interrupt moderation settings. They can be modified after
  142. * module load with ethtool.
  143. *
  144. * The default for RX should strike a balance between increasing the
  145. * round-trip latency and reducing overhead.
  146. */
  147. static unsigned int rx_irq_mod_usec = 60;
  148. /* Initial interrupt moderation settings. They can be modified after
  149. * module load with ethtool.
  150. *
  151. * This default is chosen to ensure that a 10G link does not go idle
  152. * while a TX queue is stopped after it has become full. A queue is
  153. * restarted when it drops below half full. The time this takes (assuming
  154. * worst case 3 descriptors per packet and 1024 descriptors) is
  155. * 512 / 3 * 1.2 = 205 usec.
  156. */
  157. static unsigned int tx_irq_mod_usec = 150;
  158. /* This is the first interrupt mode to try out of:
  159. * 0 => MSI-X
  160. * 1 => MSI
  161. * 2 => legacy
  162. */
  163. static unsigned int interrupt_mode;
  164. /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
  165. * i.e. the number of CPUs among which we may distribute simultaneous
  166. * interrupt handling.
  167. *
  168. * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
  169. * The default (0) means to assign an interrupt to each core.
  170. */
  171. static unsigned int rss_cpus;
  172. module_param(rss_cpus, uint, 0444);
  173. MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
  174. static bool phy_flash_cfg;
  175. module_param(phy_flash_cfg, bool, 0644);
  176. MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
  177. static unsigned irq_adapt_low_thresh = 8000;
  178. module_param(irq_adapt_low_thresh, uint, 0644);
  179. MODULE_PARM_DESC(irq_adapt_low_thresh,
  180. "Threshold score for reducing IRQ moderation");
  181. static unsigned irq_adapt_high_thresh = 16000;
  182. module_param(irq_adapt_high_thresh, uint, 0644);
  183. MODULE_PARM_DESC(irq_adapt_high_thresh,
  184. "Threshold score for increasing IRQ moderation");
  185. static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  186. NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
  187. NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
  188. NETIF_MSG_TX_ERR | NETIF_MSG_HW);
  189. module_param(debug, uint, 0);
  190. MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
  191. /**************************************************************************
  192. *
  193. * Utility functions and prototypes
  194. *
  195. *************************************************************************/
  196. static int efx_soft_enable_interrupts(struct efx_nic *efx);
  197. static void efx_soft_disable_interrupts(struct efx_nic *efx);
  198. static void efx_remove_channel(struct efx_channel *channel);
  199. static void efx_remove_channels(struct efx_nic *efx);
  200. static const struct efx_channel_type efx_default_channel_type;
  201. static void efx_remove_port(struct efx_nic *efx);
  202. static void efx_init_napi_channel(struct efx_channel *channel);
  203. static void efx_fini_napi(struct efx_nic *efx);
  204. static void efx_fini_napi_channel(struct efx_channel *channel);
  205. static void efx_fini_struct(struct efx_nic *efx);
  206. static void efx_start_all(struct efx_nic *efx);
  207. static void efx_stop_all(struct efx_nic *efx);
  208. #define EFX_ASSERT_RESET_SERIALISED(efx) \
  209. do { \
  210. if ((efx->state == STATE_READY) || \
  211. (efx->state == STATE_RECOVERY) || \
  212. (efx->state == STATE_DISABLED)) \
  213. ASSERT_RTNL(); \
  214. } while (0)
  215. static int efx_check_disabled(struct efx_nic *efx)
  216. {
  217. if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
  218. netif_err(efx, drv, efx->net_dev,
  219. "device is disabled due to earlier errors\n");
  220. return -EIO;
  221. }
  222. return 0;
  223. }
  224. /**************************************************************************
  225. *
  226. * Event queue processing
  227. *
  228. *************************************************************************/
  229. /* Process channel's event queue
  230. *
  231. * This function is responsible for processing the event queue of a
  232. * single channel. The caller must guarantee that this function will
  233. * never be concurrently called more than once on the same channel,
  234. * though different channels may be being processed concurrently.
  235. */
  236. static int efx_process_channel(struct efx_channel *channel, int budget)
  237. {
  238. struct efx_tx_queue *tx_queue;
  239. int spent;
  240. if (unlikely(!channel->enabled))
  241. return 0;
  242. efx_for_each_channel_tx_queue(tx_queue, channel) {
  243. tx_queue->pkts_compl = 0;
  244. tx_queue->bytes_compl = 0;
  245. }
  246. spent = efx_nic_process_eventq(channel, budget);
  247. if (spent && efx_channel_has_rx_queue(channel)) {
  248. struct efx_rx_queue *rx_queue =
  249. efx_channel_get_rx_queue(channel);
  250. efx_rx_flush_packet(channel);
  251. efx_fast_push_rx_descriptors(rx_queue, true);
  252. }
  253. /* Update BQL */
  254. efx_for_each_channel_tx_queue(tx_queue, channel) {
  255. if (tx_queue->bytes_compl) {
  256. netdev_tx_completed_queue(tx_queue->core_txq,
  257. tx_queue->pkts_compl, tx_queue->bytes_compl);
  258. }
  259. }
  260. return spent;
  261. }
  262. /* NAPI poll handler
  263. *
  264. * NAPI guarantees serialisation of polls of the same device, which
  265. * provides the guarantee required by efx_process_channel().
  266. */
  267. static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
  268. {
  269. int step = efx->irq_mod_step_us;
  270. if (channel->irq_mod_score < irq_adapt_low_thresh) {
  271. if (channel->irq_moderation_us > step) {
  272. channel->irq_moderation_us -= step;
  273. efx->type->push_irq_moderation(channel);
  274. }
  275. } else if (channel->irq_mod_score > irq_adapt_high_thresh) {
  276. if (channel->irq_moderation_us <
  277. efx->irq_rx_moderation_us) {
  278. channel->irq_moderation_us += step;
  279. efx->type->push_irq_moderation(channel);
  280. }
  281. }
  282. channel->irq_count = 0;
  283. channel->irq_mod_score = 0;
  284. }
  285. static int efx_poll(struct napi_struct *napi, int budget)
  286. {
  287. struct efx_channel *channel =
  288. container_of(napi, struct efx_channel, napi_str);
  289. struct efx_nic *efx = channel->efx;
  290. int spent;
  291. netif_vdbg(efx, intr, efx->net_dev,
  292. "channel %d NAPI poll executing on CPU %d\n",
  293. channel->channel, raw_smp_processor_id());
  294. spent = efx_process_channel(channel, budget);
  295. if (spent < budget) {
  296. if (efx_channel_has_rx_queue(channel) &&
  297. efx->irq_rx_adaptive &&
  298. unlikely(++channel->irq_count == 1000)) {
  299. efx_update_irq_mod(efx, channel);
  300. }
  301. efx_filter_rfs_expire(channel);
  302. /* There is no race here; although napi_disable() will
  303. * only wait for napi_complete(), this isn't a problem
  304. * since efx_nic_eventq_read_ack() will have no effect if
  305. * interrupts have already been disabled.
  306. */
  307. if (napi_complete_done(napi, spent))
  308. efx_nic_eventq_read_ack(channel);
  309. }
  310. return spent;
  311. }
  312. /* Create event queue
  313. * Event queue memory allocations are done only once. If the channel
  314. * is reset, the memory buffer will be reused; this guards against
  315. * errors during channel reset and also simplifies interrupt handling.
  316. */
  317. static int efx_probe_eventq(struct efx_channel *channel)
  318. {
  319. struct efx_nic *efx = channel->efx;
  320. unsigned long entries;
  321. netif_dbg(efx, probe, efx->net_dev,
  322. "chan %d create event queue\n", channel->channel);
  323. /* Build an event queue with room for one event per tx and rx buffer,
  324. * plus some extra for link state events and MCDI completions. */
  325. entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
  326. EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
  327. channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
  328. return efx_nic_probe_eventq(channel);
  329. }
  330. /* Prepare channel's event queue */
  331. static int efx_init_eventq(struct efx_channel *channel)
  332. {
  333. struct efx_nic *efx = channel->efx;
  334. int rc;
  335. EFX_WARN_ON_PARANOID(channel->eventq_init);
  336. netif_dbg(efx, drv, efx->net_dev,
  337. "chan %d init event queue\n", channel->channel);
  338. rc = efx_nic_init_eventq(channel);
  339. if (rc == 0) {
  340. efx->type->push_irq_moderation(channel);
  341. channel->eventq_read_ptr = 0;
  342. channel->eventq_init = true;
  343. }
  344. return rc;
  345. }
  346. /* Enable event queue processing and NAPI */
  347. void efx_start_eventq(struct efx_channel *channel)
  348. {
  349. netif_dbg(channel->efx, ifup, channel->efx->net_dev,
  350. "chan %d start event queue\n", channel->channel);
  351. /* Make sure the NAPI handler sees the enabled flag set */
  352. channel->enabled = true;
  353. smp_wmb();
  354. napi_enable(&channel->napi_str);
  355. efx_nic_eventq_read_ack(channel);
  356. }
  357. /* Disable event queue processing and NAPI */
  358. void efx_stop_eventq(struct efx_channel *channel)
  359. {
  360. if (!channel->enabled)
  361. return;
  362. napi_disable(&channel->napi_str);
  363. channel->enabled = false;
  364. }
  365. static void efx_fini_eventq(struct efx_channel *channel)
  366. {
  367. if (!channel->eventq_init)
  368. return;
  369. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  370. "chan %d fini event queue\n", channel->channel);
  371. efx_nic_fini_eventq(channel);
  372. channel->eventq_init = false;
  373. }
  374. static void efx_remove_eventq(struct efx_channel *channel)
  375. {
  376. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  377. "chan %d remove event queue\n", channel->channel);
  378. efx_nic_remove_eventq(channel);
  379. }
  380. /**************************************************************************
  381. *
  382. * Channel handling
  383. *
  384. *************************************************************************/
  385. /* Allocate and initialise a channel structure. */
  386. static struct efx_channel *
  387. efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
  388. {
  389. struct efx_channel *channel;
  390. struct efx_rx_queue *rx_queue;
  391. struct efx_tx_queue *tx_queue;
  392. int j;
  393. channel = kzalloc(sizeof(*channel), GFP_KERNEL);
  394. if (!channel)
  395. return NULL;
  396. channel->efx = efx;
  397. channel->channel = i;
  398. channel->type = &efx_default_channel_type;
  399. for (j = 0; j < EFX_TXQ_TYPES; j++) {
  400. tx_queue = &channel->tx_queue[j];
  401. tx_queue->efx = efx;
  402. tx_queue->queue = i * EFX_TXQ_TYPES + j;
  403. tx_queue->channel = channel;
  404. }
  405. rx_queue = &channel->rx_queue;
  406. rx_queue->efx = efx;
  407. setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
  408. (unsigned long)rx_queue);
  409. return channel;
  410. }
  411. /* Allocate and initialise a channel structure, copying parameters
  412. * (but not resources) from an old channel structure.
  413. */
  414. static struct efx_channel *
  415. efx_copy_channel(const struct efx_channel *old_channel)
  416. {
  417. struct efx_channel *channel;
  418. struct efx_rx_queue *rx_queue;
  419. struct efx_tx_queue *tx_queue;
  420. int j;
  421. channel = kmalloc(sizeof(*channel), GFP_KERNEL);
  422. if (!channel)
  423. return NULL;
  424. *channel = *old_channel;
  425. channel->napi_dev = NULL;
  426. INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
  427. channel->napi_str.napi_id = 0;
  428. channel->napi_str.state = 0;
  429. memset(&channel->eventq, 0, sizeof(channel->eventq));
  430. for (j = 0; j < EFX_TXQ_TYPES; j++) {
  431. tx_queue = &channel->tx_queue[j];
  432. if (tx_queue->channel)
  433. tx_queue->channel = channel;
  434. tx_queue->buffer = NULL;
  435. memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
  436. }
  437. rx_queue = &channel->rx_queue;
  438. rx_queue->buffer = NULL;
  439. memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
  440. setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
  441. (unsigned long)rx_queue);
  442. return channel;
  443. }
  444. static int efx_probe_channel(struct efx_channel *channel)
  445. {
  446. struct efx_tx_queue *tx_queue;
  447. struct efx_rx_queue *rx_queue;
  448. int rc;
  449. netif_dbg(channel->efx, probe, channel->efx->net_dev,
  450. "creating channel %d\n", channel->channel);
  451. rc = channel->type->pre_probe(channel);
  452. if (rc)
  453. goto fail;
  454. rc = efx_probe_eventq(channel);
  455. if (rc)
  456. goto fail;
  457. efx_for_each_channel_tx_queue(tx_queue, channel) {
  458. rc = efx_probe_tx_queue(tx_queue);
  459. if (rc)
  460. goto fail;
  461. }
  462. efx_for_each_channel_rx_queue(rx_queue, channel) {
  463. rc = efx_probe_rx_queue(rx_queue);
  464. if (rc)
  465. goto fail;
  466. }
  467. return 0;
  468. fail:
  469. efx_remove_channel(channel);
  470. return rc;
  471. }
  472. static void
  473. efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
  474. {
  475. struct efx_nic *efx = channel->efx;
  476. const char *type;
  477. int number;
  478. number = channel->channel;
  479. if (efx->tx_channel_offset == 0) {
  480. type = "";
  481. } else if (channel->channel < efx->tx_channel_offset) {
  482. type = "-rx";
  483. } else {
  484. type = "-tx";
  485. number -= efx->tx_channel_offset;
  486. }
  487. snprintf(buf, len, "%s%s-%d", efx->name, type, number);
  488. }
  489. static void efx_set_channel_names(struct efx_nic *efx)
  490. {
  491. struct efx_channel *channel;
  492. efx_for_each_channel(channel, efx)
  493. channel->type->get_name(channel,
  494. efx->msi_context[channel->channel].name,
  495. sizeof(efx->msi_context[0].name));
  496. }
  497. static int efx_probe_channels(struct efx_nic *efx)
  498. {
  499. struct efx_channel *channel;
  500. int rc;
  501. /* Restart special buffer allocation */
  502. efx->next_buffer_table = 0;
  503. /* Probe channels in reverse, so that any 'extra' channels
  504. * use the start of the buffer table. This allows the traffic
  505. * channels to be resized without moving them or wasting the
  506. * entries before them.
  507. */
  508. efx_for_each_channel_rev(channel, efx) {
  509. rc = efx_probe_channel(channel);
  510. if (rc) {
  511. netif_err(efx, probe, efx->net_dev,
  512. "failed to create channel %d\n",
  513. channel->channel);
  514. goto fail;
  515. }
  516. }
  517. efx_set_channel_names(efx);
  518. return 0;
  519. fail:
  520. efx_remove_channels(efx);
  521. return rc;
  522. }
  523. /* Channels are shutdown and reinitialised whilst the NIC is running
  524. * to propagate configuration changes (mtu, checksum offload), or
  525. * to clear hardware error conditions
  526. */
  527. static void efx_start_datapath(struct efx_nic *efx)
  528. {
  529. netdev_features_t old_features = efx->net_dev->features;
  530. bool old_rx_scatter = efx->rx_scatter;
  531. struct efx_tx_queue *tx_queue;
  532. struct efx_rx_queue *rx_queue;
  533. struct efx_channel *channel;
  534. size_t rx_buf_len;
  535. /* Calculate the rx buffer allocation parameters required to
  536. * support the current MTU, including padding for header
  537. * alignment and overruns.
  538. */
  539. efx->rx_dma_len = (efx->rx_prefix_size +
  540. EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
  541. efx->type->rx_buffer_padding);
  542. rx_buf_len = (sizeof(struct efx_rx_page_state) +
  543. efx->rx_ip_align + efx->rx_dma_len);
  544. if (rx_buf_len <= PAGE_SIZE) {
  545. efx->rx_scatter = efx->type->always_rx_scatter;
  546. efx->rx_buffer_order = 0;
  547. } else if (efx->type->can_rx_scatter) {
  548. BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
  549. BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
  550. 2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
  551. EFX_RX_BUF_ALIGNMENT) >
  552. PAGE_SIZE);
  553. efx->rx_scatter = true;
  554. efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
  555. efx->rx_buffer_order = 0;
  556. } else {
  557. efx->rx_scatter = false;
  558. efx->rx_buffer_order = get_order(rx_buf_len);
  559. }
  560. efx_rx_config_page_split(efx);
  561. if (efx->rx_buffer_order)
  562. netif_dbg(efx, drv, efx->net_dev,
  563. "RX buf len=%u; page order=%u batch=%u\n",
  564. efx->rx_dma_len, efx->rx_buffer_order,
  565. efx->rx_pages_per_batch);
  566. else
  567. netif_dbg(efx, drv, efx->net_dev,
  568. "RX buf len=%u step=%u bpp=%u; page batch=%u\n",
  569. efx->rx_dma_len, efx->rx_page_buf_step,
  570. efx->rx_bufs_per_page, efx->rx_pages_per_batch);
  571. /* Restore previously fixed features in hw_features and remove
  572. * features which are fixed now
  573. */
  574. efx->net_dev->hw_features |= efx->net_dev->features;
  575. efx->net_dev->hw_features &= ~efx->fixed_features;
  576. efx->net_dev->features |= efx->fixed_features;
  577. if (efx->net_dev->features != old_features)
  578. netdev_features_change(efx->net_dev);
  579. /* RX filters may also have scatter-enabled flags */
  580. if (efx->rx_scatter != old_rx_scatter)
  581. efx->type->filter_update_rx_scatter(efx);
  582. /* We must keep at least one descriptor in a TX ring empty.
  583. * We could avoid this when the queue size does not exactly
  584. * match the hardware ring size, but it's not that important.
  585. * Therefore we stop the queue when one more skb might fill
  586. * the ring completely. We wake it when half way back to
  587. * empty.
  588. */
  589. efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
  590. efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
  591. /* Initialise the channels */
  592. efx_for_each_channel(channel, efx) {
  593. efx_for_each_channel_tx_queue(tx_queue, channel) {
  594. efx_init_tx_queue(tx_queue);
  595. atomic_inc(&efx->active_queues);
  596. }
  597. efx_for_each_channel_rx_queue(rx_queue, channel) {
  598. efx_init_rx_queue(rx_queue);
  599. atomic_inc(&efx->active_queues);
  600. efx_stop_eventq(channel);
  601. efx_fast_push_rx_descriptors(rx_queue, false);
  602. efx_start_eventq(channel);
  603. }
  604. WARN_ON(channel->rx_pkt_n_frags);
  605. }
  606. efx_ptp_start_datapath(efx);
  607. if (netif_device_present(efx->net_dev))
  608. netif_tx_wake_all_queues(efx->net_dev);
  609. }
  610. static void efx_stop_datapath(struct efx_nic *efx)
  611. {
  612. struct efx_channel *channel;
  613. struct efx_tx_queue *tx_queue;
  614. struct efx_rx_queue *rx_queue;
  615. int rc;
  616. EFX_ASSERT_RESET_SERIALISED(efx);
  617. BUG_ON(efx->port_enabled);
  618. efx_ptp_stop_datapath(efx);
  619. /* Stop RX refill */
  620. efx_for_each_channel(channel, efx) {
  621. efx_for_each_channel_rx_queue(rx_queue, channel)
  622. rx_queue->refill_enabled = false;
  623. }
  624. efx_for_each_channel(channel, efx) {
  625. /* RX packet processing is pipelined, so wait for the
  626. * NAPI handler to complete. At least event queue 0
  627. * might be kept active by non-data events, so don't
  628. * use napi_synchronize() but actually disable NAPI
  629. * temporarily.
  630. */
  631. if (efx_channel_has_rx_queue(channel)) {
  632. efx_stop_eventq(channel);
  633. efx_start_eventq(channel);
  634. }
  635. }
  636. rc = efx->type->fini_dmaq(efx);
  637. if (rc) {
  638. netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
  639. } else {
  640. netif_dbg(efx, drv, efx->net_dev,
  641. "successfully flushed all queues\n");
  642. }
  643. efx_for_each_channel(channel, efx) {
  644. efx_for_each_channel_rx_queue(rx_queue, channel)
  645. efx_fini_rx_queue(rx_queue);
  646. efx_for_each_possible_channel_tx_queue(tx_queue, channel)
  647. efx_fini_tx_queue(tx_queue);
  648. }
  649. }
  650. static void efx_remove_channel(struct efx_channel *channel)
  651. {
  652. struct efx_tx_queue *tx_queue;
  653. struct efx_rx_queue *rx_queue;
  654. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  655. "destroy chan %d\n", channel->channel);
  656. efx_for_each_channel_rx_queue(rx_queue, channel)
  657. efx_remove_rx_queue(rx_queue);
  658. efx_for_each_possible_channel_tx_queue(tx_queue, channel)
  659. efx_remove_tx_queue(tx_queue);
  660. efx_remove_eventq(channel);
  661. channel->type->post_remove(channel);
  662. }
  663. static void efx_remove_channels(struct efx_nic *efx)
  664. {
  665. struct efx_channel *channel;
  666. efx_for_each_channel(channel, efx)
  667. efx_remove_channel(channel);
  668. }
  669. int
  670. efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
  671. {
  672. struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
  673. u32 old_rxq_entries, old_txq_entries;
  674. unsigned i, next_buffer_table = 0;
  675. int rc, rc2;
  676. rc = efx_check_disabled(efx);
  677. if (rc)
  678. return rc;
  679. /* Not all channels should be reallocated. We must avoid
  680. * reallocating their buffer table entries.
  681. */
  682. efx_for_each_channel(channel, efx) {
  683. struct efx_rx_queue *rx_queue;
  684. struct efx_tx_queue *tx_queue;
  685. if (channel->type->copy)
  686. continue;
  687. next_buffer_table = max(next_buffer_table,
  688. channel->eventq.index +
  689. channel->eventq.entries);
  690. efx_for_each_channel_rx_queue(rx_queue, channel)
  691. next_buffer_table = max(next_buffer_table,
  692. rx_queue->rxd.index +
  693. rx_queue->rxd.entries);
  694. efx_for_each_channel_tx_queue(tx_queue, channel)
  695. next_buffer_table = max(next_buffer_table,
  696. tx_queue->txd.index +
  697. tx_queue->txd.entries);
  698. }
  699. efx_device_detach_sync(efx);
  700. efx_stop_all(efx);
  701. efx_soft_disable_interrupts(efx);
  702. /* Clone channels (where possible) */
  703. memset(other_channel, 0, sizeof(other_channel));
  704. for (i = 0; i < efx->n_channels; i++) {
  705. channel = efx->channel[i];
  706. if (channel->type->copy)
  707. channel = channel->type->copy(channel);
  708. if (!channel) {
  709. rc = -ENOMEM;
  710. goto out;
  711. }
  712. other_channel[i] = channel;
  713. }
  714. /* Swap entry counts and channel pointers */
  715. old_rxq_entries = efx->rxq_entries;
  716. old_txq_entries = efx->txq_entries;
  717. efx->rxq_entries = rxq_entries;
  718. efx->txq_entries = txq_entries;
  719. for (i = 0; i < efx->n_channels; i++) {
  720. channel = efx->channel[i];
  721. efx->channel[i] = other_channel[i];
  722. other_channel[i] = channel;
  723. }
  724. /* Restart buffer table allocation */
  725. efx->next_buffer_table = next_buffer_table;
  726. for (i = 0; i < efx->n_channels; i++) {
  727. channel = efx->channel[i];
  728. if (!channel->type->copy)
  729. continue;
  730. rc = efx_probe_channel(channel);
  731. if (rc)
  732. goto rollback;
  733. efx_init_napi_channel(efx->channel[i]);
  734. }
  735. out:
  736. /* Destroy unused channel structures */
  737. for (i = 0; i < efx->n_channels; i++) {
  738. channel = other_channel[i];
  739. if (channel && channel->type->copy) {
  740. efx_fini_napi_channel(channel);
  741. efx_remove_channel(channel);
  742. kfree(channel);
  743. }
  744. }
  745. rc2 = efx_soft_enable_interrupts(efx);
  746. if (rc2) {
  747. rc = rc ? rc : rc2;
  748. netif_err(efx, drv, efx->net_dev,
  749. "unable to restart interrupts on channel reallocation\n");
  750. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  751. } else {
  752. efx_start_all(efx);
  753. efx_device_attach_if_not_resetting(efx);
  754. }
  755. return rc;
  756. rollback:
  757. /* Swap back */
  758. efx->rxq_entries = old_rxq_entries;
  759. efx->txq_entries = old_txq_entries;
  760. for (i = 0; i < efx->n_channels; i++) {
  761. channel = efx->channel[i];
  762. efx->channel[i] = other_channel[i];
  763. other_channel[i] = channel;
  764. }
  765. goto out;
  766. }
  767. void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
  768. {
  769. mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
  770. }
  771. static const struct efx_channel_type efx_default_channel_type = {
  772. .pre_probe = efx_channel_dummy_op_int,
  773. .post_remove = efx_channel_dummy_op_void,
  774. .get_name = efx_get_channel_name,
  775. .copy = efx_copy_channel,
  776. .keep_eventq = false,
  777. };
  778. int efx_channel_dummy_op_int(struct efx_channel *channel)
  779. {
  780. return 0;
  781. }
  782. void efx_channel_dummy_op_void(struct efx_channel *channel)
  783. {
  784. }
  785. /**************************************************************************
  786. *
  787. * Port handling
  788. *
  789. **************************************************************************/
  790. /* This ensures that the kernel is kept informed (via
  791. * netif_carrier_on/off) of the link status, and also maintains the
  792. * link status's stop on the port's TX queue.
  793. */
  794. void efx_link_status_changed(struct efx_nic *efx)
  795. {
  796. struct efx_link_state *link_state = &efx->link_state;
  797. /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
  798. * that no events are triggered between unregister_netdev() and the
  799. * driver unloading. A more general condition is that NETDEV_CHANGE
  800. * can only be generated between NETDEV_UP and NETDEV_DOWN */
  801. if (!netif_running(efx->net_dev))
  802. return;
  803. if (link_state->up != netif_carrier_ok(efx->net_dev)) {
  804. efx->n_link_state_changes++;
  805. if (link_state->up)
  806. netif_carrier_on(efx->net_dev);
  807. else
  808. netif_carrier_off(efx->net_dev);
  809. }
  810. /* Status message for kernel log */
  811. if (link_state->up)
  812. netif_info(efx, link, efx->net_dev,
  813. "link up at %uMbps %s-duplex (MTU %d)\n",
  814. link_state->speed, link_state->fd ? "full" : "half",
  815. efx->net_dev->mtu);
  816. else
  817. netif_info(efx, link, efx->net_dev, "link down\n");
  818. }
  819. void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
  820. {
  821. efx->link_advertising = advertising;
  822. if (advertising) {
  823. if (advertising & ADVERTISED_Pause)
  824. efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
  825. else
  826. efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
  827. if (advertising & ADVERTISED_Asym_Pause)
  828. efx->wanted_fc ^= EFX_FC_TX;
  829. }
  830. }
  831. void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
  832. {
  833. efx->wanted_fc = wanted_fc;
  834. if (efx->link_advertising) {
  835. if (wanted_fc & EFX_FC_RX)
  836. efx->link_advertising |= (ADVERTISED_Pause |
  837. ADVERTISED_Asym_Pause);
  838. else
  839. efx->link_advertising &= ~(ADVERTISED_Pause |
  840. ADVERTISED_Asym_Pause);
  841. if (wanted_fc & EFX_FC_TX)
  842. efx->link_advertising ^= ADVERTISED_Asym_Pause;
  843. }
  844. }
  845. static void efx_fini_port(struct efx_nic *efx);
  846. /* We assume that efx->type->reconfigure_mac will always try to sync RX
  847. * filters and therefore needs to read-lock the filter table against freeing
  848. */
  849. void efx_mac_reconfigure(struct efx_nic *efx)
  850. {
  851. down_read(&efx->filter_sem);
  852. efx->type->reconfigure_mac(efx);
  853. up_read(&efx->filter_sem);
  854. }
  855. /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
  856. * the MAC appropriately. All other PHY configuration changes are pushed
  857. * through phy_op->set_settings(), and pushed asynchronously to the MAC
  858. * through efx_monitor().
  859. *
  860. * Callers must hold the mac_lock
  861. */
  862. int __efx_reconfigure_port(struct efx_nic *efx)
  863. {
  864. enum efx_phy_mode phy_mode;
  865. int rc;
  866. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  867. /* Disable PHY transmit in mac level loopbacks */
  868. phy_mode = efx->phy_mode;
  869. if (LOOPBACK_INTERNAL(efx))
  870. efx->phy_mode |= PHY_MODE_TX_DISABLED;
  871. else
  872. efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
  873. rc = efx->type->reconfigure_port(efx);
  874. if (rc)
  875. efx->phy_mode = phy_mode;
  876. return rc;
  877. }
  878. /* Reinitialise the MAC to pick up new PHY settings, even if the port is
  879. * disabled. */
  880. int efx_reconfigure_port(struct efx_nic *efx)
  881. {
  882. int rc;
  883. EFX_ASSERT_RESET_SERIALISED(efx);
  884. mutex_lock(&efx->mac_lock);
  885. rc = __efx_reconfigure_port(efx);
  886. mutex_unlock(&efx->mac_lock);
  887. return rc;
  888. }
  889. /* Asynchronous work item for changing MAC promiscuity and multicast
  890. * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
  891. * MAC directly. */
  892. static void efx_mac_work(struct work_struct *data)
  893. {
  894. struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
  895. mutex_lock(&efx->mac_lock);
  896. if (efx->port_enabled)
  897. efx_mac_reconfigure(efx);
  898. mutex_unlock(&efx->mac_lock);
  899. }
  900. static int efx_probe_port(struct efx_nic *efx)
  901. {
  902. int rc;
  903. netif_dbg(efx, probe, efx->net_dev, "create port\n");
  904. if (phy_flash_cfg)
  905. efx->phy_mode = PHY_MODE_SPECIAL;
  906. /* Connect up MAC/PHY operations table */
  907. rc = efx->type->probe_port(efx);
  908. if (rc)
  909. return rc;
  910. /* Initialise MAC address to permanent address */
  911. ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
  912. return 0;
  913. }
  914. static int efx_init_port(struct efx_nic *efx)
  915. {
  916. int rc;
  917. netif_dbg(efx, drv, efx->net_dev, "init port\n");
  918. mutex_lock(&efx->mac_lock);
  919. rc = efx->phy_op->init(efx);
  920. if (rc)
  921. goto fail1;
  922. efx->port_initialized = true;
  923. /* Reconfigure the MAC before creating dma queues (required for
  924. * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
  925. efx_mac_reconfigure(efx);
  926. /* Ensure the PHY advertises the correct flow control settings */
  927. rc = efx->phy_op->reconfigure(efx);
  928. if (rc && rc != -EPERM)
  929. goto fail2;
  930. mutex_unlock(&efx->mac_lock);
  931. return 0;
  932. fail2:
  933. efx->phy_op->fini(efx);
  934. fail1:
  935. mutex_unlock(&efx->mac_lock);
  936. return rc;
  937. }
  938. static void efx_start_port(struct efx_nic *efx)
  939. {
  940. netif_dbg(efx, ifup, efx->net_dev, "start port\n");
  941. BUG_ON(efx->port_enabled);
  942. mutex_lock(&efx->mac_lock);
  943. efx->port_enabled = true;
  944. /* Ensure MAC ingress/egress is enabled */
  945. efx_mac_reconfigure(efx);
  946. mutex_unlock(&efx->mac_lock);
  947. }
  948. /* Cancel work for MAC reconfiguration, periodic hardware monitoring
  949. * and the async self-test, wait for them to finish and prevent them
  950. * being scheduled again. This doesn't cover online resets, which
  951. * should only be cancelled when removing the device.
  952. */
  953. static void efx_stop_port(struct efx_nic *efx)
  954. {
  955. netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
  956. EFX_ASSERT_RESET_SERIALISED(efx);
  957. mutex_lock(&efx->mac_lock);
  958. efx->port_enabled = false;
  959. mutex_unlock(&efx->mac_lock);
  960. /* Serialise against efx_set_multicast_list() */
  961. netif_addr_lock_bh(efx->net_dev);
  962. netif_addr_unlock_bh(efx->net_dev);
  963. cancel_delayed_work_sync(&efx->monitor_work);
  964. efx_selftest_async_cancel(efx);
  965. cancel_work_sync(&efx->mac_work);
  966. }
  967. static void efx_fini_port(struct efx_nic *efx)
  968. {
  969. netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
  970. if (!efx->port_initialized)
  971. return;
  972. efx->phy_op->fini(efx);
  973. efx->port_initialized = false;
  974. efx->link_state.up = false;
  975. efx_link_status_changed(efx);
  976. }
  977. static void efx_remove_port(struct efx_nic *efx)
  978. {
  979. netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
  980. efx->type->remove_port(efx);
  981. }
  982. /**************************************************************************
  983. *
  984. * NIC handling
  985. *
  986. **************************************************************************/
  987. static LIST_HEAD(efx_primary_list);
  988. static LIST_HEAD(efx_unassociated_list);
  989. static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
  990. {
  991. return left->type == right->type &&
  992. left->vpd_sn && right->vpd_sn &&
  993. !strcmp(left->vpd_sn, right->vpd_sn);
  994. }
  995. static void efx_associate(struct efx_nic *efx)
  996. {
  997. struct efx_nic *other, *next;
  998. if (efx->primary == efx) {
  999. /* Adding primary function; look for secondaries */
  1000. netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
  1001. list_add_tail(&efx->node, &efx_primary_list);
  1002. list_for_each_entry_safe(other, next, &efx_unassociated_list,
  1003. node) {
  1004. if (efx_same_controller(efx, other)) {
  1005. list_del(&other->node);
  1006. netif_dbg(other, probe, other->net_dev,
  1007. "moving to secondary list of %s %s\n",
  1008. pci_name(efx->pci_dev),
  1009. efx->net_dev->name);
  1010. list_add_tail(&other->node,
  1011. &efx->secondary_list);
  1012. other->primary = efx;
  1013. }
  1014. }
  1015. } else {
  1016. /* Adding secondary function; look for primary */
  1017. list_for_each_entry(other, &efx_primary_list, node) {
  1018. if (efx_same_controller(efx, other)) {
  1019. netif_dbg(efx, probe, efx->net_dev,
  1020. "adding to secondary list of %s %s\n",
  1021. pci_name(other->pci_dev),
  1022. other->net_dev->name);
  1023. list_add_tail(&efx->node,
  1024. &other->secondary_list);
  1025. efx->primary = other;
  1026. return;
  1027. }
  1028. }
  1029. netif_dbg(efx, probe, efx->net_dev,
  1030. "adding to unassociated list\n");
  1031. list_add_tail(&efx->node, &efx_unassociated_list);
  1032. }
  1033. }
  1034. static void efx_dissociate(struct efx_nic *efx)
  1035. {
  1036. struct efx_nic *other, *next;
  1037. list_del(&efx->node);
  1038. efx->primary = NULL;
  1039. list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
  1040. list_del(&other->node);
  1041. netif_dbg(other, probe, other->net_dev,
  1042. "moving to unassociated list\n");
  1043. list_add_tail(&other->node, &efx_unassociated_list);
  1044. other->primary = NULL;
  1045. }
  1046. }
  1047. /* This configures the PCI device to enable I/O and DMA. */
  1048. static int efx_init_io(struct efx_nic *efx)
  1049. {
  1050. struct pci_dev *pci_dev = efx->pci_dev;
  1051. dma_addr_t dma_mask = efx->type->max_dma_mask;
  1052. unsigned int mem_map_size = efx->type->mem_map_size(efx);
  1053. int rc, bar;
  1054. netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
  1055. bar = efx->type->mem_bar;
  1056. rc = pci_enable_device(pci_dev);
  1057. if (rc) {
  1058. netif_err(efx, probe, efx->net_dev,
  1059. "failed to enable PCI device\n");
  1060. goto fail1;
  1061. }
  1062. pci_set_master(pci_dev);
  1063. /* Set the PCI DMA mask. Try all possibilities from our
  1064. * genuine mask down to 32 bits, because some architectures
  1065. * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
  1066. * masks event though they reject 46 bit masks.
  1067. */
  1068. while (dma_mask > 0x7fffffffUL) {
  1069. rc = dma_set_mask_and_coherent(&pci_dev->dev, dma_mask);
  1070. if (rc == 0)
  1071. break;
  1072. dma_mask >>= 1;
  1073. }
  1074. if (rc) {
  1075. netif_err(efx, probe, efx->net_dev,
  1076. "could not find a suitable DMA mask\n");
  1077. goto fail2;
  1078. }
  1079. netif_dbg(efx, probe, efx->net_dev,
  1080. "using DMA mask %llx\n", (unsigned long long) dma_mask);
  1081. efx->membase_phys = pci_resource_start(efx->pci_dev, bar);
  1082. rc = pci_request_region(pci_dev, bar, "sfc");
  1083. if (rc) {
  1084. netif_err(efx, probe, efx->net_dev,
  1085. "request for memory BAR failed\n");
  1086. rc = -EIO;
  1087. goto fail3;
  1088. }
  1089. efx->membase = ioremap_nocache(efx->membase_phys, mem_map_size);
  1090. if (!efx->membase) {
  1091. netif_err(efx, probe, efx->net_dev,
  1092. "could not map memory BAR at %llx+%x\n",
  1093. (unsigned long long)efx->membase_phys, mem_map_size);
  1094. rc = -ENOMEM;
  1095. goto fail4;
  1096. }
  1097. netif_dbg(efx, probe, efx->net_dev,
  1098. "memory BAR at %llx+%x (virtual %p)\n",
  1099. (unsigned long long)efx->membase_phys, mem_map_size,
  1100. efx->membase);
  1101. return 0;
  1102. fail4:
  1103. pci_release_region(efx->pci_dev, bar);
  1104. fail3:
  1105. efx->membase_phys = 0;
  1106. fail2:
  1107. pci_disable_device(efx->pci_dev);
  1108. fail1:
  1109. return rc;
  1110. }
  1111. static void efx_fini_io(struct efx_nic *efx)
  1112. {
  1113. int bar;
  1114. netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
  1115. if (efx->membase) {
  1116. iounmap(efx->membase);
  1117. efx->membase = NULL;
  1118. }
  1119. if (efx->membase_phys) {
  1120. bar = efx->type->mem_bar;
  1121. pci_release_region(efx->pci_dev, bar);
  1122. efx->membase_phys = 0;
  1123. }
  1124. /* Don't disable bus-mastering if VFs are assigned */
  1125. if (!pci_vfs_assigned(efx->pci_dev))
  1126. pci_disable_device(efx->pci_dev);
  1127. }
  1128. void efx_set_default_rx_indir_table(struct efx_nic *efx)
  1129. {
  1130. size_t i;
  1131. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  1132. efx->rx_indir_table[i] =
  1133. ethtool_rxfh_indir_default(i, efx->rss_spread);
  1134. }
  1135. static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
  1136. {
  1137. cpumask_var_t thread_mask;
  1138. unsigned int count;
  1139. int cpu;
  1140. if (rss_cpus) {
  1141. count = rss_cpus;
  1142. } else {
  1143. if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
  1144. netif_warn(efx, probe, efx->net_dev,
  1145. "RSS disabled due to allocation failure\n");
  1146. return 1;
  1147. }
  1148. count = 0;
  1149. for_each_online_cpu(cpu) {
  1150. if (!cpumask_test_cpu(cpu, thread_mask)) {
  1151. ++count;
  1152. cpumask_or(thread_mask, thread_mask,
  1153. topology_sibling_cpumask(cpu));
  1154. }
  1155. }
  1156. free_cpumask_var(thread_mask);
  1157. }
  1158. if (count > EFX_MAX_RX_QUEUES) {
  1159. netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
  1160. "Reducing number of rx queues from %u to %u.\n",
  1161. count, EFX_MAX_RX_QUEUES);
  1162. count = EFX_MAX_RX_QUEUES;
  1163. }
  1164. /* If RSS is requested for the PF *and* VFs then we can't write RSS
  1165. * table entries that are inaccessible to VFs
  1166. */
  1167. #ifdef CONFIG_SFC_SRIOV
  1168. if (efx->type->sriov_wanted) {
  1169. if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
  1170. count > efx_vf_size(efx)) {
  1171. netif_warn(efx, probe, efx->net_dev,
  1172. "Reducing number of RSS channels from %u to %u for "
  1173. "VF support. Increase vf-msix-limit to use more "
  1174. "channels on the PF.\n",
  1175. count, efx_vf_size(efx));
  1176. count = efx_vf_size(efx);
  1177. }
  1178. }
  1179. #endif
  1180. return count;
  1181. }
  1182. /* Probe the number and type of interrupts we are able to obtain, and
  1183. * the resulting numbers of channels and RX queues.
  1184. */
  1185. static int efx_probe_interrupts(struct efx_nic *efx)
  1186. {
  1187. unsigned int extra_channels = 0;
  1188. unsigned int i, j;
  1189. int rc;
  1190. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
  1191. if (efx->extra_channel_type[i])
  1192. ++extra_channels;
  1193. if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
  1194. struct msix_entry xentries[EFX_MAX_CHANNELS];
  1195. unsigned int n_channels;
  1196. n_channels = efx_wanted_parallelism(efx);
  1197. if (efx_separate_tx_channels)
  1198. n_channels *= 2;
  1199. n_channels += extra_channels;
  1200. n_channels = min(n_channels, efx->max_channels);
  1201. for (i = 0; i < n_channels; i++)
  1202. xentries[i].entry = i;
  1203. rc = pci_enable_msix_range(efx->pci_dev,
  1204. xentries, 1, n_channels);
  1205. if (rc < 0) {
  1206. /* Fall back to single channel MSI */
  1207. netif_err(efx, drv, efx->net_dev,
  1208. "could not enable MSI-X\n");
  1209. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
  1210. efx->interrupt_mode = EFX_INT_MODE_MSI;
  1211. else
  1212. return rc;
  1213. } else if (rc < n_channels) {
  1214. netif_err(efx, drv, efx->net_dev,
  1215. "WARNING: Insufficient MSI-X vectors"
  1216. " available (%d < %u).\n", rc, n_channels);
  1217. netif_err(efx, drv, efx->net_dev,
  1218. "WARNING: Performance may be reduced.\n");
  1219. n_channels = rc;
  1220. }
  1221. if (rc > 0) {
  1222. efx->n_channels = n_channels;
  1223. if (n_channels > extra_channels)
  1224. n_channels -= extra_channels;
  1225. if (efx_separate_tx_channels) {
  1226. efx->n_tx_channels = min(max(n_channels / 2,
  1227. 1U),
  1228. efx->max_tx_channels);
  1229. efx->n_rx_channels = max(n_channels -
  1230. efx->n_tx_channels,
  1231. 1U);
  1232. } else {
  1233. efx->n_tx_channels = min(n_channels,
  1234. efx->max_tx_channels);
  1235. efx->n_rx_channels = n_channels;
  1236. }
  1237. for (i = 0; i < efx->n_channels; i++)
  1238. efx_get_channel(efx, i)->irq =
  1239. xentries[i].vector;
  1240. }
  1241. }
  1242. /* Try single interrupt MSI */
  1243. if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
  1244. efx->n_channels = 1;
  1245. efx->n_rx_channels = 1;
  1246. efx->n_tx_channels = 1;
  1247. rc = pci_enable_msi(efx->pci_dev);
  1248. if (rc == 0) {
  1249. efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
  1250. } else {
  1251. netif_err(efx, drv, efx->net_dev,
  1252. "could not enable MSI\n");
  1253. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
  1254. efx->interrupt_mode = EFX_INT_MODE_LEGACY;
  1255. else
  1256. return rc;
  1257. }
  1258. }
  1259. /* Assume legacy interrupts */
  1260. if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
  1261. efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
  1262. efx->n_rx_channels = 1;
  1263. efx->n_tx_channels = 1;
  1264. efx->legacy_irq = efx->pci_dev->irq;
  1265. }
  1266. /* Assign extra channels if possible */
  1267. j = efx->n_channels;
  1268. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
  1269. if (!efx->extra_channel_type[i])
  1270. continue;
  1271. if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
  1272. efx->n_channels <= extra_channels) {
  1273. efx->extra_channel_type[i]->handle_no_channel(efx);
  1274. } else {
  1275. --j;
  1276. efx_get_channel(efx, j)->type =
  1277. efx->extra_channel_type[i];
  1278. }
  1279. }
  1280. /* RSS might be usable on VFs even if it is disabled on the PF */
  1281. #ifdef CONFIG_SFC_SRIOV
  1282. if (efx->type->sriov_wanted) {
  1283. efx->rss_spread = ((efx->n_rx_channels > 1 ||
  1284. !efx->type->sriov_wanted(efx)) ?
  1285. efx->n_rx_channels : efx_vf_size(efx));
  1286. return 0;
  1287. }
  1288. #endif
  1289. efx->rss_spread = efx->n_rx_channels;
  1290. return 0;
  1291. }
  1292. static int efx_soft_enable_interrupts(struct efx_nic *efx)
  1293. {
  1294. struct efx_channel *channel, *end_channel;
  1295. int rc;
  1296. BUG_ON(efx->state == STATE_DISABLED);
  1297. efx->irq_soft_enabled = true;
  1298. smp_wmb();
  1299. efx_for_each_channel(channel, efx) {
  1300. if (!channel->type->keep_eventq) {
  1301. rc = efx_init_eventq(channel);
  1302. if (rc)
  1303. goto fail;
  1304. }
  1305. efx_start_eventq(channel);
  1306. }
  1307. efx_mcdi_mode_event(efx);
  1308. return 0;
  1309. fail:
  1310. end_channel = channel;
  1311. efx_for_each_channel(channel, efx) {
  1312. if (channel == end_channel)
  1313. break;
  1314. efx_stop_eventq(channel);
  1315. if (!channel->type->keep_eventq)
  1316. efx_fini_eventq(channel);
  1317. }
  1318. return rc;
  1319. }
  1320. static void efx_soft_disable_interrupts(struct efx_nic *efx)
  1321. {
  1322. struct efx_channel *channel;
  1323. if (efx->state == STATE_DISABLED)
  1324. return;
  1325. efx_mcdi_mode_poll(efx);
  1326. efx->irq_soft_enabled = false;
  1327. smp_wmb();
  1328. if (efx->legacy_irq)
  1329. synchronize_irq(efx->legacy_irq);
  1330. efx_for_each_channel(channel, efx) {
  1331. if (channel->irq)
  1332. synchronize_irq(channel->irq);
  1333. efx_stop_eventq(channel);
  1334. if (!channel->type->keep_eventq)
  1335. efx_fini_eventq(channel);
  1336. }
  1337. /* Flush the asynchronous MCDI request queue */
  1338. efx_mcdi_flush_async(efx);
  1339. }
  1340. static int efx_enable_interrupts(struct efx_nic *efx)
  1341. {
  1342. struct efx_channel *channel, *end_channel;
  1343. int rc;
  1344. BUG_ON(efx->state == STATE_DISABLED);
  1345. if (efx->eeh_disabled_legacy_irq) {
  1346. enable_irq(efx->legacy_irq);
  1347. efx->eeh_disabled_legacy_irq = false;
  1348. }
  1349. efx->type->irq_enable_master(efx);
  1350. efx_for_each_channel(channel, efx) {
  1351. if (channel->type->keep_eventq) {
  1352. rc = efx_init_eventq(channel);
  1353. if (rc)
  1354. goto fail;
  1355. }
  1356. }
  1357. rc = efx_soft_enable_interrupts(efx);
  1358. if (rc)
  1359. goto fail;
  1360. return 0;
  1361. fail:
  1362. end_channel = channel;
  1363. efx_for_each_channel(channel, efx) {
  1364. if (channel == end_channel)
  1365. break;
  1366. if (channel->type->keep_eventq)
  1367. efx_fini_eventq(channel);
  1368. }
  1369. efx->type->irq_disable_non_ev(efx);
  1370. return rc;
  1371. }
  1372. static void efx_disable_interrupts(struct efx_nic *efx)
  1373. {
  1374. struct efx_channel *channel;
  1375. efx_soft_disable_interrupts(efx);
  1376. efx_for_each_channel(channel, efx) {
  1377. if (channel->type->keep_eventq)
  1378. efx_fini_eventq(channel);
  1379. }
  1380. efx->type->irq_disable_non_ev(efx);
  1381. }
  1382. static void efx_remove_interrupts(struct efx_nic *efx)
  1383. {
  1384. struct efx_channel *channel;
  1385. /* Remove MSI/MSI-X interrupts */
  1386. efx_for_each_channel(channel, efx)
  1387. channel->irq = 0;
  1388. pci_disable_msi(efx->pci_dev);
  1389. pci_disable_msix(efx->pci_dev);
  1390. /* Remove legacy interrupt */
  1391. efx->legacy_irq = 0;
  1392. }
  1393. static void efx_set_channels(struct efx_nic *efx)
  1394. {
  1395. struct efx_channel *channel;
  1396. struct efx_tx_queue *tx_queue;
  1397. efx->tx_channel_offset =
  1398. efx_separate_tx_channels ?
  1399. efx->n_channels - efx->n_tx_channels : 0;
  1400. /* We need to mark which channels really have RX and TX
  1401. * queues, and adjust the TX queue numbers if we have separate
  1402. * RX-only and TX-only channels.
  1403. */
  1404. efx_for_each_channel(channel, efx) {
  1405. if (channel->channel < efx->n_rx_channels)
  1406. channel->rx_queue.core_index = channel->channel;
  1407. else
  1408. channel->rx_queue.core_index = -1;
  1409. efx_for_each_channel_tx_queue(tx_queue, channel)
  1410. tx_queue->queue -= (efx->tx_channel_offset *
  1411. EFX_TXQ_TYPES);
  1412. }
  1413. }
  1414. static int efx_probe_nic(struct efx_nic *efx)
  1415. {
  1416. int rc;
  1417. netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
  1418. /* Carry out hardware-type specific initialisation */
  1419. rc = efx->type->probe(efx);
  1420. if (rc)
  1421. return rc;
  1422. do {
  1423. if (!efx->max_channels || !efx->max_tx_channels) {
  1424. netif_err(efx, drv, efx->net_dev,
  1425. "Insufficient resources to allocate"
  1426. " any channels\n");
  1427. rc = -ENOSPC;
  1428. goto fail1;
  1429. }
  1430. /* Determine the number of channels and queues by trying
  1431. * to hook in MSI-X interrupts.
  1432. */
  1433. rc = efx_probe_interrupts(efx);
  1434. if (rc)
  1435. goto fail1;
  1436. efx_set_channels(efx);
  1437. /* dimension_resources can fail with EAGAIN */
  1438. rc = efx->type->dimension_resources(efx);
  1439. if (rc != 0 && rc != -EAGAIN)
  1440. goto fail2;
  1441. if (rc == -EAGAIN)
  1442. /* try again with new max_channels */
  1443. efx_remove_interrupts(efx);
  1444. } while (rc == -EAGAIN);
  1445. if (efx->n_channels > 1)
  1446. netdev_rss_key_fill(&efx->rx_hash_key,
  1447. sizeof(efx->rx_hash_key));
  1448. efx_set_default_rx_indir_table(efx);
  1449. netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  1450. netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  1451. /* Initialise the interrupt moderation settings */
  1452. efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
  1453. efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
  1454. true);
  1455. return 0;
  1456. fail2:
  1457. efx_remove_interrupts(efx);
  1458. fail1:
  1459. efx->type->remove(efx);
  1460. return rc;
  1461. }
  1462. static void efx_remove_nic(struct efx_nic *efx)
  1463. {
  1464. netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
  1465. efx_remove_interrupts(efx);
  1466. efx->type->remove(efx);
  1467. }
  1468. static int efx_probe_filters(struct efx_nic *efx)
  1469. {
  1470. int rc;
  1471. spin_lock_init(&efx->filter_lock);
  1472. init_rwsem(&efx->filter_sem);
  1473. mutex_lock(&efx->mac_lock);
  1474. down_write(&efx->filter_sem);
  1475. rc = efx->type->filter_table_probe(efx);
  1476. if (rc)
  1477. goto out_unlock;
  1478. #ifdef CONFIG_RFS_ACCEL
  1479. if (efx->type->offload_features & NETIF_F_NTUPLE) {
  1480. struct efx_channel *channel;
  1481. int i, success = 1;
  1482. efx_for_each_channel(channel, efx) {
  1483. channel->rps_flow_id =
  1484. kcalloc(efx->type->max_rx_ip_filters,
  1485. sizeof(*channel->rps_flow_id),
  1486. GFP_KERNEL);
  1487. if (!channel->rps_flow_id)
  1488. success = 0;
  1489. else
  1490. for (i = 0;
  1491. i < efx->type->max_rx_ip_filters;
  1492. ++i)
  1493. channel->rps_flow_id[i] =
  1494. RPS_FLOW_ID_INVALID;
  1495. }
  1496. if (!success) {
  1497. efx_for_each_channel(channel, efx)
  1498. kfree(channel->rps_flow_id);
  1499. efx->type->filter_table_remove(efx);
  1500. rc = -ENOMEM;
  1501. goto out_unlock;
  1502. }
  1503. efx->rps_expire_index = efx->rps_expire_channel = 0;
  1504. }
  1505. #endif
  1506. out_unlock:
  1507. up_write(&efx->filter_sem);
  1508. mutex_unlock(&efx->mac_lock);
  1509. return rc;
  1510. }
  1511. static void efx_remove_filters(struct efx_nic *efx)
  1512. {
  1513. #ifdef CONFIG_RFS_ACCEL
  1514. struct efx_channel *channel;
  1515. efx_for_each_channel(channel, efx)
  1516. kfree(channel->rps_flow_id);
  1517. #endif
  1518. down_write(&efx->filter_sem);
  1519. efx->type->filter_table_remove(efx);
  1520. up_write(&efx->filter_sem);
  1521. }
  1522. static void efx_restore_filters(struct efx_nic *efx)
  1523. {
  1524. down_read(&efx->filter_sem);
  1525. efx->type->filter_table_restore(efx);
  1526. up_read(&efx->filter_sem);
  1527. }
  1528. /**************************************************************************
  1529. *
  1530. * NIC startup/shutdown
  1531. *
  1532. *************************************************************************/
  1533. static int efx_probe_all(struct efx_nic *efx)
  1534. {
  1535. int rc;
  1536. rc = efx_probe_nic(efx);
  1537. if (rc) {
  1538. netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
  1539. goto fail1;
  1540. }
  1541. rc = efx_probe_port(efx);
  1542. if (rc) {
  1543. netif_err(efx, probe, efx->net_dev, "failed to create port\n");
  1544. goto fail2;
  1545. }
  1546. BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
  1547. if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
  1548. rc = -EINVAL;
  1549. goto fail3;
  1550. }
  1551. efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
  1552. #ifdef CONFIG_SFC_SRIOV
  1553. rc = efx->type->vswitching_probe(efx);
  1554. if (rc) /* not fatal; the PF will still work fine */
  1555. netif_warn(efx, probe, efx->net_dev,
  1556. "failed to setup vswitching rc=%d;"
  1557. " VFs may not function\n", rc);
  1558. #endif
  1559. rc = efx_probe_filters(efx);
  1560. if (rc) {
  1561. netif_err(efx, probe, efx->net_dev,
  1562. "failed to create filter tables\n");
  1563. goto fail4;
  1564. }
  1565. rc = efx_probe_channels(efx);
  1566. if (rc)
  1567. goto fail5;
  1568. return 0;
  1569. fail5:
  1570. efx_remove_filters(efx);
  1571. fail4:
  1572. #ifdef CONFIG_SFC_SRIOV
  1573. efx->type->vswitching_remove(efx);
  1574. #endif
  1575. fail3:
  1576. efx_remove_port(efx);
  1577. fail2:
  1578. efx_remove_nic(efx);
  1579. fail1:
  1580. return rc;
  1581. }
  1582. /* If the interface is supposed to be running but is not, start
  1583. * the hardware and software data path, regular activity for the port
  1584. * (MAC statistics, link polling, etc.) and schedule the port to be
  1585. * reconfigured. Interrupts must already be enabled. This function
  1586. * is safe to call multiple times, so long as the NIC is not disabled.
  1587. * Requires the RTNL lock.
  1588. */
  1589. static void efx_start_all(struct efx_nic *efx)
  1590. {
  1591. EFX_ASSERT_RESET_SERIALISED(efx);
  1592. BUG_ON(efx->state == STATE_DISABLED);
  1593. /* Check that it is appropriate to restart the interface. All
  1594. * of these flags are safe to read under just the rtnl lock */
  1595. if (efx->port_enabled || !netif_running(efx->net_dev) ||
  1596. efx->reset_pending)
  1597. return;
  1598. efx_start_port(efx);
  1599. efx_start_datapath(efx);
  1600. /* Start the hardware monitor if there is one */
  1601. if (efx->type->monitor != NULL)
  1602. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1603. efx_monitor_interval);
  1604. /* Link state detection is normally event-driven; we have
  1605. * to poll now because we could have missed a change
  1606. */
  1607. mutex_lock(&efx->mac_lock);
  1608. if (efx->phy_op->poll(efx))
  1609. efx_link_status_changed(efx);
  1610. mutex_unlock(&efx->mac_lock);
  1611. efx->type->start_stats(efx);
  1612. efx->type->pull_stats(efx);
  1613. spin_lock_bh(&efx->stats_lock);
  1614. efx->type->update_stats(efx, NULL, NULL);
  1615. spin_unlock_bh(&efx->stats_lock);
  1616. }
  1617. /* Quiesce the hardware and software data path, and regular activity
  1618. * for the port without bringing the link down. Safe to call multiple
  1619. * times with the NIC in almost any state, but interrupts should be
  1620. * enabled. Requires the RTNL lock.
  1621. */
  1622. static void efx_stop_all(struct efx_nic *efx)
  1623. {
  1624. EFX_ASSERT_RESET_SERIALISED(efx);
  1625. /* port_enabled can be read safely under the rtnl lock */
  1626. if (!efx->port_enabled)
  1627. return;
  1628. /* update stats before we go down so we can accurately count
  1629. * rx_nodesc_drops
  1630. */
  1631. efx->type->pull_stats(efx);
  1632. spin_lock_bh(&efx->stats_lock);
  1633. efx->type->update_stats(efx, NULL, NULL);
  1634. spin_unlock_bh(&efx->stats_lock);
  1635. efx->type->stop_stats(efx);
  1636. efx_stop_port(efx);
  1637. /* Stop the kernel transmit interface. This is only valid if
  1638. * the device is stopped or detached; otherwise the watchdog
  1639. * may fire immediately.
  1640. */
  1641. WARN_ON(netif_running(efx->net_dev) &&
  1642. netif_device_present(efx->net_dev));
  1643. netif_tx_disable(efx->net_dev);
  1644. efx_stop_datapath(efx);
  1645. }
  1646. static void efx_remove_all(struct efx_nic *efx)
  1647. {
  1648. efx_remove_channels(efx);
  1649. efx_remove_filters(efx);
  1650. #ifdef CONFIG_SFC_SRIOV
  1651. efx->type->vswitching_remove(efx);
  1652. #endif
  1653. efx_remove_port(efx);
  1654. efx_remove_nic(efx);
  1655. }
  1656. /**************************************************************************
  1657. *
  1658. * Interrupt moderation
  1659. *
  1660. **************************************************************************/
  1661. unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
  1662. {
  1663. if (usecs == 0)
  1664. return 0;
  1665. if (usecs * 1000 < efx->timer_quantum_ns)
  1666. return 1; /* never round down to 0 */
  1667. return usecs * 1000 / efx->timer_quantum_ns;
  1668. }
  1669. unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
  1670. {
  1671. /* We must round up when converting ticks to microseconds
  1672. * because we round down when converting the other way.
  1673. */
  1674. return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
  1675. }
  1676. /* Set interrupt moderation parameters */
  1677. int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
  1678. unsigned int rx_usecs, bool rx_adaptive,
  1679. bool rx_may_override_tx)
  1680. {
  1681. struct efx_channel *channel;
  1682. unsigned int timer_max_us;
  1683. EFX_ASSERT_RESET_SERIALISED(efx);
  1684. timer_max_us = efx->timer_max_ns / 1000;
  1685. if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
  1686. return -EINVAL;
  1687. if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
  1688. !rx_may_override_tx) {
  1689. netif_err(efx, drv, efx->net_dev, "Channels are shared. "
  1690. "RX and TX IRQ moderation must be equal\n");
  1691. return -EINVAL;
  1692. }
  1693. efx->irq_rx_adaptive = rx_adaptive;
  1694. efx->irq_rx_moderation_us = rx_usecs;
  1695. efx_for_each_channel(channel, efx) {
  1696. if (efx_channel_has_rx_queue(channel))
  1697. channel->irq_moderation_us = rx_usecs;
  1698. else if (efx_channel_has_tx_queues(channel))
  1699. channel->irq_moderation_us = tx_usecs;
  1700. }
  1701. return 0;
  1702. }
  1703. void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
  1704. unsigned int *rx_usecs, bool *rx_adaptive)
  1705. {
  1706. *rx_adaptive = efx->irq_rx_adaptive;
  1707. *rx_usecs = efx->irq_rx_moderation_us;
  1708. /* If channels are shared between RX and TX, so is IRQ
  1709. * moderation. Otherwise, IRQ moderation is the same for all
  1710. * TX channels and is not adaptive.
  1711. */
  1712. if (efx->tx_channel_offset == 0) {
  1713. *tx_usecs = *rx_usecs;
  1714. } else {
  1715. struct efx_channel *tx_channel;
  1716. tx_channel = efx->channel[efx->tx_channel_offset];
  1717. *tx_usecs = tx_channel->irq_moderation_us;
  1718. }
  1719. }
  1720. /**************************************************************************
  1721. *
  1722. * Hardware monitor
  1723. *
  1724. **************************************************************************/
  1725. /* Run periodically off the general workqueue */
  1726. static void efx_monitor(struct work_struct *data)
  1727. {
  1728. struct efx_nic *efx = container_of(data, struct efx_nic,
  1729. monitor_work.work);
  1730. netif_vdbg(efx, timer, efx->net_dev,
  1731. "hardware monitor executing on CPU %d\n",
  1732. raw_smp_processor_id());
  1733. BUG_ON(efx->type->monitor == NULL);
  1734. /* If the mac_lock is already held then it is likely a port
  1735. * reconfiguration is already in place, which will likely do
  1736. * most of the work of monitor() anyway. */
  1737. if (mutex_trylock(&efx->mac_lock)) {
  1738. if (efx->port_enabled)
  1739. efx->type->monitor(efx);
  1740. mutex_unlock(&efx->mac_lock);
  1741. }
  1742. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1743. efx_monitor_interval);
  1744. }
  1745. /**************************************************************************
  1746. *
  1747. * ioctls
  1748. *
  1749. *************************************************************************/
  1750. /* Net device ioctl
  1751. * Context: process, rtnl_lock() held.
  1752. */
  1753. static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
  1754. {
  1755. struct efx_nic *efx = netdev_priv(net_dev);
  1756. struct mii_ioctl_data *data = if_mii(ifr);
  1757. if (cmd == SIOCSHWTSTAMP)
  1758. return efx_ptp_set_ts_config(efx, ifr);
  1759. if (cmd == SIOCGHWTSTAMP)
  1760. return efx_ptp_get_ts_config(efx, ifr);
  1761. /* Convert phy_id from older PRTAD/DEVAD format */
  1762. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  1763. (data->phy_id & 0xfc00) == 0x0400)
  1764. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  1765. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  1766. }
  1767. /**************************************************************************
  1768. *
  1769. * NAPI interface
  1770. *
  1771. **************************************************************************/
  1772. static void efx_init_napi_channel(struct efx_channel *channel)
  1773. {
  1774. struct efx_nic *efx = channel->efx;
  1775. channel->napi_dev = efx->net_dev;
  1776. netif_napi_add(channel->napi_dev, &channel->napi_str,
  1777. efx_poll, napi_weight);
  1778. }
  1779. static void efx_init_napi(struct efx_nic *efx)
  1780. {
  1781. struct efx_channel *channel;
  1782. efx_for_each_channel(channel, efx)
  1783. efx_init_napi_channel(channel);
  1784. }
  1785. static void efx_fini_napi_channel(struct efx_channel *channel)
  1786. {
  1787. if (channel->napi_dev)
  1788. netif_napi_del(&channel->napi_str);
  1789. channel->napi_dev = NULL;
  1790. }
  1791. static void efx_fini_napi(struct efx_nic *efx)
  1792. {
  1793. struct efx_channel *channel;
  1794. efx_for_each_channel(channel, efx)
  1795. efx_fini_napi_channel(channel);
  1796. }
  1797. /**************************************************************************
  1798. *
  1799. * Kernel netpoll interface
  1800. *
  1801. *************************************************************************/
  1802. #ifdef CONFIG_NET_POLL_CONTROLLER
  1803. /* Although in the common case interrupts will be disabled, this is not
  1804. * guaranteed. However, all our work happens inside the NAPI callback,
  1805. * so no locking is required.
  1806. */
  1807. static void efx_netpoll(struct net_device *net_dev)
  1808. {
  1809. struct efx_nic *efx = netdev_priv(net_dev);
  1810. struct efx_channel *channel;
  1811. efx_for_each_channel(channel, efx)
  1812. efx_schedule_channel(channel);
  1813. }
  1814. #endif
  1815. /**************************************************************************
  1816. *
  1817. * Kernel net device interface
  1818. *
  1819. *************************************************************************/
  1820. /* Context: process, rtnl_lock() held. */
  1821. int efx_net_open(struct net_device *net_dev)
  1822. {
  1823. struct efx_nic *efx = netdev_priv(net_dev);
  1824. int rc;
  1825. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  1826. raw_smp_processor_id());
  1827. rc = efx_check_disabled(efx);
  1828. if (rc)
  1829. return rc;
  1830. if (efx->phy_mode & PHY_MODE_SPECIAL)
  1831. return -EBUSY;
  1832. if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
  1833. return -EIO;
  1834. /* Notify the kernel of the link state polled during driver load,
  1835. * before the monitor starts running */
  1836. efx_link_status_changed(efx);
  1837. efx_start_all(efx);
  1838. if (efx->state == STATE_DISABLED || efx->reset_pending)
  1839. netif_device_detach(efx->net_dev);
  1840. efx_selftest_async_start(efx);
  1841. return 0;
  1842. }
  1843. /* Context: process, rtnl_lock() held.
  1844. * Note that the kernel will ignore our return code; this method
  1845. * should really be a void.
  1846. */
  1847. int efx_net_stop(struct net_device *net_dev)
  1848. {
  1849. struct efx_nic *efx = netdev_priv(net_dev);
  1850. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  1851. raw_smp_processor_id());
  1852. /* Stop the device and flush all the channels */
  1853. efx_stop_all(efx);
  1854. return 0;
  1855. }
  1856. /* Context: process, dev_base_lock or RTNL held, non-blocking. */
  1857. static void efx_net_stats(struct net_device *net_dev,
  1858. struct rtnl_link_stats64 *stats)
  1859. {
  1860. struct efx_nic *efx = netdev_priv(net_dev);
  1861. spin_lock_bh(&efx->stats_lock);
  1862. efx->type->update_stats(efx, NULL, stats);
  1863. spin_unlock_bh(&efx->stats_lock);
  1864. }
  1865. /* Context: netif_tx_lock held, BHs disabled. */
  1866. static void efx_watchdog(struct net_device *net_dev)
  1867. {
  1868. struct efx_nic *efx = netdev_priv(net_dev);
  1869. netif_err(efx, tx_err, efx->net_dev,
  1870. "TX stuck with port_enabled=%d: resetting channels\n",
  1871. efx->port_enabled);
  1872. efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
  1873. }
  1874. /* Context: process, rtnl_lock() held. */
  1875. static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
  1876. {
  1877. struct efx_nic *efx = netdev_priv(net_dev);
  1878. int rc;
  1879. rc = efx_check_disabled(efx);
  1880. if (rc)
  1881. return rc;
  1882. netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
  1883. efx_device_detach_sync(efx);
  1884. efx_stop_all(efx);
  1885. mutex_lock(&efx->mac_lock);
  1886. net_dev->mtu = new_mtu;
  1887. efx_mac_reconfigure(efx);
  1888. mutex_unlock(&efx->mac_lock);
  1889. efx_start_all(efx);
  1890. efx_device_attach_if_not_resetting(efx);
  1891. return 0;
  1892. }
  1893. static int efx_set_mac_address(struct net_device *net_dev, void *data)
  1894. {
  1895. struct efx_nic *efx = netdev_priv(net_dev);
  1896. struct sockaddr *addr = data;
  1897. u8 *new_addr = addr->sa_data;
  1898. u8 old_addr[6];
  1899. int rc;
  1900. if (!is_valid_ether_addr(new_addr)) {
  1901. netif_err(efx, drv, efx->net_dev,
  1902. "invalid ethernet MAC address requested: %pM\n",
  1903. new_addr);
  1904. return -EADDRNOTAVAIL;
  1905. }
  1906. /* save old address */
  1907. ether_addr_copy(old_addr, net_dev->dev_addr);
  1908. ether_addr_copy(net_dev->dev_addr, new_addr);
  1909. if (efx->type->set_mac_address) {
  1910. rc = efx->type->set_mac_address(efx);
  1911. if (rc) {
  1912. ether_addr_copy(net_dev->dev_addr, old_addr);
  1913. return rc;
  1914. }
  1915. }
  1916. /* Reconfigure the MAC */
  1917. mutex_lock(&efx->mac_lock);
  1918. efx_mac_reconfigure(efx);
  1919. mutex_unlock(&efx->mac_lock);
  1920. return 0;
  1921. }
  1922. /* Context: netif_addr_lock held, BHs disabled. */
  1923. static void efx_set_rx_mode(struct net_device *net_dev)
  1924. {
  1925. struct efx_nic *efx = netdev_priv(net_dev);
  1926. if (efx->port_enabled)
  1927. queue_work(efx->workqueue, &efx->mac_work);
  1928. /* Otherwise efx_start_port() will do this */
  1929. }
  1930. static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
  1931. {
  1932. struct efx_nic *efx = netdev_priv(net_dev);
  1933. int rc;
  1934. /* If disabling RX n-tuple filtering, clear existing filters */
  1935. if (net_dev->features & ~data & NETIF_F_NTUPLE) {
  1936. rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
  1937. if (rc)
  1938. return rc;
  1939. }
  1940. /* If Rx VLAN filter is changed, update filters via mac_reconfigure */
  1941. if ((net_dev->features ^ data) & NETIF_F_HW_VLAN_CTAG_FILTER) {
  1942. /* efx_set_rx_mode() will schedule MAC work to update filters
  1943. * when a new features are finally set in net_dev.
  1944. */
  1945. efx_set_rx_mode(net_dev);
  1946. }
  1947. return 0;
  1948. }
  1949. static int efx_get_phys_port_id(struct net_device *net_dev,
  1950. struct netdev_phys_item_id *ppid)
  1951. {
  1952. struct efx_nic *efx = netdev_priv(net_dev);
  1953. if (efx->type->get_phys_port_id)
  1954. return efx->type->get_phys_port_id(efx, ppid);
  1955. else
  1956. return -EOPNOTSUPP;
  1957. }
  1958. static int efx_get_phys_port_name(struct net_device *net_dev,
  1959. char *name, size_t len)
  1960. {
  1961. struct efx_nic *efx = netdev_priv(net_dev);
  1962. if (snprintf(name, len, "p%u", efx->port_num) >= len)
  1963. return -EINVAL;
  1964. return 0;
  1965. }
  1966. static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  1967. {
  1968. struct efx_nic *efx = netdev_priv(net_dev);
  1969. if (efx->type->vlan_rx_add_vid)
  1970. return efx->type->vlan_rx_add_vid(efx, proto, vid);
  1971. else
  1972. return -EOPNOTSUPP;
  1973. }
  1974. static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  1975. {
  1976. struct efx_nic *efx = netdev_priv(net_dev);
  1977. if (efx->type->vlan_rx_kill_vid)
  1978. return efx->type->vlan_rx_kill_vid(efx, proto, vid);
  1979. else
  1980. return -EOPNOTSUPP;
  1981. }
  1982. static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
  1983. {
  1984. switch (in) {
  1985. case UDP_TUNNEL_TYPE_VXLAN:
  1986. return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
  1987. case UDP_TUNNEL_TYPE_GENEVE:
  1988. return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
  1989. default:
  1990. return -1;
  1991. }
  1992. }
  1993. static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
  1994. {
  1995. struct efx_nic *efx = netdev_priv(dev);
  1996. struct efx_udp_tunnel tnl;
  1997. int efx_tunnel_type;
  1998. efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
  1999. if (efx_tunnel_type < 0)
  2000. return;
  2001. tnl.type = (u16)efx_tunnel_type;
  2002. tnl.port = ti->port;
  2003. if (efx->type->udp_tnl_add_port)
  2004. (void)efx->type->udp_tnl_add_port(efx, tnl);
  2005. }
  2006. static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
  2007. {
  2008. struct efx_nic *efx = netdev_priv(dev);
  2009. struct efx_udp_tunnel tnl;
  2010. int efx_tunnel_type;
  2011. efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
  2012. if (efx_tunnel_type < 0)
  2013. return;
  2014. tnl.type = (u16)efx_tunnel_type;
  2015. tnl.port = ti->port;
  2016. if (efx->type->udp_tnl_del_port)
  2017. (void)efx->type->udp_tnl_del_port(efx, tnl);
  2018. }
  2019. static const struct net_device_ops efx_netdev_ops = {
  2020. .ndo_open = efx_net_open,
  2021. .ndo_stop = efx_net_stop,
  2022. .ndo_get_stats64 = efx_net_stats,
  2023. .ndo_tx_timeout = efx_watchdog,
  2024. .ndo_start_xmit = efx_hard_start_xmit,
  2025. .ndo_validate_addr = eth_validate_addr,
  2026. .ndo_do_ioctl = efx_ioctl,
  2027. .ndo_change_mtu = efx_change_mtu,
  2028. .ndo_set_mac_address = efx_set_mac_address,
  2029. .ndo_set_rx_mode = efx_set_rx_mode,
  2030. .ndo_set_features = efx_set_features,
  2031. .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
  2032. .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
  2033. #ifdef CONFIG_SFC_SRIOV
  2034. .ndo_set_vf_mac = efx_sriov_set_vf_mac,
  2035. .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
  2036. .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
  2037. .ndo_get_vf_config = efx_sriov_get_vf_config,
  2038. .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
  2039. #endif
  2040. .ndo_get_phys_port_id = efx_get_phys_port_id,
  2041. .ndo_get_phys_port_name = efx_get_phys_port_name,
  2042. #ifdef CONFIG_NET_POLL_CONTROLLER
  2043. .ndo_poll_controller = efx_netpoll,
  2044. #endif
  2045. .ndo_setup_tc = efx_setup_tc,
  2046. #ifdef CONFIG_RFS_ACCEL
  2047. .ndo_rx_flow_steer = efx_filter_rfs,
  2048. #endif
  2049. .ndo_udp_tunnel_add = efx_udp_tunnel_add,
  2050. .ndo_udp_tunnel_del = efx_udp_tunnel_del,
  2051. };
  2052. static void efx_update_name(struct efx_nic *efx)
  2053. {
  2054. strcpy(efx->name, efx->net_dev->name);
  2055. efx_mtd_rename(efx);
  2056. efx_set_channel_names(efx);
  2057. }
  2058. static int efx_netdev_event(struct notifier_block *this,
  2059. unsigned long event, void *ptr)
  2060. {
  2061. struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
  2062. if ((net_dev->netdev_ops == &efx_netdev_ops) &&
  2063. event == NETDEV_CHANGENAME)
  2064. efx_update_name(netdev_priv(net_dev));
  2065. return NOTIFY_DONE;
  2066. }
  2067. static struct notifier_block efx_netdev_notifier = {
  2068. .notifier_call = efx_netdev_event,
  2069. };
  2070. static ssize_t
  2071. show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
  2072. {
  2073. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2074. return sprintf(buf, "%d\n", efx->phy_type);
  2075. }
  2076. static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
  2077. #ifdef CONFIG_SFC_MCDI_LOGGING
  2078. static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
  2079. char *buf)
  2080. {
  2081. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2082. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  2083. return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
  2084. }
  2085. static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
  2086. const char *buf, size_t count)
  2087. {
  2088. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2089. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  2090. bool enable = count > 0 && *buf != '0';
  2091. mcdi->logging_enabled = enable;
  2092. return count;
  2093. }
  2094. static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
  2095. #endif
  2096. static int efx_register_netdev(struct efx_nic *efx)
  2097. {
  2098. struct net_device *net_dev = efx->net_dev;
  2099. struct efx_channel *channel;
  2100. int rc;
  2101. net_dev->watchdog_timeo = 5 * HZ;
  2102. net_dev->irq = efx->pci_dev->irq;
  2103. net_dev->netdev_ops = &efx_netdev_ops;
  2104. if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
  2105. net_dev->priv_flags |= IFF_UNICAST_FLT;
  2106. net_dev->ethtool_ops = &efx_ethtool_ops;
  2107. net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
  2108. net_dev->min_mtu = EFX_MIN_MTU;
  2109. net_dev->max_mtu = EFX_MAX_MTU;
  2110. rtnl_lock();
  2111. /* Enable resets to be scheduled and check whether any were
  2112. * already requested. If so, the NIC is probably hosed so we
  2113. * abort.
  2114. */
  2115. efx->state = STATE_READY;
  2116. smp_mb(); /* ensure we change state before checking reset_pending */
  2117. if (efx->reset_pending) {
  2118. netif_err(efx, probe, efx->net_dev,
  2119. "aborting probe due to scheduled reset\n");
  2120. rc = -EIO;
  2121. goto fail_locked;
  2122. }
  2123. rc = dev_alloc_name(net_dev, net_dev->name);
  2124. if (rc < 0)
  2125. goto fail_locked;
  2126. efx_update_name(efx);
  2127. /* Always start with carrier off; PHY events will detect the link */
  2128. netif_carrier_off(net_dev);
  2129. rc = register_netdevice(net_dev);
  2130. if (rc)
  2131. goto fail_locked;
  2132. efx_for_each_channel(channel, efx) {
  2133. struct efx_tx_queue *tx_queue;
  2134. efx_for_each_channel_tx_queue(tx_queue, channel)
  2135. efx_init_tx_queue_core_txq(tx_queue);
  2136. }
  2137. efx_associate(efx);
  2138. rtnl_unlock();
  2139. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2140. if (rc) {
  2141. netif_err(efx, drv, efx->net_dev,
  2142. "failed to init net dev attributes\n");
  2143. goto fail_registered;
  2144. }
  2145. #ifdef CONFIG_SFC_MCDI_LOGGING
  2146. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
  2147. if (rc) {
  2148. netif_err(efx, drv, efx->net_dev,
  2149. "failed to init net dev attributes\n");
  2150. goto fail_attr_mcdi_logging;
  2151. }
  2152. #endif
  2153. return 0;
  2154. #ifdef CONFIG_SFC_MCDI_LOGGING
  2155. fail_attr_mcdi_logging:
  2156. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2157. #endif
  2158. fail_registered:
  2159. rtnl_lock();
  2160. efx_dissociate(efx);
  2161. unregister_netdevice(net_dev);
  2162. fail_locked:
  2163. efx->state = STATE_UNINIT;
  2164. rtnl_unlock();
  2165. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  2166. return rc;
  2167. }
  2168. static void efx_unregister_netdev(struct efx_nic *efx)
  2169. {
  2170. if (!efx->net_dev)
  2171. return;
  2172. BUG_ON(netdev_priv(efx->net_dev) != efx);
  2173. if (efx_dev_registered(efx)) {
  2174. strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  2175. #ifdef CONFIG_SFC_MCDI_LOGGING
  2176. device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
  2177. #endif
  2178. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2179. unregister_netdev(efx->net_dev);
  2180. }
  2181. }
  2182. /**************************************************************************
  2183. *
  2184. * Device reset and suspend
  2185. *
  2186. **************************************************************************/
  2187. /* Tears down the entire software state and most of the hardware state
  2188. * before reset. */
  2189. void efx_reset_down(struct efx_nic *efx, enum reset_type method)
  2190. {
  2191. EFX_ASSERT_RESET_SERIALISED(efx);
  2192. if (method == RESET_TYPE_MCDI_TIMEOUT)
  2193. efx->type->prepare_flr(efx);
  2194. efx_stop_all(efx);
  2195. efx_disable_interrupts(efx);
  2196. mutex_lock(&efx->mac_lock);
  2197. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
  2198. method != RESET_TYPE_DATAPATH)
  2199. efx->phy_op->fini(efx);
  2200. efx->type->fini(efx);
  2201. }
  2202. /* This function will always ensure that the locks acquired in
  2203. * efx_reset_down() are released. A failure return code indicates
  2204. * that we were unable to reinitialise the hardware, and the
  2205. * driver should be disabled. If ok is false, then the rx and tx
  2206. * engines are not restarted, pending a RESET_DISABLE. */
  2207. int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
  2208. {
  2209. int rc;
  2210. EFX_ASSERT_RESET_SERIALISED(efx);
  2211. if (method == RESET_TYPE_MCDI_TIMEOUT)
  2212. efx->type->finish_flr(efx);
  2213. /* Ensure that SRAM is initialised even if we're disabling the device */
  2214. rc = efx->type->init(efx);
  2215. if (rc) {
  2216. netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
  2217. goto fail;
  2218. }
  2219. if (!ok)
  2220. goto fail;
  2221. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
  2222. method != RESET_TYPE_DATAPATH) {
  2223. rc = efx->phy_op->init(efx);
  2224. if (rc)
  2225. goto fail;
  2226. rc = efx->phy_op->reconfigure(efx);
  2227. if (rc && rc != -EPERM)
  2228. netif_err(efx, drv, efx->net_dev,
  2229. "could not restore PHY settings\n");
  2230. }
  2231. rc = efx_enable_interrupts(efx);
  2232. if (rc)
  2233. goto fail;
  2234. #ifdef CONFIG_SFC_SRIOV
  2235. rc = efx->type->vswitching_restore(efx);
  2236. if (rc) /* not fatal; the PF will still work fine */
  2237. netif_warn(efx, probe, efx->net_dev,
  2238. "failed to restore vswitching rc=%d;"
  2239. " VFs may not function\n", rc);
  2240. #endif
  2241. down_read(&efx->filter_sem);
  2242. efx_restore_filters(efx);
  2243. up_read(&efx->filter_sem);
  2244. if (efx->type->sriov_reset)
  2245. efx->type->sriov_reset(efx);
  2246. mutex_unlock(&efx->mac_lock);
  2247. efx_start_all(efx);
  2248. if (efx->type->udp_tnl_push_ports)
  2249. efx->type->udp_tnl_push_ports(efx);
  2250. return 0;
  2251. fail:
  2252. efx->port_initialized = false;
  2253. mutex_unlock(&efx->mac_lock);
  2254. return rc;
  2255. }
  2256. /* Reset the NIC using the specified method. Note that the reset may
  2257. * fail, in which case the card will be left in an unusable state.
  2258. *
  2259. * Caller must hold the rtnl_lock.
  2260. */
  2261. int efx_reset(struct efx_nic *efx, enum reset_type method)
  2262. {
  2263. int rc, rc2;
  2264. bool disabled;
  2265. netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
  2266. RESET_TYPE(method));
  2267. efx_device_detach_sync(efx);
  2268. efx_reset_down(efx, method);
  2269. rc = efx->type->reset(efx, method);
  2270. if (rc) {
  2271. netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
  2272. goto out;
  2273. }
  2274. /* Clear flags for the scopes we covered. We assume the NIC and
  2275. * driver are now quiescent so that there is no race here.
  2276. */
  2277. if (method < RESET_TYPE_MAX_METHOD)
  2278. efx->reset_pending &= -(1 << (method + 1));
  2279. else /* it doesn't fit into the well-ordered scope hierarchy */
  2280. __clear_bit(method, &efx->reset_pending);
  2281. /* Reinitialise bus-mastering, which may have been turned off before
  2282. * the reset was scheduled. This is still appropriate, even in the
  2283. * RESET_TYPE_DISABLE since this driver generally assumes the hardware
  2284. * can respond to requests. */
  2285. pci_set_master(efx->pci_dev);
  2286. out:
  2287. /* Leave device stopped if necessary */
  2288. disabled = rc ||
  2289. method == RESET_TYPE_DISABLE ||
  2290. method == RESET_TYPE_RECOVER_OR_DISABLE;
  2291. rc2 = efx_reset_up(efx, method, !disabled);
  2292. if (rc2) {
  2293. disabled = true;
  2294. if (!rc)
  2295. rc = rc2;
  2296. }
  2297. if (disabled) {
  2298. dev_close(efx->net_dev);
  2299. netif_err(efx, drv, efx->net_dev, "has been disabled\n");
  2300. efx->state = STATE_DISABLED;
  2301. } else {
  2302. netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
  2303. efx_device_attach_if_not_resetting(efx);
  2304. }
  2305. return rc;
  2306. }
  2307. /* Try recovery mechanisms.
  2308. * For now only EEH is supported.
  2309. * Returns 0 if the recovery mechanisms are unsuccessful.
  2310. * Returns a non-zero value otherwise.
  2311. */
  2312. int efx_try_recovery(struct efx_nic *efx)
  2313. {
  2314. #ifdef CONFIG_EEH
  2315. /* A PCI error can occur and not be seen by EEH because nothing
  2316. * happens on the PCI bus. In this case the driver may fail and
  2317. * schedule a 'recover or reset', leading to this recovery handler.
  2318. * Manually call the eeh failure check function.
  2319. */
  2320. struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
  2321. if (eeh_dev_check_failure(eehdev)) {
  2322. /* The EEH mechanisms will handle the error and reset the
  2323. * device if necessary.
  2324. */
  2325. return 1;
  2326. }
  2327. #endif
  2328. return 0;
  2329. }
  2330. static void efx_wait_for_bist_end(struct efx_nic *efx)
  2331. {
  2332. int i;
  2333. for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
  2334. if (efx_mcdi_poll_reboot(efx))
  2335. goto out;
  2336. msleep(BIST_WAIT_DELAY_MS);
  2337. }
  2338. netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
  2339. out:
  2340. /* Either way unset the BIST flag. If we found no reboot we probably
  2341. * won't recover, but we should try.
  2342. */
  2343. efx->mc_bist_for_other_fn = false;
  2344. }
  2345. /* The worker thread exists so that code that cannot sleep can
  2346. * schedule a reset for later.
  2347. */
  2348. static void efx_reset_work(struct work_struct *data)
  2349. {
  2350. struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
  2351. unsigned long pending;
  2352. enum reset_type method;
  2353. pending = ACCESS_ONCE(efx->reset_pending);
  2354. method = fls(pending) - 1;
  2355. if (method == RESET_TYPE_MC_BIST)
  2356. efx_wait_for_bist_end(efx);
  2357. if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
  2358. method == RESET_TYPE_RECOVER_OR_ALL) &&
  2359. efx_try_recovery(efx))
  2360. return;
  2361. if (!pending)
  2362. return;
  2363. rtnl_lock();
  2364. /* We checked the state in efx_schedule_reset() but it may
  2365. * have changed by now. Now that we have the RTNL lock,
  2366. * it cannot change again.
  2367. */
  2368. if (efx->state == STATE_READY)
  2369. (void)efx_reset(efx, method);
  2370. rtnl_unlock();
  2371. }
  2372. void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
  2373. {
  2374. enum reset_type method;
  2375. if (efx->state == STATE_RECOVERY) {
  2376. netif_dbg(efx, drv, efx->net_dev,
  2377. "recovering: skip scheduling %s reset\n",
  2378. RESET_TYPE(type));
  2379. return;
  2380. }
  2381. switch (type) {
  2382. case RESET_TYPE_INVISIBLE:
  2383. case RESET_TYPE_ALL:
  2384. case RESET_TYPE_RECOVER_OR_ALL:
  2385. case RESET_TYPE_WORLD:
  2386. case RESET_TYPE_DISABLE:
  2387. case RESET_TYPE_RECOVER_OR_DISABLE:
  2388. case RESET_TYPE_DATAPATH:
  2389. case RESET_TYPE_MC_BIST:
  2390. case RESET_TYPE_MCDI_TIMEOUT:
  2391. method = type;
  2392. netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
  2393. RESET_TYPE(method));
  2394. break;
  2395. default:
  2396. method = efx->type->map_reset_reason(type);
  2397. netif_dbg(efx, drv, efx->net_dev,
  2398. "scheduling %s reset for %s\n",
  2399. RESET_TYPE(method), RESET_TYPE(type));
  2400. break;
  2401. }
  2402. set_bit(method, &efx->reset_pending);
  2403. smp_mb(); /* ensure we change reset_pending before checking state */
  2404. /* If we're not READY then just leave the flags set as the cue
  2405. * to abort probing or reschedule the reset later.
  2406. */
  2407. if (ACCESS_ONCE(efx->state) != STATE_READY)
  2408. return;
  2409. /* efx_process_channel() will no longer read events once a
  2410. * reset is scheduled. So switch back to poll'd MCDI completions. */
  2411. efx_mcdi_mode_poll(efx);
  2412. queue_work(reset_workqueue, &efx->reset_work);
  2413. }
  2414. /**************************************************************************
  2415. *
  2416. * List of NICs we support
  2417. *
  2418. **************************************************************************/
  2419. /* PCI device ID table */
  2420. static const struct pci_device_id efx_pci_table[] = {
  2421. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
  2422. .driver_data = (unsigned long) &siena_a0_nic_type},
  2423. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
  2424. .driver_data = (unsigned long) &siena_a0_nic_type},
  2425. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
  2426. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2427. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */
  2428. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2429. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
  2430. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2431. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */
  2432. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2433. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */
  2434. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2435. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */
  2436. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2437. {0} /* end of list */
  2438. };
  2439. /**************************************************************************
  2440. *
  2441. * Dummy PHY/MAC operations
  2442. *
  2443. * Can be used for some unimplemented operations
  2444. * Needed so all function pointers are valid and do not have to be tested
  2445. * before use
  2446. *
  2447. **************************************************************************/
  2448. int efx_port_dummy_op_int(struct efx_nic *efx)
  2449. {
  2450. return 0;
  2451. }
  2452. void efx_port_dummy_op_void(struct efx_nic *efx) {}
  2453. static bool efx_port_dummy_op_poll(struct efx_nic *efx)
  2454. {
  2455. return false;
  2456. }
  2457. static const struct efx_phy_operations efx_dummy_phy_operations = {
  2458. .init = efx_port_dummy_op_int,
  2459. .reconfigure = efx_port_dummy_op_int,
  2460. .poll = efx_port_dummy_op_poll,
  2461. .fini = efx_port_dummy_op_void,
  2462. };
  2463. /**************************************************************************
  2464. *
  2465. * Data housekeeping
  2466. *
  2467. **************************************************************************/
  2468. /* This zeroes out and then fills in the invariants in a struct
  2469. * efx_nic (including all sub-structures).
  2470. */
  2471. static int efx_init_struct(struct efx_nic *efx,
  2472. struct pci_dev *pci_dev, struct net_device *net_dev)
  2473. {
  2474. int rc = -ENOMEM, i;
  2475. /* Initialise common structures */
  2476. INIT_LIST_HEAD(&efx->node);
  2477. INIT_LIST_HEAD(&efx->secondary_list);
  2478. spin_lock_init(&efx->biu_lock);
  2479. #ifdef CONFIG_SFC_MTD
  2480. INIT_LIST_HEAD(&efx->mtd_list);
  2481. #endif
  2482. INIT_WORK(&efx->reset_work, efx_reset_work);
  2483. INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
  2484. INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
  2485. efx->pci_dev = pci_dev;
  2486. efx->msg_enable = debug;
  2487. efx->state = STATE_UNINIT;
  2488. strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
  2489. efx->net_dev = net_dev;
  2490. efx->rx_prefix_size = efx->type->rx_prefix_size;
  2491. efx->rx_ip_align =
  2492. NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
  2493. efx->rx_packet_hash_offset =
  2494. efx->type->rx_hash_offset - efx->type->rx_prefix_size;
  2495. efx->rx_packet_ts_offset =
  2496. efx->type->rx_ts_offset - efx->type->rx_prefix_size;
  2497. spin_lock_init(&efx->stats_lock);
  2498. mutex_init(&efx->mac_lock);
  2499. efx->phy_op = &efx_dummy_phy_operations;
  2500. efx->mdio.dev = net_dev;
  2501. INIT_WORK(&efx->mac_work, efx_mac_work);
  2502. init_waitqueue_head(&efx->flush_wq);
  2503. for (i = 0; i < EFX_MAX_CHANNELS; i++) {
  2504. efx->channel[i] = efx_alloc_channel(efx, i, NULL);
  2505. if (!efx->channel[i])
  2506. goto fail;
  2507. efx->msi_context[i].efx = efx;
  2508. efx->msi_context[i].index = i;
  2509. }
  2510. /* Higher numbered interrupt modes are less capable! */
  2511. if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
  2512. efx->type->min_interrupt_mode)) {
  2513. rc = -EIO;
  2514. goto fail;
  2515. }
  2516. efx->interrupt_mode = max(efx->type->max_interrupt_mode,
  2517. interrupt_mode);
  2518. efx->interrupt_mode = min(efx->type->min_interrupt_mode,
  2519. interrupt_mode);
  2520. /* Would be good to use the net_dev name, but we're too early */
  2521. snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
  2522. pci_name(pci_dev));
  2523. efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
  2524. if (!efx->workqueue)
  2525. goto fail;
  2526. return 0;
  2527. fail:
  2528. efx_fini_struct(efx);
  2529. return rc;
  2530. }
  2531. static void efx_fini_struct(struct efx_nic *efx)
  2532. {
  2533. int i;
  2534. for (i = 0; i < EFX_MAX_CHANNELS; i++)
  2535. kfree(efx->channel[i]);
  2536. kfree(efx->vpd_sn);
  2537. if (efx->workqueue) {
  2538. destroy_workqueue(efx->workqueue);
  2539. efx->workqueue = NULL;
  2540. }
  2541. }
  2542. void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
  2543. {
  2544. u64 n_rx_nodesc_trunc = 0;
  2545. struct efx_channel *channel;
  2546. efx_for_each_channel(channel, efx)
  2547. n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
  2548. stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
  2549. stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
  2550. }
  2551. /**************************************************************************
  2552. *
  2553. * PCI interface
  2554. *
  2555. **************************************************************************/
  2556. /* Main body of final NIC shutdown code
  2557. * This is called only at module unload (or hotplug removal).
  2558. */
  2559. static void efx_pci_remove_main(struct efx_nic *efx)
  2560. {
  2561. /* Flush reset_work. It can no longer be scheduled since we
  2562. * are not READY.
  2563. */
  2564. BUG_ON(efx->state == STATE_READY);
  2565. cancel_work_sync(&efx->reset_work);
  2566. efx_disable_interrupts(efx);
  2567. efx_nic_fini_interrupt(efx);
  2568. efx_fini_port(efx);
  2569. efx->type->fini(efx);
  2570. efx_fini_napi(efx);
  2571. efx_remove_all(efx);
  2572. }
  2573. /* Final NIC shutdown
  2574. * This is called only at module unload (or hotplug removal). A PF can call
  2575. * this on its VFs to ensure they are unbound first.
  2576. */
  2577. static void efx_pci_remove(struct pci_dev *pci_dev)
  2578. {
  2579. struct efx_nic *efx;
  2580. efx = pci_get_drvdata(pci_dev);
  2581. if (!efx)
  2582. return;
  2583. /* Mark the NIC as fini, then stop the interface */
  2584. rtnl_lock();
  2585. efx_dissociate(efx);
  2586. dev_close(efx->net_dev);
  2587. efx_disable_interrupts(efx);
  2588. efx->state = STATE_UNINIT;
  2589. rtnl_unlock();
  2590. if (efx->type->sriov_fini)
  2591. efx->type->sriov_fini(efx);
  2592. efx_unregister_netdev(efx);
  2593. efx_mtd_remove(efx);
  2594. efx_pci_remove_main(efx);
  2595. efx_fini_io(efx);
  2596. netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
  2597. efx_fini_struct(efx);
  2598. free_netdev(efx->net_dev);
  2599. pci_disable_pcie_error_reporting(pci_dev);
  2600. };
  2601. /* NIC VPD information
  2602. * Called during probe to display the part number of the
  2603. * installed NIC. VPD is potentially very large but this should
  2604. * always appear within the first 512 bytes.
  2605. */
  2606. #define SFC_VPD_LEN 512
  2607. static void efx_probe_vpd_strings(struct efx_nic *efx)
  2608. {
  2609. struct pci_dev *dev = efx->pci_dev;
  2610. char vpd_data[SFC_VPD_LEN];
  2611. ssize_t vpd_size;
  2612. int ro_start, ro_size, i, j;
  2613. /* Get the vpd data from the device */
  2614. vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
  2615. if (vpd_size <= 0) {
  2616. netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
  2617. return;
  2618. }
  2619. /* Get the Read only section */
  2620. ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
  2621. if (ro_start < 0) {
  2622. netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
  2623. return;
  2624. }
  2625. ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
  2626. j = ro_size;
  2627. i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
  2628. if (i + j > vpd_size)
  2629. j = vpd_size - i;
  2630. /* Get the Part number */
  2631. i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
  2632. if (i < 0) {
  2633. netif_err(efx, drv, efx->net_dev, "Part number not found\n");
  2634. return;
  2635. }
  2636. j = pci_vpd_info_field_size(&vpd_data[i]);
  2637. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2638. if (i + j > vpd_size) {
  2639. netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
  2640. return;
  2641. }
  2642. netif_info(efx, drv, efx->net_dev,
  2643. "Part Number : %.*s\n", j, &vpd_data[i]);
  2644. i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
  2645. j = ro_size;
  2646. i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
  2647. if (i < 0) {
  2648. netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
  2649. return;
  2650. }
  2651. j = pci_vpd_info_field_size(&vpd_data[i]);
  2652. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2653. if (i + j > vpd_size) {
  2654. netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
  2655. return;
  2656. }
  2657. efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
  2658. if (!efx->vpd_sn)
  2659. return;
  2660. snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
  2661. }
  2662. /* Main body of NIC initialisation
  2663. * This is called at module load (or hotplug insertion, theoretically).
  2664. */
  2665. static int efx_pci_probe_main(struct efx_nic *efx)
  2666. {
  2667. int rc;
  2668. /* Do start-of-day initialisation */
  2669. rc = efx_probe_all(efx);
  2670. if (rc)
  2671. goto fail1;
  2672. efx_init_napi(efx);
  2673. rc = efx->type->init(efx);
  2674. if (rc) {
  2675. netif_err(efx, probe, efx->net_dev,
  2676. "failed to initialise NIC\n");
  2677. goto fail3;
  2678. }
  2679. rc = efx_init_port(efx);
  2680. if (rc) {
  2681. netif_err(efx, probe, efx->net_dev,
  2682. "failed to initialise port\n");
  2683. goto fail4;
  2684. }
  2685. rc = efx_nic_init_interrupt(efx);
  2686. if (rc)
  2687. goto fail5;
  2688. rc = efx_enable_interrupts(efx);
  2689. if (rc)
  2690. goto fail6;
  2691. return 0;
  2692. fail6:
  2693. efx_nic_fini_interrupt(efx);
  2694. fail5:
  2695. efx_fini_port(efx);
  2696. fail4:
  2697. efx->type->fini(efx);
  2698. fail3:
  2699. efx_fini_napi(efx);
  2700. efx_remove_all(efx);
  2701. fail1:
  2702. return rc;
  2703. }
  2704. static int efx_pci_probe_post_io(struct efx_nic *efx)
  2705. {
  2706. struct net_device *net_dev = efx->net_dev;
  2707. int rc = efx_pci_probe_main(efx);
  2708. if (rc)
  2709. return rc;
  2710. if (efx->type->sriov_init) {
  2711. rc = efx->type->sriov_init(efx);
  2712. if (rc)
  2713. netif_err(efx, probe, efx->net_dev,
  2714. "SR-IOV can't be enabled rc %d\n", rc);
  2715. }
  2716. /* Determine netdevice features */
  2717. net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
  2718. NETIF_F_TSO | NETIF_F_RXCSUM);
  2719. if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
  2720. net_dev->features |= NETIF_F_TSO6;
  2721. /* Check whether device supports TSO */
  2722. if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
  2723. net_dev->features &= ~NETIF_F_ALL_TSO;
  2724. /* Mask for features that also apply to VLAN devices */
  2725. net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
  2726. NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
  2727. NETIF_F_RXCSUM);
  2728. net_dev->hw_features = net_dev->features & ~efx->fixed_features;
  2729. /* Disable VLAN filtering by default. It may be enforced if
  2730. * the feature is fixed (i.e. VLAN filters are required to
  2731. * receive VLAN tagged packets due to vPort restrictions).
  2732. */
  2733. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  2734. net_dev->features |= efx->fixed_features;
  2735. rc = efx_register_netdev(efx);
  2736. if (!rc)
  2737. return 0;
  2738. efx_pci_remove_main(efx);
  2739. return rc;
  2740. }
  2741. /* NIC initialisation
  2742. *
  2743. * This is called at module load (or hotplug insertion,
  2744. * theoretically). It sets up PCI mappings, resets the NIC,
  2745. * sets up and registers the network devices with the kernel and hooks
  2746. * the interrupt service routine. It does not prepare the device for
  2747. * transmission; this is left to the first time one of the network
  2748. * interfaces is brought up (i.e. efx_net_open).
  2749. */
  2750. static int efx_pci_probe(struct pci_dev *pci_dev,
  2751. const struct pci_device_id *entry)
  2752. {
  2753. struct net_device *net_dev;
  2754. struct efx_nic *efx;
  2755. int rc;
  2756. /* Allocate and initialise a struct net_device and struct efx_nic */
  2757. net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
  2758. EFX_MAX_RX_QUEUES);
  2759. if (!net_dev)
  2760. return -ENOMEM;
  2761. efx = netdev_priv(net_dev);
  2762. efx->type = (const struct efx_nic_type *) entry->driver_data;
  2763. efx->fixed_features |= NETIF_F_HIGHDMA;
  2764. pci_set_drvdata(pci_dev, efx);
  2765. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  2766. rc = efx_init_struct(efx, pci_dev, net_dev);
  2767. if (rc)
  2768. goto fail1;
  2769. netif_info(efx, probe, efx->net_dev,
  2770. "Solarflare NIC detected\n");
  2771. if (!efx->type->is_vf)
  2772. efx_probe_vpd_strings(efx);
  2773. /* Set up basic I/O (BAR mappings etc) */
  2774. rc = efx_init_io(efx);
  2775. if (rc)
  2776. goto fail2;
  2777. rc = efx_pci_probe_post_io(efx);
  2778. if (rc) {
  2779. /* On failure, retry once immediately.
  2780. * If we aborted probe due to a scheduled reset, dismiss it.
  2781. */
  2782. efx->reset_pending = 0;
  2783. rc = efx_pci_probe_post_io(efx);
  2784. if (rc) {
  2785. /* On another failure, retry once more
  2786. * after a 50-305ms delay.
  2787. */
  2788. unsigned char r;
  2789. get_random_bytes(&r, 1);
  2790. msleep((unsigned int)r + 50);
  2791. efx->reset_pending = 0;
  2792. rc = efx_pci_probe_post_io(efx);
  2793. }
  2794. }
  2795. if (rc)
  2796. goto fail3;
  2797. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  2798. /* Try to create MTDs, but allow this to fail */
  2799. rtnl_lock();
  2800. rc = efx_mtd_probe(efx);
  2801. rtnl_unlock();
  2802. if (rc && rc != -EPERM)
  2803. netif_warn(efx, probe, efx->net_dev,
  2804. "failed to create MTDs (%d)\n", rc);
  2805. rc = pci_enable_pcie_error_reporting(pci_dev);
  2806. if (rc && rc != -EINVAL)
  2807. netif_notice(efx, probe, efx->net_dev,
  2808. "PCIE error reporting unavailable (%d).\n",
  2809. rc);
  2810. if (efx->type->udp_tnl_push_ports)
  2811. efx->type->udp_tnl_push_ports(efx);
  2812. return 0;
  2813. fail3:
  2814. efx_fini_io(efx);
  2815. fail2:
  2816. efx_fini_struct(efx);
  2817. fail1:
  2818. WARN_ON(rc > 0);
  2819. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  2820. free_netdev(net_dev);
  2821. return rc;
  2822. }
  2823. /* efx_pci_sriov_configure returns the actual number of Virtual Functions
  2824. * enabled on success
  2825. */
  2826. #ifdef CONFIG_SFC_SRIOV
  2827. static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
  2828. {
  2829. int rc;
  2830. struct efx_nic *efx = pci_get_drvdata(dev);
  2831. if (efx->type->sriov_configure) {
  2832. rc = efx->type->sriov_configure(efx, num_vfs);
  2833. if (rc)
  2834. return rc;
  2835. else
  2836. return num_vfs;
  2837. } else
  2838. return -EOPNOTSUPP;
  2839. }
  2840. #endif
  2841. static int efx_pm_freeze(struct device *dev)
  2842. {
  2843. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2844. rtnl_lock();
  2845. if (efx->state != STATE_DISABLED) {
  2846. efx->state = STATE_UNINIT;
  2847. efx_device_detach_sync(efx);
  2848. efx_stop_all(efx);
  2849. efx_disable_interrupts(efx);
  2850. }
  2851. rtnl_unlock();
  2852. return 0;
  2853. }
  2854. static int efx_pm_thaw(struct device *dev)
  2855. {
  2856. int rc;
  2857. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2858. rtnl_lock();
  2859. if (efx->state != STATE_DISABLED) {
  2860. rc = efx_enable_interrupts(efx);
  2861. if (rc)
  2862. goto fail;
  2863. mutex_lock(&efx->mac_lock);
  2864. efx->phy_op->reconfigure(efx);
  2865. mutex_unlock(&efx->mac_lock);
  2866. efx_start_all(efx);
  2867. efx_device_attach_if_not_resetting(efx);
  2868. efx->state = STATE_READY;
  2869. efx->type->resume_wol(efx);
  2870. }
  2871. rtnl_unlock();
  2872. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  2873. queue_work(reset_workqueue, &efx->reset_work);
  2874. return 0;
  2875. fail:
  2876. rtnl_unlock();
  2877. return rc;
  2878. }
  2879. static int efx_pm_poweroff(struct device *dev)
  2880. {
  2881. struct pci_dev *pci_dev = to_pci_dev(dev);
  2882. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2883. efx->type->fini(efx);
  2884. efx->reset_pending = 0;
  2885. pci_save_state(pci_dev);
  2886. return pci_set_power_state(pci_dev, PCI_D3hot);
  2887. }
  2888. /* Used for both resume and restore */
  2889. static int efx_pm_resume(struct device *dev)
  2890. {
  2891. struct pci_dev *pci_dev = to_pci_dev(dev);
  2892. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2893. int rc;
  2894. rc = pci_set_power_state(pci_dev, PCI_D0);
  2895. if (rc)
  2896. return rc;
  2897. pci_restore_state(pci_dev);
  2898. rc = pci_enable_device(pci_dev);
  2899. if (rc)
  2900. return rc;
  2901. pci_set_master(efx->pci_dev);
  2902. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  2903. if (rc)
  2904. return rc;
  2905. rc = efx->type->init(efx);
  2906. if (rc)
  2907. return rc;
  2908. rc = efx_pm_thaw(dev);
  2909. return rc;
  2910. }
  2911. static int efx_pm_suspend(struct device *dev)
  2912. {
  2913. int rc;
  2914. efx_pm_freeze(dev);
  2915. rc = efx_pm_poweroff(dev);
  2916. if (rc)
  2917. efx_pm_resume(dev);
  2918. return rc;
  2919. }
  2920. static const struct dev_pm_ops efx_pm_ops = {
  2921. .suspend = efx_pm_suspend,
  2922. .resume = efx_pm_resume,
  2923. .freeze = efx_pm_freeze,
  2924. .thaw = efx_pm_thaw,
  2925. .poweroff = efx_pm_poweroff,
  2926. .restore = efx_pm_resume,
  2927. };
  2928. /* A PCI error affecting this device was detected.
  2929. * At this point MMIO and DMA may be disabled.
  2930. * Stop the software path and request a slot reset.
  2931. */
  2932. static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
  2933. enum pci_channel_state state)
  2934. {
  2935. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2936. struct efx_nic *efx = pci_get_drvdata(pdev);
  2937. if (state == pci_channel_io_perm_failure)
  2938. return PCI_ERS_RESULT_DISCONNECT;
  2939. rtnl_lock();
  2940. if (efx->state != STATE_DISABLED) {
  2941. efx->state = STATE_RECOVERY;
  2942. efx->reset_pending = 0;
  2943. efx_device_detach_sync(efx);
  2944. efx_stop_all(efx);
  2945. efx_disable_interrupts(efx);
  2946. status = PCI_ERS_RESULT_NEED_RESET;
  2947. } else {
  2948. /* If the interface is disabled we don't want to do anything
  2949. * with it.
  2950. */
  2951. status = PCI_ERS_RESULT_RECOVERED;
  2952. }
  2953. rtnl_unlock();
  2954. pci_disable_device(pdev);
  2955. return status;
  2956. }
  2957. /* Fake a successful reset, which will be performed later in efx_io_resume. */
  2958. static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
  2959. {
  2960. struct efx_nic *efx = pci_get_drvdata(pdev);
  2961. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2962. int rc;
  2963. if (pci_enable_device(pdev)) {
  2964. netif_err(efx, hw, efx->net_dev,
  2965. "Cannot re-enable PCI device after reset.\n");
  2966. status = PCI_ERS_RESULT_DISCONNECT;
  2967. }
  2968. rc = pci_cleanup_aer_uncorrect_error_status(pdev);
  2969. if (rc) {
  2970. netif_err(efx, hw, efx->net_dev,
  2971. "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
  2972. /* Non-fatal error. Continue. */
  2973. }
  2974. return status;
  2975. }
  2976. /* Perform the actual reset and resume I/O operations. */
  2977. static void efx_io_resume(struct pci_dev *pdev)
  2978. {
  2979. struct efx_nic *efx = pci_get_drvdata(pdev);
  2980. int rc;
  2981. rtnl_lock();
  2982. if (efx->state == STATE_DISABLED)
  2983. goto out;
  2984. rc = efx_reset(efx, RESET_TYPE_ALL);
  2985. if (rc) {
  2986. netif_err(efx, hw, efx->net_dev,
  2987. "efx_reset failed after PCI error (%d)\n", rc);
  2988. } else {
  2989. efx->state = STATE_READY;
  2990. netif_dbg(efx, hw, efx->net_dev,
  2991. "Done resetting and resuming IO after PCI error.\n");
  2992. }
  2993. out:
  2994. rtnl_unlock();
  2995. }
  2996. /* For simplicity and reliability, we always require a slot reset and try to
  2997. * reset the hardware when a pci error affecting the device is detected.
  2998. * We leave both the link_reset and mmio_enabled callback unimplemented:
  2999. * with our request for slot reset the mmio_enabled callback will never be
  3000. * called, and the link_reset callback is not used by AER or EEH mechanisms.
  3001. */
  3002. static const struct pci_error_handlers efx_err_handlers = {
  3003. .error_detected = efx_io_error_detected,
  3004. .slot_reset = efx_io_slot_reset,
  3005. .resume = efx_io_resume,
  3006. };
  3007. static struct pci_driver efx_pci_driver = {
  3008. .name = KBUILD_MODNAME,
  3009. .id_table = efx_pci_table,
  3010. .probe = efx_pci_probe,
  3011. .remove = efx_pci_remove,
  3012. .driver.pm = &efx_pm_ops,
  3013. .err_handler = &efx_err_handlers,
  3014. #ifdef CONFIG_SFC_SRIOV
  3015. .sriov_configure = efx_pci_sriov_configure,
  3016. #endif
  3017. };
  3018. /**************************************************************************
  3019. *
  3020. * Kernel module interface
  3021. *
  3022. *************************************************************************/
  3023. module_param(interrupt_mode, uint, 0444);
  3024. MODULE_PARM_DESC(interrupt_mode,
  3025. "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
  3026. static int __init efx_init_module(void)
  3027. {
  3028. int rc;
  3029. printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
  3030. rc = register_netdevice_notifier(&efx_netdev_notifier);
  3031. if (rc)
  3032. goto err_notifier;
  3033. #ifdef CONFIG_SFC_SRIOV
  3034. rc = efx_init_sriov();
  3035. if (rc)
  3036. goto err_sriov;
  3037. #endif
  3038. reset_workqueue = create_singlethread_workqueue("sfc_reset");
  3039. if (!reset_workqueue) {
  3040. rc = -ENOMEM;
  3041. goto err_reset;
  3042. }
  3043. rc = pci_register_driver(&efx_pci_driver);
  3044. if (rc < 0)
  3045. goto err_pci;
  3046. return 0;
  3047. err_pci:
  3048. destroy_workqueue(reset_workqueue);
  3049. err_reset:
  3050. #ifdef CONFIG_SFC_SRIOV
  3051. efx_fini_sriov();
  3052. err_sriov:
  3053. #endif
  3054. unregister_netdevice_notifier(&efx_netdev_notifier);
  3055. err_notifier:
  3056. return rc;
  3057. }
  3058. static void __exit efx_exit_module(void)
  3059. {
  3060. printk(KERN_INFO "Solarflare NET driver unloading\n");
  3061. pci_unregister_driver(&efx_pci_driver);
  3062. destroy_workqueue(reset_workqueue);
  3063. #ifdef CONFIG_SFC_SRIOV
  3064. efx_fini_sriov();
  3065. #endif
  3066. unregister_netdevice_notifier(&efx_netdev_notifier);
  3067. }
  3068. module_init(efx_init_module);
  3069. module_exit(efx_exit_module);
  3070. MODULE_AUTHOR("Solarflare Communications and "
  3071. "Michael Brown <mbrown@fensystems.co.uk>");
  3072. MODULE_DESCRIPTION("Solarflare network driver");
  3073. MODULE_LICENSE("GPL");
  3074. MODULE_DEVICE_TABLE(pci, efx_pci_table);
  3075. MODULE_VERSION(EFX_DRIVER_VERSION);