efx.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682
  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 RSS is requested for the PF *and* VFs then we can't write RSS
  1159. * table entries that are inaccessible to VFs
  1160. */
  1161. #ifdef CONFIG_SFC_SRIOV
  1162. if (efx->type->sriov_wanted) {
  1163. if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
  1164. count > efx_vf_size(efx)) {
  1165. netif_warn(efx, probe, efx->net_dev,
  1166. "Reducing number of RSS channels from %u to %u for "
  1167. "VF support. Increase vf-msix-limit to use more "
  1168. "channels on the PF.\n",
  1169. count, efx_vf_size(efx));
  1170. count = efx_vf_size(efx);
  1171. }
  1172. }
  1173. #endif
  1174. return count;
  1175. }
  1176. /* Probe the number and type of interrupts we are able to obtain, and
  1177. * the resulting numbers of channels and RX queues.
  1178. */
  1179. static int efx_probe_interrupts(struct efx_nic *efx)
  1180. {
  1181. unsigned int extra_channels = 0;
  1182. unsigned int i, j;
  1183. int rc;
  1184. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
  1185. if (efx->extra_channel_type[i])
  1186. ++extra_channels;
  1187. if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
  1188. struct msix_entry xentries[EFX_MAX_CHANNELS];
  1189. unsigned int n_channels;
  1190. n_channels = efx_wanted_parallelism(efx);
  1191. if (efx_separate_tx_channels)
  1192. n_channels *= 2;
  1193. n_channels += extra_channels;
  1194. n_channels = min(n_channels, efx->max_channels);
  1195. for (i = 0; i < n_channels; i++)
  1196. xentries[i].entry = i;
  1197. rc = pci_enable_msix_range(efx->pci_dev,
  1198. xentries, 1, n_channels);
  1199. if (rc < 0) {
  1200. /* Fall back to single channel MSI */
  1201. netif_err(efx, drv, efx->net_dev,
  1202. "could not enable MSI-X\n");
  1203. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
  1204. efx->interrupt_mode = EFX_INT_MODE_MSI;
  1205. else
  1206. return rc;
  1207. } else if (rc < n_channels) {
  1208. netif_err(efx, drv, efx->net_dev,
  1209. "WARNING: Insufficient MSI-X vectors"
  1210. " available (%d < %u).\n", rc, n_channels);
  1211. netif_err(efx, drv, efx->net_dev,
  1212. "WARNING: Performance may be reduced.\n");
  1213. n_channels = rc;
  1214. }
  1215. if (rc > 0) {
  1216. efx->n_channels = n_channels;
  1217. if (n_channels > extra_channels)
  1218. n_channels -= extra_channels;
  1219. if (efx_separate_tx_channels) {
  1220. efx->n_tx_channels = min(max(n_channels / 2,
  1221. 1U),
  1222. efx->max_tx_channels);
  1223. efx->n_rx_channels = max(n_channels -
  1224. efx->n_tx_channels,
  1225. 1U);
  1226. } else {
  1227. efx->n_tx_channels = min(n_channels,
  1228. efx->max_tx_channels);
  1229. efx->n_rx_channels = n_channels;
  1230. }
  1231. for (i = 0; i < efx->n_channels; i++)
  1232. efx_get_channel(efx, i)->irq =
  1233. xentries[i].vector;
  1234. }
  1235. }
  1236. /* Try single interrupt MSI */
  1237. if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
  1238. efx->n_channels = 1;
  1239. efx->n_rx_channels = 1;
  1240. efx->n_tx_channels = 1;
  1241. rc = pci_enable_msi(efx->pci_dev);
  1242. if (rc == 0) {
  1243. efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
  1244. } else {
  1245. netif_err(efx, drv, efx->net_dev,
  1246. "could not enable MSI\n");
  1247. if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
  1248. efx->interrupt_mode = EFX_INT_MODE_LEGACY;
  1249. else
  1250. return rc;
  1251. }
  1252. }
  1253. /* Assume legacy interrupts */
  1254. if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
  1255. efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
  1256. efx->n_rx_channels = 1;
  1257. efx->n_tx_channels = 1;
  1258. efx->legacy_irq = efx->pci_dev->irq;
  1259. }
  1260. /* Assign extra channels if possible */
  1261. j = efx->n_channels;
  1262. for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
  1263. if (!efx->extra_channel_type[i])
  1264. continue;
  1265. if (efx->interrupt_mode != EFX_INT_MODE_MSIX ||
  1266. efx->n_channels <= extra_channels) {
  1267. efx->extra_channel_type[i]->handle_no_channel(efx);
  1268. } else {
  1269. --j;
  1270. efx_get_channel(efx, j)->type =
  1271. efx->extra_channel_type[i];
  1272. }
  1273. }
  1274. /* RSS might be usable on VFs even if it is disabled on the PF */
  1275. #ifdef CONFIG_SFC_SRIOV
  1276. if (efx->type->sriov_wanted) {
  1277. efx->rss_spread = ((efx->n_rx_channels > 1 ||
  1278. !efx->type->sriov_wanted(efx)) ?
  1279. efx->n_rx_channels : efx_vf_size(efx));
  1280. return 0;
  1281. }
  1282. #endif
  1283. efx->rss_spread = efx->n_rx_channels;
  1284. return 0;
  1285. }
  1286. static int efx_soft_enable_interrupts(struct efx_nic *efx)
  1287. {
  1288. struct efx_channel *channel, *end_channel;
  1289. int rc;
  1290. BUG_ON(efx->state == STATE_DISABLED);
  1291. efx->irq_soft_enabled = true;
  1292. smp_wmb();
  1293. efx_for_each_channel(channel, efx) {
  1294. if (!channel->type->keep_eventq) {
  1295. rc = efx_init_eventq(channel);
  1296. if (rc)
  1297. goto fail;
  1298. }
  1299. efx_start_eventq(channel);
  1300. }
  1301. efx_mcdi_mode_event(efx);
  1302. return 0;
  1303. fail:
  1304. end_channel = channel;
  1305. efx_for_each_channel(channel, efx) {
  1306. if (channel == end_channel)
  1307. break;
  1308. efx_stop_eventq(channel);
  1309. if (!channel->type->keep_eventq)
  1310. efx_fini_eventq(channel);
  1311. }
  1312. return rc;
  1313. }
  1314. static void efx_soft_disable_interrupts(struct efx_nic *efx)
  1315. {
  1316. struct efx_channel *channel;
  1317. if (efx->state == STATE_DISABLED)
  1318. return;
  1319. efx_mcdi_mode_poll(efx);
  1320. efx->irq_soft_enabled = false;
  1321. smp_wmb();
  1322. if (efx->legacy_irq)
  1323. synchronize_irq(efx->legacy_irq);
  1324. efx_for_each_channel(channel, efx) {
  1325. if (channel->irq)
  1326. synchronize_irq(channel->irq);
  1327. efx_stop_eventq(channel);
  1328. if (!channel->type->keep_eventq)
  1329. efx_fini_eventq(channel);
  1330. }
  1331. /* Flush the asynchronous MCDI request queue */
  1332. efx_mcdi_flush_async(efx);
  1333. }
  1334. static int efx_enable_interrupts(struct efx_nic *efx)
  1335. {
  1336. struct efx_channel *channel, *end_channel;
  1337. int rc;
  1338. BUG_ON(efx->state == STATE_DISABLED);
  1339. if (efx->eeh_disabled_legacy_irq) {
  1340. enable_irq(efx->legacy_irq);
  1341. efx->eeh_disabled_legacy_irq = false;
  1342. }
  1343. efx->type->irq_enable_master(efx);
  1344. efx_for_each_channel(channel, efx) {
  1345. if (channel->type->keep_eventq) {
  1346. rc = efx_init_eventq(channel);
  1347. if (rc)
  1348. goto fail;
  1349. }
  1350. }
  1351. rc = efx_soft_enable_interrupts(efx);
  1352. if (rc)
  1353. goto fail;
  1354. return 0;
  1355. fail:
  1356. end_channel = channel;
  1357. efx_for_each_channel(channel, efx) {
  1358. if (channel == end_channel)
  1359. break;
  1360. if (channel->type->keep_eventq)
  1361. efx_fini_eventq(channel);
  1362. }
  1363. efx->type->irq_disable_non_ev(efx);
  1364. return rc;
  1365. }
  1366. static void efx_disable_interrupts(struct efx_nic *efx)
  1367. {
  1368. struct efx_channel *channel;
  1369. efx_soft_disable_interrupts(efx);
  1370. efx_for_each_channel(channel, efx) {
  1371. if (channel->type->keep_eventq)
  1372. efx_fini_eventq(channel);
  1373. }
  1374. efx->type->irq_disable_non_ev(efx);
  1375. }
  1376. static void efx_remove_interrupts(struct efx_nic *efx)
  1377. {
  1378. struct efx_channel *channel;
  1379. /* Remove MSI/MSI-X interrupts */
  1380. efx_for_each_channel(channel, efx)
  1381. channel->irq = 0;
  1382. pci_disable_msi(efx->pci_dev);
  1383. pci_disable_msix(efx->pci_dev);
  1384. /* Remove legacy interrupt */
  1385. efx->legacy_irq = 0;
  1386. }
  1387. static void efx_set_channels(struct efx_nic *efx)
  1388. {
  1389. struct efx_channel *channel;
  1390. struct efx_tx_queue *tx_queue;
  1391. efx->tx_channel_offset =
  1392. efx_separate_tx_channels ?
  1393. efx->n_channels - efx->n_tx_channels : 0;
  1394. /* We need to mark which channels really have RX and TX
  1395. * queues, and adjust the TX queue numbers if we have separate
  1396. * RX-only and TX-only channels.
  1397. */
  1398. efx_for_each_channel(channel, efx) {
  1399. if (channel->channel < efx->n_rx_channels)
  1400. channel->rx_queue.core_index = channel->channel;
  1401. else
  1402. channel->rx_queue.core_index = -1;
  1403. efx_for_each_channel_tx_queue(tx_queue, channel)
  1404. tx_queue->queue -= (efx->tx_channel_offset *
  1405. EFX_TXQ_TYPES);
  1406. }
  1407. }
  1408. static int efx_probe_nic(struct efx_nic *efx)
  1409. {
  1410. int rc;
  1411. netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
  1412. /* Carry out hardware-type specific initialisation */
  1413. rc = efx->type->probe(efx);
  1414. if (rc)
  1415. return rc;
  1416. do {
  1417. if (!efx->max_channels || !efx->max_tx_channels) {
  1418. netif_err(efx, drv, efx->net_dev,
  1419. "Insufficient resources to allocate"
  1420. " any channels\n");
  1421. rc = -ENOSPC;
  1422. goto fail1;
  1423. }
  1424. /* Determine the number of channels and queues by trying
  1425. * to hook in MSI-X interrupts.
  1426. */
  1427. rc = efx_probe_interrupts(efx);
  1428. if (rc)
  1429. goto fail1;
  1430. efx_set_channels(efx);
  1431. /* dimension_resources can fail with EAGAIN */
  1432. rc = efx->type->dimension_resources(efx);
  1433. if (rc != 0 && rc != -EAGAIN)
  1434. goto fail2;
  1435. if (rc == -EAGAIN)
  1436. /* try again with new max_channels */
  1437. efx_remove_interrupts(efx);
  1438. } while (rc == -EAGAIN);
  1439. if (efx->n_channels > 1)
  1440. netdev_rss_key_fill(&efx->rx_hash_key,
  1441. sizeof(efx->rx_hash_key));
  1442. efx_set_default_rx_indir_table(efx);
  1443. netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
  1444. netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
  1445. /* Initialise the interrupt moderation settings */
  1446. efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
  1447. efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
  1448. true);
  1449. return 0;
  1450. fail2:
  1451. efx_remove_interrupts(efx);
  1452. fail1:
  1453. efx->type->remove(efx);
  1454. return rc;
  1455. }
  1456. static void efx_remove_nic(struct efx_nic *efx)
  1457. {
  1458. netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
  1459. efx_remove_interrupts(efx);
  1460. efx->type->remove(efx);
  1461. }
  1462. static int efx_probe_filters(struct efx_nic *efx)
  1463. {
  1464. int rc;
  1465. spin_lock_init(&efx->filter_lock);
  1466. init_rwsem(&efx->filter_sem);
  1467. mutex_lock(&efx->mac_lock);
  1468. down_write(&efx->filter_sem);
  1469. rc = efx->type->filter_table_probe(efx);
  1470. if (rc)
  1471. goto out_unlock;
  1472. #ifdef CONFIG_RFS_ACCEL
  1473. if (efx->type->offload_features & NETIF_F_NTUPLE) {
  1474. struct efx_channel *channel;
  1475. int i, success = 1;
  1476. efx_for_each_channel(channel, efx) {
  1477. channel->rps_flow_id =
  1478. kcalloc(efx->type->max_rx_ip_filters,
  1479. sizeof(*channel->rps_flow_id),
  1480. GFP_KERNEL);
  1481. if (!channel->rps_flow_id)
  1482. success = 0;
  1483. else
  1484. for (i = 0;
  1485. i < efx->type->max_rx_ip_filters;
  1486. ++i)
  1487. channel->rps_flow_id[i] =
  1488. RPS_FLOW_ID_INVALID;
  1489. }
  1490. if (!success) {
  1491. efx_for_each_channel(channel, efx)
  1492. kfree(channel->rps_flow_id);
  1493. efx->type->filter_table_remove(efx);
  1494. rc = -ENOMEM;
  1495. goto out_unlock;
  1496. }
  1497. efx->rps_expire_index = efx->rps_expire_channel = 0;
  1498. }
  1499. #endif
  1500. out_unlock:
  1501. up_write(&efx->filter_sem);
  1502. mutex_unlock(&efx->mac_lock);
  1503. return rc;
  1504. }
  1505. static void efx_remove_filters(struct efx_nic *efx)
  1506. {
  1507. #ifdef CONFIG_RFS_ACCEL
  1508. struct efx_channel *channel;
  1509. efx_for_each_channel(channel, efx)
  1510. kfree(channel->rps_flow_id);
  1511. #endif
  1512. down_write(&efx->filter_sem);
  1513. efx->type->filter_table_remove(efx);
  1514. up_write(&efx->filter_sem);
  1515. }
  1516. static void efx_restore_filters(struct efx_nic *efx)
  1517. {
  1518. down_read(&efx->filter_sem);
  1519. efx->type->filter_table_restore(efx);
  1520. up_read(&efx->filter_sem);
  1521. }
  1522. /**************************************************************************
  1523. *
  1524. * NIC startup/shutdown
  1525. *
  1526. *************************************************************************/
  1527. static int efx_probe_all(struct efx_nic *efx)
  1528. {
  1529. int rc;
  1530. rc = efx_probe_nic(efx);
  1531. if (rc) {
  1532. netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
  1533. goto fail1;
  1534. }
  1535. rc = efx_probe_port(efx);
  1536. if (rc) {
  1537. netif_err(efx, probe, efx->net_dev, "failed to create port\n");
  1538. goto fail2;
  1539. }
  1540. BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
  1541. if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
  1542. rc = -EINVAL;
  1543. goto fail3;
  1544. }
  1545. efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
  1546. #ifdef CONFIG_SFC_SRIOV
  1547. rc = efx->type->vswitching_probe(efx);
  1548. if (rc) /* not fatal; the PF will still work fine */
  1549. netif_warn(efx, probe, efx->net_dev,
  1550. "failed to setup vswitching rc=%d;"
  1551. " VFs may not function\n", rc);
  1552. #endif
  1553. rc = efx_probe_filters(efx);
  1554. if (rc) {
  1555. netif_err(efx, probe, efx->net_dev,
  1556. "failed to create filter tables\n");
  1557. goto fail4;
  1558. }
  1559. rc = efx_probe_channels(efx);
  1560. if (rc)
  1561. goto fail5;
  1562. return 0;
  1563. fail5:
  1564. efx_remove_filters(efx);
  1565. fail4:
  1566. #ifdef CONFIG_SFC_SRIOV
  1567. efx->type->vswitching_remove(efx);
  1568. #endif
  1569. fail3:
  1570. efx_remove_port(efx);
  1571. fail2:
  1572. efx_remove_nic(efx);
  1573. fail1:
  1574. return rc;
  1575. }
  1576. /* If the interface is supposed to be running but is not, start
  1577. * the hardware and software data path, regular activity for the port
  1578. * (MAC statistics, link polling, etc.) and schedule the port to be
  1579. * reconfigured. Interrupts must already be enabled. This function
  1580. * is safe to call multiple times, so long as the NIC is not disabled.
  1581. * Requires the RTNL lock.
  1582. */
  1583. static void efx_start_all(struct efx_nic *efx)
  1584. {
  1585. EFX_ASSERT_RESET_SERIALISED(efx);
  1586. BUG_ON(efx->state == STATE_DISABLED);
  1587. /* Check that it is appropriate to restart the interface. All
  1588. * of these flags are safe to read under just the rtnl lock */
  1589. if (efx->port_enabled || !netif_running(efx->net_dev) ||
  1590. efx->reset_pending)
  1591. return;
  1592. efx_start_port(efx);
  1593. efx_start_datapath(efx);
  1594. /* Start the hardware monitor if there is one */
  1595. if (efx->type->monitor != NULL)
  1596. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1597. efx_monitor_interval);
  1598. /* Link state detection is normally event-driven; we have
  1599. * to poll now because we could have missed a change
  1600. */
  1601. mutex_lock(&efx->mac_lock);
  1602. if (efx->phy_op->poll(efx))
  1603. efx_link_status_changed(efx);
  1604. mutex_unlock(&efx->mac_lock);
  1605. efx->type->start_stats(efx);
  1606. efx->type->pull_stats(efx);
  1607. spin_lock_bh(&efx->stats_lock);
  1608. efx->type->update_stats(efx, NULL, NULL);
  1609. spin_unlock_bh(&efx->stats_lock);
  1610. }
  1611. /* Quiesce the hardware and software data path, and regular activity
  1612. * for the port without bringing the link down. Safe to call multiple
  1613. * times with the NIC in almost any state, but interrupts should be
  1614. * enabled. Requires the RTNL lock.
  1615. */
  1616. static void efx_stop_all(struct efx_nic *efx)
  1617. {
  1618. EFX_ASSERT_RESET_SERIALISED(efx);
  1619. /* port_enabled can be read safely under the rtnl lock */
  1620. if (!efx->port_enabled)
  1621. return;
  1622. /* update stats before we go down so we can accurately count
  1623. * rx_nodesc_drops
  1624. */
  1625. efx->type->pull_stats(efx);
  1626. spin_lock_bh(&efx->stats_lock);
  1627. efx->type->update_stats(efx, NULL, NULL);
  1628. spin_unlock_bh(&efx->stats_lock);
  1629. efx->type->stop_stats(efx);
  1630. efx_stop_port(efx);
  1631. /* Stop the kernel transmit interface. This is only valid if
  1632. * the device is stopped or detached; otherwise the watchdog
  1633. * may fire immediately.
  1634. */
  1635. WARN_ON(netif_running(efx->net_dev) &&
  1636. netif_device_present(efx->net_dev));
  1637. netif_tx_disable(efx->net_dev);
  1638. efx_stop_datapath(efx);
  1639. }
  1640. static void efx_remove_all(struct efx_nic *efx)
  1641. {
  1642. efx_remove_channels(efx);
  1643. efx_remove_filters(efx);
  1644. #ifdef CONFIG_SFC_SRIOV
  1645. efx->type->vswitching_remove(efx);
  1646. #endif
  1647. efx_remove_port(efx);
  1648. efx_remove_nic(efx);
  1649. }
  1650. /**************************************************************************
  1651. *
  1652. * Interrupt moderation
  1653. *
  1654. **************************************************************************/
  1655. unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
  1656. {
  1657. if (usecs == 0)
  1658. return 0;
  1659. if (usecs * 1000 < efx->timer_quantum_ns)
  1660. return 1; /* never round down to 0 */
  1661. return usecs * 1000 / efx->timer_quantum_ns;
  1662. }
  1663. unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
  1664. {
  1665. /* We must round up when converting ticks to microseconds
  1666. * because we round down when converting the other way.
  1667. */
  1668. return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
  1669. }
  1670. /* Set interrupt moderation parameters */
  1671. int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
  1672. unsigned int rx_usecs, bool rx_adaptive,
  1673. bool rx_may_override_tx)
  1674. {
  1675. struct efx_channel *channel;
  1676. unsigned int timer_max_us;
  1677. EFX_ASSERT_RESET_SERIALISED(efx);
  1678. timer_max_us = efx->timer_max_ns / 1000;
  1679. if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
  1680. return -EINVAL;
  1681. if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
  1682. !rx_may_override_tx) {
  1683. netif_err(efx, drv, efx->net_dev, "Channels are shared. "
  1684. "RX and TX IRQ moderation must be equal\n");
  1685. return -EINVAL;
  1686. }
  1687. efx->irq_rx_adaptive = rx_adaptive;
  1688. efx->irq_rx_moderation_us = rx_usecs;
  1689. efx_for_each_channel(channel, efx) {
  1690. if (efx_channel_has_rx_queue(channel))
  1691. channel->irq_moderation_us = rx_usecs;
  1692. else if (efx_channel_has_tx_queues(channel))
  1693. channel->irq_moderation_us = tx_usecs;
  1694. }
  1695. return 0;
  1696. }
  1697. void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
  1698. unsigned int *rx_usecs, bool *rx_adaptive)
  1699. {
  1700. *rx_adaptive = efx->irq_rx_adaptive;
  1701. *rx_usecs = efx->irq_rx_moderation_us;
  1702. /* If channels are shared between RX and TX, so is IRQ
  1703. * moderation. Otherwise, IRQ moderation is the same for all
  1704. * TX channels and is not adaptive.
  1705. */
  1706. if (efx->tx_channel_offset == 0) {
  1707. *tx_usecs = *rx_usecs;
  1708. } else {
  1709. struct efx_channel *tx_channel;
  1710. tx_channel = efx->channel[efx->tx_channel_offset];
  1711. *tx_usecs = tx_channel->irq_moderation_us;
  1712. }
  1713. }
  1714. /**************************************************************************
  1715. *
  1716. * Hardware monitor
  1717. *
  1718. **************************************************************************/
  1719. /* Run periodically off the general workqueue */
  1720. static void efx_monitor(struct work_struct *data)
  1721. {
  1722. struct efx_nic *efx = container_of(data, struct efx_nic,
  1723. monitor_work.work);
  1724. netif_vdbg(efx, timer, efx->net_dev,
  1725. "hardware monitor executing on CPU %d\n",
  1726. raw_smp_processor_id());
  1727. BUG_ON(efx->type->monitor == NULL);
  1728. /* If the mac_lock is already held then it is likely a port
  1729. * reconfiguration is already in place, which will likely do
  1730. * most of the work of monitor() anyway. */
  1731. if (mutex_trylock(&efx->mac_lock)) {
  1732. if (efx->port_enabled)
  1733. efx->type->monitor(efx);
  1734. mutex_unlock(&efx->mac_lock);
  1735. }
  1736. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1737. efx_monitor_interval);
  1738. }
  1739. /**************************************************************************
  1740. *
  1741. * ioctls
  1742. *
  1743. *************************************************************************/
  1744. /* Net device ioctl
  1745. * Context: process, rtnl_lock() held.
  1746. */
  1747. static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
  1748. {
  1749. struct efx_nic *efx = netdev_priv(net_dev);
  1750. struct mii_ioctl_data *data = if_mii(ifr);
  1751. if (cmd == SIOCSHWTSTAMP)
  1752. return efx_ptp_set_ts_config(efx, ifr);
  1753. if (cmd == SIOCGHWTSTAMP)
  1754. return efx_ptp_get_ts_config(efx, ifr);
  1755. /* Convert phy_id from older PRTAD/DEVAD format */
  1756. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  1757. (data->phy_id & 0xfc00) == 0x0400)
  1758. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  1759. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  1760. }
  1761. /**************************************************************************
  1762. *
  1763. * NAPI interface
  1764. *
  1765. **************************************************************************/
  1766. static void efx_init_napi_channel(struct efx_channel *channel)
  1767. {
  1768. struct efx_nic *efx = channel->efx;
  1769. channel->napi_dev = efx->net_dev;
  1770. netif_napi_add(channel->napi_dev, &channel->napi_str,
  1771. efx_poll, napi_weight);
  1772. }
  1773. static void efx_init_napi(struct efx_nic *efx)
  1774. {
  1775. struct efx_channel *channel;
  1776. efx_for_each_channel(channel, efx)
  1777. efx_init_napi_channel(channel);
  1778. }
  1779. static void efx_fini_napi_channel(struct efx_channel *channel)
  1780. {
  1781. if (channel->napi_dev)
  1782. netif_napi_del(&channel->napi_str);
  1783. channel->napi_dev = NULL;
  1784. }
  1785. static void efx_fini_napi(struct efx_nic *efx)
  1786. {
  1787. struct efx_channel *channel;
  1788. efx_for_each_channel(channel, efx)
  1789. efx_fini_napi_channel(channel);
  1790. }
  1791. /**************************************************************************
  1792. *
  1793. * Kernel netpoll interface
  1794. *
  1795. *************************************************************************/
  1796. #ifdef CONFIG_NET_POLL_CONTROLLER
  1797. /* Although in the common case interrupts will be disabled, this is not
  1798. * guaranteed. However, all our work happens inside the NAPI callback,
  1799. * so no locking is required.
  1800. */
  1801. static void efx_netpoll(struct net_device *net_dev)
  1802. {
  1803. struct efx_nic *efx = netdev_priv(net_dev);
  1804. struct efx_channel *channel;
  1805. efx_for_each_channel(channel, efx)
  1806. efx_schedule_channel(channel);
  1807. }
  1808. #endif
  1809. /**************************************************************************
  1810. *
  1811. * Kernel net device interface
  1812. *
  1813. *************************************************************************/
  1814. /* Context: process, rtnl_lock() held. */
  1815. int efx_net_open(struct net_device *net_dev)
  1816. {
  1817. struct efx_nic *efx = netdev_priv(net_dev);
  1818. int rc;
  1819. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  1820. raw_smp_processor_id());
  1821. rc = efx_check_disabled(efx);
  1822. if (rc)
  1823. return rc;
  1824. if (efx->phy_mode & PHY_MODE_SPECIAL)
  1825. return -EBUSY;
  1826. if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
  1827. return -EIO;
  1828. /* Notify the kernel of the link state polled during driver load,
  1829. * before the monitor starts running */
  1830. efx_link_status_changed(efx);
  1831. efx_start_all(efx);
  1832. if (efx->state == STATE_DISABLED || efx->reset_pending)
  1833. netif_device_detach(efx->net_dev);
  1834. efx_selftest_async_start(efx);
  1835. return 0;
  1836. }
  1837. /* Context: process, rtnl_lock() held.
  1838. * Note that the kernel will ignore our return code; this method
  1839. * should really be a void.
  1840. */
  1841. int efx_net_stop(struct net_device *net_dev)
  1842. {
  1843. struct efx_nic *efx = netdev_priv(net_dev);
  1844. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  1845. raw_smp_processor_id());
  1846. /* Stop the device and flush all the channels */
  1847. efx_stop_all(efx);
  1848. return 0;
  1849. }
  1850. /* Context: process, dev_base_lock or RTNL held, non-blocking. */
  1851. static void efx_net_stats(struct net_device *net_dev,
  1852. struct rtnl_link_stats64 *stats)
  1853. {
  1854. struct efx_nic *efx = netdev_priv(net_dev);
  1855. spin_lock_bh(&efx->stats_lock);
  1856. efx->type->update_stats(efx, NULL, stats);
  1857. spin_unlock_bh(&efx->stats_lock);
  1858. }
  1859. /* Context: netif_tx_lock held, BHs disabled. */
  1860. static void efx_watchdog(struct net_device *net_dev)
  1861. {
  1862. struct efx_nic *efx = netdev_priv(net_dev);
  1863. netif_err(efx, tx_err, efx->net_dev,
  1864. "TX stuck with port_enabled=%d: resetting channels\n",
  1865. efx->port_enabled);
  1866. efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
  1867. }
  1868. /* Context: process, rtnl_lock() held. */
  1869. static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
  1870. {
  1871. struct efx_nic *efx = netdev_priv(net_dev);
  1872. int rc;
  1873. rc = efx_check_disabled(efx);
  1874. if (rc)
  1875. return rc;
  1876. netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
  1877. efx_device_detach_sync(efx);
  1878. efx_stop_all(efx);
  1879. mutex_lock(&efx->mac_lock);
  1880. net_dev->mtu = new_mtu;
  1881. efx_mac_reconfigure(efx);
  1882. mutex_unlock(&efx->mac_lock);
  1883. efx_start_all(efx);
  1884. efx_device_attach_if_not_resetting(efx);
  1885. return 0;
  1886. }
  1887. static int efx_set_mac_address(struct net_device *net_dev, void *data)
  1888. {
  1889. struct efx_nic *efx = netdev_priv(net_dev);
  1890. struct sockaddr *addr = data;
  1891. u8 *new_addr = addr->sa_data;
  1892. u8 old_addr[6];
  1893. int rc;
  1894. if (!is_valid_ether_addr(new_addr)) {
  1895. netif_err(efx, drv, efx->net_dev,
  1896. "invalid ethernet MAC address requested: %pM\n",
  1897. new_addr);
  1898. return -EADDRNOTAVAIL;
  1899. }
  1900. /* save old address */
  1901. ether_addr_copy(old_addr, net_dev->dev_addr);
  1902. ether_addr_copy(net_dev->dev_addr, new_addr);
  1903. if (efx->type->set_mac_address) {
  1904. rc = efx->type->set_mac_address(efx);
  1905. if (rc) {
  1906. ether_addr_copy(net_dev->dev_addr, old_addr);
  1907. return rc;
  1908. }
  1909. }
  1910. /* Reconfigure the MAC */
  1911. mutex_lock(&efx->mac_lock);
  1912. efx_mac_reconfigure(efx);
  1913. mutex_unlock(&efx->mac_lock);
  1914. return 0;
  1915. }
  1916. /* Context: netif_addr_lock held, BHs disabled. */
  1917. static void efx_set_rx_mode(struct net_device *net_dev)
  1918. {
  1919. struct efx_nic *efx = netdev_priv(net_dev);
  1920. if (efx->port_enabled)
  1921. queue_work(efx->workqueue, &efx->mac_work);
  1922. /* Otherwise efx_start_port() will do this */
  1923. }
  1924. static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
  1925. {
  1926. struct efx_nic *efx = netdev_priv(net_dev);
  1927. int rc;
  1928. /* If disabling RX n-tuple filtering, clear existing filters */
  1929. if (net_dev->features & ~data & NETIF_F_NTUPLE) {
  1930. rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
  1931. if (rc)
  1932. return rc;
  1933. }
  1934. /* If Rx VLAN filter is changed, update filters via mac_reconfigure */
  1935. if ((net_dev->features ^ data) & NETIF_F_HW_VLAN_CTAG_FILTER) {
  1936. /* efx_set_rx_mode() will schedule MAC work to update filters
  1937. * when a new features are finally set in net_dev.
  1938. */
  1939. efx_set_rx_mode(net_dev);
  1940. }
  1941. return 0;
  1942. }
  1943. static int efx_get_phys_port_id(struct net_device *net_dev,
  1944. struct netdev_phys_item_id *ppid)
  1945. {
  1946. struct efx_nic *efx = netdev_priv(net_dev);
  1947. if (efx->type->get_phys_port_id)
  1948. return efx->type->get_phys_port_id(efx, ppid);
  1949. else
  1950. return -EOPNOTSUPP;
  1951. }
  1952. static int efx_get_phys_port_name(struct net_device *net_dev,
  1953. char *name, size_t len)
  1954. {
  1955. struct efx_nic *efx = netdev_priv(net_dev);
  1956. if (snprintf(name, len, "p%u", efx->port_num) >= len)
  1957. return -EINVAL;
  1958. return 0;
  1959. }
  1960. static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  1961. {
  1962. struct efx_nic *efx = netdev_priv(net_dev);
  1963. if (efx->type->vlan_rx_add_vid)
  1964. return efx->type->vlan_rx_add_vid(efx, proto, vid);
  1965. else
  1966. return -EOPNOTSUPP;
  1967. }
  1968. static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  1969. {
  1970. struct efx_nic *efx = netdev_priv(net_dev);
  1971. if (efx->type->vlan_rx_kill_vid)
  1972. return efx->type->vlan_rx_kill_vid(efx, proto, vid);
  1973. else
  1974. return -EOPNOTSUPP;
  1975. }
  1976. static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
  1977. {
  1978. switch (in) {
  1979. case UDP_TUNNEL_TYPE_VXLAN:
  1980. return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
  1981. case UDP_TUNNEL_TYPE_GENEVE:
  1982. return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
  1983. default:
  1984. return -1;
  1985. }
  1986. }
  1987. static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
  1988. {
  1989. struct efx_nic *efx = netdev_priv(dev);
  1990. struct efx_udp_tunnel tnl;
  1991. int efx_tunnel_type;
  1992. efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
  1993. if (efx_tunnel_type < 0)
  1994. return;
  1995. tnl.type = (u16)efx_tunnel_type;
  1996. tnl.port = ti->port;
  1997. if (efx->type->udp_tnl_add_port)
  1998. (void)efx->type->udp_tnl_add_port(efx, tnl);
  1999. }
  2000. static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
  2001. {
  2002. struct efx_nic *efx = netdev_priv(dev);
  2003. struct efx_udp_tunnel tnl;
  2004. int efx_tunnel_type;
  2005. efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
  2006. if (efx_tunnel_type < 0)
  2007. return;
  2008. tnl.type = (u16)efx_tunnel_type;
  2009. tnl.port = ti->port;
  2010. if (efx->type->udp_tnl_del_port)
  2011. (void)efx->type->udp_tnl_del_port(efx, tnl);
  2012. }
  2013. static const struct net_device_ops efx_netdev_ops = {
  2014. .ndo_open = efx_net_open,
  2015. .ndo_stop = efx_net_stop,
  2016. .ndo_get_stats64 = efx_net_stats,
  2017. .ndo_tx_timeout = efx_watchdog,
  2018. .ndo_start_xmit = efx_hard_start_xmit,
  2019. .ndo_validate_addr = eth_validate_addr,
  2020. .ndo_do_ioctl = efx_ioctl,
  2021. .ndo_change_mtu = efx_change_mtu,
  2022. .ndo_set_mac_address = efx_set_mac_address,
  2023. .ndo_set_rx_mode = efx_set_rx_mode,
  2024. .ndo_set_features = efx_set_features,
  2025. .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
  2026. .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
  2027. #ifdef CONFIG_SFC_SRIOV
  2028. .ndo_set_vf_mac = efx_sriov_set_vf_mac,
  2029. .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
  2030. .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
  2031. .ndo_get_vf_config = efx_sriov_get_vf_config,
  2032. .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
  2033. #endif
  2034. .ndo_get_phys_port_id = efx_get_phys_port_id,
  2035. .ndo_get_phys_port_name = efx_get_phys_port_name,
  2036. #ifdef CONFIG_NET_POLL_CONTROLLER
  2037. .ndo_poll_controller = efx_netpoll,
  2038. #endif
  2039. .ndo_setup_tc = efx_setup_tc,
  2040. #ifdef CONFIG_RFS_ACCEL
  2041. .ndo_rx_flow_steer = efx_filter_rfs,
  2042. #endif
  2043. .ndo_udp_tunnel_add = efx_udp_tunnel_add,
  2044. .ndo_udp_tunnel_del = efx_udp_tunnel_del,
  2045. };
  2046. static void efx_update_name(struct efx_nic *efx)
  2047. {
  2048. strcpy(efx->name, efx->net_dev->name);
  2049. efx_mtd_rename(efx);
  2050. efx_set_channel_names(efx);
  2051. }
  2052. static int efx_netdev_event(struct notifier_block *this,
  2053. unsigned long event, void *ptr)
  2054. {
  2055. struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
  2056. if ((net_dev->netdev_ops == &efx_netdev_ops) &&
  2057. event == NETDEV_CHANGENAME)
  2058. efx_update_name(netdev_priv(net_dev));
  2059. return NOTIFY_DONE;
  2060. }
  2061. static struct notifier_block efx_netdev_notifier = {
  2062. .notifier_call = efx_netdev_event,
  2063. };
  2064. static ssize_t
  2065. show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
  2066. {
  2067. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2068. return sprintf(buf, "%d\n", efx->phy_type);
  2069. }
  2070. static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
  2071. #ifdef CONFIG_SFC_MCDI_LOGGING
  2072. static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
  2073. char *buf)
  2074. {
  2075. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2076. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  2077. return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
  2078. }
  2079. static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
  2080. const char *buf, size_t count)
  2081. {
  2082. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2083. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  2084. bool enable = count > 0 && *buf != '0';
  2085. mcdi->logging_enabled = enable;
  2086. return count;
  2087. }
  2088. static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
  2089. #endif
  2090. static int efx_register_netdev(struct efx_nic *efx)
  2091. {
  2092. struct net_device *net_dev = efx->net_dev;
  2093. struct efx_channel *channel;
  2094. int rc;
  2095. net_dev->watchdog_timeo = 5 * HZ;
  2096. net_dev->irq = efx->pci_dev->irq;
  2097. net_dev->netdev_ops = &efx_netdev_ops;
  2098. if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
  2099. net_dev->priv_flags |= IFF_UNICAST_FLT;
  2100. net_dev->ethtool_ops = &efx_ethtool_ops;
  2101. net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
  2102. net_dev->min_mtu = EFX_MIN_MTU;
  2103. net_dev->max_mtu = EFX_MAX_MTU;
  2104. rtnl_lock();
  2105. /* Enable resets to be scheduled and check whether any were
  2106. * already requested. If so, the NIC is probably hosed so we
  2107. * abort.
  2108. */
  2109. efx->state = STATE_READY;
  2110. smp_mb(); /* ensure we change state before checking reset_pending */
  2111. if (efx->reset_pending) {
  2112. netif_err(efx, probe, efx->net_dev,
  2113. "aborting probe due to scheduled reset\n");
  2114. rc = -EIO;
  2115. goto fail_locked;
  2116. }
  2117. rc = dev_alloc_name(net_dev, net_dev->name);
  2118. if (rc < 0)
  2119. goto fail_locked;
  2120. efx_update_name(efx);
  2121. /* Always start with carrier off; PHY events will detect the link */
  2122. netif_carrier_off(net_dev);
  2123. rc = register_netdevice(net_dev);
  2124. if (rc)
  2125. goto fail_locked;
  2126. efx_for_each_channel(channel, efx) {
  2127. struct efx_tx_queue *tx_queue;
  2128. efx_for_each_channel_tx_queue(tx_queue, channel)
  2129. efx_init_tx_queue_core_txq(tx_queue);
  2130. }
  2131. efx_associate(efx);
  2132. rtnl_unlock();
  2133. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2134. if (rc) {
  2135. netif_err(efx, drv, efx->net_dev,
  2136. "failed to init net dev attributes\n");
  2137. goto fail_registered;
  2138. }
  2139. #ifdef CONFIG_SFC_MCDI_LOGGING
  2140. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
  2141. if (rc) {
  2142. netif_err(efx, drv, efx->net_dev,
  2143. "failed to init net dev attributes\n");
  2144. goto fail_attr_mcdi_logging;
  2145. }
  2146. #endif
  2147. return 0;
  2148. #ifdef CONFIG_SFC_MCDI_LOGGING
  2149. fail_attr_mcdi_logging:
  2150. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2151. #endif
  2152. fail_registered:
  2153. rtnl_lock();
  2154. efx_dissociate(efx);
  2155. unregister_netdevice(net_dev);
  2156. fail_locked:
  2157. efx->state = STATE_UNINIT;
  2158. rtnl_unlock();
  2159. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  2160. return rc;
  2161. }
  2162. static void efx_unregister_netdev(struct efx_nic *efx)
  2163. {
  2164. if (!efx->net_dev)
  2165. return;
  2166. BUG_ON(netdev_priv(efx->net_dev) != efx);
  2167. if (efx_dev_registered(efx)) {
  2168. strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  2169. #ifdef CONFIG_SFC_MCDI_LOGGING
  2170. device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
  2171. #endif
  2172. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  2173. unregister_netdev(efx->net_dev);
  2174. }
  2175. }
  2176. /**************************************************************************
  2177. *
  2178. * Device reset and suspend
  2179. *
  2180. **************************************************************************/
  2181. /* Tears down the entire software state and most of the hardware state
  2182. * before reset. */
  2183. void efx_reset_down(struct efx_nic *efx, enum reset_type method)
  2184. {
  2185. EFX_ASSERT_RESET_SERIALISED(efx);
  2186. if (method == RESET_TYPE_MCDI_TIMEOUT)
  2187. efx->type->prepare_flr(efx);
  2188. efx_stop_all(efx);
  2189. efx_disable_interrupts(efx);
  2190. mutex_lock(&efx->mac_lock);
  2191. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
  2192. method != RESET_TYPE_DATAPATH)
  2193. efx->phy_op->fini(efx);
  2194. efx->type->fini(efx);
  2195. }
  2196. /* This function will always ensure that the locks acquired in
  2197. * efx_reset_down() are released. A failure return code indicates
  2198. * that we were unable to reinitialise the hardware, and the
  2199. * driver should be disabled. If ok is false, then the rx and tx
  2200. * engines are not restarted, pending a RESET_DISABLE. */
  2201. int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
  2202. {
  2203. int rc;
  2204. EFX_ASSERT_RESET_SERIALISED(efx);
  2205. if (method == RESET_TYPE_MCDI_TIMEOUT)
  2206. efx->type->finish_flr(efx);
  2207. /* Ensure that SRAM is initialised even if we're disabling the device */
  2208. rc = efx->type->init(efx);
  2209. if (rc) {
  2210. netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
  2211. goto fail;
  2212. }
  2213. if (!ok)
  2214. goto fail;
  2215. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
  2216. method != RESET_TYPE_DATAPATH) {
  2217. rc = efx->phy_op->init(efx);
  2218. if (rc)
  2219. goto fail;
  2220. rc = efx->phy_op->reconfigure(efx);
  2221. if (rc && rc != -EPERM)
  2222. netif_err(efx, drv, efx->net_dev,
  2223. "could not restore PHY settings\n");
  2224. }
  2225. rc = efx_enable_interrupts(efx);
  2226. if (rc)
  2227. goto fail;
  2228. #ifdef CONFIG_SFC_SRIOV
  2229. rc = efx->type->vswitching_restore(efx);
  2230. if (rc) /* not fatal; the PF will still work fine */
  2231. netif_warn(efx, probe, efx->net_dev,
  2232. "failed to restore vswitching rc=%d;"
  2233. " VFs may not function\n", rc);
  2234. #endif
  2235. down_read(&efx->filter_sem);
  2236. efx_restore_filters(efx);
  2237. up_read(&efx->filter_sem);
  2238. if (efx->type->sriov_reset)
  2239. efx->type->sriov_reset(efx);
  2240. mutex_unlock(&efx->mac_lock);
  2241. efx_start_all(efx);
  2242. if (efx->type->udp_tnl_push_ports)
  2243. efx->type->udp_tnl_push_ports(efx);
  2244. return 0;
  2245. fail:
  2246. efx->port_initialized = false;
  2247. mutex_unlock(&efx->mac_lock);
  2248. return rc;
  2249. }
  2250. /* Reset the NIC using the specified method. Note that the reset may
  2251. * fail, in which case the card will be left in an unusable state.
  2252. *
  2253. * Caller must hold the rtnl_lock.
  2254. */
  2255. int efx_reset(struct efx_nic *efx, enum reset_type method)
  2256. {
  2257. int rc, rc2;
  2258. bool disabled;
  2259. netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
  2260. RESET_TYPE(method));
  2261. efx_device_detach_sync(efx);
  2262. efx_reset_down(efx, method);
  2263. rc = efx->type->reset(efx, method);
  2264. if (rc) {
  2265. netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
  2266. goto out;
  2267. }
  2268. /* Clear flags for the scopes we covered. We assume the NIC and
  2269. * driver are now quiescent so that there is no race here.
  2270. */
  2271. if (method < RESET_TYPE_MAX_METHOD)
  2272. efx->reset_pending &= -(1 << (method + 1));
  2273. else /* it doesn't fit into the well-ordered scope hierarchy */
  2274. __clear_bit(method, &efx->reset_pending);
  2275. /* Reinitialise bus-mastering, which may have been turned off before
  2276. * the reset was scheduled. This is still appropriate, even in the
  2277. * RESET_TYPE_DISABLE since this driver generally assumes the hardware
  2278. * can respond to requests. */
  2279. pci_set_master(efx->pci_dev);
  2280. out:
  2281. /* Leave device stopped if necessary */
  2282. disabled = rc ||
  2283. method == RESET_TYPE_DISABLE ||
  2284. method == RESET_TYPE_RECOVER_OR_DISABLE;
  2285. rc2 = efx_reset_up(efx, method, !disabled);
  2286. if (rc2) {
  2287. disabled = true;
  2288. if (!rc)
  2289. rc = rc2;
  2290. }
  2291. if (disabled) {
  2292. dev_close(efx->net_dev);
  2293. netif_err(efx, drv, efx->net_dev, "has been disabled\n");
  2294. efx->state = STATE_DISABLED;
  2295. } else {
  2296. netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
  2297. efx_device_attach_if_not_resetting(efx);
  2298. }
  2299. return rc;
  2300. }
  2301. /* Try recovery mechanisms.
  2302. * For now only EEH is supported.
  2303. * Returns 0 if the recovery mechanisms are unsuccessful.
  2304. * Returns a non-zero value otherwise.
  2305. */
  2306. int efx_try_recovery(struct efx_nic *efx)
  2307. {
  2308. #ifdef CONFIG_EEH
  2309. /* A PCI error can occur and not be seen by EEH because nothing
  2310. * happens on the PCI bus. In this case the driver may fail and
  2311. * schedule a 'recover or reset', leading to this recovery handler.
  2312. * Manually call the eeh failure check function.
  2313. */
  2314. struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
  2315. if (eeh_dev_check_failure(eehdev)) {
  2316. /* The EEH mechanisms will handle the error and reset the
  2317. * device if necessary.
  2318. */
  2319. return 1;
  2320. }
  2321. #endif
  2322. return 0;
  2323. }
  2324. static void efx_wait_for_bist_end(struct efx_nic *efx)
  2325. {
  2326. int i;
  2327. for (i = 0; i < BIST_WAIT_DELAY_COUNT; ++i) {
  2328. if (efx_mcdi_poll_reboot(efx))
  2329. goto out;
  2330. msleep(BIST_WAIT_DELAY_MS);
  2331. }
  2332. netif_err(efx, drv, efx->net_dev, "Warning: No MC reboot after BIST mode\n");
  2333. out:
  2334. /* Either way unset the BIST flag. If we found no reboot we probably
  2335. * won't recover, but we should try.
  2336. */
  2337. efx->mc_bist_for_other_fn = false;
  2338. }
  2339. /* The worker thread exists so that code that cannot sleep can
  2340. * schedule a reset for later.
  2341. */
  2342. static void efx_reset_work(struct work_struct *data)
  2343. {
  2344. struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
  2345. unsigned long pending;
  2346. enum reset_type method;
  2347. pending = ACCESS_ONCE(efx->reset_pending);
  2348. method = fls(pending) - 1;
  2349. if (method == RESET_TYPE_MC_BIST)
  2350. efx_wait_for_bist_end(efx);
  2351. if ((method == RESET_TYPE_RECOVER_OR_DISABLE ||
  2352. method == RESET_TYPE_RECOVER_OR_ALL) &&
  2353. efx_try_recovery(efx))
  2354. return;
  2355. if (!pending)
  2356. return;
  2357. rtnl_lock();
  2358. /* We checked the state in efx_schedule_reset() but it may
  2359. * have changed by now. Now that we have the RTNL lock,
  2360. * it cannot change again.
  2361. */
  2362. if (efx->state == STATE_READY)
  2363. (void)efx_reset(efx, method);
  2364. rtnl_unlock();
  2365. }
  2366. void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
  2367. {
  2368. enum reset_type method;
  2369. if (efx->state == STATE_RECOVERY) {
  2370. netif_dbg(efx, drv, efx->net_dev,
  2371. "recovering: skip scheduling %s reset\n",
  2372. RESET_TYPE(type));
  2373. return;
  2374. }
  2375. switch (type) {
  2376. case RESET_TYPE_INVISIBLE:
  2377. case RESET_TYPE_ALL:
  2378. case RESET_TYPE_RECOVER_OR_ALL:
  2379. case RESET_TYPE_WORLD:
  2380. case RESET_TYPE_DISABLE:
  2381. case RESET_TYPE_RECOVER_OR_DISABLE:
  2382. case RESET_TYPE_DATAPATH:
  2383. case RESET_TYPE_MC_BIST:
  2384. case RESET_TYPE_MCDI_TIMEOUT:
  2385. method = type;
  2386. netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
  2387. RESET_TYPE(method));
  2388. break;
  2389. default:
  2390. method = efx->type->map_reset_reason(type);
  2391. netif_dbg(efx, drv, efx->net_dev,
  2392. "scheduling %s reset for %s\n",
  2393. RESET_TYPE(method), RESET_TYPE(type));
  2394. break;
  2395. }
  2396. set_bit(method, &efx->reset_pending);
  2397. smp_mb(); /* ensure we change reset_pending before checking state */
  2398. /* If we're not READY then just leave the flags set as the cue
  2399. * to abort probing or reschedule the reset later.
  2400. */
  2401. if (ACCESS_ONCE(efx->state) != STATE_READY)
  2402. return;
  2403. /* efx_process_channel() will no longer read events once a
  2404. * reset is scheduled. So switch back to poll'd MCDI completions. */
  2405. efx_mcdi_mode_poll(efx);
  2406. queue_work(reset_workqueue, &efx->reset_work);
  2407. }
  2408. /**************************************************************************
  2409. *
  2410. * List of NICs we support
  2411. *
  2412. **************************************************************************/
  2413. /* PCI device ID table */
  2414. static const struct pci_device_id efx_pci_table[] = {
  2415. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
  2416. .driver_data = (unsigned long) &siena_a0_nic_type},
  2417. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
  2418. .driver_data = (unsigned long) &siena_a0_nic_type},
  2419. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
  2420. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2421. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */
  2422. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2423. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
  2424. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2425. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */
  2426. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2427. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */
  2428. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  2429. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */
  2430. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  2431. {0} /* end of list */
  2432. };
  2433. /**************************************************************************
  2434. *
  2435. * Dummy PHY/MAC operations
  2436. *
  2437. * Can be used for some unimplemented operations
  2438. * Needed so all function pointers are valid and do not have to be tested
  2439. * before use
  2440. *
  2441. **************************************************************************/
  2442. int efx_port_dummy_op_int(struct efx_nic *efx)
  2443. {
  2444. return 0;
  2445. }
  2446. void efx_port_dummy_op_void(struct efx_nic *efx) {}
  2447. static bool efx_port_dummy_op_poll(struct efx_nic *efx)
  2448. {
  2449. return false;
  2450. }
  2451. static const struct efx_phy_operations efx_dummy_phy_operations = {
  2452. .init = efx_port_dummy_op_int,
  2453. .reconfigure = efx_port_dummy_op_int,
  2454. .poll = efx_port_dummy_op_poll,
  2455. .fini = efx_port_dummy_op_void,
  2456. };
  2457. /**************************************************************************
  2458. *
  2459. * Data housekeeping
  2460. *
  2461. **************************************************************************/
  2462. /* This zeroes out and then fills in the invariants in a struct
  2463. * efx_nic (including all sub-structures).
  2464. */
  2465. static int efx_init_struct(struct efx_nic *efx,
  2466. struct pci_dev *pci_dev, struct net_device *net_dev)
  2467. {
  2468. int rc = -ENOMEM, i;
  2469. /* Initialise common structures */
  2470. INIT_LIST_HEAD(&efx->node);
  2471. INIT_LIST_HEAD(&efx->secondary_list);
  2472. spin_lock_init(&efx->biu_lock);
  2473. #ifdef CONFIG_SFC_MTD
  2474. INIT_LIST_HEAD(&efx->mtd_list);
  2475. #endif
  2476. INIT_WORK(&efx->reset_work, efx_reset_work);
  2477. INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
  2478. INIT_DELAYED_WORK(&efx->selftest_work, efx_selftest_async_work);
  2479. efx->pci_dev = pci_dev;
  2480. efx->msg_enable = debug;
  2481. efx->state = STATE_UNINIT;
  2482. strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
  2483. efx->net_dev = net_dev;
  2484. efx->rx_prefix_size = efx->type->rx_prefix_size;
  2485. efx->rx_ip_align =
  2486. NET_IP_ALIGN ? (efx->rx_prefix_size + NET_IP_ALIGN) % 4 : 0;
  2487. efx->rx_packet_hash_offset =
  2488. efx->type->rx_hash_offset - efx->type->rx_prefix_size;
  2489. efx->rx_packet_ts_offset =
  2490. efx->type->rx_ts_offset - efx->type->rx_prefix_size;
  2491. spin_lock_init(&efx->stats_lock);
  2492. mutex_init(&efx->mac_lock);
  2493. efx->phy_op = &efx_dummy_phy_operations;
  2494. efx->mdio.dev = net_dev;
  2495. INIT_WORK(&efx->mac_work, efx_mac_work);
  2496. init_waitqueue_head(&efx->flush_wq);
  2497. for (i = 0; i < EFX_MAX_CHANNELS; i++) {
  2498. efx->channel[i] = efx_alloc_channel(efx, i, NULL);
  2499. if (!efx->channel[i])
  2500. goto fail;
  2501. efx->msi_context[i].efx = efx;
  2502. efx->msi_context[i].index = i;
  2503. }
  2504. /* Higher numbered interrupt modes are less capable! */
  2505. if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
  2506. efx->type->min_interrupt_mode)) {
  2507. rc = -EIO;
  2508. goto fail;
  2509. }
  2510. efx->interrupt_mode = max(efx->type->max_interrupt_mode,
  2511. interrupt_mode);
  2512. efx->interrupt_mode = min(efx->type->min_interrupt_mode,
  2513. interrupt_mode);
  2514. /* Would be good to use the net_dev name, but we're too early */
  2515. snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
  2516. pci_name(pci_dev));
  2517. efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
  2518. if (!efx->workqueue)
  2519. goto fail;
  2520. return 0;
  2521. fail:
  2522. efx_fini_struct(efx);
  2523. return rc;
  2524. }
  2525. static void efx_fini_struct(struct efx_nic *efx)
  2526. {
  2527. int i;
  2528. for (i = 0; i < EFX_MAX_CHANNELS; i++)
  2529. kfree(efx->channel[i]);
  2530. kfree(efx->vpd_sn);
  2531. if (efx->workqueue) {
  2532. destroy_workqueue(efx->workqueue);
  2533. efx->workqueue = NULL;
  2534. }
  2535. }
  2536. void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
  2537. {
  2538. u64 n_rx_nodesc_trunc = 0;
  2539. struct efx_channel *channel;
  2540. efx_for_each_channel(channel, efx)
  2541. n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
  2542. stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
  2543. stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
  2544. }
  2545. /**************************************************************************
  2546. *
  2547. * PCI interface
  2548. *
  2549. **************************************************************************/
  2550. /* Main body of final NIC shutdown code
  2551. * This is called only at module unload (or hotplug removal).
  2552. */
  2553. static void efx_pci_remove_main(struct efx_nic *efx)
  2554. {
  2555. /* Flush reset_work. It can no longer be scheduled since we
  2556. * are not READY.
  2557. */
  2558. BUG_ON(efx->state == STATE_READY);
  2559. cancel_work_sync(&efx->reset_work);
  2560. efx_disable_interrupts(efx);
  2561. efx_nic_fini_interrupt(efx);
  2562. efx_fini_port(efx);
  2563. efx->type->fini(efx);
  2564. efx_fini_napi(efx);
  2565. efx_remove_all(efx);
  2566. }
  2567. /* Final NIC shutdown
  2568. * This is called only at module unload (or hotplug removal). A PF can call
  2569. * this on its VFs to ensure they are unbound first.
  2570. */
  2571. static void efx_pci_remove(struct pci_dev *pci_dev)
  2572. {
  2573. struct efx_nic *efx;
  2574. efx = pci_get_drvdata(pci_dev);
  2575. if (!efx)
  2576. return;
  2577. /* Mark the NIC as fini, then stop the interface */
  2578. rtnl_lock();
  2579. efx_dissociate(efx);
  2580. dev_close(efx->net_dev);
  2581. efx_disable_interrupts(efx);
  2582. efx->state = STATE_UNINIT;
  2583. rtnl_unlock();
  2584. if (efx->type->sriov_fini)
  2585. efx->type->sriov_fini(efx);
  2586. efx_unregister_netdev(efx);
  2587. efx_mtd_remove(efx);
  2588. efx_pci_remove_main(efx);
  2589. efx_fini_io(efx);
  2590. netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
  2591. efx_fini_struct(efx);
  2592. free_netdev(efx->net_dev);
  2593. pci_disable_pcie_error_reporting(pci_dev);
  2594. };
  2595. /* NIC VPD information
  2596. * Called during probe to display the part number of the
  2597. * installed NIC. VPD is potentially very large but this should
  2598. * always appear within the first 512 bytes.
  2599. */
  2600. #define SFC_VPD_LEN 512
  2601. static void efx_probe_vpd_strings(struct efx_nic *efx)
  2602. {
  2603. struct pci_dev *dev = efx->pci_dev;
  2604. char vpd_data[SFC_VPD_LEN];
  2605. ssize_t vpd_size;
  2606. int ro_start, ro_size, i, j;
  2607. /* Get the vpd data from the device */
  2608. vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
  2609. if (vpd_size <= 0) {
  2610. netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
  2611. return;
  2612. }
  2613. /* Get the Read only section */
  2614. ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
  2615. if (ro_start < 0) {
  2616. netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
  2617. return;
  2618. }
  2619. ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
  2620. j = ro_size;
  2621. i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
  2622. if (i + j > vpd_size)
  2623. j = vpd_size - i;
  2624. /* Get the Part number */
  2625. i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
  2626. if (i < 0) {
  2627. netif_err(efx, drv, efx->net_dev, "Part number not found\n");
  2628. return;
  2629. }
  2630. j = pci_vpd_info_field_size(&vpd_data[i]);
  2631. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2632. if (i + j > vpd_size) {
  2633. netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
  2634. return;
  2635. }
  2636. netif_info(efx, drv, efx->net_dev,
  2637. "Part Number : %.*s\n", j, &vpd_data[i]);
  2638. i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
  2639. j = ro_size;
  2640. i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
  2641. if (i < 0) {
  2642. netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
  2643. return;
  2644. }
  2645. j = pci_vpd_info_field_size(&vpd_data[i]);
  2646. i += PCI_VPD_INFO_FLD_HDR_SIZE;
  2647. if (i + j > vpd_size) {
  2648. netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
  2649. return;
  2650. }
  2651. efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
  2652. if (!efx->vpd_sn)
  2653. return;
  2654. snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
  2655. }
  2656. /* Main body of NIC initialisation
  2657. * This is called at module load (or hotplug insertion, theoretically).
  2658. */
  2659. static int efx_pci_probe_main(struct efx_nic *efx)
  2660. {
  2661. int rc;
  2662. /* Do start-of-day initialisation */
  2663. rc = efx_probe_all(efx);
  2664. if (rc)
  2665. goto fail1;
  2666. efx_init_napi(efx);
  2667. rc = efx->type->init(efx);
  2668. if (rc) {
  2669. netif_err(efx, probe, efx->net_dev,
  2670. "failed to initialise NIC\n");
  2671. goto fail3;
  2672. }
  2673. rc = efx_init_port(efx);
  2674. if (rc) {
  2675. netif_err(efx, probe, efx->net_dev,
  2676. "failed to initialise port\n");
  2677. goto fail4;
  2678. }
  2679. rc = efx_nic_init_interrupt(efx);
  2680. if (rc)
  2681. goto fail5;
  2682. rc = efx_enable_interrupts(efx);
  2683. if (rc)
  2684. goto fail6;
  2685. return 0;
  2686. fail6:
  2687. efx_nic_fini_interrupt(efx);
  2688. fail5:
  2689. efx_fini_port(efx);
  2690. fail4:
  2691. efx->type->fini(efx);
  2692. fail3:
  2693. efx_fini_napi(efx);
  2694. efx_remove_all(efx);
  2695. fail1:
  2696. return rc;
  2697. }
  2698. static int efx_pci_probe_post_io(struct efx_nic *efx)
  2699. {
  2700. struct net_device *net_dev = efx->net_dev;
  2701. int rc = efx_pci_probe_main(efx);
  2702. if (rc)
  2703. return rc;
  2704. if (efx->type->sriov_init) {
  2705. rc = efx->type->sriov_init(efx);
  2706. if (rc)
  2707. netif_err(efx, probe, efx->net_dev,
  2708. "SR-IOV can't be enabled rc %d\n", rc);
  2709. }
  2710. /* Determine netdevice features */
  2711. net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
  2712. NETIF_F_TSO | NETIF_F_RXCSUM);
  2713. if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
  2714. net_dev->features |= NETIF_F_TSO6;
  2715. /* Check whether device supports TSO */
  2716. if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
  2717. net_dev->features &= ~NETIF_F_ALL_TSO;
  2718. /* Mask for features that also apply to VLAN devices */
  2719. net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
  2720. NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
  2721. NETIF_F_RXCSUM);
  2722. net_dev->hw_features = net_dev->features & ~efx->fixed_features;
  2723. /* Disable VLAN filtering by default. It may be enforced if
  2724. * the feature is fixed (i.e. VLAN filters are required to
  2725. * receive VLAN tagged packets due to vPort restrictions).
  2726. */
  2727. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  2728. net_dev->features |= efx->fixed_features;
  2729. rc = efx_register_netdev(efx);
  2730. if (!rc)
  2731. return 0;
  2732. efx_pci_remove_main(efx);
  2733. return rc;
  2734. }
  2735. /* NIC initialisation
  2736. *
  2737. * This is called at module load (or hotplug insertion,
  2738. * theoretically). It sets up PCI mappings, resets the NIC,
  2739. * sets up and registers the network devices with the kernel and hooks
  2740. * the interrupt service routine. It does not prepare the device for
  2741. * transmission; this is left to the first time one of the network
  2742. * interfaces is brought up (i.e. efx_net_open).
  2743. */
  2744. static int efx_pci_probe(struct pci_dev *pci_dev,
  2745. const struct pci_device_id *entry)
  2746. {
  2747. struct net_device *net_dev;
  2748. struct efx_nic *efx;
  2749. int rc;
  2750. /* Allocate and initialise a struct net_device and struct efx_nic */
  2751. net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
  2752. EFX_MAX_RX_QUEUES);
  2753. if (!net_dev)
  2754. return -ENOMEM;
  2755. efx = netdev_priv(net_dev);
  2756. efx->type = (const struct efx_nic_type *) entry->driver_data;
  2757. efx->fixed_features |= NETIF_F_HIGHDMA;
  2758. pci_set_drvdata(pci_dev, efx);
  2759. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  2760. rc = efx_init_struct(efx, pci_dev, net_dev);
  2761. if (rc)
  2762. goto fail1;
  2763. netif_info(efx, probe, efx->net_dev,
  2764. "Solarflare NIC detected\n");
  2765. if (!efx->type->is_vf)
  2766. efx_probe_vpd_strings(efx);
  2767. /* Set up basic I/O (BAR mappings etc) */
  2768. rc = efx_init_io(efx);
  2769. if (rc)
  2770. goto fail2;
  2771. rc = efx_pci_probe_post_io(efx);
  2772. if (rc) {
  2773. /* On failure, retry once immediately.
  2774. * If we aborted probe due to a scheduled reset, dismiss it.
  2775. */
  2776. efx->reset_pending = 0;
  2777. rc = efx_pci_probe_post_io(efx);
  2778. if (rc) {
  2779. /* On another failure, retry once more
  2780. * after a 50-305ms delay.
  2781. */
  2782. unsigned char r;
  2783. get_random_bytes(&r, 1);
  2784. msleep((unsigned int)r + 50);
  2785. efx->reset_pending = 0;
  2786. rc = efx_pci_probe_post_io(efx);
  2787. }
  2788. }
  2789. if (rc)
  2790. goto fail3;
  2791. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  2792. /* Try to create MTDs, but allow this to fail */
  2793. rtnl_lock();
  2794. rc = efx_mtd_probe(efx);
  2795. rtnl_unlock();
  2796. if (rc && rc != -EPERM)
  2797. netif_warn(efx, probe, efx->net_dev,
  2798. "failed to create MTDs (%d)\n", rc);
  2799. rc = pci_enable_pcie_error_reporting(pci_dev);
  2800. if (rc && rc != -EINVAL)
  2801. netif_notice(efx, probe, efx->net_dev,
  2802. "PCIE error reporting unavailable (%d).\n",
  2803. rc);
  2804. if (efx->type->udp_tnl_push_ports)
  2805. efx->type->udp_tnl_push_ports(efx);
  2806. return 0;
  2807. fail3:
  2808. efx_fini_io(efx);
  2809. fail2:
  2810. efx_fini_struct(efx);
  2811. fail1:
  2812. WARN_ON(rc > 0);
  2813. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  2814. free_netdev(net_dev);
  2815. return rc;
  2816. }
  2817. /* efx_pci_sriov_configure returns the actual number of Virtual Functions
  2818. * enabled on success
  2819. */
  2820. #ifdef CONFIG_SFC_SRIOV
  2821. static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
  2822. {
  2823. int rc;
  2824. struct efx_nic *efx = pci_get_drvdata(dev);
  2825. if (efx->type->sriov_configure) {
  2826. rc = efx->type->sriov_configure(efx, num_vfs);
  2827. if (rc)
  2828. return rc;
  2829. else
  2830. return num_vfs;
  2831. } else
  2832. return -EOPNOTSUPP;
  2833. }
  2834. #endif
  2835. static int efx_pm_freeze(struct device *dev)
  2836. {
  2837. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2838. rtnl_lock();
  2839. if (efx->state != STATE_DISABLED) {
  2840. efx->state = STATE_UNINIT;
  2841. efx_device_detach_sync(efx);
  2842. efx_stop_all(efx);
  2843. efx_disable_interrupts(efx);
  2844. }
  2845. rtnl_unlock();
  2846. return 0;
  2847. }
  2848. static int efx_pm_thaw(struct device *dev)
  2849. {
  2850. int rc;
  2851. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  2852. rtnl_lock();
  2853. if (efx->state != STATE_DISABLED) {
  2854. rc = efx_enable_interrupts(efx);
  2855. if (rc)
  2856. goto fail;
  2857. mutex_lock(&efx->mac_lock);
  2858. efx->phy_op->reconfigure(efx);
  2859. mutex_unlock(&efx->mac_lock);
  2860. efx_start_all(efx);
  2861. efx_device_attach_if_not_resetting(efx);
  2862. efx->state = STATE_READY;
  2863. efx->type->resume_wol(efx);
  2864. }
  2865. rtnl_unlock();
  2866. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  2867. queue_work(reset_workqueue, &efx->reset_work);
  2868. return 0;
  2869. fail:
  2870. rtnl_unlock();
  2871. return rc;
  2872. }
  2873. static int efx_pm_poweroff(struct device *dev)
  2874. {
  2875. struct pci_dev *pci_dev = to_pci_dev(dev);
  2876. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2877. efx->type->fini(efx);
  2878. efx->reset_pending = 0;
  2879. pci_save_state(pci_dev);
  2880. return pci_set_power_state(pci_dev, PCI_D3hot);
  2881. }
  2882. /* Used for both resume and restore */
  2883. static int efx_pm_resume(struct device *dev)
  2884. {
  2885. struct pci_dev *pci_dev = to_pci_dev(dev);
  2886. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  2887. int rc;
  2888. rc = pci_set_power_state(pci_dev, PCI_D0);
  2889. if (rc)
  2890. return rc;
  2891. pci_restore_state(pci_dev);
  2892. rc = pci_enable_device(pci_dev);
  2893. if (rc)
  2894. return rc;
  2895. pci_set_master(efx->pci_dev);
  2896. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  2897. if (rc)
  2898. return rc;
  2899. rc = efx->type->init(efx);
  2900. if (rc)
  2901. return rc;
  2902. rc = efx_pm_thaw(dev);
  2903. return rc;
  2904. }
  2905. static int efx_pm_suspend(struct device *dev)
  2906. {
  2907. int rc;
  2908. efx_pm_freeze(dev);
  2909. rc = efx_pm_poweroff(dev);
  2910. if (rc)
  2911. efx_pm_resume(dev);
  2912. return rc;
  2913. }
  2914. static const struct dev_pm_ops efx_pm_ops = {
  2915. .suspend = efx_pm_suspend,
  2916. .resume = efx_pm_resume,
  2917. .freeze = efx_pm_freeze,
  2918. .thaw = efx_pm_thaw,
  2919. .poweroff = efx_pm_poweroff,
  2920. .restore = efx_pm_resume,
  2921. };
  2922. /* A PCI error affecting this device was detected.
  2923. * At this point MMIO and DMA may be disabled.
  2924. * Stop the software path and request a slot reset.
  2925. */
  2926. static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
  2927. enum pci_channel_state state)
  2928. {
  2929. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2930. struct efx_nic *efx = pci_get_drvdata(pdev);
  2931. if (state == pci_channel_io_perm_failure)
  2932. return PCI_ERS_RESULT_DISCONNECT;
  2933. rtnl_lock();
  2934. if (efx->state != STATE_DISABLED) {
  2935. efx->state = STATE_RECOVERY;
  2936. efx->reset_pending = 0;
  2937. efx_device_detach_sync(efx);
  2938. efx_stop_all(efx);
  2939. efx_disable_interrupts(efx);
  2940. status = PCI_ERS_RESULT_NEED_RESET;
  2941. } else {
  2942. /* If the interface is disabled we don't want to do anything
  2943. * with it.
  2944. */
  2945. status = PCI_ERS_RESULT_RECOVERED;
  2946. }
  2947. rtnl_unlock();
  2948. pci_disable_device(pdev);
  2949. return status;
  2950. }
  2951. /* Fake a successful reset, which will be performed later in efx_io_resume. */
  2952. static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
  2953. {
  2954. struct efx_nic *efx = pci_get_drvdata(pdev);
  2955. pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
  2956. int rc;
  2957. if (pci_enable_device(pdev)) {
  2958. netif_err(efx, hw, efx->net_dev,
  2959. "Cannot re-enable PCI device after reset.\n");
  2960. status = PCI_ERS_RESULT_DISCONNECT;
  2961. }
  2962. rc = pci_cleanup_aer_uncorrect_error_status(pdev);
  2963. if (rc) {
  2964. netif_err(efx, hw, efx->net_dev,
  2965. "pci_cleanup_aer_uncorrect_error_status failed (%d)\n", rc);
  2966. /* Non-fatal error. Continue. */
  2967. }
  2968. return status;
  2969. }
  2970. /* Perform the actual reset and resume I/O operations. */
  2971. static void efx_io_resume(struct pci_dev *pdev)
  2972. {
  2973. struct efx_nic *efx = pci_get_drvdata(pdev);
  2974. int rc;
  2975. rtnl_lock();
  2976. if (efx->state == STATE_DISABLED)
  2977. goto out;
  2978. rc = efx_reset(efx, RESET_TYPE_ALL);
  2979. if (rc) {
  2980. netif_err(efx, hw, efx->net_dev,
  2981. "efx_reset failed after PCI error (%d)\n", rc);
  2982. } else {
  2983. efx->state = STATE_READY;
  2984. netif_dbg(efx, hw, efx->net_dev,
  2985. "Done resetting and resuming IO after PCI error.\n");
  2986. }
  2987. out:
  2988. rtnl_unlock();
  2989. }
  2990. /* For simplicity and reliability, we always require a slot reset and try to
  2991. * reset the hardware when a pci error affecting the device is detected.
  2992. * We leave both the link_reset and mmio_enabled callback unimplemented:
  2993. * with our request for slot reset the mmio_enabled callback will never be
  2994. * called, and the link_reset callback is not used by AER or EEH mechanisms.
  2995. */
  2996. static const struct pci_error_handlers efx_err_handlers = {
  2997. .error_detected = efx_io_error_detected,
  2998. .slot_reset = efx_io_slot_reset,
  2999. .resume = efx_io_resume,
  3000. };
  3001. static struct pci_driver efx_pci_driver = {
  3002. .name = KBUILD_MODNAME,
  3003. .id_table = efx_pci_table,
  3004. .probe = efx_pci_probe,
  3005. .remove = efx_pci_remove,
  3006. .driver.pm = &efx_pm_ops,
  3007. .err_handler = &efx_err_handlers,
  3008. #ifdef CONFIG_SFC_SRIOV
  3009. .sriov_configure = efx_pci_sriov_configure,
  3010. #endif
  3011. };
  3012. /**************************************************************************
  3013. *
  3014. * Kernel module interface
  3015. *
  3016. *************************************************************************/
  3017. module_param(interrupt_mode, uint, 0444);
  3018. MODULE_PARM_DESC(interrupt_mode,
  3019. "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
  3020. static int __init efx_init_module(void)
  3021. {
  3022. int rc;
  3023. printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
  3024. rc = register_netdevice_notifier(&efx_netdev_notifier);
  3025. if (rc)
  3026. goto err_notifier;
  3027. #ifdef CONFIG_SFC_SRIOV
  3028. rc = efx_init_sriov();
  3029. if (rc)
  3030. goto err_sriov;
  3031. #endif
  3032. reset_workqueue = create_singlethread_workqueue("sfc_reset");
  3033. if (!reset_workqueue) {
  3034. rc = -ENOMEM;
  3035. goto err_reset;
  3036. }
  3037. rc = pci_register_driver(&efx_pci_driver);
  3038. if (rc < 0)
  3039. goto err_pci;
  3040. return 0;
  3041. err_pci:
  3042. destroy_workqueue(reset_workqueue);
  3043. err_reset:
  3044. #ifdef CONFIG_SFC_SRIOV
  3045. efx_fini_sriov();
  3046. err_sriov:
  3047. #endif
  3048. unregister_netdevice_notifier(&efx_netdev_notifier);
  3049. err_notifier:
  3050. return rc;
  3051. }
  3052. static void __exit efx_exit_module(void)
  3053. {
  3054. printk(KERN_INFO "Solarflare NET driver unloading\n");
  3055. pci_unregister_driver(&efx_pci_driver);
  3056. destroy_workqueue(reset_workqueue);
  3057. #ifdef CONFIG_SFC_SRIOV
  3058. efx_fini_sriov();
  3059. #endif
  3060. unregister_netdevice_notifier(&efx_netdev_notifier);
  3061. }
  3062. module_init(efx_init_module);
  3063. module_exit(efx_exit_module);
  3064. MODULE_AUTHOR("Solarflare Communications and "
  3065. "Michael Brown <mbrown@fensystems.co.uk>");
  3066. MODULE_DESCRIPTION("Solarflare network driver");
  3067. MODULE_LICENSE("GPL");
  3068. MODULE_DEVICE_TABLE(pci, efx_pci_table);
  3069. MODULE_VERSION(EFX_DRIVER_VERSION);