efx.c 79.2 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2
/****************************************************************************
B
Ben Hutchings 已提交
3
 * Driver for Solarflare network controllers and boards
4
 * Copyright 2005-2006 Fen Systems Ltd.
B
Ben Hutchings 已提交
5
 * Copyright 2005-2013 Solarflare Communications Inc.
6 7 8 9 10 11 12 13 14 15 16 17
 */

#include <linux/module.h>
#include <linux/pci.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/notifier.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/in.h>
#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 24
#include <net/gre.h>
#include <net/udp_tunnel.h>
25
#include "efx.h"
26 27 28 29
#include "efx_common.h"
#include "efx_channels.h"
#include "rx_common.h"
#include "tx_common.h"
B
Ben Hutchings 已提交
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 42 43 44 45
/**************************************************************************
 *
 * Type name strings
 *
 **************************************************************************
 */

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/* UDP tunnel type names */
static const char *const efx_udp_tunnel_type_names[] = {
	[TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN] = "vxlan",
	[TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE] = "geneve",
};

void efx_get_udp_tunnel_type_name(u16 type, char *buf, size_t buflen)
{
	if (type < ARRAY_SIZE(efx_udp_tunnel_type_names) &&
	    efx_udp_tunnel_type_names[type] != NULL)
		snprintf(buf, buflen, "%s", efx_udp_tunnel_type_names[type]);
	else
		snprintf(buf, buflen, "type %d", type);
}

61 62 63 64 65 66 67 68 69
/**************************************************************************
 *
 * Configurable values
 *
 *************************************************************************/

/*
 * Use separate channels for TX and RX events
 *
70 71
 * Set this to 1 to use separate channels for TX and RX. It allows us
 * to control interrupt affinity separately for TX and RX.
72
 *
73
 * This is only used in MSI-X interrupt mode
74
 */
75 76 77
bool efx_separate_tx_channels;
module_param(efx_separate_tx_channels, bool, 0444);
MODULE_PARM_DESC(efx_separate_tx_channels,
78
		 "Use separate channels for TX and RX");
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

/* This is the weight assigned to each of the (per-channel) virtual
 * NAPI devices.
 */
static int napi_weight = 64;

/* Initial interrupt moderation settings.  They can be modified after
 * module load with ethtool.
 *
 * The default for RX should strike a balance between increasing the
 * round-trip latency and reducing overhead.
 */
static unsigned int rx_irq_mod_usec = 60;

/* Initial interrupt moderation settings.  They can be modified after
 * module load with ethtool.
 *
 * This default is chosen to ensure that a 10G link does not go idle
 * while a TX queue is stopped after it has become full.  A queue is
 * restarted when it drops below half full.  The time this takes (assuming
 * worst case 3 descriptors per packet and 1024 descriptors) is
 *   512 / 3 * 1.2 = 205 usec.
 */
static unsigned int tx_irq_mod_usec = 150;

/* This is the first interrupt mode to try out of:
 * 0 => MSI-X
 * 1 => MSI
 * 2 => legacy
 */
static unsigned int interrupt_mode;

/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
 * i.e. the number of CPUs among which we may distribute simultaneous
 * interrupt handling.
 *
 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
116
 * The default (0) means to assign an interrupt to each core.
117 118 119 120 121
 */
static unsigned int rss_cpus;
module_param(rss_cpus, uint, 0444);
MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");

122 123
static bool phy_flash_cfg;
module_param(phy_flash_cfg, bool, 0644);
124 125
MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially");

126
static unsigned irq_adapt_low_thresh = 8000;
127 128 129 130
module_param(irq_adapt_low_thresh, uint, 0644);
MODULE_PARM_DESC(irq_adapt_low_thresh,
		 "Threshold score for reducing IRQ moderation");

131
static unsigned irq_adapt_high_thresh = 16000;
132 133 134 135
module_param(irq_adapt_high_thresh, uint, 0644);
MODULE_PARM_DESC(irq_adapt_high_thresh,
		 "Threshold score for increasing IRQ moderation");

136 137 138 139 140 141 142
static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE |
			 NETIF_MSG_LINK | NETIF_MSG_IFDOWN |
			 NETIF_MSG_IFUP | NETIF_MSG_RX_ERR |
			 NETIF_MSG_TX_ERR | NETIF_MSG_HW);
module_param(debug, uint, 0);
MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value");

143 144 145 146 147
/**************************************************************************
 *
 * Utility functions and prototypes
 *
 *************************************************************************/
148

149
static const struct efx_channel_type efx_default_channel_type;
150
static void efx_remove_port(struct efx_nic *efx);
151 152
static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog);
static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp);
153 154
static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
			u32 flags);
155 156 157

#define EFX_ASSERT_RESET_SERIALISED(efx)		\
	do {						\
158
		if ((efx->state == STATE_READY) ||	\
159
		    (efx->state == STATE_RECOVERY) ||	\
160
		    (efx->state == STATE_DISABLED))	\
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
			ASSERT_RTNL();			\
	} while (0)

/**************************************************************************
 *
 * Event queue processing
 *
 *************************************************************************/

/* Process channel's event queue
 *
 * This function is responsible for processing the event queue of a
 * single channel.  The caller must guarantee that this function will
 * never be concurrently called more than once on the same channel,
 * though different channels may be being processed concurrently.
 */
177
static int efx_process_channel(struct efx_channel *channel, int budget)
178
{
179
	struct efx_tx_queue *tx_queue;
E
Edward Cree 已提交
180
	struct list_head rx_list;
181
	int spent;
182

183
	if (unlikely(!channel->enabled))
B
Ben Hutchings 已提交
184
		return 0;
185

E
Edward Cree 已提交
186 187 188 189 190
	/* Prepare the batch receive list */
	EFX_WARN_ON_PARANOID(channel->rx_list != NULL);
	INIT_LIST_HEAD(&rx_list);
	channel->rx_list = &rx_list;

191 192 193 194 195
	efx_for_each_channel_tx_queue(tx_queue, channel) {
		tx_queue->pkts_compl = 0;
		tx_queue->bytes_compl = 0;
	}

196
	spent = efx_nic_process_eventq(channel, budget);
197 198 199 200
	if (spent && efx_channel_has_rx_queue(channel)) {
		struct efx_rx_queue *rx_queue =
			efx_channel_get_rx_queue(channel);

201
		efx_rx_flush_packet(channel);
202
		efx_fast_push_rx_descriptors(rx_queue, true);
203 204
	}

205 206 207 208 209 210 211 212
	/* Update BQL */
	efx_for_each_channel_tx_queue(tx_queue, channel) {
		if (tx_queue->bytes_compl) {
			netdev_tx_completed_queue(tx_queue->core_txq,
				tx_queue->pkts_compl, tx_queue->bytes_compl);
		}
	}

E
Edward Cree 已提交
213 214 215 216
	/* Receive any packets we queued up */
	netif_receive_skb_list(channel->rx_list);
	channel->rx_list = NULL;

217
	return spent;
218 219 220 221 222 223 224
}

/* NAPI poll handler
 *
 * NAPI guarantees serialisation of polls of the same device, which
 * provides the guarantee required by efx_process_channel().
 */
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
static void efx_update_irq_mod(struct efx_nic *efx, struct efx_channel *channel)
{
	int step = efx->irq_mod_step_us;

	if (channel->irq_mod_score < irq_adapt_low_thresh) {
		if (channel->irq_moderation_us > step) {
			channel->irq_moderation_us -= step;
			efx->type->push_irq_moderation(channel);
		}
	} else if (channel->irq_mod_score > irq_adapt_high_thresh) {
		if (channel->irq_moderation_us <
		    efx->irq_rx_moderation_us) {
			channel->irq_moderation_us += step;
			efx->type->push_irq_moderation(channel);
		}
	}

	channel->irq_count = 0;
	channel->irq_mod_score = 0;
}

246 247 248 249
static int efx_poll(struct napi_struct *napi, int budget)
{
	struct efx_channel *channel =
		container_of(napi, struct efx_channel, napi_str);
250
	struct efx_nic *efx = channel->efx;
251
	int spent;
252

253 254 255
	netif_vdbg(efx, intr, efx->net_dev,
		   "channel %d NAPI poll executing on CPU %d\n",
		   channel->channel, raw_smp_processor_id());
256

257
	spent = efx_process_channel(channel, budget);
258

259 260
	xdp_do_flush_map();

261
	if (spent < budget) {
262
		if (efx_channel_has_rx_queue(channel) &&
263 264
		    efx->irq_rx_adaptive &&
		    unlikely(++channel->irq_count == 1000)) {
265
			efx_update_irq_mod(efx, channel);
266 267
		}

268 269
#ifdef CONFIG_RFS_ACCEL
		/* Perhaps expire some ARFS filters */
270
		mod_delayed_work(system_wq, &channel->filter_work, 0);
271
#endif
272

273
		/* There is no race here; although napi_disable() will
274
		 * only wait for napi_complete(), this isn't a problem
275
		 * since efx_nic_eventq_read_ack() will have no effect if
276 277
		 * interrupts have already been disabled.
		 */
278 279
		if (napi_complete_done(napi, spent))
			efx_nic_eventq_read_ack(channel);
280 281
	}

282
	return spent;
283 284 285 286 287 288 289
}

/* Create event queue
 * Event queue memory allocations are done only once.  If the channel
 * is reset, the memory buffer will be reused; this guards against
 * errors during channel reset and also simplifies interrupt handling.
 */
290
int efx_probe_eventq(struct efx_channel *channel)
291
{
292 293 294
	struct efx_nic *efx = channel->efx;
	unsigned long entries;

295
	netif_dbg(efx, probe, efx->net_dev,
296
		  "chan %d create event queue\n", channel->channel);
297

298 299 300
	/* Build an event queue with room for one event per tx and rx buffer,
	 * plus some extra for link state events and MCDI completions. */
	entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
301
	EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
302 303
	channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;

304
	return efx_nic_probe_eventq(channel);
305 306 307
}

/* Prepare channel's event queue */
308
int efx_init_eventq(struct efx_channel *channel)
309
{
310
	struct efx_nic *efx = channel->efx;
311 312 313 314
	int rc;

	EFX_WARN_ON_PARANOID(channel->eventq_init);

315
	netif_dbg(efx, drv, efx->net_dev,
316
		  "chan %d init event queue\n", channel->channel);
317

318 319
	rc = efx_nic_init_eventq(channel);
	if (rc == 0) {
320
		efx->type->push_irq_moderation(channel);
321 322 323 324
		channel->eventq_read_ptr = 0;
		channel->eventq_init = true;
	}
	return rc;
325 326
}

327
/* Enable event queue processing and NAPI */
328
void efx_start_eventq(struct efx_channel *channel)
329 330 331 332
{
	netif_dbg(channel->efx, ifup, channel->efx->net_dev,
		  "chan %d start event queue\n", channel->channel);

333
	/* Make sure the NAPI handler sees the enabled flag set */
334 335 336 337 338 339 340 341
	channel->enabled = true;
	smp_wmb();

	napi_enable(&channel->napi_str);
	efx_nic_eventq_read_ack(channel);
}

/* Disable event queue processing and NAPI */
342
void efx_stop_eventq(struct efx_channel *channel)
343 344 345 346 347 348 349 350
{
	if (!channel->enabled)
		return;

	napi_disable(&channel->napi_str);
	channel->enabled = false;
}

351
void efx_fini_eventq(struct efx_channel *channel)
352
{
353 354 355
	if (!channel->eventq_init)
		return;

356 357
	netif_dbg(channel->efx, drv, channel->efx->net_dev,
		  "chan %d fini event queue\n", channel->channel);
358

359
	efx_nic_fini_eventq(channel);
360
	channel->eventq_init = false;
361 362
}

363
void efx_remove_eventq(struct efx_channel *channel)
364
{
365 366
	netif_dbg(channel->efx, drv, channel->efx->net_dev,
		  "chan %d remove event queue\n", channel->channel);
367

368
	efx_nic_remove_eventq(channel);
369 370 371 372 373 374 375 376
}

/**************************************************************************
 *
 * Channel handling
 *
 *************************************************************************/

377
/* Allocate and initialise a channel structure. */
378
struct efx_channel *
379 380 381 382 383 384 385
efx_alloc_channel(struct efx_nic *efx, int i, struct efx_channel *old_channel)
{
	struct efx_channel *channel;
	struct efx_rx_queue *rx_queue;
	struct efx_tx_queue *tx_queue;
	int j;

386 387 388
	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
	if (!channel)
		return NULL;
389

390 391 392
	channel->efx = efx;
	channel->channel = i;
	channel->type = &efx_default_channel_type;
393

394 395 396 397 398 399
	for (j = 0; j < EFX_TXQ_TYPES; j++) {
		tx_queue = &channel->tx_queue[j];
		tx_queue->efx = efx;
		tx_queue->queue = i * EFX_TXQ_TYPES + j;
		tx_queue->channel = channel;
	}
400

401
#ifdef CONFIG_RFS_ACCEL
402
	INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire);
403 404
#endif

405 406
	rx_queue = &channel->rx_queue;
	rx_queue->efx = efx;
407
	timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
408

409 410 411 412 413 414
	return channel;
}

/* Allocate and initialise a channel structure, copying parameters
 * (but not resources) from an old channel structure.
 */
415
struct efx_channel *efx_copy_channel(const struct efx_channel *old_channel)
416 417 418 419 420
{
	struct efx_channel *channel;
	struct efx_rx_queue *rx_queue;
	struct efx_tx_queue *tx_queue;
	int j;
421

422 423 424 425 426 427 428
	channel = kmalloc(sizeof(*channel), GFP_KERNEL);
	if (!channel)
		return NULL;

	*channel = *old_channel;

	channel->napi_dev = NULL;
429 430 431
	INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
	channel->napi_str.napi_id = 0;
	channel->napi_str.state = 0;
432
	memset(&channel->eventq, 0, sizeof(channel->eventq));
433

434 435 436
	for (j = 0; j < EFX_TXQ_TYPES; j++) {
		tx_queue = &channel->tx_queue[j];
		if (tx_queue->channel)
437
			tx_queue->channel = channel;
438 439
		tx_queue->buffer = NULL;
		memset(&tx_queue->txd, 0, sizeof(tx_queue->txd));
440 441 442
	}

	rx_queue = &channel->rx_queue;
443 444
	rx_queue->buffer = NULL;
	memset(&rx_queue->rxd, 0, sizeof(rx_queue->rxd));
445
	timer_setup(&rx_queue->slow_fill, efx_rx_slow_fill, 0);
446
#ifdef CONFIG_RFS_ACCEL
447
	INIT_DELAYED_WORK(&channel->filter_work, efx_filter_rfs_expire);
448
#endif
449 450 451 452

	return channel;
}

453 454 455 456 457 458
static int efx_probe_channel(struct efx_channel *channel)
{
	struct efx_tx_queue *tx_queue;
	struct efx_rx_queue *rx_queue;
	int rc;

459 460
	netif_dbg(channel->efx, probe, channel->efx->net_dev,
		  "creating channel %d\n", channel->channel);
461

462 463 464 465
	rc = channel->type->pre_probe(channel);
	if (rc)
		goto fail;

466 467
	rc = efx_probe_eventq(channel);
	if (rc)
468
		goto fail;
469 470 471 472

	efx_for_each_channel_tx_queue(tx_queue, channel) {
		rc = efx_probe_tx_queue(tx_queue);
		if (rc)
473
			goto fail;
474 475 476 477 478
	}

	efx_for_each_channel_rx_queue(rx_queue, channel) {
		rc = efx_probe_rx_queue(rx_queue);
		if (rc)
479
			goto fail;
480 481
	}

E
Edward Cree 已提交
482 483
	channel->rx_list = NULL;

484 485
	return 0;

486 487
fail:
	efx_remove_channel(channel);
488 489 490
	return rc;
}

491
void efx_get_channel_name(struct efx_channel *channel, char *buf, size_t len)
492 493 494 495 496 497
{
	struct efx_nic *efx = channel->efx;
	const char *type;
	int number;

	number = channel->channel;
498 499 500 501 502 503

	if (number >= efx->xdp_channel_offset &&
	    !WARN_ON_ONCE(!efx->n_xdp_channels)) {
		type = "-xdp";
		number -= efx->xdp_channel_offset;
	} else if (efx->tx_channel_offset == 0) {
504
		type = "";
505
	} else if (number < efx->tx_channel_offset) {
506 507 508 509 510 511 512
		type = "-rx";
	} else {
		type = "-tx";
		number -= efx->tx_channel_offset;
	}
	snprintf(buf, len, "%s%s-%d", efx->name, type, number);
}
513

514
void efx_set_channel_names(struct efx_nic *efx)
515 516 517
{
	struct efx_channel *channel;

518 519
	efx_for_each_channel(channel, efx)
		channel->type->get_name(channel,
B
Ben Hutchings 已提交
520 521
					efx->msi_context[channel->channel].name,
					sizeof(efx->msi_context[0].name));
522 523
}

524
int efx_probe_channels(struct efx_nic *efx)
525 526 527 528 529 530 531
{
	struct efx_channel *channel;
	int rc;

	/* Restart special buffer allocation */
	efx->next_buffer_table = 0;

532 533 534 535 536 537
	/* Probe channels in reverse, so that any 'extra' channels
	 * use the start of the buffer table. This allows the traffic
	 * channels to be resized without moving them or wasting the
	 * entries before them.
	 */
	efx_for_each_channel_rev(channel, efx) {
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
		rc = efx_probe_channel(channel);
		if (rc) {
			netif_err(efx, probe, efx->net_dev,
				  "failed to create channel %d\n",
				  channel->channel);
			goto fail;
		}
	}
	efx_set_channel_names(efx);

	return 0;

fail:
	efx_remove_channels(efx);
	return rc;
}

555
void efx_remove_channel(struct efx_channel *channel)
556 557 558 559
{
	struct efx_tx_queue *tx_queue;
	struct efx_rx_queue *rx_queue;

560 561
	netif_dbg(channel->efx, drv, channel->efx->net_dev,
		  "destroy chan %d\n", channel->channel);
562 563 564

	efx_for_each_channel_rx_queue(rx_queue, channel)
		efx_remove_rx_queue(rx_queue);
565
	efx_for_each_possible_channel_tx_queue(tx_queue, channel)
566 567
		efx_remove_tx_queue(tx_queue);
	efx_remove_eventq(channel);
568
	channel->type->post_remove(channel);
569 570
}

571
void efx_remove_channels(struct efx_nic *efx)
572 573 574 575 576
{
	struct efx_channel *channel;

	efx_for_each_channel(channel, efx)
		efx_remove_channel(channel);
577 578

	kfree(efx->xdp_tx_queues);
579 580
}

581
int efx_realloc_channels(struct efx_nic *efx, u32 rxq_entries, u32 txq_entries)
582 583 584
{
	struct efx_channel *other_channel[EFX_MAX_CHANNELS], *channel;
	u32 old_rxq_entries, old_txq_entries;
585
	unsigned i, next_buffer_table = 0;
586
	int rc, rc2;
587 588 589 590

	rc = efx_check_disabled(efx);
	if (rc)
		return rc;
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612

	/* Not all channels should be reallocated. We must avoid
	 * reallocating their buffer table entries.
	 */
	efx_for_each_channel(channel, efx) {
		struct efx_rx_queue *rx_queue;
		struct efx_tx_queue *tx_queue;

		if (channel->type->copy)
			continue;
		next_buffer_table = max(next_buffer_table,
					channel->eventq.index +
					channel->eventq.entries);
		efx_for_each_channel_rx_queue(rx_queue, channel)
			next_buffer_table = max(next_buffer_table,
						rx_queue->rxd.index +
						rx_queue->rxd.entries);
		efx_for_each_channel_tx_queue(tx_queue, channel)
			next_buffer_table = max(next_buffer_table,
						tx_queue->txd.index +
						tx_queue->txd.entries);
	}
613

614
	efx_device_detach_sync(efx);
615
	efx_stop_all(efx);
B
Ben Hutchings 已提交
616
	efx_soft_disable_interrupts(efx);
617

618
	/* Clone channels (where possible) */
619 620
	memset(other_channel, 0, sizeof(other_channel));
	for (i = 0; i < efx->n_channels; i++) {
621 622 623
		channel = efx->channel[i];
		if (channel->type->copy)
			channel = channel->type->copy(channel);
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
		if (!channel) {
			rc = -ENOMEM;
			goto out;
		}
		other_channel[i] = channel;
	}

	/* Swap entry counts and channel pointers */
	old_rxq_entries = efx->rxq_entries;
	old_txq_entries = efx->txq_entries;
	efx->rxq_entries = rxq_entries;
	efx->txq_entries = txq_entries;
	for (i = 0; i < efx->n_channels; i++) {
		channel = efx->channel[i];
		efx->channel[i] = other_channel[i];
		other_channel[i] = channel;
	}

642 643
	/* Restart buffer table allocation */
	efx->next_buffer_table = next_buffer_table;
644 645

	for (i = 0; i < efx->n_channels; i++) {
646 647 648 649 650 651 652
		channel = efx->channel[i];
		if (!channel->type->copy)
			continue;
		rc = efx_probe_channel(channel);
		if (rc)
			goto rollback;
		efx_init_napi_channel(efx->channel[i]);
653
	}
654

655
out:
656 657 658 659 660 661 662 663 664
	/* Destroy unused channel structures */
	for (i = 0; i < efx->n_channels; i++) {
		channel = other_channel[i];
		if (channel && channel->type->copy) {
			efx_fini_napi_channel(channel);
			efx_remove_channel(channel);
			kfree(channel);
		}
	}
665

666 667 668 669 670 671 672 673
	rc2 = efx_soft_enable_interrupts(efx);
	if (rc2) {
		rc = rc ? rc : rc2;
		netif_err(efx, drv, efx->net_dev,
			  "unable to restart interrupts on channel reallocation\n");
		efx_schedule_reset(efx, RESET_TYPE_DISABLE);
	} else {
		efx_start_all(efx);
674
		efx_device_attach_if_not_resetting(efx);
675
	}
676 677 678 679 680 681 682 683 684 685 686 687 688 689
	return rc;

rollback:
	/* Swap back */
	efx->rxq_entries = old_rxq_entries;
	efx->txq_entries = old_txq_entries;
	for (i = 0; i < efx->n_channels; i++) {
		channel = efx->channel[i];
		efx->channel[i] = other_channel[i];
		other_channel[i] = channel;
	}
	goto out;
}

690
void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue)
691
{
692
	mod_timer(&rx_queue->slow_fill, jiffies + msecs_to_jiffies(10));
693 694
}

695
bool efx_default_channel_want_txqs(struct efx_channel *channel)
696 697 698 699 700
{
	return channel->channel - channel->efx->tx_channel_offset <
		channel->efx->n_tx_channels;
}

701 702
static const struct efx_channel_type efx_default_channel_type = {
	.pre_probe		= efx_channel_dummy_op_int,
703
	.post_remove		= efx_channel_dummy_op_void,
704 705
	.get_name		= efx_get_channel_name,
	.copy			= efx_copy_channel,
706
	.want_txqs		= efx_default_channel_want_txqs,
707
	.keep_eventq		= false,
708
	.want_pio		= true,
709 710 711 712 713 714 715
};

int efx_channel_dummy_op_int(struct efx_channel *channel)
{
	return 0;
}

716 717 718 719
void efx_channel_dummy_op_void(struct efx_channel *channel)
{
}

720 721 722 723 724 725
/**************************************************************************
 *
 * Port handling
 *
 **************************************************************************/

726 727
void efx_link_set_advertising(struct efx_nic *efx,
			      const unsigned long *advertising)
B
Ben Hutchings 已提交
728
{
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
	memcpy(efx->link_advertising, advertising,
	       sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));

	efx->link_advertising[0] |= ADVERTISED_Autoneg;
	if (advertising[0] & ADVERTISED_Pause)
		efx->wanted_fc |= (EFX_FC_TX | EFX_FC_RX);
	else
		efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
	if (advertising[0] & ADVERTISED_Asym_Pause)
		efx->wanted_fc ^= EFX_FC_TX;
}

/* Equivalent to efx_link_set_advertising with all-zeroes, except does not
 * force the Autoneg bit on.
 */
void efx_link_clear_advertising(struct efx_nic *efx)
{
	bitmap_zero(efx->link_advertising, __ETHTOOL_LINK_MODE_MASK_NBITS);
	efx->wanted_fc &= ~(EFX_FC_TX | EFX_FC_RX);
B
Ben Hutchings 已提交
748 749
}

750
void efx_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc)
B
Ben Hutchings 已提交
751 752
{
	efx->wanted_fc = wanted_fc;
753
	if (efx->link_advertising[0]) {
B
Ben Hutchings 已提交
754
		if (wanted_fc & EFX_FC_RX)
755 756
			efx->link_advertising[0] |= (ADVERTISED_Pause |
						     ADVERTISED_Asym_Pause);
B
Ben Hutchings 已提交
757
		else
758 759
			efx->link_advertising[0] &= ~(ADVERTISED_Pause |
						      ADVERTISED_Asym_Pause);
B
Ben Hutchings 已提交
760
		if (wanted_fc & EFX_FC_TX)
761
			efx->link_advertising[0] ^= ADVERTISED_Asym_Pause;
B
Ben Hutchings 已提交
762 763 764
	}
}

765 766
static void efx_fini_port(struct efx_nic *efx);

767 768 769 770
static int efx_probe_port(struct efx_nic *efx)
{
	int rc;

771
	netif_dbg(efx, probe, efx->net_dev, "create port\n");
772

773 774 775
	if (phy_flash_cfg)
		efx->phy_mode = PHY_MODE_SPECIAL;

776 777
	/* Connect up MAC/PHY operations table */
	rc = efx->type->probe_port(efx);
778
	if (rc)
779
		return rc;
780

781
	/* Initialise MAC address to permanent address */
782
	ether_addr_copy(efx->net_dev->dev_addr, efx->net_dev->perm_addr);
783 784 785 786 787 788 789 790

	return 0;
}

static int efx_init_port(struct efx_nic *efx)
{
	int rc;

791
	netif_dbg(efx, drv, efx->net_dev, "init port\n");
792

793 794
	mutex_lock(&efx->mac_lock);

795
	rc = efx->phy_op->init(efx);
796
	if (rc)
797
		goto fail1;
798

799
	efx->port_initialized = true;
800

B
Ben Hutchings 已提交
801 802
	/* Reconfigure the MAC before creating dma queues (required for
	 * Falcon/A1 where RX_INGR_EN/TX_DRAIN_EN isn't supported) */
803
	efx_mac_reconfigure(efx);
B
Ben Hutchings 已提交
804 805 806

	/* Ensure the PHY advertises the correct flow control settings */
	rc = efx->phy_op->reconfigure(efx);
807
	if (rc && rc != -EPERM)
B
Ben Hutchings 已提交
808 809
		goto fail2;

810
	mutex_unlock(&efx->mac_lock);
811
	return 0;
812

813
fail2:
814
	efx->phy_op->fini(efx);
815 816
fail1:
	mutex_unlock(&efx->mac_lock);
817
	return rc;
818 819 820 821
}

static void efx_fini_port(struct efx_nic *efx)
{
822
	netif_dbg(efx, drv, efx->net_dev, "shut down port\n");
823 824 825 826

	if (!efx->port_initialized)
		return;

827
	efx->phy_op->fini(efx);
828
	efx->port_initialized = false;
829

830
	efx->link_state.up = false;
831 832 833 834 835
	efx_link_status_changed(efx);
}

static void efx_remove_port(struct efx_nic *efx)
{
836
	netif_dbg(efx, drv, efx->net_dev, "destroying port\n");
837

838
	efx->type->remove_port(efx);
839 840 841 842 843 844 845 846
}

/**************************************************************************
 *
 * NIC handling
 *
 **************************************************************************/

847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
static LIST_HEAD(efx_primary_list);
static LIST_HEAD(efx_unassociated_list);

static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right)
{
	return left->type == right->type &&
		left->vpd_sn && right->vpd_sn &&
		!strcmp(left->vpd_sn, right->vpd_sn);
}

static void efx_associate(struct efx_nic *efx)
{
	struct efx_nic *other, *next;

	if (efx->primary == efx) {
		/* Adding primary function; look for secondaries */

		netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n");
		list_add_tail(&efx->node, &efx_primary_list);

		list_for_each_entry_safe(other, next, &efx_unassociated_list,
					 node) {
			if (efx_same_controller(efx, other)) {
				list_del(&other->node);
				netif_dbg(other, probe, other->net_dev,
					  "moving to secondary list of %s %s\n",
					  pci_name(efx->pci_dev),
					  efx->net_dev->name);
				list_add_tail(&other->node,
					      &efx->secondary_list);
				other->primary = efx;
			}
		}
	} else {
		/* Adding secondary function; look for primary */

		list_for_each_entry(other, &efx_primary_list, node) {
			if (efx_same_controller(efx, other)) {
				netif_dbg(efx, probe, efx->net_dev,
					  "adding to secondary list of %s %s\n",
					  pci_name(other->pci_dev),
					  other->net_dev->name);
				list_add_tail(&efx->node,
					      &other->secondary_list);
				efx->primary = other;
				return;
			}
		}

		netif_dbg(efx, probe, efx->net_dev,
			  "adding to unassociated list\n");
		list_add_tail(&efx->node, &efx_unassociated_list);
	}
}

static void efx_dissociate(struct efx_nic *efx)
{
	struct efx_nic *other, *next;

	list_del(&efx->node);
	efx->primary = NULL;

	list_for_each_entry_safe(other, next, &efx->secondary_list, node) {
		list_del(&other->node);
		netif_dbg(other, probe, other->net_dev,
			  "moving to unassociated list\n");
		list_add_tail(&other->node, &efx_unassociated_list);
		other->primary = NULL;
	}
}

918 919
void efx_set_default_rx_indir_table(struct efx_nic *efx,
				    struct efx_rss_context *ctx)
920 921 922
{
	size_t i;

923 924
	for (i = 0; i < ARRAY_SIZE(ctx->rx_indir_table); i++)
		ctx->rx_indir_table[i] =
925
			ethtool_rxfh_indir_default(i, efx->rss_spread);
926 927
}

928
static unsigned int efx_wanted_parallelism(struct efx_nic *efx)
929
{
930
	cpumask_var_t thread_mask;
931
	unsigned int count;
932
	int cpu;
933

934 935 936 937 938 939 940 941
	if (rss_cpus) {
		count = rss_cpus;
	} else {
		if (unlikely(!zalloc_cpumask_var(&thread_mask, GFP_KERNEL))) {
			netif_warn(efx, probe, efx->net_dev,
				   "RSS disabled due to allocation failure\n");
			return 1;
		}
942

943 944 945 946 947
		count = 0;
		for_each_online_cpu(cpu) {
			if (!cpumask_test_cpu(cpu, thread_mask)) {
				++count;
				cpumask_or(thread_mask, thread_mask,
948
					   topology_sibling_cpumask(cpu));
949 950 951 952
			}
		}

		free_cpumask_var(thread_mask);
R
Rusty Russell 已提交
953 954
	}

955 956 957 958 959 960 961
	if (count > EFX_MAX_RX_QUEUES) {
		netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn,
			       "Reducing number of rx queues from %u to %u.\n",
			       count, EFX_MAX_RX_QUEUES);
		count = EFX_MAX_RX_QUEUES;
	}

962 963 964
	/* If RSS is requested for the PF *and* VFs then we can't write RSS
	 * table entries that are inaccessible to VFs
	 */
965 966 967 968 969 970 971 972 973 974 975
#ifdef CONFIG_SFC_SRIOV
	if (efx->type->sriov_wanted) {
		if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
		    count > efx_vf_size(efx)) {
			netif_warn(efx, probe, efx->net_dev,
				   "Reducing number of RSS channels from %u to %u for "
				   "VF support. Increase vf-msix-limit to use more "
				   "channels on the PF.\n",
				   count, efx_vf_size(efx));
			count = efx_vf_size(efx);
		}
976
	}
977
#endif
978 979 980 981

	return count;
}

982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
static int efx_allocate_msix_channels(struct efx_nic *efx,
				      unsigned int max_channels,
				      unsigned int extra_channels,
				      unsigned int parallelism)
{
	unsigned int n_channels = parallelism;
	int vec_count;
	int n_xdp_tx;
	int n_xdp_ev;

	if (efx_separate_tx_channels)
		n_channels *= 2;
	n_channels += extra_channels;

	/* To allow XDP transmit to happen from arbitrary NAPI contexts
	 * we allocate a TX queue per CPU. We share event queues across
	 * multiple tx queues, assuming tx and ev queues are both
	 * maximum size.
	 */

	n_xdp_tx = num_possible_cpus();
	n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, EFX_TXQ_TYPES);

1005 1006 1007 1008 1009 1010
	vec_count = pci_msix_vec_count(efx->pci_dev);
	if (vec_count < 0)
		return vec_count;

	max_channels = min_t(unsigned int, vec_count, max_channels);

1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
	/* Check resources.
	 * We need a channel per event queue, plus a VI per tx queue.
	 * This may be more pessimistic than it needs to be.
	 */
	if (n_channels + n_xdp_ev > max_channels) {
		netif_err(efx, drv, efx->net_dev,
			  "Insufficient resources for %d XDP event queues (%d other channels, max %d)\n",
			  n_xdp_ev, n_channels, max_channels);
		efx->n_xdp_channels = 0;
		efx->xdp_tx_per_channel = 0;
		efx->xdp_tx_queue_count = 0;
	} else {
		efx->n_xdp_channels = n_xdp_ev;
		efx->xdp_tx_per_channel = EFX_TXQ_TYPES;
		efx->xdp_tx_queue_count = n_xdp_tx;
		n_channels += n_xdp_ev;
		netif_dbg(efx, drv, efx->net_dev,
			  "Allocating %d TX and %d event queues for XDP\n",
			  n_xdp_tx, n_xdp_ev);
	}

	if (vec_count < n_channels) {
		netif_err(efx, drv, efx->net_dev,
			  "WARNING: Insufficient MSI-X vectors available (%d < %u).\n",
			  vec_count, n_channels);
		netif_err(efx, drv, efx->net_dev,
			  "WARNING: Performance may be reduced.\n");
		n_channels = vec_count;
	}

1041
	n_channels = min(n_channels, max_channels);
1042

1043
	efx->n_channels = n_channels;
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062

	/* Ignore XDP tx channels when creating rx channels. */
	n_channels -= efx->n_xdp_channels;

	if (efx_separate_tx_channels) {
		efx->n_tx_channels =
			min(max(n_channels / 2, 1U),
			    efx->max_tx_channels);
		efx->tx_channel_offset =
			n_channels - efx->n_tx_channels;
		efx->n_rx_channels =
			max(n_channels -
			    efx->n_tx_channels, 1U);
	} else {
		efx->n_tx_channels = min(n_channels, efx->max_tx_channels);
		efx->tx_channel_offset = 0;
		efx->n_rx_channels = n_channels;
	}

1063 1064 1065 1066
	efx->n_rx_channels = min(efx->n_rx_channels, parallelism);
	efx->n_tx_channels = min(efx->n_tx_channels, parallelism);

	efx->xdp_channel_offset = n_channels;
1067 1068 1069 1070 1071 1072 1073 1074

	netif_dbg(efx, drv, efx->net_dev,
		  "Allocating %u RX channels\n",
		  efx->n_rx_channels);

	return efx->n_channels;
}

1075 1076 1077
/* Probe the number and type of interrupts we are able to obtain, and
 * the resulting numbers of channels and RX queues.
 */
1078
int efx_probe_interrupts(struct efx_nic *efx)
1079
{
1080
	unsigned int extra_channels = 0;
1081
	unsigned int rss_spread;
1082
	unsigned int i, j;
1083
	int rc;
1084

1085 1086 1087 1088
	for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++)
		if (efx->extra_channel_type[i])
			++extra_channels;

1089
	if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
1090
		unsigned int parallelism = efx_wanted_parallelism(efx);
1091
		struct msix_entry xentries[EFX_MAX_CHANNELS];
1092
		unsigned int n_channels;
1093

1094 1095 1096 1097 1098 1099 1100 1101 1102
		rc = efx_allocate_msix_channels(efx, efx->max_channels,
						extra_channels, parallelism);
		if (rc >= 0) {
			n_channels = rc;
			for (i = 0; i < n_channels; i++)
				xentries[i].entry = i;
			rc = pci_enable_msix_range(efx->pci_dev, xentries, 1,
						   n_channels);
		}
1103 1104 1105 1106
		if (rc < 0) {
			/* Fall back to single channel MSI */
			netif_err(efx, drv, efx->net_dev,
				  "could not enable MSI-X\n");
1107 1108 1109 1110
			if (efx->type->min_interrupt_mode >= EFX_INT_MODE_MSI)
				efx->interrupt_mode = EFX_INT_MODE_MSI;
			else
				return rc;
1111
		} else if (rc < n_channels) {
1112 1113
			netif_err(efx, drv, efx->net_dev,
				  "WARNING: Insufficient MSI-X vectors"
1114
				  " available (%d < %u).\n", rc, n_channels);
1115 1116
			netif_err(efx, drv, efx->net_dev,
				  "WARNING: Performance may be reduced.\n");
B
Ben Hutchings 已提交
1117
			n_channels = rc;
1118 1119
		}

1120
		if (rc > 0) {
1121
			for (i = 0; i < efx->n_channels; i++)
1122 1123
				efx_get_channel(efx, i)->irq =
					xentries[i].vector;
1124 1125 1126 1127 1128
		}
	}

	/* Try single interrupt MSI */
	if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
1129
		efx->n_channels = 1;
B
Ben Hutchings 已提交
1130 1131
		efx->n_rx_channels = 1;
		efx->n_tx_channels = 1;
1132 1133
		efx->n_xdp_channels = 0;
		efx->xdp_channel_offset = efx->n_channels;
1134 1135
		rc = pci_enable_msi(efx->pci_dev);
		if (rc == 0) {
1136
			efx_get_channel(efx, 0)->irq = efx->pci_dev->irq;
1137
		} else {
1138 1139
			netif_err(efx, drv, efx->net_dev,
				  "could not enable MSI\n");
1140 1141 1142 1143
			if (efx->type->min_interrupt_mode >= EFX_INT_MODE_LEGACY)
				efx->interrupt_mode = EFX_INT_MODE_LEGACY;
			else
				return rc;
1144 1145 1146 1147 1148
		}
	}

	/* Assume legacy interrupts */
	if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
1149
		efx->n_channels = 1 + (efx_separate_tx_channels ? 1 : 0);
B
Ben Hutchings 已提交
1150 1151
		efx->n_rx_channels = 1;
		efx->n_tx_channels = 1;
1152 1153
		efx->n_xdp_channels = 0;
		efx->xdp_channel_offset = efx->n_channels;
1154 1155
		efx->legacy_irq = efx->pci_dev->irq;
	}
1156

1157
	/* Assign extra channels if possible, before XDP channels */
1158
	efx->n_extra_tx_channels = 0;
1159
	j = efx->xdp_channel_offset;
1160 1161 1162
	for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) {
		if (!efx->extra_channel_type[i])
			continue;
1163
		if (j <= efx->tx_channel_offset + efx->n_tx_channels) {
1164 1165 1166 1167 1168
			efx->extra_channel_type[i]->handle_no_channel(efx);
		} else {
			--j;
			efx_get_channel(efx, j)->type =
				efx->extra_channel_type[i];
1169 1170
			if (efx_channel_has_tx_queues(efx_get_channel(efx, j)))
				efx->n_extra_tx_channels++;
1171 1172 1173
		}
	}

1174
	rss_spread = efx->n_rx_channels;
1175
	/* RSS might be usable on VFs even if it is disabled on the PF */
1176 1177
#ifdef CONFIG_SFC_SRIOV
	if (efx->type->sriov_wanted) {
1178
		efx->rss_spread = ((rss_spread > 1 ||
1179
				    !efx->type->sriov_wanted(efx)) ?
1180
				   rss_spread : efx_vf_size(efx));
1181 1182 1183
		return 0;
	}
#endif
1184
	efx->rss_spread = rss_spread;
1185

1186
	return 0;
1187 1188
}

1189
#if defined(CONFIG_SMP)
1190
void efx_set_interrupt_affinity(struct efx_nic *efx)
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
{
	struct efx_channel *channel;
	unsigned int cpu;

	efx_for_each_channel(channel, efx) {
		cpu = cpumask_local_spread(channel->channel,
					   pcibus_to_node(efx->pci_dev->bus));
		irq_set_affinity_hint(channel->irq, cpumask_of(cpu));
	}
}

1202
void efx_clear_interrupt_affinity(struct efx_nic *efx)
1203 1204 1205 1206 1207 1208 1209
{
	struct efx_channel *channel;

	efx_for_each_channel(channel, efx)
		irq_set_affinity_hint(channel->irq, NULL);
}
#else
1210
void efx_set_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused)))
1211 1212 1213
{
}

1214
void efx_clear_interrupt_affinity(struct efx_nic *efx __attribute__ ((unused)))
1215 1216 1217 1218
{
}
#endif /* CONFIG_SMP */

1219
int efx_soft_enable_interrupts(struct efx_nic *efx)
1220
{
1221 1222
	struct efx_channel *channel, *end_channel;
	int rc;
1223

1224 1225
	BUG_ON(efx->state == STATE_DISABLED);

B
Ben Hutchings 已提交
1226 1227
	efx->irq_soft_enabled = true;
	smp_wmb();
1228 1229

	efx_for_each_channel(channel, efx) {
1230 1231 1232 1233 1234
		if (!channel->type->keep_eventq) {
			rc = efx_init_eventq(channel);
			if (rc)
				goto fail;
		}
1235 1236 1237 1238
		efx_start_eventq(channel);
	}

	efx_mcdi_mode_event(efx);
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251

	return 0;
fail:
	end_channel = channel;
	efx_for_each_channel(channel, efx) {
		if (channel == end_channel)
			break;
		efx_stop_eventq(channel);
		if (!channel->type->keep_eventq)
			efx_fini_eventq(channel);
	}

	return rc;
1252 1253
}

1254
void efx_soft_disable_interrupts(struct efx_nic *efx)
1255 1256 1257
{
	struct efx_channel *channel;

1258 1259 1260
	if (efx->state == STATE_DISABLED)
		return;

1261 1262
	efx_mcdi_mode_poll(efx);

B
Ben Hutchings 已提交
1263 1264 1265 1266
	efx->irq_soft_enabled = false;
	smp_wmb();

	if (efx->legacy_irq)
1267 1268 1269 1270 1271 1272 1273
		synchronize_irq(efx->legacy_irq);

	efx_for_each_channel(channel, efx) {
		if (channel->irq)
			synchronize_irq(channel->irq);

		efx_stop_eventq(channel);
B
Ben Hutchings 已提交
1274
		if (!channel->type->keep_eventq)
1275
			efx_fini_eventq(channel);
1276
	}
1277 1278 1279

	/* Flush the asynchronous MCDI request queue */
	efx_mcdi_flush_async(efx);
1280 1281
}

1282
int efx_enable_interrupts(struct efx_nic *efx)
B
Ben Hutchings 已提交
1283
{
1284 1285
	struct efx_channel *channel, *end_channel;
	int rc;
B
Ben Hutchings 已提交
1286 1287 1288 1289 1290 1291 1292 1293

	BUG_ON(efx->state == STATE_DISABLED);

	if (efx->eeh_disabled_legacy_irq) {
		enable_irq(efx->legacy_irq);
		efx->eeh_disabled_legacy_irq = false;
	}

1294
	efx->type->irq_enable_master(efx);
B
Ben Hutchings 已提交
1295 1296

	efx_for_each_channel(channel, efx) {
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
		if (channel->type->keep_eventq) {
			rc = efx_init_eventq(channel);
			if (rc)
				goto fail;
		}
	}

	rc = efx_soft_enable_interrupts(efx);
	if (rc)
		goto fail;

	return 0;

fail:
	end_channel = channel;
	efx_for_each_channel(channel, efx) {
		if (channel == end_channel)
			break;
B
Ben Hutchings 已提交
1315
		if (channel->type->keep_eventq)
1316
			efx_fini_eventq(channel);
B
Ben Hutchings 已提交
1317 1318
	}

1319 1320 1321
	efx->type->irq_disable_non_ev(efx);

	return rc;
B
Ben Hutchings 已提交
1322 1323
}

1324
void efx_disable_interrupts(struct efx_nic *efx)
B
Ben Hutchings 已提交
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
{
	struct efx_channel *channel;

	efx_soft_disable_interrupts(efx);

	efx_for_each_channel(channel, efx) {
		if (channel->type->keep_eventq)
			efx_fini_eventq(channel);
	}

1335
	efx->type->irq_disable_non_ev(efx);
B
Ben Hutchings 已提交
1336 1337
}

1338
void efx_remove_interrupts(struct efx_nic *efx)
1339 1340 1341 1342
{
	struct efx_channel *channel;

	/* Remove MSI/MSI-X interrupts */
1343
	efx_for_each_channel(channel, efx)
1344 1345 1346 1347 1348 1349 1350 1351
		channel->irq = 0;
	pci_disable_msi(efx->pci_dev);
	pci_disable_msix(efx->pci_dev);

	/* Remove legacy interrupt */
	efx->legacy_irq = 0;
}

1352
int efx_set_channels(struct efx_nic *efx)
1353
{
1354 1355
	struct efx_channel *channel;
	struct efx_tx_queue *tx_queue;
1356
	int xdp_queue_number;
1357

1358
	efx->tx_channel_offset =
1359 1360
		efx_separate_tx_channels ?
		efx->n_channels - efx->n_tx_channels : 0;
1361

1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
	if (efx->xdp_tx_queue_count) {
		EFX_WARN_ON_PARANOID(efx->xdp_tx_queues);

		/* Allocate array for XDP TX queue lookup. */
		efx->xdp_tx_queues = kcalloc(efx->xdp_tx_queue_count,
					     sizeof(*efx->xdp_tx_queues),
					     GFP_KERNEL);
		if (!efx->xdp_tx_queues)
			return -ENOMEM;
	}

1373 1374
	/* We need to mark which channels really have RX and TX
	 * queues, and adjust the TX queue numbers if we have separate
1375 1376
	 * RX-only and TX-only channels.
	 */
1377
	xdp_queue_number = 0;
1378
	efx_for_each_channel(channel, efx) {
1379 1380 1381 1382 1383
		if (channel->channel < efx->n_rx_channels)
			channel->rx_queue.core_index = channel->channel;
		else
			channel->rx_queue.core_index = -1;

1384
		efx_for_each_channel_tx_queue(tx_queue, channel) {
1385 1386
			tx_queue->queue -= (efx->tx_channel_offset *
					    EFX_TXQ_TYPES);
1387 1388 1389 1390 1391 1392 1393

			if (efx_channel_is_xdp_tx(channel) &&
			    xdp_queue_number < efx->xdp_tx_queue_count) {
				efx->xdp_tx_queues[xdp_queue_number] = tx_queue;
				xdp_queue_number++;
			}
		}
1394
	}
1395
	return 0;
1396 1397 1398 1399 1400 1401
}

static int efx_probe_nic(struct efx_nic *efx)
{
	int rc;

1402
	netif_dbg(efx, probe, efx->net_dev, "creating NIC\n");
1403 1404

	/* Carry out hardware-type specific initialisation */
1405
	rc = efx->type->probe(efx);
1406 1407 1408
	if (rc)
		return rc;

1409 1410 1411 1412 1413 1414 1415 1416
	do {
		if (!efx->max_channels || !efx->max_tx_channels) {
			netif_err(efx, drv, efx->net_dev,
				  "Insufficient resources to allocate"
				  " any channels\n");
			rc = -ENOSPC;
			goto fail1;
		}
1417

1418 1419 1420 1421 1422 1423
		/* Determine the number of channels and queues by trying
		 * to hook in MSI-X interrupts.
		 */
		rc = efx_probe_interrupts(efx);
		if (rc)
			goto fail1;
1424

1425 1426 1427
		rc = efx_set_channels(efx);
		if (rc)
			goto fail1;
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438

		/* dimension_resources can fail with EAGAIN */
		rc = efx->type->dimension_resources(efx);
		if (rc != 0 && rc != -EAGAIN)
			goto fail2;

		if (rc == -EAGAIN)
			/* try again with new max_channels */
			efx_remove_interrupts(efx);

	} while (rc == -EAGAIN);
1439

1440
	if (efx->n_channels > 1)
1441 1442 1443
		netdev_rss_key_fill(efx->rss_context.rx_hash_key,
				    sizeof(efx->rss_context.rx_hash_key));
	efx_set_default_rx_indir_table(efx, &efx->rss_context);
1444

1445 1446
	netif_set_real_num_tx_queues(efx->net_dev, efx->n_tx_channels);
	netif_set_real_num_rx_queues(efx->net_dev, efx->n_rx_channels);
1447 1448

	/* Initialise the interrupt moderation settings */
1449
	efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000);
1450 1451
	efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true,
				true);
1452 1453

	return 0;
1454

1455 1456 1457
fail2:
	efx_remove_interrupts(efx);
fail1:
1458 1459
	efx->type->remove(efx);
	return rc;
1460 1461 1462 1463
}

static void efx_remove_nic(struct efx_nic *efx)
{
1464
	netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n");
1465 1466

	efx_remove_interrupts(efx);
1467
	efx->type->remove(efx);
1468 1469
}

1470 1471 1472 1473
static int efx_probe_filters(struct efx_nic *efx)
{
	int rc;

1474
	init_rwsem(&efx->filter_sem);
1475
	mutex_lock(&efx->mac_lock);
1476
	down_write(&efx->filter_sem);
1477 1478
	rc = efx->type->filter_table_probe(efx);
	if (rc)
1479
		goto out_unlock;
1480 1481 1482

#ifdef CONFIG_RFS_ACCEL
	if (efx->type->offload_features & NETIF_F_NTUPLE) {
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
		struct efx_channel *channel;
		int i, success = 1;

		efx_for_each_channel(channel, efx) {
			channel->rps_flow_id =
				kcalloc(efx->type->max_rx_ip_filters,
					sizeof(*channel->rps_flow_id),
					GFP_KERNEL);
			if (!channel->rps_flow_id)
				success = 0;
			else
				for (i = 0;
				     i < efx->type->max_rx_ip_filters;
				     ++i)
					channel->rps_flow_id[i] =
						RPS_FLOW_ID_INVALID;
E
Edward Cree 已提交
1499 1500
			channel->rfs_expire_index = 0;
			channel->rfs_filter_count = 0;
1501 1502 1503 1504 1505
		}

		if (!success) {
			efx_for_each_channel(channel, efx)
				kfree(channel->rps_flow_id);
1506
			efx->type->filter_table_remove(efx);
1507 1508
			rc = -ENOMEM;
			goto out_unlock;
1509 1510 1511
		}
	}
#endif
1512 1513
out_unlock:
	up_write(&efx->filter_sem);
1514
	mutex_unlock(&efx->mac_lock);
1515
	return rc;
1516 1517 1518 1519 1520
}

static void efx_remove_filters(struct efx_nic *efx)
{
#ifdef CONFIG_RFS_ACCEL
1521 1522
	struct efx_channel *channel;

E
Edward Cree 已提交
1523
	efx_for_each_channel(channel, efx) {
1524
		cancel_delayed_work_sync(&channel->filter_work);
1525
		kfree(channel->rps_flow_id);
E
Edward Cree 已提交
1526
	}
1527
#endif
1528
	down_write(&efx->filter_sem);
1529
	efx->type->filter_table_remove(efx);
1530
	up_write(&efx->filter_sem);
1531 1532 1533
}


1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
/**************************************************************************
 *
 * NIC startup/shutdown
 *
 *************************************************************************/

static int efx_probe_all(struct efx_nic *efx)
{
	int rc;

	rc = efx_probe_nic(efx);
	if (rc) {
1546
		netif_err(efx, probe, efx->net_dev, "failed to create NIC\n");
1547 1548 1549 1550 1551
		goto fail1;
	}

	rc = efx_probe_port(efx);
	if (rc) {
1552
		netif_err(efx, probe, efx->net_dev, "failed to create port\n");
1553 1554 1555
		goto fail2;
	}

1556 1557 1558 1559 1560
	BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT);
	if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) {
		rc = -EINVAL;
		goto fail3;
	}
1561
	efx->rxq_entries = efx->txq_entries = EFX_DEFAULT_DMAQ_SIZE;
1562

1563 1564 1565 1566 1567 1568 1569 1570
#ifdef CONFIG_SFC_SRIOV
	rc = efx->type->vswitching_probe(efx);
	if (rc) /* not fatal; the PF will still work fine */
		netif_warn(efx, probe, efx->net_dev,
			   "failed to setup vswitching rc=%d;"
			   " VFs may not function\n", rc);
#endif

B
Ben Hutchings 已提交
1571 1572 1573 1574
	rc = efx_probe_filters(efx);
	if (rc) {
		netif_err(efx, probe, efx->net_dev,
			  "failed to create filter tables\n");
1575
		goto fail4;
B
Ben Hutchings 已提交
1576 1577
	}

1578 1579
	rc = efx_probe_channels(efx);
	if (rc)
1580
		goto fail5;
1581

1582 1583
	return 0;

1584
 fail5:
1585
	efx_remove_filters(efx);
1586 1587 1588 1589
 fail4:
#ifdef CONFIG_SFC_SRIOV
	efx->type->vswitching_remove(efx);
#endif
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
 fail3:
	efx_remove_port(efx);
 fail2:
	efx_remove_nic(efx);
 fail1:
	return rc;
}

static void efx_remove_all(struct efx_nic *efx)
{
1600 1601 1602 1603
	rtnl_lock();
	efx_xdp_setup_prog(efx, NULL);
	rtnl_unlock();

1604
	efx_remove_channels(efx);
1605
	efx_remove_filters(efx);
1606 1607 1608
#ifdef CONFIG_SFC_SRIOV
	efx->type->vswitching_remove(efx);
#endif
1609 1610 1611 1612 1613 1614 1615 1616 1617
	efx_remove_port(efx);
	efx_remove_nic(efx);
}

/**************************************************************************
 *
 * Interrupt moderation
 *
 **************************************************************************/
1618
unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs)
1619
{
1620 1621
	if (usecs == 0)
		return 0;
1622
	if (usecs * 1000 < efx->timer_quantum_ns)
1623
		return 1; /* never round down to 0 */
1624 1625 1626 1627 1628 1629 1630 1631 1632
	return usecs * 1000 / efx->timer_quantum_ns;
}

unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks)
{
	/* We must round up when converting ticks to microseconds
	 * because we round down when converting the other way.
	 */
	return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000);
1633 1634
}

1635
/* Set interrupt moderation parameters */
1636 1637 1638
int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs,
			    unsigned int rx_usecs, bool rx_adaptive,
			    bool rx_may_override_tx)
1639
{
1640
	struct efx_channel *channel;
1641 1642
	unsigned int timer_max_us;

1643 1644
	EFX_ASSERT_RESET_SERIALISED(efx);

1645 1646 1647
	timer_max_us = efx->timer_max_ns / 1000;

	if (tx_usecs > timer_max_us || rx_usecs > timer_max_us)
1648 1649
		return -EINVAL;

1650
	if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 &&
1651 1652 1653 1654 1655 1656
	    !rx_may_override_tx) {
		netif_err(efx, drv, efx->net_dev, "Channels are shared. "
			  "RX and TX IRQ moderation must be equal\n");
		return -EINVAL;
	}

1657
	efx->irq_rx_adaptive = rx_adaptive;
1658
	efx->irq_rx_moderation_us = rx_usecs;
1659
	efx_for_each_channel(channel, efx) {
1660
		if (efx_channel_has_rx_queue(channel))
1661
			channel->irq_moderation_us = rx_usecs;
1662
		else if (efx_channel_has_tx_queues(channel))
1663
			channel->irq_moderation_us = tx_usecs;
1664 1665
		else if (efx_channel_is_xdp_tx(channel))
			channel->irq_moderation_us = tx_usecs;
1666
	}
1667 1668

	return 0;
1669 1670
}

1671 1672 1673 1674
void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs,
			    unsigned int *rx_usecs, bool *rx_adaptive)
{
	*rx_adaptive = efx->irq_rx_adaptive;
1675
	*rx_usecs = efx->irq_rx_moderation_us;
1676 1677 1678 1679 1680

	/* If channels are shared between RX and TX, so is IRQ
	 * moderation.  Otherwise, IRQ moderation is the same for all
	 * TX channels and is not adaptive.
	 */
1681
	if (efx->tx_channel_offset == 0) {
1682
		*tx_usecs = *rx_usecs;
1683 1684 1685 1686 1687 1688
	} else {
		struct efx_channel *tx_channel;

		tx_channel = efx->channel[efx->tx_channel_offset];
		*tx_usecs = tx_channel->irq_moderation_us;
	}
1689 1690
}

1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
/**************************************************************************
 *
 * ioctls
 *
 *************************************************************************/

/* Net device ioctl
 * Context: process, rtnl_lock() held.
 */
static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
{
1702
	struct efx_nic *efx = netdev_priv(net_dev);
1703
	struct mii_ioctl_data *data = if_mii(ifr);
1704

1705
	if (cmd == SIOCSHWTSTAMP)
1706 1707 1708
		return efx_ptp_set_ts_config(efx, ifr);
	if (cmd == SIOCGHWTSTAMP)
		return efx_ptp_get_ts_config(efx, ifr);
1709

1710 1711 1712 1713 1714 1715
	/* Convert phy_id from older PRTAD/DEVAD format */
	if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) &&
	    (data->phy_id & 0xfc00) == 0x0400)
		data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400;

	return mdio_mii_ioctl(&efx->mdio, data, cmd);
1716 1717 1718 1719 1720 1721 1722 1723
}

/**************************************************************************
 *
 * NAPI interface
 *
 **************************************************************************/

1724
void efx_init_napi_channel(struct efx_channel *channel)
1725 1726 1727 1728 1729 1730 1731 1732
{
	struct efx_nic *efx = channel->efx;

	channel->napi_dev = efx->net_dev;
	netif_napi_add(channel->napi_dev, &channel->napi_str,
		       efx_poll, napi_weight);
}

1733
void efx_init_napi(struct efx_nic *efx)
1734 1735 1736
{
	struct efx_channel *channel;

1737 1738
	efx_for_each_channel(channel, efx)
		efx_init_napi_channel(channel);
1739 1740
}

1741
void efx_fini_napi_channel(struct efx_channel *channel)
1742
{
E
Eric Dumazet 已提交
1743
	if (channel->napi_dev)
1744
		netif_napi_del(&channel->napi_str);
E
Eric Dumazet 已提交
1745

1746
	channel->napi_dev = NULL;
1747 1748
}

1749
void efx_fini_napi(struct efx_nic *efx)
1750 1751 1752
{
	struct efx_channel *channel;

1753 1754
	efx_for_each_channel(channel, efx)
		efx_fini_napi_channel(channel);
1755 1756 1757 1758 1759 1760 1761 1762 1763
}

/**************************************************************************
 *
 * Kernel net device interface
 *
 *************************************************************************/

/* Context: process, rtnl_lock() held. */
1764
int efx_net_open(struct net_device *net_dev)
1765
{
1766
	struct efx_nic *efx = netdev_priv(net_dev);
1767 1768
	int rc;

1769 1770
	netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n",
		  raw_smp_processor_id());
1771

1772 1773 1774
	rc = efx_check_disabled(efx);
	if (rc)
		return rc;
1775 1776
	if (efx->phy_mode & PHY_MODE_SPECIAL)
		return -EBUSY;
1777 1778
	if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL))
		return -EIO;
1779

1780 1781 1782 1783
	/* Notify the kernel of the link state polled during driver load,
	 * before the monitor starts running */
	efx_link_status_changed(efx);

1784
	efx_start_all(efx);
1785 1786
	if (efx->state == STATE_DISABLED || efx->reset_pending)
		netif_device_detach(efx->net_dev);
1787
	efx_selftest_async_start(efx);
1788 1789 1790 1791 1792 1793 1794
	return 0;
}

/* Context: process, rtnl_lock() held.
 * Note that the kernel will ignore our return code; this method
 * should really be a void.
 */
1795
int efx_net_stop(struct net_device *net_dev)
1796
{
1797
	struct efx_nic *efx = netdev_priv(net_dev);
1798

1799 1800
	netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n",
		  raw_smp_processor_id());
1801

1802 1803
	/* Stop the device and flush all the channels */
	efx_stop_all(efx);
1804 1805 1806 1807

	return 0;
}

1808
/* Context: process, dev_base_lock or RTNL held, non-blocking. */
1809 1810
static void efx_net_stats(struct net_device *net_dev,
			  struct rtnl_link_stats64 *stats)
1811
{
1812
	struct efx_nic *efx = netdev_priv(net_dev);
1813

1814
	spin_lock_bh(&efx->stats_lock);
1815
	efx->type->update_stats(efx, NULL, stats);
1816
	spin_unlock_bh(&efx->stats_lock);
1817 1818 1819
}

/* Context: netif_tx_lock held, BHs disabled. */
1820
static void efx_watchdog(struct net_device *net_dev, unsigned int txqueue)
1821
{
1822
	struct efx_nic *efx = netdev_priv(net_dev);
1823

1824 1825 1826
	netif_err(efx, tx_err, efx->net_dev,
		  "TX stuck with port_enabled=%d: resetting channels\n",
		  efx->port_enabled);
1827

1828
	efx_schedule_reset(efx, RESET_TYPE_TX_WATCHDOG);
1829 1830
}

1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
static unsigned int efx_xdp_max_mtu(struct efx_nic *efx)
{
	/* The maximum MTU that we can fit in a single page, allowing for
	 * framing, overhead and XDP headroom.
	 */
	int overhead = EFX_MAX_FRAME_LEN(0) + sizeof(struct efx_rx_page_state) +
		       efx->rx_prefix_size + efx->type->rx_buffer_padding +
		       efx->rx_ip_align + XDP_PACKET_HEADROOM;

	return PAGE_SIZE - overhead;
}
1842 1843 1844 1845

/* Context: process, rtnl_lock() held. */
static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
{
1846
	struct efx_nic *efx = netdev_priv(net_dev);
1847
	int rc;
1848

1849 1850 1851
	rc = efx_check_disabled(efx);
	if (rc)
		return rc;
1852

1853 1854 1855 1856 1857 1858 1859 1860
	if (rtnl_dereference(efx->xdp_prog) &&
	    new_mtu > efx_xdp_max_mtu(efx)) {
		netif_err(efx, drv, efx->net_dev,
			  "Requested MTU of %d too big for XDP (max: %d)\n",
			  new_mtu, efx_xdp_max_mtu(efx));
		return -EINVAL;
	}

1861
	netif_dbg(efx, drv, efx->net_dev, "changing MTU to %d\n", new_mtu);
1862

1863 1864 1865
	efx_device_detach_sync(efx);
	efx_stop_all(efx);

B
Ben Hutchings 已提交
1866
	mutex_lock(&efx->mac_lock);
1867
	net_dev->mtu = new_mtu;
1868
	efx_mac_reconfigure(efx);
B
Ben Hutchings 已提交
1869 1870
	mutex_unlock(&efx->mac_lock);

1871
	efx_start_all(efx);
1872
	efx_device_attach_if_not_resetting(efx);
1873
	return 0;
1874 1875 1876 1877
}

static int efx_set_mac_address(struct net_device *net_dev, void *data)
{
1878
	struct efx_nic *efx = netdev_priv(net_dev);
1879
	struct sockaddr *addr = data;
1880
	u8 *new_addr = addr->sa_data;
1881 1882
	u8 old_addr[6];
	int rc;
1883 1884

	if (!is_valid_ether_addr(new_addr)) {
1885 1886 1887
		netif_err(efx, drv, efx->net_dev,
			  "invalid ethernet MAC address requested: %pM\n",
			  new_addr);
1888
		return -EADDRNOTAVAIL;
1889 1890
	}

1891 1892
	/* save old address */
	ether_addr_copy(old_addr, net_dev->dev_addr);
1893
	ether_addr_copy(net_dev->dev_addr, new_addr);
1894 1895
	if (efx->type->set_mac_address) {
		rc = efx->type->set_mac_address(efx);
1896 1897 1898 1899 1900
		if (rc) {
			ether_addr_copy(net_dev->dev_addr, old_addr);
			return rc;
		}
	}
1901 1902

	/* Reconfigure the MAC */
B
Ben Hutchings 已提交
1903
	mutex_lock(&efx->mac_lock);
1904
	efx_mac_reconfigure(efx);
B
Ben Hutchings 已提交
1905
	mutex_unlock(&efx->mac_lock);
1906 1907 1908 1909

	return 0;
}

1910
/* Context: netif_addr_lock held, BHs disabled. */
1911
static void efx_set_rx_mode(struct net_device *net_dev)
1912
{
1913
	struct efx_nic *efx = netdev_priv(net_dev);
1914

1915 1916 1917
	if (efx->port_enabled)
		queue_work(efx->workqueue, &efx->mac_work);
	/* Otherwise efx_start_port() will do this */
1918 1919
}

1920
static int efx_set_features(struct net_device *net_dev, netdev_features_t data)
1921 1922
{
	struct efx_nic *efx = netdev_priv(net_dev);
1923
	int rc;
1924 1925

	/* If disabling RX n-tuple filtering, clear existing filters */
1926 1927 1928 1929 1930 1931
	if (net_dev->features & ~data & NETIF_F_NTUPLE) {
		rc = efx->type->filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL);
		if (rc)
			return rc;
	}

E
Edward Cree 已提交
1932 1933 1934 1935 1936
	/* If Rx VLAN filter is changed, update filters via mac_reconfigure.
	 * If rx-fcs is changed, mac_reconfigure updates that too.
	 */
	if ((net_dev->features ^ data) & (NETIF_F_HW_VLAN_CTAG_FILTER |
					  NETIF_F_RXFCS)) {
1937 1938 1939 1940 1941
		/* efx_set_rx_mode() will schedule MAC work to update filters
		 * when a new features are finally set in net_dev.
		 */
		efx_set_rx_mode(net_dev);
	}
1942 1943 1944 1945

	return 0;
}

1946 1947
static int efx_get_phys_port_id(struct net_device *net_dev,
				struct netdev_phys_item_id *ppid)
1948 1949 1950 1951 1952 1953 1954 1955 1956
{
	struct efx_nic *efx = netdev_priv(net_dev);

	if (efx->type->get_phys_port_id)
		return efx->type->get_phys_port_id(efx, ppid);
	else
		return -EOPNOTSUPP;
}

1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
static int efx_get_phys_port_name(struct net_device *net_dev,
				  char *name, size_t len)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	if (snprintf(name, len, "p%u", efx->port_num) >= len)
		return -EINVAL;
	return 0;
}

1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986
static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	if (efx->type->vlan_rx_add_vid)
		return efx->type->vlan_rx_add_vid(efx, proto, vid);
	else
		return -EOPNOTSUPP;
}

static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	if (efx->type->vlan_rx_kill_vid)
		return efx->type->vlan_rx_kill_vid(efx, proto, vid);
	else
		return -EOPNOTSUPP;
}

1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028
static int efx_udp_tunnel_type_map(enum udp_parsable_tunnel_type in)
{
	switch (in) {
	case UDP_TUNNEL_TYPE_VXLAN:
		return TUNNEL_ENCAP_UDP_PORT_ENTRY_VXLAN;
	case UDP_TUNNEL_TYPE_GENEVE:
		return TUNNEL_ENCAP_UDP_PORT_ENTRY_GENEVE;
	default:
		return -1;
	}
}

static void efx_udp_tunnel_add(struct net_device *dev, struct udp_tunnel_info *ti)
{
	struct efx_nic *efx = netdev_priv(dev);
	struct efx_udp_tunnel tnl;
	int efx_tunnel_type;

	efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
	if (efx_tunnel_type < 0)
		return;

	tnl.type = (u16)efx_tunnel_type;
	tnl.port = ti->port;

	if (efx->type->udp_tnl_add_port)
		(void)efx->type->udp_tnl_add_port(efx, tnl);
}

static void efx_udp_tunnel_del(struct net_device *dev, struct udp_tunnel_info *ti)
{
	struct efx_nic *efx = netdev_priv(dev);
	struct efx_udp_tunnel tnl;
	int efx_tunnel_type;

	efx_tunnel_type = efx_udp_tunnel_type_map(ti->type);
	if (efx_tunnel_type < 0)
		return;

	tnl.type = (u16)efx_tunnel_type;
	tnl.port = ti->port;

2029
	if (efx->type->udp_tnl_del_port)
2030 2031 2032
		(void)efx->type->udp_tnl_del_port(efx, tnl);
}

2033
static const struct net_device_ops efx_netdev_ops = {
S
Stephen Hemminger 已提交
2034 2035
	.ndo_open		= efx_net_open,
	.ndo_stop		= efx_net_stop,
2036
	.ndo_get_stats64	= efx_net_stats,
S
Stephen Hemminger 已提交
2037 2038 2039 2040 2041 2042
	.ndo_tx_timeout		= efx_watchdog,
	.ndo_start_xmit		= efx_hard_start_xmit,
	.ndo_validate_addr	= eth_validate_addr,
	.ndo_do_ioctl		= efx_ioctl,
	.ndo_change_mtu		= efx_change_mtu,
	.ndo_set_mac_address	= efx_set_mac_address,
2043
	.ndo_set_rx_mode	= efx_set_rx_mode,
2044
	.ndo_set_features	= efx_set_features,
2045 2046
	.ndo_vlan_rx_add_vid	= efx_vlan_rx_add_vid,
	.ndo_vlan_rx_kill_vid	= efx_vlan_rx_kill_vid,
2047
#ifdef CONFIG_SFC_SRIOV
2048 2049 2050 2051
	.ndo_set_vf_mac		= efx_sriov_set_vf_mac,
	.ndo_set_vf_vlan	= efx_sriov_set_vf_vlan,
	.ndo_set_vf_spoofchk	= efx_sriov_set_vf_spoofchk,
	.ndo_get_vf_config	= efx_sriov_get_vf_config,
2052
	.ndo_set_vf_link_state  = efx_sriov_set_vf_link_state,
2053
#endif
2054
	.ndo_get_phys_port_id   = efx_get_phys_port_id,
2055
	.ndo_get_phys_port_name	= efx_get_phys_port_name,
2056
	.ndo_setup_tc		= efx_setup_tc,
2057 2058 2059
#ifdef CONFIG_RFS_ACCEL
	.ndo_rx_flow_steer	= efx_filter_rfs,
#endif
2060 2061
	.ndo_udp_tunnel_add	= efx_udp_tunnel_add,
	.ndo_udp_tunnel_del	= efx_udp_tunnel_del,
2062
	.ndo_xdp_xmit		= efx_xdp_xmit,
2063
	.ndo_bpf		= efx_xdp
S
Stephen Hemminger 已提交
2064 2065
};

2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog)
{
	struct bpf_prog *old_prog;

	if (efx->xdp_rxq_info_failed) {
		netif_err(efx, drv, efx->net_dev,
			  "Unable to bind XDP program due to previous failure of rxq_info\n");
		return -EINVAL;
	}

	if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) {
		netif_err(efx, drv, efx->net_dev,
			  "Unable to configure XDP with MTU of %d (max: %d)\n",
			  efx->net_dev->mtu, efx_xdp_max_mtu(efx));
		return -EINVAL;
	}

	old_prog = rtnl_dereference(efx->xdp_prog);
	rcu_assign_pointer(efx->xdp_prog, prog);
	/* Release the reference that was originally passed by the caller. */
	if (old_prog)
		bpf_prog_put(old_prog);

	return 0;
}

/* Context: process, rtnl_lock() held. */
static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp)
{
	struct efx_nic *efx = netdev_priv(dev);
	struct bpf_prog *xdp_prog;

	switch (xdp->command) {
	case XDP_SETUP_PROG:
		return efx_xdp_setup_prog(efx, xdp->prog);
	case XDP_QUERY_PROG:
		xdp_prog = rtnl_dereference(efx->xdp_prog);
		xdp->prog_id = xdp_prog ? xdp_prog->aux->id : 0;
		return 0;
	default:
		return -EINVAL;
	}
}

2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120
static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs,
			u32 flags)
{
	struct efx_nic *efx = netdev_priv(dev);

	if (!netif_running(dev))
		return -EINVAL;

	return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH);
}

2121 2122 2123 2124 2125 2126 2127
static void efx_update_name(struct efx_nic *efx)
{
	strcpy(efx->name, efx->net_dev->name);
	efx_mtd_rename(efx);
	efx_set_channel_names(efx);
}

2128 2129 2130
static int efx_netdev_event(struct notifier_block *this,
			    unsigned long event, void *ptr)
{
2131
	struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
2132

2133
	if ((net_dev->netdev_ops == &efx_netdev_ops) &&
2134 2135
	    event == NETDEV_CHANGENAME)
		efx_update_name(netdev_priv(net_dev));
2136 2137 2138 2139 2140 2141 2142 2143

	return NOTIFY_DONE;
}

static struct notifier_block efx_netdev_notifier = {
	.notifier_call = efx_netdev_event,
};

B
Ben Hutchings 已提交
2144 2145 2146
static ssize_t
show_phy_type(struct device *dev, struct device_attribute *attr, char *buf)
{
2147
	struct efx_nic *efx = dev_get_drvdata(dev);
B
Ben Hutchings 已提交
2148 2149
	return sprintf(buf, "%d\n", efx->phy_type);
}
2150
static DEVICE_ATTR(phy_type, 0444, show_phy_type, NULL);
B
Ben Hutchings 已提交
2151

2152 2153 2154 2155
#ifdef CONFIG_SFC_MCDI_LOGGING
static ssize_t show_mcdi_log(struct device *dev, struct device_attribute *attr,
			     char *buf)
{
2156
	struct efx_nic *efx = dev_get_drvdata(dev);
2157 2158 2159 2160 2161 2162 2163
	struct efx_mcdi_iface *mcdi = efx_mcdi(efx);

	return scnprintf(buf, PAGE_SIZE, "%d\n", mcdi->logging_enabled);
}
static ssize_t set_mcdi_log(struct device *dev, struct device_attribute *attr,
			    const char *buf, size_t count)
{
2164
	struct efx_nic *efx = dev_get_drvdata(dev);
2165 2166 2167 2168 2169 2170 2171 2172 2173
	struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
	bool enable = count > 0 && *buf != '0';

	mcdi->logging_enabled = enable;
	return count;
}
static DEVICE_ATTR(mcdi_logging, 0644, show_mcdi_log, set_mcdi_log);
#endif

2174 2175 2176
static int efx_register_netdev(struct efx_nic *efx)
{
	struct net_device *net_dev = efx->net_dev;
2177
	struct efx_channel *channel;
2178 2179 2180 2181
	int rc;

	net_dev->watchdog_timeo = 5 * HZ;
	net_dev->irq = efx->pci_dev->irq;
2182 2183
	net_dev->netdev_ops = &efx_netdev_ops;
	if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0)
2184
		net_dev->priv_flags |= IFF_UNICAST_FLT;
2185
	net_dev->ethtool_ops = &efx_ethtool_ops;
2186
	net_dev->gso_max_segs = EFX_TSO_MAX_SEGS;
2187 2188
	net_dev->min_mtu = EFX_MIN_MTU;
	net_dev->max_mtu = EFX_MAX_MTU;
2189

2190
	rtnl_lock();
2191

2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204
	/* Enable resets to be scheduled and check whether any were
	 * already requested.  If so, the NIC is probably hosed so we
	 * abort.
	 */
	efx->state = STATE_READY;
	smp_mb(); /* ensure we change state before checking reset_pending */
	if (efx->reset_pending) {
		netif_err(efx, probe, efx->net_dev,
			  "aborting probe due to scheduled reset\n");
		rc = -EIO;
		goto fail_locked;
	}

2205 2206 2207
	rc = dev_alloc_name(net_dev, net_dev->name);
	if (rc < 0)
		goto fail_locked;
2208
	efx_update_name(efx);
2209

2210 2211 2212
	/* Always start with carrier off; PHY events will detect the link */
	netif_carrier_off(net_dev);

2213 2214 2215 2216
	rc = register_netdevice(net_dev);
	if (rc)
		goto fail_locked;

2217 2218
	efx_for_each_channel(channel, efx) {
		struct efx_tx_queue *tx_queue;
2219 2220
		efx_for_each_channel_tx_queue(tx_queue, channel)
			efx_init_tx_queue_core_txq(tx_queue);
2221 2222
	}

2223 2224
	efx_associate(efx);

2225
	rtnl_unlock();
2226

B
Ben Hutchings 已提交
2227 2228
	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type);
	if (rc) {
2229 2230
		netif_err(efx, drv, efx->net_dev,
			  "failed to init net dev attributes\n");
B
Ben Hutchings 已提交
2231 2232
		goto fail_registered;
	}
2233 2234 2235 2236 2237 2238 2239 2240
#ifdef CONFIG_SFC_MCDI_LOGGING
	rc = device_create_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
	if (rc) {
		netif_err(efx, drv, efx->net_dev,
			  "failed to init net dev attributes\n");
		goto fail_attr_mcdi_logging;
	}
#endif
B
Ben Hutchings 已提交
2241

2242
	return 0;
B
Ben Hutchings 已提交
2243

2244 2245 2246 2247
#ifdef CONFIG_SFC_MCDI_LOGGING
fail_attr_mcdi_logging:
	device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
#endif
2248 2249
fail_registered:
	rtnl_lock();
2250
	efx_dissociate(efx);
2251
	unregister_netdevice(net_dev);
2252
fail_locked:
2253
	efx->state = STATE_UNINIT;
2254
	rtnl_unlock();
2255
	netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
2256
	return rc;
2257 2258 2259 2260 2261 2262 2263
}

static void efx_unregister_netdev(struct efx_nic *efx)
{
	if (!efx->net_dev)
		return;

2264
	BUG_ON(netdev_priv(efx->net_dev) != efx);
2265

2266 2267 2268 2269 2270 2271 2272 2273
	if (efx_dev_registered(efx)) {
		strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
#ifdef CONFIG_SFC_MCDI_LOGGING
		device_remove_file(&efx->pci_dev->dev, &dev_attr_mcdi_logging);
#endif
		device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type);
		unregister_netdev(efx->net_dev);
	}
2274 2275 2276 2277 2278 2279 2280 2281 2282
}

/**************************************************************************
 *
 * List of NICs we support
 *
 **************************************************************************/

/* PCI device ID table */
2283
static const struct pci_device_id efx_pci_table[] = {
2284
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0803),	/* SFC9020 */
2285
	 .driver_data = (unsigned long) &siena_a0_nic_type},
2286
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0813),	/* SFL9021 */
2287
	 .driver_data = (unsigned long) &siena_a0_nic_type},
2288 2289
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903),  /* SFC9120 PF */
	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2290 2291
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903),  /* SFC9120 VF */
	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2292 2293
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923),  /* SFC9140 PF */
	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
2294 2295 2296 2297 2298 2299
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923),  /* SFC9140 VF */
	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03),  /* SFC9220 PF */
	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03),  /* SFC9220 VF */
	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2300 2301 2302 2303
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03),  /* SFC9250 PF */
	 .driver_data = (unsigned long) &efx_hunt_a0_nic_type},
	{PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03),  /* SFC9250 VF */
	 .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type},
2304 2305 2306 2307 2308 2309 2310 2311 2312
	{0}			/* end of list */
};

/**************************************************************************
 *
 * Data housekeeping
 *
 **************************************************************************/

2313
int efx_init_channels(struct efx_nic *efx)
2314
{
2315
	unsigned int i;
2316 2317

	for (i = 0; i < EFX_MAX_CHANNELS; i++) {
2318 2319
		efx->channel[i] = efx_alloc_channel(efx, i, NULL);
		if (!efx->channel[i])
2320
			return -ENOMEM;
B
Ben Hutchings 已提交
2321 2322
		efx->msi_context[i].efx = efx;
		efx->msi_context[i].index = i;
2323 2324 2325
	}

	/* Higher numbered interrupt modes are less capable! */
2326 2327
	if (WARN_ON_ONCE(efx->type->max_interrupt_mode >
			 efx->type->min_interrupt_mode)) {
2328
		return -EIO;
2329
	}
2330 2331
	efx->interrupt_mode = max(efx->type->max_interrupt_mode,
				  interrupt_mode);
2332 2333
	efx->interrupt_mode = min(efx->type->min_interrupt_mode,
				  interrupt_mode);
2334 2335 2336 2337

	return 0;
}

2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
void efx_update_sw_stats(struct efx_nic *efx, u64 *stats)
{
	u64 n_rx_nodesc_trunc = 0;
	struct efx_channel *channel;

	efx_for_each_channel(channel, efx)
		n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc;
	stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc;
	stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops);
}

E
Edward Cree 已提交
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397
bool efx_filter_spec_equal(const struct efx_filter_spec *left,
			   const struct efx_filter_spec *right)
{
	if ((left->match_flags ^ right->match_flags) |
	    ((left->flags ^ right->flags) &
	     (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
		return false;

	return memcmp(&left->outer_vid, &right->outer_vid,
		      sizeof(struct efx_filter_spec) -
		      offsetof(struct efx_filter_spec, outer_vid)) == 0;
}

u32 efx_filter_spec_hash(const struct efx_filter_spec *spec)
{
	BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
	return jhash2((const u32 *)&spec->outer_vid,
		      (sizeof(struct efx_filter_spec) -
		       offsetof(struct efx_filter_spec, outer_vid)) / 4,
		      0);
}

#ifdef CONFIG_RFS_ACCEL
bool efx_rps_check_rule(struct efx_arfs_rule *rule, unsigned int filter_idx,
			bool *force)
{
	if (rule->filter_id == EFX_ARFS_FILTER_ID_PENDING) {
		/* ARFS is currently updating this entry, leave it */
		return false;
	}
	if (rule->filter_id == EFX_ARFS_FILTER_ID_ERROR) {
		/* ARFS tried and failed to update this, so it's probably out
		 * of date.  Remove the filter and the ARFS rule entry.
		 */
		rule->filter_id = EFX_ARFS_FILTER_ID_REMOVING;
		*force = true;
		return true;
	} else if (WARN_ON(rule->filter_id != filter_idx)) { /* can't happen */
		/* ARFS has moved on, so old filter is not needed.  Since we did
		 * not mark the rule with EFX_ARFS_FILTER_ID_REMOVING, it will
		 * not be removed by efx_rps_hash_del() subsequently.
		 */
		*force = true;
		return true;
	}
	/* Remove it iff ARFS wants to. */
	return true;
}

2398
static
E
Edward Cree 已提交
2399 2400 2401 2402 2403
struct hlist_head *efx_rps_hash_bucket(struct efx_nic *efx,
				       const struct efx_filter_spec *spec)
{
	u32 hash = efx_filter_spec_hash(spec);

2404
	lockdep_assert_held(&efx->rps_hash_lock);
E
Edward Cree 已提交
2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484
	if (!efx->rps_hash_table)
		return NULL;
	return &efx->rps_hash_table[hash % EFX_ARFS_HASH_TABLE_SIZE];
}

struct efx_arfs_rule *efx_rps_hash_find(struct efx_nic *efx,
					const struct efx_filter_spec *spec)
{
	struct efx_arfs_rule *rule;
	struct hlist_head *head;
	struct hlist_node *node;

	head = efx_rps_hash_bucket(efx, spec);
	if (!head)
		return NULL;
	hlist_for_each(node, head) {
		rule = container_of(node, struct efx_arfs_rule, node);
		if (efx_filter_spec_equal(spec, &rule->spec))
			return rule;
	}
	return NULL;
}

struct efx_arfs_rule *efx_rps_hash_add(struct efx_nic *efx,
				       const struct efx_filter_spec *spec,
				       bool *new)
{
	struct efx_arfs_rule *rule;
	struct hlist_head *head;
	struct hlist_node *node;

	head = efx_rps_hash_bucket(efx, spec);
	if (!head)
		return NULL;
	hlist_for_each(node, head) {
		rule = container_of(node, struct efx_arfs_rule, node);
		if (efx_filter_spec_equal(spec, &rule->spec)) {
			*new = false;
			return rule;
		}
	}
	rule = kmalloc(sizeof(*rule), GFP_ATOMIC);
	*new = true;
	if (rule) {
		memcpy(&rule->spec, spec, sizeof(rule->spec));
		hlist_add_head(&rule->node, head);
	}
	return rule;
}

void efx_rps_hash_del(struct efx_nic *efx, const struct efx_filter_spec *spec)
{
	struct efx_arfs_rule *rule;
	struct hlist_head *head;
	struct hlist_node *node;

	head = efx_rps_hash_bucket(efx, spec);
	if (WARN_ON(!head))
		return;
	hlist_for_each(node, head) {
		rule = container_of(node, struct efx_arfs_rule, node);
		if (efx_filter_spec_equal(spec, &rule->spec)) {
			/* Someone already reused the entry.  We know that if
			 * this check doesn't fire (i.e. filter_id == REMOVING)
			 * then the REMOVING mark was put there by our caller,
			 * because caller is holding a lock on filter table and
			 * only holders of that lock set REMOVING.
			 */
			if (rule->filter_id != EFX_ARFS_FILTER_ID_REMOVING)
				return;
			hlist_del(node);
			kfree(rule);
			return;
		}
	}
	/* We didn't find it. */
	WARN_ON(1);
}
#endif

2485 2486 2487
/* RSS contexts.  We're using linked lists and crappy O(n) algorithms, because
 * (a) this is an infrequent control-plane operation and (b) n is small (max 64)
 */
2488
struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx)
2489
{
2490
	struct list_head *head = &efx->rss_context.list;
2491 2492 2493
	struct efx_rss_context *ctx, *new;
	u32 id = 1; /* Don't use zero, that refers to the master RSS context */

2494 2495
	WARN_ON(!mutex_is_locked(&efx->rss_lock));

2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520
	/* Search for first gap in the numbering */
	list_for_each_entry(ctx, head, list) {
		if (ctx->user_id != id)
			break;
		id++;
		/* Check for wrap.  If this happens, we have nearly 2^32
		 * allocated RSS contexts, which seems unlikely.
		 */
		if (WARN_ON_ONCE(!id))
			return NULL;
	}

	/* Create the new entry */
	new = kmalloc(sizeof(struct efx_rss_context), GFP_KERNEL);
	if (!new)
		return NULL;
	new->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
	new->rx_hash_udp_4tuple = false;

	/* Insert the new entry into the gap */
	new->user_id = id;
	list_add_tail(&new->list, &ctx->list);
	return new;
}

2521
struct efx_rss_context *efx_find_rss_context_entry(struct efx_nic *efx, u32 id)
2522
{
2523
	struct list_head *head = &efx->rss_context.list;
2524
	struct efx_rss_context *ctx;
2525 2526

	WARN_ON(!mutex_is_locked(&efx->rss_lock));
2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539

	list_for_each_entry(ctx, head, list)
		if (ctx->user_id == id)
			return ctx;
	return NULL;
}

void efx_free_rss_context_entry(struct efx_rss_context *ctx)
{
	list_del(&ctx->list);
	kfree(ctx);
}

2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550
/**************************************************************************
 *
 * PCI interface
 *
 **************************************************************************/

/* Main body of final NIC shutdown code
 * This is called only at module unload (or hotplug removal).
 */
static void efx_pci_remove_main(struct efx_nic *efx)
{
2551 2552 2553 2554
	/* Flush reset_work. It can no longer be scheduled since we
	 * are not READY.
	 */
	BUG_ON(efx->state == STATE_READY);
2555
	efx_flush_reset_workqueue(efx);
2556

B
Ben Hutchings 已提交
2557
	efx_disable_interrupts(efx);
2558
	efx_clear_interrupt_affinity(efx);
2559
	efx_nic_fini_interrupt(efx);
2560
	efx_fini_port(efx);
2561
	efx->type->fini(efx);
2562 2563 2564 2565 2566
	efx_fini_napi(efx);
	efx_remove_all(efx);
}

/* Final NIC shutdown
2567 2568
 * This is called only at module unload (or hotplug removal).  A PF can call
 * this on its VFs to ensure they are unbound first.
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579
 */
static void efx_pci_remove(struct pci_dev *pci_dev)
{
	struct efx_nic *efx;

	efx = pci_get_drvdata(pci_dev);
	if (!efx)
		return;

	/* Mark the NIC as fini, then stop the interface */
	rtnl_lock();
2580
	efx_dissociate(efx);
2581
	dev_close(efx->net_dev);
B
Ben Hutchings 已提交
2582
	efx_disable_interrupts(efx);
2583
	efx->state = STATE_UNINIT;
2584 2585
	rtnl_unlock();

2586 2587 2588
	if (efx->type->sriov_fini)
		efx->type->sriov_fini(efx);

2589 2590
	efx_unregister_netdev(efx);

2591 2592
	efx_mtd_remove(efx);

2593 2594
	efx_pci_remove_main(efx);

2595
	efx_fini_io(efx, efx->type->mem_bar(efx));
2596
	netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
2597 2598 2599

	efx_fini_struct(efx);
	free_netdev(efx->net_dev);
2600 2601

	pci_disable_pcie_error_reporting(pci_dev);
2602 2603
};

2604 2605 2606 2607 2608 2609
/* NIC VPD information
 * Called during probe to display the part number of the
 * installed NIC.  VPD is potentially very large but this should
 * always appear within the first 512 bytes.
 */
#define SFC_VPD_LEN 512
2610
static void efx_probe_vpd_strings(struct efx_nic *efx)
2611 2612 2613 2614
{
	struct pci_dev *dev = efx->pci_dev;
	char vpd_data[SFC_VPD_LEN];
	ssize_t vpd_size;
2615
	int ro_start, ro_size, i, j;
2616 2617 2618 2619 2620 2621 2622 2623 2624

	/* Get the vpd data from the device */
	vpd_size = pci_read_vpd(dev, 0, sizeof(vpd_data), vpd_data);
	if (vpd_size <= 0) {
		netif_err(efx, drv, efx->net_dev, "Unable to read VPD\n");
		return;
	}

	/* Get the Read only section */
2625 2626
	ro_start = pci_vpd_find_tag(vpd_data, 0, vpd_size, PCI_VPD_LRDT_RO_DATA);
	if (ro_start < 0) {
2627 2628 2629 2630
		netif_err(efx, drv, efx->net_dev, "VPD Read-only not found\n");
		return;
	}

2631 2632 2633
	ro_size = pci_vpd_lrdt_size(&vpd_data[ro_start]);
	j = ro_size;
	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652
	if (i + j > vpd_size)
		j = vpd_size - i;

	/* Get the Part number */
	i = pci_vpd_find_info_keyword(vpd_data, i, j, "PN");
	if (i < 0) {
		netif_err(efx, drv, efx->net_dev, "Part number not found\n");
		return;
	}

	j = pci_vpd_info_field_size(&vpd_data[i]);
	i += PCI_VPD_INFO_FLD_HDR_SIZE;
	if (i + j > vpd_size) {
		netif_err(efx, drv, efx->net_dev, "Incomplete part number\n");
		return;
	}

	netif_info(efx, drv, efx->net_dev,
		   "Part Number : %.*s\n", j, &vpd_data[i]);
2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673

	i = ro_start + PCI_VPD_LRDT_TAG_SIZE;
	j = ro_size;
	i = pci_vpd_find_info_keyword(vpd_data, i, j, "SN");
	if (i < 0) {
		netif_err(efx, drv, efx->net_dev, "Serial number not found\n");
		return;
	}

	j = pci_vpd_info_field_size(&vpd_data[i]);
	i += PCI_VPD_INFO_FLD_HDR_SIZE;
	if (i + j > vpd_size) {
		netif_err(efx, drv, efx->net_dev, "Incomplete serial number\n");
		return;
	}

	efx->vpd_sn = kmalloc(j + 1, GFP_KERNEL);
	if (!efx->vpd_sn)
		return;

	snprintf(efx->vpd_sn, j + 1, "%s", &vpd_data[i]);
2674 2675 2676
}


2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688
/* Main body of NIC initialisation
 * This is called at module load (or hotplug insertion, theoretically).
 */
static int efx_pci_probe_main(struct efx_nic *efx)
{
	int rc;

	/* Do start-of-day initialisation */
	rc = efx_probe_all(efx);
	if (rc)
		goto fail1;

2689
	efx_init_napi(efx);
2690

2691
	down_write(&efx->filter_sem);
2692
	rc = efx->type->init(efx);
2693
	up_write(&efx->filter_sem);
2694
	if (rc) {
2695 2696
		netif_err(efx, probe, efx->net_dev,
			  "failed to initialise NIC\n");
2697
		goto fail3;
2698 2699 2700 2701
	}

	rc = efx_init_port(efx);
	if (rc) {
2702 2703
		netif_err(efx, probe, efx->net_dev,
			  "failed to initialise port\n");
2704
		goto fail4;
2705 2706
	}

2707
	rc = efx_nic_init_interrupt(efx);
2708
	if (rc)
2709
		goto fail5;
2710 2711

	efx_set_interrupt_affinity(efx);
2712 2713 2714
	rc = efx_enable_interrupts(efx);
	if (rc)
		goto fail6;
2715 2716 2717

	return 0;

2718
 fail6:
2719
	efx_clear_interrupt_affinity(efx);
2720
	efx_nic_fini_interrupt(efx);
2721
 fail5:
2722 2723
	efx_fini_port(efx);
 fail4:
2724
	efx->type->fini(efx);
2725 2726 2727 2728 2729 2730 2731
 fail3:
	efx_fini_napi(efx);
	efx_remove_all(efx);
 fail1:
	return rc;
}

2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748
static int efx_pci_probe_post_io(struct efx_nic *efx)
{
	struct net_device *net_dev = efx->net_dev;
	int rc = efx_pci_probe_main(efx);

	if (rc)
		return rc;

	if (efx->type->sriov_init) {
		rc = efx->type->sriov_init(efx);
		if (rc)
			netif_err(efx, probe, efx->net_dev,
				  "SR-IOV can't be enabled rc %d\n", rc);
	}

	/* Determine netdevice features */
	net_dev->features |= (efx->type->offload_features | NETIF_F_SG |
E
Edward Cree 已提交
2749
			      NETIF_F_TSO | NETIF_F_RXCSUM | NETIF_F_RXALL);
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759
	if (efx->type->offload_features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
		net_dev->features |= NETIF_F_TSO6;
	/* Check whether device supports TSO */
	if (!efx->type->tso_versions || !efx->type->tso_versions(efx))
		net_dev->features &= ~NETIF_F_ALL_TSO;
	/* Mask for features that also apply to VLAN devices */
	net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG |
				   NETIF_F_HIGHDMA | NETIF_F_ALL_TSO |
				   NETIF_F_RXCSUM);

E
Edward Cree 已提交
2760 2761 2762 2763
	net_dev->hw_features |= net_dev->features & ~efx->fixed_features;

	/* Disable receiving frames with bad FCS, by default. */
	net_dev->features &= ~NETIF_F_RXALL;
2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779

	/* Disable VLAN filtering by default.  It may be enforced if
	 * the feature is fixed (i.e. VLAN filters are required to
	 * receive VLAN tagged packets due to vPort restrictions).
	 */
	net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
	net_dev->features |= efx->fixed_features;

	rc = efx_register_netdev(efx);
	if (!rc)
		return 0;

	efx_pci_remove_main(efx);
	return rc;
}

2780 2781 2782
/* NIC initialisation
 *
 * This is called at module load (or hotplug insertion,
2783
 * theoretically).  It sets up PCI mappings, resets the NIC,
2784 2785 2786 2787 2788
 * sets up and registers the network devices with the kernel and hooks
 * the interrupt service routine.  It does not prepare the device for
 * transmission; this is left to the first time one of the network
 * interfaces is brought up (i.e. efx_net_open).
 */
B
Bill Pemberton 已提交
2789
static int efx_pci_probe(struct pci_dev *pci_dev,
2790
			 const struct pci_device_id *entry)
2791 2792 2793
{
	struct net_device *net_dev;
	struct efx_nic *efx;
2794
	int rc;
2795 2796

	/* Allocate and initialise a struct net_device and struct efx_nic */
2797 2798
	net_dev = alloc_etherdev_mqs(sizeof(*efx), EFX_MAX_CORE_TX_QUEUES,
				     EFX_MAX_RX_QUEUES);
2799 2800
	if (!net_dev)
		return -ENOMEM;
2801 2802
	efx = netdev_priv(net_dev);
	efx->type = (const struct efx_nic_type *) entry->driver_data;
2803
	efx->fixed_features |= NETIF_F_HIGHDMA;
2804

2805
	pci_set_drvdata(pci_dev, efx);
2806
	SET_NETDEV_DEV(net_dev, &pci_dev->dev);
2807
	rc = efx_init_struct(efx, pci_dev, net_dev);
2808 2809 2810
	if (rc)
		goto fail1;

2811
	netif_info(efx, probe, efx->net_dev,
2812
		   "Solarflare NIC detected\n");
2813

2814 2815
	if (!efx->type->is_vf)
		efx_probe_vpd_strings(efx);
2816

2817
	/* Set up basic I/O (BAR mappings etc) */
2818 2819
	rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask,
			 efx->type->mem_map_size(efx));
2820 2821 2822
	if (rc)
		goto fail2;

2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841
	rc = efx_pci_probe_post_io(efx);
	if (rc) {
		/* On failure, retry once immediately.
		 * If we aborted probe due to a scheduled reset, dismiss it.
		 */
		efx->reset_pending = 0;
		rc = efx_pci_probe_post_io(efx);
		if (rc) {
			/* On another failure, retry once more
			 * after a 50-305ms delay.
			 */
			unsigned char r;

			get_random_bytes(&r, 1);
			msleep((unsigned int)r + 50);
			efx->reset_pending = 0;
			rc = efx_pci_probe_post_io(efx);
		}
	}
2842 2843
	if (rc)
		goto fail3;
2844

2845
	netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n");
2846

2847
	/* Try to create MTDs, but allow this to fail */
2848
	rtnl_lock();
2849
	rc = efx_mtd_probe(efx);
2850
	rtnl_unlock();
2851
	if (rc && rc != -EPERM)
2852 2853 2854
		netif_warn(efx, probe, efx->net_dev,
			   "failed to create MTDs (%d)\n", rc);

2855
	(void)pci_enable_pcie_error_reporting(pci_dev);
2856

2857 2858 2859
	if (efx->type->udp_tnl_push_ports)
		efx->type->udp_tnl_push_ports(efx);

2860 2861 2862
	return 0;

 fail3:
2863
	efx_fini_io(efx, efx->type->mem_bar(efx));
2864 2865 2866
 fail2:
	efx_fini_struct(efx);
 fail1:
S
Steve Hodgson 已提交
2867
	WARN_ON(rc > 0);
2868
	netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc);
2869 2870 2871 2872
	free_netdev(net_dev);
	return rc;
}

2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892
/* efx_pci_sriov_configure returns the actual number of Virtual Functions
 * enabled on success
 */
#ifdef CONFIG_SFC_SRIOV
static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
{
	int rc;
	struct efx_nic *efx = pci_get_drvdata(dev);

	if (efx->type->sriov_configure) {
		rc = efx->type->sriov_configure(efx, num_vfs);
		if (rc)
			return rc;
		else
			return num_vfs;
	} else
		return -EOPNOTSUPP;
}
#endif

2893 2894
static int efx_pm_freeze(struct device *dev)
{
2895
	struct efx_nic *efx = dev_get_drvdata(dev);
2896

2897 2898
	rtnl_lock();

2899 2900
	if (efx->state != STATE_DISABLED) {
		efx->state = STATE_UNINIT;
2901

2902
		efx_device_detach_sync(efx);
2903

2904
		efx_stop_all(efx);
B
Ben Hutchings 已提交
2905
		efx_disable_interrupts(efx);
2906
	}
2907

2908 2909
	rtnl_unlock();

2910 2911 2912 2913 2914
	return 0;
}

static int efx_pm_thaw(struct device *dev)
{
2915
	int rc;
2916
	struct efx_nic *efx = dev_get_drvdata(dev);
2917

2918 2919
	rtnl_lock();

2920
	if (efx->state != STATE_DISABLED) {
2921 2922 2923
		rc = efx_enable_interrupts(efx);
		if (rc)
			goto fail;
2924

2925 2926 2927
		mutex_lock(&efx->mac_lock);
		efx->phy_op->reconfigure(efx);
		mutex_unlock(&efx->mac_lock);
2928

2929
		efx_start_all(efx);
2930

2931
		efx_device_attach_if_not_resetting(efx);
2932

2933
		efx->state = STATE_READY;
2934

2935 2936
		efx->type->resume_wol(efx);
	}
2937

2938 2939
	rtnl_unlock();

2940
	/* Reschedule any quenched resets scheduled during efx_pm_freeze() */
2941
	efx_queue_reset_work(efx);
2942

2943
	return 0;
2944 2945 2946 2947 2948

fail:
	rtnl_unlock();

	return rc;
2949 2950 2951 2952 2953 2954 2955 2956 2957
}

static int efx_pm_poweroff(struct device *dev)
{
	struct pci_dev *pci_dev = to_pci_dev(dev);
	struct efx_nic *efx = pci_get_drvdata(pci_dev);

	efx->type->fini(efx);

2958
	efx->reset_pending = 0;
2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981

	pci_save_state(pci_dev);
	return pci_set_power_state(pci_dev, PCI_D3hot);
}

/* Used for both resume and restore */
static int efx_pm_resume(struct device *dev)
{
	struct pci_dev *pci_dev = to_pci_dev(dev);
	struct efx_nic *efx = pci_get_drvdata(pci_dev);
	int rc;

	rc = pci_set_power_state(pci_dev, PCI_D0);
	if (rc)
		return rc;
	pci_restore_state(pci_dev);
	rc = pci_enable_device(pci_dev);
	if (rc)
		return rc;
	pci_set_master(efx->pci_dev);
	rc = efx->type->reset(efx, RESET_TYPE_ALL);
	if (rc)
		return rc;
2982
	down_write(&efx->filter_sem);
2983
	rc = efx->type->init(efx);
2984
	up_write(&efx->filter_sem);
2985 2986
	if (rc)
		return rc;
2987 2988
	rc = efx_pm_thaw(dev);
	return rc;
2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001
}

static int efx_pm_suspend(struct device *dev)
{
	int rc;

	efx_pm_freeze(dev);
	rc = efx_pm_poweroff(dev);
	if (rc)
		efx_pm_resume(dev);
	return rc;
}

3002
static const struct dev_pm_ops efx_pm_ops = {
3003 3004 3005 3006 3007 3008 3009 3010
	.suspend	= efx_pm_suspend,
	.resume		= efx_pm_resume,
	.freeze		= efx_pm_freeze,
	.thaw		= efx_pm_thaw,
	.poweroff	= efx_pm_poweroff,
	.restore	= efx_pm_resume,
};

3011 3012 3013 3014
/* A PCI error affecting this device was detected.
 * At this point MMIO and DMA may be disabled.
 * Stop the software path and request a slot reset.
 */
3015 3016
static pci_ers_result_t efx_io_error_detected(struct pci_dev *pdev,
					      enum pci_channel_state state)
3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032
{
	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;
	struct efx_nic *efx = pci_get_drvdata(pdev);

	if (state == pci_channel_io_perm_failure)
		return PCI_ERS_RESULT_DISCONNECT;

	rtnl_lock();

	if (efx->state != STATE_DISABLED) {
		efx->state = STATE_RECOVERY;
		efx->reset_pending = 0;

		efx_device_detach_sync(efx);

		efx_stop_all(efx);
B
Ben Hutchings 已提交
3033
		efx_disable_interrupts(efx);
3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049

		status = PCI_ERS_RESULT_NEED_RESET;
	} else {
		/* If the interface is disabled we don't want to do anything
		 * with it.
		 */
		status = PCI_ERS_RESULT_RECOVERED;
	}

	rtnl_unlock();

	pci_disable_device(pdev);

	return status;
}

3050
/* Fake a successful reset, which will be performed later in efx_io_resume. */
3051
static pci_ers_result_t efx_io_slot_reset(struct pci_dev *pdev)
3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095
{
	struct efx_nic *efx = pci_get_drvdata(pdev);
	pci_ers_result_t status = PCI_ERS_RESULT_RECOVERED;

	if (pci_enable_device(pdev)) {
		netif_err(efx, hw, efx->net_dev,
			  "Cannot re-enable PCI device after reset.\n");
		status =  PCI_ERS_RESULT_DISCONNECT;
	}

	return status;
}

/* Perform the actual reset and resume I/O operations. */
static void efx_io_resume(struct pci_dev *pdev)
{
	struct efx_nic *efx = pci_get_drvdata(pdev);
	int rc;

	rtnl_lock();

	if (efx->state == STATE_DISABLED)
		goto out;

	rc = efx_reset(efx, RESET_TYPE_ALL);
	if (rc) {
		netif_err(efx, hw, efx->net_dev,
			  "efx_reset failed after PCI error (%d)\n", rc);
	} else {
		efx->state = STATE_READY;
		netif_dbg(efx, hw, efx->net_dev,
			  "Done resetting and resuming IO after PCI error.\n");
	}

out:
	rtnl_unlock();
}

/* For simplicity and reliability, we always require a slot reset and try to
 * reset the hardware when a pci error affecting the device is detected.
 * We leave both the link_reset and mmio_enabled callback unimplemented:
 * with our request for slot reset the mmio_enabled callback will never be
 * called, and the link_reset callback is not used by AER or EEH mechanisms.
 */
3096
static const struct pci_error_handlers efx_err_handlers = {
3097 3098 3099 3100 3101
	.error_detected = efx_io_error_detected,
	.slot_reset	= efx_io_slot_reset,
	.resume		= efx_io_resume,
};

3102
static struct pci_driver efx_pci_driver = {
3103
	.name		= KBUILD_MODNAME,
3104 3105 3106
	.id_table	= efx_pci_table,
	.probe		= efx_pci_probe,
	.remove		= efx_pci_remove,
3107
	.driver.pm	= &efx_pm_ops,
3108
	.err_handler	= &efx_err_handlers,
3109 3110 3111
#ifdef CONFIG_SFC_SRIOV
	.sriov_configure = efx_pci_sriov_configure,
#endif
3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133
};

/**************************************************************************
 *
 * Kernel module interface
 *
 *************************************************************************/

module_param(interrupt_mode, uint, 0444);
MODULE_PARM_DESC(interrupt_mode,
		 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");

static int __init efx_init_module(void)
{
	int rc;

	printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");

	rc = register_netdevice_notifier(&efx_netdev_notifier);
	if (rc)
		goto err_notifier;

3134
#ifdef CONFIG_SFC_SRIOV
3135 3136 3137
	rc = efx_init_sriov();
	if (rc)
		goto err_sriov;
3138
#endif
3139

3140 3141
	rc = efx_create_reset_workqueue();
	if (rc)
3142
		goto err_reset;
3143 3144 3145 3146 3147 3148 3149 3150

	rc = pci_register_driver(&efx_pci_driver);
	if (rc < 0)
		goto err_pci;

	return 0;

 err_pci:
3151
	efx_destroy_reset_workqueue();
3152
 err_reset:
3153
#ifdef CONFIG_SFC_SRIOV
3154 3155
	efx_fini_sriov();
 err_sriov:
3156
#endif
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166
	unregister_netdevice_notifier(&efx_netdev_notifier);
 err_notifier:
	return rc;
}

static void __exit efx_exit_module(void)
{
	printk(KERN_INFO "Solarflare NET driver unloading\n");

	pci_unregister_driver(&efx_pci_driver);
3167
	efx_destroy_reset_workqueue();
3168
#ifdef CONFIG_SFC_SRIOV
3169
	efx_fini_sriov();
3170
#endif
3171 3172 3173 3174 3175 3176 3177
	unregister_netdevice_notifier(&efx_netdev_notifier);

}

module_init(efx_init_module);
module_exit(efx_exit_module);

3178 3179
MODULE_AUTHOR("Solarflare Communications and "
	      "Michael Brown <mbrown@fensystems.co.uk>");
B
Ben Hutchings 已提交
3180
MODULE_DESCRIPTION("Solarflare network driver");
3181 3182
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(pci, efx_pci_table);
3183
MODULE_VERSION(EFX_DRIVER_VERSION);