]> Pileus Git - ~andy/linux/blob - drivers/net/e1000/e1000_main.c
[PATCH] e1000: Added copy break code
[~andy/linux] / drivers / net / e1000 / e1000_main.c
1 /*******************************************************************************
2
3   
4   Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
5   
6   This program is free software; you can redistribute it and/or modify it 
7   under the terms of the GNU General Public License as published by the Free 
8   Software Foundation; either version 2 of the License, or (at your option) 
9   any later version.
10   
11   This program is distributed in the hope that it will be useful, but WITHOUT 
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
14   more details.
15   
16   You should have received a copy of the GNU General Public License along with
17   this program; if not, write to the Free Software Foundation, Inc., 59 
18   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19   
20   The full GNU General Public License is included in this distribution in the
21   file called LICENSE.
22   
23   Contact Information:
24   Linux NICS <linux.nics@intel.com>
25   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27 *******************************************************************************/
28
29 #include "e1000.h"
30
31 /* Change Log
32  * 6.0.58       4/20/05
33  *   o Accepted ethtool cleanup patch from Stephen Hemminger 
34  * 6.0.44+      2/15/05
35  *   o applied Anton's patch to resolve tx hang in hardware
36  *   o Applied Andrew Mortons patch - e1000 stops working after resume
37  */
38
39 char e1000_driver_name[] = "e1000";
40 static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
41 #ifndef CONFIG_E1000_NAPI
42 #define DRIVERNAPI
43 #else
44 #define DRIVERNAPI "-NAPI"
45 #endif
46 #define DRV_VERSION "6.3.9-k2"DRIVERNAPI
47 char e1000_driver_version[] = DRV_VERSION;
48 static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
49
50 /* e1000_pci_tbl - PCI Device ID Table
51  *
52  * Last entry must be all 0s
53  *
54  * Macro expands to...
55  *   {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
56  */
57 static struct pci_device_id e1000_pci_tbl[] = {
58         INTEL_E1000_ETHERNET_DEVICE(0x1000),
59         INTEL_E1000_ETHERNET_DEVICE(0x1001),
60         INTEL_E1000_ETHERNET_DEVICE(0x1004),
61         INTEL_E1000_ETHERNET_DEVICE(0x1008),
62         INTEL_E1000_ETHERNET_DEVICE(0x1009),
63         INTEL_E1000_ETHERNET_DEVICE(0x100C),
64         INTEL_E1000_ETHERNET_DEVICE(0x100D),
65         INTEL_E1000_ETHERNET_DEVICE(0x100E),
66         INTEL_E1000_ETHERNET_DEVICE(0x100F),
67         INTEL_E1000_ETHERNET_DEVICE(0x1010),
68         INTEL_E1000_ETHERNET_DEVICE(0x1011),
69         INTEL_E1000_ETHERNET_DEVICE(0x1012),
70         INTEL_E1000_ETHERNET_DEVICE(0x1013),
71         INTEL_E1000_ETHERNET_DEVICE(0x1014),
72         INTEL_E1000_ETHERNET_DEVICE(0x1015),
73         INTEL_E1000_ETHERNET_DEVICE(0x1016),
74         INTEL_E1000_ETHERNET_DEVICE(0x1017),
75         INTEL_E1000_ETHERNET_DEVICE(0x1018),
76         INTEL_E1000_ETHERNET_DEVICE(0x1019),
77         INTEL_E1000_ETHERNET_DEVICE(0x101A),
78         INTEL_E1000_ETHERNET_DEVICE(0x101D),
79         INTEL_E1000_ETHERNET_DEVICE(0x101E),
80         INTEL_E1000_ETHERNET_DEVICE(0x1026),
81         INTEL_E1000_ETHERNET_DEVICE(0x1027),
82         INTEL_E1000_ETHERNET_DEVICE(0x1028),
83         INTEL_E1000_ETHERNET_DEVICE(0x105E),
84         INTEL_E1000_ETHERNET_DEVICE(0x105F),
85         INTEL_E1000_ETHERNET_DEVICE(0x1060),
86         INTEL_E1000_ETHERNET_DEVICE(0x1075),
87         INTEL_E1000_ETHERNET_DEVICE(0x1076),
88         INTEL_E1000_ETHERNET_DEVICE(0x1077),
89         INTEL_E1000_ETHERNET_DEVICE(0x1078),
90         INTEL_E1000_ETHERNET_DEVICE(0x1079),
91         INTEL_E1000_ETHERNET_DEVICE(0x107A),
92         INTEL_E1000_ETHERNET_DEVICE(0x107B),
93         INTEL_E1000_ETHERNET_DEVICE(0x107C),
94         INTEL_E1000_ETHERNET_DEVICE(0x107D),
95         INTEL_E1000_ETHERNET_DEVICE(0x107E),
96         INTEL_E1000_ETHERNET_DEVICE(0x107F),
97         INTEL_E1000_ETHERNET_DEVICE(0x108A),
98         INTEL_E1000_ETHERNET_DEVICE(0x108B),
99         INTEL_E1000_ETHERNET_DEVICE(0x108C),
100         INTEL_E1000_ETHERNET_DEVICE(0x1099),
101         INTEL_E1000_ETHERNET_DEVICE(0x109A),
102         INTEL_E1000_ETHERNET_DEVICE(0x10B5),
103         /* required last entry */
104         {0,}
105 };
106
107 MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
108
109 int e1000_up(struct e1000_adapter *adapter);
110 void e1000_down(struct e1000_adapter *adapter);
111 void e1000_reset(struct e1000_adapter *adapter);
112 int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
113 int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
114 int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
115 void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
116 void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
117 static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
118                                     struct e1000_tx_ring *txdr);
119 static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
120                                     struct e1000_rx_ring *rxdr);
121 static void e1000_free_tx_resources(struct e1000_adapter *adapter,
122                                     struct e1000_tx_ring *tx_ring);
123 static void e1000_free_rx_resources(struct e1000_adapter *adapter,
124                                     struct e1000_rx_ring *rx_ring);
125 void e1000_update_stats(struct e1000_adapter *adapter);
126
127 /* Local Function Prototypes */
128
129 static int e1000_init_module(void);
130 static void e1000_exit_module(void);
131 static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
132 static void __devexit e1000_remove(struct pci_dev *pdev);
133 static int e1000_alloc_queues(struct e1000_adapter *adapter);
134 #ifdef CONFIG_E1000_MQ
135 static void e1000_setup_queue_mapping(struct e1000_adapter *adapter);
136 #endif
137 static int e1000_sw_init(struct e1000_adapter *adapter);
138 static int e1000_open(struct net_device *netdev);
139 static int e1000_close(struct net_device *netdev);
140 static void e1000_configure_tx(struct e1000_adapter *adapter);
141 static void e1000_configure_rx(struct e1000_adapter *adapter);
142 static void e1000_setup_rctl(struct e1000_adapter *adapter);
143 static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
144 static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
145 static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
146                                 struct e1000_tx_ring *tx_ring);
147 static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
148                                 struct e1000_rx_ring *rx_ring);
149 static void e1000_set_multi(struct net_device *netdev);
150 static void e1000_update_phy_info(unsigned long data);
151 static void e1000_watchdog(unsigned long data);
152 static void e1000_watchdog_task(struct e1000_adapter *adapter);
153 static void e1000_82547_tx_fifo_stall(unsigned long data);
154 static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
155 static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
156 static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
157 static int e1000_set_mac(struct net_device *netdev, void *p);
158 static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs);
159 static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
160                                     struct e1000_tx_ring *tx_ring);
161 #ifdef CONFIG_E1000_NAPI
162 static int e1000_clean(struct net_device *poll_dev, int *budget);
163 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
164                                     struct e1000_rx_ring *rx_ring,
165                                     int *work_done, int work_to_do);
166 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
167                                        struct e1000_rx_ring *rx_ring,
168                                        int *work_done, int work_to_do);
169 #else
170 static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
171                                     struct e1000_rx_ring *rx_ring);
172 static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
173                                        struct e1000_rx_ring *rx_ring);
174 #endif
175 static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
176                                    struct e1000_rx_ring *rx_ring,
177                                    int cleaned_count);
178 static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
179                                       struct e1000_rx_ring *rx_ring,
180                                       int cleaned_count);
181 static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
182 static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
183                            int cmd);
184 void e1000_set_ethtool_ops(struct net_device *netdev);
185 static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
186 static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
187 static void e1000_tx_timeout(struct net_device *dev);
188 static void e1000_tx_timeout_task(struct net_device *dev);
189 static void e1000_smartspeed(struct e1000_adapter *adapter);
190 static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
191                                               struct sk_buff *skb);
192
193 static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
194 static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
195 static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
196 static void e1000_restore_vlan(struct e1000_adapter *adapter);
197
198 #ifdef CONFIG_PM
199 static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
200 static int e1000_resume(struct pci_dev *pdev);
201 #endif
202
203 #ifdef CONFIG_NET_POLL_CONTROLLER
204 /* for netdump / net console */
205 static void e1000_netpoll (struct net_device *netdev);
206 #endif
207
208 #ifdef CONFIG_E1000_MQ
209 /* for multiple Rx queues */
210 void e1000_rx_schedule(void *data);
211 #endif
212
213 /* Exported from other modules */
214
215 extern void e1000_check_options(struct e1000_adapter *adapter);
216
217 static struct pci_driver e1000_driver = {
218         .name     = e1000_driver_name,
219         .id_table = e1000_pci_tbl,
220         .probe    = e1000_probe,
221         .remove   = __devexit_p(e1000_remove),
222         /* Power Managment Hooks */
223 #ifdef CONFIG_PM
224         .suspend  = e1000_suspend,
225         .resume   = e1000_resume
226 #endif
227 };
228
229 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
230 MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
231 MODULE_LICENSE("GPL");
232 MODULE_VERSION(DRV_VERSION);
233
234 static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
235 module_param(debug, int, 0);
236 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
237
238 /**
239  * e1000_init_module - Driver Registration Routine
240  *
241  * e1000_init_module is the first routine called when the driver is
242  * loaded. All it does is register with the PCI subsystem.
243  **/
244
245 static int __init
246 e1000_init_module(void)
247 {
248         int ret;
249         printk(KERN_INFO "%s - version %s\n",
250                e1000_driver_string, e1000_driver_version);
251
252         printk(KERN_INFO "%s\n", e1000_copyright);
253
254         ret = pci_module_init(&e1000_driver);
255
256         return ret;
257 }
258
259 module_init(e1000_init_module);
260
261 /**
262  * e1000_exit_module - Driver Exit Cleanup Routine
263  *
264  * e1000_exit_module is called just before the driver is removed
265  * from memory.
266  **/
267
268 static void __exit
269 e1000_exit_module(void)
270 {
271         pci_unregister_driver(&e1000_driver);
272 }
273
274 module_exit(e1000_exit_module);
275
276 /**
277  * e1000_irq_disable - Mask off interrupt generation on the NIC
278  * @adapter: board private structure
279  **/
280
281 static inline void
282 e1000_irq_disable(struct e1000_adapter *adapter)
283 {
284         atomic_inc(&adapter->irq_sem);
285         E1000_WRITE_REG(&adapter->hw, IMC, ~0);
286         E1000_WRITE_FLUSH(&adapter->hw);
287         synchronize_irq(adapter->pdev->irq);
288 }
289
290 /**
291  * e1000_irq_enable - Enable default interrupt generation settings
292  * @adapter: board private structure
293  **/
294
295 static inline void
296 e1000_irq_enable(struct e1000_adapter *adapter)
297 {
298         if(likely(atomic_dec_and_test(&adapter->irq_sem))) {
299                 E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
300                 E1000_WRITE_FLUSH(&adapter->hw);
301         }
302 }
303
304 static void
305 e1000_update_mng_vlan(struct e1000_adapter *adapter)
306 {
307         struct net_device *netdev = adapter->netdev;
308         uint16_t vid = adapter->hw.mng_cookie.vlan_id;
309         uint16_t old_vid = adapter->mng_vlan_id;
310         if(adapter->vlgrp) {
311                 if(!adapter->vlgrp->vlan_devices[vid]) {
312                         if(adapter->hw.mng_cookie.status &
313                                 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
314                                 e1000_vlan_rx_add_vid(netdev, vid);
315                                 adapter->mng_vlan_id = vid;
316                         } else
317                                 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
318                                 
319                         if((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
320                                         (vid != old_vid) && 
321                                         !adapter->vlgrp->vlan_devices[old_vid])
322                                 e1000_vlan_rx_kill_vid(netdev, old_vid);
323                 }
324         }
325 }
326
327 /**
328  * e1000_release_hw_control - release control of the h/w to f/w
329  * @adapter: address of board private structure
330  *
331  * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
332  * For ASF and Pass Through versions of f/w this means that the
333  * driver is no longer loaded. For AMT version (only with 82573) i
334  * of the f/w this means that the netowrk i/f is closed.
335  * 
336  **/
337
338 static inline void 
339 e1000_release_hw_control(struct e1000_adapter *adapter)
340 {
341         uint32_t ctrl_ext;
342         uint32_t swsm;
343
344         /* Let firmware taken over control of h/w */
345         switch (adapter->hw.mac_type) {
346         case e1000_82571:
347         case e1000_82572:
348                 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
349                 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
350                                 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
351                 break;
352         case e1000_82573:
353                 swsm = E1000_READ_REG(&adapter->hw, SWSM);
354                 E1000_WRITE_REG(&adapter->hw, SWSM,
355                                 swsm & ~E1000_SWSM_DRV_LOAD);
356         default:
357                 break;
358         }
359 }
360
361 /**
362  * e1000_get_hw_control - get control of the h/w from f/w
363  * @adapter: address of board private structure
364  *
365  * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
366  * For ASF and Pass Through versions of f/w this means that 
367  * the driver is loaded. For AMT version (only with 82573) 
368  * of the f/w this means that the netowrk i/f is open.
369  * 
370  **/
371
372 static inline void 
373 e1000_get_hw_control(struct e1000_adapter *adapter)
374 {
375         uint32_t ctrl_ext;
376         uint32_t swsm;
377         /* Let firmware know the driver has taken over */
378         switch (adapter->hw.mac_type) {
379         case e1000_82571:
380         case e1000_82572:
381                 ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
382                 E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
383                                 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
384                 break;
385         case e1000_82573:
386                 swsm = E1000_READ_REG(&adapter->hw, SWSM);
387                 E1000_WRITE_REG(&adapter->hw, SWSM,
388                                 swsm | E1000_SWSM_DRV_LOAD);
389                 break;
390         default:
391                 break;
392         }
393 }
394
395 int
396 e1000_up(struct e1000_adapter *adapter)
397 {
398         struct net_device *netdev = adapter->netdev;
399         int i, err;
400
401         /* hardware has been reset, we need to reload some things */
402
403         /* Reset the PHY if it was previously powered down */
404         if(adapter->hw.media_type == e1000_media_type_copper) {
405                 uint16_t mii_reg;
406                 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
407                 if(mii_reg & MII_CR_POWER_DOWN)
408                         e1000_phy_reset(&adapter->hw);
409         }
410
411         e1000_set_multi(netdev);
412
413         e1000_restore_vlan(adapter);
414
415         e1000_configure_tx(adapter);
416         e1000_setup_rctl(adapter);
417         e1000_configure_rx(adapter);
418         /* call E1000_DESC_UNUSED which always leaves
419          * at least 1 descriptor unused to make sure
420          * next_to_use != next_to_clean */
421         for (i = 0; i < adapter->num_rx_queues; i++) {
422                 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
423                 adapter->alloc_rx_buf(adapter, ring,
424                                       E1000_DESC_UNUSED(ring));
425         }
426
427 #ifdef CONFIG_PCI_MSI
428         if(adapter->hw.mac_type > e1000_82547_rev_2) {
429                 adapter->have_msi = TRUE;
430                 if((err = pci_enable_msi(adapter->pdev))) {
431                         DPRINTK(PROBE, ERR,
432                          "Unable to allocate MSI interrupt Error: %d\n", err);
433                         adapter->have_msi = FALSE;
434                 }
435         }
436 #endif
437         if((err = request_irq(adapter->pdev->irq, &e1000_intr,
438                               SA_SHIRQ | SA_SAMPLE_RANDOM,
439                               netdev->name, netdev))) {
440                 DPRINTK(PROBE, ERR,
441                     "Unable to allocate interrupt Error: %d\n", err);
442                 return err;
443         }
444
445 #ifdef CONFIG_E1000_MQ
446         e1000_setup_queue_mapping(adapter);
447 #endif
448
449         adapter->tx_queue_len = netdev->tx_queue_len;
450
451         mod_timer(&adapter->watchdog_timer, jiffies);
452
453 #ifdef CONFIG_E1000_NAPI
454         netif_poll_enable(netdev);
455 #endif
456         e1000_irq_enable(adapter);
457
458         return 0;
459 }
460
461 void
462 e1000_down(struct e1000_adapter *adapter)
463 {
464         struct net_device *netdev = adapter->netdev;
465         boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) &&
466                                      e1000_check_mng_mode(&adapter->hw);
467
468         e1000_irq_disable(adapter);
469 #ifdef CONFIG_E1000_MQ
470         while (atomic_read(&adapter->rx_sched_call_data.count) != 0);
471 #endif
472         free_irq(adapter->pdev->irq, netdev);
473 #ifdef CONFIG_PCI_MSI
474         if(adapter->hw.mac_type > e1000_82547_rev_2 &&
475            adapter->have_msi == TRUE)
476                 pci_disable_msi(adapter->pdev);
477 #endif
478         del_timer_sync(&adapter->tx_fifo_stall_timer);
479         del_timer_sync(&adapter->watchdog_timer);
480         del_timer_sync(&adapter->phy_info_timer);
481
482 #ifdef CONFIG_E1000_NAPI
483         netif_poll_disable(netdev);
484 #endif
485         netdev->tx_queue_len = adapter->tx_queue_len;
486         adapter->link_speed = 0;
487         adapter->link_duplex = 0;
488         netif_carrier_off(netdev);
489         netif_stop_queue(netdev);
490
491         e1000_reset(adapter);
492         e1000_clean_all_tx_rings(adapter);
493         e1000_clean_all_rx_rings(adapter);
494
495         /* Power down the PHY so no link is implied when interface is down *
496          * The PHY cannot be powered down if any of the following is TRUE *
497          * (a) WoL is enabled
498          * (b) AMT is active
499          * (c) SoL/IDER session is active */
500         if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
501            adapter->hw.media_type == e1000_media_type_copper &&
502            !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) &&
503            !mng_mode_enabled &&
504            !e1000_check_phy_reset_block(&adapter->hw)) {
505                 uint16_t mii_reg;
506                 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
507                 mii_reg |= MII_CR_POWER_DOWN;
508                 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
509                 mdelay(1);
510         }
511 }
512
513 void
514 e1000_reset(struct e1000_adapter *adapter)
515 {
516         uint32_t pba, manc;
517         uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
518
519         /* Repartition Pba for greater than 9k mtu
520          * To take effect CTRL.RST is required.
521          */
522
523         switch (adapter->hw.mac_type) {
524         case e1000_82547:
525         case e1000_82547_rev_2:
526                 pba = E1000_PBA_30K;
527                 break;
528         case e1000_82571:
529         case e1000_82572:
530                 pba = E1000_PBA_38K;
531                 break;
532         case e1000_82573:
533                 pba = E1000_PBA_12K;
534                 break;
535         default:
536                 pba = E1000_PBA_48K;
537                 break;
538         }
539
540         if((adapter->hw.mac_type != e1000_82573) &&
541            (adapter->netdev->mtu > E1000_RXBUFFER_8192))
542                 pba -= 8; /* allocate more FIFO for Tx */
543
544
545         if(adapter->hw.mac_type == e1000_82547) {
546                 adapter->tx_fifo_head = 0;
547                 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
548                 adapter->tx_fifo_size =
549                         (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
550                 atomic_set(&adapter->tx_fifo_stall, 0);
551         }
552
553         E1000_WRITE_REG(&adapter->hw, PBA, pba);
554
555         /* flow control settings */
556         /* Set the FC high water mark to 90% of the FIFO size.
557          * Required to clear last 3 LSB */
558         fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
559
560         adapter->hw.fc_high_water = fc_high_water_mark;
561         adapter->hw.fc_low_water = fc_high_water_mark - 8;
562         adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
563         adapter->hw.fc_send_xon = 1;
564         adapter->hw.fc = adapter->hw.original_fc;
565
566         /* Allow time for pending master requests to run */
567         e1000_reset_hw(&adapter->hw);
568         if(adapter->hw.mac_type >= e1000_82544)
569                 E1000_WRITE_REG(&adapter->hw, WUC, 0);
570         if(e1000_init_hw(&adapter->hw))
571                 DPRINTK(PROBE, ERR, "Hardware Error\n");
572         e1000_update_mng_vlan(adapter);
573         /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
574         E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
575
576         e1000_reset_adaptive(&adapter->hw);
577         e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
578         if (adapter->en_mng_pt) {
579                 manc = E1000_READ_REG(&adapter->hw, MANC);
580                 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
581                 E1000_WRITE_REG(&adapter->hw, MANC, manc);
582         }
583 }
584
585 /**
586  * e1000_probe - Device Initialization Routine
587  * @pdev: PCI device information struct
588  * @ent: entry in e1000_pci_tbl
589  *
590  * Returns 0 on success, negative on failure
591  *
592  * e1000_probe initializes an adapter identified by a pci_dev structure.
593  * The OS initialization, configuring of the adapter private structure,
594  * and a hardware reset occur.
595  **/
596
597 static int __devinit
598 e1000_probe(struct pci_dev *pdev,
599             const struct pci_device_id *ent)
600 {
601         struct net_device *netdev;
602         struct e1000_adapter *adapter;
603         unsigned long mmio_start, mmio_len;
604
605         static int cards_found = 0;
606         int i, err, pci_using_dac;
607         uint16_t eeprom_data;
608         uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
609         if((err = pci_enable_device(pdev)))
610                 return err;
611
612         if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
613                 pci_using_dac = 1;
614         } else {
615                 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
616                         E1000_ERR("No usable DMA configuration, aborting\n");
617                         return err;
618                 }
619                 pci_using_dac = 0;
620         }
621
622         if((err = pci_request_regions(pdev, e1000_driver_name)))
623                 return err;
624
625         pci_set_master(pdev);
626
627         netdev = alloc_etherdev(sizeof(struct e1000_adapter));
628         if(!netdev) {
629                 err = -ENOMEM;
630                 goto err_alloc_etherdev;
631         }
632
633         SET_MODULE_OWNER(netdev);
634         SET_NETDEV_DEV(netdev, &pdev->dev);
635
636         pci_set_drvdata(pdev, netdev);
637         adapter = netdev_priv(netdev);
638         adapter->netdev = netdev;
639         adapter->pdev = pdev;
640         adapter->hw.back = adapter;
641         adapter->msg_enable = (1 << debug) - 1;
642
643         mmio_start = pci_resource_start(pdev, BAR_0);
644         mmio_len = pci_resource_len(pdev, BAR_0);
645
646         adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
647         if(!adapter->hw.hw_addr) {
648                 err = -EIO;
649                 goto err_ioremap;
650         }
651
652         for(i = BAR_1; i <= BAR_5; i++) {
653                 if(pci_resource_len(pdev, i) == 0)
654                         continue;
655                 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
656                         adapter->hw.io_base = pci_resource_start(pdev, i);
657                         break;
658                 }
659         }
660
661         netdev->open = &e1000_open;
662         netdev->stop = &e1000_close;
663         netdev->hard_start_xmit = &e1000_xmit_frame;
664         netdev->get_stats = &e1000_get_stats;
665         netdev->set_multicast_list = &e1000_set_multi;
666         netdev->set_mac_address = &e1000_set_mac;
667         netdev->change_mtu = &e1000_change_mtu;
668         netdev->do_ioctl = &e1000_ioctl;
669         e1000_set_ethtool_ops(netdev);
670         netdev->tx_timeout = &e1000_tx_timeout;
671         netdev->watchdog_timeo = 5 * HZ;
672 #ifdef CONFIG_E1000_NAPI
673         netdev->poll = &e1000_clean;
674         netdev->weight = 64;
675 #endif
676         netdev->vlan_rx_register = e1000_vlan_rx_register;
677         netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
678         netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
679 #ifdef CONFIG_NET_POLL_CONTROLLER
680         netdev->poll_controller = e1000_netpoll;
681 #endif
682         strcpy(netdev->name, pci_name(pdev));
683
684         netdev->mem_start = mmio_start;
685         netdev->mem_end = mmio_start + mmio_len;
686         netdev->base_addr = adapter->hw.io_base;
687
688         adapter->bd_number = cards_found;
689
690         /* setup the private structure */
691
692         if((err = e1000_sw_init(adapter)))
693                 goto err_sw_init;
694
695         if((err = e1000_check_phy_reset_block(&adapter->hw)))
696                 DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
697
698         if(adapter->hw.mac_type >= e1000_82543) {
699                 netdev->features = NETIF_F_SG |
700                                    NETIF_F_HW_CSUM |
701                                    NETIF_F_HW_VLAN_TX |
702                                    NETIF_F_HW_VLAN_RX |
703                                    NETIF_F_HW_VLAN_FILTER;
704         }
705
706 #ifdef NETIF_F_TSO
707         if((adapter->hw.mac_type >= e1000_82544) &&
708            (adapter->hw.mac_type != e1000_82547))
709                 netdev->features |= NETIF_F_TSO;
710
711 #ifdef NETIF_F_TSO_IPV6
712         if(adapter->hw.mac_type > e1000_82547_rev_2)
713                 netdev->features |= NETIF_F_TSO_IPV6;
714 #endif
715 #endif
716         if(pci_using_dac)
717                 netdev->features |= NETIF_F_HIGHDMA;
718
719         /* hard_start_xmit is safe against parallel locking */
720         netdev->features |= NETIF_F_LLTX; 
721  
722         adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
723
724         /* before reading the EEPROM, reset the controller to 
725          * put the device in a known good starting state */
726         
727         e1000_reset_hw(&adapter->hw);
728
729         /* make sure the EEPROM is good */
730
731         if(e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
732                 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
733                 err = -EIO;
734                 goto err_eeprom;
735         }
736
737         /* copy the MAC address out of the EEPROM */
738
739         if(e1000_read_mac_addr(&adapter->hw))
740                 DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
741         memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
742         memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
743
744         if(!is_valid_ether_addr(netdev->perm_addr)) {
745                 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
746                 err = -EIO;
747                 goto err_eeprom;
748         }
749
750         e1000_read_part_num(&adapter->hw, &(adapter->part_num));
751
752         e1000_get_bus_info(&adapter->hw);
753
754         init_timer(&adapter->tx_fifo_stall_timer);
755         adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
756         adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
757
758         init_timer(&adapter->watchdog_timer);
759         adapter->watchdog_timer.function = &e1000_watchdog;
760         adapter->watchdog_timer.data = (unsigned long) adapter;
761
762         INIT_WORK(&adapter->watchdog_task,
763                 (void (*)(void *))e1000_watchdog_task, adapter);
764
765         init_timer(&adapter->phy_info_timer);
766         adapter->phy_info_timer.function = &e1000_update_phy_info;
767         adapter->phy_info_timer.data = (unsigned long) adapter;
768
769         INIT_WORK(&adapter->tx_timeout_task,
770                 (void (*)(void *))e1000_tx_timeout_task, netdev);
771
772         /* we're going to reset, so assume we have no link for now */
773
774         netif_carrier_off(netdev);
775         netif_stop_queue(netdev);
776
777         e1000_check_options(adapter);
778
779         /* Initial Wake on LAN setting
780          * If APM wake is enabled in the EEPROM,
781          * enable the ACPI Magic Packet filter
782          */
783
784         switch(adapter->hw.mac_type) {
785         case e1000_82542_rev2_0:
786         case e1000_82542_rev2_1:
787         case e1000_82543:
788                 break;
789         case e1000_82544:
790                 e1000_read_eeprom(&adapter->hw,
791                         EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
792                 eeprom_apme_mask = E1000_EEPROM_82544_APM;
793                 break;
794         case e1000_82546:
795         case e1000_82546_rev_3:
796         case e1000_82571:
797                 if(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
798                         e1000_read_eeprom(&adapter->hw,
799                                 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
800                         break;
801                 }
802                 /* Fall Through */
803         default:
804                 e1000_read_eeprom(&adapter->hw,
805                         EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
806                 break;
807         }
808         if(eeprom_data & eeprom_apme_mask)
809                 adapter->wol |= E1000_WUFC_MAG;
810
811         /* print bus type/speed/width info */
812         {
813         struct e1000_hw *hw = &adapter->hw;
814         DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
815                 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
816                  (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
817                 ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
818                  (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
819                  (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
820                  (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
821                  (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
822                 ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
823                  (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
824                  (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
825                  "32-bit"));
826         }
827
828         for (i = 0; i < 6; i++)
829                 printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':');
830
831         /* reset the hardware with the new settings */
832         e1000_reset(adapter);
833
834         /* If the controller is 82573 and f/w is AMT, do not set
835          * DRV_LOAD until the interface is up.  For all other cases,
836          * let the f/w know that the h/w is now under the control
837          * of the driver. */
838         if (adapter->hw.mac_type != e1000_82573 ||
839             !e1000_check_mng_mode(&adapter->hw))
840                 e1000_get_hw_control(adapter);
841
842         strcpy(netdev->name, "eth%d");
843         if((err = register_netdev(netdev)))
844                 goto err_register;
845
846         DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
847
848         cards_found++;
849         return 0;
850
851 err_register:
852 err_sw_init:
853 err_eeprom:
854         iounmap(adapter->hw.hw_addr);
855 err_ioremap:
856         free_netdev(netdev);
857 err_alloc_etherdev:
858         pci_release_regions(pdev);
859         return err;
860 }
861
862 /**
863  * e1000_remove - Device Removal Routine
864  * @pdev: PCI device information struct
865  *
866  * e1000_remove is called by the PCI subsystem to alert the driver
867  * that it should release a PCI device.  The could be caused by a
868  * Hot-Plug event, or because the driver is going to be removed from
869  * memory.
870  **/
871
872 static void __devexit
873 e1000_remove(struct pci_dev *pdev)
874 {
875         struct net_device *netdev = pci_get_drvdata(pdev);
876         struct e1000_adapter *adapter = netdev_priv(netdev);
877         uint32_t manc;
878 #ifdef CONFIG_E1000_NAPI
879         int i;
880 #endif
881
882         flush_scheduled_work();
883
884         if(adapter->hw.mac_type >= e1000_82540 &&
885            adapter->hw.media_type == e1000_media_type_copper) {
886                 manc = E1000_READ_REG(&adapter->hw, MANC);
887                 if(manc & E1000_MANC_SMBUS_EN) {
888                         manc |= E1000_MANC_ARP_EN;
889                         E1000_WRITE_REG(&adapter->hw, MANC, manc);
890                 }
891         }
892
893         /* Release control of h/w to f/w.  If f/w is AMT enabled, this
894          * would have already happened in close and is redundant. */
895         e1000_release_hw_control(adapter);
896
897         unregister_netdev(netdev);
898 #ifdef CONFIG_E1000_NAPI
899         for (i = 0; i < adapter->num_rx_queues; i++)
900                 __dev_put(&adapter->polling_netdev[i]);
901 #endif
902
903         if(!e1000_check_phy_reset_block(&adapter->hw))
904                 e1000_phy_hw_reset(&adapter->hw);
905
906         kfree(adapter->tx_ring);
907         kfree(adapter->rx_ring);
908 #ifdef CONFIG_E1000_NAPI
909         kfree(adapter->polling_netdev);
910 #endif
911
912         iounmap(adapter->hw.hw_addr);
913         pci_release_regions(pdev);
914
915 #ifdef CONFIG_E1000_MQ
916         free_percpu(adapter->cpu_netdev);
917         free_percpu(adapter->cpu_tx_ring);
918 #endif
919         free_netdev(netdev);
920
921         pci_disable_device(pdev);
922 }
923
924 /**
925  * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
926  * @adapter: board private structure to initialize
927  *
928  * e1000_sw_init initializes the Adapter private data structure.
929  * Fields are initialized based on PCI device information and
930  * OS network device settings (MTU size).
931  **/
932
933 static int __devinit
934 e1000_sw_init(struct e1000_adapter *adapter)
935 {
936         struct e1000_hw *hw = &adapter->hw;
937         struct net_device *netdev = adapter->netdev;
938         struct pci_dev *pdev = adapter->pdev;
939 #ifdef CONFIG_E1000_NAPI
940         int i;
941 #endif
942
943         /* PCI config space info */
944
945         hw->vendor_id = pdev->vendor;
946         hw->device_id = pdev->device;
947         hw->subsystem_vendor_id = pdev->subsystem_vendor;
948         hw->subsystem_id = pdev->subsystem_device;
949
950         pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
951
952         pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
953
954         adapter->rx_buffer_len = E1000_RXBUFFER_2048;
955         adapter->rx_ps_bsize0 = E1000_RXBUFFER_256;
956         hw->max_frame_size = netdev->mtu +
957                              ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
958         hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
959
960         /* identify the MAC */
961
962         if(e1000_set_mac_type(hw)) {
963                 DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
964                 return -EIO;
965         }
966
967         /* initialize eeprom parameters */
968
969         if(e1000_init_eeprom_params(hw)) {
970                 E1000_ERR("EEPROM initialization failed\n");
971                 return -EIO;
972         }
973
974         switch(hw->mac_type) {
975         default:
976                 break;
977         case e1000_82541:
978         case e1000_82547:
979         case e1000_82541_rev_2:
980         case e1000_82547_rev_2:
981                 hw->phy_init_script = 1;
982                 break;
983         }
984
985         e1000_set_media_type(hw);
986
987         hw->wait_autoneg_complete = FALSE;
988         hw->tbi_compatibility_en = TRUE;
989         hw->adaptive_ifs = TRUE;
990
991         /* Copper options */
992
993         if(hw->media_type == e1000_media_type_copper) {
994                 hw->mdix = AUTO_ALL_MODES;
995                 hw->disable_polarity_correction = FALSE;
996                 hw->master_slave = E1000_MASTER_SLAVE;
997         }
998
999 #ifdef CONFIG_E1000_MQ
1000         /* Number of supported queues */
1001         switch (hw->mac_type) {
1002         case e1000_82571:
1003         case e1000_82572:
1004                 /* These controllers support 2 tx queues, but with a single
1005                  * qdisc implementation, multiple tx queues aren't quite as
1006                  * interesting.  If we can find a logical way of mapping
1007                  * flows to a queue, then perhaps we can up the num_tx_queue
1008                  * count back to its default.  Until then, we run the risk of
1009                  * terrible performance due to SACK overload. */
1010                 adapter->num_tx_queues = 1;
1011                 adapter->num_rx_queues = 2;
1012                 break;
1013         default:
1014                 adapter->num_tx_queues = 1;
1015                 adapter->num_rx_queues = 1;
1016                 break;
1017         }
1018         adapter->num_rx_queues = min(adapter->num_rx_queues, num_online_cpus());
1019         adapter->num_tx_queues = min(adapter->num_tx_queues, num_online_cpus());
1020         DPRINTK(DRV, INFO, "Multiqueue Enabled: Rx Queue count = %u %s\n",
1021                 adapter->num_rx_queues,
1022                 ((adapter->num_rx_queues == 1)
1023                  ? ((num_online_cpus() > 1)
1024                         ? "(due to unsupported feature in current adapter)"
1025                         : "(due to unsupported system configuration)")
1026                  : ""));
1027         DPRINTK(DRV, INFO, "Multiqueue Enabled: Tx Queue count = %u\n",
1028                 adapter->num_tx_queues);
1029 #else
1030         adapter->num_tx_queues = 1;
1031         adapter->num_rx_queues = 1;
1032 #endif
1033
1034         if (e1000_alloc_queues(adapter)) {
1035                 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
1036                 return -ENOMEM;
1037         }
1038
1039 #ifdef CONFIG_E1000_NAPI
1040         for (i = 0; i < adapter->num_rx_queues; i++) {
1041                 adapter->polling_netdev[i].priv = adapter;
1042                 adapter->polling_netdev[i].poll = &e1000_clean;
1043                 adapter->polling_netdev[i].weight = 64;
1044                 dev_hold(&adapter->polling_netdev[i]);
1045                 set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
1046         }
1047         spin_lock_init(&adapter->tx_queue_lock);
1048 #endif
1049
1050         atomic_set(&adapter->irq_sem, 1);
1051         spin_lock_init(&adapter->stats_lock);
1052
1053         return 0;
1054 }
1055
1056 /**
1057  * e1000_alloc_queues - Allocate memory for all rings
1058  * @adapter: board private structure to initialize
1059  *
1060  * We allocate one ring per queue at run-time since we don't know the
1061  * number of queues at compile-time.  The polling_netdev array is
1062  * intended for Multiqueue, but should work fine with a single queue.
1063  **/
1064
1065 static int __devinit
1066 e1000_alloc_queues(struct e1000_adapter *adapter)
1067 {
1068         int size;
1069
1070         size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
1071         adapter->tx_ring = kmalloc(size, GFP_KERNEL);
1072         if (!adapter->tx_ring)
1073                 return -ENOMEM;
1074         memset(adapter->tx_ring, 0, size);
1075
1076         size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
1077         adapter->rx_ring = kmalloc(size, GFP_KERNEL);
1078         if (!adapter->rx_ring) {
1079                 kfree(adapter->tx_ring);
1080                 return -ENOMEM;
1081         }
1082         memset(adapter->rx_ring, 0, size);
1083
1084 #ifdef CONFIG_E1000_NAPI
1085         size = sizeof(struct net_device) * adapter->num_rx_queues;
1086         adapter->polling_netdev = kmalloc(size, GFP_KERNEL);
1087         if (!adapter->polling_netdev) {
1088                 kfree(adapter->tx_ring);
1089                 kfree(adapter->rx_ring);
1090                 return -ENOMEM;
1091         }
1092         memset(adapter->polling_netdev, 0, size);
1093 #endif
1094
1095 #ifdef CONFIG_E1000_MQ
1096         adapter->rx_sched_call_data.func = e1000_rx_schedule;
1097         adapter->rx_sched_call_data.info = adapter->netdev;
1098
1099         adapter->cpu_netdev = alloc_percpu(struct net_device *);
1100         adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1101 #endif
1102
1103         return E1000_SUCCESS;
1104 }
1105
1106 #ifdef CONFIG_E1000_MQ
1107 static void __devinit
1108 e1000_setup_queue_mapping(struct e1000_adapter *adapter)
1109 {
1110         int i, cpu;
1111
1112         adapter->rx_sched_call_data.func = e1000_rx_schedule;
1113         adapter->rx_sched_call_data.info = adapter->netdev;
1114         cpus_clear(adapter->rx_sched_call_data.cpumask);
1115
1116         adapter->cpu_netdev = alloc_percpu(struct net_device *);
1117         adapter->cpu_tx_ring = alloc_percpu(struct e1000_tx_ring *);
1118
1119         lock_cpu_hotplug();
1120         i = 0;
1121         for_each_online_cpu(cpu) {
1122                 *per_cpu_ptr(adapter->cpu_tx_ring, cpu) = &adapter->tx_ring[i % adapter->num_tx_queues];
1123                 /* This is incomplete because we'd like to assign separate
1124                  * physical cpus to these netdev polling structures and
1125                  * avoid saturating a subset of cpus.
1126                  */
1127                 if (i < adapter->num_rx_queues) {
1128                         *per_cpu_ptr(adapter->cpu_netdev, cpu) = &adapter->polling_netdev[i];
1129                         adapter->rx_ring[i].cpu = cpu;
1130                         cpu_set(cpu, adapter->cpumask);
1131                 } else
1132                         *per_cpu_ptr(adapter->cpu_netdev, cpu) = NULL;
1133
1134                 i++;
1135         }
1136         unlock_cpu_hotplug();
1137 }
1138 #endif
1139
1140 /**
1141  * e1000_open - Called when a network interface is made active
1142  * @netdev: network interface device structure
1143  *
1144  * Returns 0 on success, negative value on failure
1145  *
1146  * The open entry point is called when a network interface is made
1147  * active by the system (IFF_UP).  At this point all resources needed
1148  * for transmit and receive operations are allocated, the interrupt
1149  * handler is registered with the OS, the watchdog timer is started,
1150  * and the stack is notified that the interface is ready.
1151  **/
1152
1153 static int
1154 e1000_open(struct net_device *netdev)
1155 {
1156         struct e1000_adapter *adapter = netdev_priv(netdev);
1157         int err;
1158
1159         /* allocate transmit descriptors */
1160
1161         if ((err = e1000_setup_all_tx_resources(adapter)))
1162                 goto err_setup_tx;
1163
1164         /* allocate receive descriptors */
1165
1166         if ((err = e1000_setup_all_rx_resources(adapter)))
1167                 goto err_setup_rx;
1168
1169         if((err = e1000_up(adapter)))
1170                 goto err_up;
1171         adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1172         if((adapter->hw.mng_cookie.status &
1173                           E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1174                 e1000_update_mng_vlan(adapter);
1175         }
1176
1177         /* If AMT is enabled, let the firmware know that the network
1178          * interface is now open */
1179         if (adapter->hw.mac_type == e1000_82573 &&
1180             e1000_check_mng_mode(&adapter->hw))
1181                 e1000_get_hw_control(adapter);
1182
1183         return E1000_SUCCESS;
1184
1185 err_up:
1186         e1000_free_all_rx_resources(adapter);
1187 err_setup_rx:
1188         e1000_free_all_tx_resources(adapter);
1189 err_setup_tx:
1190         e1000_reset(adapter);
1191
1192         return err;
1193 }
1194
1195 /**
1196  * e1000_close - Disables a network interface
1197  * @netdev: network interface device structure
1198  *
1199  * Returns 0, this is not allowed to fail
1200  *
1201  * The close entry point is called when an interface is de-activated
1202  * by the OS.  The hardware is still under the drivers control, but
1203  * needs to be disabled.  A global MAC reset is issued to stop the
1204  * hardware, and all transmit and receive resources are freed.
1205  **/
1206
1207 static int
1208 e1000_close(struct net_device *netdev)
1209 {
1210         struct e1000_adapter *adapter = netdev_priv(netdev);
1211
1212         e1000_down(adapter);
1213
1214         e1000_free_all_tx_resources(adapter);
1215         e1000_free_all_rx_resources(adapter);
1216
1217         if((adapter->hw.mng_cookie.status &
1218                           E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1219                 e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1220         }
1221
1222         /* If AMT is enabled, let the firmware know that the network
1223          * interface is now closed */
1224         if (adapter->hw.mac_type == e1000_82573 &&
1225             e1000_check_mng_mode(&adapter->hw))
1226                 e1000_release_hw_control(adapter);
1227
1228         return 0;
1229 }
1230
1231 /**
1232  * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
1233  * @adapter: address of board private structure
1234  * @start: address of beginning of memory
1235  * @len: length of memory
1236  **/
1237 static inline boolean_t
1238 e1000_check_64k_bound(struct e1000_adapter *adapter,
1239                       void *start, unsigned long len)
1240 {
1241         unsigned long begin = (unsigned long) start;
1242         unsigned long end = begin + len;
1243
1244         /* First rev 82545 and 82546 need to not allow any memory
1245          * write location to cross 64k boundary due to errata 23 */
1246         if (adapter->hw.mac_type == e1000_82545 ||
1247             adapter->hw.mac_type == e1000_82546) {
1248                 return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
1249         }
1250
1251         return TRUE;
1252 }
1253
1254 /**
1255  * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
1256  * @adapter: board private structure
1257  * @txdr:    tx descriptor ring (for a specific queue) to setup
1258  *
1259  * Return 0 on success, negative on failure
1260  **/
1261
1262 static int
1263 e1000_setup_tx_resources(struct e1000_adapter *adapter,
1264                          struct e1000_tx_ring *txdr)
1265 {
1266         struct pci_dev *pdev = adapter->pdev;
1267         int size;
1268
1269         size = sizeof(struct e1000_buffer) * txdr->count;
1270
1271         txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1272         if(!txdr->buffer_info) {
1273                 DPRINTK(PROBE, ERR,
1274                 "Unable to allocate memory for the transmit descriptor ring\n");
1275                 return -ENOMEM;
1276         }
1277         memset(txdr->buffer_info, 0, size);
1278
1279         /* round up to nearest 4K */
1280
1281         txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1282         E1000_ROUNDUP(txdr->size, 4096);
1283
1284         txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1285         if(!txdr->desc) {
1286 setup_tx_desc_die:
1287                 vfree(txdr->buffer_info);
1288                 DPRINTK(PROBE, ERR,
1289                 "Unable to allocate memory for the transmit descriptor ring\n");
1290                 return -ENOMEM;
1291         }
1292
1293         /* Fix for errata 23, can't cross 64kB boundary */
1294         if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1295                 void *olddesc = txdr->desc;
1296                 dma_addr_t olddma = txdr->dma;
1297                 DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
1298                                      "at %p\n", txdr->size, txdr->desc);
1299                 /* Try again, without freeing the previous */
1300                 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1301                 if(!txdr->desc) {
1302                 /* Failed allocation, critical failure */
1303                         pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1304                         goto setup_tx_desc_die;
1305                 }
1306
1307                 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1308                         /* give up */
1309                         pci_free_consistent(pdev, txdr->size, txdr->desc,
1310                                             txdr->dma);
1311                         pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1312                         DPRINTK(PROBE, ERR,
1313                                 "Unable to allocate aligned memory "
1314                                 "for the transmit descriptor ring\n");
1315                         vfree(txdr->buffer_info);
1316                         return -ENOMEM;
1317                 } else {
1318                         /* Free old allocation, new allocation was successful */
1319                         pci_free_consistent(pdev, txdr->size, olddesc, olddma);
1320                 }
1321         }
1322         memset(txdr->desc, 0, txdr->size);
1323
1324         txdr->next_to_use = 0;
1325         txdr->next_to_clean = 0;
1326         spin_lock_init(&txdr->tx_lock);
1327
1328         return 0;
1329 }
1330
1331 /**
1332  * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
1333  *                                (Descriptors) for all queues
1334  * @adapter: board private structure
1335  *
1336  * If this function returns with an error, then it's possible one or
1337  * more of the rings is populated (while the rest are not).  It is the
1338  * callers duty to clean those orphaned rings.
1339  *
1340  * Return 0 on success, negative on failure
1341  **/
1342
1343 int
1344 e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1345 {
1346         int i, err = 0;
1347
1348         for (i = 0; i < adapter->num_tx_queues; i++) {
1349                 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1350                 if (err) {
1351                         DPRINTK(PROBE, ERR,
1352                                 "Allocation for Tx Queue %u failed\n", i);
1353                         break;
1354                 }
1355         }
1356
1357         return err;
1358 }
1359
1360 /**
1361  * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
1362  * @adapter: board private structure
1363  *
1364  * Configure the Tx unit of the MAC after a reset.
1365  **/
1366
1367 static void
1368 e1000_configure_tx(struct e1000_adapter *adapter)
1369 {
1370         uint64_t tdba;
1371         struct e1000_hw *hw = &adapter->hw;
1372         uint32_t tdlen, tctl, tipg, tarc;
1373         uint32_t ipgr1, ipgr2;
1374
1375         /* Setup the HW Tx Head and Tail descriptor pointers */
1376
1377         switch (adapter->num_tx_queues) {
1378         case 2:
1379                 tdba = adapter->tx_ring[1].dma;
1380                 tdlen = adapter->tx_ring[1].count *
1381                         sizeof(struct e1000_tx_desc);
1382                 E1000_WRITE_REG(hw, TDBAL1, (tdba & 0x00000000ffffffffULL));
1383                 E1000_WRITE_REG(hw, TDBAH1, (tdba >> 32));
1384                 E1000_WRITE_REG(hw, TDLEN1, tdlen);
1385                 E1000_WRITE_REG(hw, TDH1, 0);
1386                 E1000_WRITE_REG(hw, TDT1, 0);
1387                 adapter->tx_ring[1].tdh = E1000_TDH1;
1388                 adapter->tx_ring[1].tdt = E1000_TDT1;
1389                 /* Fall Through */
1390         case 1:
1391         default:
1392                 tdba = adapter->tx_ring[0].dma;
1393                 tdlen = adapter->tx_ring[0].count *
1394                         sizeof(struct e1000_tx_desc);
1395                 E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
1396                 E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
1397                 E1000_WRITE_REG(hw, TDLEN, tdlen);
1398                 E1000_WRITE_REG(hw, TDH, 0);
1399                 E1000_WRITE_REG(hw, TDT, 0);
1400                 adapter->tx_ring[0].tdh = E1000_TDH;
1401                 adapter->tx_ring[0].tdt = E1000_TDT;
1402                 break;
1403         }
1404
1405         /* Set the default values for the Tx Inter Packet Gap timer */
1406
1407         if (hw->media_type == e1000_media_type_fiber ||
1408             hw->media_type == e1000_media_type_internal_serdes)
1409                 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1410         else
1411                 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1412
1413         switch (hw->mac_type) {
1414         case e1000_82542_rev2_0:
1415         case e1000_82542_rev2_1:
1416                 tipg = DEFAULT_82542_TIPG_IPGT;
1417                 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1418                 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1419                 break;
1420         default:
1421                 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1422                 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1423                 break;
1424         }
1425         tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1426         tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1427         E1000_WRITE_REG(hw, TIPG, tipg);
1428
1429         /* Set the Tx Interrupt Delay register */
1430
1431         E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
1432         if (hw->mac_type >= e1000_82540)
1433                 E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
1434
1435         /* Program the Transmit Control Register */
1436
1437         tctl = E1000_READ_REG(hw, TCTL);
1438
1439         tctl &= ~E1000_TCTL_CT;
1440         tctl |= E1000_TCTL_EN | E1000_TCTL_PSP | E1000_TCTL_RTLC |
1441                 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1442
1443         E1000_WRITE_REG(hw, TCTL, tctl);
1444
1445         if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
1446                 tarc = E1000_READ_REG(hw, TARC0);
1447                 tarc |= ((1 << 25) | (1 << 21));
1448                 E1000_WRITE_REG(hw, TARC0, tarc);
1449                 tarc = E1000_READ_REG(hw, TARC1);
1450                 tarc |= (1 << 25);
1451                 if (tctl & E1000_TCTL_MULR)
1452                         tarc &= ~(1 << 28);
1453                 else
1454                         tarc |= (1 << 28);
1455                 E1000_WRITE_REG(hw, TARC1, tarc);
1456         }
1457
1458         e1000_config_collision_dist(hw);
1459
1460         /* Setup Transmit Descriptor Settings for eop descriptor */
1461         adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP |
1462                 E1000_TXD_CMD_IFCS;
1463
1464         if (hw->mac_type < e1000_82543)
1465                 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1466         else
1467                 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1468
1469         /* Cache if we're 82544 running in PCI-X because we'll
1470          * need this to apply a workaround later in the send path. */
1471         if (hw->mac_type == e1000_82544 &&
1472             hw->bus_type == e1000_bus_type_pcix)
1473                 adapter->pcix_82544 = 1;
1474 }
1475
1476 /**
1477  * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
1478  * @adapter: board private structure
1479  * @rxdr:    rx descriptor ring (for a specific queue) to setup
1480  *
1481  * Returns 0 on success, negative on failure
1482  **/
1483
1484 static int
1485 e1000_setup_rx_resources(struct e1000_adapter *adapter,
1486                          struct e1000_rx_ring *rxdr)
1487 {
1488         struct pci_dev *pdev = adapter->pdev;
1489         int size, desc_len;
1490
1491         size = sizeof(struct e1000_buffer) * rxdr->count;
1492         rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus));
1493         if (!rxdr->buffer_info) {
1494                 DPRINTK(PROBE, ERR,
1495                 "Unable to allocate memory for the receive descriptor ring\n");
1496                 return -ENOMEM;
1497         }
1498         memset(rxdr->buffer_info, 0, size);
1499
1500         size = sizeof(struct e1000_ps_page) * rxdr->count;
1501         rxdr->ps_page = kmalloc(size, GFP_KERNEL);
1502         if(!rxdr->ps_page) {
1503                 vfree(rxdr->buffer_info);
1504                 DPRINTK(PROBE, ERR,
1505                 "Unable to allocate memory for the receive descriptor ring\n");
1506                 return -ENOMEM;
1507         }
1508         memset(rxdr->ps_page, 0, size);
1509
1510         size = sizeof(struct e1000_ps_page_dma) * rxdr->count;
1511         rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL);
1512         if(!rxdr->ps_page_dma) {
1513                 vfree(rxdr->buffer_info);
1514                 kfree(rxdr->ps_page);
1515                 DPRINTK(PROBE, ERR,
1516                 "Unable to allocate memory for the receive descriptor ring\n");
1517                 return -ENOMEM;
1518         }
1519         memset(rxdr->ps_page_dma, 0, size);
1520
1521         if(adapter->hw.mac_type <= e1000_82547_rev_2)
1522                 desc_len = sizeof(struct e1000_rx_desc);
1523         else
1524                 desc_len = sizeof(union e1000_rx_desc_packet_split);
1525
1526         /* Round up to nearest 4K */
1527
1528         rxdr->size = rxdr->count * desc_len;
1529         E1000_ROUNDUP(rxdr->size, 4096);
1530
1531         rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1532
1533         if (!rxdr->desc) {
1534                 DPRINTK(PROBE, ERR,
1535                 "Unable to allocate memory for the receive descriptor ring\n");
1536 setup_rx_desc_die:
1537                 vfree(rxdr->buffer_info);
1538                 kfree(rxdr->ps_page);
1539                 kfree(rxdr->ps_page_dma);
1540                 return -ENOMEM;
1541         }
1542
1543         /* Fix for errata 23, can't cross 64kB boundary */
1544         if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1545                 void *olddesc = rxdr->desc;
1546                 dma_addr_t olddma = rxdr->dma;
1547                 DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
1548                                      "at %p\n", rxdr->size, rxdr->desc);
1549                 /* Try again, without freeing the previous */
1550                 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1551                 /* Failed allocation, critical failure */
1552                 if (!rxdr->desc) {
1553                         pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1554                         DPRINTK(PROBE, ERR,
1555                                 "Unable to allocate memory "
1556                                 "for the receive descriptor ring\n");
1557                         goto setup_rx_desc_die;
1558                 }
1559
1560                 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1561                         /* give up */
1562                         pci_free_consistent(pdev, rxdr->size, rxdr->desc,
1563                                             rxdr->dma);
1564                         pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1565                         DPRINTK(PROBE, ERR,
1566                                 "Unable to allocate aligned memory "
1567                                 "for the receive descriptor ring\n");
1568                         goto setup_rx_desc_die;
1569                 } else {
1570                         /* Free old allocation, new allocation was successful */
1571                         pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
1572                 }
1573         }
1574         memset(rxdr->desc, 0, rxdr->size);
1575
1576         rxdr->next_to_clean = 0;
1577         rxdr->next_to_use = 0;
1578         rxdr->rx_skb_top = NULL;
1579         rxdr->rx_skb_prev = NULL;
1580
1581         return 0;
1582 }
1583
1584 /**
1585  * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
1586  *                                (Descriptors) for all queues
1587  * @adapter: board private structure
1588  *
1589  * If this function returns with an error, then it's possible one or
1590  * more of the rings is populated (while the rest are not).  It is the
1591  * callers duty to clean those orphaned rings.
1592  *
1593  * Return 0 on success, negative on failure
1594  **/
1595
1596 int
1597 e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1598 {
1599         int i, err = 0;
1600
1601         for (i = 0; i < adapter->num_rx_queues; i++) {
1602                 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1603                 if (err) {
1604                         DPRINTK(PROBE, ERR,
1605                                 "Allocation for Rx Queue %u failed\n", i);
1606                         break;
1607                 }
1608         }
1609
1610         return err;
1611 }
1612
1613 /**
1614  * e1000_setup_rctl - configure the receive control registers
1615  * @adapter: Board private structure
1616  **/
1617 #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
1618                         (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
1619 static void
1620 e1000_setup_rctl(struct e1000_adapter *adapter)
1621 {
1622         uint32_t rctl, rfctl;
1623         uint32_t psrctl = 0;
1624 #ifdef CONFIG_E1000_PACKET_SPLIT
1625         uint32_t pages = 0;
1626 #endif
1627
1628         rctl = E1000_READ_REG(&adapter->hw, RCTL);
1629
1630         rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1631
1632         rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
1633                 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1634                 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1635
1636         if (adapter->hw.mac_type > e1000_82543)
1637                 rctl |= E1000_RCTL_SECRC;
1638
1639         if (adapter->hw.tbi_compatibility_on == 1)
1640                 rctl |= E1000_RCTL_SBP;
1641         else
1642                 rctl &= ~E1000_RCTL_SBP;
1643
1644         if (adapter->netdev->mtu <= ETH_DATA_LEN)
1645                 rctl &= ~E1000_RCTL_LPE;
1646         else
1647                 rctl |= E1000_RCTL_LPE;
1648
1649         /* Setup buffer sizes */
1650         if(adapter->hw.mac_type >= e1000_82571) {
1651                 /* We can now specify buffers in 1K increments.
1652                  * BSIZE and BSEX are ignored in this case. */
1653                 rctl |= adapter->rx_buffer_len << 0x11;
1654         } else {
1655                 rctl &= ~E1000_RCTL_SZ_4096;
1656                 rctl |= E1000_RCTL_BSEX; 
1657                 switch (adapter->rx_buffer_len) {
1658                 case E1000_RXBUFFER_2048:
1659                 default:
1660                         rctl |= E1000_RCTL_SZ_2048;
1661                         rctl &= ~E1000_RCTL_BSEX;
1662                         break;
1663                 case E1000_RXBUFFER_4096:
1664                         rctl |= E1000_RCTL_SZ_4096;
1665                         break;
1666                 case E1000_RXBUFFER_8192:
1667                         rctl |= E1000_RCTL_SZ_8192;
1668                         break;
1669                 case E1000_RXBUFFER_16384:
1670                         rctl |= E1000_RCTL_SZ_16384;
1671                         break;
1672                 }
1673         }
1674
1675 #ifdef CONFIG_E1000_PACKET_SPLIT
1676         /* 82571 and greater support packet-split where the protocol
1677          * header is placed in skb->data and the packet data is
1678          * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1679          * In the case of a non-split, skb->data is linearly filled,
1680          * followed by the page buffers.  Therefore, skb->data is
1681          * sized to hold the largest protocol header.
1682          */
1683         pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1684         if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) &&
1685             PAGE_SIZE <= 16384)
1686                 adapter->rx_ps_pages = pages;
1687         else
1688                 adapter->rx_ps_pages = 0;
1689 #endif
1690         if (adapter->rx_ps_pages) {
1691                 /* Configure extra packet-split registers */
1692                 rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
1693                 rfctl |= E1000_RFCTL_EXTEN;
1694                 /* disable IPv6 packet split support */
1695                 rfctl |= E1000_RFCTL_IPV6_DIS;
1696                 E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
1697
1698                 rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC;
1699                 
1700                 psrctl |= adapter->rx_ps_bsize0 >>
1701                         E1000_PSRCTL_BSIZE0_SHIFT;
1702
1703                 switch (adapter->rx_ps_pages) {
1704                 case 3:
1705                         psrctl |= PAGE_SIZE <<
1706                                 E1000_PSRCTL_BSIZE3_SHIFT;
1707                 case 2:
1708                         psrctl |= PAGE_SIZE <<
1709                                 E1000_PSRCTL_BSIZE2_SHIFT;
1710                 case 1:
1711                         psrctl |= PAGE_SIZE >>
1712                                 E1000_PSRCTL_BSIZE1_SHIFT;
1713                         break;
1714                 }
1715
1716                 E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
1717         }
1718
1719         E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1720 }
1721
1722 /**
1723  * e1000_configure_rx - Configure 8254x Receive Unit after Reset
1724  * @adapter: board private structure
1725  *
1726  * Configure the Rx unit of the MAC after a reset.
1727  **/
1728
1729 static void
1730 e1000_configure_rx(struct e1000_adapter *adapter)
1731 {
1732         uint64_t rdba;
1733         struct e1000_hw *hw = &adapter->hw;
1734         uint32_t rdlen, rctl, rxcsum, ctrl_ext;
1735 #ifdef CONFIG_E1000_MQ
1736         uint32_t reta, mrqc;
1737         int i;
1738 #endif
1739
1740         if (adapter->rx_ps_pages) {
1741                 rdlen = adapter->rx_ring[0].count *
1742                         sizeof(union e1000_rx_desc_packet_split);
1743                 adapter->clean_rx = e1000_clean_rx_irq_ps;
1744                 adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
1745         } else {
1746                 rdlen = adapter->rx_ring[0].count *
1747                         sizeof(struct e1000_rx_desc);
1748                 adapter->clean_rx = e1000_clean_rx_irq;
1749                 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1750         }
1751
1752         /* disable receives while setting up the descriptors */
1753         rctl = E1000_READ_REG(hw, RCTL);
1754         E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
1755
1756         /* set the Receive Delay Timer Register */
1757         E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
1758
1759         if (hw->mac_type >= e1000_82540) {
1760                 E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
1761                 if(adapter->itr > 1)
1762                         E1000_WRITE_REG(hw, ITR,
1763                                 1000000000 / (adapter->itr * 256));
1764         }
1765
1766         if (hw->mac_type >= e1000_82571) {
1767                 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1768                 /* Reset delay timers after every interrupt */
1769                 ctrl_ext |= E1000_CTRL_EXT_CANC;
1770 #ifdef CONFIG_E1000_NAPI
1771                 /* Auto-Mask interrupts upon ICR read. */
1772                 ctrl_ext |= E1000_CTRL_EXT_IAME;
1773 #endif
1774                 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1775                 E1000_WRITE_REG(hw, IAM, ~0);
1776                 E1000_WRITE_FLUSH(hw);
1777         }
1778
1779         /* Setup the HW Rx Head and Tail Descriptor Pointers and
1780          * the Base and Length of the Rx Descriptor Ring */
1781         switch (adapter->num_rx_queues) {
1782 #ifdef CONFIG_E1000_MQ
1783         case 2:
1784                 rdba = adapter->rx_ring[1].dma;
1785                 E1000_WRITE_REG(hw, RDBAL1, (rdba & 0x00000000ffffffffULL));
1786                 E1000_WRITE_REG(hw, RDBAH1, (rdba >> 32));
1787                 E1000_WRITE_REG(hw, RDLEN1, rdlen);
1788                 E1000_WRITE_REG(hw, RDH1, 0);
1789                 E1000_WRITE_REG(hw, RDT1, 0);
1790                 adapter->rx_ring[1].rdh = E1000_RDH1;
1791                 adapter->rx_ring[1].rdt = E1000_RDT1;
1792                 /* Fall Through */
1793 #endif
1794         case 1:
1795         default:
1796                 rdba = adapter->rx_ring[0].dma;
1797                 E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
1798                 E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
1799                 E1000_WRITE_REG(hw, RDLEN, rdlen);
1800                 E1000_WRITE_REG(hw, RDH, 0);
1801                 E1000_WRITE_REG(hw, RDT, 0);
1802                 adapter->rx_ring[0].rdh = E1000_RDH;
1803                 adapter->rx_ring[0].rdt = E1000_RDT;
1804                 break;
1805         }
1806
1807 #ifdef CONFIG_E1000_MQ
1808         if (adapter->num_rx_queues > 1) {
1809                 uint32_t random[10];
1810
1811                 get_random_bytes(&random[0], 40);
1812
1813                 if (hw->mac_type <= e1000_82572) {
1814                         E1000_WRITE_REG(hw, RSSIR, 0);
1815                         E1000_WRITE_REG(hw, RSSIM, 0);
1816                 }
1817
1818                 switch (adapter->num_rx_queues) {
1819                 case 2:
1820                 default:
1821                         reta = 0x00800080;
1822                         mrqc = E1000_MRQC_ENABLE_RSS_2Q;
1823                         break;
1824                 }
1825
1826                 /* Fill out redirection table */
1827                 for (i = 0; i < 32; i++)
1828                         E1000_WRITE_REG_ARRAY(hw, RETA, i, reta);
1829                 /* Fill out hash function seeds */
1830                 for (i = 0; i < 10; i++)
1831                         E1000_WRITE_REG_ARRAY(hw, RSSRK, i, random[i]);
1832
1833                 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1834                          E1000_MRQC_RSS_FIELD_IPV4_TCP);
1835                 E1000_WRITE_REG(hw, MRQC, mrqc);
1836         }
1837
1838         /* Multiqueue and packet checksumming are mutually exclusive. */
1839         if (hw->mac_type >= e1000_82571) {
1840                 rxcsum = E1000_READ_REG(hw, RXCSUM);
1841                 rxcsum |= E1000_RXCSUM_PCSD;
1842                 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1843         }
1844
1845 #else
1846
1847         /* Enable 82543 Receive Checksum Offload for TCP and UDP */
1848         if (hw->mac_type >= e1000_82543) {
1849                 rxcsum = E1000_READ_REG(hw, RXCSUM);
1850                 if(adapter->rx_csum == TRUE) {
1851                         rxcsum |= E1000_RXCSUM_TUOFL;
1852
1853                         /* Enable 82571 IPv4 payload checksum for UDP fragments
1854                          * Must be used in conjunction with packet-split. */
1855                         if ((hw->mac_type >= e1000_82571) && 
1856                            (adapter->rx_ps_pages)) {
1857                                 rxcsum |= E1000_RXCSUM_IPPCSE;
1858                         }
1859                 } else {
1860                         rxcsum &= ~E1000_RXCSUM_TUOFL;
1861                         /* don't need to clear IPPCSE as it defaults to 0 */
1862                 }
1863                 E1000_WRITE_REG(hw, RXCSUM, rxcsum);
1864         }
1865 #endif /* CONFIG_E1000_MQ */
1866
1867         if (hw->mac_type == e1000_82573)
1868                 E1000_WRITE_REG(hw, ERT, 0x0100);
1869
1870         /* Enable Receives */
1871         E1000_WRITE_REG(hw, RCTL, rctl);
1872 }
1873
1874 /**
1875  * e1000_free_tx_resources - Free Tx Resources per Queue
1876  * @adapter: board private structure
1877  * @tx_ring: Tx descriptor ring for a specific queue
1878  *
1879  * Free all transmit software resources
1880  **/
1881
1882 static void
1883 e1000_free_tx_resources(struct e1000_adapter *adapter,
1884                         struct e1000_tx_ring *tx_ring)
1885 {
1886         struct pci_dev *pdev = adapter->pdev;
1887
1888         e1000_clean_tx_ring(adapter, tx_ring);
1889
1890         vfree(tx_ring->buffer_info);
1891         tx_ring->buffer_info = NULL;
1892
1893         pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
1894
1895         tx_ring->desc = NULL;
1896 }
1897
1898 /**
1899  * e1000_free_all_tx_resources - Free Tx Resources for All Queues
1900  * @adapter: board private structure
1901  *
1902  * Free all transmit software resources
1903  **/
1904
1905 void
1906 e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1907 {
1908         int i;
1909
1910         for (i = 0; i < adapter->num_tx_queues; i++)
1911                 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1912 }
1913
1914 static inline void
1915 e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1916                         struct e1000_buffer *buffer_info)
1917 {
1918         if(buffer_info->dma) {
1919                 pci_unmap_page(adapter->pdev,
1920                                 buffer_info->dma,
1921                                 buffer_info->length,
1922                                 PCI_DMA_TODEVICE);
1923                 buffer_info->dma = 0;
1924         }
1925         if(buffer_info->skb) {
1926                 dev_kfree_skb_any(buffer_info->skb);
1927                 buffer_info->skb = NULL;
1928         }
1929 }
1930
1931 /**
1932  * e1000_clean_tx_ring - Free Tx Buffers
1933  * @adapter: board private structure
1934  * @tx_ring: ring to be cleaned
1935  **/
1936
1937 static void
1938 e1000_clean_tx_ring(struct e1000_adapter *adapter,
1939                     struct e1000_tx_ring *tx_ring)
1940 {
1941         struct e1000_buffer *buffer_info;
1942         unsigned long size;
1943         unsigned int i;
1944
1945         /* Free all the Tx ring sk_buffs */
1946
1947         for(i = 0; i < tx_ring->count; i++) {
1948                 buffer_info = &tx_ring->buffer_info[i];
1949                 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
1950         }
1951
1952         size = sizeof(struct e1000_buffer) * tx_ring->count;
1953         memset(tx_ring->buffer_info, 0, size);
1954
1955         /* Zero out the descriptor ring */
1956
1957         memset(tx_ring->desc, 0, tx_ring->size);
1958
1959         tx_ring->next_to_use = 0;
1960         tx_ring->next_to_clean = 0;
1961         tx_ring->last_tx_tso = 0;
1962
1963         writel(0, adapter->hw.hw_addr + tx_ring->tdh);
1964         writel(0, adapter->hw.hw_addr + tx_ring->tdt);
1965 }
1966
1967 /**
1968  * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
1969  * @adapter: board private structure
1970  **/
1971
1972 static void
1973 e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
1974 {
1975         int i;
1976
1977         for (i = 0; i < adapter->num_tx_queues; i++)
1978                 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
1979 }
1980
1981 /**
1982  * e1000_free_rx_resources - Free Rx Resources
1983  * @adapter: board private structure
1984  * @rx_ring: ring to clean the resources from
1985  *
1986  * Free all receive software resources
1987  **/
1988
1989 static void
1990 e1000_free_rx_resources(struct e1000_adapter *adapter,
1991                         struct e1000_rx_ring *rx_ring)
1992 {
1993         struct pci_dev *pdev = adapter->pdev;
1994
1995         e1000_clean_rx_ring(adapter, rx_ring);
1996
1997         vfree(rx_ring->buffer_info);
1998         rx_ring->buffer_info = NULL;
1999         kfree(rx_ring->ps_page);
2000         rx_ring->ps_page = NULL;
2001         kfree(rx_ring->ps_page_dma);
2002         rx_ring->ps_page_dma = NULL;
2003
2004         pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2005
2006         rx_ring->desc = NULL;
2007 }
2008
2009 /**
2010  * e1000_free_all_rx_resources - Free Rx Resources for All Queues
2011  * @adapter: board private structure
2012  *
2013  * Free all receive software resources
2014  **/
2015
2016 void
2017 e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2018 {
2019         int i;
2020
2021         for (i = 0; i < adapter->num_rx_queues; i++)
2022                 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2023 }
2024
2025 /**
2026  * e1000_clean_rx_ring - Free Rx Buffers per Queue
2027  * @adapter: board private structure
2028  * @rx_ring: ring to free buffers from
2029  **/
2030
2031 static void
2032 e1000_clean_rx_ring(struct e1000_adapter *adapter,
2033                     struct e1000_rx_ring *rx_ring)
2034 {
2035         struct e1000_buffer *buffer_info;
2036         struct e1000_ps_page *ps_page;
2037         struct e1000_ps_page_dma *ps_page_dma;
2038         struct pci_dev *pdev = adapter->pdev;
2039         unsigned long size;
2040         unsigned int i, j;
2041
2042         /* Free all the Rx ring sk_buffs */
2043
2044         for(i = 0; i < rx_ring->count; i++) {
2045                 buffer_info = &rx_ring->buffer_info[i];
2046                 if(buffer_info->skb) {
2047                         ps_page = &rx_ring->ps_page[i];
2048                         ps_page_dma = &rx_ring->ps_page_dma[i];
2049                         pci_unmap_single(pdev,
2050                                          buffer_info->dma,
2051                                          buffer_info->length,
2052                                          PCI_DMA_FROMDEVICE);
2053
2054                         dev_kfree_skb(buffer_info->skb);
2055                         buffer_info->skb = NULL;
2056                 }
2057                 ps_page = &rx_ring->ps_page[i];
2058                 ps_page_dma = &rx_ring->ps_page_dma[i];
2059                 for (j = 0; j < adapter->rx_ps_pages; j++) {
2060                         if (!ps_page->ps_page[j]) break;
2061                         pci_unmap_page(pdev,
2062                                        ps_page_dma->ps_page_dma[j],
2063                                        PAGE_SIZE, PCI_DMA_FROMDEVICE);
2064                         ps_page_dma->ps_page_dma[j] = 0;
2065                         put_page(ps_page->ps_page[j]);
2066                         ps_page->ps_page[j] = NULL;
2067                 }
2068         }
2069
2070         /* there also may be some cached data in our adapter */
2071         if (rx_ring->rx_skb_top) {
2072                 dev_kfree_skb(rx_ring->rx_skb_top);
2073
2074                 /* rx_skb_prev will be wiped out by rx_skb_top */
2075                 rx_ring->rx_skb_top = NULL;
2076                 rx_ring->rx_skb_prev = NULL;
2077         }
2078
2079
2080         size = sizeof(struct e1000_buffer) * rx_ring->count;
2081         memset(rx_ring->buffer_info, 0, size);
2082         size = sizeof(struct e1000_ps_page) * rx_ring->count;
2083         memset(rx_ring->ps_page, 0, size);
2084         size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
2085         memset(rx_ring->ps_page_dma, 0, size);
2086
2087         /* Zero out the descriptor ring */
2088
2089         memset(rx_ring->desc, 0, rx_ring->size);
2090
2091         rx_ring->next_to_clean = 0;
2092         rx_ring->next_to_use = 0;
2093
2094         writel(0, adapter->hw.hw_addr + rx_ring->rdh);
2095         writel(0, adapter->hw.hw_addr + rx_ring->rdt);
2096 }
2097
2098 /**
2099  * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
2100  * @adapter: board private structure
2101  **/
2102
2103 static void
2104 e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2105 {
2106         int i;
2107
2108         for (i = 0; i < adapter->num_rx_queues; i++)
2109                 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2110 }
2111
2112 /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
2113  * and memory write and invalidate disabled for certain operations
2114  */
2115 static void
2116 e1000_enter_82542_rst(struct e1000_adapter *adapter)
2117 {
2118         struct net_device *netdev = adapter->netdev;
2119         uint32_t rctl;
2120
2121         e1000_pci_clear_mwi(&adapter->hw);
2122
2123         rctl = E1000_READ_REG(&adapter->hw, RCTL);
2124         rctl |= E1000_RCTL_RST;
2125         E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2126         E1000_WRITE_FLUSH(&adapter->hw);
2127         mdelay(5);
2128
2129         if(netif_running(netdev))
2130                 e1000_clean_all_rx_rings(adapter);
2131 }
2132
2133 static void
2134 e1000_leave_82542_rst(struct e1000_adapter *adapter)
2135 {
2136         struct net_device *netdev = adapter->netdev;
2137         uint32_t rctl;
2138
2139         rctl = E1000_READ_REG(&adapter->hw, RCTL);
2140         rctl &= ~E1000_RCTL_RST;
2141         E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
2142         E1000_WRITE_FLUSH(&adapter->hw);
2143         mdelay(5);
2144
2145         if(adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
2146                 e1000_pci_set_mwi(&adapter->hw);
2147
2148         if(netif_running(netdev)) {
2149                 e1000_configure_rx(adapter);
2150                 /* No need to loop, because 82542 supports only 1 queue */
2151                 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2152                 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2153         }
2154 }
2155
2156 /**
2157  * e1000_set_mac - Change the Ethernet Address of the NIC
2158  * @netdev: network interface device structure
2159  * @p: pointer to an address structure
2160  *
2161  * Returns 0 on success, negative on failure
2162  **/
2163
2164 static int
2165 e1000_set_mac(struct net_device *netdev, void *p)
2166 {
2167         struct e1000_adapter *adapter = netdev_priv(netdev);
2168         struct sockaddr *addr = p;
2169
2170         if(!is_valid_ether_addr(addr->sa_data))
2171                 return -EADDRNOTAVAIL;
2172
2173         /* 82542 2.0 needs to be in reset to write receive address registers */
2174
2175         if(adapter->hw.mac_type == e1000_82542_rev2_0)
2176                 e1000_enter_82542_rst(adapter);
2177
2178         memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2179         memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
2180
2181         e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2182
2183         /* With 82571 controllers, LAA may be overwritten (with the default)
2184          * due to controller reset from the other port. */
2185         if (adapter->hw.mac_type == e1000_82571) {
2186                 /* activate the work around */
2187                 adapter->hw.laa_is_present = 1;
2188
2189                 /* Hold a copy of the LAA in RAR[14] This is done so that 
2190                  * between the time RAR[0] gets clobbered  and the time it 
2191                  * gets fixed (in e1000_watchdog), the actual LAA is in one 
2192                  * of the RARs and no incoming packets directed to this port
2193                  * are dropped. Eventaully the LAA will be in RAR[0] and 
2194                  * RAR[14] */
2195                 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 
2196                                         E1000_RAR_ENTRIES - 1);
2197         }
2198
2199         if(adapter->hw.mac_type == e1000_82542_rev2_0)
2200                 e1000_leave_82542_rst(adapter);
2201
2202         return 0;
2203 }
2204
2205 /**
2206  * e1000_set_multi - Multicast and Promiscuous mode set
2207  * @netdev: network interface device structure
2208  *
2209  * The set_multi entry point is called whenever the multicast address
2210  * list or the network interface flags are updated.  This routine is
2211  * responsible for configuring the hardware for proper multicast,
2212  * promiscuous mode, and all-multi behavior.
2213  **/
2214
2215 static void
2216 e1000_set_multi(struct net_device *netdev)
2217 {
2218         struct e1000_adapter *adapter = netdev_priv(netdev);
2219         struct e1000_hw *hw = &adapter->hw;
2220         struct dev_mc_list *mc_ptr;
2221         uint32_t rctl;
2222         uint32_t hash_value;
2223         int i, rar_entries = E1000_RAR_ENTRIES;
2224
2225         /* reserve RAR[14] for LAA over-write work-around */
2226         if (adapter->hw.mac_type == e1000_82571)
2227                 rar_entries--;
2228
2229         /* Check for Promiscuous and All Multicast modes */
2230
2231         rctl = E1000_READ_REG(hw, RCTL);
2232
2233         if(netdev->flags & IFF_PROMISC) {
2234                 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2235         } else if(netdev->flags & IFF_ALLMULTI) {
2236                 rctl |= E1000_RCTL_MPE;
2237                 rctl &= ~E1000_RCTL_UPE;
2238         } else {
2239                 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
2240         }
2241
2242         E1000_WRITE_REG(hw, RCTL, rctl);
2243
2244         /* 82542 2.0 needs to be in reset to write receive address registers */
2245
2246         if(hw->mac_type == e1000_82542_rev2_0)
2247                 e1000_enter_82542_rst(adapter);
2248
2249         /* load the first 14 multicast address into the exact filters 1-14
2250          * RAR 0 is used for the station MAC adddress
2251          * if there are not 14 addresses, go ahead and clear the filters
2252          * -- with 82571 controllers only 0-13 entries are filled here
2253          */
2254         mc_ptr = netdev->mc_list;
2255
2256         for(i = 1; i < rar_entries; i++) {
2257                 if (mc_ptr) {
2258                         e1000_rar_set(hw, mc_ptr->dmi_addr, i);
2259                         mc_ptr = mc_ptr->next;
2260                 } else {
2261                         E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2262                         E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2263                 }
2264         }
2265
2266         /* clear the old settings from the multicast hash table */
2267
2268         for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++)
2269                 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2270
2271         /* load any remaining addresses into the hash table */
2272
2273         for(; mc_ptr; mc_ptr = mc_ptr->next) {
2274                 hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
2275                 e1000_mta_set(hw, hash_value);
2276         }
2277
2278         if(hw->mac_type == e1000_82542_rev2_0)
2279                 e1000_leave_82542_rst(adapter);
2280 }
2281
2282 /* Need to wait a few seconds after link up to get diagnostic information from
2283  * the phy */
2284
2285 static void
2286 e1000_update_phy_info(unsigned long data)
2287 {
2288         struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2289         e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2290 }
2291
2292 /**
2293  * e1000_82547_tx_fifo_stall - Timer Call-back
2294  * @data: pointer to adapter cast into an unsigned long
2295  **/
2296
2297 static void
2298 e1000_82547_tx_fifo_stall(unsigned long data)
2299 {
2300         struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2301         struct net_device *netdev = adapter->netdev;
2302         uint32_t tctl;
2303
2304         if(atomic_read(&adapter->tx_fifo_stall)) {
2305                 if((E1000_READ_REG(&adapter->hw, TDT) ==
2306                     E1000_READ_REG(&adapter->hw, TDH)) &&
2307                    (E1000_READ_REG(&adapter->hw, TDFT) ==
2308                     E1000_READ_REG(&adapter->hw, TDFH)) &&
2309                    (E1000_READ_REG(&adapter->hw, TDFTS) ==
2310                     E1000_READ_REG(&adapter->hw, TDFHS))) {
2311                         tctl = E1000_READ_REG(&adapter->hw, TCTL);
2312                         E1000_WRITE_REG(&adapter->hw, TCTL,
2313                                         tctl & ~E1000_TCTL_EN);
2314                         E1000_WRITE_REG(&adapter->hw, TDFT,
2315                                         adapter->tx_head_addr);
2316                         E1000_WRITE_REG(&adapter->hw, TDFH,
2317                                         adapter->tx_head_addr);
2318                         E1000_WRITE_REG(&adapter->hw, TDFTS,
2319                                         adapter->tx_head_addr);
2320                         E1000_WRITE_REG(&adapter->hw, TDFHS,
2321                                         adapter->tx_head_addr);
2322                         E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
2323                         E1000_WRITE_FLUSH(&adapter->hw);
2324
2325                         adapter->tx_fifo_head = 0;
2326                         atomic_set(&adapter->tx_fifo_stall, 0);
2327                         netif_wake_queue(netdev);
2328                 } else {
2329                         mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
2330                 }
2331         }
2332 }
2333
2334 /**
2335  * e1000_watchdog - Timer Call-back
2336  * @data: pointer to adapter cast into an unsigned long
2337  **/
2338 static void
2339 e1000_watchdog(unsigned long data)
2340 {
2341         struct e1000_adapter *adapter = (struct e1000_adapter *) data;
2342
2343         /* Do the rest outside of interrupt context */
2344         schedule_work(&adapter->watchdog_task);
2345 }
2346
2347 static void
2348 e1000_watchdog_task(struct e1000_adapter *adapter)
2349 {
2350         struct net_device *netdev = adapter->netdev;
2351         struct e1000_tx_ring *txdr = adapter->tx_ring;
2352         uint32_t link;
2353
2354         e1000_check_for_link(&adapter->hw);
2355         if (adapter->hw.mac_type == e1000_82573) {
2356                 e1000_enable_tx_pkt_filtering(&adapter->hw);
2357                 if(adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
2358                         e1000_update_mng_vlan(adapter);
2359         }       
2360
2361         if((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
2362            !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
2363                 link = !adapter->hw.serdes_link_down;
2364         else
2365                 link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
2366
2367         if(link) {
2368                 if(!netif_carrier_ok(netdev)) {
2369                         e1000_get_speed_and_duplex(&adapter->hw,
2370                                                    &adapter->link_speed,
2371                                                    &adapter->link_duplex);
2372
2373                         DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n",
2374                                adapter->link_speed,
2375                                adapter->link_duplex == FULL_DUPLEX ?
2376                                "Full Duplex" : "Half Duplex");
2377
2378                         /* tweak tx_queue_len according to speed/duplex */
2379                         netdev->tx_queue_len = adapter->tx_queue_len;
2380                         adapter->tx_timeout_factor = 1;
2381                         if (adapter->link_duplex == HALF_DUPLEX) {
2382                                 switch (adapter->link_speed) {
2383                                 case SPEED_10:
2384                                         netdev->tx_queue_len = 10;
2385                                         adapter->tx_timeout_factor = 8;
2386                                         break;
2387                                 case SPEED_100:
2388                                         netdev->tx_queue_len = 100;
2389                                         break;
2390                                 }
2391                         }
2392
2393                         netif_carrier_on(netdev);
2394                         netif_wake_queue(netdev);
2395                         mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2396                         adapter->smartspeed = 0;
2397                 }
2398         } else {
2399                 if(netif_carrier_ok(netdev)) {
2400                         adapter->link_speed = 0;
2401                         adapter->link_duplex = 0;
2402                         DPRINTK(LINK, INFO, "NIC Link is Down\n");
2403                         netif_carrier_off(netdev);
2404                         netif_stop_queue(netdev);
2405                         mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2406                 }
2407
2408                 e1000_smartspeed(adapter);
2409         }
2410
2411         e1000_update_stats(adapter);
2412
2413         adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2414         adapter->tpt_old = adapter->stats.tpt;
2415         adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
2416         adapter->colc_old = adapter->stats.colc;
2417
2418         adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2419         adapter->gorcl_old = adapter->stats.gorcl;
2420         adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2421         adapter->gotcl_old = adapter->stats.gotcl;
2422
2423         e1000_update_adaptive(&adapter->hw);
2424
2425 #ifdef CONFIG_E1000_MQ
2426         txdr = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2427 #endif
2428         if (!netif_carrier_ok(netdev)) {
2429                 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2430                         /* We've lost link, so the controller stops DMA,
2431                          * but we've got queued Tx work that's never going
2432                          * to get done, so reset controller to flush Tx.
2433                          * (Do the reset outside of interrupt context). */
2434                         schedule_work(&adapter->tx_timeout_task);
2435                 }
2436         }
2437
2438         /* Dynamic mode for Interrupt Throttle Rate (ITR) */
2439         if(adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) {
2440                 /* Symmetric Tx/Rx gets a reduced ITR=2000; Total
2441                  * asymmetrical Tx or Rx gets ITR=8000; everyone
2442                  * else is between 2000-8000. */
2443                 uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000;
2444                 uint32_t dif = (adapter->gotcl > adapter->gorcl ? 
2445                         adapter->gotcl - adapter->gorcl :
2446                         adapter->gorcl - adapter->gotcl) / 10000;
2447                 uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2448                 E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256));
2449         }
2450
2451         /* Cause software interrupt to ensure rx ring is cleaned */
2452         E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
2453
2454         /* Force detection of hung controller every watchdog period */
2455         adapter->detect_tx_hung = TRUE;
2456
2457         /* With 82571 controllers, LAA may be overwritten due to controller 
2458          * reset from the other port. Set the appropriate LAA in RAR[0] */
2459         if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
2460                 e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
2461
2462         /* Reset the timer */
2463         mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
2464 }
2465
2466 #define E1000_TX_FLAGS_CSUM             0x00000001
2467 #define E1000_TX_FLAGS_VLAN             0x00000002
2468 #define E1000_TX_FLAGS_TSO              0x00000004
2469 #define E1000_TX_FLAGS_IPV4             0x00000008
2470 #define E1000_TX_FLAGS_VLAN_MASK        0xffff0000
2471 #define E1000_TX_FLAGS_VLAN_SHIFT       16
2472
2473 static inline int
2474 e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2475           struct sk_buff *skb)
2476 {
2477 #ifdef NETIF_F_TSO
2478         struct e1000_context_desc *context_desc;
2479         struct e1000_buffer *buffer_info;
2480         unsigned int i;
2481         uint32_t cmd_length = 0;
2482         uint16_t ipcse = 0, tucse, mss;
2483         uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
2484         int err;
2485
2486         if(skb_shinfo(skb)->tso_size) {
2487                 if (skb_header_cloned(skb)) {
2488                         err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2489                         if (err)
2490                                 return err;
2491                 }
2492
2493                 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2494                 mss = skb_shinfo(skb)->tso_size;
2495                 if(skb->protocol == ntohs(ETH_P_IP)) {
2496                         skb->nh.iph->tot_len = 0;
2497                         skb->nh.iph->check = 0;
2498                         skb->h.th->check =
2499                                 ~csum_tcpudp_magic(skb->nh.iph->saddr,
2500                                                    skb->nh.iph->daddr,
2501                                                    0,
2502                                                    IPPROTO_TCP,
2503                                                    0);
2504                         cmd_length = E1000_TXD_CMD_IP;
2505                         ipcse = skb->h.raw - skb->data - 1;
2506 #ifdef NETIF_F_TSO_IPV6
2507                 } else if(skb->protocol == ntohs(ETH_P_IPV6)) {
2508                         skb->nh.ipv6h->payload_len = 0;
2509                         skb->h.th->check =
2510                                 ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
2511                                                  &skb->nh.ipv6h->daddr,
2512                                                  0,
2513                                                  IPPROTO_TCP,
2514                                                  0);
2515                         ipcse = 0;
2516 #endif
2517                 }
2518                 ipcss = skb->nh.raw - skb->data;
2519                 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
2520                 tucss = skb->h.raw - skb->data;
2521                 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
2522                 tucse = 0;
2523
2524                 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2525                                E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2526
2527                 i = tx_ring->next_to_use;
2528                 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2529                 buffer_info = &tx_ring->buffer_info[i];
2530
2531                 context_desc->lower_setup.ip_fields.ipcss  = ipcss;
2532                 context_desc->lower_setup.ip_fields.ipcso  = ipcso;
2533                 context_desc->lower_setup.ip_fields.ipcse  = cpu_to_le16(ipcse);
2534                 context_desc->upper_setup.tcp_fields.tucss = tucss;
2535                 context_desc->upper_setup.tcp_fields.tucso = tucso;
2536                 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2537                 context_desc->tcp_seg_setup.fields.mss     = cpu_to_le16(mss);
2538                 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2539                 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2540
2541                 buffer_info->time_stamp = jiffies;
2542
2543                 if (++i == tx_ring->count) i = 0;
2544                 tx_ring->next_to_use = i;
2545
2546                 return 1;
2547         }
2548 #endif
2549
2550         return 0;
2551 }
2552
2553 static inline boolean_t
2554 e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2555               struct sk_buff *skb)
2556 {
2557         struct e1000_context_desc *context_desc;
2558         struct e1000_buffer *buffer_info;
2559         unsigned int i;
2560         uint8_t css;
2561
2562         if(likely(skb->ip_summed == CHECKSUM_HW)) {
2563                 css = skb->h.raw - skb->data;
2564
2565                 i = tx_ring->next_to_use;
2566                 buffer_info = &tx_ring->buffer_info[i];
2567                 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2568
2569                 context_desc->upper_setup.tcp_fields.tucss = css;
2570                 context_desc->upper_setup.tcp_fields.tucso = css + skb->csum;
2571                 context_desc->upper_setup.tcp_fields.tucse = 0;
2572                 context_desc->tcp_seg_setup.data = 0;
2573                 context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
2574
2575                 buffer_info->time_stamp = jiffies;
2576
2577                 if (unlikely(++i == tx_ring->count)) i = 0;
2578                 tx_ring->next_to_use = i;
2579
2580                 return TRUE;
2581         }
2582
2583         return FALSE;
2584 }
2585
2586 #define E1000_MAX_TXD_PWR       12
2587 #define E1000_MAX_DATA_PER_TXD  (1<<E1000_MAX_TXD_PWR)
2588
2589 static inline int
2590 e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2591              struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
2592              unsigned int nr_frags, unsigned int mss)
2593 {
2594         struct e1000_buffer *buffer_info;
2595         unsigned int len = skb->len;
2596         unsigned int offset = 0, size, count = 0, i;
2597         unsigned int f;
2598         len -= skb->data_len;
2599
2600         i = tx_ring->next_to_use;
2601
2602         while(len) {
2603                 buffer_info = &tx_ring->buffer_info[i];
2604                 size = min(len, max_per_txd);
2605 #ifdef NETIF_F_TSO
2606                 /* Workaround for Controller erratum --
2607                  * descriptor for non-tso packet in a linear SKB that follows a
2608                  * tso gets written back prematurely before the data is fully
2609                  * DMAd to the controller */
2610                 if (!skb->data_len && tx_ring->last_tx_tso &&
2611                                 !skb_shinfo(skb)->tso_size) {
2612                         tx_ring->last_tx_tso = 0;
2613                         size -= 4;
2614                 }
2615
2616                 /* Workaround for premature desc write-backs
2617                  * in TSO mode.  Append 4-byte sentinel desc */
2618                 if(unlikely(mss && !nr_frags && size == len && size > 8))
2619                         size -= 4;
2620 #endif
2621                 /* work-around for errata 10 and it applies
2622                  * to all controllers in PCI-X mode
2623                  * The fix is to make sure that the first descriptor of a
2624                  * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
2625                  */
2626                 if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2627                                 (size > 2015) && count == 0))
2628                         size = 2015;
2629                                                                                 
2630                 /* Workaround for potential 82544 hang in PCI-X.  Avoid
2631                  * terminating buffers within evenly-aligned dwords. */
2632                 if(unlikely(adapter->pcix_82544 &&
2633                    !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2634                    size > 4))
2635                         size -= 4;
2636
2637                 buffer_info->length = size;
2638                 buffer_info->dma =
2639                         pci_map_single(adapter->pdev,
2640                                 skb->data + offset,
2641                                 size,
2642                                 PCI_DMA_TODEVICE);
2643                 buffer_info->time_stamp = jiffies;
2644
2645                 len -= size;
2646                 offset += size;
2647                 count++;
2648                 if(unlikely(++i == tx_ring->count)) i = 0;
2649         }
2650
2651         for(f = 0; f < nr_frags; f++) {
2652                 struct skb_frag_struct *frag;
2653
2654                 frag = &skb_shinfo(skb)->frags[f];
2655                 len = frag->size;
2656                 offset = frag->page_offset;
2657
2658                 while(len) {
2659                         buffer_info = &tx_ring->buffer_info[i];
2660                         size = min(len, max_per_txd);
2661 #ifdef NETIF_F_TSO
2662                         /* Workaround for premature desc write-backs
2663                          * in TSO mode.  Append 4-byte sentinel desc */
2664                         if(unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
2665                                 size -= 4;
2666 #endif
2667                         /* Workaround for potential 82544 hang in PCI-X.
2668                          * Avoid terminating buffers within evenly-aligned
2669                          * dwords. */
2670                         if(unlikely(adapter->pcix_82544 &&
2671                            !((unsigned long)(frag->page+offset+size-1) & 4) &&
2672                            size > 4))
2673                                 size -= 4;
2674
2675                         buffer_info->length = size;
2676                         buffer_info->dma =
2677                                 pci_map_page(adapter->pdev,
2678                                         frag->page,
2679                                         offset,
2680                                         size,
2681                                         PCI_DMA_TODEVICE);
2682                         buffer_info->time_stamp = jiffies;
2683
2684                         len -= size;
2685                         offset += size;
2686                         count++;
2687                         if(unlikely(++i == tx_ring->count)) i = 0;
2688                 }
2689         }
2690
2691         i = (i == 0) ? tx_ring->count - 1 : i - 1;
2692         tx_ring->buffer_info[i].skb = skb;
2693         tx_ring->buffer_info[first].next_to_watch = i;
2694
2695         return count;
2696 }
2697
2698 static inline void
2699 e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
2700                int tx_flags, int count)
2701 {
2702         struct e1000_tx_desc *tx_desc = NULL;
2703         struct e1000_buffer *buffer_info;
2704         uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2705         unsigned int i;
2706
2707         if(likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2708                 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
2709                              E1000_TXD_CMD_TSE;
2710                 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2711
2712                 if(likely(tx_flags & E1000_TX_FLAGS_IPV4))
2713                         txd_upper |= E1000_TXD_POPTS_IXSM << 8;
2714         }
2715
2716         if(likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
2717                 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
2718                 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
2719         }
2720
2721         if(unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
2722                 txd_lower |= E1000_TXD_CMD_VLE;
2723                 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
2724         }
2725
2726         i = tx_ring->next_to_use;
2727
2728         while(count--) {
2729                 buffer_info = &tx_ring->buffer_info[i];
2730                 tx_desc = E1000_TX_DESC(*tx_ring, i);
2731                 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
2732                 tx_desc->lower.data =
2733                         cpu_to_le32(txd_lower | buffer_info->length);
2734                 tx_desc->upper.data = cpu_to_le32(txd_upper);
2735                 if(unlikely(++i == tx_ring->count)) i = 0;
2736         }
2737
2738         tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
2739
2740         /* Force memory writes to complete before letting h/w
2741          * know there are new descriptors to fetch.  (Only
2742          * applicable for weak-ordered memory model archs,
2743          * such as IA-64). */
2744         wmb();
2745
2746         tx_ring->next_to_use = i;
2747         writel(i, adapter->hw.hw_addr + tx_ring->tdt);
2748 }
2749
2750 /**
2751  * 82547 workaround to avoid controller hang in half-duplex environment.
2752  * The workaround is to avoid queuing a large packet that would span
2753  * the internal Tx FIFO ring boundary by notifying the stack to resend
2754  * the packet at a later time.  This gives the Tx FIFO an opportunity to
2755  * flush all packets.  When that occurs, we reset the Tx FIFO pointers
2756  * to the beginning of the Tx FIFO.
2757  **/
2758
2759 #define E1000_FIFO_HDR                  0x10
2760 #define E1000_82547_PAD_LEN             0x3E0
2761
2762 static inline int
2763 e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
2764 {
2765         uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
2766         uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
2767
2768         E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR);
2769
2770         if(adapter->link_duplex != HALF_DUPLEX)
2771                 goto no_fifo_stall_required;
2772
2773         if(atomic_read(&adapter->tx_fifo_stall))
2774                 return 1;
2775
2776         if(skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
2777                 atomic_set(&adapter->tx_fifo_stall, 1);
2778                 return 1;
2779         }
2780
2781 no_fifo_stall_required:
2782         adapter->tx_fifo_head += skb_fifo_len;
2783         if(adapter->tx_fifo_head >= adapter->tx_fifo_size)
2784                 adapter->tx_fifo_head -= adapter->tx_fifo_size;
2785         return 0;
2786 }
2787
2788 #define MINIMUM_DHCP_PACKET_SIZE 282
2789 static inline int
2790 e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
2791 {
2792         struct e1000_hw *hw =  &adapter->hw;
2793         uint16_t length, offset;
2794         if(vlan_tx_tag_present(skb)) {
2795                 if(!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
2796                         ( adapter->hw.mng_cookie.status &
2797                           E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
2798                         return 0;
2799         }
2800         if ((skb->len > MINIMUM_DHCP_PACKET_SIZE) && (!skb->protocol)) {
2801                 struct ethhdr *eth = (struct ethhdr *) skb->data;
2802                 if((htons(ETH_P_IP) == eth->h_proto)) {
2803                         const struct iphdr *ip = 
2804                                 (struct iphdr *)((uint8_t *)skb->data+14);
2805                         if(IPPROTO_UDP == ip->protocol) {
2806                                 struct udphdr *udp = 
2807                                         (struct udphdr *)((uint8_t *)ip + 
2808                                                 (ip->ihl << 2));
2809                                 if(ntohs(udp->dest) == 67) {
2810                                         offset = (uint8_t *)udp + 8 - skb->data;
2811                                         length = skb->len - offset;
2812
2813                                         return e1000_mng_write_dhcp_info(hw,
2814                                                         (uint8_t *)udp + 8, 
2815                                                         length);
2816                                 }
2817                         }
2818                 }
2819         }
2820         return 0;
2821 }
2822
2823 #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
2824 static int
2825 e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
2826 {
2827         struct e1000_adapter *adapter = netdev_priv(netdev);
2828         struct e1000_tx_ring *tx_ring;
2829         unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
2830         unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
2831         unsigned int tx_flags = 0;
2832         unsigned int len = skb->len;
2833         unsigned long flags;
2834         unsigned int nr_frags = 0;
2835         unsigned int mss = 0;
2836         int count = 0;
2837         int tso;
2838         unsigned int f;
2839         len -= skb->data_len;
2840
2841 #ifdef CONFIG_E1000_MQ
2842         tx_ring = *per_cpu_ptr(adapter->cpu_tx_ring, smp_processor_id());
2843 #else
2844         tx_ring = adapter->tx_ring;
2845 #endif
2846
2847         if (unlikely(skb->len <= 0)) {
2848                 dev_kfree_skb_any(skb);
2849                 return NETDEV_TX_OK;
2850         }
2851
2852 #ifdef NETIF_F_TSO
2853         mss = skb_shinfo(skb)->tso_size;
2854         /* The controller does a simple calculation to 
2855          * make sure there is enough room in the FIFO before
2856          * initiating the DMA for each buffer.  The calc is:
2857          * 4 = ceil(buffer len/mss).  To make sure we don't
2858          * overrun the FIFO, adjust the max buffer len if mss
2859          * drops. */
2860         if(mss) {
2861                 uint8_t hdr_len;
2862                 max_per_txd = min(mss << 2, max_per_txd);
2863                 max_txd_pwr = fls(max_per_txd) - 1;
2864
2865         /* TSO Workaround for 82571/2 Controllers -- if skb->data
2866          * points to just header, pull a few bytes of payload from
2867          * frags into skb->data */
2868                 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
2869                 if (skb->data_len && (hdr_len == (skb->len - skb->data_len)) &&
2870                         (adapter->hw.mac_type == e1000_82571 ||
2871                         adapter->hw.mac_type == e1000_82572)) {
2872                         unsigned int pull_size;
2873                         pull_size = min((unsigned int)4, skb->data_len);
2874                         if (!__pskb_pull_tail(skb, pull_size)) {
2875                                 printk(KERN_ERR "__pskb_pull_tail failed.\n");
2876                                 dev_kfree_skb_any(skb);
2877                                 return -EFAULT;
2878                         }
2879                         len = skb->len - skb->data_len;
2880                 }
2881         }
2882
2883         if((mss) || (skb->ip_summed == CHECKSUM_HW))
2884         /* reserve a descriptor for the offload context */
2885                 count++;
2886         count++;
2887 #else
2888         if(skb->ip_summed == CHECKSUM_HW)
2889                 count++;
2890 #endif
2891
2892 #ifdef NETIF_F_TSO
2893         /* Controller Erratum workaround */
2894         if (!skb->data_len && tx_ring->last_tx_tso &&
2895                 !skb_shinfo(skb)->tso_size)
2896                 count++;
2897 #endif
2898
2899         count += TXD_USE_COUNT(len, max_txd_pwr);
2900
2901         if(adapter->pcix_82544)
2902                 count++;
2903
2904         /* work-around for errata 10 and it applies to all controllers 
2905          * in PCI-X mode, so add one more descriptor to the count
2906          */
2907         if(unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
2908                         (len > 2015)))
2909                 count++;
2910
2911         nr_frags = skb_shinfo(skb)->nr_frags;
2912         for(f = 0; f < nr_frags; f++)
2913                 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
2914                                        max_txd_pwr);
2915         if(adapter->pcix_82544)
2916                 count += nr_frags;
2917
2918         if(adapter->hw.tx_pkt_filtering && (adapter->hw.mac_type == e1000_82573) )
2919                 e1000_transfer_dhcp_info(adapter, skb);
2920
2921         local_irq_save(flags);
2922         if (!spin_trylock(&tx_ring->tx_lock)) {
2923                 /* Collision - tell upper layer to requeue */
2924                 local_irq_restore(flags);
2925                 return NETDEV_TX_LOCKED;
2926         }
2927
2928         /* need: count + 2 desc gap to keep tail from touching
2929          * head, otherwise try next time */
2930         if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) {
2931                 netif_stop_queue(netdev);
2932                 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2933                 return NETDEV_TX_BUSY;
2934         }
2935
2936         if(unlikely(adapter->hw.mac_type == e1000_82547)) {
2937                 if(unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
2938                         netif_stop_queue(netdev);
2939                         mod_timer(&adapter->tx_fifo_stall_timer, jiffies);
2940                         spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2941                         return NETDEV_TX_BUSY;
2942                 }
2943         }
2944
2945         if(unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
2946                 tx_flags |= E1000_TX_FLAGS_VLAN;
2947                 tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
2948         }
2949
2950         first = tx_ring->next_to_use;
2951         
2952         tso = e1000_tso(adapter, tx_ring, skb);
2953         if (tso < 0) {
2954                 dev_kfree_skb_any(skb);
2955                 spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2956                 return NETDEV_TX_OK;
2957         }
2958
2959         if (likely(tso)) {
2960                 tx_ring->last_tx_tso = 1;
2961                 tx_flags |= E1000_TX_FLAGS_TSO;
2962         } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
2963                 tx_flags |= E1000_TX_FLAGS_CSUM;
2964
2965         /* Old method was to assume IPv4 packet by default if TSO was enabled.
2966          * 82571 hardware supports TSO capabilities for IPv6 as well...
2967          * no longer assume, we must. */
2968         if (likely(skb->protocol == ntohs(ETH_P_IP)))
2969                 tx_flags |= E1000_TX_FLAGS_IPV4;
2970
2971         e1000_tx_queue(adapter, tx_ring, tx_flags,
2972                        e1000_tx_map(adapter, tx_ring, skb, first,
2973                                     max_per_txd, nr_frags, mss));
2974
2975         netdev->trans_start = jiffies;
2976
2977         /* Make sure there is space in the ring for the next send. */
2978         if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2))
2979                 netif_stop_queue(netdev);
2980
2981         spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
2982         return NETDEV_TX_OK;
2983 }
2984
2985 /**
2986  * e1000_tx_timeout - Respond to a Tx Hang
2987  * @netdev: network interface device structure
2988  **/
2989
2990 static void
2991 e1000_tx_timeout(struct net_device *netdev)
2992 {
2993         struct e1000_adapter *adapter = netdev_priv(netdev);
2994
2995         /* Do the reset outside of interrupt context */
2996         schedule_work(&adapter->tx_timeout_task);
2997 }
2998
2999 static void
3000 e1000_tx_timeout_task(struct net_device *netdev)
3001 {
3002         struct e1000_adapter *adapter = netdev_priv(netdev);
3003
3004         adapter->tx_timeout_count++;
3005         e1000_down(adapter);
3006         e1000_up(adapter);
3007 }
3008
3009 /**
3010  * e1000_get_stats - Get System Network Statistics
3011  * @netdev: network interface device structure
3012  *
3013  * Returns the address of the device statistics structure.
3014  * The statistics are actually updated from the timer callback.
3015  **/
3016
3017 static struct net_device_stats *
3018 e1000_get_stats(struct net_device *netdev)
3019 {
3020         struct e1000_adapter *adapter = netdev_priv(netdev);
3021
3022         /* only return the current stats */
3023         return &adapter->net_stats;
3024 }
3025
3026 /**
3027  * e1000_change_mtu - Change the Maximum Transfer Unit
3028  * @netdev: network interface device structure
3029  * @new_mtu: new value for maximum frame size
3030  *
3031  * Returns 0 on success, negative on failure
3032  **/
3033
3034 static int
3035 e1000_change_mtu(struct net_device *netdev, int new_mtu)
3036 {
3037         struct e1000_adapter *adapter = netdev_priv(netdev);
3038         int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
3039
3040         if((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
3041                 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3042                         DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
3043                 return -EINVAL;
3044         }
3045
3046         /* Adapter-specific max frame size limits. */
3047         switch (adapter->hw.mac_type) {
3048         case e1000_82542_rev2_0:
3049         case e1000_82542_rev2_1:
3050         case e1000_82573:
3051                 if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
3052                         DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
3053                         return -EINVAL;
3054                 }
3055                 break;
3056         case e1000_82571:
3057         case e1000_82572:
3058 #define MAX_STD_JUMBO_FRAME_SIZE 9234
3059                 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3060                         DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
3061                         return -EINVAL;
3062                 }
3063                 break;
3064         default:
3065                 /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
3066                 break;
3067         }
3068
3069         /* since the driver code now supports splitting a packet across
3070          * multiple descriptors, most of the fifo related limitations on
3071          * jumbo frame traffic have gone away.
3072          * simply use 2k descriptors for everything.
3073          *
3074          * NOTE: dev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3075          * means we reserve 2 more, this pushes us to allocate from the next
3076          * larger slab size
3077          * i.e. RXBUFFER_2048 --> size-4096 slab */
3078
3079         /* recent hardware supports 1KB granularity */
3080         if (adapter->hw.mac_type > e1000_82547_rev_2) {
3081                 adapter->rx_buffer_len =
3082                     ((max_frame < E1000_RXBUFFER_2048) ?
3083                         max_frame : E1000_RXBUFFER_2048);
3084                 E1000_ROUNDUP(adapter->rx_buffer_len, 1024);
3085         } else
3086                 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3087
3088         netdev->mtu = new_mtu;
3089
3090         if(netif_running(netdev)) {
3091                 e1000_down(adapter);
3092                 e1000_up(adapter);
3093         }
3094
3095         adapter->hw.max_frame_size = max_frame;
3096
3097         return 0;
3098 }
3099
3100 /**
3101  * e1000_update_stats - Update the board statistics counters
3102  * @adapter: board private structure
3103  **/
3104
3105 void
3106 e1000_update_stats(struct e1000_adapter *adapter)
3107 {
3108         struct e1000_hw *hw = &adapter->hw;
3109         unsigned long flags;
3110         uint16_t phy_tmp;
3111
3112 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3113
3114         spin_lock_irqsave(&adapter->stats_lock, flags);
3115
3116         /* these counters are modified from e1000_adjust_tbi_stats,
3117          * called from the interrupt context, so they must only
3118          * be written while holding adapter->stats_lock
3119          */
3120
3121         adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
3122         adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
3123         adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
3124         adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
3125         adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
3126         adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
3127         adapter->stats.roc += E1000_READ_REG(hw, ROC);
3128         adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
3129         adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
3130         adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
3131         adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
3132         adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
3133         adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
3134
3135         adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
3136         adapter->stats.mpc += E1000_READ_REG(hw, MPC);
3137         adapter->stats.scc += E1000_READ_REG(hw, SCC);
3138         adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
3139         adapter->stats.mcc += E1000_READ_REG(hw, MCC);
3140         adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
3141         adapter->stats.dc += E1000_READ_REG(hw, DC);
3142         adapter->stats.sec += E1000_READ_REG(hw, SEC);
3143         adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
3144         adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
3145         adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
3146         adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
3147         adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
3148         adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
3149         adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
3150         adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
3151         adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
3152         adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
3153         adapter->stats.ruc += E1000_READ_REG(hw, RUC);
3154         adapter->stats.rfc += E1000_READ_REG(hw, RFC);
3155         adapter->stats.rjc += E1000_READ_REG(hw, RJC);
3156         adapter->stats.torl += E1000_READ_REG(hw, TORL);
3157         adapter->stats.torh += E1000_READ_REG(hw, TORH);
3158         adapter->stats.totl += E1000_READ_REG(hw, TOTL);
3159         adapter->stats.toth += E1000_READ_REG(hw, TOTH);
3160         adapter->stats.tpr += E1000_READ_REG(hw, TPR);
3161         adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
3162         adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
3163         adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
3164         adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
3165         adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
3166         adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
3167         adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
3168         adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
3169
3170         /* used for adaptive IFS */
3171
3172         hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
3173         adapter->stats.tpt += hw->tx_packet_delta;
3174         hw->collision_delta = E1000_READ_REG(hw, COLC);
3175         adapter->stats.colc += hw->collision_delta;
3176
3177         if(hw->mac_type >= e1000_82543) {
3178                 adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
3179                 adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
3180                 adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
3181                 adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
3182                 adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
3183                 adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
3184         }
3185         if(hw->mac_type > e1000_82547_rev_2) {
3186                 adapter->stats.iac += E1000_READ_REG(hw, IAC);
3187                 adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
3188                 adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
3189                 adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
3190                 adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
3191                 adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
3192                 adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
3193                 adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
3194                 adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
3195         }
3196
3197         /* Fill out the OS statistics structure */
3198
3199         adapter->net_stats.rx_packets = adapter->stats.gprc;
3200         adapter->net_stats.tx_packets = adapter->stats.gptc;
3201         adapter->net_stats.rx_bytes = adapter->stats.gorcl;
3202         adapter->net_stats.tx_bytes = adapter->stats.gotcl;
3203         adapter->net_stats.multicast = adapter->stats.mprc;
3204         adapter->net_stats.collisions = adapter->stats.colc;
3205
3206         /* Rx Errors */
3207
3208         adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3209                 adapter->stats.crcerrs + adapter->stats.algnerrc +
3210                 adapter->stats.rlec + adapter->stats.cexterr;
3211         adapter->net_stats.rx_dropped = 0;
3212         adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3213         adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3214         adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3215         adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3216
3217         /* Tx Errors */
3218
3219         adapter->net_stats.tx_errors = adapter->stats.ecol +
3220                                        adapter->stats.latecol;
3221         adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3222         adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3223         adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3224
3225         /* Tx Dropped needs to be maintained elsewhere */
3226
3227         /* Phy Stats */
3228
3229         if(hw->media_type == e1000_media_type_copper) {
3230                 if((adapter->link_speed == SPEED_1000) &&
3231                    (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3232                         phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3233                         adapter->phy_stats.idle_errors += phy_tmp;
3234                 }
3235
3236                 if((hw->mac_type <= e1000_82546) &&
3237                    (hw->phy_type == e1000_phy_m88) &&
3238                    !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3239                         adapter->phy_stats.receive_errors += phy_tmp;
3240         }
3241
3242         spin_unlock_irqrestore(&adapter->stats_lock, flags);
3243 }
3244
3245 #ifdef CONFIG_E1000_MQ
3246 void
3247 e1000_rx_schedule(void *data)
3248 {
3249         struct net_device *poll_dev, *netdev = data;
3250         struct e1000_adapter *adapter = netdev->priv;
3251         int this_cpu = get_cpu();
3252
3253         poll_dev = *per_cpu_ptr(adapter->cpu_netdev, this_cpu);
3254         if (poll_dev == NULL) {
3255                 put_cpu();
3256                 return;
3257         }
3258
3259         if (likely(netif_rx_schedule_prep(poll_dev)))
3260                 __netif_rx_schedule(poll_dev);
3261         else
3262                 e1000_irq_enable(adapter);
3263
3264         put_cpu();
3265 }
3266 #endif
3267
3268 /**
3269  * e1000_intr - Interrupt Handler
3270  * @irq: interrupt number
3271  * @data: pointer to a network interface device structure
3272  * @pt_regs: CPU registers structure
3273  **/
3274
3275 static irqreturn_t
3276 e1000_intr(int irq, void *data, struct pt_regs *regs)
3277 {
3278         struct net_device *netdev = data;
3279         struct e1000_adapter *adapter = netdev_priv(netdev);
3280         struct e1000_hw *hw = &adapter->hw;
3281         uint32_t icr = E1000_READ_REG(hw, ICR);
3282 #ifndef CONFIG_E1000_NAPI
3283         int i;
3284 #else
3285         /* Interrupt Auto-Mask...upon reading ICR,
3286          * interrupts are masked.  No need for the
3287          * IMC write, but it does mean we should
3288          * account for it ASAP. */
3289         if (likely(hw->mac_type >= e1000_82571))
3290                 atomic_inc(&adapter->irq_sem);
3291 #endif
3292
3293         if (unlikely(!icr)) {
3294 #ifdef CONFIG_E1000_NAPI
3295                 if (hw->mac_type >= e1000_82571)
3296                         e1000_irq_enable(adapter);
3297 #endif
3298                 return IRQ_NONE;  /* Not our interrupt */
3299         }
3300
3301         if(unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3302                 hw->get_link_status = 1;
3303                 mod_timer(&adapter->watchdog_timer, jiffies);
3304         }
3305
3306 #ifdef CONFIG_E1000_NAPI
3307         if (unlikely(hw->mac_type < e1000_82571)) {
3308                 atomic_inc(&adapter->irq_sem);
3309                 E1000_WRITE_REG(hw, IMC, ~0);
3310                 E1000_WRITE_FLUSH(hw);
3311         }
3312 #ifdef CONFIG_E1000_MQ
3313         if (atomic_read(&adapter->rx_sched_call_data.count) == 0) {
3314                 /* We must setup the cpumask once count == 0 since
3315                  * each cpu bit is cleared when the work is done. */
3316                 adapter->rx_sched_call_data.cpumask = adapter->cpumask;
3317                 atomic_add(adapter->num_rx_queues - 1, &adapter->irq_sem);
3318                 atomic_set(&adapter->rx_sched_call_data.count,
3319                            adapter->num_rx_queues);
3320                 smp_call_async_mask(&adapter->rx_sched_call_data);
3321         } else {
3322                 printk("call_data.count == %u\n", atomic_read(&adapter->rx_sched_call_data.count));
3323         }
3324 #else /* if !CONFIG_E1000_MQ */
3325         if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0])))
3326                 __netif_rx_schedule(&adapter->polling_netdev[0]);
3327         else
3328                 e1000_irq_enable(adapter);
3329 #endif /* CONFIG_E1000_MQ */
3330
3331 #else /* if !CONFIG_E1000_NAPI */
3332         /* Writing IMC and IMS is needed for 82547.
3333            Due to Hub Link bus being occupied, an interrupt
3334            de-assertion message is not able to be sent.
3335            When an interrupt assertion message is generated later,
3336            two messages are re-ordered and sent out.
3337            That causes APIC to think 82547 is in de-assertion
3338            state, while 82547 is in assertion state, resulting
3339            in dead lock. Writing IMC forces 82547 into
3340            de-assertion state.
3341         */
3342         if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2){
3343                 atomic_inc(&adapter->irq_sem);
3344                 E1000_WRITE_REG(hw, IMC, ~0);
3345         }
3346
3347         for(i = 0; i < E1000_MAX_INTR; i++)
3348                 if(unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
3349                    !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
3350                         break;
3351
3352         if(hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
3353                 e1000_irq_enable(adapter);
3354
3355 #endif /* CONFIG_E1000_NAPI */
3356
3357         return IRQ_HANDLED;
3358 }
3359
3360 #ifdef CONFIG_E1000_NAPI
3361 /**
3362  * e1000_clean - NAPI Rx polling callback
3363  * @adapter: board private structure
3364  **/
3365
3366 static int
3367 e1000_clean(struct net_device *poll_dev, int *budget)
3368 {
3369         struct e1000_adapter *adapter;
3370         int work_to_do = min(*budget, poll_dev->quota);
3371         int tx_cleaned, i = 0, work_done = 0;
3372
3373         /* Must NOT use netdev_priv macro here. */
3374         adapter = poll_dev->priv;
3375
3376         /* Keep link state information with original netdev */
3377         if (!netif_carrier_ok(adapter->netdev))
3378                 goto quit_polling;
3379
3380         while (poll_dev != &adapter->polling_netdev[i]) {
3381                 i++;
3382                 if (unlikely(i == adapter->num_rx_queues))
3383                         BUG();
3384         }
3385
3386         tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]);
3387         adapter->clean_rx(adapter, &adapter->rx_ring[i],
3388                           &work_done, work_to_do);
3389
3390         *budget -= work_done;
3391         poll_dev->quota -= work_done;
3392         
3393         /* If no Tx and not enough Rx work done, exit the polling mode */
3394         if((!tx_cleaned && (work_done == 0)) ||
3395            !netif_running(adapter->netdev)) {
3396 quit_polling:
3397                 netif_rx_complete(poll_dev);
3398                 e1000_irq_enable(adapter);
3399                 return 0;
3400         }
3401
3402         return 1;
3403 }
3404
3405 #endif
3406 /**
3407  * e1000_clean_tx_irq - Reclaim resources after transmit completes
3408  * @adapter: board private structure
3409  **/
3410
3411 static boolean_t
3412 e1000_clean_tx_irq(struct e1000_adapter *adapter,
3413                    struct e1000_tx_ring *tx_ring)
3414 {
3415         struct net_device *netdev = adapter->netdev;
3416         struct e1000_tx_desc *tx_desc, *eop_desc;
3417         struct e1000_buffer *buffer_info;
3418         unsigned int i, eop;
3419         boolean_t cleaned = FALSE;
3420
3421         i = tx_ring->next_to_clean;
3422         eop = tx_ring->buffer_info[i].next_to_watch;
3423         eop_desc = E1000_TX_DESC(*tx_ring, eop);
3424
3425         while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
3426                 for(cleaned = FALSE; !cleaned; ) {
3427                         tx_desc = E1000_TX_DESC(*tx_ring, i);
3428                         buffer_info = &tx_ring->buffer_info[i];
3429                         cleaned = (i == eop);
3430
3431                         e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3432
3433                         tx_desc->buffer_addr = 0;
3434                         tx_desc->lower.data = 0;
3435                         tx_desc->upper.data = 0;
3436
3437                         if(unlikely(++i == tx_ring->count)) i = 0;
3438                 }
3439
3440 #ifdef CONFIG_E1000_MQ
3441                 tx_ring->tx_stats.packets++;
3442 #endif
3443
3444                 eop = tx_ring->buffer_info[i].next_to_watch;
3445                 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3446         }
3447
3448         tx_ring->next_to_clean = i;
3449
3450         spin_lock(&tx_ring->tx_lock);
3451
3452         if(unlikely(cleaned && netif_queue_stopped(netdev) &&
3453                     netif_carrier_ok(netdev)))
3454                 netif_wake_queue(netdev);
3455
3456         spin_unlock(&tx_ring->tx_lock);
3457
3458         if (adapter->detect_tx_hung) {
3459                 /* Detect a transmit hang in hardware, this serializes the
3460                  * check with the clearing of time_stamp and movement of i */
3461                 adapter->detect_tx_hung = FALSE;
3462                 if (tx_ring->buffer_info[eop].dma &&
3463                     time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3464                                adapter->tx_timeout_factor * HZ)
3465                     && !(E1000_READ_REG(&adapter->hw, STATUS) &
3466                          E1000_STATUS_TXOFF)) {
3467
3468                         /* detected Tx unit hang */
3469                         DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
3470                                         "  Tx Queue             <%lu>\n"
3471                                         "  TDH                  <%x>\n"
3472                                         "  TDT                  <%x>\n"
3473                                         "  next_to_use          <%x>\n"
3474                                         "  next_to_clean        <%x>\n"
3475                                         "buffer_info[next_to_clean]\n"
3476                                         "  time_stamp           <%lx>\n"
3477                                         "  next_to_watch        <%x>\n"
3478                                         "  jiffies              <%lx>\n"
3479                                         "  next_to_watch.status <%x>\n",
3480                                 (unsigned long)((tx_ring - adapter->tx_ring) /
3481                                         sizeof(struct e1000_tx_ring)),
3482                                 readl(adapter->hw.hw_addr + tx_ring->tdh),
3483                                 readl(adapter->hw.hw_addr + tx_ring->tdt),
3484                                 tx_ring->next_to_use,
3485                                 tx_ring->next_to_clean,
3486                                 tx_ring->buffer_info[eop].time_stamp,
3487                                 eop,
3488                                 jiffies,
3489                                 eop_desc->upper.fields.status);
3490                         netif_stop_queue(netdev);
3491                 }
3492         }
3493         return cleaned;
3494 }
3495
3496 /**
3497  * e1000_rx_checksum - Receive Checksum Offload for 82543
3498  * @adapter:     board private structure
3499  * @status_err:  receive descriptor status and error fields
3500  * @csum:        receive descriptor csum field
3501  * @sk_buff:     socket buffer with received data
3502  **/
3503
3504 static inline void
3505 e1000_rx_checksum(struct e1000_adapter *adapter,
3506                   uint32_t status_err, uint32_t csum,
3507                   struct sk_buff *skb)
3508 {
3509         uint16_t status = (uint16_t)status_err;
3510         uint8_t errors = (uint8_t)(status_err >> 24);
3511         skb->ip_summed = CHECKSUM_NONE;
3512
3513         /* 82543 or newer only */
3514         if(unlikely(adapter->hw.mac_type < e1000_82543)) return;
3515         /* Ignore Checksum bit is set */
3516         if(unlikely(status & E1000_RXD_STAT_IXSM)) return;
3517         /* TCP/UDP checksum error bit is set */
3518         if(unlikely(errors & E1000_RXD_ERR_TCPE)) {
3519                 /* let the stack verify checksum errors */
3520                 adapter->hw_csum_err++;
3521                 return;
3522         }
3523         /* TCP/UDP Checksum has not been calculated */
3524         if(adapter->hw.mac_type <= e1000_82547_rev_2) {
3525                 if(!(status & E1000_RXD_STAT_TCPCS))
3526                         return;
3527         } else {
3528                 if(!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
3529                         return;
3530         }
3531         /* It must be a TCP or UDP packet with a valid checksum */
3532         if (likely(status & E1000_RXD_STAT_TCPCS)) {
3533                 /* TCP checksum is good */
3534                 skb->ip_summed = CHECKSUM_UNNECESSARY;
3535         } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
3536                 /* IP fragment with UDP payload */
3537                 /* Hardware complements the payload checksum, so we undo it
3538                  * and then put the value in host order for further stack use.
3539                  */
3540                 csum = ntohl(csum ^ 0xFFFF);
3541                 skb->csum = csum;
3542                 skb->ip_summed = CHECKSUM_HW;
3543         }
3544         adapter->hw_csum_good++;
3545 }
3546
3547 /**
3548  * e1000_clean_rx_irq - Send received data up the network stack; legacy
3549  * @adapter: board private structure
3550  **/
3551
3552 static boolean_t
3553 #ifdef CONFIG_E1000_NAPI
3554 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3555                    struct e1000_rx_ring *rx_ring,
3556                    int *work_done, int work_to_do)
3557 #else
3558 e1000_clean_rx_irq(struct e1000_adapter *adapter,
3559                    struct e1000_rx_ring *rx_ring)
3560 #endif
3561 {
3562         struct net_device *netdev = adapter->netdev;
3563         struct pci_dev *pdev = adapter->pdev;
3564         struct e1000_rx_desc *rx_desc;
3565         struct e1000_buffer *buffer_info;
3566         struct sk_buff *skb;
3567         unsigned long flags;
3568         uint32_t length;
3569         uint8_t last_byte;
3570         unsigned int i;
3571         int cleaned_count = 0;
3572         boolean_t cleaned = FALSE, multi_descriptor = FALSE;
3573
3574         i = rx_ring->next_to_clean;
3575         rx_desc = E1000_RX_DESC(*rx_ring, i);
3576
3577         while(rx_desc->status & E1000_RXD_STAT_DD) {
3578                 buffer_info = &rx_ring->buffer_info[i];
3579                 u8 status;
3580 #ifdef CONFIG_E1000_NAPI
3581                 if(*work_done >= work_to_do)
3582                         break;
3583                 (*work_done)++;
3584 #endif
3585                 status = rx_desc->status;
3586                 cleaned = TRUE;
3587                 cleaned_count++;
3588                 pci_unmap_single(pdev,
3589                                  buffer_info->dma,
3590                                  buffer_info->length,
3591                                  PCI_DMA_FROMDEVICE);
3592
3593                 skb = buffer_info->skb;
3594                 length = le16_to_cpu(rx_desc->length);
3595
3596                 if(unlikely(!(rx_desc->status & E1000_RXD_STAT_EOP))) {
3597                         /* All receives must fit into a single buffer */
3598                         E1000_DBG("%s: Receive packet consumed multiple"
3599                                   " buffers\n", netdev->name);
3600                         dev_kfree_skb_irq(skb);
3601                         goto next_desc;
3602                 }
3603
3604                 if(unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
3605                         last_byte = *(skb->data + length - 1);
3606                         if(TBI_ACCEPT(&adapter->hw, rx_desc->status,
3607                                       rx_desc->errors, length, last_byte)) {
3608                                 spin_lock_irqsave(&adapter->stats_lock, flags);
3609                                 e1000_tbi_adjust_stats(&adapter->hw,
3610                                                        &adapter->stats,
3611                                                        length, skb->data);
3612                                 spin_unlock_irqrestore(&adapter->stats_lock,
3613                                                        flags);
3614                                 length--;
3615                         } else {
3616                                 dev_kfree_skb_irq(skb);
3617                                 goto next_desc;
3618                         }
3619                 }
3620
3621                 /* code added for copybreak, this should improve
3622                  * performance for small packets with large amounts
3623                  * of reassembly being done in the stack */
3624 #define E1000_CB_LENGTH 256
3625                 if ((length < E1000_CB_LENGTH) &&
3626                    !rx_ring->rx_skb_top &&
3627                    /* or maybe (status & E1000_RXD_STAT_EOP) && */
3628                    !multi_descriptor) {
3629                         struct sk_buff *new_skb =
3630                             dev_alloc_skb(length + NET_IP_ALIGN);
3631                         if (new_skb) {
3632                                 skb_reserve(new_skb, NET_IP_ALIGN);
3633                                 new_skb->dev = netdev;
3634                                 memcpy(new_skb->data - NET_IP_ALIGN,
3635                                        skb->data - NET_IP_ALIGN,
3636                                        length + NET_IP_ALIGN);
3637                                 /* save the skb in buffer_info as good */
3638                                 buffer_info->skb = skb;
3639                                 skb = new_skb;
3640                                 skb_put(skb, length);
3641                         }
3642                 }
3643
3644                 /* end copybreak code */
3645
3646                 /* Receive Checksum Offload */
3647                 e1000_rx_checksum(adapter,
3648                                   (uint32_t)(status) |
3649                                   ((uint32_t)(rx_desc->errors) << 24),
3650                                   rx_desc->csum, skb);
3651                 skb->protocol = eth_type_trans(skb, netdev);
3652 #ifdef CONFIG_E1000_NAPI
3653                 if(unlikely(adapter->vlgrp &&
3654                             (status & E1000_RXD_STAT_VP))) {
3655                         vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3656                                                  le16_to_cpu(rx_desc->special) &
3657                                                  E1000_RXD_SPC_VLAN_MASK);
3658                 } else {
3659                         netif_receive_skb(skb);
3660                 }
3661 #else /* CONFIG_E1000_NAPI */
3662                 if(unlikely(adapter->vlgrp &&
3663                             (rx_desc->status & E1000_RXD_STAT_VP))) {
3664                         vlan_hwaccel_rx(skb, adapter->vlgrp,
3665                                         le16_to_cpu(rx_desc->special) &
3666                                         E1000_RXD_SPC_VLAN_MASK);
3667                 } else {
3668                         netif_rx(skb);
3669                 }
3670 #endif /* CONFIG_E1000_NAPI */
3671                 netdev->last_rx = jiffies;
3672 #ifdef CONFIG_E1000_MQ
3673                 rx_ring->rx_stats.packets++;
3674                 rx_ring->rx_stats.bytes += length;
3675 #endif
3676
3677 next_desc:
3678                 rx_desc->status = 0;
3679
3680                 /* return some buffers to hardware, one at a time is too slow */
3681                 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3682                         adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3683                         cleaned_count = 0;
3684                 }
3685
3686         }
3687         rx_ring->next_to_clean = i;
3688
3689         cleaned_count = E1000_DESC_UNUSED(rx_ring);
3690         if (cleaned_count)
3691                 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3692
3693         return cleaned;
3694 }
3695
3696 /**
3697  * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
3698  * @adapter: board private structure
3699  **/
3700
3701 static boolean_t
3702 #ifdef CONFIG_E1000_NAPI
3703 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3704                       struct e1000_rx_ring *rx_ring,
3705                       int *work_done, int work_to_do)
3706 #else
3707 e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
3708                       struct e1000_rx_ring *rx_ring)
3709 #endif
3710 {
3711         union e1000_rx_desc_packet_split *rx_desc;
3712         struct net_device *netdev = adapter->netdev;
3713         struct pci_dev *pdev = adapter->pdev;
3714         struct e1000_buffer *buffer_info;
3715         struct e1000_ps_page *ps_page;
3716         struct e1000_ps_page_dma *ps_page_dma;
3717         struct sk_buff *skb;
3718         unsigned int i, j;
3719         uint32_t length, staterr;
3720         int cleaned_count = 0;
3721         boolean_t cleaned = FALSE;
3722
3723         i = rx_ring->next_to_clean;
3724         rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3725         staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3726
3727         while(staterr & E1000_RXD_STAT_DD) {
3728                 buffer_info = &rx_ring->buffer_info[i];
3729                 ps_page = &rx_ring->ps_page[i];
3730                 ps_page_dma = &rx_ring->ps_page_dma[i];
3731 #ifdef CONFIG_E1000_NAPI
3732                 if(unlikely(*work_done >= work_to_do))
3733                         break;
3734                 (*work_done)++;
3735 #endif
3736                 cleaned = TRUE;
3737                 cleaned_count++;
3738                 pci_unmap_single(pdev, buffer_info->dma,
3739                                  buffer_info->length,
3740                                  PCI_DMA_FROMDEVICE);
3741
3742                 skb = buffer_info->skb;
3743
3744                 if(unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
3745                         E1000_DBG("%s: Packet Split buffers didn't pick up"
3746                                   " the full packet\n", netdev->name);
3747                         dev_kfree_skb_irq(skb);
3748                         goto next_desc;
3749                 }
3750
3751                 if(unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
3752                         dev_kfree_skb_irq(skb);
3753                         goto next_desc;
3754                 }
3755
3756                 length = le16_to_cpu(rx_desc->wb.middle.length0);
3757
3758                 if(unlikely(!length)) {
3759                         E1000_DBG("%s: Last part of the packet spanning"
3760                                   " multiple descriptors\n", netdev->name);
3761                         dev_kfree_skb_irq(skb);
3762                         goto next_desc;
3763                 }
3764
3765                 /* Good Receive */
3766                 skb_put(skb, length);
3767
3768                 for(j = 0; j < adapter->rx_ps_pages; j++) {
3769                         if(!(length = le16_to_cpu(rx_desc->wb.upper.length[j])))
3770                                 break;
3771
3772                         pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
3773                                         PAGE_SIZE, PCI_DMA_FROMDEVICE);
3774                         ps_page_dma->ps_page_dma[j] = 0;
3775                         skb_shinfo(skb)->frags[j].page =
3776                                 ps_page->ps_page[j];
3777                         ps_page->ps_page[j] = NULL;
3778                         skb_shinfo(skb)->frags[j].page_offset = 0;
3779                         skb_shinfo(skb)->frags[j].size = length;
3780                         skb_shinfo(skb)->nr_frags++;
3781                         skb->len += length;
3782                         skb->data_len += length;
3783                 }
3784
3785                 e1000_rx_checksum(adapter, staterr,
3786                                   rx_desc->wb.lower.hi_dword.csum_ip.csum, skb);
3787                 skb->protocol = eth_type_trans(skb, netdev);
3788
3789                 if(likely(rx_desc->wb.upper.header_status &
3790                           E1000_RXDPS_HDRSTAT_HDRSP)) {
3791                         adapter->rx_hdr_split++;
3792 #ifdef HAVE_RX_ZERO_COPY
3793                         skb_shinfo(skb)->zero_copy = TRUE;
3794 #endif
3795                 }
3796 #ifdef CONFIG_E1000_NAPI
3797                 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3798                         vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3799                                 le16_to_cpu(rx_desc->wb.middle.vlan) &
3800                                 E1000_RXD_SPC_VLAN_MASK);
3801                 } else {
3802                         netif_receive_skb(skb);
3803                 }
3804 #else /* CONFIG_E1000_NAPI */
3805                 if(unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
3806                         vlan_hwaccel_rx(skb, adapter->vlgrp,
3807                                 le16_to_cpu(rx_desc->wb.middle.vlan) &
3808                                 E1000_RXD_SPC_VLAN_MASK);
3809                 } else {
3810                         netif_rx(skb);
3811                 }
3812 #endif /* CONFIG_E1000_NAPI */
3813                 netdev->last_rx = jiffies;
3814 #ifdef CONFIG_E1000_MQ
3815                 rx_ring->rx_stats.packets++;
3816                 rx_ring->rx_stats.bytes += length;
3817 #endif
3818
3819 next_desc:
3820                 rx_desc->wb.middle.status_error &= ~0xFF;
3821                 buffer_info->skb = NULL;
3822
3823                 /* return some buffers to hardware, one at a time is too slow */
3824                 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
3825                         adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3826                         cleaned_count = 0;
3827                 }
3828
3829                 staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
3830         }
3831         rx_ring->next_to_clean = i;
3832
3833         cleaned_count = E1000_DESC_UNUSED(rx_ring);
3834         if (cleaned_count)
3835                 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
3836
3837         return cleaned;
3838 }
3839
3840 /**
3841  * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
3842  * @adapter: address of board private structure
3843  **/
3844
3845 static void
3846 e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
3847                        struct e1000_rx_ring *rx_ring,
3848                        int cleaned_count)
3849 {
3850         struct net_device *netdev = adapter->netdev;
3851         struct pci_dev *pdev = adapter->pdev;
3852         struct e1000_rx_desc *rx_desc;
3853         struct e1000_buffer *buffer_info;
3854         struct sk_buff *skb;
3855         unsigned int i;
3856         unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
3857
3858         i = rx_ring->next_to_use;
3859         buffer_info = &rx_ring->buffer_info[i];
3860
3861         while (cleaned_count--) {
3862                 if (!(skb = buffer_info->skb))
3863                         skb = dev_alloc_skb(bufsz);
3864                 else {
3865                         skb_trim(skb, 0);
3866                         goto map_skb;
3867                 }
3868
3869
3870                 if(unlikely(!skb)) {
3871                         /* Better luck next round */
3872                         adapter->alloc_rx_buff_failed++;
3873                         break;
3874                 }
3875
3876                 /* Fix for errata 23, can't cross 64kB boundary */
3877                 if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3878                         struct sk_buff *oldskb = skb;
3879                         DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
3880                                              "at %p\n", bufsz, skb->data);
3881                         /* Try again, without freeing the previous */
3882                         skb = dev_alloc_skb(bufsz);
3883                         /* Failed allocation, critical failure */
3884                         if (!skb) {
3885                                 dev_kfree_skb(oldskb);
3886                                 break;
3887                         }
3888
3889                         if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
3890                                 /* give up */
3891                                 dev_kfree_skb(skb);
3892                                 dev_kfree_skb(oldskb);
3893                                 break; /* while !buffer_info->skb */
3894                         } else {
3895                                 /* Use new allocation */
3896                                 dev_kfree_skb(oldskb);
3897                         }
3898                 }
3899                 /* Make buffer alignment 2 beyond a 16 byte boundary
3900                  * this will result in a 16 byte aligned IP header after
3901                  * the 14 byte MAC header is removed
3902                  */
3903                 skb_reserve(skb, NET_IP_ALIGN);
3904
3905                 skb->dev = netdev;
3906
3907                 buffer_info->skb = skb;
3908                 buffer_info->length = adapter->rx_buffer_len;
3909 map_skb:
3910                 buffer_info->dma = pci_map_single(pdev,
3911                                                   skb->data,
3912                                                   adapter->rx_buffer_len,
3913                                                   PCI_DMA_FROMDEVICE);
3914
3915                 /* Fix for errata 23, can't cross 64kB boundary */
3916                 if (!e1000_check_64k_bound(adapter,
3917                                         (void *)(unsigned long)buffer_info->dma,
3918                                         adapter->rx_buffer_len)) {
3919                         DPRINTK(RX_ERR, ERR,
3920                                 "dma align check failed: %u bytes at %p\n",
3921                                 adapter->rx_buffer_len,
3922                                 (void *)(unsigned long)buffer_info->dma);
3923                         dev_kfree_skb(skb);
3924                         buffer_info->skb = NULL;
3925
3926                         pci_unmap_single(pdev, buffer_info->dma,
3927                                          adapter->rx_buffer_len,
3928                                          PCI_DMA_FROMDEVICE);
3929
3930                         break; /* while !buffer_info->skb */
3931                 }
3932                 rx_desc = E1000_RX_DESC(*rx_ring, i);
3933                 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3934
3935                 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
3936                         /* Force memory writes to complete before letting h/w
3937                          * know there are new descriptors to fetch.  (Only
3938                          * applicable for weak-ordered memory model archs,
3939                          * such as IA-64). */
3940                         wmb();
3941                         writel(i, adapter->hw.hw_addr + rx_ring->rdt);
3942                 }
3943
3944                 if(unlikely(++i == rx_ring->count)) i = 0;
3945                 buffer_info = &rx_ring->buffer_info[i];
3946         }
3947
3948         rx_ring->next_to_use = i;
3949 }
3950
3951 /**
3952  * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
3953  * @adapter: address of board private structure
3954  **/
3955
3956 static void
3957 e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
3958                           struct e1000_rx_ring *rx_ring,
3959                           int cleaned_count)
3960 {
3961         struct net_device *netdev = adapter->netdev;
3962         struct pci_dev *pdev = adapter->pdev;
3963         union e1000_rx_desc_packet_split *rx_desc;
3964         struct e1000_buffer *buffer_info;
3965         struct e1000_ps_page *ps_page;
3966         struct e1000_ps_page_dma *ps_page_dma;
3967         struct sk_buff *skb;
3968         unsigned int i, j;
3969
3970         i = rx_ring->next_to_use;
3971         buffer_info = &rx_ring->buffer_info[i];
3972         ps_page = &rx_ring->ps_page[i];
3973         ps_page_dma = &rx_ring->ps_page_dma[i];
3974
3975         while (cleaned_count--) {
3976                 rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
3977
3978                 for(j = 0; j < PS_PAGE_BUFFERS; j++) {
3979                         if (j < adapter->rx_ps_pages) {
3980                                 if (likely(!ps_page->ps_page[j])) {
3981                                         ps_page->ps_page[j] =
3982                                                 alloc_page(GFP_ATOMIC);
3983                                         if (unlikely(!ps_page->ps_page[j]))
3984                                                 goto no_buffers;
3985                                         ps_page_dma->ps_page_dma[j] =
3986                                                 pci_map_page(pdev,
3987                                                             ps_page->ps_page[j],
3988                                                             0, PAGE_SIZE,
3989                                                             PCI_DMA_FROMDEVICE);
3990                                 }
3991                                 /* Refresh the desc even if buffer_addrs didn't
3992                                  * change because each write-back erases 
3993                                  * this info.
3994                                  */
3995                                 rx_desc->read.buffer_addr[j+1] =
3996                                      cpu_to_le64(ps_page_dma->ps_page_dma[j]);
3997                         } else
3998                                 rx_desc->read.buffer_addr[j+1] = ~0;
3999                 }
4000
4001                 skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN);
4002
4003                 if(unlikely(!skb))
4004                         break;
4005
4006                 /* Make buffer alignment 2 beyond a 16 byte boundary
4007                  * this will result in a 16 byte aligned IP header after
4008                  * the 14 byte MAC header is removed
4009                  */
4010                 skb_reserve(skb, NET_IP_ALIGN);
4011
4012                 skb->dev = netdev;
4013
4014                 buffer_info->skb = skb;
4015                 buffer_info->length = adapter->rx_ps_bsize0;
4016                 buffer_info->dma = pci_map_single(pdev, skb->data,
4017                                                   adapter->rx_ps_bsize0,
4018                                                   PCI_DMA_FROMDEVICE);
4019
4020                 rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
4021
4022                 if(unlikely((i & ~(E1000_RX_BUFFER_WRITE - 1)) == i)) {
4023                         /* Force memory writes to complete before letting h/w
4024                          * know there are new descriptors to fetch.  (Only
4025                          * applicable for weak-ordered memory model archs,
4026                          * such as IA-64). */
4027                         wmb();
4028                         /* Hardware increments by 16 bytes, but packet split
4029                          * descriptors are 32 bytes...so we increment tail
4030                          * twice as much.
4031                          */
4032                         writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
4033                 }
4034
4035                 if(unlikely(++i == rx_ring->count)) i = 0;
4036                 buffer_info = &rx_ring->buffer_info[i];
4037                 ps_page = &rx_ring->ps_page[i];
4038                 ps_page_dma = &rx_ring->ps_page_dma[i];
4039         }
4040
4041 no_buffers:
4042         rx_ring->next_to_use = i;
4043 }
4044
4045 /**
4046  * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
4047  * @adapter:
4048  **/
4049
4050 static void
4051 e1000_smartspeed(struct e1000_adapter *adapter)
4052 {
4053         uint16_t phy_status;
4054         uint16_t phy_ctrl;
4055
4056         if((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
4057            !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
4058                 return;
4059
4060         if(adapter->smartspeed == 0) {
4061                 /* If Master/Slave config fault is asserted twice,
4062                  * we assume back-to-back */
4063                 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4064                 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4065                 e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
4066                 if(!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
4067                 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4068                 if(phy_ctrl & CR_1000T_MS_ENABLE) {
4069                         phy_ctrl &= ~CR_1000T_MS_ENABLE;
4070                         e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
4071                                             phy_ctrl);
4072                         adapter->smartspeed++;
4073                         if(!e1000_phy_setup_autoneg(&adapter->hw) &&
4074                            !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
4075                                                &phy_ctrl)) {
4076                                 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4077                                              MII_CR_RESTART_AUTO_NEG);
4078                                 e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
4079                                                     phy_ctrl);
4080                         }
4081                 }
4082                 return;
4083         } else if(adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4084                 /* If still no link, perhaps using 2/3 pair cable */
4085                 e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
4086                 phy_ctrl |= CR_1000T_MS_ENABLE;
4087                 e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
4088                 if(!e1000_phy_setup_autoneg(&adapter->hw) &&
4089                    !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
4090                         phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4091                                      MII_CR_RESTART_AUTO_NEG);
4092                         e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
4093                 }
4094         }
4095         /* Restart process after E1000_SMARTSPEED_MAX iterations */
4096         if(adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4097                 adapter->smartspeed = 0;
4098 }
4099
4100 /**
4101  * e1000_ioctl -
4102  * @netdev:
4103  * @ifreq:
4104  * @cmd:
4105  **/
4106
4107 static int
4108 e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4109 {
4110         switch (cmd) {
4111         case SIOCGMIIPHY:
4112         case SIOCGMIIREG:
4113         case SIOCSMIIREG:
4114                 return e1000_mii_ioctl(netdev, ifr, cmd);
4115         default:
4116                 return -EOPNOTSUPP;
4117         }
4118 }
4119
4120 /**
4121  * e1000_mii_ioctl -
4122  * @netdev:
4123  * @ifreq:
4124  * @cmd:
4125  **/
4126
4127 static int
4128 e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4129 {
4130         struct e1000_adapter *adapter = netdev_priv(netdev);
4131         struct mii_ioctl_data *data = if_mii(ifr);
4132         int retval;
4133         uint16_t mii_reg;
4134         uint16_t spddplx;
4135         unsigned long flags;
4136
4137         if(adapter->hw.media_type != e1000_media_type_copper)
4138                 return -EOPNOTSUPP;
4139
4140         switch (cmd) {
4141         case SIOCGMIIPHY:
4142                 data->phy_id = adapter->hw.phy_addr;
4143                 break;
4144         case SIOCGMIIREG:
4145                 if(!capable(CAP_NET_ADMIN))
4146                         return -EPERM;
4147                 spin_lock_irqsave(&adapter->stats_lock, flags);
4148                 if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4149                                    &data->val_out)) {
4150                         spin_unlock_irqrestore(&adapter->stats_lock, flags);
4151                         return -EIO;
4152                 }
4153                 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4154                 break;
4155         case SIOCSMIIREG:
4156                 if(!capable(CAP_NET_ADMIN))
4157                         return -EPERM;
4158                 if(data->reg_num & ~(0x1F))
4159                         return -EFAULT;
4160                 mii_reg = data->val_in;
4161                 spin_lock_irqsave(&adapter->stats_lock, flags);
4162                 if(e1000_write_phy_reg(&adapter->hw, data->reg_num,
4163                                         mii_reg)) {
4164                         spin_unlock_irqrestore(&adapter->stats_lock, flags);
4165                         return -EIO;
4166                 }
4167                 if(adapter->hw.phy_type == e1000_phy_m88) {
4168                         switch (data->reg_num) {
4169                         case PHY_CTRL:
4170                                 if(mii_reg & MII_CR_POWER_DOWN)
4171                                         break;
4172                                 if(mii_reg & MII_CR_AUTO_NEG_EN) {
4173                                         adapter->hw.autoneg = 1;
4174                                         adapter->hw.autoneg_advertised = 0x2F;
4175                                 } else {
4176                                         if (mii_reg & 0x40)
4177                                                 spddplx = SPEED_1000;
4178                                         else if (mii_reg & 0x2000)
4179                                                 spddplx = SPEED_100;
4180                                         else
4181                                                 spddplx = SPEED_10;
4182                                         spddplx += (mii_reg & 0x100)
4183                                                    ? FULL_DUPLEX :
4184                                                    HALF_DUPLEX;
4185                                         retval = e1000_set_spd_dplx(adapter,
4186                                                                     spddplx);
4187                                         if(retval) {
4188                                                 spin_unlock_irqrestore(
4189                                                         &adapter->stats_lock, 
4190                                                         flags);
4191                                                 return retval;
4192                                         }
4193                                 }
4194                                 if(netif_running(adapter->netdev)) {
4195                                         e1000_down(adapter);
4196                                         e1000_up(adapter);
4197                                 } else
4198                                         e1000_reset(adapter);
4199                                 break;
4200                         case M88E1000_PHY_SPEC_CTRL:
4201                         case M88E1000_EXT_PHY_SPEC_CTRL:
4202                                 if(e1000_phy_reset(&adapter->hw)) {
4203                                         spin_unlock_irqrestore(
4204                                                 &adapter->stats_lock, flags);
4205                                         return -EIO;
4206                                 }
4207                                 break;
4208                         }
4209                 } else {
4210                         switch (data->reg_num) {
4211                         case PHY_CTRL:
4212                                 if(mii_reg & MII_CR_POWER_DOWN)
4213                                         break;
4214                                 if(netif_running(adapter->netdev)) {
4215                                         e1000_down(adapter);
4216                                         e1000_up(adapter);
4217                                 } else
4218                                         e1000_reset(adapter);
4219                                 break;
4220                         }
4221                 }
4222                 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4223                 break;
4224         default:
4225                 return -EOPNOTSUPP;
4226         }
4227         return E1000_SUCCESS;
4228 }
4229
4230 void
4231 e1000_pci_set_mwi(struct e1000_hw *hw)
4232 {
4233         struct e1000_adapter *adapter = hw->back;
4234         int ret_val = pci_set_mwi(adapter->pdev);
4235
4236         if(ret_val)
4237                 DPRINTK(PROBE, ERR, "Error in setting MWI\n");
4238 }
4239
4240 void
4241 e1000_pci_clear_mwi(struct e1000_hw *hw)
4242 {
4243         struct e1000_adapter *adapter = hw->back;
4244
4245         pci_clear_mwi(adapter->pdev);
4246 }
4247
4248 void
4249 e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4250 {
4251         struct e1000_adapter *adapter = hw->back;
4252
4253         pci_read_config_word(adapter->pdev, reg, value);
4254 }
4255
4256 void
4257 e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
4258 {
4259         struct e1000_adapter *adapter = hw->back;
4260
4261         pci_write_config_word(adapter->pdev, reg, *value);
4262 }
4263
4264 uint32_t
4265 e1000_io_read(struct e1000_hw *hw, unsigned long port)
4266 {
4267         return inl(port);
4268 }
4269
4270 void
4271 e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
4272 {
4273         outl(value, port);
4274 }
4275
4276 static void
4277 e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
4278 {
4279         struct e1000_adapter *adapter = netdev_priv(netdev);
4280         uint32_t ctrl, rctl;
4281
4282         e1000_irq_disable(adapter);
4283         adapter->vlgrp = grp;
4284
4285         if(grp) {
4286                 /* enable VLAN tag insert/strip */
4287                 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4288                 ctrl |= E1000_CTRL_VME;
4289                 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4290
4291                 /* enable VLAN receive filtering */
4292                 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4293                 rctl |= E1000_RCTL_VFE;
4294                 rctl &= ~E1000_RCTL_CFIEN;
4295                 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4296                 e1000_update_mng_vlan(adapter);
4297         } else {
4298                 /* disable VLAN tag insert/strip */
4299                 ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4300                 ctrl &= ~E1000_CTRL_VME;
4301                 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4302
4303                 /* disable VLAN filtering */
4304                 rctl = E1000_READ_REG(&adapter->hw, RCTL);
4305                 rctl &= ~E1000_RCTL_VFE;
4306                 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4307                 if(adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) {
4308                         e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4309                         adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
4310                 }
4311         }
4312
4313         e1000_irq_enable(adapter);
4314 }
4315
4316 static void
4317 e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
4318 {
4319         struct e1000_adapter *adapter = netdev_priv(netdev);
4320         uint32_t vfta, index;
4321         if((adapter->hw.mng_cookie.status &
4322                 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4323                 (vid == adapter->mng_vlan_id))
4324                 return;
4325         /* add VID to filter table */
4326         index = (vid >> 5) & 0x7F;
4327         vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4328         vfta |= (1 << (vid & 0x1F));
4329         e1000_write_vfta(&adapter->hw, index, vfta);
4330 }
4331
4332 static void
4333 e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
4334 {
4335         struct e1000_adapter *adapter = netdev_priv(netdev);
4336         uint32_t vfta, index;
4337
4338         e1000_irq_disable(adapter);
4339
4340         if(adapter->vlgrp)
4341                 adapter->vlgrp->vlan_devices[vid] = NULL;
4342
4343         e1000_irq_enable(adapter);
4344
4345         if((adapter->hw.mng_cookie.status &
4346                 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4347             (vid == adapter->mng_vlan_id)) {
4348                 /* release control to f/w */
4349                 e1000_release_hw_control(adapter);
4350                 return;
4351         }
4352
4353         /* remove VID from filter table */
4354         index = (vid >> 5) & 0x7F;
4355         vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
4356         vfta &= ~(1 << (vid & 0x1F));
4357         e1000_write_vfta(&adapter->hw, index, vfta);
4358 }
4359
4360 static void
4361 e1000_restore_vlan(struct e1000_adapter *adapter)
4362 {
4363         e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4364
4365         if(adapter->vlgrp) {
4366                 uint16_t vid;
4367                 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4368                         if(!adapter->vlgrp->vlan_devices[vid])
4369                                 continue;
4370                         e1000_vlan_rx_add_vid(adapter->netdev, vid);
4371                 }
4372         }
4373 }
4374
4375 int
4376 e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
4377 {
4378         adapter->hw.autoneg = 0;
4379
4380         /* Fiber NICs only allow 1000 gbps Full duplex */
4381         if((adapter->hw.media_type == e1000_media_type_fiber) &&
4382                 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4383                 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4384                 return -EINVAL;
4385         }
4386
4387         switch(spddplx) {
4388         case SPEED_10 + DUPLEX_HALF:
4389                 adapter->hw.forced_speed_duplex = e1000_10_half;
4390                 break;
4391         case SPEED_10 + DUPLEX_FULL:
4392                 adapter->hw.forced_speed_duplex = e1000_10_full;
4393                 break;
4394         case SPEED_100 + DUPLEX_HALF:
4395                 adapter->hw.forced_speed_duplex = e1000_100_half;
4396                 break;
4397         case SPEED_100 + DUPLEX_FULL:
4398                 adapter->hw.forced_speed_duplex = e1000_100_full;
4399                 break;
4400         case SPEED_1000 + DUPLEX_FULL:
4401                 adapter->hw.autoneg = 1;
4402                 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
4403                 break;
4404         case SPEED_1000 + DUPLEX_HALF: /* not supported */
4405         default:
4406                 DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
4407                 return -EINVAL;
4408         }
4409         return 0;
4410 }
4411
4412 #ifdef CONFIG_PM
4413 static int
4414 e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4415 {
4416         struct net_device *netdev = pci_get_drvdata(pdev);
4417         struct e1000_adapter *adapter = netdev_priv(netdev);
4418         uint32_t ctrl, ctrl_ext, rctl, manc, status;
4419         uint32_t wufc = adapter->wol;
4420         int retval = 0;
4421
4422         netif_device_detach(netdev);
4423
4424         if(netif_running(netdev))
4425                 e1000_down(adapter);
4426
4427         status = E1000_READ_REG(&adapter->hw, STATUS);
4428         if(status & E1000_STATUS_LU)
4429                 wufc &= ~E1000_WUFC_LNKC;
4430
4431         if(wufc) {
4432                 e1000_setup_rctl(adapter);
4433                 e1000_set_multi(netdev);
4434
4435                 /* turn on all-multi mode if wake on multicast is enabled */
4436                 if(adapter->wol & E1000_WUFC_MC) {
4437                         rctl = E1000_READ_REG(&adapter->hw, RCTL);
4438                         rctl |= E1000_RCTL_MPE;
4439                         E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
4440                 }
4441
4442                 if(adapter->hw.mac_type >= e1000_82540) {
4443                         ctrl = E1000_READ_REG(&adapter->hw, CTRL);
4444                         /* advertise wake from D3Cold */
4445                         #define E1000_CTRL_ADVD3WUC 0x00100000
4446                         /* phy power management enable */
4447                         #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4448                         ctrl |= E1000_CTRL_ADVD3WUC |
4449                                 E1000_CTRL_EN_PHY_PWR_MGMT;
4450                         E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
4451                 }
4452
4453                 if(adapter->hw.media_type == e1000_media_type_fiber ||
4454                    adapter->hw.media_type == e1000_media_type_internal_serdes) {
4455                         /* keep the laser running in D3 */
4456                         ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
4457                         ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
4458                         E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
4459                 }
4460
4461                 /* Allow time for pending master requests to run */
4462                 e1000_disable_pciex_master(&adapter->hw);
4463
4464                 E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
4465                 E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
4466                 retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4467                 if (retval)
4468                         DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4469                 retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4470                 if (retval)
4471                         DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4472         } else {
4473                 E1000_WRITE_REG(&adapter->hw, WUC, 0);
4474                 E1000_WRITE_REG(&adapter->hw, WUFC, 0);
4475                 retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4476                 if (retval)
4477                         DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4478                 retval = pci_enable_wake(pdev, PCI_D3cold, 0); /* 4 == D3 cold */
4479                 if (retval)
4480                         DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4481         }
4482
4483         pci_save_state(pdev);
4484
4485         if(adapter->hw.mac_type >= e1000_82540 &&
4486            adapter->hw.media_type == e1000_media_type_copper) {
4487                 manc = E1000_READ_REG(&adapter->hw, MANC);
4488                 if(manc & E1000_MANC_SMBUS_EN) {
4489                         manc |= E1000_MANC_ARP_EN;
4490                         E1000_WRITE_REG(&adapter->hw, MANC, manc);
4491                         retval = pci_enable_wake(pdev, PCI_D3hot, 1);
4492                         if (retval)
4493                                 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4494                         retval = pci_enable_wake(pdev, PCI_D3cold, 1);
4495                         if (retval)
4496                                 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4497                 }
4498         }
4499
4500         /* Release control of h/w to f/w.  If f/w is AMT enabled, this
4501          * would have already happened in close and is redundant. */
4502         e1000_release_hw_control(adapter);
4503
4504         pci_disable_device(pdev);
4505
4506         retval = pci_set_power_state(pdev, pci_choose_state(pdev, state));
4507         if (retval)
4508                 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4509
4510         return 0;
4511 }
4512
4513 static int
4514 e1000_resume(struct pci_dev *pdev)
4515 {
4516         struct net_device *netdev = pci_get_drvdata(pdev);
4517         struct e1000_adapter *adapter = netdev_priv(netdev);
4518         int retval;
4519         uint32_t manc, ret_val;
4520
4521         retval = pci_set_power_state(pdev, PCI_D0);
4522         if (retval)
4523                 DPRINTK(PROBE, ERR, "Error in setting power state\n");
4524         ret_val = pci_enable_device(pdev);
4525         pci_set_master(pdev);
4526
4527         retval = pci_enable_wake(pdev, PCI_D3hot, 0);
4528         if (retval)
4529                 DPRINTK(PROBE, ERR, "Error enabling D3 wake\n");
4530         retval = pci_enable_wake(pdev, PCI_D3cold, 0);
4531         if (retval)
4532                 DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n");
4533
4534         e1000_reset(adapter);
4535         E1000_WRITE_REG(&adapter->hw, WUS, ~0);
4536
4537         if(netif_running(netdev))
4538                 e1000_up(adapter);
4539
4540         netif_device_attach(netdev);
4541
4542         if(adapter->hw.mac_type >= e1000_82540 &&
4543            adapter->hw.media_type == e1000_media_type_copper) {
4544                 manc = E1000_READ_REG(&adapter->hw, MANC);
4545                 manc &= ~(E1000_MANC_ARP_EN);
4546                 E1000_WRITE_REG(&adapter->hw, MANC, manc);
4547         }
4548
4549         /* If the controller is 82573 and f/w is AMT, do not set
4550          * DRV_LOAD until the interface is up.  For all other cases,
4551          * let the f/w know that the h/w is now under the control
4552          * of the driver. */
4553         if (adapter->hw.mac_type != e1000_82573 ||
4554             !e1000_check_mng_mode(&adapter->hw))
4555                 e1000_get_hw_control(adapter);
4556
4557         return 0;
4558 }
4559 #endif
4560 #ifdef CONFIG_NET_POLL_CONTROLLER
4561 /*
4562  * Polling 'interrupt' - used by things like netconsole to send skbs
4563  * without having to re-enable interrupts. It's not called while
4564  * the interrupt routine is executing.
4565  */
4566 static void
4567 e1000_netpoll(struct net_device *netdev)
4568 {
4569         struct e1000_adapter *adapter = netdev_priv(netdev);
4570         disable_irq(adapter->pdev->irq);
4571         e1000_intr(adapter->pdev->irq, netdev, NULL);
4572         e1000_clean_tx_irq(adapter, adapter->tx_ring);
4573 #ifndef CONFIG_E1000_NAPI
4574         adapter->clean_rx(adapter, adapter->rx_ring);
4575 #endif
4576         enable_irq(adapter->pdev->irq);
4577 }
4578 #endif
4579
4580 /* e1000_main.c */