efx.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2009 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/crc32.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/topology.h>
  22. #include <linux/gfp.h>
  23. #include "net_driver.h"
  24. #include "efx.h"
  25. #include "mdio_10g.h"
  26. #include "nic.h"
  27. #include "mcdi.h"
  28. #include "workarounds.h"
  29. /**************************************************************************
  30. *
  31. * Type name strings
  32. *
  33. **************************************************************************
  34. */
  35. /* Loopback mode names (see LOOPBACK_MODE()) */
  36. const unsigned int efx_loopback_mode_max = LOOPBACK_MAX;
  37. const char *efx_loopback_mode_names[] = {
  38. [LOOPBACK_NONE] = "NONE",
  39. [LOOPBACK_DATA] = "DATAPATH",
  40. [LOOPBACK_GMAC] = "GMAC",
  41. [LOOPBACK_XGMII] = "XGMII",
  42. [LOOPBACK_XGXS] = "XGXS",
  43. [LOOPBACK_XAUI] = "XAUI",
  44. [LOOPBACK_GMII] = "GMII",
  45. [LOOPBACK_SGMII] = "SGMII",
  46. [LOOPBACK_XGBR] = "XGBR",
  47. [LOOPBACK_XFI] = "XFI",
  48. [LOOPBACK_XAUI_FAR] = "XAUI_FAR",
  49. [LOOPBACK_GMII_FAR] = "GMII_FAR",
  50. [LOOPBACK_SGMII_FAR] = "SGMII_FAR",
  51. [LOOPBACK_XFI_FAR] = "XFI_FAR",
  52. [LOOPBACK_GPHY] = "GPHY",
  53. [LOOPBACK_PHYXS] = "PHYXS",
  54. [LOOPBACK_PCS] = "PCS",
  55. [LOOPBACK_PMAPMD] = "PMA/PMD",
  56. [LOOPBACK_XPORT] = "XPORT",
  57. [LOOPBACK_XGMII_WS] = "XGMII_WS",
  58. [LOOPBACK_XAUI_WS] = "XAUI_WS",
  59. [LOOPBACK_XAUI_WS_FAR] = "XAUI_WS_FAR",
  60. [LOOPBACK_XAUI_WS_NEAR] = "XAUI_WS_NEAR",
  61. [LOOPBACK_GMII_WS] = "GMII_WS",
  62. [LOOPBACK_XFI_WS] = "XFI_WS",
  63. [LOOPBACK_XFI_WS_FAR] = "XFI_WS_FAR",
  64. [LOOPBACK_PHYXS_WS] = "PHYXS_WS",
  65. };
  66. /* Interrupt mode names (see INT_MODE())) */
  67. const unsigned int efx_interrupt_mode_max = EFX_INT_MODE_MAX;
  68. const char *efx_interrupt_mode_names[] = {
  69. [EFX_INT_MODE_MSIX] = "MSI-X",
  70. [EFX_INT_MODE_MSI] = "MSI",
  71. [EFX_INT_MODE_LEGACY] = "legacy",
  72. };
  73. const unsigned int efx_reset_type_max = RESET_TYPE_MAX;
  74. const char *efx_reset_type_names[] = {
  75. [RESET_TYPE_INVISIBLE] = "INVISIBLE",
  76. [RESET_TYPE_ALL] = "ALL",
  77. [RESET_TYPE_WORLD] = "WORLD",
  78. [RESET_TYPE_DISABLE] = "DISABLE",
  79. [RESET_TYPE_TX_WATCHDOG] = "TX_WATCHDOG",
  80. [RESET_TYPE_INT_ERROR] = "INT_ERROR",
  81. [RESET_TYPE_RX_RECOVERY] = "RX_RECOVERY",
  82. [RESET_TYPE_RX_DESC_FETCH] = "RX_DESC_FETCH",
  83. [RESET_TYPE_TX_DESC_FETCH] = "TX_DESC_FETCH",
  84. [RESET_TYPE_TX_SKIP] = "TX_SKIP",
  85. [RESET_TYPE_MC_FAILURE] = "MC_FAILURE",
  86. };
  87. #define EFX_MAX_MTU (9 * 1024)
  88. /* Reset workqueue. If any NIC has a hardware failure then a reset will be
  89. * queued onto this work queue. This is not a per-nic work queue, because
  90. * efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
  91. */
  92. static struct workqueue_struct *reset_workqueue;
  93. /**************************************************************************
  94. *
  95. * Configurable values
  96. *
  97. *************************************************************************/
  98. /*
  99. * Use separate channels for TX and RX events
  100. *
  101. * Set this to 1 to use separate channels for TX and RX. It allows us
  102. * to control interrupt affinity separately for TX and RX.
  103. *
  104. * This is only used in MSI-X interrupt mode
  105. */
  106. static unsigned int separate_tx_channels;
  107. module_param(separate_tx_channels, uint, 0644);
  108. MODULE_PARM_DESC(separate_tx_channels,
  109. "Use separate channels for TX and RX");
  110. /* This is the weight assigned to each of the (per-channel) virtual
  111. * NAPI devices.
  112. */
  113. static int napi_weight = 64;
  114. /* This is the time (in jiffies) between invocations of the hardware
  115. * monitor, which checks for known hardware bugs and resets the
  116. * hardware and driver as necessary.
  117. */
  118. unsigned int efx_monitor_interval = 1 * HZ;
  119. /* This controls whether or not the driver will initialise devices
  120. * with invalid MAC addresses stored in the EEPROM or flash. If true,
  121. * such devices will be initialised with a random locally-generated
  122. * MAC address. This allows for loading the sfc_mtd driver to
  123. * reprogram the flash, even if the flash contents (including the MAC
  124. * address) have previously been erased.
  125. */
  126. static unsigned int allow_bad_hwaddr;
  127. /* Initial interrupt moderation settings. They can be modified after
  128. * module load with ethtool.
  129. *
  130. * The default for RX should strike a balance between increasing the
  131. * round-trip latency and reducing overhead.
  132. */
  133. static unsigned int rx_irq_mod_usec = 60;
  134. /* Initial interrupt moderation settings. They can be modified after
  135. * module load with ethtool.
  136. *
  137. * This default is chosen to ensure that a 10G link does not go idle
  138. * while a TX queue is stopped after it has become full. A queue is
  139. * restarted when it drops below half full. The time this takes (assuming
  140. * worst case 3 descriptors per packet and 1024 descriptors) is
  141. * 512 / 3 * 1.2 = 205 usec.
  142. */
  143. static unsigned int tx_irq_mod_usec = 150;
  144. /* This is the first interrupt mode to try out of:
  145. * 0 => MSI-X
  146. * 1 => MSI
  147. * 2 => legacy
  148. */
  149. static unsigned int interrupt_mode;
  150. /* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
  151. * i.e. the number of CPUs among which we may distribute simultaneous
  152. * interrupt handling.
  153. *
  154. * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
  155. * The default (0) means to assign an interrupt to each package (level II cache)
  156. */
  157. static unsigned int rss_cpus;
  158. module_param(rss_cpus, uint, 0444);
  159. MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
  160. static int phy_flash_cfg;
  161. module_param(phy_flash_cfg, int, 0644);
  162. MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
  163. static unsigned irq_adapt_low_thresh = 10000;
  164. module_param(irq_adapt_low_thresh, uint, 0644);
  165. MODULE_PARM_DESC(irq_adapt_low_thresh,
  166. "Threshold score for reducing IRQ moderation");
  167. static unsigned irq_adapt_high_thresh = 20000;
  168. module_param(irq_adapt_high_thresh, uint, 0644);
  169. MODULE_PARM_DESC(irq_adapt_high_thresh,
  170. "Threshold score for increasing IRQ moderation");
  171. static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  172. NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
  173. NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
  174. NETIF_MSG_TX_ERR | NETIF_MSG_HW);
  175. module_param(debug, uint, 0);
  176. MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
  177. /**************************************************************************
  178. *
  179. * Utility functions and prototypes
  180. *
  181. *************************************************************************/
  182. static void efx_remove_channel(struct efx_channel *channel);
  183. static void efx_remove_port(struct efx_nic *efx);
  184. static void efx_fini_napi(struct efx_nic *efx);
  185. static void efx_fini_channels(struct efx_nic *efx);
  186. #define EFX_ASSERT_RESET_SERIALISED(efx) \
  187. do { \
  188. if ((efx->state == STATE_RUNNING) || \
  189. (efx->state == STATE_DISABLED)) \
  190. ASSERT_RTNL(); \
  191. } while (0)
  192. /**************************************************************************
  193. *
  194. * Event queue processing
  195. *
  196. *************************************************************************/
  197. /* Process channel's event queue
  198. *
  199. * This function is responsible for processing the event queue of a
  200. * single channel. The caller must guarantee that this function will
  201. * never be concurrently called more than once on the same channel,
  202. * though different channels may be being processed concurrently.
  203. */
  204. static int efx_process_channel(struct efx_channel *channel, int budget)
  205. {
  206. struct efx_nic *efx = channel->efx;
  207. int spent;
  208. if (unlikely(efx->reset_pending != RESET_TYPE_NONE ||
  209. !channel->enabled))
  210. return 0;
  211. spent = efx_nic_process_eventq(channel, budget);
  212. if (spent == 0)
  213. return 0;
  214. /* Deliver last RX packet. */
  215. if (channel->rx_pkt) {
  216. __efx_rx_packet(channel, channel->rx_pkt,
  217. channel->rx_pkt_csummed);
  218. channel->rx_pkt = NULL;
  219. }
  220. efx_rx_strategy(channel);
  221. efx_fast_push_rx_descriptors(&efx->rx_queue[channel->channel]);
  222. return spent;
  223. }
  224. /* Mark channel as finished processing
  225. *
  226. * Note that since we will not receive further interrupts for this
  227. * channel before we finish processing and call the eventq_read_ack()
  228. * method, there is no need to use the interrupt hold-off timers.
  229. */
  230. static inline void efx_channel_processed(struct efx_channel *channel)
  231. {
  232. /* The interrupt handler for this channel may set work_pending
  233. * as soon as we acknowledge the events we've seen. Make sure
  234. * it's cleared before then. */
  235. channel->work_pending = false;
  236. smp_wmb();
  237. efx_nic_eventq_read_ack(channel);
  238. }
  239. /* NAPI poll handler
  240. *
  241. * NAPI guarantees serialisation of polls of the same device, which
  242. * provides the guarantee required by efx_process_channel().
  243. */
  244. static int efx_poll(struct napi_struct *napi, int budget)
  245. {
  246. struct efx_channel *channel =
  247. container_of(napi, struct efx_channel, napi_str);
  248. struct efx_nic *efx = channel->efx;
  249. int spent;
  250. netif_vdbg(efx, intr, efx->net_dev,
  251. "channel %d NAPI poll executing on CPU %d\n",
  252. channel->channel, raw_smp_processor_id());
  253. spent = efx_process_channel(channel, budget);
  254. if (spent < budget) {
  255. if (channel->channel < efx->n_rx_channels &&
  256. efx->irq_rx_adaptive &&
  257. unlikely(++channel->irq_count == 1000)) {
  258. if (unlikely(channel->irq_mod_score <
  259. irq_adapt_low_thresh)) {
  260. if (channel->irq_moderation > 1) {
  261. channel->irq_moderation -= 1;
  262. efx->type->push_irq_moderation(channel);
  263. }
  264. } else if (unlikely(channel->irq_mod_score >
  265. irq_adapt_high_thresh)) {
  266. if (channel->irq_moderation <
  267. efx->irq_rx_moderation) {
  268. channel->irq_moderation += 1;
  269. efx->type->push_irq_moderation(channel);
  270. }
  271. }
  272. channel->irq_count = 0;
  273. channel->irq_mod_score = 0;
  274. }
  275. /* There is no race here; although napi_disable() will
  276. * only wait for napi_complete(), this isn't a problem
  277. * since efx_channel_processed() will have no effect if
  278. * interrupts have already been disabled.
  279. */
  280. napi_complete(napi);
  281. efx_channel_processed(channel);
  282. }
  283. return spent;
  284. }
  285. /* Process the eventq of the specified channel immediately on this CPU
  286. *
  287. * Disable hardware generated interrupts, wait for any existing
  288. * processing to finish, then directly poll (and ack ) the eventq.
  289. * Finally reenable NAPI and interrupts.
  290. *
  291. * Since we are touching interrupts the caller should hold the suspend lock
  292. */
  293. void efx_process_channel_now(struct efx_channel *channel)
  294. {
  295. struct efx_nic *efx = channel->efx;
  296. BUG_ON(!channel->enabled);
  297. /* Disable interrupts and wait for ISRs to complete */
  298. efx_nic_disable_interrupts(efx);
  299. if (efx->legacy_irq)
  300. synchronize_irq(efx->legacy_irq);
  301. if (channel->irq)
  302. synchronize_irq(channel->irq);
  303. /* Wait for any NAPI processing to complete */
  304. napi_disable(&channel->napi_str);
  305. /* Poll the channel */
  306. efx_process_channel(channel, EFX_EVQ_SIZE);
  307. /* Ack the eventq. This may cause an interrupt to be generated
  308. * when they are reenabled */
  309. efx_channel_processed(channel);
  310. napi_enable(&channel->napi_str);
  311. efx_nic_enable_interrupts(efx);
  312. }
  313. /* Create event queue
  314. * Event queue memory allocations are done only once. If the channel
  315. * is reset, the memory buffer will be reused; this guards against
  316. * errors during channel reset and also simplifies interrupt handling.
  317. */
  318. static int efx_probe_eventq(struct efx_channel *channel)
  319. {
  320. netif_dbg(channel->efx, probe, channel->efx->net_dev,
  321. "chan %d create event queue\n", channel->channel);
  322. return efx_nic_probe_eventq(channel);
  323. }
  324. /* Prepare channel's event queue */
  325. static void efx_init_eventq(struct efx_channel *channel)
  326. {
  327. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  328. "chan %d init event queue\n", channel->channel);
  329. channel->eventq_read_ptr = 0;
  330. efx_nic_init_eventq(channel);
  331. }
  332. static void efx_fini_eventq(struct efx_channel *channel)
  333. {
  334. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  335. "chan %d fini event queue\n", channel->channel);
  336. efx_nic_fini_eventq(channel);
  337. }
  338. static void efx_remove_eventq(struct efx_channel *channel)
  339. {
  340. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  341. "chan %d remove event queue\n", channel->channel);
  342. efx_nic_remove_eventq(channel);
  343. }
  344. /**************************************************************************
  345. *
  346. * Channel handling
  347. *
  348. *************************************************************************/
  349. static int efx_probe_channel(struct efx_channel *channel)
  350. {
  351. struct efx_tx_queue *tx_queue;
  352. struct efx_rx_queue *rx_queue;
  353. int rc;
  354. netif_dbg(channel->efx, probe, channel->efx->net_dev,
  355. "creating channel %d\n", channel->channel);
  356. rc = efx_probe_eventq(channel);
  357. if (rc)
  358. goto fail1;
  359. efx_for_each_channel_tx_queue(tx_queue, channel) {
  360. rc = efx_probe_tx_queue(tx_queue);
  361. if (rc)
  362. goto fail2;
  363. }
  364. efx_for_each_channel_rx_queue(rx_queue, channel) {
  365. rc = efx_probe_rx_queue(rx_queue);
  366. if (rc)
  367. goto fail3;
  368. }
  369. channel->n_rx_frm_trunc = 0;
  370. return 0;
  371. fail3:
  372. efx_for_each_channel_rx_queue(rx_queue, channel)
  373. efx_remove_rx_queue(rx_queue);
  374. fail2:
  375. efx_for_each_channel_tx_queue(tx_queue, channel)
  376. efx_remove_tx_queue(tx_queue);
  377. fail1:
  378. return rc;
  379. }
  380. static void efx_set_channel_names(struct efx_nic *efx)
  381. {
  382. struct efx_channel *channel;
  383. const char *type = "";
  384. int number;
  385. efx_for_each_channel(channel, efx) {
  386. number = channel->channel;
  387. if (efx->n_channels > efx->n_rx_channels) {
  388. if (channel->channel < efx->n_rx_channels) {
  389. type = "-rx";
  390. } else {
  391. type = "-tx";
  392. number -= efx->n_rx_channels;
  393. }
  394. }
  395. snprintf(channel->name, sizeof(channel->name),
  396. "%s%s-%d", efx->name, type, number);
  397. }
  398. }
  399. /* Channels are shutdown and reinitialised whilst the NIC is running
  400. * to propagate configuration changes (mtu, checksum offload), or
  401. * to clear hardware error conditions
  402. */
  403. static void efx_init_channels(struct efx_nic *efx)
  404. {
  405. struct efx_tx_queue *tx_queue;
  406. struct efx_rx_queue *rx_queue;
  407. struct efx_channel *channel;
  408. /* Calculate the rx buffer allocation parameters required to
  409. * support the current MTU, including padding for header
  410. * alignment and overruns.
  411. */
  412. efx->rx_buffer_len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) +
  413. EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
  414. efx->type->rx_buffer_padding);
  415. efx->rx_buffer_order = get_order(efx->rx_buffer_len +
  416. sizeof(struct efx_rx_page_state));
  417. /* Initialise the channels */
  418. efx_for_each_channel(channel, efx) {
  419. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  420. "init chan %d\n", channel->channel);
  421. efx_init_eventq(channel);
  422. efx_for_each_channel_tx_queue(tx_queue, channel)
  423. efx_init_tx_queue(tx_queue);
  424. /* The rx buffer allocation strategy is MTU dependent */
  425. efx_rx_strategy(channel);
  426. efx_for_each_channel_rx_queue(rx_queue, channel)
  427. efx_init_rx_queue(rx_queue);
  428. WARN_ON(channel->rx_pkt != NULL);
  429. efx_rx_strategy(channel);
  430. }
  431. }
  432. /* This enables event queue processing and packet transmission.
  433. *
  434. * Note that this function is not allowed to fail, since that would
  435. * introduce too much complexity into the suspend/resume path.
  436. */
  437. static void efx_start_channel(struct efx_channel *channel)
  438. {
  439. struct efx_rx_queue *rx_queue;
  440. netif_dbg(channel->efx, ifup, channel->efx->net_dev,
  441. "starting chan %d\n", channel->channel);
  442. /* The interrupt handler for this channel may set work_pending
  443. * as soon as we enable it. Make sure it's cleared before
  444. * then. Similarly, make sure it sees the enabled flag set. */
  445. channel->work_pending = false;
  446. channel->enabled = true;
  447. smp_wmb();
  448. /* Fill the queues before enabling NAPI */
  449. efx_for_each_channel_rx_queue(rx_queue, channel)
  450. efx_fast_push_rx_descriptors(rx_queue);
  451. napi_enable(&channel->napi_str);
  452. }
  453. /* This disables event queue processing and packet transmission.
  454. * This function does not guarantee that all queue processing
  455. * (e.g. RX refill) is complete.
  456. */
  457. static void efx_stop_channel(struct efx_channel *channel)
  458. {
  459. if (!channel->enabled)
  460. return;
  461. netif_dbg(channel->efx, ifdown, channel->efx->net_dev,
  462. "stop chan %d\n", channel->channel);
  463. channel->enabled = false;
  464. napi_disable(&channel->napi_str);
  465. }
  466. static void efx_fini_channels(struct efx_nic *efx)
  467. {
  468. struct efx_channel *channel;
  469. struct efx_tx_queue *tx_queue;
  470. struct efx_rx_queue *rx_queue;
  471. int rc;
  472. EFX_ASSERT_RESET_SERIALISED(efx);
  473. BUG_ON(efx->port_enabled);
  474. rc = efx_nic_flush_queues(efx);
  475. if (rc && EFX_WORKAROUND_7803(efx)) {
  476. /* Schedule a reset to recover from the flush failure. The
  477. * descriptor caches reference memory we're about to free,
  478. * but falcon_reconfigure_mac_wrapper() won't reconnect
  479. * the MACs because of the pending reset. */
  480. netif_err(efx, drv, efx->net_dev,
  481. "Resetting to recover from flush failure\n");
  482. efx_schedule_reset(efx, RESET_TYPE_ALL);
  483. } else if (rc) {
  484. netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
  485. } else {
  486. netif_dbg(efx, drv, efx->net_dev,
  487. "successfully flushed all queues\n");
  488. }
  489. efx_for_each_channel(channel, efx) {
  490. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  491. "shut down chan %d\n", channel->channel);
  492. efx_for_each_channel_rx_queue(rx_queue, channel)
  493. efx_fini_rx_queue(rx_queue);
  494. efx_for_each_channel_tx_queue(tx_queue, channel)
  495. efx_fini_tx_queue(tx_queue);
  496. efx_fini_eventq(channel);
  497. }
  498. }
  499. static void efx_remove_channel(struct efx_channel *channel)
  500. {
  501. struct efx_tx_queue *tx_queue;
  502. struct efx_rx_queue *rx_queue;
  503. netif_dbg(channel->efx, drv, channel->efx->net_dev,
  504. "destroy chan %d\n", channel->channel);
  505. efx_for_each_channel_rx_queue(rx_queue, channel)
  506. efx_remove_rx_queue(rx_queue);
  507. efx_for_each_channel_tx_queue(tx_queue, channel)
  508. efx_remove_tx_queue(tx_queue);
  509. efx_remove_eventq(channel);
  510. }
  511. void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
  512. {
  513. mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(100));
  514. }
  515. /**************************************************************************
  516. *
  517. * Port handling
  518. *
  519. **************************************************************************/
  520. /* This ensures that the kernel is kept informed (via
  521. * netif_carrier_on/off) of the link status, and also maintains the
  522. * link status's stop on the port's TX queue.
  523. */
  524. void efx_link_status_changed(struct efx_nic *efx)
  525. {
  526. struct efx_link_state *link_state = &efx->link_state;
  527. /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
  528. * that no events are triggered between unregister_netdev() and the
  529. * driver unloading. A more general condition is that NETDEV_CHANGE
  530. * can only be generated between NETDEV_UP and NETDEV_DOWN */
  531. if (!netif_running(efx->net_dev))
  532. return;
  533. if (efx->port_inhibited) {
  534. netif_carrier_off(efx->net_dev);
  535. return;
  536. }
  537. if (link_state->up != netif_carrier_ok(efx->net_dev)) {
  538. efx->n_link_state_changes++;
  539. if (link_state->up)
  540. netif_carrier_on(efx->net_dev);
  541. else
  542. netif_carrier_off(efx->net_dev);
  543. }
  544. /* Status message for kernel log */
  545. if (link_state->up) {
  546. netif_info(efx, link, efx->net_dev,
  547. "link up at %uMbps %s-duplex (MTU %d)%s\n",
  548. link_state->speed, link_state->fd ? "full" : "half",
  549. efx->net_dev->mtu,
  550. (efx->promiscuous ? " [PROMISC]" : ""));
  551. } else {
  552. netif_info(efx, link, efx->net_dev, "link down\n");
  553. }
  554. }
  555. void efx_link_set_advertising(struct efx_nic *efx, u32 advertising)
  556. {
  557. efx->link_advertising = advertising;
  558. if (advertising) {
  559. if (advertising & ADVERTISED_Pause)
  560. efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
  561. else
  562. efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
  563. if (advertising & ADVERTISED_Asym_Pause)
  564. efx->wanted_fc ^= EFX_FC_TX;
  565. }
  566. }
  567. void efx_link_set_wanted_fc(struct efx_nic *efx, enum efx_fc_type wanted_fc)
  568. {
  569. efx->wanted_fc = wanted_fc;
  570. if (efx->link_advertising) {
  571. if (wanted_fc & EFX_FC_RX)
  572. efx->link_advertising |= (ADVERTISED_Pause |
  573. ADVERTISED_Asym_Pause);
  574. else
  575. efx->link_advertising &= ~(ADVERTISED_Pause |
  576. ADVERTISED_Asym_Pause);
  577. if (wanted_fc & EFX_FC_TX)
  578. efx->link_advertising ^= ADVERTISED_Asym_Pause;
  579. }
  580. }
  581. static void efx_fini_port(struct efx_nic *efx);
  582. /* Push loopback/power/transmit disable settings to the PHY, and reconfigure
  583. * the MAC appropriately. All other PHY configuration changes are pushed
  584. * through phy_op->set_settings(), and pushed asynchronously to the MAC
  585. * through efx_monitor().
  586. *
  587. * Callers must hold the mac_lock
  588. */
  589. int __efx_reconfigure_port(struct efx_nic *efx)
  590. {
  591. enum efx_phy_mode phy_mode;
  592. int rc;
  593. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  594. /* Serialise the promiscuous flag with efx_set_multicast_list. */
  595. if (efx_dev_registered(efx)) {
  596. netif_addr_lock_bh(efx->net_dev);
  597. netif_addr_unlock_bh(efx->net_dev);
  598. }
  599. /* Disable PHY transmit in mac level loopbacks */
  600. phy_mode = efx->phy_mode;
  601. if (LOOPBACK_INTERNAL(efx))
  602. efx->phy_mode |= PHY_MODE_TX_DISABLED;
  603. else
  604. efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
  605. rc = efx->type->reconfigure_port(efx);
  606. if (rc)
  607. efx->phy_mode = phy_mode;
  608. return rc;
  609. }
  610. /* Reinitialise the MAC to pick up new PHY settings, even if the port is
  611. * disabled. */
  612. int efx_reconfigure_port(struct efx_nic *efx)
  613. {
  614. int rc;
  615. EFX_ASSERT_RESET_SERIALISED(efx);
  616. mutex_lock(&efx->mac_lock);
  617. rc = __efx_reconfigure_port(efx);
  618. mutex_unlock(&efx->mac_lock);
  619. return rc;
  620. }
  621. /* Asynchronous work item for changing MAC promiscuity and multicast
  622. * hash. Avoid a drain/rx_ingress enable by reconfiguring the current
  623. * MAC directly. */
  624. static void efx_mac_work(struct work_struct *data)
  625. {
  626. struct efx_nic *efx = container_of(data, struct efx_nic, mac_work);
  627. mutex_lock(&efx->mac_lock);
  628. if (efx->port_enabled) {
  629. efx->type->push_multicast_hash(efx);
  630. efx->mac_op->reconfigure(efx);
  631. }
  632. mutex_unlock(&efx->mac_lock);
  633. }
  634. static int efx_probe_port(struct efx_nic *efx)
  635. {
  636. int rc;
  637. netif_dbg(efx, probe, efx->net_dev, "create port\n");
  638. if (phy_flash_cfg)
  639. efx->phy_mode = PHY_MODE_SPECIAL;
  640. /* Connect up MAC/PHY operations table */
  641. rc = efx->type->probe_port(efx);
  642. if (rc)
  643. goto err;
  644. /* Sanity check MAC address */
  645. if (is_valid_ether_addr(efx->mac_address)) {
  646. memcpy(efx->net_dev->dev_addr, efx->mac_address, ETH_ALEN);
  647. } else {
  648. netif_err(efx, probe, efx->net_dev, "invalid MAC address %pM\n",
  649. efx->mac_address);
  650. if (!allow_bad_hwaddr) {
  651. rc = -EINVAL;
  652. goto err;
  653. }
  654. random_ether_addr(efx->net_dev->dev_addr);
  655. netif_info(efx, probe, efx->net_dev,
  656. "using locally-generated MAC %pM\n",
  657. efx->net_dev->dev_addr);
  658. }
  659. return 0;
  660. err:
  661. efx_remove_port(efx);
  662. return rc;
  663. }
  664. static int efx_init_port(struct efx_nic *efx)
  665. {
  666. int rc;
  667. netif_dbg(efx, drv, efx->net_dev, "init port\n");
  668. mutex_lock(&efx->mac_lock);
  669. rc = efx->phy_op->init(efx);
  670. if (rc)
  671. goto fail1;
  672. efx->port_initialized = true;
  673. /* Reconfigure the MAC before creating dma queues (required for
  674. * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
  675. efx->mac_op->reconfigure(efx);
  676. /* Ensure the PHY advertises the correct flow control settings */
  677. rc = efx->phy_op->reconfigure(efx);
  678. if (rc)
  679. goto fail2;
  680. mutex_unlock(&efx->mac_lock);
  681. return 0;
  682. fail2:
  683. efx->phy_op->fini(efx);
  684. fail1:
  685. mutex_unlock(&efx->mac_lock);
  686. return rc;
  687. }
  688. static void efx_start_port(struct efx_nic *efx)
  689. {
  690. netif_dbg(efx, ifup, efx->net_dev, "start port\n");
  691. BUG_ON(efx->port_enabled);
  692. mutex_lock(&efx->mac_lock);
  693. efx->port_enabled = true;
  694. /* efx_mac_work() might have been scheduled after efx_stop_port(),
  695. * and then cancelled by efx_flush_all() */
  696. efx->type->push_multicast_hash(efx);
  697. efx->mac_op->reconfigure(efx);
  698. mutex_unlock(&efx->mac_lock);
  699. }
  700. /* Prevent efx_mac_work() and efx_monitor() from working */
  701. static void efx_stop_port(struct efx_nic *efx)
  702. {
  703. netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
  704. mutex_lock(&efx->mac_lock);
  705. efx->port_enabled = false;
  706. mutex_unlock(&efx->mac_lock);
  707. /* Serialise against efx_set_multicast_list() */
  708. if (efx_dev_registered(efx)) {
  709. netif_addr_lock_bh(efx->net_dev);
  710. netif_addr_unlock_bh(efx->net_dev);
  711. }
  712. }
  713. static void efx_fini_port(struct efx_nic *efx)
  714. {
  715. netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
  716. if (!efx->port_initialized)
  717. return;
  718. efx->phy_op->fini(efx);
  719. efx->port_initialized = false;
  720. efx->link_state.up = false;
  721. efx_link_status_changed(efx);
  722. }
  723. static void efx_remove_port(struct efx_nic *efx)
  724. {
  725. netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
  726. efx->type->remove_port(efx);
  727. }
  728. /**************************************************************************
  729. *
  730. * NIC handling
  731. *
  732. **************************************************************************/
  733. /* This configures the PCI device to enable I/O and DMA. */
  734. static int efx_init_io(struct efx_nic *efx)
  735. {
  736. struct pci_dev *pci_dev = efx->pci_dev;
  737. dma_addr_t dma_mask = efx->type->max_dma_mask;
  738. int rc;
  739. netif_dbg(efx, probe, efx->net_dev, "initialising I/O\n");
  740. rc = pci_enable_device(pci_dev);
  741. if (rc) {
  742. netif_err(efx, probe, efx->net_dev,
  743. "failed to enable PCI device\n");
  744. goto fail1;
  745. }
  746. pci_set_master(pci_dev);
  747. /* Set the PCI DMA mask. Try all possibilities from our
  748. * genuine mask down to 32 bits, because some architectures
  749. * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
  750. * masks event though they reject 46 bit masks.
  751. */
  752. while (dma_mask > 0x7fffffffUL) {
  753. if (pci_dma_supported(pci_dev, dma_mask) &&
  754. ((rc = pci_set_dma_mask(pci_dev, dma_mask)) == 0))
  755. break;
  756. dma_mask >>= 1;
  757. }
  758. if (rc) {
  759. netif_err(efx, probe, efx->net_dev,
  760. "could not find a suitable DMA mask\n");
  761. goto fail2;
  762. }
  763. netif_dbg(efx, probe, efx->net_dev,
  764. "using DMA mask %llx\n", (unsigned long long) dma_mask);
  765. rc = pci_set_consistent_dma_mask(pci_dev, dma_mask);
  766. if (rc) {
  767. /* pci_set_consistent_dma_mask() is not *allowed* to
  768. * fail with a mask that pci_set_dma_mask() accepted,
  769. * but just in case...
  770. */
  771. netif_err(efx, probe, efx->net_dev,
  772. "failed to set consistent DMA mask\n");
  773. goto fail2;
  774. }
  775. efx->membase_phys = pci_resource_start(efx->pci_dev, EFX_MEM_BAR);
  776. rc = pci_request_region(pci_dev, EFX_MEM_BAR, "sfc");
  777. if (rc) {
  778. netif_err(efx, probe, efx->net_dev,
  779. "request for memory BAR failed\n");
  780. rc = -EIO;
  781. goto fail3;
  782. }
  783. efx->membase = ioremap_nocache(efx->membase_phys,
  784. efx->type->mem_map_size);
  785. if (!efx->membase) {
  786. netif_err(efx, probe, efx->net_dev,
  787. "could not map memory BAR at %llx+%x\n",
  788. (unsigned long long)efx->membase_phys,
  789. efx->type->mem_map_size);
  790. rc = -ENOMEM;
  791. goto fail4;
  792. }
  793. netif_dbg(efx, probe, efx->net_dev,
  794. "memory BAR at %llx+%x (virtual %p)\n",
  795. (unsigned long long)efx->membase_phys,
  796. efx->type->mem_map_size, efx->membase);
  797. return 0;
  798. fail4:
  799. pci_release_region(efx->pci_dev, EFX_MEM_BAR);
  800. fail3:
  801. efx->membase_phys = 0;
  802. fail2:
  803. pci_disable_device(efx->pci_dev);
  804. fail1:
  805. return rc;
  806. }
  807. static void efx_fini_io(struct efx_nic *efx)
  808. {
  809. netif_dbg(efx, drv, efx->net_dev, "shutting down I/O\n");
  810. if (efx->membase) {
  811. iounmap(efx->membase);
  812. efx->membase = NULL;
  813. }
  814. if (efx->membase_phys) {
  815. pci_release_region(efx->pci_dev, EFX_MEM_BAR);
  816. efx->membase_phys = 0;
  817. }
  818. pci_disable_device(efx->pci_dev);
  819. }
  820. /* Get number of channels wanted. Each channel will have its own IRQ,
  821. * 1 RX queue and/or 2 TX queues. */
  822. static int efx_wanted_channels(void)
  823. {
  824. cpumask_var_t core_mask;
  825. int count;
  826. int cpu;
  827. if (unlikely(!zalloc_cpumask_var(&core_mask, GFP_KERNEL))) {
  828. printk(KERN_WARNING
  829. "sfc: RSS disabled due to allocation failure\n");
  830. return 1;
  831. }
  832. count = 0;
  833. for_each_online_cpu(cpu) {
  834. if (!cpumask_test_cpu(cpu, core_mask)) {
  835. ++count;
  836. cpumask_or(core_mask, core_mask,
  837. topology_core_cpumask(cpu));
  838. }
  839. }
  840. free_cpumask_var(core_mask);
  841. return count;
  842. }
  843. /* Probe the number and type of interrupts we are able to obtain, and
  844. * the resulting numbers of channels and RX queues.
  845. */
  846. static void efx_probe_interrupts(struct efx_nic *efx)
  847. {
  848. int max_channels =
  849. min_t(int, efx->type->phys_addr_channels, EFX_MAX_CHANNELS);
  850. int rc, i;
  851. if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
  852. struct msix_entry xentries[EFX_MAX_CHANNELS];
  853. int n_channels;
  854. n_channels = efx_wanted_channels();
  855. if (separate_tx_channels)
  856. n_channels *= 2;
  857. n_channels = min(n_channels, max_channels);
  858. for (i = 0; i < n_channels; i++)
  859. xentries[i].entry = i;
  860. rc = pci_enable_msix(efx->pci_dev, xentries, n_channels);
  861. if (rc > 0) {
  862. netif_err(efx, drv, efx->net_dev,
  863. "WARNING: Insufficient MSI-X vectors"
  864. " available (%d < %d).\n", rc, n_channels);
  865. netif_err(efx, drv, efx->net_dev,
  866. "WARNING: Performance may be reduced.\n");
  867. EFX_BUG_ON_PARANOID(rc >= n_channels);
  868. n_channels = rc;
  869. rc = pci_enable_msix(efx->pci_dev, xentries,
  870. n_channels);
  871. }
  872. if (rc == 0) {
  873. efx->n_channels = n_channels;
  874. if (separate_tx_channels) {
  875. efx->n_tx_channels =
  876. max(efx->n_channels / 2, 1U);
  877. efx->n_rx_channels =
  878. max(efx->n_channels -
  879. efx->n_tx_channels, 1U);
  880. } else {
  881. efx->n_tx_channels = efx->n_channels;
  882. efx->n_rx_channels = efx->n_channels;
  883. }
  884. for (i = 0; i < n_channels; i++)
  885. efx->channel[i].irq = xentries[i].vector;
  886. } else {
  887. /* Fall back to single channel MSI */
  888. efx->interrupt_mode = EFX_INT_MODE_MSI;
  889. netif_err(efx, drv, efx->net_dev,
  890. "could not enable MSI-X\n");
  891. }
  892. }
  893. /* Try single interrupt MSI */
  894. if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
  895. efx->n_channels = 1;
  896. efx->n_rx_channels = 1;
  897. efx->n_tx_channels = 1;
  898. rc = pci_enable_msi(efx->pci_dev);
  899. if (rc == 0) {
  900. efx->channel[0].irq = efx->pci_dev->irq;
  901. } else {
  902. netif_err(efx, drv, efx->net_dev,
  903. "could not enable MSI\n");
  904. efx->interrupt_mode = EFX_INT_MODE_LEGACY;
  905. }
  906. }
  907. /* Assume legacy interrupts */
  908. if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
  909. efx->n_channels = 1 + (separate_tx_channels ? 1 : 0);
  910. efx->n_rx_channels = 1;
  911. efx->n_tx_channels = 1;
  912. efx->legacy_irq = efx->pci_dev->irq;
  913. }
  914. }
  915. static void efx_remove_interrupts(struct efx_nic *efx)
  916. {
  917. struct efx_channel *channel;
  918. /* Remove MSI/MSI-X interrupts */
  919. efx_for_each_channel(channel, efx)
  920. channel->irq = 0;
  921. pci_disable_msi(efx->pci_dev);
  922. pci_disable_msix(efx->pci_dev);
  923. /* Remove legacy interrupt */
  924. efx->legacy_irq = 0;
  925. }
  926. static void efx_set_channels(struct efx_nic *efx)
  927. {
  928. struct efx_channel *channel;
  929. struct efx_tx_queue *tx_queue;
  930. struct efx_rx_queue *rx_queue;
  931. unsigned tx_channel_offset =
  932. separate_tx_channels ? efx->n_channels - efx->n_tx_channels : 0;
  933. efx_for_each_channel(channel, efx) {
  934. if (channel->channel - tx_channel_offset < efx->n_tx_channels) {
  935. channel->tx_queue = &efx->tx_queue[
  936. (channel->channel - tx_channel_offset) *
  937. EFX_TXQ_TYPES];
  938. efx_for_each_channel_tx_queue(tx_queue, channel)
  939. tx_queue->channel = channel;
  940. }
  941. }
  942. efx_for_each_rx_queue(rx_queue, efx)
  943. rx_queue->channel = &efx->channel[rx_queue->queue];
  944. }
  945. static int efx_probe_nic(struct efx_nic *efx)
  946. {
  947. int rc;
  948. netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
  949. /* Carry out hardware-type specific initialisation */
  950. rc = efx->type->probe(efx);
  951. if (rc)
  952. return rc;
  953. /* Determine the number of channels and queues by trying to hook
  954. * in MSI-X interrupts. */
  955. efx_probe_interrupts(efx);
  956. efx_set_channels(efx);
  957. efx->net_dev->real_num_tx_queues = efx->n_tx_channels;
  958. /* Initialise the interrupt moderation settings */
  959. efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true);
  960. return 0;
  961. }
  962. static void efx_remove_nic(struct efx_nic *efx)
  963. {
  964. netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
  965. efx_remove_interrupts(efx);
  966. efx->type->remove(efx);
  967. }
  968. /**************************************************************************
  969. *
  970. * NIC startup/shutdown
  971. *
  972. *************************************************************************/
  973. static int efx_probe_all(struct efx_nic *efx)
  974. {
  975. struct efx_channel *channel;
  976. int rc;
  977. /* Create NIC */
  978. rc = efx_probe_nic(efx);
  979. if (rc) {
  980. netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
  981. goto fail1;
  982. }
  983. /* Create port */
  984. rc = efx_probe_port(efx);
  985. if (rc) {
  986. netif_err(efx, probe, efx->net_dev, "failed to create port\n");
  987. goto fail2;
  988. }
  989. /* Create channels */
  990. efx_for_each_channel(channel, efx) {
  991. rc = efx_probe_channel(channel);
  992. if (rc) {
  993. netif_err(efx, probe, efx->net_dev,
  994. "failed to create channel %d\n",
  995. channel->channel);
  996. goto fail3;
  997. }
  998. }
  999. efx_set_channel_names(efx);
  1000. return 0;
  1001. fail3:
  1002. efx_for_each_channel(channel, efx)
  1003. efx_remove_channel(channel);
  1004. efx_remove_port(efx);
  1005. fail2:
  1006. efx_remove_nic(efx);
  1007. fail1:
  1008. return rc;
  1009. }
  1010. /* Called after previous invocation(s) of efx_stop_all, restarts the
  1011. * port, kernel transmit queue, NAPI processing and hardware interrupts,
  1012. * and ensures that the port is scheduled to be reconfigured.
  1013. * This function is safe to call multiple times when the NIC is in any
  1014. * state. */
  1015. static void efx_start_all(struct efx_nic *efx)
  1016. {
  1017. struct efx_channel *channel;
  1018. EFX_ASSERT_RESET_SERIALISED(efx);
  1019. /* Check that it is appropriate to restart the interface. All
  1020. * of these flags are safe to read under just the rtnl lock */
  1021. if (efx->port_enabled)
  1022. return;
  1023. if ((efx->state != STATE_RUNNING) && (efx->state != STATE_INIT))
  1024. return;
  1025. if (efx_dev_registered(efx) && !netif_running(efx->net_dev))
  1026. return;
  1027. /* Mark the port as enabled so port reconfigurations can start, then
  1028. * restart the transmit interface early so the watchdog timer stops */
  1029. efx_start_port(efx);
  1030. efx_for_each_channel(channel, efx) {
  1031. if (efx_dev_registered(efx))
  1032. efx_wake_queue(channel);
  1033. efx_start_channel(channel);
  1034. }
  1035. efx_nic_enable_interrupts(efx);
  1036. /* Switch to event based MCDI completions after enabling interrupts.
  1037. * If a reset has been scheduled, then we need to stay in polled mode.
  1038. * Rather than serialising efx_mcdi_mode_event() [which sleeps] and
  1039. * reset_pending [modified from an atomic context], we instead guarantee
  1040. * that efx_mcdi_mode_poll() isn't reverted erroneously */
  1041. efx_mcdi_mode_event(efx);
  1042. if (efx->reset_pending != RESET_TYPE_NONE)
  1043. efx_mcdi_mode_poll(efx);
  1044. /* Start the hardware monitor if there is one. Otherwise (we're link
  1045. * event driven), we have to poll the PHY because after an event queue
  1046. * flush, we could have a missed a link state change */
  1047. if (efx->type->monitor != NULL) {
  1048. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1049. efx_monitor_interval);
  1050. } else {
  1051. mutex_lock(&efx->mac_lock);
  1052. if (efx->phy_op->poll(efx))
  1053. efx_link_status_changed(efx);
  1054. mutex_unlock(&efx->mac_lock);
  1055. }
  1056. efx->type->start_stats(efx);
  1057. }
  1058. /* Flush all delayed work. Should only be called when no more delayed work
  1059. * will be scheduled. This doesn't flush pending online resets (efx_reset),
  1060. * since we're holding the rtnl_lock at this point. */
  1061. static void efx_flush_all(struct efx_nic *efx)
  1062. {
  1063. /* Make sure the hardware monitor is stopped */
  1064. cancel_delayed_work_sync(&efx->monitor_work);
  1065. /* Stop scheduled port reconfigurations */
  1066. cancel_work_sync(&efx->mac_work);
  1067. }
  1068. /* Quiesce hardware and software without bringing the link down.
  1069. * Safe to call multiple times, when the nic and interface is in any
  1070. * state. The caller is guaranteed to subsequently be in a position
  1071. * to modify any hardware and software state they see fit without
  1072. * taking locks. */
  1073. static void efx_stop_all(struct efx_nic *efx)
  1074. {
  1075. struct efx_channel *channel;
  1076. EFX_ASSERT_RESET_SERIALISED(efx);
  1077. /* port_enabled can be read safely under the rtnl lock */
  1078. if (!efx->port_enabled)
  1079. return;
  1080. efx->type->stop_stats(efx);
  1081. /* Switch to MCDI polling on Siena before disabling interrupts */
  1082. efx_mcdi_mode_poll(efx);
  1083. /* Disable interrupts and wait for ISR to complete */
  1084. efx_nic_disable_interrupts(efx);
  1085. if (efx->legacy_irq)
  1086. synchronize_irq(efx->legacy_irq);
  1087. efx_for_each_channel(channel, efx) {
  1088. if (channel->irq)
  1089. synchronize_irq(channel->irq);
  1090. }
  1091. /* Stop all NAPI processing and synchronous rx refills */
  1092. efx_for_each_channel(channel, efx)
  1093. efx_stop_channel(channel);
  1094. /* Stop all asynchronous port reconfigurations. Since all
  1095. * event processing has already been stopped, there is no
  1096. * window to loose phy events */
  1097. efx_stop_port(efx);
  1098. /* Flush efx_mac_work(), refill_workqueue, monitor_work */
  1099. efx_flush_all(efx);
  1100. /* Stop the kernel transmit interface late, so the watchdog
  1101. * timer isn't ticking over the flush */
  1102. if (efx_dev_registered(efx)) {
  1103. struct efx_channel *channel;
  1104. efx_for_each_channel(channel, efx)
  1105. efx_stop_queue(channel);
  1106. netif_tx_lock_bh(efx->net_dev);
  1107. netif_tx_unlock_bh(efx->net_dev);
  1108. }
  1109. }
  1110. static void efx_remove_all(struct efx_nic *efx)
  1111. {
  1112. struct efx_channel *channel;
  1113. efx_for_each_channel(channel, efx)
  1114. efx_remove_channel(channel);
  1115. efx_remove_port(efx);
  1116. efx_remove_nic(efx);
  1117. }
  1118. /**************************************************************************
  1119. *
  1120. * Interrupt moderation
  1121. *
  1122. **************************************************************************/
  1123. static unsigned irq_mod_ticks(int usecs, int resolution)
  1124. {
  1125. if (usecs <= 0)
  1126. return 0; /* cannot receive interrupts ahead of time :-) */
  1127. if (usecs < resolution)
  1128. return 1; /* never round down to 0 */
  1129. return usecs / resolution;
  1130. }
  1131. /* Set interrupt moderation parameters */
  1132. void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs,
  1133. bool rx_adaptive)
  1134. {
  1135. struct efx_tx_queue *tx_queue;
  1136. struct efx_rx_queue *rx_queue;
  1137. unsigned tx_ticks = irq_mod_ticks(tx_usecs, EFX_IRQ_MOD_RESOLUTION);
  1138. unsigned rx_ticks = irq_mod_ticks(rx_usecs, EFX_IRQ_MOD_RESOLUTION);
  1139. EFX_ASSERT_RESET_SERIALISED(efx);
  1140. efx_for_each_tx_queue(tx_queue, efx)
  1141. tx_queue->channel->irq_moderation = tx_ticks;
  1142. efx->irq_rx_adaptive = rx_adaptive;
  1143. efx->irq_rx_moderation = rx_ticks;
  1144. efx_for_each_rx_queue(rx_queue, efx)
  1145. rx_queue->channel->irq_moderation = rx_ticks;
  1146. }
  1147. /**************************************************************************
  1148. *
  1149. * Hardware monitor
  1150. *
  1151. **************************************************************************/
  1152. /* Run periodically off the general workqueue. Serialised against
  1153. * efx_reconfigure_port via the mac_lock */
  1154. static void efx_monitor(struct work_struct *data)
  1155. {
  1156. struct efx_nic *efx = container_of(data, struct efx_nic,
  1157. monitor_work.work);
  1158. netif_vdbg(efx, timer, efx->net_dev,
  1159. "hardware monitor executing on CPU %d\n",
  1160. raw_smp_processor_id());
  1161. BUG_ON(efx->type->monitor == NULL);
  1162. /* If the mac_lock is already held then it is likely a port
  1163. * reconfiguration is already in place, which will likely do
  1164. * most of the work of check_hw() anyway. */
  1165. if (!mutex_trylock(&efx->mac_lock))
  1166. goto out_requeue;
  1167. if (!efx->port_enabled)
  1168. goto out_unlock;
  1169. efx->type->monitor(efx);
  1170. out_unlock:
  1171. mutex_unlock(&efx->mac_lock);
  1172. out_requeue:
  1173. queue_delayed_work(efx->workqueue, &efx->monitor_work,
  1174. efx_monitor_interval);
  1175. }
  1176. /**************************************************************************
  1177. *
  1178. * ioctls
  1179. *
  1180. *************************************************************************/
  1181. /* Net device ioctl
  1182. * Context: process, rtnl_lock() held.
  1183. */
  1184. static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
  1185. {
  1186. struct efx_nic *efx = netdev_priv(net_dev);
  1187. struct mii_ioctl_data *data = if_mii(ifr);
  1188. EFX_ASSERT_RESET_SERIALISED(efx);
  1189. /* Convert phy_id from older PRTAD/DEVAD format */
  1190. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  1191. (data->phy_id & 0xfc00) == 0x0400)
  1192. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  1193. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  1194. }
  1195. /**************************************************************************
  1196. *
  1197. * NAPI interface
  1198. *
  1199. **************************************************************************/
  1200. static int efx_init_napi(struct efx_nic *efx)
  1201. {
  1202. struct efx_channel *channel;
  1203. efx_for_each_channel(channel, efx) {
  1204. channel->napi_dev = efx->net_dev;
  1205. netif_napi_add(channel->napi_dev, &channel->napi_str,
  1206. efx_poll, napi_weight);
  1207. }
  1208. return 0;
  1209. }
  1210. static void efx_fini_napi(struct efx_nic *efx)
  1211. {
  1212. struct efx_channel *channel;
  1213. efx_for_each_channel(channel, efx) {
  1214. if (channel->napi_dev)
  1215. netif_napi_del(&channel->napi_str);
  1216. channel->napi_dev = NULL;
  1217. }
  1218. }
  1219. /**************************************************************************
  1220. *
  1221. * Kernel netpoll interface
  1222. *
  1223. *************************************************************************/
  1224. #ifdef CONFIG_NET_POLL_CONTROLLER
  1225. /* Although in the common case interrupts will be disabled, this is not
  1226. * guaranteed. However, all our work happens inside the NAPI callback,
  1227. * so no locking is required.
  1228. */
  1229. static void efx_netpoll(struct net_device *net_dev)
  1230. {
  1231. struct efx_nic *efx = netdev_priv(net_dev);
  1232. struct efx_channel *channel;
  1233. efx_for_each_channel(channel, efx)
  1234. efx_schedule_channel(channel);
  1235. }
  1236. #endif
  1237. /**************************************************************************
  1238. *
  1239. * Kernel net device interface
  1240. *
  1241. *************************************************************************/
  1242. /* Context: process, rtnl_lock() held. */
  1243. static int efx_net_open(struct net_device *net_dev)
  1244. {
  1245. struct efx_nic *efx = netdev_priv(net_dev);
  1246. EFX_ASSERT_RESET_SERIALISED(efx);
  1247. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  1248. raw_smp_processor_id());
  1249. if (efx->state == STATE_DISABLED)
  1250. return -EIO;
  1251. if (efx->phy_mode & PHY_MODE_SPECIAL)
  1252. return -EBUSY;
  1253. if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
  1254. return -EIO;
  1255. /* Notify the kernel of the link state polled during driver load,
  1256. * before the monitor starts running */
  1257. efx_link_status_changed(efx);
  1258. efx_start_all(efx);
  1259. return 0;
  1260. }
  1261. /* Context: process, rtnl_lock() held.
  1262. * Note that the kernel will ignore our return code; this method
  1263. * should really be a void.
  1264. */
  1265. static int efx_net_stop(struct net_device *net_dev)
  1266. {
  1267. struct efx_nic *efx = netdev_priv(net_dev);
  1268. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  1269. raw_smp_processor_id());
  1270. if (efx->state != STATE_DISABLED) {
  1271. /* Stop the device and flush all the channels */
  1272. efx_stop_all(efx);
  1273. efx_fini_channels(efx);
  1274. efx_init_channels(efx);
  1275. }
  1276. return 0;
  1277. }
  1278. /* Context: process, dev_base_lock or RTNL held, non-blocking. */
  1279. static struct rtnl_link_stats64 *efx_net_stats(struct net_device *net_dev)
  1280. {
  1281. struct efx_nic *efx = netdev_priv(net_dev);
  1282. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  1283. struct rtnl_link_stats64 *stats = &net_dev->stats64;
  1284. spin_lock_bh(&efx->stats_lock);
  1285. efx->type->update_stats(efx);
  1286. spin_unlock_bh(&efx->stats_lock);
  1287. stats->rx_packets = mac_stats->rx_packets;
  1288. stats->tx_packets = mac_stats->tx_packets;
  1289. stats->rx_bytes = mac_stats->rx_bytes;
  1290. stats->tx_bytes = mac_stats->tx_bytes;
  1291. stats->multicast = mac_stats->rx_multicast;
  1292. stats->collisions = mac_stats->tx_collision;
  1293. stats->rx_length_errors = (mac_stats->rx_gtjumbo +
  1294. mac_stats->rx_length_error);
  1295. stats->rx_over_errors = efx->n_rx_nodesc_drop_cnt;
  1296. stats->rx_crc_errors = mac_stats->rx_bad;
  1297. stats->rx_frame_errors = mac_stats->rx_align_error;
  1298. stats->rx_fifo_errors = mac_stats->rx_overflow;
  1299. stats->rx_missed_errors = mac_stats->rx_missed;
  1300. stats->tx_window_errors = mac_stats->tx_late_collision;
  1301. stats->rx_errors = (stats->rx_length_errors +
  1302. stats->rx_crc_errors +
  1303. stats->rx_frame_errors +
  1304. mac_stats->rx_symbol_error);
  1305. stats->tx_errors = (stats->tx_window_errors +
  1306. mac_stats->tx_bad);
  1307. return stats;
  1308. }
  1309. /* Context: netif_tx_lock held, BHs disabled. */
  1310. static void efx_watchdog(struct net_device *net_dev)
  1311. {
  1312. struct efx_nic *efx = netdev_priv(net_dev);
  1313. netif_err(efx, tx_err, efx->net_dev,
  1314. "TX stuck with port_enabled=%d: resetting channels\n",
  1315. efx->port_enabled);
  1316. efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
  1317. }
  1318. /* Context: process, rtnl_lock() held. */
  1319. static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
  1320. {
  1321. struct efx_nic *efx = netdev_priv(net_dev);
  1322. int rc = 0;
  1323. EFX_ASSERT_RESET_SERIALISED(efx);
  1324. if (new_mtu > EFX_MAX_MTU)
  1325. return -EINVAL;
  1326. efx_stop_all(efx);
  1327. netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
  1328. efx_fini_channels(efx);
  1329. mutex_lock(&efx->mac_lock);
  1330. /* Reconfigure the MAC before enabling the dma queues so that
  1331. * the RX buffers don't overflow */
  1332. net_dev->mtu = new_mtu;
  1333. efx->mac_op->reconfigure(efx);
  1334. mutex_unlock(&efx->mac_lock);
  1335. efx_init_channels(efx);
  1336. efx_start_all(efx);
  1337. return rc;
  1338. }
  1339. static int efx_set_mac_address(struct net_device *net_dev, void *data)
  1340. {
  1341. struct efx_nic *efx = netdev_priv(net_dev);
  1342. struct sockaddr *addr = data;
  1343. char *new_addr = addr->sa_data;
  1344. EFX_ASSERT_RESET_SERIALISED(efx);
  1345. if (!is_valid_ether_addr(new_addr)) {
  1346. netif_err(efx, drv, efx->net_dev,
  1347. "invalid ethernet MAC address requested: %pM\n",
  1348. new_addr);
  1349. return -EINVAL;
  1350. }
  1351. memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
  1352. /* Reconfigure the MAC */
  1353. mutex_lock(&efx->mac_lock);
  1354. efx->mac_op->reconfigure(efx);
  1355. mutex_unlock(&efx->mac_lock);
  1356. return 0;
  1357. }
  1358. /* Context: netif_addr_lock held, BHs disabled. */
  1359. static void efx_set_multicast_list(struct net_device *net_dev)
  1360. {
  1361. struct efx_nic *efx = netdev_priv(net_dev);
  1362. struct netdev_hw_addr *ha;
  1363. union efx_multicast_hash *mc_hash = &efx->multicast_hash;
  1364. u32 crc;
  1365. int bit;
  1366. efx->promiscuous = !!(net_dev->flags & IFF_PROMISC);
  1367. /* Build multicast hash table */
  1368. if (efx->promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
  1369. memset(mc_hash, 0xff, sizeof(*mc_hash));
  1370. } else {
  1371. memset(mc_hash, 0x00, sizeof(*mc_hash));
  1372. netdev_for_each_mc_addr(ha, net_dev) {
  1373. crc = ether_crc_le(ETH_ALEN, ha->addr);
  1374. bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
  1375. set_bit_le(bit, mc_hash->byte);
  1376. }
  1377. /* Broadcast packets go through the multicast hash filter.
  1378. * ether_crc_le() of the broadcast address is 0xbe2612ff
  1379. * so we always add bit 0xff to the mask.
  1380. */
  1381. set_bit_le(0xff, mc_hash->byte);
  1382. }
  1383. if (efx->port_enabled)
  1384. queue_work(efx->workqueue, &efx->mac_work);
  1385. /* Otherwise efx_start_port() will do this */
  1386. }
  1387. static const struct net_device_ops efx_netdev_ops = {
  1388. .ndo_open = efx_net_open,
  1389. .ndo_stop = efx_net_stop,
  1390. .ndo_get_stats64 = efx_net_stats,
  1391. .ndo_tx_timeout = efx_watchdog,
  1392. .ndo_start_xmit = efx_hard_start_xmit,
  1393. .ndo_validate_addr = eth_validate_addr,
  1394. .ndo_do_ioctl = efx_ioctl,
  1395. .ndo_change_mtu = efx_change_mtu,
  1396. .ndo_set_mac_address = efx_set_mac_address,
  1397. .ndo_set_multicast_list = efx_set_multicast_list,
  1398. #ifdef CONFIG_NET_POLL_CONTROLLER
  1399. .ndo_poll_controller = efx_netpoll,
  1400. #endif
  1401. };
  1402. static void efx_update_name(struct efx_nic *efx)
  1403. {
  1404. strcpy(efx->name, efx->net_dev->name);
  1405. efx_mtd_rename(efx);
  1406. efx_set_channel_names(efx);
  1407. }
  1408. static int efx_netdev_event(struct notifier_block *this,
  1409. unsigned long event, void *ptr)
  1410. {
  1411. struct net_device *net_dev = ptr;
  1412. if (net_dev->netdev_ops == &efx_netdev_ops &&
  1413. event == NETDEV_CHANGENAME)
  1414. efx_update_name(netdev_priv(net_dev));
  1415. return NOTIFY_DONE;
  1416. }
  1417. static struct notifier_block efx_netdev_notifier = {
  1418. .notifier_call = efx_netdev_event,
  1419. };
  1420. static ssize_t
  1421. show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
  1422. {
  1423. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  1424. return sprintf(buf, "%d\n", efx->phy_type);
  1425. }
  1426. static DEVICE_ATTR(phy_type, 0644, show_phy_type, NULL);
  1427. static int efx_register_netdev(struct efx_nic *efx)
  1428. {
  1429. struct net_device *net_dev = efx->net_dev;
  1430. int rc;
  1431. net_dev->watchdog_timeo = 5 * HZ;
  1432. net_dev->irq = efx->pci_dev->irq;
  1433. net_dev->netdev_ops = &efx_netdev_ops;
  1434. SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
  1435. /* Clear MAC statistics */
  1436. efx->mac_op->update_stats(efx);
  1437. memset(&efx->mac_stats, 0, sizeof(efx->mac_stats));
  1438. rtnl_lock();
  1439. rc = dev_alloc_name(net_dev, net_dev->name);
  1440. if (rc < 0)
  1441. goto fail_locked;
  1442. efx_update_name(efx);
  1443. rc = register_netdevice(net_dev);
  1444. if (rc)
  1445. goto fail_locked;
  1446. /* Always start with carrier off; PHY events will detect the link */
  1447. netif_carrier_off(efx->net_dev);
  1448. rtnl_unlock();
  1449. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  1450. if (rc) {
  1451. netif_err(efx, drv, efx->net_dev,
  1452. "failed to init net dev attributes\n");
  1453. goto fail_registered;
  1454. }
  1455. return 0;
  1456. fail_locked:
  1457. rtnl_unlock();
  1458. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  1459. return rc;
  1460. fail_registered:
  1461. unregister_netdev(net_dev);
  1462. return rc;
  1463. }
  1464. static void efx_unregister_netdev(struct efx_nic *efx)
  1465. {
  1466. struct efx_tx_queue *tx_queue;
  1467. if (!efx->net_dev)
  1468. return;
  1469. BUG_ON(netdev_priv(efx->net_dev) != efx);
  1470. /* Free up any skbs still remaining. This has to happen before
  1471. * we try to unregister the netdev as running their destructors
  1472. * may be needed to get the device ref. count to 0. */
  1473. efx_for_each_tx_queue(tx_queue, efx)
  1474. efx_release_tx_buffers(tx_queue);
  1475. if (efx_dev_registered(efx)) {
  1476. strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  1477. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  1478. unregister_netdev(efx->net_dev);
  1479. }
  1480. }
  1481. /**************************************************************************
  1482. *
  1483. * Device reset and suspend
  1484. *
  1485. **************************************************************************/
  1486. /* Tears down the entire software state and most of the hardware state
  1487. * before reset. */
  1488. void efx_reset_down(struct efx_nic *efx, enum reset_type method)
  1489. {
  1490. EFX_ASSERT_RESET_SERIALISED(efx);
  1491. efx_stop_all(efx);
  1492. mutex_lock(&efx->mac_lock);
  1493. mutex_lock(&efx->spi_lock);
  1494. efx_fini_channels(efx);
  1495. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE)
  1496. efx->phy_op->fini(efx);
  1497. efx->type->fini(efx);
  1498. }
  1499. /* This function will always ensure that the locks acquired in
  1500. * efx_reset_down() are released. A failure return code indicates
  1501. * that we were unable to reinitialise the hardware, and the
  1502. * driver should be disabled. If ok is false, then the rx and tx
  1503. * engines are not restarted, pending a RESET_DISABLE. */
  1504. int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
  1505. {
  1506. int rc;
  1507. EFX_ASSERT_RESET_SERIALISED(efx);
  1508. rc = efx->type->init(efx);
  1509. if (rc) {
  1510. netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
  1511. goto fail;
  1512. }
  1513. if (!ok)
  1514. goto fail;
  1515. if (efx->port_initialized && method != RESET_TYPE_INVISIBLE) {
  1516. rc = efx->phy_op->init(efx);
  1517. if (rc)
  1518. goto fail;
  1519. if (efx->phy_op->reconfigure(efx))
  1520. netif_err(efx, drv, efx->net_dev,
  1521. "could not restore PHY settings\n");
  1522. }
  1523. efx->mac_op->reconfigure(efx);
  1524. efx_init_channels(efx);
  1525. mutex_unlock(&efx->spi_lock);
  1526. mutex_unlock(&efx->mac_lock);
  1527. efx_start_all(efx);
  1528. return 0;
  1529. fail:
  1530. efx->port_initialized = false;
  1531. mutex_unlock(&efx->spi_lock);
  1532. mutex_unlock(&efx->mac_lock);
  1533. return rc;
  1534. }
  1535. /* Reset the NIC using the specified method. Note that the reset may
  1536. * fail, in which case the card will be left in an unusable state.
  1537. *
  1538. * Caller must hold the rtnl_lock.
  1539. */
  1540. int efx_reset(struct efx_nic *efx, enum reset_type method)
  1541. {
  1542. int rc, rc2;
  1543. bool disabled;
  1544. netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
  1545. RESET_TYPE(method));
  1546. efx_reset_down(efx, method);
  1547. rc = efx->type->reset(efx, method);
  1548. if (rc) {
  1549. netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
  1550. goto out;
  1551. }
  1552. /* Allow resets to be rescheduled. */
  1553. efx->reset_pending = RESET_TYPE_NONE;
  1554. /* Reinitialise bus-mastering, which may have been turned off before
  1555. * the reset was scheduled. This is still appropriate, even in the
  1556. * RESET_TYPE_DISABLE since this driver generally assumes the hardware
  1557. * can respond to requests. */
  1558. pci_set_master(efx->pci_dev);
  1559. out:
  1560. /* Leave device stopped if necessary */
  1561. disabled = rc || method == RESET_TYPE_DISABLE;
  1562. rc2 = efx_reset_up(efx, method, !disabled);
  1563. if (rc2) {
  1564. disabled = true;
  1565. if (!rc)
  1566. rc = rc2;
  1567. }
  1568. if (disabled) {
  1569. dev_close(efx->net_dev);
  1570. netif_err(efx, drv, efx->net_dev, "has been disabled\n");
  1571. efx->state = STATE_DISABLED;
  1572. } else {
  1573. netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
  1574. }
  1575. return rc;
  1576. }
  1577. /* The worker thread exists so that code that cannot sleep can
  1578. * schedule a reset for later.
  1579. */
  1580. static void efx_reset_work(struct work_struct *data)
  1581. {
  1582. struct efx_nic *efx = container_of(data, struct efx_nic, reset_work);
  1583. if (efx->reset_pending == RESET_TYPE_NONE)
  1584. return;
  1585. /* If we're not RUNNING then don't reset. Leave the reset_pending
  1586. * flag set so that efx_pci_probe_main will be retried */
  1587. if (efx->state != STATE_RUNNING) {
  1588. netif_info(efx, drv, efx->net_dev,
  1589. "scheduled reset quenched. NIC not RUNNING\n");
  1590. return;
  1591. }
  1592. rtnl_lock();
  1593. (void)efx_reset(efx, efx->reset_pending);
  1594. rtnl_unlock();
  1595. }
  1596. void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
  1597. {
  1598. enum reset_type method;
  1599. if (efx->reset_pending != RESET_TYPE_NONE) {
  1600. netif_info(efx, drv, efx->net_dev,
  1601. "quenching already scheduled reset\n");
  1602. return;
  1603. }
  1604. switch (type) {
  1605. case RESET_TYPE_INVISIBLE:
  1606. case RESET_TYPE_ALL:
  1607. case RESET_TYPE_WORLD:
  1608. case RESET_TYPE_DISABLE:
  1609. method = type;
  1610. break;
  1611. case RESET_TYPE_RX_RECOVERY:
  1612. case RESET_TYPE_RX_DESC_FETCH:
  1613. case RESET_TYPE_TX_DESC_FETCH:
  1614. case RESET_TYPE_TX_SKIP:
  1615. method = RESET_TYPE_INVISIBLE;
  1616. break;
  1617. case RESET_TYPE_MC_FAILURE:
  1618. default:
  1619. method = RESET_TYPE_ALL;
  1620. break;
  1621. }
  1622. if (method != type)
  1623. netif_dbg(efx, drv, efx->net_dev,
  1624. "scheduling %s reset for %s\n",
  1625. RESET_TYPE(method), RESET_TYPE(type));
  1626. else
  1627. netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
  1628. RESET_TYPE(method));
  1629. efx->reset_pending = method;
  1630. /* efx_process_channel() will no longer read events once a
  1631. * reset is scheduled. So switch back to poll'd MCDI completions. */
  1632. efx_mcdi_mode_poll(efx);
  1633. queue_work(reset_workqueue, &efx->reset_work);
  1634. }
  1635. /**************************************************************************
  1636. *
  1637. * List of NICs we support
  1638. *
  1639. **************************************************************************/
  1640. /* PCI device ID table */
  1641. static DEFINE_PCI_DEVICE_TABLE(efx_pci_table) = {
  1642. {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID),
  1643. .driver_data = (unsigned long) &falcon_a1_nic_type},
  1644. {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID),
  1645. .driver_data = (unsigned long) &falcon_b0_nic_type},
  1646. {PCI_DEVICE(EFX_VENDID_SFC, BETHPAGE_A_P_DEVID),
  1647. .driver_data = (unsigned long) &siena_a0_nic_type},
  1648. {PCI_DEVICE(EFX_VENDID_SFC, SIENA_A_P_DEVID),
  1649. .driver_data = (unsigned long) &siena_a0_nic_type},
  1650. {0} /* end of list */
  1651. };
  1652. /**************************************************************************
  1653. *
  1654. * Dummy PHY/MAC operations
  1655. *
  1656. * Can be used for some unimplemented operations
  1657. * Needed so all function pointers are valid and do not have to be tested
  1658. * before use
  1659. *
  1660. **************************************************************************/
  1661. int efx_port_dummy_op_int(struct efx_nic *efx)
  1662. {
  1663. return 0;
  1664. }
  1665. void efx_port_dummy_op_void(struct efx_nic *efx) {}
  1666. void efx_port_dummy_op_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  1667. {
  1668. }
  1669. bool efx_port_dummy_op_poll(struct efx_nic *efx)
  1670. {
  1671. return false;
  1672. }
  1673. static struct efx_phy_operations efx_dummy_phy_operations = {
  1674. .init = efx_port_dummy_op_int,
  1675. .reconfigure = efx_port_dummy_op_int,
  1676. .poll = efx_port_dummy_op_poll,
  1677. .fini = efx_port_dummy_op_void,
  1678. };
  1679. /**************************************************************************
  1680. *
  1681. * Data housekeeping
  1682. *
  1683. **************************************************************************/
  1684. /* This zeroes out and then fills in the invariants in a struct
  1685. * efx_nic (including all sub-structures).
  1686. */
  1687. static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
  1688. struct pci_dev *pci_dev, struct net_device *net_dev)
  1689. {
  1690. struct efx_channel *channel;
  1691. struct efx_tx_queue *tx_queue;
  1692. struct efx_rx_queue *rx_queue;
  1693. int i;
  1694. /* Initialise common structures */
  1695. memset(efx, 0, sizeof(*efx));
  1696. spin_lock_init(&efx->biu_lock);
  1697. mutex_init(&efx->mdio_lock);
  1698. mutex_init(&efx->spi_lock);
  1699. #ifdef CONFIG_SFC_MTD
  1700. INIT_LIST_HEAD(&efx->mtd_list);
  1701. #endif
  1702. INIT_WORK(&efx->reset_work, efx_reset_work);
  1703. INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
  1704. efx->pci_dev = pci_dev;
  1705. efx->msg_enable = debug;
  1706. efx->state = STATE_INIT;
  1707. efx->reset_pending = RESET_TYPE_NONE;
  1708. strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
  1709. efx->net_dev = net_dev;
  1710. efx->rx_checksum_enabled = true;
  1711. spin_lock_init(&efx->stats_lock);
  1712. mutex_init(&efx->mac_lock);
  1713. efx->mac_op = type->default_mac_ops;
  1714. efx->phy_op = &efx_dummy_phy_operations;
  1715. efx->mdio.dev = net_dev;
  1716. INIT_WORK(&efx->mac_work, efx_mac_work);
  1717. for (i = 0; i < EFX_MAX_CHANNELS; i++) {
  1718. channel = &efx->channel[i];
  1719. channel->efx = efx;
  1720. channel->channel = i;
  1721. channel->work_pending = false;
  1722. spin_lock_init(&channel->tx_stop_lock);
  1723. atomic_set(&channel->tx_stop_count, 1);
  1724. }
  1725. for (i = 0; i < EFX_MAX_TX_QUEUES; i++) {
  1726. tx_queue = &efx->tx_queue[i];
  1727. tx_queue->efx = efx;
  1728. tx_queue->queue = i;
  1729. tx_queue->buffer = NULL;
  1730. tx_queue->channel = &efx->channel[0]; /* for safety */
  1731. tx_queue->tso_headers_free = NULL;
  1732. }
  1733. for (i = 0; i < EFX_MAX_RX_QUEUES; i++) {
  1734. rx_queue = &efx->rx_queue[i];
  1735. rx_queue->efx = efx;
  1736. rx_queue->queue = i;
  1737. rx_queue->channel = &efx->channel[0]; /* for safety */
  1738. rx_queue->buffer = NULL;
  1739. setup_timer(&rx_queue->slow_fill, efx_rx_slow_fill,
  1740. (unsigned long)rx_queue);
  1741. }
  1742. efx->type = type;
  1743. /* As close as we can get to guaranteeing that we don't overflow */
  1744. BUILD_BUG_ON(EFX_EVQ_SIZE < EFX_TXQ_SIZE + EFX_RXQ_SIZE);
  1745. EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
  1746. /* Higher numbered interrupt modes are less capable! */
  1747. efx->interrupt_mode = max(efx->type->max_interrupt_mode,
  1748. interrupt_mode);
  1749. /* Would be good to use the net_dev name, but we're too early */
  1750. snprintf(efx->workqueue_name, sizeof(efx->workqueue_name), "sfc%s",
  1751. pci_name(pci_dev));
  1752. efx->workqueue = create_singlethread_workqueue(efx->workqueue_name);
  1753. if (!efx->workqueue)
  1754. return -ENOMEM;
  1755. return 0;
  1756. }
  1757. static void efx_fini_struct(struct efx_nic *efx)
  1758. {
  1759. if (efx->workqueue) {
  1760. destroy_workqueue(efx->workqueue);
  1761. efx->workqueue = NULL;
  1762. }
  1763. }
  1764. /**************************************************************************
  1765. *
  1766. * PCI interface
  1767. *
  1768. **************************************************************************/
  1769. /* Main body of final NIC shutdown code
  1770. * This is called only at module unload (or hotplug removal).
  1771. */
  1772. static void efx_pci_remove_main(struct efx_nic *efx)
  1773. {
  1774. efx_nic_fini_interrupt(efx);
  1775. efx_fini_channels(efx);
  1776. efx_fini_port(efx);
  1777. efx->type->fini(efx);
  1778. efx_fini_napi(efx);
  1779. efx_remove_all(efx);
  1780. }
  1781. /* Final NIC shutdown
  1782. * This is called only at module unload (or hotplug removal).
  1783. */
  1784. static void efx_pci_remove(struct pci_dev *pci_dev)
  1785. {
  1786. struct efx_nic *efx;
  1787. efx = pci_get_drvdata(pci_dev);
  1788. if (!efx)
  1789. return;
  1790. /* Mark the NIC as fini, then stop the interface */
  1791. rtnl_lock();
  1792. efx->state = STATE_FINI;
  1793. dev_close(efx->net_dev);
  1794. /* Allow any queued efx_resets() to complete */
  1795. rtnl_unlock();
  1796. efx_unregister_netdev(efx);
  1797. efx_mtd_remove(efx);
  1798. /* Wait for any scheduled resets to complete. No more will be
  1799. * scheduled from this point because efx_stop_all() has been
  1800. * called, we are no longer registered with driverlink, and
  1801. * the net_device's have been removed. */
  1802. cancel_work_sync(&efx->reset_work);
  1803. efx_pci_remove_main(efx);
  1804. efx_fini_io(efx);
  1805. netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
  1806. pci_set_drvdata(pci_dev, NULL);
  1807. efx_fini_struct(efx);
  1808. free_netdev(efx->net_dev);
  1809. };
  1810. /* Main body of NIC initialisation
  1811. * This is called at module load (or hotplug insertion, theoretically).
  1812. */
  1813. static int efx_pci_probe_main(struct efx_nic *efx)
  1814. {
  1815. int rc;
  1816. /* Do start-of-day initialisation */
  1817. rc = efx_probe_all(efx);
  1818. if (rc)
  1819. goto fail1;
  1820. rc = efx_init_napi(efx);
  1821. if (rc)
  1822. goto fail2;
  1823. rc = efx->type->init(efx);
  1824. if (rc) {
  1825. netif_err(efx, probe, efx->net_dev,
  1826. "failed to initialise NIC\n");
  1827. goto fail3;
  1828. }
  1829. rc = efx_init_port(efx);
  1830. if (rc) {
  1831. netif_err(efx, probe, efx->net_dev,
  1832. "failed to initialise port\n");
  1833. goto fail4;
  1834. }
  1835. efx_init_channels(efx);
  1836. rc = efx_nic_init_interrupt(efx);
  1837. if (rc)
  1838. goto fail5;
  1839. return 0;
  1840. fail5:
  1841. efx_fini_channels(efx);
  1842. efx_fini_port(efx);
  1843. fail4:
  1844. efx->type->fini(efx);
  1845. fail3:
  1846. efx_fini_napi(efx);
  1847. fail2:
  1848. efx_remove_all(efx);
  1849. fail1:
  1850. return rc;
  1851. }
  1852. /* NIC initialisation
  1853. *
  1854. * This is called at module load (or hotplug insertion,
  1855. * theoretically). It sets up PCI mappings, tests and resets the NIC,
  1856. * sets up and registers the network devices with the kernel and hooks
  1857. * the interrupt service routine. It does not prepare the device for
  1858. * transmission; this is left to the first time one of the network
  1859. * interfaces is brought up (i.e. efx_net_open).
  1860. */
  1861. static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
  1862. const struct pci_device_id *entry)
  1863. {
  1864. struct efx_nic_type *type = (struct efx_nic_type *) entry->driver_data;
  1865. struct net_device *net_dev;
  1866. struct efx_nic *efx;
  1867. int i, rc;
  1868. /* Allocate and initialise a struct net_device and struct efx_nic */
  1869. net_dev = alloc_etherdev_mq(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES);
  1870. if (!net_dev)
  1871. return -ENOMEM;
  1872. net_dev->features |= (type->offload_features | NETIF_F_SG |
  1873. NETIF_F_HIGHDMA | NETIF_F_TSO |
  1874. NETIF_F_GRO);
  1875. if (type->offload_features & NETIF_F_V6_CSUM)
  1876. net_dev->features |= NETIF_F_TSO6;
  1877. /* Mask for features that also apply to VLAN devices */
  1878. net_dev->vlan_features |= (NETIF_F_ALL_CSUM | NETIF_F_SG |
  1879. NETIF_F_HIGHDMA | NETIF_F_TSO);
  1880. efx = netdev_priv(net_dev);
  1881. pci_set_drvdata(pci_dev, efx);
  1882. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  1883. rc = efx_init_struct(efx, type, pci_dev, net_dev);
  1884. if (rc)
  1885. goto fail1;
  1886. netif_info(efx, probe, efx->net_dev,
  1887. "Solarflare Communications NIC detected\n");
  1888. /* Set up basic I/O (BAR mappings etc) */
  1889. rc = efx_init_io(efx);
  1890. if (rc)
  1891. goto fail2;
  1892. /* No serialisation is required with the reset path because
  1893. * we're in STATE_INIT. */
  1894. for (i = 0; i < 5; i++) {
  1895. rc = efx_pci_probe_main(efx);
  1896. /* Serialise against efx_reset(). No more resets will be
  1897. * scheduled since efx_stop_all() has been called, and we
  1898. * have not and never have been registered with either
  1899. * the rtnetlink or driverlink layers. */
  1900. cancel_work_sync(&efx->reset_work);
  1901. if (rc == 0) {
  1902. if (efx->reset_pending != RESET_TYPE_NONE) {
  1903. /* If there was a scheduled reset during
  1904. * probe, the NIC is probably hosed anyway */
  1905. efx_pci_remove_main(efx);
  1906. rc = -EIO;
  1907. } else {
  1908. break;
  1909. }
  1910. }
  1911. /* Retry if a recoverably reset event has been scheduled */
  1912. if ((efx->reset_pending != RESET_TYPE_INVISIBLE) &&
  1913. (efx->reset_pending != RESET_TYPE_ALL))
  1914. goto fail3;
  1915. efx->reset_pending = RESET_TYPE_NONE;
  1916. }
  1917. if (rc) {
  1918. netif_err(efx, probe, efx->net_dev, "Could not reset NIC\n");
  1919. goto fail4;
  1920. }
  1921. /* Switch to the running state before we expose the device to the OS,
  1922. * so that dev_open()|efx_start_all() will actually start the device */
  1923. efx->state = STATE_RUNNING;
  1924. rc = efx_register_netdev(efx);
  1925. if (rc)
  1926. goto fail5;
  1927. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  1928. rtnl_lock();
  1929. efx_mtd_probe(efx); /* allowed to fail */
  1930. rtnl_unlock();
  1931. return 0;
  1932. fail5:
  1933. efx_pci_remove_main(efx);
  1934. fail4:
  1935. fail3:
  1936. efx_fini_io(efx);
  1937. fail2:
  1938. efx_fini_struct(efx);
  1939. fail1:
  1940. WARN_ON(rc > 0);
  1941. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  1942. free_netdev(net_dev);
  1943. return rc;
  1944. }
  1945. static int efx_pm_freeze(struct device *dev)
  1946. {
  1947. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  1948. efx->state = STATE_FINI;
  1949. netif_device_detach(efx->net_dev);
  1950. efx_stop_all(efx);
  1951. efx_fini_channels(efx);
  1952. return 0;
  1953. }
  1954. static int efx_pm_thaw(struct device *dev)
  1955. {
  1956. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  1957. efx->state = STATE_INIT;
  1958. efx_init_channels(efx);
  1959. mutex_lock(&efx->mac_lock);
  1960. efx->phy_op->reconfigure(efx);
  1961. mutex_unlock(&efx->mac_lock);
  1962. efx_start_all(efx);
  1963. netif_device_attach(efx->net_dev);
  1964. efx->state = STATE_RUNNING;
  1965. efx->type->resume_wol(efx);
  1966. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  1967. queue_work(reset_workqueue, &efx->reset_work);
  1968. return 0;
  1969. }
  1970. static int efx_pm_poweroff(struct device *dev)
  1971. {
  1972. struct pci_dev *pci_dev = to_pci_dev(dev);
  1973. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  1974. efx->type->fini(efx);
  1975. efx->reset_pending = RESET_TYPE_NONE;
  1976. pci_save_state(pci_dev);
  1977. return pci_set_power_state(pci_dev, PCI_D3hot);
  1978. }
  1979. /* Used for both resume and restore */
  1980. static int efx_pm_resume(struct device *dev)
  1981. {
  1982. struct pci_dev *pci_dev = to_pci_dev(dev);
  1983. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  1984. int rc;
  1985. rc = pci_set_power_state(pci_dev, PCI_D0);
  1986. if (rc)
  1987. return rc;
  1988. pci_restore_state(pci_dev);
  1989. rc = pci_enable_device(pci_dev);
  1990. if (rc)
  1991. return rc;
  1992. pci_set_master(efx->pci_dev);
  1993. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  1994. if (rc)
  1995. return rc;
  1996. rc = efx->type->init(efx);
  1997. if (rc)
  1998. return rc;
  1999. efx_pm_thaw(dev);
  2000. return 0;
  2001. }
  2002. static int efx_pm_suspend(struct device *dev)
  2003. {
  2004. int rc;
  2005. efx_pm_freeze(dev);
  2006. rc = efx_pm_poweroff(dev);
  2007. if (rc)
  2008. efx_pm_resume(dev);
  2009. return rc;
  2010. }
  2011. static struct dev_pm_ops efx_pm_ops = {
  2012. .suspend = efx_pm_suspend,
  2013. .resume = efx_pm_resume,
  2014. .freeze = efx_pm_freeze,
  2015. .thaw = efx_pm_thaw,
  2016. .poweroff = efx_pm_poweroff,
  2017. .restore = efx_pm_resume,
  2018. };
  2019. static struct pci_driver efx_pci_driver = {
  2020. .name = KBUILD_MODNAME,
  2021. .id_table = efx_pci_table,
  2022. .probe = efx_pci_probe,
  2023. .remove = efx_pci_remove,
  2024. .driver.pm = &efx_pm_ops,
  2025. };
  2026. /**************************************************************************
  2027. *
  2028. * Kernel module interface
  2029. *
  2030. *************************************************************************/
  2031. module_param(interrupt_mode, uint, 0444);
  2032. MODULE_PARM_DESC(interrupt_mode,
  2033. "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
  2034. static int __init efx_init_module(void)
  2035. {
  2036. int rc;
  2037. printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
  2038. rc = register_netdevice_notifier(&efx_netdev_notifier);
  2039. if (rc)
  2040. goto err_notifier;
  2041. reset_workqueue = create_singlethread_workqueue("sfc_reset");
  2042. if (!reset_workqueue) {
  2043. rc = -ENOMEM;
  2044. goto err_reset;
  2045. }
  2046. rc = pci_register_driver(&efx_pci_driver);
  2047. if (rc < 0)
  2048. goto err_pci;
  2049. return 0;
  2050. err_pci:
  2051. destroy_workqueue(reset_workqueue);
  2052. err_reset:
  2053. unregister_netdevice_notifier(&efx_netdev_notifier);
  2054. err_notifier:
  2055. return rc;
  2056. }
  2057. static void __exit efx_exit_module(void)
  2058. {
  2059. printk(KERN_INFO "Solarflare NET driver unloading\n");
  2060. pci_unregister_driver(&efx_pci_driver);
  2061. destroy_workqueue(reset_workqueue);
  2062. unregister_netdevice_notifier(&efx_netdev_notifier);
  2063. }
  2064. module_init(efx_init_module);
  2065. module_exit(efx_exit_module);
  2066. MODULE_AUTHOR("Solarflare Communications and "
  2067. "Michael Brown <mbrown@fensystems.co.uk>");
  2068. MODULE_DESCRIPTION("Solarflare Communications network driver");
  2069. MODULE_LICENSE("GPL");
  2070. MODULE_DEVICE_TABLE(pci, efx_pci_table);