e1000_main.c 153 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>
Linus Torvalds's avatar
Linus Torvalds committed
31
32

char e1000_driver_name[] = "e1000";
33
static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
Linus Torvalds's avatar
Linus Torvalds committed
34
35
36
37
38
#ifndef CONFIG_E1000_NAPI
#define DRIVERNAPI
#else
#define DRIVERNAPI "-NAPI"
#endif
39
#define DRV_VERSION "7.3.15-k2"DRIVERNAPI
Linus Torvalds's avatar
Linus Torvalds committed
40
char e1000_driver_version[] = DRV_VERSION;
41
static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
Linus Torvalds's avatar
Linus Torvalds committed
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

/* e1000_pci_tbl - PCI Device ID Table
 *
 * Last entry must be all 0s
 *
 * Macro expands to...
 *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
 */
static struct pci_device_id e1000_pci_tbl[] = {
	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),
70
	INTEL_E1000_ETHERNET_DEVICE(0x101A),
Linus Torvalds's avatar
Linus Torvalds committed
71
72
73
74
75
	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),
Auke Kok's avatar
Auke Kok committed
76
77
78
79
80
	INTEL_E1000_ETHERNET_DEVICE(0x1049),
	INTEL_E1000_ETHERNET_DEVICE(0x104A),
	INTEL_E1000_ETHERNET_DEVICE(0x104B),
	INTEL_E1000_ETHERNET_DEVICE(0x104C),
	INTEL_E1000_ETHERNET_DEVICE(0x104D),
81
82
83
	INTEL_E1000_ETHERNET_DEVICE(0x105E),
	INTEL_E1000_ETHERNET_DEVICE(0x105F),
	INTEL_E1000_ETHERNET_DEVICE(0x1060),
Linus Torvalds's avatar
Linus Torvalds committed
84
85
86
87
88
89
90
91
	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),
92
93
94
	INTEL_E1000_ETHERNET_DEVICE(0x107D),
	INTEL_E1000_ETHERNET_DEVICE(0x107E),
	INTEL_E1000_ETHERNET_DEVICE(0x107F),
Linus Torvalds's avatar
Linus Torvalds committed
95
	INTEL_E1000_ETHERNET_DEVICE(0x108A),
96
97
	INTEL_E1000_ETHERNET_DEVICE(0x108B),
	INTEL_E1000_ETHERNET_DEVICE(0x108C),
98
99
	INTEL_E1000_ETHERNET_DEVICE(0x1096),
	INTEL_E1000_ETHERNET_DEVICE(0x1098),
100
	INTEL_E1000_ETHERNET_DEVICE(0x1099),
101
	INTEL_E1000_ETHERNET_DEVICE(0x109A),
102
	INTEL_E1000_ETHERNET_DEVICE(0x10A4),
103
	INTEL_E1000_ETHERNET_DEVICE(0x10B5),
104
	INTEL_E1000_ETHERNET_DEVICE(0x10B9),
Auke Kok's avatar
Auke Kok committed
105
106
	INTEL_E1000_ETHERNET_DEVICE(0x10BA),
	INTEL_E1000_ETHERNET_DEVICE(0x10BB),
Auke Kok's avatar
Auke Kok committed
107
108
109
	INTEL_E1000_ETHERNET_DEVICE(0x10BC),
	INTEL_E1000_ETHERNET_DEVICE(0x10C4),
	INTEL_E1000_ETHERNET_DEVICE(0x10C5),
Linus Torvalds's avatar
Linus Torvalds committed
110
111
112
113
114
115
	/* required last entry */
	{0,}
};

MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);

116
117
118
119
120
121
122
123
124
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);
int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
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);
125
static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
126
                             struct e1000_tx_ring *txdr);
127
static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
128
                             struct e1000_rx_ring *rxdr);
129
static void e1000_free_tx_resources(struct e1000_adapter *adapter,
130
                             struct e1000_tx_ring *tx_ring);
131
static void e1000_free_rx_resources(struct e1000_adapter *adapter,
132
133
                             struct e1000_rx_ring *rx_ring);
void e1000_update_stats(struct e1000_adapter *adapter);
Linus Torvalds's avatar
Linus Torvalds committed
134
135
136
137
138

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);
139
static int e1000_alloc_queues(struct e1000_adapter *adapter);
Linus Torvalds's avatar
Linus Torvalds committed
140
141
142
143
144
145
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);
146
147
148
149
150
151
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);
Linus Torvalds's avatar
Linus Torvalds committed
152
153
154
155
156
157
158
159
static void e1000_set_multi(struct net_device *netdev);
static void e1000_update_phy_info(unsigned long data);
static void e1000_watchdog(unsigned long data);
static void e1000_82547_tx_fifo_stall(unsigned long data);
static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
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);
160
static irqreturn_t e1000_intr(int irq, void *data);
161
162
163
#ifdef CONFIG_PCI_MSI
static irqreturn_t e1000_intr_msi(int irq, void *data);
#endif
164
165
static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
                                    struct e1000_tx_ring *tx_ring);
Linus Torvalds's avatar
Linus Torvalds committed
166
#ifdef CONFIG_E1000_NAPI
167
static int e1000_clean(struct net_device *poll_dev, int *budget);
Linus Torvalds's avatar
Linus Torvalds committed
168
static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
169
                                    struct e1000_rx_ring *rx_ring,
Linus Torvalds's avatar
Linus Torvalds committed
170
                                    int *work_done, int work_to_do);
171
static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
172
                                       struct e1000_rx_ring *rx_ring,
173
                                       int *work_done, int work_to_do);
Linus Torvalds's avatar
Linus Torvalds committed
174
#else
175
176
177
178
static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
                                    struct e1000_rx_ring *rx_ring);
static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
                                       struct e1000_rx_ring *rx_ring);
Linus Torvalds's avatar
Linus Torvalds committed
179
#endif
180
static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
181
182
                                   struct e1000_rx_ring *rx_ring,
				   int cleaned_count);
183
static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
184
185
                                      struct e1000_rx_ring *rx_ring,
				      int cleaned_count);
Linus Torvalds's avatar
Linus Torvalds committed
186
187
188
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);
189
void e1000_set_ethtool_ops(struct net_device *netdev);
Linus Torvalds's avatar
Linus Torvalds committed
190
191
192
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);
193
static void e1000_reset_task(struct work_struct *work);
Linus Torvalds's avatar
Linus Torvalds committed
194
static void e1000_smartspeed(struct e1000_adapter *adapter);
195
196
static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
                                       struct sk_buff *skb);
Linus Torvalds's avatar
Linus Torvalds committed
197
198
199
200
201
202

static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
static void e1000_restore_vlan(struct e1000_adapter *adapter);

203
static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
Auke Kok's avatar
Auke Kok committed
204
#ifdef CONFIG_PM
Linus Torvalds's avatar
Linus Torvalds committed
205
206
static int e1000_resume(struct pci_dev *pdev);
#endif
207
static void e1000_shutdown(struct pci_dev *pdev);
Linus Torvalds's avatar
Linus Torvalds committed
208
209
210
211
212
213

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

214
215
extern void e1000_check_options(struct e1000_adapter *adapter);

216
217
218
219
220
221
#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
222
223
224
225
226
227
228
229
230
231
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,
};
232

Linus Torvalds's avatar
Linus Torvalds committed
233
234
235
236
237
static struct pci_driver e1000_driver = {
	.name     = e1000_driver_name,
	.id_table = e1000_pci_tbl,
	.probe    = e1000_probe,
	.remove   = __devexit_p(e1000_remove),
238
#ifdef CONFIG_PM
Linus Torvalds's avatar
Linus Torvalds committed
239
240
	/* Power Managment Hooks */
	.suspend  = e1000_suspend,
241
	.resume   = e1000_resume,
Linus Torvalds's avatar
Linus Torvalds committed
242
#endif
Auke Kok's avatar
Auke Kok committed
243
244
	.shutdown = e1000_shutdown,
	.err_handler = &e1000_err_handler
Linus Torvalds's avatar
Linus Torvalds committed
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
};

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)");

/**
 * 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.
 **/

static int __init
e1000_init_module(void)
{
	int ret;
	printk(KERN_INFO "%s - version %s\n",
	       e1000_driver_string, e1000_driver_version);

	printk(KERN_INFO "%s\n", e1000_copyright);

272
	ret = pci_register_driver(&e1000_driver);
273
274
275
276
277
278
279
	if (copybreak != COPYBREAK_DEFAULT) {
		if (copybreak == 0)
			printk(KERN_INFO "e1000: copybreak disabled\n");
		else
			printk(KERN_INFO "e1000: copybreak enabled for "
			       "packets <= %u bytes\n", copybreak);
	}
Linus Torvalds's avatar
Linus Torvalds committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
	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.
 **/

static void __exit
e1000_exit_module(void)
{
	pci_unregister_driver(&e1000_driver);
}

module_exit(e1000_exit_module);

300
301
302
303
304
static int e1000_request_irq(struct e1000_adapter *adapter)
{
	struct net_device *netdev = adapter->netdev;
	int flags, err = 0;

305
	flags = IRQF_SHARED;
306
#ifdef CONFIG_PCI_MSI
307
	if (adapter->hw.mac_type >= e1000_82571) {
308
309
310
311
312
313
314
		adapter->have_msi = TRUE;
		if ((err = pci_enable_msi(adapter->pdev))) {
			DPRINTK(PROBE, ERR,
			 "Unable to allocate MSI interrupt Error: %d\n", err);
			adapter->have_msi = FALSE;
		}
	}
315
	if (adapter->have_msi) {
316
		flags &= ~IRQF_SHARED;
317
318
319
320
321
322
		err = request_irq(adapter->pdev->irq, &e1000_intr_msi, flags,
		                  netdev->name, netdev);
		if (err)
			DPRINTK(PROBE, ERR,
			       "Unable to allocate interrupt Error: %d\n", err);
	} else
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#endif
	if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
	                       netdev->name, netdev)))
		DPRINTK(PROBE, ERR,
		        "Unable to allocate interrupt Error: %d\n", err);

	return err;
}

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

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

#ifdef CONFIG_PCI_MSI
	if (adapter->have_msi)
		pci_disable_msi(adapter->pdev);
#endif
}

Linus Torvalds's avatar
Linus Torvalds committed
344
345
346
347
348
/**
 * e1000_irq_disable - Mask off interrupt generation on the NIC
 * @adapter: board private structure
 **/

349
static void
Linus Torvalds's avatar
Linus Torvalds committed
350
351
352
353
354
355
356
357
358
359
360
361
362
e1000_irq_disable(struct e1000_adapter *adapter)
{
	atomic_inc(&adapter->irq_sem);
	E1000_WRITE_REG(&adapter->hw, IMC, ~0);
	E1000_WRITE_FLUSH(&adapter->hw);
	synchronize_irq(adapter->pdev->irq);
}

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

363
static void
Linus Torvalds's avatar
Linus Torvalds committed
364
365
e1000_irq_enable(struct e1000_adapter *adapter)
{
366
	if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
Linus Torvalds's avatar
Linus Torvalds committed
367
368
369
370
		E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
		E1000_WRITE_FLUSH(&adapter->hw);
	}
}
371
372

static void
373
374
375
376
377
e1000_update_mng_vlan(struct e1000_adapter *adapter)
{
	struct net_device *netdev = adapter->netdev;
	uint16_t vid = adapter->hw.mng_cookie.vlan_id;
	uint16_t old_vid = adapter->mng_vlan_id;
378
379
380
	if (adapter->vlgrp) {
		if (!adapter->vlgrp->vlan_devices[vid]) {
			if (adapter->hw.mng_cookie.status &
381
382
383
384
385
				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;
386
387
388

			if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
					(vid != old_vid) &&
389
390
					!adapter->vlgrp->vlan_devices[old_vid])
				e1000_vlan_rx_kill_vid(netdev, old_vid);
391
392
		} else
			adapter->mng_vlan_id = vid;
393
394
	}
}
395
396
397
398
399
400
401
402

/**
 * e1000_release_hw_control - release control of the h/w to f/w
 * @adapter: address of board private structure
 *
 * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
 * For ASF and Pass Through versions of f/w this means that the
 * driver is no longer loaded. For AMT version (only with 82573) i
403
 * of the f/w this means that the network i/f is closed.
404
 *
405
406
 **/

407
static void
408
409
410
411
e1000_release_hw_control(struct e1000_adapter *adapter)
{
	uint32_t ctrl_ext;
	uint32_t swsm;
412
	uint32_t extcnf;
413
414
415
416
417

	/* Let firmware taken over control of h/w */
	switch (adapter->hw.mac_type) {
	case e1000_82571:
	case e1000_82572:
418
	case e1000_80003es2lan:
419
420
421
422
423
424
425
426
		ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
				ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
		break;
	case e1000_82573:
		swsm = E1000_READ_REG(&adapter->hw, SWSM);
		E1000_WRITE_REG(&adapter->hw, SWSM,
				swsm & ~E1000_SWSM_DRV_LOAD);
427
428
429
430
431
	case e1000_ich8lan:
		extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT);
		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
				extcnf & ~E1000_CTRL_EXT_DRV_LOAD);
		break;
432
433
434
435
436
437
438
439
440
441
	default:
		break;
	}
}

/**
 * e1000_get_hw_control - get control of the h/w from f/w
 * @adapter: address of board private structure
 *
 * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
442
443
 * For ASF and Pass Through versions of f/w this means that
 * the driver is loaded. For AMT version (only with 82573)
444
 * of the f/w this means that the network i/f is open.
445
 *
446
447
 **/

448
static void
449
450
451
452
e1000_get_hw_control(struct e1000_adapter *adapter)
{
	uint32_t ctrl_ext;
	uint32_t swsm;
453
	uint32_t extcnf;
454

455
456
457
458
	/* Let firmware know the driver has taken over */
	switch (adapter->hw.mac_type) {
	case e1000_82571:
	case e1000_82572:
459
	case e1000_80003es2lan:
460
461
462
463
464
465
466
467
468
		ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
		E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
				ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
		break;
	case e1000_82573:
		swsm = E1000_READ_REG(&adapter->hw, SWSM);
		E1000_WRITE_REG(&adapter->hw, SWSM,
				swsm | E1000_SWSM_DRV_LOAD);
		break;
469
470
471
472
473
	case e1000_ich8lan:
		extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL);
		E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL,
				extcnf | E1000_EXTCNF_CTRL_SWFLAG);
		break;
474
475
476
477
478
	default:
		break;
	}
}

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
static void
e1000_init_manageability(struct e1000_adapter *adapter)
{
	if (adapter->en_mng_pt) {
		uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);

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

		/* enable receiving management packets to the host */
		/* this will probably generate destination unreachable messages
		 * from the host OS, but the packets will be handled on SMBUS */
		if (adapter->hw.has_manc2h) {
			uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);

			manc |= E1000_MANC_EN_MNG2HOST;
#define E1000_MNG2HOST_PORT_623 (1 << 5)
#define E1000_MNG2HOST_PORT_664 (1 << 6)
			manc2h |= E1000_MNG2HOST_PORT_623;
			manc2h |= E1000_MNG2HOST_PORT_664;
			E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
		}

		E1000_WRITE_REG(&adapter->hw, MANC, manc);
	}
}

static void
e1000_release_manageability(struct e1000_adapter *adapter)
{
	if (adapter->en_mng_pt) {
		uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);

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

		if (adapter->hw.has_manc2h)
			manc &= ~E1000_MANC_EN_MNG2HOST;

		/* don't explicitly have to mess with MANC2H since
		 * MANC has an enable disable that gates MANC2H */

		E1000_WRITE_REG(&adapter->hw, MANC, manc);
	}
}

Linus Torvalds's avatar
Linus Torvalds committed
525
526
527
528
int
e1000_up(struct e1000_adapter *adapter)
{
	struct net_device *netdev = adapter->netdev;
529
	int i;
Linus Torvalds's avatar
Linus Torvalds committed
530
531
532
533
534
535

	/* hardware has been reset, we need to reload some things */

	e1000_set_multi(netdev);

	e1000_restore_vlan(adapter);
536
	e1000_init_manageability(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
537
538
539
540

	e1000_configure_tx(adapter);
	e1000_setup_rctl(adapter);
	e1000_configure_rx(adapter);
541
542
543
	/* call E1000_DESC_UNUSED which always leaves
	 * at least 1 descriptor unused to make sure
	 * next_to_use != next_to_clean */
544
	for (i = 0; i < adapter->num_rx_queues; i++) {
545
		struct e1000_rx_ring *ring = &adapter->rx_ring[i];
546
547
		adapter->alloc_rx_buf(adapter, ring,
		                      E1000_DESC_UNUSED(ring));
548
	}
Linus Torvalds's avatar
Linus Torvalds committed
549

550
551
	adapter->tx_queue_len = netdev->tx_queue_len;

Linus Torvalds's avatar
Linus Torvalds committed
552
553
554
#ifdef CONFIG_E1000_NAPI
	netif_poll_enable(netdev);
#endif
555
556
	e1000_irq_enable(adapter);

557
558
	clear_bit(__E1000_DOWN, &adapter->flags);

559
560
	/* fire a link change interrupt to start the watchdog */
	E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
Linus Torvalds's avatar
Linus Torvalds committed
561
562
563
	return 0;
}

564
565
566
567
568
569
570
571
572
573
/**
 * 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 ***
 *
 **/

574
void e1000_power_up_phy(struct e1000_adapter *adapter)
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
{
	uint16_t mii_reg = 0;

	/* Just clear the power down bit to wake the phy back up */
	if (adapter->hw.media_type == e1000_media_type_copper) {
		/* according to the manual, the phy will retain its
		 * settings across a power-down/up cycle */
		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
		mii_reg &= ~MII_CR_POWER_DOWN;
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
	}
}

static void e1000_power_down_phy(struct e1000_adapter *adapter)
{
590
591
	/* Power down the PHY so no link is implied when interface is down *
	 * The PHY cannot be powered down if any of the following is TRUE *
592
593
594
595
	 * (a) WoL is enabled
	 * (b) AMT is active
	 * (c) SoL/IDER session is active */
	if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
596
	   adapter->hw.media_type == e1000_media_type_copper) {
597
		uint16_t mii_reg = 0;
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

		switch (adapter->hw.mac_type) {
		case e1000_82540:
		case e1000_82545:
		case e1000_82545_rev_3:
		case e1000_82546:
		case e1000_82546_rev_3:
		case e1000_82541:
		case e1000_82541_rev_2:
		case e1000_82547:
		case e1000_82547_rev_2:
			if (E1000_READ_REG(&adapter->hw, MANC) &
			    E1000_MANC_SMBUS_EN)
				goto out;
			break;
		case e1000_82571:
		case e1000_82572:
		case e1000_82573:
		case e1000_80003es2lan:
		case e1000_ich8lan:
			if (e1000_check_mng_mode(&adapter->hw) ||
			    e1000_check_phy_reset_block(&adapter->hw))
				goto out;
			break;
		default:
			goto out;
		}
625
626
627
628
629
		e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
		mii_reg |= MII_CR_POWER_DOWN;
		e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
		mdelay(1);
	}
630
631
out:
	return;
632
633
}

Linus Torvalds's avatar
Linus Torvalds committed
634
635
636
637
638
void
e1000_down(struct e1000_adapter *adapter)
{
	struct net_device *netdev = adapter->netdev;

639
640
641
642
	/* signal that we're down so the interrupt handler does not
	 * reschedule our watchdog timer */
	set_bit(__E1000_DOWN, &adapter->flags);

Linus Torvalds's avatar
Linus Torvalds committed
643
	e1000_irq_disable(adapter);
644

Linus Torvalds's avatar
Linus Torvalds committed
645
646
647
648
649
650
651
	del_timer_sync(&adapter->tx_fifo_stall_timer);
	del_timer_sync(&adapter->watchdog_timer);
	del_timer_sync(&adapter->phy_info_timer);

#ifdef CONFIG_E1000_NAPI
	netif_poll_disable(netdev);
#endif
652
	netdev->tx_queue_len = adapter->tx_queue_len;
Linus Torvalds's avatar
Linus Torvalds committed
653
654
655
656
657
658
	adapter->link_speed = 0;
	adapter->link_duplex = 0;
	netif_carrier_off(netdev);
	netif_stop_queue(netdev);

	e1000_reset(adapter);
659
660
	e1000_clean_all_tx_rings(adapter);
	e1000_clean_all_rx_rings(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
661
662
}

663
664
665
666
667
668
669
670
671
void
e1000_reinit_locked(struct e1000_adapter *adapter)
{
	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
672
673
674
675
676
}

void
e1000_reset(struct e1000_adapter *adapter)
{
677
	uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
678
	uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
679
	boolean_t legacy_pba_adjust = FALSE;
Linus Torvalds's avatar
Linus Torvalds committed
680
681
682
683
684

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

685
	switch (adapter->hw.mac_type) {
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
	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:
		legacy_pba_adjust = TRUE;
		pba = E1000_PBA_48K;
		break;
	case e1000_82545:
	case e1000_82545_rev_3:
	case e1000_82546:
	case e1000_82546_rev_3:
		pba = E1000_PBA_48K;
		break;
702
	case e1000_82547:
703
	case e1000_82547_rev_2:
704
		legacy_pba_adjust = TRUE;
705
706
		pba = E1000_PBA_30K;
		break;
707
708
	case e1000_82571:
	case e1000_82572:
709
	case e1000_80003es2lan:
710
711
		pba = E1000_PBA_38K;
		break;
712
	case e1000_82573:
713
		pba = E1000_PBA_20K;
714
		break;
715
716
	case e1000_ich8lan:
		pba = E1000_PBA_8K;
717
718
	case e1000_undefined:
	case e1000_num_macs:
719
720
721
		break;
	}

722
723
724
	if (legacy_pba_adjust == TRUE) {
		if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
			pba -= 8; /* allocate more FIFO for Tx */
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
		if (adapter->hw.mac_type == e1000_82547) {
			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);
		}
	} else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
		/* adjust PBA for jumbo frames */
		E1000_WRITE_REG(&adapter->hw, PBA, pba);

		/* To maintain wire speed transmits, the Tx FIFO should be
		 * large enough to accomodate two full transmit packets,
		 * rounded up to the next 1KB and expressed in KB.  Likewise,
		 * the Rx FIFO should be large enough to accomodate at least
		 * one full receive packet and is similarly rounded up and
		 * expressed in KB. */
		pba = E1000_READ_REG(&adapter->hw, PBA);
		/* 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;
		/* don't include ethernet FCS because hardware appends/strips */
		min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
		               VLAN_TAG_SIZE;
		min_tx_space = min_rx_space;
		min_tx_space *= 2;
		E1000_ROUNDUP(min_tx_space, 1024);
		min_tx_space >>= 10;
		E1000_ROUNDUP(min_rx_space, 1024);
		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 */
			switch (adapter->hw.mac_type) {
			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 */
			if (pba < min_rx_space) {
				switch (adapter->hw.mac_type) {
				case e1000_82573:
					/* ERT enabled in e1000_configure_rx */
					break;
				default:
					pba = min_rx_space;
					break;
				}
			}
		}
Linus Torvalds's avatar
Linus Torvalds committed
787
	}
788

Linus Torvalds's avatar
Linus Torvalds committed
789
790
791
	E1000_WRITE_REG(&adapter->hw, PBA, pba);

	/* flow control settings */
792
793
794
	/* Set the FC high water mark to 90% of the FIFO size.
	 * Required to clear last 3 LSB */
	fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
795
796
797
798
799
800
	/* We can't use 90% on small FIFOs because the remainder
	 * would be less than 1 full frame.  In this case, we size
	 * it to allow at least a full frame above the high water
	 *  mark. */
	if (pba < E1000_PBA_16K)
		fc_high_water_mark = (pba * 1024) - 1600;
801
802
803

	adapter->hw.fc_high_water = fc_high_water_mark;
	adapter->hw.fc_low_water = fc_high_water_mark - 8;
804
805
806
807
	if (adapter->hw.mac_type == e1000_80003es2lan)
		adapter->hw.fc_pause_time = 0xFFFF;
	else
		adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
Linus Torvalds's avatar
Linus Torvalds committed
808
809
810
	adapter->hw.fc_send_xon = 1;
	adapter->hw.fc = adapter->hw.original_fc;

811
	/* Allow time for pending master requests to run */
Linus Torvalds's avatar
Linus Torvalds committed
812
	e1000_reset_hw(&adapter->hw);
813
	if (adapter->hw.mac_type >= e1000_82544)
Linus Torvalds's avatar
Linus Torvalds committed
814
		E1000_WRITE_REG(&adapter->hw, WUC, 0);
815

816
	if (e1000_init_hw(&adapter->hw))
Linus Torvalds's avatar
Linus Torvalds committed
817
		DPRINTK(PROBE, ERR, "Hardware Error\n");
818
	e1000_update_mng_vlan(adapter);
819
820
821
822
823
824
825
826
827
828
829
830
831
832

	/* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
	if (adapter->hw.mac_type >= e1000_82544 &&
	    adapter->hw.mac_type <= e1000_82547_rev_2 &&
	    adapter->hw.autoneg == 1 &&
	    adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
		uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
		/* 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;
		E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
	}

Linus Torvalds's avatar
Linus Torvalds committed
833
834
835
836
837
	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
	E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);

	e1000_reset_adaptive(&adapter->hw);
	e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
Auke Kok's avatar
Auke Kok committed
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852

	if (!adapter->smart_power_down &&
	    (adapter->hw.mac_type == e1000_82571 ||
	     adapter->hw.mac_type == e1000_82572)) {
		uint16_t phy_data = 0;
		/* speed up time to link by disabling smart power down, ignore
		 * the return value of this function because there is nothing
		 * different we would do if it failed */
		e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
		                   &phy_data);
		phy_data &= ~IGP02E1000_PM_SPD;
		e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
		                    phy_data);
	}

853
	e1000_release_manageability(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
}

/**
 * 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.
 **/

static int __devinit
e1000_probe(struct pci_dev *pdev,
            const struct pci_device_id *ent)
{
	struct net_device *netdev;
	struct e1000_adapter *adapter;
874
	unsigned long mmio_start, mmio_len;
875
	unsigned long flash_start, flash_len;
876

Linus Torvalds's avatar
Linus Torvalds committed
877
	static int cards_found = 0;
878
	static int global_quad_port_a = 0; /* global ksp3 port a indication */
879
	int i, err, pci_using_dac;
880
	uint16_t eeprom_data = 0;
Linus Torvalds's avatar
Linus Torvalds committed
881
	uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
882
	if ((err = pci_enable_device(pdev)))
Linus Torvalds's avatar
Linus Torvalds committed
883
884
		return err;

885
886
	if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
	    !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
Linus Torvalds's avatar
Linus Torvalds committed
887
888
		pci_using_dac = 1;
	} else {
889
890
		if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
		    (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
Linus Torvalds's avatar
Linus Torvalds committed
891
			E1000_ERR("No usable DMA configuration, aborting\n");
892
			goto err_dma;
Linus Torvalds's avatar
Linus Torvalds committed
893
894
895
896
		}
		pci_using_dac = 0;
	}

897
	if ((err = pci_request_regions(pdev, e1000_driver_name)))
898
		goto err_pci_reg;
Linus Torvalds's avatar
Linus Torvalds committed
899
900
901

	pci_set_master(pdev);

902
	err = -ENOMEM;
Linus Torvalds's avatar
Linus Torvalds committed
903
	netdev = alloc_etherdev(sizeof(struct e1000_adapter));
904
	if (!netdev)
Linus Torvalds's avatar
Linus Torvalds committed
905
906
907
908
909
910
		goto err_alloc_etherdev;

	SET_MODULE_OWNER(netdev);
	SET_NETDEV_DEV(netdev, &pdev->dev);

	pci_set_drvdata(pdev, netdev);
911
	adapter = netdev_priv(netdev);
Linus Torvalds's avatar
Linus Torvalds committed
912
913
914
915
916
917
918
919
	adapter->netdev = netdev;
	adapter->pdev = pdev;
	adapter->hw.back = adapter;
	adapter->msg_enable = (1 << debug) - 1;

	mmio_start = pci_resource_start(pdev, BAR_0);
	mmio_len = pci_resource_len(pdev, BAR_0);

920
	err = -EIO;
Linus Torvalds's avatar
Linus Torvalds committed
921
	adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
922
	if (!adapter->hw.hw_addr)
Linus Torvalds's avatar
Linus Torvalds committed
923
924
		goto err_ioremap;

925
926
	for (i = BAR_1; i <= BAR_5; i++) {
		if (pci_resource_len(pdev, i) == 0)
Linus Torvalds's avatar
Linus Torvalds committed
927
			continue;
928
		if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Linus Torvalds's avatar
Linus Torvalds committed
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
			adapter->hw.io_base = pci_resource_start(pdev, i);
			break;
		}
	}

	netdev->open = &e1000_open;
	netdev->stop = &e1000_close;
	netdev->hard_start_xmit = &e1000_xmit_frame;
	netdev->get_stats = &e1000_get_stats;
	netdev->set_multicast_list = &e1000_set_multi;
	netdev->set_mac_address = &e1000_set_mac;
	netdev->change_mtu = &e1000_change_mtu;
	netdev->do_ioctl = &e1000_ioctl;
	e1000_set_ethtool_ops(netdev);
	netdev->tx_timeout = &e1000_tx_timeout;
	netdev->watchdog_timeo = 5 * HZ;
#ifdef CONFIG_E1000_NAPI
	netdev->poll = &e1000_clean;
	netdev->weight = 64;
#endif
	netdev->vlan_rx_register = e1000_vlan_rx_register;
	netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
	netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
#ifdef CONFIG_NET_POLL_CONTROLLER
	netdev->poll_controller = e1000_netpoll;
#endif
955
	strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Linus Torvalds's avatar
Linus Torvalds committed
956
957
958
959
960
961
962
963
964

	netdev->mem_start = mmio_start;
	netdev->mem_end = mmio_start + mmio_len;
	netdev->base_addr = adapter->hw.io_base;

	adapter->bd_number = cards_found;

	/* setup the private structure */

965
	if ((err = e1000_sw_init(adapter)))
Linus Torvalds's avatar
Linus Torvalds committed
966
967
		goto err_sw_init;

968
	err = -EIO;
969
970
971
972
973
974
975
	/* Flash BAR mapping must happen after e1000_sw_init
	 * because it depends on mac_type */
	if ((adapter->hw.mac_type == e1000_ich8lan) &&
	   (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
		flash_start = pci_resource_start(pdev, 1);
		flash_len = pci_resource_len(pdev, 1);
		adapter->hw.flash_address = ioremap(flash_start, flash_len);
976
		if (!adapter->hw.flash_address)
977
978
979
			goto err_flashmap;
	}

980
	if (e1000_check_phy_reset_block(&adapter->hw))
981
982
		DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");

983
	if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds's avatar
Linus Torvalds committed
984
985
986
987
988
		netdev->features = NETIF_F_SG |
				   NETIF_F_HW_CSUM |
				   NETIF_F_HW_VLAN_TX |
				   NETIF_F_HW_VLAN_RX |
				   NETIF_F_HW_VLAN_FILTER;
989
990
		if (adapter->hw.mac_type == e1000_ich8lan)
			netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
Linus Torvalds's avatar
Linus Torvalds committed
991
992
993
	}

#ifdef NETIF_F_TSO
994
	if ((adapter->hw.mac_type >= e1000_82544) &&
Linus Torvalds's avatar
Linus Torvalds committed
995
996
	   (adapter->hw.mac_type != e1000_82547))
		netdev->features |= NETIF_F_TSO;
997

Auke Kok's avatar
Auke Kok committed
998
#ifdef NETIF_F_TSO6
999
	if (adapter->hw.mac_type > e1000_82547_rev_2)
Auke Kok's avatar
Auke Kok committed
1000
		netdev->features |= NETIF_F_TSO6;
1001
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1002
#endif
1003
	if (pci_using_dac)
Linus Torvalds's avatar
Linus Torvalds committed
1004
1005
		netdev->features |= NETIF_F_HIGHDMA;

1006
1007
	netdev->features |= NETIF_F_LLTX;

1008
1009
	adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);

1010
1011
1012
1013
	/* initialize eeprom parameters */

	if (e1000_init_eeprom_params(&adapter->hw)) {
		E1000_ERR("EEPROM initialization failed\n");
1014
		goto err_eeprom;
1015
1016
	}

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

Linus Torvalds's avatar
Linus Torvalds committed
1020
1021
1022
1023
	e1000_reset_hw(&adapter->hw);

	/* make sure the EEPROM is good */

1024
	if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
Linus Torvalds's avatar
Linus Torvalds committed
1025
1026
1027
1028
1029
1030
		DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
		goto err_eeprom;
	}

	/* copy the MAC address out of the EEPROM */

1031
	if (e1000_read_mac_addr(&adapter->hw))
Linus Torvalds's avatar
Linus Torvalds committed
1032
1033
		DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
	memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
1034
	memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
Linus Torvalds's avatar
Linus Torvalds committed
1035

1036
	if (!is_valid_ether_addr(netdev->perm_addr)) {
Linus Torvalds's avatar
Linus Torvalds committed
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
		DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
		goto err_eeprom;
	}

	e1000_get_bus_info(&adapter->hw);

	init_timer(&adapter->tx_fifo_stall_timer);
	adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
	adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;

	init_timer(&adapter->watchdog_timer);
	adapter->watchdog_timer.function = &e1000_watchdog;
	adapter->watchdog_timer.data = (unsigned long) adapter;

	init_timer(&adapter->phy_info_timer);
	adapter->phy_info_timer.function = &e1000_update_phy_info;
	adapter->phy_info_timer.data = (unsigned long) adapter;

1055
	INIT_WORK(&adapter->reset_task, e1000_reset_task);
Linus Torvalds's avatar
Linus Torvalds committed
1056
1057
1058
1059
1060
1061
1062
1063

	e1000_check_options(adapter);

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

1064
	switch (adapter->hw.mac_type) {
Linus Torvalds's avatar
Linus Torvalds committed
1065
1066
1067
1068
1069
1070
1071
1072
1073
	case e1000_82542_rev2_0:
	case e1000_82542_rev2_1:
	case e1000_82543:
		break;
	case e1000_82544:
		e1000_read_eeprom(&adapter->hw,
			EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
		eeprom_apme_mask = E1000_EEPROM_82544_APM;
		break;
1074
1075
1076
1077
1078
	case e1000_ich8lan:
		e1000_read_eeprom(&adapter->hw,
			EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
		eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
		break;
Linus Torvalds's avatar
Linus Torvalds committed
1079
1080
	case e1000_82546:
	case e1000_82546_rev_3:
Jeff Kirsher's avatar
Jeff Kirsher committed
1081
	case e1000_82571:
1082
	case e1000_80003es2lan:
1083
		if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
Linus Torvalds's avatar
Linus Torvalds committed
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
			e1000_read_eeprom(&adapter->hw,
				EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
			break;
		}
		/* Fall Through */
	default:
		e1000_read_eeprom(&adapter->hw,
			EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
		break;
	}
1094
	if (eeprom_data & eeprom_apme_mask)
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
		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:
	case E1000_DEV_ID_82571EB_FIBER:
		/* Wake events only supported on port A for dual fiber
		 * regardless of eeprom setting */
		if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
			adapter->eeprom_wol = 0;
		break;
	case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1113
	case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kok's avatar
Auke Kok committed
1114
	case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
		/* 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;
Linus Torvalds's avatar
Linus Torvalds committed
1128

1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
	/* print bus type/speed/width info */
	{
	struct e1000_hw *hw = &adapter->hw;
	DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
		((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
		 (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
		((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
		 (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
		 (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
		 (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
		 (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
		((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
		 (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
		 (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
		 "32-bit"));
	}

	for (i = 0; i < 6; i++)
		printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');

Linus Torvalds's avatar
Linus Torvalds committed
1149
1150
1151
	/* reset the hardware with the new settings */
	e1000_reset(adapter);

1152
1153
1154
1155
1156
1157
1158
	/* If the controller is 82573 and f/w is AMT, do not set
	 * DRV_LOAD until the interface is up.  For all other cases,
	 * let the f/w know that the h/w is now under the control
	 * of the driver. */
	if (adapter->hw.mac_type != e1000_82573 ||
	    !e1000_check_mng_mode(&adapter->hw))
		e1000_get_hw_control(adapter);
1159

Linus Torvalds's avatar
Linus Torvalds committed
1160
	strcpy(netdev->name, "eth%d");
1161
	if ((err = register_netdev(netdev)))
Linus Torvalds's avatar
Linus Torvalds committed
1162
1163
		goto err_register;

1164
1165
1166
1167
	/* tell the stack to leave us alone until e1000_open() is called */
	netif_carrier_off(netdev);
	netif_stop_queue(netdev);

Linus Torvalds's avatar
Linus Torvalds committed
1168
1169
1170
1171
1172
1173
	DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");

	cards_found++;
	return 0;

err_register:
1174
1175
1176
1177
1178
	e1000_release_hw_control(adapter);
err_eeprom:
	if (!e1000_check_phy_reset_block(&adapter->hw))
		e1000_phy_hw_reset(&adapter->hw);

1179
1180
1181
	if (adapter->hw.flash_address)
		iounmap(adapter->hw.flash_address);
err_flashmap:
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
#ifdef CONFIG_E1000_NAPI
	for (i = 0; i < adapter->num_rx_queues; i++)
		dev_put(&adapter->polling_netdev[i]);
#endif

	kfree(adapter->tx_ring);
	kfree(adapter->rx_ring);
#ifdef CONFIG_E1000_NAPI
	kfree(adapter->polling_netdev);
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1192
1193
1194
1195
1196
1197
err_sw_init:
	iounmap(adapter->hw.hw_addr);
err_ioremap:
	free_netdev(netdev);
err_alloc_etherdev:
	pci_release_regions(pdev);
1198
1199
1200
err_pci_reg:
err_dma:
	pci_disable_device(pdev);
Linus Torvalds's avatar
Linus Torvalds committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
	return err;
}

/**
 * e1000_remove - Device Removal Routine
 * @pdev: PCI device information struct
 *
 * e1000_remove is called by the PCI subsystem to alert the driver
 * that it should release a PCI device.  The could be caused by a
 * Hot-Plug event, or because the driver is going to be removed from
 * memory.
 **/

static void __devexit
e1000_remove(struct pci_dev *pdev)
{
	struct net_device *netdev = pci_get_drvdata(pdev);
1218
	struct e1000_adapter *adapter = netdev_priv(netdev);
1219
1220
1221
#ifdef CONFIG_E1000_NAPI
	int i;
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1222

Jeff Garzik's avatar
Jeff Garzik committed
1223
1224
	flush_scheduled_work();

1225
	e1000_release_manageability(adapter);
Linus Torvalds's avatar
Linus Torvalds committed
1226

1227
1228
1229
	/* Release control of h/w to f/w.  If f/w is AMT enabled, this
	 * would have already happened in close and is redundant. */
	e1000_release_hw_control(adapter);
1230

Linus Torvalds's avatar
Linus Torvalds committed
1231
	unregister_netdev(netdev);
1232
#ifdef CONFIG_E1000_NAPI
1233
	for (i = 0; i < adapter->num_rx_queues; i++)
1234
		dev_put(&adapter->polling_netdev[i]);
1235
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1236

1237
	if (!e1000_check_phy_reset_block(&adapter->hw))
1238
		e1000_phy_hw_reset(&adapter->hw);
Linus Torvalds's avatar
Linus Torvalds committed
1239

1240
1241
1242
1243
1244
1245
	kfree(adapter->tx_ring);
	kfree(adapter->rx_ring);
#ifdef CONFIG_E1000_NAPI
	kfree(adapter->polling_netdev);
#endif

Linus Torvalds's avatar
Linus Torvalds committed
1246
	iounmap(adapter->hw.hw_addr);
1247
1248
	if (adapter->hw.flash_address)
		iounmap(adapter->hw.flash_address);
Linus Torvalds's avatar
Linus Torvalds committed
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
	pci_release_regions(pdev);

	free_netdev(netdev);

	pci_disable_device(pdev);
}

/**
 * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
 * @adapter: board private structure to initialize
 *
 * e1000_sw_init initializes the Adapter private data structure.
 * Fields are initialized based on PCI device information and
 * OS network device settings (MTU size).
 **/

static int __devinit
e1000_sw_init(struct e1000_adapter *adapter)
{
	struct e1000_hw *hw = &adapter->hw;
	struct net_device *netdev = adapter->netdev;
	struct pci_dev *pdev = adapter->pdev;
1271
1272
1273
#ifdef CONFIG_E1000_NAPI
	int i;
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285

	/* 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;

	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);

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

1286
	adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1287
	adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
Linus Torvalds's avatar
Linus Torvalds committed
1288
1289
1290
1291
1292
1293
	hw->max_frame_size = netdev->mtu +
			     ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
	hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;

	/* identify the MAC */

1294
	if (e1000_set_mac_type(hw)) {
Linus Torvalds's avatar
Linus Torvalds committed
1295
1296
1297
1298
		DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
		return -EIO;
	}

1299
	switch (hw->mac_type) {
Linus Torvalds's avatar
Linus Torvalds committed
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
	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);

	hw->wait_autoneg_complete = FALSE;
	hw->tbi_compatibility_en = TRUE;
	hw->adaptive_ifs = TRUE;

	/* Copper options */

1318
	if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds's avatar
Linus Torvalds committed
1319
1320
1321
1322
1323
		hw->mdix = AUTO_ALL_MODES;
		hw->disable_polarity_correction = FALSE;
		hw->master_slave = E1000_MASTER_SLAVE;
	}

1324
1325
	adapter->num_tx_queues = 1;
	adapter->num_rx_queues = 1;
1326
1327
1328
1329
1330
1331
1332

	if (e1000_alloc_queues(adapter)) {
		DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
		return -ENOMEM;
	}

#ifdef CONFIG_E1000_NAPI
1333
	for (i = 0; i < adapter->num_rx_queues; i++) {
1334
1335
1336
1337
1338
1339
		adapter->polling_netdev[i].priv = adapter;
		adapter->polling_netdev[i].poll = &e1000_clean;
		adapter->polling_netdev[i].weight = 64;
		dev_hold(&adapter->polling_netdev[i]);
		set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
	}
1340
	spin_lock_init(&adapter->tx_queue_lock);
1341
1342
#endif

Linus Torvalds's avatar
Linus Torvalds committed
1343
1344
1345
	atomic_set(&adapter->irq_sem, 1);
	spin_lock_init(&adapter->stats_lock);

1346
1347
	set_bit(__E1000_DOWN, &adapter->flags);

Linus Torvalds's avatar
Linus Torvalds committed
1348
1349
1350
	return 0;
}

1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
/**
 * e1000_alloc_queues - Allocate memory for all rings
 * @adapter: board private structure to initialize
 *
 * We allocate one ring per queue at run-time since we don't know the
 * number of queues at compile-time.  The polling_netdev array is
 * intended for Multiqueue, but should work fine with a single queue.
 **/

static int __devinit
e1000_alloc_queues(struct e1000_adapter *adapter)
{
	int size;

1365
	size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1366
1367
1368
1369
1370
	adapter->tx_ring = kmalloc(size, GFP_KERNEL);
	if (!adapter->tx_ring)
		return -ENOMEM;
	memset(adapter->tx_ring, 0, size);

1371
	size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1372
1373
1374
1375
1376
1377
1378
1379
	adapter->rx_ring = kmalloc(size, GFP_KERNEL);
	if (!adapter->rx_ring) {
		kfree(adapter->tx_ring);
		return -ENOMEM;
	}
	memset(adapter->rx_ring, 0, size);

#ifdef CONFIG_E1000_NAPI
1380
	size = sizeof(struct net_device) * adapter->num_rx_queues;
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
	adapter->pol