blob: 9331e5212461f40766aefdceb89a144c0d775e8d [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007 Intel Corporation.
5
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.
9
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
13 more details.
14
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.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
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>
Auke Kok9d5c8242008-01-24 02:22:38 -080034#include <linux/ipv6.h>
35#include <net/checksum.h>
36#include <net/ip6_checksum.h>
37#include <linux/mii.h>
38#include <linux/ethtool.h>
39#include <linux/if_vlan.h>
40#include <linux/pci.h>
Alexander Duyckc54106b2008-10-16 21:26:57 -070041#include <linux/pci-aspm.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080042#include <linux/delay.h>
43#include <linux/interrupt.h>
44#include <linux/if_ether.h>
Alexander Duyck40a914f2008-11-27 00:24:37 -080045#include <linux/aer.h>
Jeff Kirsher421e02f2008-10-17 11:08:31 -070046#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -070047#include <linux/dca.h>
48#endif
Auke Kok9d5c8242008-01-24 02:22:38 -080049#include "igb.h"
50
Auke Kok0024fd02008-07-08 15:09:37 -070051#define DRV_VERSION "1.2.45-k2"
Auke Kok9d5c8242008-01-24 02:22:38 -080052char igb_driver_name[] = "igb";
53char igb_driver_version[] = DRV_VERSION;
54static const char igb_driver_string[] =
55 "Intel(R) Gigabit Ethernet Network Driver";
Alexander Duyck2d064c02008-07-08 15:10:12 -070056static const char igb_copyright[] = "Copyright (c) 2008 Intel Corporation.";
Auke Kok9d5c8242008-01-24 02:22:38 -080057
Auke Kok9d5c8242008-01-24 02:22:38 -080058static const struct e1000_info *igb_info_tbl[] = {
59 [board_82575] = &e1000_82575_info,
60};
61
62static struct pci_device_id igb_pci_tbl[] = {
Alexander Duyck2d064c02008-07-08 15:10:12 -070063 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
64 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
65 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
Auke Kok9d5c8242008-01-24 02:22:38 -080066 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
67 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
68 { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
69 /* required last entry */
70 {0, }
71};
72
73MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
74
75void igb_reset(struct igb_adapter *);
76static int igb_setup_all_tx_resources(struct igb_adapter *);
77static int igb_setup_all_rx_resources(struct igb_adapter *);
78static void igb_free_all_tx_resources(struct igb_adapter *);
79static void igb_free_all_rx_resources(struct igb_adapter *);
Auke Kok9d5c8242008-01-24 02:22:38 -080080void igb_update_stats(struct igb_adapter *);
81static int igb_probe(struct pci_dev *, const struct pci_device_id *);
82static void __devexit igb_remove(struct pci_dev *pdev);
83static int igb_sw_init(struct igb_adapter *);
84static int igb_open(struct net_device *);
85static int igb_close(struct net_device *);
86static void igb_configure_tx(struct igb_adapter *);
87static void igb_configure_rx(struct igb_adapter *);
88static void igb_setup_rctl(struct igb_adapter *);
89static void igb_clean_all_tx_rings(struct igb_adapter *);
90static void igb_clean_all_rx_rings(struct igb_adapter *);
Mitch Williams3b644cf2008-06-27 10:59:48 -070091static void igb_clean_tx_ring(struct igb_ring *);
92static void igb_clean_rx_ring(struct igb_ring *);
Auke Kok9d5c8242008-01-24 02:22:38 -080093static void igb_set_multi(struct net_device *);
94static void igb_update_phy_info(unsigned long);
95static void igb_watchdog(unsigned long);
96static void igb_watchdog_task(struct work_struct *);
97static int igb_xmit_frame_ring_adv(struct sk_buff *, struct net_device *,
98 struct igb_ring *);
99static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *);
100static struct net_device_stats *igb_get_stats(struct net_device *);
101static int igb_change_mtu(struct net_device *, int);
102static int igb_set_mac(struct net_device *, void *);
103static irqreturn_t igb_intr(int irq, void *);
104static irqreturn_t igb_intr_msi(int irq, void *);
105static irqreturn_t igb_msix_other(int irq, void *);
106static irqreturn_t igb_msix_rx(int irq, void *);
107static irqreturn_t igb_msix_tx(int irq, void *);
108static int igb_clean_rx_ring_msix(struct napi_struct *, int);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700109#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700110static void igb_update_rx_dca(struct igb_ring *);
111static void igb_update_tx_dca(struct igb_ring *);
112static void igb_setup_dca(struct igb_adapter *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700113#endif /* CONFIG_IGB_DCA */
Mitch Williams3b644cf2008-06-27 10:59:48 -0700114static bool igb_clean_tx_irq(struct igb_ring *);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700115static int igb_poll(struct napi_struct *, int);
Mitch Williams3b644cf2008-06-27 10:59:48 -0700116static bool igb_clean_rx_irq_adv(struct igb_ring *, int *, int);
117static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
Alexander Duyckd3352522008-07-08 15:12:13 -0700118#ifdef CONFIG_IGB_LRO
119static int igb_get_skb_hdr(struct sk_buff *skb, void **, void **, u64 *, void *);
120#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800121static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
122static void igb_tx_timeout(struct net_device *);
123static void igb_reset_task(struct work_struct *);
124static void igb_vlan_rx_register(struct net_device *, struct vlan_group *);
125static void igb_vlan_rx_add_vid(struct net_device *, u16);
126static void igb_vlan_rx_kill_vid(struct net_device *, u16);
127static void igb_restore_vlan(struct igb_adapter *);
128
129static int igb_suspend(struct pci_dev *, pm_message_t);
130#ifdef CONFIG_PM
131static int igb_resume(struct pci_dev *);
132#endif
133static void igb_shutdown(struct pci_dev *);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700134#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700135static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
136static struct notifier_block dca_notifier = {
137 .notifier_call = igb_notify_dca,
138 .next = NULL,
139 .priority = 0
140};
141#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800142
143#ifdef CONFIG_NET_POLL_CONTROLLER
144/* for netdump / net console */
145static void igb_netpoll(struct net_device *);
146#endif
147
148static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
149 pci_channel_state_t);
150static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
151static void igb_io_resume(struct pci_dev *);
152
153static struct pci_error_handlers igb_err_handler = {
154 .error_detected = igb_io_error_detected,
155 .slot_reset = igb_io_slot_reset,
156 .resume = igb_io_resume,
157};
158
159
160static struct pci_driver igb_driver = {
161 .name = igb_driver_name,
162 .id_table = igb_pci_tbl,
163 .probe = igb_probe,
164 .remove = __devexit_p(igb_remove),
165#ifdef CONFIG_PM
166 /* Power Managment Hooks */
167 .suspend = igb_suspend,
168 .resume = igb_resume,
169#endif
170 .shutdown = igb_shutdown,
171 .err_handler = &igb_err_handler
172};
173
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700174static int global_quad_port_a; /* global quad port a indication */
175
Auke Kok9d5c8242008-01-24 02:22:38 -0800176MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
177MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
178MODULE_LICENSE("GPL");
179MODULE_VERSION(DRV_VERSION);
180
181#ifdef DEBUG
182/**
183 * igb_get_hw_dev_name - return device name string
184 * used by hardware layer to print debugging information
185 **/
186char *igb_get_hw_dev_name(struct e1000_hw *hw)
187{
188 struct igb_adapter *adapter = hw->back;
189 return adapter->netdev->name;
190}
191#endif
192
193/**
194 * igb_init_module - Driver Registration Routine
195 *
196 * igb_init_module is the first routine called when the driver is
197 * loaded. All it does is register with the PCI subsystem.
198 **/
199static int __init igb_init_module(void)
200{
201 int ret;
202 printk(KERN_INFO "%s - version %s\n",
203 igb_driver_string, igb_driver_version);
204
205 printk(KERN_INFO "%s\n", igb_copyright);
206
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700207 global_quad_port_a = 0;
208
Auke Kok9d5c8242008-01-24 02:22:38 -0800209 ret = pci_register_driver(&igb_driver);
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700210#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700211 dca_register_notify(&dca_notifier);
212#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800213 return ret;
214}
215
216module_init(igb_init_module);
217
218/**
219 * igb_exit_module - Driver Exit Cleanup Routine
220 *
221 * igb_exit_module is called just before the driver is removed
222 * from memory.
223 **/
224static void __exit igb_exit_module(void)
225{
Jeff Kirsher421e02f2008-10-17 11:08:31 -0700226#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -0700227 dca_unregister_notify(&dca_notifier);
228#endif
Auke Kok9d5c8242008-01-24 02:22:38 -0800229 pci_unregister_driver(&igb_driver);
230}
231
232module_exit(igb_exit_module);
233
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800234#define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
235/**
236 * igb_cache_ring_register - Descriptor ring to register mapping
237 * @adapter: board private structure to initialize
238 *
239 * Once we know the feature-set enabled for the device, we'll cache
240 * the register offset the descriptor ring is assigned to.
241 **/
242static void igb_cache_ring_register(struct igb_adapter *adapter)
243{
244 int i;
245
246 switch (adapter->hw.mac.type) {
247 case e1000_82576:
248 /* The queues are allocated for virtualization such that VF 0
249 * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
250 * In order to avoid collision we start at the first free queue
251 * and continue consuming queues in the same sequence
252 */
253 for (i = 0; i < adapter->num_rx_queues; i++)
254 adapter->rx_ring[i].reg_idx = Q_IDX_82576(i);
255 for (i = 0; i < adapter->num_tx_queues; i++)
256 adapter->tx_ring[i].reg_idx = Q_IDX_82576(i);
257 break;
258 case e1000_82575:
259 default:
260 for (i = 0; i < adapter->num_rx_queues; i++)
261 adapter->rx_ring[i].reg_idx = i;
262 for (i = 0; i < adapter->num_tx_queues; i++)
263 adapter->tx_ring[i].reg_idx = i;
264 break;
265 }
266}
267
Auke Kok9d5c8242008-01-24 02:22:38 -0800268/**
269 * igb_alloc_queues - Allocate memory for all rings
270 * @adapter: board private structure to initialize
271 *
272 * We allocate one ring per queue at run-time since we don't know the
273 * number of queues at compile-time.
274 **/
275static int igb_alloc_queues(struct igb_adapter *adapter)
276{
277 int i;
278
279 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
280 sizeof(struct igb_ring), GFP_KERNEL);
281 if (!adapter->tx_ring)
282 return -ENOMEM;
283
284 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
285 sizeof(struct igb_ring), GFP_KERNEL);
286 if (!adapter->rx_ring) {
287 kfree(adapter->tx_ring);
288 return -ENOMEM;
289 }
290
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -0700291 adapter->rx_ring->buddy = adapter->tx_ring;
292
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700293 for (i = 0; i < adapter->num_tx_queues; i++) {
294 struct igb_ring *ring = &(adapter->tx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800295 ring->count = adapter->tx_ring_count;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700296 ring->adapter = adapter;
297 ring->queue_index = i;
298 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800299 for (i = 0; i < adapter->num_rx_queues; i++) {
300 struct igb_ring *ring = &(adapter->rx_ring[i]);
Alexander Duyck68fd9912008-11-20 00:48:10 -0800301 ring->count = adapter->rx_ring_count;
Auke Kok9d5c8242008-01-24 02:22:38 -0800302 ring->adapter = adapter;
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700303 ring->queue_index = i;
Auke Kok9d5c8242008-01-24 02:22:38 -0800304 ring->itr_register = E1000_ITR;
305
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700306 /* set a default napi handler for each rx_ring */
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700307 netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64);
Auke Kok9d5c8242008-01-24 02:22:38 -0800308 }
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800309
310 igb_cache_ring_register(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800311 return 0;
312}
313
Alexander Duycka88f10e2008-07-08 15:13:38 -0700314static void igb_free_queues(struct igb_adapter *adapter)
315{
316 int i;
317
318 for (i = 0; i < adapter->num_rx_queues; i++)
319 netif_napi_del(&adapter->rx_ring[i].napi);
320
321 kfree(adapter->tx_ring);
322 kfree(adapter->rx_ring);
323}
324
Auke Kok9d5c8242008-01-24 02:22:38 -0800325#define IGB_N0_QUEUE -1
326static void igb_assign_vector(struct igb_adapter *adapter, int rx_queue,
327 int tx_queue, int msix_vector)
328{
329 u32 msixbm = 0;
330 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700331 u32 ivar, index;
332
333 switch (hw->mac.type) {
334 case e1000_82575:
Auke Kok9d5c8242008-01-24 02:22:38 -0800335 /* The 82575 assigns vectors using a bitmask, which matches the
336 bitmask for the EICR/EIMS/EIMC registers. To assign one
337 or more queues to a vector, we write the appropriate bits
338 into the MSIXBM register for that vector. */
339 if (rx_queue > IGB_N0_QUEUE) {
340 msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
341 adapter->rx_ring[rx_queue].eims_value = msixbm;
342 }
343 if (tx_queue > IGB_N0_QUEUE) {
344 msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
345 adapter->tx_ring[tx_queue].eims_value =
346 E1000_EICR_TX_QUEUE0 << tx_queue;
347 }
348 array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700349 break;
350 case e1000_82576:
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800351 /* 82576 uses a table-based method for assigning vectors.
Alexander Duyck2d064c02008-07-08 15:10:12 -0700352 Each queue has a single entry in the table to which we write
353 a vector number along with a "valid" bit. Sadly, the layout
354 of the table is somewhat counterintuitive. */
355 if (rx_queue > IGB_N0_QUEUE) {
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800356 index = (rx_queue >> 1);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700357 ivar = array_rd32(E1000_IVAR0, index);
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800358 if (rx_queue & 0x1) {
Alexander Duyck2d064c02008-07-08 15:10:12 -0700359 /* vector goes into third byte of register */
360 ivar = ivar & 0xFF00FFFF;
361 ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800362 } else {
363 /* vector goes into low byte of register */
364 ivar = ivar & 0xFFFFFF00;
365 ivar |= msix_vector | E1000_IVAR_VALID;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700366 }
367 adapter->rx_ring[rx_queue].eims_value= 1 << msix_vector;
368 array_wr32(E1000_IVAR0, index, ivar);
369 }
370 if (tx_queue > IGB_N0_QUEUE) {
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800371 index = (tx_queue >> 1);
Alexander Duyck2d064c02008-07-08 15:10:12 -0700372 ivar = array_rd32(E1000_IVAR0, index);
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800373 if (tx_queue & 0x1) {
Alexander Duyck2d064c02008-07-08 15:10:12 -0700374 /* vector goes into high byte of register */
375 ivar = ivar & 0x00FFFFFF;
376 ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
Alexander Duyck26bc19e2008-12-26 01:34:11 -0800377 } else {
378 /* vector goes into second byte of register */
379 ivar = ivar & 0xFFFF00FF;
380 ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700381 }
382 adapter->tx_ring[tx_queue].eims_value= 1 << msix_vector;
383 array_wr32(E1000_IVAR0, index, ivar);
384 }
385 break;
386 default:
387 BUG();
388 break;
389 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800390}
391
392/**
393 * igb_configure_msix - Configure MSI-X hardware
394 *
395 * igb_configure_msix sets up the hardware to properly
396 * generate MSI-X interrupts.
397 **/
398static void igb_configure_msix(struct igb_adapter *adapter)
399{
400 u32 tmp;
401 int i, vector = 0;
402 struct e1000_hw *hw = &adapter->hw;
403
404 adapter->eims_enable_mask = 0;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700405 if (hw->mac.type == e1000_82576)
406 /* Turn on MSI-X capability first, or our settings
407 * won't stick. And it will take days to debug. */
408 wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
409 E1000_GPIE_PBA | E1000_GPIE_EIAME |
410 E1000_GPIE_NSICR);
Auke Kok9d5c8242008-01-24 02:22:38 -0800411
412 for (i = 0; i < adapter->num_tx_queues; i++) {
413 struct igb_ring *tx_ring = &adapter->tx_ring[i];
414 igb_assign_vector(adapter, IGB_N0_QUEUE, i, vector++);
415 adapter->eims_enable_mask |= tx_ring->eims_value;
416 if (tx_ring->itr_val)
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -0700417 writel(tx_ring->itr_val,
Auke Kok9d5c8242008-01-24 02:22:38 -0800418 hw->hw_addr + tx_ring->itr_register);
419 else
420 writel(1, hw->hw_addr + tx_ring->itr_register);
421 }
422
423 for (i = 0; i < adapter->num_rx_queues; i++) {
424 struct igb_ring *rx_ring = &adapter->rx_ring[i];
Harvey Harrison25ac3c22008-07-16 12:45:27 -0700425 rx_ring->buddy = NULL;
Auke Kok9d5c8242008-01-24 02:22:38 -0800426 igb_assign_vector(adapter, i, IGB_N0_QUEUE, vector++);
427 adapter->eims_enable_mask |= rx_ring->eims_value;
428 if (rx_ring->itr_val)
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -0700429 writel(rx_ring->itr_val,
Auke Kok9d5c8242008-01-24 02:22:38 -0800430 hw->hw_addr + rx_ring->itr_register);
431 else
432 writel(1, hw->hw_addr + rx_ring->itr_register);
433 }
434
435
436 /* set vector for other causes, i.e. link changes */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700437 switch (hw->mac.type) {
438 case e1000_82575:
Auke Kok9d5c8242008-01-24 02:22:38 -0800439 array_wr32(E1000_MSIXBM(0), vector++,
440 E1000_EIMS_OTHER);
441
Auke Kok9d5c8242008-01-24 02:22:38 -0800442 tmp = rd32(E1000_CTRL_EXT);
443 /* enable MSI-X PBA support*/
444 tmp |= E1000_CTRL_EXT_PBA_CLR;
445
446 /* Auto-Mask interrupts upon ICR read. */
447 tmp |= E1000_CTRL_EXT_EIAME;
448 tmp |= E1000_CTRL_EXT_IRCA;
449
450 wr32(E1000_CTRL_EXT, tmp);
451 adapter->eims_enable_mask |= E1000_EIMS_OTHER;
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700452 adapter->eims_other = E1000_EIMS_OTHER;
Auke Kok9d5c8242008-01-24 02:22:38 -0800453
Alexander Duyck2d064c02008-07-08 15:10:12 -0700454 break;
455
456 case e1000_82576:
457 tmp = (vector++ | E1000_IVAR_VALID) << 8;
458 wr32(E1000_IVAR_MISC, tmp);
459
460 adapter->eims_enable_mask = (1 << (vector)) - 1;
461 adapter->eims_other = 1 << (vector - 1);
462 break;
463 default:
464 /* do nothing, since nothing else supports MSI-X */
465 break;
466 } /* switch (hw->mac.type) */
Auke Kok9d5c8242008-01-24 02:22:38 -0800467 wrfl();
468}
469
470/**
471 * igb_request_msix - Initialize MSI-X interrupts
472 *
473 * igb_request_msix allocates MSI-X vectors and requests interrupts from the
474 * kernel.
475 **/
476static int igb_request_msix(struct igb_adapter *adapter)
477{
478 struct net_device *netdev = adapter->netdev;
479 int i, err = 0, vector = 0;
480
481 vector = 0;
482
483 for (i = 0; i < adapter->num_tx_queues; i++) {
484 struct igb_ring *ring = &(adapter->tx_ring[i]);
Alexander Duyckcb7b48f2008-12-05 15:08:03 -0800485 sprintf(ring->name, "%s-tx-%d", netdev->name, i);
Auke Kok9d5c8242008-01-24 02:22:38 -0800486 err = request_irq(adapter->msix_entries[vector].vector,
487 &igb_msix_tx, 0, ring->name,
488 &(adapter->tx_ring[i]));
489 if (err)
490 goto out;
491 ring->itr_register = E1000_EITR(0) + (vector << 2);
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -0700492 ring->itr_val = 976; /* ~4000 ints/sec */
Auke Kok9d5c8242008-01-24 02:22:38 -0800493 vector++;
494 }
495 for (i = 0; i < adapter->num_rx_queues; i++) {
496 struct igb_ring *ring = &(adapter->rx_ring[i]);
497 if (strlen(netdev->name) < (IFNAMSIZ - 5))
Alexander Duyckcb7b48f2008-12-05 15:08:03 -0800498 sprintf(ring->name, "%s-rx-%d", netdev->name, i);
Auke Kok9d5c8242008-01-24 02:22:38 -0800499 else
500 memcpy(ring->name, netdev->name, IFNAMSIZ);
501 err = request_irq(adapter->msix_entries[vector].vector,
502 &igb_msix_rx, 0, ring->name,
503 &(adapter->rx_ring[i]));
504 if (err)
505 goto out;
506 ring->itr_register = E1000_EITR(0) + (vector << 2);
507 ring->itr_val = adapter->itr;
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700508 /* overwrite the poll routine for MSIX, we've already done
509 * netif_napi_add */
510 ring->napi.poll = &igb_clean_rx_ring_msix;
Auke Kok9d5c8242008-01-24 02:22:38 -0800511 vector++;
512 }
513
514 err = request_irq(adapter->msix_entries[vector].vector,
515 &igb_msix_other, 0, netdev->name, netdev);
516 if (err)
517 goto out;
518
Auke Kok9d5c8242008-01-24 02:22:38 -0800519 igb_configure_msix(adapter);
520 return 0;
521out:
522 return err;
523}
524
525static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
526{
527 if (adapter->msix_entries) {
528 pci_disable_msix(adapter->pdev);
529 kfree(adapter->msix_entries);
530 adapter->msix_entries = NULL;
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700531 } else if (adapter->flags & IGB_FLAG_HAS_MSI)
Auke Kok9d5c8242008-01-24 02:22:38 -0800532 pci_disable_msi(adapter->pdev);
533 return;
534}
535
536
537/**
538 * igb_set_interrupt_capability - set MSI or MSI-X if supported
539 *
540 * Attempt to configure interrupts using the best available
541 * capabilities of the hardware and kernel.
542 **/
543static void igb_set_interrupt_capability(struct igb_adapter *adapter)
544{
545 int err;
546 int numvecs, i;
547
548 numvecs = adapter->num_tx_queues + adapter->num_rx_queues + 1;
549 adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
550 GFP_KERNEL);
551 if (!adapter->msix_entries)
552 goto msi_only;
553
554 for (i = 0; i < numvecs; i++)
555 adapter->msix_entries[i].entry = i;
556
557 err = pci_enable_msix(adapter->pdev,
558 adapter->msix_entries,
559 numvecs);
560 if (err == 0)
Alexander Duyck34a20e82008-08-26 04:25:13 -0700561 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800562
563 igb_reset_interrupt_capability(adapter);
564
565 /* If we can't do MSI-X, try MSI */
566msi_only:
567 adapter->num_rx_queues = 1;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700568 adapter->num_tx_queues = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -0800569 if (!pci_enable_msi(adapter->pdev))
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700570 adapter->flags |= IGB_FLAG_HAS_MSI;
Alexander Duyck34a20e82008-08-26 04:25:13 -0700571out:
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -0700572 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -0700573 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Auke Kok9d5c8242008-01-24 02:22:38 -0800574 return;
575}
576
577/**
578 * igb_request_irq - initialize interrupts
579 *
580 * Attempts to configure interrupts using the best available
581 * capabilities of the hardware and kernel.
582 **/
583static int igb_request_irq(struct igb_adapter *adapter)
584{
585 struct net_device *netdev = adapter->netdev;
586 struct e1000_hw *hw = &adapter->hw;
587 int err = 0;
588
589 if (adapter->msix_entries) {
590 err = igb_request_msix(adapter);
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700591 if (!err)
Auke Kok9d5c8242008-01-24 02:22:38 -0800592 goto request_done;
Auke Kok9d5c8242008-01-24 02:22:38 -0800593 /* fall back to MSI */
594 igb_reset_interrupt_capability(adapter);
595 if (!pci_enable_msi(adapter->pdev))
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700596 adapter->flags |= IGB_FLAG_HAS_MSI;
Auke Kok9d5c8242008-01-24 02:22:38 -0800597 igb_free_all_tx_resources(adapter);
598 igb_free_all_rx_resources(adapter);
599 adapter->num_rx_queues = 1;
600 igb_alloc_queues(adapter);
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700601 } else {
Alexander Duyck2d064c02008-07-08 15:10:12 -0700602 switch (hw->mac.type) {
603 case e1000_82575:
604 wr32(E1000_MSIXBM(0),
605 (E1000_EICR_RX_QUEUE0 | E1000_EIMS_OTHER));
606 break;
607 case e1000_82576:
608 wr32(E1000_IVAR0, E1000_IVAR_VALID);
609 break;
610 default:
611 break;
612 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800613 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700614
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700615 if (adapter->flags & IGB_FLAG_HAS_MSI) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800616 err = request_irq(adapter->pdev->irq, &igb_intr_msi, 0,
617 netdev->name, netdev);
618 if (!err)
619 goto request_done;
620 /* fall back to legacy interrupts */
621 igb_reset_interrupt_capability(adapter);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -0700622 adapter->flags &= ~IGB_FLAG_HAS_MSI;
Auke Kok9d5c8242008-01-24 02:22:38 -0800623 }
624
625 err = request_irq(adapter->pdev->irq, &igb_intr, IRQF_SHARED,
626 netdev->name, netdev);
627
Andy Gospodarek6cb5e572008-02-15 14:05:25 -0800628 if (err)
Auke Kok9d5c8242008-01-24 02:22:38 -0800629 dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
630 err);
Auke Kok9d5c8242008-01-24 02:22:38 -0800631
632request_done:
633 return err;
634}
635
636static void igb_free_irq(struct igb_adapter *adapter)
637{
638 struct net_device *netdev = adapter->netdev;
639
640 if (adapter->msix_entries) {
641 int vector = 0, i;
642
643 for (i = 0; i < adapter->num_tx_queues; i++)
644 free_irq(adapter->msix_entries[vector++].vector,
645 &(adapter->tx_ring[i]));
646 for (i = 0; i < adapter->num_rx_queues; i++)
647 free_irq(adapter->msix_entries[vector++].vector,
648 &(adapter->rx_ring[i]));
649
650 free_irq(adapter->msix_entries[vector++].vector, netdev);
651 return;
652 }
653
654 free_irq(adapter->pdev->irq, netdev);
655}
656
657/**
658 * igb_irq_disable - Mask off interrupt generation on the NIC
659 * @adapter: board private structure
660 **/
661static void igb_irq_disable(struct igb_adapter *adapter)
662{
663 struct e1000_hw *hw = &adapter->hw;
664
665 if (adapter->msix_entries) {
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700666 wr32(E1000_EIAM, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800667 wr32(E1000_EIMC, ~0);
668 wr32(E1000_EIAC, 0);
669 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700670
671 wr32(E1000_IAM, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800672 wr32(E1000_IMC, ~0);
673 wrfl();
674 synchronize_irq(adapter->pdev->irq);
675}
676
677/**
678 * igb_irq_enable - Enable default interrupt generation settings
679 * @adapter: board private structure
680 **/
681static void igb_irq_enable(struct igb_adapter *adapter)
682{
683 struct e1000_hw *hw = &adapter->hw;
684
685 if (adapter->msix_entries) {
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700686 wr32(E1000_EIAC, adapter->eims_enable_mask);
687 wr32(E1000_EIAM, adapter->eims_enable_mask);
688 wr32(E1000_EIMS, adapter->eims_enable_mask);
Auke Kok9d5c8242008-01-24 02:22:38 -0800689 wr32(E1000_IMS, E1000_IMS_LSC);
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700690 } else {
691 wr32(E1000_IMS, IMS_ENABLE_MASK);
692 wr32(E1000_IAM, IMS_ENABLE_MASK);
693 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800694}
695
696static void igb_update_mng_vlan(struct igb_adapter *adapter)
697{
698 struct net_device *netdev = adapter->netdev;
699 u16 vid = adapter->hw.mng_cookie.vlan_id;
700 u16 old_vid = adapter->mng_vlan_id;
701 if (adapter->vlgrp) {
702 if (!vlan_group_get_device(adapter->vlgrp, vid)) {
703 if (adapter->hw.mng_cookie.status &
704 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
705 igb_vlan_rx_add_vid(netdev, vid);
706 adapter->mng_vlan_id = vid;
707 } else
708 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
709
710 if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
711 (vid != old_vid) &&
712 !vlan_group_get_device(adapter->vlgrp, old_vid))
713 igb_vlan_rx_kill_vid(netdev, old_vid);
714 } else
715 adapter->mng_vlan_id = vid;
716 }
717}
718
719/**
720 * igb_release_hw_control - release control of the h/w to f/w
721 * @adapter: address of board private structure
722 *
723 * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
724 * For ASF and Pass Through versions of f/w this means that the
725 * driver is no longer loaded.
726 *
727 **/
728static void igb_release_hw_control(struct igb_adapter *adapter)
729{
730 struct e1000_hw *hw = &adapter->hw;
731 u32 ctrl_ext;
732
733 /* Let firmware take over control of h/w */
734 ctrl_ext = rd32(E1000_CTRL_EXT);
735 wr32(E1000_CTRL_EXT,
736 ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
737}
738
739
740/**
741 * igb_get_hw_control - get control of the h/w from f/w
742 * @adapter: address of board private structure
743 *
744 * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
745 * For ASF and Pass Through versions of f/w this means that
746 * the driver is loaded.
747 *
748 **/
749static void igb_get_hw_control(struct igb_adapter *adapter)
750{
751 struct e1000_hw *hw = &adapter->hw;
752 u32 ctrl_ext;
753
754 /* Let firmware know the driver has taken over */
755 ctrl_ext = rd32(E1000_CTRL_EXT);
756 wr32(E1000_CTRL_EXT,
757 ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
758}
759
Auke Kok9d5c8242008-01-24 02:22:38 -0800760/**
761 * igb_configure - configure the hardware for RX and TX
762 * @adapter: private board structure
763 **/
764static void igb_configure(struct igb_adapter *adapter)
765{
766 struct net_device *netdev = adapter->netdev;
767 int i;
768
769 igb_get_hw_control(adapter);
770 igb_set_multi(netdev);
771
772 igb_restore_vlan(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800773
774 igb_configure_tx(adapter);
775 igb_setup_rctl(adapter);
776 igb_configure_rx(adapter);
Alexander Duyck662d7202008-06-27 11:00:29 -0700777
778 igb_rx_fifo_flush_82575(&adapter->hw);
779
Auke Kok9d5c8242008-01-24 02:22:38 -0800780 /* call IGB_DESC_UNUSED which always leaves
781 * at least 1 descriptor unused to make sure
782 * next_to_use != next_to_clean */
783 for (i = 0; i < adapter->num_rx_queues; i++) {
784 struct igb_ring *ring = &adapter->rx_ring[i];
Mitch Williams3b644cf2008-06-27 10:59:48 -0700785 igb_alloc_rx_buffers_adv(ring, IGB_DESC_UNUSED(ring));
Auke Kok9d5c8242008-01-24 02:22:38 -0800786 }
787
788
789 adapter->tx_queue_len = netdev->tx_queue_len;
790}
791
792
793/**
794 * igb_up - Open the interface and prepare it to handle traffic
795 * @adapter: board private structure
796 **/
797
798int igb_up(struct igb_adapter *adapter)
799{
800 struct e1000_hw *hw = &adapter->hw;
801 int i;
802
803 /* hardware has been reset, we need to reload some things */
804 igb_configure(adapter);
805
806 clear_bit(__IGB_DOWN, &adapter->state);
807
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700808 for (i = 0; i < adapter->num_rx_queues; i++)
809 napi_enable(&adapter->rx_ring[i].napi);
810 if (adapter->msix_entries)
Auke Kok9d5c8242008-01-24 02:22:38 -0800811 igb_configure_msix(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800812
813 /* Clear any pending interrupts. */
814 rd32(E1000_ICR);
815 igb_irq_enable(adapter);
816
817 /* Fire a link change interrupt to start the watchdog. */
818 wr32(E1000_ICS, E1000_ICS_LSC);
819 return 0;
820}
821
822void igb_down(struct igb_adapter *adapter)
823{
824 struct e1000_hw *hw = &adapter->hw;
825 struct net_device *netdev = adapter->netdev;
826 u32 tctl, rctl;
827 int i;
828
829 /* signal that we're down so the interrupt handler does not
830 * reschedule our watchdog timer */
831 set_bit(__IGB_DOWN, &adapter->state);
832
833 /* disable receives in the hardware */
834 rctl = rd32(E1000_RCTL);
835 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
836 /* flush and sleep below */
837
David S. Millerfd2ea0a2008-07-17 01:56:23 -0700838 netif_tx_stop_all_queues(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -0800839
840 /* disable transmits in the hardware */
841 tctl = rd32(E1000_TCTL);
842 tctl &= ~E1000_TCTL_EN;
843 wr32(E1000_TCTL, tctl);
844 /* flush both disables and wait for them to finish */
845 wrfl();
846 msleep(10);
847
PJ Waskiewicz844290e2008-06-27 11:00:39 -0700848 for (i = 0; i < adapter->num_rx_queues; i++)
849 napi_disable(&adapter->rx_ring[i].napi);
Auke Kok9d5c8242008-01-24 02:22:38 -0800850
Auke Kok9d5c8242008-01-24 02:22:38 -0800851 igb_irq_disable(adapter);
852
853 del_timer_sync(&adapter->watchdog_timer);
854 del_timer_sync(&adapter->phy_info_timer);
855
856 netdev->tx_queue_len = adapter->tx_queue_len;
857 netif_carrier_off(netdev);
858 adapter->link_speed = 0;
859 adapter->link_duplex = 0;
860
Jeff Kirsher30236822008-06-24 17:01:15 -0700861 if (!pci_channel_offline(adapter->pdev))
862 igb_reset(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -0800863 igb_clean_all_tx_rings(adapter);
864 igb_clean_all_rx_rings(adapter);
865}
866
867void igb_reinit_locked(struct igb_adapter *adapter)
868{
869 WARN_ON(in_interrupt());
870 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
871 msleep(1);
872 igb_down(adapter);
873 igb_up(adapter);
874 clear_bit(__IGB_RESETTING, &adapter->state);
875}
876
877void igb_reset(struct igb_adapter *adapter)
878{
879 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700880 struct e1000_mac_info *mac = &hw->mac;
881 struct e1000_fc_info *fc = &hw->fc;
Auke Kok9d5c8242008-01-24 02:22:38 -0800882 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
883 u16 hwm;
884
885 /* Repartition Pba for greater than 9k mtu
886 * To take effect CTRL.RST is required.
887 */
Alexander Duyck2d064c02008-07-08 15:10:12 -0700888 if (mac->type != e1000_82576) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800889 pba = E1000_PBA_34K;
Alexander Duyck2d064c02008-07-08 15:10:12 -0700890 }
891 else {
892 pba = E1000_PBA_64K;
893 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800894
Alexander Duyck2d064c02008-07-08 15:10:12 -0700895 if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
896 (mac->type < e1000_82576)) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800897 /* adjust PBA for jumbo frames */
898 wr32(E1000_PBA, pba);
899
900 /* To maintain wire speed transmits, the Tx FIFO should be
901 * large enough to accommodate two full transmit packets,
902 * rounded up to the next 1KB and expressed in KB. Likewise,
903 * the Rx FIFO should be large enough to accommodate at least
904 * one full receive packet and is similarly rounded up and
905 * expressed in KB. */
906 pba = rd32(E1000_PBA);
907 /* upper 16 bits has Tx packet buffer allocation size in KB */
908 tx_space = pba >> 16;
909 /* lower 16 bits has Rx packet buffer allocation size in KB */
910 pba &= 0xffff;
911 /* the tx fifo also stores 16 bytes of information about the tx
912 * but don't include ethernet FCS because hardware appends it */
913 min_tx_space = (adapter->max_frame_size +
914 sizeof(struct e1000_tx_desc) -
915 ETH_FCS_LEN) * 2;
916 min_tx_space = ALIGN(min_tx_space, 1024);
917 min_tx_space >>= 10;
918 /* software strips receive CRC, so leave room for it */
919 min_rx_space = adapter->max_frame_size;
920 min_rx_space = ALIGN(min_rx_space, 1024);
921 min_rx_space >>= 10;
922
923 /* If current Tx allocation is less than the min Tx FIFO size,
924 * and the min Tx FIFO size is less than the current Rx FIFO
925 * allocation, take space away from current Rx allocation */
926 if (tx_space < min_tx_space &&
927 ((min_tx_space - tx_space) < pba)) {
928 pba = pba - (min_tx_space - tx_space);
929
930 /* if short on rx space, rx wins and must trump tx
931 * adjustment */
932 if (pba < min_rx_space)
933 pba = min_rx_space;
934 }
Alexander Duyck2d064c02008-07-08 15:10:12 -0700935 wr32(E1000_PBA, pba);
Auke Kok9d5c8242008-01-24 02:22:38 -0800936 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800937
938 /* flow control settings */
939 /* The high water mark must be low enough to fit one full frame
940 * (or the size used for early receive) above it in the Rx FIFO.
941 * Set it to the lower of:
942 * - 90% of the Rx FIFO size, or
943 * - the full Rx FIFO size minus one full frame */
944 hwm = min(((pba << 10) * 9 / 10),
Alexander Duyck2d064c02008-07-08 15:10:12 -0700945 ((pba << 10) - 2 * adapter->max_frame_size));
Auke Kok9d5c8242008-01-24 02:22:38 -0800946
Alexander Duyck2d064c02008-07-08 15:10:12 -0700947 if (mac->type < e1000_82576) {
948 fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
949 fc->low_water = fc->high_water - 8;
950 } else {
951 fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
952 fc->low_water = fc->high_water - 16;
953 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800954 fc->pause_time = 0xFFFF;
955 fc->send_xon = 1;
956 fc->type = fc->original_type;
957
958 /* Allow time for pending master requests to run */
959 adapter->hw.mac.ops.reset_hw(&adapter->hw);
960 wr32(E1000_WUC, 0);
961
962 if (adapter->hw.mac.ops.init_hw(&adapter->hw))
963 dev_err(&adapter->pdev->dev, "Hardware Error\n");
964
965 igb_update_mng_vlan(adapter);
966
967 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
968 wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
969
970 igb_reset_adaptive(&adapter->hw);
Alexander Duyckf5f4cf02008-11-21 21:30:24 -0800971 igb_get_phy_info(&adapter->hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800972}
973
974/**
Taku Izumi42bfd33a2008-06-20 12:10:30 +0900975 * igb_is_need_ioport - determine if an adapter needs ioport resources or not
976 * @pdev: PCI device information struct
977 *
978 * Returns true if an adapter needs ioport resources
979 **/
980static int igb_is_need_ioport(struct pci_dev *pdev)
981{
982 switch (pdev->device) {
983 /* Currently there are no adapters that need ioport resources */
984 default:
985 return false;
986 }
987}
988
Stephen Hemminger2e5c6922008-11-19 22:20:44 -0800989static const struct net_device_ops igb_netdev_ops = {
990 .ndo_open = igb_open,
991 .ndo_stop = igb_close,
Stephen Hemminger00829822008-11-20 20:14:53 -0800992 .ndo_start_xmit = igb_xmit_frame_adv,
Stephen Hemminger2e5c6922008-11-19 22:20:44 -0800993 .ndo_get_stats = igb_get_stats,
994 .ndo_set_multicast_list = igb_set_multi,
995 .ndo_set_mac_address = igb_set_mac,
996 .ndo_change_mtu = igb_change_mtu,
997 .ndo_do_ioctl = igb_ioctl,
998 .ndo_tx_timeout = igb_tx_timeout,
999 .ndo_validate_addr = eth_validate_addr,
1000 .ndo_vlan_rx_register = igb_vlan_rx_register,
1001 .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
1002 .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
1003#ifdef CONFIG_NET_POLL_CONTROLLER
1004 .ndo_poll_controller = igb_netpoll,
1005#endif
1006};
1007
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001008/**
Auke Kok9d5c8242008-01-24 02:22:38 -08001009 * igb_probe - Device Initialization Routine
1010 * @pdev: PCI device information struct
1011 * @ent: entry in igb_pci_tbl
1012 *
1013 * Returns 0 on success, negative on failure
1014 *
1015 * igb_probe initializes an adapter identified by a pci_dev structure.
1016 * The OS initialization, configuring of the adapter private structure,
1017 * and a hardware reset occur.
1018 **/
1019static int __devinit igb_probe(struct pci_dev *pdev,
1020 const struct pci_device_id *ent)
1021{
1022 struct net_device *netdev;
1023 struct igb_adapter *adapter;
1024 struct e1000_hw *hw;
Alexander Duyckc54106b2008-10-16 21:26:57 -07001025 struct pci_dev *us_dev;
Auke Kok9d5c8242008-01-24 02:22:38 -08001026 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
1027 unsigned long mmio_start, mmio_len;
Alexander Duyckc54106b2008-10-16 21:26:57 -07001028 int i, err, pci_using_dac, pos;
1029 u16 eeprom_data = 0, state = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001030 u16 eeprom_apme_mask = IGB_EEPROM_APME;
1031 u32 part_num;
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001032 int bars, need_ioport;
Auke Kok9d5c8242008-01-24 02:22:38 -08001033
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001034 /* do not allocate ioport bars when not needed */
1035 need_ioport = igb_is_need_ioport(pdev);
1036 if (need_ioport) {
1037 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1038 err = pci_enable_device(pdev);
1039 } else {
1040 bars = pci_select_bars(pdev, IORESOURCE_MEM);
1041 err = pci_enable_device_mem(pdev);
1042 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001043 if (err)
1044 return err;
1045
1046 pci_using_dac = 0;
1047 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
1048 if (!err) {
1049 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1050 if (!err)
1051 pci_using_dac = 1;
1052 } else {
1053 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1054 if (err) {
1055 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1056 if (err) {
1057 dev_err(&pdev->dev, "No usable DMA "
1058 "configuration, aborting\n");
1059 goto err_dma;
1060 }
1061 }
1062 }
1063
Alexander Duyckc54106b2008-10-16 21:26:57 -07001064 /* 82575 requires that the pci-e link partner disable the L0s state */
1065 switch (pdev->device) {
1066 case E1000_DEV_ID_82575EB_COPPER:
1067 case E1000_DEV_ID_82575EB_FIBER_SERDES:
1068 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1069 us_dev = pdev->bus->self;
1070 pos = pci_find_capability(us_dev, PCI_CAP_ID_EXP);
1071 if (pos) {
1072 pci_read_config_word(us_dev, pos + PCI_EXP_LNKCTL,
1073 &state);
1074 state &= ~PCIE_LINK_STATE_L0S;
1075 pci_write_config_word(us_dev, pos + PCI_EXP_LNKCTL,
1076 state);
Bjorn Helgaasac450202008-11-13 06:20:10 +00001077 dev_info(&pdev->dev,
1078 "Disabling ASPM L0s upstream switch port %s\n",
1079 pci_name(us_dev));
Alexander Duyckc54106b2008-10-16 21:26:57 -07001080 }
1081 default:
1082 break;
1083 }
1084
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001085 err = pci_request_selected_regions(pdev, bars, igb_driver_name);
Auke Kok9d5c8242008-01-24 02:22:38 -08001086 if (err)
1087 goto err_pci_reg;
1088
Jeff Kirsherea943d42008-12-11 20:34:19 -08001089 err = pci_enable_pcie_error_reporting(pdev);
1090 if (err) {
1091 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
1092 "0x%x\n", err);
1093 /* non-fatal, continue */
1094 }
Alexander Duyck40a914f2008-11-27 00:24:37 -08001095
Auke Kok9d5c8242008-01-24 02:22:38 -08001096 pci_set_master(pdev);
Auke Kokc682fc22008-04-23 11:09:34 -07001097 pci_save_state(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001098
1099 err = -ENOMEM;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001100 netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), IGB_MAX_TX_QUEUES);
Auke Kok9d5c8242008-01-24 02:22:38 -08001101 if (!netdev)
1102 goto err_alloc_etherdev;
1103
1104 SET_NETDEV_DEV(netdev, &pdev->dev);
1105
1106 pci_set_drvdata(pdev, netdev);
1107 adapter = netdev_priv(netdev);
1108 adapter->netdev = netdev;
1109 adapter->pdev = pdev;
1110 hw = &adapter->hw;
1111 hw->back = adapter;
1112 adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001113 adapter->bars = bars;
1114 adapter->need_ioport = need_ioport;
Auke Kok9d5c8242008-01-24 02:22:38 -08001115
1116 mmio_start = pci_resource_start(pdev, 0);
1117 mmio_len = pci_resource_len(pdev, 0);
1118
1119 err = -EIO;
1120 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
1121 if (!adapter->hw.hw_addr)
1122 goto err_ioremap;
1123
Stephen Hemminger2e5c6922008-11-19 22:20:44 -08001124 netdev->netdev_ops = &igb_netdev_ops;
Auke Kok9d5c8242008-01-24 02:22:38 -08001125 igb_set_ethtool_ops(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001126 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9d5c8242008-01-24 02:22:38 -08001127
1128 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1129
1130 netdev->mem_start = mmio_start;
1131 netdev->mem_end = mmio_start + mmio_len;
1132
Auke Kok9d5c8242008-01-24 02:22:38 -08001133 /* PCI config space info */
1134 hw->vendor_id = pdev->vendor;
1135 hw->device_id = pdev->device;
1136 hw->revision_id = pdev->revision;
1137 hw->subsystem_vendor_id = pdev->subsystem_vendor;
1138 hw->subsystem_device_id = pdev->subsystem_device;
1139
1140 /* setup the private structure */
1141 hw->back = adapter;
1142 /* Copy the default MAC, PHY and NVM function pointers */
1143 memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
1144 memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
1145 memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
1146 /* Initialize skew-specific constants */
1147 err = ei->get_invariants(hw);
1148 if (err)
1149 goto err_hw_init;
1150
1151 err = igb_sw_init(adapter);
1152 if (err)
1153 goto err_sw_init;
1154
1155 igb_get_bus_info_pcie(hw);
1156
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001157 /* set flags */
1158 switch (hw->mac.type) {
1159 case e1000_82576:
1160 case e1000_82575:
1161 adapter->flags |= IGB_FLAG_HAS_DCA;
1162 adapter->flags |= IGB_FLAG_NEED_CTX_IDX;
1163 break;
1164 default:
1165 break;
1166 }
1167
Auke Kok9d5c8242008-01-24 02:22:38 -08001168 hw->phy.autoneg_wait_to_complete = false;
1169 hw->mac.adaptive_ifs = true;
1170
1171 /* Copper options */
1172 if (hw->phy.media_type == e1000_media_type_copper) {
1173 hw->phy.mdix = AUTO_ALL_MODES;
1174 hw->phy.disable_polarity_correction = false;
1175 hw->phy.ms_type = e1000_ms_hw_default;
1176 }
1177
1178 if (igb_check_reset_block(hw))
1179 dev_info(&pdev->dev,
1180 "PHY reset is blocked due to SOL/IDER session.\n");
1181
1182 netdev->features = NETIF_F_SG |
1183 NETIF_F_HW_CSUM |
1184 NETIF_F_HW_VLAN_TX |
1185 NETIF_F_HW_VLAN_RX |
1186 NETIF_F_HW_VLAN_FILTER;
1187
1188 netdev->features |= NETIF_F_TSO;
Auke Kok9d5c8242008-01-24 02:22:38 -08001189 netdev->features |= NETIF_F_TSO6;
Jeff Kirsher48f29ff2008-06-05 04:06:27 -07001190
Alexander Duyckd3352522008-07-08 15:12:13 -07001191#ifdef CONFIG_IGB_LRO
1192 netdev->features |= NETIF_F_LRO;
1193#endif
1194
Jeff Kirsher48f29ff2008-06-05 04:06:27 -07001195 netdev->vlan_features |= NETIF_F_TSO;
1196 netdev->vlan_features |= NETIF_F_TSO6;
1197 netdev->vlan_features |= NETIF_F_HW_CSUM;
1198 netdev->vlan_features |= NETIF_F_SG;
1199
Auke Kok9d5c8242008-01-24 02:22:38 -08001200 if (pci_using_dac)
1201 netdev->features |= NETIF_F_HIGHDMA;
1202
1203 netdev->features |= NETIF_F_LLTX;
1204 adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw);
1205
1206 /* before reading the NVM, reset the controller to put the device in a
1207 * known good starting state */
1208 hw->mac.ops.reset_hw(hw);
1209
1210 /* make sure the NVM is good */
1211 if (igb_validate_nvm_checksum(hw) < 0) {
1212 dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
1213 err = -EIO;
1214 goto err_eeprom;
1215 }
1216
1217 /* copy the MAC address out of the NVM */
1218 if (hw->mac.ops.read_mac_addr(hw))
1219 dev_err(&pdev->dev, "NVM Read Error\n");
1220
1221 memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
1222 memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
1223
1224 if (!is_valid_ether_addr(netdev->perm_addr)) {
1225 dev_err(&pdev->dev, "Invalid MAC Address\n");
1226 err = -EIO;
1227 goto err_eeprom;
1228 }
1229
1230 init_timer(&adapter->watchdog_timer);
1231 adapter->watchdog_timer.function = &igb_watchdog;
1232 adapter->watchdog_timer.data = (unsigned long) adapter;
1233
1234 init_timer(&adapter->phy_info_timer);
1235 adapter->phy_info_timer.function = &igb_update_phy_info;
1236 adapter->phy_info_timer.data = (unsigned long) adapter;
1237
1238 INIT_WORK(&adapter->reset_task, igb_reset_task);
1239 INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
1240
1241 /* Initialize link & ring properties that are user-changeable */
1242 adapter->tx_ring->count = 256;
1243 for (i = 0; i < adapter->num_tx_queues; i++)
1244 adapter->tx_ring[i].count = adapter->tx_ring->count;
1245 adapter->rx_ring->count = 256;
1246 for (i = 0; i < adapter->num_rx_queues; i++)
1247 adapter->rx_ring[i].count = adapter->rx_ring->count;
1248
1249 adapter->fc_autoneg = true;
1250 hw->mac.autoneg = true;
1251 hw->phy.autoneg_advertised = 0x2f;
1252
1253 hw->fc.original_type = e1000_fc_default;
1254 hw->fc.type = e1000_fc_default;
1255
1256 adapter->itr_setting = 3;
1257 adapter->itr = IGB_START_ITR;
1258
1259 igb_validate_mdi_setting(hw);
1260
1261 adapter->rx_csum = 1;
1262
1263 /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
1264 * enable the ACPI Magic Packet filter
1265 */
1266
1267 if (hw->bus.func == 0 ||
1268 hw->device_id == E1000_DEV_ID_82575EB_COPPER)
1269 hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL3_PORT_A, 1,
1270 &eeprom_data);
1271
1272 if (eeprom_data & eeprom_apme_mask)
1273 adapter->eeprom_wol |= E1000_WUFC_MAG;
1274
1275 /* now that we have the eeprom settings, apply the special cases where
1276 * the eeprom may be wrong or the board simply won't support wake on
1277 * lan on a particular port */
1278 switch (pdev->device) {
1279 case E1000_DEV_ID_82575GB_QUAD_COPPER:
1280 adapter->eeprom_wol = 0;
1281 break;
1282 case E1000_DEV_ID_82575EB_FIBER_SERDES:
Alexander Duyck2d064c02008-07-08 15:10:12 -07001283 case E1000_DEV_ID_82576_FIBER:
1284 case E1000_DEV_ID_82576_SERDES:
Auke Kok9d5c8242008-01-24 02:22:38 -08001285 /* Wake events only supported on port A for dual fiber
1286 * regardless of eeprom setting */
1287 if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
1288 adapter->eeprom_wol = 0;
1289 break;
1290 }
1291
1292 /* initialize the wol settings based on the eeprom settings */
1293 adapter->wol = adapter->eeprom_wol;
\"Rafael J. Wysocki\e1b86d82008-11-07 20:30:37 +00001294 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
Auke Kok9d5c8242008-01-24 02:22:38 -08001295
1296 /* reset the hardware with the new settings */
1297 igb_reset(adapter);
1298
1299 /* let the f/w know that the h/w is now under the control of the
1300 * driver. */
1301 igb_get_hw_control(adapter);
1302
1303 /* tell the stack to leave us alone until igb_open() is called */
1304 netif_carrier_off(netdev);
David S. Millerfd2ea0a2008-07-17 01:56:23 -07001305 netif_tx_stop_all_queues(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08001306
1307 strcpy(netdev->name, "eth%d");
1308 err = register_netdev(netdev);
1309 if (err)
1310 goto err_register;
1311
Jeff Kirsher421e02f2008-10-17 11:08:31 -07001312#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001313 if ((adapter->flags & IGB_FLAG_HAS_DCA) &&
1314 (dca_add_requester(&pdev->dev) == 0)) {
1315 adapter->flags |= IGB_FLAG_DCA_ENABLED;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07001316 dev_info(&pdev->dev, "DCA enabled\n");
1317 /* Always use CB2 mode, difference is masked
1318 * in the CB driver. */
1319 wr32(E1000_DCA_CTRL, 2);
1320 igb_setup_dca(adapter);
1321 }
1322#endif
1323
Auke Kok9d5c8242008-01-24 02:22:38 -08001324 dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
1325 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07001326 dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
Auke Kok9d5c8242008-01-24 02:22:38 -08001327 netdev->name,
1328 ((hw->bus.speed == e1000_bus_speed_2500)
1329 ? "2.5Gb/s" : "unknown"),
1330 ((hw->bus.width == e1000_bus_width_pcie_x4)
1331 ? "Width x4" : (hw->bus.width == e1000_bus_width_pcie_x1)
1332 ? "Width x1" : "unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07001333 netdev->dev_addr);
Auke Kok9d5c8242008-01-24 02:22:38 -08001334
1335 igb_read_part_num(hw, &part_num);
1336 dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name,
1337 (part_num >> 8), (part_num & 0xff));
1338
1339 dev_info(&pdev->dev,
1340 "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
1341 adapter->msix_entries ? "MSI-X" :
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001342 (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
Auke Kok9d5c8242008-01-24 02:22:38 -08001343 adapter->num_rx_queues, adapter->num_tx_queues);
1344
Auke Kok9d5c8242008-01-24 02:22:38 -08001345 return 0;
1346
1347err_register:
1348 igb_release_hw_control(adapter);
1349err_eeprom:
1350 if (!igb_check_reset_block(hw))
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001351 igb_reset_phy(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001352
1353 if (hw->flash_address)
1354 iounmap(hw->flash_address);
1355
1356 igb_remove_device(hw);
Alexander Duycka88f10e2008-07-08 15:13:38 -07001357 igb_free_queues(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001358err_sw_init:
1359err_hw_init:
1360 iounmap(hw->hw_addr);
1361err_ioremap:
1362 free_netdev(netdev);
1363err_alloc_etherdev:
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001364 pci_release_selected_regions(pdev, bars);
Auke Kok9d5c8242008-01-24 02:22:38 -08001365err_pci_reg:
1366err_dma:
1367 pci_disable_device(pdev);
1368 return err;
1369}
1370
1371/**
1372 * igb_remove - Device Removal Routine
1373 * @pdev: PCI device information struct
1374 *
1375 * igb_remove is called by the PCI subsystem to alert the driver
1376 * that it should release a PCI device. The could be caused by a
1377 * Hot-Plug event, or because the driver is going to be removed from
1378 * memory.
1379 **/
1380static void __devexit igb_remove(struct pci_dev *pdev)
1381{
1382 struct net_device *netdev = pci_get_drvdata(pdev);
1383 struct igb_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher421e02f2008-10-17 11:08:31 -07001384#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -07001385 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck9280fa52008-07-08 15:14:04 -07001386#endif
Jeff Kirsherea943d42008-12-11 20:34:19 -08001387 int err;
Auke Kok9d5c8242008-01-24 02:22:38 -08001388
1389 /* flush_scheduled work may reschedule our watchdog task, so
1390 * explicitly disable watchdog tasks from being rescheduled */
1391 set_bit(__IGB_DOWN, &adapter->state);
1392 del_timer_sync(&adapter->watchdog_timer);
1393 del_timer_sync(&adapter->phy_info_timer);
1394
1395 flush_scheduled_work();
1396
Jeff Kirsher421e02f2008-10-17 11:08:31 -07001397#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001398 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
Jeb Cramerfe4506b2008-07-08 15:07:55 -07001399 dev_info(&pdev->dev, "DCA disabled\n");
1400 dca_remove_requester(&pdev->dev);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07001401 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07001402 wr32(E1000_DCA_CTRL, 1);
1403 }
1404#endif
1405
Auke Kok9d5c8242008-01-24 02:22:38 -08001406 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1407 * would have already happened in close and is redundant. */
1408 igb_release_hw_control(adapter);
1409
1410 unregister_netdev(netdev);
1411
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08001412 if (!igb_check_reset_block(&adapter->hw))
1413 igb_reset_phy(&adapter->hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001414
1415 igb_remove_device(&adapter->hw);
1416 igb_reset_interrupt_capability(adapter);
1417
Alexander Duycka88f10e2008-07-08 15:13:38 -07001418 igb_free_queues(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08001419
1420 iounmap(adapter->hw.hw_addr);
1421 if (adapter->hw.flash_address)
1422 iounmap(adapter->hw.flash_address);
Taku Izumi42bfd33a2008-06-20 12:10:30 +09001423 pci_release_selected_regions(pdev, adapter->bars);
Auke Kok9d5c8242008-01-24 02:22:38 -08001424
1425 free_netdev(netdev);
1426
Jeff Kirsherea943d42008-12-11 20:34:19 -08001427 err = pci_disable_pcie_error_reporting(pdev);
1428 if (err)
1429 dev_err(&pdev->dev,
1430 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
Alexander Duyck40a914f2008-11-27 00:24:37 -08001431
Auke Kok9d5c8242008-01-24 02:22:38 -08001432 pci_disable_device(pdev);
1433}
1434
1435/**
1436 * igb_sw_init - Initialize general software structures (struct igb_adapter)
1437 * @adapter: board private structure to initialize
1438 *
1439 * igb_sw_init initializes the Adapter private data structure.
1440 * Fields are initialized based on PCI device information and
1441 * OS network device settings (MTU size).
1442 **/
1443static int __devinit igb_sw_init(struct igb_adapter *adapter)
1444{
1445 struct e1000_hw *hw = &adapter->hw;
1446 struct net_device *netdev = adapter->netdev;
1447 struct pci_dev *pdev = adapter->pdev;
1448
1449 pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
1450
Alexander Duyck68fd9912008-11-20 00:48:10 -08001451 adapter->tx_ring_count = IGB_DEFAULT_TXD;
1452 adapter->rx_ring_count = IGB_DEFAULT_RXD;
Auke Kok9d5c8242008-01-24 02:22:38 -08001453 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1454 adapter->rx_ps_hdr_size = 0; /* disable packet split */
1455 adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
1456 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
1457
1458 /* Number of supported queues. */
1459 /* Having more queues than CPUs doesn't make sense. */
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001460 adapter->num_rx_queues = min((u32)IGB_MAX_RX_QUEUES, (u32)num_online_cpus());
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001461 adapter->num_tx_queues = min(IGB_MAX_TX_QUEUES, num_online_cpus());
Auke Kok9d5c8242008-01-24 02:22:38 -08001462
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001463 /* This call may decrease the number of queues depending on
1464 * interrupt mode. */
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 igb_set_interrupt_capability(adapter);
1466
1467 if (igb_alloc_queues(adapter)) {
1468 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
1469 return -ENOMEM;
1470 }
1471
1472 /* Explicitly disable IRQ since the NIC can be in any state. */
1473 igb_irq_disable(adapter);
1474
1475 set_bit(__IGB_DOWN, &adapter->state);
1476 return 0;
1477}
1478
1479/**
1480 * igb_open - Called when a network interface is made active
1481 * @netdev: network interface device structure
1482 *
1483 * Returns 0 on success, negative value on failure
1484 *
1485 * The open entry point is called when a network interface is made
1486 * active by the system (IFF_UP). At this point all resources needed
1487 * for transmit and receive operations are allocated, the interrupt
1488 * handler is registered with the OS, the watchdog timer is started,
1489 * and the stack is notified that the interface is ready.
1490 **/
1491static int igb_open(struct net_device *netdev)
1492{
1493 struct igb_adapter *adapter = netdev_priv(netdev);
1494 struct e1000_hw *hw = &adapter->hw;
1495 int err;
1496 int i;
1497
1498 /* disallow open during test */
1499 if (test_bit(__IGB_TESTING, &adapter->state))
1500 return -EBUSY;
1501
1502 /* allocate transmit descriptors */
1503 err = igb_setup_all_tx_resources(adapter);
1504 if (err)
1505 goto err_setup_tx;
1506
1507 /* allocate receive descriptors */
1508 err = igb_setup_all_rx_resources(adapter);
1509 if (err)
1510 goto err_setup_rx;
1511
1512 /* e1000_power_up_phy(adapter); */
1513
1514 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
1515 if ((adapter->hw.mng_cookie.status &
1516 E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
1517 igb_update_mng_vlan(adapter);
1518
1519 /* before we allocate an interrupt, we must be ready to handle it.
1520 * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
1521 * as soon as we call pci_request_irq, so we have to setup our
1522 * clean_rx handler before we do so. */
1523 igb_configure(adapter);
1524
1525 err = igb_request_irq(adapter);
1526 if (err)
1527 goto err_req_irq;
1528
1529 /* From here on the code is the same as igb_up() */
1530 clear_bit(__IGB_DOWN, &adapter->state);
1531
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001532 for (i = 0; i < adapter->num_rx_queues; i++)
1533 napi_enable(&adapter->rx_ring[i].napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08001534
1535 /* Clear any pending interrupts. */
1536 rd32(E1000_ICR);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07001537
1538 igb_irq_enable(adapter);
1539
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07001540 netif_tx_start_all_queues(netdev);
1541
Auke Kok9d5c8242008-01-24 02:22:38 -08001542 /* Fire a link status change interrupt to start the watchdog. */
1543 wr32(E1000_ICS, E1000_ICS_LSC);
1544
1545 return 0;
1546
1547err_req_irq:
1548 igb_release_hw_control(adapter);
1549 /* e1000_power_down_phy(adapter); */
1550 igb_free_all_rx_resources(adapter);
1551err_setup_rx:
1552 igb_free_all_tx_resources(adapter);
1553err_setup_tx:
1554 igb_reset(adapter);
1555
1556 return err;
1557}
1558
1559/**
1560 * igb_close - Disables a network interface
1561 * @netdev: network interface device structure
1562 *
1563 * Returns 0, this is not allowed to fail
1564 *
1565 * The close entry point is called when an interface is de-activated
1566 * by the OS. The hardware is still under the driver's control, but
1567 * needs to be disabled. A global MAC reset is issued to stop the
1568 * hardware, and all transmit and receive resources are freed.
1569 **/
1570static int igb_close(struct net_device *netdev)
1571{
1572 struct igb_adapter *adapter = netdev_priv(netdev);
1573
1574 WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
1575 igb_down(adapter);
1576
1577 igb_free_irq(adapter);
1578
1579 igb_free_all_tx_resources(adapter);
1580 igb_free_all_rx_resources(adapter);
1581
1582 /* kill manageability vlan ID if supported, but not if a vlan with
1583 * the same ID is registered on the host OS (let 8021q kill it) */
1584 if ((adapter->hw.mng_cookie.status &
1585 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
1586 !(adapter->vlgrp &&
1587 vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
1588 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
1589
1590 return 0;
1591}
1592
1593/**
1594 * igb_setup_tx_resources - allocate Tx resources (Descriptors)
1595 * @adapter: board private structure
1596 * @tx_ring: tx descriptor ring (for a specific queue) to setup
1597 *
1598 * Return 0 on success, negative on failure
1599 **/
1600
1601int igb_setup_tx_resources(struct igb_adapter *adapter,
1602 struct igb_ring *tx_ring)
1603{
1604 struct pci_dev *pdev = adapter->pdev;
1605 int size;
1606
1607 size = sizeof(struct igb_buffer) * tx_ring->count;
1608 tx_ring->buffer_info = vmalloc(size);
1609 if (!tx_ring->buffer_info)
1610 goto err;
1611 memset(tx_ring->buffer_info, 0, size);
1612
1613 /* round up to nearest 4K */
Alexander Duyck0e014cb2008-12-26 01:33:18 -08001614 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
Auke Kok9d5c8242008-01-24 02:22:38 -08001615 tx_ring->size = ALIGN(tx_ring->size, 4096);
1616
1617 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
1618 &tx_ring->dma);
1619
1620 if (!tx_ring->desc)
1621 goto err;
1622
1623 tx_ring->adapter = adapter;
1624 tx_ring->next_to_use = 0;
1625 tx_ring->next_to_clean = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001626 return 0;
1627
1628err:
1629 vfree(tx_ring->buffer_info);
1630 dev_err(&adapter->pdev->dev,
1631 "Unable to allocate memory for the transmit descriptor ring\n");
1632 return -ENOMEM;
1633}
1634
1635/**
1636 * igb_setup_all_tx_resources - wrapper to allocate Tx resources
1637 * (Descriptors) for all queues
1638 * @adapter: board private structure
1639 *
1640 * Return 0 on success, negative on failure
1641 **/
1642static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
1643{
1644 int i, err = 0;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001645 int r_idx;
Auke Kok9d5c8242008-01-24 02:22:38 -08001646
1647 for (i = 0; i < adapter->num_tx_queues; i++) {
1648 err = igb_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1649 if (err) {
1650 dev_err(&adapter->pdev->dev,
1651 "Allocation for Tx Queue %u failed\n", i);
1652 for (i--; i >= 0; i--)
Mitch Williams3b644cf2008-06-27 10:59:48 -07001653 igb_free_tx_resources(&adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08001654 break;
1655 }
1656 }
1657
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07001658 for (i = 0; i < IGB_MAX_TX_QUEUES; i++) {
1659 r_idx = i % adapter->num_tx_queues;
1660 adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx];
1661 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001662 return err;
1663}
1664
1665/**
1666 * igb_configure_tx - Configure transmit Unit after Reset
1667 * @adapter: board private structure
1668 *
1669 * Configure the Tx unit of the MAC after a reset.
1670 **/
1671static void igb_configure_tx(struct igb_adapter *adapter)
1672{
Alexander Duyck0e014cb2008-12-26 01:33:18 -08001673 u64 tdba;
Auke Kok9d5c8242008-01-24 02:22:38 -08001674 struct e1000_hw *hw = &adapter->hw;
1675 u32 tctl;
1676 u32 txdctl, txctrl;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001677 int i, j;
Auke Kok9d5c8242008-01-24 02:22:38 -08001678
1679 for (i = 0; i < adapter->num_tx_queues; i++) {
1680 struct igb_ring *ring = &(adapter->tx_ring[i]);
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001681 j = ring->reg_idx;
1682 wr32(E1000_TDLEN(j),
Auke Kok9d5c8242008-01-24 02:22:38 -08001683 ring->count * sizeof(struct e1000_tx_desc));
1684 tdba = ring->dma;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001685 wr32(E1000_TDBAL(j),
Auke Kok9d5c8242008-01-24 02:22:38 -08001686 tdba & 0x00000000ffffffffULL);
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001687 wr32(E1000_TDBAH(j), tdba >> 32);
Auke Kok9d5c8242008-01-24 02:22:38 -08001688
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001689 ring->head = E1000_TDH(j);
1690 ring->tail = E1000_TDT(j);
Auke Kok9d5c8242008-01-24 02:22:38 -08001691 writel(0, hw->hw_addr + ring->tail);
1692 writel(0, hw->hw_addr + ring->head);
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001693 txdctl = rd32(E1000_TXDCTL(j));
Auke Kok9d5c8242008-01-24 02:22:38 -08001694 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001695 wr32(E1000_TXDCTL(j), txdctl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001696
1697 /* Turn off Relaxed Ordering on head write-backs. The
1698 * writebacks MUST be delivered in order or it will
1699 * completely screw up our bookeeping.
1700 */
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001701 txctrl = rd32(E1000_DCA_TXCTRL(j));
Auke Kok9d5c8242008-01-24 02:22:38 -08001702 txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001703 wr32(E1000_DCA_TXCTRL(j), txctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001704 }
1705
1706
1707
1708 /* Use the default values for the Tx Inter Packet Gap (IPG) timer */
1709
1710 /* Program the Transmit Control Register */
1711
1712 tctl = rd32(E1000_TCTL);
1713 tctl &= ~E1000_TCTL_CT;
1714 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1715 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1716
1717 igb_config_collision_dist(hw);
1718
1719 /* Setup Transmit Descriptor Settings for eop descriptor */
1720 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS;
1721
1722 /* Enable transmits */
1723 tctl |= E1000_TCTL_EN;
1724
1725 wr32(E1000_TCTL, tctl);
1726}
1727
1728/**
1729 * igb_setup_rx_resources - allocate Rx resources (Descriptors)
1730 * @adapter: board private structure
1731 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1732 *
1733 * Returns 0 on success, negative on failure
1734 **/
1735
1736int igb_setup_rx_resources(struct igb_adapter *adapter,
1737 struct igb_ring *rx_ring)
1738{
1739 struct pci_dev *pdev = adapter->pdev;
1740 int size, desc_len;
1741
Alexander Duyckd3352522008-07-08 15:12:13 -07001742#ifdef CONFIG_IGB_LRO
1743 size = sizeof(struct net_lro_desc) * MAX_LRO_DESCRIPTORS;
1744 rx_ring->lro_mgr.lro_arr = vmalloc(size);
1745 if (!rx_ring->lro_mgr.lro_arr)
1746 goto err;
1747 memset(rx_ring->lro_mgr.lro_arr, 0, size);
1748#endif
1749
Auke Kok9d5c8242008-01-24 02:22:38 -08001750 size = sizeof(struct igb_buffer) * rx_ring->count;
1751 rx_ring->buffer_info = vmalloc(size);
1752 if (!rx_ring->buffer_info)
1753 goto err;
1754 memset(rx_ring->buffer_info, 0, size);
1755
1756 desc_len = sizeof(union e1000_adv_rx_desc);
1757
1758 /* Round up to nearest 4K */
1759 rx_ring->size = rx_ring->count * desc_len;
1760 rx_ring->size = ALIGN(rx_ring->size, 4096);
1761
1762 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
1763 &rx_ring->dma);
1764
1765 if (!rx_ring->desc)
1766 goto err;
1767
1768 rx_ring->next_to_clean = 0;
1769 rx_ring->next_to_use = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001770
1771 rx_ring->adapter = adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08001772
1773 return 0;
1774
1775err:
Alexander Duyckd3352522008-07-08 15:12:13 -07001776#ifdef CONFIG_IGB_LRO
1777 vfree(rx_ring->lro_mgr.lro_arr);
1778 rx_ring->lro_mgr.lro_arr = NULL;
1779#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08001780 vfree(rx_ring->buffer_info);
1781 dev_err(&adapter->pdev->dev, "Unable to allocate memory for "
1782 "the receive descriptor ring\n");
1783 return -ENOMEM;
1784}
1785
1786/**
1787 * igb_setup_all_rx_resources - wrapper to allocate Rx resources
1788 * (Descriptors) for all queues
1789 * @adapter: board private structure
1790 *
1791 * Return 0 on success, negative on failure
1792 **/
1793static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
1794{
1795 int i, err = 0;
1796
1797 for (i = 0; i < adapter->num_rx_queues; i++) {
1798 err = igb_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1799 if (err) {
1800 dev_err(&adapter->pdev->dev,
1801 "Allocation for Rx Queue %u failed\n", i);
1802 for (i--; i >= 0; i--)
Mitch Williams3b644cf2008-06-27 10:59:48 -07001803 igb_free_rx_resources(&adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08001804 break;
1805 }
1806 }
1807
1808 return err;
1809}
1810
1811/**
1812 * igb_setup_rctl - configure the receive control registers
1813 * @adapter: Board private structure
1814 **/
1815static void igb_setup_rctl(struct igb_adapter *adapter)
1816{
1817 struct e1000_hw *hw = &adapter->hw;
1818 u32 rctl;
1819 u32 srrctl = 0;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001820 int i, j;
Auke Kok9d5c8242008-01-24 02:22:38 -08001821
1822 rctl = rd32(E1000_RCTL);
1823
1824 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
Alexander Duyck69d728b2008-11-25 01:04:03 -08001825 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001826
Alexander Duyck69d728b2008-11-25 01:04:03 -08001827 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
Auke Kok9d5c8242008-01-24 02:22:38 -08001828 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1829
Auke Kok87cb7e82008-07-08 15:08:29 -07001830 /*
1831 * enable stripping of CRC. It's unlikely this will break BMC
1832 * redirection as it did with e1000. Newer features require
1833 * that the HW strips the CRC.
Auke Kok9d5c8242008-01-24 02:22:38 -08001834 */
Auke Kok87cb7e82008-07-08 15:08:29 -07001835 rctl |= E1000_RCTL_SECRC;
Auke Kok9d5c8242008-01-24 02:22:38 -08001836
Alexander Duyck9b07f3d32008-11-25 01:03:26 -08001837 /*
1838 * disable store bad packets, long packet enable, and clear size bits.
1839 */
1840 rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_LPE | E1000_RCTL_SZ_256);
Auke Kok9d5c8242008-01-24 02:22:38 -08001841
Alexander Duyckb4557be2008-12-10 01:08:59 -08001842 if (adapter->netdev->mtu > ETH_DATA_LEN)
Alexander Duyck9b07f3d32008-11-25 01:03:26 -08001843 rctl |= E1000_RCTL_LPE;
Alexander Duyckb4557be2008-12-10 01:08:59 -08001844
1845 /* Setup buffer sizes */
1846 switch (adapter->rx_buffer_len) {
1847 case IGB_RXBUFFER_256:
1848 rctl |= E1000_RCTL_SZ_256;
1849 break;
1850 case IGB_RXBUFFER_512:
1851 rctl |= E1000_RCTL_SZ_512;
1852 break;
1853 default:
1854 srrctl = ALIGN(adapter->rx_buffer_len, 1024)
1855 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
1856 break;
Auke Kok9d5c8242008-01-24 02:22:38 -08001857 }
1858
1859 /* 82575 and greater support packet-split where the protocol
1860 * header is placed in skb->data and the packet data is
1861 * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
1862 * In the case of a non-split, skb->data is linearly filled,
1863 * followed by the page buffers. Therefore, skb->data is
1864 * sized to hold the largest protocol header.
1865 */
1866 /* allocations using alloc_page take too long for regular MTU
1867 * so only enable packet split for jumbo frames */
1868 if (rctl & E1000_RCTL_LPE) {
1869 adapter->rx_ps_hdr_size = IGB_RXBUFFER_128;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07001870 srrctl |= adapter->rx_ps_hdr_size <<
Auke Kok9d5c8242008-01-24 02:22:38 -08001871 E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
Auke Kok9d5c8242008-01-24 02:22:38 -08001872 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1873 } else {
1874 adapter->rx_ps_hdr_size = 0;
1875 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
1876 }
1877
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001878 for (i = 0; i < adapter->num_rx_queues; i++) {
1879 j = adapter->rx_ring[i].reg_idx;
1880 wr32(E1000_SRRCTL(j), srrctl);
1881 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001882
1883 wr32(E1000_RCTL, rctl);
1884}
1885
1886/**
1887 * igb_configure_rx - Configure receive Unit after Reset
1888 * @adapter: board private structure
1889 *
1890 * Configure the Rx unit of the MAC after a reset.
1891 **/
1892static void igb_configure_rx(struct igb_adapter *adapter)
1893{
1894 u64 rdba;
1895 struct e1000_hw *hw = &adapter->hw;
1896 u32 rctl, rxcsum;
1897 u32 rxdctl;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001898 int i, j;
Auke Kok9d5c8242008-01-24 02:22:38 -08001899
1900 /* disable receives while setting up the descriptors */
1901 rctl = rd32(E1000_RCTL);
1902 wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
1903 wrfl();
1904 mdelay(10);
1905
1906 if (adapter->itr_setting > 3)
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07001907 wr32(E1000_ITR, adapter->itr);
Auke Kok9d5c8242008-01-24 02:22:38 -08001908
1909 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1910 * the Base and Length of the Rx Descriptor Ring */
1911 for (i = 0; i < adapter->num_rx_queues; i++) {
1912 struct igb_ring *ring = &(adapter->rx_ring[i]);
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001913 j = ring->reg_idx;
Auke Kok9d5c8242008-01-24 02:22:38 -08001914 rdba = ring->dma;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001915 wr32(E1000_RDBAL(j),
Auke Kok9d5c8242008-01-24 02:22:38 -08001916 rdba & 0x00000000ffffffffULL);
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001917 wr32(E1000_RDBAH(j), rdba >> 32);
1918 wr32(E1000_RDLEN(j),
Auke Kok9d5c8242008-01-24 02:22:38 -08001919 ring->count * sizeof(union e1000_adv_rx_desc));
1920
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001921 ring->head = E1000_RDH(j);
1922 ring->tail = E1000_RDT(j);
Auke Kok9d5c8242008-01-24 02:22:38 -08001923 writel(0, hw->hw_addr + ring->tail);
1924 writel(0, hw->hw_addr + ring->head);
1925
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001926 rxdctl = rd32(E1000_RXDCTL(j));
Auke Kok9d5c8242008-01-24 02:22:38 -08001927 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
1928 rxdctl &= 0xFFF00000;
1929 rxdctl |= IGB_RX_PTHRESH;
1930 rxdctl |= IGB_RX_HTHRESH << 8;
1931 rxdctl |= IGB_RX_WTHRESH << 16;
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001932 wr32(E1000_RXDCTL(j), rxdctl);
Alexander Duyckd3352522008-07-08 15:12:13 -07001933#ifdef CONFIG_IGB_LRO
1934 /* Intitial LRO Settings */
1935 ring->lro_mgr.max_aggr = MAX_LRO_AGGR;
1936 ring->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1937 ring->lro_mgr.get_skb_header = igb_get_skb_hdr;
1938 ring->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1939 ring->lro_mgr.dev = adapter->netdev;
1940 ring->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1941 ring->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1942#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08001943 }
1944
1945 if (adapter->num_rx_queues > 1) {
1946 u32 random[10];
1947 u32 mrqc;
1948 u32 j, shift;
1949 union e1000_reta {
1950 u32 dword;
1951 u8 bytes[4];
1952 } reta;
1953
1954 get_random_bytes(&random[0], 40);
1955
Alexander Duyck2d064c02008-07-08 15:10:12 -07001956 if (hw->mac.type >= e1000_82576)
1957 shift = 0;
1958 else
1959 shift = 6;
Auke Kok9d5c8242008-01-24 02:22:38 -08001960 for (j = 0; j < (32 * 4); j++) {
1961 reta.bytes[j & 3] =
Alexander Duyck26bc19e2008-12-26 01:34:11 -08001962 adapter->rx_ring[(j % adapter->num_rx_queues)].reg_idx << shift;
Auke Kok9d5c8242008-01-24 02:22:38 -08001963 if ((j & 3) == 3)
1964 writel(reta.dword,
1965 hw->hw_addr + E1000_RETA(0) + (j & ~3));
1966 }
1967 mrqc = E1000_MRQC_ENABLE_RSS_4Q;
1968
1969 /* Fill out hash function seeds */
1970 for (j = 0; j < 10; j++)
1971 array_wr32(E1000_RSSRK(0), j, random[j]);
1972
1973 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
1974 E1000_MRQC_RSS_FIELD_IPV4_TCP);
1975 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 |
1976 E1000_MRQC_RSS_FIELD_IPV6_TCP);
1977 mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP |
1978 E1000_MRQC_RSS_FIELD_IPV6_UDP);
1979 mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX |
1980 E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
1981
1982
1983 wr32(E1000_MRQC, mrqc);
1984
1985 /* Multiqueue and raw packet checksumming are mutually
1986 * exclusive. Note that this not the same as TCP/IP
1987 * checksumming, which works fine. */
1988 rxcsum = rd32(E1000_RXCSUM);
1989 rxcsum |= E1000_RXCSUM_PCSD;
1990 wr32(E1000_RXCSUM, rxcsum);
1991 } else {
1992 /* Enable Receive Checksum Offload for TCP and UDP */
1993 rxcsum = rd32(E1000_RXCSUM);
1994 if (adapter->rx_csum) {
1995 rxcsum |= E1000_RXCSUM_TUOFL;
1996
1997 /* Enable IPv4 payload checksum for UDP fragments
1998 * Must be used in conjunction with packet-split. */
1999 if (adapter->rx_ps_hdr_size)
2000 rxcsum |= E1000_RXCSUM_IPPCSE;
2001 } else {
2002 rxcsum &= ~E1000_RXCSUM_TUOFL;
2003 /* don't need to clear IPPCSE as it defaults to 0 */
2004 }
2005 wr32(E1000_RXCSUM, rxcsum);
2006 }
2007
2008 if (adapter->vlgrp)
2009 wr32(E1000_RLPML,
2010 adapter->max_frame_size + VLAN_TAG_SIZE);
2011 else
2012 wr32(E1000_RLPML, adapter->max_frame_size);
2013
2014 /* Enable Receives */
2015 wr32(E1000_RCTL, rctl);
2016}
2017
2018/**
2019 * igb_free_tx_resources - Free Tx Resources per Queue
Auke Kok9d5c8242008-01-24 02:22:38 -08002020 * @tx_ring: Tx descriptor ring for a specific queue
2021 *
2022 * Free all transmit software resources
2023 **/
Alexander Duyck68fd9912008-11-20 00:48:10 -08002024void igb_free_tx_resources(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002025{
Mitch Williams3b644cf2008-06-27 10:59:48 -07002026 struct pci_dev *pdev = tx_ring->adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002027
Mitch Williams3b644cf2008-06-27 10:59:48 -07002028 igb_clean_tx_ring(tx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08002029
2030 vfree(tx_ring->buffer_info);
2031 tx_ring->buffer_info = NULL;
2032
2033 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
2034
2035 tx_ring->desc = NULL;
2036}
2037
2038/**
2039 * igb_free_all_tx_resources - Free Tx Resources for All Queues
2040 * @adapter: board private structure
2041 *
2042 * Free all transmit software resources
2043 **/
2044static void igb_free_all_tx_resources(struct igb_adapter *adapter)
2045{
2046 int i;
2047
2048 for (i = 0; i < adapter->num_tx_queues; i++)
Mitch Williams3b644cf2008-06-27 10:59:48 -07002049 igb_free_tx_resources(&adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002050}
2051
2052static void igb_unmap_and_free_tx_resource(struct igb_adapter *adapter,
2053 struct igb_buffer *buffer_info)
2054{
2055 if (buffer_info->dma) {
2056 pci_unmap_page(adapter->pdev,
2057 buffer_info->dma,
2058 buffer_info->length,
2059 PCI_DMA_TODEVICE);
2060 buffer_info->dma = 0;
2061 }
2062 if (buffer_info->skb) {
2063 dev_kfree_skb_any(buffer_info->skb);
2064 buffer_info->skb = NULL;
2065 }
2066 buffer_info->time_stamp = 0;
2067 /* buffer_info must be completely set up in the transmit path */
2068}
2069
2070/**
2071 * igb_clean_tx_ring - Free Tx Buffers
Auke Kok9d5c8242008-01-24 02:22:38 -08002072 * @tx_ring: ring to be cleaned
2073 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07002074static void igb_clean_tx_ring(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002075{
Mitch Williams3b644cf2008-06-27 10:59:48 -07002076 struct igb_adapter *adapter = tx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08002077 struct igb_buffer *buffer_info;
2078 unsigned long size;
2079 unsigned int i;
2080
2081 if (!tx_ring->buffer_info)
2082 return;
2083 /* Free all the Tx ring sk_buffs */
2084
2085 for (i = 0; i < tx_ring->count; i++) {
2086 buffer_info = &tx_ring->buffer_info[i];
2087 igb_unmap_and_free_tx_resource(adapter, buffer_info);
2088 }
2089
2090 size = sizeof(struct igb_buffer) * tx_ring->count;
2091 memset(tx_ring->buffer_info, 0, size);
2092
2093 /* Zero out the descriptor ring */
2094
2095 memset(tx_ring->desc, 0, tx_ring->size);
2096
2097 tx_ring->next_to_use = 0;
2098 tx_ring->next_to_clean = 0;
2099
2100 writel(0, adapter->hw.hw_addr + tx_ring->head);
2101 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2102}
2103
2104/**
2105 * igb_clean_all_tx_rings - Free Tx Buffers for all queues
2106 * @adapter: board private structure
2107 **/
2108static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
2109{
2110 int i;
2111
2112 for (i = 0; i < adapter->num_tx_queues; i++)
Mitch Williams3b644cf2008-06-27 10:59:48 -07002113 igb_clean_tx_ring(&adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002114}
2115
2116/**
2117 * igb_free_rx_resources - Free Rx Resources
Auke Kok9d5c8242008-01-24 02:22:38 -08002118 * @rx_ring: ring to clean the resources from
2119 *
2120 * Free all receive software resources
2121 **/
Alexander Duyck68fd9912008-11-20 00:48:10 -08002122void igb_free_rx_resources(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002123{
Mitch Williams3b644cf2008-06-27 10:59:48 -07002124 struct pci_dev *pdev = rx_ring->adapter->pdev;
Auke Kok9d5c8242008-01-24 02:22:38 -08002125
Mitch Williams3b644cf2008-06-27 10:59:48 -07002126 igb_clean_rx_ring(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08002127
2128 vfree(rx_ring->buffer_info);
2129 rx_ring->buffer_info = NULL;
2130
Alexander Duyckd3352522008-07-08 15:12:13 -07002131#ifdef CONFIG_IGB_LRO
2132 vfree(rx_ring->lro_mgr.lro_arr);
2133 rx_ring->lro_mgr.lro_arr = NULL;
2134#endif
2135
Auke Kok9d5c8242008-01-24 02:22:38 -08002136 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
2137
2138 rx_ring->desc = NULL;
2139}
2140
2141/**
2142 * igb_free_all_rx_resources - Free Rx Resources for All Queues
2143 * @adapter: board private structure
2144 *
2145 * Free all receive software resources
2146 **/
2147static void igb_free_all_rx_resources(struct igb_adapter *adapter)
2148{
2149 int i;
2150
2151 for (i = 0; i < adapter->num_rx_queues; i++)
Mitch Williams3b644cf2008-06-27 10:59:48 -07002152 igb_free_rx_resources(&adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002153}
2154
2155/**
2156 * igb_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9d5c8242008-01-24 02:22:38 -08002157 * @rx_ring: ring to free buffers from
2158 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07002159static void igb_clean_rx_ring(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002160{
Mitch Williams3b644cf2008-06-27 10:59:48 -07002161 struct igb_adapter *adapter = rx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08002162 struct igb_buffer *buffer_info;
2163 struct pci_dev *pdev = adapter->pdev;
2164 unsigned long size;
2165 unsigned int i;
2166
2167 if (!rx_ring->buffer_info)
2168 return;
2169 /* Free all the Rx ring sk_buffs */
2170 for (i = 0; i < rx_ring->count; i++) {
2171 buffer_info = &rx_ring->buffer_info[i];
2172 if (buffer_info->dma) {
2173 if (adapter->rx_ps_hdr_size)
2174 pci_unmap_single(pdev, buffer_info->dma,
2175 adapter->rx_ps_hdr_size,
2176 PCI_DMA_FROMDEVICE);
2177 else
2178 pci_unmap_single(pdev, buffer_info->dma,
2179 adapter->rx_buffer_len,
2180 PCI_DMA_FROMDEVICE);
2181 buffer_info->dma = 0;
2182 }
2183
2184 if (buffer_info->skb) {
2185 dev_kfree_skb(buffer_info->skb);
2186 buffer_info->skb = NULL;
2187 }
2188 if (buffer_info->page) {
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07002189 if (buffer_info->page_dma)
2190 pci_unmap_page(pdev, buffer_info->page_dma,
2191 PAGE_SIZE / 2,
2192 PCI_DMA_FROMDEVICE);
Auke Kok9d5c8242008-01-24 02:22:38 -08002193 put_page(buffer_info->page);
2194 buffer_info->page = NULL;
2195 buffer_info->page_dma = 0;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07002196 buffer_info->page_offset = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002197 }
2198 }
2199
Auke Kok9d5c8242008-01-24 02:22:38 -08002200 size = sizeof(struct igb_buffer) * rx_ring->count;
2201 memset(rx_ring->buffer_info, 0, size);
2202
2203 /* Zero out the descriptor ring */
2204 memset(rx_ring->desc, 0, rx_ring->size);
2205
2206 rx_ring->next_to_clean = 0;
2207 rx_ring->next_to_use = 0;
2208
2209 writel(0, adapter->hw.hw_addr + rx_ring->head);
2210 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2211}
2212
2213/**
2214 * igb_clean_all_rx_rings - Free Rx Buffers for all queues
2215 * @adapter: board private structure
2216 **/
2217static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
2218{
2219 int i;
2220
2221 for (i = 0; i < adapter->num_rx_queues; i++)
Mitch Williams3b644cf2008-06-27 10:59:48 -07002222 igb_clean_rx_ring(&adapter->rx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08002223}
2224
2225/**
2226 * igb_set_mac - Change the Ethernet Address of the NIC
2227 * @netdev: network interface device structure
2228 * @p: pointer to an address structure
2229 *
2230 * Returns 0 on success, negative on failure
2231 **/
2232static int igb_set_mac(struct net_device *netdev, void *p)
2233{
2234 struct igb_adapter *adapter = netdev_priv(netdev);
2235 struct sockaddr *addr = p;
2236
2237 if (!is_valid_ether_addr(addr->sa_data))
2238 return -EADDRNOTAVAIL;
2239
2240 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2241 memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
2242
2243 adapter->hw.mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
2244
2245 return 0;
2246}
2247
2248/**
2249 * igb_set_multi - Multicast and Promiscuous mode set
2250 * @netdev: network interface device structure
2251 *
2252 * The set_multi entry point is called whenever the multicast address
2253 * list or the network interface flags are updated. This routine is
2254 * responsible for configuring the hardware for proper multicast,
2255 * promiscuous mode, and all-multi behavior.
2256 **/
2257static void igb_set_multi(struct net_device *netdev)
2258{
2259 struct igb_adapter *adapter = netdev_priv(netdev);
2260 struct e1000_hw *hw = &adapter->hw;
2261 struct e1000_mac_info *mac = &hw->mac;
2262 struct dev_mc_list *mc_ptr;
2263 u8 *mta_list;
2264 u32 rctl;
2265 int i;
2266
2267 /* Check for Promiscuous and All Multicast modes */
2268
2269 rctl = rd32(E1000_RCTL);
2270
Patrick McHardy746b9f02008-07-16 20:15:45 -07002271 if (netdev->flags & IFF_PROMISC) {
Auke Kok9d5c8242008-01-24 02:22:38 -08002272 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy746b9f02008-07-16 20:15:45 -07002273 rctl &= ~E1000_RCTL_VFE;
2274 } else {
2275 if (netdev->flags & IFF_ALLMULTI) {
2276 rctl |= E1000_RCTL_MPE;
2277 rctl &= ~E1000_RCTL_UPE;
2278 } else
2279 rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
Patrick McHardy78ed11a2008-07-16 20:16:14 -07002280 rctl |= E1000_RCTL_VFE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07002281 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002282 wr32(E1000_RCTL, rctl);
2283
2284 if (!netdev->mc_count) {
2285 /* nothing to program, so clear mc list */
Alexander Duyck2d064c02008-07-08 15:10:12 -07002286 igb_update_mc_addr_list_82575(hw, NULL, 0, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -08002287 mac->rar_entry_count);
2288 return;
2289 }
2290
2291 mta_list = kzalloc(netdev->mc_count * 6, GFP_ATOMIC);
2292 if (!mta_list)
2293 return;
2294
2295 /* The shared function expects a packed array of only addresses. */
2296 mc_ptr = netdev->mc_list;
2297
2298 for (i = 0; i < netdev->mc_count; i++) {
2299 if (!mc_ptr)
2300 break;
2301 memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
2302 mc_ptr = mc_ptr->next;
2303 }
Alexander Duyck2d064c02008-07-08 15:10:12 -07002304 igb_update_mc_addr_list_82575(hw, mta_list, i, 1,
2305 mac->rar_entry_count);
Auke Kok9d5c8242008-01-24 02:22:38 -08002306 kfree(mta_list);
2307}
2308
2309/* Need to wait a few seconds after link up to get diagnostic information from
2310 * the phy */
2311static void igb_update_phy_info(unsigned long data)
2312{
2313 struct igb_adapter *adapter = (struct igb_adapter *) data;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08002314 igb_get_phy_info(&adapter->hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08002315}
2316
2317/**
2318 * igb_watchdog - Timer Call-back
2319 * @data: pointer to adapter cast into an unsigned long
2320 **/
2321static void igb_watchdog(unsigned long data)
2322{
2323 struct igb_adapter *adapter = (struct igb_adapter *)data;
2324 /* Do the rest outside of interrupt context */
2325 schedule_work(&adapter->watchdog_task);
2326}
2327
2328static void igb_watchdog_task(struct work_struct *work)
2329{
2330 struct igb_adapter *adapter = container_of(work,
2331 struct igb_adapter, watchdog_task);
2332 struct e1000_hw *hw = &adapter->hw;
2333
2334 struct net_device *netdev = adapter->netdev;
2335 struct igb_ring *tx_ring = adapter->tx_ring;
2336 struct e1000_mac_info *mac = &adapter->hw.mac;
2337 u32 link;
Alexander Duyck7a6ea552008-08-26 04:25:03 -07002338 u32 eics = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002339 s32 ret_val;
Alexander Duyck7a6ea552008-08-26 04:25:03 -07002340 int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002341
2342 if ((netif_carrier_ok(netdev)) &&
2343 (rd32(E1000_STATUS) & E1000_STATUS_LU))
2344 goto link_up;
2345
2346 ret_val = hw->mac.ops.check_for_link(&adapter->hw);
2347 if ((ret_val == E1000_ERR_PHY) &&
2348 (hw->phy.type == e1000_phy_igp_3) &&
2349 (rd32(E1000_CTRL) &
2350 E1000_PHY_CTRL_GBE_DISABLE))
2351 dev_info(&adapter->pdev->dev,
2352 "Gigabit has been disabled, downgrading speed\n");
2353
2354 if ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
2355 !(rd32(E1000_TXCW) & E1000_TXCW_ANE))
2356 link = mac->serdes_has_link;
2357 else
2358 link = rd32(E1000_STATUS) &
2359 E1000_STATUS_LU;
2360
2361 if (link) {
2362 if (!netif_carrier_ok(netdev)) {
2363 u32 ctrl;
2364 hw->mac.ops.get_speed_and_duplex(&adapter->hw,
2365 &adapter->link_speed,
2366 &adapter->link_duplex);
2367
2368 ctrl = rd32(E1000_CTRL);
Alexander Duyck527d47c2008-11-27 00:21:39 -08002369 /* Links status message must follow this format */
2370 printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
Auke Kok9d5c8242008-01-24 02:22:38 -08002371 "Flow Control: %s\n",
Alexander Duyck527d47c2008-11-27 00:21:39 -08002372 netdev->name,
Auke Kok9d5c8242008-01-24 02:22:38 -08002373 adapter->link_speed,
2374 adapter->link_duplex == FULL_DUPLEX ?
2375 "Full Duplex" : "Half Duplex",
2376 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2377 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2378 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2379 E1000_CTRL_TFCE) ? "TX" : "None")));
2380
2381 /* tweak tx_queue_len according to speed/duplex and
2382 * adjust the timeout factor */
2383 netdev->tx_queue_len = adapter->tx_queue_len;
2384 adapter->tx_timeout_factor = 1;
2385 switch (adapter->link_speed) {
2386 case SPEED_10:
2387 netdev->tx_queue_len = 10;
2388 adapter->tx_timeout_factor = 14;
2389 break;
2390 case SPEED_100:
2391 netdev->tx_queue_len = 100;
2392 /* maybe add some timeout factor ? */
2393 break;
2394 }
2395
2396 netif_carrier_on(netdev);
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002397 netif_tx_wake_all_queues(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002398
2399 if (!test_bit(__IGB_DOWN, &adapter->state))
2400 mod_timer(&adapter->phy_info_timer,
2401 round_jiffies(jiffies + 2 * HZ));
2402 }
2403 } else {
2404 if (netif_carrier_ok(netdev)) {
2405 adapter->link_speed = 0;
2406 adapter->link_duplex = 0;
Alexander Duyck527d47c2008-11-27 00:21:39 -08002407 /* Links status message must follow this format */
2408 printk(KERN_INFO "igb: %s NIC Link is Down\n",
2409 netdev->name);
Auke Kok9d5c8242008-01-24 02:22:38 -08002410 netif_carrier_off(netdev);
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002411 netif_tx_stop_all_queues(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08002412 if (!test_bit(__IGB_DOWN, &adapter->state))
2413 mod_timer(&adapter->phy_info_timer,
2414 round_jiffies(jiffies + 2 * HZ));
2415 }
2416 }
2417
2418link_up:
2419 igb_update_stats(adapter);
2420
2421 mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2422 adapter->tpt_old = adapter->stats.tpt;
2423 mac->collision_delta = adapter->stats.colc - adapter->colc_old;
2424 adapter->colc_old = adapter->stats.colc;
2425
2426 adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
2427 adapter->gorc_old = adapter->stats.gorc;
2428 adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
2429 adapter->gotc_old = adapter->stats.gotc;
2430
2431 igb_update_adaptive(&adapter->hw);
2432
2433 if (!netif_carrier_ok(netdev)) {
2434 if (IGB_DESC_UNUSED(tx_ring) + 1 < tx_ring->count) {
2435 /* We've lost link, so the controller stops DMA,
2436 * but we've got queued Tx work that's never going
2437 * to get done, so reset controller to flush Tx.
2438 * (Do the reset outside of interrupt context). */
2439 adapter->tx_timeout_count++;
2440 schedule_work(&adapter->reset_task);
2441 }
2442 }
2443
2444 /* Cause software interrupt to ensure rx ring is cleaned */
Alexander Duyck7a6ea552008-08-26 04:25:03 -07002445 if (adapter->msix_entries) {
2446 for (i = 0; i < adapter->num_rx_queues; i++)
2447 eics |= adapter->rx_ring[i].eims_value;
2448 wr32(E1000_EICS, eics);
2449 } else {
2450 wr32(E1000_ICS, E1000_ICS_RXDMT0);
2451 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002452
2453 /* Force detection of hung controller every watchdog period */
2454 tx_ring->detect_tx_hung = true;
2455
2456 /* Reset the timer */
2457 if (!test_bit(__IGB_DOWN, &adapter->state))
2458 mod_timer(&adapter->watchdog_timer,
2459 round_jiffies(jiffies + 2 * HZ));
2460}
2461
2462enum latency_range {
2463 lowest_latency = 0,
2464 low_latency = 1,
2465 bulk_latency = 2,
2466 latency_invalid = 255
2467};
2468
2469
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002470/**
2471 * igb_update_ring_itr - update the dynamic ITR value based on packet size
2472 *
2473 * Stores a new ITR value based on strictly on packet size. This
2474 * algorithm is less sophisticated than that used in igb_update_itr,
2475 * due to the difficulty of synchronizing statistics across multiple
2476 * receive rings. The divisors and thresholds used by this fuction
2477 * were determined based on theoretical maximum wire speed and testing
2478 * data, in order to minimize response time while increasing bulk
2479 * throughput.
2480 * This functionality is controlled by the InterruptThrottleRate module
2481 * parameter (see igb_param.c)
2482 * NOTE: This function is called only when operating in a multiqueue
2483 * receive environment.
2484 * @rx_ring: pointer to ring
2485 **/
2486static void igb_update_ring_itr(struct igb_ring *rx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08002487{
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002488 int new_val = rx_ring->itr_val;
2489 int avg_wire_size = 0;
2490 struct igb_adapter *adapter = rx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08002491
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002492 if (!rx_ring->total_packets)
2493 goto clear_counts; /* no packets, so don't do anything */
Auke Kok9d5c8242008-01-24 02:22:38 -08002494
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002495 /* For non-gigabit speeds, just fix the interrupt rate at 4000
2496 * ints/sec - ITR timer value of 120 ticks.
2497 */
2498 if (adapter->link_speed != SPEED_1000) {
2499 new_val = 120;
2500 goto set_itr_val;
2501 }
2502 avg_wire_size = rx_ring->total_bytes / rx_ring->total_packets;
2503
2504 /* Add 24 bytes to size to account for CRC, preamble, and gap */
2505 avg_wire_size += 24;
2506
2507 /* Don't starve jumbo frames */
2508 avg_wire_size = min(avg_wire_size, 3000);
2509
2510 /* Give a little boost to mid-size frames */
2511 if ((avg_wire_size > 300) && (avg_wire_size < 1200))
2512 new_val = avg_wire_size / 3;
2513 else
2514 new_val = avg_wire_size / 2;
2515
2516set_itr_val:
Auke Kok9d5c8242008-01-24 02:22:38 -08002517 if (new_val != rx_ring->itr_val) {
2518 rx_ring->itr_val = new_val;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002519 rx_ring->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08002520 }
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002521clear_counts:
2522 rx_ring->total_bytes = 0;
2523 rx_ring->total_packets = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08002524}
2525
2526/**
2527 * igb_update_itr - update the dynamic ITR value based on statistics
2528 * Stores a new ITR value based on packets and byte
2529 * counts during the last interrupt. The advantage of per interrupt
2530 * computation is faster updates and more accurate ITR for the current
2531 * traffic pattern. Constants in this function were computed
2532 * based on theoretical maximum wire speed and thresholds were set based
2533 * on testing data as well as attempting to minimize response time
2534 * while increasing bulk throughput.
2535 * this functionality is controlled by the InterruptThrottleRate module
2536 * parameter (see igb_param.c)
2537 * NOTE: These calculations are only valid when operating in a single-
2538 * queue environment.
2539 * @adapter: pointer to adapter
2540 * @itr_setting: current adapter->itr
2541 * @packets: the number of packets during this measurement interval
2542 * @bytes: the number of bytes during this measurement interval
2543 **/
2544static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
2545 int packets, int bytes)
2546{
2547 unsigned int retval = itr_setting;
2548
2549 if (packets == 0)
2550 goto update_itr_done;
2551
2552 switch (itr_setting) {
2553 case lowest_latency:
2554 /* handle TSO and jumbo frames */
2555 if (bytes/packets > 8000)
2556 retval = bulk_latency;
2557 else if ((packets < 5) && (bytes > 512))
2558 retval = low_latency;
2559 break;
2560 case low_latency: /* 50 usec aka 20000 ints/s */
2561 if (bytes > 10000) {
2562 /* this if handles the TSO accounting */
2563 if (bytes/packets > 8000) {
2564 retval = bulk_latency;
2565 } else if ((packets < 10) || ((bytes/packets) > 1200)) {
2566 retval = bulk_latency;
2567 } else if ((packets > 35)) {
2568 retval = lowest_latency;
2569 }
2570 } else if (bytes/packets > 2000) {
2571 retval = bulk_latency;
2572 } else if (packets <= 2 && bytes < 512) {
2573 retval = lowest_latency;
2574 }
2575 break;
2576 case bulk_latency: /* 250 usec aka 4000 ints/s */
2577 if (bytes > 25000) {
2578 if (packets > 35)
2579 retval = low_latency;
2580 } else if (bytes < 6000) {
2581 retval = low_latency;
2582 }
2583 break;
2584 }
2585
2586update_itr_done:
2587 return retval;
2588}
2589
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002590static void igb_set_itr(struct igb_adapter *adapter)
Auke Kok9d5c8242008-01-24 02:22:38 -08002591{
2592 u16 current_itr;
2593 u32 new_itr = adapter->itr;
2594
2595 /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
2596 if (adapter->link_speed != SPEED_1000) {
2597 current_itr = 0;
2598 new_itr = 4000;
2599 goto set_itr_now;
2600 }
2601
2602 adapter->rx_itr = igb_update_itr(adapter,
2603 adapter->rx_itr,
2604 adapter->rx_ring->total_packets,
2605 adapter->rx_ring->total_bytes);
Auke Kok9d5c8242008-01-24 02:22:38 -08002606
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002607 if (adapter->rx_ring->buddy) {
Auke Kok9d5c8242008-01-24 02:22:38 -08002608 adapter->tx_itr = igb_update_itr(adapter,
2609 adapter->tx_itr,
2610 adapter->tx_ring->total_packets,
2611 adapter->tx_ring->total_bytes);
Auke Kok9d5c8242008-01-24 02:22:38 -08002612
2613 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2614 } else {
2615 current_itr = adapter->rx_itr;
2616 }
2617
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002618 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2619 if (adapter->itr_setting == 3 &&
2620 current_itr == lowest_latency)
2621 current_itr = low_latency;
2622
Auke Kok9d5c8242008-01-24 02:22:38 -08002623 switch (current_itr) {
2624 /* counts and packets in update_itr are dependent on these numbers */
2625 case lowest_latency:
2626 new_itr = 70000;
2627 break;
2628 case low_latency:
2629 new_itr = 20000; /* aka hwitr = ~200 */
2630 break;
2631 case bulk_latency:
2632 new_itr = 4000;
2633 break;
2634 default:
2635 break;
2636 }
2637
2638set_itr_now:
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002639 adapter->rx_ring->total_bytes = 0;
2640 adapter->rx_ring->total_packets = 0;
2641 if (adapter->rx_ring->buddy) {
2642 adapter->rx_ring->buddy->total_bytes = 0;
2643 adapter->rx_ring->buddy->total_packets = 0;
2644 }
2645
Auke Kok9d5c8242008-01-24 02:22:38 -08002646 if (new_itr != adapter->itr) {
2647 /* this attempts to bias the interrupt rate towards Bulk
2648 * by adding intermediate steps when interrupt rate is
2649 * increasing */
2650 new_itr = new_itr > adapter->itr ?
2651 min(adapter->itr + (new_itr >> 2), new_itr) :
2652 new_itr;
2653 /* Don't write the value here; it resets the adapter's
2654 * internal timer, and causes us to delay far longer than
2655 * we should between interrupts. Instead, we write the ITR
2656 * value at the beginning of the next interrupt so the timing
2657 * ends up being correct.
2658 */
2659 adapter->itr = new_itr;
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07002660 adapter->rx_ring->itr_val = 1000000000 / (new_itr * 256);
2661 adapter->rx_ring->set_itr = 1;
Auke Kok9d5c8242008-01-24 02:22:38 -08002662 }
2663
2664 return;
2665}
2666
2667
2668#define IGB_TX_FLAGS_CSUM 0x00000001
2669#define IGB_TX_FLAGS_VLAN 0x00000002
2670#define IGB_TX_FLAGS_TSO 0x00000004
2671#define IGB_TX_FLAGS_IPV4 0x00000008
2672#define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
2673#define IGB_TX_FLAGS_VLAN_SHIFT 16
2674
2675static inline int igb_tso_adv(struct igb_adapter *adapter,
2676 struct igb_ring *tx_ring,
2677 struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
2678{
2679 struct e1000_adv_tx_context_desc *context_desc;
2680 unsigned int i;
2681 int err;
2682 struct igb_buffer *buffer_info;
2683 u32 info = 0, tu_cmd = 0;
2684 u32 mss_l4len_idx, l4len;
2685 *hdr_len = 0;
2686
2687 if (skb_header_cloned(skb)) {
2688 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
2689 if (err)
2690 return err;
2691 }
2692
2693 l4len = tcp_hdrlen(skb);
2694 *hdr_len += l4len;
2695
2696 if (skb->protocol == htons(ETH_P_IP)) {
2697 struct iphdr *iph = ip_hdr(skb);
2698 iph->tot_len = 0;
2699 iph->check = 0;
2700 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2701 iph->daddr, 0,
2702 IPPROTO_TCP,
2703 0);
2704 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
2705 ipv6_hdr(skb)->payload_len = 0;
2706 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2707 &ipv6_hdr(skb)->daddr,
2708 0, IPPROTO_TCP, 0);
2709 }
2710
2711 i = tx_ring->next_to_use;
2712
2713 buffer_info = &tx_ring->buffer_info[i];
2714 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
2715 /* VLAN MACLEN IPLEN */
2716 if (tx_flags & IGB_TX_FLAGS_VLAN)
2717 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
2718 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
2719 *hdr_len += skb_network_offset(skb);
2720 info |= skb_network_header_len(skb);
2721 *hdr_len += skb_network_header_len(skb);
2722 context_desc->vlan_macip_lens = cpu_to_le32(info);
2723
2724 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
2725 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
2726
2727 if (skb->protocol == htons(ETH_P_IP))
2728 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
2729 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2730
2731 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
2732
2733 /* MSS L4LEN IDX */
2734 mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
2735 mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
2736
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002737 /* Context index must be unique per ring. */
2738 if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
2739 mss_l4len_idx |= tx_ring->queue_index << 4;
Auke Kok9d5c8242008-01-24 02:22:38 -08002740
2741 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
2742 context_desc->seqnum_seed = 0;
2743
2744 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002745 buffer_info->next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002746 buffer_info->dma = 0;
2747 i++;
2748 if (i == tx_ring->count)
2749 i = 0;
2750
2751 tx_ring->next_to_use = i;
2752
2753 return true;
2754}
2755
2756static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
2757 struct igb_ring *tx_ring,
2758 struct sk_buff *skb, u32 tx_flags)
2759{
2760 struct e1000_adv_tx_context_desc *context_desc;
2761 unsigned int i;
2762 struct igb_buffer *buffer_info;
2763 u32 info = 0, tu_cmd = 0;
2764
2765 if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
2766 (tx_flags & IGB_TX_FLAGS_VLAN)) {
2767 i = tx_ring->next_to_use;
2768 buffer_info = &tx_ring->buffer_info[i];
2769 context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
2770
2771 if (tx_flags & IGB_TX_FLAGS_VLAN)
2772 info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
2773 info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
2774 if (skb->ip_summed == CHECKSUM_PARTIAL)
2775 info |= skb_network_header_len(skb);
2776
2777 context_desc->vlan_macip_lens = cpu_to_le32(info);
2778
2779 tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
2780
2781 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Mitch Williams44b0cda2008-03-07 10:32:13 -08002782 switch (skb->protocol) {
2783 case __constant_htons(ETH_P_IP):
Auke Kok9d5c8242008-01-24 02:22:38 -08002784 tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
Mitch Williams44b0cda2008-03-07 10:32:13 -08002785 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2786 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2787 break;
2788 case __constant_htons(ETH_P_IPV6):
2789 /* XXX what about other V6 headers?? */
2790 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2791 tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
2792 break;
2793 default:
2794 if (unlikely(net_ratelimit()))
2795 dev_warn(&adapter->pdev->dev,
2796 "partial checksum but proto=%x!\n",
2797 skb->protocol);
2798 break;
2799 }
Auke Kok9d5c8242008-01-24 02:22:38 -08002800 }
2801
2802 context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
2803 context_desc->seqnum_seed = 0;
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002804 if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
2805 context_desc->mss_l4len_idx =
2806 cpu_to_le32(tx_ring->queue_index << 4);
Auke Kok9d5c8242008-01-24 02:22:38 -08002807
2808 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002809 buffer_info->next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002810 buffer_info->dma = 0;
2811
2812 i++;
2813 if (i == tx_ring->count)
2814 i = 0;
2815 tx_ring->next_to_use = i;
2816
2817 return true;
2818 }
2819
2820
2821 return false;
2822}
2823
2824#define IGB_MAX_TXD_PWR 16
2825#define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
2826
2827static inline int igb_tx_map_adv(struct igb_adapter *adapter,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002828 struct igb_ring *tx_ring, struct sk_buff *skb,
2829 unsigned int first)
Auke Kok9d5c8242008-01-24 02:22:38 -08002830{
2831 struct igb_buffer *buffer_info;
2832 unsigned int len = skb_headlen(skb);
2833 unsigned int count = 0, i;
2834 unsigned int f;
2835
2836 i = tx_ring->next_to_use;
2837
2838 buffer_info = &tx_ring->buffer_info[i];
2839 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
2840 buffer_info->length = len;
2841 /* set time_stamp *before* dma to help avoid a possible race */
2842 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002843 buffer_info->next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002844 buffer_info->dma = pci_map_single(adapter->pdev, skb->data, len,
2845 PCI_DMA_TODEVICE);
2846 count++;
2847 i++;
2848 if (i == tx_ring->count)
2849 i = 0;
2850
2851 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
2852 struct skb_frag_struct *frag;
2853
2854 frag = &skb_shinfo(skb)->frags[f];
2855 len = frag->size;
2856
2857 buffer_info = &tx_ring->buffer_info[i];
2858 BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
2859 buffer_info->length = len;
2860 buffer_info->time_stamp = jiffies;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002861 buffer_info->next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002862 buffer_info->dma = pci_map_page(adapter->pdev,
2863 frag->page,
2864 frag->page_offset,
2865 len,
2866 PCI_DMA_TODEVICE);
2867
2868 count++;
2869 i++;
2870 if (i == tx_ring->count)
2871 i = 0;
2872 }
2873
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002874 i = ((i == 0) ? tx_ring->count - 1 : i - 1);
Auke Kok9d5c8242008-01-24 02:22:38 -08002875 tx_ring->buffer_info[i].skb = skb;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002876 tx_ring->buffer_info[first].next_to_watch = i;
Auke Kok9d5c8242008-01-24 02:22:38 -08002877
2878 return count;
2879}
2880
2881static inline void igb_tx_queue_adv(struct igb_adapter *adapter,
2882 struct igb_ring *tx_ring,
2883 int tx_flags, int count, u32 paylen,
2884 u8 hdr_len)
2885{
2886 union e1000_adv_tx_desc *tx_desc = NULL;
2887 struct igb_buffer *buffer_info;
2888 u32 olinfo_status = 0, cmd_type_len;
2889 unsigned int i;
2890
2891 cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
2892 E1000_ADVTXD_DCMD_DEXT);
2893
2894 if (tx_flags & IGB_TX_FLAGS_VLAN)
2895 cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
2896
2897 if (tx_flags & IGB_TX_FLAGS_TSO) {
2898 cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
2899
2900 /* insert tcp checksum */
2901 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
2902
2903 /* insert ip checksum */
2904 if (tx_flags & IGB_TX_FLAGS_IPV4)
2905 olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
2906
2907 } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
2908 olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
2909 }
2910
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07002911 if ((adapter->flags & IGB_FLAG_NEED_CTX_IDX) &&
2912 (tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_TSO |
2913 IGB_TX_FLAGS_VLAN)))
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07002914 olinfo_status |= tx_ring->queue_index << 4;
Auke Kok9d5c8242008-01-24 02:22:38 -08002915
2916 olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
2917
2918 i = tx_ring->next_to_use;
2919 while (count--) {
2920 buffer_info = &tx_ring->buffer_info[i];
2921 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
2922 tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
2923 tx_desc->read.cmd_type_len =
2924 cpu_to_le32(cmd_type_len | buffer_info->length);
2925 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
2926 i++;
2927 if (i == tx_ring->count)
2928 i = 0;
2929 }
2930
2931 tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd);
2932 /* Force memory writes to complete before letting h/w
2933 * know there are new descriptors to fetch. (Only
2934 * applicable for weak-ordered memory model archs,
2935 * such as IA-64). */
2936 wmb();
2937
2938 tx_ring->next_to_use = i;
2939 writel(i, adapter->hw.hw_addr + tx_ring->tail);
2940 /* we need this if more than one processor can write to our tail
2941 * at a time, it syncronizes IO on IA64/Altix systems */
2942 mmiowb();
2943}
2944
2945static int __igb_maybe_stop_tx(struct net_device *netdev,
2946 struct igb_ring *tx_ring, int size)
2947{
2948 struct igb_adapter *adapter = netdev_priv(netdev);
2949
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07002950 netif_stop_subqueue(netdev, tx_ring->queue_index);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07002951
Auke Kok9d5c8242008-01-24 02:22:38 -08002952 /* Herbert's original patch had:
2953 * smp_mb__after_netif_stop_queue();
2954 * but since that doesn't exist yet, just open code it. */
2955 smp_mb();
2956
2957 /* We need to check again in a case another CPU has just
2958 * made room available. */
2959 if (IGB_DESC_UNUSED(tx_ring) < size)
2960 return -EBUSY;
2961
2962 /* A reprieve! */
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07002963 netif_wake_subqueue(netdev, tx_ring->queue_index);
Auke Kok9d5c8242008-01-24 02:22:38 -08002964 ++adapter->restart_queue;
2965 return 0;
2966}
2967
2968static int igb_maybe_stop_tx(struct net_device *netdev,
2969 struct igb_ring *tx_ring, int size)
2970{
2971 if (IGB_DESC_UNUSED(tx_ring) >= size)
2972 return 0;
2973 return __igb_maybe_stop_tx(netdev, tx_ring, size);
2974}
2975
2976#define TXD_USE_COUNT(S) (((S) >> (IGB_MAX_TXD_PWR)) + 1)
2977
2978static int igb_xmit_frame_ring_adv(struct sk_buff *skb,
2979 struct net_device *netdev,
2980 struct igb_ring *tx_ring)
2981{
2982 struct igb_adapter *adapter = netdev_priv(netdev);
Alexander Duyck0e014cb2008-12-26 01:33:18 -08002983 unsigned int first;
Auke Kok9d5c8242008-01-24 02:22:38 -08002984 unsigned int tx_flags = 0;
2985 unsigned int len;
Auke Kok9d5c8242008-01-24 02:22:38 -08002986 u8 hdr_len = 0;
2987 int tso = 0;
2988
2989 len = skb_headlen(skb);
2990
2991 if (test_bit(__IGB_DOWN, &adapter->state)) {
2992 dev_kfree_skb_any(skb);
2993 return NETDEV_TX_OK;
2994 }
2995
2996 if (skb->len <= 0) {
2997 dev_kfree_skb_any(skb);
2998 return NETDEV_TX_OK;
2999 }
3000
Auke Kok9d5c8242008-01-24 02:22:38 -08003001 /* need: 1 descriptor per page,
3002 * + 2 desc gap to keep tail from touching head,
3003 * + 1 desc for skb->data,
3004 * + 1 desc for context descriptor,
3005 * otherwise try next time */
3006 if (igb_maybe_stop_tx(netdev, tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
3007 /* this is a hard error */
Auke Kok9d5c8242008-01-24 02:22:38 -08003008 return NETDEV_TX_BUSY;
3009 }
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003010 skb_orphan(skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08003011
3012 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3013 tx_flags |= IGB_TX_FLAGS_VLAN;
3014 tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
3015 }
3016
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003017 if (skb->protocol == htons(ETH_P_IP))
3018 tx_flags |= IGB_TX_FLAGS_IPV4;
3019
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003020 first = tx_ring->next_to_use;
3021
Auke Kok9d5c8242008-01-24 02:22:38 -08003022 tso = skb_is_gso(skb) ? igb_tso_adv(adapter, tx_ring, skb, tx_flags,
3023 &hdr_len) : 0;
3024
3025 if (tso < 0) {
3026 dev_kfree_skb_any(skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08003027 return NETDEV_TX_OK;
3028 }
3029
3030 if (tso)
3031 tx_flags |= IGB_TX_FLAGS_TSO;
3032 else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags))
3033 if (skb->ip_summed == CHECKSUM_PARTIAL)
3034 tx_flags |= IGB_TX_FLAGS_CSUM;
3035
Auke Kok9d5c8242008-01-24 02:22:38 -08003036 igb_tx_queue_adv(adapter, tx_ring, tx_flags,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003037 igb_tx_map_adv(adapter, tx_ring, skb, first),
Auke Kok9d5c8242008-01-24 02:22:38 -08003038 skb->len, hdr_len);
3039
3040 netdev->trans_start = jiffies;
3041
3042 /* Make sure there is space in the ring for the next send. */
3043 igb_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 4);
3044
Auke Kok9d5c8242008-01-24 02:22:38 -08003045 return NETDEV_TX_OK;
3046}
3047
3048static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *netdev)
3049{
3050 struct igb_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003051 struct igb_ring *tx_ring;
3052
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003053 int r_idx = 0;
3054 r_idx = skb->queue_mapping & (IGB_MAX_TX_QUEUES - 1);
3055 tx_ring = adapter->multi_tx_table[r_idx];
Auke Kok9d5c8242008-01-24 02:22:38 -08003056
3057 /* This goes back to the question of how to logically map a tx queue
3058 * to a flow. Right now, performance is impacted slightly negatively
3059 * if using multiple tx queues. If the stack breaks away from a
3060 * single qdisc implementation, we can look at this again. */
3061 return (igb_xmit_frame_ring_adv(skb, netdev, tx_ring));
3062}
3063
3064/**
3065 * igb_tx_timeout - Respond to a Tx Hang
3066 * @netdev: network interface device structure
3067 **/
3068static void igb_tx_timeout(struct net_device *netdev)
3069{
3070 struct igb_adapter *adapter = netdev_priv(netdev);
3071 struct e1000_hw *hw = &adapter->hw;
3072
3073 /* Do the reset outside of interrupt context */
3074 adapter->tx_timeout_count++;
3075 schedule_work(&adapter->reset_task);
3076 wr32(E1000_EICS, adapter->eims_enable_mask &
3077 ~(E1000_EIMS_TCP_TIMER | E1000_EIMS_OTHER));
3078}
3079
3080static void igb_reset_task(struct work_struct *work)
3081{
3082 struct igb_adapter *adapter;
3083 adapter = container_of(work, struct igb_adapter, reset_task);
3084
3085 igb_reinit_locked(adapter);
3086}
3087
3088/**
3089 * igb_get_stats - Get System Network Statistics
3090 * @netdev: network interface device structure
3091 *
3092 * Returns the address of the device statistics structure.
3093 * The statistics are actually updated from the timer callback.
3094 **/
3095static struct net_device_stats *
3096igb_get_stats(struct net_device *netdev)
3097{
3098 struct igb_adapter *adapter = netdev_priv(netdev);
3099
3100 /* only return the current stats */
3101 return &adapter->net_stats;
3102}
3103
3104/**
3105 * igb_change_mtu - Change the Maximum Transfer Unit
3106 * @netdev: network interface device structure
3107 * @new_mtu: new value for maximum frame size
3108 *
3109 * Returns 0 on success, negative on failure
3110 **/
3111static int igb_change_mtu(struct net_device *netdev, int new_mtu)
3112{
3113 struct igb_adapter *adapter = netdev_priv(netdev);
3114 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3115
3116 if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
3117 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
3118 dev_err(&adapter->pdev->dev, "Invalid MTU setting\n");
3119 return -EINVAL;
3120 }
3121
3122#define MAX_STD_JUMBO_FRAME_SIZE 9234
3123 if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
3124 dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
3125 return -EINVAL;
3126 }
3127
3128 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
3129 msleep(1);
3130 /* igb_down has a dependency on max_frame_size */
3131 adapter->max_frame_size = max_frame;
3132 if (netif_running(netdev))
3133 igb_down(adapter);
3134
3135 /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
3136 * means we reserve 2 more, this pushes us to allocate from the next
3137 * larger slab size.
3138 * i.e. RXBUFFER_2048 --> size-4096 slab
3139 */
3140
3141 if (max_frame <= IGB_RXBUFFER_256)
3142 adapter->rx_buffer_len = IGB_RXBUFFER_256;
3143 else if (max_frame <= IGB_RXBUFFER_512)
3144 adapter->rx_buffer_len = IGB_RXBUFFER_512;
3145 else if (max_frame <= IGB_RXBUFFER_1024)
3146 adapter->rx_buffer_len = IGB_RXBUFFER_1024;
3147 else if (max_frame <= IGB_RXBUFFER_2048)
3148 adapter->rx_buffer_len = IGB_RXBUFFER_2048;
3149 else
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003150#if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
3151 adapter->rx_buffer_len = IGB_RXBUFFER_16384;
3152#else
3153 adapter->rx_buffer_len = PAGE_SIZE / 2;
3154#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08003155 /* adjust allocation if LPE protects us, and we aren't using SBP */
3156 if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
3157 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))
3158 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3159
3160 dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
3161 netdev->mtu, new_mtu);
3162 netdev->mtu = new_mtu;
3163
3164 if (netif_running(netdev))
3165 igb_up(adapter);
3166 else
3167 igb_reset(adapter);
3168
3169 clear_bit(__IGB_RESETTING, &adapter->state);
3170
3171 return 0;
3172}
3173
3174/**
3175 * igb_update_stats - Update the board statistics counters
3176 * @adapter: board private structure
3177 **/
3178
3179void igb_update_stats(struct igb_adapter *adapter)
3180{
3181 struct e1000_hw *hw = &adapter->hw;
3182 struct pci_dev *pdev = adapter->pdev;
3183 u16 phy_tmp;
3184
3185#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3186
3187 /*
3188 * Prevent stats update while adapter is being reset, or if the pci
3189 * connection is down.
3190 */
3191 if (adapter->link_speed == 0)
3192 return;
3193 if (pci_channel_offline(pdev))
3194 return;
3195
3196 adapter->stats.crcerrs += rd32(E1000_CRCERRS);
3197 adapter->stats.gprc += rd32(E1000_GPRC);
3198 adapter->stats.gorc += rd32(E1000_GORCL);
3199 rd32(E1000_GORCH); /* clear GORCL */
3200 adapter->stats.bprc += rd32(E1000_BPRC);
3201 adapter->stats.mprc += rd32(E1000_MPRC);
3202 adapter->stats.roc += rd32(E1000_ROC);
3203
3204 adapter->stats.prc64 += rd32(E1000_PRC64);
3205 adapter->stats.prc127 += rd32(E1000_PRC127);
3206 adapter->stats.prc255 += rd32(E1000_PRC255);
3207 adapter->stats.prc511 += rd32(E1000_PRC511);
3208 adapter->stats.prc1023 += rd32(E1000_PRC1023);
3209 adapter->stats.prc1522 += rd32(E1000_PRC1522);
3210 adapter->stats.symerrs += rd32(E1000_SYMERRS);
3211 adapter->stats.sec += rd32(E1000_SEC);
3212
3213 adapter->stats.mpc += rd32(E1000_MPC);
3214 adapter->stats.scc += rd32(E1000_SCC);
3215 adapter->stats.ecol += rd32(E1000_ECOL);
3216 adapter->stats.mcc += rd32(E1000_MCC);
3217 adapter->stats.latecol += rd32(E1000_LATECOL);
3218 adapter->stats.dc += rd32(E1000_DC);
3219 adapter->stats.rlec += rd32(E1000_RLEC);
3220 adapter->stats.xonrxc += rd32(E1000_XONRXC);
3221 adapter->stats.xontxc += rd32(E1000_XONTXC);
3222 adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
3223 adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
3224 adapter->stats.fcruc += rd32(E1000_FCRUC);
3225 adapter->stats.gptc += rd32(E1000_GPTC);
3226 adapter->stats.gotc += rd32(E1000_GOTCL);
3227 rd32(E1000_GOTCH); /* clear GOTCL */
3228 adapter->stats.rnbc += rd32(E1000_RNBC);
3229 adapter->stats.ruc += rd32(E1000_RUC);
3230 adapter->stats.rfc += rd32(E1000_RFC);
3231 adapter->stats.rjc += rd32(E1000_RJC);
3232 adapter->stats.tor += rd32(E1000_TORH);
3233 adapter->stats.tot += rd32(E1000_TOTH);
3234 adapter->stats.tpr += rd32(E1000_TPR);
3235
3236 adapter->stats.ptc64 += rd32(E1000_PTC64);
3237 adapter->stats.ptc127 += rd32(E1000_PTC127);
3238 adapter->stats.ptc255 += rd32(E1000_PTC255);
3239 adapter->stats.ptc511 += rd32(E1000_PTC511);
3240 adapter->stats.ptc1023 += rd32(E1000_PTC1023);
3241 adapter->stats.ptc1522 += rd32(E1000_PTC1522);
3242
3243 adapter->stats.mptc += rd32(E1000_MPTC);
3244 adapter->stats.bptc += rd32(E1000_BPTC);
3245
3246 /* used for adaptive IFS */
3247
3248 hw->mac.tx_packet_delta = rd32(E1000_TPT);
3249 adapter->stats.tpt += hw->mac.tx_packet_delta;
3250 hw->mac.collision_delta = rd32(E1000_COLC);
3251 adapter->stats.colc += hw->mac.collision_delta;
3252
3253 adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
3254 adapter->stats.rxerrc += rd32(E1000_RXERRC);
3255 adapter->stats.tncrs += rd32(E1000_TNCRS);
3256 adapter->stats.tsctc += rd32(E1000_TSCTC);
3257 adapter->stats.tsctfc += rd32(E1000_TSCTFC);
3258
3259 adapter->stats.iac += rd32(E1000_IAC);
3260 adapter->stats.icrxoc += rd32(E1000_ICRXOC);
3261 adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
3262 adapter->stats.icrxatc += rd32(E1000_ICRXATC);
3263 adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
3264 adapter->stats.ictxatc += rd32(E1000_ICTXATC);
3265 adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
3266 adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
3267 adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
3268
3269 /* Fill out the OS statistics structure */
3270 adapter->net_stats.multicast = adapter->stats.mprc;
3271 adapter->net_stats.collisions = adapter->stats.colc;
3272
3273 /* Rx Errors */
3274
3275 /* RLEC on some newer hardware can be incorrect so build
3276 * our own version based on RUC and ROC */
3277 adapter->net_stats.rx_errors = adapter->stats.rxerrc +
3278 adapter->stats.crcerrs + adapter->stats.algnerrc +
3279 adapter->stats.ruc + adapter->stats.roc +
3280 adapter->stats.cexterr;
3281 adapter->net_stats.rx_length_errors = adapter->stats.ruc +
3282 adapter->stats.roc;
3283 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
3284 adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
3285 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
3286
3287 /* Tx Errors */
3288 adapter->net_stats.tx_errors = adapter->stats.ecol +
3289 adapter->stats.latecol;
3290 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3291 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3292 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3293
3294 /* Tx Dropped needs to be maintained elsewhere */
3295
3296 /* Phy Stats */
3297 if (hw->phy.media_type == e1000_media_type_copper) {
3298 if ((adapter->link_speed == SPEED_1000) &&
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08003299 (!igb_read_phy_reg(hw, PHY_1000T_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -08003300 &phy_tmp))) {
3301 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3302 adapter->phy_stats.idle_errors += phy_tmp;
3303 }
3304 }
3305
3306 /* Management Stats */
3307 adapter->stats.mgptc += rd32(E1000_MGTPTC);
3308 adapter->stats.mgprc += rd32(E1000_MGTPRC);
3309 adapter->stats.mgpdc += rd32(E1000_MGTPDC);
3310}
3311
3312
3313static irqreturn_t igb_msix_other(int irq, void *data)
3314{
3315 struct net_device *netdev = data;
3316 struct igb_adapter *adapter = netdev_priv(netdev);
3317 struct e1000_hw *hw = &adapter->hw;
PJ Waskiewicz844290e2008-06-27 11:00:39 -07003318 u32 icr = rd32(E1000_ICR);
Auke Kok9d5c8242008-01-24 02:22:38 -08003319
PJ Waskiewicz844290e2008-06-27 11:00:39 -07003320 /* reading ICR causes bit 31 of EICR to be cleared */
3321 if (!(icr & E1000_ICR_LSC))
3322 goto no_link_interrupt;
3323 hw->mac.get_link_status = 1;
3324 /* guard against interrupt when we're going down */
3325 if (!test_bit(__IGB_DOWN, &adapter->state))
3326 mod_timer(&adapter->watchdog_timer, jiffies + 1);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003327
Auke Kok9d5c8242008-01-24 02:22:38 -08003328no_link_interrupt:
3329 wr32(E1000_IMS, E1000_IMS_LSC);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07003330 wr32(E1000_EIMS, adapter->eims_other);
Auke Kok9d5c8242008-01-24 02:22:38 -08003331
3332 return IRQ_HANDLED;
3333}
3334
3335static irqreturn_t igb_msix_tx(int irq, void *data)
3336{
3337 struct igb_ring *tx_ring = data;
3338 struct igb_adapter *adapter = tx_ring->adapter;
3339 struct e1000_hw *hw = &adapter->hw;
3340
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003341#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003342 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003343 igb_update_tx_dca(tx_ring);
3344#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08003345 tx_ring->total_bytes = 0;
3346 tx_ring->total_packets = 0;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003347
3348 /* auto mask will automatically reenable the interrupt when we write
3349 * EICS */
Mitch Williams3b644cf2008-06-27 10:59:48 -07003350 if (!igb_clean_tx_irq(tx_ring))
Auke Kok9d5c8242008-01-24 02:22:38 -08003351 /* Ring was not completely cleaned, so fire another interrupt */
3352 wr32(E1000_EICS, tx_ring->eims_value);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003353 else
Auke Kok9d5c8242008-01-24 02:22:38 -08003354 wr32(E1000_EIMS, tx_ring->eims_value);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003355
Auke Kok9d5c8242008-01-24 02:22:38 -08003356 return IRQ_HANDLED;
3357}
3358
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003359static void igb_write_itr(struct igb_ring *ring)
3360{
3361 struct e1000_hw *hw = &ring->adapter->hw;
3362 if ((ring->adapter->itr_setting & 3) && ring->set_itr) {
3363 switch (hw->mac.type) {
3364 case e1000_82576:
3365 wr32(ring->itr_register,
3366 ring->itr_val |
3367 0x80000000);
3368 break;
3369 default:
3370 wr32(ring->itr_register,
3371 ring->itr_val |
3372 (ring->itr_val << 16));
3373 break;
3374 }
3375 ring->set_itr = 0;
3376 }
3377}
3378
Auke Kok9d5c8242008-01-24 02:22:38 -08003379static irqreturn_t igb_msix_rx(int irq, void *data)
3380{
3381 struct igb_ring *rx_ring = data;
3382 struct igb_adapter *adapter = rx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08003383
PJ Waskiewicz844290e2008-06-27 11:00:39 -07003384 /* Write the ITR value calculated at the end of the
3385 * previous interrupt.
3386 */
Auke Kok9d5c8242008-01-24 02:22:38 -08003387
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003388 igb_write_itr(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003389
Neil Horman908a7a12008-12-22 20:43:12 -08003390 if (netif_rx_schedule_prep(&rx_ring->napi))
3391 __netif_rx_schedule(&rx_ring->napi);
PJ Waskiewicz844290e2008-06-27 11:00:39 -07003392
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003393#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003394 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003395 igb_update_rx_dca(rx_ring);
3396#endif
3397 return IRQ_HANDLED;
Auke Kok9d5c8242008-01-24 02:22:38 -08003398}
3399
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003400#ifdef CONFIG_IGB_DCA
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003401static void igb_update_rx_dca(struct igb_ring *rx_ring)
3402{
3403 u32 dca_rxctrl;
3404 struct igb_adapter *adapter = rx_ring->adapter;
3405 struct e1000_hw *hw = &adapter->hw;
3406 int cpu = get_cpu();
Alexander Duyck26bc19e2008-12-26 01:34:11 -08003407 int q = rx_ring->reg_idx;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003408
3409 if (rx_ring->cpu != cpu) {
3410 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
Alexander Duyck2d064c02008-07-08 15:10:12 -07003411 if (hw->mac.type == e1000_82576) {
3412 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
3413 dca_rxctrl |= dca_get_tag(cpu) <<
3414 E1000_DCA_RXCTRL_CPUID_SHIFT;
3415 } else {
3416 dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
3417 dca_rxctrl |= dca_get_tag(cpu);
3418 }
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003419 dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
3420 dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
3421 dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
3422 wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
3423 rx_ring->cpu = cpu;
3424 }
3425 put_cpu();
3426}
3427
3428static void igb_update_tx_dca(struct igb_ring *tx_ring)
3429{
3430 u32 dca_txctrl;
3431 struct igb_adapter *adapter = tx_ring->adapter;
3432 struct e1000_hw *hw = &adapter->hw;
3433 int cpu = get_cpu();
Alexander Duyck26bc19e2008-12-26 01:34:11 -08003434 int q = tx_ring->reg_idx;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003435
3436 if (tx_ring->cpu != cpu) {
3437 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
Alexander Duyck2d064c02008-07-08 15:10:12 -07003438 if (hw->mac.type == e1000_82576) {
3439 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
3440 dca_txctrl |= dca_get_tag(cpu) <<
3441 E1000_DCA_TXCTRL_CPUID_SHIFT;
3442 } else {
3443 dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
3444 dca_txctrl |= dca_get_tag(cpu);
3445 }
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003446 dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
3447 wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
3448 tx_ring->cpu = cpu;
3449 }
3450 put_cpu();
3451}
3452
3453static void igb_setup_dca(struct igb_adapter *adapter)
3454{
3455 int i;
3456
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003457 if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003458 return;
3459
3460 for (i = 0; i < adapter->num_tx_queues; i++) {
3461 adapter->tx_ring[i].cpu = -1;
3462 igb_update_tx_dca(&adapter->tx_ring[i]);
3463 }
3464 for (i = 0; i < adapter->num_rx_queues; i++) {
3465 adapter->rx_ring[i].cpu = -1;
3466 igb_update_rx_dca(&adapter->rx_ring[i]);
3467 }
3468}
3469
3470static int __igb_notify_dca(struct device *dev, void *data)
3471{
3472 struct net_device *netdev = dev_get_drvdata(dev);
3473 struct igb_adapter *adapter = netdev_priv(netdev);
3474 struct e1000_hw *hw = &adapter->hw;
3475 unsigned long event = *(unsigned long *)data;
3476
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003477 if (!(adapter->flags & IGB_FLAG_HAS_DCA))
3478 goto out;
3479
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003480 switch (event) {
3481 case DCA_PROVIDER_ADD:
3482 /* if already enabled, don't do it again */
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003483 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003484 break;
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003485 adapter->flags |= IGB_FLAG_DCA_ENABLED;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003486 /* Always use CB2 mode, difference is masked
3487 * in the CB driver. */
3488 wr32(E1000_DCA_CTRL, 2);
3489 if (dca_add_requester(dev) == 0) {
3490 dev_info(&adapter->pdev->dev, "DCA enabled\n");
3491 igb_setup_dca(adapter);
3492 break;
3493 }
3494 /* Fall Through since DCA is disabled. */
3495 case DCA_PROVIDER_REMOVE:
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003496 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003497 /* without this a class_device is left
3498 * hanging around in the sysfs model */
3499 dca_remove_requester(dev);
3500 dev_info(&adapter->pdev->dev, "DCA disabled\n");
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003501 adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003502 wr32(E1000_DCA_CTRL, 1);
3503 }
3504 break;
3505 }
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003506out:
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003507 return 0;
3508}
3509
3510static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
3511 void *p)
3512{
3513 int ret_val;
3514
3515 ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
3516 __igb_notify_dca);
3517
3518 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
3519}
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003520#endif /* CONFIG_IGB_DCA */
Auke Kok9d5c8242008-01-24 02:22:38 -08003521
3522/**
3523 * igb_intr_msi - Interrupt Handler
3524 * @irq: interrupt number
3525 * @data: pointer to a network interface device structure
3526 **/
3527static irqreturn_t igb_intr_msi(int irq, void *data)
3528{
3529 struct net_device *netdev = data;
3530 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08003531 struct e1000_hw *hw = &adapter->hw;
3532 /* read ICR disables interrupts using IAM */
3533 u32 icr = rd32(E1000_ICR);
3534
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003535 igb_write_itr(adapter->rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003536
Auke Kok9d5c8242008-01-24 02:22:38 -08003537 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3538 hw->mac.get_link_status = 1;
3539 if (!test_bit(__IGB_DOWN, &adapter->state))
3540 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3541 }
3542
Neil Horman908a7a12008-12-22 20:43:12 -08003543 netif_rx_schedule(&adapter->rx_ring[0].napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08003544
3545 return IRQ_HANDLED;
3546}
3547
3548/**
3549 * igb_intr - Interrupt Handler
3550 * @irq: interrupt number
3551 * @data: pointer to a network interface device structure
3552 **/
3553static irqreturn_t igb_intr(int irq, void *data)
3554{
3555 struct net_device *netdev = data;
3556 struct igb_adapter *adapter = netdev_priv(netdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08003557 struct e1000_hw *hw = &adapter->hw;
3558 /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
3559 * need for the IMC write */
3560 u32 icr = rd32(E1000_ICR);
3561 u32 eicr = 0;
3562 if (!icr)
3563 return IRQ_NONE; /* Not our interrupt */
3564
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003565 igb_write_itr(adapter->rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003566
3567 /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
3568 * not set, then the adapter didn't send an interrupt */
3569 if (!(icr & E1000_ICR_INT_ASSERTED))
3570 return IRQ_NONE;
3571
3572 eicr = rd32(E1000_EICR);
3573
3574 if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
3575 hw->mac.get_link_status = 1;
3576 /* guard against interrupt when we're going down */
3577 if (!test_bit(__IGB_DOWN, &adapter->state))
3578 mod_timer(&adapter->watchdog_timer, jiffies + 1);
3579 }
3580
Neil Horman908a7a12008-12-22 20:43:12 -08003581 netif_rx_schedule(&adapter->rx_ring[0].napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08003582
3583 return IRQ_HANDLED;
3584}
3585
3586/**
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003587 * igb_poll - NAPI Rx polling callback
3588 * @napi: napi polling structure
3589 * @budget: count of how many packets we should handle
Auke Kok9d5c8242008-01-24 02:22:38 -08003590 **/
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003591static int igb_poll(struct napi_struct *napi, int budget)
Auke Kok9d5c8242008-01-24 02:22:38 -08003592{
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003593 struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
3594 struct igb_adapter *adapter = rx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08003595 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003596 int tx_clean_complete, work_done = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003597
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003598 /* this poll routine only supports one tx and one rx queue */
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003599#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003600 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003601 igb_update_tx_dca(&adapter->tx_ring[0]);
3602#endif
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003603 tx_clean_complete = igb_clean_tx_irq(&adapter->tx_ring[0]);
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003604
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003605#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003606 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003607 igb_update_rx_dca(&adapter->rx_ring[0]);
3608#endif
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003609 igb_clean_rx_irq_adv(&adapter->rx_ring[0], &work_done, budget);
Auke Kok9d5c8242008-01-24 02:22:38 -08003610
3611 /* If no Tx and not enough Rx work done, exit the polling mode */
3612 if ((tx_clean_complete && (work_done < budget)) ||
3613 !netif_running(netdev)) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003614 if (adapter->itr_setting & 3)
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003615 igb_set_itr(adapter);
Neil Horman908a7a12008-12-22 20:43:12 -08003616 netif_rx_complete(napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08003617 if (!test_bit(__IGB_DOWN, &adapter->state))
3618 igb_irq_enable(adapter);
3619 return 0;
3620 }
3621
3622 return 1;
3623}
3624
3625static int igb_clean_rx_ring_msix(struct napi_struct *napi, int budget)
3626{
3627 struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
3628 struct igb_adapter *adapter = rx_ring->adapter;
3629 struct e1000_hw *hw = &adapter->hw;
3630 struct net_device *netdev = adapter->netdev;
3631 int work_done = 0;
3632
Jeff Kirsher421e02f2008-10-17 11:08:31 -07003633#ifdef CONFIG_IGB_DCA
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07003634 if (adapter->flags & IGB_FLAG_DCA_ENABLED)
Jeb Cramerfe4506b2008-07-08 15:07:55 -07003635 igb_update_rx_dca(rx_ring);
3636#endif
Mitch Williams3b644cf2008-06-27 10:59:48 -07003637 igb_clean_rx_irq_adv(rx_ring, &work_done, budget);
Auke Kok9d5c8242008-01-24 02:22:38 -08003638
3639
3640 /* If not enough Rx work done, exit the polling mode */
3641 if ((work_done == 0) || !netif_running(netdev)) {
Neil Horman908a7a12008-12-22 20:43:12 -08003642 netif_rx_complete(napi);
Auke Kok9d5c8242008-01-24 02:22:38 -08003643
Alexander Duyck6eb5a7f2008-07-08 15:14:44 -07003644 if (adapter->itr_setting & 3) {
3645 if (adapter->num_rx_queues == 1)
3646 igb_set_itr(adapter);
3647 else
3648 igb_update_ring_itr(rx_ring);
Auke Kok9d5c8242008-01-24 02:22:38 -08003649 }
PJ Waskiewicz844290e2008-06-27 11:00:39 -07003650
3651 if (!test_bit(__IGB_DOWN, &adapter->state))
3652 wr32(E1000_EIMS, rx_ring->eims_value);
3653
Auke Kok9d5c8242008-01-24 02:22:38 -08003654 return 0;
3655 }
3656
3657 return 1;
3658}
Al Viro6d8126f2008-03-16 22:23:24 +00003659
Auke Kok9d5c8242008-01-24 02:22:38 -08003660/**
3661 * igb_clean_tx_irq - Reclaim resources after transmit completes
3662 * @adapter: board private structure
3663 * returns true if ring is completely cleaned
3664 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07003665static bool igb_clean_tx_irq(struct igb_ring *tx_ring)
Auke Kok9d5c8242008-01-24 02:22:38 -08003666{
Mitch Williams3b644cf2008-06-27 10:59:48 -07003667 struct igb_adapter *adapter = tx_ring->adapter;
Mitch Williams3b644cf2008-06-27 10:59:48 -07003668 struct net_device *netdev = adapter->netdev;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003669 struct e1000_hw *hw = &adapter->hw;
Auke Kok9d5c8242008-01-24 02:22:38 -08003670 struct igb_buffer *buffer_info;
3671 struct sk_buff *skb;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003672 union e1000_adv_tx_desc *tx_desc, *eop_desc;
Auke Kok9d5c8242008-01-24 02:22:38 -08003673 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003674 unsigned int i, eop, count = 0;
3675 bool cleaned = false;
Auke Kok9d5c8242008-01-24 02:22:38 -08003676
Auke Kok9d5c8242008-01-24 02:22:38 -08003677 i = tx_ring->next_to_clean;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003678 eop = tx_ring->buffer_info[i].next_to_watch;
3679 eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
3680
3681 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3682 (count < tx_ring->count)) {
3683 for (cleaned = false; !cleaned; count++) {
3684 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
Auke Kok9d5c8242008-01-24 02:22:38 -08003685 buffer_info = &tx_ring->buffer_info[i];
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003686 cleaned = (i == eop);
Auke Kok9d5c8242008-01-24 02:22:38 -08003687 skb = buffer_info->skb;
3688
3689 if (skb) {
3690 unsigned int segs, bytecount;
3691 /* gso_segs is currently only valid for tcp */
3692 segs = skb_shinfo(skb)->gso_segs ?: 1;
3693 /* multiply data chunks by size of headers */
3694 bytecount = ((segs - 1) * skb_headlen(skb)) +
3695 skb->len;
3696 total_packets += segs;
3697 total_bytes += bytecount;
3698 }
3699
3700 igb_unmap_and_free_tx_resource(adapter, buffer_info);
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003701 tx_desc->wb.status = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003702
3703 i++;
3704 if (i == tx_ring->count)
3705 i = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08003706 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003707
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003708 eop = tx_ring->buffer_info[i].next_to_watch;
3709 eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
3710 }
3711
Auke Kok9d5c8242008-01-24 02:22:38 -08003712 tx_ring->next_to_clean = i;
3713
Alexander Duyckfc7d3452008-08-26 04:25:08 -07003714 if (unlikely(count &&
Auke Kok9d5c8242008-01-24 02:22:38 -08003715 netif_carrier_ok(netdev) &&
3716 IGB_DESC_UNUSED(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
3717 /* Make sure that anybody stopping the queue after this
3718 * sees the new next_to_clean.
3719 */
3720 smp_mb();
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003721 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
3722 !(test_bit(__IGB_DOWN, &adapter->state))) {
3723 netif_wake_subqueue(netdev, tx_ring->queue_index);
3724 ++adapter->restart_queue;
3725 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003726 }
3727
3728 if (tx_ring->detect_tx_hung) {
3729 /* Detect a transmit hang in hardware, this serializes the
3730 * check with the clearing of time_stamp and movement of i */
3731 tx_ring->detect_tx_hung = false;
3732 if (tx_ring->buffer_info[i].time_stamp &&
3733 time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
3734 (adapter->tx_timeout_factor * HZ))
3735 && !(rd32(E1000_STATUS) &
3736 E1000_STATUS_TXOFF)) {
3737
Auke Kok9d5c8242008-01-24 02:22:38 -08003738 /* detected Tx unit hang */
3739 dev_err(&adapter->pdev->dev,
3740 "Detected Tx Unit Hang\n"
Alexander Duyck2d064c02008-07-08 15:10:12 -07003741 " Tx Queue <%d>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08003742 " TDH <%x>\n"
3743 " TDT <%x>\n"
3744 " next_to_use <%x>\n"
3745 " next_to_clean <%x>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08003746 "buffer_info[next_to_clean]\n"
3747 " time_stamp <%lx>\n"
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003748 " next_to_watch <%x>\n"
Auke Kok9d5c8242008-01-24 02:22:38 -08003749 " jiffies <%lx>\n"
3750 " desc.status <%x>\n",
Alexander Duyck2d064c02008-07-08 15:10:12 -07003751 tx_ring->queue_index,
Auke Kok9d5c8242008-01-24 02:22:38 -08003752 readl(adapter->hw.hw_addr + tx_ring->head),
3753 readl(adapter->hw.hw_addr + tx_ring->tail),
3754 tx_ring->next_to_use,
3755 tx_ring->next_to_clean,
Auke Kok9d5c8242008-01-24 02:22:38 -08003756 tx_ring->buffer_info[i].time_stamp,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003757 eop,
Auke Kok9d5c8242008-01-24 02:22:38 -08003758 jiffies,
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003759 eop_desc->wb.status);
Peter P Waskiewicz Jr661086d2008-07-08 15:06:51 -07003760 netif_stop_subqueue(netdev, tx_ring->queue_index);
Auke Kok9d5c8242008-01-24 02:22:38 -08003761 }
3762 }
3763 tx_ring->total_bytes += total_bytes;
3764 tx_ring->total_packets += total_packets;
Alexander Duycke21ed352008-07-08 15:07:24 -07003765 tx_ring->tx_stats.bytes += total_bytes;
3766 tx_ring->tx_stats.packets += total_packets;
Auke Kok9d5c8242008-01-24 02:22:38 -08003767 adapter->net_stats.tx_bytes += total_bytes;
3768 adapter->net_stats.tx_packets += total_packets;
Alexander Duyck0e014cb2008-12-26 01:33:18 -08003769 return (count < tx_ring->count);
Auke Kok9d5c8242008-01-24 02:22:38 -08003770}
3771
Alexander Duyckd3352522008-07-08 15:12:13 -07003772#ifdef CONFIG_IGB_LRO
3773 /**
3774 * igb_get_skb_hdr - helper function for LRO header processing
3775 * @skb: pointer to sk_buff to be added to LRO packet
3776 * @iphdr: pointer to ip header structure
3777 * @tcph: pointer to tcp header structure
3778 * @hdr_flags: pointer to header flags
3779 * @priv: pointer to the receive descriptor for the current sk_buff
3780 **/
3781static int igb_get_skb_hdr(struct sk_buff *skb, void **iphdr, void **tcph,
3782 u64 *hdr_flags, void *priv)
3783{
3784 union e1000_adv_rx_desc *rx_desc = priv;
3785 u16 pkt_type = rx_desc->wb.lower.lo_dword.pkt_info &
3786 (E1000_RXDADV_PKTTYPE_IPV4 | E1000_RXDADV_PKTTYPE_TCP);
3787
3788 /* Verify that this is a valid IPv4 TCP packet */
3789 if (pkt_type != (E1000_RXDADV_PKTTYPE_IPV4 |
3790 E1000_RXDADV_PKTTYPE_TCP))
3791 return -1;
3792
3793 /* Set network headers */
3794 skb_reset_network_header(skb);
3795 skb_set_transport_header(skb, ip_hdrlen(skb));
3796 *iphdr = ip_hdr(skb);
3797 *tcph = tcp_hdr(skb);
3798 *hdr_flags = LRO_IPV4 | LRO_TCP;
3799
3800 return 0;
3801
3802}
3803#endif /* CONFIG_IGB_LRO */
Auke Kok9d5c8242008-01-24 02:22:38 -08003804
3805/**
3806 * igb_receive_skb - helper function to handle rx indications
Alexander Duyckd3352522008-07-08 15:12:13 -07003807 * @ring: pointer to receive ring receving this packet
Auke Kok9d5c8242008-01-24 02:22:38 -08003808 * @status: descriptor status field as written by hardware
3809 * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
3810 * @skb: pointer to sk_buff to be indicated to stack
3811 **/
Alexander Duyckd3352522008-07-08 15:12:13 -07003812static void igb_receive_skb(struct igb_ring *ring, u8 status,
3813 union e1000_adv_rx_desc * rx_desc,
3814 struct sk_buff *skb)
Auke Kok9d5c8242008-01-24 02:22:38 -08003815{
Alexander Duyckd3352522008-07-08 15:12:13 -07003816 struct igb_adapter * adapter = ring->adapter;
3817 bool vlan_extracted = (adapter->vlgrp && (status & E1000_RXD_STAT_VP));
3818
3819#ifdef CONFIG_IGB_LRO
3820 if (adapter->netdev->features & NETIF_F_LRO &&
3821 skb->ip_summed == CHECKSUM_UNNECESSARY) {
3822 if (vlan_extracted)
3823 lro_vlan_hwaccel_receive_skb(&ring->lro_mgr, skb,
3824 adapter->vlgrp,
3825 le16_to_cpu(rx_desc->wb.upper.vlan),
3826 rx_desc);
3827 else
3828 lro_receive_skb(&ring->lro_mgr,skb, rx_desc);
3829 ring->lro_used = 1;
3830 } else {
3831#endif
3832 if (vlan_extracted)
3833 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
3834 le16_to_cpu(rx_desc->wb.upper.vlan));
3835 else
3836
3837 netif_receive_skb(skb);
3838#ifdef CONFIG_IGB_LRO
3839 }
3840#endif
Auke Kok9d5c8242008-01-24 02:22:38 -08003841}
3842
3843
3844static inline void igb_rx_checksum_adv(struct igb_adapter *adapter,
3845 u32 status_err, struct sk_buff *skb)
3846{
3847 skb->ip_summed = CHECKSUM_NONE;
3848
3849 /* Ignore Checksum bit is set or checksum is disabled through ethtool */
3850 if ((status_err & E1000_RXD_STAT_IXSM) || !adapter->rx_csum)
3851 return;
3852 /* TCP/UDP checksum error bit is set */
3853 if (status_err &
3854 (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
3855 /* let the stack verify checksum errors */
3856 adapter->hw_csum_err++;
3857 return;
3858 }
3859 /* It must be a TCP or UDP packet with a valid checksum */
3860 if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
3861 skb->ip_summed = CHECKSUM_UNNECESSARY;
3862
3863 adapter->hw_csum_good++;
3864}
3865
Mitch Williams3b644cf2008-06-27 10:59:48 -07003866static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
3867 int *work_done, int budget)
Auke Kok9d5c8242008-01-24 02:22:38 -08003868{
Mitch Williams3b644cf2008-06-27 10:59:48 -07003869 struct igb_adapter *adapter = rx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08003870 struct net_device *netdev = adapter->netdev;
3871 struct pci_dev *pdev = adapter->pdev;
3872 union e1000_adv_rx_desc *rx_desc , *next_rxd;
3873 struct igb_buffer *buffer_info , *next_buffer;
3874 struct sk_buff *skb;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003875 unsigned int i;
Auke Kok9d5c8242008-01-24 02:22:38 -08003876 u32 length, hlen, staterr;
3877 bool cleaned = false;
3878 int cleaned_count = 0;
3879 unsigned int total_bytes = 0, total_packets = 0;
3880
3881 i = rx_ring->next_to_clean;
3882 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
3883 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
3884
3885 while (staterr & E1000_RXD_STAT_DD) {
3886 if (*work_done >= budget)
3887 break;
3888 (*work_done)++;
3889 buffer_info = &rx_ring->buffer_info[i];
3890
3891 /* HW will not DMA in data larger than the given buffer, even
3892 * if it parses the (NFS, of course) header to be larger. In
3893 * that case, it fills the header buffer and spills the rest
3894 * into the page.
3895 */
Al Viro7deb07b2008-03-16 22:43:06 +00003896 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
3897 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9d5c8242008-01-24 02:22:38 -08003898 if (hlen > adapter->rx_ps_hdr_size)
3899 hlen = adapter->rx_ps_hdr_size;
3900
3901 length = le16_to_cpu(rx_desc->wb.upper.length);
3902 cleaned = true;
3903 cleaned_count++;
3904
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003905 skb = buffer_info->skb;
3906 prefetch(skb->data - NET_IP_ALIGN);
3907 buffer_info->skb = NULL;
3908 if (!adapter->rx_ps_hdr_size) {
3909 pci_unmap_single(pdev, buffer_info->dma,
3910 adapter->rx_buffer_len +
3911 NET_IP_ALIGN,
3912 PCI_DMA_FROMDEVICE);
3913 skb_put(skb, length);
3914 goto send_up;
Auke Kok9d5c8242008-01-24 02:22:38 -08003915 }
3916
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003917 if (!skb_shinfo(skb)->nr_frags) {
3918 pci_unmap_single(pdev, buffer_info->dma,
3919 adapter->rx_ps_hdr_size +
3920 NET_IP_ALIGN,
3921 PCI_DMA_FROMDEVICE);
3922 skb_put(skb, hlen);
3923 }
3924
3925 if (length) {
Auke Kok9d5c8242008-01-24 02:22:38 -08003926 pci_unmap_page(pdev, buffer_info->page_dma,
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003927 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9d5c8242008-01-24 02:22:38 -08003928 buffer_info->page_dma = 0;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003929
3930 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
3931 buffer_info->page,
3932 buffer_info->page_offset,
3933 length);
3934
3935 if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) ||
3936 (page_count(buffer_info->page) != 1))
3937 buffer_info->page = NULL;
3938 else
3939 get_page(buffer_info->page);
Auke Kok9d5c8242008-01-24 02:22:38 -08003940
3941 skb->len += length;
3942 skb->data_len += length;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003943
Auke Kok9d5c8242008-01-24 02:22:38 -08003944 skb->truesize += length;
Auke Kok9d5c8242008-01-24 02:22:38 -08003945 }
3946send_up:
Auke Kok9d5c8242008-01-24 02:22:38 -08003947 i++;
3948 if (i == rx_ring->count)
3949 i = 0;
3950 next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
3951 prefetch(next_rxd);
3952 next_buffer = &rx_ring->buffer_info[i];
3953
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003954 if (!(staterr & E1000_RXD_STAT_EOP)) {
Alexander Duyckb2d56532008-11-20 00:47:34 -08003955 buffer_info->skb = next_buffer->skb;
3956 buffer_info->dma = next_buffer->dma;
3957 next_buffer->skb = skb;
3958 next_buffer->dma = 0;
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003959 goto next_desc;
3960 }
3961
Auke Kok9d5c8242008-01-24 02:22:38 -08003962 if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
3963 dev_kfree_skb_irq(skb);
3964 goto next_desc;
3965 }
Auke Kok9d5c8242008-01-24 02:22:38 -08003966
3967 total_bytes += skb->len;
3968 total_packets++;
3969
3970 igb_rx_checksum_adv(adapter, staterr, skb);
3971
3972 skb->protocol = eth_type_trans(skb, netdev);
3973
Alexander Duyckd3352522008-07-08 15:12:13 -07003974 igb_receive_skb(rx_ring, staterr, rx_desc, skb);
Auke Kok9d5c8242008-01-24 02:22:38 -08003975
Auke Kok9d5c8242008-01-24 02:22:38 -08003976next_desc:
3977 rx_desc->wb.upper.status_error = 0;
3978
3979 /* return some buffers to hardware, one at a time is too slow */
3980 if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
Mitch Williams3b644cf2008-06-27 10:59:48 -07003981 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
Auke Kok9d5c8242008-01-24 02:22:38 -08003982 cleaned_count = 0;
3983 }
3984
3985 /* use prefetched values */
3986 rx_desc = next_rxd;
3987 buffer_info = next_buffer;
3988
3989 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
3990 }
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07003991
Auke Kok9d5c8242008-01-24 02:22:38 -08003992 rx_ring->next_to_clean = i;
3993 cleaned_count = IGB_DESC_UNUSED(rx_ring);
3994
Alexander Duyckd3352522008-07-08 15:12:13 -07003995#ifdef CONFIG_IGB_LRO
3996 if (rx_ring->lro_used) {
3997 lro_flush_all(&rx_ring->lro_mgr);
3998 rx_ring->lro_used = 0;
3999 }
4000#endif
4001
Auke Kok9d5c8242008-01-24 02:22:38 -08004002 if (cleaned_count)
Mitch Williams3b644cf2008-06-27 10:59:48 -07004003 igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
Auke Kok9d5c8242008-01-24 02:22:38 -08004004
4005 rx_ring->total_packets += total_packets;
4006 rx_ring->total_bytes += total_bytes;
4007 rx_ring->rx_stats.packets += total_packets;
4008 rx_ring->rx_stats.bytes += total_bytes;
4009 adapter->net_stats.rx_bytes += total_bytes;
4010 adapter->net_stats.rx_packets += total_packets;
4011 return cleaned;
4012}
4013
4014
4015/**
4016 * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
4017 * @adapter: address of board private structure
4018 **/
Mitch Williams3b644cf2008-06-27 10:59:48 -07004019static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
Auke Kok9d5c8242008-01-24 02:22:38 -08004020 int cleaned_count)
4021{
Mitch Williams3b644cf2008-06-27 10:59:48 -07004022 struct igb_adapter *adapter = rx_ring->adapter;
Auke Kok9d5c8242008-01-24 02:22:38 -08004023 struct net_device *netdev = adapter->netdev;
4024 struct pci_dev *pdev = adapter->pdev;
4025 union e1000_adv_rx_desc *rx_desc;
4026 struct igb_buffer *buffer_info;
4027 struct sk_buff *skb;
4028 unsigned int i;
4029
4030 i = rx_ring->next_to_use;
4031 buffer_info = &rx_ring->buffer_info[i];
4032
4033 while (cleaned_count--) {
4034 rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
4035
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07004036 if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004037 if (!buffer_info->page) {
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07004038 buffer_info->page = alloc_page(GFP_ATOMIC);
4039 if (!buffer_info->page) {
4040 adapter->alloc_rx_buff_failed++;
4041 goto no_buffers;
4042 }
4043 buffer_info->page_offset = 0;
4044 } else {
4045 buffer_info->page_offset ^= PAGE_SIZE / 2;
Auke Kok9d5c8242008-01-24 02:22:38 -08004046 }
4047 buffer_info->page_dma =
4048 pci_map_page(pdev,
4049 buffer_info->page,
Alexander Duyckbf36c1a2008-07-08 15:11:40 -07004050 buffer_info->page_offset,
4051 PAGE_SIZE / 2,
Auke Kok9d5c8242008-01-24 02:22:38 -08004052 PCI_DMA_FROMDEVICE);
4053 }
4054
4055 if (!buffer_info->skb) {
4056 int bufsz;
4057
4058 if (adapter->rx_ps_hdr_size)
4059 bufsz = adapter->rx_ps_hdr_size;
4060 else
4061 bufsz = adapter->rx_buffer_len;
4062 bufsz += NET_IP_ALIGN;
4063 skb = netdev_alloc_skb(netdev, bufsz);
4064
4065 if (!skb) {
4066 adapter->alloc_rx_buff_failed++;
4067 goto no_buffers;
4068 }
4069
4070 /* Make buffer alignment 2 beyond a 16 byte boundary
4071 * this will result in a 16 byte aligned IP header after
4072 * the 14 byte MAC header is removed
4073 */
4074 skb_reserve(skb, NET_IP_ALIGN);
4075
4076 buffer_info->skb = skb;
4077 buffer_info->dma = pci_map_single(pdev, skb->data,
4078 bufsz,
4079 PCI_DMA_FROMDEVICE);
4080
4081 }
4082 /* Refresh the desc even if buffer_addrs didn't change because
4083 * each write-back erases this info. */
4084 if (adapter->rx_ps_hdr_size) {
4085 rx_desc->read.pkt_addr =
4086 cpu_to_le64(buffer_info->page_dma);
4087 rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
4088 } else {
4089 rx_desc->read.pkt_addr =
4090 cpu_to_le64(buffer_info->dma);
4091 rx_desc->read.hdr_addr = 0;
4092 }
4093
4094 i++;
4095 if (i == rx_ring->count)
4096 i = 0;
4097 buffer_info = &rx_ring->buffer_info[i];
4098 }
4099
4100no_buffers:
4101 if (rx_ring->next_to_use != i) {
4102 rx_ring->next_to_use = i;
4103 if (i == 0)
4104 i = (rx_ring->count - 1);
4105 else
4106 i--;
4107
4108 /* Force memory writes to complete before letting h/w
4109 * know there are new descriptors to fetch. (Only
4110 * applicable for weak-ordered memory model archs,
4111 * such as IA-64). */
4112 wmb();
4113 writel(i, adapter->hw.hw_addr + rx_ring->tail);
4114 }
4115}
4116
4117/**
4118 * igb_mii_ioctl -
4119 * @netdev:
4120 * @ifreq:
4121 * @cmd:
4122 **/
4123static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4124{
4125 struct igb_adapter *adapter = netdev_priv(netdev);
4126 struct mii_ioctl_data *data = if_mii(ifr);
4127
4128 if (adapter->hw.phy.media_type != e1000_media_type_copper)
4129 return -EOPNOTSUPP;
4130
4131 switch (cmd) {
4132 case SIOCGMIIPHY:
4133 data->phy_id = adapter->hw.phy.addr;
4134 break;
4135 case SIOCGMIIREG:
4136 if (!capable(CAP_NET_ADMIN))
4137 return -EPERM;
Alexander Duyckf5f4cf02008-11-21 21:30:24 -08004138 if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
4139 &data->val_out))
Auke Kok9d5c8242008-01-24 02:22:38 -08004140 return -EIO;
4141 break;
4142 case SIOCSMIIREG:
4143 default:
4144 return -EOPNOTSUPP;
4145 }
4146 return 0;
4147}
4148
4149/**
4150 * igb_ioctl -
4151 * @netdev:
4152 * @ifreq:
4153 * @cmd:
4154 **/
4155static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4156{
4157 switch (cmd) {
4158 case SIOCGMIIPHY:
4159 case SIOCGMIIREG:
4160 case SIOCSMIIREG:
4161 return igb_mii_ioctl(netdev, ifr, cmd);
4162 default:
4163 return -EOPNOTSUPP;
4164 }
4165}
4166
4167static void igb_vlan_rx_register(struct net_device *netdev,
4168 struct vlan_group *grp)
4169{
4170 struct igb_adapter *adapter = netdev_priv(netdev);
4171 struct e1000_hw *hw = &adapter->hw;
4172 u32 ctrl, rctl;
4173
4174 igb_irq_disable(adapter);
4175 adapter->vlgrp = grp;
4176
4177 if (grp) {
4178 /* enable VLAN tag insert/strip */
4179 ctrl = rd32(E1000_CTRL);
4180 ctrl |= E1000_CTRL_VME;
4181 wr32(E1000_CTRL, ctrl);
4182
4183 /* enable VLAN receive filtering */
4184 rctl = rd32(E1000_RCTL);
Auke Kok9d5c8242008-01-24 02:22:38 -08004185 rctl &= ~E1000_RCTL_CFIEN;
4186 wr32(E1000_RCTL, rctl);
4187 igb_update_mng_vlan(adapter);
4188 wr32(E1000_RLPML,
4189 adapter->max_frame_size + VLAN_TAG_SIZE);
4190 } else {
4191 /* disable VLAN tag insert/strip */
4192 ctrl = rd32(E1000_CTRL);
4193 ctrl &= ~E1000_CTRL_VME;
4194 wr32(E1000_CTRL, ctrl);
4195
Auke Kok9d5c8242008-01-24 02:22:38 -08004196 if (adapter->mng_vlan_id != (u16)IGB_MNG_VLAN_NONE) {
4197 igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
4198 adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
4199 }
4200 wr32(E1000_RLPML,
4201 adapter->max_frame_size);
4202 }
4203
4204 if (!test_bit(__IGB_DOWN, &adapter->state))
4205 igb_irq_enable(adapter);
4206}
4207
4208static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
4209{
4210 struct igb_adapter *adapter = netdev_priv(netdev);
4211 struct e1000_hw *hw = &adapter->hw;
4212 u32 vfta, index;
4213
4214 if ((adapter->hw.mng_cookie.status &
4215 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
4216 (vid == adapter->mng_vlan_id))
4217 return;
4218 /* add VID to filter table */
4219 index = (vid >> 5) & 0x7F;
4220 vfta = array_rd32(E1000_VFTA, index);
4221 vfta |= (1 << (vid & 0x1F));
4222 igb_write_vfta(&adapter->hw, index, vfta);
4223}
4224
4225static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
4226{
4227 struct igb_adapter *adapter = netdev_priv(netdev);
4228 struct e1000_hw *hw = &adapter->hw;
4229 u32 vfta, index;
4230
4231 igb_irq_disable(adapter);
4232 vlan_group_set_device(adapter->vlgrp, vid, NULL);
4233
4234 if (!test_bit(__IGB_DOWN, &adapter->state))
4235 igb_irq_enable(adapter);
4236
4237 if ((adapter->hw.mng_cookie.status &
4238 E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
4239 (vid == adapter->mng_vlan_id)) {
4240 /* release control to f/w */
4241 igb_release_hw_control(adapter);
4242 return;
4243 }
4244
4245 /* remove VID from filter table */
4246 index = (vid >> 5) & 0x7F;
4247 vfta = array_rd32(E1000_VFTA, index);
4248 vfta &= ~(1 << (vid & 0x1F));
4249 igb_write_vfta(&adapter->hw, index, vfta);
4250}
4251
4252static void igb_restore_vlan(struct igb_adapter *adapter)
4253{
4254 igb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
4255
4256 if (adapter->vlgrp) {
4257 u16 vid;
4258 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4259 if (!vlan_group_get_device(adapter->vlgrp, vid))
4260 continue;
4261 igb_vlan_rx_add_vid(adapter->netdev, vid);
4262 }
4263 }
4264}
4265
4266int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
4267{
4268 struct e1000_mac_info *mac = &adapter->hw.mac;
4269
4270 mac->autoneg = 0;
4271
4272 /* Fiber NICs only allow 1000 gbps Full duplex */
4273 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
4274 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
4275 dev_err(&adapter->pdev->dev,
4276 "Unsupported Speed/Duplex configuration\n");
4277 return -EINVAL;
4278 }
4279
4280 switch (spddplx) {
4281 case SPEED_10 + DUPLEX_HALF:
4282 mac->forced_speed_duplex = ADVERTISE_10_HALF;
4283 break;
4284 case SPEED_10 + DUPLEX_FULL:
4285 mac->forced_speed_duplex = ADVERTISE_10_FULL;
4286 break;
4287 case SPEED_100 + DUPLEX_HALF:
4288 mac->forced_speed_duplex = ADVERTISE_100_HALF;
4289 break;
4290 case SPEED_100 + DUPLEX_FULL:
4291 mac->forced_speed_duplex = ADVERTISE_100_FULL;
4292 break;
4293 case SPEED_1000 + DUPLEX_FULL:
4294 mac->autoneg = 1;
4295 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
4296 break;
4297 case SPEED_1000 + DUPLEX_HALF: /* not supported */
4298 default:
4299 dev_err(&adapter->pdev->dev,
4300 "Unsupported Speed/Duplex configuration\n");
4301 return -EINVAL;
4302 }
4303 return 0;
4304}
4305
4306
4307static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
4308{
4309 struct net_device *netdev = pci_get_drvdata(pdev);
4310 struct igb_adapter *adapter = netdev_priv(netdev);
4311 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck2d064c02008-07-08 15:10:12 -07004312 u32 ctrl, rctl, status;
Auke Kok9d5c8242008-01-24 02:22:38 -08004313 u32 wufc = adapter->wol;
4314#ifdef CONFIG_PM
4315 int retval = 0;
4316#endif
4317
4318 netif_device_detach(netdev);
4319
Alexander Duycka88f10e2008-07-08 15:13:38 -07004320 if (netif_running(netdev))
4321 igb_close(netdev);
4322
4323 igb_reset_interrupt_capability(adapter);
4324
4325 igb_free_queues(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08004326
4327#ifdef CONFIG_PM
4328 retval = pci_save_state(pdev);
4329 if (retval)
4330 return retval;
4331#endif
4332
4333 status = rd32(E1000_STATUS);
4334 if (status & E1000_STATUS_LU)
4335 wufc &= ~E1000_WUFC_LNKC;
4336
4337 if (wufc) {
4338 igb_setup_rctl(adapter);
4339 igb_set_multi(netdev);
4340
4341 /* turn on all-multi mode if wake on multicast is enabled */
4342 if (wufc & E1000_WUFC_MC) {
4343 rctl = rd32(E1000_RCTL);
4344 rctl |= E1000_RCTL_MPE;
4345 wr32(E1000_RCTL, rctl);
4346 }
4347
4348 ctrl = rd32(E1000_CTRL);
4349 /* advertise wake from D3Cold */
4350 #define E1000_CTRL_ADVD3WUC 0x00100000
4351 /* phy power management enable */
4352 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
4353 ctrl |= E1000_CTRL_ADVD3WUC;
4354 wr32(E1000_CTRL, ctrl);
4355
Auke Kok9d5c8242008-01-24 02:22:38 -08004356 /* Allow time for pending master requests to run */
4357 igb_disable_pcie_master(&adapter->hw);
4358
4359 wr32(E1000_WUC, E1000_WUC_PME_EN);
4360 wr32(E1000_WUFC, wufc);
Auke Kok9d5c8242008-01-24 02:22:38 -08004361 } else {
4362 wr32(E1000_WUC, 0);
4363 wr32(E1000_WUFC, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08004364 }
4365
Alexander Duyck2d064c02008-07-08 15:10:12 -07004366 /* make sure adapter isn't asleep if manageability/wol is enabled */
4367 if (wufc || adapter->en_mng_pt) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004368 pci_enable_wake(pdev, PCI_D3hot, 1);
4369 pci_enable_wake(pdev, PCI_D3cold, 1);
Alexander Duyck2d064c02008-07-08 15:10:12 -07004370 } else {
4371 igb_shutdown_fiber_serdes_link_82575(hw);
4372 pci_enable_wake(pdev, PCI_D3hot, 0);
4373 pci_enable_wake(pdev, PCI_D3cold, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -08004374 }
4375
4376 /* Release control of h/w to f/w. If f/w is AMT enabled, this
4377 * would have already happened in close and is redundant. */
4378 igb_release_hw_control(adapter);
4379
4380 pci_disable_device(pdev);
4381
4382 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4383
4384 return 0;
4385}
4386
4387#ifdef CONFIG_PM
4388static int igb_resume(struct pci_dev *pdev)
4389{
4390 struct net_device *netdev = pci_get_drvdata(pdev);
4391 struct igb_adapter *adapter = netdev_priv(netdev);
4392 struct e1000_hw *hw = &adapter->hw;
4393 u32 err;
4394
4395 pci_set_power_state(pdev, PCI_D0);
4396 pci_restore_state(pdev);
Taku Izumi42bfd33a2008-06-20 12:10:30 +09004397
4398 if (adapter->need_ioport)
4399 err = pci_enable_device(pdev);
4400 else
4401 err = pci_enable_device_mem(pdev);
Auke Kok9d5c8242008-01-24 02:22:38 -08004402 if (err) {
4403 dev_err(&pdev->dev,
4404 "igb: Cannot enable PCI device from suspend\n");
4405 return err;
4406 }
4407 pci_set_master(pdev);
4408
4409 pci_enable_wake(pdev, PCI_D3hot, 0);
4410 pci_enable_wake(pdev, PCI_D3cold, 0);
4411
Alexander Duycka88f10e2008-07-08 15:13:38 -07004412 igb_set_interrupt_capability(adapter);
4413
4414 if (igb_alloc_queues(adapter)) {
4415 dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
4416 return -ENOMEM;
Auke Kok9d5c8242008-01-24 02:22:38 -08004417 }
4418
4419 /* e1000_power_up_phy(adapter); */
4420
4421 igb_reset(adapter);
4422 wr32(E1000_WUS, ~0);
4423
Alexander Duycka88f10e2008-07-08 15:13:38 -07004424 if (netif_running(netdev)) {
4425 err = igb_open(netdev);
4426 if (err)
4427 return err;
4428 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004429
4430 netif_device_attach(netdev);
4431
4432 /* let the f/w know that the h/w is now under the control of the
4433 * driver. */
4434 igb_get_hw_control(adapter);
4435
4436 return 0;
4437}
4438#endif
4439
4440static void igb_shutdown(struct pci_dev *pdev)
4441{
4442 igb_suspend(pdev, PMSG_SUSPEND);
4443}
4444
4445#ifdef CONFIG_NET_POLL_CONTROLLER
4446/*
4447 * Polling 'interrupt' - used by things like netconsole to send skbs
4448 * without having to re-enable interrupts. It's not called while
4449 * the interrupt routine is executing.
4450 */
4451static void igb_netpoll(struct net_device *netdev)
4452{
4453 struct igb_adapter *adapter = netdev_priv(netdev);
4454 int i;
4455 int work_done = 0;
4456
4457 igb_irq_disable(adapter);
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004458 adapter->flags |= IGB_FLAG_IN_NETPOLL;
4459
Auke Kok9d5c8242008-01-24 02:22:38 -08004460 for (i = 0; i < adapter->num_tx_queues; i++)
Mitch Williams3b644cf2008-06-27 10:59:48 -07004461 igb_clean_tx_irq(&adapter->tx_ring[i]);
Auke Kok9d5c8242008-01-24 02:22:38 -08004462
4463 for (i = 0; i < adapter->num_rx_queues; i++)
Mitch Williams3b644cf2008-06-27 10:59:48 -07004464 igb_clean_rx_irq_adv(&adapter->rx_ring[i],
Auke Kok9d5c8242008-01-24 02:22:38 -08004465 &work_done,
4466 adapter->rx_ring[i].napi.weight);
4467
Alexander Duyck7dfc16f2008-07-08 15:10:46 -07004468 adapter->flags &= ~IGB_FLAG_IN_NETPOLL;
Auke Kok9d5c8242008-01-24 02:22:38 -08004469 igb_irq_enable(adapter);
4470}
4471#endif /* CONFIG_NET_POLL_CONTROLLER */
4472
4473/**
4474 * igb_io_error_detected - called when PCI error is detected
4475 * @pdev: Pointer to PCI device
4476 * @state: The current pci connection state
4477 *
4478 * This function is called after a PCI bus error affecting
4479 * this device has been detected.
4480 */
4481static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
4482 pci_channel_state_t state)
4483{
4484 struct net_device *netdev = pci_get_drvdata(pdev);
4485 struct igb_adapter *adapter = netdev_priv(netdev);
4486
4487 netif_device_detach(netdev);
4488
4489 if (netif_running(netdev))
4490 igb_down(adapter);
4491 pci_disable_device(pdev);
4492
4493 /* Request a slot slot reset. */
4494 return PCI_ERS_RESULT_NEED_RESET;
4495}
4496
4497/**
4498 * igb_io_slot_reset - called after the pci bus has been reset.
4499 * @pdev: Pointer to PCI device
4500 *
4501 * Restart the card from scratch, as if from a cold-boot. Implementation
4502 * resembles the first-half of the igb_resume routine.
4503 */
4504static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
4505{
4506 struct net_device *netdev = pci_get_drvdata(pdev);
4507 struct igb_adapter *adapter = netdev_priv(netdev);
4508 struct e1000_hw *hw = &adapter->hw;
Alexander Duyck40a914f2008-11-27 00:24:37 -08004509 pci_ers_result_t result;
Taku Izumi42bfd33a2008-06-20 12:10:30 +09004510 int err;
Auke Kok9d5c8242008-01-24 02:22:38 -08004511
Taku Izumi42bfd33a2008-06-20 12:10:30 +09004512 if (adapter->need_ioport)
4513 err = pci_enable_device(pdev);
4514 else
4515 err = pci_enable_device_mem(pdev);
Alexander Duyck40a914f2008-11-27 00:24:37 -08004516
Taku Izumi42bfd33a2008-06-20 12:10:30 +09004517 if (err) {
Auke Kok9d5c8242008-01-24 02:22:38 -08004518 dev_err(&pdev->dev,
4519 "Cannot re-enable PCI device after reset.\n");
Alexander Duyck40a914f2008-11-27 00:24:37 -08004520 result = PCI_ERS_RESULT_DISCONNECT;
4521 } else {
4522 pci_set_master(pdev);
4523 pci_restore_state(pdev);
4524
4525 pci_enable_wake(pdev, PCI_D3hot, 0);
4526 pci_enable_wake(pdev, PCI_D3cold, 0);
4527
4528 igb_reset(adapter);
4529 wr32(E1000_WUS, ~0);
4530 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9d5c8242008-01-24 02:22:38 -08004531 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004532
Jeff Kirsherea943d42008-12-11 20:34:19 -08004533 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4534 if (err) {
4535 dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
4536 "failed 0x%0x\n", err);
4537 /* non-fatal, continue */
4538 }
Auke Kok9d5c8242008-01-24 02:22:38 -08004539
Alexander Duyck40a914f2008-11-27 00:24:37 -08004540 return result;
Auke Kok9d5c8242008-01-24 02:22:38 -08004541}
4542
4543/**
4544 * igb_io_resume - called when traffic can start flowing again.
4545 * @pdev: Pointer to PCI device
4546 *
4547 * This callback is called when the error recovery driver tells us that
4548 * its OK to resume normal operation. Implementation resembles the
4549 * second-half of the igb_resume routine.
4550 */
4551static void igb_io_resume(struct pci_dev *pdev)
4552{
4553 struct net_device *netdev = pci_get_drvdata(pdev);
4554 struct igb_adapter *adapter = netdev_priv(netdev);
4555
Auke Kok9d5c8242008-01-24 02:22:38 -08004556 if (netif_running(netdev)) {
4557 if (igb_up(adapter)) {
4558 dev_err(&pdev->dev, "igb_up failed after reset\n");
4559 return;
4560 }
4561 }
4562
4563 netif_device_attach(netdev);
4564
4565 /* let the f/w know that the h/w is now under the control of the
4566 * driver. */
4567 igb_get_hw_control(adapter);
Auke Kok9d5c8242008-01-24 02:22:38 -08004568}
4569
4570/* igb_main.c */