e1000_main.c 134 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
2
/*******************************************************************************

3
4
5
6
7
8
9
10
11
12
  Intel PRO/1000 Linux driver
  Copyright(c) 1999 - 2006 Intel Corporation.

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope 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
Linus Torvalds's avatar
Linus Torvalds committed
13
  more details.
14

Linus Torvalds's avatar
Linus Torvalds committed
15
  You should have received a copy of the GNU General Public License along with
16
17
18
19
20
21
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

Linus Torvalds's avatar
Linus Torvalds committed
22
23
  Contact Information:
  Linux NICS <linux.nics@intel.com>
24
  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds's avatar
Linus Torvalds committed
25
26
27
28
29
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497

*******************************************************************************/

#include "e1000.h"
Andrew Morton's avatar
Andrew Morton committed
30
#include <net/ip6_checksum.h>
31
32
33
34
35
36
#include <linux/io.h>

/* Intel Media SOC GbE MDIO physical base address */
static unsigned long ce4100_gbe_mdio_base_phy;
/* Intel Media SOC GbE MDIO virtual base address */
void __iomem *ce4100_gbe_mdio_base_virt;
Linus Torvalds's avatar
Linus Torvalds committed
37
38

char e1000_driver_name[] = "e1000";
39
static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Anupam Chanda's avatar
Anupam Chanda committed
40
#define DRV_VERSION "7.3.21-k8-NAPI"
41
42
const char e1000_driver_version[] = DRV_VERSION;
static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds's avatar
Linus Torvalds committed
43
44
45
46
47
48
49
50

/* e1000_pci_tbl - PCI Device ID Table
 *
 * Last entry must be all 0s
 *
 * Macro expands to...
 *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
 */
51
static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
Linus Torvalds's avatar
Linus Torvalds committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	INTEL_E1000_ETHERNET_DEVICE(0x1000),
	INTEL_E1000_ETHERNET_DEVICE(0x1001),
	INTEL_E1000_ETHERNET_DEVICE(0x1004),
	INTEL_E1000_ETHERNET_DEVICE(0x1008),
	INTEL_E1000_ETHERNET_DEVICE(0x1009),
	INTEL_E1000_ETHERNET_DEVICE(0x100C),
	INTEL_E1000_ETHERNET_DEVICE(0x100D),
	INTEL_E1000_ETHERNET_DEVICE(0x100E),
	INTEL_E1000_ETHERNET_DEVICE(0x100F),
	INTEL_E1000_ETHERNET_DEVICE(0x1010),
	INTEL_E1000_ETHERNET_DEVICE(0x1011),
	INTEL_E1000_ETHERNET_DEVICE(0x1012),
	INTEL_E1000_ETHERNET_DEVICE(0x1013),
	INTEL_E1000_ETHERNET_DEVICE(0x1014),
	INTEL_E1000_ETHERNET_DEVICE(0x1015),
	INTEL_E1000_ETHERNET_DEVICE(0x1016),
	INTEL_E1000_ETHERNET_DEVICE(0x1017),
	INTEL_E1000_ETHERNET_DEVICE(0x1018),
	INTEL_E1000_ETHERNET_DEVICE(0x1019),
71
	INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds's avatar
Linus Torvalds committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	INTEL_E1000_ETHERNET_DEVICE(0x101D),
	INTEL_E1000_ETHERNET_DEVICE(0x101E),
	INTEL_E1000_ETHERNET_DEVICE(0x1026),
	INTEL_E1000_ETHERNET_DEVICE(0x1027),
	INTEL_E1000_ETHERNET_DEVICE(0x1028),
	INTEL_E1000_ETHERNET_DEVICE(0x1075),
	INTEL_E1000_ETHERNET_DEVICE(0x1076),
	INTEL_E1000_ETHERNET_DEVICE(0x1077),
	INTEL_E1000_ETHERNET_DEVICE(0x1078),
	INTEL_E1000_ETHERNET_DEVICE(0x1079),
	INTEL_E1000_ETHERNET_DEVICE(0x107A),
	INTEL_E1000_ETHERNET_DEVICE(0x107B),
	INTEL_E1000_ETHERNET_DEVICE(0x107C),
	INTEL_E1000_ETHERNET_DEVICE(0x108A),
86
87
	INTEL_E1000_ETHERNET_DEVICE(0x1099),
	INTEL_E1000_ETHERNET_DEVICE(0x10B5),
88
	INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
Linus Torvalds's avatar
Linus Torvalds committed
89
90
91
92
93
94
	/* required last entry */
	{0,}
};

MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);

95
96
97
98
int e1000_up(struct e1000_adapter *adapter);
void e1000_down(struct e1000_adapter *adapter);
void e1000_reinit_locked(struct e1000_adapter *adapter);
void e1000_reset(struct e1000_adapter *adapter);
99
int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
100
101
102
103
int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
104
static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
105
                             struct e1000_tx_ring *txdr);
106
static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
107
                             struct e1000_rx_ring *rxdr);
108
static void e1000_free_tx_resources(struct e1000_adapter *adapter,
109
                             struct e1000_tx_ring *tx_ring);
110
static void e1000_free_rx_resources(struct e1000_adapter *adapter,
111
112
                             struct e1000_rx_ring *rx_ring);
void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds's avatar
Linus Torvalds committed
113
114
115
116
117

static int e1000_init_module(void);
static void e1000_exit_module(void);
static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
static void __devexit e1000_remove(struct pci_dev *pdev);
118
static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds's avatar
Linus Torvalds committed
119
120
121
122
123
124
static int e1000_sw_init(struct e1000_adapter *adapter);
static int e1000_open(struct net_device *netdev);
static int e1000_close(struct net_device *netdev);
static void e1000_configure_tx(struct e1000_adapter *adapter);
static void e1000_configure_rx(struct e1000_adapter *adapter);
static void e1000_setup_rctl(struct e1000_adapter *adapter);
125
126
127
128
129
130
static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
                                struct e1000_tx_ring *tx_ring);
static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
                                struct e1000_rx_ring *rx_ring);
131
static void e1000_set_rx_mode(struct net_device *netdev);
Linus Torvalds's avatar
Linus Torvalds committed
132
static void e1000_update_phy_info(unsigned long data);
Jesse Brandeburg's avatar
Jesse Brandeburg committed
133
static void e1000_update_phy_info_task(struct work_struct *work);
Linus Torvalds's avatar
Linus Torvalds committed
134
135
static void e1000_watchdog(unsigned long data);
static void e1000_82547_tx_fifo_stall(unsigned long data);
Jesse Brandeburg's avatar
Jesse Brandeburg committed
136
static void e1000_82547_tx_fifo_stall_task(struct work_struct *work);
137
138
static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
				    struct net_device *netdev);
Linus Torvalds's avatar
Linus Torvalds committed
139
140
141
static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
static int e1000_set_mac(struct net_device *netdev, void *p);
142
static irqreturn_t e1000_intr(int irq, void *data);
Joe Perches's avatar
Joe Perches committed
143
144
static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
			       struct e1000_tx_ring *tx_ring);
145
static int e1000_clean(struct napi_struct *napi, int budget);
Joe Perches's avatar
Joe Perches committed
146
147
148
static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
			       struct e1000_rx_ring *rx_ring,
			       int *work_done, int work_to_do);
149
150
151
static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
				     struct e1000_rx_ring *rx_ring,
				     int *work_done, int work_to_do);
152
static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
153
				   struct e1000_rx_ring *rx_ring,
154
				   int cleaned_count);
155
156
157
static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
					 struct e1000_rx_ring *rx_ring,
					 int cleaned_count);
Linus Torvalds's avatar
Linus Torvalds committed
158
159
160
161
162
163
static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
			   int cmd);
static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
static void e1000_tx_timeout(struct net_device *dev);
164
static void e1000_reset_task(struct work_struct *work);
Linus Torvalds's avatar
Linus Torvalds committed
165
static void e1000_smartspeed(struct e1000_adapter *adapter);
166
167
static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
                                       struct sk_buff *skb);
Linus Torvalds's avatar
Linus Torvalds committed
168
169

static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
170
171
static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
Linus Torvalds's avatar
Linus Torvalds committed
172
173
static void e1000_restore_vlan(struct e1000_adapter *adapter);

Auke Kok's avatar
Auke Kok committed
174
#ifdef CONFIG_PM
175
static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds's avatar
Linus Torvalds committed
176
177
static int e1000_resume(struct pci_dev *pdev);
#endif
178
static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds's avatar
Linus Torvalds committed
179
180
181
182
183
184

#ifdef CONFIG_NET_POLL_CONTROLLER
/* for netdump / net console */
static void e1000_netpoll (struct net_device *netdev);
#endif

185
186
187
188
189
190
#define COPYBREAK_DEFAULT 256
static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
module_param(copybreak, uint, 0644);
MODULE_PARM_DESC(copybreak,
	"Maximum size of packet that is copied to a new buffer on receive");

Auke Kok's avatar
Auke Kok committed
191
192
193
194
195
196
197
198
199
200
static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
                     pci_channel_state_t state);
static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
static void e1000_io_resume(struct pci_dev *pdev);

static struct pci_error_handlers e1000_err_handler = {
	.error_detected = e1000_io_error_detected,
	.slot_reset = e1000_io_slot_reset,
	.resume = e1000_io_resume,
};
201

Linus Torvalds's avatar
Linus Torvalds committed
202
203
204
205
206
static struct pci_driver e1000_driver = {
	.name     = e1000_driver_name,
	.id_table = e1000_pci_tbl,
	.probe    = e1000_probe,
	.remove   = __devexit_p(e1000_remove),
207
#ifdef CONFIG_PM
Linus Torvalds's avatar
Linus Torvalds committed
208
209
	/* Power Managment Hooks */
	.suspend  = e1000_suspend,
210
	.resume   = e1000_resume,
Linus Torvalds's avatar
Linus Torvalds committed
211
#endif
Auke Kok's avatar
Auke Kok committed
212
213
	.shutdown = e1000_shutdown,
	.err_handler = &e1000_err_handler
Linus Torvalds's avatar
Linus Torvalds committed
214
215
216
217
218
219
220
221
222
223
224
};

MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION(DRV_VERSION);

static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
module_param(debug, int, 0);
MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");

225
226
227
228
229
230
231
232
233
234
235
/**
 * e1000_get_hw_dev - return device
 * used by hardware layer to print debugging information
 *
 **/
struct net_device *e1000_get_hw_dev(struct e1000_hw *hw)
{
	struct e1000_adapter *adapter = hw->back;
	return adapter->netdev;
}

Linus Torvalds's avatar
Linus Torvalds committed
236
237
238
239
240
241
242
/**
 * e1000_init_module - Driver Registration Routine
 *
 * e1000_init_module is the first routine called when the driver is
 * loaded. All it does is register with the PCI subsystem.
 **/

243
static int __init e1000_init_module(void)
Linus Torvalds's avatar
Linus Torvalds committed
244
245
{
	int ret;
246
	pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version);
Linus Torvalds's avatar
Linus Torvalds committed
247

248
	pr_info("%s\n", e1000_copyright);
Linus Torvalds's avatar
Linus Torvalds committed
249

250
	ret = pci_register_driver(&e1000_driver);
251
252
	if (copybreak != COPYBREAK_DEFAULT) {
		if (copybreak == 0)
253
			pr_info("copybreak disabled\n");
254
		else
255
256
			pr_info("copybreak enabled for "
				   "packets <= %u bytes\n", copybreak);
257
	}
Linus Torvalds's avatar
Linus Torvalds committed
258
259
260
261
262
263
264
265
266
267
268
269
	return ret;
}

module_init(e1000_init_module);

/**
 * e1000_exit_module - Driver Exit Cleanup Routine
 *
 * e1000_exit_module is called just before the driver is removed
 * from memory.
 **/

270
static void __exit e1000_exit_module(void)
Linus Torvalds's avatar
Linus Torvalds committed
271
272
273
274
275
276
{
	pci_unregister_driver(&e1000_driver);
}

module_exit(e1000_exit_module);

277
278
279
static int e1000_request_irq(struct e1000_adapter *adapter)
{
	struct net_device *netdev = adapter->netdev;
Al Viro's avatar
Al Viro committed
280
	irq_handler_t handler = e1000_intr;
281
282
	int irq_flags = IRQF_SHARED;
	int err;
283

284
285
286
	err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
	                  netdev);
	if (err) {
287
		e_err(probe, "Unable to allocate interrupt Error: %d\n", err);
288
	}
289
290
291
292
293
294
295
296
297
298
299

	return err;
}

static void e1000_free_irq(struct e1000_adapter *adapter)
{
	struct net_device *netdev = adapter->netdev;

	free_irq(adapter->pdev->irq, netdev);
}

Linus Torvalds's avatar
Linus Torvalds committed
300
301
302
303
304
/**
 * e1000_irq_disable - Mask off interrupt generation on the NIC
 * @adapter: board private structure
 **/

305
static void e1000_irq_disable(struct e1000_adapter *adapter)
Linus Torvalds's avatar
Linus Torvalds committed
306
{
Joe Perches's avatar
Joe Perches committed
307
308
309
310
	struct e1000_hw *hw = &adapter->hw;

	ew32(IMC, ~0);
	E1000_WRITE_FLUSH();
Linus Torvalds's avatar
Linus Torvalds committed
311
312
313
314
315
316
317
318
	synchronize_irq(adapter->pdev->irq);
}

/**
 * e1000_irq_enable - Enable default interrupt generation settings
 * @adapter: board private structure
 **/

319
static void e1000_irq_enable(struct e1000_adapter *adapter)
Linus Torvalds's avatar
Linus Torvalds committed
320
{
Joe Perches's avatar
Joe Perches committed
321
322
323
324
	struct e1000_hw *hw = &adapter->hw;

	ew32(IMS, IMS_ENABLE_MASK);
	E1000_WRITE_FLUSH();
Linus Torvalds's avatar
Linus Torvalds committed
325
}
326

327
static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
328
{
Joe Perches's avatar
Joe Perches committed
329
	struct e1000_hw *hw = &adapter->hw;
330
	struct net_device *netdev = adapter->netdev;
Joe Perches's avatar
Joe Perches committed
331
	u16 vid = hw->mng_cookie.vlan_id;
332
	u16 old_vid = adapter->mng_vlan_id;
333
	if (adapter->vlgrp) {
334
		if (!vlan_group_get_device(adapter->vlgrp, vid)) {
Joe Perches's avatar
Joe Perches committed
335
			if (hw->mng_cookie.status &
336
337
338
339
340
				E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
				e1000_vlan_rx_add_vid(netdev, vid);
				adapter->mng_vlan_id = vid;
			} else
				adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
341

342
			if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
343
					(vid != old_vid) &&
344
			    !vlan_group_get_device(adapter->vlgrp, old_vid))
345
				e1000_vlan_rx_kill_vid(netdev, old_vid);
346
347
		} else
			adapter->mng_vlan_id = vid;
348
349
	}
}
350

351
static void e1000_init_manageability(struct e1000_adapter *adapter)
352
{
Joe Perches's avatar
Joe Perches committed
353
354
	struct e1000_hw *hw = &adapter->hw;

355
	if (adapter->en_mng_pt) {
Joe Perches's avatar
Joe Perches committed
356
		u32 manc = er32(MANC);
357
358
359
360

		/* disable hardware interception of ARP */
		manc &= ~(E1000_MANC_ARP_EN);

Joe Perches's avatar
Joe Perches committed
361
		ew32(MANC, manc);
362
363
364
	}
}

365
static void e1000_release_manageability(struct e1000_adapter *adapter)
366
{
Joe Perches's avatar
Joe Perches committed
367
368
	struct e1000_hw *hw = &adapter->hw;

369
	if (adapter->en_mng_pt) {
Joe Perches's avatar
Joe Perches committed
370
		u32 manc = er32(MANC);
371
372
373
374

		/* re-enable hardware interception of ARP */
		manc |= E1000_MANC_ARP_EN;

Joe Perches's avatar
Joe Perches committed
375
		ew32(MANC, manc);
376
377
378
	}
}

379
380
381
382
383
/**
 * e1000_configure - configure the hardware for RX and TX
 * @adapter = private board structure
 **/
static void e1000_configure(struct e1000_adapter *adapter)
Linus Torvalds's avatar
Linus Torvalds committed
384
385
{
	struct net_device *netdev = adapter->netdev;
386
	int i;
Linus Torvalds's avatar
Linus Torvalds committed
387

388
	e1000_set_rx_mode(netdev);
Linus Torvalds's avatar
Linus Torvalds committed
389
390

	e1000_restore_vlan(adapter);
391
	e1000_init_manageability(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
392
393
394
395

	e1000_configure_tx(adapter);
	e1000_setup_rctl(adapter);
	e1000_configure_rx(adapter);
396
397
398
	/* call E1000_DESC_UNUSED which always leaves
	 * at least 1 descriptor unused to make sure
	 * next_to_use != next_to_clean */
399
	for (i = 0; i < adapter->num_rx_queues; i++) {
400
		struct e1000_rx_ring *ring = &adapter->rx_ring[i];
401
402
		adapter->alloc_rx_buf(adapter, ring,
		                      E1000_DESC_UNUSED(ring));
403
	}
404
405
406
407
}

int e1000_up(struct e1000_adapter *adapter)
{
Joe Perches's avatar
Joe Perches committed
408
409
	struct e1000_hw *hw = &adapter->hw;

410
411
412
413
	/* hardware has been reset, we need to reload some things */
	e1000_configure(adapter);

	clear_bit(__E1000_DOWN, &adapter->flags);
414

415
	napi_enable(&adapter->napi);
416

417
418
	e1000_irq_enable(adapter);

419
420
	netif_wake_queue(adapter->netdev);

421
	/* fire a link change interrupt to start the watchdog */
Joe Perches's avatar
Joe Perches committed
422
	ew32(ICS, E1000_ICS_LSC);
Linus Torvalds's avatar
Linus Torvalds committed
423
424
425
	return 0;
}

426
427
428
429
430
431
432
433
434
435
/**
 * e1000_power_up_phy - restore link in case the phy was powered down
 * @adapter: address of board private structure
 *
 * The phy may be powered down to save power and turn off link when the
 * driver is unloaded and wake on lan is not enabled (among others)
 * *** this routine MUST be followed by a call to e1000_reset ***
 *
 **/

436
void e1000_power_up_phy(struct e1000_adapter *adapter)
437
{
Joe Perches's avatar
Joe Perches committed
438
	struct e1000_hw *hw = &adapter->hw;
439
	u16 mii_reg = 0;
440
441

	/* Just clear the power down bit to wake the phy back up */
Joe Perches's avatar
Joe Perches committed
442
	if (hw->media_type == e1000_media_type_copper) {
443
444
		/* according to the manual, the phy will retain its
		 * settings across a power-down/up cycle */
Joe Perches's avatar
Joe Perches committed
445
		e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
446
		mii_reg &= ~MII_CR_POWER_DOWN;
Joe Perches's avatar
Joe Perches committed
447
		e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
448
449
450
451
452
	}
}

static void e1000_power_down_phy(struct e1000_adapter *adapter)
{
Joe Perches's avatar
Joe Perches committed
453
454
	struct e1000_hw *hw = &adapter->hw;

455
	/* Power down the PHY so no link is implied when interface is down *
Joe Perches's avatar
Joe Perches committed
456
	 * The PHY cannot be powered down if any of the following is true *
457
458
459
	 * (a) WoL is enabled
	 * (b) AMT is active
	 * (c) SoL/IDER session is active */
Joe Perches's avatar
Joe Perches committed
460
461
	if (!adapter->wol && hw->mac_type >= e1000_82540 &&
	   hw->media_type == e1000_media_type_copper) {
462
		u16 mii_reg = 0;
463

Joe Perches's avatar
Joe Perches committed
464
		switch (hw->mac_type) {
465
466
467
468
		case e1000_82540:
		case e1000_82545:
		case e1000_82545_rev_3:
		case e1000_82546:
469
		case e1000_ce4100:
470
471
472
473
474
		case e1000_82546_rev_3:
		case e1000_82541:
		case e1000_82541_rev_2:
		case e1000_82547:
		case e1000_82547_rev_2:
Joe Perches's avatar
Joe Perches committed
475
			if (er32(MANC) & E1000_MANC_SMBUS_EN)
476
477
478
479
480
				goto out;
			break;
		default:
			goto out;
		}
Joe Perches's avatar
Joe Perches committed
481
		e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
482
		mii_reg |= MII_CR_POWER_DOWN;
Joe Perches's avatar
Joe Perches committed
483
		e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
484
485
		mdelay(1);
	}
486
487
out:
	return;
488
489
}

490
void e1000_down(struct e1000_adapter *adapter)
Linus Torvalds's avatar
Linus Torvalds committed
491
{
492
	struct e1000_hw *hw = &adapter->hw;
Linus Torvalds's avatar
Linus Torvalds committed
493
	struct net_device *netdev = adapter->netdev;
494
	u32 rctl, tctl;
Linus Torvalds's avatar
Linus Torvalds committed
495

496

497
498
499
500
501
	/* disable receives in the hardware */
	rctl = er32(RCTL);
	ew32(RCTL, rctl & ~E1000_RCTL_EN);
	/* flush and sleep below */

Jesse Brandeburg's avatar
Jesse Brandeburg committed
502
	netif_tx_disable(netdev);
503
504
505
506
507
508
509
510
511

	/* disable transmits in the hardware */
	tctl = er32(TCTL);
	tctl &= ~E1000_TCTL_EN;
	ew32(TCTL, tctl);
	/* flush both disables and wait for them to finish */
	E1000_WRITE_FLUSH();
	msleep(10);

512
	napi_disable(&adapter->napi);
513

Linus Torvalds's avatar
Linus Torvalds committed
514
	e1000_irq_disable(adapter);
515

Anupam Chanda's avatar
Anupam Chanda committed
516
517
518
519
520
521
522
	/*
	 * Setting DOWN must be after irq_disable to prevent
	 * a screaming interrupt.  Setting DOWN also prevents
	 * timers and tasks from rescheduling.
	 */
	set_bit(__E1000_DOWN, &adapter->flags);

Linus Torvalds's avatar
Linus Torvalds committed
523
524
525
526
527
528
529
530
531
	del_timer_sync(&adapter->tx_fifo_stall_timer);
	del_timer_sync(&adapter->watchdog_timer);
	del_timer_sync(&adapter->phy_info_timer);

	adapter->link_speed = 0;
	adapter->link_duplex = 0;
	netif_carrier_off(netdev);

	e1000_reset(adapter);
532
533
	e1000_clean_all_tx_rings(adapter);
	e1000_clean_all_rx_rings(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
534
535
}

536
static void e1000_reinit_safe(struct e1000_adapter *adapter)
537
538
539
540
541
542
543
544
545
546
{
	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
		msleep(1);
	rtnl_lock();
	e1000_down(adapter);
	e1000_up(adapter);
	rtnl_unlock();
	clear_bit(__E1000_RESETTING, &adapter->flags);
}

547
void e1000_reinit_locked(struct e1000_adapter *adapter)
548
{
549
550
	/* if rtnl_lock is not held the call path is bogus */
	ASSERT_RTNL();
551
552
553
554
555
556
	WARN_ON(in_interrupt());
	while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
		msleep(1);
	e1000_down(adapter);
	e1000_up(adapter);
	clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds's avatar
Linus Torvalds committed
557
558
}

559
void e1000_reset(struct e1000_adapter *adapter)
Linus Torvalds's avatar
Linus Torvalds committed
560
{
Joe Perches's avatar
Joe Perches committed
561
	struct e1000_hw *hw = &adapter->hw;
562
	u32 pba = 0, tx_space, min_tx_space, min_rx_space;
Joe Perches's avatar
Joe Perches committed
563
	bool legacy_pba_adjust = false;
564
	u16 hwm;
Linus Torvalds's avatar
Linus Torvalds committed
565
566
567
568
569

	/* Repartition Pba for greater than 9k mtu
	 * To take effect CTRL.RST is required.
	 */

Joe Perches's avatar
Joe Perches committed
570
	switch (hw->mac_type) {
571
572
573
574
575
576
577
	case e1000_82542_rev2_0:
	case e1000_82542_rev2_1:
	case e1000_82543:
	case e1000_82544:
	case e1000_82540:
	case e1000_82541:
	case e1000_82541_rev_2:
Joe Perches's avatar
Joe Perches committed
578
		legacy_pba_adjust = true;
579
580
581
582
583
		pba = E1000_PBA_48K;
		break;
	case e1000_82545:
	case e1000_82545_rev_3:
	case e1000_82546:
584
	case e1000_ce4100:
585
586
587
	case e1000_82546_rev_3:
		pba = E1000_PBA_48K;
		break;
588
	case e1000_82547:
589
	case e1000_82547_rev_2:
Joe Perches's avatar
Joe Perches committed
590
		legacy_pba_adjust = true;
591
592
		pba = E1000_PBA_30K;
		break;
593
594
	case e1000_undefined:
	case e1000_num_macs:
595
596
597
		break;
	}

Joe Perches's avatar
Joe Perches committed
598
	if (legacy_pba_adjust) {
599
		if (hw->max_frame_size > E1000_RXBUFFER_8192)
600
			pba -= 8; /* allocate more FIFO for Tx */
601

Joe Perches's avatar
Joe Perches committed
602
		if (hw->mac_type == e1000_82547) {
603
604
605
606
607
608
			adapter->tx_fifo_head = 0;
			adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
			adapter->tx_fifo_size =
				(E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
			atomic_set(&adapter->tx_fifo_stall, 0);
		}
609
	} else if (hw->max_frame_size >  ETH_FRAME_LEN + ETH_FCS_LEN) {
610
		/* adjust PBA for jumbo frames */
Joe Perches's avatar
Joe Perches committed
611
		ew32(PBA, pba);
612
613

		/* To maintain wire speed transmits, the Tx FIFO should be
614
		 * large enough to accommodate two full transmit packets,
615
		 * rounded up to the next 1KB and expressed in KB.  Likewise,
616
		 * the Rx FIFO should be large enough to accommodate at least
617
618
		 * one full receive packet and is similarly rounded up and
		 * expressed in KB. */
Joe Perches's avatar
Joe Perches committed
619
		pba = er32(PBA);
620
621
622
623
		/* upper 16 bits has Tx packet buffer allocation size in KB */
		tx_space = pba >> 16;
		/* lower 16 bits has Rx packet buffer allocation size in KB */
		pba &= 0xffff;
624
625
626
627
628
629
630
		/*
		 * the tx fifo also stores 16 bytes of information about the tx
		 * but don't include ethernet FCS because hardware appends it
		 */
		min_tx_space = (hw->max_frame_size +
		                sizeof(struct e1000_tx_desc) -
		                ETH_FCS_LEN) * 2;
631
		min_tx_space = ALIGN(min_tx_space, 1024);
632
		min_tx_space >>= 10;
633
634
		/* software strips receive CRC, so leave room for it */
		min_rx_space = hw->max_frame_size;
635
		min_rx_space = ALIGN(min_rx_space, 1024);
636
637
638
639
640
641
642
643
644
645
		min_rx_space >>= 10;

		/* If current Tx allocation is less than the min Tx FIFO size,
		 * and the min Tx FIFO size is less than the current Rx FIFO
		 * allocation, take space away from current Rx allocation */
		if (tx_space < min_tx_space &&
		    ((min_tx_space - tx_space) < pba)) {
			pba = pba - (min_tx_space - tx_space);

			/* PCI/PCIx hardware has PBA alignment constraints */
Joe Perches's avatar
Joe Perches committed
646
			switch (hw->mac_type) {
647
648
649
650
651
652
653
654
655
			case e1000_82545 ... e1000_82546_rev_3:
				pba &= ~(E1000_PBA_8K - 1);
				break;
			default:
				break;
			}

			/* if short on rx space, rx wins and must trump tx
			 * adjustment or use Early Receive if available */
656
657
			if (pba < min_rx_space)
				pba = min_rx_space;
658
		}
Linus Torvalds's avatar
Linus Torvalds committed
659
	}
660

Joe Perches's avatar
Joe Perches committed
661
	ew32(PBA, pba);
Linus Torvalds's avatar
Linus Torvalds committed
662

663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
	/*
	 * flow control settings:
	 * The high water mark must be low enough to fit one full frame
	 * (or the size used for early receive) above it in the Rx FIFO.
	 * Set it to the lower of:
	 * - 90% of the Rx FIFO size, and
	 * - the full Rx FIFO size minus the early receive size (for parts
	 *   with ERT support assuming ERT set to E1000_ERT_2048), or
	 * - the full Rx FIFO size minus one full frame
	 */
	hwm = min(((pba << 10) * 9 / 10),
		  ((pba << 10) - hw->max_frame_size));

	hw->fc_high_water = hwm & 0xFFF8;	/* 8-byte granularity */
	hw->fc_low_water = hw->fc_high_water - 8;
678
	hw->fc_pause_time = E1000_FC_PAUSE_TIME;
Joe Perches's avatar
Joe Perches committed
679
680
	hw->fc_send_xon = 1;
	hw->fc = hw->original_fc;
Linus Torvalds's avatar
Linus Torvalds committed
681

682
	/* Allow time for pending master requests to run */
Joe Perches's avatar
Joe Perches committed
683
684
685
	e1000_reset_hw(hw);
	if (hw->mac_type >= e1000_82544)
		ew32(WUC, 0);
686

Joe Perches's avatar
Joe Perches committed
687
	if (e1000_init_hw(hw))
688
		e_dev_err("Hardware Error\n");
689
	e1000_update_mng_vlan(adapter);
690
691

	/* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
Joe Perches's avatar
Joe Perches committed
692
693
694
695
	if (hw->mac_type >= e1000_82544 &&
	    hw->autoneg == 1 &&
	    hw->autoneg_advertised == ADVERTISE_1000_FULL) {
		u32 ctrl = er32(CTRL);
696
697
698
699
		/* clear phy power management bit if we are in gig only mode,
		 * which if enabled will attempt negotiation to 100Mb, which
		 * can cause a loss of link at power off or driver unload */
		ctrl &= ~E1000_CTRL_SWDPIN3;
Joe Perches's avatar
Joe Perches committed
700
		ew32(CTRL, ctrl);
701
702
	}

Linus Torvalds's avatar
Linus Torvalds committed
703
	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
Joe Perches's avatar
Joe Perches committed
704
	ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
Linus Torvalds's avatar
Linus Torvalds committed
705

Joe Perches's avatar
Joe Perches committed
706
707
	e1000_reset_adaptive(hw);
	e1000_phy_get_info(hw, &adapter->phy_info);
Auke Kok's avatar
Auke Kok committed
708

709
	e1000_release_manageability(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
710
711
}

712
713
714
/**
 *  Dump the eeprom for users having checksum issues
 **/
715
static void e1000_dump_eeprom(struct e1000_adapter *adapter)
716
717
718
719
720
721
722
723
724
725
726
727
728
{
	struct net_device *netdev = adapter->netdev;
	struct ethtool_eeprom eeprom;
	const struct ethtool_ops *ops = netdev->ethtool_ops;
	u8 *data;
	int i;
	u16 csum_old, csum_new = 0;

	eeprom.len = ops->get_eeprom_len(netdev);
	eeprom.offset = 0;

	data = kmalloc(eeprom.len, GFP_KERNEL);
	if (!data) {
729
		pr_err("Unable to allocate memory to dump EEPROM data\n");
730
731
732
733
734
735
736
737
738
739
740
		return;
	}

	ops->get_eeprom(netdev, &eeprom, data);

	csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
		   (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
	for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
		csum_new += data[i] + (data[i + 1] << 8);
	csum_new = EEPROM_SUM - csum_new;

741
742
743
	pr_err("/*********************/\n");
	pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old);
	pr_err("Calculated              : 0x%04x\n", csum_new);
744

745
746
	pr_err("Offset    Values\n");
	pr_err("========  ======\n");
747
748
	print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);

749
750
751
752
753
754
755
756
757
758
759
	pr_err("Include this output when contacting your support provider.\n");
	pr_err("This is not a software error! Something bad happened to\n");
	pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
	pr_err("result in further problems, possibly loss of data,\n");
	pr_err("corruption or system hangs!\n");
	pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
	pr_err("which is invalid and requires you to set the proper MAC\n");
	pr_err("address manually before continuing to enable this network\n");
	pr_err("device. Please inspect the EEPROM dump and report the\n");
	pr_err("issue to your hardware vendor or Intel Customer Support.\n");
	pr_err("/*********************/\n");
760
761
762
763

	kfree(data);
}

Taku Izumi's avatar
Taku Izumi committed
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/**
 * e1000_is_need_ioport - determine if an adapter needs ioport resources or not
 * @pdev: PCI device information struct
 *
 * Return true if an adapter needs ioport resources
 **/
static int e1000_is_need_ioport(struct pci_dev *pdev)
{
	switch (pdev->device) {
	case E1000_DEV_ID_82540EM:
	case E1000_DEV_ID_82540EM_LOM:
	case E1000_DEV_ID_82540EP:
	case E1000_DEV_ID_82540EP_LOM:
	case E1000_DEV_ID_82540EP_LP:
	case E1000_DEV_ID_82541EI:
	case E1000_DEV_ID_82541EI_MOBILE:
	case E1000_DEV_ID_82541ER:
	case E1000_DEV_ID_82541ER_LOM:
	case E1000_DEV_ID_82541GI:
	case E1000_DEV_ID_82541GI_LF:
	case E1000_DEV_ID_82541GI_MOBILE:
	case E1000_DEV_ID_82544EI_COPPER:
	case E1000_DEV_ID_82544EI_FIBER:
	case E1000_DEV_ID_82544GC_COPPER:
	case E1000_DEV_ID_82544GC_LOM:
	case E1000_DEV_ID_82545EM_COPPER:
	case E1000_DEV_ID_82545EM_FIBER:
	case E1000_DEV_ID_82546EB_COPPER:
	case E1000_DEV_ID_82546EB_FIBER:
	case E1000_DEV_ID_82546EB_QUAD_COPPER:
		return true;
	default:
		return false;
	}
}

800
801
802
static const struct net_device_ops e1000_netdev_ops = {
	.ndo_open		= e1000_open,
	.ndo_stop		= e1000_close,
803
	.ndo_start_xmit		= e1000_xmit_frame,
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
	.ndo_get_stats		= e1000_get_stats,
	.ndo_set_rx_mode	= e1000_set_rx_mode,
	.ndo_set_mac_address	= e1000_set_mac,
	.ndo_tx_timeout 	= e1000_tx_timeout,
	.ndo_change_mtu		= e1000_change_mtu,
	.ndo_do_ioctl		= e1000_ioctl,
	.ndo_validate_addr	= eth_validate_addr,

	.ndo_vlan_rx_register	= e1000_vlan_rx_register,
	.ndo_vlan_rx_add_vid	= e1000_vlan_rx_add_vid,
	.ndo_vlan_rx_kill_vid	= e1000_vlan_rx_kill_vid,
#ifdef CONFIG_NET_POLL_CONTROLLER
	.ndo_poll_controller	= e1000_netpoll,
#endif
};

820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
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
/**
 * e1000_init_hw_struct - initialize members of hw struct
 * @adapter: board private struct
 * @hw: structure used by e1000_hw.c
 *
 * Factors out initialization of the e1000_hw struct to its own function
 * that can be called very early at init (just after struct allocation).
 * Fields are initialized based on PCI device information and
 * OS network device settings (MTU size).
 * Returns negative error codes if MAC type setup fails.
 */
static int e1000_init_hw_struct(struct e1000_adapter *adapter,
				struct e1000_hw *hw)
{
	struct pci_dev *pdev = adapter->pdev;

	/* PCI config space info */
	hw->vendor_id = pdev->vendor;
	hw->device_id = pdev->device;
	hw->subsystem_vendor_id = pdev->subsystem_vendor;
	hw->subsystem_id = pdev->subsystem_device;
	hw->revision_id = pdev->revision;

	pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);

	hw->max_frame_size = adapter->netdev->mtu +
			     ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;

	/* identify the MAC */
	if (e1000_set_mac_type(hw)) {
		e_err(probe, "Unknown MAC Type\n");
		return -EIO;
	}

	switch (hw->mac_type) {
	default:
		break;
	case e1000_82541:
	case e1000_82547:
	case e1000_82541_rev_2:
	case e1000_82547_rev_2:
		hw->phy_init_script = 1;
		break;
	}

	e1000_set_media_type(hw);
	e1000_get_bus_info(hw);

	hw->wait_autoneg_complete = false;
	hw->tbi_compatibility_en = true;
	hw->adaptive_ifs = true;

	/* Copper options */

	if (hw->media_type == e1000_media_type_copper) {
		hw->mdix = AUTO_ALL_MODES;
		hw->disable_polarity_correction = false;
		hw->master_slave = E1000_MASTER_SLAVE;
	}

	return 0;
}

Linus Torvalds's avatar
Linus Torvalds committed
884
885
886
887
888
889
890
891
892
893
894
/**
 * e1000_probe - Device Initialization Routine
 * @pdev: PCI device information struct
 * @ent: entry in e1000_pci_tbl
 *
 * Returns 0 on success, negative on failure
 *
 * e1000_probe initializes an adapter identified by a pci_dev structure.
 * The OS initialization, configuring of the adapter private structure,
 * and a hardware reset occur.
 **/
Joe Perches's avatar
Joe Perches committed
895
896
static int __devinit e1000_probe(struct pci_dev *pdev,
				 const struct pci_device_id *ent)
Linus Torvalds's avatar
Linus Torvalds committed
897
898
899
{
	struct net_device *netdev;
	struct e1000_adapter *adapter;
Joe Perches's avatar
Joe Perches committed
900
	struct e1000_hw *hw;
901

Linus Torvalds's avatar
Linus Torvalds committed
902
	static int cards_found = 0;
903
	static int global_quad_port_a = 0; /* global ksp3 port a indication */
904
	int i, err, pci_using_dac;
905
	u16 eeprom_data = 0;
906
	u16 tmp = 0;
907
	u16 eeprom_apme_mask = E1000_EEPROM_APME;
Taku Izumi's avatar
Taku Izumi committed
908
	int bars, need_ioport;
909

Taku Izumi's avatar
Taku Izumi committed
910
911
912
913
914
915
916
	/* do not allocate ioport bars when not needed */
	need_ioport = e1000_is_need_ioport(pdev);
	if (need_ioport) {
		bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
		err = pci_enable_device(pdev);
	} else {
		bars = pci_select_bars(pdev, IORESOURCE_MEM);
917
		err = pci_enable_device_mem(pdev);
Taku Izumi's avatar
Taku Izumi committed
918
	}
919
	if (err)
Linus Torvalds's avatar
Linus Torvalds committed
920
921
		return err;

Taku Izumi's avatar
Taku Izumi committed
922
	err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
923
	if (err)
924
		goto err_pci_reg;
Linus Torvalds's avatar
Linus Torvalds committed
925
926

	pci_set_master(pdev);
927
928
929
	err = pci_save_state(pdev);
	if (err)
		goto err_alloc_etherdev;
Linus Torvalds's avatar
Linus Torvalds committed
930

931
	err = -ENOMEM;
Linus Torvalds's avatar
Linus Torvalds committed
932
	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
933
	if (!netdev)
Linus Torvalds's avatar
Linus Torvalds committed
934
935
936
937
938
		goto err_alloc_etherdev;

	SET_NETDEV_DEV(netdev, &pdev->dev);

	pci_set_drvdata(pdev, netdev);
939
	adapter = netdev_priv(netdev);
Linus Torvalds's avatar
Linus Torvalds committed
940
941
942
	adapter->netdev = netdev;
	adapter->pdev = pdev;
	adapter->msg_enable = (1 << debug) - 1;
Taku Izumi's avatar
Taku Izumi committed
943
944
	adapter->bars = bars;
	adapter->need_ioport = need_ioport;
Linus Torvalds's avatar
Linus Torvalds committed
945

Joe Perches's avatar
Joe Perches committed
946
947
948
	hw = &adapter->hw;
	hw->back = adapter;

949
	err = -EIO;
950
	hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
Joe Perches's avatar
Joe Perches committed
951
	if (!hw->hw_addr)
Linus Torvalds's avatar
Linus Torvalds committed
952
953
		goto err_ioremap;

Taku Izumi's avatar
Taku Izumi committed
954
955
956
957
958
959
960
961
	if (adapter->need_ioport) {
		for (i = BAR_1; i <= BAR_5; i++) {
			if (pci_resource_len(pdev, i) == 0)
				continue;
			if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
				hw->io_base = pci_resource_start(pdev, i);
				break;
			}
Linus Torvalds's avatar
Linus Torvalds committed
962
963
964
		}
	}

965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
	/* make ready for any if (hw->...) below */
	err = e1000_init_hw_struct(adapter, hw);
	if (err)
		goto err_sw_init;

	/*
	 * there is a workaround being applied below that limits
	 * 64-bit DMA addresses to 64-bit hardware.  There are some
	 * 32-bit adapters that Tx hang when given 64-bit DMA addresses
	 */
	pci_using_dac = 0;
	if ((hw->bus_type == e1000_bus_type_pcix) &&
	    !dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
		/*
		 * according to DMA-API-HOWTO, coherent calls will always
		 * succeed if the set call did
		 */
		dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
		pci_using_dac = 1;
	} else {
985
986
987
988
989
990
		err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
		if (err) {
			pr_err("No usable DMA config, aborting\n");
			goto err_dma;
		}
		dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
991
992
	}

993
	netdev->netdev_ops = &e1000_netdev_ops;
Linus Torvalds's avatar
Linus Torvalds committed
994
995
	e1000_set_ethtool_ops(netdev);
	netdev->watchdog_timeo = 5 * HZ;
996
	netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
997

998
	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds's avatar
Linus Torvalds committed
999
1000
1001
1002
1003

	adapter->bd_number = cards_found;

	/* setup the private structure */

1004
1005
	err = e1000_sw_init(adapter);
	if (err)
Linus Torvalds's avatar
Linus Torvalds committed
1006
1007
		goto err_sw_init;

1008
	err = -EIO;
1009
1010
1011
1012
1013
1014
1015
1016
	if (hw->mac_type == e1000_ce4100) {
		ce4100_gbe_mdio_base_phy = pci_resource_start(pdev, BAR_1);
		ce4100_gbe_mdio_base_virt = ioremap(ce4100_gbe_mdio_base_phy,
		                                pci_resource_len(pdev, BAR_1));

		if (!ce4100_gbe_mdio_base_virt)
			goto err_mdio_ioremap;
	}
1017

Joe Perches's avatar
Joe Perches committed
1018
	if (hw->mac_type >= e1000_82543) {
Linus Torvalds's avatar
Linus Torvalds committed
1019
1020
1021
1022
1023
1024
1025
		netdev->features = NETIF_F_SG |
				   NETIF_F_HW_CSUM |
				   NETIF_F_HW_VLAN_TX |
				   NETIF_F_HW_VLAN_RX |
				   NETIF_F_HW_VLAN_FILTER;
	}

Joe Perches's avatar
Joe Perches committed
1026
1027
	if ((hw->mac_type >= e1000_82544) &&
	   (hw->mac_type != e1000_82547))
Linus Torvalds's avatar
Linus Torvalds committed
1028
		netdev->features |= NETIF_F_TSO;
1029

1030
	if (pci_using_dac) {
Linus Torvalds's avatar
Linus Torvalds committed
1031
		netdev->features |= NETIF_F_HIGHDMA;
1032
1033
		netdev->vlan_features |= NETIF_F_HIGHDMA;
	}
Linus Torvalds's avatar
Linus Torvalds committed
1034

1035
1036
1037
1038
	netdev->vlan_features |= NETIF_F_TSO;
	netdev->vlan_features |= NETIF_F_HW_CSUM;
	netdev->vlan_features |= NETIF_F_SG;

Joe Perches's avatar
Joe Perches committed
1039
	adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1040

1041
	/* initialize eeprom parameters */
Joe Perches's avatar
Joe Perches committed
1042
	if (e1000_init_eeprom_params(hw)) {
1043
		e_err(probe, "EEPROM initialization failed\n");
1044
		goto err_eeprom;
1045
1046
	}

1047
	/* before reading the EEPROM, reset the controller to
Linus Torvalds's avatar
Linus Torvalds committed
1048
	 * put the device in a known good starting state */
1049

Joe Perches's avatar
Joe Perches committed
1050
	e1000_reset_hw(hw);
Linus Torvalds's avatar
Linus Torvalds committed
1051
1052

	/* make sure the EEPROM is good */
Joe Perches's avatar
Joe Perches committed
1053
	if (e1000_validate_eeprom_checksum(hw) < 0) {
1054
		e_err(probe, "The EEPROM Checksum Is Not Valid\n");
1055
1056
1057
1058
1059
1060
1061
1062
1063
		e1000_dump_eeprom(adapter);
		/*
		 * set MAC address to all zeroes to invalidate and temporary
		 * disable this device for the user. This blocks regular
		 * traffic while still permitting ethtool ioctls from reaching
		 * the hardware as well as allowing the user to run the
		 * interface after manually setting a hw addr using
		 * `ip set address`
		 */
Joe Perches's avatar
Joe Perches committed
1064
		memset(hw->mac_addr, 0, netdev->addr_len);
1065
1066
	} else {
		/* copy the MAC address out of the EEPROM */
Joe Perches's avatar
Joe Perches committed
1067
		if (e1000_read_mac_addr(hw))
1068
			e_err(probe, "EEPROM Read Error\n");
Linus Torvalds's avatar
Linus Torvalds committed
1069
	}
1070
	/* don't block initalization here due to bad MAC address */
Joe Perches's avatar
Joe Perches committed
1071
1072
	memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
	memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len);
Linus Torvalds's avatar
Linus Torvalds committed
1073

1074
	if (!is_valid_ether_addr(netdev->perm_addr))
1075
		e_err(probe, "Invalid MAC Address\n");
Linus Torvalds's avatar
Linus Torvalds committed
1076
1077

	init_timer(&adapter->tx_fifo_stall_timer);
1078
	adapter->tx_fifo_stall_timer.function = e1000_82547_tx_fifo_stall;
1079
	adapter->tx_fifo_stall_timer.data = (unsigned long)adapter;
Linus Torvalds's avatar
Linus Torvalds committed
1080
1081

	init_timer(&adapter->watchdog_timer);
1082
	adapter->watchdog_timer.function = e1000_watchdog;
Linus Torvalds's avatar
Linus Torvalds committed
1083
1084
1085
	adapter->watchdog_timer.data = (unsigned long) adapter;

	init_timer(&adapter->phy_info_timer);
1086
	adapter->phy_info_timer.function = e1000_update_phy_info;
1087
	adapter->phy_info_timer.data = (unsigned long)adapter;
Linus Torvalds's avatar
Linus Torvalds committed
1088

Jesse Brandeburg's avatar
Jesse Brandeburg committed
1089
	INIT_WORK(&adapter->fifo_stall_task, e1000_82547_tx_fifo_stall_task);
1090
	INIT_WORK(&adapter->reset_task, e1000_reset_task);
Jesse Brandeburg's avatar
Jesse Brandeburg committed
1091
	INIT_WORK(&adapter->phy_info_task, e1000_update_phy_info_task);
Linus Torvalds's avatar
Linus Torvalds committed
1092
1093
1094
1095
1096
1097
1098
1099

	e1000_check_options(adapter);

	/* Initial Wake on LAN setting
	 * If APM wake is enabled in the EEPROM,
	 * enable the ACPI Magic Packet filter
	 */

Joe Perches's avatar
Joe Perches committed
1100
	switch (hw->mac_type) {
Linus Torvalds's avatar
Linus Torvalds committed
1101
1102
1103
1104
1105
	case e1000_82542_rev2_0:
	case e1000_82542_rev2_1:
	case e1000_82543:
		break;
	case e1000_82544:
Joe Perches's avatar
Joe Perches committed
1106
		e1000_read_eeprom(hw,
Linus Torvalds's avatar
Linus Torvalds committed
1107
1108
1109
1110
1111
			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
		eeprom_apme_mask = E1000_EEPROM_82544_APM;
		break;
	case e1000_82546:
	case e1000_82546_rev_3:
Joe Perches's avatar
Joe Perches committed
1112
1113
		if (er32(STATUS) & E1000_STATUS_FUNC_1){
			e1000_read_eeprom(hw,
Linus Torvalds's avatar
Linus Torvalds committed
1114
1115
1116
1117
1118
				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
			break;
		}
		/* Fall Through */
	default:
Joe Perches's avatar
Joe Perches committed
1119
		e1000_read_eeprom(hw,
Linus Torvalds's avatar
Linus Torvalds committed
1120
1121
1122
			EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
		break;
	}
1123
	if (eeprom_data & eeprom_apme_mask)
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
		adapter->eeprom_wol |= E1000_WUFC_MAG;

	/* now that we have the eeprom settings, apply the special cases
	 * where the eeprom may be wrong or the board simply won't support
	 * wake on lan on a particular port */
	switch (pdev->device) {
	case E1000_DEV_ID_82546GB_PCIE:
		adapter->eeprom_wol = 0;
		break;
	case E1000_DEV_ID_82546EB_FIBER:
	case E1000_DEV_ID_82546GB_FIBER:
		/* Wake events only supported on port A for dual fiber
		 * regardless of eeprom setting */
Joe Perches's avatar
Joe Perches committed
1137
		if (er32(STATUS) & E1000_STATUS_FUNC_1)
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
			adapter->eeprom_wol = 0;
		break;
	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
		/* if quad port adapter, disable WoL on all but port A */
		if (global_quad_port_a != 0)
			adapter->eeprom_wol = 0;
		else
			adapter->quad_port_a = 1;
		/* Reset for multiple quad port adapters */
		if (++global_quad_port_a == 4)
			global_quad_port_a = 0;
		break;
	}

	/* initialize the wol settings based on the eeprom settings */
	adapter->wol = adapter->eeprom_wol;
1154
	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Linus Torvalds's avatar
Linus Torvalds committed
1155

1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
	/* Auto detect PHY address */
	if (hw->mac_type == e1000_ce4100) {
		for (i = 0; i < 32; i++) {
			hw->phy_addr = i;
			e1000_read_phy_reg(hw, PHY_ID2, &tmp);
			if (tmp == 0 || tmp == 0xFF) {
				if (i == 31)
					goto err_eeprom;
				continue;
			} else
				break;
		}
	}

1170
1171
1172
1173
1174
1175
1176
1177
	/* reset the hardware with the new settings */
	e1000_reset(adapter);

	strcpy(netd