ixgb: remove lltx support and update tx routine
[deliverable/linux.git] / drivers / net / ixgb / ixgb_main.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2
0abb6eb1
AK
3 Intel PRO/10GbE Linux driver
4 Copyright(c) 1999 - 2006 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
1da177e4 13 more details.
0abb6eb1 14
1da177e4 15 You should have received a copy of the GNU General Public License along with
0abb6eb1
AK
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
1da177e4
LT
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
0abb6eb1 24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
1da177e4
LT
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "ixgb.h"
30
1da177e4 31char ixgb_driver_name[] = "ixgb";
e9ab1d14 32static char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
1da177e4
LT
33
34#ifndef CONFIG_IXGB_NAPI
35#define DRIVERNAPI
36#else
37#define DRIVERNAPI "-NAPI"
38#endif
8b32e63d 39#define DRV_VERSION "1.0.126-k4"DRIVERNAPI
273dc74e
SH
40const char ixgb_driver_version[] = DRV_VERSION;
41static const char ixgb_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
1da177e4
LT
42
43/* ixgb_pci_tbl - PCI Device ID Table
44 *
45 * Wildcard entries (PCI_ANY_ID) should come last
46 * Last entry must be all 0s
47 *
48 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
49 * Class, Class Mask, private data (not used) }
50 */
51static struct pci_device_id ixgb_pci_tbl[] = {
52 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX,
53 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
940829e2
AK
54 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_CX4,
55 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1da177e4
LT
56 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR,
57 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
58 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_LR,
59 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
60
61 /* required last entry */
62 {0,}
63};
64
65MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
66
67/* Local Function Prototypes */
68
69int ixgb_up(struct ixgb_adapter *adapter);
446490ca 70void ixgb_down(struct ixgb_adapter *adapter, bool kill_watchdog);
1da177e4
LT
71void ixgb_reset(struct ixgb_adapter *adapter);
72int ixgb_setup_tx_resources(struct ixgb_adapter *adapter);
73int ixgb_setup_rx_resources(struct ixgb_adapter *adapter);
74void ixgb_free_tx_resources(struct ixgb_adapter *adapter);
75void ixgb_free_rx_resources(struct ixgb_adapter *adapter);
76void ixgb_update_stats(struct ixgb_adapter *adapter);
77
78static int ixgb_init_module(void);
79static void ixgb_exit_module(void);
80static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
81static void __devexit ixgb_remove(struct pci_dev *pdev);
82static int ixgb_sw_init(struct ixgb_adapter *adapter);
83static int ixgb_open(struct net_device *netdev);
84static int ixgb_close(struct net_device *netdev);
85static void ixgb_configure_tx(struct ixgb_adapter *adapter);
86static void ixgb_configure_rx(struct ixgb_adapter *adapter);
87static void ixgb_setup_rctl(struct ixgb_adapter *adapter);
88static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter);
89static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter);
90static void ixgb_set_multi(struct net_device *netdev);
91static void ixgb_watchdog(unsigned long data);
92static int ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
93static struct net_device_stats *ixgb_get_stats(struct net_device *netdev);
94static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
95static int ixgb_set_mac(struct net_device *netdev, void *p);
7d12e780 96static irqreturn_t ixgb_intr(int irq, void *data);
446490ca 97static bool ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
ac79c82e 98
1da177e4 99#ifdef CONFIG_IXGB_NAPI
bea3348e 100static int ixgb_clean(struct napi_struct *napi, int budget);
446490ca
JP
101static bool ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
102 int *work_done, int work_to_do);
1da177e4 103#else
446490ca 104static bool ixgb_clean_rx_irq(struct ixgb_adapter *adapter);
1da177e4
LT
105#endif
106static void ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter);
1da177e4 107static void ixgb_tx_timeout(struct net_device *dev);
c4028958 108static void ixgb_tx_timeout_task(struct work_struct *work);
1da177e4
LT
109static void ixgb_vlan_rx_register(struct net_device *netdev,
110 struct vlan_group *grp);
222441a6
JP
111static void ixgb_vlan_rx_add_vid(struct net_device *netdev, u16 vid);
112static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid);
1da177e4
LT
113static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
114
1da177e4
LT
115#ifdef CONFIG_NET_POLL_CONTROLLER
116/* for netdump / net console */
117static void ixgb_netpoll(struct net_device *dev);
118#endif
119
01748fbb
LV
120static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
121 enum pci_channel_state state);
122static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev);
123static void ixgb_io_resume (struct pci_dev *pdev);
1da177e4 124
01748fbb
LV
125static struct pci_error_handlers ixgb_err_handler = {
126 .error_detected = ixgb_io_error_detected,
127 .slot_reset = ixgb_io_slot_reset,
128 .resume = ixgb_io_resume,
129};
130
1da177e4 131static struct pci_driver ixgb_driver = {
c2eba932 132 .name = ixgb_driver_name,
1da177e4 133 .id_table = ixgb_pci_tbl,
c2eba932
MC
134 .probe = ixgb_probe,
135 .remove = __devexit_p(ixgb_remove),
01748fbb 136 .err_handler = &ixgb_err_handler
1da177e4
LT
137};
138
139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
141MODULE_LICENSE("GPL");
01e5abc2 142MODULE_VERSION(DRV_VERSION);
1da177e4 143
ec9c3f5d
AK
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145static int debug = DEFAULT_DEBUG_LEVEL_SHIFT;
146module_param(debug, int, 0);
147MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
148
1da177e4
LT
149/**
150 * ixgb_init_module - Driver Registration Routine
151 *
152 * ixgb_init_module is the first routine called when the driver is
153 * loaded. All it does is register with the PCI subsystem.
154 **/
155
156static int __init
157ixgb_init_module(void)
158{
1da177e4
LT
159 printk(KERN_INFO "%s - version %s\n",
160 ixgb_driver_string, ixgb_driver_version);
161
162 printk(KERN_INFO "%s\n", ixgb_copyright);
163
29917620 164 return pci_register_driver(&ixgb_driver);
1da177e4
LT
165}
166
167module_init(ixgb_init_module);
168
169/**
170 * ixgb_exit_module - Driver Exit Cleanup Routine
171 *
172 * ixgb_exit_module is called just before the driver is removed
173 * from memory.
174 **/
175
176static void __exit
177ixgb_exit_module(void)
178{
1da177e4
LT
179 pci_unregister_driver(&ixgb_driver);
180}
181
182module_exit(ixgb_exit_module);
183
184/**
185 * ixgb_irq_disable - Mask off interrupt generation on the NIC
186 * @adapter: board private structure
187 **/
188
235949d1 189static void
1da177e4
LT
190ixgb_irq_disable(struct ixgb_adapter *adapter)
191{
1da177e4
LT
192 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
193 IXGB_WRITE_FLUSH(&adapter->hw);
194 synchronize_irq(adapter->pdev->irq);
195}
196
197/**
198 * ixgb_irq_enable - Enable default interrupt generation settings
199 * @adapter: board private structure
200 **/
201
235949d1 202static void
1da177e4
LT
203ixgb_irq_enable(struct ixgb_adapter *adapter)
204{
9c61a9dc
JB
205 u32 val = IXGB_INT_RXT0 | IXGB_INT_RXDMT0 |
206 IXGB_INT_TXDW | IXGB_INT_LSC;
207 if (adapter->hw.subsystem_vendor_id == SUN_SUBVENDOR_ID)
208 val |= IXGB_INT_GPI0;
209 IXGB_WRITE_REG(&adapter->hw, IMS, val);
210 IXGB_WRITE_FLUSH(&adapter->hw);
1da177e4
LT
211}
212
213int
214ixgb_up(struct ixgb_adapter *adapter)
215{
216 struct net_device *netdev = adapter->netdev;
fb136c07 217 int err, irq_flags = IRQF_SHARED;
1da177e4
LT
218 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
219 struct ixgb_hw *hw = &adapter->hw;
220
221 /* hardware has been reset, we need to reload some things */
222
8556f0d1 223 ixgb_rar_set(hw, netdev->dev_addr, 0);
1da177e4
LT
224 ixgb_set_multi(netdev);
225
226 ixgb_restore_vlan(adapter);
227
228 ixgb_configure_tx(adapter);
229 ixgb_setup_rctl(adapter);
230 ixgb_configure_rx(adapter);
231 ixgb_alloc_rx_buffers(adapter);
232
e59d1696
AK
233 /* disable interrupts and get the hardware into a known state */
234 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
235
fb136c07
AK
236 /* only enable MSI if bus is in PCI-X mode */
237 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_PCIX_MODE) {
238 err = pci_enable_msi(adapter->pdev);
239 if (!err) {
240 adapter->have_msi = 1;
241 irq_flags = 0;
242 }
1da177e4
LT
243 /* proceed to try to request regular interrupt */
244 }
1da177e4 245
fb136c07
AK
246 err = request_irq(adapter->pdev->irq, &ixgb_intr, irq_flags,
247 netdev->name, netdev);
248 if (err) {
249 if (adapter->have_msi)
250 pci_disable_msi(adapter->pdev);
ec9c3f5d
AK
251 DPRINTK(PROBE, ERR,
252 "Unable to allocate interrupt Error: %d\n", err);
1da177e4 253 return err;
ec9c3f5d 254 }
1da177e4 255
1da177e4
LT
256 if((hw->max_frame_size != max_frame) ||
257 (hw->max_frame_size !=
258 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
259
260 hw->max_frame_size = max_frame;
261
262 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
263
264 if(hw->max_frame_size >
265 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
222441a6 266 u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
1da177e4
LT
267
268 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
269 ctrl0 |= IXGB_CTRL0_JFE;
270 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
271 }
272 }
273 }
274
bab2bce7 275 clear_bit(__IXGB_DOWN, &adapter->flags);
1da177e4
LT
276
277#ifdef CONFIG_IXGB_NAPI
bea3348e 278 napi_enable(&adapter->napi);
1da177e4 279#endif
e59d1696
AK
280 ixgb_irq_enable(adapter);
281
bab2bce7
JB
282 mod_timer(&adapter->watchdog_timer, jiffies);
283
1da177e4
LT
284 return 0;
285}
286
287void
446490ca 288ixgb_down(struct ixgb_adapter *adapter, bool kill_watchdog)
1da177e4
LT
289{
290 struct net_device *netdev = adapter->netdev;
291
bab2bce7
JB
292 /* prevent the interrupt handler from restarting watchdog */
293 set_bit(__IXGB_DOWN, &adapter->flags);
294
49d85c50
DM
295#ifdef CONFIG_IXGB_NAPI
296 napi_disable(&adapter->napi);
49d85c50 297#endif
bab2bce7 298 /* waiting for NAPI to complete can re-enable interrupts */
1da177e4
LT
299 ixgb_irq_disable(adapter);
300 free_irq(adapter->pdev->irq, netdev);
fb136c07
AK
301
302 if (adapter->have_msi)
1da177e4
LT
303 pci_disable_msi(adapter->pdev);
304
1da177e4
LT
305 if(kill_watchdog)
306 del_timer_sync(&adapter->watchdog_timer);
49d85c50 307
1da177e4
LT
308 adapter->link_speed = 0;
309 adapter->link_duplex = 0;
310 netif_carrier_off(netdev);
311 netif_stop_queue(netdev);
312
313 ixgb_reset(adapter);
314 ixgb_clean_tx_ring(adapter);
315 ixgb_clean_rx_ring(adapter);
316}
317
318void
319ixgb_reset(struct ixgb_adapter *adapter)
320{
3fd7131f 321 struct ixgb_hw *hw = &adapter->hw;
1da177e4 322
3fd7131f
MW
323 ixgb_adapter_stop(hw);
324 if (!ixgb_init_hw(hw))
ec9c3f5d 325 DPRINTK(PROBE, ERR, "ixgb_init_hw failed.\n");
3fd7131f
MW
326
327 /* restore frame size information */
328 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
329 if (hw->max_frame_size >
330 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
331 u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
332 if (!(ctrl0 & IXGB_CTRL0_JFE)) {
333 ctrl0 |= IXGB_CTRL0_JFE;
334 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
335 }
336 }
1da177e4
LT
337}
338
339/**
340 * ixgb_probe - Device Initialization Routine
341 * @pdev: PCI device information struct
342 * @ent: entry in ixgb_pci_tbl
343 *
344 * Returns 0 on success, negative on failure
345 *
346 * ixgb_probe initializes an adapter identified by a pci_dev structure.
347 * The OS initialization, configuring of the adapter private structure,
348 * and a hardware reset occur.
349 **/
350
351static int __devinit
352ixgb_probe(struct pci_dev *pdev,
353 const struct pci_device_id *ent)
354{
355 struct net_device *netdev = NULL;
356 struct ixgb_adapter *adapter;
357 static int cards_found = 0;
1da177e4
LT
358 int pci_using_dac;
359 int i;
360 int err;
361
362 if((err = pci_enable_device(pdev)))
363 return err;
364
c91e468a
AS
365 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
366 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
1da177e4
LT
367 pci_using_dac = 1;
368 } else {
c91e468a
AS
369 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
370 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
ec9c3f5d
AK
371 printk(KERN_ERR
372 "ixgb: No usable DMA configuration, aborting\n");
c91e468a 373 goto err_dma_mask;
1da177e4
LT
374 }
375 pci_using_dac = 0;
376 }
377
378 if((err = pci_request_regions(pdev, ixgb_driver_name)))
c91e468a 379 goto err_request_regions;
1da177e4
LT
380
381 pci_set_master(pdev);
382
383 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
384 if(!netdev) {
385 err = -ENOMEM;
386 goto err_alloc_etherdev;
387 }
388
1da177e4
LT
389 SET_NETDEV_DEV(netdev, &pdev->dev);
390
391 pci_set_drvdata(pdev, netdev);
8908c6cd 392 adapter = netdev_priv(netdev);
1da177e4
LT
393 adapter->netdev = netdev;
394 adapter->pdev = pdev;
395 adapter->hw.back = adapter;
ec9c3f5d 396 adapter->msg_enable = netif_msg_init(debug, DEFAULT_DEBUG_LEVEL_SHIFT);
1da177e4 397
e539e466
JB
398 adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0),
399 pci_resource_len(pdev, BAR_0));
400 if (!adapter->hw.hw_addr) {
1da177e4
LT
401 err = -EIO;
402 goto err_ioremap;
403 }
404
405 for(i = BAR_1; i <= BAR_5; i++) {
406 if(pci_resource_len(pdev, i) == 0)
407 continue;
408 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
409 adapter->hw.io_base = pci_resource_start(pdev, i);
410 break;
411 }
412 }
413
414 netdev->open = &ixgb_open;
415 netdev->stop = &ixgb_close;
416 netdev->hard_start_xmit = &ixgb_xmit_frame;
417 netdev->get_stats = &ixgb_get_stats;
418 netdev->set_multicast_list = &ixgb_set_multi;
419 netdev->set_mac_address = &ixgb_set_mac;
420 netdev->change_mtu = &ixgb_change_mtu;
421 ixgb_set_ethtool_ops(netdev);
422 netdev->tx_timeout = &ixgb_tx_timeout;
9b8118df 423 netdev->watchdog_timeo = 5 * HZ;
1da177e4 424#ifdef CONFIG_IXGB_NAPI
bea3348e 425 netif_napi_add(netdev, &adapter->napi, ixgb_clean, 64);
1da177e4
LT
426#endif
427 netdev->vlan_rx_register = ixgb_vlan_rx_register;
428 netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
429 netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
430#ifdef CONFIG_NET_POLL_CONTROLLER
431 netdev->poll_controller = ixgb_netpoll;
432#endif
433
0eb5a34c 434 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1da177e4
LT
435
436 adapter->bd_number = cards_found;
437 adapter->link_speed = 0;
438 adapter->link_duplex = 0;
439
440 /* setup the private structure */
441
442 if((err = ixgb_sw_init(adapter)))
443 goto err_sw_init;
444
445 netdev->features = NETIF_F_SG |
446 NETIF_F_HW_CSUM |
447 NETIF_F_HW_VLAN_TX |
448 NETIF_F_HW_VLAN_RX |
449 NETIF_F_HW_VLAN_FILTER;
1da177e4 450 netdev->features |= NETIF_F_TSO;
1da177e4
LT
451
452 if(pci_using_dac)
453 netdev->features |= NETIF_F_HIGHDMA;
454
455 /* make sure the EEPROM is good */
456
457 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
ec9c3f5d 458 DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
1da177e4
LT
459 err = -EIO;
460 goto err_eeprom;
461 }
462
463 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
df859c51 464 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
1da177e4 465
df859c51 466 if(!is_valid_ether_addr(netdev->perm_addr)) {
ec9c3f5d 467 DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
1da177e4
LT
468 err = -EIO;
469 goto err_eeprom;
470 }
471
472 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
473
474 init_timer(&adapter->watchdog_timer);
475 adapter->watchdog_timer.function = &ixgb_watchdog;
476 adapter->watchdog_timer.data = (unsigned long)adapter;
477
c4028958 478 INIT_WORK(&adapter->tx_timeout_task, ixgb_tx_timeout_task);
1da177e4 479
ec9c3f5d 480 strcpy(netdev->name, "eth%d");
1da177e4
LT
481 if((err = register_netdev(netdev)))
482 goto err_register;
483
484 /* we're going to reset, so assume we have no link for now */
485
486 netif_carrier_off(netdev);
487 netif_stop_queue(netdev);
488
ec9c3f5d 489 DPRINTK(PROBE, INFO, "Intel(R) PRO/10GbE Network Connection\n");
1da177e4
LT
490 ixgb_check_options(adapter);
491 /* reset the hardware with the new settings */
492
493 ixgb_reset(adapter);
494
495 cards_found++;
496 return 0;
497
498err_register:
499err_sw_init:
500err_eeprom:
501 iounmap(adapter->hw.hw_addr);
502err_ioremap:
503 free_netdev(netdev);
504err_alloc_etherdev:
505 pci_release_regions(pdev);
c91e468a
AS
506err_request_regions:
507err_dma_mask:
508 pci_disable_device(pdev);
1da177e4
LT
509 return err;
510}
511
512/**
513 * ixgb_remove - Device Removal Routine
514 * @pdev: PCI device information struct
515 *
516 * ixgb_remove is called by the PCI subsystem to alert the driver
517 * that it should release a PCI device. The could be caused by a
518 * Hot-Plug event, or because the driver is going to be removed from
519 * memory.
520 **/
521
522static void __devexit
523ixgb_remove(struct pci_dev *pdev)
524{
525 struct net_device *netdev = pci_get_drvdata(pdev);
8908c6cd 526 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4 527
12579697
JB
528 flush_scheduled_work();
529
1da177e4
LT
530 unregister_netdev(netdev);
531
532 iounmap(adapter->hw.hw_addr);
533 pci_release_regions(pdev);
534
535 free_netdev(netdev);
536}
537
538/**
539 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
540 * @adapter: board private structure to initialize
541 *
542 * ixgb_sw_init initializes the Adapter private data structure.
543 * Fields are initialized based on PCI device information and
544 * OS network device settings (MTU size).
545 **/
546
547static int __devinit
548ixgb_sw_init(struct ixgb_adapter *adapter)
549{
550 struct ixgb_hw *hw = &adapter->hw;
551 struct net_device *netdev = adapter->netdev;
552 struct pci_dev *pdev = adapter->pdev;
553
554 /* PCI config space info */
555
556 hw->vendor_id = pdev->vendor;
557 hw->device_id = pdev->device;
558 hw->subsystem_vendor_id = pdev->subsystem_vendor;
559 hw->subsystem_id = pdev->subsystem_device;
560
1da177e4 561 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
a3dc3da0 562 adapter->rx_buffer_len = hw->max_frame_size + 8; /* + 8 for errata */
1da177e4
LT
563
564 if((hw->device_id == IXGB_DEVICE_ID_82597EX)
940829e2
AK
565 || (hw->device_id == IXGB_DEVICE_ID_82597EX_CX4)
566 || (hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
567 || (hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
1da177e4
LT
568 hw->mac_type = ixgb_82597;
569 else {
570 /* should never have loaded on this device */
ec9c3f5d 571 DPRINTK(PROBE, ERR, "unsupported device id\n");
1da177e4
LT
572 }
573
574 /* enable flow control to be programmed */
575 hw->fc.send_xon = 1;
576
bab2bce7 577 set_bit(__IXGB_DOWN, &adapter->flags);
1da177e4
LT
578 return 0;
579}
580
581/**
582 * ixgb_open - Called when a network interface is made active
583 * @netdev: network interface device structure
584 *
585 * Returns 0 on success, negative value on failure
586 *
587 * The open entry point is called when a network interface is made
588 * active by the system (IFF_UP). At this point all resources needed
589 * for transmit and receive operations are allocated, the interrupt
590 * handler is registered with the OS, the watchdog timer is started,
591 * and the stack is notified that the interface is ready.
592 **/
593
594static int
595ixgb_open(struct net_device *netdev)
596{
8908c6cd 597 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
598 int err;
599
600 /* allocate transmit descriptors */
601
602 if((err = ixgb_setup_tx_resources(adapter)))
603 goto err_setup_tx;
604
605 /* allocate receive descriptors */
606
607 if((err = ixgb_setup_rx_resources(adapter)))
608 goto err_setup_rx;
609
610 if((err = ixgb_up(adapter)))
611 goto err_up;
612
613 return 0;
614
615err_up:
616 ixgb_free_rx_resources(adapter);
617err_setup_rx:
618 ixgb_free_tx_resources(adapter);
619err_setup_tx:
620 ixgb_reset(adapter);
621
622 return err;
623}
624
625/**
626 * ixgb_close - Disables a network interface
627 * @netdev: network interface device structure
628 *
629 * Returns 0, this is not allowed to fail
630 *
631 * The close entry point is called when an interface is de-activated
632 * by the OS. The hardware is still under the drivers control, but
633 * needs to be disabled. A global MAC reset is issued to stop the
634 * hardware, and all transmit and receive resources are freed.
635 **/
636
637static int
638ixgb_close(struct net_device *netdev)
639{
8908c6cd 640 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4 641
446490ca 642 ixgb_down(adapter, true);
1da177e4
LT
643
644 ixgb_free_tx_resources(adapter);
645 ixgb_free_rx_resources(adapter);
646
647 return 0;
648}
649
650/**
651 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
652 * @adapter: board private structure
653 *
654 * Return 0 on success, negative on failure
655 **/
656
657int
658ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
659{
660 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
661 struct pci_dev *pdev = adapter->pdev;
662 int size;
663
664 size = sizeof(struct ixgb_buffer) * txdr->count;
665 txdr->buffer_info = vmalloc(size);
666 if(!txdr->buffer_info) {
ec9c3f5d
AK
667 DPRINTK(PROBE, ERR,
668 "Unable to allocate transmit descriptor ring memory\n");
1da177e4
LT
669 return -ENOMEM;
670 }
671 memset(txdr->buffer_info, 0, size);
672
673 /* round up to nearest 4K */
674
675 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
55e924cf 676 txdr->size = ALIGN(txdr->size, 4096);
1da177e4
LT
677
678 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
679 if(!txdr->desc) {
680 vfree(txdr->buffer_info);
ec9c3f5d
AK
681 DPRINTK(PROBE, ERR,
682 "Unable to allocate transmit descriptor memory\n");
1da177e4
LT
683 return -ENOMEM;
684 }
685 memset(txdr->desc, 0, txdr->size);
686
687 txdr->next_to_use = 0;
688 txdr->next_to_clean = 0;
689
690 return 0;
691}
692
693/**
694 * ixgb_configure_tx - Configure 82597 Transmit Unit after Reset.
695 * @adapter: board private structure
696 *
697 * Configure the Tx unit of the MAC after a reset.
698 **/
699
700static void
701ixgb_configure_tx(struct ixgb_adapter *adapter)
702{
222441a6
JP
703 u64 tdba = adapter->tx_ring.dma;
704 u32 tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
705 u32 tctl;
1da177e4
LT
706 struct ixgb_hw *hw = &adapter->hw;
707
708 /* Setup the Base and Length of the Tx Descriptor Ring
709 * tx_ring.dma can be either a 32 or 64 bit value
710 */
711
712 IXGB_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
713 IXGB_WRITE_REG(hw, TDBAH, (tdba >> 32));
714
715 IXGB_WRITE_REG(hw, TDLEN, tdlen);
716
717 /* Setup the HW Tx Head and Tail descriptor pointers */
718
719 IXGB_WRITE_REG(hw, TDH, 0);
720 IXGB_WRITE_REG(hw, TDT, 0);
721
722 /* don't set up txdctl, it induces performance problems if configured
723 * incorrectly */
724 /* Set the Tx Interrupt Delay register */
725
726 IXGB_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
727
728 /* Program the Transmit Control Register */
729
730 tctl = IXGB_TCTL_TCE | IXGB_TCTL_TXEN | IXGB_TCTL_TPDE;
731 IXGB_WRITE_REG(hw, TCTL, tctl);
732
733 /* Setup Transmit Descriptor Settings for this adapter */
734 adapter->tx_cmd_type =
735 IXGB_TX_DESC_TYPE
736 | (adapter->tx_int_delay_enable ? IXGB_TX_DESC_CMD_IDE : 0);
737}
738
739/**
740 * ixgb_setup_rx_resources - allocate Rx resources (Descriptors)
741 * @adapter: board private structure
742 *
743 * Returns 0 on success, negative on failure
744 **/
745
746int
747ixgb_setup_rx_resources(struct ixgb_adapter *adapter)
748{
749 struct ixgb_desc_ring *rxdr = &adapter->rx_ring;
750 struct pci_dev *pdev = adapter->pdev;
751 int size;
752
753 size = sizeof(struct ixgb_buffer) * rxdr->count;
754 rxdr->buffer_info = vmalloc(size);
755 if(!rxdr->buffer_info) {
ec9c3f5d
AK
756 DPRINTK(PROBE, ERR,
757 "Unable to allocate receive descriptor ring\n");
1da177e4
LT
758 return -ENOMEM;
759 }
760 memset(rxdr->buffer_info, 0, size);
761
762 /* Round up to nearest 4K */
763
764 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
55e924cf 765 rxdr->size = ALIGN(rxdr->size, 4096);
1da177e4
LT
766
767 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
768
769 if(!rxdr->desc) {
770 vfree(rxdr->buffer_info);
ec9c3f5d
AK
771 DPRINTK(PROBE, ERR,
772 "Unable to allocate receive descriptors\n");
1da177e4
LT
773 return -ENOMEM;
774 }
775 memset(rxdr->desc, 0, rxdr->size);
776
777 rxdr->next_to_clean = 0;
778 rxdr->next_to_use = 0;
779
780 return 0;
781}
782
783/**
784 * ixgb_setup_rctl - configure the receive control register
785 * @adapter: Board private structure
786 **/
787
788static void
789ixgb_setup_rctl(struct ixgb_adapter *adapter)
790{
222441a6 791 u32 rctl;
1da177e4
LT
792
793 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
794
795 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
796
797 rctl |=
798 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
799 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
800 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
801
802 rctl |= IXGB_RCTL_SECRC;
803
3f3dc0dd 804 if (adapter->rx_buffer_len <= IXGB_RXBUFFER_2048)
1da177e4 805 rctl |= IXGB_RCTL_BSIZE_2048;
3f3dc0dd 806 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_4096)
1da177e4 807 rctl |= IXGB_RCTL_BSIZE_4096;
3f3dc0dd 808 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_8192)
1da177e4 809 rctl |= IXGB_RCTL_BSIZE_8192;
3f3dc0dd 810 else if (adapter->rx_buffer_len <= IXGB_RXBUFFER_16384)
1da177e4 811 rctl |= IXGB_RCTL_BSIZE_16384;
1da177e4
LT
812
813 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
814}
815
816/**
817 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
818 * @adapter: board private structure
819 *
820 * Configure the Rx unit of the MAC after a reset.
821 **/
822
823static void
824ixgb_configure_rx(struct ixgb_adapter *adapter)
825{
222441a6
JP
826 u64 rdba = adapter->rx_ring.dma;
827 u32 rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
1da177e4 828 struct ixgb_hw *hw = &adapter->hw;
222441a6
JP
829 u32 rctl;
830 u32 rxcsum;
1da177e4
LT
831
832 /* make sure receives are disabled while setting up the descriptors */
833
834 rctl = IXGB_READ_REG(hw, RCTL);
835 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
836
837 /* set the Receive Delay Timer Register */
838
839 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
840
841 /* Setup the Base and Length of the Rx Descriptor Ring */
842
843 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
844 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
845
846 IXGB_WRITE_REG(hw, RDLEN, rdlen);
847
848 /* Setup the HW Rx Head and Tail Descriptor Pointers */
849 IXGB_WRITE_REG(hw, RDH, 0);
850 IXGB_WRITE_REG(hw, RDT, 0);
851
4360386f
JB
852 /* due to the hardware errata with RXDCTL, we are unable to use any of
853 * the performance enhancing features of it without causing other
854 * subtle bugs, some of the bugs could include receive length
855 * corruption at high data rates (WTHRESH > 0) and/or receive
856 * descriptor ring irregularites (particularly in hardware cache) */
857 IXGB_WRITE_REG(hw, RXDCTL, 0);
1da177e4
LT
858
859 /* Enable Receive Checksum Offload for TCP and UDP */
446490ca 860 if (adapter->rx_csum) {
1da177e4
LT
861 rxcsum = IXGB_READ_REG(hw, RXCSUM);
862 rxcsum |= IXGB_RXCSUM_TUOFL;
863 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
864 }
865
866 /* Enable Receives */
867
868 IXGB_WRITE_REG(hw, RCTL, rctl);
869}
870
871/**
872 * ixgb_free_tx_resources - Free Tx Resources
873 * @adapter: board private structure
874 *
875 * Free all transmit software resources
876 **/
877
878void
879ixgb_free_tx_resources(struct ixgb_adapter *adapter)
880{
881 struct pci_dev *pdev = adapter->pdev;
882
883 ixgb_clean_tx_ring(adapter);
884
885 vfree(adapter->tx_ring.buffer_info);
886 adapter->tx_ring.buffer_info = NULL;
887
888 pci_free_consistent(pdev, adapter->tx_ring.size,
889 adapter->tx_ring.desc, adapter->tx_ring.dma);
890
891 adapter->tx_ring.desc = NULL;
892}
893
235949d1 894static void
1da177e4
LT
895ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
896 struct ixgb_buffer *buffer_info)
897{
898 struct pci_dev *pdev = adapter->pdev;
1dfdd7df
AK
899
900 if (buffer_info->dma)
901 pci_unmap_page(pdev, buffer_info->dma, buffer_info->length,
902 PCI_DMA_TODEVICE);
903
904 if (buffer_info->skb)
1da177e4 905 dev_kfree_skb_any(buffer_info->skb);
1dfdd7df
AK
906
907 buffer_info->skb = NULL;
908 buffer_info->dma = 0;
909 buffer_info->time_stamp = 0;
910 /* these fields must always be initialized in tx
911 * buffer_info->length = 0;
912 * buffer_info->next_to_watch = 0; */
1da177e4
LT
913}
914
915/**
916 * ixgb_clean_tx_ring - Free Tx Buffers
917 * @adapter: board private structure
918 **/
919
920static void
921ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
922{
923 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
924 struct ixgb_buffer *buffer_info;
925 unsigned long size;
926 unsigned int i;
927
928 /* Free all the Tx ring sk_buffs */
929
930 for(i = 0; i < tx_ring->count; i++) {
931 buffer_info = &tx_ring->buffer_info[i];
932 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
933 }
934
935 size = sizeof(struct ixgb_buffer) * tx_ring->count;
936 memset(tx_ring->buffer_info, 0, size);
937
938 /* Zero out the descriptor ring */
939
940 memset(tx_ring->desc, 0, tx_ring->size);
941
942 tx_ring->next_to_use = 0;
943 tx_ring->next_to_clean = 0;
944
945 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
946 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
947}
948
949/**
950 * ixgb_free_rx_resources - Free Rx Resources
951 * @adapter: board private structure
952 *
953 * Free all receive software resources
954 **/
955
956void
957ixgb_free_rx_resources(struct ixgb_adapter *adapter)
958{
959 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
960 struct pci_dev *pdev = adapter->pdev;
961
962 ixgb_clean_rx_ring(adapter);
963
964 vfree(rx_ring->buffer_info);
965 rx_ring->buffer_info = NULL;
966
967 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
968
969 rx_ring->desc = NULL;
970}
971
972/**
973 * ixgb_clean_rx_ring - Free Rx Buffers
974 * @adapter: board private structure
975 **/
976
977static void
978ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
979{
980 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
981 struct ixgb_buffer *buffer_info;
982 struct pci_dev *pdev = adapter->pdev;
983 unsigned long size;
984 unsigned int i;
985
986 /* Free all the Rx ring sk_buffs */
987
988 for(i = 0; i < rx_ring->count; i++) {
989 buffer_info = &rx_ring->buffer_info[i];
990 if(buffer_info->skb) {
991
992 pci_unmap_single(pdev,
993 buffer_info->dma,
994 buffer_info->length,
995 PCI_DMA_FROMDEVICE);
996
997 dev_kfree_skb(buffer_info->skb);
998
999 buffer_info->skb = NULL;
1000 }
1001 }
1002
1003 size = sizeof(struct ixgb_buffer) * rx_ring->count;
1004 memset(rx_ring->buffer_info, 0, size);
1005
1006 /* Zero out the descriptor ring */
1007
1008 memset(rx_ring->desc, 0, rx_ring->size);
1009
1010 rx_ring->next_to_clean = 0;
1011 rx_ring->next_to_use = 0;
1012
1013 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1014 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1015}
1016
1017/**
1018 * ixgb_set_mac - Change the Ethernet Address of the NIC
1019 * @netdev: network interface device structure
1020 * @p: pointer to an address structure
1021 *
1022 * Returns 0 on success, negative on failure
1023 **/
1024
1025static int
1026ixgb_set_mac(struct net_device *netdev, void *p)
1027{
8908c6cd 1028 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
1029 struct sockaddr *addr = p;
1030
1031 if(!is_valid_ether_addr(addr->sa_data))
1032 return -EADDRNOTAVAIL;
1033
1034 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1035
1036 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1037
1038 return 0;
1039}
1040
1041/**
1042 * ixgb_set_multi - Multicast and Promiscuous mode set
1043 * @netdev: network interface device structure
1044 *
1045 * The set_multi entry point is called whenever the multicast address
1046 * list or the network interface flags are updated. This routine is
1047 * responsible for configuring the hardware for proper multicast,
1048 * promiscuous mode, and all-multi behavior.
1049 **/
1050
1051static void
1052ixgb_set_multi(struct net_device *netdev)
1053{
8908c6cd 1054 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
1055 struct ixgb_hw *hw = &adapter->hw;
1056 struct dev_mc_list *mc_ptr;
222441a6 1057 u32 rctl;
1da177e4
LT
1058 int i;
1059
1060 /* Check for Promiscuous and All Multicast modes */
1061
1062 rctl = IXGB_READ_REG(hw, RCTL);
1063
1064 if(netdev->flags & IFF_PROMISC) {
1065 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1066 } else if(netdev->flags & IFF_ALLMULTI) {
1067 rctl |= IXGB_RCTL_MPE;
1068 rctl &= ~IXGB_RCTL_UPE;
1069 } else {
1070 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1071 }
1072
1073 if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1074 rctl |= IXGB_RCTL_MPE;
1075 IXGB_WRITE_REG(hw, RCTL, rctl);
1076 } else {
222441a6 1077 u8 mta[IXGB_MAX_NUM_MULTICAST_ADDRESSES *
273dc74e 1078 IXGB_ETH_LENGTH_OF_ADDRESS];
1da177e4
LT
1079
1080 IXGB_WRITE_REG(hw, RCTL, rctl);
1081
1082 for(i = 0, mc_ptr = netdev->mc_list; mc_ptr;
1083 i++, mc_ptr = mc_ptr->next)
1084 memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
1085 mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
1086
1087 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1088 }
1089}
1090
1091/**
1092 * ixgb_watchdog - Timer Call-back
1093 * @data: pointer to netdev cast into an unsigned long
1094 **/
1095
1096static void
1097ixgb_watchdog(unsigned long data)
1098{
1099 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1100 struct net_device *netdev = adapter->netdev;
1101 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1102
1103 ixgb_check_for_link(&adapter->hw);
1104
1105 if (ixgb_check_for_bad_link(&adapter->hw)) {
1106 /* force the reset path */
1107 netif_stop_queue(netdev);
1108 }
1109
1110 if(adapter->hw.link_up) {
1111 if(!netif_carrier_ok(netdev)) {
ec9c3f5d
AK
1112 DPRINTK(LINK, INFO,
1113 "NIC Link is Up 10000 Mbps Full Duplex\n");
1da177e4
LT
1114 adapter->link_speed = 10000;
1115 adapter->link_duplex = FULL_DUPLEX;
1116 netif_carrier_on(netdev);
1117 netif_wake_queue(netdev);
1118 }
1119 } else {
1120 if(netif_carrier_ok(netdev)) {
1121 adapter->link_speed = 0;
1122 adapter->link_duplex = 0;
ec9c3f5d 1123 DPRINTK(LINK, INFO, "NIC Link is Down\n");
1da177e4
LT
1124 netif_carrier_off(netdev);
1125 netif_stop_queue(netdev);
1126
1127 }
1128 }
1129
1130 ixgb_update_stats(adapter);
1131
1132 if(!netif_carrier_ok(netdev)) {
1133 if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1134 /* We've lost link, so the controller stops DMA,
1135 * but we've got queued Tx work that's never going
1136 * to get done, so reset controller to flush Tx.
1137 * (Do the reset outside of interrupt context). */
1138 schedule_work(&adapter->tx_timeout_task);
1139 }
1140 }
1141
1142 /* Force detection of hung controller every watchdog period */
446490ca 1143 adapter->detect_tx_hung = true;
1da177e4
LT
1144
1145 /* generate an interrupt to force clean up of any stragglers */
1146 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1147
1148 /* Reset the timer */
1149 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1150}
1151
1152#define IXGB_TX_FLAGS_CSUM 0x00000001
1153#define IXGB_TX_FLAGS_VLAN 0x00000002
1154#define IXGB_TX_FLAGS_TSO 0x00000004
1155
235949d1 1156static int
1da177e4
LT
1157ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1158{
1da177e4
LT
1159 struct ixgb_context_desc *context_desc;
1160 unsigned int i;
222441a6
JP
1161 u8 ipcss, ipcso, tucss, tucso, hdr_len;
1162 u16 ipcse, tucse, mss;
1da177e4
LT
1163 int err;
1164
89114afd 1165 if (likely(skb_is_gso(skb))) {
adc54139 1166 struct ixgb_buffer *buffer_info;
eddc9ec5
ACM
1167 struct iphdr *iph;
1168
1da177e4
LT
1169 if (skb_header_cloned(skb)) {
1170 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1171 if (err)
1172 return err;
1173 }
1174
ab6a5bb6 1175 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
7967168c 1176 mss = skb_shinfo(skb)->gso_size;
eddc9ec5
ACM
1177 iph = ip_hdr(skb);
1178 iph->tot_len = 0;
1179 iph->check = 0;
aa8223c7
ACM
1180 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
1181 iph->daddr, 0,
1182 IPPROTO_TCP, 0);
bbe735e4 1183 ipcss = skb_network_offset(skb);
eddc9ec5 1184 ipcso = (void *)&(iph->check) - (void *)skb->data;
ea2ae17d
ACM
1185 ipcse = skb_transport_offset(skb) - 1;
1186 tucss = skb_transport_offset(skb);
aa8223c7 1187 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
1da177e4
LT
1188 tucse = 0;
1189
1190 i = adapter->tx_ring.next_to_use;
1191 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
adc54139
JB
1192 buffer_info = &adapter->tx_ring.buffer_info[i];
1193 WARN_ON(buffer_info->dma != 0);
1da177e4
LT
1194
1195 context_desc->ipcss = ipcss;
1196 context_desc->ipcso = ipcso;
1197 context_desc->ipcse = cpu_to_le16(ipcse);
1198 context_desc->tucss = tucss;
1199 context_desc->tucso = tucso;
1200 context_desc->tucse = cpu_to_le16(tucse);
1201 context_desc->mss = cpu_to_le16(mss);
1202 context_desc->hdr_len = hdr_len;
1203 context_desc->status = 0;
1204 context_desc->cmd_type_len = cpu_to_le32(
1205 IXGB_CONTEXT_DESC_TYPE
1206 | IXGB_CONTEXT_DESC_CMD_TSE
1207 | IXGB_CONTEXT_DESC_CMD_IP
1208 | IXGB_CONTEXT_DESC_CMD_TCP
1da177e4
LT
1209 | IXGB_CONTEXT_DESC_CMD_IDE
1210 | (skb->len - (hdr_len)));
1211
06c2f9ec 1212
1da177e4
LT
1213 if(++i == adapter->tx_ring.count) i = 0;
1214 adapter->tx_ring.next_to_use = i;
1215
1216 return 1;
1217 }
1da177e4
LT
1218
1219 return 0;
1220}
1221
446490ca 1222static bool
1da177e4
LT
1223ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1224{
1225 struct ixgb_context_desc *context_desc;
1226 unsigned int i;
222441a6 1227 u8 css, cso;
1da177e4 1228
84fa7933 1229 if(likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
adc54139 1230 struct ixgb_buffer *buffer_info;
ea2ae17d 1231 css = skb_transport_offset(skb);
ff1dcadb 1232 cso = css + skb->csum_offset;
1da177e4
LT
1233
1234 i = adapter->tx_ring.next_to_use;
1235 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
adc54139
JB
1236 buffer_info = &adapter->tx_ring.buffer_info[i];
1237 WARN_ON(buffer_info->dma != 0);
1da177e4
LT
1238
1239 context_desc->tucss = css;
1240 context_desc->tucso = cso;
1241 context_desc->tucse = 0;
1242 /* zero out any previously existing data in one instruction */
222441a6 1243 *(u32 *)&(context_desc->ipcss) = 0;
1da177e4
LT
1244 context_desc->status = 0;
1245 context_desc->hdr_len = 0;
1246 context_desc->mss = 0;
1247 context_desc->cmd_type_len =
1248 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
06c2f9ec 1249 | IXGB_TX_DESC_CMD_IDE);
1da177e4
LT
1250
1251 if(++i == adapter->tx_ring.count) i = 0;
1252 adapter->tx_ring.next_to_use = i;
1253
446490ca 1254 return true;
1da177e4
LT
1255 }
1256
446490ca 1257 return false;
1da177e4
LT
1258}
1259
1260#define IXGB_MAX_TXD_PWR 14
1261#define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1262
235949d1 1263static int
1da177e4
LT
1264ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1265 unsigned int first)
1266{
1267 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1268 struct ixgb_buffer *buffer_info;
1269 int len = skb->len;
1270 unsigned int offset = 0, size, count = 0, i;
5d927853 1271 unsigned int mss = skb_shinfo(skb)->gso_size;
1da177e4
LT
1272
1273 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1274 unsigned int f;
ac79c82e 1275
1da177e4
LT
1276 len -= skb->data_len;
1277
1278 i = tx_ring->next_to_use;
1279
1280 while(len) {
1281 buffer_info = &tx_ring->buffer_info[i];
709cf018 1282 size = min(len, IXGB_MAX_DATA_PER_TXD);
5d927853
JB
1283 /* Workaround for premature desc write-backs
1284 * in TSO mode. Append 4-byte sentinel desc */
1285 if (unlikely(mss && !nr_frags && size == len && size > 8))
1286 size -= 4;
1287
1da177e4 1288 buffer_info->length = size;
adc54139 1289 WARN_ON(buffer_info->dma != 0);
34336635 1290 buffer_info->time_stamp = jiffies;
1da177e4
LT
1291 buffer_info->dma =
1292 pci_map_single(adapter->pdev,
1293 skb->data + offset,
1294 size,
1295 PCI_DMA_TODEVICE);
1dfdd7df 1296 buffer_info->next_to_watch = 0;
1da177e4
LT
1297
1298 len -= size;
1299 offset += size;
1300 count++;
1301 if(++i == tx_ring->count) i = 0;
1302 }
1303
1304 for(f = 0; f < nr_frags; f++) {
1305 struct skb_frag_struct *frag;
1306
1307 frag = &skb_shinfo(skb)->frags[f];
1308 len = frag->size;
1309 offset = 0;
1310
1311 while(len) {
1312 buffer_info = &tx_ring->buffer_info[i];
709cf018 1313 size = min(len, IXGB_MAX_DATA_PER_TXD);
5d927853
JB
1314
1315 /* Workaround for premature desc write-backs
1316 * in TSO mode. Append 4-byte sentinel desc */
19abe86d
AK
1317 if (unlikely(mss && (f == (nr_frags - 1))
1318 && size == len && size > 8))
5d927853
JB
1319 size -= 4;
1320
1da177e4 1321 buffer_info->length = size;
34336635 1322 buffer_info->time_stamp = jiffies;
1da177e4
LT
1323 buffer_info->dma =
1324 pci_map_page(adapter->pdev,
1325 frag->page,
1326 frag->page_offset + offset,
1327 size,
1328 PCI_DMA_TODEVICE);
1dfdd7df 1329 buffer_info->next_to_watch = 0;
1da177e4
LT
1330
1331 len -= size;
1332 offset += size;
1333 count++;
1334 if(++i == tx_ring->count) i = 0;
1335 }
1336 }
1337 i = (i == 0) ? tx_ring->count - 1 : i - 1;
1338 tx_ring->buffer_info[i].skb = skb;
1339 tx_ring->buffer_info[first].next_to_watch = i;
1340
1341 return count;
1342}
1343
235949d1 1344static void
1da177e4
LT
1345ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1346{
1347 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1348 struct ixgb_tx_desc *tx_desc = NULL;
1349 struct ixgb_buffer *buffer_info;
222441a6
JP
1350 u32 cmd_type_len = adapter->tx_cmd_type;
1351 u8 status = 0;
1352 u8 popts = 0;
1da177e4
LT
1353 unsigned int i;
1354
1355 if(tx_flags & IXGB_TX_FLAGS_TSO) {
1356 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1357 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1358 }
1359
1360 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1361 popts |= IXGB_TX_DESC_POPTS_TXSM;
1362
1363 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1364 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1365 }
1366
1367 i = tx_ring->next_to_use;
1368
1369 while(count--) {
1370 buffer_info = &tx_ring->buffer_info[i];
1371 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1372 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1373 tx_desc->cmd_type_len =
1374 cpu_to_le32(cmd_type_len | buffer_info->length);
1375 tx_desc->status = status;
1376 tx_desc->popts = popts;
1377 tx_desc->vlan = cpu_to_le16(vlan_id);
1378
1379 if(++i == tx_ring->count) i = 0;
1380 }
1381
1382 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1383 | IXGB_TX_DESC_CMD_RS );
1384
1385 /* Force memory writes to complete before letting h/w
1386 * know there are new descriptors to fetch. (Only
1387 * applicable for weak-ordered memory model archs,
1388 * such as IA-64). */
1389 wmb();
1390
1391 tx_ring->next_to_use = i;
1392 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1393}
1394
dfd341e4
JB
1395static int __ixgb_maybe_stop_tx(struct net_device *netdev, int size)
1396{
1397 struct ixgb_adapter *adapter = netdev_priv(netdev);
1398 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1399
1400 netif_stop_queue(netdev);
1401 /* Herbert's original patch had:
1402 * smp_mb__after_netif_stop_queue();
1403 * but since that doesn't exist yet, just open code it. */
1404 smp_mb();
1405
1406 /* We need to check again in a case another CPU has just
1407 * made room available. */
1408 if (likely(IXGB_DESC_UNUSED(tx_ring) < size))
1409 return -EBUSY;
1410
1411 /* A reprieve! */
1412 netif_start_queue(netdev);
1413 ++adapter->restart_queue;
1414 return 0;
1415}
1416
1417static int ixgb_maybe_stop_tx(struct net_device *netdev,
1418 struct ixgb_desc_ring *tx_ring, int size)
1419{
1420 if (likely(IXGB_DESC_UNUSED(tx_ring) >= size))
1421 return 0;
1422 return __ixgb_maybe_stop_tx(netdev, size);
1423}
1424
1425
1da177e4
LT
1426/* Tx Descriptors needed, worst case */
1427#define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1428 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
5d927853
JB
1429#define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) /* skb->date */ + \
1430 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1 /* for context */ \
1431 + 1 /* one more needed for sentinel TSO workaround */
1da177e4
LT
1432
1433static int
1434ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1435{
8908c6cd 1436 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
1437 unsigned int first;
1438 unsigned int tx_flags = 0;
1da177e4
LT
1439 int vlan_id = 0;
1440 int tso;
1441
bab2bce7
JB
1442 if (test_bit(__IXGB_DOWN, &adapter->flags)) {
1443 dev_kfree_skb(skb);
1444 return NETDEV_TX_OK;
1445 }
1446
1da177e4
LT
1447 if(skb->len <= 0) {
1448 dev_kfree_skb_any(skb);
1449 return 0;
1450 }
1451
dfd341e4 1452 if (unlikely(ixgb_maybe_stop_tx(netdev, &adapter->tx_ring,
db582944 1453 DESC_NEEDED)))
f017f14b 1454 return NETDEV_TX_BUSY;
1da177e4
LT
1455
1456 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1457 tx_flags |= IXGB_TX_FLAGS_VLAN;
1458 vlan_id = vlan_tx_tag_get(skb);
1459 }
1460
1461 first = adapter->tx_ring.next_to_use;
1462
1463 tso = ixgb_tso(adapter, skb);
1464 if (tso < 0) {
1465 dev_kfree_skb_any(skb);
1466 return NETDEV_TX_OK;
1467 }
1468
96f9c2e2 1469 if (likely(tso))
1da177e4
LT
1470 tx_flags |= IXGB_TX_FLAGS_TSO;
1471 else if(ixgb_tx_csum(adapter, skb))
1472 tx_flags |= IXGB_TX_FLAGS_CSUM;
1473
1474 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1475 tx_flags);
1476
1477 netdev->trans_start = jiffies;
1478
f017f14b 1479 /* Make sure there is space in the ring for the next send. */
dfd341e4 1480 ixgb_maybe_stop_tx(netdev, &adapter->tx_ring, DESC_NEEDED);
f017f14b 1481
f017f14b 1482 return NETDEV_TX_OK;
1da177e4
LT
1483}
1484
1485/**
1486 * ixgb_tx_timeout - Respond to a Tx Hang
1487 * @netdev: network interface device structure
1488 **/
1489
1490static void
1491ixgb_tx_timeout(struct net_device *netdev)
1492{
8908c6cd 1493 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
1494
1495 /* Do the reset outside of interrupt context */
1496 schedule_work(&adapter->tx_timeout_task);
1497}
1498
1499static void
c4028958 1500ixgb_tx_timeout_task(struct work_struct *work)
1da177e4 1501{
c4028958
DH
1502 struct ixgb_adapter *adapter =
1503 container_of(work, struct ixgb_adapter, tx_timeout_task);
1da177e4 1504
9b8118df 1505 adapter->tx_timeout_count++;
446490ca 1506 ixgb_down(adapter, true);
1da177e4
LT
1507 ixgb_up(adapter);
1508}
1509
1510/**
1511 * ixgb_get_stats - Get System Network Statistics
1512 * @netdev: network interface device structure
1513 *
1514 * Returns the address of the device statistics structure.
1515 * The statistics are actually updated from the timer callback.
1516 **/
1517
1518static struct net_device_stats *
1519ixgb_get_stats(struct net_device *netdev)
1520{
8908c6cd 1521 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
1522
1523 return &adapter->net_stats;
1524}
1525
1526/**
1527 * ixgb_change_mtu - Change the Maximum Transfer Unit
1528 * @netdev: network interface device structure
1529 * @new_mtu: new value for maximum frame size
1530 *
1531 * Returns 0 on success, negative on failure
1532 **/
1533
1534static int
1535ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1536{
8908c6cd 1537 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4
LT
1538 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1539 int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1540
a65a604a
JB
1541 /* MTU < 68 is an error for IPv4 traffic, just don't allow it */
1542 if ((new_mtu < 68) ||
1543 (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
ec9c3f5d 1544 DPRINTK(PROBE, ERR, "Invalid MTU setting %d\n", new_mtu);
1da177e4
LT
1545 return -EINVAL;
1546 }
1547
b5ca88eb
JB
1548 if (old_max_frame == max_frame)
1549 return 0;
1550
1551 if (netif_running(netdev))
1552 ixgb_down(adapter, true);
1553
a3dc3da0 1554 adapter->rx_buffer_len = max_frame + 8; /* + 8 for errata */
1da177e4
LT
1555
1556 netdev->mtu = new_mtu;
1557
b5ca88eb 1558 if (netif_running(netdev))
1da177e4 1559 ixgb_up(adapter);
1da177e4
LT
1560
1561 return 0;
1562}
1563
1564/**
1565 * ixgb_update_stats - Update the board statistics counters.
1566 * @adapter: board private structure
1567 **/
1568
1569void
1570ixgb_update_stats(struct ixgb_adapter *adapter)
1571{
5633684d 1572 struct net_device *netdev = adapter->netdev;
01748fbb
LV
1573 struct pci_dev *pdev = adapter->pdev;
1574
1575 /* Prevent stats update while adapter is being reset */
81b1955e 1576 if (pci_channel_offline(pdev))
01748fbb 1577 return;
5633684d
MC
1578
1579 if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
1580 (netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES)) {
1581 u64 multi = IXGB_READ_REG(&adapter->hw, MPRCL);
1582 u32 bcast_l = IXGB_READ_REG(&adapter->hw, BPRCL);
1583 u32 bcast_h = IXGB_READ_REG(&adapter->hw, BPRCH);
1584 u64 bcast = ((u64)bcast_h << 32) | bcast_l;
1585
1586 multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
1587 /* fix up multicast stats by removing broadcasts */
7b89178d
MC
1588 if(multi >= bcast)
1589 multi -= bcast;
5633684d
MC
1590
1591 adapter->stats.mprcl += (multi & 0xFFFFFFFF);
1592 adapter->stats.mprch += (multi >> 32);
1593 adapter->stats.bprcl += bcast_l;
1594 adapter->stats.bprch += bcast_h;
1595 } else {
1596 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1597 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1598 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1599 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1600 }
1da177e4
LT
1601 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1602 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1603 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1604 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1da177e4
LT
1605 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1606 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1607 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1608 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1609 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1610 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1611 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1612 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1613 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1614 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1615 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1616 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1617 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1618 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1619 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1620 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1621 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1622 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1623 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1624 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1625 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1626 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1627 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1628 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1629 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1630 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1631 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1632 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1633 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1634 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1635 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1636 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1637 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1638 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1639 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1640 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1641 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1642 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1643 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1644 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1645 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1646 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1647 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1648 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1649 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1650 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1651 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1652 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1653 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1654 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1655 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1656 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1657
1658 /* Fill out the OS statistics structure */
1659
1660 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1661 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1662 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1663 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1664 adapter->net_stats.multicast = adapter->stats.mprcl;
1665 adapter->net_stats.collisions = 0;
1666
1667 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1668 * with a length in the type/len field */
1669 adapter->net_stats.rx_errors =
1670 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1671 adapter->stats.ruc +
1672 adapter->stats.roc /*+ adapter->stats.rlec */ +
1673 adapter->stats.icbc +
1674 adapter->stats.ecbc + adapter->stats.mpc;
1675
1da177e4
LT
1676 /* see above
1677 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1678 */
1679
1680 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1681 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1682 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1683 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1684
1685 adapter->net_stats.tx_errors = 0;
1686 adapter->net_stats.rx_frame_errors = 0;
1687 adapter->net_stats.tx_aborted_errors = 0;
1688 adapter->net_stats.tx_carrier_errors = 0;
1689 adapter->net_stats.tx_fifo_errors = 0;
1690 adapter->net_stats.tx_heartbeat_errors = 0;
1691 adapter->net_stats.tx_window_errors = 0;
1692}
1693
1694#define IXGB_MAX_INTR 10
1695/**
1696 * ixgb_intr - Interrupt Handler
1697 * @irq: interrupt number
1698 * @data: pointer to a network interface device structure
1da177e4
LT
1699 **/
1700
1701static irqreturn_t
7d12e780 1702ixgb_intr(int irq, void *data)
1da177e4
LT
1703{
1704 struct net_device *netdev = data;
8908c6cd 1705 struct ixgb_adapter *adapter = netdev_priv(netdev);
1da177e4 1706 struct ixgb_hw *hw = &adapter->hw;
222441a6 1707 u32 icr = IXGB_READ_REG(hw, ICR);
1da177e4
LT
1708#ifndef CONFIG_IXGB_NAPI
1709 unsigned int i;
1710#endif
1711
1712 if(unlikely(!icr))
1713 return IRQ_NONE; /* Not our interrupt */
1714
bab2bce7
JB
1715 if (unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC)))
1716 if (!test_bit(__IXGB_DOWN, &adapter->flags))
1717 mod_timer(&adapter->watchdog_timer, jiffies);
1da177e4
LT
1718
1719#ifdef CONFIG_IXGB_NAPI
bea3348e 1720 if (netif_rx_schedule_prep(netdev, &adapter->napi)) {
1da177e4
LT
1721
1722 /* Disable interrupts and register for poll. The flush
1723 of the posted write is intentionally left out.
1724 */
1725
1da177e4 1726 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
bea3348e 1727 __netif_rx_schedule(netdev, &adapter->napi);
1da177e4
LT
1728 }
1729#else
1730 /* yes, that is actually a & and it is meant to make sure that
1731 * every pass through this for loop checks both receive and
1732 * transmit queues for completed descriptors, intended to
1733 * avoid starvation issues and assist tx/rx fairness. */
1734 for(i = 0; i < IXGB_MAX_INTR; i++)
1735 if(!ixgb_clean_rx_irq(adapter) &
1736 !ixgb_clean_tx_irq(adapter))
1737 break;
1738#endif
1739 return IRQ_HANDLED;
1740}
1741
1742#ifdef CONFIG_IXGB_NAPI
1743/**
1744 * ixgb_clean - NAPI Rx polling callback
1745 * @adapter: board private structure
1746 **/
1747
1748static int
bea3348e 1749ixgb_clean(struct napi_struct *napi, int budget)
1da177e4 1750{
bea3348e
SH
1751 struct ixgb_adapter *adapter = container_of(napi, struct ixgb_adapter, napi);
1752 struct net_device *netdev = adapter->netdev;
1da177e4
LT
1753 int work_done = 0;
1754
53e52c72 1755 ixgb_clean_tx_irq(adapter);
bea3348e 1756 ixgb_clean_rx_irq(adapter, &work_done, budget);
1da177e4 1757
53e52c72
DM
1758 /* If budget not fully consumed, exit the polling mode */
1759 if (work_done < budget) {
bea3348e 1760 netif_rx_complete(netdev, napi);
72ab5195
JB
1761 if (!test_bit(__IXGB_DOWN, &adapter->flags))
1762 ixgb_irq_enable(adapter);
1da177e4
LT
1763 }
1764
bea3348e 1765 return work_done;
1da177e4
LT
1766}
1767#endif
1768
1769/**
1770 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1771 * @adapter: board private structure
1772 **/
1773
446490ca 1774static bool
1da177e4
LT
1775ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1776{
1777 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1778 struct net_device *netdev = adapter->netdev;
1779 struct ixgb_tx_desc *tx_desc, *eop_desc;
1780 struct ixgb_buffer *buffer_info;
1781 unsigned int i, eop;
446490ca 1782 bool cleaned = false;
1da177e4
LT
1783
1784 i = tx_ring->next_to_clean;
1785 eop = tx_ring->buffer_info[i].next_to_watch;
1786 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1787
1788 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1789
446490ca 1790 for (cleaned = false; !cleaned; ) {
1da177e4
LT
1791 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1792 buffer_info = &tx_ring->buffer_info[i];
1793
1794 if (tx_desc->popts
1795 & (IXGB_TX_DESC_POPTS_TXSM |
1796 IXGB_TX_DESC_POPTS_IXSM))
1797 adapter->hw_csum_tx_good++;
1798
1799 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1800
222441a6 1801 *(u32 *)&(tx_desc->status) = 0;
1da177e4
LT
1802
1803 cleaned = (i == eop);
1804 if(++i == tx_ring->count) i = 0;
1805 }
1806
1807 eop = tx_ring->buffer_info[i].next_to_watch;
1808 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1809 }
1810
1811 tx_ring->next_to_clean = i;
1812
0f8ecbad
JB
1813 if (unlikely(cleaned && netif_carrier_ok(netdev) &&
1814 IXGB_DESC_UNUSED(tx_ring) >= DESC_NEEDED)) {
1815 /* Make sure that anybody stopping the queue after this
1816 * sees the new next_to_clean. */
1817 smp_mb();
1818
1819 if (netif_queue_stopped(netdev) &&
1820 !(test_bit(__IXGB_DOWN, &adapter->flags))) {
3352a3b2 1821 netif_wake_queue(netdev);
0f8ecbad
JB
1822 ++adapter->restart_queue;
1823 }
1da177e4 1824 }
1da177e4
LT
1825
1826 if(adapter->detect_tx_hung) {
1827 /* detect a transmit hang in hardware, this serializes the
1828 * check with the clearing of time_stamp and movement of i */
446490ca 1829 adapter->detect_tx_hung = false;
9b8118df
AK
1830 if (tx_ring->buffer_info[eop].dma &&
1831 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + HZ)
1da177e4 1832 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
9b8118df
AK
1833 IXGB_STATUS_TXOFF)) {
1834 /* detected Tx unit hang */
1835 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
1836 " TDH <%x>\n"
1837 " TDT <%x>\n"
1838 " next_to_use <%x>\n"
1839 " next_to_clean <%x>\n"
1840 "buffer_info[next_to_clean]\n"
1841 " time_stamp <%lx>\n"
1842 " next_to_watch <%x>\n"
1843 " jiffies <%lx>\n"
1844 " next_to_watch.status <%x>\n",
1845 IXGB_READ_REG(&adapter->hw, TDH),
1846 IXGB_READ_REG(&adapter->hw, TDT),
1847 tx_ring->next_to_use,
1848 tx_ring->next_to_clean,
1849 tx_ring->buffer_info[eop].time_stamp,
1850 eop,
1851 jiffies,
1852 eop_desc->status);
1da177e4 1853 netif_stop_queue(netdev);
9b8118df 1854 }
1da177e4
LT
1855 }
1856
1857 return cleaned;
1858}
1859
1860/**
1861 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1862 * @adapter: board private structure
1863 * @rx_desc: receive descriptor
1864 * @sk_buff: socket buffer with received data
1865 **/
1866
235949d1 1867static void
1da177e4
LT
1868ixgb_rx_checksum(struct ixgb_adapter *adapter,
1869 struct ixgb_rx_desc *rx_desc,
1870 struct sk_buff *skb)
1871{
1872 /* Ignore Checksum bit is set OR
1873 * TCP Checksum has not been calculated
1874 */
1875 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1876 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1877 skb->ip_summed = CHECKSUM_NONE;
1878 return;
1879 }
1880
1881 /* At this point we know the hardware did the TCP checksum */
1882 /* now look at the TCP checksum error bit */
1883 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1884 /* let the stack verify checksum errors */
1885 skb->ip_summed = CHECKSUM_NONE;
1886 adapter->hw_csum_rx_error++;
1887 } else {
1888 /* TCP checksum is good */
1889 skb->ip_summed = CHECKSUM_UNNECESSARY;
1890 adapter->hw_csum_rx_good++;
1891 }
1892}
1893
1894/**
1895 * ixgb_clean_rx_irq - Send received data up the network stack,
1896 * @adapter: board private structure
1897 **/
1898
446490ca 1899static bool
1da177e4
LT
1900#ifdef CONFIG_IXGB_NAPI
1901ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1902#else
1903ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1904#endif
1905{
1906 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1907 struct net_device *netdev = adapter->netdev;
1908 struct pci_dev *pdev = adapter->pdev;
1909 struct ixgb_rx_desc *rx_desc, *next_rxd;
1910 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
222441a6 1911 u32 length;
1da177e4 1912 unsigned int i, j;
446490ca 1913 bool cleaned = false;
1da177e4
LT
1914
1915 i = rx_ring->next_to_clean;
1916 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1917 buffer_info = &rx_ring->buffer_info[i];
1918
1919 while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
f404de1c
MC
1920 struct sk_buff *skb, *next_skb;
1921 u8 status;
1da177e4
LT
1922
1923#ifdef CONFIG_IXGB_NAPI
1924 if(*work_done >= work_to_do)
1925 break;
1926
1927 (*work_done)++;
1928#endif
f404de1c 1929 status = rx_desc->status;
1da177e4 1930 skb = buffer_info->skb;
1dfdd7df 1931 buffer_info->skb = NULL;
f404de1c 1932
1da177e4
LT
1933 prefetch(skb->data);
1934
1935 if(++i == rx_ring->count) i = 0;
1936 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1937 prefetch(next_rxd);
1938
1939 if((j = i + 1) == rx_ring->count) j = 0;
1940 next2_buffer = &rx_ring->buffer_info[j];
1941 prefetch(next2_buffer);
1942
1943 next_buffer = &rx_ring->buffer_info[i];
1944 next_skb = next_buffer->skb;
1945 prefetch(next_skb);
1946
446490ca 1947 cleaned = true;
1da177e4
LT
1948
1949 pci_unmap_single(pdev,
1950 buffer_info->dma,
1951 buffer_info->length,
1952 PCI_DMA_FROMDEVICE);
1953
1954 length = le16_to_cpu(rx_desc->length);
1955
f404de1c 1956 if(unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
1da177e4
LT
1957
1958 /* All receives must fit into a single buffer */
1959
1960 IXGB_DBG("Receive packet consumed multiple buffers "
1961 "length<%x>\n", length);
1962
1963 dev_kfree_skb_irq(skb);
f404de1c 1964 goto rxdesc_done;
1da177e4
LT
1965 }
1966
1967 if (unlikely(rx_desc->errors
1968 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
1969 | IXGB_RX_DESC_ERRORS_P |
1970 IXGB_RX_DESC_ERRORS_RXE))) {
1971
1972 dev_kfree_skb_irq(skb);
f404de1c 1973 goto rxdesc_done;
1da177e4
LT
1974 }
1975
6b900bb4
AK
1976 /* code added for copybreak, this should improve
1977 * performance for small packets with large amounts
1978 * of reassembly being done in the stack */
1979#define IXGB_CB_LENGTH 256
1980 if (length < IXGB_CB_LENGTH) {
1981 struct sk_buff *new_skb =
5791704f 1982 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
6b900bb4
AK
1983 if (new_skb) {
1984 skb_reserve(new_skb, NET_IP_ALIGN);
27d7ff46
ACM
1985 skb_copy_to_linear_data_offset(new_skb,
1986 -NET_IP_ALIGN,
1987 (skb->data -
1988 NET_IP_ALIGN),
1989 (length +
1990 NET_IP_ALIGN));
6b900bb4
AK
1991 /* save the skb in buffer_info as good */
1992 buffer_info->skb = skb;
1993 skb = new_skb;
1994 }
1995 }
1996 /* end copybreak code */
1997
1da177e4
LT
1998 /* Good Receive */
1999 skb_put(skb, length);
2000
2001 /* Receive Checksum Offload */
2002 ixgb_rx_checksum(adapter, rx_desc, skb);
2003
2004 skb->protocol = eth_type_trans(skb, netdev);
2005#ifdef CONFIG_IXGB_NAPI
f404de1c 2006 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
1da177e4 2007 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
38b22195 2008 le16_to_cpu(rx_desc->special));
1da177e4
LT
2009 } else {
2010 netif_receive_skb(skb);
2011 }
2012#else /* CONFIG_IXGB_NAPI */
f404de1c 2013 if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
1da177e4 2014 vlan_hwaccel_rx(skb, adapter->vlgrp,
38b22195 2015 le16_to_cpu(rx_desc->special));
1da177e4
LT
2016 } else {
2017 netif_rx(skb);
2018 }
2019#endif /* CONFIG_IXGB_NAPI */
2020 netdev->last_rx = jiffies;
2021
f404de1c
MC
2022rxdesc_done:
2023 /* clean up descriptor, might be written over by hw */
1da177e4 2024 rx_desc->status = 0;
1da177e4 2025
f404de1c 2026 /* use prefetched values */
1da177e4
LT
2027 rx_desc = next_rxd;
2028 buffer_info = next_buffer;
2029 }
2030
2031 rx_ring->next_to_clean = i;
2032
2033 ixgb_alloc_rx_buffers(adapter);
2034
2035 return cleaned;
2036}
2037
2038/**
2039 * ixgb_alloc_rx_buffers - Replace used receive buffers
2040 * @adapter: address of board private structure
2041 **/
2042
2043static void
2044ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
2045{
2046 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
2047 struct net_device *netdev = adapter->netdev;
2048 struct pci_dev *pdev = adapter->pdev;
2049 struct ixgb_rx_desc *rx_desc;
2050 struct ixgb_buffer *buffer_info;
2051 struct sk_buff *skb;
2052 unsigned int i;
1da177e4
LT
2053 long cleancount;
2054
2055 i = rx_ring->next_to_use;
2056 buffer_info = &rx_ring->buffer_info[i];
2057 cleancount = IXGB_DESC_UNUSED(rx_ring);
2058
1da177e4 2059
41639fed
MC
2060 /* leave three descriptors unused */
2061 while(--cleancount > 2) {
1dfdd7df 2062 /* recycle! its good for you */
69c7a940
AK
2063 skb = buffer_info->skb;
2064 if (skb) {
1dfdd7df
AK
2065 skb_trim(skb, 0);
2066 goto map_skb;
2067 }
1da177e4 2068
69c7a940
AK
2069 skb = netdev_alloc_skb(netdev, adapter->rx_buffer_len
2070 + NET_IP_ALIGN);
1dfdd7df 2071 if (unlikely(!skb)) {
1da177e4 2072 /* Better luck next round */
1dfdd7df 2073 adapter->alloc_rx_buff_failed++;
1da177e4
LT
2074 break;
2075 }
2076
2077 /* Make buffer alignment 2 beyond a 16 byte boundary
2078 * this will result in a 16 byte aligned IP header after
2079 * the 14 byte MAC header is removed
2080 */
2081 skb_reserve(skb, NET_IP_ALIGN);
2082
1da177e4
LT
2083 buffer_info->skb = skb;
2084 buffer_info->length = adapter->rx_buffer_len;
1dfdd7df
AK
2085map_skb:
2086 buffer_info->dma = pci_map_single(pdev,
2087 skb->data,
2088 adapter->rx_buffer_len,
2089 PCI_DMA_FROMDEVICE);
1da177e4 2090
1dfdd7df 2091 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1da177e4 2092 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
41639fed
MC
2093 /* guarantee DD bit not set now before h/w gets descriptor
2094 * this is the rest of the workaround for h/w double
2095 * writeback. */
2096 rx_desc->status = 0;
1da177e4 2097
1da177e4
LT
2098
2099 if(++i == rx_ring->count) i = 0;
2100 buffer_info = &rx_ring->buffer_info[i];
2101 }
2102
1dfdd7df
AK
2103 if (likely(rx_ring->next_to_use != i)) {
2104 rx_ring->next_to_use = i;
2105 if (unlikely(i-- == 0))
2106 i = (rx_ring->count - 1);
2107
2108 /* Force memory writes to complete before letting h/w
2109 * know there are new descriptors to fetch. (Only
2110 * applicable for weak-ordered memory model archs, such
2111 * as IA-64). */
2112 wmb();
2113 IXGB_WRITE_REG(&adapter->hw, RDT, i);
2114 }
1da177e4
LT
2115}
2116
2117/**
2118 * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
2119 *
2120 * @param netdev network interface device structure
2121 * @param grp indicates to enable or disable tagging/stripping
2122 **/
2123static void
2124ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
2125{
8908c6cd 2126 struct ixgb_adapter *adapter = netdev_priv(netdev);
222441a6 2127 u32 ctrl, rctl;
1da177e4
LT
2128
2129 ixgb_irq_disable(adapter);
2130 adapter->vlgrp = grp;
2131
2132 if(grp) {
2133 /* enable VLAN tag insert/strip */
2134 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2135 ctrl |= IXGB_CTRL0_VME;
2136 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2137
2138 /* enable VLAN receive filtering */
2139
2140 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2141 rctl |= IXGB_RCTL_VFE;
2142 rctl &= ~IXGB_RCTL_CFIEN;
2143 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2144 } else {
2145 /* disable VLAN tag insert/strip */
2146
2147 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2148 ctrl &= ~IXGB_CTRL0_VME;
2149 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2150
2151 /* disable VLAN filtering */
2152
2153 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2154 rctl &= ~IXGB_RCTL_VFE;
2155 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2156 }
2157
bab2bce7
JB
2158 /* don't enable interrupts unless we are UP */
2159 if (adapter->netdev->flags & IFF_UP)
2160 ixgb_irq_enable(adapter);
1da177e4
LT
2161}
2162
2163static void
222441a6 2164ixgb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1da177e4 2165{
8908c6cd 2166 struct ixgb_adapter *adapter = netdev_priv(netdev);
222441a6 2167 u32 vfta, index;
1da177e4
LT
2168
2169 /* add VID to filter table */
2170
2171 index = (vid >> 5) & 0x7F;
2172 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2173 vfta |= (1 << (vid & 0x1F));
2174 ixgb_write_vfta(&adapter->hw, index, vfta);
2175}
2176
2177static void
222441a6 2178ixgb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1da177e4 2179{
8908c6cd 2180 struct ixgb_adapter *adapter = netdev_priv(netdev);
222441a6 2181 u32 vfta, index;
1da177e4
LT
2182
2183 ixgb_irq_disable(adapter);
2184
5c15bdec 2185 vlan_group_set_device(adapter->vlgrp, vid, NULL);
1da177e4 2186
bab2bce7
JB
2187 /* don't enable interrupts unless we are UP */
2188 if (adapter->netdev->flags & IFF_UP)
2189 ixgb_irq_enable(adapter);
1da177e4 2190
bab2bce7 2191 /* remove VID from filter table */
1da177e4
LT
2192
2193 index = (vid >> 5) & 0x7F;
2194 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2195 vfta &= ~(1 << (vid & 0x1F));
2196 ixgb_write_vfta(&adapter->hw, index, vfta);
2197}
2198
2199static void
2200ixgb_restore_vlan(struct ixgb_adapter *adapter)
2201{
2202 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2203
2204 if(adapter->vlgrp) {
222441a6 2205 u16 vid;
1da177e4 2206 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
5c15bdec 2207 if(!vlan_group_get_device(adapter->vlgrp, vid))
1da177e4
LT
2208 continue;
2209 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2210 }
2211 }
2212}
2213
1da177e4
LT
2214#ifdef CONFIG_NET_POLL_CONTROLLER
2215/*
2216 * Polling 'interrupt' - used by things like netconsole to send skbs
2217 * without having to re-enable interrupts. It's not called while
2218 * the interrupt routine is executing.
2219 */
2220
2221static void ixgb_netpoll(struct net_device *dev)
2222{
f990b426 2223 struct ixgb_adapter *adapter = netdev_priv(dev);
ac79c82e 2224
1da177e4 2225 disable_irq(adapter->pdev->irq);
7d12e780 2226 ixgb_intr(adapter->pdev->irq, dev);
1da177e4
LT
2227 enable_irq(adapter->pdev->irq);
2228}
2229#endif
2230
01748fbb
LV
2231/**
2232 * ixgb_io_error_detected() - called when PCI error is detected
2233 * @pdev pointer to pci device with error
2234 * @state pci channel state after error
2235 *
2236 * This callback is called by the PCI subsystem whenever
2237 * a PCI bus error is detected.
2238 */
2239static pci_ers_result_t ixgb_io_error_detected (struct pci_dev *pdev,
2240 enum pci_channel_state state)
2241{
2242 struct net_device *netdev = pci_get_drvdata(pdev);
f7d4fa01 2243 struct ixgb_adapter *adapter = netdev_priv(netdev);
01748fbb
LV
2244
2245 if(netif_running(netdev))
446490ca 2246 ixgb_down(adapter, true);
01748fbb
LV
2247
2248 pci_disable_device(pdev);
2249
2250 /* Request a slot reset. */
2251 return PCI_ERS_RESULT_NEED_RESET;
2252}
2253
2254/**
2255 * ixgb_io_slot_reset - called after the pci bus has been reset.
2256 * @pdev pointer to pci device with error
2257 *
2258 * This callback is called after the PCI buss has been reset.
2259 * Basically, this tries to restart the card from scratch.
2260 * This is a shortened version of the device probe/discovery code,
2261 * it resembles the first-half of the ixgb_probe() routine.
2262 */
2263static pci_ers_result_t ixgb_io_slot_reset (struct pci_dev *pdev)
2264{
2265 struct net_device *netdev = pci_get_drvdata(pdev);
f7d4fa01 2266 struct ixgb_adapter *adapter = netdev_priv(netdev);
01748fbb
LV
2267
2268 if(pci_enable_device(pdev)) {
2269 DPRINTK(PROBE, ERR, "Cannot re-enable PCI device after reset.\n");
2270 return PCI_ERS_RESULT_DISCONNECT;
2271 }
2272
2273 /* Perform card reset only on one instance of the card */
2274 if (0 != PCI_FUNC (pdev->devfn))
2275 return PCI_ERS_RESULT_RECOVERED;
2276
2277 pci_set_master(pdev);
2278
2279 netif_carrier_off(netdev);
2280 netif_stop_queue(netdev);
2281 ixgb_reset(adapter);
2282
2283 /* Make sure the EEPROM is good */
2284 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
2285 DPRINTK(PROBE, ERR, "After reset, the EEPROM checksum is not valid.\n");
2286 return PCI_ERS_RESULT_DISCONNECT;
2287 }
2288 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
2289 memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
2290
2291 if(!is_valid_ether_addr(netdev->perm_addr)) {
2292 DPRINTK(PROBE, ERR, "After reset, invalid MAC address.\n");
2293 return PCI_ERS_RESULT_DISCONNECT;
2294 }
2295
2296 return PCI_ERS_RESULT_RECOVERED;
2297}
2298
2299/**
2300 * ixgb_io_resume - called when its OK to resume normal operations
2301 * @pdev pointer to pci device with error
2302 *
2303 * The error recovery driver tells us that its OK to resume
2304 * normal operation. Implementation resembles the second-half
2305 * of the ixgb_probe() routine.
2306 */
2307static void ixgb_io_resume (struct pci_dev *pdev)
2308{
2309 struct net_device *netdev = pci_get_drvdata(pdev);
f7d4fa01 2310 struct ixgb_adapter *adapter = netdev_priv(netdev);
01748fbb
LV
2311
2312 pci_set_master(pdev);
2313
2314 if(netif_running(netdev)) {
2315 if(ixgb_up(adapter)) {
2316 printk ("ixgb: can't bring device back up after reset\n");
2317 return;
2318 }
2319 }
2320
2321 netif_device_attach(netdev);
2322 mod_timer(&adapter->watchdog_timer, jiffies);
2323}
2324
1da177e4 2325/* ixgb_main.c */
This page took 0.669238 seconds and 5 git commands to generate.