1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2009 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/ipv6.h>
35 #include <net/checksum.h>
36 #include <net/ip6_checksum.h>
37 #include <linux/net_tstamp.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/pci-aspm.h>
43 #include <linux/delay.h>
44 #include <linux/interrupt.h>
45 #include <linux/if_ether.h>
46 #include <linux/aer.h>
48 #include <linux/dca.h>
52 #define DRV_VERSION "1.3.16-k2"
53 char igb_driver_name
[] = "igb";
54 char igb_driver_version
[] = DRV_VERSION
;
55 static const char igb_driver_string
[] =
56 "Intel(R) Gigabit Ethernet Network Driver";
57 static const char igb_copyright
[] = "Copyright (c) 2007-2009 Intel Corporation.";
59 static const struct e1000_info
*igb_info_tbl
[] = {
60 [board_82575
] = &e1000_82575_info
,
63 static struct pci_device_id igb_pci_tbl
[] = {
64 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82576
), board_82575
},
65 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82576_NS
), board_82575
},
66 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82576_FIBER
), board_82575
},
67 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82576_SERDES
), board_82575
},
68 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82576_QUAD_COPPER
), board_82575
},
69 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82575EB_COPPER
), board_82575
},
70 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82575EB_FIBER_SERDES
), board_82575
},
71 { PCI_VDEVICE(INTEL
, E1000_DEV_ID_82575GB_QUAD_COPPER
), board_82575
},
72 /* required last entry */
76 MODULE_DEVICE_TABLE(pci
, igb_pci_tbl
);
78 void igb_reset(struct igb_adapter
*);
79 static int igb_setup_all_tx_resources(struct igb_adapter
*);
80 static int igb_setup_all_rx_resources(struct igb_adapter
*);
81 static void igb_free_all_tx_resources(struct igb_adapter
*);
82 static void igb_free_all_rx_resources(struct igb_adapter
*);
83 void igb_update_stats(struct igb_adapter
*);
84 static int igb_probe(struct pci_dev
*, const struct pci_device_id
*);
85 static void __devexit
igb_remove(struct pci_dev
*pdev
);
86 static int igb_sw_init(struct igb_adapter
*);
87 static int igb_open(struct net_device
*);
88 static int igb_close(struct net_device
*);
89 static void igb_configure_tx(struct igb_adapter
*);
90 static void igb_configure_rx(struct igb_adapter
*);
91 static void igb_setup_rctl(struct igb_adapter
*);
92 static void igb_clean_all_tx_rings(struct igb_adapter
*);
93 static void igb_clean_all_rx_rings(struct igb_adapter
*);
94 static void igb_clean_tx_ring(struct igb_ring
*);
95 static void igb_clean_rx_ring(struct igb_ring
*);
96 static void igb_set_multi(struct net_device
*);
97 static void igb_update_phy_info(unsigned long);
98 static void igb_watchdog(unsigned long);
99 static void igb_watchdog_task(struct work_struct
*);
100 static int igb_xmit_frame_ring_adv(struct sk_buff
*, struct net_device
*,
102 static int igb_xmit_frame_adv(struct sk_buff
*skb
, struct net_device
*);
103 static struct net_device_stats
*igb_get_stats(struct net_device
*);
104 static int igb_change_mtu(struct net_device
*, int);
105 static int igb_set_mac(struct net_device
*, void *);
106 static irqreturn_t
igb_intr(int irq
, void *);
107 static irqreturn_t
igb_intr_msi(int irq
, void *);
108 static irqreturn_t
igb_msix_other(int irq
, void *);
109 static irqreturn_t
igb_msix_rx(int irq
, void *);
110 static irqreturn_t
igb_msix_tx(int irq
, void *);
111 #ifdef CONFIG_IGB_DCA
112 static void igb_update_rx_dca(struct igb_ring
*);
113 static void igb_update_tx_dca(struct igb_ring
*);
114 static void igb_setup_dca(struct igb_adapter
*);
115 #endif /* CONFIG_IGB_DCA */
116 static bool igb_clean_tx_irq(struct igb_ring
*);
117 static int igb_poll(struct napi_struct
*, int);
118 static bool igb_clean_rx_irq_adv(struct igb_ring
*, int *, int);
119 static void igb_alloc_rx_buffers_adv(struct igb_ring
*, int);
120 static int igb_ioctl(struct net_device
*, struct ifreq
*, int cmd
);
121 static void igb_tx_timeout(struct net_device
*);
122 static void igb_reset_task(struct work_struct
*);
123 static void igb_vlan_rx_register(struct net_device
*, struct vlan_group
*);
124 static void igb_vlan_rx_add_vid(struct net_device
*, u16
);
125 static void igb_vlan_rx_kill_vid(struct net_device
*, u16
);
126 static void igb_restore_vlan(struct igb_adapter
*);
127 static void igb_ping_all_vfs(struct igb_adapter
*);
128 static void igb_msg_task(struct igb_adapter
*);
129 static int igb_rcv_msg_from_vf(struct igb_adapter
*, u32
);
130 static inline void igb_set_rah_pool(struct e1000_hw
*, int , int);
131 static void igb_set_mc_list_pools(struct igb_adapter
*, int, u16
);
132 static void igb_vmm_control(struct igb_adapter
*);
133 static inline void igb_set_vmolr(struct e1000_hw
*, int);
134 static inline int igb_set_vf_rlpml(struct igb_adapter
*, int, int);
135 static int igb_set_vf_mac(struct igb_adapter
*adapter
, int, unsigned char *);
136 static void igb_restore_vf_multicasts(struct igb_adapter
*adapter
);
139 static int igb_suspend(struct pci_dev
*, pm_message_t
);
140 static int igb_resume(struct pci_dev
*);
142 static void igb_shutdown(struct pci_dev
*);
143 #ifdef CONFIG_IGB_DCA
144 static int igb_notify_dca(struct notifier_block
*, unsigned long, void *);
145 static struct notifier_block dca_notifier
= {
146 .notifier_call
= igb_notify_dca
,
151 #ifdef CONFIG_NET_POLL_CONTROLLER
152 /* for netdump / net console */
153 static void igb_netpoll(struct net_device
*);
155 #ifdef CONFIG_PCI_IOV
156 static unsigned int max_vfs
= 0;
157 module_param(max_vfs
, uint
, 0);
158 MODULE_PARM_DESC(max_vfs
, "Maximum number of virtual functions to allocate "
159 "per physical function");
160 #endif /* CONFIG_PCI_IOV */
162 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*,
163 pci_channel_state_t
);
164 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*);
165 static void igb_io_resume(struct pci_dev
*);
167 static struct pci_error_handlers igb_err_handler
= {
168 .error_detected
= igb_io_error_detected
,
169 .slot_reset
= igb_io_slot_reset
,
170 .resume
= igb_io_resume
,
174 static struct pci_driver igb_driver
= {
175 .name
= igb_driver_name
,
176 .id_table
= igb_pci_tbl
,
178 .remove
= __devexit_p(igb_remove
),
180 /* Power Managment Hooks */
181 .suspend
= igb_suspend
,
182 .resume
= igb_resume
,
184 .shutdown
= igb_shutdown
,
185 .err_handler
= &igb_err_handler
188 static int global_quad_port_a
; /* global quad port a indication */
190 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
191 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
192 MODULE_LICENSE("GPL");
193 MODULE_VERSION(DRV_VERSION
);
196 * Scale the NIC clock cycle by a large factor so that
197 * relatively small clock corrections can be added or
198 * substracted at each clock tick. The drawbacks of a
199 * large factor are a) that the clock register overflows
200 * more quickly (not such a big deal) and b) that the
201 * increment per tick has to fit into 24 bits.
204 * TIMINCA = IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS *
206 * TIMINCA += TIMINCA * adjustment [ppm] / 1e9
208 * The base scale factor is intentionally a power of two
209 * so that the division in %struct timecounter can be done with
212 #define IGB_TSYNC_SHIFT (19)
213 #define IGB_TSYNC_SCALE (1<<IGB_TSYNC_SHIFT)
216 * The duration of one clock cycle of the NIC.
218 * @todo This hard-coded value is part of the specification and might change
219 * in future hardware revisions. Add revision check.
221 #define IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS 16
223 #if (IGB_TSYNC_SCALE * IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS) >= (1<<24)
224 # error IGB_TSYNC_SCALE and/or IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS are too large to fit into TIMINCA
228 * igb_read_clock - read raw cycle counter (to be used by time counter)
230 static cycle_t
igb_read_clock(const struct cyclecounter
*tc
)
232 struct igb_adapter
*adapter
=
233 container_of(tc
, struct igb_adapter
, cycles
);
234 struct e1000_hw
*hw
= &adapter
->hw
;
237 stamp
= rd32(E1000_SYSTIML
);
238 stamp
|= (u64
)rd32(E1000_SYSTIMH
) << 32ULL;
245 * igb_get_hw_dev_name - return device name string
246 * used by hardware layer to print debugging information
248 char *igb_get_hw_dev_name(struct e1000_hw
*hw
)
250 struct igb_adapter
*adapter
= hw
->back
;
251 return adapter
->netdev
->name
;
255 * igb_get_time_str - format current NIC and system time as string
257 static char *igb_get_time_str(struct igb_adapter
*adapter
,
260 cycle_t hw
= adapter
->cycles
.read(&adapter
->cycles
);
261 struct timespec nic
= ns_to_timespec(timecounter_read(&adapter
->clock
));
263 struct timespec delta
;
264 getnstimeofday(&sys
);
266 delta
= timespec_sub(nic
, sys
);
269 "HW %llu, NIC %ld.%09lus, SYS %ld.%09lus, NIC-SYS %lds + %09luns",
271 (long)nic
.tv_sec
, nic
.tv_nsec
,
272 (long)sys
.tv_sec
, sys
.tv_nsec
,
273 (long)delta
.tv_sec
, delta
.tv_nsec
);
280 * igb_desc_unused - calculate if we have unused descriptors
282 static int igb_desc_unused(struct igb_ring
*ring
)
284 if (ring
->next_to_clean
> ring
->next_to_use
)
285 return ring
->next_to_clean
- ring
->next_to_use
- 1;
287 return ring
->count
+ ring
->next_to_clean
- ring
->next_to_use
- 1;
291 * igb_init_module - Driver Registration Routine
293 * igb_init_module is the first routine called when the driver is
294 * loaded. All it does is register with the PCI subsystem.
296 static int __init
igb_init_module(void)
299 printk(KERN_INFO
"%s - version %s\n",
300 igb_driver_string
, igb_driver_version
);
302 printk(KERN_INFO
"%s\n", igb_copyright
);
304 global_quad_port_a
= 0;
306 #ifdef CONFIG_IGB_DCA
307 dca_register_notify(&dca_notifier
);
310 ret
= pci_register_driver(&igb_driver
);
314 module_init(igb_init_module
);
317 * igb_exit_module - Driver Exit Cleanup Routine
319 * igb_exit_module is called just before the driver is removed
322 static void __exit
igb_exit_module(void)
324 #ifdef CONFIG_IGB_DCA
325 dca_unregister_notify(&dca_notifier
);
327 pci_unregister_driver(&igb_driver
);
330 module_exit(igb_exit_module
);
332 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
334 * igb_cache_ring_register - Descriptor ring to register mapping
335 * @adapter: board private structure to initialize
337 * Once we know the feature-set enabled for the device, we'll cache
338 * the register offset the descriptor ring is assigned to.
340 static void igb_cache_ring_register(struct igb_adapter
*adapter
)
343 unsigned int rbase_offset
= adapter
->vfs_allocated_count
;
345 switch (adapter
->hw
.mac
.type
) {
347 /* The queues are allocated for virtualization such that VF 0
348 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
349 * In order to avoid collision we start at the first free queue
350 * and continue consuming queues in the same sequence
352 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
353 adapter
->rx_ring
[i
].reg_idx
= rbase_offset
+
355 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
356 adapter
->tx_ring
[i
].reg_idx
= rbase_offset
+
361 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
362 adapter
->rx_ring
[i
].reg_idx
= i
;
363 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
364 adapter
->tx_ring
[i
].reg_idx
= i
;
370 * igb_alloc_queues - Allocate memory for all rings
371 * @adapter: board private structure to initialize
373 * We allocate one ring per queue at run-time since we don't know the
374 * number of queues at compile-time.
376 static int igb_alloc_queues(struct igb_adapter
*adapter
)
380 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
381 sizeof(struct igb_ring
), GFP_KERNEL
);
382 if (!adapter
->tx_ring
)
385 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
386 sizeof(struct igb_ring
), GFP_KERNEL
);
387 if (!adapter
->rx_ring
) {
388 kfree(adapter
->tx_ring
);
392 adapter
->rx_ring
->buddy
= adapter
->tx_ring
;
394 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
395 struct igb_ring
*ring
= &(adapter
->tx_ring
[i
]);
396 ring
->count
= adapter
->tx_ring_count
;
397 ring
->adapter
= adapter
;
398 ring
->queue_index
= i
;
400 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
401 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
402 ring
->count
= adapter
->rx_ring_count
;
403 ring
->adapter
= adapter
;
404 ring
->queue_index
= i
;
405 ring
->itr_register
= E1000_ITR
;
407 /* set a default napi handler for each rx_ring */
408 netif_napi_add(adapter
->netdev
, &ring
->napi
, igb_poll
, 64);
411 igb_cache_ring_register(adapter
);
415 static void igb_free_queues(struct igb_adapter
*adapter
)
419 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
420 netif_napi_del(&adapter
->rx_ring
[i
].napi
);
422 adapter
->num_rx_queues
= 0;
423 adapter
->num_tx_queues
= 0;
425 kfree(adapter
->tx_ring
);
426 kfree(adapter
->rx_ring
);
429 #define IGB_N0_QUEUE -1
430 static void igb_assign_vector(struct igb_adapter
*adapter
, int rx_queue
,
431 int tx_queue
, int msix_vector
)
434 struct e1000_hw
*hw
= &adapter
->hw
;
437 switch (hw
->mac
.type
) {
439 /* The 82575 assigns vectors using a bitmask, which matches the
440 bitmask for the EICR/EIMS/EIMC registers. To assign one
441 or more queues to a vector, we write the appropriate bits
442 into the MSIXBM register for that vector. */
443 if (rx_queue
> IGB_N0_QUEUE
) {
444 msixbm
= E1000_EICR_RX_QUEUE0
<< rx_queue
;
445 adapter
->rx_ring
[rx_queue
].eims_value
= msixbm
;
447 if (tx_queue
> IGB_N0_QUEUE
) {
448 msixbm
|= E1000_EICR_TX_QUEUE0
<< tx_queue
;
449 adapter
->tx_ring
[tx_queue
].eims_value
=
450 E1000_EICR_TX_QUEUE0
<< tx_queue
;
452 array_wr32(E1000_MSIXBM(0), msix_vector
, msixbm
);
455 /* 82576 uses a table-based method for assigning vectors.
456 Each queue has a single entry in the table to which we write
457 a vector number along with a "valid" bit. Sadly, the layout
458 of the table is somewhat counterintuitive. */
459 if (rx_queue
> IGB_N0_QUEUE
) {
460 index
= (rx_queue
>> 1) + adapter
->vfs_allocated_count
;
461 ivar
= array_rd32(E1000_IVAR0
, index
);
462 if (rx_queue
& 0x1) {
463 /* vector goes into third byte of register */
464 ivar
= ivar
& 0xFF00FFFF;
465 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << 16;
467 /* vector goes into low byte of register */
468 ivar
= ivar
& 0xFFFFFF00;
469 ivar
|= msix_vector
| E1000_IVAR_VALID
;
471 adapter
->rx_ring
[rx_queue
].eims_value
= 1 << msix_vector
;
472 array_wr32(E1000_IVAR0
, index
, ivar
);
474 if (tx_queue
> IGB_N0_QUEUE
) {
475 index
= (tx_queue
>> 1) + adapter
->vfs_allocated_count
;
476 ivar
= array_rd32(E1000_IVAR0
, index
);
477 if (tx_queue
& 0x1) {
478 /* vector goes into high byte of register */
479 ivar
= ivar
& 0x00FFFFFF;
480 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << 24;
482 /* vector goes into second byte of register */
483 ivar
= ivar
& 0xFFFF00FF;
484 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << 8;
486 adapter
->tx_ring
[tx_queue
].eims_value
= 1 << msix_vector
;
487 array_wr32(E1000_IVAR0
, index
, ivar
);
497 * igb_configure_msix - Configure MSI-X hardware
499 * igb_configure_msix sets up the hardware to properly
500 * generate MSI-X interrupts.
502 static void igb_configure_msix(struct igb_adapter
*adapter
)
506 struct e1000_hw
*hw
= &adapter
->hw
;
508 adapter
->eims_enable_mask
= 0;
509 if (hw
->mac
.type
== e1000_82576
)
510 /* Turn on MSI-X capability first, or our settings
511 * won't stick. And it will take days to debug. */
512 wr32(E1000_GPIE
, E1000_GPIE_MSIX_MODE
|
513 E1000_GPIE_PBA
| E1000_GPIE_EIAME
|
516 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
517 struct igb_ring
*tx_ring
= &adapter
->tx_ring
[i
];
518 igb_assign_vector(adapter
, IGB_N0_QUEUE
, i
, vector
++);
519 adapter
->eims_enable_mask
|= tx_ring
->eims_value
;
520 if (tx_ring
->itr_val
)
521 writel(tx_ring
->itr_val
,
522 hw
->hw_addr
+ tx_ring
->itr_register
);
524 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
527 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
528 struct igb_ring
*rx_ring
= &adapter
->rx_ring
[i
];
529 rx_ring
->buddy
= NULL
;
530 igb_assign_vector(adapter
, i
, IGB_N0_QUEUE
, vector
++);
531 adapter
->eims_enable_mask
|= rx_ring
->eims_value
;
532 if (rx_ring
->itr_val
)
533 writel(rx_ring
->itr_val
,
534 hw
->hw_addr
+ rx_ring
->itr_register
);
536 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
540 /* set vector for other causes, i.e. link changes */
541 switch (hw
->mac
.type
) {
543 array_wr32(E1000_MSIXBM(0), vector
++,
546 tmp
= rd32(E1000_CTRL_EXT
);
547 /* enable MSI-X PBA support*/
548 tmp
|= E1000_CTRL_EXT_PBA_CLR
;
550 /* Auto-Mask interrupts upon ICR read. */
551 tmp
|= E1000_CTRL_EXT_EIAME
;
552 tmp
|= E1000_CTRL_EXT_IRCA
;
554 wr32(E1000_CTRL_EXT
, tmp
);
555 adapter
->eims_enable_mask
|= E1000_EIMS_OTHER
;
556 adapter
->eims_other
= E1000_EIMS_OTHER
;
561 tmp
= (vector
++ | E1000_IVAR_VALID
) << 8;
562 wr32(E1000_IVAR_MISC
, tmp
);
564 adapter
->eims_enable_mask
= (1 << (vector
)) - 1;
565 adapter
->eims_other
= 1 << (vector
- 1);
568 /* do nothing, since nothing else supports MSI-X */
570 } /* switch (hw->mac.type) */
575 * igb_request_msix - Initialize MSI-X interrupts
577 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
580 static int igb_request_msix(struct igb_adapter
*adapter
)
582 struct net_device
*netdev
= adapter
->netdev
;
583 int i
, err
= 0, vector
= 0;
587 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
588 struct igb_ring
*ring
= &(adapter
->tx_ring
[i
]);
589 sprintf(ring
->name
, "%s-tx-%d", netdev
->name
, i
);
590 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
591 &igb_msix_tx
, 0, ring
->name
,
592 &(adapter
->tx_ring
[i
]));
595 ring
->itr_register
= E1000_EITR(0) + (vector
<< 2);
596 ring
->itr_val
= 976; /* ~4000 ints/sec */
599 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
600 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
601 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
602 sprintf(ring
->name
, "%s-rx-%d", netdev
->name
, i
);
604 memcpy(ring
->name
, netdev
->name
, IFNAMSIZ
);
605 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
606 &igb_msix_rx
, 0, ring
->name
,
607 &(adapter
->rx_ring
[i
]));
610 ring
->itr_register
= E1000_EITR(0) + (vector
<< 2);
611 ring
->itr_val
= adapter
->itr
;
615 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
616 &igb_msix_other
, 0, netdev
->name
, netdev
);
620 igb_configure_msix(adapter
);
626 static void igb_reset_interrupt_capability(struct igb_adapter
*adapter
)
628 if (adapter
->msix_entries
) {
629 pci_disable_msix(adapter
->pdev
);
630 kfree(adapter
->msix_entries
);
631 adapter
->msix_entries
= NULL
;
632 } else if (adapter
->flags
& IGB_FLAG_HAS_MSI
)
633 pci_disable_msi(adapter
->pdev
);
639 * igb_set_interrupt_capability - set MSI or MSI-X if supported
641 * Attempt to configure interrupts using the best available
642 * capabilities of the hardware and kernel.
644 static void igb_set_interrupt_capability(struct igb_adapter
*adapter
)
649 /* Number of supported queues. */
650 /* Having more queues than CPUs doesn't make sense. */
651 adapter
->num_rx_queues
= min_t(u32
, IGB_MAX_RX_QUEUES
, num_online_cpus());
652 adapter
->num_tx_queues
= min_t(u32
, IGB_MAX_TX_QUEUES
, num_online_cpus());
654 numvecs
= adapter
->num_tx_queues
+ adapter
->num_rx_queues
+ 1;
655 adapter
->msix_entries
= kcalloc(numvecs
, sizeof(struct msix_entry
),
657 if (!adapter
->msix_entries
)
660 for (i
= 0; i
< numvecs
; i
++)
661 adapter
->msix_entries
[i
].entry
= i
;
663 err
= pci_enable_msix(adapter
->pdev
,
664 adapter
->msix_entries
,
669 igb_reset_interrupt_capability(adapter
);
671 /* If we can't do MSI-X, try MSI */
673 #ifdef CONFIG_PCI_IOV
674 /* disable SR-IOV for non MSI-X configurations */
675 if (adapter
->vf_data
) {
676 struct e1000_hw
*hw
= &adapter
->hw
;
677 /* disable iov and allow time for transactions to clear */
678 pci_disable_sriov(adapter
->pdev
);
681 kfree(adapter
->vf_data
);
682 adapter
->vf_data
= NULL
;
683 wr32(E1000_IOVCTL
, E1000_IOVCTL_REUSE_VFQ
);
685 dev_info(&adapter
->pdev
->dev
, "IOV Disabled\n");
688 adapter
->num_rx_queues
= 1;
689 adapter
->num_tx_queues
= 1;
690 if (!pci_enable_msi(adapter
->pdev
))
691 adapter
->flags
|= IGB_FLAG_HAS_MSI
;
693 /* Notify the stack of the (possibly) reduced Tx Queue count. */
694 adapter
->netdev
->real_num_tx_queues
= adapter
->num_tx_queues
;
699 * igb_request_irq - initialize interrupts
701 * Attempts to configure interrupts using the best available
702 * capabilities of the hardware and kernel.
704 static int igb_request_irq(struct igb_adapter
*adapter
)
706 struct net_device
*netdev
= adapter
->netdev
;
707 struct e1000_hw
*hw
= &adapter
->hw
;
710 if (adapter
->msix_entries
) {
711 err
= igb_request_msix(adapter
);
714 /* fall back to MSI */
715 igb_reset_interrupt_capability(adapter
);
716 if (!pci_enable_msi(adapter
->pdev
))
717 adapter
->flags
|= IGB_FLAG_HAS_MSI
;
718 igb_free_all_tx_resources(adapter
);
719 igb_free_all_rx_resources(adapter
);
720 adapter
->num_rx_queues
= 1;
721 igb_alloc_queues(adapter
);
723 switch (hw
->mac
.type
) {
725 wr32(E1000_MSIXBM(0),
726 (E1000_EICR_RX_QUEUE0
| E1000_EIMS_OTHER
));
729 wr32(E1000_IVAR0
, E1000_IVAR_VALID
);
736 if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
737 err
= request_irq(adapter
->pdev
->irq
, &igb_intr_msi
, 0,
738 netdev
->name
, netdev
);
741 /* fall back to legacy interrupts */
742 igb_reset_interrupt_capability(adapter
);
743 adapter
->flags
&= ~IGB_FLAG_HAS_MSI
;
746 err
= request_irq(adapter
->pdev
->irq
, &igb_intr
, IRQF_SHARED
,
747 netdev
->name
, netdev
);
750 dev_err(&adapter
->pdev
->dev
, "Error %d getting interrupt\n",
757 static void igb_free_irq(struct igb_adapter
*adapter
)
759 struct net_device
*netdev
= adapter
->netdev
;
761 if (adapter
->msix_entries
) {
764 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
765 free_irq(adapter
->msix_entries
[vector
++].vector
,
766 &(adapter
->tx_ring
[i
]));
767 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
768 free_irq(adapter
->msix_entries
[vector
++].vector
,
769 &(adapter
->rx_ring
[i
]));
771 free_irq(adapter
->msix_entries
[vector
++].vector
, netdev
);
775 free_irq(adapter
->pdev
->irq
, netdev
);
779 * igb_irq_disable - Mask off interrupt generation on the NIC
780 * @adapter: board private structure
782 static void igb_irq_disable(struct igb_adapter
*adapter
)
784 struct e1000_hw
*hw
= &adapter
->hw
;
786 if (adapter
->msix_entries
) {
788 wr32(E1000_EIMC
, ~0);
795 synchronize_irq(adapter
->pdev
->irq
);
799 * igb_irq_enable - Enable default interrupt generation settings
800 * @adapter: board private structure
802 static void igb_irq_enable(struct igb_adapter
*adapter
)
804 struct e1000_hw
*hw
= &adapter
->hw
;
806 if (adapter
->msix_entries
) {
807 wr32(E1000_EIAC
, adapter
->eims_enable_mask
);
808 wr32(E1000_EIAM
, adapter
->eims_enable_mask
);
809 wr32(E1000_EIMS
, adapter
->eims_enable_mask
);
810 if (adapter
->vfs_allocated_count
)
811 wr32(E1000_MBVFIMR
, 0xFF);
812 wr32(E1000_IMS
, (E1000_IMS_LSC
| E1000_IMS_VMMB
|
813 E1000_IMS_DOUTSYNC
));
815 wr32(E1000_IMS
, IMS_ENABLE_MASK
);
816 wr32(E1000_IAM
, IMS_ENABLE_MASK
);
820 static void igb_update_mng_vlan(struct igb_adapter
*adapter
)
822 struct net_device
*netdev
= adapter
->netdev
;
823 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
824 u16 old_vid
= adapter
->mng_vlan_id
;
825 if (adapter
->vlgrp
) {
826 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
827 if (adapter
->hw
.mng_cookie
.status
&
828 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
829 igb_vlan_rx_add_vid(netdev
, vid
);
830 adapter
->mng_vlan_id
= vid
;
832 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
834 if ((old_vid
!= (u16
)IGB_MNG_VLAN_NONE
) &&
836 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
837 igb_vlan_rx_kill_vid(netdev
, old_vid
);
839 adapter
->mng_vlan_id
= vid
;
844 * igb_release_hw_control - release control of the h/w to f/w
845 * @adapter: address of board private structure
847 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
848 * For ASF and Pass Through versions of f/w this means that the
849 * driver is no longer loaded.
852 static void igb_release_hw_control(struct igb_adapter
*adapter
)
854 struct e1000_hw
*hw
= &adapter
->hw
;
857 /* Let firmware take over control of h/w */
858 ctrl_ext
= rd32(E1000_CTRL_EXT
);
860 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
865 * igb_get_hw_control - get control of the h/w from f/w
866 * @adapter: address of board private structure
868 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
869 * For ASF and Pass Through versions of f/w this means that
870 * the driver is loaded.
873 static void igb_get_hw_control(struct igb_adapter
*adapter
)
875 struct e1000_hw
*hw
= &adapter
->hw
;
878 /* Let firmware know the driver has taken over */
879 ctrl_ext
= rd32(E1000_CTRL_EXT
);
881 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
885 * igb_configure - configure the hardware for RX and TX
886 * @adapter: private board structure
888 static void igb_configure(struct igb_adapter
*adapter
)
890 struct net_device
*netdev
= adapter
->netdev
;
893 igb_get_hw_control(adapter
);
894 igb_set_multi(netdev
);
896 igb_restore_vlan(adapter
);
898 igb_configure_tx(adapter
);
899 igb_setup_rctl(adapter
);
900 igb_configure_rx(adapter
);
902 igb_rx_fifo_flush_82575(&adapter
->hw
);
904 /* call igb_desc_unused which always leaves
905 * at least 1 descriptor unused to make sure
906 * next_to_use != next_to_clean */
907 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
908 struct igb_ring
*ring
= &adapter
->rx_ring
[i
];
909 igb_alloc_rx_buffers_adv(ring
, igb_desc_unused(ring
));
913 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
918 * igb_up - Open the interface and prepare it to handle traffic
919 * @adapter: board private structure
922 int igb_up(struct igb_adapter
*adapter
)
924 struct e1000_hw
*hw
= &adapter
->hw
;
927 /* hardware has been reset, we need to reload some things */
928 igb_configure(adapter
);
930 clear_bit(__IGB_DOWN
, &adapter
->state
);
932 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
933 napi_enable(&adapter
->rx_ring
[i
].napi
);
934 if (adapter
->msix_entries
)
935 igb_configure_msix(adapter
);
937 igb_vmm_control(adapter
);
938 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, 0);
939 igb_set_vmolr(hw
, adapter
->vfs_allocated_count
);
941 /* Clear any pending interrupts. */
943 igb_irq_enable(adapter
);
945 /* Fire a link change interrupt to start the watchdog. */
946 wr32(E1000_ICS
, E1000_ICS_LSC
);
950 void igb_down(struct igb_adapter
*adapter
)
952 struct e1000_hw
*hw
= &adapter
->hw
;
953 struct net_device
*netdev
= adapter
->netdev
;
957 /* signal that we're down so the interrupt handler does not
958 * reschedule our watchdog timer */
959 set_bit(__IGB_DOWN
, &adapter
->state
);
961 /* disable receives in the hardware */
962 rctl
= rd32(E1000_RCTL
);
963 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
964 /* flush and sleep below */
966 netif_tx_stop_all_queues(netdev
);
968 /* disable transmits in the hardware */
969 tctl
= rd32(E1000_TCTL
);
970 tctl
&= ~E1000_TCTL_EN
;
971 wr32(E1000_TCTL
, tctl
);
972 /* flush both disables and wait for them to finish */
976 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
977 napi_disable(&adapter
->rx_ring
[i
].napi
);
979 igb_irq_disable(adapter
);
981 del_timer_sync(&adapter
->watchdog_timer
);
982 del_timer_sync(&adapter
->phy_info_timer
);
984 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
985 netif_carrier_off(netdev
);
987 /* record the stats before reset*/
988 igb_update_stats(adapter
);
990 adapter
->link_speed
= 0;
991 adapter
->link_duplex
= 0;
993 if (!pci_channel_offline(adapter
->pdev
))
995 igb_clean_all_tx_rings(adapter
);
996 igb_clean_all_rx_rings(adapter
);
999 void igb_reinit_locked(struct igb_adapter
*adapter
)
1001 WARN_ON(in_interrupt());
1002 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
1006 clear_bit(__IGB_RESETTING
, &adapter
->state
);
1009 void igb_reset(struct igb_adapter
*adapter
)
1011 struct e1000_hw
*hw
= &adapter
->hw
;
1012 struct e1000_mac_info
*mac
= &hw
->mac
;
1013 struct e1000_fc_info
*fc
= &hw
->fc
;
1014 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
1017 /* Repartition Pba for greater than 9k mtu
1018 * To take effect CTRL.RST is required.
1020 switch (mac
->type
) {
1022 pba
= E1000_PBA_64K
;
1026 pba
= E1000_PBA_34K
;
1030 if ((adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) &&
1031 (mac
->type
< e1000_82576
)) {
1032 /* adjust PBA for jumbo frames */
1033 wr32(E1000_PBA
, pba
);
1035 /* To maintain wire speed transmits, the Tx FIFO should be
1036 * large enough to accommodate two full transmit packets,
1037 * rounded up to the next 1KB and expressed in KB. Likewise,
1038 * the Rx FIFO should be large enough to accommodate at least
1039 * one full receive packet and is similarly rounded up and
1040 * expressed in KB. */
1041 pba
= rd32(E1000_PBA
);
1042 /* upper 16 bits has Tx packet buffer allocation size in KB */
1043 tx_space
= pba
>> 16;
1044 /* lower 16 bits has Rx packet buffer allocation size in KB */
1046 /* the tx fifo also stores 16 bytes of information about the tx
1047 * but don't include ethernet FCS because hardware appends it */
1048 min_tx_space
= (adapter
->max_frame_size
+
1049 sizeof(union e1000_adv_tx_desc
) -
1051 min_tx_space
= ALIGN(min_tx_space
, 1024);
1052 min_tx_space
>>= 10;
1053 /* software strips receive CRC, so leave room for it */
1054 min_rx_space
= adapter
->max_frame_size
;
1055 min_rx_space
= ALIGN(min_rx_space
, 1024);
1056 min_rx_space
>>= 10;
1058 /* If current Tx allocation is less than the min Tx FIFO size,
1059 * and the min Tx FIFO size is less than the current Rx FIFO
1060 * allocation, take space away from current Rx allocation */
1061 if (tx_space
< min_tx_space
&&
1062 ((min_tx_space
- tx_space
) < pba
)) {
1063 pba
= pba
- (min_tx_space
- tx_space
);
1065 /* if short on rx space, rx wins and must trump tx
1067 if (pba
< min_rx_space
)
1070 wr32(E1000_PBA
, pba
);
1073 /* flow control settings */
1074 /* The high water mark must be low enough to fit one full frame
1075 * (or the size used for early receive) above it in the Rx FIFO.
1076 * Set it to the lower of:
1077 * - 90% of the Rx FIFO size, or
1078 * - the full Rx FIFO size minus one full frame */
1079 hwm
= min(((pba
<< 10) * 9 / 10),
1080 ((pba
<< 10) - 2 * adapter
->max_frame_size
));
1082 if (mac
->type
< e1000_82576
) {
1083 fc
->high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
1084 fc
->low_water
= fc
->high_water
- 8;
1086 fc
->high_water
= hwm
& 0xFFF0; /* 16-byte granularity */
1087 fc
->low_water
= fc
->high_water
- 16;
1089 fc
->pause_time
= 0xFFFF;
1091 fc
->type
= fc
->original_type
;
1093 /* disable receive for all VFs and wait one second */
1094 if (adapter
->vfs_allocated_count
) {
1096 for (i
= 0 ; i
< adapter
->vfs_allocated_count
; i
++)
1097 adapter
->vf_data
[i
].clear_to_send
= false;
1099 /* ping all the active vfs to let them know we are going down */
1100 igb_ping_all_vfs(adapter
);
1102 /* disable transmits and receives */
1103 wr32(E1000_VFRE
, 0);
1104 wr32(E1000_VFTE
, 0);
1107 /* Allow time for pending master requests to run */
1108 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
1111 if (adapter
->hw
.mac
.ops
.init_hw(&adapter
->hw
))
1112 dev_err(&adapter
->pdev
->dev
, "Hardware Error\n");
1114 igb_update_mng_vlan(adapter
);
1116 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
1117 wr32(E1000_VET
, ETHERNET_IEEE_VLAN_TYPE
);
1119 igb_reset_adaptive(&adapter
->hw
);
1120 igb_get_phy_info(&adapter
->hw
);
1123 static const struct net_device_ops igb_netdev_ops
= {
1124 .ndo_open
= igb_open
,
1125 .ndo_stop
= igb_close
,
1126 .ndo_start_xmit
= igb_xmit_frame_adv
,
1127 .ndo_get_stats
= igb_get_stats
,
1128 .ndo_set_multicast_list
= igb_set_multi
,
1129 .ndo_set_mac_address
= igb_set_mac
,
1130 .ndo_change_mtu
= igb_change_mtu
,
1131 .ndo_do_ioctl
= igb_ioctl
,
1132 .ndo_tx_timeout
= igb_tx_timeout
,
1133 .ndo_validate_addr
= eth_validate_addr
,
1134 .ndo_vlan_rx_register
= igb_vlan_rx_register
,
1135 .ndo_vlan_rx_add_vid
= igb_vlan_rx_add_vid
,
1136 .ndo_vlan_rx_kill_vid
= igb_vlan_rx_kill_vid
,
1137 #ifdef CONFIG_NET_POLL_CONTROLLER
1138 .ndo_poll_controller
= igb_netpoll
,
1143 * igb_probe - Device Initialization Routine
1144 * @pdev: PCI device information struct
1145 * @ent: entry in igb_pci_tbl
1147 * Returns 0 on success, negative on failure
1149 * igb_probe initializes an adapter identified by a pci_dev structure.
1150 * The OS initialization, configuring of the adapter private structure,
1151 * and a hardware reset occur.
1153 static int __devinit
igb_probe(struct pci_dev
*pdev
,
1154 const struct pci_device_id
*ent
)
1156 struct net_device
*netdev
;
1157 struct igb_adapter
*adapter
;
1158 struct e1000_hw
*hw
;
1159 const struct e1000_info
*ei
= igb_info_tbl
[ent
->driver_data
];
1160 unsigned long mmio_start
, mmio_len
;
1161 int err
, pci_using_dac
;
1162 u16 eeprom_data
= 0;
1163 u16 eeprom_apme_mask
= IGB_EEPROM_APME
;
1166 err
= pci_enable_device_mem(pdev
);
1171 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
1173 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64));
1177 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1179 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
1181 dev_err(&pdev
->dev
, "No usable DMA "
1182 "configuration, aborting\n");
1188 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
1194 err
= pci_enable_pcie_error_reporting(pdev
);
1196 dev_err(&pdev
->dev
, "pci_enable_pcie_error_reporting failed "
1198 /* non-fatal, continue */
1201 pci_set_master(pdev
);
1202 pci_save_state(pdev
);
1205 netdev
= alloc_etherdev_mq(sizeof(struct igb_adapter
),
1206 IGB_ABS_MAX_TX_QUEUES
);
1208 goto err_alloc_etherdev
;
1210 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1212 pci_set_drvdata(pdev
, netdev
);
1213 adapter
= netdev_priv(netdev
);
1214 adapter
->netdev
= netdev
;
1215 adapter
->pdev
= pdev
;
1218 adapter
->msg_enable
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
1220 mmio_start
= pci_resource_start(pdev
, 0);
1221 mmio_len
= pci_resource_len(pdev
, 0);
1224 hw
->hw_addr
= ioremap(mmio_start
, mmio_len
);
1228 netdev
->netdev_ops
= &igb_netdev_ops
;
1229 igb_set_ethtool_ops(netdev
);
1230 netdev
->watchdog_timeo
= 5 * HZ
;
1232 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
1234 netdev
->mem_start
= mmio_start
;
1235 netdev
->mem_end
= mmio_start
+ mmio_len
;
1237 /* PCI config space info */
1238 hw
->vendor_id
= pdev
->vendor
;
1239 hw
->device_id
= pdev
->device
;
1240 hw
->revision_id
= pdev
->revision
;
1241 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
1242 hw
->subsystem_device_id
= pdev
->subsystem_device
;
1244 /* setup the private structure */
1246 /* Copy the default MAC, PHY and NVM function pointers */
1247 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
1248 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
1249 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
1250 /* Initialize skew-specific constants */
1251 err
= ei
->get_invariants(hw
);
1255 #ifdef CONFIG_PCI_IOV
1256 /* since iov functionality isn't critical to base device function we
1257 * can accept failure. If it fails we don't allow iov to be enabled */
1258 if (hw
->mac
.type
== e1000_82576
) {
1259 /* 82576 supports a maximum of 7 VFs in addition to the PF */
1260 unsigned int num_vfs
= (max_vfs
> 7) ? 7 : max_vfs
;
1262 unsigned char mac_addr
[ETH_ALEN
];
1265 adapter
->vf_data
= kcalloc(num_vfs
,
1266 sizeof(struct vf_data_storage
),
1268 if (!adapter
->vf_data
) {
1270 "Could not allocate VF private data - "
1271 "IOV enable failed\n");
1273 err
= pci_enable_sriov(pdev
, num_vfs
);
1275 adapter
->vfs_allocated_count
= num_vfs
;
1276 dev_info(&pdev
->dev
,
1277 "%d vfs allocated\n",
1280 i
< adapter
->vfs_allocated_count
;
1282 random_ether_addr(mac_addr
);
1283 igb_set_vf_mac(adapter
, i
,
1287 kfree(adapter
->vf_data
);
1288 adapter
->vf_data
= NULL
;
1295 /* setup the private structure */
1296 err
= igb_sw_init(adapter
);
1300 igb_get_bus_info_pcie(hw
);
1303 switch (hw
->mac
.type
) {
1305 adapter
->flags
|= IGB_FLAG_NEED_CTX_IDX
;
1312 hw
->phy
.autoneg_wait_to_complete
= false;
1313 hw
->mac
.adaptive_ifs
= true;
1315 /* Copper options */
1316 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1317 hw
->phy
.mdix
= AUTO_ALL_MODES
;
1318 hw
->phy
.disable_polarity_correction
= false;
1319 hw
->phy
.ms_type
= e1000_ms_hw_default
;
1322 if (igb_check_reset_block(hw
))
1323 dev_info(&pdev
->dev
,
1324 "PHY reset is blocked due to SOL/IDER session.\n");
1326 netdev
->features
= NETIF_F_SG
|
1328 NETIF_F_HW_VLAN_TX
|
1329 NETIF_F_HW_VLAN_RX
|
1330 NETIF_F_HW_VLAN_FILTER
;
1332 netdev
->features
|= NETIF_F_IPV6_CSUM
;
1333 netdev
->features
|= NETIF_F_TSO
;
1334 netdev
->features
|= NETIF_F_TSO6
;
1336 netdev
->features
|= NETIF_F_GRO
;
1338 netdev
->vlan_features
|= NETIF_F_TSO
;
1339 netdev
->vlan_features
|= NETIF_F_TSO6
;
1340 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
1341 netdev
->vlan_features
|= NETIF_F_SG
;
1344 netdev
->features
|= NETIF_F_HIGHDMA
;
1346 adapter
->en_mng_pt
= igb_enable_mng_pass_thru(&adapter
->hw
);
1348 /* before reading the NVM, reset the controller to put the device in a
1349 * known good starting state */
1350 hw
->mac
.ops
.reset_hw(hw
);
1352 /* make sure the NVM is good */
1353 if (igb_validate_nvm_checksum(hw
) < 0) {
1354 dev_err(&pdev
->dev
, "The NVM Checksum Is Not Valid\n");
1359 /* copy the MAC address out of the NVM */
1360 if (hw
->mac
.ops
.read_mac_addr(hw
))
1361 dev_err(&pdev
->dev
, "NVM Read Error\n");
1363 memcpy(netdev
->dev_addr
, hw
->mac
.addr
, netdev
->addr_len
);
1364 memcpy(netdev
->perm_addr
, hw
->mac
.addr
, netdev
->addr_len
);
1366 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
1367 dev_err(&pdev
->dev
, "Invalid MAC Address\n");
1372 setup_timer(&adapter
->watchdog_timer
, &igb_watchdog
,
1373 (unsigned long) adapter
);
1374 setup_timer(&adapter
->phy_info_timer
, &igb_update_phy_info
,
1375 (unsigned long) adapter
);
1377 INIT_WORK(&adapter
->reset_task
, igb_reset_task
);
1378 INIT_WORK(&adapter
->watchdog_task
, igb_watchdog_task
);
1380 /* Initialize link properties that are user-changeable */
1381 adapter
->fc_autoneg
= true;
1382 hw
->mac
.autoneg
= true;
1383 hw
->phy
.autoneg_advertised
= 0x2f;
1385 hw
->fc
.original_type
= e1000_fc_default
;
1386 hw
->fc
.type
= e1000_fc_default
;
1388 adapter
->itr_setting
= IGB_DEFAULT_ITR
;
1389 adapter
->itr
= IGB_START_ITR
;
1391 igb_validate_mdi_setting(hw
);
1393 adapter
->rx_csum
= 1;
1395 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1396 * enable the ACPI Magic Packet filter
1399 if (hw
->bus
.func
== 0)
1400 hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1401 else if (hw
->bus
.func
== 1)
1402 hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1404 if (eeprom_data
& eeprom_apme_mask
)
1405 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1407 /* now that we have the eeprom settings, apply the special cases where
1408 * the eeprom may be wrong or the board simply won't support wake on
1409 * lan on a particular port */
1410 switch (pdev
->device
) {
1411 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
1412 adapter
->eeprom_wol
= 0;
1414 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
1415 case E1000_DEV_ID_82576_FIBER
:
1416 case E1000_DEV_ID_82576_SERDES
:
1417 /* Wake events only supported on port A for dual fiber
1418 * regardless of eeprom setting */
1419 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
)
1420 adapter
->eeprom_wol
= 0;
1422 case E1000_DEV_ID_82576_QUAD_COPPER
:
1423 /* if quad port adapter, disable WoL on all but port A */
1424 if (global_quad_port_a
!= 0)
1425 adapter
->eeprom_wol
= 0;
1427 adapter
->flags
|= IGB_FLAG_QUAD_PORT_A
;
1428 /* Reset for multiple quad port adapters */
1429 if (++global_quad_port_a
== 4)
1430 global_quad_port_a
= 0;
1434 /* initialize the wol settings based on the eeprom settings */
1435 adapter
->wol
= adapter
->eeprom_wol
;
1436 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1438 /* reset the hardware with the new settings */
1441 /* let the f/w know that the h/w is now under the control of the
1443 igb_get_hw_control(adapter
);
1445 /* tell the stack to leave us alone until igb_open() is called */
1446 netif_carrier_off(netdev
);
1447 netif_tx_stop_all_queues(netdev
);
1449 strcpy(netdev
->name
, "eth%d");
1450 err
= register_netdev(netdev
);
1454 #ifdef CONFIG_IGB_DCA
1455 if (dca_add_requester(&pdev
->dev
) == 0) {
1456 adapter
->flags
|= IGB_FLAG_DCA_ENABLED
;
1457 dev_info(&pdev
->dev
, "DCA enabled\n");
1458 /* Always use CB2 mode, difference is masked
1459 * in the CB driver. */
1460 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_CB2
);
1461 igb_setup_dca(adapter
);
1466 * Initialize hardware timer: we keep it running just in case
1467 * that some program needs it later on.
1469 memset(&adapter
->cycles
, 0, sizeof(adapter
->cycles
));
1470 adapter
->cycles
.read
= igb_read_clock
;
1471 adapter
->cycles
.mask
= CLOCKSOURCE_MASK(64);
1472 adapter
->cycles
.mult
= 1;
1473 adapter
->cycles
.shift
= IGB_TSYNC_SHIFT
;
1476 IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS
* IGB_TSYNC_SCALE
);
1479 * Avoid rollover while we initialize by resetting the time counter.
1481 wr32(E1000_SYSTIML
, 0x00000000);
1482 wr32(E1000_SYSTIMH
, 0x00000000);
1485 * Set registers so that rollover occurs soon to test this.
1487 wr32(E1000_SYSTIML
, 0x00000000);
1488 wr32(E1000_SYSTIMH
, 0xFF800000);
1491 timecounter_init(&adapter
->clock
,
1493 ktime_to_ns(ktime_get_real()));
1496 * Synchronize our NIC clock against system wall clock. NIC
1497 * time stamp reading requires ~3us per sample, each sample
1498 * was pretty stable even under load => only require 10
1499 * samples for each offset comparison.
1501 memset(&adapter
->compare
, 0, sizeof(adapter
->compare
));
1502 adapter
->compare
.source
= &adapter
->clock
;
1503 adapter
->compare
.target
= ktime_get_real
;
1504 adapter
->compare
.num_samples
= 10;
1505 timecompare_update(&adapter
->compare
, 0);
1511 "igb: %s: hw %p initialized timer\n",
1512 igb_get_time_str(adapter
, buffer
),
1517 dev_info(&pdev
->dev
, "Intel(R) Gigabit Ethernet Network Connection\n");
1518 /* print bus type/speed/width info */
1519 dev_info(&pdev
->dev
, "%s: (PCIe:%s:%s) %pM\n",
1521 ((hw
->bus
.speed
== e1000_bus_speed_2500
)
1522 ? "2.5Gb/s" : "unknown"),
1523 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
1524 (hw
->bus
.width
== e1000_bus_width_pcie_x2
) ? "Width x2" :
1525 (hw
->bus
.width
== e1000_bus_width_pcie_x1
) ? "Width x1" :
1529 igb_read_part_num(hw
, &part_num
);
1530 dev_info(&pdev
->dev
, "%s: PBA No: %06x-%03x\n", netdev
->name
,
1531 (part_num
>> 8), (part_num
& 0xff));
1533 dev_info(&pdev
->dev
,
1534 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
1535 adapter
->msix_entries
? "MSI-X" :
1536 (adapter
->flags
& IGB_FLAG_HAS_MSI
) ? "MSI" : "legacy",
1537 adapter
->num_rx_queues
, adapter
->num_tx_queues
);
1542 igb_release_hw_control(adapter
);
1544 if (!igb_check_reset_block(hw
))
1547 if (hw
->flash_address
)
1548 iounmap(hw
->flash_address
);
1550 igb_free_queues(adapter
);
1552 iounmap(hw
->hw_addr
);
1554 free_netdev(netdev
);
1556 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
1560 pci_disable_device(pdev
);
1565 * igb_remove - Device Removal Routine
1566 * @pdev: PCI device information struct
1568 * igb_remove is called by the PCI subsystem to alert the driver
1569 * that it should release a PCI device. The could be caused by a
1570 * Hot-Plug event, or because the driver is going to be removed from
1573 static void __devexit
igb_remove(struct pci_dev
*pdev
)
1575 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1576 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1577 struct e1000_hw
*hw
= &adapter
->hw
;
1580 /* flush_scheduled work may reschedule our watchdog task, so
1581 * explicitly disable watchdog tasks from being rescheduled */
1582 set_bit(__IGB_DOWN
, &adapter
->state
);
1583 del_timer_sync(&adapter
->watchdog_timer
);
1584 del_timer_sync(&adapter
->phy_info_timer
);
1586 flush_scheduled_work();
1588 #ifdef CONFIG_IGB_DCA
1589 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
) {
1590 dev_info(&pdev
->dev
, "DCA disabled\n");
1591 dca_remove_requester(&pdev
->dev
);
1592 adapter
->flags
&= ~IGB_FLAG_DCA_ENABLED
;
1593 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_DISABLE
);
1597 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1598 * would have already happened in close and is redundant. */
1599 igb_release_hw_control(adapter
);
1601 unregister_netdev(netdev
);
1603 if (!igb_check_reset_block(&adapter
->hw
))
1604 igb_reset_phy(&adapter
->hw
);
1606 igb_reset_interrupt_capability(adapter
);
1608 igb_free_queues(adapter
);
1610 #ifdef CONFIG_PCI_IOV
1611 /* reclaim resources allocated to VFs */
1612 if (adapter
->vf_data
) {
1613 /* disable iov and allow time for transactions to clear */
1614 pci_disable_sriov(pdev
);
1617 kfree(adapter
->vf_data
);
1618 adapter
->vf_data
= NULL
;
1619 wr32(E1000_IOVCTL
, E1000_IOVCTL_REUSE_VFQ
);
1621 dev_info(&pdev
->dev
, "IOV Disabled\n");
1624 iounmap(hw
->hw_addr
);
1625 if (hw
->flash_address
)
1626 iounmap(hw
->flash_address
);
1627 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
1630 free_netdev(netdev
);
1632 err
= pci_disable_pcie_error_reporting(pdev
);
1635 "pci_disable_pcie_error_reporting failed 0x%x\n", err
);
1637 pci_disable_device(pdev
);
1641 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1642 * @adapter: board private structure to initialize
1644 * igb_sw_init initializes the Adapter private data structure.
1645 * Fields are initialized based on PCI device information and
1646 * OS network device settings (MTU size).
1648 static int __devinit
igb_sw_init(struct igb_adapter
*adapter
)
1650 struct e1000_hw
*hw
= &adapter
->hw
;
1651 struct net_device
*netdev
= adapter
->netdev
;
1652 struct pci_dev
*pdev
= adapter
->pdev
;
1654 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->bus
.pci_cmd_word
);
1656 adapter
->tx_ring_count
= IGB_DEFAULT_TXD
;
1657 adapter
->rx_ring_count
= IGB_DEFAULT_RXD
;
1658 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1659 adapter
->rx_ps_hdr_size
= 0; /* disable packet split */
1660 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1661 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
1663 /* This call may decrease the number of queues depending on
1664 * interrupt mode. */
1665 igb_set_interrupt_capability(adapter
);
1667 if (igb_alloc_queues(adapter
)) {
1668 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
1672 /* Explicitly disable IRQ since the NIC can be in any state. */
1673 igb_irq_disable(adapter
);
1675 set_bit(__IGB_DOWN
, &adapter
->state
);
1680 * igb_open - Called when a network interface is made active
1681 * @netdev: network interface device structure
1683 * Returns 0 on success, negative value on failure
1685 * The open entry point is called when a network interface is made
1686 * active by the system (IFF_UP). At this point all resources needed
1687 * for transmit and receive operations are allocated, the interrupt
1688 * handler is registered with the OS, the watchdog timer is started,
1689 * and the stack is notified that the interface is ready.
1691 static int igb_open(struct net_device
*netdev
)
1693 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1694 struct e1000_hw
*hw
= &adapter
->hw
;
1698 /* disallow open during test */
1699 if (test_bit(__IGB_TESTING
, &adapter
->state
))
1702 /* allocate transmit descriptors */
1703 err
= igb_setup_all_tx_resources(adapter
);
1707 /* allocate receive descriptors */
1708 err
= igb_setup_all_rx_resources(adapter
);
1712 /* e1000_power_up_phy(adapter); */
1714 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
1715 if ((adapter
->hw
.mng_cookie
.status
&
1716 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
1717 igb_update_mng_vlan(adapter
);
1719 /* before we allocate an interrupt, we must be ready to handle it.
1720 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1721 * as soon as we call pci_request_irq, so we have to setup our
1722 * clean_rx handler before we do so. */
1723 igb_configure(adapter
);
1725 igb_vmm_control(adapter
);
1726 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, 0);
1727 igb_set_vmolr(hw
, adapter
->vfs_allocated_count
);
1729 err
= igb_request_irq(adapter
);
1733 /* From here on the code is the same as igb_up() */
1734 clear_bit(__IGB_DOWN
, &adapter
->state
);
1736 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1737 napi_enable(&adapter
->rx_ring
[i
].napi
);
1739 /* Clear any pending interrupts. */
1742 igb_irq_enable(adapter
);
1744 netif_tx_start_all_queues(netdev
);
1746 /* Fire a link status change interrupt to start the watchdog. */
1747 wr32(E1000_ICS
, E1000_ICS_LSC
);
1752 igb_release_hw_control(adapter
);
1753 /* e1000_power_down_phy(adapter); */
1754 igb_free_all_rx_resources(adapter
);
1756 igb_free_all_tx_resources(adapter
);
1764 * igb_close - Disables a network interface
1765 * @netdev: network interface device structure
1767 * Returns 0, this is not allowed to fail
1769 * The close entry point is called when an interface is de-activated
1770 * by the OS. The hardware is still under the driver's control, but
1771 * needs to be disabled. A global MAC reset is issued to stop the
1772 * hardware, and all transmit and receive resources are freed.
1774 static int igb_close(struct net_device
*netdev
)
1776 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1778 WARN_ON(test_bit(__IGB_RESETTING
, &adapter
->state
));
1781 igb_free_irq(adapter
);
1783 igb_free_all_tx_resources(adapter
);
1784 igb_free_all_rx_resources(adapter
);
1786 /* kill manageability vlan ID if supported, but not if a vlan with
1787 * the same ID is registered on the host OS (let 8021q kill it) */
1788 if ((adapter
->hw
.mng_cookie
.status
&
1789 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
1791 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
)))
1792 igb_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1798 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
1799 * @adapter: board private structure
1800 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1802 * Return 0 on success, negative on failure
1804 int igb_setup_tx_resources(struct igb_adapter
*adapter
,
1805 struct igb_ring
*tx_ring
)
1807 struct pci_dev
*pdev
= adapter
->pdev
;
1810 size
= sizeof(struct igb_buffer
) * tx_ring
->count
;
1811 tx_ring
->buffer_info
= vmalloc(size
);
1812 if (!tx_ring
->buffer_info
)
1814 memset(tx_ring
->buffer_info
, 0, size
);
1816 /* round up to nearest 4K */
1817 tx_ring
->size
= tx_ring
->count
* sizeof(union e1000_adv_tx_desc
);
1818 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1820 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
1826 tx_ring
->adapter
= adapter
;
1827 tx_ring
->next_to_use
= 0;
1828 tx_ring
->next_to_clean
= 0;
1832 vfree(tx_ring
->buffer_info
);
1833 dev_err(&adapter
->pdev
->dev
,
1834 "Unable to allocate memory for the transmit descriptor ring\n");
1839 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
1840 * (Descriptors) for all queues
1841 * @adapter: board private structure
1843 * Return 0 on success, negative on failure
1845 static int igb_setup_all_tx_resources(struct igb_adapter
*adapter
)
1850 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1851 err
= igb_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1853 dev_err(&adapter
->pdev
->dev
,
1854 "Allocation for Tx Queue %u failed\n", i
);
1855 for (i
--; i
>= 0; i
--)
1856 igb_free_tx_resources(&adapter
->tx_ring
[i
]);
1861 for (i
= 0; i
< IGB_MAX_TX_QUEUES
; i
++) {
1862 r_idx
= i
% adapter
->num_tx_queues
;
1863 adapter
->multi_tx_table
[i
] = &adapter
->tx_ring
[r_idx
];
1869 * igb_configure_tx - Configure transmit Unit after Reset
1870 * @adapter: board private structure
1872 * Configure the Tx unit of the MAC after a reset.
1874 static void igb_configure_tx(struct igb_adapter
*adapter
)
1877 struct e1000_hw
*hw
= &adapter
->hw
;
1882 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1883 struct igb_ring
*ring
= &adapter
->tx_ring
[i
];
1885 wr32(E1000_TDLEN(j
),
1886 ring
->count
* sizeof(union e1000_adv_tx_desc
));
1888 wr32(E1000_TDBAL(j
),
1889 tdba
& 0x00000000ffffffffULL
);
1890 wr32(E1000_TDBAH(j
), tdba
>> 32);
1892 ring
->head
= E1000_TDH(j
);
1893 ring
->tail
= E1000_TDT(j
);
1894 writel(0, hw
->hw_addr
+ ring
->tail
);
1895 writel(0, hw
->hw_addr
+ ring
->head
);
1896 txdctl
= rd32(E1000_TXDCTL(j
));
1897 txdctl
|= E1000_TXDCTL_QUEUE_ENABLE
;
1898 wr32(E1000_TXDCTL(j
), txdctl
);
1900 /* Turn off Relaxed Ordering on head write-backs. The
1901 * writebacks MUST be delivered in order or it will
1902 * completely screw up our bookeeping.
1904 txctrl
= rd32(E1000_DCA_TXCTRL(j
));
1905 txctrl
&= ~E1000_DCA_TXCTRL_TX_WB_RO_EN
;
1906 wr32(E1000_DCA_TXCTRL(j
), txctrl
);
1909 /* disable queue 0 to prevent tail bump w/o re-configuration */
1910 if (adapter
->vfs_allocated_count
)
1911 wr32(E1000_TXDCTL(0), 0);
1913 /* Program the Transmit Control Register */
1914 tctl
= rd32(E1000_TCTL
);
1915 tctl
&= ~E1000_TCTL_CT
;
1916 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1917 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1919 igb_config_collision_dist(hw
);
1921 /* Setup Transmit Descriptor Settings for eop descriptor */
1922 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_RS
;
1924 /* Enable transmits */
1925 tctl
|= E1000_TCTL_EN
;
1927 wr32(E1000_TCTL
, tctl
);
1931 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
1932 * @adapter: board private structure
1933 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1935 * Returns 0 on success, negative on failure
1937 int igb_setup_rx_resources(struct igb_adapter
*adapter
,
1938 struct igb_ring
*rx_ring
)
1940 struct pci_dev
*pdev
= adapter
->pdev
;
1943 size
= sizeof(struct igb_buffer
) * rx_ring
->count
;
1944 rx_ring
->buffer_info
= vmalloc(size
);
1945 if (!rx_ring
->buffer_info
)
1947 memset(rx_ring
->buffer_info
, 0, size
);
1949 desc_len
= sizeof(union e1000_adv_rx_desc
);
1951 /* Round up to nearest 4K */
1952 rx_ring
->size
= rx_ring
->count
* desc_len
;
1953 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
1955 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
,
1961 rx_ring
->next_to_clean
= 0;
1962 rx_ring
->next_to_use
= 0;
1964 rx_ring
->adapter
= adapter
;
1969 vfree(rx_ring
->buffer_info
);
1970 dev_err(&adapter
->pdev
->dev
, "Unable to allocate memory for "
1971 "the receive descriptor ring\n");
1976 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
1977 * (Descriptors) for all queues
1978 * @adapter: board private structure
1980 * Return 0 on success, negative on failure
1982 static int igb_setup_all_rx_resources(struct igb_adapter
*adapter
)
1986 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1987 err
= igb_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1989 dev_err(&adapter
->pdev
->dev
,
1990 "Allocation for Rx Queue %u failed\n", i
);
1991 for (i
--; i
>= 0; i
--)
1992 igb_free_rx_resources(&adapter
->rx_ring
[i
]);
2001 * igb_setup_rctl - configure the receive control registers
2002 * @adapter: Board private structure
2004 static void igb_setup_rctl(struct igb_adapter
*adapter
)
2006 struct e1000_hw
*hw
= &adapter
->hw
;
2011 rctl
= rd32(E1000_RCTL
);
2013 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
2014 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
2016 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_RDMTS_HALF
|
2017 (hw
->mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
2020 * enable stripping of CRC. It's unlikely this will break BMC
2021 * redirection as it did with e1000. Newer features require
2022 * that the HW strips the CRC.
2024 rctl
|= E1000_RCTL_SECRC
;
2027 * disable store bad packets and clear size bits.
2029 rctl
&= ~(E1000_RCTL_SBP
| E1000_RCTL_SZ_256
);
2031 /* enable LPE when to prevent packets larger than max_frame_size */
2032 rctl
|= E1000_RCTL_LPE
;
2034 /* Setup buffer sizes */
2035 switch (adapter
->rx_buffer_len
) {
2036 case IGB_RXBUFFER_256
:
2037 rctl
|= E1000_RCTL_SZ_256
;
2039 case IGB_RXBUFFER_512
:
2040 rctl
|= E1000_RCTL_SZ_512
;
2043 srrctl
= ALIGN(adapter
->rx_buffer_len
, 1024)
2044 >> E1000_SRRCTL_BSIZEPKT_SHIFT
;
2048 /* 82575 and greater support packet-split where the protocol
2049 * header is placed in skb->data and the packet data is
2050 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2051 * In the case of a non-split, skb->data is linearly filled,
2052 * followed by the page buffers. Therefore, skb->data is
2053 * sized to hold the largest protocol header.
2055 /* allocations using alloc_page take too long for regular MTU
2056 * so only enable packet split for jumbo frames */
2057 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
2058 adapter
->rx_ps_hdr_size
= IGB_RXBUFFER_128
;
2059 srrctl
|= adapter
->rx_ps_hdr_size
<<
2060 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT
;
2061 srrctl
|= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
2063 adapter
->rx_ps_hdr_size
= 0;
2064 srrctl
|= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF
;
2067 /* Attention!!! For SR-IOV PF driver operations you must enable
2068 * queue drop for all VF and PF queues to prevent head of line blocking
2069 * if an un-trusted VF does not provide descriptors to hardware.
2071 if (adapter
->vfs_allocated_count
) {
2074 /* set all queue drop enable bits */
2075 wr32(E1000_QDE
, ALL_QUEUES
);
2076 srrctl
|= E1000_SRRCTL_DROP_EN
;
2078 /* disable queue 0 to prevent tail write w/o re-config */
2079 wr32(E1000_RXDCTL(0), 0);
2081 vmolr
= rd32(E1000_VMOLR(adapter
->vfs_allocated_count
));
2082 if (rctl
& E1000_RCTL_LPE
)
2083 vmolr
|= E1000_VMOLR_LPE
;
2084 if (adapter
->num_rx_queues
> 1)
2085 vmolr
|= E1000_VMOLR_RSSE
;
2086 wr32(E1000_VMOLR(adapter
->vfs_allocated_count
), vmolr
);
2089 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2090 int j
= adapter
->rx_ring
[i
].reg_idx
;
2091 wr32(E1000_SRRCTL(j
), srrctl
);
2094 wr32(E1000_RCTL
, rctl
);
2098 * igb_rlpml_set - set maximum receive packet size
2099 * @adapter: board private structure
2101 * Configure maximum receivable packet size.
2103 static void igb_rlpml_set(struct igb_adapter
*adapter
)
2105 u32 max_frame_size
= adapter
->max_frame_size
;
2106 struct e1000_hw
*hw
= &adapter
->hw
;
2107 u16 pf_id
= adapter
->vfs_allocated_count
;
2110 max_frame_size
+= VLAN_TAG_SIZE
;
2112 /* if vfs are enabled we set RLPML to the largest possible request
2113 * size and set the VMOLR RLPML to the size we need */
2115 igb_set_vf_rlpml(adapter
, max_frame_size
, pf_id
);
2116 max_frame_size
= MAX_STD_JUMBO_FRAME_SIZE
+ VLAN_TAG_SIZE
;
2119 wr32(E1000_RLPML
, max_frame_size
);
2123 * igb_configure_vt_default_pool - Configure VT default pool
2124 * @adapter: board private structure
2126 * Configure the default pool
2128 static void igb_configure_vt_default_pool(struct igb_adapter
*adapter
)
2130 struct e1000_hw
*hw
= &adapter
->hw
;
2131 u16 pf_id
= adapter
->vfs_allocated_count
;
2134 /* not in sr-iov mode - do nothing */
2138 vtctl
= rd32(E1000_VT_CTL
);
2139 vtctl
&= ~(E1000_VT_CTL_DEFAULT_POOL_MASK
|
2140 E1000_VT_CTL_DISABLE_DEF_POOL
);
2141 vtctl
|= pf_id
<< E1000_VT_CTL_DEFAULT_POOL_SHIFT
;
2142 wr32(E1000_VT_CTL
, vtctl
);
2146 * igb_configure_rx - Configure receive Unit after Reset
2147 * @adapter: board private structure
2149 * Configure the Rx unit of the MAC after a reset.
2151 static void igb_configure_rx(struct igb_adapter
*adapter
)
2154 struct e1000_hw
*hw
= &adapter
->hw
;
2159 /* disable receives while setting up the descriptors */
2160 rctl
= rd32(E1000_RCTL
);
2161 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
2165 if (adapter
->itr_setting
> 3)
2166 wr32(E1000_ITR
, adapter
->itr
);
2168 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2169 * the Base and Length of the Rx Descriptor Ring */
2170 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2171 struct igb_ring
*ring
= &adapter
->rx_ring
[i
];
2172 int j
= ring
->reg_idx
;
2174 wr32(E1000_RDBAL(j
),
2175 rdba
& 0x00000000ffffffffULL
);
2176 wr32(E1000_RDBAH(j
), rdba
>> 32);
2177 wr32(E1000_RDLEN(j
),
2178 ring
->count
* sizeof(union e1000_adv_rx_desc
));
2180 ring
->head
= E1000_RDH(j
);
2181 ring
->tail
= E1000_RDT(j
);
2182 writel(0, hw
->hw_addr
+ ring
->tail
);
2183 writel(0, hw
->hw_addr
+ ring
->head
);
2185 rxdctl
= rd32(E1000_RXDCTL(j
));
2186 rxdctl
|= E1000_RXDCTL_QUEUE_ENABLE
;
2187 rxdctl
&= 0xFFF00000;
2188 rxdctl
|= IGB_RX_PTHRESH
;
2189 rxdctl
|= IGB_RX_HTHRESH
<< 8;
2190 rxdctl
|= IGB_RX_WTHRESH
<< 16;
2191 wr32(E1000_RXDCTL(j
), rxdctl
);
2194 if (adapter
->num_rx_queues
> 1) {
2203 get_random_bytes(&random
[0], 40);
2205 if (hw
->mac
.type
>= e1000_82576
)
2209 for (j
= 0; j
< (32 * 4); j
++) {
2211 adapter
->rx_ring
[(j
% adapter
->num_rx_queues
)].reg_idx
<< shift
;
2214 hw
->hw_addr
+ E1000_RETA(0) + (j
& ~3));
2216 if (adapter
->vfs_allocated_count
)
2217 mrqc
= E1000_MRQC_ENABLE_VMDQ_RSS_2Q
;
2219 mrqc
= E1000_MRQC_ENABLE_RSS_4Q
;
2221 /* Fill out hash function seeds */
2222 for (j
= 0; j
< 10; j
++)
2223 array_wr32(E1000_RSSRK(0), j
, random
[j
]);
2225 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
2226 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
2227 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV6
|
2228 E1000_MRQC_RSS_FIELD_IPV6_TCP
);
2229 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4_UDP
|
2230 E1000_MRQC_RSS_FIELD_IPV6_UDP
);
2231 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX
|
2232 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX
);
2235 wr32(E1000_MRQC
, mrqc
);
2237 /* Multiqueue and raw packet checksumming are mutually
2238 * exclusive. Note that this not the same as TCP/IP
2239 * checksumming, which works fine. */
2240 rxcsum
= rd32(E1000_RXCSUM
);
2241 rxcsum
|= E1000_RXCSUM_PCSD
;
2242 wr32(E1000_RXCSUM
, rxcsum
);
2244 /* Enable multi-queue for sr-iov */
2245 if (adapter
->vfs_allocated_count
)
2246 wr32(E1000_MRQC
, E1000_MRQC_ENABLE_VMDQ
);
2247 /* Enable Receive Checksum Offload for TCP and UDP */
2248 rxcsum
= rd32(E1000_RXCSUM
);
2249 if (adapter
->rx_csum
)
2250 rxcsum
|= E1000_RXCSUM_TUOFL
| E1000_RXCSUM_IPPCSE
;
2252 rxcsum
&= ~(E1000_RXCSUM_TUOFL
| E1000_RXCSUM_IPPCSE
);
2254 wr32(E1000_RXCSUM
, rxcsum
);
2257 /* Set the default pool for the PF's first queue */
2258 igb_configure_vt_default_pool(adapter
);
2260 igb_rlpml_set(adapter
);
2262 /* Enable Receives */
2263 wr32(E1000_RCTL
, rctl
);
2267 * igb_free_tx_resources - Free Tx Resources per Queue
2268 * @tx_ring: Tx descriptor ring for a specific queue
2270 * Free all transmit software resources
2272 void igb_free_tx_resources(struct igb_ring
*tx_ring
)
2274 struct pci_dev
*pdev
= tx_ring
->adapter
->pdev
;
2276 igb_clean_tx_ring(tx_ring
);
2278 vfree(tx_ring
->buffer_info
);
2279 tx_ring
->buffer_info
= NULL
;
2281 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
2283 tx_ring
->desc
= NULL
;
2287 * igb_free_all_tx_resources - Free Tx Resources for All Queues
2288 * @adapter: board private structure
2290 * Free all transmit software resources
2292 static void igb_free_all_tx_resources(struct igb_adapter
*adapter
)
2296 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2297 igb_free_tx_resources(&adapter
->tx_ring
[i
]);
2300 static void igb_unmap_and_free_tx_resource(struct igb_adapter
*adapter
,
2301 struct igb_buffer
*buffer_info
)
2303 buffer_info
->dma
= 0;
2304 if (buffer_info
->skb
) {
2305 skb_dma_unmap(&adapter
->pdev
->dev
, buffer_info
->skb
,
2307 dev_kfree_skb_any(buffer_info
->skb
);
2308 buffer_info
->skb
= NULL
;
2310 buffer_info
->time_stamp
= 0;
2311 /* buffer_info must be completely set up in the transmit path */
2315 * igb_clean_tx_ring - Free Tx Buffers
2316 * @tx_ring: ring to be cleaned
2318 static void igb_clean_tx_ring(struct igb_ring
*tx_ring
)
2320 struct igb_adapter
*adapter
= tx_ring
->adapter
;
2321 struct igb_buffer
*buffer_info
;
2325 if (!tx_ring
->buffer_info
)
2327 /* Free all the Tx ring sk_buffs */
2329 for (i
= 0; i
< tx_ring
->count
; i
++) {
2330 buffer_info
= &tx_ring
->buffer_info
[i
];
2331 igb_unmap_and_free_tx_resource(adapter
, buffer_info
);
2334 size
= sizeof(struct igb_buffer
) * tx_ring
->count
;
2335 memset(tx_ring
->buffer_info
, 0, size
);
2337 /* Zero out the descriptor ring */
2339 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2341 tx_ring
->next_to_use
= 0;
2342 tx_ring
->next_to_clean
= 0;
2344 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
2345 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2349 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
2350 * @adapter: board private structure
2352 static void igb_clean_all_tx_rings(struct igb_adapter
*adapter
)
2356 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2357 igb_clean_tx_ring(&adapter
->tx_ring
[i
]);
2361 * igb_free_rx_resources - Free Rx Resources
2362 * @rx_ring: ring to clean the resources from
2364 * Free all receive software resources
2366 void igb_free_rx_resources(struct igb_ring
*rx_ring
)
2368 struct pci_dev
*pdev
= rx_ring
->adapter
->pdev
;
2370 igb_clean_rx_ring(rx_ring
);
2372 vfree(rx_ring
->buffer_info
);
2373 rx_ring
->buffer_info
= NULL
;
2375 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2377 rx_ring
->desc
= NULL
;
2381 * igb_free_all_rx_resources - Free Rx Resources for All Queues
2382 * @adapter: board private structure
2384 * Free all receive software resources
2386 static void igb_free_all_rx_resources(struct igb_adapter
*adapter
)
2390 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2391 igb_free_rx_resources(&adapter
->rx_ring
[i
]);
2395 * igb_clean_rx_ring - Free Rx Buffers per Queue
2396 * @rx_ring: ring to free buffers from
2398 static void igb_clean_rx_ring(struct igb_ring
*rx_ring
)
2400 struct igb_adapter
*adapter
= rx_ring
->adapter
;
2401 struct igb_buffer
*buffer_info
;
2402 struct pci_dev
*pdev
= adapter
->pdev
;
2406 if (!rx_ring
->buffer_info
)
2408 /* Free all the Rx ring sk_buffs */
2409 for (i
= 0; i
< rx_ring
->count
; i
++) {
2410 buffer_info
= &rx_ring
->buffer_info
[i
];
2411 if (buffer_info
->dma
) {
2412 if (adapter
->rx_ps_hdr_size
)
2413 pci_unmap_single(pdev
, buffer_info
->dma
,
2414 adapter
->rx_ps_hdr_size
,
2415 PCI_DMA_FROMDEVICE
);
2417 pci_unmap_single(pdev
, buffer_info
->dma
,
2418 adapter
->rx_buffer_len
,
2419 PCI_DMA_FROMDEVICE
);
2420 buffer_info
->dma
= 0;
2423 if (buffer_info
->skb
) {
2424 dev_kfree_skb(buffer_info
->skb
);
2425 buffer_info
->skb
= NULL
;
2427 if (buffer_info
->page
) {
2428 if (buffer_info
->page_dma
)
2429 pci_unmap_page(pdev
, buffer_info
->page_dma
,
2431 PCI_DMA_FROMDEVICE
);
2432 put_page(buffer_info
->page
);
2433 buffer_info
->page
= NULL
;
2434 buffer_info
->page_dma
= 0;
2435 buffer_info
->page_offset
= 0;
2439 size
= sizeof(struct igb_buffer
) * rx_ring
->count
;
2440 memset(rx_ring
->buffer_info
, 0, size
);
2442 /* Zero out the descriptor ring */
2443 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2445 rx_ring
->next_to_clean
= 0;
2446 rx_ring
->next_to_use
= 0;
2448 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
2449 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
2453 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
2454 * @adapter: board private structure
2456 static void igb_clean_all_rx_rings(struct igb_adapter
*adapter
)
2460 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2461 igb_clean_rx_ring(&adapter
->rx_ring
[i
]);
2465 * igb_set_mac - Change the Ethernet Address of the NIC
2466 * @netdev: network interface device structure
2467 * @p: pointer to an address structure
2469 * Returns 0 on success, negative on failure
2471 static int igb_set_mac(struct net_device
*netdev
, void *p
)
2473 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2474 struct e1000_hw
*hw
= &adapter
->hw
;
2475 struct sockaddr
*addr
= p
;
2477 if (!is_valid_ether_addr(addr
->sa_data
))
2478 return -EADDRNOTAVAIL
;
2480 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2481 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
2483 hw
->mac
.ops
.rar_set(hw
, hw
->mac
.addr
, 0);
2485 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, 0);
2491 * igb_set_multi - Multicast and Promiscuous mode set
2492 * @netdev: network interface device structure
2494 * The set_multi entry point is called whenever the multicast address
2495 * list or the network interface flags are updated. This routine is
2496 * responsible for configuring the hardware for proper multicast,
2497 * promiscuous mode, and all-multi behavior.
2499 static void igb_set_multi(struct net_device
*netdev
)
2501 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2502 struct e1000_hw
*hw
= &adapter
->hw
;
2503 struct e1000_mac_info
*mac
= &hw
->mac
;
2504 struct dev_mc_list
*mc_ptr
;
2505 u8
*mta_list
= NULL
;
2509 /* Check for Promiscuous and All Multicast modes */
2511 rctl
= rd32(E1000_RCTL
);
2513 if (netdev
->flags
& IFF_PROMISC
) {
2514 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2515 rctl
&= ~E1000_RCTL_VFE
;
2517 if (netdev
->flags
& IFF_ALLMULTI
) {
2518 rctl
|= E1000_RCTL_MPE
;
2519 rctl
&= ~E1000_RCTL_UPE
;
2521 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2522 rctl
|= E1000_RCTL_VFE
;
2524 wr32(E1000_RCTL
, rctl
);
2526 if (netdev
->mc_count
) {
2527 mta_list
= kzalloc(netdev
->mc_count
* 6, GFP_ATOMIC
);
2529 dev_err(&adapter
->pdev
->dev
,
2530 "failed to allocate multicast filter list\n");
2535 /* The shared function expects a packed array of only addresses. */
2536 mc_ptr
= netdev
->mc_list
;
2538 for (i
= 0; i
< netdev
->mc_count
; i
++) {
2541 memcpy(mta_list
+ (i
*ETH_ALEN
), mc_ptr
->dmi_addr
, ETH_ALEN
);
2542 mc_ptr
= mc_ptr
->next
;
2544 igb_update_mc_addr_list(hw
, mta_list
, i
,
2545 adapter
->vfs_allocated_count
+ 1,
2546 mac
->rar_entry_count
);
2548 igb_set_mc_list_pools(adapter
, i
, mac
->rar_entry_count
);
2549 igb_restore_vf_multicasts(adapter
);
2554 /* Need to wait a few seconds after link up to get diagnostic information from
2556 static void igb_update_phy_info(unsigned long data
)
2558 struct igb_adapter
*adapter
= (struct igb_adapter
*) data
;
2559 igb_get_phy_info(&adapter
->hw
);
2563 * igb_has_link - check shared code for link and determine up/down
2564 * @adapter: pointer to driver private info
2566 static bool igb_has_link(struct igb_adapter
*adapter
)
2568 struct e1000_hw
*hw
= &adapter
->hw
;
2569 bool link_active
= false;
2572 /* get_link_status is set on LSC (link status) interrupt or
2573 * rx sequence error interrupt. get_link_status will stay
2574 * false until the e1000_check_for_link establishes link
2575 * for copper adapters ONLY
2577 switch (hw
->phy
.media_type
) {
2578 case e1000_media_type_copper
:
2579 if (hw
->mac
.get_link_status
) {
2580 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2581 link_active
= !hw
->mac
.get_link_status
;
2586 case e1000_media_type_fiber
:
2587 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2588 link_active
= !!(rd32(E1000_STATUS
) & E1000_STATUS_LU
);
2590 case e1000_media_type_internal_serdes
:
2591 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2592 link_active
= hw
->mac
.serdes_has_link
;
2595 case e1000_media_type_unknown
:
2603 * igb_watchdog - Timer Call-back
2604 * @data: pointer to adapter cast into an unsigned long
2606 static void igb_watchdog(unsigned long data
)
2608 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
2609 /* Do the rest outside of interrupt context */
2610 schedule_work(&adapter
->watchdog_task
);
2613 static void igb_watchdog_task(struct work_struct
*work
)
2615 struct igb_adapter
*adapter
= container_of(work
,
2616 struct igb_adapter
, watchdog_task
);
2617 struct e1000_hw
*hw
= &adapter
->hw
;
2618 struct net_device
*netdev
= adapter
->netdev
;
2619 struct igb_ring
*tx_ring
= adapter
->tx_ring
;
2624 link
= igb_has_link(adapter
);
2625 if ((netif_carrier_ok(netdev
)) && link
)
2629 if (!netif_carrier_ok(netdev
)) {
2631 hw
->mac
.ops
.get_speed_and_duplex(&adapter
->hw
,
2632 &adapter
->link_speed
,
2633 &adapter
->link_duplex
);
2635 ctrl
= rd32(E1000_CTRL
);
2636 /* Links status message must follow this format */
2637 printk(KERN_INFO
"igb: %s NIC Link is Up %d Mbps %s, "
2638 "Flow Control: %s\n",
2640 adapter
->link_speed
,
2641 adapter
->link_duplex
== FULL_DUPLEX
?
2642 "Full Duplex" : "Half Duplex",
2643 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2644 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2645 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2646 E1000_CTRL_TFCE
) ? "TX" : "None")));
2648 /* tweak tx_queue_len according to speed/duplex and
2649 * adjust the timeout factor */
2650 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2651 adapter
->tx_timeout_factor
= 1;
2652 switch (adapter
->link_speed
) {
2654 netdev
->tx_queue_len
= 10;
2655 adapter
->tx_timeout_factor
= 14;
2658 netdev
->tx_queue_len
= 100;
2659 /* maybe add some timeout factor ? */
2663 netif_carrier_on(netdev
);
2664 netif_tx_wake_all_queues(netdev
);
2666 igb_ping_all_vfs(adapter
);
2668 /* link state has changed, schedule phy info update */
2669 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2670 mod_timer(&adapter
->phy_info_timer
,
2671 round_jiffies(jiffies
+ 2 * HZ
));
2674 if (netif_carrier_ok(netdev
)) {
2675 adapter
->link_speed
= 0;
2676 adapter
->link_duplex
= 0;
2677 /* Links status message must follow this format */
2678 printk(KERN_INFO
"igb: %s NIC Link is Down\n",
2680 netif_carrier_off(netdev
);
2681 netif_tx_stop_all_queues(netdev
);
2683 igb_ping_all_vfs(adapter
);
2685 /* link state has changed, schedule phy info update */
2686 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2687 mod_timer(&adapter
->phy_info_timer
,
2688 round_jiffies(jiffies
+ 2 * HZ
));
2693 igb_update_stats(adapter
);
2695 hw
->mac
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2696 adapter
->tpt_old
= adapter
->stats
.tpt
;
2697 hw
->mac
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2698 adapter
->colc_old
= adapter
->stats
.colc
;
2700 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
2701 adapter
->gorc_old
= adapter
->stats
.gorc
;
2702 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
2703 adapter
->gotc_old
= adapter
->stats
.gotc
;
2705 igb_update_adaptive(&adapter
->hw
);
2707 if (!netif_carrier_ok(netdev
)) {
2708 if (igb_desc_unused(tx_ring
) + 1 < tx_ring
->count
) {
2709 /* We've lost link, so the controller stops DMA,
2710 * but we've got queued Tx work that's never going
2711 * to get done, so reset controller to flush Tx.
2712 * (Do the reset outside of interrupt context). */
2713 adapter
->tx_timeout_count
++;
2714 schedule_work(&adapter
->reset_task
);
2718 /* Cause software interrupt to ensure rx ring is cleaned */
2719 if (adapter
->msix_entries
) {
2720 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2721 eics
|= adapter
->rx_ring
[i
].eims_value
;
2722 wr32(E1000_EICS
, eics
);
2724 wr32(E1000_ICS
, E1000_ICS_RXDMT0
);
2727 /* Force detection of hung controller every watchdog period */
2728 tx_ring
->detect_tx_hung
= true;
2730 /* Reset the timer */
2731 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2732 mod_timer(&adapter
->watchdog_timer
,
2733 round_jiffies(jiffies
+ 2 * HZ
));
2736 enum latency_range
{
2740 latency_invalid
= 255
2745 * igb_update_ring_itr - update the dynamic ITR value based on packet size
2747 * Stores a new ITR value based on strictly on packet size. This
2748 * algorithm is less sophisticated than that used in igb_update_itr,
2749 * due to the difficulty of synchronizing statistics across multiple
2750 * receive rings. The divisors and thresholds used by this fuction
2751 * were determined based on theoretical maximum wire speed and testing
2752 * data, in order to minimize response time while increasing bulk
2754 * This functionality is controlled by the InterruptThrottleRate module
2755 * parameter (see igb_param.c)
2756 * NOTE: This function is called only when operating in a multiqueue
2757 * receive environment.
2758 * @rx_ring: pointer to ring
2760 static void igb_update_ring_itr(struct igb_ring
*rx_ring
)
2762 int new_val
= rx_ring
->itr_val
;
2763 int avg_wire_size
= 0;
2764 struct igb_adapter
*adapter
= rx_ring
->adapter
;
2766 if (!rx_ring
->total_packets
)
2767 goto clear_counts
; /* no packets, so don't do anything */
2769 /* For non-gigabit speeds, just fix the interrupt rate at 4000
2770 * ints/sec - ITR timer value of 120 ticks.
2772 if (adapter
->link_speed
!= SPEED_1000
) {
2776 avg_wire_size
= rx_ring
->total_bytes
/ rx_ring
->total_packets
;
2778 /* Add 24 bytes to size to account for CRC, preamble, and gap */
2779 avg_wire_size
+= 24;
2781 /* Don't starve jumbo frames */
2782 avg_wire_size
= min(avg_wire_size
, 3000);
2784 /* Give a little boost to mid-size frames */
2785 if ((avg_wire_size
> 300) && (avg_wire_size
< 1200))
2786 new_val
= avg_wire_size
/ 3;
2788 new_val
= avg_wire_size
/ 2;
2791 if (new_val
!= rx_ring
->itr_val
) {
2792 rx_ring
->itr_val
= new_val
;
2793 rx_ring
->set_itr
= 1;
2796 rx_ring
->total_bytes
= 0;
2797 rx_ring
->total_packets
= 0;
2801 * igb_update_itr - update the dynamic ITR value based on statistics
2802 * Stores a new ITR value based on packets and byte
2803 * counts during the last interrupt. The advantage of per interrupt
2804 * computation is faster updates and more accurate ITR for the current
2805 * traffic pattern. Constants in this function were computed
2806 * based on theoretical maximum wire speed and thresholds were set based
2807 * on testing data as well as attempting to minimize response time
2808 * while increasing bulk throughput.
2809 * this functionality is controlled by the InterruptThrottleRate module
2810 * parameter (see igb_param.c)
2811 * NOTE: These calculations are only valid when operating in a single-
2812 * queue environment.
2813 * @adapter: pointer to adapter
2814 * @itr_setting: current adapter->itr
2815 * @packets: the number of packets during this measurement interval
2816 * @bytes: the number of bytes during this measurement interval
2818 static unsigned int igb_update_itr(struct igb_adapter
*adapter
, u16 itr_setting
,
2819 int packets
, int bytes
)
2821 unsigned int retval
= itr_setting
;
2824 goto update_itr_done
;
2826 switch (itr_setting
) {
2827 case lowest_latency
:
2828 /* handle TSO and jumbo frames */
2829 if (bytes
/packets
> 8000)
2830 retval
= bulk_latency
;
2831 else if ((packets
< 5) && (bytes
> 512))
2832 retval
= low_latency
;
2834 case low_latency
: /* 50 usec aka 20000 ints/s */
2835 if (bytes
> 10000) {
2836 /* this if handles the TSO accounting */
2837 if (bytes
/packets
> 8000) {
2838 retval
= bulk_latency
;
2839 } else if ((packets
< 10) || ((bytes
/packets
) > 1200)) {
2840 retval
= bulk_latency
;
2841 } else if ((packets
> 35)) {
2842 retval
= lowest_latency
;
2844 } else if (bytes
/packets
> 2000) {
2845 retval
= bulk_latency
;
2846 } else if (packets
<= 2 && bytes
< 512) {
2847 retval
= lowest_latency
;
2850 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2851 if (bytes
> 25000) {
2853 retval
= low_latency
;
2854 } else if (bytes
< 1500) {
2855 retval
= low_latency
;
2864 static void igb_set_itr(struct igb_adapter
*adapter
)
2867 u32 new_itr
= adapter
->itr
;
2869 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2870 if (adapter
->link_speed
!= SPEED_1000
) {
2876 adapter
->rx_itr
= igb_update_itr(adapter
,
2878 adapter
->rx_ring
->total_packets
,
2879 adapter
->rx_ring
->total_bytes
);
2881 if (adapter
->rx_ring
->buddy
) {
2882 adapter
->tx_itr
= igb_update_itr(adapter
,
2884 adapter
->tx_ring
->total_packets
,
2885 adapter
->tx_ring
->total_bytes
);
2886 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2888 current_itr
= adapter
->rx_itr
;
2891 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2892 if (adapter
->itr_setting
== 3 && current_itr
== lowest_latency
)
2893 current_itr
= low_latency
;
2895 switch (current_itr
) {
2896 /* counts and packets in update_itr are dependent on these numbers */
2897 case lowest_latency
:
2901 new_itr
= 20000; /* aka hwitr = ~200 */
2911 adapter
->rx_ring
->total_bytes
= 0;
2912 adapter
->rx_ring
->total_packets
= 0;
2913 if (adapter
->rx_ring
->buddy
) {
2914 adapter
->rx_ring
->buddy
->total_bytes
= 0;
2915 adapter
->rx_ring
->buddy
->total_packets
= 0;
2918 if (new_itr
!= adapter
->itr
) {
2919 /* this attempts to bias the interrupt rate towards Bulk
2920 * by adding intermediate steps when interrupt rate is
2922 new_itr
= new_itr
> adapter
->itr
?
2923 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2925 /* Don't write the value here; it resets the adapter's
2926 * internal timer, and causes us to delay far longer than
2927 * we should between interrupts. Instead, we write the ITR
2928 * value at the beginning of the next interrupt so the timing
2929 * ends up being correct.
2931 adapter
->itr
= new_itr
;
2932 adapter
->rx_ring
->itr_val
= 1000000000 / (new_itr
* 256);
2933 adapter
->rx_ring
->set_itr
= 1;
2940 #define IGB_TX_FLAGS_CSUM 0x00000001
2941 #define IGB_TX_FLAGS_VLAN 0x00000002
2942 #define IGB_TX_FLAGS_TSO 0x00000004
2943 #define IGB_TX_FLAGS_IPV4 0x00000008
2944 #define IGB_TX_FLAGS_TSTAMP 0x00000010
2945 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
2946 #define IGB_TX_FLAGS_VLAN_SHIFT 16
2948 static inline int igb_tso_adv(struct igb_adapter
*adapter
,
2949 struct igb_ring
*tx_ring
,
2950 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2952 struct e1000_adv_tx_context_desc
*context_desc
;
2955 struct igb_buffer
*buffer_info
;
2956 u32 info
= 0, tu_cmd
= 0;
2957 u32 mss_l4len_idx
, l4len
;
2960 if (skb_header_cloned(skb
)) {
2961 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2966 l4len
= tcp_hdrlen(skb
);
2969 if (skb
->protocol
== htons(ETH_P_IP
)) {
2970 struct iphdr
*iph
= ip_hdr(skb
);
2973 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2977 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
2978 ipv6_hdr(skb
)->payload_len
= 0;
2979 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2980 &ipv6_hdr(skb
)->daddr
,
2984 i
= tx_ring
->next_to_use
;
2986 buffer_info
= &tx_ring
->buffer_info
[i
];
2987 context_desc
= E1000_TX_CTXTDESC_ADV(*tx_ring
, i
);
2988 /* VLAN MACLEN IPLEN */
2989 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
2990 info
|= (tx_flags
& IGB_TX_FLAGS_VLAN_MASK
);
2991 info
|= (skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
);
2992 *hdr_len
+= skb_network_offset(skb
);
2993 info
|= skb_network_header_len(skb
);
2994 *hdr_len
+= skb_network_header_len(skb
);
2995 context_desc
->vlan_macip_lens
= cpu_to_le32(info
);
2997 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2998 tu_cmd
|= (E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
);
3000 if (skb
->protocol
== htons(ETH_P_IP
))
3001 tu_cmd
|= E1000_ADVTXD_TUCMD_IPV4
;
3002 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
3004 context_desc
->type_tucmd_mlhl
= cpu_to_le32(tu_cmd
);
3007 mss_l4len_idx
= (skb_shinfo(skb
)->gso_size
<< E1000_ADVTXD_MSS_SHIFT
);
3008 mss_l4len_idx
|= (l4len
<< E1000_ADVTXD_L4LEN_SHIFT
);
3010 /* For 82575, context index must be unique per ring. */
3011 if (adapter
->flags
& IGB_FLAG_NEED_CTX_IDX
)
3012 mss_l4len_idx
|= tx_ring
->queue_index
<< 4;
3014 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
3015 context_desc
->seqnum_seed
= 0;
3017 buffer_info
->time_stamp
= jiffies
;
3018 buffer_info
->next_to_watch
= i
;
3019 buffer_info
->dma
= 0;
3021 if (i
== tx_ring
->count
)
3024 tx_ring
->next_to_use
= i
;
3029 static inline bool igb_tx_csum_adv(struct igb_adapter
*adapter
,
3030 struct igb_ring
*tx_ring
,
3031 struct sk_buff
*skb
, u32 tx_flags
)
3033 struct e1000_adv_tx_context_desc
*context_desc
;
3035 struct igb_buffer
*buffer_info
;
3036 u32 info
= 0, tu_cmd
= 0;
3038 if ((skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
3039 (tx_flags
& IGB_TX_FLAGS_VLAN
)) {
3040 i
= tx_ring
->next_to_use
;
3041 buffer_info
= &tx_ring
->buffer_info
[i
];
3042 context_desc
= E1000_TX_CTXTDESC_ADV(*tx_ring
, i
);
3044 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
3045 info
|= (tx_flags
& IGB_TX_FLAGS_VLAN_MASK
);
3046 info
|= (skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
);
3047 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
3048 info
|= skb_network_header_len(skb
);
3050 context_desc
->vlan_macip_lens
= cpu_to_le32(info
);
3052 tu_cmd
|= (E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
);
3054 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
3057 if (skb
->protocol
== cpu_to_be16(ETH_P_8021Q
)) {
3058 const struct vlan_ethhdr
*vhdr
=
3059 (const struct vlan_ethhdr
*)skb
->data
;
3061 protocol
= vhdr
->h_vlan_encapsulated_proto
;
3063 protocol
= skb
->protocol
;
3067 case cpu_to_be16(ETH_P_IP
):
3068 tu_cmd
|= E1000_ADVTXD_TUCMD_IPV4
;
3069 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
3070 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
3072 case cpu_to_be16(ETH_P_IPV6
):
3073 /* XXX what about other V6 headers?? */
3074 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
3075 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
3078 if (unlikely(net_ratelimit()))
3079 dev_warn(&adapter
->pdev
->dev
,
3080 "partial checksum but proto=%x!\n",
3086 context_desc
->type_tucmd_mlhl
= cpu_to_le32(tu_cmd
);
3087 context_desc
->seqnum_seed
= 0;
3088 if (adapter
->flags
& IGB_FLAG_NEED_CTX_IDX
)
3089 context_desc
->mss_l4len_idx
=
3090 cpu_to_le32(tx_ring
->queue_index
<< 4);
3092 context_desc
->mss_l4len_idx
= 0;
3094 buffer_info
->time_stamp
= jiffies
;
3095 buffer_info
->next_to_watch
= i
;
3096 buffer_info
->dma
= 0;
3099 if (i
== tx_ring
->count
)
3101 tx_ring
->next_to_use
= i
;
3108 #define IGB_MAX_TXD_PWR 16
3109 #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
3111 static inline int igb_tx_map_adv(struct igb_adapter
*adapter
,
3112 struct igb_ring
*tx_ring
, struct sk_buff
*skb
,
3115 struct igb_buffer
*buffer_info
;
3116 unsigned int len
= skb_headlen(skb
);
3117 unsigned int count
= 0, i
;
3121 i
= tx_ring
->next_to_use
;
3123 if (skb_dma_map(&adapter
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
3124 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
3128 map
= skb_shinfo(skb
)->dma_maps
;
3130 buffer_info
= &tx_ring
->buffer_info
[i
];
3131 BUG_ON(len
>= IGB_MAX_DATA_PER_TXD
);
3132 buffer_info
->length
= len
;
3133 /* set time_stamp *before* dma to help avoid a possible race */
3134 buffer_info
->time_stamp
= jiffies
;
3135 buffer_info
->next_to_watch
= i
;
3136 buffer_info
->dma
= map
[count
];
3139 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++) {
3140 struct skb_frag_struct
*frag
;
3143 if (i
== tx_ring
->count
)
3146 frag
= &skb_shinfo(skb
)->frags
[f
];
3149 buffer_info
= &tx_ring
->buffer_info
[i
];
3150 BUG_ON(len
>= IGB_MAX_DATA_PER_TXD
);
3151 buffer_info
->length
= len
;
3152 buffer_info
->time_stamp
= jiffies
;
3153 buffer_info
->next_to_watch
= i
;
3154 buffer_info
->dma
= map
[count
];
3158 tx_ring
->buffer_info
[i
].skb
= skb
;
3159 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3164 static inline void igb_tx_queue_adv(struct igb_adapter
*adapter
,
3165 struct igb_ring
*tx_ring
,
3166 int tx_flags
, int count
, u32 paylen
,
3169 union e1000_adv_tx_desc
*tx_desc
= NULL
;
3170 struct igb_buffer
*buffer_info
;
3171 u32 olinfo_status
= 0, cmd_type_len
;
3174 cmd_type_len
= (E1000_ADVTXD_DTYP_DATA
| E1000_ADVTXD_DCMD_IFCS
|
3175 E1000_ADVTXD_DCMD_DEXT
);
3177 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
3178 cmd_type_len
|= E1000_ADVTXD_DCMD_VLE
;
3180 if (tx_flags
& IGB_TX_FLAGS_TSTAMP
)
3181 cmd_type_len
|= E1000_ADVTXD_MAC_TSTAMP
;
3183 if (tx_flags
& IGB_TX_FLAGS_TSO
) {
3184 cmd_type_len
|= E1000_ADVTXD_DCMD_TSE
;
3186 /* insert tcp checksum */
3187 olinfo_status
|= E1000_TXD_POPTS_TXSM
<< 8;
3189 /* insert ip checksum */
3190 if (tx_flags
& IGB_TX_FLAGS_IPV4
)
3191 olinfo_status
|= E1000_TXD_POPTS_IXSM
<< 8;
3193 } else if (tx_flags
& IGB_TX_FLAGS_CSUM
) {
3194 olinfo_status
|= E1000_TXD_POPTS_TXSM
<< 8;
3197 if ((adapter
->flags
& IGB_FLAG_NEED_CTX_IDX
) &&
3198 (tx_flags
& (IGB_TX_FLAGS_CSUM
| IGB_TX_FLAGS_TSO
|
3199 IGB_TX_FLAGS_VLAN
)))
3200 olinfo_status
|= tx_ring
->queue_index
<< 4;
3202 olinfo_status
|= ((paylen
- hdr_len
) << E1000_ADVTXD_PAYLEN_SHIFT
);
3204 i
= tx_ring
->next_to_use
;
3206 buffer_info
= &tx_ring
->buffer_info
[i
];
3207 tx_desc
= E1000_TX_DESC_ADV(*tx_ring
, i
);
3208 tx_desc
->read
.buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3209 tx_desc
->read
.cmd_type_len
=
3210 cpu_to_le32(cmd_type_len
| buffer_info
->length
);
3211 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
3213 if (i
== tx_ring
->count
)
3217 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(adapter
->txd_cmd
);
3218 /* Force memory writes to complete before letting h/w
3219 * know there are new descriptors to fetch. (Only
3220 * applicable for weak-ordered memory model archs,
3221 * such as IA-64). */
3224 tx_ring
->next_to_use
= i
;
3225 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3226 /* we need this if more than one processor can write to our tail
3227 * at a time, it syncronizes IO on IA64/Altix systems */
3231 static int __igb_maybe_stop_tx(struct net_device
*netdev
,
3232 struct igb_ring
*tx_ring
, int size
)
3234 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3236 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
3238 /* Herbert's original patch had:
3239 * smp_mb__after_netif_stop_queue();
3240 * but since that doesn't exist yet, just open code it. */
3243 /* We need to check again in a case another CPU has just
3244 * made room available. */
3245 if (igb_desc_unused(tx_ring
) < size
)
3249 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
3250 ++adapter
->restart_queue
;
3254 static int igb_maybe_stop_tx(struct net_device
*netdev
,
3255 struct igb_ring
*tx_ring
, int size
)
3257 if (igb_desc_unused(tx_ring
) >= size
)
3259 return __igb_maybe_stop_tx(netdev
, tx_ring
, size
);
3262 static int igb_xmit_frame_ring_adv(struct sk_buff
*skb
,
3263 struct net_device
*netdev
,
3264 struct igb_ring
*tx_ring
)
3266 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3268 unsigned int tx_flags
= 0;
3272 union skb_shared_tx
*shtx
;
3274 if (test_bit(__IGB_DOWN
, &adapter
->state
)) {
3275 dev_kfree_skb_any(skb
);
3276 return NETDEV_TX_OK
;
3279 if (skb
->len
<= 0) {
3280 dev_kfree_skb_any(skb
);
3281 return NETDEV_TX_OK
;
3284 /* need: 1 descriptor per page,
3285 * + 2 desc gap to keep tail from touching head,
3286 * + 1 desc for skb->data,
3287 * + 1 desc for context descriptor,
3288 * otherwise try next time */
3289 if (igb_maybe_stop_tx(netdev
, tx_ring
, skb_shinfo(skb
)->nr_frags
+ 4)) {
3290 /* this is a hard error */
3291 return NETDEV_TX_BUSY
;
3295 * TODO: check that there currently is no other packet with
3296 * time stamping in the queue
3298 * When doing time stamping, keep the connection to the socket
3299 * a while longer: it is still needed by skb_hwtstamp_tx(),
3300 * called either in igb_tx_hwtstamp() or by our caller when
3301 * doing software time stamping.
3304 if (unlikely(shtx
->hardware
)) {
3305 shtx
->in_progress
= 1;
3306 tx_flags
|= IGB_TX_FLAGS_TSTAMP
;
3309 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
3310 tx_flags
|= IGB_TX_FLAGS_VLAN
;
3311 tx_flags
|= (vlan_tx_tag_get(skb
) << IGB_TX_FLAGS_VLAN_SHIFT
);
3314 if (skb
->protocol
== htons(ETH_P_IP
))
3315 tx_flags
|= IGB_TX_FLAGS_IPV4
;
3317 first
= tx_ring
->next_to_use
;
3318 tso
= skb_is_gso(skb
) ? igb_tso_adv(adapter
, tx_ring
, skb
, tx_flags
,
3322 dev_kfree_skb_any(skb
);
3323 return NETDEV_TX_OK
;
3327 tx_flags
|= IGB_TX_FLAGS_TSO
;
3328 else if (igb_tx_csum_adv(adapter
, tx_ring
, skb
, tx_flags
) &&
3329 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3330 tx_flags
|= IGB_TX_FLAGS_CSUM
;
3333 * count reflects descriptors mapped, if 0 then mapping error
3334 * has occured and we need to rewind the descriptor queue
3336 count
= igb_tx_map_adv(adapter
, tx_ring
, skb
, first
);
3339 igb_tx_queue_adv(adapter
, tx_ring
, tx_flags
, count
,
3341 netdev
->trans_start
= jiffies
;
3342 /* Make sure there is space in the ring for the next send. */
3343 igb_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 4);
3345 dev_kfree_skb_any(skb
);
3346 tx_ring
->buffer_info
[first
].time_stamp
= 0;
3347 tx_ring
->next_to_use
= first
;
3350 return NETDEV_TX_OK
;
3353 static int igb_xmit_frame_adv(struct sk_buff
*skb
, struct net_device
*netdev
)
3355 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3356 struct igb_ring
*tx_ring
;
3359 r_idx
= skb
->queue_mapping
& (IGB_ABS_MAX_TX_QUEUES
- 1);
3360 tx_ring
= adapter
->multi_tx_table
[r_idx
];
3362 /* This goes back to the question of how to logically map a tx queue
3363 * to a flow. Right now, performance is impacted slightly negatively
3364 * if using multiple tx queues. If the stack breaks away from a
3365 * single qdisc implementation, we can look at this again. */
3366 return (igb_xmit_frame_ring_adv(skb
, netdev
, tx_ring
));
3370 * igb_tx_timeout - Respond to a Tx Hang
3371 * @netdev: network interface device structure
3373 static void igb_tx_timeout(struct net_device
*netdev
)
3375 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3376 struct e1000_hw
*hw
= &adapter
->hw
;
3378 /* Do the reset outside of interrupt context */
3379 adapter
->tx_timeout_count
++;
3380 schedule_work(&adapter
->reset_task
);
3382 (adapter
->eims_enable_mask
& ~adapter
->eims_other
));
3385 static void igb_reset_task(struct work_struct
*work
)
3387 struct igb_adapter
*adapter
;
3388 adapter
= container_of(work
, struct igb_adapter
, reset_task
);
3390 igb_reinit_locked(adapter
);
3394 * igb_get_stats - Get System Network Statistics
3395 * @netdev: network interface device structure
3397 * Returns the address of the device statistics structure.
3398 * The statistics are actually updated from the timer callback.
3400 static struct net_device_stats
*igb_get_stats(struct net_device
*netdev
)
3402 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3404 /* only return the current stats */
3405 return &adapter
->net_stats
;
3409 * igb_change_mtu - Change the Maximum Transfer Unit
3410 * @netdev: network interface device structure
3411 * @new_mtu: new value for maximum frame size
3413 * Returns 0 on success, negative on failure
3415 static int igb_change_mtu(struct net_device
*netdev
, int new_mtu
)
3417 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3418 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3420 if ((max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
) ||
3421 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3422 dev_err(&adapter
->pdev
->dev
, "Invalid MTU setting\n");
3426 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3427 dev_err(&adapter
->pdev
->dev
, "MTU > 9216 not supported.\n");
3431 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
3434 /* igb_down has a dependency on max_frame_size */
3435 adapter
->max_frame_size
= max_frame
;
3436 if (netif_running(netdev
))
3439 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3440 * means we reserve 2 more, this pushes us to allocate from the next
3442 * i.e. RXBUFFER_2048 --> size-4096 slab
3445 if (max_frame
<= IGB_RXBUFFER_256
)
3446 adapter
->rx_buffer_len
= IGB_RXBUFFER_256
;
3447 else if (max_frame
<= IGB_RXBUFFER_512
)
3448 adapter
->rx_buffer_len
= IGB_RXBUFFER_512
;
3449 else if (max_frame
<= IGB_RXBUFFER_1024
)
3450 adapter
->rx_buffer_len
= IGB_RXBUFFER_1024
;
3451 else if (max_frame
<= IGB_RXBUFFER_2048
)
3452 adapter
->rx_buffer_len
= IGB_RXBUFFER_2048
;
3454 #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
3455 adapter
->rx_buffer_len
= IGB_RXBUFFER_16384
;
3457 adapter
->rx_buffer_len
= PAGE_SIZE
/ 2;
3460 /* if sr-iov is enabled we need to force buffer size to 1K or larger */
3461 if (adapter
->vfs_allocated_count
&&
3462 (adapter
->rx_buffer_len
< IGB_RXBUFFER_1024
))
3463 adapter
->rx_buffer_len
= IGB_RXBUFFER_1024
;
3465 /* adjust allocation if LPE protects us, and we aren't using SBP */
3466 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
3467 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
))
3468 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3470 dev_info(&adapter
->pdev
->dev
, "changing MTU from %d to %d\n",
3471 netdev
->mtu
, new_mtu
);
3472 netdev
->mtu
= new_mtu
;
3474 if (netif_running(netdev
))
3479 clear_bit(__IGB_RESETTING
, &adapter
->state
);
3485 * igb_update_stats - Update the board statistics counters
3486 * @adapter: board private structure
3489 void igb_update_stats(struct igb_adapter
*adapter
)
3491 struct e1000_hw
*hw
= &adapter
->hw
;
3492 struct pci_dev
*pdev
= adapter
->pdev
;
3495 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3498 * Prevent stats update while adapter is being reset, or if the pci
3499 * connection is down.
3501 if (adapter
->link_speed
== 0)
3503 if (pci_channel_offline(pdev
))
3506 adapter
->stats
.crcerrs
+= rd32(E1000_CRCERRS
);
3507 adapter
->stats
.gprc
+= rd32(E1000_GPRC
);
3508 adapter
->stats
.gorc
+= rd32(E1000_GORCL
);
3509 rd32(E1000_GORCH
); /* clear GORCL */
3510 adapter
->stats
.bprc
+= rd32(E1000_BPRC
);
3511 adapter
->stats
.mprc
+= rd32(E1000_MPRC
);
3512 adapter
->stats
.roc
+= rd32(E1000_ROC
);
3514 adapter
->stats
.prc64
+= rd32(E1000_PRC64
);
3515 adapter
->stats
.prc127
+= rd32(E1000_PRC127
);
3516 adapter
->stats
.prc255
+= rd32(E1000_PRC255
);
3517 adapter
->stats
.prc511
+= rd32(E1000_PRC511
);
3518 adapter
->stats
.prc1023
+= rd32(E1000_PRC1023
);
3519 adapter
->stats
.prc1522
+= rd32(E1000_PRC1522
);
3520 adapter
->stats
.symerrs
+= rd32(E1000_SYMERRS
);
3521 adapter
->stats
.sec
+= rd32(E1000_SEC
);
3523 adapter
->stats
.mpc
+= rd32(E1000_MPC
);
3524 adapter
->stats
.scc
+= rd32(E1000_SCC
);
3525 adapter
->stats
.ecol
+= rd32(E1000_ECOL
);
3526 adapter
->stats
.mcc
+= rd32(E1000_MCC
);
3527 adapter
->stats
.latecol
+= rd32(E1000_LATECOL
);
3528 adapter
->stats
.dc
+= rd32(E1000_DC
);
3529 adapter
->stats
.rlec
+= rd32(E1000_RLEC
);
3530 adapter
->stats
.xonrxc
+= rd32(E1000_XONRXC
);
3531 adapter
->stats
.xontxc
+= rd32(E1000_XONTXC
);
3532 adapter
->stats
.xoffrxc
+= rd32(E1000_XOFFRXC
);
3533 adapter
->stats
.xofftxc
+= rd32(E1000_XOFFTXC
);
3534 adapter
->stats
.fcruc
+= rd32(E1000_FCRUC
);
3535 adapter
->stats
.gptc
+= rd32(E1000_GPTC
);
3536 adapter
->stats
.gotc
+= rd32(E1000_GOTCL
);
3537 rd32(E1000_GOTCH
); /* clear GOTCL */
3538 adapter
->stats
.rnbc
+= rd32(E1000_RNBC
);
3539 adapter
->stats
.ruc
+= rd32(E1000_RUC
);
3540 adapter
->stats
.rfc
+= rd32(E1000_RFC
);
3541 adapter
->stats
.rjc
+= rd32(E1000_RJC
);
3542 adapter
->stats
.tor
+= rd32(E1000_TORH
);
3543 adapter
->stats
.tot
+= rd32(E1000_TOTH
);
3544 adapter
->stats
.tpr
+= rd32(E1000_TPR
);
3546 adapter
->stats
.ptc64
+= rd32(E1000_PTC64
);
3547 adapter
->stats
.ptc127
+= rd32(E1000_PTC127
);
3548 adapter
->stats
.ptc255
+= rd32(E1000_PTC255
);
3549 adapter
->stats
.ptc511
+= rd32(E1000_PTC511
);
3550 adapter
->stats
.ptc1023
+= rd32(E1000_PTC1023
);
3551 adapter
->stats
.ptc1522
+= rd32(E1000_PTC1522
);
3553 adapter
->stats
.mptc
+= rd32(E1000_MPTC
);
3554 adapter
->stats
.bptc
+= rd32(E1000_BPTC
);
3556 /* used for adaptive IFS */
3558 hw
->mac
.tx_packet_delta
= rd32(E1000_TPT
);
3559 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
3560 hw
->mac
.collision_delta
= rd32(E1000_COLC
);
3561 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
3563 adapter
->stats
.algnerrc
+= rd32(E1000_ALGNERRC
);
3564 adapter
->stats
.rxerrc
+= rd32(E1000_RXERRC
);
3565 adapter
->stats
.tncrs
+= rd32(E1000_TNCRS
);
3566 adapter
->stats
.tsctc
+= rd32(E1000_TSCTC
);
3567 adapter
->stats
.tsctfc
+= rd32(E1000_TSCTFC
);
3569 adapter
->stats
.iac
+= rd32(E1000_IAC
);
3570 adapter
->stats
.icrxoc
+= rd32(E1000_ICRXOC
);
3571 adapter
->stats
.icrxptc
+= rd32(E1000_ICRXPTC
);
3572 adapter
->stats
.icrxatc
+= rd32(E1000_ICRXATC
);
3573 adapter
->stats
.ictxptc
+= rd32(E1000_ICTXPTC
);
3574 adapter
->stats
.ictxatc
+= rd32(E1000_ICTXATC
);
3575 adapter
->stats
.ictxqec
+= rd32(E1000_ICTXQEC
);
3576 adapter
->stats
.ictxqmtc
+= rd32(E1000_ICTXQMTC
);
3577 adapter
->stats
.icrxdmtc
+= rd32(E1000_ICRXDMTC
);
3579 /* Fill out the OS statistics structure */
3580 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3581 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3585 /* RLEC on some newer hardware can be incorrect so build
3586 * our own version based on RUC and ROC */
3587 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3588 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3589 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3590 adapter
->stats
.cexterr
;
3591 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.ruc
+
3593 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3594 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3595 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3598 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3599 adapter
->stats
.latecol
;
3600 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3601 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3602 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3604 /* Tx Dropped needs to be maintained elsewhere */
3607 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
3608 if ((adapter
->link_speed
== SPEED_1000
) &&
3609 (!igb_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3610 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3611 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3615 /* Management Stats */
3616 adapter
->stats
.mgptc
+= rd32(E1000_MGTPTC
);
3617 adapter
->stats
.mgprc
+= rd32(E1000_MGTPRC
);
3618 adapter
->stats
.mgpdc
+= rd32(E1000_MGTPDC
);
3621 static irqreturn_t
igb_msix_other(int irq
, void *data
)
3623 struct net_device
*netdev
= data
;
3624 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3625 struct e1000_hw
*hw
= &adapter
->hw
;
3626 u32 icr
= rd32(E1000_ICR
);
3628 /* reading ICR causes bit 31 of EICR to be cleared */
3630 if(icr
& E1000_ICR_DOUTSYNC
) {
3631 /* HW is reporting DMA is out of sync */
3632 adapter
->stats
.doosync
++;
3635 /* Check for a mailbox event */
3636 if (icr
& E1000_ICR_VMMB
)
3637 igb_msg_task(adapter
);
3639 if (icr
& E1000_ICR_LSC
) {
3640 hw
->mac
.get_link_status
= 1;
3641 /* guard against interrupt when we're going down */
3642 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3643 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3646 wr32(E1000_IMS
, E1000_IMS_LSC
| E1000_IMS_DOUTSYNC
| E1000_IMS_VMMB
);
3647 wr32(E1000_EIMS
, adapter
->eims_other
);
3652 static irqreturn_t
igb_msix_tx(int irq
, void *data
)
3654 struct igb_ring
*tx_ring
= data
;
3655 struct igb_adapter
*adapter
= tx_ring
->adapter
;
3656 struct e1000_hw
*hw
= &adapter
->hw
;
3658 #ifdef CONFIG_IGB_DCA
3659 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
3660 igb_update_tx_dca(tx_ring
);
3663 tx_ring
->total_bytes
= 0;
3664 tx_ring
->total_packets
= 0;
3666 /* auto mask will automatically reenable the interrupt when we write
3668 if (!igb_clean_tx_irq(tx_ring
))
3669 /* Ring was not completely cleaned, so fire another interrupt */
3670 wr32(E1000_EICS
, tx_ring
->eims_value
);
3672 wr32(E1000_EIMS
, tx_ring
->eims_value
);
3677 static void igb_write_itr(struct igb_ring
*ring
)
3679 struct e1000_hw
*hw
= &ring
->adapter
->hw
;
3680 if ((ring
->adapter
->itr_setting
& 3) && ring
->set_itr
) {
3681 switch (hw
->mac
.type
) {
3683 wr32(ring
->itr_register
, ring
->itr_val
|
3687 wr32(ring
->itr_register
, ring
->itr_val
|
3688 (ring
->itr_val
<< 16));
3695 static irqreturn_t
igb_msix_rx(int irq
, void *data
)
3697 struct igb_ring
*rx_ring
= data
;
3699 /* Write the ITR value calculated at the end of the
3700 * previous interrupt.
3703 igb_write_itr(rx_ring
);
3705 if (napi_schedule_prep(&rx_ring
->napi
))
3706 __napi_schedule(&rx_ring
->napi
);
3708 #ifdef CONFIG_IGB_DCA
3709 if (rx_ring
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
3710 igb_update_rx_dca(rx_ring
);
3715 #ifdef CONFIG_IGB_DCA
3716 static void igb_update_rx_dca(struct igb_ring
*rx_ring
)
3719 struct igb_adapter
*adapter
= rx_ring
->adapter
;
3720 struct e1000_hw
*hw
= &adapter
->hw
;
3721 int cpu
= get_cpu();
3722 int q
= rx_ring
->reg_idx
;
3724 if (rx_ring
->cpu
!= cpu
) {
3725 dca_rxctrl
= rd32(E1000_DCA_RXCTRL(q
));
3726 if (hw
->mac
.type
== e1000_82576
) {
3727 dca_rxctrl
&= ~E1000_DCA_RXCTRL_CPUID_MASK_82576
;
3728 dca_rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
3729 E1000_DCA_RXCTRL_CPUID_SHIFT
;
3731 dca_rxctrl
&= ~E1000_DCA_RXCTRL_CPUID_MASK
;
3732 dca_rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
3734 dca_rxctrl
|= E1000_DCA_RXCTRL_DESC_DCA_EN
;
3735 dca_rxctrl
|= E1000_DCA_RXCTRL_HEAD_DCA_EN
;
3736 dca_rxctrl
|= E1000_DCA_RXCTRL_DATA_DCA_EN
;
3737 wr32(E1000_DCA_RXCTRL(q
), dca_rxctrl
);
3743 static void igb_update_tx_dca(struct igb_ring
*tx_ring
)
3746 struct igb_adapter
*adapter
= tx_ring
->adapter
;
3747 struct e1000_hw
*hw
= &adapter
->hw
;
3748 int cpu
= get_cpu();
3749 int q
= tx_ring
->reg_idx
;
3751 if (tx_ring
->cpu
!= cpu
) {
3752 dca_txctrl
= rd32(E1000_DCA_TXCTRL(q
));
3753 if (hw
->mac
.type
== e1000_82576
) {
3754 dca_txctrl
&= ~E1000_DCA_TXCTRL_CPUID_MASK_82576
;
3755 dca_txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
3756 E1000_DCA_TXCTRL_CPUID_SHIFT
;
3758 dca_txctrl
&= ~E1000_DCA_TXCTRL_CPUID_MASK
;
3759 dca_txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
3761 dca_txctrl
|= E1000_DCA_TXCTRL_DESC_DCA_EN
;
3762 wr32(E1000_DCA_TXCTRL(q
), dca_txctrl
);
3768 static void igb_setup_dca(struct igb_adapter
*adapter
)
3772 if (!(adapter
->flags
& IGB_FLAG_DCA_ENABLED
))
3775 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3776 adapter
->tx_ring
[i
].cpu
= -1;
3777 igb_update_tx_dca(&adapter
->tx_ring
[i
]);
3779 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3780 adapter
->rx_ring
[i
].cpu
= -1;
3781 igb_update_rx_dca(&adapter
->rx_ring
[i
]);
3785 static int __igb_notify_dca(struct device
*dev
, void *data
)
3787 struct net_device
*netdev
= dev_get_drvdata(dev
);
3788 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3789 struct e1000_hw
*hw
= &adapter
->hw
;
3790 unsigned long event
= *(unsigned long *)data
;
3793 case DCA_PROVIDER_ADD
:
3794 /* if already enabled, don't do it again */
3795 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
3797 /* Always use CB2 mode, difference is masked
3798 * in the CB driver. */
3799 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_CB2
);
3800 if (dca_add_requester(dev
) == 0) {
3801 adapter
->flags
|= IGB_FLAG_DCA_ENABLED
;
3802 dev_info(&adapter
->pdev
->dev
, "DCA enabled\n");
3803 igb_setup_dca(adapter
);
3806 /* Fall Through since DCA is disabled. */
3807 case DCA_PROVIDER_REMOVE
:
3808 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
) {
3809 /* without this a class_device is left
3810 * hanging around in the sysfs model */
3811 dca_remove_requester(dev
);
3812 dev_info(&adapter
->pdev
->dev
, "DCA disabled\n");
3813 adapter
->flags
&= ~IGB_FLAG_DCA_ENABLED
;
3814 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_DISABLE
);
3822 static int igb_notify_dca(struct notifier_block
*nb
, unsigned long event
,
3827 ret_val
= driver_for_each_device(&igb_driver
.driver
, NULL
, &event
,
3830 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
3832 #endif /* CONFIG_IGB_DCA */
3834 static void igb_ping_all_vfs(struct igb_adapter
*adapter
)
3836 struct e1000_hw
*hw
= &adapter
->hw
;
3840 for (i
= 0 ; i
< adapter
->vfs_allocated_count
; i
++) {
3841 ping
= E1000_PF_CONTROL_MSG
;
3842 if (adapter
->vf_data
[i
].clear_to_send
)
3843 ping
|= E1000_VT_MSGTYPE_CTS
;
3844 igb_write_mbx(hw
, &ping
, 1, i
);
3848 static int igb_set_vf_multicasts(struct igb_adapter
*adapter
,
3849 u32
*msgbuf
, u32 vf
)
3851 int n
= (msgbuf
[0] & E1000_VT_MSGINFO_MASK
) >> E1000_VT_MSGINFO_SHIFT
;
3852 u16
*hash_list
= (u16
*)&msgbuf
[1];
3853 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
3856 /* only up to 30 hash values supported */
3860 /* salt away the number of multi cast addresses assigned
3861 * to this VF for later use to restore when the PF multi cast
3864 vf_data
->num_vf_mc_hashes
= n
;
3866 /* VFs are limited to using the MTA hash table for their multicast
3868 for (i
= 0; i
< n
; i
++)
3869 vf_data
->vf_mc_hashes
[i
] = hash_list
[i
];;
3871 /* Flush and reset the mta with the new values */
3872 igb_set_multi(adapter
->netdev
);
3877 static void igb_restore_vf_multicasts(struct igb_adapter
*adapter
)
3879 struct e1000_hw
*hw
= &adapter
->hw
;
3880 struct vf_data_storage
*vf_data
;
3883 for (i
= 0; i
< adapter
->vfs_allocated_count
; i
++) {
3884 vf_data
= &adapter
->vf_data
[i
];
3885 for (j
= 0; j
< vf_data
->num_vf_mc_hashes
; j
++)
3886 igb_mta_set(hw
, vf_data
->vf_mc_hashes
[j
]);
3890 static void igb_clear_vf_vfta(struct igb_adapter
*adapter
, u32 vf
)
3892 struct e1000_hw
*hw
= &adapter
->hw
;
3893 u32 pool_mask
, reg
, vid
;
3896 pool_mask
= 1 << (E1000_VLVF_POOLSEL_SHIFT
+ vf
);
3898 /* Find the vlan filter for this id */
3899 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
3900 reg
= rd32(E1000_VLVF(i
));
3902 /* remove the vf from the pool */
3905 /* if pool is empty then remove entry from vfta */
3906 if (!(reg
& E1000_VLVF_POOLSEL_MASK
) &&
3907 (reg
& E1000_VLVF_VLANID_ENABLE
)) {
3909 vid
= reg
& E1000_VLVF_VLANID_MASK
;
3910 igb_vfta_set(hw
, vid
, false);
3913 wr32(E1000_VLVF(i
), reg
);
3917 static s32
igb_vlvf_set(struct igb_adapter
*adapter
, u32 vid
, bool add
, u32 vf
)
3919 struct e1000_hw
*hw
= &adapter
->hw
;
3922 /* It is an error to call this function when VFs are not enabled */
3923 if (!adapter
->vfs_allocated_count
)
3926 /* Find the vlan filter for this id */
3927 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
3928 reg
= rd32(E1000_VLVF(i
));
3929 if ((reg
& E1000_VLVF_VLANID_ENABLE
) &&
3930 vid
== (reg
& E1000_VLVF_VLANID_MASK
))
3935 if (i
== E1000_VLVF_ARRAY_SIZE
) {
3936 /* Did not find a matching VLAN ID entry that was
3937 * enabled. Search for a free filter entry, i.e.
3938 * one without the enable bit set
3940 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
3941 reg
= rd32(E1000_VLVF(i
));
3942 if (!(reg
& E1000_VLVF_VLANID_ENABLE
))
3946 if (i
< E1000_VLVF_ARRAY_SIZE
) {
3947 /* Found an enabled/available entry */
3948 reg
|= 1 << (E1000_VLVF_POOLSEL_SHIFT
+ vf
);
3950 /* if !enabled we need to set this up in vfta */
3951 if (!(reg
& E1000_VLVF_VLANID_ENABLE
)) {
3952 /* add VID to filter table, if bit already set
3953 * PF must have added it outside of table */
3954 if (igb_vfta_set(hw
, vid
, true))
3955 reg
|= 1 << (E1000_VLVF_POOLSEL_SHIFT
+
3956 adapter
->vfs_allocated_count
);
3957 reg
|= E1000_VLVF_VLANID_ENABLE
;
3959 reg
&= ~E1000_VLVF_VLANID_MASK
;
3962 wr32(E1000_VLVF(i
), reg
);
3966 if (i
< E1000_VLVF_ARRAY_SIZE
) {
3967 /* remove vf from the pool */
3968 reg
&= ~(1 << (E1000_VLVF_POOLSEL_SHIFT
+ vf
));
3969 /* if pool is empty then remove entry from vfta */
3970 if (!(reg
& E1000_VLVF_POOLSEL_MASK
)) {
3972 igb_vfta_set(hw
, vid
, false);
3974 wr32(E1000_VLVF(i
), reg
);
3981 static int igb_set_vf_vlan(struct igb_adapter
*adapter
, u32
*msgbuf
, u32 vf
)
3983 int add
= (msgbuf
[0] & E1000_VT_MSGINFO_MASK
) >> E1000_VT_MSGINFO_SHIFT
;
3984 int vid
= (msgbuf
[1] & E1000_VLVF_VLANID_MASK
);
3986 return igb_vlvf_set(adapter
, vid
, add
, vf
);
3989 static inline void igb_vf_reset_event(struct igb_adapter
*adapter
, u32 vf
)
3991 struct e1000_hw
*hw
= &adapter
->hw
;
3993 /* disable mailbox functionality for vf */
3994 adapter
->vf_data
[vf
].clear_to_send
= false;
3996 /* reset offloads to defaults */
3997 igb_set_vmolr(hw
, vf
);
3999 /* reset vlans for device */
4000 igb_clear_vf_vfta(adapter
, vf
);
4002 /* reset multicast table array for vf */
4003 adapter
->vf_data
[vf
].num_vf_mc_hashes
= 0;
4005 /* Flush and reset the mta with the new values */
4006 igb_set_multi(adapter
->netdev
);
4009 static inline void igb_vf_reset_msg(struct igb_adapter
*adapter
, u32 vf
)
4011 struct e1000_hw
*hw
= &adapter
->hw
;
4012 unsigned char *vf_mac
= adapter
->vf_data
[vf
].vf_mac_addresses
;
4014 u8
*addr
= (u8
*)(&msgbuf
[1]);
4016 /* process all the same items cleared in a function level reset */
4017 igb_vf_reset_event(adapter
, vf
);
4019 /* set vf mac address */
4020 igb_rar_set(hw
, vf_mac
, vf
+ 1);
4021 igb_set_rah_pool(hw
, vf
, vf
+ 1);
4023 /* enable transmit and receive for vf */
4024 reg
= rd32(E1000_VFTE
);
4025 wr32(E1000_VFTE
, reg
| (1 << vf
));
4026 reg
= rd32(E1000_VFRE
);
4027 wr32(E1000_VFRE
, reg
| (1 << vf
));
4029 /* enable mailbox functionality for vf */
4030 adapter
->vf_data
[vf
].clear_to_send
= true;
4032 /* reply to reset with ack and vf mac address */
4033 msgbuf
[0] = E1000_VF_RESET
| E1000_VT_MSGTYPE_ACK
;
4034 memcpy(addr
, vf_mac
, 6);
4035 igb_write_mbx(hw
, msgbuf
, 3, vf
);
4038 static int igb_set_vf_mac_addr(struct igb_adapter
*adapter
, u32
*msg
, int vf
)
4040 unsigned char *addr
= (char *)&msg
[1];
4043 if (is_valid_ether_addr(addr
))
4044 err
= igb_set_vf_mac(adapter
, vf
, addr
);
4050 static void igb_rcv_ack_from_vf(struct igb_adapter
*adapter
, u32 vf
)
4052 struct e1000_hw
*hw
= &adapter
->hw
;
4053 u32 msg
= E1000_VT_MSGTYPE_NACK
;
4055 /* if device isn't clear to send it shouldn't be reading either */
4056 if (!adapter
->vf_data
[vf
].clear_to_send
)
4057 igb_write_mbx(hw
, &msg
, 1, vf
);
4061 static void igb_msg_task(struct igb_adapter
*adapter
)
4063 struct e1000_hw
*hw
= &adapter
->hw
;
4066 for (vf
= 0; vf
< adapter
->vfs_allocated_count
; vf
++) {
4067 /* process any reset requests */
4068 if (!igb_check_for_rst(hw
, vf
)) {
4069 adapter
->vf_data
[vf
].clear_to_send
= false;
4070 igb_vf_reset_event(adapter
, vf
);
4073 /* process any messages pending */
4074 if (!igb_check_for_msg(hw
, vf
))
4075 igb_rcv_msg_from_vf(adapter
, vf
);
4077 /* process any acks */
4078 if (!igb_check_for_ack(hw
, vf
))
4079 igb_rcv_ack_from_vf(adapter
, vf
);
4084 static int igb_rcv_msg_from_vf(struct igb_adapter
*adapter
, u32 vf
)
4086 u32 mbx_size
= E1000_VFMAILBOX_SIZE
;
4087 u32 msgbuf
[mbx_size
];
4088 struct e1000_hw
*hw
= &adapter
->hw
;
4091 retval
= igb_read_mbx(hw
, msgbuf
, mbx_size
, vf
);
4094 dev_err(&adapter
->pdev
->dev
,
4095 "Error receiving message from VF\n");
4097 /* this is a message we already processed, do nothing */
4098 if (msgbuf
[0] & (E1000_VT_MSGTYPE_ACK
| E1000_VT_MSGTYPE_NACK
))
4102 * until the vf completes a reset it should not be
4103 * allowed to start any configuration.
4106 if (msgbuf
[0] == E1000_VF_RESET
) {
4107 igb_vf_reset_msg(adapter
, vf
);
4112 if (!adapter
->vf_data
[vf
].clear_to_send
) {
4113 msgbuf
[0] |= E1000_VT_MSGTYPE_NACK
;
4114 igb_write_mbx(hw
, msgbuf
, 1, vf
);
4118 switch ((msgbuf
[0] & 0xFFFF)) {
4119 case E1000_VF_SET_MAC_ADDR
:
4120 retval
= igb_set_vf_mac_addr(adapter
, msgbuf
, vf
);
4122 case E1000_VF_SET_MULTICAST
:
4123 retval
= igb_set_vf_multicasts(adapter
, msgbuf
, vf
);
4125 case E1000_VF_SET_LPE
:
4126 retval
= igb_set_vf_rlpml(adapter
, msgbuf
[1], vf
);
4128 case E1000_VF_SET_VLAN
:
4129 retval
= igb_set_vf_vlan(adapter
, msgbuf
, vf
);
4132 dev_err(&adapter
->pdev
->dev
, "Unhandled Msg %08x\n", msgbuf
[0]);
4137 /* notify the VF of the results of what it sent us */
4139 msgbuf
[0] |= E1000_VT_MSGTYPE_NACK
;
4141 msgbuf
[0] |= E1000_VT_MSGTYPE_ACK
;
4143 msgbuf
[0] |= E1000_VT_MSGTYPE_CTS
;
4145 igb_write_mbx(hw
, msgbuf
, 1, vf
);
4151 * igb_intr_msi - Interrupt Handler
4152 * @irq: interrupt number
4153 * @data: pointer to a network interface device structure
4155 static irqreturn_t
igb_intr_msi(int irq
, void *data
)
4157 struct net_device
*netdev
= data
;
4158 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4159 struct e1000_hw
*hw
= &adapter
->hw
;
4160 /* read ICR disables interrupts using IAM */
4161 u32 icr
= rd32(E1000_ICR
);
4163 igb_write_itr(adapter
->rx_ring
);
4165 if(icr
& E1000_ICR_DOUTSYNC
) {
4166 /* HW is reporting DMA is out of sync */
4167 adapter
->stats
.doosync
++;
4170 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
4171 hw
->mac
.get_link_status
= 1;
4172 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
4173 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
4176 napi_schedule(&adapter
->rx_ring
[0].napi
);
4182 * igb_intr - Legacy Interrupt Handler
4183 * @irq: interrupt number
4184 * @data: pointer to a network interface device structure
4186 static irqreturn_t
igb_intr(int irq
, void *data
)
4188 struct net_device
*netdev
= data
;
4189 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4190 struct e1000_hw
*hw
= &adapter
->hw
;
4191 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
4192 * need for the IMC write */
4193 u32 icr
= rd32(E1000_ICR
);
4195 return IRQ_NONE
; /* Not our interrupt */
4197 igb_write_itr(adapter
->rx_ring
);
4199 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
4200 * not set, then the adapter didn't send an interrupt */
4201 if (!(icr
& E1000_ICR_INT_ASSERTED
))
4204 if(icr
& E1000_ICR_DOUTSYNC
) {
4205 /* HW is reporting DMA is out of sync */
4206 adapter
->stats
.doosync
++;
4209 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
4210 hw
->mac
.get_link_status
= 1;
4211 /* guard against interrupt when we're going down */
4212 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
4213 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
4216 napi_schedule(&adapter
->rx_ring
[0].napi
);
4221 static inline void igb_rx_irq_enable(struct igb_ring
*rx_ring
)
4223 struct igb_adapter
*adapter
= rx_ring
->adapter
;
4224 struct e1000_hw
*hw
= &adapter
->hw
;
4226 if (adapter
->itr_setting
& 3) {
4227 if (adapter
->num_rx_queues
== 1)
4228 igb_set_itr(adapter
);
4230 igb_update_ring_itr(rx_ring
);
4233 if (!test_bit(__IGB_DOWN
, &adapter
->state
)) {
4234 if (adapter
->msix_entries
)
4235 wr32(E1000_EIMS
, rx_ring
->eims_value
);
4237 igb_irq_enable(adapter
);
4242 * igb_poll - NAPI Rx polling callback
4243 * @napi: napi polling structure
4244 * @budget: count of how many packets we should handle
4246 static int igb_poll(struct napi_struct
*napi
, int budget
)
4248 struct igb_ring
*rx_ring
= container_of(napi
, struct igb_ring
, napi
);
4251 #ifdef CONFIG_IGB_DCA
4252 if (rx_ring
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
4253 igb_update_rx_dca(rx_ring
);
4255 igb_clean_rx_irq_adv(rx_ring
, &work_done
, budget
);
4257 if (rx_ring
->buddy
) {
4258 #ifdef CONFIG_IGB_DCA
4259 if (rx_ring
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
4260 igb_update_tx_dca(rx_ring
->buddy
);
4262 if (!igb_clean_tx_irq(rx_ring
->buddy
))
4266 /* If not enough Rx work done, exit the polling mode */
4267 if (work_done
< budget
) {
4268 napi_complete(napi
);
4269 igb_rx_irq_enable(rx_ring
);
4276 * igb_hwtstamp - utility function which checks for TX time stamp
4277 * @adapter: board private structure
4278 * @skb: packet that was just sent
4280 * If we were asked to do hardware stamping and such a time stamp is
4281 * available, then it must have been for this skb here because we only
4282 * allow only one such packet into the queue.
4284 static void igb_tx_hwtstamp(struct igb_adapter
*adapter
, struct sk_buff
*skb
)
4286 union skb_shared_tx
*shtx
= skb_tx(skb
);
4287 struct e1000_hw
*hw
= &adapter
->hw
;
4289 if (unlikely(shtx
->hardware
)) {
4290 u32 valid
= rd32(E1000_TSYNCTXCTL
) & E1000_TSYNCTXCTL_VALID
;
4292 u64 regval
= rd32(E1000_TXSTMPL
);
4294 struct skb_shared_hwtstamps shhwtstamps
;
4296 memset(&shhwtstamps
, 0, sizeof(shhwtstamps
));
4297 regval
|= (u64
)rd32(E1000_TXSTMPH
) << 32;
4298 ns
= timecounter_cyc2time(&adapter
->clock
,
4300 timecompare_update(&adapter
->compare
, ns
);
4301 shhwtstamps
.hwtstamp
= ns_to_ktime(ns
);
4302 shhwtstamps
.syststamp
=
4303 timecompare_transform(&adapter
->compare
, ns
);
4304 skb_tstamp_tx(skb
, &shhwtstamps
);
4310 * igb_clean_tx_irq - Reclaim resources after transmit completes
4311 * @adapter: board private structure
4312 * returns true if ring is completely cleaned
4314 static bool igb_clean_tx_irq(struct igb_ring
*tx_ring
)
4316 struct igb_adapter
*adapter
= tx_ring
->adapter
;
4317 struct net_device
*netdev
= adapter
->netdev
;
4318 struct e1000_hw
*hw
= &adapter
->hw
;
4319 struct igb_buffer
*buffer_info
;
4320 struct sk_buff
*skb
;
4321 union e1000_adv_tx_desc
*tx_desc
, *eop_desc
;
4322 unsigned int total_bytes
= 0, total_packets
= 0;
4323 unsigned int i
, eop
, count
= 0;
4324 bool cleaned
= false;
4326 i
= tx_ring
->next_to_clean
;
4327 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4328 eop_desc
= E1000_TX_DESC_ADV(*tx_ring
, eop
);
4330 while ((eop_desc
->wb
.status
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
4331 (count
< tx_ring
->count
)) {
4332 for (cleaned
= false; !cleaned
; count
++) {
4333 tx_desc
= E1000_TX_DESC_ADV(*tx_ring
, i
);
4334 buffer_info
= &tx_ring
->buffer_info
[i
];
4335 cleaned
= (i
== eop
);
4336 skb
= buffer_info
->skb
;
4339 unsigned int segs
, bytecount
;
4340 /* gso_segs is currently only valid for tcp */
4341 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
4342 /* multiply data chunks by size of headers */
4343 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
4345 total_packets
+= segs
;
4346 total_bytes
+= bytecount
;
4348 igb_tx_hwtstamp(adapter
, skb
);
4351 igb_unmap_and_free_tx_resource(adapter
, buffer_info
);
4352 tx_desc
->wb
.status
= 0;
4355 if (i
== tx_ring
->count
)
4358 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4359 eop_desc
= E1000_TX_DESC_ADV(*tx_ring
, eop
);
4362 tx_ring
->next_to_clean
= i
;
4364 if (unlikely(count
&&
4365 netif_carrier_ok(netdev
) &&
4366 igb_desc_unused(tx_ring
) >= IGB_TX_QUEUE_WAKE
)) {
4367 /* Make sure that anybody stopping the queue after this
4368 * sees the new next_to_clean.
4371 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
4372 !(test_bit(__IGB_DOWN
, &adapter
->state
))) {
4373 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
4374 ++adapter
->restart_queue
;
4378 if (tx_ring
->detect_tx_hung
) {
4379 /* Detect a transmit hang in hardware, this serializes the
4380 * check with the clearing of time_stamp and movement of i */
4381 tx_ring
->detect_tx_hung
= false;
4382 if (tx_ring
->buffer_info
[i
].time_stamp
&&
4383 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+
4384 (adapter
->tx_timeout_factor
* HZ
))
4385 && !(rd32(E1000_STATUS
) &
4386 E1000_STATUS_TXOFF
)) {
4388 /* detected Tx unit hang */
4389 dev_err(&adapter
->pdev
->dev
,
4390 "Detected Tx Unit Hang\n"
4394 " next_to_use <%x>\n"
4395 " next_to_clean <%x>\n"
4396 "buffer_info[next_to_clean]\n"
4397 " time_stamp <%lx>\n"
4398 " next_to_watch <%x>\n"
4400 " desc.status <%x>\n",
4401 tx_ring
->queue_index
,
4402 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
4403 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
4404 tx_ring
->next_to_use
,
4405 tx_ring
->next_to_clean
,
4406 tx_ring
->buffer_info
[i
].time_stamp
,
4409 eop_desc
->wb
.status
);
4410 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
4413 tx_ring
->total_bytes
+= total_bytes
;
4414 tx_ring
->total_packets
+= total_packets
;
4415 tx_ring
->tx_stats
.bytes
+= total_bytes
;
4416 tx_ring
->tx_stats
.packets
+= total_packets
;
4417 adapter
->net_stats
.tx_bytes
+= total_bytes
;
4418 adapter
->net_stats
.tx_packets
+= total_packets
;
4419 return (count
< tx_ring
->count
);
4423 * igb_receive_skb - helper function to handle rx indications
4424 * @ring: pointer to receive ring receving this packet
4425 * @status: descriptor status field as written by hardware
4426 * @rx_desc: receive descriptor containing vlan and type information.
4427 * @skb: pointer to sk_buff to be indicated to stack
4429 static void igb_receive_skb(struct igb_ring
*ring
, u8 status
,
4430 union e1000_adv_rx_desc
* rx_desc
,
4431 struct sk_buff
*skb
)
4433 struct igb_adapter
* adapter
= ring
->adapter
;
4434 bool vlan_extracted
= (adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
));
4436 skb_record_rx_queue(skb
, ring
->queue_index
);
4437 if (skb
->ip_summed
== CHECKSUM_UNNECESSARY
) {
4439 vlan_gro_receive(&ring
->napi
, adapter
->vlgrp
,
4440 le16_to_cpu(rx_desc
->wb
.upper
.vlan
),
4443 napi_gro_receive(&ring
->napi
, skb
);
4446 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4447 le16_to_cpu(rx_desc
->wb
.upper
.vlan
));
4449 netif_receive_skb(skb
);
4453 static inline void igb_rx_checksum_adv(struct igb_adapter
*adapter
,
4454 u32 status_err
, struct sk_buff
*skb
)
4456 skb
->ip_summed
= CHECKSUM_NONE
;
4458 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
4459 if ((status_err
& E1000_RXD_STAT_IXSM
) || !adapter
->rx_csum
)
4461 /* TCP/UDP checksum error bit is set */
4463 (E1000_RXDEXT_STATERR_TCPE
| E1000_RXDEXT_STATERR_IPE
)) {
4464 /* let the stack verify checksum errors */
4465 adapter
->hw_csum_err
++;
4468 /* It must be a TCP or UDP packet with a valid checksum */
4469 if (status_err
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
))
4470 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4472 adapter
->hw_csum_good
++;
4475 static bool igb_clean_rx_irq_adv(struct igb_ring
*rx_ring
,
4476 int *work_done
, int budget
)
4478 struct igb_adapter
*adapter
= rx_ring
->adapter
;
4479 struct net_device
*netdev
= adapter
->netdev
;
4480 struct e1000_hw
*hw
= &adapter
->hw
;
4481 struct pci_dev
*pdev
= adapter
->pdev
;
4482 union e1000_adv_rx_desc
*rx_desc
, *next_rxd
;
4483 struct igb_buffer
*buffer_info
, *next_buffer
;
4484 struct sk_buff
*skb
;
4485 bool cleaned
= false;
4486 int cleaned_count
= 0;
4487 unsigned int total_bytes
= 0, total_packets
= 0;
4489 u32 length
, hlen
, staterr
;
4491 i
= rx_ring
->next_to_clean
;
4492 buffer_info
= &rx_ring
->buffer_info
[i
];
4493 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
4494 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
4496 while (staterr
& E1000_RXD_STAT_DD
) {
4497 if (*work_done
>= budget
)
4501 skb
= buffer_info
->skb
;
4502 prefetch(skb
->data
- NET_IP_ALIGN
);
4503 buffer_info
->skb
= NULL
;
4506 if (i
== rx_ring
->count
)
4508 next_rxd
= E1000_RX_DESC_ADV(*rx_ring
, i
);
4510 next_buffer
= &rx_ring
->buffer_info
[i
];
4512 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
4516 if (!adapter
->rx_ps_hdr_size
) {
4517 pci_unmap_single(pdev
, buffer_info
->dma
,
4518 adapter
->rx_buffer_len
+
4520 PCI_DMA_FROMDEVICE
);
4521 skb_put(skb
, length
);
4525 /* HW will not DMA in data larger than the given buffer, even
4526 * if it parses the (NFS, of course) header to be larger. In
4527 * that case, it fills the header buffer and spills the rest
4530 hlen
= (le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hdr_info
) &
4531 E1000_RXDADV_HDRBUFLEN_MASK
) >> E1000_RXDADV_HDRBUFLEN_SHIFT
;
4532 if (hlen
> adapter
->rx_ps_hdr_size
)
4533 hlen
= adapter
->rx_ps_hdr_size
;
4535 if (!skb_shinfo(skb
)->nr_frags
) {
4536 pci_unmap_single(pdev
, buffer_info
->dma
,
4537 adapter
->rx_ps_hdr_size
+ NET_IP_ALIGN
,
4538 PCI_DMA_FROMDEVICE
);
4543 pci_unmap_page(pdev
, buffer_info
->page_dma
,
4544 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
4545 buffer_info
->page_dma
= 0;
4547 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
++,
4549 buffer_info
->page_offset
,
4552 if ((adapter
->rx_buffer_len
> (PAGE_SIZE
/ 2)) ||
4553 (page_count(buffer_info
->page
) != 1))
4554 buffer_info
->page
= NULL
;
4556 get_page(buffer_info
->page
);
4559 skb
->data_len
+= length
;
4561 skb
->truesize
+= length
;
4564 if (!(staterr
& E1000_RXD_STAT_EOP
)) {
4565 buffer_info
->skb
= next_buffer
->skb
;
4566 buffer_info
->dma
= next_buffer
->dma
;
4567 next_buffer
->skb
= skb
;
4568 next_buffer
->dma
= 0;
4573 * If this bit is set, then the RX registers contain
4574 * the time stamp. No other packet will be time
4575 * stamped until we read these registers, so read the
4576 * registers to make them available again. Because
4577 * only one packet can be time stamped at a time, we
4578 * know that the register values must belong to this
4579 * one here and therefore we don't need to compare
4580 * any of the additional attributes stored for it.
4582 * If nothing went wrong, then it should have a
4583 * skb_shared_tx that we can turn into a
4584 * skb_shared_hwtstamps.
4586 * TODO: can time stamping be triggered (thus locking
4587 * the registers) without the packet reaching this point
4588 * here? In that case RX time stamping would get stuck.
4590 * TODO: in "time stamp all packets" mode this bit is
4591 * not set. Need a global flag for this mode and then
4592 * always read the registers. Cannot be done without
4595 if (unlikely(staterr
& E1000_RXD_STAT_TS
)) {
4598 struct skb_shared_hwtstamps
*shhwtstamps
=
4601 WARN(!(rd32(E1000_TSYNCRXCTL
) & E1000_TSYNCRXCTL_VALID
),
4602 "igb: no RX time stamp available for time stamped packet");
4603 regval
= rd32(E1000_RXSTMPL
);
4604 regval
|= (u64
)rd32(E1000_RXSTMPH
) << 32;
4605 ns
= timecounter_cyc2time(&adapter
->clock
, regval
);
4606 timecompare_update(&adapter
->compare
, ns
);
4607 memset(shhwtstamps
, 0, sizeof(*shhwtstamps
));
4608 shhwtstamps
->hwtstamp
= ns_to_ktime(ns
);
4609 shhwtstamps
->syststamp
=
4610 timecompare_transform(&adapter
->compare
, ns
);
4613 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
4614 dev_kfree_skb_irq(skb
);
4618 total_bytes
+= skb
->len
;
4621 igb_rx_checksum_adv(adapter
, staterr
, skb
);
4623 skb
->protocol
= eth_type_trans(skb
, netdev
);
4625 igb_receive_skb(rx_ring
, staterr
, rx_desc
, skb
);
4628 rx_desc
->wb
.upper
.status_error
= 0;
4630 /* return some buffers to hardware, one at a time is too slow */
4631 if (cleaned_count
>= IGB_RX_BUFFER_WRITE
) {
4632 igb_alloc_rx_buffers_adv(rx_ring
, cleaned_count
);
4636 /* use prefetched values */
4638 buffer_info
= next_buffer
;
4639 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
4642 rx_ring
->next_to_clean
= i
;
4643 cleaned_count
= igb_desc_unused(rx_ring
);
4646 igb_alloc_rx_buffers_adv(rx_ring
, cleaned_count
);
4648 rx_ring
->total_packets
+= total_packets
;
4649 rx_ring
->total_bytes
+= total_bytes
;
4650 rx_ring
->rx_stats
.packets
+= total_packets
;
4651 rx_ring
->rx_stats
.bytes
+= total_bytes
;
4652 adapter
->net_stats
.rx_bytes
+= total_bytes
;
4653 adapter
->net_stats
.rx_packets
+= total_packets
;
4658 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
4659 * @adapter: address of board private structure
4661 static void igb_alloc_rx_buffers_adv(struct igb_ring
*rx_ring
,
4664 struct igb_adapter
*adapter
= rx_ring
->adapter
;
4665 struct net_device
*netdev
= adapter
->netdev
;
4666 struct pci_dev
*pdev
= adapter
->pdev
;
4667 union e1000_adv_rx_desc
*rx_desc
;
4668 struct igb_buffer
*buffer_info
;
4669 struct sk_buff
*skb
;
4673 i
= rx_ring
->next_to_use
;
4674 buffer_info
= &rx_ring
->buffer_info
[i
];
4676 if (adapter
->rx_ps_hdr_size
)
4677 bufsz
= adapter
->rx_ps_hdr_size
;
4679 bufsz
= adapter
->rx_buffer_len
;
4680 bufsz
+= NET_IP_ALIGN
;
4682 while (cleaned_count
--) {
4683 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
4685 if (adapter
->rx_ps_hdr_size
&& !buffer_info
->page_dma
) {
4686 if (!buffer_info
->page
) {
4687 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
4688 if (!buffer_info
->page
) {
4689 adapter
->alloc_rx_buff_failed
++;
4692 buffer_info
->page_offset
= 0;
4694 buffer_info
->page_offset
^= PAGE_SIZE
/ 2;
4696 buffer_info
->page_dma
=
4697 pci_map_page(pdev
, buffer_info
->page
,
4698 buffer_info
->page_offset
,
4700 PCI_DMA_FROMDEVICE
);
4703 if (!buffer_info
->skb
) {
4704 skb
= netdev_alloc_skb(netdev
, bufsz
);
4706 adapter
->alloc_rx_buff_failed
++;
4710 /* Make buffer alignment 2 beyond a 16 byte boundary
4711 * this will result in a 16 byte aligned IP header after
4712 * the 14 byte MAC header is removed
4714 skb_reserve(skb
, NET_IP_ALIGN
);
4716 buffer_info
->skb
= skb
;
4717 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
4719 PCI_DMA_FROMDEVICE
);
4721 /* Refresh the desc even if buffer_addrs didn't change because
4722 * each write-back erases this info. */
4723 if (adapter
->rx_ps_hdr_size
) {
4724 rx_desc
->read
.pkt_addr
=
4725 cpu_to_le64(buffer_info
->page_dma
);
4726 rx_desc
->read
.hdr_addr
= cpu_to_le64(buffer_info
->dma
);
4728 rx_desc
->read
.pkt_addr
=
4729 cpu_to_le64(buffer_info
->dma
);
4730 rx_desc
->read
.hdr_addr
= 0;
4734 if (i
== rx_ring
->count
)
4736 buffer_info
= &rx_ring
->buffer_info
[i
];
4740 if (rx_ring
->next_to_use
!= i
) {
4741 rx_ring
->next_to_use
= i
;
4743 i
= (rx_ring
->count
- 1);
4747 /* Force memory writes to complete before letting h/w
4748 * know there are new descriptors to fetch. (Only
4749 * applicable for weak-ordered memory model archs,
4750 * such as IA-64). */
4752 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
4762 static int igb_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4764 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4765 struct mii_ioctl_data
*data
= if_mii(ifr
);
4767 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
4772 data
->phy_id
= adapter
->hw
.phy
.addr
;
4775 if (!capable(CAP_NET_ADMIN
))
4777 if (igb_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4789 * igb_hwtstamp_ioctl - control hardware time stamping
4794 * Outgoing time stamping can be enabled and disabled. Play nice and
4795 * disable it when requested, although it shouldn't case any overhead
4796 * when no packet needs it. At most one packet in the queue may be
4797 * marked for time stamping, otherwise it would be impossible to tell
4798 * for sure to which packet the hardware time stamp belongs.
4800 * Incoming time stamping has to be configured via the hardware
4801 * filters. Not all combinations are supported, in particular event
4802 * type has to be specified. Matching the kind of event packet is
4803 * not supported, with the exception of "all V2 events regardless of
4807 static int igb_hwtstamp_ioctl(struct net_device
*netdev
,
4808 struct ifreq
*ifr
, int cmd
)
4810 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4811 struct e1000_hw
*hw
= &adapter
->hw
;
4812 struct hwtstamp_config config
;
4813 u32 tsync_tx_ctl_bit
= E1000_TSYNCTXCTL_ENABLED
;
4814 u32 tsync_rx_ctl_bit
= E1000_TSYNCRXCTL_ENABLED
;
4815 u32 tsync_rx_ctl_type
= 0;
4816 u32 tsync_rx_cfg
= 0;
4819 short port
= 319; /* PTP */
4822 if (copy_from_user(&config
, ifr
->ifr_data
, sizeof(config
)))
4825 /* reserved for future extensions */
4829 switch (config
.tx_type
) {
4830 case HWTSTAMP_TX_OFF
:
4831 tsync_tx_ctl_bit
= 0;
4833 case HWTSTAMP_TX_ON
:
4834 tsync_tx_ctl_bit
= E1000_TSYNCTXCTL_ENABLED
;
4840 switch (config
.rx_filter
) {
4841 case HWTSTAMP_FILTER_NONE
:
4842 tsync_rx_ctl_bit
= 0;
4844 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
4845 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
4846 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
4847 case HWTSTAMP_FILTER_ALL
:
4849 * register TSYNCRXCFG must be set, therefore it is not
4850 * possible to time stamp both Sync and Delay_Req messages
4851 * => fall back to time stamping all packets
4853 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_ALL
;
4854 config
.rx_filter
= HWTSTAMP_FILTER_ALL
;
4856 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
4857 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L4_V1
;
4858 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE
;
4861 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
4862 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L4_V1
;
4863 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE
;
4866 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
4867 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
4868 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L2_L4_V2
;
4869 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE
;
4872 config
.rx_filter
= HWTSTAMP_FILTER_SOME
;
4874 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
4875 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
4876 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L2_L4_V2
;
4877 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE
;
4880 config
.rx_filter
= HWTSTAMP_FILTER_SOME
;
4882 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
4883 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
4884 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
4885 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_EVENT_V2
;
4886 config
.rx_filter
= HWTSTAMP_FILTER_PTP_V2_EVENT
;
4893 /* enable/disable TX */
4894 regval
= rd32(E1000_TSYNCTXCTL
);
4895 regval
= (regval
& ~E1000_TSYNCTXCTL_ENABLED
) | tsync_tx_ctl_bit
;
4896 wr32(E1000_TSYNCTXCTL
, regval
);
4898 /* enable/disable RX, define which PTP packets are time stamped */
4899 regval
= rd32(E1000_TSYNCRXCTL
);
4900 regval
= (regval
& ~E1000_TSYNCRXCTL_ENABLED
) | tsync_rx_ctl_bit
;
4901 regval
= (regval
& ~0xE) | tsync_rx_ctl_type
;
4902 wr32(E1000_TSYNCRXCTL
, regval
);
4903 wr32(E1000_TSYNCRXCFG
, tsync_rx_cfg
);
4906 * Ethertype Filter Queue Filter[0][15:0] = 0x88F7
4907 * (Ethertype to filter on)
4908 * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter)
4909 * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping)
4911 wr32(E1000_ETQF0
, is_l2
? 0x440088f7 : 0);
4913 /* L4 Queue Filter[0]: only filter by source and destination port */
4914 wr32(E1000_SPQF0
, htons(port
));
4915 wr32(E1000_IMIREXT(0), is_l4
?
4916 ((1<<12) | (1<<19) /* bypass size and control flags */) : 0);
4917 wr32(E1000_IMIR(0), is_l4
?
4919 | (0<<16) /* immediate interrupt disabled */
4920 | 0 /* (1<<17) bit cleared: do not bypass
4921 destination port check */)
4923 wr32(E1000_FTQF0
, is_l4
?
4925 | (1<<15) /* VF not compared */
4926 | (1<<27) /* Enable Timestamping */
4927 | (7<<28) /* only source port filter enabled,
4928 source/target address and protocol
4930 : ((1<<15) | (15<<28) /* all mask bits set = filter not
4935 adapter
->hwtstamp_config
= config
;
4937 /* clear TX/RX time stamp registers, just to be sure */
4938 regval
= rd32(E1000_TXSTMPH
);
4939 regval
= rd32(E1000_RXSTMPH
);
4941 return copy_to_user(ifr
->ifr_data
, &config
, sizeof(config
)) ?
4951 static int igb_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4957 return igb_mii_ioctl(netdev
, ifr
, cmd
);
4959 return igb_hwtstamp_ioctl(netdev
, ifr
, cmd
);
4965 static void igb_vlan_rx_register(struct net_device
*netdev
,
4966 struct vlan_group
*grp
)
4968 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4969 struct e1000_hw
*hw
= &adapter
->hw
;
4972 igb_irq_disable(adapter
);
4973 adapter
->vlgrp
= grp
;
4976 /* enable VLAN tag insert/strip */
4977 ctrl
= rd32(E1000_CTRL
);
4978 ctrl
|= E1000_CTRL_VME
;
4979 wr32(E1000_CTRL
, ctrl
);
4981 /* enable VLAN receive filtering */
4982 rctl
= rd32(E1000_RCTL
);
4983 rctl
&= ~E1000_RCTL_CFIEN
;
4984 wr32(E1000_RCTL
, rctl
);
4985 igb_update_mng_vlan(adapter
);
4987 /* disable VLAN tag insert/strip */
4988 ctrl
= rd32(E1000_CTRL
);
4989 ctrl
&= ~E1000_CTRL_VME
;
4990 wr32(E1000_CTRL
, ctrl
);
4992 if (adapter
->mng_vlan_id
!= (u16
)IGB_MNG_VLAN_NONE
) {
4993 igb_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4994 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
4998 igb_rlpml_set(adapter
);
5000 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
5001 igb_irq_enable(adapter
);
5004 static void igb_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
5006 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5007 struct e1000_hw
*hw
= &adapter
->hw
;
5008 int pf_id
= adapter
->vfs_allocated_count
;
5010 if ((hw
->mng_cookie
.status
&
5011 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
5012 (vid
== adapter
->mng_vlan_id
))
5015 /* add vid to vlvf if sr-iov is enabled,
5016 * if that fails add directly to filter table */
5017 if (igb_vlvf_set(adapter
, vid
, true, pf_id
))
5018 igb_vfta_set(hw
, vid
, true);
5022 static void igb_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
5024 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5025 struct e1000_hw
*hw
= &adapter
->hw
;
5026 int pf_id
= adapter
->vfs_allocated_count
;
5028 igb_irq_disable(adapter
);
5029 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
5031 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
5032 igb_irq_enable(adapter
);
5034 if ((adapter
->hw
.mng_cookie
.status
&
5035 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
5036 (vid
== adapter
->mng_vlan_id
)) {
5037 /* release control to f/w */
5038 igb_release_hw_control(adapter
);
5042 /* remove vid from vlvf if sr-iov is enabled,
5043 * if not in vlvf remove from vfta */
5044 if (igb_vlvf_set(adapter
, vid
, false, pf_id
))
5045 igb_vfta_set(hw
, vid
, false);
5048 static void igb_restore_vlan(struct igb_adapter
*adapter
)
5050 igb_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
5052 if (adapter
->vlgrp
) {
5054 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
5055 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
5057 igb_vlan_rx_add_vid(adapter
->netdev
, vid
);
5062 int igb_set_spd_dplx(struct igb_adapter
*adapter
, u16 spddplx
)
5064 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
5068 /* Fiber NICs only allow 1000 gbps Full duplex */
5069 if ((adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
) &&
5070 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
5071 dev_err(&adapter
->pdev
->dev
,
5072 "Unsupported Speed/Duplex configuration\n");
5077 case SPEED_10
+ DUPLEX_HALF
:
5078 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
5080 case SPEED_10
+ DUPLEX_FULL
:
5081 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
5083 case SPEED_100
+ DUPLEX_HALF
:
5084 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
5086 case SPEED_100
+ DUPLEX_FULL
:
5087 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
5089 case SPEED_1000
+ DUPLEX_FULL
:
5091 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
5093 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
5095 dev_err(&adapter
->pdev
->dev
,
5096 "Unsupported Speed/Duplex configuration\n");
5102 static int __igb_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
5104 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5105 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5106 struct e1000_hw
*hw
= &adapter
->hw
;
5107 u32 ctrl
, rctl
, status
;
5108 u32 wufc
= adapter
->wol
;
5113 netif_device_detach(netdev
);
5115 if (netif_running(netdev
))
5118 igb_reset_interrupt_capability(adapter
);
5120 igb_free_queues(adapter
);
5123 retval
= pci_save_state(pdev
);
5128 status
= rd32(E1000_STATUS
);
5129 if (status
& E1000_STATUS_LU
)
5130 wufc
&= ~E1000_WUFC_LNKC
;
5133 igb_setup_rctl(adapter
);
5134 igb_set_multi(netdev
);
5136 /* turn on all-multi mode if wake on multicast is enabled */
5137 if (wufc
& E1000_WUFC_MC
) {
5138 rctl
= rd32(E1000_RCTL
);
5139 rctl
|= E1000_RCTL_MPE
;
5140 wr32(E1000_RCTL
, rctl
);
5143 ctrl
= rd32(E1000_CTRL
);
5144 /* advertise wake from D3Cold */
5145 #define E1000_CTRL_ADVD3WUC 0x00100000
5146 /* phy power management enable */
5147 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5148 ctrl
|= E1000_CTRL_ADVD3WUC
;
5149 wr32(E1000_CTRL
, ctrl
);
5151 /* Allow time for pending master requests to run */
5152 igb_disable_pcie_master(&adapter
->hw
);
5154 wr32(E1000_WUC
, E1000_WUC_PME_EN
);
5155 wr32(E1000_WUFC
, wufc
);
5158 wr32(E1000_WUFC
, 0);
5161 *enable_wake
= wufc
|| adapter
->en_mng_pt
;
5163 igb_shutdown_fiber_serdes_link_82575(hw
);
5165 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5166 * would have already happened in close and is redundant. */
5167 igb_release_hw_control(adapter
);
5169 pci_disable_device(pdev
);
5175 static int igb_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5180 retval
= __igb_shutdown(pdev
, &wake
);
5185 pci_prepare_to_sleep(pdev
);
5187 pci_wake_from_d3(pdev
, false);
5188 pci_set_power_state(pdev
, PCI_D3hot
);
5194 static int igb_resume(struct pci_dev
*pdev
)
5196 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5197 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5198 struct e1000_hw
*hw
= &adapter
->hw
;
5201 pci_set_power_state(pdev
, PCI_D0
);
5202 pci_restore_state(pdev
);
5204 err
= pci_enable_device_mem(pdev
);
5207 "igb: Cannot enable PCI device from suspend\n");
5210 pci_set_master(pdev
);
5212 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5213 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5215 igb_set_interrupt_capability(adapter
);
5217 if (igb_alloc_queues(adapter
)) {
5218 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
5222 /* e1000_power_up_phy(adapter); */
5226 /* let the f/w know that the h/w is now under the control of the
5228 igb_get_hw_control(adapter
);
5230 wr32(E1000_WUS
, ~0);
5232 if (netif_running(netdev
)) {
5233 err
= igb_open(netdev
);
5238 netif_device_attach(netdev
);
5244 static void igb_shutdown(struct pci_dev
*pdev
)
5248 __igb_shutdown(pdev
, &wake
);
5250 if (system_state
== SYSTEM_POWER_OFF
) {
5251 pci_wake_from_d3(pdev
, wake
);
5252 pci_set_power_state(pdev
, PCI_D3hot
);
5256 #ifdef CONFIG_NET_POLL_CONTROLLER
5258 * Polling 'interrupt' - used by things like netconsole to send skbs
5259 * without having to re-enable interrupts. It's not called while
5260 * the interrupt routine is executing.
5262 static void igb_netpoll(struct net_device
*netdev
)
5264 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5265 struct e1000_hw
*hw
= &adapter
->hw
;
5268 if (!adapter
->msix_entries
) {
5269 igb_irq_disable(adapter
);
5270 napi_schedule(&adapter
->rx_ring
[0].napi
);
5274 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5275 struct igb_ring
*tx_ring
= &adapter
->tx_ring
[i
];
5276 wr32(E1000_EIMC
, tx_ring
->eims_value
);
5277 igb_clean_tx_irq(tx_ring
);
5278 wr32(E1000_EIMS
, tx_ring
->eims_value
);
5281 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5282 struct igb_ring
*rx_ring
= &adapter
->rx_ring
[i
];
5283 wr32(E1000_EIMC
, rx_ring
->eims_value
);
5284 napi_schedule(&rx_ring
->napi
);
5287 #endif /* CONFIG_NET_POLL_CONTROLLER */
5290 * igb_io_error_detected - called when PCI error is detected
5291 * @pdev: Pointer to PCI device
5292 * @state: The current pci connection state
5294 * This function is called after a PCI bus error affecting
5295 * this device has been detected.
5297 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*pdev
,
5298 pci_channel_state_t state
)
5300 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5301 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5303 netif_device_detach(netdev
);
5305 if (netif_running(netdev
))
5307 pci_disable_device(pdev
);
5309 /* Request a slot slot reset. */
5310 return PCI_ERS_RESULT_NEED_RESET
;
5314 * igb_io_slot_reset - called after the pci bus has been reset.
5315 * @pdev: Pointer to PCI device
5317 * Restart the card from scratch, as if from a cold-boot. Implementation
5318 * resembles the first-half of the igb_resume routine.
5320 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*pdev
)
5322 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5323 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5324 struct e1000_hw
*hw
= &adapter
->hw
;
5325 pci_ers_result_t result
;
5328 if (pci_enable_device_mem(pdev
)) {
5330 "Cannot re-enable PCI device after reset.\n");
5331 result
= PCI_ERS_RESULT_DISCONNECT
;
5333 pci_set_master(pdev
);
5334 pci_restore_state(pdev
);
5336 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5337 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5340 wr32(E1000_WUS
, ~0);
5341 result
= PCI_ERS_RESULT_RECOVERED
;
5344 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
5346 dev_err(&pdev
->dev
, "pci_cleanup_aer_uncorrect_error_status "
5347 "failed 0x%0x\n", err
);
5348 /* non-fatal, continue */
5355 * igb_io_resume - called when traffic can start flowing again.
5356 * @pdev: Pointer to PCI device
5358 * This callback is called when the error recovery driver tells us that
5359 * its OK to resume normal operation. Implementation resembles the
5360 * second-half of the igb_resume routine.
5362 static void igb_io_resume(struct pci_dev
*pdev
)
5364 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5365 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5367 if (netif_running(netdev
)) {
5368 if (igb_up(adapter
)) {
5369 dev_err(&pdev
->dev
, "igb_up failed after reset\n");
5374 netif_device_attach(netdev
);
5376 /* let the f/w know that the h/w is now under the control of the
5378 igb_get_hw_control(adapter
);
5381 static inline void igb_set_vmolr(struct e1000_hw
*hw
, int vfn
)
5385 reg_data
= rd32(E1000_VMOLR(vfn
));
5386 reg_data
|= E1000_VMOLR_BAM
| /* Accept broadcast */
5387 E1000_VMOLR_ROPE
| /* Accept packets matched in UTA */
5388 E1000_VMOLR_ROMPE
| /* Accept packets matched in MTA */
5389 E1000_VMOLR_AUPE
| /* Accept untagged packets */
5390 E1000_VMOLR_STRVLAN
; /* Strip vlan tags */
5391 wr32(E1000_VMOLR(vfn
), reg_data
);
5394 static inline int igb_set_vf_rlpml(struct igb_adapter
*adapter
, int size
,
5397 struct e1000_hw
*hw
= &adapter
->hw
;
5400 vmolr
= rd32(E1000_VMOLR(vfn
));
5401 vmolr
&= ~E1000_VMOLR_RLPML_MASK
;
5402 vmolr
|= size
| E1000_VMOLR_LPE
;
5403 wr32(E1000_VMOLR(vfn
), vmolr
);
5408 static inline void igb_set_rah_pool(struct e1000_hw
*hw
, int pool
, int entry
)
5412 reg_data
= rd32(E1000_RAH(entry
));
5413 reg_data
&= ~E1000_RAH_POOL_MASK
;
5414 reg_data
|= E1000_RAH_POOL_1
<< pool
;;
5415 wr32(E1000_RAH(entry
), reg_data
);
5418 static void igb_set_mc_list_pools(struct igb_adapter
*adapter
,
5419 int entry_count
, u16 total_rar_filters
)
5421 struct e1000_hw
*hw
= &adapter
->hw
;
5422 int i
= adapter
->vfs_allocated_count
+ 1;
5424 if ((i
+ entry_count
) < total_rar_filters
)
5425 total_rar_filters
= i
+ entry_count
;
5427 for (; i
< total_rar_filters
; i
++)
5428 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, i
);
5431 static int igb_set_vf_mac(struct igb_adapter
*adapter
,
5432 int vf
, unsigned char *mac_addr
)
5434 struct e1000_hw
*hw
= &adapter
->hw
;
5435 int rar_entry
= vf
+ 1; /* VF MAC addresses start at entry 1 */
5437 igb_rar_set(hw
, mac_addr
, rar_entry
);
5439 memcpy(adapter
->vf_data
[vf
].vf_mac_addresses
, mac_addr
, ETH_ALEN
);
5441 igb_set_rah_pool(hw
, vf
, rar_entry
);
5446 static void igb_vmm_control(struct igb_adapter
*adapter
)
5448 struct e1000_hw
*hw
= &adapter
->hw
;
5451 if (!adapter
->vfs_allocated_count
)
5454 /* VF's need PF reset indication before they
5455 * can send/receive mail */
5456 reg_data
= rd32(E1000_CTRL_EXT
);
5457 reg_data
|= E1000_CTRL_EXT_PFRSTD
;
5458 wr32(E1000_CTRL_EXT
, reg_data
);
5460 igb_vmdq_set_loopback_pf(hw
, true);
5461 igb_vmdq_set_replication_pf(hw
, true);