efx.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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/aer.h>
  21. #include <linux/interrupt.h>
  22. #include "net_driver.h"
  23. #include <net/gre.h>
  24. #include <net/udp_tunnel.h>
  25. #include "efx.h"
  26. #include "efx_common.h"
  27. #include "efx_channels.h"
  28. #include "ef100.h"
  29. #include "rx_common.h"
  30. #include "tx_common.h"
  31. #include "nic.h"
  32. #include "io.h"
  33. #include "selftest.h"
  34. #include "sriov.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);
  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. if (cmd == SIOCSHWTSTAMP)
  411. return efx_ptp_set_ts_config(efx, ifr);
  412. if (cmd == SIOCGHWTSTAMP)
  413. return efx_ptp_get_ts_config(efx, ifr);
  414. /* Convert phy_id from older PRTAD/DEVAD format */
  415. if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
  416. (data->phy_id & 0xfc00) == 0x0400)
  417. data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
  418. return mdio_mii_ioctl(&efx->mdio, data, cmd);
  419. }
  420. /**************************************************************************
  421. *
  422. * Kernel net device interface
  423. *
  424. *************************************************************************/
  425. /* Context: process, rtnl_lock() held. */
  426. int efx_net_open(struct net_device *net_dev)
  427. {
  428. struct efx_nic *efx = efx_netdev_priv(net_dev);
  429. int rc;
  430. netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
  431. raw_smp_processor_id());
  432. rc = efx_check_disabled(efx);
  433. if (rc)
  434. return rc;
  435. if (efx->phy_mode & PHY_MODE_SPECIAL)
  436. return -EBUSY;
  437. if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
  438. return -EIO;
  439. /* Notify the kernel of the link state polled during driver load,
  440. * before the monitor starts running */
  441. efx_link_status_changed(efx);
  442. efx_start_all(efx);
  443. if (efx->state == STATE_DISABLED || efx->reset_pending)
  444. netif_device_detach(efx->net_dev);
  445. else
  446. efx->state = STATE_NET_UP;
  447. return 0;
  448. }
  449. /* Context: process, rtnl_lock() held.
  450. * Note that the kernel will ignore our return code; this method
  451. * should really be a void.
  452. */
  453. int efx_net_stop(struct net_device *net_dev)
  454. {
  455. struct efx_nic *efx = efx_netdev_priv(net_dev);
  456. netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
  457. raw_smp_processor_id());
  458. /* Stop the device and flush all the channels */
  459. efx_stop_all(efx);
  460. return 0;
  461. }
  462. static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  463. {
  464. struct efx_nic *efx = efx_netdev_priv(net_dev);
  465. if (efx->type->vlan_rx_add_vid)
  466. return efx->type->vlan_rx_add_vid(efx, proto, vid);
  467. else
  468. return -EOPNOTSUPP;
  469. }
  470. static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
  471. {
  472. struct efx_nic *efx = efx_netdev_priv(net_dev);
  473. if (efx->type->vlan_rx_kill_vid)
  474. return efx->type->vlan_rx_kill_vid(efx, proto, vid);
  475. else
  476. return -EOPNOTSUPP;
  477. }
  478. static const struct net_device_ops efx_netdev_ops = {
  479. .ndo_open = efx_net_open,
  480. .ndo_stop = efx_net_stop,
  481. .ndo_get_stats64 = efx_net_stats,
  482. .ndo_tx_timeout = efx_watchdog,
  483. .ndo_start_xmit = efx_hard_start_xmit,
  484. .ndo_validate_addr = eth_validate_addr,
  485. .ndo_eth_ioctl = efx_ioctl,
  486. .ndo_change_mtu = efx_change_mtu,
  487. .ndo_set_mac_address = efx_set_mac_address,
  488. .ndo_set_rx_mode = efx_set_rx_mode,
  489. .ndo_set_features = efx_set_features,
  490. .ndo_features_check = efx_features_check,
  491. .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid,
  492. .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid,
  493. #ifdef CONFIG_SFC_SRIOV
  494. .ndo_set_vf_mac = efx_sriov_set_vf_mac,
  495. .ndo_set_vf_vlan = efx_sriov_set_vf_vlan,
  496. .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk,
  497. .ndo_get_vf_config = efx_sriov_get_vf_config,
  498. .ndo_set_vf_link_state = efx_sriov_set_vf_link_state,
  499. #endif
  500. .ndo_get_phys_port_id = efx_get_phys_port_id,
  501. .ndo_get_phys_port_name = efx_get_phys_port_name,
  502. .ndo_setup_tc = efx_setup_tc,
  503. #ifdef CONFIG_RFS_ACCEL
  504. .ndo_rx_flow_steer = efx_filter_rfs,
  505. #endif
  506. .ndo_xdp_xmit = efx_xdp_xmit,
  507. .ndo_bpf = efx_xdp
  508. };
  509. static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
  510. {
  511. struct bpf_prog *old_prog;
  512. if (efx->xdp_rxq_info_failed) {
  513. netif_err(efx, drv, efx->net_dev,
  514. "Unable to bind XDP program due to previous failure of rxq_info\n");
  515. return -EINVAL;
  516. }
  517. if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) {
  518. netif_err(efx, drv, efx->net_dev,
  519. "Unable to configure XDP with MTU of %d (max: %d)\n",
  520. efx->net_dev->mtu, efx_xdp_max_mtu(efx));
  521. return -EINVAL;
  522. }
  523. old_prog = rtnl_dereference(efx->xdp_prog);
  524. rcu_assign_pointer(efx->xdp_prog, prog);
  525. /* Release the reference that was originally passed by the caller. */
  526. if (old_prog)
  527. bpf_prog_put(old_prog);
  528. return 0;
  529. }
  530. /* Context: process, rtnl_lock() held. */
  531. static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
  532. {
  533. struct efx_nic *efx = efx_netdev_priv(dev);
  534. switch (xdp->command) {
  535. case XDP_SETUP_PROG:
  536. return efx_xdp_setup_prog(efx, xdp->prog);
  537. default:
  538. return -EINVAL;
  539. }
  540. }
  541. static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
  542. u32 flags)
  543. {
  544. struct efx_nic *efx = efx_netdev_priv(dev);
  545. if (!netif_running(dev))
  546. return -EINVAL;
  547. return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
  548. }
  549. static void efx_update_name(struct efx_nic *efx)
  550. {
  551. strcpy(efx->name, efx->net_dev->name);
  552. efx_mtd_rename(efx);
  553. efx_set_channel_names(efx);
  554. }
  555. static int efx_netdev_event(struct notifier_block *this,
  556. unsigned long event, void *ptr)
  557. {
  558. struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
  559. if ((net_dev->netdev_ops == &efx_netdev_ops) &&
  560. event == NETDEV_CHANGENAME)
  561. efx_update_name(efx_netdev_priv(net_dev));
  562. return NOTIFY_DONE;
  563. }
  564. static struct notifier_block efx_netdev_notifier = {
  565. .notifier_call = efx_netdev_event,
  566. };
  567. static ssize_t phy_type_show(struct device *dev,
  568. struct device_attribute *attr, char *buf)
  569. {
  570. struct efx_nic *efx = dev_get_drvdata(dev);
  571. return sprintf(buf, "%d\n", efx->phy_type);
  572. }
  573. static DEVICE_ATTR_RO(phy_type);
  574. static int efx_register_netdev(struct efx_nic *efx)
  575. {
  576. struct net_device *net_dev = efx->net_dev;
  577. struct efx_channel *channel;
  578. int rc;
  579. net_dev->watchdog_timeo = 5 * HZ;
  580. net_dev->irq = efx->pci_dev->irq;
  581. net_dev->netdev_ops = &efx_netdev_ops;
  582. if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
  583. net_dev->priv_flags |= IFF_UNICAST_FLT;
  584. net_dev->ethtool_ops = &efx_ethtool_ops;
  585. netif_set_tso_max_segs(net_dev, EFX_TSO_MAX_SEGS);
  586. net_dev->min_mtu = EFX_MIN_MTU;
  587. net_dev->max_mtu = EFX_MAX_MTU;
  588. rtnl_lock();
  589. /* Enable resets to be scheduled and check whether any were
  590. * already requested. If so, the NIC is probably hosed so we
  591. * abort.
  592. */
  593. if (efx->reset_pending) {
  594. pci_err(efx->pci_dev, "aborting probe due to scheduled reset\n");
  595. rc = -EIO;
  596. goto fail_locked;
  597. }
  598. rc = dev_alloc_name(net_dev, net_dev->name);
  599. if (rc < 0)
  600. goto fail_locked;
  601. efx_update_name(efx);
  602. /* Always start with carrier off; PHY events will detect the link */
  603. netif_carrier_off(net_dev);
  604. rc = register_netdevice(net_dev);
  605. if (rc)
  606. goto fail_locked;
  607. efx_for_each_channel(channel, efx) {
  608. struct efx_tx_queue *tx_queue;
  609. efx_for_each_channel_tx_queue(tx_queue, channel)
  610. efx_init_tx_queue_core_txq(tx_queue);
  611. }
  612. efx_associate(efx);
  613. efx->state = STATE_NET_DOWN;
  614. rtnl_unlock();
  615. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  616. if (rc) {
  617. netif_err(efx, drv, efx->net_dev,
  618. "failed to init net dev attributes\n");
  619. goto fail_registered;
  620. }
  621. efx_init_mcdi_logging(efx);
  622. return 0;
  623. fail_registered:
  624. rtnl_lock();
  625. efx_dissociate(efx);
  626. unregister_netdevice(net_dev);
  627. fail_locked:
  628. efx->state = STATE_UNINIT;
  629. rtnl_unlock();
  630. netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
  631. return rc;
  632. }
  633. static void efx_unregister_netdev(struct efx_nic *efx)
  634. {
  635. if (!efx->net_dev)
  636. return;
  637. if (WARN_ON(efx_netdev_priv(efx->net_dev) != efx))
  638. return;
  639. if (efx_dev_registered(efx)) {
  640. strscpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
  641. efx_fini_mcdi_logging(efx);
  642. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
  643. unregister_netdev(efx->net_dev);
  644. }
  645. }
  646. /**************************************************************************
  647. *
  648. * List of NICs we support
  649. *
  650. **************************************************************************/
  651. /* PCI device ID table */
  652. static const struct pci_device_id efx_pci_table[] = {
  653. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */
  654. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  655. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */
  656. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  657. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */
  658. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  659. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */
  660. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  661. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */
  662. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  663. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */
  664. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  665. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03), /* SFC9250 PF */
  666. .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
  667. {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03), /* SFC9250 VF */
  668. .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
  669. {0} /* end of list */
  670. };
  671. /**************************************************************************
  672. *
  673. * Data housekeeping
  674. *
  675. **************************************************************************/
  676. void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
  677. {
  678. u64 n_rx_nodesc_trunc = 0;
  679. struct efx_channel *channel;
  680. efx_for_each_channel(channel, efx)
  681. n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
  682. stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
  683. stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
  684. }
  685. /**************************************************************************
  686. *
  687. * PCI interface
  688. *
  689. **************************************************************************/
  690. /* Main body of final NIC shutdown code
  691. * This is called only at module unload (or hotplug removal).
  692. */
  693. static void efx_pci_remove_main(struct efx_nic *efx)
  694. {
  695. /* Flush reset_work. It can no longer be scheduled since we
  696. * are not READY.
  697. */
  698. WARN_ON(efx_net_active(efx->state));
  699. efx_flush_reset_workqueue(efx);
  700. efx_disable_interrupts(efx);
  701. efx_clear_interrupt_affinity(efx);
  702. efx_nic_fini_interrupt(efx);
  703. efx_fini_port(efx);
  704. efx->type->fini(efx);
  705. efx_fini_napi(efx);
  706. efx_remove_all(efx);
  707. }
  708. /* Final NIC shutdown
  709. * This is called only at module unload (or hotplug removal). A PF can call
  710. * this on its VFs to ensure they are unbound first.
  711. */
  712. static void efx_pci_remove(struct pci_dev *pci_dev)
  713. {
  714. struct efx_probe_data *probe_data;
  715. struct efx_nic *efx;
  716. efx = pci_get_drvdata(pci_dev);
  717. if (!efx)
  718. return;
  719. /* Mark the NIC as fini, then stop the interface */
  720. rtnl_lock();
  721. efx_dissociate(efx);
  722. dev_close(efx->net_dev);
  723. efx_disable_interrupts(efx);
  724. efx->state = STATE_UNINIT;
  725. rtnl_unlock();
  726. if (efx->type->sriov_fini)
  727. efx->type->sriov_fini(efx);
  728. efx_unregister_netdev(efx);
  729. efx_mtd_remove(efx);
  730. efx_pci_remove_main(efx);
  731. efx_fini_io(efx);
  732. pci_dbg(efx->pci_dev, "shutdown successful\n");
  733. efx_fini_struct(efx);
  734. free_netdev(efx->net_dev);
  735. probe_data = container_of(efx, struct efx_probe_data, efx);
  736. kfree(probe_data);
  737. pci_disable_pcie_error_reporting(pci_dev);
  738. };
  739. /* NIC VPD information
  740. * Called during probe to display the part number of the
  741. * installed NIC.
  742. */
  743. static void efx_probe_vpd_strings(struct efx_nic *efx)
  744. {
  745. struct pci_dev *dev = efx->pci_dev;
  746. unsigned int vpd_size, kw_len;
  747. u8 *vpd_data;
  748. int start;
  749. vpd_data = pci_vpd_alloc(dev, &vpd_size);
  750. if (IS_ERR(vpd_data)) {
  751. pci_warn(dev, "Unable to read VPD\n");
  752. return;
  753. }
  754. start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
  755. PCI_VPD_RO_KEYWORD_PARTNO, &kw_len);
  756. if (start < 0)
  757. pci_err(dev, "Part number not found or incomplete\n");
  758. else
  759. pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start);
  760. start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size,
  761. PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len);
  762. if (start < 0)
  763. pci_err(dev, "Serial number not found or incomplete\n");
  764. else
  765. efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL);
  766. kfree(vpd_data);
  767. }
  768. /* Main body of NIC initialisation
  769. * This is called at module load (or hotplug insertion, theoretically).
  770. */
  771. static int efx_pci_probe_main(struct efx_nic *efx)
  772. {
  773. int rc;
  774. /* Do start-of-day initialisation */
  775. rc = efx_probe_all(efx);
  776. if (rc)
  777. goto fail1;
  778. efx_init_napi(efx);
  779. down_write(&efx->filter_sem);
  780. rc = efx->type->init(efx);
  781. up_write(&efx->filter_sem);
  782. if (rc) {
  783. pci_err(efx->pci_dev, "failed to initialise NIC\n");
  784. goto fail3;
  785. }
  786. rc = efx_init_port(efx);
  787. if (rc) {
  788. netif_err(efx, probe, efx->net_dev,
  789. "failed to initialise port\n");
  790. goto fail4;
  791. }
  792. rc = efx_nic_init_interrupt(efx);
  793. if (rc)
  794. goto fail5;
  795. efx_set_interrupt_affinity(efx);
  796. rc = efx_enable_interrupts(efx);
  797. if (rc)
  798. goto fail6;
  799. return 0;
  800. fail6:
  801. efx_clear_interrupt_affinity(efx);
  802. efx_nic_fini_interrupt(efx);
  803. fail5:
  804. efx_fini_port(efx);
  805. fail4:
  806. efx->type->fini(efx);
  807. fail3:
  808. efx_fini_napi(efx);
  809. efx_remove_all(efx);
  810. fail1:
  811. return rc;
  812. }
  813. static int efx_pci_probe_post_io(struct efx_nic *efx)
  814. {
  815. struct net_device *net_dev = efx->net_dev;
  816. int rc = efx_pci_probe_main(efx);
  817. if (rc)
  818. return rc;
  819. if (efx->type->sriov_init) {
  820. rc = efx->type->sriov_init(efx);
  821. if (rc)
  822. pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n",
  823. rc);
  824. }
  825. /* Determine netdevice features */
  826. net_dev->features |= efx->type->offload_features;
  827. /* Add TSO features */
  828. if (efx->type->tso_versions && efx->type->tso_versions(efx))
  829. net_dev->features |= NETIF_F_TSO | NETIF_F_TSO6;
  830. /* Mask for features that also apply to VLAN devices */
  831. net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
  832. NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
  833. NETIF_F_RXCSUM);
  834. /* Determine user configurable features */
  835. net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
  836. /* Disable receiving frames with bad FCS, by default. */
  837. net_dev->features &= ~NETIF_F_RXALL;
  838. /* Disable VLAN filtering by default. It may be enforced if
  839. * the feature is fixed (i.e. VLAN filters are required to
  840. * receive VLAN tagged packets due to vPort restrictions).
  841. */
  842. net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  843. net_dev->features |= efx->fixed_features;
  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 efx_probe_data *probe_data, **probe_ptr;
  863. struct net_device *net_dev;
  864. struct efx_nic *efx;
  865. int rc;
  866. /* Allocate probe data and struct efx_nic */
  867. probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL);
  868. if (!probe_data)
  869. return -ENOMEM;
  870. probe_data->pci_dev = pci_dev;
  871. efx = &probe_data->efx;
  872. /* Allocate and initialise a struct net_device */
  873. net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES);
  874. if (!net_dev) {
  875. rc = -ENOMEM;
  876. goto fail0;
  877. }
  878. probe_ptr = netdev_priv(net_dev);
  879. *probe_ptr = probe_data;
  880. efx->net_dev = net_dev;
  881. efx->type = (const struct efx_nic_type *) entry->driver_data;
  882. efx->fixed_features |= NETIF_F_HIGHDMA;
  883. pci_set_drvdata(pci_dev, efx);
  884. SET_NETDEV_DEV(net_dev, &pci_dev->dev);
  885. rc = efx_init_struct(efx, pci_dev);
  886. if (rc)
  887. goto fail1;
  888. efx->mdio.dev = net_dev;
  889. pci_info(pci_dev, "Solarflare NIC detected\n");
  890. if (!efx->type->is_vf)
  891. efx_probe_vpd_strings(efx);
  892. /* Set up basic I/O (BAR mappings etc) */
  893. rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask,
  894. efx->type->mem_map_size(efx));
  895. if (rc)
  896. goto fail2;
  897. rc = efx_pci_probe_post_io(efx);
  898. if (rc) {
  899. /* On failure, retry once immediately.
  900. * If we aborted probe due to a scheduled reset, dismiss it.
  901. */
  902. efx->reset_pending = 0;
  903. rc = efx_pci_probe_post_io(efx);
  904. if (rc) {
  905. /* On another failure, retry once more
  906. * after a 50-305ms delay.
  907. */
  908. unsigned char r;
  909. get_random_bytes(&r, 1);
  910. msleep((unsigned int)r + 50);
  911. efx->reset_pending = 0;
  912. rc = efx_pci_probe_post_io(efx);
  913. }
  914. }
  915. if (rc)
  916. goto fail3;
  917. netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
  918. /* Try to create MTDs, but allow this to fail */
  919. rtnl_lock();
  920. rc = efx_mtd_probe(efx);
  921. rtnl_unlock();
  922. if (rc && rc != -EPERM)
  923. netif_warn(efx, probe, efx->net_dev,
  924. "failed to create MTDs (%d)\n", rc);
  925. (void)pci_enable_pcie_error_reporting(pci_dev);
  926. if (efx->type->udp_tnl_push_ports)
  927. efx->type->udp_tnl_push_ports(efx);
  928. return 0;
  929. fail3:
  930. efx_fini_io(efx);
  931. fail2:
  932. efx_fini_struct(efx);
  933. fail1:
  934. WARN_ON(rc > 0);
  935. netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
  936. free_netdev(net_dev);
  937. fail0:
  938. kfree(probe_data);
  939. return rc;
  940. }
  941. /* efx_pci_sriov_configure returns the actual number of Virtual Functions
  942. * enabled on success
  943. */
  944. #ifdef CONFIG_SFC_SRIOV
  945. static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
  946. {
  947. int rc;
  948. struct efx_nic *efx = pci_get_drvdata(dev);
  949. if (efx->type->sriov_configure) {
  950. rc = efx->type->sriov_configure(efx, num_vfs);
  951. if (rc)
  952. return rc;
  953. else
  954. return num_vfs;
  955. } else
  956. return -EOPNOTSUPP;
  957. }
  958. #endif
  959. static int efx_pm_freeze(struct device *dev)
  960. {
  961. struct efx_nic *efx = dev_get_drvdata(dev);
  962. rtnl_lock();
  963. if (efx_net_active(efx->state)) {
  964. efx_device_detach_sync(efx);
  965. efx_stop_all(efx);
  966. efx_disable_interrupts(efx);
  967. efx->state = efx_freeze(efx->state);
  968. }
  969. rtnl_unlock();
  970. return 0;
  971. }
  972. static void efx_pci_shutdown(struct pci_dev *pci_dev)
  973. {
  974. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  975. if (!efx)
  976. return;
  977. efx_pm_freeze(&pci_dev->dev);
  978. pci_disable_device(pci_dev);
  979. }
  980. static int efx_pm_thaw(struct device *dev)
  981. {
  982. int rc;
  983. struct efx_nic *efx = dev_get_drvdata(dev);
  984. rtnl_lock();
  985. if (efx_frozen(efx->state)) {
  986. rc = efx_enable_interrupts(efx);
  987. if (rc)
  988. goto fail;
  989. mutex_lock(&efx->mac_lock);
  990. efx_mcdi_port_reconfigure(efx);
  991. mutex_unlock(&efx->mac_lock);
  992. efx_start_all(efx);
  993. efx_device_attach_if_not_resetting(efx);
  994. efx->state = efx_thaw(efx->state);
  995. efx->type->resume_wol(efx);
  996. }
  997. rtnl_unlock();
  998. /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
  999. efx_queue_reset_work(efx);
  1000. return 0;
  1001. fail:
  1002. rtnl_unlock();
  1003. return rc;
  1004. }
  1005. static int efx_pm_poweroff(struct device *dev)
  1006. {
  1007. struct pci_dev *pci_dev = to_pci_dev(dev);
  1008. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  1009. efx->type->fini(efx);
  1010. efx->reset_pending = 0;
  1011. pci_save_state(pci_dev);
  1012. return pci_set_power_state(pci_dev, PCI_D3hot);
  1013. }
  1014. /* Used for both resume and restore */
  1015. static int efx_pm_resume(struct device *dev)
  1016. {
  1017. struct pci_dev *pci_dev = to_pci_dev(dev);
  1018. struct efx_nic *efx = pci_get_drvdata(pci_dev);
  1019. int rc;
  1020. rc = pci_set_power_state(pci_dev, PCI_D0);
  1021. if (rc)
  1022. return rc;
  1023. pci_restore_state(pci_dev);
  1024. rc = pci_enable_device(pci_dev);
  1025. if (rc)
  1026. return rc;
  1027. pci_set_master(efx->pci_dev);
  1028. rc = efx->type->reset(efx, RESET_TYPE_ALL);
  1029. if (rc)
  1030. return rc;
  1031. down_write(&efx->filter_sem);
  1032. rc = efx->type->init(efx);
  1033. up_write(&efx->filter_sem);
  1034. if (rc)
  1035. return rc;
  1036. rc = efx_pm_thaw(dev);
  1037. return rc;
  1038. }
  1039. static int efx_pm_suspend(struct device *dev)
  1040. {
  1041. int rc;
  1042. efx_pm_freeze(dev);
  1043. rc = efx_pm_poweroff(dev);
  1044. if (rc)
  1045. efx_pm_resume(dev);
  1046. return rc;
  1047. }
  1048. static const struct dev_pm_ops efx_pm_ops = {
  1049. .suspend = efx_pm_suspend,
  1050. .resume = efx_pm_resume,
  1051. .freeze = efx_pm_freeze,
  1052. .thaw = efx_pm_thaw,
  1053. .poweroff = efx_pm_poweroff,
  1054. .restore = efx_pm_resume,
  1055. };
  1056. static struct pci_driver efx_pci_driver = {
  1057. .name = KBUILD_MODNAME,
  1058. .id_table = efx_pci_table,
  1059. .probe = efx_pci_probe,
  1060. .remove = efx_pci_remove,
  1061. .driver.pm = &efx_pm_ops,
  1062. .shutdown = efx_pci_shutdown,
  1063. .err_handler = &efx_err_handlers,
  1064. #ifdef CONFIG_SFC_SRIOV
  1065. .sriov_configure = efx_pci_sriov_configure,
  1066. #endif
  1067. };
  1068. /**************************************************************************
  1069. *
  1070. * Kernel module interface
  1071. *
  1072. *************************************************************************/
  1073. static int __init efx_init_module(void)
  1074. {
  1075. int rc;
  1076. printk(KERN_INFO "Solarflare NET driver\n");
  1077. rc = register_netdevice_notifier(&efx_netdev_notifier);
  1078. if (rc)
  1079. goto err_notifier;
  1080. rc = efx_create_reset_workqueue();
  1081. if (rc)
  1082. goto err_reset;
  1083. rc = pci_register_driver(&efx_pci_driver);
  1084. if (rc < 0)
  1085. goto err_pci;
  1086. rc = pci_register_driver(&ef100_pci_driver);
  1087. if (rc < 0)
  1088. goto err_pci_ef100;
  1089. return 0;
  1090. err_pci_ef100:
  1091. pci_unregister_driver(&efx_pci_driver);
  1092. err_pci:
  1093. efx_destroy_reset_workqueue();
  1094. err_reset:
  1095. unregister_netdevice_notifier(&efx_netdev_notifier);
  1096. err_notifier:
  1097. return rc;
  1098. }
  1099. static void __exit efx_exit_module(void)
  1100. {
  1101. printk(KERN_INFO "Solarflare NET driver unloading\n");
  1102. pci_unregister_driver(&ef100_pci_driver);
  1103. pci_unregister_driver(&efx_pci_driver);
  1104. efx_destroy_reset_workqueue();
  1105. unregister_netdevice_notifier(&efx_netdev_notifier);
  1106. }
  1107. module_init(efx_init_module);
  1108. module_exit(efx_exit_module);
  1109. MODULE_AUTHOR("Solarflare Communications and "
  1110. "Michael Brown <[email protected]>");
  1111. MODULE_DESCRIPTION("Solarflare network driver");
  1112. MODULE_LICENSE("GPL");
  1113. MODULE_DEVICE_TABLE(pci, efx_pci_table);