efx.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2005-2006 Fen Systems Ltd.
  5. * Copyright 2005-2013 Solarflare Communications Inc.
  6. */
  7. #include <linux/filter.h>
  8. #include <linux/module.h>
  9. #include <linux/pci.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/delay.h>
  13. #include <linux/notifier.h>
  14. #include <linux/ip.h>
  15. #include <linux/tcp.h>
  16. #include <linux/in.h>
  17. #include <linux/ethtool.h>
  18. #include <linux/topology.h>
  19. #include <linux/gfp.h>
  20. #include <linux/interrupt.h>
  21. #include "net_driver.h"
  22. #include <net/gre.h>
  23. #include <net/udp_tunnel.h>
  24. #include "efx.h"
  25. #include "efx_common.h"
  26. #include "efx_channels.h"
  27. #include "rx_common.h"
  28. #include "tx_common.h"
  29. #include "nic.h"
  30. #include "io.h"
  31. #include "selftest.h"
  32. #include "sriov.h"
  33. #ifdef CONFIG_SFC_SIENA_SRIOV
  34. #include "siena_sriov.h"
  35. #endif
  36. #include "mcdi_port_common.h"
  37. #include "mcdi_pcol.h"
  38. #include "workarounds.h"
  39. /**************************************************************************
  40. *
  41. * Configurable values
  42. *
  43. *************************************************************************/
  44. module_param_named(interrupt_mode, efx_siena_interrupt_mode, uint, 0444);
  45. MODULE_PARM_DESC(interrupt_mode,
  46. "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
  47. module_param_named(rss_cpus, efx_siena_rss_cpus, uint, 0444);
  48. MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
  49. /*
  50. * Use separate channels for TX and RX events
  51. *
  52. * Set this to 1 to use separate channels for TX and RX. It allows us
  53. * to control interrupt affinity separately for TX and RX.
  54. *
  55. * This is only used in MSI-X interrupt mode
  56. */
  57. bool efx_siena_separate_tx_channels;
  58. module_param_named(efx_separate_tx_channels, efx_siena_separate_tx_channels,
  59. bool, 0444);
  60. MODULE_PARM_DESC(efx_separate_tx_channels,
  61. "Use separate channels for TX and RX");
  62. /* Initial interrupt moderation settings. They can be modified after
  63. * module load with ethtool.
  64. *
  65. * The default for RX should strike a balance between increasing the
  66. * round-trip latency and reducing overhead.
  67. */
  68. static unsigned int rx_irq_mod_usec = 60;
  69. /* Initial interrupt moderation settings. They can be modified after
  70. * module load with ethtool.
  71. *
  72. * This default is chosen to ensure that a 10G link does not go idle
  73. * while a TX queue is stopped after it has become full. A queue is
  74. * restarted when it drops below half full. The time this takes (assuming
  75. * worst case 3 descriptors per packet and 1024 descriptors) is
  76. * 512 / 3 * 1.2 = 205 usec.
  77. */
  78. static unsigned int tx_irq_mod_usec = 150;
  79. static bool phy_flash_cfg;
  80. module_param(phy_flash_cfg, bool, 0644);
  81. MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
  82. static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
  83. NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
  84. NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
  85. NETIF_MSG_TX_ERR | NETIF_MSG_HW);
  86. module_param(debug, uint, 0);
  87. MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
  88. /**************************************************************************
  89. *
  90. * Utility functions and prototypes
  91. *
  92. *************************************************************************/
  93. static void efx_remove_port(struct efx_nic *efx);
  94. static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog);
  95. static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp);
  96. static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
  97. u32 flags);
  98. #define EFX_ASSERT_RESET_SERIALISED(efx) \
  99. do { \
  100. if ((efx->state == STATE_READY) || \
  101. (efx->state == STATE_RECOVERY) || \
  102. (efx->state == STATE_DISABLED)) \
  103. ASSERT_RTNL(); \
  104. } while (0)
  105. /**************************************************************************
  106. *
  107. * Port handling
  108. *
  109. **************************************************************************/
  110. static void efx_fini_port(struct efx_nic *efx);
  111. static int efx_probe_port(struct efx_nic *efx)
  112. {
  113. int rc;
  114. netif_dbg(efx, probe, efx->net_dev, "create port\n");
  115. if (phy_flash_cfg)
  116. efx->phy_mode = PHY_MODE_SPECIAL;
  117. /* Connect up MAC/PHY operations table */
  118. rc = efx->type->probe_port(efx);
  119. if (rc)
  120. return rc;
  121. /* Initialise MAC address to permanent address */
  122. eth_hw_addr_set(efx->net_dev, efx->net_dev->perm_addr);
  123. return 0;
  124. }
  125. static int efx_init_port(struct efx_nic *efx)
  126. {
  127. int rc;
  128. netif_dbg(efx, drv, efx->net_dev, "init port\n");
  129. mutex_lock(&efx->mac_lock);
  130. efx->port_initialized = true;
  131. /* Ensure the PHY advertises the correct flow control settings */
  132. rc = efx_siena_mcdi_port_reconfigure(efx);
  133. if (rc && rc != -EPERM)
  134. goto fail;
  135. mutex_unlock(&efx->mac_lock);
  136. return 0;
  137. fail:
  138. mutex_unlock(&efx->mac_lock);
  139. return rc;
  140. }
  141. static void efx_fini_port(struct efx_nic *efx)
  142. {
  143. netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
  144. if (!efx->port_initialized)
  145. return;
  146. efx->port_initialized = false;
  147. efx->link_state.up = false;
  148. efx_siena_link_status_changed(efx);
  149. }
  150. static void efx_remove_port(struct efx_nic *efx)
  151. {
  152. netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
  153. efx->type->remove_port(efx);
  154. }
  155. /**************************************************************************
  156. *
  157. * NIC handling
  158. *
  159. **************************************************************************/
  160. static LIST_HEAD(efx_primary_list);
  161. static LIST_HEAD(efx_unassociated_list);
  162. static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
  163. {
  164. return left->type == right->type &&
  165. left->vpd_sn && right->vpd_sn &&
  166. !strcmp(left->vpd_sn, right->vpd_sn);
  167. }
  168. static void efx_associate(struct efx_nic *efx)
  169. {
  170. struct efx_nic *other, *next;
  171. if (efx->primary == efx) {
  172. /* Adding primary function; look for secondaries */
  173. netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
  174. list_add_tail(&efx->node, &efx_primary_list);
  175. list_for_each_entry_safe(other, next, &efx_unassociated_list,
  176. node) {
  177. if (efx_same_controller(efx, other)) {
  178. list_del(&other->node);
  179. netif_dbg(other, probe, other->net_dev,
  180. "moving to secondary list of %s %s\n",
  181. pci_name(efx->pci_dev),
  182. efx->net_dev->name);
  183. list_add_tail(&other->node,
  184. &efx->secondary_list);
  185. other->primary = efx;
  186. }
  187. }
  188. } else {
  189. /* Adding secondary function; look for primary */
  190. list_for_each_entry(other, &efx_primary_list, node) {
  191. if (efx_same_controller(efx, other)) {
  192. netif_dbg(efx, probe, efx->net_dev,
  193. "adding to secondary list of %s %s\n",
  194. pci_name(other->pci_dev),
  195. other->net_dev->name);
  196. list_add_tail(&efx->node,
  197. &other->secondary_list);
  198. efx->primary = other;
  199. return;
  200. }
  201. }
  202. netif_dbg(efx, probe, efx->net_dev,
  203. "adding to unassociated list\n");
  204. list_add_tail(&efx->node, &efx_unassociated_list);
  205. }
  206. }
  207. static void efx_dissociate(struct efx_nic *efx)
  208. {
  209. struct efx_nic *other, *next;
  210. list_del(&efx->node);
  211. efx->primary = NULL;
  212. list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
  213. list_del(&other->node);
  214. netif_dbg(other, probe, other->net_dev,
  215. "moving to unassociated list\n");
  216. list_add_tail(&other->node, &efx_unassociated_list);
  217. other->primary = NULL;
  218. }
  219. }
  220. static int efx_probe_nic(struct efx_nic *efx)
  221. {
  222. int rc;
  223. netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
  224. /* Carry out hardware-type specific initialisation */
  225. rc = efx->type->probe(efx);
  226. if (rc)
  227. return rc;
  228. do {
  229. if (!efx->max_channels || !efx->max_tx_channels) {
  230. netif_err(efx, drv, efx->net_dev,
  231. "Insufficient resources to allocate"
  232. " any channels\n");
  233. rc = -ENOSPC;
  234. goto fail1;
  235. }
  236. /* Determine the number of channels and queues by trying
  237. * to hook in MSI-X interrupts.
  238. */
  239. rc = efx_siena_probe_interrupts(efx);
  240. if (rc)
  241. goto fail1;
  242. rc = efx_siena_set_channels(efx);
  243. if (rc)
  244. goto fail1;
  245. /* dimension_resources can fail with EAGAIN */
  246. rc = efx->type->dimension_resources(efx);
  247. if (rc != 0 && rc != -EAGAIN)
  248. goto fail2;
  249. if (rc == -EAGAIN)
  250. /* try again with new max_channels */
  251. efx_siena_remove_interrupts(efx);
  252. } while (rc == -EAGAIN);
  253. if (efx->n_channels > 1)
  254. netdev_rss_key_fill(efx->rss_context.rx_hash_key,
  255. sizeof(efx->rss_context.rx_hash_key));
  256. efx_siena_set_default_rx_indir_table(efx, &efx->rss_context);
  257. /* Initialise the interrupt moderation settings */
  258. efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
  259. efx_siena_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec,
  260. true, true);
  261. return 0;
  262. fail2:
  263. efx_siena_remove_interrupts(efx);
  264. fail1:
  265. efx->type->remove(efx);
  266. return rc;
  267. }
  268. static void efx_remove_nic(struct efx_nic *efx)
  269. {
  270. netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
  271. efx_siena_remove_interrupts(efx);
  272. efx->type->remove(efx);
  273. }
  274. /**************************************************************************
  275. *
  276. * NIC startup/shutdown
  277. *
  278. *************************************************************************/
  279. static int efx_probe_all(struct efx_nic *efx)
  280. {
  281. int rc;
  282. rc = efx_probe_nic(efx);
  283. if (rc) {
  284. netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
  285. goto fail1;
  286. }
  287. rc = efx_probe_port(efx);
  288. if (rc) {
  289. netif_err(efx, probe, efx->net_dev, "failed to create port\n");
  290. goto fail2;
  291. }
  292. BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
  293. if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
  294. rc = -EINVAL;
  295. goto fail3;
  296. }
  297. #ifdef CONFIG_SFC_SIENA_SRIOV
  298. rc = efx->type->vswitching_probe(efx);
  299. if (rc) /* not fatal; the PF will still work fine */
  300. netif_warn(efx, probe, efx->net_dev,
  301. "failed to setup vswitching rc=%d;"
  302. " VFs may not function\n", rc);
  303. #endif
  304. rc = efx_siena_probe_filters(efx);
  305. if (rc) {
  306. netif_err(efx, probe, efx->net_dev,
  307. "failed to create filter tables\n");
  308. goto fail4;
  309. }
  310. rc = efx_siena_probe_channels(efx);
  311. if (rc)
  312. goto fail5;
  313. return 0;
  314. fail5:
  315. efx_siena_remove_filters(efx);
  316. fail4:
  317. #ifdef CONFIG_SFC_SIENA_SRIOV
  318. efx->type->vswitching_remove(efx);
  319. #endif
  320. fail3:
  321. efx_remove_port(efx);
  322. fail2:
  323. efx_remove_nic(efx);
  324. fail1:
  325. return rc;
  326. }
  327. static void efx_remove_all(struct efx_nic *efx)
  328. {
  329. rtnl_lock();
  330. efx_xdp_setup_prog(efx, NULL);
  331. rtnl_unlock();
  332. efx_siena_remove_channels(efx);
  333. efx_siena_remove_filters(efx);
  334. #ifdef CONFIG_SFC_SIENA_SRIOV
  335. efx->type->vswitching_remove(efx);
  336. #endif
  337. efx_remove_port(efx);
  338. efx_remove_nic(efx);
  339. }
  340. /**************************************************************************
  341. *
  342. * Interrupt moderation
  343. *
  344. **************************************************************************/
  345. unsigned int efx_siena_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
  346. {
  347. if (usecs == 0)
  348. return 0;
  349. if (usecs * 1000 < efx->timer_quantum_ns)
  350. return 1; /* never round down to 0 */
  351. return usecs * 1000 / efx->timer_quantum_ns;
  352. }
  353. /* Set interrupt moderation parameters */
  354. int efx_siena_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
  355. unsigned int rx_usecs, bool rx_adaptive,
  356. bool rx_may_override_tx)
  357. {
  358. struct efx_channel *channel;
  359. unsigned int timer_max_us;
  360. EFX_ASSERT_RESET_SERIALISED(efx);
  361. timer_max_us = efx->timer_max_ns / 1000;
  362. if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
  363. return -EINVAL;
  364. if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
  365. !rx_may_override_tx) {
  366. netif_err(efx, drv, efx->net_dev, "Channels are shared. "
  367. "RX and TX IRQ moderation must be equal\n");
  368. return -EINVAL;
  369. }
  370. efx->irq_rx_adaptive = rx_adaptive;
  371. efx->irq_rx_moderation_us = rx_usecs;
  372. efx_for_each_channel(channel, efx) {
  373. if (efx_channel_has_rx_queue(channel))
  374. channel->irq_moderation_us = rx_usecs;
  375. else if (efx_channel_has_tx_queues(channel))
  376. channel->irq_moderation_us = tx_usecs;
  377. else if (efx_channel_is_xdp_tx(channel))
  378. channel->irq_moderation_us = tx_usecs;
  379. }
  380. return 0;
  381. }
  382. void efx_siena_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
  383. unsigned int *rx_usecs, bool *rx_adaptive)
  384. {
  385. *rx_adaptive = efx->irq_rx_adaptive;
  386. *rx_usecs = efx->irq_rx_moderation_us;
  387. /* If channels are shared between RX and TX, so is IRQ
  388. * moderation. Otherwise, IRQ moderation is the same for all
  389. * TX channels and is not adaptive.
  390. */
  391. if (efx->tx_channel_offset == 0) {
  392. *tx_usecs = *rx_usecs;
  393. } else {
  394. struct efx_channel *tx_channel;
  395. tx_channel = efx->channel[efx->tx_channel_offset];
  396. *tx_usecs = tx_channel->irq_moderation_us;
  397. }
  398. }
  399. /**************************************************************************
  400. *
  401. * ioctls
  402. *
  403. *************************************************************************/
  404. /* Net device ioctl
  405. * Context: process, rtnl_lock() held.
  406. */
  407. static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
  408. {
  409. struct efx_nic *efx = netdev_priv(net_dev);
  410. struct mii_ioctl_data *data = if_mii(ifr);
  411. /* Convert phy_id from older PRTAD/DEVAD format */
  412. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  413. (data->phy_id & 0xfc00) == 0x0400)
  414. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  415. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  416. }
  417. /**************************************************************************
  418. *
  419. * Kernel net device interface
  420. *
  421. *************************************************************************/
  422. /* Context: process, rtnl_lock() held. */
  423. static int efx_net_open(struct net_device *net_dev)
  424. {
  425. struct efx_nic *efx = netdev_priv(net_dev);
  426. int rc;
  427. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  428. raw_smp_processor_id());
  429. rc = efx_check_disabled(efx);
  430. if (rc)
  431. return rc;
  432. if (efx->phy_mode & PHY_MODE_SPECIAL)
  433. return -EBUSY;
  434. if (efx_siena_mcdi_poll_reboot(efx) && efx_siena_reset(efx, RESET_TYPE_ALL))
  435. return -EIO;
  436. /* Notify the kernel of the link state polled during driver load,
  437. * before the monitor starts running */
  438. efx_siena_link_status_changed(efx);
  439. efx_siena_start_all(efx);
  440. if (efx->state == STATE_DISABLED || efx->reset_pending)
  441. netif_device_detach(efx->net_dev);
  442. efx_siena_selftest_async_start(efx);
  443. return 0;
  444. }
  445. /* Context: process, rtnl_lock() held.
  446. * Note that the kernel will ignore our return code; this method
  447. * should really be a void.
  448. */
  449. static int efx_net_stop(struct net_device *net_dev)
  450. {
  451. struct efx_nic *efx = netdev_priv(net_dev);
  452. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  453. raw_smp_processor_id());
  454. /* Stop the device and flush all the channels */
  455. efx_siena_stop_all(efx);
  456. return 0;
  457. }
  458. static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  459. {
  460. struct efx_nic *efx = netdev_priv(net_dev);
  461. if (efx->type->vlan_rx_add_vid)
  462. return efx->type->vlan_rx_add_vid(efx, proto, vid);
  463. else
  464. return -EOPNOTSUPP;
  465. }
  466. static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  467. {
  468. struct efx_nic *efx = netdev_priv(net_dev);
  469. if (efx->type->vlan_rx_kill_vid)
  470. return efx->type->vlan_rx_kill_vid(efx, proto, vid);
  471. else
  472. return -EOPNOTSUPP;
  473. }
  474. static int efx_siena_hwtstamp_set(struct net_device *net_dev,
  475. struct kernel_hwtstamp_config *config,
  476. struct netlink_ext_ack *extack)
  477. {
  478. struct efx_nic *efx = netdev_priv(net_dev);
  479. return efx_siena_ptp_set_ts_config(efx, config, extack);
  480. }
  481. static int efx_siena_hwtstamp_get(struct net_device *net_dev,
  482. struct kernel_hwtstamp_config *config)
  483. {
  484. struct efx_nic *efx = netdev_priv(net_dev);
  485. return efx_siena_ptp_get_ts_config(efx, config);
  486. }
  487. static const struct net_device_ops efx_netdev_ops = {
  488. .ndo_open = efx_net_open,
  489. .ndo_stop = efx_net_stop,
  490. .ndo_get_stats64 = efx_siena_net_stats,
  491. .ndo_tx_timeout = efx_siena_watchdog,
  492. .ndo_start_xmit = efx_siena_hard_start_xmit,
  493. .ndo_validate_addr = eth_validate_addr,
  494. .ndo_eth_ioctl = efx_ioctl,
  495. .ndo_change_mtu = efx_siena_change_mtu,
  496. .ndo_set_mac_address = efx_siena_set_mac_address,
  497. .ndo_set_rx_mode = efx_siena_set_rx_mode,
  498. .ndo_set_features = efx_siena_set_features,
  499. .ndo_features_check = efx_siena_features_check,
  500. .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
  501. .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
  502. .ndo_hwtstamp_set = efx_siena_hwtstamp_set,
  503. .ndo_hwtstamp_get = efx_siena_hwtstamp_get,
  504. #ifdef CONFIG_SFC_SIENA_SRIOV
  505. .ndo_set_vf_mac = efx_sriov_set_vf_mac,
  506. .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
  507. .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
  508. .ndo_get_vf_config = efx_sriov_get_vf_config,
  509. .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
  510. #endif
  511. .ndo_get_phys_port_id = efx_siena_get_phys_port_id,
  512. .ndo_get_phys_port_name = efx_siena_get_phys_port_name,
  513. .ndo_setup_tc = efx_siena_setup_tc,
  514. #ifdef CONFIG_RFS_ACCEL
  515. .ndo_rx_flow_steer = efx_siena_filter_rfs,
  516. #endif
  517. .ndo_xdp_xmit = efx_xdp_xmit,
  518. .ndo_bpf = efx_xdp
  519. };
  520. static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
  521. {
  522. struct bpf_prog *old_prog;
  523. if (efx->xdp_rxq_info_failed) {
  524. netif_err(efx, drv, efx->net_dev,
  525. "Unable to bind XDP program due to previous failure of rxq_info\n");
  526. return -EINVAL;
  527. }
  528. if (prog && efx->net_dev->mtu > efx_siena_xdp_max_mtu(efx)) {
  529. netif_err(efx, drv, efx->net_dev,
  530. "Unable to configure XDP with MTU of %d (max: %d)\n",
  531. efx->net_dev->mtu, efx_siena_xdp_max_mtu(efx));
  532. return -EINVAL;
  533. }
  534. old_prog = rtnl_dereference(efx->xdp_prog);
  535. rcu_assign_pointer(efx->xdp_prog, prog);
  536. /* Release the reference that was originally passed by the caller. */
  537. if (old_prog)
  538. bpf_prog_put(old_prog);
  539. return 0;
  540. }
  541. /* Context: process, rtnl_lock() held. */
  542. static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
  543. {
  544. struct efx_nic *efx = netdev_priv(dev);
  545. switch (xdp->command) {
  546. case XDP_SETUP_PROG:
  547. return efx_xdp_setup_prog(efx, xdp->prog);
  548. default:
  549. return -EINVAL;
  550. }
  551. }
  552. static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
  553. u32 flags)
  554. {
  555. struct efx_nic *efx = netdev_priv(dev);
  556. if (!netif_running(dev))
  557. return -EINVAL;
  558. return efx_siena_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
  559. }
  560. static void efx_update_name(struct efx_nic *efx)
  561. {
  562. strcpy(efx->name, efx->net_dev->name);
  563. efx_siena_mtd_rename(efx);
  564. efx_siena_set_channel_names(efx);
  565. }
  566. static int efx_netdev_event(struct notifier_block *this,
  567. unsigned long event, void *ptr)
  568. {
  569. struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
  570. if ((net_dev->netdev_ops == &efx_netdev_ops) &&
  571. event == NETDEV_CHANGENAME)
  572. efx_update_name(netdev_priv(net_dev));
  573. return NOTIFY_DONE;
  574. }
  575. static struct notifier_block efx_netdev_notifier = {
  576. .notifier_call = efx_netdev_event,
  577. };
  578. static ssize_t phy_type_show(struct device *dev,
  579. struct device_attribute *attr, char *buf)
  580. {
  581. struct efx_nic *efx = dev_get_drvdata(dev);
  582. return sprintf(buf, "%d\n", efx->phy_type);
  583. }
  584. static DEVICE_ATTR_RO(phy_type);
  585. static int efx_register_netdev(struct efx_nic *efx)
  586. {
  587. struct net_device *net_dev = efx->net_dev;
  588. struct efx_channel *channel;
  589. int rc;
  590. net_dev->watchdog_timeo = 5 * HZ;
  591. net_dev->irq = efx->pci_dev->irq;
  592. net_dev->netdev_ops = &efx_netdev_ops;
  593. if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
  594. net_dev->priv_flags |= IFF_UNICAST_FLT;
  595. net_dev->ethtool_ops = &efx_siena_ethtool_ops;
  596. netif_set_tso_max_segs(net_dev, EFX_TSO_MAX_SEGS);
  597. net_dev->min_mtu = EFX_MIN_MTU;
  598. net_dev->max_mtu = EFX_MAX_MTU;
  599. rtnl_lock();
  600. /* Enable resets to be scheduled and check whether any were
  601. * already requested. If so, the NIC is probably hosed so we
  602. * abort.
  603. */
  604. efx->state = STATE_READY;
  605. smp_mb(); /* ensure we change state before checking reset_pending */
  606. if (efx->reset_pending) {
  607. pci_err(efx->pci_dev, "aborting probe due to scheduled reset\n");
  608. rc = -EIO;
  609. goto fail_locked;
  610. }
  611. rc = dev_alloc_name(net_dev, net_dev->name);
  612. if (rc < 0)
  613. goto fail_locked;
  614. efx_update_name(efx);
  615. /* Always start with carrier off; PHY events will detect the link */
  616. netif_carrier_off(net_dev);
  617. rc = register_netdevice(net_dev);
  618. if (rc)
  619. goto fail_locked;
  620. efx_for_each_channel(channel, efx) {
  621. struct efx_tx_queue *tx_queue;
  622. efx_for_each_channel_tx_queue(tx_queue, channel)
  623. efx_siena_init_tx_queue_core_txq(tx_queue);
  624. }
  625. efx_associate(efx);
  626. rtnl_unlock();
  627. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  628. if (rc) {
  629. netif_err(efx, drv, efx->net_dev,
  630. "failed to init net dev attributes\n");
  631. goto fail_registered;
  632. }
  633. efx_siena_init_mcdi_logging(efx);
  634. return 0;
  635. fail_registered:
  636. rtnl_lock();
  637. efx_dissociate(efx);
  638. unregister_netdevice(net_dev);
  639. fail_locked:
  640. efx->state = STATE_UNINIT;
  641. rtnl_unlock();
  642. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  643. return rc;
  644. }
  645. static void efx_unregister_netdev(struct efx_nic *efx)
  646. {
  647. if (!efx->net_dev)
  648. return;
  649. BUG_ON(netdev_priv(efx->net_dev) != efx);
  650. if (efx_dev_registered(efx)) {
  651. strscpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  652. efx_siena_fini_mcdi_logging(efx);
  653. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  654. unregister_netdev(efx->net_dev);
  655. }
  656. }
  657. /**************************************************************************
  658. *
  659. * List of NICs we support
  660. *
  661. **************************************************************************/
  662. /* PCI device ID table */
  663. static const struct pci_device_id efx_pci_table[] = {
  664. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803), /* SFC9020 */
  665. .driver_data = (unsigned long)&siena_a0_nic_type},
  666. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813), /* SFL9021 */
  667. .driver_data = (unsigned long)&siena_a0_nic_type},
  668. {0} /* end of list */
  669. };
  670. /**************************************************************************
  671. *
  672. * Data housekeeping
  673. *
  674. **************************************************************************/
  675. void efx_siena_update_sw_stats(struct efx_nic *efx, u64 *stats)
  676. {
  677. u64 n_rx_nodesc_trunc = 0;
  678. struct efx_channel *channel;
  679. efx_for_each_channel(channel, efx)
  680. n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
  681. stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
  682. stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
  683. }
  684. /**************************************************************************
  685. *
  686. * PCI interface
  687. *
  688. **************************************************************************/
  689. /* Main body of final NIC shutdown code
  690. * This is called only at module unload (or hotplug removal).
  691. */
  692. static void efx_pci_remove_main(struct efx_nic *efx)
  693. {
  694. /* Flush reset_work. It can no longer be scheduled since we
  695. * are not READY.
  696. */
  697. BUG_ON(efx->state == STATE_READY);
  698. efx_siena_flush_reset_workqueue(efx);
  699. efx_siena_disable_interrupts(efx);
  700. efx_siena_clear_interrupt_affinity(efx);
  701. efx_siena_fini_interrupt(efx);
  702. efx_fini_port(efx);
  703. efx->type->fini(efx);
  704. efx_siena_fini_napi(efx);
  705. efx_remove_all(efx);
  706. }
  707. /* Final NIC shutdown
  708. * This is called only at module unload (or hotplug removal). A PF can call
  709. * this on its VFs to ensure they are unbound first.
  710. */
  711. static void efx_pci_remove(struct pci_dev *pci_dev)
  712. {
  713. struct efx_nic *efx;
  714. efx = pci_get_drvdata(pci_dev);
  715. if (!efx)
  716. return;
  717. /* Mark the NIC as fini, then stop the interface */
  718. rtnl_lock();
  719. efx_dissociate(efx);
  720. dev_close(efx->net_dev);
  721. efx_siena_disable_interrupts(efx);
  722. efx->state = STATE_UNINIT;
  723. rtnl_unlock();
  724. if (efx->type->sriov_fini)
  725. efx->type->sriov_fini(efx);
  726. efx_unregister_netdev(efx);
  727. efx_siena_mtd_remove(efx);
  728. efx_pci_remove_main(efx);
  729. efx_siena_fini_io(efx);
  730. netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
  731. efx_siena_fini_struct(efx);
  732. free_netdev(efx->net_dev);
  733. };
  734. /* NIC VPD information
  735. * Called during probe to display the part number of the
  736. * installed NIC.
  737. */
  738. static void efx_probe_vpd_strings(struct efx_nic *efx)
  739. {
  740. struct pci_dev *dev = efx->pci_dev;
  741. unsigned int vpd_size, kw_len;
  742. u8 *vpd_data;
  743. int start;
  744. vpd_data = pci_vpd_alloc(dev, &vpd_size);
  745. if (IS_ERR(vpd_data)) {
  746. pci_warn(dev, "Unable to read VPD\n");
  747. return;
  748. }
  749. start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
  750. PCI_VPD_RO_KEYWORD_PARTNO, &kw_len);
  751. if (start < 0)
  752. pci_err(dev, "Part number not found or incomplete\n");
  753. else
  754. pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start);
  755. start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
  756. PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len);
  757. if (start < 0)
  758. pci_err(dev, "Serial number not found or incomplete\n");
  759. else
  760. efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL);
  761. kfree(vpd_data);
  762. }
  763. /* Main body of NIC initialisation
  764. * This is called at module load (or hotplug insertion, theoretically).
  765. */
  766. static int efx_pci_probe_main(struct efx_nic *efx)
  767. {
  768. int rc;
  769. /* Do start-of-day initialisation */
  770. rc = efx_probe_all(efx);
  771. if (rc)
  772. goto fail1;
  773. efx_siena_init_napi(efx);
  774. down_write(&efx->filter_sem);
  775. rc = efx->type->init(efx);
  776. up_write(&efx->filter_sem);
  777. if (rc) {
  778. pci_err(efx->pci_dev, "failed to initialise NIC\n");
  779. goto fail3;
  780. }
  781. rc = efx_init_port(efx);
  782. if (rc) {
  783. netif_err(efx, probe, efx->net_dev,
  784. "failed to initialise port\n");
  785. goto fail4;
  786. }
  787. rc = efx_siena_init_interrupt(efx);
  788. if (rc)
  789. goto fail5;
  790. efx_siena_set_interrupt_affinity(efx);
  791. rc = efx_siena_enable_interrupts(efx);
  792. if (rc)
  793. goto fail6;
  794. return 0;
  795. fail6:
  796. efx_siena_clear_interrupt_affinity(efx);
  797. efx_siena_fini_interrupt(efx);
  798. fail5:
  799. efx_fini_port(efx);
  800. fail4:
  801. efx->type->fini(efx);
  802. fail3:
  803. efx_siena_fini_napi(efx);
  804. efx_remove_all(efx);
  805. fail1:
  806. return rc;
  807. }
  808. static int efx_pci_probe_post_io(struct efx_nic *efx)
  809. {
  810. struct net_device *net_dev = efx->net_dev;
  811. int rc = efx_pci_probe_main(efx);
  812. if (rc)
  813. return rc;
  814. if (efx->type->sriov_init) {
  815. rc = efx->type->sriov_init(efx);
  816. if (rc)
  817. pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n",
  818. rc);
  819. }
  820. /* Determine netdevice features */
  821. net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
  822. NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
  823. if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
  824. net_dev->features |= NETIF_F_TSO6;
  825. /* Check whether device supports TSO */
  826. if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
  827. net_dev->features &= ~NETIF_F_ALL_TSO;
  828. /* Mask for features that also apply to VLAN devices */
  829. net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
  830. NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
  831. NETIF_F_RXCSUM);
  832. net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
  833. /* Disable receiving frames with bad FCS, by default. */
  834. net_dev->features &= ~NETIF_F_RXALL;
  835. /* Disable VLAN filtering by default. It may be enforced if
  836. * the feature is fixed (i.e. VLAN filters are required to
  837. * receive VLAN tagged packets due to vPort restrictions).
  838. */
  839. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  840. net_dev->features |= efx->fixed_features;
  841. net_dev->xdp_features = NETDEV_XDP_ACT_BASIC |
  842. NETDEV_XDP_ACT_REDIRECT |
  843. NETDEV_XDP_ACT_NDO_XMIT;
  844. rc = efx_register_netdev(efx);
  845. if (!rc)
  846. return 0;
  847. efx_pci_remove_main(efx);
  848. return rc;
  849. }
  850. /* NIC initialisation
  851. *
  852. * This is called at module load (or hotplug insertion,
  853. * theoretically). It sets up PCI mappings, resets the NIC,
  854. * sets up and registers the network devices with the kernel and hooks
  855. * the interrupt service routine. It does not prepare the device for
  856. * transmission; this is left to the first time one of the network
  857. * interfaces is brought up (i.e. efx_net_open).
  858. */
  859. static int efx_pci_probe(struct pci_dev *pci_dev,
  860. const struct pci_device_id *entry)
  861. {
  862. struct net_device *net_dev;
  863. struct efx_nic *efx;
  864. int rc;
  865. /* Allocate and initialise a struct net_device and struct efx_nic */
  866. net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
  867. EFX_MAX_RX_QUEUES);
  868. if (!net_dev)
  869. return -ENOMEM;
  870. efx = netdev_priv(net_dev);
  871. efx->type = (const struct efx_nic_type *) entry->driver_data;
  872. efx->fixed_features |= NETIF_F_HIGHDMA;
  873. pci_set_drvdata(pci_dev, efx);
  874. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  875. rc = efx_siena_init_struct(efx, pci_dev, net_dev);
  876. if (rc)
  877. goto fail1;
  878. pci_info(pci_dev, "Solarflare NIC detected\n");
  879. if (!efx->type->is_vf)
  880. efx_probe_vpd_strings(efx);
  881. /* Set up basic I/O (BAR mappings etc) */
  882. rc = efx_siena_init_io(efx, efx->type->mem_bar(efx),
  883. efx->type->max_dma_mask,
  884. efx->type->mem_map_size(efx));
  885. if (rc)
  886. goto fail2;
  887. rc = efx_pci_probe_post_io(efx);
  888. if (rc) {
  889. /* On failure, retry once immediately.
  890. * If we aborted probe due to a scheduled reset, dismiss it.
  891. */
  892. efx->reset_pending = 0;
  893. rc = efx_pci_probe_post_io(efx);
  894. if (rc) {
  895. /* On another failure, retry once more
  896. * after a 50-305ms delay.
  897. */
  898. unsigned char r;
  899. get_random_bytes(&r, 1);
  900. msleep((unsigned int)r + 50);
  901. efx->reset_pending = 0;
  902. rc = efx_pci_probe_post_io(efx);
  903. }
  904. }
  905. if (rc)
  906. goto fail3;
  907. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  908. /* Try to create MTDs, but allow this to fail */
  909. rtnl_lock();
  910. rc = efx_mtd_probe(efx);
  911. rtnl_unlock();
  912. if (rc && rc != -EPERM)
  913. netif_warn(efx, probe, efx->net_dev,
  914. "failed to create MTDs (%d)\n", rc);
  915. if (efx->type->udp_tnl_push_ports)
  916. efx->type->udp_tnl_push_ports(efx);
  917. return 0;
  918. fail3:
  919. efx_siena_fini_io(efx);
  920. fail2:
  921. efx_siena_fini_struct(efx);
  922. fail1:
  923. WARN_ON(rc > 0);
  924. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  925. free_netdev(net_dev);
  926. return rc;
  927. }
  928. /* efx_pci_sriov_configure returns the actual number of Virtual Functions
  929. * enabled on success
  930. */
  931. #ifdef CONFIG_SFC_SIENA_SRIOV
  932. static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
  933. {
  934. int rc;
  935. struct efx_nic *efx = pci_get_drvdata(dev);
  936. if (efx->type->sriov_configure) {
  937. rc = efx->type->sriov_configure(efx, num_vfs);
  938. if (rc)
  939. return rc;
  940. else
  941. return num_vfs;
  942. } else
  943. return -EOPNOTSUPP;
  944. }
  945. #endif
  946. static int efx_pm_freeze(struct device *dev)
  947. {
  948. struct efx_nic *efx = dev_get_drvdata(dev);
  949. rtnl_lock();
  950. if (efx->state != STATE_DISABLED) {
  951. efx->state = STATE_UNINIT;
  952. efx_device_detach_sync(efx);
  953. efx_siena_stop_all(efx);
  954. efx_siena_disable_interrupts(efx);
  955. }
  956. rtnl_unlock();
  957. return 0;
  958. }
  959. static void efx_pci_shutdown(struct pci_dev *pci_dev)
  960. {
  961. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  962. if (!efx)
  963. return;
  964. efx_pm_freeze(&pci_dev->dev);
  965. pci_disable_device(pci_dev);
  966. }
  967. static int efx_pm_thaw(struct device *dev)
  968. {
  969. int rc;
  970. struct efx_nic *efx = dev_get_drvdata(dev);
  971. rtnl_lock();
  972. if (efx->state != STATE_DISABLED) {
  973. rc = efx_siena_enable_interrupts(efx);
  974. if (rc)
  975. goto fail;
  976. mutex_lock(&efx->mac_lock);
  977. efx_siena_mcdi_port_reconfigure(efx);
  978. mutex_unlock(&efx->mac_lock);
  979. efx_siena_start_all(efx);
  980. efx_device_attach_if_not_resetting(efx);
  981. efx->state = STATE_READY;
  982. efx->type->resume_wol(efx);
  983. }
  984. rtnl_unlock();
  985. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  986. efx_siena_queue_reset_work(efx);
  987. return 0;
  988. fail:
  989. rtnl_unlock();
  990. return rc;
  991. }
  992. static int efx_pm_poweroff(struct device *dev)
  993. {
  994. struct pci_dev *pci_dev = to_pci_dev(dev);
  995. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  996. efx->type->fini(efx);
  997. efx->reset_pending = 0;
  998. pci_save_state(pci_dev);
  999. return pci_set_power_state(pci_dev, PCI_D3hot);
  1000. }
  1001. /* Used for both resume and restore */
  1002. static int efx_pm_resume(struct device *dev)
  1003. {
  1004. struct pci_dev *pci_dev = to_pci_dev(dev);
  1005. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  1006. int rc;
  1007. rc = pci_set_power_state(pci_dev, PCI_D0);
  1008. if (rc)
  1009. return rc;
  1010. pci_restore_state(pci_dev);
  1011. rc = pci_enable_device(pci_dev);
  1012. if (rc)
  1013. return rc;
  1014. pci_set_master(efx->pci_dev);
  1015. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  1016. if (rc)
  1017. return rc;
  1018. down_write(&efx->filter_sem);
  1019. rc = efx->type->init(efx);
  1020. up_write(&efx->filter_sem);
  1021. if (rc)
  1022. return rc;
  1023. rc = efx_pm_thaw(dev);
  1024. return rc;
  1025. }
  1026. static int efx_pm_suspend(struct device *dev)
  1027. {
  1028. int rc;
  1029. efx_pm_freeze(dev);
  1030. rc = efx_pm_poweroff(dev);
  1031. if (rc)
  1032. efx_pm_resume(dev);
  1033. return rc;
  1034. }
  1035. static const struct dev_pm_ops efx_pm_ops = {
  1036. .suspend = efx_pm_suspend,
  1037. .resume = efx_pm_resume,
  1038. .freeze = efx_pm_freeze,
  1039. .thaw = efx_pm_thaw,
  1040. .poweroff = efx_pm_poweroff,
  1041. .restore = efx_pm_resume,
  1042. };
  1043. static struct pci_driver efx_pci_driver = {
  1044. .name = KBUILD_MODNAME,
  1045. .id_table = efx_pci_table,
  1046. .probe = efx_pci_probe,
  1047. .remove = efx_pci_remove,
  1048. .driver.pm = &efx_pm_ops,
  1049. .shutdown = efx_pci_shutdown,
  1050. .err_handler = &efx_siena_err_handlers,
  1051. #ifdef CONFIG_SFC_SIENA_SRIOV
  1052. .sriov_configure = efx_pci_sriov_configure,
  1053. #endif
  1054. };
  1055. /**************************************************************************
  1056. *
  1057. * Kernel module interface
  1058. *
  1059. *************************************************************************/
  1060. static int __init efx_init_module(void)
  1061. {
  1062. int rc;
  1063. pr_info("Solarflare Siena driver\n");
  1064. rc = register_netdevice_notifier(&efx_netdev_notifier);
  1065. if (rc)
  1066. goto err_notifier;
  1067. #ifdef CONFIG_SFC_SIENA_SRIOV
  1068. rc = efx_init_sriov();
  1069. if (rc)
  1070. goto err_sriov;
  1071. #endif
  1072. rc = efx_siena_create_reset_workqueue();
  1073. if (rc)
  1074. goto err_reset;
  1075. rc = pci_register_driver(&efx_pci_driver);
  1076. if (rc < 0)
  1077. goto err_pci;
  1078. return 0;
  1079. err_pci:
  1080. efx_siena_destroy_reset_workqueue();
  1081. err_reset:
  1082. #ifdef CONFIG_SFC_SIENA_SRIOV
  1083. efx_fini_sriov();
  1084. err_sriov:
  1085. #endif
  1086. unregister_netdevice_notifier(&efx_netdev_notifier);
  1087. err_notifier:
  1088. return rc;
  1089. }
  1090. static void __exit efx_exit_module(void)
  1091. {
  1092. pr_info("Solarflare Siena driver unloading\n");
  1093. pci_unregister_driver(&efx_pci_driver);
  1094. efx_siena_destroy_reset_workqueue();
  1095. #ifdef CONFIG_SFC_SIENA_SRIOV
  1096. efx_fini_sriov();
  1097. #endif
  1098. unregister_netdevice_notifier(&efx_netdev_notifier);
  1099. }
  1100. module_init(efx_init_module);
  1101. module_exit(efx_exit_module);
  1102. MODULE_AUTHOR("Solarflare Communications and "
  1103. "Michael Brown <mbrown@fensystems.co.uk>");
  1104. MODULE_DESCRIPTION("Solarflare Siena network driver");
  1105. MODULE_LICENSE("GPL");
  1106. MODULE_DEVICE_TABLE(pci, efx_pci_table);