efx.c 66 KB

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