efx.c 79 KB

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