]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/ethernet/sfc/efx.c
sfc: move MCDI logging device attribute
[linux.git] / drivers / net / ethernet / sfc / efx.c
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
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 "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
35 #include "mcdi.h"
36 #include "mcdi_pcol.h"
37 #include "workarounds.h"
38
39 /**************************************************************************
40  *
41  * Type name strings
42  *
43  **************************************************************************
44  */
45
46 /* UDP tunnel type names */
47 static const char *const efx_udp_tunnel_type_names[] = {
48         [TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan",
49         [TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve",
50 };
51
52 void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen)
53 {
54         if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) &&
55             efx_udp_tunnel_type_names[type] != NULL)
56                 snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]);
57         else
58                 snprintf(buf, buflen, "type %d", type);
59 }
60
61 /**************************************************************************
62  *
63  * Configurable values
64  *
65  *************************************************************************/
66
67 /*
68  * Use separate channels for TX and RX events
69  *
70  * Set this to 1 to use separate channels for TX and RX. It allows us
71  * to control interrupt affinity separately for TX and RX.
72  *
73  * This is only used in MSI-X interrupt mode
74  */
75 bool efx_separate_tx_channels;
76 module_param(efx_separate_tx_channels, bool, 0444);
77 MODULE_PARM_DESC(efx_separate_tx_channels,
78                  "Use separate channels for TX and RX");
79
80 /* Initial interrupt moderation settings.  They can be modified after
81  * module load with ethtool.
82  *
83  * The default for RX should strike a balance between increasing the
84  * round-trip latency and reducing overhead.
85  */
86 static unsigned int rx_irq_mod_usec = 60;
87
88 /* Initial interrupt moderation settings.  They can be modified after
89  * module load with ethtool.
90  *
91  * This default is chosen to ensure that a 10G link does not go idle
92  * while a TX queue is stopped after it has become full.  A queue is
93  * restarted when it drops below half full.  The time this takes (assuming
94  * worst case 3 descriptors per packet and 1024 descriptors) is
95  *   512 / 3 * 1.2 = 205 usec.
96  */
97 static unsigned int tx_irq_mod_usec = 150;
98
99 static bool phy_flash_cfg;
100 module_param(phy_flash_cfg, bool, 0644);
101 MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");
102
103 static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
104                          NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
105                          NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
106                          NETIF_MSG_TX_ERR | NETIF_MSG_HW);
107 module_param(debug, uint, 0);
108 MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");
109
110 /**************************************************************************
111  *
112  * Utility functions and prototypes
113  *
114  *************************************************************************/
115
116 static const struct efx_channel_type efx_default_channel_type;
117 static void efx_remove_port(struct efx_nic *efx);
118 static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog);
119 static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp);
120 static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
121                         u32 flags);
122
123 #define EFX_ASSERT_RESET_SERIALISED(efx)                \
124         do {                                            \
125                 if ((efx->state == STATE_READY) ||      \
126                     (efx->state == STATE_RECOVERY) ||   \
127                     (efx->state == STATE_DISABLED))     \
128                         ASSERT_RTNL();                  \
129         } while (0)
130
131 /**************************************************************************
132  *
133  * Port handling
134  *
135  **************************************************************************/
136
137 /* Equivalent to efx_link_set_advertising with all-zeroes, except does not
138  * force the Autoneg bit on.
139  */
140 void efx_link_clear_advertising(struct efx_nic *efx)
141 {
142         bitmap_zero(efx->link_advertising, __ETHTOOL_LINK_MODE_MASK_NBITS);
143         efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
144 }
145
146 void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
147 {
148         efx->wanted_fc = wanted_fc;
149         if (efx->link_advertising[0]) {
150                 if (wanted_fc & EFX_FC_RX)
151                         efx->link_advertising[0] |= (ADVERTISED_Pause |
152                                                      ADVERTISED_Asym_Pause);
153                 else
154                         efx->link_advertising[0] &= ~(ADVERTISED_Pause |
155                                                       ADVERTISED_Asym_Pause);
156                 if (wanted_fc & EFX_FC_TX)
157                         efx->link_advertising[0] ^= ADVERTISED_Asym_Pause;
158         }
159 }
160
161 static void efx_fini_port(struct efx_nic *efx);
162
163 static int efx_probe_port(struct efx_nic *efx)
164 {
165         int rc;
166
167         netif_dbg(efx, probe, efx->net_dev, "create port\n");
168
169         if (phy_flash_cfg)
170                 efx->phy_mode = PHY_MODE_SPECIAL;
171
172         /* Connect up MAC/PHY operations table */
173         rc = efx->type->probe_port(efx);
174         if (rc)
175                 return rc;
176
177         /* Initialise MAC address to permanent address */
178         ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
179
180         return 0;
181 }
182
183 static int efx_init_port(struct efx_nic *efx)
184 {
185         int rc;
186
187         netif_dbg(efx, drv, efx->net_dev, "init port\n");
188
189         mutex_lock(&efx->mac_lock);
190
191         rc = efx->phy_op->init(efx);
192         if (rc)
193                 goto fail1;
194
195         efx->port_initialized = true;
196
197         /* Reconfigure the MAC before creating dma queues (required for
198          * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
199         efx_mac_reconfigure(efx);
200
201         /* Ensure the PHY advertises the correct flow control settings */
202         rc = efx->phy_op->reconfigure(efx);
203         if (rc && rc != -EPERM)
204                 goto fail2;
205
206         mutex_unlock(&efx->mac_lock);
207         return 0;
208
209 fail2:
210         efx->phy_op->fini(efx);
211 fail1:
212         mutex_unlock(&efx->mac_lock);
213         return rc;
214 }
215
216 static void efx_fini_port(struct efx_nic *efx)
217 {
218         netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
219
220         if (!efx->port_initialized)
221                 return;
222
223         efx->phy_op->fini(efx);
224         efx->port_initialized = false;
225
226         efx->link_state.up = false;
227         efx_link_status_changed(efx);
228 }
229
230 static void efx_remove_port(struct efx_nic *efx)
231 {
232         netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
233
234         efx->type->remove_port(efx);
235 }
236
237 /**************************************************************************
238  *
239  * NIC handling
240  *
241  **************************************************************************/
242
243 static LIST_HEAD(efx_primary_list);
244 static LIST_HEAD(efx_unassociated_list);
245
246 static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
247 {
248         return left->type == right->type &&
249                 left->vpd_sn && right->vpd_sn &&
250                 !strcmp(left->vpd_sn, right->vpd_sn);
251 }
252
253 static void efx_associate(struct efx_nic *efx)
254 {
255         struct efx_nic *other, *next;
256
257         if (efx->primary == efx) {
258                 /* Adding primary function; look for secondaries */
259
260                 netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
261                 list_add_tail(&efx->node, &efx_primary_list);
262
263                 list_for_each_entry_safe(other, next, &efx_unassociated_list,
264                                          node) {
265                         if (efx_same_controller(efx, other)) {
266                                 list_del(&other->node);
267                                 netif_dbg(other, probe, other->net_dev,
268                                           "moving to secondary list of %s %s\n",
269                                           pci_name(efx->pci_dev),
270                                           efx->net_dev->name);
271                                 list_add_tail(&other->node,
272                                               &efx->secondary_list);
273                                 other->primary = efx;
274                         }
275                 }
276         } else {
277                 /* Adding secondary function; look for primary */
278
279                 list_for_each_entry(other, &efx_primary_list, node) {
280                         if (efx_same_controller(efx, other)) {
281                                 netif_dbg(efx, probe, efx->net_dev,
282                                           "adding to secondary list of %s %s\n",
283                                           pci_name(other->pci_dev),
284                                           other->net_dev->name);
285                                 list_add_tail(&efx->node,
286                                               &other->secondary_list);
287                                 efx->primary = other;
288                                 return;
289                         }
290                 }
291
292                 netif_dbg(efx, probe, efx->net_dev,
293                           "adding to unassociated list\n");
294                 list_add_tail(&efx->node, &efx_unassociated_list);
295         }
296 }
297
298 static void efx_dissociate(struct efx_nic *efx)
299 {
300         struct efx_nic *other, *next;
301
302         list_del(&efx->node);
303         efx->primary = NULL;
304
305         list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
306                 list_del(&other->node);
307                 netif_dbg(other, probe, other->net_dev,
308                           "moving to unassociated list\n");
309                 list_add_tail(&other->node, &efx_unassociated_list);
310                 other->primary = NULL;
311         }
312 }
313
314 void efx_set_default_rx_indir_table(struct efx_nic *efx,
315                                     struct efx_rss_context *ctx)
316 {
317         size_t i;
318
319         for (i = 0; i < ARRAY_SIZE(ctx->rx_indir_table); i++)
320                 ctx->rx_indir_table[i] =
321                         ethtool_rxfh_indir_default(i, efx->rss_spread);
322 }
323
324 static int efx_probe_nic(struct efx_nic *efx)
325 {
326         int rc;
327
328         netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
329
330         /* Carry out hardware-type specific initialisation */
331         rc = efx->type->probe(efx);
332         if (rc)
333                 return rc;
334
335         do {
336                 if (!efx->max_channels || !efx->max_tx_channels) {
337                         netif_err(efx, drv, efx->net_dev,
338                                   "Insufficient resources to allocate"
339                                   " any channels\n");
340                         rc = -ENOSPC;
341                         goto fail1;
342                 }
343
344                 /* Determine the number of channels and queues by trying
345                  * to hook in MSI-X interrupts.
346                  */
347                 rc = efx_probe_interrupts(efx);
348                 if (rc)
349                         goto fail1;
350
351                 rc = efx_set_channels(efx);
352                 if (rc)
353                         goto fail1;
354
355                 /* dimension_resources can fail with EAGAIN */
356                 rc = efx->type->dimension_resources(efx);
357                 if (rc != 0 && rc != -EAGAIN)
358                         goto fail2;
359
360                 if (rc == -EAGAIN)
361                         /* try again with new max_channels */
362                         efx_remove_interrupts(efx);
363
364         } while (rc == -EAGAIN);
365
366         if (efx->n_channels > 1)
367                 netdev_rss_key_fill(efx->rss_context.rx_hash_key,
368                                     sizeof(efx->rss_context.rx_hash_key));
369         efx_set_default_rx_indir_table(efx, &efx->rss_context);
370
371         netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
372         netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
373
374         /* Initialise the interrupt moderation settings */
375         efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
376         efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
377                                 true);
378
379         return 0;
380
381 fail2:
382         efx_remove_interrupts(efx);
383 fail1:
384         efx->type->remove(efx);
385         return rc;
386 }
387
388 static void efx_remove_nic(struct efx_nic *efx)
389 {
390         netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
391
392         efx_remove_interrupts(efx);
393         efx->type->remove(efx);
394 }
395
396 static int efx_probe_filters(struct efx_nic *efx)
397 {
398         int rc;
399
400         init_rwsem(&efx->filter_sem);
401         mutex_lock(&efx->mac_lock);
402         down_write(&efx->filter_sem);
403         rc = efx->type->filter_table_probe(efx);
404         if (rc)
405                 goto out_unlock;
406
407 #ifdef CONFIG_RFS_ACCEL
408         if (efx->type->offload_features & NETIF_F_NTUPLE) {
409                 struct efx_channel *channel;
410                 int i, success = 1;
411
412                 efx_for_each_channel(channel, efx) {
413                         channel->rps_flow_id =
414                                 kcalloc(efx->type->max_rx_ip_filters,
415                                         sizeof(*channel->rps_flow_id),
416                                         GFP_KERNEL);
417                         if (!channel->rps_flow_id)
418                                 success = 0;
419                         else
420                                 for (i = 0;
421                                      i < efx->type->max_rx_ip_filters;
422                                      ++i)
423                                         channel->rps_flow_id[i] =
424                                                 RPS_FLOW_ID_INVALID;
425                         channel->rfs_expire_index = 0;
426                         channel->rfs_filter_count = 0;
427                 }
428
429                 if (!success) {
430                         efx_for_each_channel(channel, efx)
431                                 kfree(channel->rps_flow_id);
432                         efx->type->filter_table_remove(efx);
433                         rc = -ENOMEM;
434                         goto out_unlock;
435                 }
436         }
437 #endif
438 out_unlock:
439         up_write(&efx->filter_sem);
440         mutex_unlock(&efx->mac_lock);
441         return rc;
442 }
443
444 static void efx_remove_filters(struct efx_nic *efx)
445 {
446 #ifdef CONFIG_RFS_ACCEL
447         struct efx_channel *channel;
448
449         efx_for_each_channel(channel, efx) {
450                 cancel_delayed_work_sync(&channel->filter_work);
451                 kfree(channel->rps_flow_id);
452         }
453 #endif
454         down_write(&efx->filter_sem);
455         efx->type->filter_table_remove(efx);
456         up_write(&efx->filter_sem);
457 }
458
459
460 /**************************************************************************
461  *
462  * NIC startup/shutdown
463  *
464  *************************************************************************/
465
466 static int efx_probe_all(struct efx_nic *efx)
467 {
468         int rc;
469
470         rc = efx_probe_nic(efx);
471         if (rc) {
472                 netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
473                 goto fail1;
474         }
475
476         rc = efx_probe_port(efx);
477         if (rc) {
478                 netif_err(efx, probe, efx->net_dev, "failed to create port\n");
479                 goto fail2;
480         }
481
482         BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
483         if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
484                 rc = -EINVAL;
485                 goto fail3;
486         }
487         efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
488
489 #ifdef CONFIG_SFC_SRIOV
490         rc = efx->type->vswitching_probe(efx);
491         if (rc) /* not fatal; the PF will still work fine */
492                 netif_warn(efx, probe, efx->net_dev,
493                            "failed to setup vswitching rc=%d;"
494                            " VFs may not function\n", rc);
495 #endif
496
497         rc = efx_probe_filters(efx);
498         if (rc) {
499                 netif_err(efx, probe, efx->net_dev,
500                           "failed to create filter tables\n");
501                 goto fail4;
502         }
503
504         rc = efx_probe_channels(efx);
505         if (rc)
506                 goto fail5;
507
508         return 0;
509
510  fail5:
511         efx_remove_filters(efx);
512  fail4:
513 #ifdef CONFIG_SFC_SRIOV
514         efx->type->vswitching_remove(efx);
515 #endif
516  fail3:
517         efx_remove_port(efx);
518  fail2:
519         efx_remove_nic(efx);
520  fail1:
521         return rc;
522 }
523
524 static void efx_remove_all(struct efx_nic *efx)
525 {
526         rtnl_lock();
527         efx_xdp_setup_prog(efx, NULL);
528         rtnl_unlock();
529
530         efx_remove_channels(efx);
531         efx_remove_filters(efx);
532 #ifdef CONFIG_SFC_SRIOV
533         efx->type->vswitching_remove(efx);
534 #endif
535         efx_remove_port(efx);
536         efx_remove_nic(efx);
537 }
538
539 /**************************************************************************
540  *
541  * Interrupt moderation
542  *
543  **************************************************************************/
544 unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
545 {
546         if (usecs == 0)
547                 return 0;
548         if (usecs * 1000 < efx->timer_quantum_ns)
549                 return 1; /* never round down to 0 */
550         return usecs * 1000 / efx->timer_quantum_ns;
551 }
552
553 unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
554 {
555         /* We must round up when converting ticks to microseconds
556          * because we round down when converting the other way.
557          */
558         return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
559 }
560
561 /* Set interrupt moderation parameters */
562 int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
563                             unsigned int rx_usecs, bool rx_adaptive,
564                             bool rx_may_override_tx)
565 {
566         struct efx_channel *channel;
567         unsigned int timer_max_us;
568
569         EFX_ASSERT_RESET_SERIALISED(efx);
570
571         timer_max_us = efx->timer_max_ns / 1000;
572
573         if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
574                 return -EINVAL;
575
576         if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
577             !rx_may_override_tx) {
578                 netif_err(efx, drv, efx->net_dev, "Channels are shared. "
579                           "RX and TX IRQ moderation must be equal\n");
580                 return -EINVAL;
581         }
582
583         efx->irq_rx_adaptive = rx_adaptive;
584         efx->irq_rx_moderation_us = rx_usecs;
585         efx_for_each_channel(channel, efx) {
586                 if (efx_channel_has_rx_queue(channel))
587                         channel->irq_moderation_us = rx_usecs;
588                 else if (efx_channel_has_tx_queues(channel))
589                         channel->irq_moderation_us = tx_usecs;
590                 else if (efx_channel_is_xdp_tx(channel))
591                         channel->irq_moderation_us = tx_usecs;
592         }
593
594         return 0;
595 }
596
597 void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
598                             unsigned int *rx_usecs, bool *rx_adaptive)
599 {
600         *rx_adaptive = efx->irq_rx_adaptive;
601         *rx_usecs = efx->irq_rx_moderation_us;
602
603         /* If channels are shared between RX and TX, so is IRQ
604          * moderation.  Otherwise, IRQ moderation is the same for all
605          * TX channels and is not adaptive.
606          */
607         if (efx->tx_channel_offset == 0) {
608                 *tx_usecs = *rx_usecs;
609         } else {
610                 struct efx_channel *tx_channel;
611
612                 tx_channel = efx->channel[efx->tx_channel_offset];
613                 *tx_usecs = tx_channel->irq_moderation_us;
614         }
615 }
616
617 /**************************************************************************
618  *
619  * ioctls
620  *
621  *************************************************************************/
622
623 /* Net device ioctl
624  * Context: process, rtnl_lock() held.
625  */
626 static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
627 {
628         struct efx_nic *efx = netdev_priv(net_dev);
629         struct mii_ioctl_data *data = if_mii(ifr);
630
631         if (cmd == SIOCSHWTSTAMP)
632                 return efx_ptp_set_ts_config(efx, ifr);
633         if (cmd == SIOCGHWTSTAMP)
634                 return efx_ptp_get_ts_config(efx, ifr);
635
636         /* Convert phy_id from older PRTAD/DEVAD format */
637         if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
638             (data->phy_id & 0xfc00) == 0x0400)
639                 data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;
640
641         return mdio_mii_ioctl(&efx->mdio, data, cmd);
642 }
643
644 /**************************************************************************
645  *
646  * Kernel net device interface
647  *
648  *************************************************************************/
649
650 /* Context: process, rtnl_lock() held. */
651 int efx_net_open(struct net_device *net_dev)
652 {
653         struct efx_nic *efx = netdev_priv(net_dev);
654         int rc;
655
656         netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
657                   raw_smp_processor_id());
658
659         rc = efx_check_disabled(efx);
660         if (rc)
661                 return rc;
662         if (efx->phy_mode & PHY_MODE_SPECIAL)
663                 return -EBUSY;
664         if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
665                 return -EIO;
666
667         /* Notify the kernel of the link state polled during driver load,
668          * before the monitor starts running */
669         efx_link_status_changed(efx);
670
671         efx_start_all(efx);
672         if (efx->state == STATE_DISABLED || efx->reset_pending)
673                 netif_device_detach(efx->net_dev);
674         efx_selftest_async_start(efx);
675         return 0;
676 }
677
678 /* Context: process, rtnl_lock() held.
679  * Note that the kernel will ignore our return code; this method
680  * should really be a void.
681  */
682 int efx_net_stop(struct net_device *net_dev)
683 {
684         struct efx_nic *efx = netdev_priv(net_dev);
685
686         netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
687                   raw_smp_processor_id());
688
689         /* Stop the device and flush all the channels */
690         efx_stop_all(efx);
691
692         return 0;
693 }
694
695 /* Context: process, dev_base_lock or RTNL held, non-blocking. */
696 static void efx_net_stats(struct net_device *net_dev,
697                           struct rtnl_link_stats64 *stats)
698 {
699         struct efx_nic *efx = netdev_priv(net_dev);
700
701         spin_lock_bh(&efx->stats_lock);
702         efx->type->update_stats(efx, NULL, stats);
703         spin_unlock_bh(&efx->stats_lock);
704 }
705
706 /* Context: netif_tx_lock held, BHs disabled. */
707 static void efx_watchdog(struct net_device *net_dev, unsigned int txqueue)
708 {
709         struct efx_nic *efx = netdev_priv(net_dev);
710
711         netif_err(efx, tx_err, efx->net_dev,
712                   "TX stuck with port_enabled=%d: resetting channels\n",
713                   efx->port_enabled);
714
715         efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
716 }
717
718 static unsigned int efx_xdp_max_mtu(struct efx_nic *efx)
719 {
720         /* The maximum MTU that we can fit in a single page, allowing for
721          * framing, overhead and XDP headroom.
722          */
723         int overhead = EFX_MAX_FRAME_LEN(0) + sizeof(struct efx_rx_page_state) +
724                        efx->rx_prefix_size + efx->type->rx_buffer_padding +
725                        efx->rx_ip_align + XDP_PACKET_HEADROOM;
726
727         return PAGE_SIZE - overhead;
728 }
729
730 /* Context: process, rtnl_lock() held. */
731 static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
732 {
733         struct efx_nic *efx = netdev_priv(net_dev);
734         int rc;
735
736         rc = efx_check_disabled(efx);
737         if (rc)
738                 return rc;
739
740         if (rtnl_dereference(efx->xdp_prog) &&
741             new_mtu > efx_xdp_max_mtu(efx)) {
742                 netif_err(efx, drv, efx->net_dev,
743                           "Requested MTU of %d too big for XDP (max: %d)\n",
744                           new_mtu, efx_xdp_max_mtu(efx));
745                 return -EINVAL;
746         }
747
748         netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
749
750         efx_device_detach_sync(efx);
751         efx_stop_all(efx);
752
753         mutex_lock(&efx->mac_lock);
754         net_dev->mtu = new_mtu;
755         efx_mac_reconfigure(efx);
756         mutex_unlock(&efx->mac_lock);
757
758         efx_start_all(efx);
759         efx_device_attach_if_not_resetting(efx);
760         return 0;
761 }
762
763 static int efx_set_mac_address(struct net_device *net_dev, void *data)
764 {
765         struct efx_nic *efx = netdev_priv(net_dev);
766         struct sockaddr *addr = data;
767         u8 *new_addr = addr->sa_data;
768         u8 old_addr[6];
769         int rc;
770
771         if (!is_valid_ether_addr(new_addr)) {
772                 netif_err(efx, drv, efx->net_dev,
773                           "invalid ethernet MAC address requested: %pM\n",
774                           new_addr);
775                 return -EADDRNOTAVAIL;
776         }
777
778         /* save old address */
779         ether_addr_copy(old_addr, net_dev->dev_addr);
780         ether_addr_copy(net_dev->dev_addr, new_addr);
781         if (efx->type->set_mac_address) {
782                 rc = efx->type->set_mac_address(efx);
783                 if (rc) {
784                         ether_addr_copy(net_dev->dev_addr, old_addr);
785                         return rc;
786                 }
787         }
788
789         /* Reconfigure the MAC */
790         mutex_lock(&efx->mac_lock);
791         efx_mac_reconfigure(efx);
792         mutex_unlock(&efx->mac_lock);
793
794         return 0;
795 }
796
797 /* Context: netif_addr_lock held, BHs disabled. */
798 static void efx_set_rx_mode(struct net_device *net_dev)
799 {
800         struct efx_nic *efx = netdev_priv(net_dev);
801
802         if (efx->port_enabled)
803                 queue_work(efx->workqueue, &efx->mac_work);
804         /* Otherwise efx_start_port() will do this */
805 }
806
807 static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
808 {
809         struct efx_nic *efx = netdev_priv(net_dev);
810         int rc;
811
812         /* If disabling RX n-tuple filtering, clear existing filters */
813         if (net_dev->features & ~data & NETIF_F_NTUPLE) {
814                 rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
815                 if (rc)
816                         return rc;
817         }
818
819         /* If Rx VLAN filter is changed, update filters via mac_reconfigure.
820          * If rx-fcs is changed, mac_reconfigure updates that too.
821          */
822         if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
823                                           NETIF_F_RXFCS)) {
824                 /* efx_set_rx_mode() will schedule MAC work to update filters
825                  * when a new features are finally set in net_dev.
826                  */
827                 efx_set_rx_mode(net_dev);
828         }
829
830         return 0;
831 }
832
833 static int efx_get_phys_port_id(struct net_device *net_dev,
834                                 struct netdev_phys_item_id *ppid)
835 {
836         struct efx_nic *efx = netdev_priv(net_dev);
837
838         if (efx->type->get_phys_port_id)
839                 return efx->type->get_phys_port_id(efx, ppid);
840         else
841                 return -EOPNOTSUPP;
842 }
843
844 static int efx_get_phys_port_name(struct net_device *net_dev,
845                                   char *name, size_t len)
846 {
847         struct efx_nic *efx = netdev_priv(net_dev);
848
849         if (snprintf(name, len, "p%u", efx->port_num) >= len)
850                 return -EINVAL;
851         return 0;
852 }
853
854 static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
855 {
856         struct efx_nic *efx = netdev_priv(net_dev);
857
858         if (efx->type->vlan_rx_add_vid)
859                 return efx->type->vlan_rx_add_vid(efx, proto, vid);
860         else
861                 return -EOPNOTSUPP;
862 }
863
864 static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
865 {
866         struct efx_nic *efx = netdev_priv(net_dev);
867
868         if (efx->type->vlan_rx_kill_vid)
869                 return efx->type->vlan_rx_kill_vid(efx, proto, vid);
870         else
871                 return -EOPNOTSUPP;
872 }
873
874 static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
875 {
876         switch (in) {
877         case UDP_TUNNEL_TYPE_VXLAN:
878                 return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
879         case UDP_TUNNEL_TYPE_GENEVE:
880                 return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
881         default:
882                 return -1;
883         }
884 }
885
886 static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
887 {
888         struct efx_nic *efx = netdev_priv(dev);
889         struct efx_udp_tunnel tnl;
890         int efx_tunnel_type;
891
892         efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
893         if (efx_tunnel_type < 0)
894                 return;
895
896         tnl.type = (u16)efx_tunnel_type;
897         tnl.port = ti->port;
898
899         if (efx->type->udp_tnl_add_port)
900                 (void)efx->type->udp_tnl_add_port(efx, tnl);
901 }
902
903 static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
904 {
905         struct efx_nic *efx = netdev_priv(dev);
906         struct efx_udp_tunnel tnl;
907         int efx_tunnel_type;
908
909         efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
910         if (efx_tunnel_type < 0)
911                 return;
912
913         tnl.type = (u16)efx_tunnel_type;
914         tnl.port = ti->port;
915
916         if (efx->type->udp_tnl_del_port)
917                 (void)efx->type->udp_tnl_del_port(efx, tnl);
918 }
919
920 static const struct net_device_ops efx_netdev_ops = {
921         .ndo_open               = efx_net_open,
922         .ndo_stop               = efx_net_stop,
923         .ndo_get_stats64        = efx_net_stats,
924         .ndo_tx_timeout         = efx_watchdog,
925         .ndo_start_xmit         = efx_hard_start_xmit,
926         .ndo_validate_addr      = eth_validate_addr,
927         .ndo_do_ioctl           = efx_ioctl,
928         .ndo_change_mtu         = efx_change_mtu,
929         .ndo_set_mac_address    = efx_set_mac_address,
930         .ndo_set_rx_mode        = efx_set_rx_mode,
931         .ndo_set_features       = efx_set_features,
932         .ndo_vlan_rx_add_vid    = efx_vlan_rx_add_vid,
933         .ndo_vlan_rx_kill_vid   = efx_vlan_rx_kill_vid,
934 #ifdef CONFIG_SFC_SRIOV
935         .ndo_set_vf_mac         = efx_sriov_set_vf_mac,
936         .ndo_set_vf_vlan        = efx_sriov_set_vf_vlan,
937         .ndo_set_vf_spoofchk    = efx_sriov_set_vf_spoofchk,
938         .ndo_get_vf_config      = efx_sriov_get_vf_config,
939         .ndo_set_vf_link_state  = efx_sriov_set_vf_link_state,
940 #endif
941         .ndo_get_phys_port_id   = efx_get_phys_port_id,
942         .ndo_get_phys_port_name = efx_get_phys_port_name,
943         .ndo_setup_tc           = efx_setup_tc,
944 #ifdef CONFIG_RFS_ACCEL
945         .ndo_rx_flow_steer      = efx_filter_rfs,
946 #endif
947         .ndo_udp_tunnel_add     = efx_udp_tunnel_add,
948         .ndo_udp_tunnel_del     = efx_udp_tunnel_del,
949         .ndo_xdp_xmit           = efx_xdp_xmit,
950         .ndo_bpf                = efx_xdp
951 };
952
953 static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
954 {
955         struct bpf_prog *old_prog;
956
957         if (efx->xdp_rxq_info_failed) {
958                 netif_err(efx, drv, efx->net_dev,
959                           "Unable to bind XDP program due to previous failure of rxq_info\n");
960                 return -EINVAL;
961         }
962
963         if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) {
964                 netif_err(efx, drv, efx->net_dev,
965                           "Unable to configure XDP with MTU of %d (max: %d)\n",
966                           efx->net_dev->mtu, efx_xdp_max_mtu(efx));
967                 return -EINVAL;
968         }
969
970         old_prog = rtnl_dereference(efx->xdp_prog);
971         rcu_assign_pointer(efx->xdp_prog, prog);
972         /* Release the reference that was originally passed by the caller. */
973         if (old_prog)
974                 bpf_prog_put(old_prog);
975
976         return 0;
977 }
978
979 /* Context: process, rtnl_lock() held. */
980 static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
981 {
982         struct efx_nic *efx = netdev_priv(dev);
983         struct bpf_prog *xdp_prog;
984
985         switch (xdp->command) {
986         case XDP_SETUP_PROG:
987                 return efx_xdp_setup_prog(efx, xdp->prog);
988         case XDP_QUERY_PROG:
989                 xdp_prog = rtnl_dereference(efx->xdp_prog);
990                 xdp->prog_id = xdp_prog ? xdp_prog->aux->id : 0;
991                 return 0;
992         default:
993                 return -EINVAL;
994         }
995 }
996
997 static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
998                         u32 flags)
999 {
1000         struct efx_nic *efx = netdev_priv(dev);
1001
1002         if (!netif_running(dev))
1003                 return -EINVAL;
1004
1005         return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
1006 }
1007
1008 static void efx_update_name(struct efx_nic *efx)
1009 {
1010         strcpy(efx->name, efx->net_dev->name);
1011         efx_mtd_rename(efx);
1012         efx_set_channel_names(efx);
1013 }
1014
1015 static int efx_netdev_event(struct notifier_block *this,
1016                             unsigned long event, void *ptr)
1017 {
1018         struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
1019
1020         if ((net_dev->netdev_ops == &efx_netdev_ops) &&
1021             event == NETDEV_CHANGENAME)
1022                 efx_update_name(netdev_priv(net_dev));
1023
1024         return NOTIFY_DONE;
1025 }
1026
1027 static struct notifier_block efx_netdev_notifier = {
1028         .notifier_call = efx_netdev_event,
1029 };
1030
1031 static ssize_t
1032 show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
1033 {
1034         struct efx_nic *efx = dev_get_drvdata(dev);
1035         return sprintf(buf, "%d\n", efx->phy_type);
1036 }
1037 static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
1038
1039 static int efx_register_netdev(struct efx_nic *efx)
1040 {
1041         struct net_device *net_dev = efx->net_dev;
1042         struct efx_channel *channel;
1043         int rc;
1044
1045         net_dev->watchdog_timeo = 5 * HZ;
1046         net_dev->irq = efx->pci_dev->irq;
1047         net_dev->netdev_ops = &efx_netdev_ops;
1048         if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
1049                 net_dev->priv_flags |= IFF_UNICAST_FLT;
1050         net_dev->ethtool_ops = &efx_ethtool_ops;
1051         net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
1052         net_dev->min_mtu = EFX_MIN_MTU;
1053         net_dev->max_mtu = EFX_MAX_MTU;
1054
1055         rtnl_lock();
1056
1057         /* Enable resets to be scheduled and check whether any were
1058          * already requested.  If so, the NIC is probably hosed so we
1059          * abort.
1060          */
1061         efx->state = STATE_READY;
1062         smp_mb(); /* ensure we change state before checking reset_pending */
1063         if (efx->reset_pending) {
1064                 netif_err(efx, probe, efx->net_dev,
1065                           "aborting probe due to scheduled reset\n");
1066                 rc = -EIO;
1067                 goto fail_locked;
1068         }
1069
1070         rc = dev_alloc_name(net_dev, net_dev->name);
1071         if (rc < 0)
1072                 goto fail_locked;
1073         efx_update_name(efx);
1074
1075         /* Always start with carrier off; PHY events will detect the link */
1076         netif_carrier_off(net_dev);
1077
1078         rc = register_netdevice(net_dev);
1079         if (rc)
1080                 goto fail_locked;
1081
1082         efx_for_each_channel(channel, efx) {
1083                 struct efx_tx_queue *tx_queue;
1084                 efx_for_each_channel_tx_queue(tx_queue, channel)
1085                         efx_init_tx_queue_core_txq(tx_queue);
1086         }
1087
1088         efx_associate(efx);
1089
1090         rtnl_unlock();
1091
1092         rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
1093         if (rc) {
1094                 netif_err(efx, drv, efx->net_dev,
1095                           "failed to init net dev attributes\n");
1096                 goto fail_registered;
1097         }
1098
1099         efx_init_mcdi_logging(efx);
1100
1101         return 0;
1102
1103 fail_registered:
1104         rtnl_lock();
1105         efx_dissociate(efx);
1106         unregister_netdevice(net_dev);
1107 fail_locked:
1108         efx->state = STATE_UNINIT;
1109         rtnl_unlock();
1110         netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
1111         return rc;
1112 }
1113
1114 static void efx_unregister_netdev(struct efx_nic *efx)
1115 {
1116         if (!efx->net_dev)
1117                 return;
1118
1119         BUG_ON(netdev_priv(efx->net_dev) != efx);
1120
1121         if (efx_dev_registered(efx)) {
1122                 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
1123                 efx_fini_mcdi_logging(efx);
1124                 device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
1125                 unregister_netdev(efx->net_dev);
1126         }
1127 }
1128
1129 /**************************************************************************
1130  *
1131  * List of NICs we support
1132  *
1133  **************************************************************************/
1134
1135 /* PCI device ID table */
1136 static const struct pci_device_id efx_pci_table[] = {
1137         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803),  /* SFC9020 */
1138          .driver_data = (unsigned long) &siena_a0_nic_type},
1139         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813),  /* SFL9021 */
1140          .driver_data = (unsigned long) &siena_a0_nic_type},
1141         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903),  /* SFC9120 PF */
1142          .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
1143         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903),  /* SFC9120 VF */
1144          .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
1145         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923),  /* SFC9140 PF */
1146          .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
1147         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923),  /* SFC9140 VF */
1148          .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
1149         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03),  /* SFC9220 PF */
1150          .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
1151         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03),  /* SFC9220 VF */
1152          .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
1153         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03),  /* SFC9250 PF */
1154          .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
1155         {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03),  /* SFC9250 VF */
1156          .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
1157         {0}                     /* end of list */
1158 };
1159
1160 /**************************************************************************
1161  *
1162  * Data housekeeping
1163  *
1164  **************************************************************************/
1165
1166 void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
1167 {
1168         u64 n_rx_nodesc_trunc = 0;
1169         struct efx_channel *channel;
1170
1171         efx_for_each_channel(channel, efx)
1172                 n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
1173         stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
1174         stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
1175 }
1176
1177 bool efx_filter_spec_equal(const struct efx_filter_spec *left,
1178                            const struct efx_filter_spec *right)
1179 {
1180         if ((left->match_flags ^ right->match_flags) |
1181             ((left->flags ^ right->flags) &
1182              (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
1183                 return false;
1184
1185         return memcmp(&left->outer_vid, &right->outer_vid,
1186                       sizeof(struct efx_filter_spec) -
1187                       offsetof(struct efx_filter_spec, outer_vid)) == 0;
1188 }
1189
1190 u32 efx_filter_spec_hash(const struct efx_filter_spec *spec)
1191 {
1192         BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
1193         return jhash2((const u32 *)&spec->outer_vid,
1194                       (sizeof(struct efx_filter_spec) -
1195                        offsetof(struct efx_filter_spec, outer_vid)) / 4,
1196                       0);
1197 }
1198
1199 #ifdef CONFIG_RFS_ACCEL
1200 bool efx_rps_check_rule(struct efx_arfs_rule *rule, unsigned int filter_idx,
1201                         bool *force)
1202 {
1203         if (rule->filter_id == EFX_ARFS_FILTER_ID_PENDING) {
1204                 /* ARFS is currently updating this entry, leave it */
1205                 return false;
1206         }
1207         if (rule->filter_id == EFX_ARFS_FILTER_ID_ERROR) {
1208                 /* ARFS tried and failed to update this, so it's probably out
1209                  * of date.  Remove the filter and the ARFS rule entry.
1210                  */
1211                 rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING;
1212                 *force = true;
1213                 return true;
1214         } else if (WARN_ON(rule->filter_id != filter_idx)) { /* can't happen */
1215                 /* ARFS has moved on, so old filter is not needed.  Since we did
1216                  * not mark the rule with EFX_ARFS_FILTER_ID_REMOVING, it will
1217                  * not be removed by efx_rps_hash_del() subsequently.
1218                  */
1219                 *force = true;
1220                 return true;
1221         }
1222         /* Remove it iff ARFS wants to. */
1223         return true;
1224 }
1225
1226 static
1227 struct hlist_head *efx_rps_hash_bucket(struct efx_nic *efx,
1228                                        const struct efx_filter_spec *spec)
1229 {
1230         u32 hash = efx_filter_spec_hash(spec);
1231
1232         lockdep_assert_held(&efx->rps_hash_lock);
1233         if (!efx->rps_hash_table)
1234                 return NULL;
1235         return &efx->rps_hash_table[hash % EFX_ARFS_HASH_TABLE_SIZE];
1236 }
1237
1238 struct efx_arfs_rule *efx_rps_hash_find(struct efx_nic *efx,
1239                                         const struct efx_filter_spec *spec)
1240 {
1241         struct efx_arfs_rule *rule;
1242         struct hlist_head *head;
1243         struct hlist_node *node;
1244
1245         head = efx_rps_hash_bucket(efx, spec);
1246         if (!head)
1247                 return NULL;
1248         hlist_for_each(node, head) {
1249                 rule = container_of(node, struct efx_arfs_rule, node);
1250                 if (efx_filter_spec_equal(spec, &rule->spec))
1251                         return rule;
1252         }
1253         return NULL;
1254 }
1255
1256 struct efx_arfs_rule *efx_rps_hash_add(struct efx_nic *efx,
1257                                        const struct efx_filter_spec *spec,
1258                                        bool *new)
1259 {
1260         struct efx_arfs_rule *rule;
1261         struct hlist_head *head;
1262         struct hlist_node *node;
1263
1264         head = efx_rps_hash_bucket(efx, spec);
1265         if (!head)
1266                 return NULL;
1267         hlist_for_each(node, head) {
1268                 rule = container_of(node, struct efx_arfs_rule, node);
1269                 if (efx_filter_spec_equal(spec, &rule->spec)) {
1270                         *new = false;
1271                         return rule;
1272                 }
1273         }
1274         rule = kmalloc(sizeof(*rule), GFP_ATOMIC);
1275         *new = true;
1276         if (rule) {
1277                 memcpy(&rule->spec, spec, sizeof(rule->spec));
1278                 hlist_add_head(&rule->node, head);
1279         }
1280         return rule;
1281 }
1282
1283 void efx_rps_hash_del(struct efx_nic *efx, const struct efx_filter_spec *spec)
1284 {
1285         struct efx_arfs_rule *rule;
1286         struct hlist_head *head;
1287         struct hlist_node *node;
1288
1289         head = efx_rps_hash_bucket(efx, spec);
1290         if (WARN_ON(!head))
1291                 return;
1292         hlist_for_each(node, head) {
1293                 rule = container_of(node, struct efx_arfs_rule, node);
1294                 if (efx_filter_spec_equal(spec, &rule->spec)) {
1295                         /* Someone already reused the entry.  We know that if
1296                          * this check doesn't fire (i.e. filter_id == REMOVING)
1297                          * then the REMOVING mark was put there by our caller,
1298                          * because caller is holding a lock on filter table and
1299                          * only holders of that lock set REMOVING.
1300                          */
1301                         if (rule->filter_id != EFX_ARFS_FILTER_ID_REMOVING)
1302                                 return;
1303                         hlist_del(node);
1304                         kfree(rule);
1305                         return;
1306                 }
1307         }
1308         /* We didn't find it. */
1309         WARN_ON(1);
1310 }
1311 #endif
1312
1313 /* RSS contexts.  We're using linked lists and crappy O(n) algorithms, because
1314  * (a) this is an infrequent control-plane operation and (b) n is small (max 64)
1315  */
1316 struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)
1317 {
1318         struct list_head *head = &efx->rss_context.list;
1319         struct efx_rss_context *ctx, *new;
1320         u32 id = 1; /* Don't use zero, that refers to the master RSS context */
1321
1322         WARN_ON(!mutex_is_locked(&efx->rss_lock));
1323
1324         /* Search for first gap in the numbering */
1325         list_for_each_entry(ctx, head, list) {
1326                 if (ctx->user_id != id)
1327                         break;
1328                 id++;
1329                 /* Check for wrap.  If this happens, we have nearly 2^32
1330                  * allocated RSS contexts, which seems unlikely.
1331                  */
1332                 if (WARN_ON_ONCE(!id))
1333                         return NULL;
1334         }
1335
1336         /* Create the new entry */
1337         new = kmalloc(sizeof(struct efx_rss_context), GFP_KERNEL);
1338         if (!new)
1339                 return NULL;
1340         new->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
1341         new->rx_hash_udp_4tuple = false;
1342
1343         /* Insert the new entry into the gap */
1344         new->user_id = id;
1345         list_add_tail(&new->list, &ctx->list);
1346         return new;
1347 }
1348
1349 struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id)
1350 {
1351         struct list_head *head = &efx->rss_context.list;
1352         struct efx_rss_context *ctx;
1353
1354         WARN_ON(!mutex_is_locked(&efx->rss_lock));
1355
1356         list_for_each_entry(ctx, head, list)
1357                 if (ctx->user_id == id)
1358                         return ctx;
1359         return NULL;
1360 }
1361
1362 void efx_free_rss_context_entry(struct efx_rss_context *ctx)
1363 {
1364         list_del(&ctx->list);
1365         kfree(ctx);
1366 }
1367
1368 /**************************************************************************
1369  *
1370  * PCI interface
1371  *
1372  **************************************************************************/
1373
1374 /* Main body of final NIC shutdown code
1375  * This is called only at module unload (or hotplug removal).
1376  */
1377 static void efx_pci_remove_main(struct efx_nic *efx)
1378 {
1379         /* Flush reset_work. It can no longer be scheduled since we
1380          * are not READY.
1381          */
1382         BUG_ON(efx->state == STATE_READY);
1383         efx_flush_reset_workqueue(efx);
1384
1385         efx_disable_interrupts(efx);
1386         efx_clear_interrupt_affinity(efx);
1387         efx_nic_fini_interrupt(efx);
1388         efx_fini_port(efx);
1389         efx->type->fini(efx);
1390         efx_fini_napi(efx);
1391         efx_remove_all(efx);
1392 }
1393
1394 /* Final NIC shutdown
1395  * This is called only at module unload (or hotplug removal).  A PF can call
1396  * this on its VFs to ensure they are unbound first.
1397  */
1398 static void efx_pci_remove(struct pci_dev *pci_dev)
1399 {
1400         struct efx_nic *efx;
1401
1402         efx = pci_get_drvdata(pci_dev);
1403         if (!efx)
1404                 return;
1405
1406         /* Mark the NIC as fini, then stop the interface */
1407         rtnl_lock();
1408         efx_dissociate(efx);
1409         dev_close(efx->net_dev);
1410         efx_disable_interrupts(efx);
1411         efx->state = STATE_UNINIT;
1412         rtnl_unlock();
1413
1414         if (efx->type->sriov_fini)
1415                 efx->type->sriov_fini(efx);
1416
1417         efx_unregister_netdev(efx);
1418
1419         efx_mtd_remove(efx);
1420
1421         efx_pci_remove_main(efx);
1422
1423         efx_fini_io(efx, efx->type->mem_bar(efx));
1424         netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
1425
1426         efx_fini_struct(efx);
1427         free_netdev(efx->net_dev);
1428
1429         pci_disable_pcie_error_reporting(pci_dev);
1430 };
1431
1432 /* NIC VPD information
1433  * Called during probe to display the part number of the
1434  * installed NIC.  VPD is potentially very large but this should
1435  * always appear within the first 512 bytes.
1436  */
1437 #define SFC_VPD_LEN 512
1438 static void efx_probe_vpd_strings(struct efx_nic *efx)
1439 {
1440         struct pci_dev *dev = efx->pci_dev;
1441         char vpd_data[SFC_VPD_LEN];
1442         ssize_t vpd_size;
1443         int ro_start, ro_size, i, j;
1444
1445         /* Get the vpd data from the device */
1446         vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
1447         if (vpd_size <= 0) {
1448                 netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
1449                 return;
1450         }
1451
1452         /* Get the Read only section */
1453         ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
1454         if (ro_start < 0) {
1455                 netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
1456                 return;
1457         }
1458
1459         ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
1460         j = ro_size;
1461         i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
1462         if (i + j > vpd_size)
1463                 j = vpd_size - i;
1464
1465         /* Get the Part number */
1466         i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
1467         if (i < 0) {
1468                 netif_err(efx, drv, efx->net_dev, "Part number not found\n");
1469                 return;
1470         }
1471
1472         j = pci_vpd_info_field_size(&vpd_data[i]);
1473         i += PCI_VPD_INFO_FLD_HDR_SIZE;
1474         if (i + j > vpd_size) {
1475                 netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
1476                 return;
1477         }
1478
1479         netif_info(efx, drv, efx->net_dev,
1480                    "Part Number : %.*s\n", j, &vpd_data[i]);
1481
1482         i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
1483         j = ro_size;
1484         i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
1485         if (i < 0) {
1486                 netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
1487                 return;
1488         }
1489
1490         j = pci_vpd_info_field_size(&vpd_data[i]);
1491         i += PCI_VPD_INFO_FLD_HDR_SIZE;
1492         if (i + j > vpd_size) {
1493                 netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
1494                 return;
1495         }
1496
1497         efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
1498         if (!efx->vpd_sn)
1499                 return;
1500
1501         snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
1502 }
1503
1504
1505 /* Main body of NIC initialisation
1506  * This is called at module load (or hotplug insertion, theoretically).
1507  */
1508 static int efx_pci_probe_main(struct efx_nic *efx)
1509 {
1510         int rc;
1511
1512         /* Do start-of-day initialisation */
1513         rc = efx_probe_all(efx);
1514         if (rc)
1515                 goto fail1;
1516
1517         efx_init_napi(efx);
1518
1519         down_write(&efx->filter_sem);
1520         rc = efx->type->init(efx);
1521         up_write(&efx->filter_sem);
1522         if (rc) {
1523                 netif_err(efx, probe, efx->net_dev,
1524                           "failed to initialise NIC\n");
1525                 goto fail3;
1526         }
1527
1528         rc = efx_init_port(efx);
1529         if (rc) {
1530                 netif_err(efx, probe, efx->net_dev,
1531                           "failed to initialise port\n");
1532                 goto fail4;
1533         }
1534
1535         rc = efx_nic_init_interrupt(efx);
1536         if (rc)
1537                 goto fail5;
1538
1539         efx_set_interrupt_affinity(efx);
1540         rc = efx_enable_interrupts(efx);
1541         if (rc)
1542                 goto fail6;
1543
1544         return 0;
1545
1546  fail6:
1547         efx_clear_interrupt_affinity(efx);
1548         efx_nic_fini_interrupt(efx);
1549  fail5:
1550         efx_fini_port(efx);
1551  fail4:
1552         efx->type->fini(efx);
1553  fail3:
1554         efx_fini_napi(efx);
1555         efx_remove_all(efx);
1556  fail1:
1557         return rc;
1558 }
1559
1560 static int efx_pci_probe_post_io(struct efx_nic *efx)
1561 {
1562         struct net_device *net_dev = efx->net_dev;
1563         int rc = efx_pci_probe_main(efx);
1564
1565         if (rc)
1566                 return rc;
1567
1568         if (efx->type->sriov_init) {
1569                 rc = efx->type->sriov_init(efx);
1570                 if (rc)
1571                         netif_err(efx, probe, efx->net_dev,
1572                                   "SR-IOV can't be enabled rc %d\n", rc);
1573         }
1574
1575         /* Determine netdevice features */
1576         net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
1577                               NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
1578         if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
1579                 net_dev->features |= NETIF_F_TSO6;
1580         /* Check whether device supports TSO */
1581         if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
1582                 net_dev->features &= ~NETIF_F_ALL_TSO;
1583         /* Mask for features that also apply to VLAN devices */
1584         net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
1585                                    NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
1586                                    NETIF_F_RXCSUM);
1587
1588         net_dev->hw_features |= net_dev->features & ~efx->fixed_features;
1589
1590         /* Disable receiving frames with bad FCS, by default. */
1591         net_dev->features &= ~NETIF_F_RXALL;
1592
1593         /* Disable VLAN filtering by default.  It may be enforced if
1594          * the feature is fixed (i.e. VLAN filters are required to
1595          * receive VLAN tagged packets due to vPort restrictions).
1596          */
1597         net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
1598         net_dev->features |= efx->fixed_features;
1599
1600         rc = efx_register_netdev(efx);
1601         if (!rc)
1602                 return 0;
1603
1604         efx_pci_remove_main(efx);
1605         return rc;
1606 }
1607
1608 /* NIC initialisation
1609  *
1610  * This is called at module load (or hotplug insertion,
1611  * theoretically).  It sets up PCI mappings, resets the NIC,
1612  * sets up and registers the network devices with the kernel and hooks
1613  * the interrupt service routine.  It does not prepare the device for
1614  * transmission; this is left to the first time one of the network
1615  * interfaces is brought up (i.e. efx_net_open).
1616  */
1617 static int efx_pci_probe(struct pci_dev *pci_dev,
1618                          const struct pci_device_id *entry)
1619 {
1620         struct net_device *net_dev;
1621         struct efx_nic *efx;
1622         int rc;
1623
1624         /* Allocate and initialise a struct net_device and struct efx_nic */
1625         net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
1626                                      EFX_MAX_RX_QUEUES);
1627         if (!net_dev)
1628                 return -ENOMEM;
1629         efx = netdev_priv(net_dev);
1630         efx->type = (const struct efx_nic_type *) entry->driver_data;
1631         efx->fixed_features |= NETIF_F_HIGHDMA;
1632
1633         pci_set_drvdata(pci_dev, efx);
1634         SET_NETDEV_DEV(net_dev, &pci_dev->dev);
1635         rc = efx_init_struct(efx, pci_dev, net_dev);
1636         if (rc)
1637                 goto fail1;
1638
1639         netif_info(efx, probe, efx->net_dev,
1640                    "Solarflare NIC detected\n");
1641
1642         if (!efx->type->is_vf)
1643                 efx_probe_vpd_strings(efx);
1644
1645         /* Set up basic I/O (BAR mappings etc) */
1646         rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask,
1647                          efx->type->mem_map_size(efx));
1648         if (rc)
1649                 goto fail2;
1650
1651         rc = efx_pci_probe_post_io(efx);
1652         if (rc) {
1653                 /* On failure, retry once immediately.
1654                  * If we aborted probe due to a scheduled reset, dismiss it.
1655                  */
1656                 efx->reset_pending = 0;
1657                 rc = efx_pci_probe_post_io(efx);
1658                 if (rc) {
1659                         /* On another failure, retry once more
1660                          * after a 50-305ms delay.
1661                          */
1662                         unsigned char r;
1663
1664                         get_random_bytes(&r, 1);
1665                         msleep((unsigned int)r + 50);
1666                         efx->reset_pending = 0;
1667                         rc = efx_pci_probe_post_io(efx);
1668                 }
1669         }
1670         if (rc)
1671                 goto fail3;
1672
1673         netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
1674
1675         /* Try to create MTDs, but allow this to fail */
1676         rtnl_lock();
1677         rc = efx_mtd_probe(efx);
1678         rtnl_unlock();
1679         if (rc && rc != -EPERM)
1680                 netif_warn(efx, probe, efx->net_dev,
1681                            "failed to create MTDs (%d)\n", rc);
1682
1683         (void)pci_enable_pcie_error_reporting(pci_dev);
1684
1685         if (efx->type->udp_tnl_push_ports)
1686                 efx->type->udp_tnl_push_ports(efx);
1687
1688         return 0;
1689
1690  fail3:
1691         efx_fini_io(efx, efx->type->mem_bar(efx));
1692  fail2:
1693         efx_fini_struct(efx);
1694  fail1:
1695         WARN_ON(rc > 0);
1696         netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
1697         free_netdev(net_dev);
1698         return rc;
1699 }
1700
1701 /* efx_pci_sriov_configure returns the actual number of Virtual Functions
1702  * enabled on success
1703  */
1704 #ifdef CONFIG_SFC_SRIOV
1705 static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
1706 {
1707         int rc;
1708         struct efx_nic *efx = pci_get_drvdata(dev);
1709
1710         if (efx->type->sriov_configure) {
1711                 rc = efx->type->sriov_configure(efx, num_vfs);
1712                 if (rc)
1713                         return rc;
1714                 else
1715                         return num_vfs;
1716         } else
1717                 return -EOPNOTSUPP;
1718 }
1719 #endif
1720
1721 static int efx_pm_freeze(struct device *dev)
1722 {
1723         struct efx_nic *efx = dev_get_drvdata(dev);
1724
1725         rtnl_lock();
1726
1727         if (efx->state != STATE_DISABLED) {
1728                 efx->state = STATE_UNINIT;
1729
1730                 efx_device_detach_sync(efx);
1731
1732                 efx_stop_all(efx);
1733                 efx_disable_interrupts(efx);
1734         }
1735
1736         rtnl_unlock();
1737
1738         return 0;
1739 }
1740
1741 static int efx_pm_thaw(struct device *dev)
1742 {
1743         int rc;
1744         struct efx_nic *efx = dev_get_drvdata(dev);
1745
1746         rtnl_lock();
1747
1748         if (efx->state != STATE_DISABLED) {
1749                 rc = efx_enable_interrupts(efx);
1750                 if (rc)
1751                         goto fail;
1752
1753                 mutex_lock(&efx->mac_lock);
1754                 efx->phy_op->reconfigure(efx);
1755                 mutex_unlock(&efx->mac_lock);
1756
1757                 efx_start_all(efx);
1758
1759                 efx_device_attach_if_not_resetting(efx);
1760
1761                 efx->state = STATE_READY;
1762
1763                 efx->type->resume_wol(efx);
1764         }
1765
1766         rtnl_unlock();
1767
1768         /* Reschedule any quenched resets scheduled during efx_pm_freeze() */
1769         efx_queue_reset_work(efx);
1770
1771         return 0;
1772
1773 fail:
1774         rtnl_unlock();
1775
1776         return rc;
1777 }
1778
1779 static int efx_pm_poweroff(struct device *dev)
1780 {
1781         struct pci_dev *pci_dev = to_pci_dev(dev);
1782         struct efx_nic *efx = pci_get_drvdata(pci_dev);
1783
1784         efx->type->fini(efx);
1785
1786         efx->reset_pending = 0;
1787
1788         pci_save_state(pci_dev);
1789         return pci_set_power_state(pci_dev, PCI_D3hot);
1790 }
1791
1792 /* Used for both resume and restore */
1793 static int efx_pm_resume(struct device *dev)
1794 {
1795         struct pci_dev *pci_dev = to_pci_dev(dev);
1796         struct efx_nic *efx = pci_get_drvdata(pci_dev);
1797         int rc;
1798
1799         rc = pci_set_power_state(pci_dev, PCI_D0);
1800         if (rc)
1801                 return rc;
1802         pci_restore_state(pci_dev);
1803         rc = pci_enable_device(pci_dev);
1804         if (rc)
1805                 return rc;
1806         pci_set_master(efx->pci_dev);
1807         rc = efx->type->reset(efx, RESET_TYPE_ALL);
1808         if (rc)
1809                 return rc;
1810         down_write(&efx->filter_sem);
1811         rc = efx->type->init(efx);
1812         up_write(&efx->filter_sem);
1813         if (rc)
1814                 return rc;
1815         rc = efx_pm_thaw(dev);
1816         return rc;
1817 }
1818
1819 static int efx_pm_suspend(struct device *dev)
1820 {
1821         int rc;
1822
1823         efx_pm_freeze(dev);
1824         rc = efx_pm_poweroff(dev);
1825         if (rc)
1826                 efx_pm_resume(dev);
1827         return rc;
1828 }
1829
1830 static const struct dev_pm_ops efx_pm_ops = {
1831         .suspend        = efx_pm_suspend,
1832         .resume         = efx_pm_resume,
1833         .freeze         = efx_pm_freeze,
1834         .thaw           = efx_pm_thaw,
1835         .poweroff       = efx_pm_poweroff,
1836         .restore        = efx_pm_resume,
1837 };
1838
1839 /* A PCI error affecting this device was detected.
1840  * At this point MMIO and DMA may be disabled.
1841  * Stop the software path and request a slot reset.
1842  */
1843 static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
1844                                               enum pci_channel_state state)
1845 {
1846         pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
1847         struct efx_nic *efx = pci_get_drvdata(pdev);
1848
1849         if (state == pci_channel_io_perm_failure)
1850                 return PCI_ERS_RESULT_DISCONNECT;
1851
1852         rtnl_lock();
1853
1854         if (efx->state != STATE_DISABLED) {
1855                 efx->state = STATE_RECOVERY;
1856                 efx->reset_pending = 0;
1857
1858                 efx_device_detach_sync(efx);
1859
1860                 efx_stop_all(efx);
1861                 efx_disable_interrupts(efx);
1862
1863                 status = PCI_ERS_RESULT_NEED_RESET;
1864         } else {
1865                 /* If the interface is disabled we don't want to do anything
1866                  * with it.
1867                  */
1868                 status = PCI_ERS_RESULT_RECOVERED;
1869         }
1870
1871         rtnl_unlock();
1872
1873         pci_disable_device(pdev);
1874
1875         return status;
1876 }
1877
1878 /* Fake a successful reset, which will be performed later in efx_io_resume. */
1879 static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
1880 {
1881         struct efx_nic *efx = pci_get_drvdata(pdev);
1882         pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
1883
1884         if (pci_enable_device(pdev)) {
1885                 netif_err(efx, hw, efx->net_dev,
1886                           "Cannot re-enable PCI device after reset.\n");
1887                 status =  PCI_ERS_RESULT_DISCONNECT;
1888         }
1889
1890         return status;
1891 }
1892
1893 /* Perform the actual reset and resume I/O operations. */
1894 static void efx_io_resume(struct pci_dev *pdev)
1895 {
1896         struct efx_nic *efx = pci_get_drvdata(pdev);
1897         int rc;
1898
1899         rtnl_lock();
1900
1901         if (efx->state == STATE_DISABLED)
1902                 goto out;
1903
1904         rc = efx_reset(efx, RESET_TYPE_ALL);
1905         if (rc) {
1906                 netif_err(efx, hw, efx->net_dev,
1907                           "efx_reset failed after PCI error (%d)\n", rc);
1908         } else {
1909                 efx->state = STATE_READY;
1910                 netif_dbg(efx, hw, efx->net_dev,
1911                           "Done resetting and resuming IO after PCI error.\n");
1912         }
1913
1914 out:
1915         rtnl_unlock();
1916 }
1917
1918 /* For simplicity and reliability, we always require a slot reset and try to
1919  * reset the hardware when a pci error affecting the device is detected.
1920  * We leave both the link_reset and mmio_enabled callback unimplemented:
1921  * with our request for slot reset the mmio_enabled callback will never be
1922  * called, and the link_reset callback is not used by AER or EEH mechanisms.
1923  */
1924 static const struct pci_error_handlers efx_err_handlers = {
1925         .error_detected = efx_io_error_detected,
1926         .slot_reset     = efx_io_slot_reset,
1927         .resume         = efx_io_resume,
1928 };
1929
1930 static struct pci_driver efx_pci_driver = {
1931         .name           = KBUILD_MODNAME,
1932         .id_table       = efx_pci_table,
1933         .probe          = efx_pci_probe,
1934         .remove         = efx_pci_remove,
1935         .driver.pm      = &efx_pm_ops,
1936         .err_handler    = &efx_err_handlers,
1937 #ifdef CONFIG_SFC_SRIOV
1938         .sriov_configure = efx_pci_sriov_configure,
1939 #endif
1940 };
1941
1942 /**************************************************************************
1943  *
1944  * Kernel module interface
1945  *
1946  *************************************************************************/
1947
1948 static int __init efx_init_module(void)
1949 {
1950         int rc;
1951
1952         printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
1953
1954         rc = register_netdevice_notifier(&efx_netdev_notifier);
1955         if (rc)
1956                 goto err_notifier;
1957
1958 #ifdef CONFIG_SFC_SRIOV
1959         rc = efx_init_sriov();
1960         if (rc)
1961                 goto err_sriov;
1962 #endif
1963
1964         rc = efx_create_reset_workqueue();
1965         if (rc)
1966                 goto err_reset;
1967
1968         rc = pci_register_driver(&efx_pci_driver);
1969         if (rc < 0)
1970                 goto err_pci;
1971
1972         return 0;
1973
1974  err_pci:
1975         efx_destroy_reset_workqueue();
1976  err_reset:
1977 #ifdef CONFIG_SFC_SRIOV
1978         efx_fini_sriov();
1979  err_sriov:
1980 #endif
1981         unregister_netdevice_notifier(&efx_netdev_notifier);
1982  err_notifier:
1983         return rc;
1984 }
1985
1986 static void __exit efx_exit_module(void)
1987 {
1988         printk(KERN_INFO "Solarflare NET driver unloading\n");
1989
1990         pci_unregister_driver(&efx_pci_driver);
1991         efx_destroy_reset_workqueue();
1992 #ifdef CONFIG_SFC_SRIOV
1993         efx_fini_sriov();
1994 #endif
1995         unregister_netdevice_notifier(&efx_netdev_notifier);
1996
1997 }
1998
1999 module_init(efx_init_module);
2000 module_exit(efx_exit_module);
2001
2002 MODULE_AUTHOR("Solarflare Communications and "
2003               "Michael Brown <mbrown@fensystems.co.uk>");
2004 MODULE_DESCRIPTION("Solarflare network driver");
2005 MODULE_LICENSE("GPL");
2006 MODULE_DEVICE_TABLE(pci, efx_pci_table);
2007 MODULE_VERSION(EFX_DRIVER_VERSION);