efx.c 34 KB

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