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
*);
156 #ifdef CONFIG_PCI_IOV
157 static ssize_t
igb_set_num_vfs(struct device
*, struct device_attribute
*,
158 const char *, size_t);
159 static ssize_t
igb_show_num_vfs(struct device
*, struct device_attribute
*,
161 DEVICE_ATTR(num_vfs
, S_IRUGO
| S_IWUSR
, igb_show_num_vfs
, igb_set_num_vfs
);
163 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*,
164 pci_channel_state_t
);
165 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*);
166 static void igb_io_resume(struct pci_dev
*);
168 static struct pci_error_handlers igb_err_handler
= {
169 .error_detected
= igb_io_error_detected
,
170 .slot_reset
= igb_io_slot_reset
,
171 .resume
= igb_io_resume
,
175 static struct pci_driver igb_driver
= {
176 .name
= igb_driver_name
,
177 .id_table
= igb_pci_tbl
,
179 .remove
= __devexit_p(igb_remove
),
181 /* Power Managment Hooks */
182 .suspend
= igb_suspend
,
183 .resume
= igb_resume
,
185 .shutdown
= igb_shutdown
,
186 .err_handler
= &igb_err_handler
189 static int global_quad_port_a
; /* global quad port a indication */
191 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
192 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
193 MODULE_LICENSE("GPL");
194 MODULE_VERSION(DRV_VERSION
);
197 * Scale the NIC clock cycle by a large factor so that
198 * relatively small clock corrections can be added or
199 * substracted at each clock tick. The drawbacks of a
200 * large factor are a) that the clock register overflows
201 * more quickly (not such a big deal) and b) that the
202 * increment per tick has to fit into 24 bits.
205 * TIMINCA = IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS *
207 * TIMINCA += TIMINCA * adjustment [ppm] / 1e9
209 * The base scale factor is intentionally a power of two
210 * so that the division in %struct timecounter can be done with
213 #define IGB_TSYNC_SHIFT (19)
214 #define IGB_TSYNC_SCALE (1<<IGB_TSYNC_SHIFT)
217 * The duration of one clock cycle of the NIC.
219 * @todo This hard-coded value is part of the specification and might change
220 * in future hardware revisions. Add revision check.
222 #define IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS 16
224 #if (IGB_TSYNC_SCALE * IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS) >= (1<<24)
225 # error IGB_TSYNC_SCALE and/or IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS are too large to fit into TIMINCA
229 * igb_read_clock - read raw cycle counter (to be used by time counter)
231 static cycle_t
igb_read_clock(const struct cyclecounter
*tc
)
233 struct igb_adapter
*adapter
=
234 container_of(tc
, struct igb_adapter
, cycles
);
235 struct e1000_hw
*hw
= &adapter
->hw
;
238 stamp
= rd32(E1000_SYSTIML
);
239 stamp
|= (u64
)rd32(E1000_SYSTIMH
) << 32ULL;
246 * igb_get_hw_dev_name - return device name string
247 * used by hardware layer to print debugging information
249 char *igb_get_hw_dev_name(struct e1000_hw
*hw
)
251 struct igb_adapter
*adapter
= hw
->back
;
252 return adapter
->netdev
->name
;
256 * igb_get_time_str - format current NIC and system time as string
258 static char *igb_get_time_str(struct igb_adapter
*adapter
,
261 cycle_t hw
= adapter
->cycles
.read(&adapter
->cycles
);
262 struct timespec nic
= ns_to_timespec(timecounter_read(&adapter
->clock
));
264 struct timespec delta
;
265 getnstimeofday(&sys
);
267 delta
= timespec_sub(nic
, sys
);
270 "HW %llu, NIC %ld.%09lus, SYS %ld.%09lus, NIC-SYS %lds + %09luns",
272 (long)nic
.tv_sec
, nic
.tv_nsec
,
273 (long)sys
.tv_sec
, sys
.tv_nsec
,
274 (long)delta
.tv_sec
, delta
.tv_nsec
);
281 * igb_desc_unused - calculate if we have unused descriptors
283 static int igb_desc_unused(struct igb_ring
*ring
)
285 if (ring
->next_to_clean
> ring
->next_to_use
)
286 return ring
->next_to_clean
- ring
->next_to_use
- 1;
288 return ring
->count
+ ring
->next_to_clean
- ring
->next_to_use
- 1;
292 * igb_init_module - Driver Registration Routine
294 * igb_init_module is the first routine called when the driver is
295 * loaded. All it does is register with the PCI subsystem.
297 static int __init
igb_init_module(void)
300 printk(KERN_INFO
"%s - version %s\n",
301 igb_driver_string
, igb_driver_version
);
303 printk(KERN_INFO
"%s\n", igb_copyright
);
305 global_quad_port_a
= 0;
307 #ifdef CONFIG_IGB_DCA
308 dca_register_notify(&dca_notifier
);
311 ret
= pci_register_driver(&igb_driver
);
315 module_init(igb_init_module
);
318 * igb_exit_module - Driver Exit Cleanup Routine
320 * igb_exit_module is called just before the driver is removed
323 static void __exit
igb_exit_module(void)
325 #ifdef CONFIG_IGB_DCA
326 dca_unregister_notify(&dca_notifier
);
328 pci_unregister_driver(&igb_driver
);
331 module_exit(igb_exit_module
);
333 #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
335 * igb_cache_ring_register - Descriptor ring to register mapping
336 * @adapter: board private structure to initialize
338 * Once we know the feature-set enabled for the device, we'll cache
339 * the register offset the descriptor ring is assigned to.
341 static void igb_cache_ring_register(struct igb_adapter
*adapter
)
344 unsigned int rbase_offset
= adapter
->vfs_allocated_count
;
346 switch (adapter
->hw
.mac
.type
) {
348 /* The queues are allocated for virtualization such that VF 0
349 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
350 * In order to avoid collision we start at the first free queue
351 * and continue consuming queues in the same sequence
353 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
354 adapter
->rx_ring
[i
].reg_idx
= rbase_offset
+
356 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
357 adapter
->tx_ring
[i
].reg_idx
= rbase_offset
+
362 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
363 adapter
->rx_ring
[i
].reg_idx
= i
;
364 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
365 adapter
->tx_ring
[i
].reg_idx
= i
;
371 * igb_alloc_queues - Allocate memory for all rings
372 * @adapter: board private structure to initialize
374 * We allocate one ring per queue at run-time since we don't know the
375 * number of queues at compile-time.
377 static int igb_alloc_queues(struct igb_adapter
*adapter
)
381 adapter
->tx_ring
= kcalloc(adapter
->num_tx_queues
,
382 sizeof(struct igb_ring
), GFP_KERNEL
);
383 if (!adapter
->tx_ring
)
386 adapter
->rx_ring
= kcalloc(adapter
->num_rx_queues
,
387 sizeof(struct igb_ring
), GFP_KERNEL
);
388 if (!adapter
->rx_ring
) {
389 kfree(adapter
->tx_ring
);
393 adapter
->rx_ring
->buddy
= adapter
->tx_ring
;
395 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
396 struct igb_ring
*ring
= &(adapter
->tx_ring
[i
]);
397 ring
->count
= adapter
->tx_ring_count
;
398 ring
->adapter
= adapter
;
399 ring
->queue_index
= i
;
401 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
402 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
403 ring
->count
= adapter
->rx_ring_count
;
404 ring
->adapter
= adapter
;
405 ring
->queue_index
= i
;
406 ring
->itr_register
= E1000_ITR
;
408 /* set a default napi handler for each rx_ring */
409 netif_napi_add(adapter
->netdev
, &ring
->napi
, igb_poll
, 64);
412 igb_cache_ring_register(adapter
);
416 static void igb_free_queues(struct igb_adapter
*adapter
)
420 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
421 netif_napi_del(&adapter
->rx_ring
[i
].napi
);
423 adapter
->num_rx_queues
= 0;
424 adapter
->num_tx_queues
= 0;
426 kfree(adapter
->tx_ring
);
427 kfree(adapter
->rx_ring
);
430 #define IGB_N0_QUEUE -1
431 static void igb_assign_vector(struct igb_adapter
*adapter
, int rx_queue
,
432 int tx_queue
, int msix_vector
)
435 struct e1000_hw
*hw
= &adapter
->hw
;
438 switch (hw
->mac
.type
) {
440 /* The 82575 assigns vectors using a bitmask, which matches the
441 bitmask for the EICR/EIMS/EIMC registers. To assign one
442 or more queues to a vector, we write the appropriate bits
443 into the MSIXBM register for that vector. */
444 if (rx_queue
> IGB_N0_QUEUE
) {
445 msixbm
= E1000_EICR_RX_QUEUE0
<< rx_queue
;
446 adapter
->rx_ring
[rx_queue
].eims_value
= msixbm
;
448 if (tx_queue
> IGB_N0_QUEUE
) {
449 msixbm
|= E1000_EICR_TX_QUEUE0
<< tx_queue
;
450 adapter
->tx_ring
[tx_queue
].eims_value
=
451 E1000_EICR_TX_QUEUE0
<< tx_queue
;
453 array_wr32(E1000_MSIXBM(0), msix_vector
, msixbm
);
456 /* 82576 uses a table-based method for assigning vectors.
457 Each queue has a single entry in the table to which we write
458 a vector number along with a "valid" bit. Sadly, the layout
459 of the table is somewhat counterintuitive. */
460 if (rx_queue
> IGB_N0_QUEUE
) {
461 index
= (rx_queue
>> 1) + adapter
->vfs_allocated_count
;
462 ivar
= array_rd32(E1000_IVAR0
, index
);
463 if (rx_queue
& 0x1) {
464 /* vector goes into third byte of register */
465 ivar
= ivar
& 0xFF00FFFF;
466 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << 16;
468 /* vector goes into low byte of register */
469 ivar
= ivar
& 0xFFFFFF00;
470 ivar
|= msix_vector
| E1000_IVAR_VALID
;
472 adapter
->rx_ring
[rx_queue
].eims_value
= 1 << msix_vector
;
473 array_wr32(E1000_IVAR0
, index
, ivar
);
475 if (tx_queue
> IGB_N0_QUEUE
) {
476 index
= (tx_queue
>> 1) + adapter
->vfs_allocated_count
;
477 ivar
= array_rd32(E1000_IVAR0
, index
);
478 if (tx_queue
& 0x1) {
479 /* vector goes into high byte of register */
480 ivar
= ivar
& 0x00FFFFFF;
481 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << 24;
483 /* vector goes into second byte of register */
484 ivar
= ivar
& 0xFFFF00FF;
485 ivar
|= (msix_vector
| E1000_IVAR_VALID
) << 8;
487 adapter
->tx_ring
[tx_queue
].eims_value
= 1 << msix_vector
;
488 array_wr32(E1000_IVAR0
, index
, ivar
);
498 * igb_configure_msix - Configure MSI-X hardware
500 * igb_configure_msix sets up the hardware to properly
501 * generate MSI-X interrupts.
503 static void igb_configure_msix(struct igb_adapter
*adapter
)
507 struct e1000_hw
*hw
= &adapter
->hw
;
509 adapter
->eims_enable_mask
= 0;
510 if (hw
->mac
.type
== e1000_82576
)
511 /* Turn on MSI-X capability first, or our settings
512 * won't stick. And it will take days to debug. */
513 wr32(E1000_GPIE
, E1000_GPIE_MSIX_MODE
|
514 E1000_GPIE_PBA
| E1000_GPIE_EIAME
|
517 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
518 struct igb_ring
*tx_ring
= &adapter
->tx_ring
[i
];
519 igb_assign_vector(adapter
, IGB_N0_QUEUE
, i
, vector
++);
520 adapter
->eims_enable_mask
|= tx_ring
->eims_value
;
521 if (tx_ring
->itr_val
)
522 writel(tx_ring
->itr_val
,
523 hw
->hw_addr
+ tx_ring
->itr_register
);
525 writel(1, hw
->hw_addr
+ tx_ring
->itr_register
);
528 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
529 struct igb_ring
*rx_ring
= &adapter
->rx_ring
[i
];
530 rx_ring
->buddy
= NULL
;
531 igb_assign_vector(adapter
, i
, IGB_N0_QUEUE
, vector
++);
532 adapter
->eims_enable_mask
|= rx_ring
->eims_value
;
533 if (rx_ring
->itr_val
)
534 writel(rx_ring
->itr_val
,
535 hw
->hw_addr
+ rx_ring
->itr_register
);
537 writel(1, hw
->hw_addr
+ rx_ring
->itr_register
);
541 /* set vector for other causes, i.e. link changes */
542 switch (hw
->mac
.type
) {
544 array_wr32(E1000_MSIXBM(0), vector
++,
547 tmp
= rd32(E1000_CTRL_EXT
);
548 /* enable MSI-X PBA support*/
549 tmp
|= E1000_CTRL_EXT_PBA_CLR
;
551 /* Auto-Mask interrupts upon ICR read. */
552 tmp
|= E1000_CTRL_EXT_EIAME
;
553 tmp
|= E1000_CTRL_EXT_IRCA
;
555 wr32(E1000_CTRL_EXT
, tmp
);
556 adapter
->eims_enable_mask
|= E1000_EIMS_OTHER
;
557 adapter
->eims_other
= E1000_EIMS_OTHER
;
562 tmp
= (vector
++ | E1000_IVAR_VALID
) << 8;
563 wr32(E1000_IVAR_MISC
, tmp
);
565 adapter
->eims_enable_mask
= (1 << (vector
)) - 1;
566 adapter
->eims_other
= 1 << (vector
- 1);
569 /* do nothing, since nothing else supports MSI-X */
571 } /* switch (hw->mac.type) */
576 * igb_request_msix - Initialize MSI-X interrupts
578 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
581 static int igb_request_msix(struct igb_adapter
*adapter
)
583 struct net_device
*netdev
= adapter
->netdev
;
584 int i
, err
= 0, vector
= 0;
588 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
589 struct igb_ring
*ring
= &(adapter
->tx_ring
[i
]);
590 sprintf(ring
->name
, "%s-tx-%d", netdev
->name
, i
);
591 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
592 &igb_msix_tx
, 0, ring
->name
,
593 &(adapter
->tx_ring
[i
]));
596 ring
->itr_register
= E1000_EITR(0) + (vector
<< 2);
597 ring
->itr_val
= 976; /* ~4000 ints/sec */
600 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
601 struct igb_ring
*ring
= &(adapter
->rx_ring
[i
]);
602 if (strlen(netdev
->name
) < (IFNAMSIZ
- 5))
603 sprintf(ring
->name
, "%s-rx-%d", netdev
->name
, i
);
605 memcpy(ring
->name
, netdev
->name
, IFNAMSIZ
);
606 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
607 &igb_msix_rx
, 0, ring
->name
,
608 &(adapter
->rx_ring
[i
]));
611 ring
->itr_register
= E1000_EITR(0) + (vector
<< 2);
612 ring
->itr_val
= adapter
->itr
;
616 err
= request_irq(adapter
->msix_entries
[vector
].vector
,
617 &igb_msix_other
, 0, netdev
->name
, netdev
);
621 igb_configure_msix(adapter
);
627 static void igb_reset_interrupt_capability(struct igb_adapter
*adapter
)
629 if (adapter
->msix_entries
) {
630 pci_disable_msix(adapter
->pdev
);
631 kfree(adapter
->msix_entries
);
632 adapter
->msix_entries
= NULL
;
633 } else if (adapter
->flags
& IGB_FLAG_HAS_MSI
)
634 pci_disable_msi(adapter
->pdev
);
640 * igb_set_interrupt_capability - set MSI or MSI-X if supported
642 * Attempt to configure interrupts using the best available
643 * capabilities of the hardware and kernel.
645 static void igb_set_interrupt_capability(struct igb_adapter
*adapter
)
650 /* Number of supported queues. */
651 /* Having more queues than CPUs doesn't make sense. */
652 adapter
->num_rx_queues
= min_t(u32
, IGB_MAX_RX_QUEUES
, num_online_cpus());
653 adapter
->num_tx_queues
= min_t(u32
, IGB_MAX_TX_QUEUES
, num_online_cpus());
655 numvecs
= adapter
->num_tx_queues
+ adapter
->num_rx_queues
+ 1;
656 adapter
->msix_entries
= kcalloc(numvecs
, sizeof(struct msix_entry
),
658 if (!adapter
->msix_entries
)
661 for (i
= 0; i
< numvecs
; i
++)
662 adapter
->msix_entries
[i
].entry
= i
;
664 err
= pci_enable_msix(adapter
->pdev
,
665 adapter
->msix_entries
,
670 igb_reset_interrupt_capability(adapter
);
672 /* If we can't do MSI-X, try MSI */
674 adapter
->num_rx_queues
= 1;
675 adapter
->num_tx_queues
= 1;
676 if (!pci_enable_msi(adapter
->pdev
))
677 adapter
->flags
|= IGB_FLAG_HAS_MSI
;
679 /* Notify the stack of the (possibly) reduced Tx Queue count. */
680 adapter
->netdev
->real_num_tx_queues
= adapter
->num_tx_queues
;
685 * igb_request_irq - initialize interrupts
687 * Attempts to configure interrupts using the best available
688 * capabilities of the hardware and kernel.
690 static int igb_request_irq(struct igb_adapter
*adapter
)
692 struct net_device
*netdev
= adapter
->netdev
;
693 struct e1000_hw
*hw
= &adapter
->hw
;
696 if (adapter
->msix_entries
) {
697 err
= igb_request_msix(adapter
);
700 /* fall back to MSI */
701 igb_reset_interrupt_capability(adapter
);
702 if (!pci_enable_msi(adapter
->pdev
))
703 adapter
->flags
|= IGB_FLAG_HAS_MSI
;
704 igb_free_all_tx_resources(adapter
);
705 igb_free_all_rx_resources(adapter
);
706 adapter
->num_rx_queues
= 1;
707 igb_alloc_queues(adapter
);
709 switch (hw
->mac
.type
) {
711 wr32(E1000_MSIXBM(0),
712 (E1000_EICR_RX_QUEUE0
| E1000_EIMS_OTHER
));
715 wr32(E1000_IVAR0
, E1000_IVAR_VALID
);
722 if (adapter
->flags
& IGB_FLAG_HAS_MSI
) {
723 err
= request_irq(adapter
->pdev
->irq
, &igb_intr_msi
, 0,
724 netdev
->name
, netdev
);
727 /* fall back to legacy interrupts */
728 igb_reset_interrupt_capability(adapter
);
729 adapter
->flags
&= ~IGB_FLAG_HAS_MSI
;
732 err
= request_irq(adapter
->pdev
->irq
, &igb_intr
, IRQF_SHARED
,
733 netdev
->name
, netdev
);
736 dev_err(&adapter
->pdev
->dev
, "Error %d getting interrupt\n",
743 static void igb_free_irq(struct igb_adapter
*adapter
)
745 struct net_device
*netdev
= adapter
->netdev
;
747 if (adapter
->msix_entries
) {
750 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
751 free_irq(adapter
->msix_entries
[vector
++].vector
,
752 &(adapter
->tx_ring
[i
]));
753 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
754 free_irq(adapter
->msix_entries
[vector
++].vector
,
755 &(adapter
->rx_ring
[i
]));
757 free_irq(adapter
->msix_entries
[vector
++].vector
, netdev
);
761 free_irq(adapter
->pdev
->irq
, netdev
);
765 * igb_irq_disable - Mask off interrupt generation on the NIC
766 * @adapter: board private structure
768 static void igb_irq_disable(struct igb_adapter
*adapter
)
770 struct e1000_hw
*hw
= &adapter
->hw
;
772 if (adapter
->msix_entries
) {
774 wr32(E1000_EIMC
, ~0);
781 synchronize_irq(adapter
->pdev
->irq
);
785 * igb_irq_enable - Enable default interrupt generation settings
786 * @adapter: board private structure
788 static void igb_irq_enable(struct igb_adapter
*adapter
)
790 struct e1000_hw
*hw
= &adapter
->hw
;
792 if (adapter
->msix_entries
) {
793 wr32(E1000_EIAC
, adapter
->eims_enable_mask
);
794 wr32(E1000_EIAM
, adapter
->eims_enable_mask
);
795 wr32(E1000_EIMS
, adapter
->eims_enable_mask
);
796 if (adapter
->vfs_allocated_count
)
797 wr32(E1000_MBVFIMR
, 0xFF);
798 wr32(E1000_IMS
, (E1000_IMS_LSC
| E1000_IMS_VMMB
|
799 E1000_IMS_DOUTSYNC
));
801 wr32(E1000_IMS
, IMS_ENABLE_MASK
);
802 wr32(E1000_IAM
, IMS_ENABLE_MASK
);
806 static void igb_update_mng_vlan(struct igb_adapter
*adapter
)
808 struct net_device
*netdev
= adapter
->netdev
;
809 u16 vid
= adapter
->hw
.mng_cookie
.vlan_id
;
810 u16 old_vid
= adapter
->mng_vlan_id
;
811 if (adapter
->vlgrp
) {
812 if (!vlan_group_get_device(adapter
->vlgrp
, vid
)) {
813 if (adapter
->hw
.mng_cookie
.status
&
814 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) {
815 igb_vlan_rx_add_vid(netdev
, vid
);
816 adapter
->mng_vlan_id
= vid
;
818 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
820 if ((old_vid
!= (u16
)IGB_MNG_VLAN_NONE
) &&
822 !vlan_group_get_device(adapter
->vlgrp
, old_vid
))
823 igb_vlan_rx_kill_vid(netdev
, old_vid
);
825 adapter
->mng_vlan_id
= vid
;
830 * igb_release_hw_control - release control of the h/w to f/w
831 * @adapter: address of board private structure
833 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
834 * For ASF and Pass Through versions of f/w this means that the
835 * driver is no longer loaded.
838 static void igb_release_hw_control(struct igb_adapter
*adapter
)
840 struct e1000_hw
*hw
= &adapter
->hw
;
843 /* Let firmware take over control of h/w */
844 ctrl_ext
= rd32(E1000_CTRL_EXT
);
846 ctrl_ext
& ~E1000_CTRL_EXT_DRV_LOAD
);
851 * igb_get_hw_control - get control of the h/w from f/w
852 * @adapter: address of board private structure
854 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
855 * For ASF and Pass Through versions of f/w this means that
856 * the driver is loaded.
859 static void igb_get_hw_control(struct igb_adapter
*adapter
)
861 struct e1000_hw
*hw
= &adapter
->hw
;
864 /* Let firmware know the driver has taken over */
865 ctrl_ext
= rd32(E1000_CTRL_EXT
);
867 ctrl_ext
| E1000_CTRL_EXT_DRV_LOAD
);
871 * igb_configure - configure the hardware for RX and TX
872 * @adapter: private board structure
874 static void igb_configure(struct igb_adapter
*adapter
)
876 struct net_device
*netdev
= adapter
->netdev
;
879 igb_get_hw_control(adapter
);
880 igb_set_multi(netdev
);
882 igb_restore_vlan(adapter
);
884 igb_configure_tx(adapter
);
885 igb_setup_rctl(adapter
);
886 igb_configure_rx(adapter
);
888 igb_rx_fifo_flush_82575(&adapter
->hw
);
890 /* call igb_desc_unused which always leaves
891 * at least 1 descriptor unused to make sure
892 * next_to_use != next_to_clean */
893 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
894 struct igb_ring
*ring
= &adapter
->rx_ring
[i
];
895 igb_alloc_rx_buffers_adv(ring
, igb_desc_unused(ring
));
899 adapter
->tx_queue_len
= netdev
->tx_queue_len
;
904 * igb_up - Open the interface and prepare it to handle traffic
905 * @adapter: board private structure
908 int igb_up(struct igb_adapter
*adapter
)
910 struct e1000_hw
*hw
= &adapter
->hw
;
913 /* hardware has been reset, we need to reload some things */
914 igb_configure(adapter
);
916 clear_bit(__IGB_DOWN
, &adapter
->state
);
918 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
919 napi_enable(&adapter
->rx_ring
[i
].napi
);
920 if (adapter
->msix_entries
)
921 igb_configure_msix(adapter
);
923 igb_vmm_control(adapter
);
924 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, 0);
925 igb_set_vmolr(hw
, adapter
->vfs_allocated_count
);
927 /* Clear any pending interrupts. */
929 igb_irq_enable(adapter
);
931 /* Fire a link change interrupt to start the watchdog. */
932 wr32(E1000_ICS
, E1000_ICS_LSC
);
936 void igb_down(struct igb_adapter
*adapter
)
938 struct e1000_hw
*hw
= &adapter
->hw
;
939 struct net_device
*netdev
= adapter
->netdev
;
943 /* signal that we're down so the interrupt handler does not
944 * reschedule our watchdog timer */
945 set_bit(__IGB_DOWN
, &adapter
->state
);
947 /* disable receives in the hardware */
948 rctl
= rd32(E1000_RCTL
);
949 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
950 /* flush and sleep below */
952 netif_tx_stop_all_queues(netdev
);
954 /* disable transmits in the hardware */
955 tctl
= rd32(E1000_TCTL
);
956 tctl
&= ~E1000_TCTL_EN
;
957 wr32(E1000_TCTL
, tctl
);
958 /* flush both disables and wait for them to finish */
962 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
963 napi_disable(&adapter
->rx_ring
[i
].napi
);
965 igb_irq_disable(adapter
);
967 del_timer_sync(&adapter
->watchdog_timer
);
968 del_timer_sync(&adapter
->phy_info_timer
);
970 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
971 netif_carrier_off(netdev
);
973 /* record the stats before reset*/
974 igb_update_stats(adapter
);
976 adapter
->link_speed
= 0;
977 adapter
->link_duplex
= 0;
979 if (!pci_channel_offline(adapter
->pdev
))
981 igb_clean_all_tx_rings(adapter
);
982 igb_clean_all_rx_rings(adapter
);
985 void igb_reinit_locked(struct igb_adapter
*adapter
)
987 WARN_ON(in_interrupt());
988 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
992 clear_bit(__IGB_RESETTING
, &adapter
->state
);
995 void igb_reset(struct igb_adapter
*adapter
)
997 struct e1000_hw
*hw
= &adapter
->hw
;
998 struct e1000_mac_info
*mac
= &hw
->mac
;
999 struct e1000_fc_info
*fc
= &hw
->fc
;
1000 u32 pba
= 0, tx_space
, min_tx_space
, min_rx_space
;
1003 /* Repartition Pba for greater than 9k mtu
1004 * To take effect CTRL.RST is required.
1006 switch (mac
->type
) {
1008 pba
= E1000_PBA_64K
;
1012 pba
= E1000_PBA_34K
;
1016 if ((adapter
->max_frame_size
> ETH_FRAME_LEN
+ ETH_FCS_LEN
) &&
1017 (mac
->type
< e1000_82576
)) {
1018 /* adjust PBA for jumbo frames */
1019 wr32(E1000_PBA
, pba
);
1021 /* To maintain wire speed transmits, the Tx FIFO should be
1022 * large enough to accommodate two full transmit packets,
1023 * rounded up to the next 1KB and expressed in KB. Likewise,
1024 * the Rx FIFO should be large enough to accommodate at least
1025 * one full receive packet and is similarly rounded up and
1026 * expressed in KB. */
1027 pba
= rd32(E1000_PBA
);
1028 /* upper 16 bits has Tx packet buffer allocation size in KB */
1029 tx_space
= pba
>> 16;
1030 /* lower 16 bits has Rx packet buffer allocation size in KB */
1032 /* the tx fifo also stores 16 bytes of information about the tx
1033 * but don't include ethernet FCS because hardware appends it */
1034 min_tx_space
= (adapter
->max_frame_size
+
1035 sizeof(union e1000_adv_tx_desc
) -
1037 min_tx_space
= ALIGN(min_tx_space
, 1024);
1038 min_tx_space
>>= 10;
1039 /* software strips receive CRC, so leave room for it */
1040 min_rx_space
= adapter
->max_frame_size
;
1041 min_rx_space
= ALIGN(min_rx_space
, 1024);
1042 min_rx_space
>>= 10;
1044 /* If current Tx allocation is less than the min Tx FIFO size,
1045 * and the min Tx FIFO size is less than the current Rx FIFO
1046 * allocation, take space away from current Rx allocation */
1047 if (tx_space
< min_tx_space
&&
1048 ((min_tx_space
- tx_space
) < pba
)) {
1049 pba
= pba
- (min_tx_space
- tx_space
);
1051 /* if short on rx space, rx wins and must trump tx
1053 if (pba
< min_rx_space
)
1056 wr32(E1000_PBA
, pba
);
1059 /* flow control settings */
1060 /* The high water mark must be low enough to fit one full frame
1061 * (or the size used for early receive) above it in the Rx FIFO.
1062 * Set it to the lower of:
1063 * - 90% of the Rx FIFO size, or
1064 * - the full Rx FIFO size minus one full frame */
1065 hwm
= min(((pba
<< 10) * 9 / 10),
1066 ((pba
<< 10) - 2 * adapter
->max_frame_size
));
1068 if (mac
->type
< e1000_82576
) {
1069 fc
->high_water
= hwm
& 0xFFF8; /* 8-byte granularity */
1070 fc
->low_water
= fc
->high_water
- 8;
1072 fc
->high_water
= hwm
& 0xFFF0; /* 16-byte granularity */
1073 fc
->low_water
= fc
->high_water
- 16;
1075 fc
->pause_time
= 0xFFFF;
1077 fc
->type
= fc
->original_type
;
1079 /* disable receive for all VFs and wait one second */
1080 if (adapter
->vfs_allocated_count
) {
1082 for (i
= 0 ; i
< adapter
->vfs_allocated_count
; i
++)
1083 adapter
->vf_data
[i
].clear_to_send
= false;
1085 /* ping all the active vfs to let them know we are going down */
1086 igb_ping_all_vfs(adapter
);
1088 /* disable transmits and receives */
1089 wr32(E1000_VFRE
, 0);
1090 wr32(E1000_VFTE
, 0);
1093 /* Allow time for pending master requests to run */
1094 adapter
->hw
.mac
.ops
.reset_hw(&adapter
->hw
);
1097 if (adapter
->hw
.mac
.ops
.init_hw(&adapter
->hw
))
1098 dev_err(&adapter
->pdev
->dev
, "Hardware Error\n");
1100 igb_update_mng_vlan(adapter
);
1102 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
1103 wr32(E1000_VET
, ETHERNET_IEEE_VLAN_TYPE
);
1105 igb_reset_adaptive(&adapter
->hw
);
1106 igb_get_phy_info(&adapter
->hw
);
1109 static const struct net_device_ops igb_netdev_ops
= {
1110 .ndo_open
= igb_open
,
1111 .ndo_stop
= igb_close
,
1112 .ndo_start_xmit
= igb_xmit_frame_adv
,
1113 .ndo_get_stats
= igb_get_stats
,
1114 .ndo_set_multicast_list
= igb_set_multi
,
1115 .ndo_set_mac_address
= igb_set_mac
,
1116 .ndo_change_mtu
= igb_change_mtu
,
1117 .ndo_do_ioctl
= igb_ioctl
,
1118 .ndo_tx_timeout
= igb_tx_timeout
,
1119 .ndo_validate_addr
= eth_validate_addr
,
1120 .ndo_vlan_rx_register
= igb_vlan_rx_register
,
1121 .ndo_vlan_rx_add_vid
= igb_vlan_rx_add_vid
,
1122 .ndo_vlan_rx_kill_vid
= igb_vlan_rx_kill_vid
,
1123 #ifdef CONFIG_NET_POLL_CONTROLLER
1124 .ndo_poll_controller
= igb_netpoll
,
1129 * igb_probe - Device Initialization Routine
1130 * @pdev: PCI device information struct
1131 * @ent: entry in igb_pci_tbl
1133 * Returns 0 on success, negative on failure
1135 * igb_probe initializes an adapter identified by a pci_dev structure.
1136 * The OS initialization, configuring of the adapter private structure,
1137 * and a hardware reset occur.
1139 static int __devinit
igb_probe(struct pci_dev
*pdev
,
1140 const struct pci_device_id
*ent
)
1142 struct net_device
*netdev
;
1143 struct igb_adapter
*adapter
;
1144 struct e1000_hw
*hw
;
1145 const struct e1000_info
*ei
= igb_info_tbl
[ent
->driver_data
];
1146 unsigned long mmio_start
, mmio_len
;
1147 int err
, pci_using_dac
;
1148 u16 eeprom_data
= 0;
1149 u16 eeprom_apme_mask
= IGB_EEPROM_APME
;
1152 err
= pci_enable_device_mem(pdev
);
1157 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
1159 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
1163 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
1165 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
1167 dev_err(&pdev
->dev
, "No usable DMA "
1168 "configuration, aborting\n");
1174 err
= pci_request_selected_regions(pdev
, pci_select_bars(pdev
,
1180 err
= pci_enable_pcie_error_reporting(pdev
);
1182 dev_err(&pdev
->dev
, "pci_enable_pcie_error_reporting failed "
1184 /* non-fatal, continue */
1187 pci_set_master(pdev
);
1188 pci_save_state(pdev
);
1191 netdev
= alloc_etherdev_mq(sizeof(struct igb_adapter
),
1192 IGB_ABS_MAX_TX_QUEUES
);
1194 goto err_alloc_etherdev
;
1196 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
1198 pci_set_drvdata(pdev
, netdev
);
1199 adapter
= netdev_priv(netdev
);
1200 adapter
->netdev
= netdev
;
1201 adapter
->pdev
= pdev
;
1204 adapter
->msg_enable
= NETIF_MSG_DRV
| NETIF_MSG_PROBE
;
1206 mmio_start
= pci_resource_start(pdev
, 0);
1207 mmio_len
= pci_resource_len(pdev
, 0);
1210 hw
->hw_addr
= ioremap(mmio_start
, mmio_len
);
1214 netdev
->netdev_ops
= &igb_netdev_ops
;
1215 igb_set_ethtool_ops(netdev
);
1216 netdev
->watchdog_timeo
= 5 * HZ
;
1218 strncpy(netdev
->name
, pci_name(pdev
), sizeof(netdev
->name
) - 1);
1220 netdev
->mem_start
= mmio_start
;
1221 netdev
->mem_end
= mmio_start
+ mmio_len
;
1223 /* PCI config space info */
1224 hw
->vendor_id
= pdev
->vendor
;
1225 hw
->device_id
= pdev
->device
;
1226 hw
->revision_id
= pdev
->revision
;
1227 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
1228 hw
->subsystem_device_id
= pdev
->subsystem_device
;
1230 /* setup the private structure */
1232 /* Copy the default MAC, PHY and NVM function pointers */
1233 memcpy(&hw
->mac
.ops
, ei
->mac_ops
, sizeof(hw
->mac
.ops
));
1234 memcpy(&hw
->phy
.ops
, ei
->phy_ops
, sizeof(hw
->phy
.ops
));
1235 memcpy(&hw
->nvm
.ops
, ei
->nvm_ops
, sizeof(hw
->nvm
.ops
));
1236 /* Initialize skew-specific constants */
1237 err
= ei
->get_invariants(hw
);
1241 /* setup the private structure */
1242 err
= igb_sw_init(adapter
);
1246 igb_get_bus_info_pcie(hw
);
1249 switch (hw
->mac
.type
) {
1251 adapter
->flags
|= IGB_FLAG_NEED_CTX_IDX
;
1258 hw
->phy
.autoneg_wait_to_complete
= false;
1259 hw
->mac
.adaptive_ifs
= true;
1261 /* Copper options */
1262 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1263 hw
->phy
.mdix
= AUTO_ALL_MODES
;
1264 hw
->phy
.disable_polarity_correction
= false;
1265 hw
->phy
.ms_type
= e1000_ms_hw_default
;
1268 if (igb_check_reset_block(hw
))
1269 dev_info(&pdev
->dev
,
1270 "PHY reset is blocked due to SOL/IDER session.\n");
1272 netdev
->features
= NETIF_F_SG
|
1274 NETIF_F_HW_VLAN_TX
|
1275 NETIF_F_HW_VLAN_RX
|
1276 NETIF_F_HW_VLAN_FILTER
;
1278 netdev
->features
|= NETIF_F_IPV6_CSUM
;
1279 netdev
->features
|= NETIF_F_TSO
;
1280 netdev
->features
|= NETIF_F_TSO6
;
1282 netdev
->features
|= NETIF_F_GRO
;
1284 netdev
->vlan_features
|= NETIF_F_TSO
;
1285 netdev
->vlan_features
|= NETIF_F_TSO6
;
1286 netdev
->vlan_features
|= NETIF_F_IP_CSUM
;
1287 netdev
->vlan_features
|= NETIF_F_SG
;
1290 netdev
->features
|= NETIF_F_HIGHDMA
;
1292 adapter
->en_mng_pt
= igb_enable_mng_pass_thru(&adapter
->hw
);
1294 /* before reading the NVM, reset the controller to put the device in a
1295 * known good starting state */
1296 hw
->mac
.ops
.reset_hw(hw
);
1298 /* make sure the NVM is good */
1299 if (igb_validate_nvm_checksum(hw
) < 0) {
1300 dev_err(&pdev
->dev
, "The NVM Checksum Is Not Valid\n");
1305 /* copy the MAC address out of the NVM */
1306 if (hw
->mac
.ops
.read_mac_addr(hw
))
1307 dev_err(&pdev
->dev
, "NVM Read Error\n");
1309 memcpy(netdev
->dev_addr
, hw
->mac
.addr
, netdev
->addr_len
);
1310 memcpy(netdev
->perm_addr
, hw
->mac
.addr
, netdev
->addr_len
);
1312 if (!is_valid_ether_addr(netdev
->perm_addr
)) {
1313 dev_err(&pdev
->dev
, "Invalid MAC Address\n");
1318 setup_timer(&adapter
->watchdog_timer
, &igb_watchdog
,
1319 (unsigned long) adapter
);
1320 setup_timer(&adapter
->phy_info_timer
, &igb_update_phy_info
,
1321 (unsigned long) adapter
);
1323 INIT_WORK(&adapter
->reset_task
, igb_reset_task
);
1324 INIT_WORK(&adapter
->watchdog_task
, igb_watchdog_task
);
1326 /* Initialize link properties that are user-changeable */
1327 adapter
->fc_autoneg
= true;
1328 hw
->mac
.autoneg
= true;
1329 hw
->phy
.autoneg_advertised
= 0x2f;
1331 hw
->fc
.original_type
= e1000_fc_default
;
1332 hw
->fc
.type
= e1000_fc_default
;
1334 adapter
->itr_setting
= IGB_DEFAULT_ITR
;
1335 adapter
->itr
= IGB_START_ITR
;
1337 igb_validate_mdi_setting(hw
);
1339 adapter
->rx_csum
= 1;
1341 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1342 * enable the ACPI Magic Packet filter
1345 if (hw
->bus
.func
== 0)
1346 hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_A
, 1, &eeprom_data
);
1347 else if (hw
->bus
.func
== 1)
1348 hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL3_PORT_B
, 1, &eeprom_data
);
1350 if (eeprom_data
& eeprom_apme_mask
)
1351 adapter
->eeprom_wol
|= E1000_WUFC_MAG
;
1353 /* now that we have the eeprom settings, apply the special cases where
1354 * the eeprom may be wrong or the board simply won't support wake on
1355 * lan on a particular port */
1356 switch (pdev
->device
) {
1357 case E1000_DEV_ID_82575GB_QUAD_COPPER
:
1358 adapter
->eeprom_wol
= 0;
1360 case E1000_DEV_ID_82575EB_FIBER_SERDES
:
1361 case E1000_DEV_ID_82576_FIBER
:
1362 case E1000_DEV_ID_82576_SERDES
:
1363 /* Wake events only supported on port A for dual fiber
1364 * regardless of eeprom setting */
1365 if (rd32(E1000_STATUS
) & E1000_STATUS_FUNC_1
)
1366 adapter
->eeprom_wol
= 0;
1368 case E1000_DEV_ID_82576_QUAD_COPPER
:
1369 /* if quad port adapter, disable WoL on all but port A */
1370 if (global_quad_port_a
!= 0)
1371 adapter
->eeprom_wol
= 0;
1373 adapter
->flags
|= IGB_FLAG_QUAD_PORT_A
;
1374 /* Reset for multiple quad port adapters */
1375 if (++global_quad_port_a
== 4)
1376 global_quad_port_a
= 0;
1380 /* initialize the wol settings based on the eeprom settings */
1381 adapter
->wol
= adapter
->eeprom_wol
;
1382 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
1384 /* reset the hardware with the new settings */
1387 /* let the f/w know that the h/w is now under the control of the
1389 igb_get_hw_control(adapter
);
1391 /* tell the stack to leave us alone until igb_open() is called */
1392 netif_carrier_off(netdev
);
1393 netif_tx_stop_all_queues(netdev
);
1395 strcpy(netdev
->name
, "eth%d");
1396 err
= register_netdev(netdev
);
1400 #ifdef CONFIG_PCI_IOV
1401 /* since iov functionality isn't critical to base device function we
1402 * can accept failure. If it fails we don't allow iov to be enabled */
1403 if (hw
->mac
.type
== e1000_82576
) {
1404 err
= pci_enable_sriov(pdev
, 0);
1406 err
= device_create_file(&netdev
->dev
,
1409 dev_err(&pdev
->dev
, "Failed to initialize IOV\n");
1413 #ifdef CONFIG_IGB_DCA
1414 if (dca_add_requester(&pdev
->dev
) == 0) {
1415 adapter
->flags
|= IGB_FLAG_DCA_ENABLED
;
1416 dev_info(&pdev
->dev
, "DCA enabled\n");
1417 /* Always use CB2 mode, difference is masked
1418 * in the CB driver. */
1419 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_CB2
);
1420 igb_setup_dca(adapter
);
1425 * Initialize hardware timer: we keep it running just in case
1426 * that some program needs it later on.
1428 memset(&adapter
->cycles
, 0, sizeof(adapter
->cycles
));
1429 adapter
->cycles
.read
= igb_read_clock
;
1430 adapter
->cycles
.mask
= CLOCKSOURCE_MASK(64);
1431 adapter
->cycles
.mult
= 1;
1432 adapter
->cycles
.shift
= IGB_TSYNC_SHIFT
;
1435 IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS
* IGB_TSYNC_SCALE
);
1438 * Avoid rollover while we initialize by resetting the time counter.
1440 wr32(E1000_SYSTIML
, 0x00000000);
1441 wr32(E1000_SYSTIMH
, 0x00000000);
1444 * Set registers so that rollover occurs soon to test this.
1446 wr32(E1000_SYSTIML
, 0x00000000);
1447 wr32(E1000_SYSTIMH
, 0xFF800000);
1450 timecounter_init(&adapter
->clock
,
1452 ktime_to_ns(ktime_get_real()));
1455 * Synchronize our NIC clock against system wall clock. NIC
1456 * time stamp reading requires ~3us per sample, each sample
1457 * was pretty stable even under load => only require 10
1458 * samples for each offset comparison.
1460 memset(&adapter
->compare
, 0, sizeof(adapter
->compare
));
1461 adapter
->compare
.source
= &adapter
->clock
;
1462 adapter
->compare
.target
= ktime_get_real
;
1463 adapter
->compare
.num_samples
= 10;
1464 timecompare_update(&adapter
->compare
, 0);
1470 "igb: %s: hw %p initialized timer\n",
1471 igb_get_time_str(adapter
, buffer
),
1476 dev_info(&pdev
->dev
, "Intel(R) Gigabit Ethernet Network Connection\n");
1477 /* print bus type/speed/width info */
1478 dev_info(&pdev
->dev
, "%s: (PCIe:%s:%s) %pM\n",
1480 ((hw
->bus
.speed
== e1000_bus_speed_2500
)
1481 ? "2.5Gb/s" : "unknown"),
1482 ((hw
->bus
.width
== e1000_bus_width_pcie_x4
) ? "Width x4" :
1483 (hw
->bus
.width
== e1000_bus_width_pcie_x2
) ? "Width x2" :
1484 (hw
->bus
.width
== e1000_bus_width_pcie_x1
) ? "Width x1" :
1488 igb_read_part_num(hw
, &part_num
);
1489 dev_info(&pdev
->dev
, "%s: PBA No: %06x-%03x\n", netdev
->name
,
1490 (part_num
>> 8), (part_num
& 0xff));
1492 dev_info(&pdev
->dev
,
1493 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
1494 adapter
->msix_entries
? "MSI-X" :
1495 (adapter
->flags
& IGB_FLAG_HAS_MSI
) ? "MSI" : "legacy",
1496 adapter
->num_rx_queues
, adapter
->num_tx_queues
);
1501 igb_release_hw_control(adapter
);
1503 if (!igb_check_reset_block(hw
))
1506 if (hw
->flash_address
)
1507 iounmap(hw
->flash_address
);
1509 igb_free_queues(adapter
);
1511 iounmap(hw
->hw_addr
);
1513 free_netdev(netdev
);
1515 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
1519 pci_disable_device(pdev
);
1524 * igb_remove - Device Removal Routine
1525 * @pdev: PCI device information struct
1527 * igb_remove is called by the PCI subsystem to alert the driver
1528 * that it should release a PCI device. The could be caused by a
1529 * Hot-Plug event, or because the driver is going to be removed from
1532 static void __devexit
igb_remove(struct pci_dev
*pdev
)
1534 struct net_device
*netdev
= pci_get_drvdata(pdev
);
1535 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1536 struct e1000_hw
*hw
= &adapter
->hw
;
1539 /* flush_scheduled work may reschedule our watchdog task, so
1540 * explicitly disable watchdog tasks from being rescheduled */
1541 set_bit(__IGB_DOWN
, &adapter
->state
);
1542 del_timer_sync(&adapter
->watchdog_timer
);
1543 del_timer_sync(&adapter
->phy_info_timer
);
1545 flush_scheduled_work();
1547 #ifdef CONFIG_IGB_DCA
1548 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
) {
1549 dev_info(&pdev
->dev
, "DCA disabled\n");
1550 dca_remove_requester(&pdev
->dev
);
1551 adapter
->flags
&= ~IGB_FLAG_DCA_ENABLED
;
1552 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_DISABLE
);
1556 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1557 * would have already happened in close and is redundant. */
1558 igb_release_hw_control(adapter
);
1560 unregister_netdev(netdev
);
1562 if (!igb_check_reset_block(&adapter
->hw
))
1563 igb_reset_phy(&adapter
->hw
);
1565 igb_reset_interrupt_capability(adapter
);
1567 igb_free_queues(adapter
);
1569 #ifdef CONFIG_PCI_IOV
1570 /* reclaim resources allocated to VFs */
1571 if (adapter
->vf_data
) {
1572 /* disable iov and allow time for transactions to clear */
1573 pci_disable_sriov(pdev
);
1576 kfree(adapter
->vf_data
);
1577 adapter
->vf_data
= NULL
;
1578 wr32(E1000_IOVCTL
, E1000_IOVCTL_REUSE_VFQ
);
1580 dev_info(&pdev
->dev
, "IOV Disabled\n");
1583 iounmap(hw
->hw_addr
);
1584 if (hw
->flash_address
)
1585 iounmap(hw
->flash_address
);
1586 pci_release_selected_regions(pdev
, pci_select_bars(pdev
,
1589 free_netdev(netdev
);
1591 err
= pci_disable_pcie_error_reporting(pdev
);
1594 "pci_disable_pcie_error_reporting failed 0x%x\n", err
);
1596 pci_disable_device(pdev
);
1600 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1601 * @adapter: board private structure to initialize
1603 * igb_sw_init initializes the Adapter private data structure.
1604 * Fields are initialized based on PCI device information and
1605 * OS network device settings (MTU size).
1607 static int __devinit
igb_sw_init(struct igb_adapter
*adapter
)
1609 struct e1000_hw
*hw
= &adapter
->hw
;
1610 struct net_device
*netdev
= adapter
->netdev
;
1611 struct pci_dev
*pdev
= adapter
->pdev
;
1613 pci_read_config_word(pdev
, PCI_COMMAND
, &hw
->bus
.pci_cmd_word
);
1615 adapter
->tx_ring_count
= IGB_DEFAULT_TXD
;
1616 adapter
->rx_ring_count
= IGB_DEFAULT_RXD
;
1617 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
1618 adapter
->rx_ps_hdr_size
= 0; /* disable packet split */
1619 adapter
->max_frame_size
= netdev
->mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
1620 adapter
->min_frame_size
= ETH_ZLEN
+ ETH_FCS_LEN
;
1622 /* This call may decrease the number of queues depending on
1623 * interrupt mode. */
1624 igb_set_interrupt_capability(adapter
);
1626 if (igb_alloc_queues(adapter
)) {
1627 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
1631 /* Explicitly disable IRQ since the NIC can be in any state. */
1632 igb_irq_disable(adapter
);
1634 set_bit(__IGB_DOWN
, &adapter
->state
);
1639 * igb_open - Called when a network interface is made active
1640 * @netdev: network interface device structure
1642 * Returns 0 on success, negative value on failure
1644 * The open entry point is called when a network interface is made
1645 * active by the system (IFF_UP). At this point all resources needed
1646 * for transmit and receive operations are allocated, the interrupt
1647 * handler is registered with the OS, the watchdog timer is started,
1648 * and the stack is notified that the interface is ready.
1650 static int igb_open(struct net_device
*netdev
)
1652 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1653 struct e1000_hw
*hw
= &adapter
->hw
;
1657 /* disallow open during test */
1658 if (test_bit(__IGB_TESTING
, &adapter
->state
))
1661 /* allocate transmit descriptors */
1662 err
= igb_setup_all_tx_resources(adapter
);
1666 /* allocate receive descriptors */
1667 err
= igb_setup_all_rx_resources(adapter
);
1671 /* e1000_power_up_phy(adapter); */
1673 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
1674 if ((adapter
->hw
.mng_cookie
.status
&
1675 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
))
1676 igb_update_mng_vlan(adapter
);
1678 /* before we allocate an interrupt, we must be ready to handle it.
1679 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1680 * as soon as we call pci_request_irq, so we have to setup our
1681 * clean_rx handler before we do so. */
1682 igb_configure(adapter
);
1684 igb_vmm_control(adapter
);
1685 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, 0);
1686 igb_set_vmolr(hw
, adapter
->vfs_allocated_count
);
1688 err
= igb_request_irq(adapter
);
1692 /* From here on the code is the same as igb_up() */
1693 clear_bit(__IGB_DOWN
, &adapter
->state
);
1695 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
1696 napi_enable(&adapter
->rx_ring
[i
].napi
);
1698 /* Clear any pending interrupts. */
1701 igb_irq_enable(adapter
);
1703 netif_tx_start_all_queues(netdev
);
1705 /* Fire a link status change interrupt to start the watchdog. */
1706 wr32(E1000_ICS
, E1000_ICS_LSC
);
1711 igb_release_hw_control(adapter
);
1712 /* e1000_power_down_phy(adapter); */
1713 igb_free_all_rx_resources(adapter
);
1715 igb_free_all_tx_resources(adapter
);
1723 * igb_close - Disables a network interface
1724 * @netdev: network interface device structure
1726 * Returns 0, this is not allowed to fail
1728 * The close entry point is called when an interface is de-activated
1729 * by the OS. The hardware is still under the driver's control, but
1730 * needs to be disabled. A global MAC reset is issued to stop the
1731 * hardware, and all transmit and receive resources are freed.
1733 static int igb_close(struct net_device
*netdev
)
1735 struct igb_adapter
*adapter
= netdev_priv(netdev
);
1737 WARN_ON(test_bit(__IGB_RESETTING
, &adapter
->state
));
1740 igb_free_irq(adapter
);
1742 igb_free_all_tx_resources(adapter
);
1743 igb_free_all_rx_resources(adapter
);
1745 /* kill manageability vlan ID if supported, but not if a vlan with
1746 * the same ID is registered on the host OS (let 8021q kill it) */
1747 if ((adapter
->hw
.mng_cookie
.status
&
1748 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
1750 vlan_group_get_device(adapter
->vlgrp
, adapter
->mng_vlan_id
)))
1751 igb_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
1757 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
1758 * @adapter: board private structure
1759 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1761 * Return 0 on success, negative on failure
1763 int igb_setup_tx_resources(struct igb_adapter
*adapter
,
1764 struct igb_ring
*tx_ring
)
1766 struct pci_dev
*pdev
= adapter
->pdev
;
1769 size
= sizeof(struct igb_buffer
) * tx_ring
->count
;
1770 tx_ring
->buffer_info
= vmalloc(size
);
1771 if (!tx_ring
->buffer_info
)
1773 memset(tx_ring
->buffer_info
, 0, size
);
1775 /* round up to nearest 4K */
1776 tx_ring
->size
= tx_ring
->count
* sizeof(union e1000_adv_tx_desc
);
1777 tx_ring
->size
= ALIGN(tx_ring
->size
, 4096);
1779 tx_ring
->desc
= pci_alloc_consistent(pdev
, tx_ring
->size
,
1785 tx_ring
->adapter
= adapter
;
1786 tx_ring
->next_to_use
= 0;
1787 tx_ring
->next_to_clean
= 0;
1791 vfree(tx_ring
->buffer_info
);
1792 dev_err(&adapter
->pdev
->dev
,
1793 "Unable to allocate memory for the transmit descriptor ring\n");
1798 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
1799 * (Descriptors) for all queues
1800 * @adapter: board private structure
1802 * Return 0 on success, negative on failure
1804 static int igb_setup_all_tx_resources(struct igb_adapter
*adapter
)
1809 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1810 err
= igb_setup_tx_resources(adapter
, &adapter
->tx_ring
[i
]);
1812 dev_err(&adapter
->pdev
->dev
,
1813 "Allocation for Tx Queue %u failed\n", i
);
1814 for (i
--; i
>= 0; i
--)
1815 igb_free_tx_resources(&adapter
->tx_ring
[i
]);
1820 for (i
= 0; i
< IGB_MAX_TX_QUEUES
; i
++) {
1821 r_idx
= i
% adapter
->num_tx_queues
;
1822 adapter
->multi_tx_table
[i
] = &adapter
->tx_ring
[r_idx
];
1828 * igb_configure_tx - Configure transmit Unit after Reset
1829 * @adapter: board private structure
1831 * Configure the Tx unit of the MAC after a reset.
1833 static void igb_configure_tx(struct igb_adapter
*adapter
)
1836 struct e1000_hw
*hw
= &adapter
->hw
;
1841 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
1842 struct igb_ring
*ring
= &adapter
->tx_ring
[i
];
1844 wr32(E1000_TDLEN(j
),
1845 ring
->count
* sizeof(union e1000_adv_tx_desc
));
1847 wr32(E1000_TDBAL(j
),
1848 tdba
& 0x00000000ffffffffULL
);
1849 wr32(E1000_TDBAH(j
), tdba
>> 32);
1851 ring
->head
= E1000_TDH(j
);
1852 ring
->tail
= E1000_TDT(j
);
1853 writel(0, hw
->hw_addr
+ ring
->tail
);
1854 writel(0, hw
->hw_addr
+ ring
->head
);
1855 txdctl
= rd32(E1000_TXDCTL(j
));
1856 txdctl
|= E1000_TXDCTL_QUEUE_ENABLE
;
1857 wr32(E1000_TXDCTL(j
), txdctl
);
1859 /* Turn off Relaxed Ordering on head write-backs. The
1860 * writebacks MUST be delivered in order or it will
1861 * completely screw up our bookeeping.
1863 txctrl
= rd32(E1000_DCA_TXCTRL(j
));
1864 txctrl
&= ~E1000_DCA_TXCTRL_TX_WB_RO_EN
;
1865 wr32(E1000_DCA_TXCTRL(j
), txctrl
);
1868 /* disable queue 0 to prevent tail bump w/o re-configuration */
1869 if (adapter
->vfs_allocated_count
)
1870 wr32(E1000_TXDCTL(0), 0);
1872 /* Program the Transmit Control Register */
1873 tctl
= rd32(E1000_TCTL
);
1874 tctl
&= ~E1000_TCTL_CT
;
1875 tctl
|= E1000_TCTL_PSP
| E1000_TCTL_RTLC
|
1876 (E1000_COLLISION_THRESHOLD
<< E1000_CT_SHIFT
);
1878 igb_config_collision_dist(hw
);
1880 /* Setup Transmit Descriptor Settings for eop descriptor */
1881 adapter
->txd_cmd
= E1000_TXD_CMD_EOP
| E1000_TXD_CMD_RS
;
1883 /* Enable transmits */
1884 tctl
|= E1000_TCTL_EN
;
1886 wr32(E1000_TCTL
, tctl
);
1890 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
1891 * @adapter: board private structure
1892 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1894 * Returns 0 on success, negative on failure
1896 int igb_setup_rx_resources(struct igb_adapter
*adapter
,
1897 struct igb_ring
*rx_ring
)
1899 struct pci_dev
*pdev
= adapter
->pdev
;
1902 size
= sizeof(struct igb_buffer
) * rx_ring
->count
;
1903 rx_ring
->buffer_info
= vmalloc(size
);
1904 if (!rx_ring
->buffer_info
)
1906 memset(rx_ring
->buffer_info
, 0, size
);
1908 desc_len
= sizeof(union e1000_adv_rx_desc
);
1910 /* Round up to nearest 4K */
1911 rx_ring
->size
= rx_ring
->count
* desc_len
;
1912 rx_ring
->size
= ALIGN(rx_ring
->size
, 4096);
1914 rx_ring
->desc
= pci_alloc_consistent(pdev
, rx_ring
->size
,
1920 rx_ring
->next_to_clean
= 0;
1921 rx_ring
->next_to_use
= 0;
1923 rx_ring
->adapter
= adapter
;
1928 vfree(rx_ring
->buffer_info
);
1929 dev_err(&adapter
->pdev
->dev
, "Unable to allocate memory for "
1930 "the receive descriptor ring\n");
1935 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
1936 * (Descriptors) for all queues
1937 * @adapter: board private structure
1939 * Return 0 on success, negative on failure
1941 static int igb_setup_all_rx_resources(struct igb_adapter
*adapter
)
1945 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
1946 err
= igb_setup_rx_resources(adapter
, &adapter
->rx_ring
[i
]);
1948 dev_err(&adapter
->pdev
->dev
,
1949 "Allocation for Rx Queue %u failed\n", i
);
1950 for (i
--; i
>= 0; i
--)
1951 igb_free_rx_resources(&adapter
->rx_ring
[i
]);
1960 * igb_setup_rctl - configure the receive control registers
1961 * @adapter: Board private structure
1963 static void igb_setup_rctl(struct igb_adapter
*adapter
)
1965 struct e1000_hw
*hw
= &adapter
->hw
;
1970 rctl
= rd32(E1000_RCTL
);
1972 rctl
&= ~(3 << E1000_RCTL_MO_SHIFT
);
1973 rctl
&= ~(E1000_RCTL_LBM_TCVR
| E1000_RCTL_LBM_MAC
);
1975 rctl
|= E1000_RCTL_EN
| E1000_RCTL_BAM
| E1000_RCTL_RDMTS_HALF
|
1976 (hw
->mac
.mc_filter_type
<< E1000_RCTL_MO_SHIFT
);
1979 * enable stripping of CRC. It's unlikely this will break BMC
1980 * redirection as it did with e1000. Newer features require
1981 * that the HW strips the CRC.
1983 rctl
|= E1000_RCTL_SECRC
;
1986 * disable store bad packets and clear size bits.
1988 rctl
&= ~(E1000_RCTL_SBP
| E1000_RCTL_SZ_256
);
1990 /* enable LPE when to prevent packets larger than max_frame_size */
1991 rctl
|= E1000_RCTL_LPE
;
1993 /* Setup buffer sizes */
1994 switch (adapter
->rx_buffer_len
) {
1995 case IGB_RXBUFFER_256
:
1996 rctl
|= E1000_RCTL_SZ_256
;
1998 case IGB_RXBUFFER_512
:
1999 rctl
|= E1000_RCTL_SZ_512
;
2002 srrctl
= ALIGN(adapter
->rx_buffer_len
, 1024)
2003 >> E1000_SRRCTL_BSIZEPKT_SHIFT
;
2007 /* 82575 and greater support packet-split where the protocol
2008 * header is placed in skb->data and the packet data is
2009 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
2010 * In the case of a non-split, skb->data is linearly filled,
2011 * followed by the page buffers. Therefore, skb->data is
2012 * sized to hold the largest protocol header.
2014 /* allocations using alloc_page take too long for regular MTU
2015 * so only enable packet split for jumbo frames */
2016 if (adapter
->netdev
->mtu
> ETH_DATA_LEN
) {
2017 adapter
->rx_ps_hdr_size
= IGB_RXBUFFER_128
;
2018 srrctl
|= adapter
->rx_ps_hdr_size
<<
2019 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT
;
2020 srrctl
|= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS
;
2022 adapter
->rx_ps_hdr_size
= 0;
2023 srrctl
|= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF
;
2026 /* Attention!!! For SR-IOV PF driver operations you must enable
2027 * queue drop for all VF and PF queues to prevent head of line blocking
2028 * if an un-trusted VF does not provide descriptors to hardware.
2030 if (adapter
->vfs_allocated_count
) {
2033 j
= adapter
->rx_ring
[0].reg_idx
;
2035 /* set all queue drop enable bits */
2036 wr32(E1000_QDE
, ALL_QUEUES
);
2037 srrctl
|= E1000_SRRCTL_DROP_EN
;
2039 /* disable queue 0 to prevent tail write w/o re-config */
2040 wr32(E1000_RXDCTL(0), 0);
2042 vmolr
= rd32(E1000_VMOLR(j
));
2043 if (rctl
& E1000_RCTL_LPE
)
2044 vmolr
|= E1000_VMOLR_LPE
;
2045 if (adapter
->num_rx_queues
> 0)
2046 vmolr
|= E1000_VMOLR_RSSE
;
2047 wr32(E1000_VMOLR(j
), vmolr
);
2050 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2051 j
= adapter
->rx_ring
[i
].reg_idx
;
2052 wr32(E1000_SRRCTL(j
), srrctl
);
2055 wr32(E1000_RCTL
, rctl
);
2059 * igb_rlpml_set - set maximum receive packet size
2060 * @adapter: board private structure
2062 * Configure maximum receivable packet size.
2064 static void igb_rlpml_set(struct igb_adapter
*adapter
)
2066 u32 max_frame_size
= adapter
->max_frame_size
;
2067 struct e1000_hw
*hw
= &adapter
->hw
;
2068 u16 pf_id
= adapter
->vfs_allocated_count
;
2071 max_frame_size
+= VLAN_TAG_SIZE
;
2073 /* if vfs are enabled we set RLPML to the largest possible request
2074 * size and set the VMOLR RLPML to the size we need */
2076 igb_set_vf_rlpml(adapter
, max_frame_size
, pf_id
);
2077 max_frame_size
= MAX_STD_JUMBO_FRAME_SIZE
+ VLAN_TAG_SIZE
;
2080 wr32(E1000_RLPML
, max_frame_size
);
2084 * igb_configure_vt_default_pool - Configure VT default pool
2085 * @adapter: board private structure
2087 * Configure the default pool
2089 static void igb_configure_vt_default_pool(struct igb_adapter
*adapter
)
2091 struct e1000_hw
*hw
= &adapter
->hw
;
2092 u16 pf_id
= adapter
->vfs_allocated_count
;
2095 /* not in sr-iov mode - do nothing */
2099 vtctl
= rd32(E1000_VT_CTL
);
2100 vtctl
&= ~(E1000_VT_CTL_DEFAULT_POOL_MASK
|
2101 E1000_VT_CTL_DISABLE_DEF_POOL
);
2102 vtctl
|= pf_id
<< E1000_VT_CTL_DEFAULT_POOL_SHIFT
;
2103 wr32(E1000_VT_CTL
, vtctl
);
2107 * igb_configure_rx - Configure receive Unit after Reset
2108 * @adapter: board private structure
2110 * Configure the Rx unit of the MAC after a reset.
2112 static void igb_configure_rx(struct igb_adapter
*adapter
)
2115 struct e1000_hw
*hw
= &adapter
->hw
;
2120 /* disable receives while setting up the descriptors */
2121 rctl
= rd32(E1000_RCTL
);
2122 wr32(E1000_RCTL
, rctl
& ~E1000_RCTL_EN
);
2126 if (adapter
->itr_setting
> 3)
2127 wr32(E1000_ITR
, adapter
->itr
);
2129 /* Setup the HW Rx Head and Tail Descriptor Pointers and
2130 * the Base and Length of the Rx Descriptor Ring */
2131 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
2132 struct igb_ring
*ring
= &adapter
->rx_ring
[i
];
2133 int j
= ring
->reg_idx
;
2135 wr32(E1000_RDBAL(j
),
2136 rdba
& 0x00000000ffffffffULL
);
2137 wr32(E1000_RDBAH(j
), rdba
>> 32);
2138 wr32(E1000_RDLEN(j
),
2139 ring
->count
* sizeof(union e1000_adv_rx_desc
));
2141 ring
->head
= E1000_RDH(j
);
2142 ring
->tail
= E1000_RDT(j
);
2143 writel(0, hw
->hw_addr
+ ring
->tail
);
2144 writel(0, hw
->hw_addr
+ ring
->head
);
2146 rxdctl
= rd32(E1000_RXDCTL(j
));
2147 rxdctl
|= E1000_RXDCTL_QUEUE_ENABLE
;
2148 rxdctl
&= 0xFFF00000;
2149 rxdctl
|= IGB_RX_PTHRESH
;
2150 rxdctl
|= IGB_RX_HTHRESH
<< 8;
2151 rxdctl
|= IGB_RX_WTHRESH
<< 16;
2152 wr32(E1000_RXDCTL(j
), rxdctl
);
2155 if (adapter
->num_rx_queues
> 1) {
2164 get_random_bytes(&random
[0], 40);
2166 if (hw
->mac
.type
>= e1000_82576
)
2170 for (j
= 0; j
< (32 * 4); j
++) {
2172 adapter
->rx_ring
[(j
% adapter
->num_rx_queues
)].reg_idx
<< shift
;
2175 hw
->hw_addr
+ E1000_RETA(0) + (j
& ~3));
2177 if (adapter
->vfs_allocated_count
)
2178 mrqc
= E1000_MRQC_ENABLE_VMDQ_RSS_2Q
;
2180 mrqc
= E1000_MRQC_ENABLE_RSS_4Q
;
2182 /* Fill out hash function seeds */
2183 for (j
= 0; j
< 10; j
++)
2184 array_wr32(E1000_RSSRK(0), j
, random
[j
]);
2186 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4
|
2187 E1000_MRQC_RSS_FIELD_IPV4_TCP
);
2188 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV6
|
2189 E1000_MRQC_RSS_FIELD_IPV6_TCP
);
2190 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV4_UDP
|
2191 E1000_MRQC_RSS_FIELD_IPV6_UDP
);
2192 mrqc
|= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX
|
2193 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX
);
2196 wr32(E1000_MRQC
, mrqc
);
2198 /* Multiqueue and raw packet checksumming are mutually
2199 * exclusive. Note that this not the same as TCP/IP
2200 * checksumming, which works fine. */
2201 rxcsum
= rd32(E1000_RXCSUM
);
2202 rxcsum
|= E1000_RXCSUM_PCSD
;
2203 wr32(E1000_RXCSUM
, rxcsum
);
2205 /* Enable multi-queue for sr-iov */
2206 if (adapter
->vfs_allocated_count
)
2207 wr32(E1000_MRQC
, E1000_MRQC_ENABLE_VMDQ
);
2208 /* Enable Receive Checksum Offload for TCP and UDP */
2209 rxcsum
= rd32(E1000_RXCSUM
);
2210 if (adapter
->rx_csum
)
2211 rxcsum
|= E1000_RXCSUM_TUOFL
| E1000_RXCSUM_IPPCSE
;
2213 rxcsum
&= ~(E1000_RXCSUM_TUOFL
| E1000_RXCSUM_IPPCSE
);
2215 wr32(E1000_RXCSUM
, rxcsum
);
2218 /* Set the default pool for the PF's first queue */
2219 igb_configure_vt_default_pool(adapter
);
2221 igb_rlpml_set(adapter
);
2223 /* Enable Receives */
2224 wr32(E1000_RCTL
, rctl
);
2228 * igb_free_tx_resources - Free Tx Resources per Queue
2229 * @tx_ring: Tx descriptor ring for a specific queue
2231 * Free all transmit software resources
2233 void igb_free_tx_resources(struct igb_ring
*tx_ring
)
2235 struct pci_dev
*pdev
= tx_ring
->adapter
->pdev
;
2237 igb_clean_tx_ring(tx_ring
);
2239 vfree(tx_ring
->buffer_info
);
2240 tx_ring
->buffer_info
= NULL
;
2242 pci_free_consistent(pdev
, tx_ring
->size
, tx_ring
->desc
, tx_ring
->dma
);
2244 tx_ring
->desc
= NULL
;
2248 * igb_free_all_tx_resources - Free Tx Resources for All Queues
2249 * @adapter: board private structure
2251 * Free all transmit software resources
2253 static void igb_free_all_tx_resources(struct igb_adapter
*adapter
)
2257 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2258 igb_free_tx_resources(&adapter
->tx_ring
[i
]);
2261 static void igb_unmap_and_free_tx_resource(struct igb_adapter
*adapter
,
2262 struct igb_buffer
*buffer_info
)
2264 buffer_info
->dma
= 0;
2265 if (buffer_info
->skb
) {
2266 skb_dma_unmap(&adapter
->pdev
->dev
, buffer_info
->skb
,
2268 dev_kfree_skb_any(buffer_info
->skb
);
2269 buffer_info
->skb
= NULL
;
2271 buffer_info
->time_stamp
= 0;
2272 /* buffer_info must be completely set up in the transmit path */
2276 * igb_clean_tx_ring - Free Tx Buffers
2277 * @tx_ring: ring to be cleaned
2279 static void igb_clean_tx_ring(struct igb_ring
*tx_ring
)
2281 struct igb_adapter
*adapter
= tx_ring
->adapter
;
2282 struct igb_buffer
*buffer_info
;
2286 if (!tx_ring
->buffer_info
)
2288 /* Free all the Tx ring sk_buffs */
2290 for (i
= 0; i
< tx_ring
->count
; i
++) {
2291 buffer_info
= &tx_ring
->buffer_info
[i
];
2292 igb_unmap_and_free_tx_resource(adapter
, buffer_info
);
2295 size
= sizeof(struct igb_buffer
) * tx_ring
->count
;
2296 memset(tx_ring
->buffer_info
, 0, size
);
2298 /* Zero out the descriptor ring */
2300 memset(tx_ring
->desc
, 0, tx_ring
->size
);
2302 tx_ring
->next_to_use
= 0;
2303 tx_ring
->next_to_clean
= 0;
2305 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->head
);
2306 writel(0, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
2310 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
2311 * @adapter: board private structure
2313 static void igb_clean_all_tx_rings(struct igb_adapter
*adapter
)
2317 for (i
= 0; i
< adapter
->num_tx_queues
; i
++)
2318 igb_clean_tx_ring(&adapter
->tx_ring
[i
]);
2322 * igb_free_rx_resources - Free Rx Resources
2323 * @rx_ring: ring to clean the resources from
2325 * Free all receive software resources
2327 void igb_free_rx_resources(struct igb_ring
*rx_ring
)
2329 struct pci_dev
*pdev
= rx_ring
->adapter
->pdev
;
2331 igb_clean_rx_ring(rx_ring
);
2333 vfree(rx_ring
->buffer_info
);
2334 rx_ring
->buffer_info
= NULL
;
2336 pci_free_consistent(pdev
, rx_ring
->size
, rx_ring
->desc
, rx_ring
->dma
);
2338 rx_ring
->desc
= NULL
;
2342 * igb_free_all_rx_resources - Free Rx Resources for All Queues
2343 * @adapter: board private structure
2345 * Free all receive software resources
2347 static void igb_free_all_rx_resources(struct igb_adapter
*adapter
)
2351 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2352 igb_free_rx_resources(&adapter
->rx_ring
[i
]);
2356 * igb_clean_rx_ring - Free Rx Buffers per Queue
2357 * @rx_ring: ring to free buffers from
2359 static void igb_clean_rx_ring(struct igb_ring
*rx_ring
)
2361 struct igb_adapter
*adapter
= rx_ring
->adapter
;
2362 struct igb_buffer
*buffer_info
;
2363 struct pci_dev
*pdev
= adapter
->pdev
;
2367 if (!rx_ring
->buffer_info
)
2369 /* Free all the Rx ring sk_buffs */
2370 for (i
= 0; i
< rx_ring
->count
; i
++) {
2371 buffer_info
= &rx_ring
->buffer_info
[i
];
2372 if (buffer_info
->dma
) {
2373 if (adapter
->rx_ps_hdr_size
)
2374 pci_unmap_single(pdev
, buffer_info
->dma
,
2375 adapter
->rx_ps_hdr_size
,
2376 PCI_DMA_FROMDEVICE
);
2378 pci_unmap_single(pdev
, buffer_info
->dma
,
2379 adapter
->rx_buffer_len
,
2380 PCI_DMA_FROMDEVICE
);
2381 buffer_info
->dma
= 0;
2384 if (buffer_info
->skb
) {
2385 dev_kfree_skb(buffer_info
->skb
);
2386 buffer_info
->skb
= NULL
;
2388 if (buffer_info
->page
) {
2389 if (buffer_info
->page_dma
)
2390 pci_unmap_page(pdev
, buffer_info
->page_dma
,
2392 PCI_DMA_FROMDEVICE
);
2393 put_page(buffer_info
->page
);
2394 buffer_info
->page
= NULL
;
2395 buffer_info
->page_dma
= 0;
2396 buffer_info
->page_offset
= 0;
2400 size
= sizeof(struct igb_buffer
) * rx_ring
->count
;
2401 memset(rx_ring
->buffer_info
, 0, size
);
2403 /* Zero out the descriptor ring */
2404 memset(rx_ring
->desc
, 0, rx_ring
->size
);
2406 rx_ring
->next_to_clean
= 0;
2407 rx_ring
->next_to_use
= 0;
2409 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->head
);
2410 writel(0, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
2414 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
2415 * @adapter: board private structure
2417 static void igb_clean_all_rx_rings(struct igb_adapter
*adapter
)
2421 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2422 igb_clean_rx_ring(&adapter
->rx_ring
[i
]);
2426 * igb_set_mac - Change the Ethernet Address of the NIC
2427 * @netdev: network interface device structure
2428 * @p: pointer to an address structure
2430 * Returns 0 on success, negative on failure
2432 static int igb_set_mac(struct net_device
*netdev
, void *p
)
2434 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2435 struct e1000_hw
*hw
= &adapter
->hw
;
2436 struct sockaddr
*addr
= p
;
2438 if (!is_valid_ether_addr(addr
->sa_data
))
2439 return -EADDRNOTAVAIL
;
2441 memcpy(netdev
->dev_addr
, addr
->sa_data
, netdev
->addr_len
);
2442 memcpy(hw
->mac
.addr
, addr
->sa_data
, netdev
->addr_len
);
2444 hw
->mac
.ops
.rar_set(hw
, hw
->mac
.addr
, 0);
2446 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, 0);
2452 * igb_set_multi - Multicast and Promiscuous mode set
2453 * @netdev: network interface device structure
2455 * The set_multi entry point is called whenever the multicast address
2456 * list or the network interface flags are updated. This routine is
2457 * responsible for configuring the hardware for proper multicast,
2458 * promiscuous mode, and all-multi behavior.
2460 static void igb_set_multi(struct net_device
*netdev
)
2462 struct igb_adapter
*adapter
= netdev_priv(netdev
);
2463 struct e1000_hw
*hw
= &adapter
->hw
;
2464 struct e1000_mac_info
*mac
= &hw
->mac
;
2465 struct dev_mc_list
*mc_ptr
;
2466 u8
*mta_list
= NULL
;
2470 /* Check for Promiscuous and All Multicast modes */
2472 rctl
= rd32(E1000_RCTL
);
2474 if (netdev
->flags
& IFF_PROMISC
) {
2475 rctl
|= (E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2476 rctl
&= ~E1000_RCTL_VFE
;
2478 if (netdev
->flags
& IFF_ALLMULTI
) {
2479 rctl
|= E1000_RCTL_MPE
;
2480 rctl
&= ~E1000_RCTL_UPE
;
2482 rctl
&= ~(E1000_RCTL_UPE
| E1000_RCTL_MPE
);
2483 rctl
|= E1000_RCTL_VFE
;
2485 wr32(E1000_RCTL
, rctl
);
2487 if (netdev
->mc_count
) {
2488 mta_list
= kzalloc(netdev
->mc_count
* 6, GFP_ATOMIC
);
2490 dev_err(&adapter
->pdev
->dev
,
2491 "failed to allocate multicast filter list\n");
2496 /* The shared function expects a packed array of only addresses. */
2497 mc_ptr
= netdev
->mc_list
;
2499 for (i
= 0; i
< netdev
->mc_count
; i
++) {
2502 memcpy(mta_list
+ (i
*ETH_ALEN
), mc_ptr
->dmi_addr
, ETH_ALEN
);
2503 mc_ptr
= mc_ptr
->next
;
2505 igb_update_mc_addr_list(hw
, mta_list
, i
,
2506 adapter
->vfs_allocated_count
+ 1,
2507 mac
->rar_entry_count
);
2509 igb_set_mc_list_pools(adapter
, i
, mac
->rar_entry_count
);
2510 igb_restore_vf_multicasts(adapter
);
2515 /* Need to wait a few seconds after link up to get diagnostic information from
2517 static void igb_update_phy_info(unsigned long data
)
2519 struct igb_adapter
*adapter
= (struct igb_adapter
*) data
;
2520 igb_get_phy_info(&adapter
->hw
);
2524 * igb_has_link - check shared code for link and determine up/down
2525 * @adapter: pointer to driver private info
2527 static bool igb_has_link(struct igb_adapter
*adapter
)
2529 struct e1000_hw
*hw
= &adapter
->hw
;
2530 bool link_active
= false;
2533 /* get_link_status is set on LSC (link status) interrupt or
2534 * rx sequence error interrupt. get_link_status will stay
2535 * false until the e1000_check_for_link establishes link
2536 * for copper adapters ONLY
2538 switch (hw
->phy
.media_type
) {
2539 case e1000_media_type_copper
:
2540 if (hw
->mac
.get_link_status
) {
2541 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2542 link_active
= !hw
->mac
.get_link_status
;
2547 case e1000_media_type_fiber
:
2548 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2549 link_active
= !!(rd32(E1000_STATUS
) & E1000_STATUS_LU
);
2551 case e1000_media_type_internal_serdes
:
2552 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
2553 link_active
= hw
->mac
.serdes_has_link
;
2556 case e1000_media_type_unknown
:
2564 * igb_watchdog - Timer Call-back
2565 * @data: pointer to adapter cast into an unsigned long
2567 static void igb_watchdog(unsigned long data
)
2569 struct igb_adapter
*adapter
= (struct igb_adapter
*)data
;
2570 /* Do the rest outside of interrupt context */
2571 schedule_work(&adapter
->watchdog_task
);
2574 static void igb_watchdog_task(struct work_struct
*work
)
2576 struct igb_adapter
*adapter
= container_of(work
,
2577 struct igb_adapter
, watchdog_task
);
2578 struct e1000_hw
*hw
= &adapter
->hw
;
2579 struct net_device
*netdev
= adapter
->netdev
;
2580 struct igb_ring
*tx_ring
= adapter
->tx_ring
;
2585 link
= igb_has_link(adapter
);
2586 if ((netif_carrier_ok(netdev
)) && link
)
2590 if (!netif_carrier_ok(netdev
)) {
2592 hw
->mac
.ops
.get_speed_and_duplex(&adapter
->hw
,
2593 &adapter
->link_speed
,
2594 &adapter
->link_duplex
);
2596 ctrl
= rd32(E1000_CTRL
);
2597 /* Links status message must follow this format */
2598 printk(KERN_INFO
"igb: %s NIC Link is Up %d Mbps %s, "
2599 "Flow Control: %s\n",
2601 adapter
->link_speed
,
2602 adapter
->link_duplex
== FULL_DUPLEX
?
2603 "Full Duplex" : "Half Duplex",
2604 ((ctrl
& E1000_CTRL_TFCE
) && (ctrl
&
2605 E1000_CTRL_RFCE
)) ? "RX/TX" : ((ctrl
&
2606 E1000_CTRL_RFCE
) ? "RX" : ((ctrl
&
2607 E1000_CTRL_TFCE
) ? "TX" : "None")));
2609 /* tweak tx_queue_len according to speed/duplex and
2610 * adjust the timeout factor */
2611 netdev
->tx_queue_len
= adapter
->tx_queue_len
;
2612 adapter
->tx_timeout_factor
= 1;
2613 switch (adapter
->link_speed
) {
2615 netdev
->tx_queue_len
= 10;
2616 adapter
->tx_timeout_factor
= 14;
2619 netdev
->tx_queue_len
= 100;
2620 /* maybe add some timeout factor ? */
2624 netif_carrier_on(netdev
);
2625 netif_tx_wake_all_queues(netdev
);
2627 igb_ping_all_vfs(adapter
);
2629 /* link state has changed, schedule phy info update */
2630 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2631 mod_timer(&adapter
->phy_info_timer
,
2632 round_jiffies(jiffies
+ 2 * HZ
));
2635 if (netif_carrier_ok(netdev
)) {
2636 adapter
->link_speed
= 0;
2637 adapter
->link_duplex
= 0;
2638 /* Links status message must follow this format */
2639 printk(KERN_INFO
"igb: %s NIC Link is Down\n",
2641 netif_carrier_off(netdev
);
2642 netif_tx_stop_all_queues(netdev
);
2644 igb_ping_all_vfs(adapter
);
2646 /* link state has changed, schedule phy info update */
2647 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2648 mod_timer(&adapter
->phy_info_timer
,
2649 round_jiffies(jiffies
+ 2 * HZ
));
2654 igb_update_stats(adapter
);
2656 hw
->mac
.tx_packet_delta
= adapter
->stats
.tpt
- adapter
->tpt_old
;
2657 adapter
->tpt_old
= adapter
->stats
.tpt
;
2658 hw
->mac
.collision_delta
= adapter
->stats
.colc
- adapter
->colc_old
;
2659 adapter
->colc_old
= adapter
->stats
.colc
;
2661 adapter
->gorc
= adapter
->stats
.gorc
- adapter
->gorc_old
;
2662 adapter
->gorc_old
= adapter
->stats
.gorc
;
2663 adapter
->gotc
= adapter
->stats
.gotc
- adapter
->gotc_old
;
2664 adapter
->gotc_old
= adapter
->stats
.gotc
;
2666 igb_update_adaptive(&adapter
->hw
);
2668 if (!netif_carrier_ok(netdev
)) {
2669 if (igb_desc_unused(tx_ring
) + 1 < tx_ring
->count
) {
2670 /* We've lost link, so the controller stops DMA,
2671 * but we've got queued Tx work that's never going
2672 * to get done, so reset controller to flush Tx.
2673 * (Do the reset outside of interrupt context). */
2674 adapter
->tx_timeout_count
++;
2675 schedule_work(&adapter
->reset_task
);
2679 /* Cause software interrupt to ensure rx ring is cleaned */
2680 if (adapter
->msix_entries
) {
2681 for (i
= 0; i
< adapter
->num_rx_queues
; i
++)
2682 eics
|= adapter
->rx_ring
[i
].eims_value
;
2683 wr32(E1000_EICS
, eics
);
2685 wr32(E1000_ICS
, E1000_ICS_RXDMT0
);
2688 /* Force detection of hung controller every watchdog period */
2689 tx_ring
->detect_tx_hung
= true;
2691 /* Reset the timer */
2692 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
2693 mod_timer(&adapter
->watchdog_timer
,
2694 round_jiffies(jiffies
+ 2 * HZ
));
2697 enum latency_range
{
2701 latency_invalid
= 255
2706 * igb_update_ring_itr - update the dynamic ITR value based on packet size
2708 * Stores a new ITR value based on strictly on packet size. This
2709 * algorithm is less sophisticated than that used in igb_update_itr,
2710 * due to the difficulty of synchronizing statistics across multiple
2711 * receive rings. The divisors and thresholds used by this fuction
2712 * were determined based on theoretical maximum wire speed and testing
2713 * data, in order to minimize response time while increasing bulk
2715 * This functionality is controlled by the InterruptThrottleRate module
2716 * parameter (see igb_param.c)
2717 * NOTE: This function is called only when operating in a multiqueue
2718 * receive environment.
2719 * @rx_ring: pointer to ring
2721 static void igb_update_ring_itr(struct igb_ring
*rx_ring
)
2723 int new_val
= rx_ring
->itr_val
;
2724 int avg_wire_size
= 0;
2725 struct igb_adapter
*adapter
= rx_ring
->adapter
;
2727 if (!rx_ring
->total_packets
)
2728 goto clear_counts
; /* no packets, so don't do anything */
2730 /* For non-gigabit speeds, just fix the interrupt rate at 4000
2731 * ints/sec - ITR timer value of 120 ticks.
2733 if (adapter
->link_speed
!= SPEED_1000
) {
2737 avg_wire_size
= rx_ring
->total_bytes
/ rx_ring
->total_packets
;
2739 /* Add 24 bytes to size to account for CRC, preamble, and gap */
2740 avg_wire_size
+= 24;
2742 /* Don't starve jumbo frames */
2743 avg_wire_size
= min(avg_wire_size
, 3000);
2745 /* Give a little boost to mid-size frames */
2746 if ((avg_wire_size
> 300) && (avg_wire_size
< 1200))
2747 new_val
= avg_wire_size
/ 3;
2749 new_val
= avg_wire_size
/ 2;
2752 if (new_val
!= rx_ring
->itr_val
) {
2753 rx_ring
->itr_val
= new_val
;
2754 rx_ring
->set_itr
= 1;
2757 rx_ring
->total_bytes
= 0;
2758 rx_ring
->total_packets
= 0;
2762 * igb_update_itr - update the dynamic ITR value based on statistics
2763 * Stores a new ITR value based on packets and byte
2764 * counts during the last interrupt. The advantage of per interrupt
2765 * computation is faster updates and more accurate ITR for the current
2766 * traffic pattern. Constants in this function were computed
2767 * based on theoretical maximum wire speed and thresholds were set based
2768 * on testing data as well as attempting to minimize response time
2769 * while increasing bulk throughput.
2770 * this functionality is controlled by the InterruptThrottleRate module
2771 * parameter (see igb_param.c)
2772 * NOTE: These calculations are only valid when operating in a single-
2773 * queue environment.
2774 * @adapter: pointer to adapter
2775 * @itr_setting: current adapter->itr
2776 * @packets: the number of packets during this measurement interval
2777 * @bytes: the number of bytes during this measurement interval
2779 static unsigned int igb_update_itr(struct igb_adapter
*adapter
, u16 itr_setting
,
2780 int packets
, int bytes
)
2782 unsigned int retval
= itr_setting
;
2785 goto update_itr_done
;
2787 switch (itr_setting
) {
2788 case lowest_latency
:
2789 /* handle TSO and jumbo frames */
2790 if (bytes
/packets
> 8000)
2791 retval
= bulk_latency
;
2792 else if ((packets
< 5) && (bytes
> 512))
2793 retval
= low_latency
;
2795 case low_latency
: /* 50 usec aka 20000 ints/s */
2796 if (bytes
> 10000) {
2797 /* this if handles the TSO accounting */
2798 if (bytes
/packets
> 8000) {
2799 retval
= bulk_latency
;
2800 } else if ((packets
< 10) || ((bytes
/packets
) > 1200)) {
2801 retval
= bulk_latency
;
2802 } else if ((packets
> 35)) {
2803 retval
= lowest_latency
;
2805 } else if (bytes
/packets
> 2000) {
2806 retval
= bulk_latency
;
2807 } else if (packets
<= 2 && bytes
< 512) {
2808 retval
= lowest_latency
;
2811 case bulk_latency
: /* 250 usec aka 4000 ints/s */
2812 if (bytes
> 25000) {
2814 retval
= low_latency
;
2815 } else if (bytes
< 1500) {
2816 retval
= low_latency
;
2825 static void igb_set_itr(struct igb_adapter
*adapter
)
2828 u32 new_itr
= adapter
->itr
;
2830 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2831 if (adapter
->link_speed
!= SPEED_1000
) {
2837 adapter
->rx_itr
= igb_update_itr(adapter
,
2839 adapter
->rx_ring
->total_packets
,
2840 adapter
->rx_ring
->total_bytes
);
2842 if (adapter
->rx_ring
->buddy
) {
2843 adapter
->tx_itr
= igb_update_itr(adapter
,
2845 adapter
->tx_ring
->total_packets
,
2846 adapter
->tx_ring
->total_bytes
);
2847 current_itr
= max(adapter
->rx_itr
, adapter
->tx_itr
);
2849 current_itr
= adapter
->rx_itr
;
2852 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2853 if (adapter
->itr_setting
== 3 && current_itr
== lowest_latency
)
2854 current_itr
= low_latency
;
2856 switch (current_itr
) {
2857 /* counts and packets in update_itr are dependent on these numbers */
2858 case lowest_latency
:
2862 new_itr
= 20000; /* aka hwitr = ~200 */
2872 adapter
->rx_ring
->total_bytes
= 0;
2873 adapter
->rx_ring
->total_packets
= 0;
2874 if (adapter
->rx_ring
->buddy
) {
2875 adapter
->rx_ring
->buddy
->total_bytes
= 0;
2876 adapter
->rx_ring
->buddy
->total_packets
= 0;
2879 if (new_itr
!= adapter
->itr
) {
2880 /* this attempts to bias the interrupt rate towards Bulk
2881 * by adding intermediate steps when interrupt rate is
2883 new_itr
= new_itr
> adapter
->itr
?
2884 min(adapter
->itr
+ (new_itr
>> 2), new_itr
) :
2886 /* Don't write the value here; it resets the adapter's
2887 * internal timer, and causes us to delay far longer than
2888 * we should between interrupts. Instead, we write the ITR
2889 * value at the beginning of the next interrupt so the timing
2890 * ends up being correct.
2892 adapter
->itr
= new_itr
;
2893 adapter
->rx_ring
->itr_val
= 1000000000 / (new_itr
* 256);
2894 adapter
->rx_ring
->set_itr
= 1;
2901 #define IGB_TX_FLAGS_CSUM 0x00000001
2902 #define IGB_TX_FLAGS_VLAN 0x00000002
2903 #define IGB_TX_FLAGS_TSO 0x00000004
2904 #define IGB_TX_FLAGS_IPV4 0x00000008
2905 #define IGB_TX_FLAGS_TSTAMP 0x00000010
2906 #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
2907 #define IGB_TX_FLAGS_VLAN_SHIFT 16
2909 static inline int igb_tso_adv(struct igb_adapter
*adapter
,
2910 struct igb_ring
*tx_ring
,
2911 struct sk_buff
*skb
, u32 tx_flags
, u8
*hdr_len
)
2913 struct e1000_adv_tx_context_desc
*context_desc
;
2916 struct igb_buffer
*buffer_info
;
2917 u32 info
= 0, tu_cmd
= 0;
2918 u32 mss_l4len_idx
, l4len
;
2921 if (skb_header_cloned(skb
)) {
2922 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2927 l4len
= tcp_hdrlen(skb
);
2930 if (skb
->protocol
== htons(ETH_P_IP
)) {
2931 struct iphdr
*iph
= ip_hdr(skb
);
2934 tcp_hdr(skb
)->check
= ~csum_tcpudp_magic(iph
->saddr
,
2938 } else if (skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
) {
2939 ipv6_hdr(skb
)->payload_len
= 0;
2940 tcp_hdr(skb
)->check
= ~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
2941 &ipv6_hdr(skb
)->daddr
,
2945 i
= tx_ring
->next_to_use
;
2947 buffer_info
= &tx_ring
->buffer_info
[i
];
2948 context_desc
= E1000_TX_CTXTDESC_ADV(*tx_ring
, i
);
2949 /* VLAN MACLEN IPLEN */
2950 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
2951 info
|= (tx_flags
& IGB_TX_FLAGS_VLAN_MASK
);
2952 info
|= (skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
);
2953 *hdr_len
+= skb_network_offset(skb
);
2954 info
|= skb_network_header_len(skb
);
2955 *hdr_len
+= skb_network_header_len(skb
);
2956 context_desc
->vlan_macip_lens
= cpu_to_le32(info
);
2958 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2959 tu_cmd
|= (E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
);
2961 if (skb
->protocol
== htons(ETH_P_IP
))
2962 tu_cmd
|= E1000_ADVTXD_TUCMD_IPV4
;
2963 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
2965 context_desc
->type_tucmd_mlhl
= cpu_to_le32(tu_cmd
);
2968 mss_l4len_idx
= (skb_shinfo(skb
)->gso_size
<< E1000_ADVTXD_MSS_SHIFT
);
2969 mss_l4len_idx
|= (l4len
<< E1000_ADVTXD_L4LEN_SHIFT
);
2971 /* For 82575, context index must be unique per ring. */
2972 if (adapter
->flags
& IGB_FLAG_NEED_CTX_IDX
)
2973 mss_l4len_idx
|= tx_ring
->queue_index
<< 4;
2975 context_desc
->mss_l4len_idx
= cpu_to_le32(mss_l4len_idx
);
2976 context_desc
->seqnum_seed
= 0;
2978 buffer_info
->time_stamp
= jiffies
;
2979 buffer_info
->next_to_watch
= i
;
2980 buffer_info
->dma
= 0;
2982 if (i
== tx_ring
->count
)
2985 tx_ring
->next_to_use
= i
;
2990 static inline bool igb_tx_csum_adv(struct igb_adapter
*adapter
,
2991 struct igb_ring
*tx_ring
,
2992 struct sk_buff
*skb
, u32 tx_flags
)
2994 struct e1000_adv_tx_context_desc
*context_desc
;
2996 struct igb_buffer
*buffer_info
;
2997 u32 info
= 0, tu_cmd
= 0;
2999 if ((skb
->ip_summed
== CHECKSUM_PARTIAL
) ||
3000 (tx_flags
& IGB_TX_FLAGS_VLAN
)) {
3001 i
= tx_ring
->next_to_use
;
3002 buffer_info
= &tx_ring
->buffer_info
[i
];
3003 context_desc
= E1000_TX_CTXTDESC_ADV(*tx_ring
, i
);
3005 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
3006 info
|= (tx_flags
& IGB_TX_FLAGS_VLAN_MASK
);
3007 info
|= (skb_network_offset(skb
) << E1000_ADVTXD_MACLEN_SHIFT
);
3008 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
3009 info
|= skb_network_header_len(skb
);
3011 context_desc
->vlan_macip_lens
= cpu_to_le32(info
);
3013 tu_cmd
|= (E1000_TXD_CMD_DEXT
| E1000_ADVTXD_DTYP_CTXT
);
3015 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
3018 if (skb
->protocol
== cpu_to_be16(ETH_P_8021Q
)) {
3019 const struct vlan_ethhdr
*vhdr
=
3020 (const struct vlan_ethhdr
*)skb
->data
;
3022 protocol
= vhdr
->h_vlan_encapsulated_proto
;
3024 protocol
= skb
->protocol
;
3028 case cpu_to_be16(ETH_P_IP
):
3029 tu_cmd
|= E1000_ADVTXD_TUCMD_IPV4
;
3030 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
3031 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
3033 case cpu_to_be16(ETH_P_IPV6
):
3034 /* XXX what about other V6 headers?? */
3035 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
3036 tu_cmd
|= E1000_ADVTXD_TUCMD_L4T_TCP
;
3039 if (unlikely(net_ratelimit()))
3040 dev_warn(&adapter
->pdev
->dev
,
3041 "partial checksum but proto=%x!\n",
3047 context_desc
->type_tucmd_mlhl
= cpu_to_le32(tu_cmd
);
3048 context_desc
->seqnum_seed
= 0;
3049 if (adapter
->flags
& IGB_FLAG_NEED_CTX_IDX
)
3050 context_desc
->mss_l4len_idx
=
3051 cpu_to_le32(tx_ring
->queue_index
<< 4);
3053 context_desc
->mss_l4len_idx
= 0;
3055 buffer_info
->time_stamp
= jiffies
;
3056 buffer_info
->next_to_watch
= i
;
3057 buffer_info
->dma
= 0;
3060 if (i
== tx_ring
->count
)
3062 tx_ring
->next_to_use
= i
;
3069 #define IGB_MAX_TXD_PWR 16
3070 #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
3072 static inline int igb_tx_map_adv(struct igb_adapter
*adapter
,
3073 struct igb_ring
*tx_ring
, struct sk_buff
*skb
,
3076 struct igb_buffer
*buffer_info
;
3077 unsigned int len
= skb_headlen(skb
);
3078 unsigned int count
= 0, i
;
3082 i
= tx_ring
->next_to_use
;
3084 if (skb_dma_map(&adapter
->pdev
->dev
, skb
, DMA_TO_DEVICE
)) {
3085 dev_err(&adapter
->pdev
->dev
, "TX DMA map failed\n");
3089 map
= skb_shinfo(skb
)->dma_maps
;
3091 buffer_info
= &tx_ring
->buffer_info
[i
];
3092 BUG_ON(len
>= IGB_MAX_DATA_PER_TXD
);
3093 buffer_info
->length
= len
;
3094 /* set time_stamp *before* dma to help avoid a possible race */
3095 buffer_info
->time_stamp
= jiffies
;
3096 buffer_info
->next_to_watch
= i
;
3097 buffer_info
->dma
= map
[count
];
3100 for (f
= 0; f
< skb_shinfo(skb
)->nr_frags
; f
++) {
3101 struct skb_frag_struct
*frag
;
3104 if (i
== tx_ring
->count
)
3107 frag
= &skb_shinfo(skb
)->frags
[f
];
3110 buffer_info
= &tx_ring
->buffer_info
[i
];
3111 BUG_ON(len
>= IGB_MAX_DATA_PER_TXD
);
3112 buffer_info
->length
= len
;
3113 buffer_info
->time_stamp
= jiffies
;
3114 buffer_info
->next_to_watch
= i
;
3115 buffer_info
->dma
= map
[count
];
3119 tx_ring
->buffer_info
[i
].skb
= skb
;
3120 tx_ring
->buffer_info
[first
].next_to_watch
= i
;
3125 static inline void igb_tx_queue_adv(struct igb_adapter
*adapter
,
3126 struct igb_ring
*tx_ring
,
3127 int tx_flags
, int count
, u32 paylen
,
3130 union e1000_adv_tx_desc
*tx_desc
= NULL
;
3131 struct igb_buffer
*buffer_info
;
3132 u32 olinfo_status
= 0, cmd_type_len
;
3135 cmd_type_len
= (E1000_ADVTXD_DTYP_DATA
| E1000_ADVTXD_DCMD_IFCS
|
3136 E1000_ADVTXD_DCMD_DEXT
);
3138 if (tx_flags
& IGB_TX_FLAGS_VLAN
)
3139 cmd_type_len
|= E1000_ADVTXD_DCMD_VLE
;
3141 if (tx_flags
& IGB_TX_FLAGS_TSTAMP
)
3142 cmd_type_len
|= E1000_ADVTXD_MAC_TSTAMP
;
3144 if (tx_flags
& IGB_TX_FLAGS_TSO
) {
3145 cmd_type_len
|= E1000_ADVTXD_DCMD_TSE
;
3147 /* insert tcp checksum */
3148 olinfo_status
|= E1000_TXD_POPTS_TXSM
<< 8;
3150 /* insert ip checksum */
3151 if (tx_flags
& IGB_TX_FLAGS_IPV4
)
3152 olinfo_status
|= E1000_TXD_POPTS_IXSM
<< 8;
3154 } else if (tx_flags
& IGB_TX_FLAGS_CSUM
) {
3155 olinfo_status
|= E1000_TXD_POPTS_TXSM
<< 8;
3158 if ((adapter
->flags
& IGB_FLAG_NEED_CTX_IDX
) &&
3159 (tx_flags
& (IGB_TX_FLAGS_CSUM
| IGB_TX_FLAGS_TSO
|
3160 IGB_TX_FLAGS_VLAN
)))
3161 olinfo_status
|= tx_ring
->queue_index
<< 4;
3163 olinfo_status
|= ((paylen
- hdr_len
) << E1000_ADVTXD_PAYLEN_SHIFT
);
3165 i
= tx_ring
->next_to_use
;
3167 buffer_info
= &tx_ring
->buffer_info
[i
];
3168 tx_desc
= E1000_TX_DESC_ADV(*tx_ring
, i
);
3169 tx_desc
->read
.buffer_addr
= cpu_to_le64(buffer_info
->dma
);
3170 tx_desc
->read
.cmd_type_len
=
3171 cpu_to_le32(cmd_type_len
| buffer_info
->length
);
3172 tx_desc
->read
.olinfo_status
= cpu_to_le32(olinfo_status
);
3174 if (i
== tx_ring
->count
)
3178 tx_desc
->read
.cmd_type_len
|= cpu_to_le32(adapter
->txd_cmd
);
3179 /* Force memory writes to complete before letting h/w
3180 * know there are new descriptors to fetch. (Only
3181 * applicable for weak-ordered memory model archs,
3182 * such as IA-64). */
3185 tx_ring
->next_to_use
= i
;
3186 writel(i
, adapter
->hw
.hw_addr
+ tx_ring
->tail
);
3187 /* we need this if more than one processor can write to our tail
3188 * at a time, it syncronizes IO on IA64/Altix systems */
3192 static int __igb_maybe_stop_tx(struct net_device
*netdev
,
3193 struct igb_ring
*tx_ring
, int size
)
3195 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3197 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
3199 /* Herbert's original patch had:
3200 * smp_mb__after_netif_stop_queue();
3201 * but since that doesn't exist yet, just open code it. */
3204 /* We need to check again in a case another CPU has just
3205 * made room available. */
3206 if (igb_desc_unused(tx_ring
) < size
)
3210 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
3211 ++adapter
->restart_queue
;
3215 static int igb_maybe_stop_tx(struct net_device
*netdev
,
3216 struct igb_ring
*tx_ring
, int size
)
3218 if (igb_desc_unused(tx_ring
) >= size
)
3220 return __igb_maybe_stop_tx(netdev
, tx_ring
, size
);
3223 static int igb_xmit_frame_ring_adv(struct sk_buff
*skb
,
3224 struct net_device
*netdev
,
3225 struct igb_ring
*tx_ring
)
3227 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3229 unsigned int tx_flags
= 0;
3233 union skb_shared_tx
*shtx
;
3235 if (test_bit(__IGB_DOWN
, &adapter
->state
)) {
3236 dev_kfree_skb_any(skb
);
3237 return NETDEV_TX_OK
;
3240 if (skb
->len
<= 0) {
3241 dev_kfree_skb_any(skb
);
3242 return NETDEV_TX_OK
;
3245 /* need: 1 descriptor per page,
3246 * + 2 desc gap to keep tail from touching head,
3247 * + 1 desc for skb->data,
3248 * + 1 desc for context descriptor,
3249 * otherwise try next time */
3250 if (igb_maybe_stop_tx(netdev
, tx_ring
, skb_shinfo(skb
)->nr_frags
+ 4)) {
3251 /* this is a hard error */
3252 return NETDEV_TX_BUSY
;
3256 * TODO: check that there currently is no other packet with
3257 * time stamping in the queue
3259 * When doing time stamping, keep the connection to the socket
3260 * a while longer: it is still needed by skb_hwtstamp_tx(),
3261 * called either in igb_tx_hwtstamp() or by our caller when
3262 * doing software time stamping.
3265 if (unlikely(shtx
->hardware
)) {
3266 shtx
->in_progress
= 1;
3267 tx_flags
|= IGB_TX_FLAGS_TSTAMP
;
3270 if (adapter
->vlgrp
&& vlan_tx_tag_present(skb
)) {
3271 tx_flags
|= IGB_TX_FLAGS_VLAN
;
3272 tx_flags
|= (vlan_tx_tag_get(skb
) << IGB_TX_FLAGS_VLAN_SHIFT
);
3275 if (skb
->protocol
== htons(ETH_P_IP
))
3276 tx_flags
|= IGB_TX_FLAGS_IPV4
;
3278 first
= tx_ring
->next_to_use
;
3279 tso
= skb_is_gso(skb
) ? igb_tso_adv(adapter
, tx_ring
, skb
, tx_flags
,
3283 dev_kfree_skb_any(skb
);
3284 return NETDEV_TX_OK
;
3288 tx_flags
|= IGB_TX_FLAGS_TSO
;
3289 else if (igb_tx_csum_adv(adapter
, tx_ring
, skb
, tx_flags
) &&
3290 (skb
->ip_summed
== CHECKSUM_PARTIAL
))
3291 tx_flags
|= IGB_TX_FLAGS_CSUM
;
3294 * count reflects descriptors mapped, if 0 then mapping error
3295 * has occured and we need to rewind the descriptor queue
3297 count
= igb_tx_map_adv(adapter
, tx_ring
, skb
, first
);
3300 igb_tx_queue_adv(adapter
, tx_ring
, tx_flags
, count
,
3302 netdev
->trans_start
= jiffies
;
3303 /* Make sure there is space in the ring for the next send. */
3304 igb_maybe_stop_tx(netdev
, tx_ring
, MAX_SKB_FRAGS
+ 4);
3306 dev_kfree_skb_any(skb
);
3307 tx_ring
->buffer_info
[first
].time_stamp
= 0;
3308 tx_ring
->next_to_use
= first
;
3311 return NETDEV_TX_OK
;
3314 static int igb_xmit_frame_adv(struct sk_buff
*skb
, struct net_device
*netdev
)
3316 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3317 struct igb_ring
*tx_ring
;
3320 r_idx
= skb
->queue_mapping
& (IGB_ABS_MAX_TX_QUEUES
- 1);
3321 tx_ring
= adapter
->multi_tx_table
[r_idx
];
3323 /* This goes back to the question of how to logically map a tx queue
3324 * to a flow. Right now, performance is impacted slightly negatively
3325 * if using multiple tx queues. If the stack breaks away from a
3326 * single qdisc implementation, we can look at this again. */
3327 return (igb_xmit_frame_ring_adv(skb
, netdev
, tx_ring
));
3331 * igb_tx_timeout - Respond to a Tx Hang
3332 * @netdev: network interface device structure
3334 static void igb_tx_timeout(struct net_device
*netdev
)
3336 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3337 struct e1000_hw
*hw
= &adapter
->hw
;
3339 /* Do the reset outside of interrupt context */
3340 adapter
->tx_timeout_count
++;
3341 schedule_work(&adapter
->reset_task
);
3343 (adapter
->eims_enable_mask
& ~adapter
->eims_other
));
3346 static void igb_reset_task(struct work_struct
*work
)
3348 struct igb_adapter
*adapter
;
3349 adapter
= container_of(work
, struct igb_adapter
, reset_task
);
3351 igb_reinit_locked(adapter
);
3355 * igb_get_stats - Get System Network Statistics
3356 * @netdev: network interface device structure
3358 * Returns the address of the device statistics structure.
3359 * The statistics are actually updated from the timer callback.
3361 static struct net_device_stats
*igb_get_stats(struct net_device
*netdev
)
3363 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3365 /* only return the current stats */
3366 return &adapter
->net_stats
;
3370 * igb_change_mtu - Change the Maximum Transfer Unit
3371 * @netdev: network interface device structure
3372 * @new_mtu: new value for maximum frame size
3374 * Returns 0 on success, negative on failure
3376 static int igb_change_mtu(struct net_device
*netdev
, int new_mtu
)
3378 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3379 int max_frame
= new_mtu
+ ETH_HLEN
+ ETH_FCS_LEN
;
3381 if ((max_frame
< ETH_ZLEN
+ ETH_FCS_LEN
) ||
3382 (max_frame
> MAX_JUMBO_FRAME_SIZE
)) {
3383 dev_err(&adapter
->pdev
->dev
, "Invalid MTU setting\n");
3387 if (max_frame
> MAX_STD_JUMBO_FRAME_SIZE
) {
3388 dev_err(&adapter
->pdev
->dev
, "MTU > 9216 not supported.\n");
3392 while (test_and_set_bit(__IGB_RESETTING
, &adapter
->state
))
3395 /* igb_down has a dependency on max_frame_size */
3396 adapter
->max_frame_size
= max_frame
;
3397 if (netif_running(netdev
))
3400 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3401 * means we reserve 2 more, this pushes us to allocate from the next
3403 * i.e. RXBUFFER_2048 --> size-4096 slab
3406 if (max_frame
<= IGB_RXBUFFER_256
)
3407 adapter
->rx_buffer_len
= IGB_RXBUFFER_256
;
3408 else if (max_frame
<= IGB_RXBUFFER_512
)
3409 adapter
->rx_buffer_len
= IGB_RXBUFFER_512
;
3410 else if (max_frame
<= IGB_RXBUFFER_1024
)
3411 adapter
->rx_buffer_len
= IGB_RXBUFFER_1024
;
3412 else if (max_frame
<= IGB_RXBUFFER_2048
)
3413 adapter
->rx_buffer_len
= IGB_RXBUFFER_2048
;
3415 #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
3416 adapter
->rx_buffer_len
= IGB_RXBUFFER_16384
;
3418 adapter
->rx_buffer_len
= PAGE_SIZE
/ 2;
3421 /* if sr-iov is enabled we need to force buffer size to 1K or larger */
3422 if (adapter
->vfs_allocated_count
&&
3423 (adapter
->rx_buffer_len
< IGB_RXBUFFER_1024
))
3424 adapter
->rx_buffer_len
= IGB_RXBUFFER_1024
;
3426 /* adjust allocation if LPE protects us, and we aren't using SBP */
3427 if ((max_frame
== ETH_FRAME_LEN
+ ETH_FCS_LEN
) ||
3428 (max_frame
== MAXIMUM_ETHERNET_VLAN_SIZE
))
3429 adapter
->rx_buffer_len
= MAXIMUM_ETHERNET_VLAN_SIZE
;
3431 dev_info(&adapter
->pdev
->dev
, "changing MTU from %d to %d\n",
3432 netdev
->mtu
, new_mtu
);
3433 netdev
->mtu
= new_mtu
;
3435 if (netif_running(netdev
))
3440 clear_bit(__IGB_RESETTING
, &adapter
->state
);
3446 * igb_update_stats - Update the board statistics counters
3447 * @adapter: board private structure
3450 void igb_update_stats(struct igb_adapter
*adapter
)
3452 struct e1000_hw
*hw
= &adapter
->hw
;
3453 struct pci_dev
*pdev
= adapter
->pdev
;
3456 #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3459 * Prevent stats update while adapter is being reset, or if the pci
3460 * connection is down.
3462 if (adapter
->link_speed
== 0)
3464 if (pci_channel_offline(pdev
))
3467 adapter
->stats
.crcerrs
+= rd32(E1000_CRCERRS
);
3468 adapter
->stats
.gprc
+= rd32(E1000_GPRC
);
3469 adapter
->stats
.gorc
+= rd32(E1000_GORCL
);
3470 rd32(E1000_GORCH
); /* clear GORCL */
3471 adapter
->stats
.bprc
+= rd32(E1000_BPRC
);
3472 adapter
->stats
.mprc
+= rd32(E1000_MPRC
);
3473 adapter
->stats
.roc
+= rd32(E1000_ROC
);
3475 adapter
->stats
.prc64
+= rd32(E1000_PRC64
);
3476 adapter
->stats
.prc127
+= rd32(E1000_PRC127
);
3477 adapter
->stats
.prc255
+= rd32(E1000_PRC255
);
3478 adapter
->stats
.prc511
+= rd32(E1000_PRC511
);
3479 adapter
->stats
.prc1023
+= rd32(E1000_PRC1023
);
3480 adapter
->stats
.prc1522
+= rd32(E1000_PRC1522
);
3481 adapter
->stats
.symerrs
+= rd32(E1000_SYMERRS
);
3482 adapter
->stats
.sec
+= rd32(E1000_SEC
);
3484 adapter
->stats
.mpc
+= rd32(E1000_MPC
);
3485 adapter
->stats
.scc
+= rd32(E1000_SCC
);
3486 adapter
->stats
.ecol
+= rd32(E1000_ECOL
);
3487 adapter
->stats
.mcc
+= rd32(E1000_MCC
);
3488 adapter
->stats
.latecol
+= rd32(E1000_LATECOL
);
3489 adapter
->stats
.dc
+= rd32(E1000_DC
);
3490 adapter
->stats
.rlec
+= rd32(E1000_RLEC
);
3491 adapter
->stats
.xonrxc
+= rd32(E1000_XONRXC
);
3492 adapter
->stats
.xontxc
+= rd32(E1000_XONTXC
);
3493 adapter
->stats
.xoffrxc
+= rd32(E1000_XOFFRXC
);
3494 adapter
->stats
.xofftxc
+= rd32(E1000_XOFFTXC
);
3495 adapter
->stats
.fcruc
+= rd32(E1000_FCRUC
);
3496 adapter
->stats
.gptc
+= rd32(E1000_GPTC
);
3497 adapter
->stats
.gotc
+= rd32(E1000_GOTCL
);
3498 rd32(E1000_GOTCH
); /* clear GOTCL */
3499 adapter
->stats
.rnbc
+= rd32(E1000_RNBC
);
3500 adapter
->stats
.ruc
+= rd32(E1000_RUC
);
3501 adapter
->stats
.rfc
+= rd32(E1000_RFC
);
3502 adapter
->stats
.rjc
+= rd32(E1000_RJC
);
3503 adapter
->stats
.tor
+= rd32(E1000_TORH
);
3504 adapter
->stats
.tot
+= rd32(E1000_TOTH
);
3505 adapter
->stats
.tpr
+= rd32(E1000_TPR
);
3507 adapter
->stats
.ptc64
+= rd32(E1000_PTC64
);
3508 adapter
->stats
.ptc127
+= rd32(E1000_PTC127
);
3509 adapter
->stats
.ptc255
+= rd32(E1000_PTC255
);
3510 adapter
->stats
.ptc511
+= rd32(E1000_PTC511
);
3511 adapter
->stats
.ptc1023
+= rd32(E1000_PTC1023
);
3512 adapter
->stats
.ptc1522
+= rd32(E1000_PTC1522
);
3514 adapter
->stats
.mptc
+= rd32(E1000_MPTC
);
3515 adapter
->stats
.bptc
+= rd32(E1000_BPTC
);
3517 /* used for adaptive IFS */
3519 hw
->mac
.tx_packet_delta
= rd32(E1000_TPT
);
3520 adapter
->stats
.tpt
+= hw
->mac
.tx_packet_delta
;
3521 hw
->mac
.collision_delta
= rd32(E1000_COLC
);
3522 adapter
->stats
.colc
+= hw
->mac
.collision_delta
;
3524 adapter
->stats
.algnerrc
+= rd32(E1000_ALGNERRC
);
3525 adapter
->stats
.rxerrc
+= rd32(E1000_RXERRC
);
3526 adapter
->stats
.tncrs
+= rd32(E1000_TNCRS
);
3527 adapter
->stats
.tsctc
+= rd32(E1000_TSCTC
);
3528 adapter
->stats
.tsctfc
+= rd32(E1000_TSCTFC
);
3530 adapter
->stats
.iac
+= rd32(E1000_IAC
);
3531 adapter
->stats
.icrxoc
+= rd32(E1000_ICRXOC
);
3532 adapter
->stats
.icrxptc
+= rd32(E1000_ICRXPTC
);
3533 adapter
->stats
.icrxatc
+= rd32(E1000_ICRXATC
);
3534 adapter
->stats
.ictxptc
+= rd32(E1000_ICTXPTC
);
3535 adapter
->stats
.ictxatc
+= rd32(E1000_ICTXATC
);
3536 adapter
->stats
.ictxqec
+= rd32(E1000_ICTXQEC
);
3537 adapter
->stats
.ictxqmtc
+= rd32(E1000_ICTXQMTC
);
3538 adapter
->stats
.icrxdmtc
+= rd32(E1000_ICRXDMTC
);
3540 /* Fill out the OS statistics structure */
3541 adapter
->net_stats
.multicast
= adapter
->stats
.mprc
;
3542 adapter
->net_stats
.collisions
= adapter
->stats
.colc
;
3546 /* RLEC on some newer hardware can be incorrect so build
3547 * our own version based on RUC and ROC */
3548 adapter
->net_stats
.rx_errors
= adapter
->stats
.rxerrc
+
3549 adapter
->stats
.crcerrs
+ adapter
->stats
.algnerrc
+
3550 adapter
->stats
.ruc
+ adapter
->stats
.roc
+
3551 adapter
->stats
.cexterr
;
3552 adapter
->net_stats
.rx_length_errors
= adapter
->stats
.ruc
+
3554 adapter
->net_stats
.rx_crc_errors
= adapter
->stats
.crcerrs
;
3555 adapter
->net_stats
.rx_frame_errors
= adapter
->stats
.algnerrc
;
3556 adapter
->net_stats
.rx_missed_errors
= adapter
->stats
.mpc
;
3559 adapter
->net_stats
.tx_errors
= adapter
->stats
.ecol
+
3560 adapter
->stats
.latecol
;
3561 adapter
->net_stats
.tx_aborted_errors
= adapter
->stats
.ecol
;
3562 adapter
->net_stats
.tx_window_errors
= adapter
->stats
.latecol
;
3563 adapter
->net_stats
.tx_carrier_errors
= adapter
->stats
.tncrs
;
3565 /* Tx Dropped needs to be maintained elsewhere */
3568 if (hw
->phy
.media_type
== e1000_media_type_copper
) {
3569 if ((adapter
->link_speed
== SPEED_1000
) &&
3570 (!igb_read_phy_reg(hw
, PHY_1000T_STATUS
, &phy_tmp
))) {
3571 phy_tmp
&= PHY_IDLE_ERROR_COUNT_MASK
;
3572 adapter
->phy_stats
.idle_errors
+= phy_tmp
;
3576 /* Management Stats */
3577 adapter
->stats
.mgptc
+= rd32(E1000_MGTPTC
);
3578 adapter
->stats
.mgprc
+= rd32(E1000_MGTPRC
);
3579 adapter
->stats
.mgpdc
+= rd32(E1000_MGTPDC
);
3582 static irqreturn_t
igb_msix_other(int irq
, void *data
)
3584 struct net_device
*netdev
= data
;
3585 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3586 struct e1000_hw
*hw
= &adapter
->hw
;
3587 u32 icr
= rd32(E1000_ICR
);
3589 /* reading ICR causes bit 31 of EICR to be cleared */
3591 if(icr
& E1000_ICR_DOUTSYNC
) {
3592 /* HW is reporting DMA is out of sync */
3593 adapter
->stats
.doosync
++;
3596 /* Check for a mailbox event */
3597 if (icr
& E1000_ICR_VMMB
)
3598 igb_msg_task(adapter
);
3600 if (icr
& E1000_ICR_LSC
) {
3601 hw
->mac
.get_link_status
= 1;
3602 /* guard against interrupt when we're going down */
3603 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
3604 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
3607 wr32(E1000_IMS
, E1000_IMS_LSC
| E1000_IMS_DOUTSYNC
| E1000_IMS_VMMB
);
3608 wr32(E1000_EIMS
, adapter
->eims_other
);
3613 static irqreturn_t
igb_msix_tx(int irq
, void *data
)
3615 struct igb_ring
*tx_ring
= data
;
3616 struct igb_adapter
*adapter
= tx_ring
->adapter
;
3617 struct e1000_hw
*hw
= &adapter
->hw
;
3619 #ifdef CONFIG_IGB_DCA
3620 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
3621 igb_update_tx_dca(tx_ring
);
3624 tx_ring
->total_bytes
= 0;
3625 tx_ring
->total_packets
= 0;
3627 /* auto mask will automatically reenable the interrupt when we write
3629 if (!igb_clean_tx_irq(tx_ring
))
3630 /* Ring was not completely cleaned, so fire another interrupt */
3631 wr32(E1000_EICS
, tx_ring
->eims_value
);
3633 wr32(E1000_EIMS
, tx_ring
->eims_value
);
3638 static void igb_write_itr(struct igb_ring
*ring
)
3640 struct e1000_hw
*hw
= &ring
->adapter
->hw
;
3641 if ((ring
->adapter
->itr_setting
& 3) && ring
->set_itr
) {
3642 switch (hw
->mac
.type
) {
3644 wr32(ring
->itr_register
, ring
->itr_val
|
3648 wr32(ring
->itr_register
, ring
->itr_val
|
3649 (ring
->itr_val
<< 16));
3656 static irqreturn_t
igb_msix_rx(int irq
, void *data
)
3658 struct igb_ring
*rx_ring
= data
;
3660 /* Write the ITR value calculated at the end of the
3661 * previous interrupt.
3664 igb_write_itr(rx_ring
);
3666 if (napi_schedule_prep(&rx_ring
->napi
))
3667 __napi_schedule(&rx_ring
->napi
);
3669 #ifdef CONFIG_IGB_DCA
3670 if (rx_ring
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
3671 igb_update_rx_dca(rx_ring
);
3676 #ifdef CONFIG_IGB_DCA
3677 static void igb_update_rx_dca(struct igb_ring
*rx_ring
)
3680 struct igb_adapter
*adapter
= rx_ring
->adapter
;
3681 struct e1000_hw
*hw
= &adapter
->hw
;
3682 int cpu
= get_cpu();
3683 int q
= rx_ring
->reg_idx
;
3685 if (rx_ring
->cpu
!= cpu
) {
3686 dca_rxctrl
= rd32(E1000_DCA_RXCTRL(q
));
3687 if (hw
->mac
.type
== e1000_82576
) {
3688 dca_rxctrl
&= ~E1000_DCA_RXCTRL_CPUID_MASK_82576
;
3689 dca_rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
3690 E1000_DCA_RXCTRL_CPUID_SHIFT
;
3692 dca_rxctrl
&= ~E1000_DCA_RXCTRL_CPUID_MASK
;
3693 dca_rxctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
3695 dca_rxctrl
|= E1000_DCA_RXCTRL_DESC_DCA_EN
;
3696 dca_rxctrl
|= E1000_DCA_RXCTRL_HEAD_DCA_EN
;
3697 dca_rxctrl
|= E1000_DCA_RXCTRL_DATA_DCA_EN
;
3698 wr32(E1000_DCA_RXCTRL(q
), dca_rxctrl
);
3704 static void igb_update_tx_dca(struct igb_ring
*tx_ring
)
3707 struct igb_adapter
*adapter
= tx_ring
->adapter
;
3708 struct e1000_hw
*hw
= &adapter
->hw
;
3709 int cpu
= get_cpu();
3710 int q
= tx_ring
->reg_idx
;
3712 if (tx_ring
->cpu
!= cpu
) {
3713 dca_txctrl
= rd32(E1000_DCA_TXCTRL(q
));
3714 if (hw
->mac
.type
== e1000_82576
) {
3715 dca_txctrl
&= ~E1000_DCA_TXCTRL_CPUID_MASK_82576
;
3716 dca_txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
) <<
3717 E1000_DCA_TXCTRL_CPUID_SHIFT
;
3719 dca_txctrl
&= ~E1000_DCA_TXCTRL_CPUID_MASK
;
3720 dca_txctrl
|= dca3_get_tag(&adapter
->pdev
->dev
, cpu
);
3722 dca_txctrl
|= E1000_DCA_TXCTRL_DESC_DCA_EN
;
3723 wr32(E1000_DCA_TXCTRL(q
), dca_txctrl
);
3729 static void igb_setup_dca(struct igb_adapter
*adapter
)
3733 if (!(adapter
->flags
& IGB_FLAG_DCA_ENABLED
))
3736 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
3737 adapter
->tx_ring
[i
].cpu
= -1;
3738 igb_update_tx_dca(&adapter
->tx_ring
[i
]);
3740 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
3741 adapter
->rx_ring
[i
].cpu
= -1;
3742 igb_update_rx_dca(&adapter
->rx_ring
[i
]);
3746 static int __igb_notify_dca(struct device
*dev
, void *data
)
3748 struct net_device
*netdev
= dev_get_drvdata(dev
);
3749 struct igb_adapter
*adapter
= netdev_priv(netdev
);
3750 struct e1000_hw
*hw
= &adapter
->hw
;
3751 unsigned long event
= *(unsigned long *)data
;
3754 case DCA_PROVIDER_ADD
:
3755 /* if already enabled, don't do it again */
3756 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
3758 /* Always use CB2 mode, difference is masked
3759 * in the CB driver. */
3760 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_CB2
);
3761 if (dca_add_requester(dev
) == 0) {
3762 adapter
->flags
|= IGB_FLAG_DCA_ENABLED
;
3763 dev_info(&adapter
->pdev
->dev
, "DCA enabled\n");
3764 igb_setup_dca(adapter
);
3767 /* Fall Through since DCA is disabled. */
3768 case DCA_PROVIDER_REMOVE
:
3769 if (adapter
->flags
& IGB_FLAG_DCA_ENABLED
) {
3770 /* without this a class_device is left
3771 * hanging around in the sysfs model */
3772 dca_remove_requester(dev
);
3773 dev_info(&adapter
->pdev
->dev
, "DCA disabled\n");
3774 adapter
->flags
&= ~IGB_FLAG_DCA_ENABLED
;
3775 wr32(E1000_DCA_CTRL
, E1000_DCA_CTRL_DCA_MODE_DISABLE
);
3783 static int igb_notify_dca(struct notifier_block
*nb
, unsigned long event
,
3788 ret_val
= driver_for_each_device(&igb_driver
.driver
, NULL
, &event
,
3791 return ret_val
? NOTIFY_BAD
: NOTIFY_DONE
;
3793 #endif /* CONFIG_IGB_DCA */
3795 static void igb_ping_all_vfs(struct igb_adapter
*adapter
)
3797 struct e1000_hw
*hw
= &adapter
->hw
;
3801 for (i
= 0 ; i
< adapter
->vfs_allocated_count
; i
++) {
3802 ping
= E1000_PF_CONTROL_MSG
;
3803 if (adapter
->vf_data
[i
].clear_to_send
)
3804 ping
|= E1000_VT_MSGTYPE_CTS
;
3805 igb_write_mbx(hw
, &ping
, 1, i
);
3809 static int igb_set_vf_multicasts(struct igb_adapter
*adapter
,
3810 u32
*msgbuf
, u32 vf
)
3812 int n
= (msgbuf
[0] & E1000_VT_MSGINFO_MASK
) >> E1000_VT_MSGINFO_SHIFT
;
3813 u16
*hash_list
= (u16
*)&msgbuf
[1];
3814 struct vf_data_storage
*vf_data
= &adapter
->vf_data
[vf
];
3817 /* only up to 30 hash values supported */
3821 /* salt away the number of multi cast addresses assigned
3822 * to this VF for later use to restore when the PF multi cast
3825 vf_data
->num_vf_mc_hashes
= n
;
3827 /* VFs are limited to using the MTA hash table for their multicast
3829 for (i
= 0; i
< n
; i
++)
3830 vf_data
->vf_mc_hashes
[i
] = hash_list
[i
];;
3832 /* Flush and reset the mta with the new values */
3833 igb_set_multi(adapter
->netdev
);
3838 static void igb_restore_vf_multicasts(struct igb_adapter
*adapter
)
3840 struct e1000_hw
*hw
= &adapter
->hw
;
3841 struct vf_data_storage
*vf_data
;
3844 for (i
= 0; i
< adapter
->vfs_allocated_count
; i
++) {
3845 vf_data
= &adapter
->vf_data
[i
];
3846 for (j
= 0; j
< vf_data
->num_vf_mc_hashes
; j
++)
3847 igb_mta_set(hw
, vf_data
->vf_mc_hashes
[j
]);
3851 static void igb_clear_vf_vfta(struct igb_adapter
*adapter
, u32 vf
)
3853 struct e1000_hw
*hw
= &adapter
->hw
;
3854 u32 pool_mask
, reg
, vid
;
3857 pool_mask
= 1 << (E1000_VLVF_POOLSEL_SHIFT
+ vf
);
3859 /* Find the vlan filter for this id */
3860 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
3861 reg
= rd32(E1000_VLVF(i
));
3863 /* remove the vf from the pool */
3866 /* if pool is empty then remove entry from vfta */
3867 if (!(reg
& E1000_VLVF_POOLSEL_MASK
) &&
3868 (reg
& E1000_VLVF_VLANID_ENABLE
)) {
3870 vid
= reg
& E1000_VLVF_VLANID_MASK
;
3871 igb_vfta_set(hw
, vid
, false);
3874 wr32(E1000_VLVF(i
), reg
);
3878 static s32
igb_vlvf_set(struct igb_adapter
*adapter
, u32 vid
, bool add
, u32 vf
)
3880 struct e1000_hw
*hw
= &adapter
->hw
;
3883 /* It is an error to call this function when VFs are not enabled */
3884 if (!adapter
->vfs_allocated_count
)
3887 /* Find the vlan filter for this id */
3888 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
3889 reg
= rd32(E1000_VLVF(i
));
3890 if ((reg
& E1000_VLVF_VLANID_ENABLE
) &&
3891 vid
== (reg
& E1000_VLVF_VLANID_MASK
))
3896 if (i
== E1000_VLVF_ARRAY_SIZE
) {
3897 /* Did not find a matching VLAN ID entry that was
3898 * enabled. Search for a free filter entry, i.e.
3899 * one without the enable bit set
3901 for (i
= 0; i
< E1000_VLVF_ARRAY_SIZE
; i
++) {
3902 reg
= rd32(E1000_VLVF(i
));
3903 if (!(reg
& E1000_VLVF_VLANID_ENABLE
))
3907 if (i
< E1000_VLVF_ARRAY_SIZE
) {
3908 /* Found an enabled/available entry */
3909 reg
|= 1 << (E1000_VLVF_POOLSEL_SHIFT
+ vf
);
3911 /* if !enabled we need to set this up in vfta */
3912 if (!(reg
& E1000_VLVF_VLANID_ENABLE
)) {
3913 /* add VID to filter table, if bit already set
3914 * PF must have added it outside of table */
3915 if (igb_vfta_set(hw
, vid
, true))
3916 reg
|= 1 << (E1000_VLVF_POOLSEL_SHIFT
+
3917 adapter
->vfs_allocated_count
);
3918 reg
|= E1000_VLVF_VLANID_ENABLE
;
3920 reg
&= ~E1000_VLVF_VLANID_MASK
;
3923 wr32(E1000_VLVF(i
), reg
);
3927 if (i
< E1000_VLVF_ARRAY_SIZE
) {
3928 /* remove vf from the pool */
3929 reg
&= ~(1 << (E1000_VLVF_POOLSEL_SHIFT
+ vf
));
3930 /* if pool is empty then remove entry from vfta */
3931 if (!(reg
& E1000_VLVF_POOLSEL_MASK
)) {
3933 igb_vfta_set(hw
, vid
, false);
3935 wr32(E1000_VLVF(i
), reg
);
3942 static int igb_set_vf_vlan(struct igb_adapter
*adapter
, u32
*msgbuf
, u32 vf
)
3944 int add
= (msgbuf
[0] & E1000_VT_MSGINFO_MASK
) >> E1000_VT_MSGINFO_SHIFT
;
3945 int vid
= (msgbuf
[1] & E1000_VLVF_VLANID_MASK
);
3947 return igb_vlvf_set(adapter
, vid
, add
, vf
);
3950 static inline void igb_vf_reset_event(struct igb_adapter
*adapter
, u32 vf
)
3952 struct e1000_hw
*hw
= &adapter
->hw
;
3954 /* disable mailbox functionality for vf */
3955 adapter
->vf_data
[vf
].clear_to_send
= false;
3957 /* reset offloads to defaults */
3958 igb_set_vmolr(hw
, vf
);
3960 /* reset vlans for device */
3961 igb_clear_vf_vfta(adapter
, vf
);
3963 /* reset multicast table array for vf */
3964 adapter
->vf_data
[vf
].num_vf_mc_hashes
= 0;
3966 /* Flush and reset the mta with the new values */
3967 igb_set_multi(adapter
->netdev
);
3970 static inline void igb_vf_reset_msg(struct igb_adapter
*adapter
, u32 vf
)
3972 struct e1000_hw
*hw
= &adapter
->hw
;
3973 unsigned char *vf_mac
= adapter
->vf_data
[vf
].vf_mac_addresses
;
3975 u8
*addr
= (u8
*)(&msgbuf
[1]);
3977 /* process all the same items cleared in a function level reset */
3978 igb_vf_reset_event(adapter
, vf
);
3980 /* set vf mac address */
3981 igb_rar_set(hw
, vf_mac
, vf
+ 1);
3982 igb_set_rah_pool(hw
, vf
, vf
+ 1);
3984 /* enable transmit and receive for vf */
3985 reg
= rd32(E1000_VFTE
);
3986 wr32(E1000_VFTE
, reg
| (1 << vf
));
3987 reg
= rd32(E1000_VFRE
);
3988 wr32(E1000_VFRE
, reg
| (1 << vf
));
3990 /* enable mailbox functionality for vf */
3991 adapter
->vf_data
[vf
].clear_to_send
= true;
3993 /* reply to reset with ack and vf mac address */
3994 msgbuf
[0] = E1000_VF_RESET
| E1000_VT_MSGTYPE_ACK
;
3995 memcpy(addr
, vf_mac
, 6);
3996 igb_write_mbx(hw
, msgbuf
, 3, vf
);
3999 static int igb_set_vf_mac_addr(struct igb_adapter
*adapter
, u32
*msg
, int vf
)
4001 unsigned char *addr
= (char *)&msg
[1];
4004 if (is_valid_ether_addr(addr
))
4005 err
= igb_set_vf_mac(adapter
, vf
, addr
);
4011 static void igb_rcv_ack_from_vf(struct igb_adapter
*adapter
, u32 vf
)
4013 struct e1000_hw
*hw
= &adapter
->hw
;
4014 u32 msg
= E1000_VT_MSGTYPE_NACK
;
4016 /* if device isn't clear to send it shouldn't be reading either */
4017 if (!adapter
->vf_data
[vf
].clear_to_send
)
4018 igb_write_mbx(hw
, &msg
, 1, vf
);
4022 static void igb_msg_task(struct igb_adapter
*adapter
)
4024 struct e1000_hw
*hw
= &adapter
->hw
;
4027 for (vf
= 0; vf
< adapter
->vfs_allocated_count
; vf
++) {
4028 /* process any reset requests */
4029 if (!igb_check_for_rst(hw
, vf
)) {
4030 adapter
->vf_data
[vf
].clear_to_send
= false;
4031 igb_vf_reset_event(adapter
, vf
);
4034 /* process any messages pending */
4035 if (!igb_check_for_msg(hw
, vf
))
4036 igb_rcv_msg_from_vf(adapter
, vf
);
4038 /* process any acks */
4039 if (!igb_check_for_ack(hw
, vf
))
4040 igb_rcv_ack_from_vf(adapter
, vf
);
4045 static int igb_rcv_msg_from_vf(struct igb_adapter
*adapter
, u32 vf
)
4047 u32 mbx_size
= E1000_VFMAILBOX_SIZE
;
4048 u32 msgbuf
[mbx_size
];
4049 struct e1000_hw
*hw
= &adapter
->hw
;
4052 retval
= igb_read_mbx(hw
, msgbuf
, mbx_size
, vf
);
4055 dev_err(&adapter
->pdev
->dev
,
4056 "Error receiving message from VF\n");
4058 /* this is a message we already processed, do nothing */
4059 if (msgbuf
[0] & (E1000_VT_MSGTYPE_ACK
| E1000_VT_MSGTYPE_NACK
))
4063 * until the vf completes a reset it should not be
4064 * allowed to start any configuration.
4067 if (msgbuf
[0] == E1000_VF_RESET
) {
4068 igb_vf_reset_msg(adapter
, vf
);
4073 if (!adapter
->vf_data
[vf
].clear_to_send
) {
4074 msgbuf
[0] |= E1000_VT_MSGTYPE_NACK
;
4075 igb_write_mbx(hw
, msgbuf
, 1, vf
);
4079 switch ((msgbuf
[0] & 0xFFFF)) {
4080 case E1000_VF_SET_MAC_ADDR
:
4081 retval
= igb_set_vf_mac_addr(adapter
, msgbuf
, vf
);
4083 case E1000_VF_SET_MULTICAST
:
4084 retval
= igb_set_vf_multicasts(adapter
, msgbuf
, vf
);
4086 case E1000_VF_SET_LPE
:
4087 retval
= igb_set_vf_rlpml(adapter
, msgbuf
[1], vf
);
4089 case E1000_VF_SET_VLAN
:
4090 retval
= igb_set_vf_vlan(adapter
, msgbuf
, vf
);
4093 dev_err(&adapter
->pdev
->dev
, "Unhandled Msg %08x\n", msgbuf
[0]);
4098 /* notify the VF of the results of what it sent us */
4100 msgbuf
[0] |= E1000_VT_MSGTYPE_NACK
;
4102 msgbuf
[0] |= E1000_VT_MSGTYPE_ACK
;
4104 msgbuf
[0] |= E1000_VT_MSGTYPE_CTS
;
4106 igb_write_mbx(hw
, msgbuf
, 1, vf
);
4112 * igb_intr_msi - Interrupt Handler
4113 * @irq: interrupt number
4114 * @data: pointer to a network interface device structure
4116 static irqreturn_t
igb_intr_msi(int irq
, void *data
)
4118 struct net_device
*netdev
= data
;
4119 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4120 struct e1000_hw
*hw
= &adapter
->hw
;
4121 /* read ICR disables interrupts using IAM */
4122 u32 icr
= rd32(E1000_ICR
);
4124 igb_write_itr(adapter
->rx_ring
);
4126 if(icr
& E1000_ICR_DOUTSYNC
) {
4127 /* HW is reporting DMA is out of sync */
4128 adapter
->stats
.doosync
++;
4131 if (icr
& (E1000_ICR_RXSEQ
| E1000_ICR_LSC
)) {
4132 hw
->mac
.get_link_status
= 1;
4133 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
4134 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
4137 napi_schedule(&adapter
->rx_ring
[0].napi
);
4143 * igb_intr - Legacy Interrupt Handler
4144 * @irq: interrupt number
4145 * @data: pointer to a network interface device structure
4147 static irqreturn_t
igb_intr(int irq
, void *data
)
4149 struct net_device
*netdev
= data
;
4150 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4151 struct e1000_hw
*hw
= &adapter
->hw
;
4152 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
4153 * need for the IMC write */
4154 u32 icr
= rd32(E1000_ICR
);
4156 return IRQ_NONE
; /* Not our interrupt */
4158 igb_write_itr(adapter
->rx_ring
);
4160 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
4161 * not set, then the adapter didn't send an interrupt */
4162 if (!(icr
& E1000_ICR_INT_ASSERTED
))
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 /* guard against interrupt when we're going down */
4173 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
4174 mod_timer(&adapter
->watchdog_timer
, jiffies
+ 1);
4177 napi_schedule(&adapter
->rx_ring
[0].napi
);
4182 static inline void igb_rx_irq_enable(struct igb_ring
*rx_ring
)
4184 struct igb_adapter
*adapter
= rx_ring
->adapter
;
4185 struct e1000_hw
*hw
= &adapter
->hw
;
4187 if (adapter
->itr_setting
& 3) {
4188 if (adapter
->num_rx_queues
== 1)
4189 igb_set_itr(adapter
);
4191 igb_update_ring_itr(rx_ring
);
4194 if (!test_bit(__IGB_DOWN
, &adapter
->state
)) {
4195 if (adapter
->msix_entries
)
4196 wr32(E1000_EIMS
, rx_ring
->eims_value
);
4198 igb_irq_enable(adapter
);
4203 * igb_poll - NAPI Rx polling callback
4204 * @napi: napi polling structure
4205 * @budget: count of how many packets we should handle
4207 static int igb_poll(struct napi_struct
*napi
, int budget
)
4209 struct igb_ring
*rx_ring
= container_of(napi
, struct igb_ring
, napi
);
4212 #ifdef CONFIG_IGB_DCA
4213 if (rx_ring
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
4214 igb_update_rx_dca(rx_ring
);
4216 igb_clean_rx_irq_adv(rx_ring
, &work_done
, budget
);
4218 if (rx_ring
->buddy
) {
4219 #ifdef CONFIG_IGB_DCA
4220 if (rx_ring
->adapter
->flags
& IGB_FLAG_DCA_ENABLED
)
4221 igb_update_tx_dca(rx_ring
->buddy
);
4223 if (!igb_clean_tx_irq(rx_ring
->buddy
))
4227 /* If not enough Rx work done, exit the polling mode */
4228 if (work_done
< budget
) {
4229 napi_complete(napi
);
4230 igb_rx_irq_enable(rx_ring
);
4237 * igb_hwtstamp - utility function which checks for TX time stamp
4238 * @adapter: board private structure
4239 * @skb: packet that was just sent
4241 * If we were asked to do hardware stamping and such a time stamp is
4242 * available, then it must have been for this skb here because we only
4243 * allow only one such packet into the queue.
4245 static void igb_tx_hwtstamp(struct igb_adapter
*adapter
, struct sk_buff
*skb
)
4247 union skb_shared_tx
*shtx
= skb_tx(skb
);
4248 struct e1000_hw
*hw
= &adapter
->hw
;
4250 if (unlikely(shtx
->hardware
)) {
4251 u32 valid
= rd32(E1000_TSYNCTXCTL
) & E1000_TSYNCTXCTL_VALID
;
4253 u64 regval
= rd32(E1000_TXSTMPL
);
4255 struct skb_shared_hwtstamps shhwtstamps
;
4257 memset(&shhwtstamps
, 0, sizeof(shhwtstamps
));
4258 regval
|= (u64
)rd32(E1000_TXSTMPH
) << 32;
4259 ns
= timecounter_cyc2time(&adapter
->clock
,
4261 timecompare_update(&adapter
->compare
, ns
);
4262 shhwtstamps
.hwtstamp
= ns_to_ktime(ns
);
4263 shhwtstamps
.syststamp
=
4264 timecompare_transform(&adapter
->compare
, ns
);
4265 skb_tstamp_tx(skb
, &shhwtstamps
);
4271 * igb_clean_tx_irq - Reclaim resources after transmit completes
4272 * @adapter: board private structure
4273 * returns true if ring is completely cleaned
4275 static bool igb_clean_tx_irq(struct igb_ring
*tx_ring
)
4277 struct igb_adapter
*adapter
= tx_ring
->adapter
;
4278 struct net_device
*netdev
= adapter
->netdev
;
4279 struct e1000_hw
*hw
= &adapter
->hw
;
4280 struct igb_buffer
*buffer_info
;
4281 struct sk_buff
*skb
;
4282 union e1000_adv_tx_desc
*tx_desc
, *eop_desc
;
4283 unsigned int total_bytes
= 0, total_packets
= 0;
4284 unsigned int i
, eop
, count
= 0;
4285 bool cleaned
= false;
4287 i
= tx_ring
->next_to_clean
;
4288 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4289 eop_desc
= E1000_TX_DESC_ADV(*tx_ring
, eop
);
4291 while ((eop_desc
->wb
.status
& cpu_to_le32(E1000_TXD_STAT_DD
)) &&
4292 (count
< tx_ring
->count
)) {
4293 for (cleaned
= false; !cleaned
; count
++) {
4294 tx_desc
= E1000_TX_DESC_ADV(*tx_ring
, i
);
4295 buffer_info
= &tx_ring
->buffer_info
[i
];
4296 cleaned
= (i
== eop
);
4297 skb
= buffer_info
->skb
;
4300 unsigned int segs
, bytecount
;
4301 /* gso_segs is currently only valid for tcp */
4302 segs
= skb_shinfo(skb
)->gso_segs
?: 1;
4303 /* multiply data chunks by size of headers */
4304 bytecount
= ((segs
- 1) * skb_headlen(skb
)) +
4306 total_packets
+= segs
;
4307 total_bytes
+= bytecount
;
4309 igb_tx_hwtstamp(adapter
, skb
);
4312 igb_unmap_and_free_tx_resource(adapter
, buffer_info
);
4313 tx_desc
->wb
.status
= 0;
4316 if (i
== tx_ring
->count
)
4319 eop
= tx_ring
->buffer_info
[i
].next_to_watch
;
4320 eop_desc
= E1000_TX_DESC_ADV(*tx_ring
, eop
);
4323 tx_ring
->next_to_clean
= i
;
4325 if (unlikely(count
&&
4326 netif_carrier_ok(netdev
) &&
4327 igb_desc_unused(tx_ring
) >= IGB_TX_QUEUE_WAKE
)) {
4328 /* Make sure that anybody stopping the queue after this
4329 * sees the new next_to_clean.
4332 if (__netif_subqueue_stopped(netdev
, tx_ring
->queue_index
) &&
4333 !(test_bit(__IGB_DOWN
, &adapter
->state
))) {
4334 netif_wake_subqueue(netdev
, tx_ring
->queue_index
);
4335 ++adapter
->restart_queue
;
4339 if (tx_ring
->detect_tx_hung
) {
4340 /* Detect a transmit hang in hardware, this serializes the
4341 * check with the clearing of time_stamp and movement of i */
4342 tx_ring
->detect_tx_hung
= false;
4343 if (tx_ring
->buffer_info
[i
].time_stamp
&&
4344 time_after(jiffies
, tx_ring
->buffer_info
[i
].time_stamp
+
4345 (adapter
->tx_timeout_factor
* HZ
))
4346 && !(rd32(E1000_STATUS
) &
4347 E1000_STATUS_TXOFF
)) {
4349 /* detected Tx unit hang */
4350 dev_err(&adapter
->pdev
->dev
,
4351 "Detected Tx Unit Hang\n"
4355 " next_to_use <%x>\n"
4356 " next_to_clean <%x>\n"
4357 "buffer_info[next_to_clean]\n"
4358 " time_stamp <%lx>\n"
4359 " next_to_watch <%x>\n"
4361 " desc.status <%x>\n",
4362 tx_ring
->queue_index
,
4363 readl(adapter
->hw
.hw_addr
+ tx_ring
->head
),
4364 readl(adapter
->hw
.hw_addr
+ tx_ring
->tail
),
4365 tx_ring
->next_to_use
,
4366 tx_ring
->next_to_clean
,
4367 tx_ring
->buffer_info
[i
].time_stamp
,
4370 eop_desc
->wb
.status
);
4371 netif_stop_subqueue(netdev
, tx_ring
->queue_index
);
4374 tx_ring
->total_bytes
+= total_bytes
;
4375 tx_ring
->total_packets
+= total_packets
;
4376 tx_ring
->tx_stats
.bytes
+= total_bytes
;
4377 tx_ring
->tx_stats
.packets
+= total_packets
;
4378 adapter
->net_stats
.tx_bytes
+= total_bytes
;
4379 adapter
->net_stats
.tx_packets
+= total_packets
;
4380 return (count
< tx_ring
->count
);
4384 * igb_receive_skb - helper function to handle rx indications
4385 * @ring: pointer to receive ring receving this packet
4386 * @status: descriptor status field as written by hardware
4387 * @rx_desc: receive descriptor containing vlan and type information.
4388 * @skb: pointer to sk_buff to be indicated to stack
4390 static void igb_receive_skb(struct igb_ring
*ring
, u8 status
,
4391 union e1000_adv_rx_desc
* rx_desc
,
4392 struct sk_buff
*skb
)
4394 struct igb_adapter
* adapter
= ring
->adapter
;
4395 bool vlan_extracted
= (adapter
->vlgrp
&& (status
& E1000_RXD_STAT_VP
));
4397 skb_record_rx_queue(skb
, ring
->queue_index
);
4398 if (skb
->ip_summed
== CHECKSUM_UNNECESSARY
) {
4400 vlan_gro_receive(&ring
->napi
, adapter
->vlgrp
,
4401 le16_to_cpu(rx_desc
->wb
.upper
.vlan
),
4404 napi_gro_receive(&ring
->napi
, skb
);
4407 vlan_hwaccel_receive_skb(skb
, adapter
->vlgrp
,
4408 le16_to_cpu(rx_desc
->wb
.upper
.vlan
));
4410 netif_receive_skb(skb
);
4414 static inline void igb_rx_checksum_adv(struct igb_adapter
*adapter
,
4415 u32 status_err
, struct sk_buff
*skb
)
4417 skb
->ip_summed
= CHECKSUM_NONE
;
4419 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
4420 if ((status_err
& E1000_RXD_STAT_IXSM
) || !adapter
->rx_csum
)
4422 /* TCP/UDP checksum error bit is set */
4424 (E1000_RXDEXT_STATERR_TCPE
| E1000_RXDEXT_STATERR_IPE
)) {
4425 /* let the stack verify checksum errors */
4426 adapter
->hw_csum_err
++;
4429 /* It must be a TCP or UDP packet with a valid checksum */
4430 if (status_err
& (E1000_RXD_STAT_TCPCS
| E1000_RXD_STAT_UDPCS
))
4431 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
4433 adapter
->hw_csum_good
++;
4436 static bool igb_clean_rx_irq_adv(struct igb_ring
*rx_ring
,
4437 int *work_done
, int budget
)
4439 struct igb_adapter
*adapter
= rx_ring
->adapter
;
4440 struct net_device
*netdev
= adapter
->netdev
;
4441 struct e1000_hw
*hw
= &adapter
->hw
;
4442 struct pci_dev
*pdev
= adapter
->pdev
;
4443 union e1000_adv_rx_desc
*rx_desc
, *next_rxd
;
4444 struct igb_buffer
*buffer_info
, *next_buffer
;
4445 struct sk_buff
*skb
;
4446 bool cleaned
= false;
4447 int cleaned_count
= 0;
4448 unsigned int total_bytes
= 0, total_packets
= 0;
4450 u32 length
, hlen
, staterr
;
4452 i
= rx_ring
->next_to_clean
;
4453 buffer_info
= &rx_ring
->buffer_info
[i
];
4454 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
4455 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
4457 while (staterr
& E1000_RXD_STAT_DD
) {
4458 if (*work_done
>= budget
)
4462 skb
= buffer_info
->skb
;
4463 prefetch(skb
->data
- NET_IP_ALIGN
);
4464 buffer_info
->skb
= NULL
;
4467 if (i
== rx_ring
->count
)
4469 next_rxd
= E1000_RX_DESC_ADV(*rx_ring
, i
);
4471 next_buffer
= &rx_ring
->buffer_info
[i
];
4473 length
= le16_to_cpu(rx_desc
->wb
.upper
.length
);
4477 if (!adapter
->rx_ps_hdr_size
) {
4478 pci_unmap_single(pdev
, buffer_info
->dma
,
4479 adapter
->rx_buffer_len
+
4481 PCI_DMA_FROMDEVICE
);
4482 skb_put(skb
, length
);
4486 /* HW will not DMA in data larger than the given buffer, even
4487 * if it parses the (NFS, of course) header to be larger. In
4488 * that case, it fills the header buffer and spills the rest
4491 hlen
= (le16_to_cpu(rx_desc
->wb
.lower
.lo_dword
.hdr_info
) &
4492 E1000_RXDADV_HDRBUFLEN_MASK
) >> E1000_RXDADV_HDRBUFLEN_SHIFT
;
4493 if (hlen
> adapter
->rx_ps_hdr_size
)
4494 hlen
= adapter
->rx_ps_hdr_size
;
4496 if (!skb_shinfo(skb
)->nr_frags
) {
4497 pci_unmap_single(pdev
, buffer_info
->dma
,
4498 adapter
->rx_ps_hdr_size
+ NET_IP_ALIGN
,
4499 PCI_DMA_FROMDEVICE
);
4504 pci_unmap_page(pdev
, buffer_info
->page_dma
,
4505 PAGE_SIZE
/ 2, PCI_DMA_FROMDEVICE
);
4506 buffer_info
->page_dma
= 0;
4508 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
++,
4510 buffer_info
->page_offset
,
4513 if ((adapter
->rx_buffer_len
> (PAGE_SIZE
/ 2)) ||
4514 (page_count(buffer_info
->page
) != 1))
4515 buffer_info
->page
= NULL
;
4517 get_page(buffer_info
->page
);
4520 skb
->data_len
+= length
;
4522 skb
->truesize
+= length
;
4525 if (!(staterr
& E1000_RXD_STAT_EOP
)) {
4526 buffer_info
->skb
= next_buffer
->skb
;
4527 buffer_info
->dma
= next_buffer
->dma
;
4528 next_buffer
->skb
= skb
;
4529 next_buffer
->dma
= 0;
4534 * If this bit is set, then the RX registers contain
4535 * the time stamp. No other packet will be time
4536 * stamped until we read these registers, so read the
4537 * registers to make them available again. Because
4538 * only one packet can be time stamped at a time, we
4539 * know that the register values must belong to this
4540 * one here and therefore we don't need to compare
4541 * any of the additional attributes stored for it.
4543 * If nothing went wrong, then it should have a
4544 * skb_shared_tx that we can turn into a
4545 * skb_shared_hwtstamps.
4547 * TODO: can time stamping be triggered (thus locking
4548 * the registers) without the packet reaching this point
4549 * here? In that case RX time stamping would get stuck.
4551 * TODO: in "time stamp all packets" mode this bit is
4552 * not set. Need a global flag for this mode and then
4553 * always read the registers. Cannot be done without
4556 if (unlikely(staterr
& E1000_RXD_STAT_TS
)) {
4559 struct skb_shared_hwtstamps
*shhwtstamps
=
4562 WARN(!(rd32(E1000_TSYNCRXCTL
) & E1000_TSYNCRXCTL_VALID
),
4563 "igb: no RX time stamp available for time stamped packet");
4564 regval
= rd32(E1000_RXSTMPL
);
4565 regval
|= (u64
)rd32(E1000_RXSTMPH
) << 32;
4566 ns
= timecounter_cyc2time(&adapter
->clock
, regval
);
4567 timecompare_update(&adapter
->compare
, ns
);
4568 memset(shhwtstamps
, 0, sizeof(*shhwtstamps
));
4569 shhwtstamps
->hwtstamp
= ns_to_ktime(ns
);
4570 shhwtstamps
->syststamp
=
4571 timecompare_transform(&adapter
->compare
, ns
);
4574 if (staterr
& E1000_RXDEXT_ERR_FRAME_ERR_MASK
) {
4575 dev_kfree_skb_irq(skb
);
4579 total_bytes
+= skb
->len
;
4582 igb_rx_checksum_adv(adapter
, staterr
, skb
);
4584 skb
->protocol
= eth_type_trans(skb
, netdev
);
4586 igb_receive_skb(rx_ring
, staterr
, rx_desc
, skb
);
4589 rx_desc
->wb
.upper
.status_error
= 0;
4591 /* return some buffers to hardware, one at a time is too slow */
4592 if (cleaned_count
>= IGB_RX_BUFFER_WRITE
) {
4593 igb_alloc_rx_buffers_adv(rx_ring
, cleaned_count
);
4597 /* use prefetched values */
4599 buffer_info
= next_buffer
;
4600 staterr
= le32_to_cpu(rx_desc
->wb
.upper
.status_error
);
4603 rx_ring
->next_to_clean
= i
;
4604 cleaned_count
= igb_desc_unused(rx_ring
);
4607 igb_alloc_rx_buffers_adv(rx_ring
, cleaned_count
);
4609 rx_ring
->total_packets
+= total_packets
;
4610 rx_ring
->total_bytes
+= total_bytes
;
4611 rx_ring
->rx_stats
.packets
+= total_packets
;
4612 rx_ring
->rx_stats
.bytes
+= total_bytes
;
4613 adapter
->net_stats
.rx_bytes
+= total_bytes
;
4614 adapter
->net_stats
.rx_packets
+= total_packets
;
4619 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
4620 * @adapter: address of board private structure
4622 static void igb_alloc_rx_buffers_adv(struct igb_ring
*rx_ring
,
4625 struct igb_adapter
*adapter
= rx_ring
->adapter
;
4626 struct net_device
*netdev
= adapter
->netdev
;
4627 struct pci_dev
*pdev
= adapter
->pdev
;
4628 union e1000_adv_rx_desc
*rx_desc
;
4629 struct igb_buffer
*buffer_info
;
4630 struct sk_buff
*skb
;
4634 i
= rx_ring
->next_to_use
;
4635 buffer_info
= &rx_ring
->buffer_info
[i
];
4637 if (adapter
->rx_ps_hdr_size
)
4638 bufsz
= adapter
->rx_ps_hdr_size
;
4640 bufsz
= adapter
->rx_buffer_len
;
4641 bufsz
+= NET_IP_ALIGN
;
4643 while (cleaned_count
--) {
4644 rx_desc
= E1000_RX_DESC_ADV(*rx_ring
, i
);
4646 if (adapter
->rx_ps_hdr_size
&& !buffer_info
->page_dma
) {
4647 if (!buffer_info
->page
) {
4648 buffer_info
->page
= alloc_page(GFP_ATOMIC
);
4649 if (!buffer_info
->page
) {
4650 adapter
->alloc_rx_buff_failed
++;
4653 buffer_info
->page_offset
= 0;
4655 buffer_info
->page_offset
^= PAGE_SIZE
/ 2;
4657 buffer_info
->page_dma
=
4658 pci_map_page(pdev
, buffer_info
->page
,
4659 buffer_info
->page_offset
,
4661 PCI_DMA_FROMDEVICE
);
4664 if (!buffer_info
->skb
) {
4665 skb
= netdev_alloc_skb(netdev
, bufsz
);
4667 adapter
->alloc_rx_buff_failed
++;
4671 /* Make buffer alignment 2 beyond a 16 byte boundary
4672 * this will result in a 16 byte aligned IP header after
4673 * the 14 byte MAC header is removed
4675 skb_reserve(skb
, NET_IP_ALIGN
);
4677 buffer_info
->skb
= skb
;
4678 buffer_info
->dma
= pci_map_single(pdev
, skb
->data
,
4680 PCI_DMA_FROMDEVICE
);
4682 /* Refresh the desc even if buffer_addrs didn't change because
4683 * each write-back erases this info. */
4684 if (adapter
->rx_ps_hdr_size
) {
4685 rx_desc
->read
.pkt_addr
=
4686 cpu_to_le64(buffer_info
->page_dma
);
4687 rx_desc
->read
.hdr_addr
= cpu_to_le64(buffer_info
->dma
);
4689 rx_desc
->read
.pkt_addr
=
4690 cpu_to_le64(buffer_info
->dma
);
4691 rx_desc
->read
.hdr_addr
= 0;
4695 if (i
== rx_ring
->count
)
4697 buffer_info
= &rx_ring
->buffer_info
[i
];
4701 if (rx_ring
->next_to_use
!= i
) {
4702 rx_ring
->next_to_use
= i
;
4704 i
= (rx_ring
->count
- 1);
4708 /* Force memory writes to complete before letting h/w
4709 * know there are new descriptors to fetch. (Only
4710 * applicable for weak-ordered memory model archs,
4711 * such as IA-64). */
4713 writel(i
, adapter
->hw
.hw_addr
+ rx_ring
->tail
);
4723 static int igb_mii_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4725 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4726 struct mii_ioctl_data
*data
= if_mii(ifr
);
4728 if (adapter
->hw
.phy
.media_type
!= e1000_media_type_copper
)
4733 data
->phy_id
= adapter
->hw
.phy
.addr
;
4736 if (!capable(CAP_NET_ADMIN
))
4738 if (igb_read_phy_reg(&adapter
->hw
, data
->reg_num
& 0x1F,
4750 * igb_hwtstamp_ioctl - control hardware time stamping
4755 * Outgoing time stamping can be enabled and disabled. Play nice and
4756 * disable it when requested, although it shouldn't case any overhead
4757 * when no packet needs it. At most one packet in the queue may be
4758 * marked for time stamping, otherwise it would be impossible to tell
4759 * for sure to which packet the hardware time stamp belongs.
4761 * Incoming time stamping has to be configured via the hardware
4762 * filters. Not all combinations are supported, in particular event
4763 * type has to be specified. Matching the kind of event packet is
4764 * not supported, with the exception of "all V2 events regardless of
4768 static int igb_hwtstamp_ioctl(struct net_device
*netdev
,
4769 struct ifreq
*ifr
, int cmd
)
4771 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4772 struct e1000_hw
*hw
= &adapter
->hw
;
4773 struct hwtstamp_config config
;
4774 u32 tsync_tx_ctl_bit
= E1000_TSYNCTXCTL_ENABLED
;
4775 u32 tsync_rx_ctl_bit
= E1000_TSYNCRXCTL_ENABLED
;
4776 u32 tsync_rx_ctl_type
= 0;
4777 u32 tsync_rx_cfg
= 0;
4780 short port
= 319; /* PTP */
4783 if (copy_from_user(&config
, ifr
->ifr_data
, sizeof(config
)))
4786 /* reserved for future extensions */
4790 switch (config
.tx_type
) {
4791 case HWTSTAMP_TX_OFF
:
4792 tsync_tx_ctl_bit
= 0;
4794 case HWTSTAMP_TX_ON
:
4795 tsync_tx_ctl_bit
= E1000_TSYNCTXCTL_ENABLED
;
4801 switch (config
.rx_filter
) {
4802 case HWTSTAMP_FILTER_NONE
:
4803 tsync_rx_ctl_bit
= 0;
4805 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
4806 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
4807 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
4808 case HWTSTAMP_FILTER_ALL
:
4810 * register TSYNCRXCFG must be set, therefore it is not
4811 * possible to time stamp both Sync and Delay_Req messages
4812 * => fall back to time stamping all packets
4814 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_ALL
;
4815 config
.rx_filter
= HWTSTAMP_FILTER_ALL
;
4817 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
4818 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L4_V1
;
4819 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE
;
4822 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
4823 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L4_V1
;
4824 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE
;
4827 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
4828 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
4829 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L2_L4_V2
;
4830 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE
;
4833 config
.rx_filter
= HWTSTAMP_FILTER_SOME
;
4835 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
4836 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
4837 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_L2_L4_V2
;
4838 tsync_rx_cfg
= E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE
;
4841 config
.rx_filter
= HWTSTAMP_FILTER_SOME
;
4843 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
4844 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
4845 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
4846 tsync_rx_ctl_type
= E1000_TSYNCRXCTL_TYPE_EVENT_V2
;
4847 config
.rx_filter
= HWTSTAMP_FILTER_PTP_V2_EVENT
;
4854 /* enable/disable TX */
4855 regval
= rd32(E1000_TSYNCTXCTL
);
4856 regval
= (regval
& ~E1000_TSYNCTXCTL_ENABLED
) | tsync_tx_ctl_bit
;
4857 wr32(E1000_TSYNCTXCTL
, regval
);
4859 /* enable/disable RX, define which PTP packets are time stamped */
4860 regval
= rd32(E1000_TSYNCRXCTL
);
4861 regval
= (regval
& ~E1000_TSYNCRXCTL_ENABLED
) | tsync_rx_ctl_bit
;
4862 regval
= (regval
& ~0xE) | tsync_rx_ctl_type
;
4863 wr32(E1000_TSYNCRXCTL
, regval
);
4864 wr32(E1000_TSYNCRXCFG
, tsync_rx_cfg
);
4867 * Ethertype Filter Queue Filter[0][15:0] = 0x88F7
4868 * (Ethertype to filter on)
4869 * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter)
4870 * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping)
4872 wr32(E1000_ETQF0
, is_l2
? 0x440088f7 : 0);
4874 /* L4 Queue Filter[0]: only filter by source and destination port */
4875 wr32(E1000_SPQF0
, htons(port
));
4876 wr32(E1000_IMIREXT(0), is_l4
?
4877 ((1<<12) | (1<<19) /* bypass size and control flags */) : 0);
4878 wr32(E1000_IMIR(0), is_l4
?
4880 | (0<<16) /* immediate interrupt disabled */
4881 | 0 /* (1<<17) bit cleared: do not bypass
4882 destination port check */)
4884 wr32(E1000_FTQF0
, is_l4
?
4886 | (1<<15) /* VF not compared */
4887 | (1<<27) /* Enable Timestamping */
4888 | (7<<28) /* only source port filter enabled,
4889 source/target address and protocol
4891 : ((1<<15) | (15<<28) /* all mask bits set = filter not
4896 adapter
->hwtstamp_config
= config
;
4898 /* clear TX/RX time stamp registers, just to be sure */
4899 regval
= rd32(E1000_TXSTMPH
);
4900 regval
= rd32(E1000_RXSTMPH
);
4902 return copy_to_user(ifr
->ifr_data
, &config
, sizeof(config
)) ?
4912 static int igb_ioctl(struct net_device
*netdev
, struct ifreq
*ifr
, int cmd
)
4918 return igb_mii_ioctl(netdev
, ifr
, cmd
);
4920 return igb_hwtstamp_ioctl(netdev
, ifr
, cmd
);
4926 static void igb_vlan_rx_register(struct net_device
*netdev
,
4927 struct vlan_group
*grp
)
4929 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4930 struct e1000_hw
*hw
= &adapter
->hw
;
4933 igb_irq_disable(adapter
);
4934 adapter
->vlgrp
= grp
;
4937 /* enable VLAN tag insert/strip */
4938 ctrl
= rd32(E1000_CTRL
);
4939 ctrl
|= E1000_CTRL_VME
;
4940 wr32(E1000_CTRL
, ctrl
);
4942 /* enable VLAN receive filtering */
4943 rctl
= rd32(E1000_RCTL
);
4944 rctl
&= ~E1000_RCTL_CFIEN
;
4945 wr32(E1000_RCTL
, rctl
);
4946 igb_update_mng_vlan(adapter
);
4948 /* disable VLAN tag insert/strip */
4949 ctrl
= rd32(E1000_CTRL
);
4950 ctrl
&= ~E1000_CTRL_VME
;
4951 wr32(E1000_CTRL
, ctrl
);
4953 if (adapter
->mng_vlan_id
!= (u16
)IGB_MNG_VLAN_NONE
) {
4954 igb_vlan_rx_kill_vid(netdev
, adapter
->mng_vlan_id
);
4955 adapter
->mng_vlan_id
= IGB_MNG_VLAN_NONE
;
4959 igb_rlpml_set(adapter
);
4961 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
4962 igb_irq_enable(adapter
);
4965 static void igb_vlan_rx_add_vid(struct net_device
*netdev
, u16 vid
)
4967 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4968 struct e1000_hw
*hw
= &adapter
->hw
;
4969 int pf_id
= adapter
->vfs_allocated_count
;
4971 if ((hw
->mng_cookie
.status
&
4972 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
4973 (vid
== adapter
->mng_vlan_id
))
4976 /* add vid to vlvf if sr-iov is enabled,
4977 * if that fails add directly to filter table */
4978 if (igb_vlvf_set(adapter
, vid
, true, pf_id
))
4979 igb_vfta_set(hw
, vid
, true);
4983 static void igb_vlan_rx_kill_vid(struct net_device
*netdev
, u16 vid
)
4985 struct igb_adapter
*adapter
= netdev_priv(netdev
);
4986 struct e1000_hw
*hw
= &adapter
->hw
;
4987 int pf_id
= adapter
->vfs_allocated_count
;
4989 igb_irq_disable(adapter
);
4990 vlan_group_set_device(adapter
->vlgrp
, vid
, NULL
);
4992 if (!test_bit(__IGB_DOWN
, &adapter
->state
))
4993 igb_irq_enable(adapter
);
4995 if ((adapter
->hw
.mng_cookie
.status
&
4996 E1000_MNG_DHCP_COOKIE_STATUS_VLAN
) &&
4997 (vid
== adapter
->mng_vlan_id
)) {
4998 /* release control to f/w */
4999 igb_release_hw_control(adapter
);
5003 /* remove vid from vlvf if sr-iov is enabled,
5004 * if not in vlvf remove from vfta */
5005 if (igb_vlvf_set(adapter
, vid
, false, pf_id
))
5006 igb_vfta_set(hw
, vid
, false);
5009 static void igb_restore_vlan(struct igb_adapter
*adapter
)
5011 igb_vlan_rx_register(adapter
->netdev
, adapter
->vlgrp
);
5013 if (adapter
->vlgrp
) {
5015 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
5016 if (!vlan_group_get_device(adapter
->vlgrp
, vid
))
5018 igb_vlan_rx_add_vid(adapter
->netdev
, vid
);
5023 int igb_set_spd_dplx(struct igb_adapter
*adapter
, u16 spddplx
)
5025 struct e1000_mac_info
*mac
= &adapter
->hw
.mac
;
5029 /* Fiber NICs only allow 1000 gbps Full duplex */
5030 if ((adapter
->hw
.phy
.media_type
== e1000_media_type_fiber
) &&
5031 spddplx
!= (SPEED_1000
+ DUPLEX_FULL
)) {
5032 dev_err(&adapter
->pdev
->dev
,
5033 "Unsupported Speed/Duplex configuration\n");
5038 case SPEED_10
+ DUPLEX_HALF
:
5039 mac
->forced_speed_duplex
= ADVERTISE_10_HALF
;
5041 case SPEED_10
+ DUPLEX_FULL
:
5042 mac
->forced_speed_duplex
= ADVERTISE_10_FULL
;
5044 case SPEED_100
+ DUPLEX_HALF
:
5045 mac
->forced_speed_duplex
= ADVERTISE_100_HALF
;
5047 case SPEED_100
+ DUPLEX_FULL
:
5048 mac
->forced_speed_duplex
= ADVERTISE_100_FULL
;
5050 case SPEED_1000
+ DUPLEX_FULL
:
5052 adapter
->hw
.phy
.autoneg_advertised
= ADVERTISE_1000_FULL
;
5054 case SPEED_1000
+ DUPLEX_HALF
: /* not supported */
5056 dev_err(&adapter
->pdev
->dev
,
5057 "Unsupported Speed/Duplex configuration\n");
5063 static int __igb_shutdown(struct pci_dev
*pdev
, bool *enable_wake
)
5065 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5066 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5067 struct e1000_hw
*hw
= &adapter
->hw
;
5068 u32 ctrl
, rctl
, status
;
5069 u32 wufc
= adapter
->wol
;
5074 netif_device_detach(netdev
);
5076 if (netif_running(netdev
))
5079 igb_reset_interrupt_capability(adapter
);
5081 igb_free_queues(adapter
);
5084 retval
= pci_save_state(pdev
);
5089 status
= rd32(E1000_STATUS
);
5090 if (status
& E1000_STATUS_LU
)
5091 wufc
&= ~E1000_WUFC_LNKC
;
5094 igb_setup_rctl(adapter
);
5095 igb_set_multi(netdev
);
5097 /* turn on all-multi mode if wake on multicast is enabled */
5098 if (wufc
& E1000_WUFC_MC
) {
5099 rctl
= rd32(E1000_RCTL
);
5100 rctl
|= E1000_RCTL_MPE
;
5101 wr32(E1000_RCTL
, rctl
);
5104 ctrl
= rd32(E1000_CTRL
);
5105 /* advertise wake from D3Cold */
5106 #define E1000_CTRL_ADVD3WUC 0x00100000
5107 /* phy power management enable */
5108 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5109 ctrl
|= E1000_CTRL_ADVD3WUC
;
5110 wr32(E1000_CTRL
, ctrl
);
5112 /* Allow time for pending master requests to run */
5113 igb_disable_pcie_master(&adapter
->hw
);
5115 wr32(E1000_WUC
, E1000_WUC_PME_EN
);
5116 wr32(E1000_WUFC
, wufc
);
5119 wr32(E1000_WUFC
, 0);
5122 *enable_wake
= wufc
|| adapter
->en_mng_pt
;
5124 igb_shutdown_fiber_serdes_link_82575(hw
);
5126 /* Release control of h/w to f/w. If f/w is AMT enabled, this
5127 * would have already happened in close and is redundant. */
5128 igb_release_hw_control(adapter
);
5130 pci_disable_device(pdev
);
5136 static int igb_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5141 retval
= __igb_shutdown(pdev
, &wake
);
5146 pci_prepare_to_sleep(pdev
);
5148 pci_wake_from_d3(pdev
, false);
5149 pci_set_power_state(pdev
, PCI_D3hot
);
5155 static int igb_resume(struct pci_dev
*pdev
)
5157 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5158 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5159 struct e1000_hw
*hw
= &adapter
->hw
;
5162 pci_set_power_state(pdev
, PCI_D0
);
5163 pci_restore_state(pdev
);
5165 err
= pci_enable_device_mem(pdev
);
5168 "igb: Cannot enable PCI device from suspend\n");
5171 pci_set_master(pdev
);
5173 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5174 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5176 igb_set_interrupt_capability(adapter
);
5178 if (igb_alloc_queues(adapter
)) {
5179 dev_err(&pdev
->dev
, "Unable to allocate memory for queues\n");
5183 /* e1000_power_up_phy(adapter); */
5187 /* let the f/w know that the h/w is now under the control of the
5189 igb_get_hw_control(adapter
);
5191 wr32(E1000_WUS
, ~0);
5193 if (netif_running(netdev
)) {
5194 err
= igb_open(netdev
);
5199 netif_device_attach(netdev
);
5205 static void igb_shutdown(struct pci_dev
*pdev
)
5209 __igb_shutdown(pdev
, &wake
);
5211 if (system_state
== SYSTEM_POWER_OFF
) {
5212 pci_wake_from_d3(pdev
, wake
);
5213 pci_set_power_state(pdev
, PCI_D3hot
);
5217 #ifdef CONFIG_NET_POLL_CONTROLLER
5219 * Polling 'interrupt' - used by things like netconsole to send skbs
5220 * without having to re-enable interrupts. It's not called while
5221 * the interrupt routine is executing.
5223 static void igb_netpoll(struct net_device
*netdev
)
5225 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5226 struct e1000_hw
*hw
= &adapter
->hw
;
5229 if (!adapter
->msix_entries
) {
5230 igb_irq_disable(adapter
);
5231 napi_schedule(&adapter
->rx_ring
[0].napi
);
5235 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
5236 struct igb_ring
*tx_ring
= &adapter
->tx_ring
[i
];
5237 wr32(E1000_EIMC
, tx_ring
->eims_value
);
5238 igb_clean_tx_irq(tx_ring
);
5239 wr32(E1000_EIMS
, tx_ring
->eims_value
);
5242 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
5243 struct igb_ring
*rx_ring
= &adapter
->rx_ring
[i
];
5244 wr32(E1000_EIMC
, rx_ring
->eims_value
);
5245 napi_schedule(&rx_ring
->napi
);
5248 #endif /* CONFIG_NET_POLL_CONTROLLER */
5251 * igb_io_error_detected - called when PCI error is detected
5252 * @pdev: Pointer to PCI device
5253 * @state: The current pci connection state
5255 * This function is called after a PCI bus error affecting
5256 * this device has been detected.
5258 static pci_ers_result_t
igb_io_error_detected(struct pci_dev
*pdev
,
5259 pci_channel_state_t state
)
5261 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5262 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5264 netif_device_detach(netdev
);
5266 if (netif_running(netdev
))
5268 pci_disable_device(pdev
);
5270 /* Request a slot slot reset. */
5271 return PCI_ERS_RESULT_NEED_RESET
;
5275 * igb_io_slot_reset - called after the pci bus has been reset.
5276 * @pdev: Pointer to PCI device
5278 * Restart the card from scratch, as if from a cold-boot. Implementation
5279 * resembles the first-half of the igb_resume routine.
5281 static pci_ers_result_t
igb_io_slot_reset(struct pci_dev
*pdev
)
5283 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5284 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5285 struct e1000_hw
*hw
= &adapter
->hw
;
5286 pci_ers_result_t result
;
5289 if (pci_enable_device_mem(pdev
)) {
5291 "Cannot re-enable PCI device after reset.\n");
5292 result
= PCI_ERS_RESULT_DISCONNECT
;
5294 pci_set_master(pdev
);
5295 pci_restore_state(pdev
);
5297 pci_enable_wake(pdev
, PCI_D3hot
, 0);
5298 pci_enable_wake(pdev
, PCI_D3cold
, 0);
5301 wr32(E1000_WUS
, ~0);
5302 result
= PCI_ERS_RESULT_RECOVERED
;
5305 err
= pci_cleanup_aer_uncorrect_error_status(pdev
);
5307 dev_err(&pdev
->dev
, "pci_cleanup_aer_uncorrect_error_status "
5308 "failed 0x%0x\n", err
);
5309 /* non-fatal, continue */
5316 * igb_io_resume - called when traffic can start flowing again.
5317 * @pdev: Pointer to PCI device
5319 * This callback is called when the error recovery driver tells us that
5320 * its OK to resume normal operation. Implementation resembles the
5321 * second-half of the igb_resume routine.
5323 static void igb_io_resume(struct pci_dev
*pdev
)
5325 struct net_device
*netdev
= pci_get_drvdata(pdev
);
5326 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5328 if (netif_running(netdev
)) {
5329 if (igb_up(adapter
)) {
5330 dev_err(&pdev
->dev
, "igb_up failed after reset\n");
5335 netif_device_attach(netdev
);
5337 /* let the f/w know that the h/w is now under the control of the
5339 igb_get_hw_control(adapter
);
5342 static inline void igb_set_vmolr(struct e1000_hw
*hw
, int vfn
)
5346 reg_data
= rd32(E1000_VMOLR(vfn
));
5347 reg_data
|= E1000_VMOLR_BAM
| /* Accept broadcast */
5348 E1000_VMOLR_ROPE
| /* Accept packets matched in UTA */
5349 E1000_VMOLR_ROMPE
| /* Accept packets matched in MTA */
5350 E1000_VMOLR_AUPE
| /* Accept untagged packets */
5351 E1000_VMOLR_STRVLAN
; /* Strip vlan tags */
5352 wr32(E1000_VMOLR(vfn
), reg_data
);
5355 static inline int igb_set_vf_rlpml(struct igb_adapter
*adapter
, int size
,
5358 struct e1000_hw
*hw
= &adapter
->hw
;
5361 vmolr
= rd32(E1000_VMOLR(vfn
));
5362 vmolr
&= ~E1000_VMOLR_RLPML_MASK
;
5363 vmolr
|= size
| E1000_VMOLR_LPE
;
5364 wr32(E1000_VMOLR(vfn
), vmolr
);
5369 static inline void igb_set_rah_pool(struct e1000_hw
*hw
, int pool
, int entry
)
5373 reg_data
= rd32(E1000_RAH(entry
));
5374 reg_data
&= ~E1000_RAH_POOL_MASK
;
5375 reg_data
|= E1000_RAH_POOL_1
<< pool
;;
5376 wr32(E1000_RAH(entry
), reg_data
);
5379 static void igb_set_mc_list_pools(struct igb_adapter
*adapter
,
5380 int entry_count
, u16 total_rar_filters
)
5382 struct e1000_hw
*hw
= &adapter
->hw
;
5383 int i
= adapter
->vfs_allocated_count
+ 1;
5385 if ((i
+ entry_count
) < total_rar_filters
)
5386 total_rar_filters
= i
+ entry_count
;
5388 for (; i
< total_rar_filters
; i
++)
5389 igb_set_rah_pool(hw
, adapter
->vfs_allocated_count
, i
);
5392 static int igb_set_vf_mac(struct igb_adapter
*adapter
,
5393 int vf
, unsigned char *mac_addr
)
5395 struct e1000_hw
*hw
= &adapter
->hw
;
5396 int rar_entry
= vf
+ 1; /* VF MAC addresses start at entry 1 */
5398 igb_rar_set(hw
, mac_addr
, rar_entry
);
5400 memcpy(adapter
->vf_data
[vf
].vf_mac_addresses
, mac_addr
, ETH_ALEN
);
5402 igb_set_rah_pool(hw
, vf
, rar_entry
);
5407 static void igb_vmm_control(struct igb_adapter
*adapter
)
5409 struct e1000_hw
*hw
= &adapter
->hw
;
5412 if (!adapter
->vfs_allocated_count
)
5415 /* VF's need PF reset indication before they
5416 * can send/receive mail */
5417 reg_data
= rd32(E1000_CTRL_EXT
);
5418 reg_data
|= E1000_CTRL_EXT_PFRSTD
;
5419 wr32(E1000_CTRL_EXT
, reg_data
);
5421 igb_vmdq_set_loopback_pf(hw
, true);
5422 igb_vmdq_set_replication_pf(hw
, true);
5425 #ifdef CONFIG_PCI_IOV
5426 static ssize_t
igb_show_num_vfs(struct device
*dev
,
5427 struct device_attribute
*attr
, char *buf
)
5429 struct igb_adapter
*adapter
= netdev_priv(to_net_dev(dev
));
5431 return sprintf(buf
, "%d\n", adapter
->vfs_allocated_count
);
5434 static ssize_t
igb_set_num_vfs(struct device
*dev
,
5435 struct device_attribute
*attr
,
5436 const char *buf
, size_t count
)
5438 struct net_device
*netdev
= to_net_dev(dev
);
5439 struct igb_adapter
*adapter
= netdev_priv(netdev
);
5440 struct e1000_hw
*hw
= &adapter
->hw
;
5441 struct pci_dev
*pdev
= adapter
->pdev
;
5442 unsigned int num_vfs
, i
;
5443 unsigned char mac_addr
[ETH_ALEN
];
5446 sscanf(buf
, "%u", &num_vfs
);
5451 /* value unchanged do nothing */
5452 if (num_vfs
== adapter
->vfs_allocated_count
)
5455 if (netdev
->flags
& IFF_UP
)
5458 igb_reset_interrupt_capability(adapter
);
5459 igb_free_queues(adapter
);
5460 adapter
->tx_ring
= NULL
;
5461 adapter
->rx_ring
= NULL
;
5462 adapter
->vfs_allocated_count
= 0;
5464 /* reclaim resources allocated to VFs since we are changing count */
5465 if (adapter
->vf_data
) {
5466 /* disable iov and allow time for transactions to clear */
5467 pci_disable_sriov(pdev
);
5470 kfree(adapter
->vf_data
);
5471 adapter
->vf_data
= NULL
;
5472 wr32(E1000_IOVCTL
, E1000_IOVCTL_REUSE_VFQ
);
5474 dev_info(&pdev
->dev
, "IOV Disabled\n");
5478 adapter
->vf_data
= kcalloc(num_vfs
,
5479 sizeof(struct vf_data_storage
),
5481 if (!adapter
->vf_data
) {
5482 dev_err(&pdev
->dev
, "Could not allocate VF private "
5483 "data - IOV enable failed\n");
5485 err
= pci_enable_sriov(pdev
, num_vfs
);
5487 adapter
->vfs_allocated_count
= num_vfs
;
5488 dev_info(&pdev
->dev
, "%d vfs allocated\n", num_vfs
);
5489 for (i
= 0; i
< adapter
->vfs_allocated_count
; i
++) {
5490 random_ether_addr(mac_addr
);
5491 igb_set_vf_mac(adapter
, i
, mac_addr
);
5494 kfree(adapter
->vf_data
);
5495 adapter
->vf_data
= NULL
;
5500 igb_set_interrupt_capability(adapter
);
5501 igb_alloc_queues(adapter
);
5504 if (netdev
->flags
& IFF_UP
)
5509 #endif /* CONFIG_PCI_IOV */