summaryrefslogtreecommitdiffstats
path: root/src/drivers/net/intelxlvf.c
blob: 8f76daf3dd60a2a9d0004ed3b6d5efe7e58f0249 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
/*
 * Copyright (C) 2019 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * You can also choose to distribute this program under the terms of
 * the Unmodified Binary Distribution Licence (as given in the file
 * COPYING.UBDL), provided that you have satisfied its requirements.
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/pci.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include "intelxlvf.h"

/** @file
 *
 * Intel 40 Gigabit Ethernet virtual function network card driver
 *
 */

/******************************************************************************
 *
 * Device reset
 *
 ******************************************************************************
 */

/**
 * Reset hardware via PCIe function-level reset
 *
 * @v intelxl		Intel device
 */
static void intelxlvf_reset_flr ( struct intelxl_nic *intelxl,
				  struct pci_device *pci ) {
	uint16_t control;

	/* Perform a PCIe function-level reset */
	pci_read_config_word ( pci, ( intelxl->exp + PCI_EXP_DEVCTL ),
			       &control );
	pci_write_config_word ( pci, ( intelxl->exp + PCI_EXP_DEVCTL ),
				( control | PCI_EXP_DEVCTL_FLR ) );
	mdelay ( INTELXL_RESET_DELAY_MS );
}

/**
 * Wait for admin event queue to be torn down
 *
 * @v intelxl		Intel device
 * @ret rc		Return status code
 */
static int intelxlvf_reset_wait_teardown ( struct intelxl_nic *intelxl ) {
	uint32_t admin_evt_len;
	unsigned int i;

	/* Wait for admin event queue to be torn down */
	for ( i = 0 ; i < INTELXLVF_RESET_MAX_WAIT_MS ; i++ ) {

		/* Check admin event queue length register */
		admin_evt_len = readl ( intelxl->regs + INTELXLVF_ADMIN +
					INTELXLVF_ADMIN_EVT_LEN );
		if ( ! ( admin_evt_len & INTELXL_ADMIN_LEN_ENABLE ) )
			return 0;

		/* Delay */
		mdelay ( 1 );
	}

	DBGC ( intelxl, "INTELXL %p timed out waiting for teardown (%#08x)\n",
	       intelxl, admin_evt_len );
	return -ETIMEDOUT;
}

/**
 * Wait for virtual function to be marked as active
 *
 * @v intelxl		Intel device
 * @ret rc		Return status code
 */
static int intelxlvf_reset_wait_active ( struct intelxl_nic *intelxl ) {
	uint32_t vfgen_rstat;
	unsigned int vfr_state;
	unsigned int i;

	/* Wait for virtual function to be marked as active */
	for ( i = 0 ; i < INTELXLVF_RESET_MAX_WAIT_MS ; i++ ) {

		/* Check status as written by physical function driver */
		vfgen_rstat = readl ( intelxl->regs + INTELXLVF_VFGEN_RSTAT );
		vfr_state = INTELXLVF_VFGEN_RSTAT_VFR_STATE ( vfgen_rstat );
		if ( vfr_state == INTELXLVF_VFGEN_RSTAT_VFR_STATE_ACTIVE )
			return 0;

		/* Delay */
		mdelay ( 1 );
	}

	DBGC ( intelxl, "INTELXL %p timed out waiting for activation "
	       "(%#08x)\n", intelxl, vfgen_rstat );
	return -ETIMEDOUT;
}

/**
 * Reset hardware via admin queue
 *
 * @v intelxl		Intel device
 * @ret rc		Return status code
 */
static int intelxlvf_reset_admin ( struct intelxl_nic *intelxl ) {
	struct intelxl_admin_descriptor *cmd;
	int rc;

	/* Populate descriptor */
	cmd = intelxl_admin_command_descriptor ( intelxl );
	cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_SEND_TO_PF );
	cmd->vopcode = cpu_to_le32 ( INTELXL_ADMIN_VF_RESET );

	/* Issue command */
	if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
		goto err_command;

	/* Wait for minimum reset time */
	mdelay ( INTELXL_RESET_DELAY_MS );

	/* Wait for reset to take effect */
	if ( ( rc = intelxlvf_reset_wait_teardown ( intelxl ) ) != 0 )
		goto err_teardown;

	/* Wait for virtual function to become active */
	if ( ( rc = intelxlvf_reset_wait_active ( intelxl ) ) != 0 )
		goto err_active;

 err_active:
 err_teardown:
	intelxl_reopen_admin ( intelxl );
 err_command:
	return rc;
}

/******************************************************************************
 *
 * Admin queue
 *
 ******************************************************************************
 */

/** Admin command queue register offsets */
static const struct intelxl_admin_offsets intelxlvf_admin_command_offsets = {
	.bal = INTELXLVF_ADMIN_CMD_BAL,
	.bah = INTELXLVF_ADMIN_CMD_BAH,
	.len = INTELXLVF_ADMIN_CMD_LEN,
	.head = INTELXLVF_ADMIN_CMD_HEAD,
	.tail = INTELXLVF_ADMIN_CMD_TAIL,
};

/** Admin event queue register offsets */
static const struct intelxl_admin_offsets intelxlvf_admin_event_offsets = {
	.bal = INTELXLVF_ADMIN_EVT_BAL,
	.bah = INTELXLVF_ADMIN_EVT_BAH,
	.len = INTELXLVF_ADMIN_EVT_LEN,
	.head = INTELXLVF_ADMIN_EVT_HEAD,
	.tail = INTELXLVF_ADMIN_EVT_TAIL,
};

/**
 * Issue admin queue virtual function command
 *
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int intelxlvf_admin_command ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	struct intelxl_admin *admin = &intelxl->command;
	struct intelxl_admin_descriptor *cmd;
	unsigned int i;
	int rc;

	/* Populate descriptor */
	cmd = &admin->desc[ admin->index % INTELXL_ADMIN_NUM_DESC ];
	cmd->opcode = cpu_to_le16 ( INTELXL_ADMIN_SEND_TO_PF );

	/* Record opcode */
	intelxl->vopcode = le32_to_cpu ( cmd->vopcode );

	/* Issue command */
	if ( ( rc = intelxl_admin_command ( intelxl ) ) != 0 )
		goto err_command;

	/* Wait for response */
	for ( i = 0 ; i < INTELXLVF_ADMIN_MAX_WAIT_MS ; i++ ) {

		/* Poll admin event queue */
		intelxl_poll_admin ( netdev );

		/* If response has not arrived, delay 1ms and retry */
		if ( intelxl->vopcode ) {
			mdelay ( 1 );
			continue;
		}

		/* Check for errors */
		if ( intelxl->vret != 0 )
			return -EIO;

		return 0;
	}

	rc = -ETIMEDOUT;
	DBGC ( intelxl, "INTELXL %p timed out waiting for admin VF command "
	       "%#x\n", intelxl, intelxl->vopcode );
 err_command:
	intelxl->vopcode = 0;
	return rc;
}

/**
 * Handle link status event
 *
 * @v netdev		Network device
 * @v link		Link status
 */
static void intelxlvf_admin_link ( struct net_device *netdev,
				   struct intelxl_admin_vf_status_link *link ) {
	struct intelxl_nic *intelxl = netdev->priv;

	DBGC ( intelxl, "INTELXL %p link %#02x speed %#02x\n", intelxl,
	       link->status, link->speed );

	/* Update network device */
	if ( link->status ) {
		netdev_link_up ( netdev );
	} else {
		netdev_link_down ( netdev );
	}
}

/**
 * Handle status change event
 *
 * @v netdev		Network device
 * @v stat		Status change event
 */
static void
intelxlvf_admin_status ( struct net_device *netdev,
			 struct intelxl_admin_vf_status_buffer *stat ) {
	struct intelxl_nic *intelxl = netdev->priv;

	/* Handle event */
	switch ( stat->event ) {
	case cpu_to_le32 ( INTELXL_ADMIN_VF_STATUS_LINK ):
		intelxlvf_admin_link ( netdev, &stat->data.link );
		break;
	default:
		DBGC ( intelxl, "INTELXL %p unrecognised status change "
		       "event %#x:\n", intelxl, le32_to_cpu ( stat->event ) );
		DBGC_HDA ( intelxl, 0, stat, sizeof ( *stat ) );
		break;
	}
}

/**
 * Handle virtual function event
 *
 * @v netdev		Network device
 * @v evt		Admin queue event descriptor
 * @v buf		Admin queue event data buffer
 */
void intelxlvf_admin_event ( struct net_device *netdev,
			     struct intelxl_admin_descriptor *evt,
			     union intelxl_admin_buffer *buf ) {
	struct intelxl_nic *intelxl = netdev->priv;
	unsigned int vopcode = le32_to_cpu ( evt->vopcode );

	/* Record command response if applicable */
	if ( vopcode == intelxl->vopcode ) {
		memcpy ( &intelxl->vbuf, buf, sizeof ( intelxl->vbuf ) );
		intelxl->vopcode = 0;
		intelxl->vret = le32_to_cpu ( evt->vret );
		if ( intelxl->vret != 0 ) {
			DBGC ( intelxl, "INTELXL %p admin VF command %#x "
			       "error %d\n", intelxl, vopcode, intelxl->vret );
			DBGC_HDA ( intelxl, virt_to_bus ( evt ), evt,
				   sizeof ( *evt ) );
			DBGC_HDA ( intelxl, virt_to_bus ( buf ), buf,
				   le16_to_cpu ( evt->len ) );
		}
		return;
	}

	/* Handle unsolicited events */
	switch ( vopcode ) {
	case INTELXL_ADMIN_VF_STATUS:
		intelxlvf_admin_status ( netdev, &buf->stat );
		break;
	default:
		DBGC ( intelxl, "INTELXL %p unrecognised VF event %#x:\n",
		       intelxl, vopcode );
		DBGC_HDA ( intelxl, 0, evt, sizeof ( *evt ) );
		DBGC_HDA ( intelxl, 0, buf, le16_to_cpu ( evt->len ) );
		break;
	}
}

/**
 * Get resources
 *
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int intelxlvf_admin_get_resources ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	struct intelxl_admin_descriptor *cmd;
	struct intelxl_admin_vf_get_resources_buffer *res;
	int rc;

	/* Populate descriptor */
	cmd = intelxl_admin_command_descriptor ( intelxl );
	cmd->vopcode = cpu_to_le32 ( INTELXL_ADMIN_VF_GET_RESOURCES );

	/* Issue command */
	if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
		return rc;

	/* Parse response */
	res = &intelxl->vbuf.res;
	intelxl->vsi = le16_to_cpu ( res->vsi );
	memcpy ( netdev->hw_addr, res->mac, ETH_ALEN );
	DBGC ( intelxl, "INTELXL %p VSI %#04x\n", intelxl, intelxl->vsi );

	return 0;
}

/******************************************************************************
 *
 * Network device interface
 *
 ******************************************************************************
 */

/**
 * Configure queues
 *
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int intelxlvf_admin_configure ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	struct intelxl_admin_descriptor *cmd;
	union intelxl_admin_buffer *buf;
	int rc;

	/* Populate descriptor */
	cmd = intelxl_admin_command_descriptor ( intelxl );
	cmd->vopcode = cpu_to_le32 ( INTELXL_ADMIN_VF_CONFIGURE );
	cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_RD | INTELXL_ADMIN_FL_BUF );
	cmd->len = cpu_to_le16 ( sizeof ( buf->cfg ) );
	buf = intelxl_admin_command_buffer ( intelxl );
	buf->cfg.vsi = cpu_to_le16 ( intelxl->vsi );
	buf->cfg.count = cpu_to_le16 ( 1 );
	buf->cfg.tx.vsi = cpu_to_le16 ( intelxl->vsi );
	buf->cfg.tx.count = cpu_to_le16 ( INTELXL_TX_NUM_DESC );
	buf->cfg.tx.base = cpu_to_le64 ( virt_to_bus ( intelxl->tx.desc.raw ) );
	buf->cfg.rx.vsi = cpu_to_le16 ( intelxl->vsi );
	buf->cfg.rx.count = cpu_to_le32 ( INTELXL_RX_NUM_DESC );
	buf->cfg.rx.len = cpu_to_le32 ( intelxl->mfs );
	buf->cfg.rx.mfs = cpu_to_le32 ( intelxl->mfs );
	buf->cfg.rx.base = cpu_to_le64 ( virt_to_bus ( intelxl->rx.desc.raw ) );

	/* Issue command */
	if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
		return rc;

	return 0;
}

/**
 * Configure IRQ mapping
 *
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int intelxlvf_admin_irq_map ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	struct intelxl_admin_descriptor *cmd;
	union intelxl_admin_buffer *buf;
	int rc;

	/* Populate descriptor */
	cmd = intelxl_admin_command_descriptor ( intelxl );
	cmd->vopcode = cpu_to_le32 ( INTELXL_ADMIN_VF_IRQ_MAP );
	cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_RD | INTELXL_ADMIN_FL_BUF );
	cmd->len = cpu_to_le16 ( sizeof ( buf->irq ) );
	buf = intelxl_admin_command_buffer ( intelxl );
	buf->irq.count = cpu_to_le16 ( 1 );
	buf->irq.vsi = cpu_to_le16 ( intelxl->vsi );
	buf->irq.rxmap = cpu_to_le16 ( 0x0001 );
	buf->irq.txmap = cpu_to_le16 ( 0x0001 );

	/* Issue command */
	if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
		return rc;

	return 0;
}

/**
 * Enable/disable queues
 *
 * @v netdev		Network device
 * @v enable		Enable queues
 * @ret rc		Return status code
 */
static int intelxlvf_admin_queues ( struct net_device *netdev, int enable ) {
	struct intelxl_nic *intelxl = netdev->priv;
	struct intelxl_admin_descriptor *cmd;
	union intelxl_admin_buffer *buf;
	int rc;

	/* Populate descriptor */
	cmd = intelxl_admin_command_descriptor ( intelxl );
	cmd->vopcode = ( enable ? cpu_to_le32 ( INTELXL_ADMIN_VF_ENABLE ) :
			 cpu_to_le32 ( INTELXL_ADMIN_VF_DISABLE ) );
	cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_RD | INTELXL_ADMIN_FL_BUF );
	cmd->len = cpu_to_le16 ( sizeof ( buf->queues ) );
	buf = intelxl_admin_command_buffer ( intelxl );
	buf->queues.vsi = cpu_to_le16 ( intelxl->vsi );
	buf->queues.rx = cpu_to_le32 ( 1 );
	buf->queues.tx = cpu_to_le32 ( 1 );

	/* Issue command */
	if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
		return rc;

	return 0;
}

/**
 * Configure promiscuous mode
 *
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int intelxlvf_admin_promisc ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	struct intelxl_admin_descriptor *cmd;
	union intelxl_admin_buffer *buf;
	int rc;

	/* Populate descriptor */
	cmd = intelxl_admin_command_descriptor ( intelxl );
	cmd->vopcode = cpu_to_le32 ( INTELXL_ADMIN_VF_PROMISC );
	cmd->flags = cpu_to_le16 ( INTELXL_ADMIN_FL_RD | INTELXL_ADMIN_FL_BUF );
	cmd->len = cpu_to_le16 ( sizeof ( buf->promisc ) );
	buf = intelxl_admin_command_buffer ( intelxl );
	buf->promisc.vsi = cpu_to_le16 ( intelxl->vsi );
	buf->promisc.flags = cpu_to_le16 ( INTELXL_ADMIN_PROMISC_FL_UNICAST |
					   INTELXL_ADMIN_PROMISC_FL_MULTICAST );

	/* Issue command */
	if ( ( rc = intelxlvf_admin_command ( netdev ) ) != 0 )
		return rc;

	return 0;
}

/**
 * Open network device
 *
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int intelxlvf_open ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	int rc;

	/* Calculate maximum frame size */
	intelxl->mfs = ( ( ETH_HLEN + netdev->mtu + 4 /* CRC */ +
			   INTELXL_ALIGN - 1 ) & ~( INTELXL_ALIGN - 1 ) );

	/* Allocate transmit descriptor ring */
	if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->tx ) ) != 0 )
		goto err_alloc_tx;

	/* Allocate receive descriptor ring */
	if ( ( rc = intelxl_alloc_ring ( intelxl, &intelxl->rx ) ) != 0 )
		goto err_alloc_rx;

	/* Configure queues */
	if ( ( rc = intelxlvf_admin_configure ( netdev ) ) != 0 )
		goto err_configure;

	/* Configure IRQ map */
	if ( ( rc = intelxlvf_admin_irq_map ( netdev ) ) != 0 )
		goto err_irq_map;

	/* Enable queues */
	if ( ( rc = intelxlvf_admin_queues ( netdev, 1 ) ) != 0 )
		goto err_enable;

	/* Configure promiscuous mode */
	if ( ( rc = intelxlvf_admin_promisc ( netdev ) ) != 0 )
		goto err_promisc;

	return 0;

 err_promisc:
	intelxlvf_admin_queues ( netdev, INTELXL_ADMIN_VF_DISABLE );
 err_enable:
 err_irq_map:
 err_configure:
	intelxl_free_ring ( intelxl, &intelxl->rx );
 err_alloc_rx:
	intelxl_free_ring ( intelxl, &intelxl->tx );
 err_alloc_tx:
	return rc;
}

/**
 * Close network device
 *
 * @v netdev		Network device
 */
static void intelxlvf_close ( struct net_device *netdev ) {
	struct intelxl_nic *intelxl = netdev->priv;
	int rc;

	/* Disable queues */
	if ( ( rc = intelxlvf_admin_queues ( netdev, 0 ) ) != 0 ) {
		/* Leak memory; there's nothing else we can do */
		return;
	}

	/* Free receive descriptor ring */
	intelxl_free_ring ( intelxl, &intelxl->rx );

	/* Free transmit descriptor ring */
	intelxl_free_ring ( intelxl, &intelxl->tx );

	/* Discard any unused receive buffers */
	intelxl_empty_rx ( intelxl );
}

/** Network device operations */
static struct net_device_operations intelxlvf_operations = {
	.open		= intelxlvf_open,
	.close		= intelxlvf_close,
	.transmit	= intelxl_transmit,
	.poll		= intelxl_poll,
};

/******************************************************************************
 *
 * PCI interface
 *
 ******************************************************************************
 */

/**
 * Probe PCI device
 *
 * @v pci		PCI device
 * @ret rc		Return status code
 */
static int intelxlvf_probe ( struct pci_device *pci ) {
	struct net_device *netdev;
	struct intelxl_nic *intelxl;
	int rc;

	/* Allocate and initialise net device */
	netdev = alloc_etherdev ( sizeof ( *intelxl ) );
	if ( ! netdev ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	netdev_init ( netdev, &intelxlvf_operations );
	intelxl = netdev->priv;
	pci_set_drvdata ( pci, netdev );
	netdev->dev = &pci->dev;
	memset ( intelxl, 0, sizeof ( *intelxl ) );
	intelxl->intr = INTELXLVF_VFINT_DYN_CTL0;
	intelxl_init_admin ( &intelxl->command, INTELXLVF_ADMIN,
			     &intelxlvf_admin_command_offsets );
	intelxl_init_admin ( &intelxl->event, INTELXLVF_ADMIN,
			     &intelxlvf_admin_event_offsets );
	intelxlvf_init_ring ( &intelxl->tx, INTELXL_TX_NUM_DESC,
			      sizeof ( intelxl->tx.desc.tx[0] ),
			      INTELXLVF_QTX_TAIL );
	intelxlvf_init_ring ( &intelxl->rx, INTELXL_RX_NUM_DESC,
			      sizeof ( intelxl->rx.desc.rx[0] ),
			      INTELXLVF_QRX_TAIL );

	/* Fix up PCI device */
	adjust_pci_device ( pci );

	/* Map registers */
	intelxl->regs = ioremap ( pci->membase, INTELXLVF_BAR_SIZE );
	if ( ! intelxl->regs ) {
		rc = -ENODEV;
		goto err_ioremap;
	}

	/* Locate PCI Express capability */
	intelxl->exp = pci_find_capability ( pci, PCI_CAP_ID_EXP );
	if ( ! intelxl->exp ) {
		DBGC ( intelxl, "INTELXL %p missing PCIe capability\n",
		       intelxl );
		rc = -ENXIO;
		goto err_exp;
	}

	/* Reset the function via PCIe FLR */
	intelxlvf_reset_flr ( intelxl, pci );

	/* Enable MSI-X dummy interrupt */
	if ( ( rc = intelxl_msix_enable ( intelxl, pci ) ) != 0 )
		goto err_msix;

	/* Open admin queues */
	if ( ( rc = intelxl_open_admin ( intelxl ) ) != 0 )
		goto err_open_admin;

	/* Reset the function via admin queue */
	if ( ( rc = intelxlvf_reset_admin ( intelxl ) ) != 0 )
		goto err_reset_admin;

	/* Get MAC address */
	if ( ( rc = intelxlvf_admin_get_resources ( netdev ) ) != 0 )
		goto err_get_resources;

	/* Register network device */
	if ( ( rc = register_netdev ( netdev ) ) != 0 )
		goto err_register_netdev;

	return 0;

	unregister_netdev ( netdev );
 err_register_netdev:
 err_get_resources:
 err_reset_admin:
	intelxl_close_admin ( intelxl );
 err_open_admin:
	intelxl_msix_disable ( intelxl, pci );
 err_msix:
	intelxlvf_reset_flr ( intelxl, pci );
 err_exp:
	iounmap ( intelxl->regs );
 err_ioremap:
	netdev_nullify ( netdev );
	netdev_put ( netdev );
 err_alloc:
	return rc;
}

/**
 * Remove PCI device
 *
 * @v pci		PCI device
 */
static void intelxlvf_remove ( struct pci_device *pci ) {
	struct net_device *netdev = pci_get_drvdata ( pci );
	struct intelxl_nic *intelxl = netdev->priv;

	/* Unregister network device */
	unregister_netdev ( netdev );

	/* Reset the function via admin queue */
	intelxlvf_reset_admin ( intelxl );

	/* Close admin queues */
	intelxl_close_admin ( intelxl );

	/* Disable MSI-X dummy interrupt */
	intelxl_msix_disable ( intelxl, pci );

	/* Reset the function via PCIe FLR */
	intelxlvf_reset_flr ( intelxl, pci );

	/* Free network device */
	iounmap ( intelxl->regs );
	netdev_nullify ( netdev );
	netdev_put ( netdev );
}

/** PCI device IDs */
static struct pci_device_id intelxlvf_nics[] = {
	PCI_ROM ( 0x8086, 0x154c, "xl710-vf", "XL710 VF", 0 ),
	PCI_ROM ( 0x8086, 0x1571, "xl710-vf-hv", "XL710 VF (Hyper-V)", 0 ),
	PCI_ROM ( 0x8086, 0x1889, "xl710-vf-ad", "XL710 VF (adaptive)", 0 ),
	PCI_ROM ( 0x8086, 0x37cd, "x722-vf", "X722 VF", 0 ),
	PCI_ROM ( 0x8086, 0x37d9, "x722-vf-hv", "X722 VF (Hyper-V)", 0 ),
};

/** PCI driver */
struct pci_driver intelxlvf_driver __pci_driver = {
	.ids = intelxlvf_nics,
	.id_count = ( sizeof ( intelxlvf_nics ) /
		      sizeof ( intelxlvf_nics[0] ) ),
	.probe = intelxlvf_probe,
	.remove = intelxlvf_remove,
};