1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include <linux/module.h>
29 #include <linux/types.h>
30 #include <linux/init.h>
31 #include <linux/vmalloc.h>
32 #include <linux/pagemap.h>
33 #include <linux/netdevice.h>
34 #include <linux/tcp.h>
35 #include <linux/ipv6.h>
36 #include <net/checksum.h>
37 #include <net/ip6_checksum.h>
38 #include <linux/mii.h>
39 #include <linux/ethtool.h>
40 #include <linux/if_vlan.h>
41 #include <linux/pci.h>
42 #include <linux/delay.h>
43 #include <linux/interrupt.h>
44 #include <linux/if_ether.h>
48 #define DRV_VERSION "1.0.8-k2"
49 char igb_driver_name
[] = "igb";
50 char igb_driver_version
[] = DRV_VERSION
;
51 static const char igb_driver_string
[] =
52 "Intel(R) Gigabit Ethernet Network Driver";
53 static const char igb_copyright
[] = "Copyright (c) 2007 Intel Corporation.";
56 static const struct e1000_info
*igb_info_tbl
[] = {
57 [board_82575
] = &e1000_82575_info
,
60 static struct pci_device_id igb_pci_tbl
[] = {
61 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82575EB_COPPER
), board_82575
},
62 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82575EB_FIBER_SERDES
), board_82575
},
63 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82575GB_QUAD_COPPER
), board_82575
},
64 /* required last entry */
68 MODULE_DEVICE_TABLE(pci
, igb_pci_tbl
);
70 void igb_reset(struct igb_adapter
*);
71 static int igb_setup_all_tx_resources(struct igb_adapter
*);
72 static int igb_setup_all_rx_resources(struct igb_adapter
*);
73 static void igb_free_all_tx_resources(struct igb_adapter
*);
74 static void igb_free_all_rx_resources(struct igb_adapter
*);
75 static void igb_free_tx_resources(struct igb_adapter
*, struct igb_ring
*);
76 static void igb_free_rx_resources(struct igb_adapter
*, struct igb_ring
*);
77 void igb_update_stats(struct igb_adapter
*);
78 static int igb_probe(struct pci_dev
*, const struct pci_device_id
*);
79 static void __devexit
igb_remove(struct pci_dev
*pdev
);
80 static int igb_sw_init(struct igb_adapter
*);
81 static int igb_open(struct net_device
*);
82 static int igb_close(struct net_device
*);
83 static void igb_configure_tx(struct igb_adapter
*);
84 static void igb_configure_rx(struct igb_adapter
*);
85 static void igb_setup_rctl(struct igb_adapter
*);
86 static void igb_clean_all_tx_rings(struct igb_adapter
*);
87 static void igb_clean_all_rx_rings(struct igb_adapter
*);
88 static void igb_clean_tx_ring(struct igb_adapter
*, struct igb_ring
*);
89 static void igb_clean_rx_ring(struct igb_adapter
*, struct igb_ring
*);
90 static void igb_set_multi(struct net_device
*);
91 static void igb_update_phy_info(unsigned long);
92 static void igb_watchdog(unsigned long);
93 static void igb_watchdog_task(struct work_struct
*);
94 static int igb_xmit_frame_ring_adv(struct sk_buff
*, struct net_device
*,
96 static int igb_xmit_frame_adv(struct sk_buff
*skb
, struct net_device
*);
97 static struct net_device_stats
*igb_get_stats(struct net_device
*);
98 static int igb_change_mtu(struct net_device
*, int);
99 static int igb_set_mac(struct net_device
*, void *);
100 static irqreturn_t
igb_intr(int irq
, void *);
101 static irqreturn_t
igb_intr_msi(int irq
, void *);
102 static irqreturn_t
igb_msix_other(int irq
, void *);
103 static irqreturn_t
igb_msix_rx(int irq
, void *);
104 static irqreturn_t
igb_msix_tx(int irq
, void *);
105 static int igb_clean_rx_ring_msix(struct napi_struct
*, int);
106 static bool igb_clean_tx_irq(struct igb_adapter
*, struct igb_ring
*);
107 static int igb_clean(struct napi_struct
*, int);
108 static bool igb_clean_rx_irq_adv(struct igb_adapter
*,
109 struct igb_ring
*, int *, int);
110 static void igb_alloc_rx_buffers_adv(struct igb_adapter
*,
111 struct igb_ring
*, int);
112 static int igb_ioctl(struct net_device
*, struct ifreq
*, int cmd
);
113 static void igb_tx_timeout(struct net_device
*);
114 static void igb_reset_task(struct work_struct
*);
115 static void igb_vlan_rx_register(struct net_device
*, struct vlan_group
*);
116 static void igb_vlan_rx_add_vid(struct net_device
*, u16
);
117 static void igb_vlan_rx_kill_vid(struct net_device
*, u16
);
118 static void igb_restore_vlan(struct igb_adapter
*);
120 static int igb_suspend(struct pci_dev
*, pm_message_t
);
122 static int igb_resume(struct pci_dev
*);
124 static void igb_shutdown(struct pci_dev
*);
126 #ifdef CONFIG_NET_POLL_CONTROLLER
127 /* for netdump / net console */
128 static void igb_netpoll(struct net_device
*);
131 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*,
132 pci_channel_state_t
);
133 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*);
134 static void igb_io_resume(struct pci_dev
*);
136 static struct pci_error_handlers igb_err_handler
= {
137 .error_detected
= igb_io_error_detected
,
138 .slot_reset
= igb_io_slot_reset
,
139 .resume
= igb_io_resume
,
143 static struct pci_driver igb_driver
= {
144 .name
= igb_driver_name
,
145 .id_table
= igb_pci_tbl
,
147 .remove
= __devexit_p(igb_remove
),
149 /* Power Managment Hooks */
150 .suspend
= igb_suspend
,
151 .resume
= igb_resume
,
153 .shutdown
= igb_shutdown
,
154 .err_handler
= &igb_err_handler
157 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
158 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
159 MODULE_LICENSE("GPL");
160 MODULE_VERSION(DRV_VERSION
);
164 * igb_get_hw_dev_name - return device name string
165 * used by hardware layer to print debugging information
167 char *igb_get_hw_dev_name(struct e1000_hw
*hw
)
169 struct igb_adapter
*adapter
= hw
->back
;
170 return adapter
->netdev
->name
;
175 * igb_init_module - Driver Registration Routine
177 * igb_init_module is the first routine called when the driver is
178 * loaded. All it does is register with the PCI subsystem.
180 static int __init
igb_init_module(void)
183 printk(KERN_INFO
"%s - version %s\n",
184 igb_driver_string
, igb_driver_version
);
186 printk(KERN_INFO
"%s\n", igb_copyright
);
188 ret
= pci_register_driver(&igb_driver
);
192 module_init(igb_init_module
);
195 * igb_exit_module - Driver Exit Cleanup Routine
197 * igb_exit_module is called just before the driver is removed
200 static void __exit
igb_exit_module(void)
202 pci_unregister_driver(&igb_driver
);
205 module_exit(igb_exit_module
);
208 * igb_alloc_queues - Allocate memory for all rings
209 * @adapter: board private structure to initialize
211 * We allocate one ring per queue at run-time since we don't know the
212 * number of queues at compile-time.
214 static int igb_alloc_queues(struct igb_adapter
*adapter
)
218 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
219 sizeof(struct igb_ring
), GFP_KERNEL
);
220 if (!adapter
->tx_ring
)
223 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
224 sizeof(struct igb_ring
), GFP_KERNEL
);
225 if (!adapter
->rx_ring
) {
226 kfree(adapter
->tx_ring
);
230 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
231 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
232 ring
->adapter
= adapter
;
233 ring
->itr_register
= E1000_ITR
;
235 if (!ring
->napi
.poll
)
236 netif_napi_add(adapter
->netdev
, &ring
->napi
, igb_clean
,
237 adapter
->napi
.weight
/
238 adapter
->num_rx_queues
);
243 #define IGB_N0_QUEUE -1
244 static void igb_assign_vector(struct igb_adapter
*adapter
, int rx_queue
,
245 int tx_queue
, int msix_vector
)
248 struct e1000_hw
*hw
= &adapter
->hw
;
249 /* The 82575 assigns vectors using a bitmask, which matches the
250 bitmask for the EICR/EIMS/EIMC registers. To assign one
251 or more queues to a vector, we write the appropriate bits
252 into the MSIXBM register for that vector. */
253 if (rx_queue
> IGB_N0_QUEUE
) {
254 msixbm
= E1000_EICR_RX_QUEUE0
<< rx_queue
;
255 adapter
->rx_ring
[rx_queue
].eims_value
= msixbm
;
257 if (tx_queue
> IGB_N0_QUEUE
) {
258 msixbm
|= E1000_EICR_TX_QUEUE0
<< tx_queue
;
259 adapter
->tx_ring
[tx_queue
].eims_value
=
260 E1000_EICR_TX_QUEUE0
<< tx_queue
;
262 array_wr32(E1000_MSIXBM(0), msix_vector
, msixbm
);
266 * igb_configure_msix - Configure MSI-X hardware
268 * igb_configure_msix sets up the hardware to properly
269 * generate MSI-X interrupts.
271 static void igb_configure_msix(struct igb_adapter
*adapter
)
275 struct e1000_hw
*hw
= &adapter
->hw
;
277 adapter
->eims_enable_mask
= 0;
279 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
280 struct igb_ring
*tx_ring
= &adapter
->tx_ring
[i
];
281 igb_assign_vector(adapter
, IGB_N0_QUEUE
, i
, vector
++);
282 adapter
->eims_enable_mask
|= tx_ring
->eims_value
;
283 if (tx_ring
->itr_val
)
284 writel(1000000000 / (tx_ring
->itr_val
* 256),
285 hw
->hw_addr
+ tx_ring
->itr_register
);
287 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
290 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
291 struct igb_ring
*rx_ring
= &adapter
->rx_ring
[i
];
292 igb_assign_vector(adapter
, i
, IGB_N0_QUEUE
, vector
++);
293 adapter
->eims_enable_mask
|= rx_ring
->eims_value
;
294 if (rx_ring
->itr_val
)
295 writel(1000000000 / (rx_ring
->itr_val
* 256),
296 hw
->hw_addr
+ rx_ring
->itr_register
);
298 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
302 /* set vector for other causes, i.e. link changes */
303 array_wr32(E1000_MSIXBM(0), vector
++,
306 /* disable IAM for ICR interrupt bits */
309 tmp
= rd32(E1000_CTRL_EXT
);
310 /* enable MSI-X PBA support*/
311 tmp
|= E1000_CTRL_EXT_PBA_CLR
;
313 /* Auto-Mask interrupts upon ICR read. */
314 tmp
|= E1000_CTRL_EXT_EIAME
;
315 tmp
|= E1000_CTRL_EXT_IRCA
;
317 wr32(E1000_CTRL_EXT
, tmp
);
318 adapter
->eims_enable_mask
|= E1000_EIMS_OTHER
;
324 * igb_request_msix - Initialize MSI-X interrupts
326 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
329 static int igb_request_msix(struct igb_adapter
*adapter
)
331 struct net_device
*netdev
= adapter
->netdev
;
332 int i
, err
= 0, vector
= 0;
336 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
337 struct igb_ring
*ring
= &(adapter
->tx_ring
[i
]);
338 sprintf(ring
->name
, "%s-tx%d", netdev
->name
, i
);
339 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
340 &igb_msix_tx
, 0, ring
->name
,
341 &(adapter
->tx_ring
[i
]));
344 ring
->itr_register
= E1000_EITR(0) + (vector
<< 2);
345 ring
->itr_val
= adapter
->itr
;
348 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
349 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
350 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
351 sprintf(ring
->name
, "%s-rx%d", netdev
->name
, i
);
353 memcpy(ring
->name
, netdev
->name
, IFNAMSIZ
);
354 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
355 &igb_msix_rx
, 0, ring
->name
,
356 &(adapter
->rx_ring
[i
]));
359 ring
->itr_register
= E1000_EITR(0) + (vector
<< 2);
360 ring
->itr_val
= adapter
->itr
;
364 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
365 &igb_msix_other
, 0, netdev
->name
, netdev
);
369 adapter
->napi
.poll
= igb_clean_rx_ring_msix
;
370 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
371 adapter
->rx_ring
[i
].napi
.poll
= adapter
->napi
.poll
;
372 igb_configure_msix(adapter
);
378 static void igb_reset_interrupt_capability(struct igb_adapter
*adapter
)
380 if (adapter
->msix_entries
) {
381 pci_disable_msix(adapter
->pdev
);
382 kfree(adapter
->msix_entries
);
383 adapter
->msix_entries
= NULL
;
384 } else if (adapter
->msi_enabled
)
385 pci_disable_msi(adapter
->pdev
);
391 * igb_set_interrupt_capability - set MSI or MSI-X if supported
393 * Attempt to configure interrupts using the best available
394 * capabilities of the hardware and kernel.
396 static void igb_set_interrupt_capability(struct igb_adapter
*adapter
)
401 numvecs
= adapter
->num_tx_queues
+ adapter
->num_rx_queues
+ 1;
402 adapter
->msix_entries
= kcalloc(numvecs
, sizeof(struct msix_entry
),
404 if (!adapter
->msix_entries
)
407 for (i
= 0; i
< numvecs
; i
++)
408 adapter
->msix_entries
[i
].entry
= i
;
410 err
= pci_enable_msix(adapter
->pdev
,
411 adapter
->msix_entries
,
416 igb_reset_interrupt_capability(adapter
);
418 /* If we can't do MSI-X, try MSI */
420 adapter
->num_rx_queues
= 1;
421 if (!pci_enable_msi(adapter
->pdev
))
422 adapter
->msi_enabled
= 1;
427 * igb_request_irq - initialize interrupts
429 * Attempts to configure interrupts using the best available
430 * capabilities of the hardware and kernel.
432 static int igb_request_irq(struct igb_adapter
*adapter
)
434 struct net_device
*netdev
= adapter
->netdev
;
435 struct e1000_hw
*hw
= &adapter
->hw
;
438 if (adapter
->msix_entries
) {
439 err
= igb_request_msix(adapter
);
441 /* enable IAM, auto-mask,
442 <<<<<<< HEAD:drivers/net/igb/igb_main.c
443 * DO NOT USE EIAME or IAME in legacy mode */
445 * DO NOT USE EIAM
or IAM in legacy mode */
446 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
447 wr32(E1000_IAM
, IMS_ENABLE_MASK
);
450 /* fall back to MSI */
451 igb_reset_interrupt_capability(adapter
);
452 if (!pci_enable_msi(adapter
->pdev
))
453 adapter
->msi_enabled
= 1;
454 igb_free_all_tx_resources(adapter
);
455 igb_free_all_rx_resources(adapter
);
456 adapter
->num_rx_queues
= 1;
457 igb_alloc_queues(adapter
);
459 if (adapter
->msi_enabled
) {
460 err
= request_irq(adapter
->pdev
->irq
, &igb_intr_msi
, 0,
461 netdev
->name
, netdev
);
464 /* fall back to legacy interrupts */
465 igb_reset_interrupt_capability(adapter
);
466 adapter
->msi_enabled
= 0;
469 err
= request_irq(adapter
->pdev
->irq
, &igb_intr
, IRQF_SHARED
,
470 netdev
->name
, netdev
);
472 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
476 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
477 dev_err(&adapter
->pdev
->dev
, "Error %d getting interrupt\n",
479 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
483 /* enable IAM, auto-mask */
484 wr32(E1000_IAM
, IMS_ENABLE_MASK
);
486 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
492 static void igb_free_irq(struct igb_adapter
*adapter
)
494 struct net_device
*netdev
= adapter
->netdev
;
496 if (adapter
->msix_entries
) {
499 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
500 free_irq(adapter
->msix_entries
[vector
++].vector
,
501 &(adapter
->tx_ring
[i
]));
502 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
503 free_irq(adapter
->msix_entries
[vector
++].vector
,
504 &(adapter
->rx_ring
[i
]));
506 free_irq(adapter
->msix_entries
[vector
++].vector
, netdev
);
510 free_irq(adapter
->pdev
->irq
, netdev
);
514 * igb_irq_disable - Mask off interrupt generation on the NIC
515 * @adapter: board private structure
517 static void igb_irq_disable(struct igb_adapter
*adapter
)
519 struct e1000_hw
*hw
= &adapter
->hw
;
521 if (adapter
->msix_entries
) {
522 wr32(E1000_EIMC
, ~0);
527 synchronize_irq(adapter
->pdev
->irq
);
531 * igb_irq_enable - Enable default interrupt generation settings
532 * @adapter: board private structure
534 static void igb_irq_enable(struct igb_adapter
*adapter
)
536 struct e1000_hw
*hw
= &adapter
->hw
;
538 if (adapter
->msix_entries
) {
540 adapter
->eims_enable_mask
);
542 adapter
->eims_enable_mask
);
543 wr32(E1000_IMS
, E1000_IMS_LSC
);
545 wr32(E1000_IMS
, IMS_ENABLE_MASK
);
548 static void igb_update_mng_vlan(struct igb_adapter
*adapter
)
550 struct net_device
*netdev
= adapter
->netdev
;
551 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
552 u16 old_vid
= adapter
->mng_vlan_id
;
553 if (adapter
->vlgrp
) {
554 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
555 if (adapter
->hw
.mng_cookie
.status
&
556 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
557 igb_vlan_rx_add_vid(netdev
, vid
);
558 adapter
->mng_vlan_id
= vid
;
560 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
562 if ((old_vid
!= (u16
)IGB_MNG_VLAN_NONE
) &&
564 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
565 igb_vlan_rx_kill_vid(netdev
, old_vid
);
567 adapter
->mng_vlan_id
= vid
;
572 * igb_release_hw_control - release control of the h/w to f/w
573 * @adapter: address of board private structure
575 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
576 * For ASF and Pass Through versions of f/w this means that the
577 * driver is no longer loaded.
580 static void igb_release_hw_control(struct igb_adapter
*adapter
)
582 struct e1000_hw
*hw
= &adapter
->hw
;
585 /* Let firmware take over control of h/w */
586 ctrl_ext
= rd32(E1000_CTRL_EXT
);
588 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
593 * igb_get_hw_control - get control of the h/w from f/w
594 * @adapter: address of board private structure
596 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
597 * For ASF and Pass Through versions of f/w this means that
598 * the driver is loaded.
601 static void igb_get_hw_control(struct igb_adapter
*adapter
)
603 struct e1000_hw
*hw
= &adapter
->hw
;
606 /* Let firmware know the driver has taken over */
607 ctrl_ext
= rd32(E1000_CTRL_EXT
);
609 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
612 static void igb_init_manageability(struct igb_adapter
*adapter
)
614 struct e1000_hw
*hw
= &adapter
->hw
;
616 if (adapter
->en_mng_pt
) {
617 u32 manc2h
= rd32(E1000_MANC2H
);
618 u32 manc
= rd32(E1000_MANC
);
620 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
621 /* disable hardware interception of ARP */
622 manc
&= ~(E1000_MANC_ARP_EN
);
625 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
626 /* enable receiving management packets to the host */
627 /* this will probably generate destination unreachable messages
628 * from the host OS, but the packets will be handled on SMBUS */
629 manc
|= E1000_MANC_EN_MNG2HOST
;
630 #define E1000_MNG2HOST_PORT_623 (1 << 5)
631 #define E1000_MNG2HOST_PORT_664 (1 << 6)
632 manc2h
|= E1000_MNG2HOST_PORT_623
;
633 manc2h
|= E1000_MNG2HOST_PORT_664
;
634 wr32(E1000_MANC2H
, manc2h
);
636 wr32(E1000_MANC
, manc
);
640 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
641 static void igb_release_manageability(struct igb_adapter
*adapter
)
643 struct e1000_hw
*hw
= &adapter
->hw
;
645 if (adapter
->en_mng_pt
) {
646 u32 manc
= rd32(E1000_MANC
);
648 /* re-enable hardware interception of ARP */
649 manc
|= E1000_MANC_ARP_EN
;
650 manc
&= ~E1000_MANC_EN_MNG2HOST
;
652 /* don't explicitly have to mess with MANC2H since
653 * MANC has an enable disable that gates MANC2H */
655 /* XXX stop the hardware watchdog ? */
656 wr32(E1000_MANC
, manc
);
661 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
663 * igb_configure - configure the hardware for RX and TX
664 * @adapter: private board structure
666 static void igb_configure(struct igb_adapter
*adapter
)
668 struct net_device
*netdev
= adapter
->netdev
;
671 igb_get_hw_control(adapter
);
672 igb_set_multi(netdev
);
674 igb_restore_vlan(adapter
);
675 igb_init_manageability(adapter
);
677 igb_configure_tx(adapter
);
678 igb_setup_rctl(adapter
);
679 igb_configure_rx(adapter
);
680 /* call IGB_DESC_UNUSED which always leaves
681 * at least 1 descriptor unused to make sure
682 * next_to_use != next_to_clean */
683 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
684 struct igb_ring
*ring
= &adapter
->rx_ring
[i
];
685 igb_alloc_rx_buffers_adv(adapter
, ring
, IGB_DESC_UNUSED(ring
));
689 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
694 * igb_up - Open the interface and prepare it to handle traffic
695 * @adapter: board private structure
698 int igb_up(struct igb_adapter
*adapter
)
700 struct e1000_hw
*hw
= &adapter
->hw
;
703 /* hardware has been reset, we need to reload some things */
704 igb_configure(adapter
);
706 clear_bit(__IGB_DOWN
, &adapter
->state
);
708 napi_enable(&adapter
->napi
);
710 if (adapter
->msix_entries
) {
711 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
712 napi_enable(&adapter
->rx_ring
[i
].napi
);
713 igb_configure_msix(adapter
);
716 /* Clear any pending interrupts. */
718 igb_irq_enable(adapter
);
720 /* Fire a link change interrupt to start the watchdog. */
721 wr32(E1000_ICS
, E1000_ICS_LSC
);
725 void igb_down(struct igb_adapter
*adapter
)
727 struct e1000_hw
*hw
= &adapter
->hw
;
728 struct net_device
*netdev
= adapter
->netdev
;
732 /* signal that we're down so the interrupt handler does not
733 * reschedule our watchdog timer */
734 set_bit(__IGB_DOWN
, &adapter
->state
);
736 /* disable receives in the hardware */
737 rctl
= rd32(E1000_RCTL
);
738 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
739 /* flush and sleep below */
741 netif_stop_queue(netdev
);
743 /* disable transmits in the hardware */
744 tctl
= rd32(E1000_TCTL
);
745 tctl
&= ~E1000_TCTL_EN
;
746 wr32(E1000_TCTL
, tctl
);
747 /* flush both disables and wait for them to finish */
751 napi_disable(&adapter
->napi
);
753 if (adapter
->msix_entries
)
754 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
755 napi_disable(&adapter
->rx_ring
[i
].napi
);
756 igb_irq_disable(adapter
);
758 del_timer_sync(&adapter
->watchdog_timer
);
759 del_timer_sync(&adapter
->phy_info_timer
);
761 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
762 netif_carrier_off(netdev
);
763 adapter
->link_speed
= 0;
764 adapter
->link_duplex
= 0;
767 igb_clean_all_tx_rings(adapter
);
768 igb_clean_all_rx_rings(adapter
);
771 void igb_reinit_locked(struct igb_adapter
*adapter
)
773 WARN_ON(in_interrupt());
774 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
778 clear_bit(__IGB_RESETTING
, &adapter
->state
);
781 void igb_reset(struct igb_adapter
*adapter
)
783 struct e1000_hw
*hw
= &adapter
->hw
;
784 struct e1000_fc_info
*fc
= &adapter
->hw
.fc
;
785 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
788 /* Repartition Pba for greater than 9k mtu
789 * To take effect CTRL.RST is required.
793 if (adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) {
794 /* adjust PBA for jumbo frames */
795 wr32(E1000_PBA
, pba
);
797 /* To maintain wire speed transmits, the Tx FIFO should be
798 * large enough to accommodate two full transmit packets,
799 * rounded up to the next 1KB and expressed in KB. Likewise,
800 * the Rx FIFO should be large enough to accommodate at least
801 * one full receive packet and is similarly rounded up and
802 * expressed in KB. */
803 pba
= rd32(E1000_PBA
);
804 /* upper 16 bits has Tx packet buffer allocation size in KB */
805 tx_space
= pba
>> 16;
806 /* lower 16 bits has Rx packet buffer allocation size in KB */
808 /* the tx fifo also stores 16 bytes of information about the tx
809 * but don't include ethernet FCS because hardware appends it */
810 min_tx_space
= (adapter
->max_frame_size
+
811 sizeof(struct e1000_tx_desc
) -
813 min_tx_space
= ALIGN(min_tx_space
, 1024);
815 /* software strips receive CRC, so leave room for it */
816 min_rx_space
= adapter
->max_frame_size
;
817 min_rx_space
= ALIGN(min_rx_space
, 1024);
820 /* If current Tx allocation is less than the min Tx FIFO size,
821 * and the min Tx FIFO size is less than the current Rx FIFO
822 * allocation, take space away from current Rx allocation */
823 if (tx_space
< min_tx_space
&&
824 ((min_tx_space
- tx_space
) < pba
)) {
825 pba
= pba
- (min_tx_space
- tx_space
);
827 /* if short on rx space, rx wins and must trump tx
829 if (pba
< min_rx_space
)
833 wr32(E1000_PBA
, pba
);
835 /* flow control settings */
836 /* The high water mark must be low enough to fit one full frame
837 * (or the size used for early receive) above it in the Rx FIFO.
838 * Set it to the lower of:
839 * - 90% of the Rx FIFO size, or
840 * - the full Rx FIFO size minus one full frame */
841 hwm
= min(((pba
<< 10) * 9 / 10),
842 ((pba
<< 10) - adapter
->max_frame_size
));
844 fc
->high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
845 fc
->low_water
= fc
->high_water
- 8;
846 fc
->pause_time
= 0xFFFF;
848 fc
->type
= fc
->original_type
;
850 /* Allow time for pending master requests to run */
851 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
854 if (adapter
->hw
.mac
.ops
.init_hw(&adapter
->hw
))
855 dev_err(&adapter
->pdev
->dev
, "Hardware Error\n");
857 igb_update_mng_vlan(adapter
);
859 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
860 wr32(E1000_VET
, ETHERNET_IEEE_VLAN_TYPE
);
862 igb_reset_adaptive(&adapter
->hw
);
863 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
864 adapter
->hw
.phy
.ops
.get_phy_info(&adapter
->hw
);
865 igb_release_manageability(adapter
);
867 if (adapter
->hw
.phy
.ops
.get_phy_info
)
868 adapter
->hw
.phy
.ops
.get_phy_info(&adapter
->hw
);
869 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
873 * igb_probe - Device Initialization Routine
874 * @pdev: PCI device information struct
875 * @ent: entry in igb_pci_tbl
877 * Returns 0 on success, negative on failure
879 * igb_probe initializes an adapter identified by a pci_dev structure.
880 * The OS initialization, configuring of the adapter private structure,
881 * and a hardware reset occur.
883 static int __devinit
igb_probe(struct pci_dev
*pdev
,
884 const struct pci_device_id
*ent
)
886 struct net_device
*netdev
;
887 struct igb_adapter
*adapter
;
889 const struct e1000_info
*ei
= igb_info_tbl
[ent
->driver_data
];
890 unsigned long mmio_start
, mmio_len
;
891 static int cards_found
;
892 int i
, err
, pci_using_dac
;
894 u16 eeprom_apme_mask
= IGB_EEPROM_APME
;
897 err
= pci_enable_device(pdev
);
902 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
904 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
908 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
910 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
912 dev_err(&pdev
->dev
, "No usable DMA "
913 "configuration, aborting\n");
919 err
= pci_request_regions(pdev
, igb_driver_name
);
923 pci_set_master(pdev
);
926 netdev
= alloc_etherdev(sizeof(struct igb_adapter
));
928 goto err_alloc_etherdev
;
930 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
932 pci_set_drvdata(pdev
, netdev
);
933 adapter
= netdev_priv(netdev
);
934 adapter
->netdev
= netdev
;
935 adapter
->pdev
= pdev
;
938 adapter
->msg_enable
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
940 mmio_start
= pci_resource_start(pdev
, 0);
941 mmio_len
= pci_resource_len(pdev
, 0);
944 adapter
->hw
.hw_addr
= ioremap(mmio_start
, mmio_len
);
945 if (!adapter
->hw
.hw_addr
)
948 netdev
->open
= &igb_open
;
949 netdev
->stop
= &igb_close
;
950 netdev
->get_stats
= &igb_get_stats
;
951 netdev
->set_multicast_list
= &igb_set_multi
;
952 netdev
->set_mac_address
= &igb_set_mac
;
953 netdev
->change_mtu
= &igb_change_mtu
;
954 netdev
->do_ioctl
= &igb_ioctl
;
955 igb_set_ethtool_ops(netdev
);
956 netdev
->tx_timeout
= &igb_tx_timeout
;
957 netdev
->watchdog_timeo
= 5 * HZ
;
958 netif_napi_add(netdev
, &adapter
->napi
, igb_clean
, 64);
959 netdev
->vlan_rx_register
= igb_vlan_rx_register
;
960 netdev
->vlan_rx_add_vid
= igb_vlan_rx_add_vid
;
961 netdev
->vlan_rx_kill_vid
= igb_vlan_rx_kill_vid
;
962 #ifdef CONFIG_NET_POLL_CONTROLLER
963 netdev
->poll_controller
= igb_netpoll
;
965 netdev
->hard_start_xmit
= &igb_xmit_frame_adv
;
967 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
969 netdev
->mem_start
= mmio_start
;
970 netdev
->mem_end
= mmio_start
+ mmio_len
;
972 adapter
->bd_number
= cards_found
;
974 /* PCI config space info */
975 hw
->vendor_id
= pdev
->vendor
;
976 hw
->device_id
= pdev
->device
;
977 hw
->revision_id
= pdev
->revision
;
978 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
979 hw
->subsystem_device_id
= pdev
->subsystem_device
;
981 /* setup the private structure */
983 /* Copy the default MAC, PHY and NVM function pointers */
984 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
985 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
986 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
987 /* Initialize skew-specific constants */
988 err
= ei
->get_invariants(hw
);
992 err
= igb_sw_init(adapter
);
996 igb_get_bus_info_pcie(hw
);
998 hw
->phy
.autoneg_wait_to_complete
= false;
999 hw
->mac
.adaptive_ifs
= true;
1001 /* Copper options */
1002 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1003 hw
->phy
.mdix
= AUTO_ALL_MODES
;
1004 hw
->phy
.disable_polarity_correction
= false;
1005 hw
->phy
.ms_type
= e1000_ms_hw_default
;
1008 if (igb_check_reset_block(hw
))
1009 dev_info(&pdev
->dev
,
1010 "PHY reset is blocked due to SOL/IDER session.\n");
1012 netdev
->features
= NETIF_F_SG
|
1014 NETIF_F_HW_VLAN_TX
|
1015 NETIF_F_HW_VLAN_RX
|
1016 NETIF_F_HW_VLAN_FILTER
;
1018 netdev
->features
|= NETIF_F_TSO
;
1020 netdev
->features
|= NETIF_F_TSO6
;
1022 netdev
->features
|= NETIF_F_HIGHDMA
;
1024 netdev
->features
|= NETIF_F_LLTX
;
1025 adapter
->en_mng_pt
= igb_enable_mng_pass_thru(&adapter
->hw
);
1027 /* before reading the NVM, reset the controller to put the device in a
1028 * known good starting state */
1029 hw
->mac
.ops
.reset_hw(hw
);
1031 /* make sure the NVM is good */
1032 if (igb_validate_nvm_checksum(hw
) < 0) {
1033 dev_err(&pdev
->dev
, "The NVM Checksum Is Not Valid\n");
1038 /* copy the MAC address out of the NVM */
1039 if (hw
->mac
.ops
.read_mac_addr(hw
))
1040 dev_err(&pdev
->dev
, "NVM Read Error\n");
1042 memcpy(netdev
->dev_addr
, hw
->mac
.addr
, netdev
->addr_len
);
1043 memcpy(netdev
->perm_addr
, hw
->mac
.addr
, netdev
->addr_len
);
1045 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
1046 dev_err(&pdev
->dev
, "Invalid MAC Address\n");
1051 init_timer(&adapter
->watchdog_timer
);
1052 adapter
->watchdog_timer
.function
= &igb_watchdog
;
1053 adapter
->watchdog_timer
.data
= (unsigned long) adapter
;
1055 init_timer(&adapter
->phy_info_timer
);
1056 adapter
->phy_info_timer
.function
= &igb_update_phy_info
;
1057 adapter
->phy_info_timer
.data
= (unsigned long) adapter
;
1059 INIT_WORK(&adapter
->reset_task
, igb_reset_task
);
1060 INIT_WORK(&adapter
->watchdog_task
, igb_watchdog_task
);
1062 /* Initialize link & ring properties that are user-changeable */
1063 adapter
->tx_ring
->count
= 256;
1064 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1065 adapter
->tx_ring
[i
].count
= adapter
->tx_ring
->count
;
1066 adapter
->rx_ring
->count
= 256;
1067 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1068 adapter
->rx_ring
[i
].count
= adapter
->rx_ring
->count
;
1070 adapter
->fc_autoneg
= true;
1071 hw
->mac
.autoneg
= true;
1072 hw
->phy
.autoneg_advertised
= 0x2f;
1074 hw
->fc
.original_type
= e1000_fc_default
;
1075 hw
->fc
.type
= e1000_fc_default
;
1077 adapter
->itr_setting
= 3;
1078 adapter
->itr
= IGB_START_ITR
;
1080 igb_validate_mdi_setting(hw
);
1082 adapter
->rx_csum
= 1;
1084 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1085 * enable the ACPI Magic Packet filter
1088 if (hw
->bus
.func
== 0 ||
1089 hw
->device_id
== E1000_DEV_ID_82575EB_COPPER
)
1090 hw
->nvm
.ops
.read_nvm(hw
, NVM_INIT_CONTROL3_PORT_A
, 1,
1093 if (eeprom_data
& eeprom_apme_mask
)
1094 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1096 /* now that we have the eeprom settings, apply the special cases where
1097 * the eeprom may be wrong or the board simply won't support wake on
1098 * lan on a particular port */
1099 switch (pdev
->device
) {
1100 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
1101 adapter
->eeprom_wol
= 0;
1103 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
1104 /* Wake events only supported on port A for dual fiber
1105 * regardless of eeprom setting */
1106 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
)
1107 adapter
->eeprom_wol
= 0;
1111 /* initialize the wol settings based on the eeprom settings */
1112 adapter
->wol
= adapter
->eeprom_wol
;
1114 /* reset the hardware with the new settings */
1117 /* let the f/w know that the h/w is now under the control of the
1119 igb_get_hw_control(adapter
);
1121 /* tell the stack to leave us alone until igb_open() is called */
1122 netif_carrier_off(netdev
);
1123 netif_stop_queue(netdev
);
1125 strcpy(netdev
->name
, "eth%d");
1126 err
= register_netdev(netdev
);
1130 dev_info(&pdev
->dev
, "Intel(R) Gigabit Ethernet Network Connection\n");
1131 /* print bus type/speed/width info */
1132 dev_info(&pdev
->dev
,
1133 "%s: (PCIe:%s:%s) %02x:%02x:%02x:%02x:%02x:%02x\n",
1135 ((hw
->bus
.speed
== e1000_bus_speed_2500
)
1136 ? "2.5Gb/s" : "unknown"),
1137 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
)
1138 ? "Width x4" : (hw
->bus
.width
== e1000_bus_width_pcie_x1
)
1139 ? "Width x1" : "unknown"),
1140 netdev
->dev_addr
[0], netdev
->dev_addr
[1], netdev
->dev_addr
[2],
1141 netdev
->dev_addr
[3], netdev
->dev_addr
[4], netdev
->dev_addr
[5]);
1143 igb_read_part_num(hw
, &part_num
);
1144 dev_info(&pdev
->dev
, "%s: PBA No: %06x-%03x\n", netdev
->name
,
1145 (part_num
>> 8), (part_num
& 0xff));
1147 dev_info(&pdev
->dev
,
1148 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
1149 adapter
->msix_entries
? "MSI-X" :
1150 adapter
->msi_enabled
? "MSI" : "legacy",
1151 adapter
->num_rx_queues
, adapter
->num_tx_queues
);
1157 igb_release_hw_control(adapter
);
1159 if (!igb_check_reset_block(hw
))
1160 hw
->phy
.ops
.reset_phy(hw
);
1162 if (hw
->flash_address
)
1163 iounmap(hw
->flash_address
);
1165 igb_remove_device(hw
);
1166 kfree(adapter
->tx_ring
);
1167 kfree(adapter
->rx_ring
);
1170 iounmap(hw
->hw_addr
);
1172 free_netdev(netdev
);
1174 pci_release_regions(pdev
);
1177 pci_disable_device(pdev
);
1182 * igb_remove - Device Removal Routine
1183 * @pdev: PCI device information struct
1185 * igb_remove is called by the PCI subsystem to alert the driver
1186 * that it should release a PCI device. The could be caused by a
1187 * Hot-Plug event, or because the driver is going to be removed from
1190 static void __devexit
igb_remove(struct pci_dev
*pdev
)
1192 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1193 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1195 /* flush_scheduled work may reschedule our watchdog task, so
1196 * explicitly disable watchdog tasks from being rescheduled */
1197 set_bit(__IGB_DOWN
, &adapter
->state
);
1198 del_timer_sync(&adapter
->watchdog_timer
);
1199 del_timer_sync(&adapter
->phy_info_timer
);
1201 flush_scheduled_work();
1203 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
1205 igb_release_manageability(adapter
);
1208 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
1209 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1210 * would have already happened in close and is redundant. */
1211 igb_release_hw_control(adapter
);
1213 unregister_netdev(netdev
);
1215 if (!igb_check_reset_block(&adapter
->hw
))
1216 adapter
->hw
.phy
.ops
.reset_phy(&adapter
->hw
);
1218 igb_remove_device(&adapter
->hw
);
1219 igb_reset_interrupt_capability(adapter
);
1221 kfree(adapter
->tx_ring
);
1222 kfree(adapter
->rx_ring
);
1224 iounmap(adapter
->hw
.hw_addr
);
1225 if (adapter
->hw
.flash_address
)
1226 iounmap(adapter
->hw
.flash_address
);
1227 pci_release_regions(pdev
);
1229 free_netdev(netdev
);
1231 pci_disable_device(pdev
);
1235 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1236 * @adapter: board private structure to initialize
1238 * igb_sw_init initializes the Adapter private data structure.
1239 * Fields are initialized based on PCI device information and
1240 * OS network device settings (MTU size).
1242 static int __devinit
igb_sw_init(struct igb_adapter
*adapter
)
1244 struct e1000_hw
*hw
= &adapter
->hw
;
1245 struct net_device
*netdev
= adapter
->netdev
;
1246 struct pci_dev
*pdev
= adapter
->pdev
;
1248 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->bus
.pci_cmd_word
);
1250 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1251 adapter
->rx_ps_hdr_size
= 0; /* disable packet split */
1252 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1253 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
1255 /* Number of supported queues. */
1256 /* Having more queues than CPUs doesn't make sense. */
1257 adapter
->num_tx_queues
= 1;
1258 adapter
->num_rx_queues
= min(IGB_MAX_RX_QUEUES
, num_online_cpus());
1260 igb_set_interrupt_capability(adapter
);
1262 if (igb_alloc_queues(adapter
)) {
1263 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
1267 /* Explicitly disable IRQ since the NIC can be in any state. */
1268 igb_irq_disable(adapter
);
1270 set_bit(__IGB_DOWN
, &adapter
->state
);
1275 * igb_open - Called when a network interface is made active
1276 * @netdev: network interface device structure
1278 * Returns 0 on success, negative value on failure
1280 * The open entry point is called when a network interface is made
1281 * active by the system (IFF_UP). At this point all resources needed
1282 * for transmit and receive operations are allocated, the interrupt
1283 * handler is registered with the OS, the watchdog timer is started,
1284 * and the stack is notified that the interface is ready.
1286 static int igb_open(struct net_device
*netdev
)
1288 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1289 struct e1000_hw
*hw
= &adapter
->hw
;
1293 /* disallow open during test */
1294 if (test_bit(__IGB_TESTING
, &adapter
->state
))
1297 /* allocate transmit descriptors */
1298 err
= igb_setup_all_tx_resources(adapter
);
1302 /* allocate receive descriptors */
1303 err
= igb_setup_all_rx_resources(adapter
);
1307 /* e1000_power_up_phy(adapter); */
1309 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
1310 if ((adapter
->hw
.mng_cookie
.status
&
1311 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
1312 igb_update_mng_vlan(adapter
);
1314 /* before we allocate an interrupt, we must be ready to handle it.
1315 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1316 * as soon as we call pci_request_irq, so we have to setup our
1317 * clean_rx handler before we do so. */
1318 igb_configure(adapter
);
1320 err
= igb_request_irq(adapter
);
1324 /* From here on the code is the same as igb_up() */
1325 clear_bit(__IGB_DOWN
, &adapter
->state
);
1327 napi_enable(&adapter
->napi
);
1328 if (adapter
->msix_entries
)
1329 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1330 napi_enable(&adapter
->rx_ring
[i
].napi
);
1332 igb_irq_enable(adapter
);
1334 /* Clear any pending interrupts. */
1336 /* Fire a link status change interrupt to start the watchdog. */
1337 wr32(E1000_ICS
, E1000_ICS_LSC
);
1342 igb_release_hw_control(adapter
);
1343 /* e1000_power_down_phy(adapter); */
1344 igb_free_all_rx_resources(adapter
);
1346 igb_free_all_tx_resources(adapter
);
1354 * igb_close - Disables a network interface
1355 * @netdev: network interface device structure
1357 * Returns 0, this is not allowed to fail
1359 * The close entry point is called when an interface is de-activated
1360 * by the OS. The hardware is still under the driver's control, but
1361 * needs to be disabled. A global MAC reset is issued to stop the
1362 * hardware, and all transmit and receive resources are freed.
1364 static int igb_close(struct net_device
*netdev
)
1366 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1368 WARN_ON(test_bit(__IGB_RESETTING
, &adapter
->state
));
1371 igb_free_irq(adapter
);
1373 igb_free_all_tx_resources(adapter
);
1374 igb_free_all_rx_resources(adapter
);
1376 /* kill manageability vlan ID if supported, but not if a vlan with
1377 * the same ID is registered on the host OS (let 8021q kill it) */
1378 if ((adapter
->hw
.mng_cookie
.status
&
1379 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
1381 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
)))
1382 igb_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1388 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
1389 * @adapter: board private structure
1390 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1392 * Return 0 on success, negative on failure
1395 int igb_setup_tx_resources(struct igb_adapter
*adapter
,
1396 struct igb_ring
*tx_ring
)
1398 struct pci_dev
*pdev
= adapter
->pdev
;
1401 size
= sizeof(struct igb_buffer
) * tx_ring
->count
;
1402 tx_ring
->buffer_info
= vmalloc(size
);
1403 if (!tx_ring
->buffer_info
)
1405 memset(tx_ring
->buffer_info
, 0, size
);
1407 /* round up to nearest 4K */
1408 tx_ring
->size
= tx_ring
->count
* sizeof(struct e1000_tx_desc
)
1410 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1412 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
1418 tx_ring
->adapter
= adapter
;
1419 tx_ring
->next_to_use
= 0;
1420 tx_ring
->next_to_clean
= 0;
1421 spin_lock_init(&tx_ring
->tx_clean_lock
);
1422 spin_lock_init(&tx_ring
->tx_lock
);
1426 vfree(tx_ring
->buffer_info
);
1427 dev_err(&adapter
->pdev
->dev
,
1428 "Unable to allocate memory for the transmit descriptor ring\n");
1433 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
1434 * (Descriptors) for all queues
1435 * @adapter: board private structure
1437 * Return 0 on success, negative on failure
1439 static int igb_setup_all_tx_resources(struct igb_adapter
*adapter
)
1443 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1444 err
= igb_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1446 dev_err(&adapter
->pdev
->dev
,
1447 "Allocation for Tx Queue %u failed\n", i
);
1448 for (i
--; i
>= 0; i
--)
1449 igb_free_tx_resources(adapter
,
1450 &adapter
->tx_ring
[i
]);
1459 * igb_configure_tx - Configure transmit Unit after Reset
1460 * @adapter: board private structure
1462 * Configure the Tx unit of the MAC after a reset.
1464 static void igb_configure_tx(struct igb_adapter
*adapter
)
1467 struct e1000_hw
*hw
= &adapter
->hw
;
1472 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1473 struct igb_ring
*ring
= &(adapter
->tx_ring
[i
]);
1475 wr32(E1000_TDLEN(i
),
1476 ring
->count
* sizeof(struct e1000_tx_desc
));
1478 wr32(E1000_TDBAL(i
),
1479 tdba
& 0x00000000ffffffffULL
);
1480 wr32(E1000_TDBAH(i
), tdba
>> 32);
1482 tdwba
= ring
->dma
+ ring
->count
* sizeof(struct e1000_tx_desc
);
1483 tdwba
|= 1; /* enable head wb */
1484 wr32(E1000_TDWBAL(i
),
1485 tdwba
& 0x00000000ffffffffULL
);
1486 wr32(E1000_TDWBAH(i
), tdwba
>> 32);
1488 ring
->head
= E1000_TDH(i
);
1489 ring
->tail
= E1000_TDT(i
);
1490 writel(0, hw
->hw_addr
+ ring
->tail
);
1491 writel(0, hw
->hw_addr
+ ring
->head
);
1492 txdctl
= rd32(E1000_TXDCTL(i
));
1493 txdctl
|= E1000_TXDCTL_QUEUE_ENABLE
;
1494 wr32(E1000_TXDCTL(i
), txdctl
);
1496 /* Turn off Relaxed Ordering on head write-backs. The
1497 * writebacks MUST be delivered in order or it will
1498 * completely screw up our bookeeping.
1500 txctrl
= rd32(E1000_DCA_TXCTRL(i
));
1501 txctrl
&= ~E1000_DCA_TXCTRL_TX_WB_RO_EN
;
1502 wr32(E1000_DCA_TXCTRL(i
), txctrl
);
1507 /* Use the default values for the Tx Inter Packet Gap (IPG) timer */
1509 /* Program the Transmit Control Register */
1511 tctl
= rd32(E1000_TCTL
);
1512 tctl
&= ~E1000_TCTL_CT
;
1513 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1514 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1516 igb_config_collision_dist(hw
);
1518 /* Setup Transmit Descriptor Settings for eop descriptor */
1519 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_RS
;
1521 /* Enable transmits */
1522 tctl
|= E1000_TCTL_EN
;
1524 wr32(E1000_TCTL
, tctl
);
1528 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
1529 * @adapter: board private structure
1530 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1532 * Returns 0 on success, negative on failure
1535 int igb_setup_rx_resources(struct igb_adapter
*adapter
,
1536 struct igb_ring
*rx_ring
)
1538 struct pci_dev
*pdev
= adapter
->pdev
;
1541 size
= sizeof(struct igb_buffer
) * rx_ring
->count
;
1542 rx_ring
->buffer_info
= vmalloc(size
);
1543 if (!rx_ring
->buffer_info
)
1545 memset(rx_ring
->buffer_info
, 0, size
);
1547 desc_len
= sizeof(union e1000_adv_rx_desc
);
1549 /* Round up to nearest 4K */
1550 rx_ring
->size
= rx_ring
->count
* desc_len
;
1551 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
1553 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
,
1559 rx_ring
->next_to_clean
= 0;
1560 rx_ring
->next_to_use
= 0;
1561 rx_ring
->pending_skb
= NULL
;
1563 rx_ring
->adapter
= adapter
;
1564 /* FIXME: do we want to setup ring->napi->poll here? */
1565 rx_ring
->napi
.poll
= adapter
->napi
.poll
;
1570 vfree(rx_ring
->buffer_info
);
1571 dev_err(&adapter
->pdev
->dev
, "Unable to allocate memory for "
1572 "the receive descriptor ring\n");
1577 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
1578 * (Descriptors) for all queues
1579 * @adapter: board private structure
1581 * Return 0 on success, negative on failure
1583 static int igb_setup_all_rx_resources(struct igb_adapter
*adapter
)
1587 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1588 err
= igb_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1590 dev_err(&adapter
->pdev
->dev
,
1591 "Allocation for Rx Queue %u failed\n", i
);
1592 for (i
--; i
>= 0; i
--)
1593 igb_free_rx_resources(adapter
,
1594 &adapter
->rx_ring
[i
]);
1603 * igb_setup_rctl - configure the receive control registers
1604 * @adapter: Board private structure
1606 static void igb_setup_rctl(struct igb_adapter
*adapter
)
1608 struct e1000_hw
*hw
= &adapter
->hw
;
1613 rctl
= rd32(E1000_RCTL
);
1615 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1617 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
|
1618 E1000_RCTL_LBM_NO
| E1000_RCTL_RDMTS_HALF
|
1619 (adapter
->hw
.mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1621 /* disable the stripping of CRC because it breaks
1622 * BMC firmware connected over SMBUS
1623 rctl |= E1000_RCTL_SECRC;
1626 rctl
&= ~E1000_RCTL_SBP
;
1628 if (adapter
->netdev
->mtu
<= ETH_DATA_LEN
)
1629 rctl
&= ~E1000_RCTL_LPE
;
1631 rctl
|= E1000_RCTL_LPE
;
1632 if (adapter
->rx_buffer_len
<= IGB_RXBUFFER_2048
) {
1633 /* Setup buffer sizes */
1634 rctl
&= ~E1000_RCTL_SZ_4096
;
1635 rctl
|= E1000_RCTL_BSEX
;
1636 switch (adapter
->rx_buffer_len
) {
1637 case IGB_RXBUFFER_256
:
1638 rctl
|= E1000_RCTL_SZ_256
;
1639 rctl
&= ~E1000_RCTL_BSEX
;
1641 case IGB_RXBUFFER_512
:
1642 rctl
|= E1000_RCTL_SZ_512
;
1643 rctl
&= ~E1000_RCTL_BSEX
;
1645 case IGB_RXBUFFER_1024
:
1646 rctl
|= E1000_RCTL_SZ_1024
;
1647 rctl
&= ~E1000_RCTL_BSEX
;
1649 case IGB_RXBUFFER_2048
:
1651 rctl
|= E1000_RCTL_SZ_2048
;
1652 rctl
&= ~E1000_RCTL_BSEX
;
1654 case IGB_RXBUFFER_4096
:
1655 rctl
|= E1000_RCTL_SZ_4096
;
1657 case IGB_RXBUFFER_8192
:
1658 rctl
|= E1000_RCTL_SZ_8192
;
1660 case IGB_RXBUFFER_16384
:
1661 rctl
|= E1000_RCTL_SZ_16384
;
1665 rctl
&= ~E1000_RCTL_BSEX
;
1666 srrctl
= adapter
->rx_buffer_len
>> E1000_SRRCTL_BSIZEPKT_SHIFT
;
1669 /* 82575 and greater support packet-split where the protocol
1670 * header is placed in skb->data and the packet data is
1671 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1672 * In the case of a non-split, skb->data is linearly filled,
1673 * followed by the page buffers. Therefore, skb->data is
1674 * sized to hold the largest protocol header.
1676 /* allocations using alloc_page take too long for regular MTU
1677 * so only enable packet split for jumbo frames */
1678 if (rctl
& E1000_RCTL_LPE
) {
1679 adapter
->rx_ps_hdr_size
= IGB_RXBUFFER_128
;
1680 srrctl
= adapter
->rx_ps_hdr_size
<<
1681 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT
;
1682 /* buffer size is ALWAYS one page */
1683 srrctl
|= PAGE_SIZE
>> E1000_SRRCTL_BSIZEPKT_SHIFT
;
1684 srrctl
|= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
1686 adapter
->rx_ps_hdr_size
= 0;
1687 srrctl
|= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF
;
1690 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1691 wr32(E1000_SRRCTL(i
), srrctl
);
1693 wr32(E1000_RCTL
, rctl
);
1697 * igb_configure_rx - Configure receive Unit after Reset
1698 * @adapter: board private structure
1700 * Configure the Rx unit of the MAC after a reset.
1702 static void igb_configure_rx(struct igb_adapter
*adapter
)
1705 struct e1000_hw
*hw
= &adapter
->hw
;
1710 /* disable receives while setting up the descriptors */
1711 rctl
= rd32(E1000_RCTL
);
1712 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
1716 if (adapter
->itr_setting
> 3)
1718 1000000000 / (adapter
->itr
* 256));
1720 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1721 * the Base and Length of the Rx Descriptor Ring */
1722 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1723 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
1725 wr32(E1000_RDBAL(i
),
1726 rdba
& 0x00000000ffffffffULL
);
1727 wr32(E1000_RDBAH(i
), rdba
>> 32);
1728 wr32(E1000_RDLEN(i
),
1729 ring
->count
* sizeof(union e1000_adv_rx_desc
));
1731 ring
->head
= E1000_RDH(i
);
1732 ring
->tail
= E1000_RDT(i
);
1733 writel(0, hw
->hw_addr
+ ring
->tail
);
1734 writel(0, hw
->hw_addr
+ ring
->head
);
1736 rxdctl
= rd32(E1000_RXDCTL(i
));
1737 rxdctl
|= E1000_RXDCTL_QUEUE_ENABLE
;
1738 rxdctl
&= 0xFFF00000;
1739 rxdctl
|= IGB_RX_PTHRESH
;
1740 rxdctl
|= IGB_RX_HTHRESH
<< 8;
1741 rxdctl
|= IGB_RX_WTHRESH
<< 16;
1742 wr32(E1000_RXDCTL(i
), rxdctl
);
1745 if (adapter
->num_rx_queues
> 1) {
1754 get_random_bytes(&random
[0], 40);
1757 for (j
= 0; j
< (32 * 4); j
++) {
1759 (j
% adapter
->num_rx_queues
) << shift
;
1762 hw
->hw_addr
+ E1000_RETA(0) + (j
& ~3));
1764 mrqc
= E1000_MRQC_ENABLE_RSS_4Q
;
1766 /* Fill out hash function seeds */
1767 for (j
= 0; j
< 10; j
++)
1768 array_wr32(E1000_RSSRK(0), j
, random
[j
]);
1770 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
1771 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
1772 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV6
|
1773 E1000_MRQC_RSS_FIELD_IPV6_TCP
);
1774 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4_UDP
|
1775 E1000_MRQC_RSS_FIELD_IPV6_UDP
);
1776 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX
|
1777 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX
);
1780 wr32(E1000_MRQC
, mrqc
);
1782 /* Multiqueue and raw packet checksumming are mutually
1783 * exclusive. Note that this not the same as TCP/IP
1784 * checksumming, which works fine. */
1785 rxcsum
= rd32(E1000_RXCSUM
);
1786 rxcsum
|= E1000_RXCSUM_PCSD
;
1787 wr32(E1000_RXCSUM
, rxcsum
);
1789 /* Enable Receive Checksum Offload for TCP and UDP */
1790 rxcsum
= rd32(E1000_RXCSUM
);
1791 if (adapter
->rx_csum
) {
1792 rxcsum
|= E1000_RXCSUM_TUOFL
;
1794 /* Enable IPv4 payload checksum for UDP fragments
1795 * Must be used in conjunction with packet-split. */
1796 if (adapter
->rx_ps_hdr_size
)
1797 rxcsum
|= E1000_RXCSUM_IPPCSE
;
1799 rxcsum
&= ~E1000_RXCSUM_TUOFL
;
1800 /* don't need to clear IPPCSE as it defaults to 0 */
1802 wr32(E1000_RXCSUM
, rxcsum
);
1807 adapter
->max_frame_size
+ VLAN_TAG_SIZE
);
1809 wr32(E1000_RLPML
, adapter
->max_frame_size
);
1811 /* Enable Receives */
1812 wr32(E1000_RCTL
, rctl
);
1816 * igb_free_tx_resources - Free Tx Resources per Queue
1817 * @adapter: board private structure
1818 * @tx_ring: Tx descriptor ring for a specific queue
1820 * Free all transmit software resources
1822 static void igb_free_tx_resources(struct igb_adapter
*adapter
,
1823 struct igb_ring
*tx_ring
)
1825 struct pci_dev
*pdev
= adapter
->pdev
;
1827 igb_clean_tx_ring(adapter
, tx_ring
);
1829 vfree(tx_ring
->buffer_info
);
1830 tx_ring
->buffer_info
= NULL
;
1832 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
1834 tx_ring
->desc
= NULL
;
1838 * igb_free_all_tx_resources - Free Tx Resources for All Queues
1839 * @adapter: board private structure
1841 * Free all transmit software resources
1843 static void igb_free_all_tx_resources(struct igb_adapter
*adapter
)
1847 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1848 igb_free_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1851 static void igb_unmap_and_free_tx_resource(struct igb_adapter
*adapter
,
1852 struct igb_buffer
*buffer_info
)
1854 if (buffer_info
->dma
) {
1855 pci_unmap_page(adapter
->pdev
,
1857 buffer_info
->length
,
1859 buffer_info
->dma
= 0;
1861 if (buffer_info
->skb
) {
1862 dev_kfree_skb_any(buffer_info
->skb
);
1863 buffer_info
->skb
= NULL
;
1865 buffer_info
->time_stamp
= 0;
1866 /* buffer_info must be completely set up in the transmit path */
1870 * igb_clean_tx_ring - Free Tx Buffers
1871 * @adapter: board private structure
1872 * @tx_ring: ring to be cleaned
1874 static void igb_clean_tx_ring(struct igb_adapter
*adapter
,
1875 struct igb_ring
*tx_ring
)
1877 struct igb_buffer
*buffer_info
;
1881 if (!tx_ring
->buffer_info
)
1883 /* Free all the Tx ring sk_buffs */
1885 for (i
= 0; i
< tx_ring
->count
; i
++) {
1886 buffer_info
= &tx_ring
->buffer_info
[i
];
1887 igb_unmap_and_free_tx_resource(adapter
, buffer_info
);
1890 size
= sizeof(struct igb_buffer
) * tx_ring
->count
;
1891 memset(tx_ring
->buffer_info
, 0, size
);
1893 /* Zero out the descriptor ring */
1895 memset(tx_ring
->desc
, 0, tx_ring
->size
);
1897 tx_ring
->next_to_use
= 0;
1898 tx_ring
->next_to_clean
= 0;
1900 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
1901 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
1905 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
1906 * @adapter: board private structure
1908 static void igb_clean_all_tx_rings(struct igb_adapter
*adapter
)
1912 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
1913 igb_clean_tx_ring(adapter
, &adapter
->tx_ring
[i
]);
1917 * igb_free_rx_resources - Free Rx Resources
1918 * @adapter: board private structure
1919 * @rx_ring: ring to clean the resources from
1921 * Free all receive software resources
1923 static void igb_free_rx_resources(struct igb_adapter
*adapter
,
1924 struct igb_ring
*rx_ring
)
1926 struct pci_dev
*pdev
= adapter
->pdev
;
1928 igb_clean_rx_ring(adapter
, rx_ring
);
1930 vfree(rx_ring
->buffer_info
);
1931 rx_ring
->buffer_info
= NULL
;
1933 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
1935 rx_ring
->desc
= NULL
;
1939 * igb_free_all_rx_resources - Free Rx Resources for All Queues
1940 * @adapter: board private structure
1942 * Free all receive software resources
1944 static void igb_free_all_rx_resources(struct igb_adapter
*adapter
)
1948 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1949 igb_free_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1953 * igb_clean_rx_ring - Free Rx Buffers per Queue
1954 * @adapter: board private structure
1955 * @rx_ring: ring to free buffers from
1957 static void igb_clean_rx_ring(struct igb_adapter
*adapter
,
1958 struct igb_ring
*rx_ring
)
1960 struct igb_buffer
*buffer_info
;
1961 struct pci_dev
*pdev
= adapter
->pdev
;
1965 if (!rx_ring
->buffer_info
)
1967 /* Free all the Rx ring sk_buffs */
1968 for (i
= 0; i
< rx_ring
->count
; i
++) {
1969 buffer_info
= &rx_ring
->buffer_info
[i
];
1970 if (buffer_info
->dma
) {
1971 if (adapter
->rx_ps_hdr_size
)
1972 pci_unmap_single(pdev
, buffer_info
->dma
,
1973 adapter
->rx_ps_hdr_size
,
1974 PCI_DMA_FROMDEVICE
);
1976 pci_unmap_single(pdev
, buffer_info
->dma
,
1977 adapter
->rx_buffer_len
,
1978 PCI_DMA_FROMDEVICE
);
1979 buffer_info
->dma
= 0;
1982 if (buffer_info
->skb
) {
1983 dev_kfree_skb(buffer_info
->skb
);
1984 buffer_info
->skb
= NULL
;
1986 if (buffer_info
->page
) {
1987 pci_unmap_page(pdev
, buffer_info
->page_dma
,
1988 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
1989 put_page(buffer_info
->page
);
1990 buffer_info
->page
= NULL
;
1991 buffer_info
->page_dma
= 0;
1995 /* there also may be some cached data from a chained receive */
1996 if (rx_ring
->pending_skb
) {
1997 dev_kfree_skb(rx_ring
->pending_skb
);
1998 rx_ring
->pending_skb
= NULL
;
2001 size
= sizeof(struct igb_buffer
) * rx_ring
->count
;
2002 memset(rx_ring
->buffer_info
, 0, size
);
2004 /* Zero out the descriptor ring */
2005 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2007 rx_ring
->next_to_clean
= 0;
2008 rx_ring
->next_to_use
= 0;
2010 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
2011 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
2015 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
2016 * @adapter: board private structure
2018 static void igb_clean_all_rx_rings(struct igb_adapter
*adapter
)
2022 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2023 igb_clean_rx_ring(adapter
, &adapter
->rx_ring
[i
]);
2027 * igb_set_mac - Change the Ethernet Address of the NIC
2028 * @netdev: network interface device structure
2029 * @p: pointer to an address structure
2031 * Returns 0 on success, negative on failure
2033 static int igb_set_mac(struct net_device
*netdev
, void *p
)
2035 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2036 struct sockaddr
*addr
= p
;
2038 if (!is_valid_ether_addr(addr
->sa_data
))
2039 return -EADDRNOTAVAIL
;
2041 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2042 memcpy(adapter
->hw
.mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
2044 adapter
->hw
.mac
.ops
.rar_set(&adapter
->hw
, adapter
->hw
.mac
.addr
, 0);
2050 * igb_set_multi - Multicast and Promiscuous mode set
2051 * @netdev: network interface device structure
2053 * The set_multi entry point is called whenever the multicast address
2054 * list or the network interface flags are updated. This routine is
2055 * responsible for configuring the hardware for proper multicast,
2056 * promiscuous mode, and all-multi behavior.
2058 static void igb_set_multi(struct net_device
*netdev
)
2060 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2061 struct e1000_hw
*hw
= &adapter
->hw
;
2062 struct e1000_mac_info
*mac
= &hw
->mac
;
2063 struct dev_mc_list
*mc_ptr
;
2068 /* Check for Promiscuous and All Multicast modes */
2070 rctl
= rd32(E1000_RCTL
);
2072 if (netdev
->flags
& IFF_PROMISC
)
2073 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2074 else if (netdev
->flags
& IFF_ALLMULTI
) {
2075 rctl
|= E1000_RCTL_MPE
;
2076 rctl
&= ~E1000_RCTL_UPE
;
2078 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2080 wr32(E1000_RCTL
, rctl
);
2082 if (!netdev
->mc_count
) {
2083 /* nothing to program, so clear mc list */
2084 igb_update_mc_addr_list(hw
, NULL
, 0, 1,
2085 mac
->rar_entry_count
);
2089 mta_list
= kzalloc(netdev
->mc_count
* 6, GFP_ATOMIC
);
2093 /* The shared function expects a packed array of only addresses. */
2094 mc_ptr
= netdev
->mc_list
;
2096 for (i
= 0; i
< netdev
->mc_count
; i
++) {
2099 memcpy(mta_list
+ (i
*ETH_ALEN
), mc_ptr
->dmi_addr
, ETH_ALEN
);
2100 mc_ptr
= mc_ptr
->next
;
2102 igb_update_mc_addr_list(hw
, mta_list
, i
, 1, mac
->rar_entry_count
);
2106 /* Need to wait a few seconds after link up to get diagnostic information from
2108 static void igb_update_phy_info(unsigned long data
)
2110 struct igb_adapter
*adapter
= (struct igb_adapter
*) data
;
2111 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
2112 adapter
->hw
.phy
.ops
.get_phy_info(&adapter
->hw
);
2114 if (adapter
->hw
.phy
.ops
.get_phy_info
)
2115 adapter
->hw
.phy
.ops
.get_phy_info(&adapter
->hw
);
2116 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
2120 * igb_watchdog - Timer Call-back
2121 * @data: pointer to adapter cast into an unsigned long
2123 static void igb_watchdog(unsigned long data
)
2125 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
2126 /* Do the rest outside of interrupt context */
2127 schedule_work(&adapter
->watchdog_task
);
2130 static void igb_watchdog_task(struct work_struct
*work
)
2132 struct igb_adapter
*adapter
= container_of(work
,
2133 struct igb_adapter
, watchdog_task
);
2134 struct e1000_hw
*hw
= &adapter
->hw
;
2136 struct net_device
*netdev
= adapter
->netdev
;
2137 struct igb_ring
*tx_ring
= adapter
->tx_ring
;
2138 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
2142 if ((netif_carrier_ok(netdev
)) &&
2143 (rd32(E1000_STATUS
) & E1000_STATUS_LU
))
2146 ret_val
= hw
->mac
.ops
.check_for_link(&adapter
->hw
);
2147 if ((ret_val
== E1000_ERR_PHY
) &&
2148 (hw
->phy
.type
== e1000_phy_igp_3
) &&
2150 E1000_PHY_CTRL_GBE_DISABLE
))
2151 dev_info(&adapter
->pdev
->dev
,
2152 "Gigabit has been disabled, downgrading speed\n");
2154 if ((hw
->phy
.media_type
== e1000_media_type_internal_serdes
) &&
2155 !(rd32(E1000_TXCW
) & E1000_TXCW_ANE
))
2156 link
= mac
->serdes_has_link
;
2158 link
= rd32(E1000_STATUS
) &
2162 if (!netif_carrier_ok(netdev
)) {
2164 hw
->mac
.ops
.get_speed_and_duplex(&adapter
->hw
,
2165 &adapter
->link_speed
,
2166 &adapter
->link_duplex
);
2168 ctrl
= rd32(E1000_CTRL
);
2169 dev_info(&adapter
->pdev
->dev
,
2170 "NIC Link is Up %d Mbps %s, "
2171 "Flow Control: %s\n",
2172 adapter
->link_speed
,
2173 adapter
->link_duplex
== FULL_DUPLEX
?
2174 "Full Duplex" : "Half Duplex",
2175 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2176 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2177 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2178 E1000_CTRL_TFCE
) ? "TX" : "None")));
2180 /* tweak tx_queue_len according to speed/duplex and
2181 * adjust the timeout factor */
2182 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2183 adapter
->tx_timeout_factor
= 1;
2184 switch (adapter
->link_speed
) {
2186 netdev
->tx_queue_len
= 10;
2187 adapter
->tx_timeout_factor
= 14;
2190 netdev
->tx_queue_len
= 100;
2191 /* maybe add some timeout factor ? */
2195 netif_carrier_on(netdev
);
2196 netif_wake_queue(netdev
);
2198 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2199 mod_timer(&adapter
->phy_info_timer
,
2200 round_jiffies(jiffies
+ 2 * HZ
));
2203 if (netif_carrier_ok(netdev
)) {
2204 adapter
->link_speed
= 0;
2205 adapter
->link_duplex
= 0;
2206 dev_info(&adapter
->pdev
->dev
, "NIC Link is Down\n");
2207 netif_carrier_off(netdev
);
2208 netif_stop_queue(netdev
);
2209 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2210 mod_timer(&adapter
->phy_info_timer
,
2211 round_jiffies(jiffies
+ 2 * HZ
));
2216 igb_update_stats(adapter
);
2218 mac
->tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2219 adapter
->tpt_old
= adapter
->stats
.tpt
;
2220 mac
->collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2221 adapter
->colc_old
= adapter
->stats
.colc
;
2223 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
2224 adapter
->gorc_old
= adapter
->stats
.gorc
;
2225 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
2226 adapter
->gotc_old
= adapter
->stats
.gotc
;
2228 igb_update_adaptive(&adapter
->hw
);
2230 if (!netif_carrier_ok(netdev
)) {
2231 if (IGB_DESC_UNUSED(tx_ring
) + 1 < tx_ring
->count
) {
2232 /* We've lost link, so the controller stops DMA,
2233 * but we've got queued Tx work that's never going
2234 * to get done, so reset controller to flush Tx.
2235 * (Do the reset outside of interrupt context). */
2236 adapter
->tx_timeout_count
++;
2237 schedule_work(&adapter
->reset_task
);
2241 /* Cause software interrupt to ensure rx ring is cleaned */
2242 wr32(E1000_ICS
, E1000_ICS_RXDMT0
);
2244 /* Force detection of hung controller every watchdog period */
2245 tx_ring
->detect_tx_hung
= true;
2247 /* Reset the timer */
2248 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2249 mod_timer(&adapter
->watchdog_timer
,
2250 round_jiffies(jiffies
+ 2 * HZ
));
2253 enum latency_range
{
2257 latency_invalid
= 255
2261 static void igb_lower_rx_eitr(struct igb_adapter
*adapter
,
2262 struct igb_ring
*rx_ring
)
2264 struct e1000_hw
*hw
= &adapter
->hw
;
2267 new_val
= rx_ring
->itr_val
/ 2;
2268 if (new_val
< IGB_MIN_DYN_ITR
)
2269 new_val
= IGB_MIN_DYN_ITR
;
2271 if (new_val
!= rx_ring
->itr_val
) {
2272 rx_ring
->itr_val
= new_val
;
2273 wr32(rx_ring
->itr_register
,
2274 1000000000 / (new_val
* 256));
2278 static void igb_raise_rx_eitr(struct igb_adapter
*adapter
,
2279 struct igb_ring
*rx_ring
)
2281 struct e1000_hw
*hw
= &adapter
->hw
;
2284 new_val
= rx_ring
->itr_val
* 2;
2285 if (new_val
> IGB_MAX_DYN_ITR
)
2286 new_val
= IGB_MAX_DYN_ITR
;
2288 if (new_val
!= rx_ring
->itr_val
) {
2289 rx_ring
->itr_val
= new_val
;
2290 wr32(rx_ring
->itr_register
,
2291 1000000000 / (new_val
* 256));
2296 * igb_update_itr - update the dynamic ITR value based on statistics
2297 * Stores a new ITR value based on packets and byte
2298 * counts during the last interrupt. The advantage of per interrupt
2299 * computation is faster updates and more accurate ITR for the current
2300 * traffic pattern. Constants in this function were computed
2301 * based on theoretical maximum wire speed and thresholds were set based
2302 * on testing data as well as attempting to minimize response time
2303 * while increasing bulk throughput.
2304 * this functionality is controlled by the InterruptThrottleRate module
2305 * parameter (see igb_param.c)
2306 * NOTE: These calculations are only valid when operating in a single-
2307 * queue environment.
2308 * @adapter: pointer to adapter
2309 * @itr_setting: current adapter->itr
2310 * @packets: the number of packets during this measurement interval
2311 * @bytes: the number of bytes during this measurement interval
2313 static unsigned int igb_update_itr(struct igb_adapter
*adapter
, u16 itr_setting
,
2314 int packets
, int bytes
)
2316 unsigned int retval
= itr_setting
;
2319 goto update_itr_done
;
2321 switch (itr_setting
) {
2322 case lowest_latency
:
2323 /* handle TSO and jumbo frames */
2324 if (bytes
/packets
> 8000)
2325 retval
= bulk_latency
;
2326 else if ((packets
< 5) && (bytes
> 512))
2327 retval
= low_latency
;
2329 case low_latency
: /* 50 usec aka 20000 ints/s */
2330 if (bytes
> 10000) {
2331 /* this if handles the TSO accounting */
2332 if (bytes
/packets
> 8000) {
2333 retval
= bulk_latency
;
2334 } else if ((packets
< 10) || ((bytes
/packets
) > 1200)) {
2335 retval
= bulk_latency
;
2336 } else if ((packets
> 35)) {
2337 retval
= lowest_latency
;
2339 } else if (bytes
/packets
> 2000) {
2340 retval
= bulk_latency
;
2341 } else if (packets
<= 2 && bytes
< 512) {
2342 retval
= lowest_latency
;
2345 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2346 if (bytes
> 25000) {
2348 retval
= low_latency
;
2349 } else if (bytes
< 6000) {
2350 retval
= low_latency
;
2359 static void igb_set_itr(struct igb_adapter
*adapter
, u16 itr_register
,
2363 u32 new_itr
= adapter
->itr
;
2365 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2366 if (adapter
->link_speed
!= SPEED_1000
) {
2372 adapter
->rx_itr
= igb_update_itr(adapter
,
2374 adapter
->rx_ring
->total_packets
,
2375 adapter
->rx_ring
->total_bytes
);
2376 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2377 if (adapter
->itr_setting
== 3 && adapter
->rx_itr
== lowest_latency
)
2378 adapter
->rx_itr
= low_latency
;
2381 adapter
->tx_itr
= igb_update_itr(adapter
,
2383 adapter
->tx_ring
->total_packets
,
2384 adapter
->tx_ring
->total_bytes
);
2385 /* conservative mode (itr 3) eliminates the
2386 * lowest_latency setting */
2387 if (adapter
->itr_setting
== 3 &&
2388 adapter
->tx_itr
== lowest_latency
)
2389 adapter
->tx_itr
= low_latency
;
2391 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2393 current_itr
= adapter
->rx_itr
;
2396 switch (current_itr
) {
2397 /* counts and packets in update_itr are dependent on these numbers */
2398 case lowest_latency
:
2402 new_itr
= 20000; /* aka hwitr = ~200 */
2412 if (new_itr
!= adapter
->itr
) {
2413 /* this attempts to bias the interrupt rate towards Bulk
2414 * by adding intermediate steps when interrupt rate is
2416 new_itr
= new_itr
> adapter
->itr
?
2417 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2419 /* Don't write the value here; it resets the adapter's
2420 * internal timer, and causes us to delay far longer than
2421 * we should between interrupts. Instead, we write the ITR
2422 * value at the beginning of the next interrupt so the timing
2423 * ends up being correct.
2425 adapter
->itr
= new_itr
;
2426 adapter
->set_itr
= 1;
2433 #define IGB_TX_FLAGS_CSUM 0x00000001
2434 #define IGB_TX_FLAGS_VLAN 0x00000002
2435 #define IGB_TX_FLAGS_TSO 0x00000004
2436 #define IGB_TX_FLAGS_IPV4 0x00000008
2437 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
2438 #define IGB_TX_FLAGS_VLAN_SHIFT 16
2440 static inline int igb_tso_adv(struct igb_adapter
*adapter
,
2441 struct igb_ring
*tx_ring
,
2442 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2444 struct e1000_adv_tx_context_desc
*context_desc
;
2447 struct igb_buffer
*buffer_info
;
2448 u32 info
= 0, tu_cmd
= 0;
2449 u32 mss_l4len_idx
, l4len
;
2452 if (skb_header_cloned(skb
)) {
2453 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2458 l4len
= tcp_hdrlen(skb
);
2461 if (skb
->protocol
== htons(ETH_P_IP
)) {
2462 struct iphdr
*iph
= ip_hdr(skb
);
2465 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2469 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
2470 ipv6_hdr(skb
)->payload_len
= 0;
2471 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2472 &ipv6_hdr(skb
)->daddr
,
2476 i
= tx_ring
->next_to_use
;
2478 buffer_info
= &tx_ring
->buffer_info
[i
];
2479 context_desc
= E1000_TX_CTXTDESC_ADV(*tx_ring
, i
);
2480 /* VLAN MACLEN IPLEN */
2481 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
2482 info
|= (tx_flags
& IGB_TX_FLAGS_VLAN_MASK
);
2483 info
|= (skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
);
2484 *hdr_len
+= skb_network_offset(skb
);
2485 info
|= skb_network_header_len(skb
);
2486 *hdr_len
+= skb_network_header_len(skb
);
2487 context_desc
->vlan_macip_lens
= cpu_to_le32(info
);
2489 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2490 tu_cmd
|= (E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
);
2492 if (skb
->protocol
== htons(ETH_P_IP
))
2493 tu_cmd
|= E1000_ADVTXD_TUCMD_IPV4
;
2494 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
2496 context_desc
->type_tucmd_mlhl
= cpu_to_le32(tu_cmd
);
2499 mss_l4len_idx
= (skb_shinfo(skb
)->gso_size
<< E1000_ADVTXD_MSS_SHIFT
);
2500 mss_l4len_idx
|= (l4len
<< E1000_ADVTXD_L4LEN_SHIFT
);
2502 /* Context index must be unique per ring. Luckily, so is the interrupt
2504 mss_l4len_idx
|= tx_ring
->eims_value
>> 4;
2506 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2507 context_desc
->seqnum_seed
= 0;
2509 buffer_info
->time_stamp
= jiffies
;
2510 buffer_info
->dma
= 0;
2512 if (i
== tx_ring
->count
)
2515 tx_ring
->next_to_use
= i
;
2520 static inline bool igb_tx_csum_adv(struct igb_adapter
*adapter
,
2521 struct igb_ring
*tx_ring
,
2522 struct sk_buff
*skb
, u32 tx_flags
)
2524 struct e1000_adv_tx_context_desc
*context_desc
;
2526 struct igb_buffer
*buffer_info
;
2527 u32 info
= 0, tu_cmd
= 0;
2529 if ((skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
2530 (tx_flags
& IGB_TX_FLAGS_VLAN
)) {
2531 i
= tx_ring
->next_to_use
;
2532 buffer_info
= &tx_ring
->buffer_info
[i
];
2533 context_desc
= E1000_TX_CTXTDESC_ADV(*tx_ring
, i
);
2535 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
2536 info
|= (tx_flags
& IGB_TX_FLAGS_VLAN_MASK
);
2537 info
|= (skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
);
2538 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2539 info
|= skb_network_header_len(skb
);
2541 context_desc
->vlan_macip_lens
= cpu_to_le32(info
);
2543 tu_cmd
|= (E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
);
2545 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2546 if (skb
->protocol
== htons(ETH_P_IP
))
2547 tu_cmd
|= E1000_ADVTXD_TUCMD_IPV4
;
2548 if (skb
->sk
&& (skb
->sk
->sk_protocol
== IPPROTO_TCP
))
2549 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
2552 context_desc
->type_tucmd_mlhl
= cpu_to_le32(tu_cmd
);
2553 context_desc
->seqnum_seed
= 0;
2554 context_desc
->mss_l4len_idx
=
2555 cpu_to_le32(tx_ring
->eims_value
>> 4);
2557 buffer_info
->time_stamp
= jiffies
;
2558 buffer_info
->dma
= 0;
2561 if (i
== tx_ring
->count
)
2563 tx_ring
->next_to_use
= i
;
2572 #define IGB_MAX_TXD_PWR 16
2573 #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
2575 static inline int igb_tx_map_adv(struct igb_adapter
*adapter
,
2576 struct igb_ring
*tx_ring
,
2577 struct sk_buff
*skb
)
2579 struct igb_buffer
*buffer_info
;
2580 unsigned int len
= skb_headlen(skb
);
2581 unsigned int count
= 0, i
;
2584 i
= tx_ring
->next_to_use
;
2586 buffer_info
= &tx_ring
->buffer_info
[i
];
2587 BUG_ON(len
>= IGB_MAX_DATA_PER_TXD
);
2588 buffer_info
->length
= len
;
2589 /* set time_stamp *before* dma to help avoid a possible race */
2590 buffer_info
->time_stamp
= jiffies
;
2591 buffer_info
->dma
= pci_map_single(adapter
->pdev
, skb
->data
, len
,
2595 if (i
== tx_ring
->count
)
2598 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++) {
2599 struct skb_frag_struct
*frag
;
2601 frag
= &skb_shinfo(skb
)->frags
[f
];
2604 buffer_info
= &tx_ring
->buffer_info
[i
];
2605 BUG_ON(len
>= IGB_MAX_DATA_PER_TXD
);
2606 buffer_info
->length
= len
;
2607 buffer_info
->time_stamp
= jiffies
;
2608 buffer_info
->dma
= pci_map_page(adapter
->pdev
,
2616 if (i
== tx_ring
->count
)
2620 i
= (i
== 0) ? tx_ring
->count
- 1 : i
- 1;
2621 tx_ring
->buffer_info
[i
].skb
= skb
;
2626 static inline void igb_tx_queue_adv(struct igb_adapter
*adapter
,
2627 struct igb_ring
*tx_ring
,
2628 int tx_flags
, int count
, u32 paylen
,
2631 union e1000_adv_tx_desc
*tx_desc
= NULL
;
2632 struct igb_buffer
*buffer_info
;
2633 u32 olinfo_status
= 0, cmd_type_len
;
2636 cmd_type_len
= (E1000_ADVTXD_DTYP_DATA
| E1000_ADVTXD_DCMD_IFCS
|
2637 E1000_ADVTXD_DCMD_DEXT
);
2639 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
2640 cmd_type_len
|= E1000_ADVTXD_DCMD_VLE
;
2642 if (tx_flags
& IGB_TX_FLAGS_TSO
) {
2643 cmd_type_len
|= E1000_ADVTXD_DCMD_TSE
;
2645 /* insert tcp checksum */
2646 olinfo_status
|= E1000_TXD_POPTS_TXSM
<< 8;
2648 /* insert ip checksum */
2649 if (tx_flags
& IGB_TX_FLAGS_IPV4
)
2650 olinfo_status
|= E1000_TXD_POPTS_IXSM
<< 8;
2652 } else if (tx_flags
& IGB_TX_FLAGS_CSUM
) {
2653 olinfo_status
|= E1000_TXD_POPTS_TXSM
<< 8;
2656 if (tx_flags
& (IGB_TX_FLAGS_CSUM
| IGB_TX_FLAGS_TSO
|
2658 olinfo_status
|= tx_ring
->eims_value
>> 4;
2660 olinfo_status
|= ((paylen
- hdr_len
) << E1000_ADVTXD_PAYLEN_SHIFT
);
2662 i
= tx_ring
->next_to_use
;
2664 buffer_info
= &tx_ring
->buffer_info
[i
];
2665 tx_desc
= E1000_TX_DESC_ADV(*tx_ring
, i
);
2666 tx_desc
->read
.buffer_addr
= cpu_to_le64(buffer_info
->dma
);
2667 tx_desc
->read
.cmd_type_len
=
2668 cpu_to_le32(cmd_type_len
| buffer_info
->length
);
2669 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
2671 if (i
== tx_ring
->count
)
2675 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(adapter
->txd_cmd
);
2676 /* Force memory writes to complete before letting h/w
2677 * know there are new descriptors to fetch. (Only
2678 * applicable for weak-ordered memory model archs,
2679 * such as IA-64). */
2682 tx_ring
->next_to_use
= i
;
2683 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2684 /* we need this if more than one processor can write to our tail
2685 * at a time, it syncronizes IO on IA64/Altix systems */
2689 static int __igb_maybe_stop_tx(struct net_device
*netdev
,
2690 struct igb_ring
*tx_ring
, int size
)
2692 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2694 netif_stop_queue(netdev
);
2695 /* Herbert's original patch had:
2696 * smp_mb__after_netif_stop_queue();
2697 * but since that doesn't exist yet, just open code it. */
2700 /* We need to check again in a case another CPU has just
2701 * made room available. */
2702 if (IGB_DESC_UNUSED(tx_ring
) < size
)
2706 netif_start_queue(netdev
);
2707 ++adapter
->restart_queue
;
2711 static int igb_maybe_stop_tx(struct net_device
*netdev
,
2712 struct igb_ring
*tx_ring
, int size
)
2714 if (IGB_DESC_UNUSED(tx_ring
) >= size
)
2716 return __igb_maybe_stop_tx(netdev
, tx_ring
, size
);
2719 #define TXD_USE_COUNT(S) (((S) >> (IGB_MAX_TXD_PWR)) + 1)
2721 static int igb_xmit_frame_ring_adv(struct sk_buff
*skb
,
2722 struct net_device
*netdev
,
2723 struct igb_ring
*tx_ring
)
2725 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2726 unsigned int tx_flags
= 0;
2728 unsigned long irq_flags
;
2732 len
= skb_headlen(skb
);
2734 if (test_bit(__IGB_DOWN
, &adapter
->state
)) {
2735 dev_kfree_skb_any(skb
);
2736 return NETDEV_TX_OK
;
2739 if (skb
->len
<= 0) {
2740 dev_kfree_skb_any(skb
);
2741 return NETDEV_TX_OK
;
2744 if (!spin_trylock_irqsave(&tx_ring
->tx_lock
, irq_flags
))
2745 /* Collision - tell upper layer to requeue */
2746 return NETDEV_TX_LOCKED
;
2748 /* need: 1 descriptor per page,
2749 * + 2 desc gap to keep tail from touching head,
2750 * + 1 desc for skb->data,
2751 * + 1 desc for context descriptor,
2752 * otherwise try next time */
2753 if (igb_maybe_stop_tx(netdev
, tx_ring
, skb_shinfo(skb
)->nr_frags
+ 4)) {
2754 /* this is a hard error */
2755 spin_unlock_irqrestore(&tx_ring
->tx_lock
, irq_flags
);
2756 return NETDEV_TX_BUSY
;
2759 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
2760 tx_flags
|= IGB_TX_FLAGS_VLAN
;
2761 tx_flags
|= (vlan_tx_tag_get(skb
) << IGB_TX_FLAGS_VLAN_SHIFT
);
2764 tso
= skb_is_gso(skb
) ? igb_tso_adv(adapter
, tx_ring
, skb
, tx_flags
,
2768 dev_kfree_skb_any(skb
);
2769 spin_unlock_irqrestore(&tx_ring
->tx_lock
, irq_flags
);
2770 return NETDEV_TX_OK
;
2774 tx_flags
|= IGB_TX_FLAGS_TSO
;
2775 else if (igb_tx_csum_adv(adapter
, tx_ring
, skb
, tx_flags
))
2776 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
2777 tx_flags
|= IGB_TX_FLAGS_CSUM
;
2779 if (skb
->protocol
== htons(ETH_P_IP
))
2780 tx_flags
|= IGB_TX_FLAGS_IPV4
;
2782 igb_tx_queue_adv(adapter
, tx_ring
, tx_flags
,
2783 igb_tx_map_adv(adapter
, tx_ring
, skb
),
2786 netdev
->trans_start
= jiffies
;
2788 /* Make sure there is space in the ring for the next send. */
2789 igb_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 4);
2791 spin_unlock_irqrestore(&tx_ring
->tx_lock
, irq_flags
);
2792 return NETDEV_TX_OK
;
2795 static int igb_xmit_frame_adv(struct sk_buff
*skb
, struct net_device
*netdev
)
2797 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2798 struct igb_ring
*tx_ring
= &adapter
->tx_ring
[0];
2800 /* This goes back to the question of how to logically map a tx queue
2801 * to a flow. Right now, performance is impacted slightly negatively
2802 * if using multiple tx queues. If the stack breaks away from a
2803 * single qdisc implementation, we can look at this again. */
2804 return (igb_xmit_frame_ring_adv(skb
, netdev
, tx_ring
));
2808 * igb_tx_timeout - Respond to a Tx Hang
2809 * @netdev: network interface device structure
2811 static void igb_tx_timeout(struct net_device
*netdev
)
2813 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2814 struct e1000_hw
*hw
= &adapter
->hw
;
2816 /* Do the reset outside of interrupt context */
2817 adapter
->tx_timeout_count
++;
2818 schedule_work(&adapter
->reset_task
);
2819 wr32(E1000_EICS
, adapter
->eims_enable_mask
&
2820 ~(E1000_EIMS_TCP_TIMER
| E1000_EIMS_OTHER
));
2823 static void igb_reset_task(struct work_struct
*work
)
2825 struct igb_adapter
*adapter
;
2826 adapter
= container_of(work
, struct igb_adapter
, reset_task
);
2828 igb_reinit_locked(adapter
);
2832 * igb_get_stats - Get System Network Statistics
2833 * @netdev: network interface device structure
2835 * Returns the address of the device statistics structure.
2836 * The statistics are actually updated from the timer callback.
2838 static struct net_device_stats
*
2839 igb_get_stats(struct net_device
*netdev
)
2841 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2843 /* only return the current stats */
2844 return &adapter
->net_stats
;
2848 * igb_change_mtu - Change the Maximum Transfer Unit
2849 * @netdev: network interface device structure
2850 * @new_mtu: new value for maximum frame size
2852 * Returns 0 on success, negative on failure
2854 static int igb_change_mtu(struct net_device
*netdev
, int new_mtu
)
2856 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2857 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
2859 if ((max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
) ||
2860 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
2861 dev_err(&adapter
->pdev
->dev
, "Invalid MTU setting\n");
2865 #define MAX_STD_JUMBO_FRAME_SIZE 9234
2866 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
2867 dev_err(&adapter
->pdev
->dev
, "MTU > 9216 not supported.\n");
2871 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
2873 /* igb_down has a dependency on max_frame_size */
2874 adapter
->max_frame_size
= max_frame
;
2875 if (netif_running(netdev
))
2878 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
2879 * means we reserve 2 more, this pushes us to allocate from the next
2881 * i.e. RXBUFFER_2048 --> size-4096 slab
2884 if (max_frame
<= IGB_RXBUFFER_256
)
2885 adapter
->rx_buffer_len
= IGB_RXBUFFER_256
;
2886 else if (max_frame
<= IGB_RXBUFFER_512
)
2887 adapter
->rx_buffer_len
= IGB_RXBUFFER_512
;
2888 else if (max_frame
<= IGB_RXBUFFER_1024
)
2889 adapter
->rx_buffer_len
= IGB_RXBUFFER_1024
;
2890 else if (max_frame
<= IGB_RXBUFFER_2048
)
2891 adapter
->rx_buffer_len
= IGB_RXBUFFER_2048
;
2893 adapter
->rx_buffer_len
= IGB_RXBUFFER_4096
;
2894 /* adjust allocation if LPE protects us, and we aren't using SBP */
2895 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
2896 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
))
2897 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
2899 dev_info(&adapter
->pdev
->dev
, "changing MTU from %d to %d\n",
2900 netdev
->mtu
, new_mtu
);
2901 netdev
->mtu
= new_mtu
;
2903 if (netif_running(netdev
))
2908 clear_bit(__IGB_RESETTING
, &adapter
->state
);
2914 * igb_update_stats - Update the board statistics counters
2915 * @adapter: board private structure
2918 void igb_update_stats(struct igb_adapter
*adapter
)
2920 struct e1000_hw
*hw
= &adapter
->hw
;
2921 struct pci_dev
*pdev
= adapter
->pdev
;
2924 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
2927 * Prevent stats update while adapter is being reset, or if the pci
2928 * connection is down.
2930 if (adapter
->link_speed
== 0)
2932 if (pci_channel_offline(pdev
))
2935 adapter
->stats
.crcerrs
+= rd32(E1000_CRCERRS
);
2936 adapter
->stats
.gprc
+= rd32(E1000_GPRC
);
2937 adapter
->stats
.gorc
+= rd32(E1000_GORCL
);
2938 rd32(E1000_GORCH
); /* clear GORCL */
2939 adapter
->stats
.bprc
+= rd32(E1000_BPRC
);
2940 adapter
->stats
.mprc
+= rd32(E1000_MPRC
);
2941 adapter
->stats
.roc
+= rd32(E1000_ROC
);
2943 adapter
->stats
.prc64
+= rd32(E1000_PRC64
);
2944 adapter
->stats
.prc127
+= rd32(E1000_PRC127
);
2945 adapter
->stats
.prc255
+= rd32(E1000_PRC255
);
2946 adapter
->stats
.prc511
+= rd32(E1000_PRC511
);
2947 adapter
->stats
.prc1023
+= rd32(E1000_PRC1023
);
2948 adapter
->stats
.prc1522
+= rd32(E1000_PRC1522
);
2949 adapter
->stats
.symerrs
+= rd32(E1000_SYMERRS
);
2950 adapter
->stats
.sec
+= rd32(E1000_SEC
);
2952 adapter
->stats
.mpc
+= rd32(E1000_MPC
);
2953 adapter
->stats
.scc
+= rd32(E1000_SCC
);
2954 adapter
->stats
.ecol
+= rd32(E1000_ECOL
);
2955 adapter
->stats
.mcc
+= rd32(E1000_MCC
);
2956 adapter
->stats
.latecol
+= rd32(E1000_LATECOL
);
2957 adapter
->stats
.dc
+= rd32(E1000_DC
);
2958 adapter
->stats
.rlec
+= rd32(E1000_RLEC
);
2959 adapter
->stats
.xonrxc
+= rd32(E1000_XONRXC
);
2960 adapter
->stats
.xontxc
+= rd32(E1000_XONTXC
);
2961 adapter
->stats
.xoffrxc
+= rd32(E1000_XOFFRXC
);
2962 adapter
->stats
.xofftxc
+= rd32(E1000_XOFFTXC
);
2963 adapter
->stats
.fcruc
+= rd32(E1000_FCRUC
);
2964 adapter
->stats
.gptc
+= rd32(E1000_GPTC
);
2965 adapter
->stats
.gotc
+= rd32(E1000_GOTCL
);
2966 rd32(E1000_GOTCH
); /* clear GOTCL */
2967 adapter
->stats
.rnbc
+= rd32(E1000_RNBC
);
2968 adapter
->stats
.ruc
+= rd32(E1000_RUC
);
2969 adapter
->stats
.rfc
+= rd32(E1000_RFC
);
2970 adapter
->stats
.rjc
+= rd32(E1000_RJC
);
2971 adapter
->stats
.tor
+= rd32(E1000_TORH
);
2972 adapter
->stats
.tot
+= rd32(E1000_TOTH
);
2973 adapter
->stats
.tpr
+= rd32(E1000_TPR
);
2975 adapter
->stats
.ptc64
+= rd32(E1000_PTC64
);
2976 adapter
->stats
.ptc127
+= rd32(E1000_PTC127
);
2977 adapter
->stats
.ptc255
+= rd32(E1000_PTC255
);
2978 adapter
->stats
.ptc511
+= rd32(E1000_PTC511
);
2979 adapter
->stats
.ptc1023
+= rd32(E1000_PTC1023
);
2980 adapter
->stats
.ptc1522
+= rd32(E1000_PTC1522
);
2982 adapter
->stats
.mptc
+= rd32(E1000_MPTC
);
2983 adapter
->stats
.bptc
+= rd32(E1000_BPTC
);
2985 /* used for adaptive IFS */
2987 hw
->mac
.tx_packet_delta
= rd32(E1000_TPT
);
2988 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
2989 hw
->mac
.collision_delta
= rd32(E1000_COLC
);
2990 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
2992 adapter
->stats
.algnerrc
+= rd32(E1000_ALGNERRC
);
2993 adapter
->stats
.rxerrc
+= rd32(E1000_RXERRC
);
2994 adapter
->stats
.tncrs
+= rd32(E1000_TNCRS
);
2995 adapter
->stats
.tsctc
+= rd32(E1000_TSCTC
);
2996 adapter
->stats
.tsctfc
+= rd32(E1000_TSCTFC
);
2998 adapter
->stats
.iac
+= rd32(E1000_IAC
);
2999 adapter
->stats
.icrxoc
+= rd32(E1000_ICRXOC
);
3000 adapter
->stats
.icrxptc
+= rd32(E1000_ICRXPTC
);
3001 adapter
->stats
.icrxatc
+= rd32(E1000_ICRXATC
);
3002 adapter
->stats
.ictxptc
+= rd32(E1000_ICTXPTC
);
3003 adapter
->stats
.ictxatc
+= rd32(E1000_ICTXATC
);
3004 adapter
->stats
.ictxqec
+= rd32(E1000_ICTXQEC
);
3005 adapter
->stats
.ictxqmtc
+= rd32(E1000_ICTXQMTC
);
3006 adapter
->stats
.icrxdmtc
+= rd32(E1000_ICRXDMTC
);
3008 /* Fill out the OS statistics structure */
3009 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3010 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3014 /* RLEC on some newer hardware can be incorrect so build
3015 * our own version based on RUC and ROC */
3016 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3017 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3018 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3019 adapter
->stats
.cexterr
;
3020 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.ruc
+
3022 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3023 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3024 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3027 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3028 adapter
->stats
.latecol
;
3029 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3030 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3031 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3033 /* Tx Dropped needs to be maintained elsewhere */
3036 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
3037 if ((adapter
->link_speed
== SPEED_1000
) &&
3038 (!hw
->phy
.ops
.read_phy_reg(hw
, PHY_1000T_STATUS
,
3040 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3041 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3045 /* Management Stats */
3046 adapter
->stats
.mgptc
+= rd32(E1000_MGTPTC
);
3047 adapter
->stats
.mgprc
+= rd32(E1000_MGTPRC
);
3048 adapter
->stats
.mgpdc
+= rd32(E1000_MGTPDC
);
3052 static irqreturn_t
igb_msix_other(int irq
, void *data
)
3054 struct net_device
*netdev
= data
;
3055 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3056 struct e1000_hw
*hw
= &adapter
->hw
;
3058 /* disable interrupts from the "other" bit, avoid re-entry */
3059 wr32(E1000_EIMC
, E1000_EIMS_OTHER
);
3061 eicr
= rd32(E1000_EICR
);
3063 if (eicr
& E1000_EIMS_OTHER
) {
3064 u32 icr
= rd32(E1000_ICR
);
3065 /* reading ICR causes bit 31 of EICR to be cleared */
3066 if (!(icr
& E1000_ICR_LSC
))
3067 goto no_link_interrupt
;
3068 hw
->mac
.get_link_status
= 1;
3069 /* guard against interrupt when we're going down */
3070 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3071 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3075 wr32(E1000_IMS
, E1000_IMS_LSC
);
3076 wr32(E1000_EIMS
, E1000_EIMS_OTHER
);
3081 static irqreturn_t
igb_msix_tx(int irq
, void *data
)
3083 struct igb_ring
*tx_ring
= data
;
3084 struct igb_adapter
*adapter
= tx_ring
->adapter
;
3085 struct e1000_hw
*hw
= &adapter
->hw
;
3087 if (!tx_ring
->itr_val
)
3088 wr32(E1000_EIMC
, tx_ring
->eims_value
);
3090 tx_ring
->total_bytes
= 0;
3091 tx_ring
->total_packets
= 0;
3092 if (!igb_clean_tx_irq(adapter
, tx_ring
))
3093 /* Ring was not completely cleaned, so fire another interrupt */
3094 wr32(E1000_EICS
, tx_ring
->eims_value
);
3096 if (!tx_ring
->itr_val
)
3097 wr32(E1000_EIMS
, tx_ring
->eims_value
);
3101 static irqreturn_t
igb_msix_rx(int irq
, void *data
)
3103 struct igb_ring
*rx_ring
= data
;
3104 struct igb_adapter
*adapter
= rx_ring
->adapter
;
3105 struct e1000_hw
*hw
= &adapter
->hw
;
3107 if (!rx_ring
->itr_val
)
3108 wr32(E1000_EIMC
, rx_ring
->eims_value
);
3110 if (netif_rx_schedule_prep(adapter
->netdev
, &rx_ring
->napi
)) {
3111 rx_ring
->total_bytes
= 0;
3112 rx_ring
->total_packets
= 0;
3113 rx_ring
->no_itr_adjust
= 0;
3114 __netif_rx_schedule(adapter
->netdev
, &rx_ring
->napi
);
3116 if (!rx_ring
->no_itr_adjust
) {
3117 igb_lower_rx_eitr(adapter
, rx_ring
);
3118 rx_ring
->no_itr_adjust
= 1;
3127 * igb_intr_msi - Interrupt Handler
3128 * @irq: interrupt number
3129 * @data: pointer to a network interface device structure
3131 static irqreturn_t
igb_intr_msi(int irq
, void *data
)
3133 struct net_device
*netdev
= data
;
3134 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3135 struct napi_struct
*napi
= &adapter
->napi
;
3136 struct e1000_hw
*hw
= &adapter
->hw
;
3137 /* read ICR disables interrupts using IAM */
3138 u32 icr
= rd32(E1000_ICR
);
3140 /* Write the ITR value calculated at the end of the
3141 * previous interrupt.
3143 if (adapter
->set_itr
) {
3145 1000000000 / (adapter
->itr
* 256));
3146 adapter
->set_itr
= 0;
3149 /* read ICR disables interrupts using IAM */
3150 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
3151 hw
->mac
.get_link_status
= 1;
3152 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3153 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3156 if (netif_rx_schedule_prep(netdev
, napi
)) {
3157 adapter
->tx_ring
->total_bytes
= 0;
3158 adapter
->tx_ring
->total_packets
= 0;
3159 adapter
->rx_ring
->total_bytes
= 0;
3160 adapter
->rx_ring
->total_packets
= 0;
3161 __netif_rx_schedule(netdev
, napi
);
3168 * igb_intr - Interrupt Handler
3169 * @irq: interrupt number
3170 * @data: pointer to a network interface device structure
3172 static irqreturn_t
igb_intr(int irq
, void *data
)
3174 struct net_device
*netdev
= data
;
3175 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3176 struct napi_struct
*napi
= &adapter
->napi
;
3177 struct e1000_hw
*hw
= &adapter
->hw
;
3178 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3179 * need for the IMC write */
3180 u32 icr
= rd32(E1000_ICR
);
3183 return IRQ_NONE
; /* Not our interrupt */
3185 /* Write the ITR value calculated at the end of the
3186 * previous interrupt.
3188 if (adapter
->set_itr
) {
3190 1000000000 / (adapter
->itr
* 256));
3191 adapter
->set_itr
= 0;
3194 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3195 * not set, then the adapter didn't send an interrupt */
3196 if (!(icr
& E1000_ICR_INT_ASSERTED
))
3199 eicr
= rd32(E1000_EICR
);
3201 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
3202 hw
->mac
.get_link_status
= 1;
3203 /* guard against interrupt when we're going down */
3204 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3205 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3208 if (netif_rx_schedule_prep(netdev
, napi
)) {
3209 adapter
->tx_ring
->total_bytes
= 0;
3210 adapter
->rx_ring
->total_bytes
= 0;
3211 adapter
->tx_ring
->total_packets
= 0;
3212 adapter
->rx_ring
->total_packets
= 0;
3213 __netif_rx_schedule(netdev
, napi
);
3220 * igb_clean - NAPI Rx polling callback
3221 * @adapter: board private structure
3223 static int igb_clean(struct napi_struct
*napi
, int budget
)
3225 struct igb_adapter
*adapter
= container_of(napi
, struct igb_adapter
,
3227 struct net_device
*netdev
= adapter
->netdev
;
3228 int tx_clean_complete
= 1, work_done
= 0;
3231 /* Must NOT use netdev_priv macro here. */
3232 adapter
= netdev
->priv
;
3234 /* Keep link state information with original netdev */
3235 if (!netif_carrier_ok(netdev
))
3238 /* igb_clean is called per-cpu. This lock protects tx_ring[i] from
3239 * being cleaned by multiple cpus simultaneously. A failure obtaining
3240 * the lock means tx_ring[i] is currently being cleaned anyway. */
3241 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3242 if (spin_trylock(&adapter
->tx_ring
[i
].tx_clean_lock
)) {
3243 tx_clean_complete
&= igb_clean_tx_irq(adapter
,
3244 &adapter
->tx_ring
[i
]);
3245 spin_unlock(&adapter
->tx_ring
[i
].tx_clean_lock
);
3249 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
3250 igb_clean_rx_irq_adv(adapter
, &adapter
->rx_ring
[i
], &work_done
,
3251 adapter
->rx_ring
[i
].napi
.weight
);
3253 /* If no Tx and not enough Rx work done, exit the polling mode */
3254 if ((tx_clean_complete
&& (work_done
< budget
)) ||
3255 !netif_running(netdev
)) {
3257 if (adapter
->itr_setting
& 3)
3258 igb_set_itr(adapter
, E1000_ITR
, false);
3259 netif_rx_complete(netdev
, napi
);
3260 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3261 igb_irq_enable(adapter
);
3268 static int igb_clean_rx_ring_msix(struct napi_struct
*napi
, int budget
)
3270 struct igb_ring
*rx_ring
= container_of(napi
, struct igb_ring
, napi
);
3271 struct igb_adapter
*adapter
= rx_ring
->adapter
;
3272 struct e1000_hw
*hw
= &adapter
->hw
;
3273 struct net_device
*netdev
= adapter
->netdev
;
3276 /* Keep link state information with original netdev */
3277 if (!netif_carrier_ok(netdev
))
3280 igb_clean_rx_irq_adv(adapter
, rx_ring
, &work_done
, budget
);
3283 /* If not enough Rx work done, exit the polling mode */
3284 if ((work_done
== 0) || !netif_running(netdev
)) {
3286 netif_rx_complete(netdev
, napi
);
3288 wr32(E1000_EIMS
, rx_ring
->eims_value
);
3289 if ((adapter
->itr_setting
& 3) && !rx_ring
->no_itr_adjust
&&
3290 (rx_ring
->total_packets
> IGB_DYN_ITR_PACKET_THRESHOLD
)) {
3291 int mean_size
= rx_ring
->total_bytes
/
3292 rx_ring
->total_packets
;
3293 if (mean_size
< IGB_DYN_ITR_LENGTH_LOW
)
3294 igb_raise_rx_eitr(adapter
, rx_ring
);
3295 else if (mean_size
> IGB_DYN_ITR_LENGTH_HIGH
)
3296 igb_lower_rx_eitr(adapter
, rx_ring
);
3304 * igb_clean_tx_irq - Reclaim resources after transmit completes
3305 * @adapter: board private structure
3306 * returns true if ring is completely cleaned
3308 static bool igb_clean_tx_irq(struct igb_adapter
*adapter
,
3309 struct igb_ring
*tx_ring
)
3311 struct net_device
*netdev
= adapter
->netdev
;
3312 struct e1000_hw
*hw
= &adapter
->hw
;
3313 struct e1000_tx_desc
*tx_desc
;
3314 struct igb_buffer
*buffer_info
;
3315 struct sk_buff
*skb
;
3318 unsigned int count
= 0;
3319 bool cleaned
= false;
3321 unsigned int total_bytes
= 0, total_packets
= 0;
3324 head
= *(volatile u32
*)((struct e1000_tx_desc
*)tx_ring
->desc
3326 head
= le32_to_cpu(head
);
3327 i
= tx_ring
->next_to_clean
;
3331 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3332 buffer_info
= &tx_ring
->buffer_info
[i
];
3333 skb
= buffer_info
->skb
;
3336 unsigned int segs
, bytecount
;
3337 /* gso_segs is currently only valid for tcp */
3338 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
3339 /* multiply data chunks by size of headers */
3340 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
3342 total_packets
+= segs
;
3343 total_bytes
+= bytecount
;
3346 igb_unmap_and_free_tx_resource(adapter
, buffer_info
);
3347 tx_desc
->upper
.data
= 0;
3350 if (i
== tx_ring
->count
)
3354 if (count
== IGB_MAX_TX_CLEAN
) {
3361 head
= *(volatile u32
*)((struct e1000_tx_desc
*)tx_ring
->desc
3363 head
= le32_to_cpu(head
);
3364 if (head
== oldhead
)
3369 tx_ring
->next_to_clean
= i
;
3371 if (unlikely(cleaned
&&
3372 netif_carrier_ok(netdev
) &&
3373 IGB_DESC_UNUSED(tx_ring
) >= IGB_TX_QUEUE_WAKE
)) {
3374 /* Make sure that anybody stopping the queue after this
3375 * sees the new next_to_clean.
3378 if (netif_queue_stopped(netdev
) &&
3379 !(test_bit(__IGB_DOWN
, &adapter
->state
))) {
3380 netif_wake_queue(netdev
);
3381 ++adapter
->restart_queue
;
3385 if (tx_ring
->detect_tx_hung
) {
3386 /* Detect a transmit hang in hardware, this serializes the
3387 * check with the clearing of time_stamp and movement of i */
3388 tx_ring
->detect_tx_hung
= false;
3389 if (tx_ring
->buffer_info
[i
].time_stamp
&&
3390 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+
3391 (adapter
->tx_timeout_factor
* HZ
))
3392 && !(rd32(E1000_STATUS
) &
3393 E1000_STATUS_TXOFF
)) {
3395 tx_desc
= E1000_TX_DESC(*tx_ring
, i
);
3396 /* detected Tx unit hang */
3397 dev_err(&adapter
->pdev
->dev
,
3398 "Detected Tx Unit Hang\n"
3402 " next_to_use <%x>\n"
3403 " next_to_clean <%x>\n"
3405 "buffer_info[next_to_clean]\n"
3406 " time_stamp <%lx>\n"
3408 " desc.status <%x>\n",
3409 (unsigned long)((tx_ring
- adapter
->tx_ring
) /
3410 sizeof(struct igb_ring
)),
3411 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
3412 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
3413 tx_ring
->next_to_use
,
3414 tx_ring
->next_to_clean
,
3416 tx_ring
->buffer_info
[i
].time_stamp
,
3418 tx_desc
->upper
.fields
.status
);
3419 netif_stop_queue(netdev
);
3422 tx_ring
->total_bytes
+= total_bytes
;
3423 tx_ring
->total_packets
+= total_packets
;
3424 adapter
->net_stats
.tx_bytes
+= total_bytes
;
3425 adapter
->net_stats
.tx_packets
+= total_packets
;
3431 * igb_receive_skb - helper function to handle rx indications
3432 * @adapter: board private structure
3433 * @status: descriptor status field as written by hardware
3434 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3435 * @skb: pointer to sk_buff to be indicated to stack
3437 static void igb_receive_skb(struct igb_adapter
*adapter
, u8 status
, u16 vlan
,
3438 struct sk_buff
*skb
)
3440 if (adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
))
3441 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
3443 E1000_RXD_SPC_VLAN_MASK
);
3445 netif_receive_skb(skb
);
3449 static inline void igb_rx_checksum_adv(struct igb_adapter
*adapter
,
3450 u32 status_err
, struct sk_buff
*skb
)
3452 skb
->ip_summed
= CHECKSUM_NONE
;
3454 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
3455 if ((status_err
& E1000_RXD_STAT_IXSM
) || !adapter
->rx_csum
)
3457 /* TCP/UDP checksum error bit is set */
3459 (E1000_RXDEXT_STATERR_TCPE
| E1000_RXDEXT_STATERR_IPE
)) {
3460 /* let the stack verify checksum errors */
3461 adapter
->hw_csum_err
++;
3464 /* It must be a TCP or UDP packet with a valid checksum */
3465 if (status_err
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
))
3466 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
3468 adapter
->hw_csum_good
++;
3471 static bool igb_clean_rx_irq_adv(struct igb_adapter
*adapter
,
3472 struct igb_ring
*rx_ring
,
3473 int *work_done
, int budget
)
3475 struct net_device
*netdev
= adapter
->netdev
;
3476 struct pci_dev
*pdev
= adapter
->pdev
;
3477 union e1000_adv_rx_desc
*rx_desc
, *next_rxd
;
3478 struct igb_buffer
*buffer_info
, *next_buffer
;
3479 struct sk_buff
*skb
;
3481 u32 length
, hlen
, staterr
;
3482 bool cleaned
= false;
3483 int cleaned_count
= 0;
3484 unsigned int total_bytes
= 0, total_packets
= 0;
3486 i
= rx_ring
->next_to_clean
;
3487 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
3488 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
3490 while (staterr
& E1000_RXD_STAT_DD
) {
3491 if (*work_done
>= budget
)
3494 buffer_info
= &rx_ring
->buffer_info
[i
];
3496 /* HW will not DMA in data larger than the given buffer, even
3497 * if it parses the (NFS, of course) header to be larger. In
3498 * that case, it fills the header buffer and spills the rest
3501 hlen
= le16_to_cpu((rx_desc
->wb
.lower
.lo_dword
.hdr_info
&
3502 E1000_RXDADV_HDRBUFLEN_MASK
) >> E1000_RXDADV_HDRBUFLEN_SHIFT
);
3503 if (hlen
> adapter
->rx_ps_hdr_size
)
3504 hlen
= adapter
->rx_ps_hdr_size
;
3506 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
3510 if (rx_ring
->pending_skb
!= NULL
) {
3511 skb
= rx_ring
->pending_skb
;
3512 rx_ring
->pending_skb
= NULL
;
3513 j
= rx_ring
->pending_skb_page
;
3515 skb
= buffer_info
->skb
;
3516 prefetch(skb
->data
- NET_IP_ALIGN
);
3517 buffer_info
->skb
= NULL
;
3519 pci_unmap_single(pdev
, buffer_info
->dma
,
3520 adapter
->rx_ps_hdr_size
+
3522 PCI_DMA_FROMDEVICE
);
3525 pci_unmap_single(pdev
, buffer_info
->dma
,
3526 adapter
->rx_buffer_len
+
3528 PCI_DMA_FROMDEVICE
);
3529 skb_put(skb
, length
);
3536 pci_unmap_page(pdev
, buffer_info
->page_dma
,
3537 PAGE_SIZE
, PCI_DMA_FROMDEVICE
);
3538 buffer_info
->page_dma
= 0;
3539 skb_fill_page_desc(skb
, j
, buffer_info
->page
,
3541 buffer_info
->page
= NULL
;
3544 skb
->data_len
+= length
;
3545 skb
->truesize
+= length
;
3546 rx_desc
->wb
.upper
.status_error
= 0;
3547 if (staterr
& E1000_RXD_STAT_EOP
)
3553 if (i
== rx_ring
->count
)
3556 buffer_info
= &rx_ring
->buffer_info
[i
];
3557 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
3558 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
3559 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
3560 if (!(staterr
& E1000_RXD_STAT_DD
)) {
3561 rx_ring
->pending_skb
= skb
;
3562 rx_ring
->pending_skb_page
= j
;
3567 pskb_trim(skb
, skb
->len
- 4);
3569 if (i
== rx_ring
->count
)
3571 next_rxd
= E1000_RX_DESC_ADV(*rx_ring
, i
);
3573 next_buffer
= &rx_ring
->buffer_info
[i
];
3575 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
3576 dev_kfree_skb_irq(skb
);
3579 rx_ring
->no_itr_adjust
|= (staterr
& E1000_RXD_STAT_DYNINT
);
3581 total_bytes
+= skb
->len
;
3584 igb_rx_checksum_adv(adapter
, staterr
, skb
);
3586 skb
->protocol
= eth_type_trans(skb
, netdev
);
3588 igb_receive_skb(adapter
, staterr
, rx_desc
->wb
.upper
.vlan
, skb
);
3590 netdev
->last_rx
= jiffies
;
3593 rx_desc
->wb
.upper
.status_error
= 0;
3595 /* return some buffers to hardware, one at a time is too slow */
3596 if (cleaned_count
>= IGB_RX_BUFFER_WRITE
) {
3597 igb_alloc_rx_buffers_adv(adapter
, rx_ring
,
3602 /* use prefetched values */
3604 buffer_info
= next_buffer
;
3606 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
3609 rx_ring
->next_to_clean
= i
;
3610 cleaned_count
= IGB_DESC_UNUSED(rx_ring
);
3613 igb_alloc_rx_buffers_adv(adapter
, rx_ring
, cleaned_count
);
3615 rx_ring
->total_packets
+= total_packets
;
3616 rx_ring
->total_bytes
+= total_bytes
;
3617 rx_ring
->rx_stats
.packets
+= total_packets
;
3618 rx_ring
->rx_stats
.bytes
+= total_bytes
;
3619 adapter
->net_stats
.rx_bytes
+= total_bytes
;
3620 adapter
->net_stats
.rx_packets
+= total_packets
;
3626 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
3627 * @adapter: address of board private structure
3629 static void igb_alloc_rx_buffers_adv(struct igb_adapter
*adapter
,
3630 struct igb_ring
*rx_ring
,
3633 struct net_device
*netdev
= adapter
->netdev
;
3634 struct pci_dev
*pdev
= adapter
->pdev
;
3635 union e1000_adv_rx_desc
*rx_desc
;
3636 struct igb_buffer
*buffer_info
;
3637 struct sk_buff
*skb
;
3640 i
= rx_ring
->next_to_use
;
3641 buffer_info
= &rx_ring
->buffer_info
[i
];
3643 while (cleaned_count
--) {
3644 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
3646 if (adapter
->rx_ps_hdr_size
&& !buffer_info
->page
) {
3647 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
3648 if (!buffer_info
->page
) {
3649 adapter
->alloc_rx_buff_failed
++;
3652 buffer_info
->page_dma
=
3656 PCI_DMA_FROMDEVICE
);
3659 if (!buffer_info
->skb
) {
3662 if (adapter
->rx_ps_hdr_size
)
3663 bufsz
= adapter
->rx_ps_hdr_size
;
3665 bufsz
= adapter
->rx_buffer_len
;
3666 bufsz
+= NET_IP_ALIGN
;
3667 skb
= netdev_alloc_skb(netdev
, bufsz
);
3670 adapter
->alloc_rx_buff_failed
++;
3674 /* Make buffer alignment 2 beyond a 16 byte boundary
3675 * this will result in a 16 byte aligned IP header after
3676 * the 14 byte MAC header is removed
3678 skb_reserve(skb
, NET_IP_ALIGN
);
3680 buffer_info
->skb
= skb
;
3681 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
3683 PCI_DMA_FROMDEVICE
);
3686 /* Refresh the desc even if buffer_addrs didn't change because
3687 * each write-back erases this info. */
3688 if (adapter
->rx_ps_hdr_size
) {
3689 rx_desc
->read
.pkt_addr
=
3690 cpu_to_le64(buffer_info
->page_dma
);
3691 rx_desc
->read
.hdr_addr
= cpu_to_le64(buffer_info
->dma
);
3693 rx_desc
->read
.pkt_addr
=
3694 cpu_to_le64(buffer_info
->dma
);
3695 rx_desc
->read
.hdr_addr
= 0;
3699 if (i
== rx_ring
->count
)
3701 buffer_info
= &rx_ring
->buffer_info
[i
];
3705 if (rx_ring
->next_to_use
!= i
) {
3706 rx_ring
->next_to_use
= i
;
3708 i
= (rx_ring
->count
- 1);
3712 /* Force memory writes to complete before letting h/w
3713 * know there are new descriptors to fetch. (Only
3714 * applicable for weak-ordered memory model archs,
3715 * such as IA-64). */
3717 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
3727 static int igb_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
3729 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3730 struct mii_ioctl_data
*data
= if_mii(ifr
);
3732 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
3737 data
->phy_id
= adapter
->hw
.phy
.addr
;
3740 if (!capable(CAP_NET_ADMIN
))
3742 if (adapter
->hw
.phy
.ops
.read_phy_reg(&adapter
->hw
,
3744 & 0x1F, &data
->val_out
))
3760 static int igb_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
3766 return igb_mii_ioctl(netdev
, ifr
, cmd
);
3772 static void igb_vlan_rx_register(struct net_device
*netdev
,
3773 struct vlan_group
*grp
)
3775 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3776 struct e1000_hw
*hw
= &adapter
->hw
;
3779 igb_irq_disable(adapter
);
3780 adapter
->vlgrp
= grp
;
3783 /* enable VLAN tag insert/strip */
3784 ctrl
= rd32(E1000_CTRL
);
3785 ctrl
|= E1000_CTRL_VME
;
3786 wr32(E1000_CTRL
, ctrl
);
3788 /* enable VLAN receive filtering */
3789 rctl
= rd32(E1000_RCTL
);
3790 rctl
|= E1000_RCTL_VFE
;
3791 rctl
&= ~E1000_RCTL_CFIEN
;
3792 wr32(E1000_RCTL
, rctl
);
3793 igb_update_mng_vlan(adapter
);
3795 adapter
->max_frame_size
+ VLAN_TAG_SIZE
);
3797 /* disable VLAN tag insert/strip */
3798 ctrl
= rd32(E1000_CTRL
);
3799 ctrl
&= ~E1000_CTRL_VME
;
3800 wr32(E1000_CTRL
, ctrl
);
3802 /* disable VLAN filtering */
3803 rctl
= rd32(E1000_RCTL
);
3804 rctl
&= ~E1000_RCTL_VFE
;
3805 wr32(E1000_RCTL
, rctl
);
3806 if (adapter
->mng_vlan_id
!= (u16
)IGB_MNG_VLAN_NONE
) {
3807 igb_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
3808 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
3811 adapter
->max_frame_size
);
3814 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3815 igb_irq_enable(adapter
);
3818 static void igb_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
3820 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3821 struct e1000_hw
*hw
= &adapter
->hw
;
3824 if ((adapter
->hw
.mng_cookie
.status
&
3825 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
3826 (vid
== adapter
->mng_vlan_id
))
3828 /* add VID to filter table */
3829 index
= (vid
>> 5) & 0x7F;
3830 vfta
= array_rd32(E1000_VFTA
, index
);
3831 vfta
|= (1 << (vid
& 0x1F));
3832 igb_write_vfta(&adapter
->hw
, index
, vfta
);
3835 static void igb_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
3837 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3838 struct e1000_hw
*hw
= &adapter
->hw
;
3841 igb_irq_disable(adapter
);
3842 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
3844 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3845 igb_irq_enable(adapter
);
3847 if ((adapter
->hw
.mng_cookie
.status
&
3848 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
3849 (vid
== adapter
->mng_vlan_id
)) {
3850 /* release control to f/w */
3851 igb_release_hw_control(adapter
);
3855 /* remove VID from filter table */
3856 index
= (vid
>> 5) & 0x7F;
3857 vfta
= array_rd32(E1000_VFTA
, index
);
3858 vfta
&= ~(1 << (vid
& 0x1F));
3859 igb_write_vfta(&adapter
->hw
, index
, vfta
);
3862 static void igb_restore_vlan(struct igb_adapter
*adapter
)
3864 igb_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
3866 if (adapter
->vlgrp
) {
3868 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
3869 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
3871 igb_vlan_rx_add_vid(adapter
->netdev
, vid
);
3876 int igb_set_spd_dplx(struct igb_adapter
*adapter
, u16 spddplx
)
3878 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
3882 /* Fiber NICs only allow 1000 gbps Full duplex */
3883 if ((adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
) &&
3884 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
3885 dev_err(&adapter
->pdev
->dev
,
3886 "Unsupported Speed/Duplex configuration\n");
3891 case SPEED_10
+ DUPLEX_HALF
:
3892 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
3894 case SPEED_10
+ DUPLEX_FULL
:
3895 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
3897 case SPEED_100
+ DUPLEX_HALF
:
3898 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
3900 case SPEED_100
+ DUPLEX_FULL
:
3901 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
3903 case SPEED_1000
+ DUPLEX_FULL
:
3905 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
3907 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
3909 dev_err(&adapter
->pdev
->dev
,
3910 "Unsupported Speed/Duplex configuration\n");
3917 static int igb_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3919 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3920 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3921 struct e1000_hw
*hw
= &adapter
->hw
;
3922 u32 ctrl
, ctrl_ext
, rctl
, status
;
3923 u32 wufc
= adapter
->wol
;
3928 netif_device_detach(netdev
);
3930 if (netif_running(netdev
)) {
3931 WARN_ON(test_bit(__IGB_RESETTING
, &adapter
->state
));
3933 igb_free_irq(adapter
);
3937 retval
= pci_save_state(pdev
);
3942 status
= rd32(E1000_STATUS
);
3943 if (status
& E1000_STATUS_LU
)
3944 wufc
&= ~E1000_WUFC_LNKC
;
3947 igb_setup_rctl(adapter
);
3948 igb_set_multi(netdev
);
3950 /* turn on all-multi mode if wake on multicast is enabled */
3951 if (wufc
& E1000_WUFC_MC
) {
3952 rctl
= rd32(E1000_RCTL
);
3953 rctl
|= E1000_RCTL_MPE
;
3954 wr32(E1000_RCTL
, rctl
);
3957 ctrl
= rd32(E1000_CTRL
);
3958 /* advertise wake from D3Cold */
3959 #define E1000_CTRL_ADVD3WUC 0x00100000
3960 /* phy power management enable */
3961 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
3962 ctrl
|= E1000_CTRL_ADVD3WUC
;
3963 wr32(E1000_CTRL
, ctrl
);
3965 if (adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
||
3966 adapter
->hw
.phy
.media_type
==
3967 e1000_media_type_internal_serdes
) {
3968 /* keep the laser running in D3 */
3969 ctrl_ext
= rd32(E1000_CTRL_EXT
);
3970 ctrl_ext
|= E1000_CTRL_EXT_SDP7_DATA
;
3971 wr32(E1000_CTRL_EXT
, ctrl_ext
);
3974 /* Allow time for pending master requests to run */
3975 igb_disable_pcie_master(&adapter
->hw
);
3977 wr32(E1000_WUC
, E1000_WUC_PME_EN
);
3978 wr32(E1000_WUFC
, wufc
);
3979 pci_enable_wake(pdev
, PCI_D3hot
, 1);
3980 pci_enable_wake(pdev
, PCI_D3cold
, 1);
3983 wr32(E1000_WUFC
, 0);
3984 pci_enable_wake(pdev
, PCI_D3hot
, 0);
3985 pci_enable_wake(pdev
, PCI_D3cold
, 0);
3988 <<<<<<< HEAD
:drivers
/net
/igb
/igb_main
.c
3989 igb_release_manageability(adapter
);
3992 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/net
/igb
/igb_main
.c
3993 /* make sure adapter isn't asleep if manageability is enabled */
3994 if (adapter
->en_mng_pt
) {
3995 pci_enable_wake(pdev
, PCI_D3hot
, 1);
3996 pci_enable_wake(pdev
, PCI_D3cold
, 1);
3999 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4000 * would have already happened in close and is redundant. */
4001 igb_release_hw_control(adapter
);
4003 pci_disable_device(pdev
);
4005 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
4011 static int igb_resume(struct pci_dev
*pdev
)
4013 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4014 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4015 struct e1000_hw
*hw
= &adapter
->hw
;
4018 pci_set_power_state(pdev
, PCI_D0
);
4019 pci_restore_state(pdev
);
4020 err
= pci_enable_device(pdev
);
4023 "igb: Cannot enable PCI device from suspend\n");
4026 pci_set_master(pdev
);
4028 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4029 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4031 if (netif_running(netdev
)) {
4032 err
= igb_request_irq(adapter
);
4037 /* e1000_power_up_phy(adapter); */
4040 wr32(E1000_WUS
, ~0);
4042 igb_init_manageability(adapter
);
4044 if (netif_running(netdev
))
4047 netif_device_attach(netdev
);
4049 /* let the f/w know that the h/w is now under the control of the
4051 igb_get_hw_control(adapter
);
4057 static void igb_shutdown(struct pci_dev
*pdev
)
4059 igb_suspend(pdev
, PMSG_SUSPEND
);
4062 #ifdef CONFIG_NET_POLL_CONTROLLER
4064 * Polling 'interrupt' - used by things like netconsole to send skbs
4065 * without having to re-enable interrupts. It's not called while
4066 * the interrupt routine is executing.
4068 static void igb_netpoll(struct net_device
*netdev
)
4070 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4074 igb_irq_disable(adapter
);
4075 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
4076 igb_clean_tx_irq(adapter
, &adapter
->tx_ring
[i
]);
4078 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
4079 igb_clean_rx_irq_adv(adapter
, &adapter
->rx_ring
[i
],
4081 adapter
->rx_ring
[i
].napi
.weight
);
4083 igb_irq_enable(adapter
);
4085 #endif /* CONFIG_NET_POLL_CONTROLLER */
4088 * igb_io_error_detected - called when PCI error is detected
4089 * @pdev: Pointer to PCI device
4090 * @state: The current pci connection state
4092 * This function is called after a PCI bus error affecting
4093 * this device has been detected.
4095 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*pdev
,
4096 pci_channel_state_t state
)
4098 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4099 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4101 netif_device_detach(netdev
);
4103 if (netif_running(netdev
))
4105 pci_disable_device(pdev
);
4107 /* Request a slot slot reset. */
4108 return PCI_ERS_RESULT_NEED_RESET
;
4112 * igb_io_slot_reset - called after the pci bus has been reset.
4113 * @pdev: Pointer to PCI device
4115 * Restart the card from scratch, as if from a cold-boot. Implementation
4116 * resembles the first-half of the igb_resume routine.
4118 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*pdev
)
4120 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4121 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4122 struct e1000_hw
*hw
= &adapter
->hw
;
4124 if (pci_enable_device(pdev
)) {
4126 "Cannot re-enable PCI device after reset.\n");
4127 return PCI_ERS_RESULT_DISCONNECT
;
4129 pci_set_master(pdev
);
4131 pci_enable_wake(pdev
, PCI_D3hot
, 0);
4132 pci_enable_wake(pdev
, PCI_D3cold
, 0);
4135 wr32(E1000_WUS
, ~0);
4137 return PCI_ERS_RESULT_RECOVERED
;
4141 * igb_io_resume - called when traffic can start flowing again.
4142 * @pdev: Pointer to PCI device
4144 * This callback is called when the error recovery driver tells us that
4145 * its OK to resume normal operation. Implementation resembles the
4146 * second-half of the igb_resume routine.
4148 static void igb_io_resume(struct pci_dev
*pdev
)
4150 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4151 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4153 igb_init_manageability(adapter
);
4155 if (netif_running(netdev
)) {
4156 if (igb_up(adapter
)) {
4157 dev_err(&pdev
->dev
, "igb_up failed after reset\n");
4162 netif_device_attach(netdev
);
4164 /* let the f/w know that the h/w is now under the control of the
4166 igb_get_hw_control(adapter
);