if_ix.c 134 KB
Newer Older
1
2
/******************************************************************************

jfv's avatar
jfv committed
3
  Copyright (c) 2001-2015, Intel Corporation 
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
  All rights reserved.
  
  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions are met:
  
   1. Redistributions of source code must retain the above copyright notice, 
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in the 
      documentation and/or other materials provided with the distribution.
  
   3. Neither the name of the Intel Corporation nor the names of its 
      contributors may be used to endorse or promote products derived from 
      this software without specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.

******************************************************************************/
/*$FreeBSD$*/
jfv's avatar
jfv committed
34

35

jfv's avatar
jfv committed
36
#ifndef IXGBE_STANDALONE_BUILD
37
#include "opt_inet.h"
38
#include "opt_inet6.h"
39
#include "opt_rss.h"
jfv's avatar
jfv committed
40
41
#endif

42
#include "ixgbe.h"
jfv's avatar
jfv committed
43

44
#ifdef	RSS
45
#include <net/rss_config.h>
jfv's avatar
jfv committed
46
#include <netinet/in_rss.h>
47
48
#endif

jfv's avatar
jfv committed
49
50
51
52
53
54
55
56
/*********************************************************************
 *  Set this to one to display debug statistics
 *********************************************************************/
int             ixgbe_display_debug_stats = 0;

/*********************************************************************
 *  Driver version
 *********************************************************************/
57
char ixgbe_driver_version[] = "2.8.3";
jfv's avatar
jfv committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

/*********************************************************************
 *  PCI Device ID Table
 *
 *  Used by probe to select devices to load on
 *  Last field stores an index into ixgbe_strings
 *  Last entry must be all 0s
 *
 *  { Vendor ID, Device ID, SubVendor ID, SubDevice ID, String Index }
 *********************************************************************/

static ixgbe_vendor_info_t ixgbe_vendor_info_array[] =
{
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT, 0, 0, 0},
73
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4, 0, 0, 0},
jfv's avatar
jfv committed
74
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT, 0, 0, 0},
jfv's avatar
jfv committed
75
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2, 0, 0, 0},
jfv's avatar
jfv committed
76
77
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT, 0, 0, 0},
78
79
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR, 0, 0, 0},
jfv's avatar
jfv committed
80
81
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM, 0, 0, 0},
82
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4, 0, 0, 0},
jfv's avatar
jfv committed
83
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ, 0, 0, 0},
84
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP, 0, 0, 0},
85
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM, 0, 0, 0},
jfv's avatar
jfv committed
86
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4, 0, 0, 0},
jfv's avatar
jfv committed
87
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM, 0, 0, 0},
jfv's avatar
jfv committed
88
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE, 0, 0, 0},
jfv's avatar
jfv committed
89
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE, 0, 0, 0},
jfv's avatar
jfv committed
90
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2, 0, 0, 0},
jfv's avatar
jfv committed
91
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE, 0, 0, 0},
92
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP, 0, 0, 0},
93
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF_QP, 0, 0, 0},
jfv's avatar
jfv committed
94
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_QSFP_SF_QP, 0, 0, 0},
95
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T, 0, 0, 0},
jfv's avatar
jfv committed
96
97
98
99
100
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KR, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KX4, 0, 0, 0},
	{IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_10G_T, 0, 0, 0},
jfv's avatar
jfv committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
	/* required last entry */
	{0, 0, 0, 0, 0}
};

/*********************************************************************
 *  Table of branding strings
 *********************************************************************/

static char    *ixgbe_strings[] = {
	"Intel(R) PRO/10GbE PCI-Express Network Driver"
};

/*********************************************************************
 *  Function prototypes
 *********************************************************************/
static int      ixgbe_probe(device_t);
static int      ixgbe_attach(device_t);
static int      ixgbe_detach(device_t);
static int      ixgbe_shutdown(device_t);
120
121
static int	ixgbe_suspend(device_t);
static int	ixgbe_resume(device_t);
jfv's avatar
jfv committed
122
static int      ixgbe_ioctl(struct ifnet *, u_long, caddr_t);
123
static void	ixgbe_init(void *);
124
static void	ixgbe_init_locked(struct adapter *);
jfv's avatar
jfv committed
125
static void     ixgbe_stop(void *);
jfv's avatar
jfv committed
126
#if __FreeBSD_version >= 1100036
glebius's avatar
glebius committed
127
static uint64_t	ixgbe_get_counter(struct ifnet *, ift_counter);
jfv's avatar
jfv committed
128
129
#endif
static void	ixgbe_add_media_types(struct adapter *);
jfv's avatar
jfv committed
130
131
132
133
static void     ixgbe_media_status(struct ifnet *, struct ifmediareq *);
static int      ixgbe_media_change(struct ifnet *);
static void     ixgbe_identify_hardware(struct adapter *);
static int      ixgbe_allocate_pci_resources(struct adapter *);
134
static void	ixgbe_get_slot_info(struct ixgbe_hw *);
135
136
137
138
static int      ixgbe_allocate_msix(struct adapter *);
static int      ixgbe_allocate_legacy(struct adapter *);
static int	ixgbe_setup_msix(struct adapter *);
static void	ixgbe_free_pci_resources(struct adapter *);
139
140
static void	ixgbe_local_timer(void *);
static int	ixgbe_setup_interface(device_t, struct adapter *);
141
142
static void	ixgbe_config_dmac(struct adapter *);
static void	ixgbe_config_delay_values(struct adapter *);
143
static void	ixgbe_config_link(struct adapter *);
144
145
146
static void	ixgbe_check_eee_support(struct adapter *);
static void	ixgbe_check_wol_support(struct adapter *);
static int	ixgbe_setup_low_power_mode(struct adapter *);
jfv's avatar
jfv committed
147
static void	ixgbe_rearm_queues(struct adapter *, u64);
148

jfv's avatar
jfv committed
149
150
static void     ixgbe_initialize_transmit_units(struct adapter *);
static void     ixgbe_initialize_receive_units(struct adapter *);
jfv's avatar
jfv committed
151
152
static void	ixgbe_enable_rx_drop(struct adapter *);
static void	ixgbe_disable_rx_drop(struct adapter *);
jfv's avatar
jfv committed
153
154
155
156
157
158
159

static void     ixgbe_enable_intr(struct adapter *);
static void     ixgbe_disable_intr(struct adapter *);
static void     ixgbe_update_stats_counters(struct adapter *);
static void     ixgbe_set_promisc(struct adapter *);
static void     ixgbe_set_multi(struct adapter *);
static void     ixgbe_update_link_status(struct adapter *);
160
static void	ixgbe_set_ivar(struct adapter *, u8, u8, s8);
jfv's avatar
jfv committed
161
static void	ixgbe_configure_ivars(struct adapter *);
162
163
static u8 *	ixgbe_mc_array_itr(struct ixgbe_hw *, u8 **, u32 *);

164
static void	ixgbe_setup_vlan_hw_support(struct adapter *);
165
166
static void	ixgbe_register_vlan(void *, struct ifnet *, u16);
static void	ixgbe_unregister_vlan(void *, struct ifnet *, u16);
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
static void	ixgbe_add_device_sysctls(struct adapter *);
static void     ixgbe_add_hw_stats(struct adapter *);

/* Sysctl handlers */
static int	ixgbe_set_flowcntl(SYSCTL_HANDLER_ARGS);
static int	ixgbe_set_advertise(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_thermal_test(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_dmac(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_phy_temp(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_phy_overtemp_occurred(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_wol_enable(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_wufc(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_eee_enable(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_eee_negotiated(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_eee_rx_lpi_status(SYSCTL_HANDLER_ARGS);
static int	ixgbe_sysctl_eee_tx_lpi_status(SYSCTL_HANDLER_ARGS);
184

jfv's avatar
jfv committed
185
186
/* Support for pluggable optic modules */
static bool	ixgbe_sfp_probe(struct adapter *);
jfv's avatar
jfv committed
187
static void	ixgbe_setup_optics(struct adapter *);
jfv's avatar
jfv committed
188

189
190
/* Legacy (single vector interrupt handler */
static void	ixgbe_legacy_irq(void *);
jfv's avatar
jfv committed
191
192

/* The MSI/X Interrupt handlers */
jfv's avatar
jfv committed
193
static void	ixgbe_msix_que(void *);
194
195
static void	ixgbe_msix_link(void *);

196
/* Deferred interrupt tasklets */
jfv's avatar
jfv committed
197
static void	ixgbe_handle_que(void *, int);
198
199
200
static void	ixgbe_handle_link(void *, int);
static void	ixgbe_handle_msf(void *, int);
static void	ixgbe_handle_mod(void *, int);
201
static void	ixgbe_handle_phy(void *, int);
jfv's avatar
jfv committed
202

jfv's avatar
jfv committed
203
204
205
#ifdef IXGBE_FDIR
static void	ixgbe_reinit_fdir(void *, int);
#endif
jfv's avatar
jfv committed
206
207
208
209
210

/*********************************************************************
 *  FreeBSD Device Interface Entry Points
 *********************************************************************/

211
static device_method_t ix_methods[] = {
jfv's avatar
jfv committed
212
213
214
215
216
	/* Device interface */
	DEVMETHOD(device_probe, ixgbe_probe),
	DEVMETHOD(device_attach, ixgbe_attach),
	DEVMETHOD(device_detach, ixgbe_detach),
	DEVMETHOD(device_shutdown, ixgbe_shutdown),
217
218
	DEVMETHOD(device_suspend, ixgbe_suspend),
	DEVMETHOD(device_resume, ixgbe_resume),
219
	DEVMETHOD_END
jfv's avatar
jfv committed
220
221
};

222
223
static driver_t ix_driver = {
	"ix", ix_methods, sizeof(struct adapter),
jfv's avatar
jfv committed
224
225
};

226
227
devclass_t ix_devclass;
DRIVER_MODULE(ix, pci, ix_driver, ix_devclass, 0, 0);
jfv's avatar
jfv committed
228

229
230
MODULE_DEPEND(ix, pci, 1, 1, 1);
MODULE_DEPEND(ix, ether, 1, 1, 1);
jfv's avatar
jfv committed
231

232
233
234
235
/*
** TUNEABLE PARAMETERS:
*/

hiren's avatar
hiren committed
236
237
238
static SYSCTL_NODE(_hw, OID_AUTO, ix, CTLFLAG_RD, 0,
		   "IXGBE driver parameters");

jfv's avatar
jfv committed
239
/*
jfv's avatar
jfv committed
240
241
242
243
** AIM: Adaptive Interrupt Moderation
** which means that the interrupt rate
** is varied over time based on the
** traffic for that interrupt vector
jfv's avatar
jfv committed
244
245
*/
static int ixgbe_enable_aim = TRUE;
246
SYSCTL_INT(_hw_ix, OID_AUTO, enable_aim, CTLFLAG_RWTUN, &ixgbe_enable_aim, 0,
hiren's avatar
hiren committed
247
    "Enable adaptive interrupt moderation");
jfv's avatar
jfv committed
248

luigi's avatar
luigi committed
249
static int ixgbe_max_interrupt_rate = (4000000 / IXGBE_LOW_LATENCY);
hiren's avatar
hiren committed
250
251
SYSCTL_INT(_hw_ix, OID_AUTO, max_interrupt_rate, CTLFLAG_RDTUN,
    &ixgbe_max_interrupt_rate, 0, "Maximum interrupts per second");
252

jfv's avatar
jfv committed
253
/* How many packets rxeof tries to clean at a time */
254
static int ixgbe_rx_process_limit = 256;
jfv's avatar
jfv committed
255
TUNABLE_INT("hw.ixgbe.rx_process_limit", &ixgbe_rx_process_limit);
hiren's avatar
hiren committed
256
257
258
259
SYSCTL_INT(_hw_ix, OID_AUTO, rx_process_limit, CTLFLAG_RDTUN,
    &ixgbe_rx_process_limit, 0,
    "Maximum number of received packets to process at a time,"
    "-1 means unlimited");
jfv's avatar
jfv committed
260

261
262
/* How many packets txeof tries to clean at a time */
static int ixgbe_tx_process_limit = 256;
jfv's avatar
jfv committed
263
TUNABLE_INT("hw.ixgbe.tx_process_limit", &ixgbe_tx_process_limit);
hiren's avatar
hiren committed
264
265
266
267
SYSCTL_INT(_hw_ix, OID_AUTO, tx_process_limit, CTLFLAG_RDTUN,
    &ixgbe_tx_process_limit, 0,
    "Maximum number of sent packets to process at a time,"
    "-1 means unlimited");
268

jfv's avatar
jfv committed
269
270
271
272
273
274
275
276
277
/*
** Smart speed setting, default to on
** this only works as a compile option
** right now as its during attach, set
** this to 'ixgbe_smart_speed_off' to
** disable.
*/
static int ixgbe_smart_speed = ixgbe_smart_speed_on;

278
279
280
281
282
/*
 * MSIX should be the default for best performance,
 * but this allows it to be forced off for testing.
 */
static int ixgbe_enable_msix = 1;
hiren's avatar
hiren committed
283
284
SYSCTL_INT(_hw_ix, OID_AUTO, enable_msix, CTLFLAG_RDTUN, &ixgbe_enable_msix, 0,
    "Enable MSI-X interrupts");
285

jfv's avatar
jfv committed
286
/*
jfv's avatar
jfv committed
287
288
 * Number of Queues, can be set to 0,
 * it then autoconfigures based on the
289
290
 * number of cpus with a max of 8. This
 * can be overriden manually here.
jfv's avatar
jfv committed
291
 */
292
static int ixgbe_num_queues = 0;
hiren's avatar
hiren committed
293
294
SYSCTL_INT(_hw_ix, OID_AUTO, num_queues, CTLFLAG_RDTUN, &ixgbe_num_queues, 0,
    "Number of queues to configure, 0 indicates autoconfigure");
295

jfv's avatar
jfv committed
296
297
298
299
300
301
/*
** Number of TX descriptors per ring,
** setting higher than RX as this seems
** the better performing choice.
*/
static int ixgbe_txd = PERFORM_TXD;
hiren's avatar
hiren committed
302
SYSCTL_INT(_hw_ix, OID_AUTO, txd, CTLFLAG_RDTUN, &ixgbe_txd, 0,
hiren's avatar
hiren committed
303
    "Number of transmit descriptors per queue");
304
305

/* Number of RX descriptors per ring */
jfv's avatar
jfv committed
306
static int ixgbe_rxd = PERFORM_RXD;
hiren's avatar
hiren committed
307
308
SYSCTL_INT(_hw_ix, OID_AUTO, rxd, CTLFLAG_RDTUN, &ixgbe_rxd, 0,
    "Number of receive descriptors per queue");
309

310
311
312
313
314
315
/*
** Defining this on will allow the use
** of unsupported SFP+ modules, note that
** doing so you are on your own :)
*/
static int allow_unsupported_sfp = FALSE;
316
TUNABLE_INT("hw.ix.unsupported_sfp", &allow_unsupported_sfp);
317

jfv's avatar
jfv committed
318
/* Keep running tab on them for sanity check */
319
320
static int ixgbe_total_ports;

jfv's avatar
jfv committed
321
322
323
324
325
326
327
328
329
330
331
#ifdef IXGBE_FDIR
/* 
** Flow Director actually 'steals'
** part of the packet buffer as its
** filter pool, this variable controls
** how much it uses:
**  0 = 64K, 1 = 128K, 2 = 256K
*/
static int fdir_pballoc = 1;
#endif

332
333
334
335
336
337
#ifdef DEV_NETMAP
/*
 * The #ifdef DEV_NETMAP / #endif blocks in this file are meant to
 * be a reference on how to implement netmap support in a driver.
 * Additional comments are in ixgbe_netmap.h .
 *
luigi's avatar
luigi committed
338
 * <dev/netmap/ixgbe_netmap.h> contains functions for netmap support
339
340
341
342
343
 * that extend the standard driver.
 */
#include <dev/netmap/ixgbe_netmap.h>
#endif /* DEV_NETMAP */

jfv's avatar
jfv committed
344
345
346
347
348
349
/*********************************************************************
 *  Device identification routine
 *
 *  ixgbe_probe determines if the driver should be loaded on
 *  adapter based on PCI vendor/device id of the adapter.
 *
350
 *  return BUS_PROBE_DEFAULT on success, positive on failure
jfv's avatar
jfv committed
351
352
353
354
355
356
357
 *********************************************************************/

static int
ixgbe_probe(device_t dev)
{
	ixgbe_vendor_info_t *ent;

jfv's avatar
jfv committed
358
359
360
361
362
	u16	pci_vendor_id = 0;
	u16	pci_device_id = 0;
	u16	pci_subvendor_id = 0;
	u16	pci_subdevice_id = 0;
	char	adapter_name[256];
jfv's avatar
jfv committed
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

	INIT_DEBUGOUT("ixgbe_probe: begin");

	pci_vendor_id = pci_get_vendor(dev);
	if (pci_vendor_id != IXGBE_INTEL_VENDOR_ID)
		return (ENXIO);

	pci_device_id = pci_get_device(dev);
	pci_subvendor_id = pci_get_subvendor(dev);
	pci_subdevice_id = pci_get_subdevice(dev);

	ent = ixgbe_vendor_info_array;
	while (ent->vendor_id != 0) {
		if ((pci_vendor_id == ent->vendor_id) &&
		    (pci_device_id == ent->device_id) &&

		    ((pci_subvendor_id == ent->subvendor_id) ||
		     (ent->subvendor_id == 0)) &&

		    ((pci_subdevice_id == ent->subdevice_id) ||
		     (ent->subdevice_id == 0))) {
			sprintf(adapter_name, "%s, Version - %s",
				ixgbe_strings[ent->index],
				ixgbe_driver_version);
			device_set_desc_copy(dev, adapter_name);
388
			++ixgbe_total_ports;
389
			return (BUS_PROBE_DEFAULT);
jfv's avatar
jfv committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
		}
		ent++;
	}
	return (ENXIO);
}

/*********************************************************************
 *  Device initialization routine
 *
 *  The attach entry point is called when the driver is being loaded.
 *  This routine identifies the type of hardware, allocates all resources
 *  and initializes the hardware.
 *
 *  return 0 on success, positive on failure
 *********************************************************************/

static int
ixgbe_attach(device_t dev)
{
	struct adapter *adapter;
410
	struct ixgbe_hw *hw;
jfv's avatar
jfv committed
411
	int             error = 0;
jfv's avatar
jfv committed
412
	u16		csum;
jfv's avatar
jfv committed
413
	u32		ctrl_ext;
jfv's avatar
jfv committed
414
415
416
417
418
419

	INIT_DEBUGOUT("ixgbe_attach: begin");

	/* Allocate, clear, and link in our adapter structure */
	adapter = device_get_softc(dev);
	adapter->dev = adapter->osdep.dev = dev;
420
	hw = &adapter->hw;
421
422
423

	/* Core Lock Init*/
	IXGBE_CORE_LOCK_INIT(adapter, device_get_nameunit(dev));
jfv's avatar
jfv committed
424
425

	/* Set up the timer callout */
426
	callout_init_mtx(&adapter->timer, &adapter->core_mtx, 0);
jfv's avatar
jfv committed
427
428
429
430
431
432
433
434
435
436
437

	/* Determine hardware revision */
	ixgbe_identify_hardware(adapter);

	/* Do base PCI setup - map BAR0 */
	if (ixgbe_allocate_pci_resources(adapter)) {
		device_printf(dev, "Allocation of PCI resources failed\n");
		error = ENXIO;
		goto err_out;
	}

438
439
440
441
442
443
444
445
446
447
448
449
450
	/* Do descriptor calc and sanity checks */
	if (((ixgbe_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
	    ixgbe_txd < MIN_TXD || ixgbe_txd > MAX_TXD) {
		device_printf(dev, "TXD config issue, using default!\n");
		adapter->num_tx_desc = DEFAULT_TXD;
	} else
		adapter->num_tx_desc = ixgbe_txd;

	/*
	** With many RX rings it is easy to exceed the
	** system mbuf allocation. Tuning nmbclusters
	** can alleviate this.
	*/
jfv's avatar
jfv committed
451
	if (nmbclusters > 0) {
452
		int s;
453
		s = (ixgbe_rxd * adapter->num_queues) * ixgbe_total_ports;
454
455
456
457
458
459
460
461
		if (s > nmbclusters) {
			device_printf(dev, "RX Descriptors exceed "
			    "system mbuf max, using default instead!\n");
			ixgbe_rxd = DEFAULT_RXD;
		}
	}

	if (((ixgbe_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
462
	    ixgbe_rxd < MIN_RXD || ixgbe_rxd > MAX_RXD) {
463
464
465
466
467
		device_printf(dev, "RXD config issue, using default!\n");
		adapter->num_rx_desc = DEFAULT_RXD;
	} else
		adapter->num_rx_desc = ixgbe_rxd;

jfv's avatar
jfv committed
468
469
470
471
472
473
	/* Allocate our TX/RX Queues */
	if (ixgbe_allocate_queues(adapter)) {
		error = ENOMEM;
		goto err_out;
	}

474
475
476
477
478
479
480
481
482
	/* Allocate multicast array memory. */
	adapter->mta = malloc(sizeof(u8) * IXGBE_ETH_LENGTH_OF_ADDRESS *
	    MAX_NUM_MULTICAST_ADDRESSES, M_DEVBUF, M_NOWAIT);
	if (adapter->mta == NULL) {
		device_printf(dev, "Can not allocate multicast setup array\n");
		error = ENOMEM;
		goto err_late;
	}

jfv's avatar
jfv committed
483
	/* Initialize the shared code */
484
	hw->allow_unsupported_sfp = allow_unsupported_sfp;
485
	error = ixgbe_init_shared_code(hw);
jfv's avatar
jfv committed
486
487
488
489
490
491
492
493
494
495
496
497
498
	if (error == IXGBE_ERR_SFP_NOT_PRESENT) {
		/*
		** No optics in this port, set up
		** so the timer routine will probe 
		** for later insertion.
		*/
		adapter->sfp_probe = TRUE;
		error = 0;
	} else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) {
		device_printf(dev,"Unsupported SFP+ module detected!\n");
		error = EIO;
		goto err_late;
	} else if (error) {
jfv's avatar
jfv committed
499
500
		device_printf(dev,"Unable to initialize the shared code\n");
		error = EIO;
501
		goto err_late;
jfv's avatar
jfv committed
502
503
	}

jfv's avatar
jfv committed
504
505
506
	/* Make sure we have a good EEPROM before we read from it */
	if (ixgbe_validate_eeprom_checksum(&adapter->hw, &csum) < 0) {
		device_printf(dev,"The EEPROM Checksum Is Not Valid\n");
jfv's avatar
jfv committed
507
		error = EIO;
508
		goto err_late;
jfv's avatar
jfv committed
509
510
	}

jfv's avatar
jfv committed
511
	error = ixgbe_init_hw(hw);
jfv's avatar
jfv committed
512
513
	switch (error) {
	case IXGBE_ERR_EEPROM_VERSION:
jfv's avatar
jfv committed
514
515
516
517
518
		device_printf(dev, "This device is a pre-production adapter/"
		    "LOM.  Please be aware there may be issues associated "
		    "with your hardware.\n If you are experiencing problems "
		    "please contact your Intel or hardware representative "
		    "who provided you with this hardware.\n");
jfv's avatar
jfv committed
519
520
		break;
	case IXGBE_ERR_SFP_NOT_SUPPORTED:
jfv's avatar
jfv committed
521
522
523
		device_printf(dev,"Unsupported SFP+ Module\n");
		error = EIO;
		goto err_late;
jfv's avatar
jfv committed
524
525
526
527
528
	case IXGBE_ERR_SFP_NOT_PRESENT:
		device_printf(dev,"No SFP+ Module found\n");
		/* falls thru */
	default:
		break;
jfv's avatar
jfv committed
529
530
	}

jfv's avatar
jfv committed
531
532
533
	/* Detect and set physical type */
	ixgbe_setup_optics(adapter);

534
535
536
537
538
539
540
	if ((adapter->msix > 1) && (ixgbe_enable_msix))
		error = ixgbe_allocate_msix(adapter); 
	else
		error = ixgbe_allocate_legacy(adapter); 
	if (error) 
		goto err_late;

jfv's avatar
jfv committed
541
	/* Setup OS specific network interface */
542
543
	if (ixgbe_setup_interface(dev, adapter) != 0)
		goto err_late;
jfv's avatar
jfv committed
544
545
546
547

	/* Initialize statistics */
	ixgbe_update_stats_counters(adapter);

548
549
	/* Register for VLAN events */
	adapter->vlan_attach = EVENTHANDLER_REGISTER(vlan_config,
550
	    ixgbe_register_vlan, adapter, EVENTHANDLER_PRI_FIRST);
551
	adapter->vlan_detach = EVENTHANDLER_REGISTER(vlan_unconfig,
552
	    ixgbe_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
553

554
        /* Check PCIE slot type/speed/width */
555
	ixgbe_get_slot_info(hw);
jfv's avatar
jfv committed
556

jfv's avatar
jfv committed
557

558
	/* Set an initial default flow control value */
jfv's avatar
jfv committed
559
	adapter->fc = ixgbe_fc_full;
560

561
562
563
564
565
566
567
568
	/* Check for certain supported features */
	ixgbe_check_wol_support(adapter);
	ixgbe_check_eee_support(adapter);

	/* Add sysctls */
	ixgbe_add_device_sysctls(adapter);
	ixgbe_add_hw_stats(adapter);

jfv's avatar
jfv committed
569
	/* let hardware know driver is loaded */
570
	ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
jfv's avatar
jfv committed
571
	ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
572
	IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
jfv's avatar
jfv committed
573

574
575
576
#ifdef DEV_NETMAP
	ixgbe_netmap_attach(adapter);
#endif /* DEV_NETMAP */
jfv's avatar
jfv committed
577
578
	INIT_DEBUGOUT("ixgbe_attach: end");
	return (0);
jfv's avatar
jfv committed
579

580
581
582
err_late:
	ixgbe_free_transmit_structures(adapter);
	ixgbe_free_receive_structures(adapter);
jfv's avatar
jfv committed
583
err_out:
584
585
	if (adapter->ifp != NULL)
		if_free(adapter->ifp);
jfv's avatar
jfv committed
586
	ixgbe_free_pci_resources(adapter);
587
	free(adapter->mta, M_DEVBUF);
jfv's avatar
jfv committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
	return (error);
}

/*********************************************************************
 *  Device removal routine
 *
 *  The detach entry point is called when the driver is being removed.
 *  This routine stops the adapter and deallocates all the resources
 *  that were allocated for driver operation.
 *
 *  return 0 on success, positive on failure
 *********************************************************************/

static int
ixgbe_detach(device_t dev)
{
	struct adapter *adapter = device_get_softc(dev);
jfv's avatar
jfv committed
605
	struct ix_queue *que = adapter->queues;
606
	struct tx_ring *txr = adapter->tx_rings;
jfv's avatar
jfv committed
607
608
609
610
611
612
613
614
615
616
	u32	ctrl_ext;

	INIT_DEBUGOUT("ixgbe_detach: begin");

	/* Make sure VLANS are not using driver */
	if (adapter->ifp->if_vlantrunk != NULL) {
		device_printf(dev,"Vlan in use, detach first\n");
		return (EBUSY);
	}

617
	/* Stop the adapter */
618
	IXGBE_CORE_LOCK(adapter);
619
	ixgbe_setup_low_power_mode(adapter);
620
	IXGBE_CORE_UNLOCK(adapter);
621

622
	for (int i = 0; i < adapter->num_queues; i++, que++, txr++) {
jfv's avatar
jfv committed
623
		if (que->tq) {
624
#ifndef IXGBE_LEGACY_TX
625
626
			taskqueue_drain(que->tq, &txr->txq_task);
#endif
jfv's avatar
jfv committed
627
628
			taskqueue_drain(que->tq, &que->que_task);
			taskqueue_free(que->tq);
629
		}
630
	}
631

632
633
634
635
636
	/* Drain the Link queue */
	if (adapter->tq) {
		taskqueue_drain(adapter->tq, &adapter->link_task);
		taskqueue_drain(adapter->tq, &adapter->mod_task);
		taskqueue_drain(adapter->tq, &adapter->msf_task);
637
		taskqueue_drain(adapter->tq, &adapter->phy_task);
jfv's avatar
jfv committed
638
639
640
#ifdef IXGBE_FDIR
		taskqueue_drain(adapter->tq, &adapter->fdir_task);
#endif
641
642
643
		taskqueue_free(adapter->tq);
	}

jfv's avatar
jfv committed
644
645
646
647
648
	/* let hardware know driver is unloading */
	ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
	ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD;
	IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, ctrl_ext);

649
650
651
652
653
	/* Unregister VLAN events */
	if (adapter->vlan_attach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_config, adapter->vlan_attach);
	if (adapter->vlan_detach != NULL)
		EVENTHANDLER_DEREGISTER(vlan_unconfig, adapter->vlan_detach);
jfv's avatar
jfv committed
654
655
656

	ether_ifdetach(adapter->ifp);
	callout_drain(&adapter->timer);
657
658
659
#ifdef DEV_NETMAP
	netmap_detach(adapter->ifp);
#endif /* DEV_NETMAP */
jfv's avatar
jfv committed
660
661
662
663
664
665
	ixgbe_free_pci_resources(adapter);
	bus_generic_detach(dev);
	if_free(adapter->ifp);

	ixgbe_free_transmit_structures(adapter);
	ixgbe_free_receive_structures(adapter);
666
	free(adapter->mta, M_DEVBUF);
jfv's avatar
jfv committed
667

668
	IXGBE_CORE_LOCK_DESTROY(adapter);
jfv's avatar
jfv committed
669
670
671
672
673
674
675
676
677
678
679
680
681
	return (0);
}

/*********************************************************************
 *
 *  Shutdown entry point
 *
 **********************************************************************/

static int
ixgbe_shutdown(device_t dev)
{
	struct adapter *adapter = device_get_softc(dev);
682
683
684
685
	int error = 0;

	INIT_DEBUGOUT("ixgbe_shutdown: begin");

686
	IXGBE_CORE_LOCK(adapter);
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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
	error = ixgbe_setup_low_power_mode(adapter);
	IXGBE_CORE_UNLOCK(adapter);

	return (error);
}

/**
 * Methods for going from:
 * D0 -> D3: ixgbe_suspend
 * D3 -> D0: ixgbe_resume
 */
static int
ixgbe_suspend(device_t dev)
{
	struct adapter *adapter = device_get_softc(dev);
	int error = 0;

	INIT_DEBUGOUT("ixgbe_suspend: begin");

	IXGBE_CORE_LOCK(adapter);

	error = ixgbe_setup_low_power_mode(adapter);

	/* Save state and power down */
	pci_save_state(dev);
	pci_set_powerstate(dev, PCI_POWERSTATE_D3);

	IXGBE_CORE_UNLOCK(adapter);

	return (error);
}

static int
ixgbe_resume(device_t dev)
{
	struct adapter *adapter = device_get_softc(dev);
	struct ifnet *ifp = adapter->ifp;
	struct ixgbe_hw *hw = &adapter->hw;
	u32 wus;

	INIT_DEBUGOUT("ixgbe_resume: begin");

	IXGBE_CORE_LOCK(adapter);

	pci_set_powerstate(dev, PCI_POWERSTATE_D0);
	pci_restore_state(dev);

	/* Read & clear WUS register */
	wus = IXGBE_READ_REG(hw, IXGBE_WUS);
	if (wus)
		device_printf(dev, "Woken up by (WUS): %#010x\n",
		    IXGBE_READ_REG(hw, IXGBE_WUS));
	IXGBE_WRITE_REG(hw, IXGBE_WUS, 0xffffffff);
	/* And clear WUFC until next low-power transition */
	IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);

	/*
	 * Required after D3->D0 transition;
	 * will re-advertise all previous advertised speeds
	 */
	if (ifp->if_flags & IFF_UP)
		ixgbe_init_locked(adapter);

750
	IXGBE_CORE_UNLOCK(adapter);
751
752

	INIT_DEBUGOUT("ixgbe_resume: end");
jfv's avatar
jfv committed
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
	return (0);
}


/*********************************************************************
 *  Ioctl entry point
 *
 *  ixgbe_ioctl is called when the user wants to configure the
 *  interface.
 *
 *  return 0 on success, positive on failure
 **********************************************************************/

static int
ixgbe_ioctl(struct ifnet * ifp, u_long command, caddr_t data)
{
jfv's avatar
jfv committed
769
770
	struct adapter	*adapter = ifp->if_softc;
	struct ifreq	*ifr = (struct ifreq *) data;
771
#if defined(INET) || defined(INET6)
772
	struct ifaddr *ifa = (struct ifaddr *)data;
773
	bool		avoid_reset = FALSE;
774
#endif
775
	int             error = 0;
jfv's avatar
jfv committed
776
777

	switch (command) {
jfv's avatar
jfv committed
778

779
780
        case SIOCSIFADDR:
#ifdef INET
781
782
783
784
785
786
787
788
789
790
791
792
793
		if (ifa->ifa_addr->sa_family == AF_INET)
			avoid_reset = TRUE;
#endif
#ifdef INET6
		if (ifa->ifa_addr->sa_family == AF_INET6)
			avoid_reset = TRUE;
#endif
#if defined(INET) || defined(INET6)
		/*
		** Calling init results in link renegotiation,
		** so we avoid doing it when possible.
		*/
		if (avoid_reset) {
794
			ifp->if_flags |= IFF_UP;
795
796
			if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
				ixgbe_init(adapter);
797
798
799
800
			if (!(ifp->if_flags & IFF_NOARP))
				arp_ifinit(ifp, ifa);
		} else
			error = ether_ioctl(ifp, command, data);
801
#endif
802
		break;
jfv's avatar
jfv committed
803
804
	case SIOCSIFMTU:
		IOCTL_DEBUGOUT("ioctl: SIOCSIFMTU (Set Interface MTU)");
805
		if (ifr->ifr_mtu > IXGBE_MAX_MTU) {
jfv's avatar
jfv committed
806
807
			error = EINVAL;
		} else {
808
			IXGBE_CORE_LOCK(adapter);
jfv's avatar
jfv committed
809
810
			ifp->if_mtu = ifr->ifr_mtu;
			adapter->max_frame_size =
811
				ifp->if_mtu + IXGBE_MTU_HDR;
812
			ixgbe_init_locked(adapter);
813
			IXGBE_CORE_UNLOCK(adapter);
jfv's avatar
jfv committed
814
815
816
817
		}
		break;
	case SIOCSIFFLAGS:
		IOCTL_DEBUGOUT("ioctl: SIOCSIFFLAGS (Set Interface Flags)");
818
		IXGBE_CORE_LOCK(adapter);
jfv's avatar
jfv committed
819
		if (ifp->if_flags & IFF_UP) {
820
			if ((ifp->if_drv_flags & IFF_DRV_RUNNING)) {
jfv's avatar
jfv committed
821
				if ((ifp->if_flags ^ adapter->if_flags) &
822
				    (IFF_PROMISC | IFF_ALLMULTI)) {
jfv's avatar
jfv committed
823
824
825
					ixgbe_set_promisc(adapter);
                                }
			} else
826
				ixgbe_init_locked(adapter);
jfv's avatar
jfv committed
827
828
829
830
		} else
			if (ifp->if_drv_flags & IFF_DRV_RUNNING)
				ixgbe_stop(adapter);
		adapter->if_flags = ifp->if_flags;
831
		IXGBE_CORE_UNLOCK(adapter);
jfv's avatar
jfv committed
832
833
834
835
836
		break;
	case SIOCADDMULTI:
	case SIOCDELMULTI:
		IOCTL_DEBUGOUT("ioctl: SIOC(ADD|DEL)MULTI");
		if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
837
			IXGBE_CORE_LOCK(adapter);
jfv's avatar
jfv committed
838
839
840
			ixgbe_disable_intr(adapter);
			ixgbe_set_multi(adapter);
			ixgbe_enable_intr(adapter);
841
			IXGBE_CORE_UNLOCK(adapter);
jfv's avatar
jfv committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
		}
		break;
	case SIOCSIFMEDIA:
	case SIOCGIFMEDIA:
		IOCTL_DEBUGOUT("ioctl: SIOCxIFMEDIA (Get/Set Interface Media)");
		error = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
		break;
	case SIOCSIFCAP:
	{
		int mask = ifr->ifr_reqcap ^ ifp->if_capenable;
		IOCTL_DEBUGOUT("ioctl: SIOCSIFCAP (Set Capabilities)");
		if (mask & IFCAP_HWCSUM)
			ifp->if_capenable ^= IFCAP_HWCSUM;
		if (mask & IFCAP_TSO4)
			ifp->if_capenable ^= IFCAP_TSO4;
bz's avatar
bz committed
857
858
		if (mask & IFCAP_TSO6)
			ifp->if_capenable ^= IFCAP_TSO6;
jfv's avatar
jfv committed
859
		if (mask & IFCAP_LRO)
860
			ifp->if_capenable ^= IFCAP_LRO;
jfv's avatar
jfv committed
861
862
		if (mask & IFCAP_VLAN_HWTAGGING)
			ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
jfv's avatar
jfv committed
863
864
		if (mask & IFCAP_VLAN_HWFILTER)
			ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
865
866
		if (mask & IFCAP_VLAN_HWTSO)
			ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
867
868
		if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
			IXGBE_CORE_LOCK(adapter);
869
			ixgbe_init_locked(adapter);
870
871
			IXGBE_CORE_UNLOCK(adapter);
		}
jfv's avatar
jfv committed
872
873
874
		VLAN_CAPABILITIES(ifp);
		break;
	}
jfv's avatar
jfv committed
875
#if __FreeBSD_version >= 1100036
876
877
	case SIOCGI2C:
	{
jfv's avatar
jfv committed
878
		struct ixgbe_hw *hw = &adapter->hw;
879
880
		struct ifi2creq i2c;
		int i;
881
882
		IOCTL_DEBUGOUT("ioctl: SIOCGI2C (Get I2C Data)");
		error = copyin(ifr->ifr_data, &i2c, sizeof(i2c));
883
		if (error != 0)
884
			break;
885
		if (i2c.dev_addr != 0xA0 && i2c.dev_addr != 0xA2) {
886
887
888
			error = EINVAL;
			break;
		}
889
890
891
892
893
894
895
896
		if (i2c.len > sizeof(i2c.data)) {
			error = EINVAL;
			break;
		}

		for (i = 0; i < i2c.len; i++)
			hw->phy.ops.read_i2c_byte(hw, i2c.offset + i,
			    i2c.dev_addr, &i2c.data[i]);
897
898
899
		error = copyout(&i2c, ifr->ifr_data, sizeof(i2c));
		break;
	}
jfv's avatar
jfv committed
900
#endif
jfv's avatar
jfv committed
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
	default:
		IOCTL_DEBUGOUT1("ioctl: UNKNOWN (0x%X)\n", (int)command);
		error = ether_ioctl(ifp, command, data);
		break;
	}

	return (error);
}

/*********************************************************************
 *  Init entry point
 *
 *  This routine is used in two ways. It is used by the stack as
 *  init entry point in network interface structure. It is also used
 *  by the driver as a hw/sw initialization routine to get to a
 *  consistent state.
 *
 *  return 0 on success, positive on failure
 **********************************************************************/
#define IXGBE_MHADD_MFS_SHIFT 16

922
static void
jfv's avatar
jfv committed
923
924
925
926
ixgbe_init_locked(struct adapter *adapter)
{
	struct ifnet   *ifp = adapter->ifp;
	device_t 	dev = adapter->dev;
jfv's avatar
jfv committed
927
	struct ixgbe_hw *hw = &adapter->hw;
jfv's avatar
jfv committed
928
929
	u32		k, txdctl, mhadd, gpie;
	u32		rxdctl, rxctrl;
jfv's avatar
jfv committed
930

jfv's avatar
jfv committed
931
	mtx_assert(&adapter->core_mtx, MA_OWNED);
jfv's avatar
jfv committed
932
	INIT_DEBUGOUT("ixgbe_init_locked: begin");
jfv's avatar
jfv committed
933
934
935
	hw->adapter_stopped = FALSE;
	ixgbe_stop_adapter(hw);
        callout_stop(&adapter->timer);
jfv's avatar
jfv committed
936

jfv's avatar
jfv committed
937
938
        /* reprogram the RAR[0] in case user changed it. */
        ixgbe_set_rar(hw, 0, adapter->hw.mac.addr, 0, IXGBE_RAH_AV);
jfv's avatar
jfv committed
939
940

	/* Get the latest mac address, User can use a LAA */
jfv's avatar
jfv committed
941
	bcopy(IF_LLADDR(adapter->ifp), hw->mac.addr,
jfv's avatar
jfv committed
942
	      IXGBE_ETH_LENGTH_OF_ADDRESS);
jfv's avatar
jfv committed
943
944
	ixgbe_set_rar(hw, 0, hw->mac.addr, 0, 1);
	hw->addr_ctrl.rar_used_count = 1;
jfv's avatar
jfv committed
945

jfv's avatar
jfv committed
946
947
	/* Set the various hardware offload abilities */
	ifp->if_hwassist = 0;
bz's avatar
bz committed
948
	if (ifp->if_capenable & IFCAP_TSO)
jfv's avatar
jfv committed
949
950
951
952
		ifp->if_hwassist |= CSUM_TSO;
	if (ifp->if_capenable & IFCAP_TXCSUM) {
		ifp->if_hwassist |= (CSUM_TCP | CSUM_UDP);
#if __FreeBSD_version >= 800000
953
		if (hw->mac.type != ixgbe_mac_82598EB)
jfv's avatar
jfv committed
954
955
956
957
			ifp->if_hwassist |= CSUM_SCTP;
#endif
	}

jfv's avatar
jfv committed
958
959
	/* Prepare transmit descriptors and buffers */
	if (ixgbe_setup_transmit_structures(adapter)) {
960
		device_printf(dev, "Could not setup transmit structures\n");
jfv's avatar
jfv committed
961
		ixgbe_stop(adapter);
962
		return;
jfv's avatar
jfv committed
963
964
	}

jfv's avatar
jfv committed
965
	ixgbe_init_hw(hw);
jfv's avatar
jfv committed
966
967
968
969
970
971
	ixgbe_initialize_transmit_units(adapter);

	/* Setup Multicast table */
	ixgbe_set_multi(adapter);

	/*
jfv's avatar
jfv committed
972
	** Determine the correct mbuf pool
973
	** for doing jumbo frames
jfv's avatar
jfv committed
974
	*/
jfv's avatar
jfv committed
975
976
977
	if (adapter->max_frame_size <= 2048)
		adapter->rx_mbuf_sz = MCLBYTES;
	else if (adapter->max_frame_size <= 4096)
jfv's avatar
jfv committed
978
		adapter->rx_mbuf_sz = MJUMPAGESIZE;
jfv's avatar
jfv committed
979
	else if (adapter->max_frame_size <= 9216)
jfv's avatar
jfv committed
980
		adapter->rx_mbuf_sz = MJUM9BYTES;
jfv's avatar
jfv committed
981
982
	else
		adapter->rx_mbuf_sz = MJUM16BYTES;
jfv's avatar
jfv committed
983
984
985

	/* Prepare receive descriptors and buffers */
	if (ixgbe_setup_receive_structures(adapter)) {
986
		device_printf(dev, "Could not setup receive structures\n");
jfv's avatar
jfv committed
987
		ixgbe_stop(adapter);
988
		return;
jfv's avatar
jfv committed
989
990
991
992
993
	}

	/* Configure RX settings */
	ixgbe_initialize_receive_units(adapter);

994
	gpie = IXGBE_READ_REG(&adapter->hw, IXGBE_GPIE);
jfv's avatar
jfv committed
995

996
	/* Enable Fan Failure Interrupt */
jfv's avatar
jfv committed
997
	gpie |= IXGBE_SDP1_GPIEN_BY_MAC(hw);
998

999
	/* Add for Module detection */
1000
	if (hw->mac.type == ixgbe_mac_82599EB)
For faster browsing, not all history is shown. View entire blame