aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ixgb/ixgb_main.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/net/ixgb/ixgb_main.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/net/ixgb/ixgb_main.c')
-rw-r--r--drivers/net/ixgb/ixgb_main.c2166
1 files changed, 2166 insertions, 0 deletions
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
new file mode 100644
index 000000000000..7d26623d8592
--- /dev/null
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -0,0 +1,2166 @@
1/*******************************************************************************
2
3
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 The full GNU General Public License is included in this distribution in the
21 file called LICENSE.
22
23 Contact Information:
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include "ixgb.h"
30
31/* Change Log
32 * 1.0.88 01/05/05
33 * - include fix to the condition that determines when to quit NAPI - Robert Olsson
34 * - use netif_poll_{disable/enable} to synchronize between NAPI and i/f up/down
35 * 1.0.84 10/26/04
36 * - reset buffer_info->dma in Tx resource cleanup logic
37 * 1.0.83 10/12/04
38 * - sparse cleanup - shemminger@osdl.org
39 * - fix tx resource cleanup logic
40 */
41
42char ixgb_driver_name[] = "ixgb";
43char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
44
45#ifndef CONFIG_IXGB_NAPI
46#define DRIVERNAPI
47#else
48#define DRIVERNAPI "-NAPI"
49#endif
50char ixgb_driver_version[] = "1.0.90-k2"DRIVERNAPI;
51char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
52
53/* ixgb_pci_tbl - PCI Device ID Table
54 *
55 * Wildcard entries (PCI_ANY_ID) should come last
56 * Last entry must be all 0s
57 *
58 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
59 * Class, Class Mask, private data (not used) }
60 */
61static struct pci_device_id ixgb_pci_tbl[] = {
62 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX,
63 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
64 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_SR,
65 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
66 {INTEL_VENDOR_ID, IXGB_DEVICE_ID_82597EX_LR,
67 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
68
69 /* required last entry */
70 {0,}
71};
72
73MODULE_DEVICE_TABLE(pci, ixgb_pci_tbl);
74
75/* Local Function Prototypes */
76
77int ixgb_up(struct ixgb_adapter *adapter);
78void ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog);
79void ixgb_reset(struct ixgb_adapter *adapter);
80int ixgb_setup_tx_resources(struct ixgb_adapter *adapter);
81int ixgb_setup_rx_resources(struct ixgb_adapter *adapter);
82void ixgb_free_tx_resources(struct ixgb_adapter *adapter);
83void ixgb_free_rx_resources(struct ixgb_adapter *adapter);
84void ixgb_update_stats(struct ixgb_adapter *adapter);
85
86static int ixgb_init_module(void);
87static void ixgb_exit_module(void);
88static int ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
89static void __devexit ixgb_remove(struct pci_dev *pdev);
90static int ixgb_sw_init(struct ixgb_adapter *adapter);
91static int ixgb_open(struct net_device *netdev);
92static int ixgb_close(struct net_device *netdev);
93static void ixgb_configure_tx(struct ixgb_adapter *adapter);
94static void ixgb_configure_rx(struct ixgb_adapter *adapter);
95static void ixgb_setup_rctl(struct ixgb_adapter *adapter);
96static void ixgb_clean_tx_ring(struct ixgb_adapter *adapter);
97static void ixgb_clean_rx_ring(struct ixgb_adapter *adapter);
98static void ixgb_set_multi(struct net_device *netdev);
99static void ixgb_watchdog(unsigned long data);
100static int ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
101static struct net_device_stats *ixgb_get_stats(struct net_device *netdev);
102static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
103static int ixgb_set_mac(struct net_device *netdev, void *p);
104static irqreturn_t ixgb_intr(int irq, void *data, struct pt_regs *regs);
105static boolean_t ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
106#ifdef CONFIG_IXGB_NAPI
107static int ixgb_clean(struct net_device *netdev, int *budget);
108static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
109 int *work_done, int work_to_do);
110#else
111static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter);
112#endif
113static void ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter);
114void ixgb_set_ethtool_ops(struct net_device *netdev);
115static void ixgb_tx_timeout(struct net_device *dev);
116static void ixgb_tx_timeout_task(struct net_device *dev);
117static void ixgb_vlan_rx_register(struct net_device *netdev,
118 struct vlan_group *grp);
119static void ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
120static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
121static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
122
123static int ixgb_notify_reboot(struct notifier_block *, unsigned long event,
124 void *ptr);
125static int ixgb_suspend(struct pci_dev *pdev, uint32_t state);
126
127#ifdef CONFIG_NET_POLL_CONTROLLER
128/* for netdump / net console */
129static void ixgb_netpoll(struct net_device *dev);
130#endif
131
132struct notifier_block ixgb_notifier_reboot = {
133 .notifier_call = ixgb_notify_reboot,
134 .next = NULL,
135 .priority = 0
136};
137
138/* Exported from other modules */
139
140extern void ixgb_check_options(struct ixgb_adapter *adapter);
141
142static struct pci_driver ixgb_driver = {
143 .name = ixgb_driver_name,
144 .id_table = ixgb_pci_tbl,
145 .probe = ixgb_probe,
146 .remove = __devexit_p(ixgb_remove),
147 /* Power Managment Hooks */
148 .suspend = NULL,
149 .resume = NULL
150};
151
152MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
153MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
154MODULE_LICENSE("GPL");
155
156/* some defines for controlling descriptor fetches in h/w */
157#define RXDCTL_PTHRESH_DEFAULT 128 /* chip considers prefech below this */
158#define RXDCTL_HTHRESH_DEFAULT 16 /* chip will only prefetch if tail is
159 pushed this many descriptors from head */
160#define RXDCTL_WTHRESH_DEFAULT 16 /* chip writes back at this many or RXT0 */
161
162/**
163 * ixgb_init_module - Driver Registration Routine
164 *
165 * ixgb_init_module is the first routine called when the driver is
166 * loaded. All it does is register with the PCI subsystem.
167 **/
168
169static int __init
170ixgb_init_module(void)
171{
172 int ret;
173 printk(KERN_INFO "%s - version %s\n",
174 ixgb_driver_string, ixgb_driver_version);
175
176 printk(KERN_INFO "%s\n", ixgb_copyright);
177
178 ret = pci_module_init(&ixgb_driver);
179 if(ret >= 0) {
180 register_reboot_notifier(&ixgb_notifier_reboot);
181 }
182 return ret;
183}
184
185module_init(ixgb_init_module);
186
187/**
188 * ixgb_exit_module - Driver Exit Cleanup Routine
189 *
190 * ixgb_exit_module is called just before the driver is removed
191 * from memory.
192 **/
193
194static void __exit
195ixgb_exit_module(void)
196{
197 unregister_reboot_notifier(&ixgb_notifier_reboot);
198 pci_unregister_driver(&ixgb_driver);
199}
200
201module_exit(ixgb_exit_module);
202
203/**
204 * ixgb_irq_disable - Mask off interrupt generation on the NIC
205 * @adapter: board private structure
206 **/
207
208static inline void
209ixgb_irq_disable(struct ixgb_adapter *adapter)
210{
211 atomic_inc(&adapter->irq_sem);
212 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
213 IXGB_WRITE_FLUSH(&adapter->hw);
214 synchronize_irq(adapter->pdev->irq);
215}
216
217/**
218 * ixgb_irq_enable - Enable default interrupt generation settings
219 * @adapter: board private structure
220 **/
221
222static inline void
223ixgb_irq_enable(struct ixgb_adapter *adapter)
224{
225 if(atomic_dec_and_test(&adapter->irq_sem)) {
226 IXGB_WRITE_REG(&adapter->hw, IMS,
227 IXGB_INT_RXT0 | IXGB_INT_RXDMT0 | IXGB_INT_TXDW |
228 IXGB_INT_RXO | IXGB_INT_LSC);
229 IXGB_WRITE_FLUSH(&adapter->hw);
230 }
231}
232
233int
234ixgb_up(struct ixgb_adapter *adapter)
235{
236 struct net_device *netdev = adapter->netdev;
237 int err;
238 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
239 struct ixgb_hw *hw = &adapter->hw;
240
241 /* hardware has been reset, we need to reload some things */
242
243 ixgb_set_multi(netdev);
244
245 ixgb_restore_vlan(adapter);
246
247 ixgb_configure_tx(adapter);
248 ixgb_setup_rctl(adapter);
249 ixgb_configure_rx(adapter);
250 ixgb_alloc_rx_buffers(adapter);
251
252#ifdef CONFIG_PCI_MSI
253 {
254 boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) &
255 IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE;
256 adapter->have_msi = TRUE;
257
258 if (!pcix)
259 adapter->have_msi = FALSE;
260 else if((err = pci_enable_msi(adapter->pdev))) {
261 printk (KERN_ERR
262 "Unable to allocate MSI interrupt Error: %d\n", err);
263 adapter->have_msi = FALSE;
264 /* proceed to try to request regular interrupt */
265 }
266 }
267
268#endif
269 if((err = request_irq(adapter->pdev->irq, &ixgb_intr,
270 SA_SHIRQ | SA_SAMPLE_RANDOM,
271 netdev->name, netdev)))
272 return err;
273
274 /* disable interrupts and get the hardware into a known state */
275 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
276
277 if((hw->max_frame_size != max_frame) ||
278 (hw->max_frame_size !=
279 (IXGB_READ_REG(hw, MFS) >> IXGB_MFS_SHIFT))) {
280
281 hw->max_frame_size = max_frame;
282
283 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
284
285 if(hw->max_frame_size >
286 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
287 uint32_t ctrl0 = IXGB_READ_REG(hw, CTRL0);
288
289 if(!(ctrl0 & IXGB_CTRL0_JFE)) {
290 ctrl0 |= IXGB_CTRL0_JFE;
291 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
292 }
293 }
294 }
295
296 mod_timer(&adapter->watchdog_timer, jiffies);
297 ixgb_irq_enable(adapter);
298
299#ifdef CONFIG_IXGB_NAPI
300 netif_poll_enable(netdev);
301#endif
302 return 0;
303}
304
305void
306ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
307{
308 struct net_device *netdev = adapter->netdev;
309
310 ixgb_irq_disable(adapter);
311 free_irq(adapter->pdev->irq, netdev);
312#ifdef CONFIG_PCI_MSI
313 if(adapter->have_msi == TRUE)
314 pci_disable_msi(adapter->pdev);
315
316#endif
317 if(kill_watchdog)
318 del_timer_sync(&adapter->watchdog_timer);
319#ifdef CONFIG_IXGB_NAPI
320 netif_poll_disable(netdev);
321#endif
322 adapter->link_speed = 0;
323 adapter->link_duplex = 0;
324 netif_carrier_off(netdev);
325 netif_stop_queue(netdev);
326
327 ixgb_reset(adapter);
328 ixgb_clean_tx_ring(adapter);
329 ixgb_clean_rx_ring(adapter);
330}
331
332void
333ixgb_reset(struct ixgb_adapter *adapter)
334{
335
336 ixgb_adapter_stop(&adapter->hw);
337 if(!ixgb_init_hw(&adapter->hw))
338 IXGB_DBG("ixgb_init_hw failed.\n");
339}
340
341/**
342 * ixgb_probe - Device Initialization Routine
343 * @pdev: PCI device information struct
344 * @ent: entry in ixgb_pci_tbl
345 *
346 * Returns 0 on success, negative on failure
347 *
348 * ixgb_probe initializes an adapter identified by a pci_dev structure.
349 * The OS initialization, configuring of the adapter private structure,
350 * and a hardware reset occur.
351 **/
352
353static int __devinit
354ixgb_probe(struct pci_dev *pdev,
355 const struct pci_device_id *ent)
356{
357 struct net_device *netdev = NULL;
358 struct ixgb_adapter *adapter;
359 static int cards_found = 0;
360 unsigned long mmio_start;
361 int mmio_len;
362 int pci_using_dac;
363 int i;
364 int err;
365
366 if((err = pci_enable_device(pdev)))
367 return err;
368
369 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) {
370 pci_using_dac = 1;
371 } else {
372 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
373 IXGB_ERR("No usable DMA configuration, aborting\n");
374 return err;
375 }
376 pci_using_dac = 0;
377 }
378
379 if((err = pci_request_regions(pdev, ixgb_driver_name)))
380 return err;
381
382 pci_set_master(pdev);
383
384 netdev = alloc_etherdev(sizeof(struct ixgb_adapter));
385 if(!netdev) {
386 err = -ENOMEM;
387 goto err_alloc_etherdev;
388 }
389
390 SET_MODULE_OWNER(netdev);
391 SET_NETDEV_DEV(netdev, &pdev->dev);
392
393 pci_set_drvdata(pdev, netdev);
394 adapter = netdev->priv;
395 adapter->netdev = netdev;
396 adapter->pdev = pdev;
397 adapter->hw.back = adapter;
398
399 mmio_start = pci_resource_start(pdev, BAR_0);
400 mmio_len = pci_resource_len(pdev, BAR_0);
401
402 adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
403 if(!adapter->hw.hw_addr) {
404 err = -EIO;
405 goto err_ioremap;
406 }
407
408 for(i = BAR_1; i <= BAR_5; i++) {
409 if(pci_resource_len(pdev, i) == 0)
410 continue;
411 if(pci_resource_flags(pdev, i) & IORESOURCE_IO) {
412 adapter->hw.io_base = pci_resource_start(pdev, i);
413 break;
414 }
415 }
416
417 netdev->open = &ixgb_open;
418 netdev->stop = &ixgb_close;
419 netdev->hard_start_xmit = &ixgb_xmit_frame;
420 netdev->get_stats = &ixgb_get_stats;
421 netdev->set_multicast_list = &ixgb_set_multi;
422 netdev->set_mac_address = &ixgb_set_mac;
423 netdev->change_mtu = &ixgb_change_mtu;
424 ixgb_set_ethtool_ops(netdev);
425 netdev->tx_timeout = &ixgb_tx_timeout;
426 netdev->watchdog_timeo = HZ;
427#ifdef CONFIG_IXGB_NAPI
428 netdev->poll = &ixgb_clean;
429 netdev->weight = 64;
430#endif
431 netdev->vlan_rx_register = ixgb_vlan_rx_register;
432 netdev->vlan_rx_add_vid = ixgb_vlan_rx_add_vid;
433 netdev->vlan_rx_kill_vid = ixgb_vlan_rx_kill_vid;
434#ifdef CONFIG_NET_POLL_CONTROLLER
435 netdev->poll_controller = ixgb_netpoll;
436#endif
437
438 netdev->mem_start = mmio_start;
439 netdev->mem_end = mmio_start + mmio_len;
440 netdev->base_addr = adapter->hw.io_base;
441
442 adapter->bd_number = cards_found;
443 adapter->link_speed = 0;
444 adapter->link_duplex = 0;
445
446 /* setup the private structure */
447
448 if((err = ixgb_sw_init(adapter)))
449 goto err_sw_init;
450
451 netdev->features = NETIF_F_SG |
452 NETIF_F_HW_CSUM |
453 NETIF_F_HW_VLAN_TX |
454 NETIF_F_HW_VLAN_RX |
455 NETIF_F_HW_VLAN_FILTER;
456#ifdef NETIF_F_TSO
457 netdev->features |= NETIF_F_TSO;
458#endif
459
460 if(pci_using_dac)
461 netdev->features |= NETIF_F_HIGHDMA;
462
463 /* make sure the EEPROM is good */
464
465 if(!ixgb_validate_eeprom_checksum(&adapter->hw)) {
466 printk(KERN_ERR "The EEPROM Checksum Is Not Valid\n");
467 err = -EIO;
468 goto err_eeprom;
469 }
470
471 ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
472
473 if(!is_valid_ether_addr(netdev->dev_addr)) {
474 err = -EIO;
475 goto err_eeprom;
476 }
477
478 adapter->part_num = ixgb_get_ee_pba_number(&adapter->hw);
479
480 init_timer(&adapter->watchdog_timer);
481 adapter->watchdog_timer.function = &ixgb_watchdog;
482 adapter->watchdog_timer.data = (unsigned long)adapter;
483
484 INIT_WORK(&adapter->tx_timeout_task,
485 (void (*)(void *))ixgb_tx_timeout_task, netdev);
486
487 if((err = register_netdev(netdev)))
488 goto err_register;
489
490 /* we're going to reset, so assume we have no link for now */
491
492 netif_carrier_off(netdev);
493 netif_stop_queue(netdev);
494
495 printk(KERN_INFO "%s: Intel(R) PRO/10GbE Network Connection\n",
496 netdev->name);
497 ixgb_check_options(adapter);
498 /* reset the hardware with the new settings */
499
500 ixgb_reset(adapter);
501
502 cards_found++;
503 return 0;
504
505err_register:
506err_sw_init:
507err_eeprom:
508 iounmap(adapter->hw.hw_addr);
509err_ioremap:
510 free_netdev(netdev);
511err_alloc_etherdev:
512 pci_release_regions(pdev);
513 return err;
514}
515
516/**
517 * ixgb_remove - Device Removal Routine
518 * @pdev: PCI device information struct
519 *
520 * ixgb_remove is called by the PCI subsystem to alert the driver
521 * that it should release a PCI device. The could be caused by a
522 * Hot-Plug event, or because the driver is going to be removed from
523 * memory.
524 **/
525
526static void __devexit
527ixgb_remove(struct pci_dev *pdev)
528{
529 struct net_device *netdev = pci_get_drvdata(pdev);
530 struct ixgb_adapter *adapter = netdev->priv;
531
532 unregister_netdev(netdev);
533
534 iounmap(adapter->hw.hw_addr);
535 pci_release_regions(pdev);
536
537 free_netdev(netdev);
538}
539
540/**
541 * ixgb_sw_init - Initialize general software structures (struct ixgb_adapter)
542 * @adapter: board private structure to initialize
543 *
544 * ixgb_sw_init initializes the Adapter private data structure.
545 * Fields are initialized based on PCI device information and
546 * OS network device settings (MTU size).
547 **/
548
549static int __devinit
550ixgb_sw_init(struct ixgb_adapter *adapter)
551{
552 struct ixgb_hw *hw = &adapter->hw;
553 struct net_device *netdev = adapter->netdev;
554 struct pci_dev *pdev = adapter->pdev;
555
556 /* PCI config space info */
557
558 hw->vendor_id = pdev->vendor;
559 hw->device_id = pdev->device;
560 hw->subsystem_vendor_id = pdev->subsystem_vendor;
561 hw->subsystem_id = pdev->subsystem_device;
562
563 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
564
565 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
566
567 if((hw->device_id == IXGB_DEVICE_ID_82597EX)
568 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_LR)
569 ||(hw->device_id == IXGB_DEVICE_ID_82597EX_SR))
570 hw->mac_type = ixgb_82597;
571 else {
572 /* should never have loaded on this device */
573 printk(KERN_ERR "ixgb: unsupported device id\n");
574 }
575
576 /* enable flow control to be programmed */
577 hw->fc.send_xon = 1;
578
579 atomic_set(&adapter->irq_sem, 1);
580 spin_lock_init(&adapter->tx_lock);
581
582 return 0;
583}
584
585/**
586 * ixgb_open - Called when a network interface is made active
587 * @netdev: network interface device structure
588 *
589 * Returns 0 on success, negative value on failure
590 *
591 * The open entry point is called when a network interface is made
592 * active by the system (IFF_UP). At this point all resources needed
593 * for transmit and receive operations are allocated, the interrupt
594 * handler is registered with the OS, the watchdog timer is started,
595 * and the stack is notified that the interface is ready.
596 **/
597
598static int
599ixgb_open(struct net_device *netdev)
600{
601 struct ixgb_adapter *adapter = netdev->priv;
602 int err;
603
604 /* allocate transmit descriptors */
605
606 if((err = ixgb_setup_tx_resources(adapter)))
607 goto err_setup_tx;
608
609 /* allocate receive descriptors */
610
611 if((err = ixgb_setup_rx_resources(adapter)))
612 goto err_setup_rx;
613
614 if((err = ixgb_up(adapter)))
615 goto err_up;
616
617 return 0;
618
619err_up:
620 ixgb_free_rx_resources(adapter);
621err_setup_rx:
622 ixgb_free_tx_resources(adapter);
623err_setup_tx:
624 ixgb_reset(adapter);
625
626 return err;
627}
628
629/**
630 * ixgb_close - Disables a network interface
631 * @netdev: network interface device structure
632 *
633 * Returns 0, this is not allowed to fail
634 *
635 * The close entry point is called when an interface is de-activated
636 * by the OS. The hardware is still under the drivers control, but
637 * needs to be disabled. A global MAC reset is issued to stop the
638 * hardware, and all transmit and receive resources are freed.
639 **/
640
641static int
642ixgb_close(struct net_device *netdev)
643{
644 struct ixgb_adapter *adapter = netdev->priv;
645
646 ixgb_down(adapter, TRUE);
647
648 ixgb_free_tx_resources(adapter);
649 ixgb_free_rx_resources(adapter);
650
651 return 0;
652}
653
654/**
655 * ixgb_setup_tx_resources - allocate Tx resources (Descriptors)
656 * @adapter: board private structure
657 *
658 * Return 0 on success, negative on failure
659 **/
660
661int
662ixgb_setup_tx_resources(struct ixgb_adapter *adapter)
663{
664 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
665 struct pci_dev *pdev = adapter->pdev;
666 int size;
667
668 size = sizeof(struct ixgb_buffer) * txdr->count;
669 txdr->buffer_info = vmalloc(size);
670 if(!txdr->buffer_info) {
671 return -ENOMEM;
672 }
673 memset(txdr->buffer_info, 0, size);
674
675 /* round up to nearest 4K */
676
677 txdr->size = txdr->count * sizeof(struct ixgb_tx_desc);
678 IXGB_ROUNDUP(txdr->size, 4096);
679
680 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
681 if(!txdr->desc) {
682 vfree(txdr->buffer_info);
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{
703 uint64_t tdba = adapter->tx_ring.dma;
704 uint32_t tdlen = adapter->tx_ring.count * sizeof(struct ixgb_tx_desc);
705 uint32_t tctl;
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) {
756 return -ENOMEM;
757 }
758 memset(rxdr->buffer_info, 0, size);
759
760 /* Round up to nearest 4K */
761
762 rxdr->size = rxdr->count * sizeof(struct ixgb_rx_desc);
763 IXGB_ROUNDUP(rxdr->size, 4096);
764
765 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
766
767 if(!rxdr->desc) {
768 vfree(rxdr->buffer_info);
769 return -ENOMEM;
770 }
771 memset(rxdr->desc, 0, rxdr->size);
772
773 rxdr->next_to_clean = 0;
774 rxdr->next_to_use = 0;
775
776 return 0;
777}
778
779/**
780 * ixgb_setup_rctl - configure the receive control register
781 * @adapter: Board private structure
782 **/
783
784static void
785ixgb_setup_rctl(struct ixgb_adapter *adapter)
786{
787 uint32_t rctl;
788
789 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
790
791 rctl &= ~(3 << IXGB_RCTL_MO_SHIFT);
792
793 rctl |=
794 IXGB_RCTL_BAM | IXGB_RCTL_RDMTS_1_2 |
795 IXGB_RCTL_RXEN | IXGB_RCTL_CFF |
796 (adapter->hw.mc_filter_type << IXGB_RCTL_MO_SHIFT);
797
798 rctl |= IXGB_RCTL_SECRC;
799
800 switch (adapter->rx_buffer_len) {
801 case IXGB_RXBUFFER_2048:
802 default:
803 rctl |= IXGB_RCTL_BSIZE_2048;
804 break;
805 case IXGB_RXBUFFER_4096:
806 rctl |= IXGB_RCTL_BSIZE_4096;
807 break;
808 case IXGB_RXBUFFER_8192:
809 rctl |= IXGB_RCTL_BSIZE_8192;
810 break;
811 case IXGB_RXBUFFER_16384:
812 rctl |= IXGB_RCTL_BSIZE_16384;
813 break;
814 }
815
816 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
817}
818
819/**
820 * ixgb_configure_rx - Configure 82597 Receive Unit after Reset.
821 * @adapter: board private structure
822 *
823 * Configure the Rx unit of the MAC after a reset.
824 **/
825
826static void
827ixgb_configure_rx(struct ixgb_adapter *adapter)
828{
829 uint64_t rdba = adapter->rx_ring.dma;
830 uint32_t rdlen = adapter->rx_ring.count * sizeof(struct ixgb_rx_desc);
831 struct ixgb_hw *hw = &adapter->hw;
832 uint32_t rctl;
833 uint32_t rxcsum;
834 uint32_t rxdctl;
835
836 /* make sure receives are disabled while setting up the descriptors */
837
838 rctl = IXGB_READ_REG(hw, RCTL);
839 IXGB_WRITE_REG(hw, RCTL, rctl & ~IXGB_RCTL_RXEN);
840
841 /* set the Receive Delay Timer Register */
842
843 IXGB_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
844
845 /* Setup the Base and Length of the Rx Descriptor Ring */
846
847 IXGB_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
848 IXGB_WRITE_REG(hw, RDBAH, (rdba >> 32));
849
850 IXGB_WRITE_REG(hw, RDLEN, rdlen);
851
852 /* Setup the HW Rx Head and Tail Descriptor Pointers */
853 IXGB_WRITE_REG(hw, RDH, 0);
854 IXGB_WRITE_REG(hw, RDT, 0);
855
856 /* set up pre-fetching of receive buffers so we get some before we
857 * run out (default hardware behavior is to run out before fetching
858 * more). This sets up to fetch if HTHRESH rx descriptors are avail
859 * and the descriptors in hw cache are below PTHRESH. This avoids
860 * the hardware behavior of fetching <=512 descriptors in a single
861 * burst that pre-empts all other activity, usually causing fifo
862 * overflows. */
863 /* use WTHRESH to burst write 16 descriptors or burst when RXT0 */
864 rxdctl = RXDCTL_WTHRESH_DEFAULT << IXGB_RXDCTL_WTHRESH_SHIFT |
865 RXDCTL_HTHRESH_DEFAULT << IXGB_RXDCTL_HTHRESH_SHIFT |
866 RXDCTL_PTHRESH_DEFAULT << IXGB_RXDCTL_PTHRESH_SHIFT;
867 IXGB_WRITE_REG(hw, RXDCTL, rxdctl);
868
869 /* Enable Receive Checksum Offload for TCP and UDP */
870 if(adapter->rx_csum == TRUE) {
871 rxcsum = IXGB_READ_REG(hw, RXCSUM);
872 rxcsum |= IXGB_RXCSUM_TUOFL;
873 IXGB_WRITE_REG(hw, RXCSUM, rxcsum);
874 }
875
876 /* Enable Receives */
877
878 IXGB_WRITE_REG(hw, RCTL, rctl);
879}
880
881/**
882 * ixgb_free_tx_resources - Free Tx Resources
883 * @adapter: board private structure
884 *
885 * Free all transmit software resources
886 **/
887
888void
889ixgb_free_tx_resources(struct ixgb_adapter *adapter)
890{
891 struct pci_dev *pdev = adapter->pdev;
892
893 ixgb_clean_tx_ring(adapter);
894
895 vfree(adapter->tx_ring.buffer_info);
896 adapter->tx_ring.buffer_info = NULL;
897
898 pci_free_consistent(pdev, adapter->tx_ring.size,
899 adapter->tx_ring.desc, adapter->tx_ring.dma);
900
901 adapter->tx_ring.desc = NULL;
902}
903
904static inline void
905ixgb_unmap_and_free_tx_resource(struct ixgb_adapter *adapter,
906 struct ixgb_buffer *buffer_info)
907{
908 struct pci_dev *pdev = adapter->pdev;
909 if(buffer_info->dma) {
910 pci_unmap_page(pdev,
911 buffer_info->dma,
912 buffer_info->length,
913 PCI_DMA_TODEVICE);
914 buffer_info->dma = 0;
915 }
916 if(buffer_info->skb) {
917 dev_kfree_skb_any(buffer_info->skb);
918 buffer_info->skb = NULL;
919 }
920}
921
922/**
923 * ixgb_clean_tx_ring - Free Tx Buffers
924 * @adapter: board private structure
925 **/
926
927static void
928ixgb_clean_tx_ring(struct ixgb_adapter *adapter)
929{
930 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
931 struct ixgb_buffer *buffer_info;
932 unsigned long size;
933 unsigned int i;
934
935 /* Free all the Tx ring sk_buffs */
936
937 for(i = 0; i < tx_ring->count; i++) {
938 buffer_info = &tx_ring->buffer_info[i];
939 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
940 }
941
942 size = sizeof(struct ixgb_buffer) * tx_ring->count;
943 memset(tx_ring->buffer_info, 0, size);
944
945 /* Zero out the descriptor ring */
946
947 memset(tx_ring->desc, 0, tx_ring->size);
948
949 tx_ring->next_to_use = 0;
950 tx_ring->next_to_clean = 0;
951
952 IXGB_WRITE_REG(&adapter->hw, TDH, 0);
953 IXGB_WRITE_REG(&adapter->hw, TDT, 0);
954}
955
956/**
957 * ixgb_free_rx_resources - Free Rx Resources
958 * @adapter: board private structure
959 *
960 * Free all receive software resources
961 **/
962
963void
964ixgb_free_rx_resources(struct ixgb_adapter *adapter)
965{
966 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
967 struct pci_dev *pdev = adapter->pdev;
968
969 ixgb_clean_rx_ring(adapter);
970
971 vfree(rx_ring->buffer_info);
972 rx_ring->buffer_info = NULL;
973
974 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
975
976 rx_ring->desc = NULL;
977}
978
979/**
980 * ixgb_clean_rx_ring - Free Rx Buffers
981 * @adapter: board private structure
982 **/
983
984static void
985ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
986{
987 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
988 struct ixgb_buffer *buffer_info;
989 struct pci_dev *pdev = adapter->pdev;
990 unsigned long size;
991 unsigned int i;
992
993 /* Free all the Rx ring sk_buffs */
994
995 for(i = 0; i < rx_ring->count; i++) {
996 buffer_info = &rx_ring->buffer_info[i];
997 if(buffer_info->skb) {
998
999 pci_unmap_single(pdev,
1000 buffer_info->dma,
1001 buffer_info->length,
1002 PCI_DMA_FROMDEVICE);
1003
1004 dev_kfree_skb(buffer_info->skb);
1005
1006 buffer_info->skb = NULL;
1007 }
1008 }
1009
1010 size = sizeof(struct ixgb_buffer) * rx_ring->count;
1011 memset(rx_ring->buffer_info, 0, size);
1012
1013 /* Zero out the descriptor ring */
1014
1015 memset(rx_ring->desc, 0, rx_ring->size);
1016
1017 rx_ring->next_to_clean = 0;
1018 rx_ring->next_to_use = 0;
1019
1020 IXGB_WRITE_REG(&adapter->hw, RDH, 0);
1021 IXGB_WRITE_REG(&adapter->hw, RDT, 0);
1022}
1023
1024/**
1025 * ixgb_set_mac - Change the Ethernet Address of the NIC
1026 * @netdev: network interface device structure
1027 * @p: pointer to an address structure
1028 *
1029 * Returns 0 on success, negative on failure
1030 **/
1031
1032static int
1033ixgb_set_mac(struct net_device *netdev, void *p)
1034{
1035 struct ixgb_adapter *adapter = netdev->priv;
1036 struct sockaddr *addr = p;
1037
1038 if(!is_valid_ether_addr(addr->sa_data))
1039 return -EADDRNOTAVAIL;
1040
1041 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
1042
1043 ixgb_rar_set(&adapter->hw, addr->sa_data, 0);
1044
1045 return 0;
1046}
1047
1048/**
1049 * ixgb_set_multi - Multicast and Promiscuous mode set
1050 * @netdev: network interface device structure
1051 *
1052 * The set_multi entry point is called whenever the multicast address
1053 * list or the network interface flags are updated. This routine is
1054 * responsible for configuring the hardware for proper multicast,
1055 * promiscuous mode, and all-multi behavior.
1056 **/
1057
1058static void
1059ixgb_set_multi(struct net_device *netdev)
1060{
1061 struct ixgb_adapter *adapter = netdev->priv;
1062 struct ixgb_hw *hw = &adapter->hw;
1063 struct dev_mc_list *mc_ptr;
1064 uint32_t rctl;
1065 int i;
1066
1067 /* Check for Promiscuous and All Multicast modes */
1068
1069 rctl = IXGB_READ_REG(hw, RCTL);
1070
1071 if(netdev->flags & IFF_PROMISC) {
1072 rctl |= (IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1073 } else if(netdev->flags & IFF_ALLMULTI) {
1074 rctl |= IXGB_RCTL_MPE;
1075 rctl &= ~IXGB_RCTL_UPE;
1076 } else {
1077 rctl &= ~(IXGB_RCTL_UPE | IXGB_RCTL_MPE);
1078 }
1079
1080 if(netdev->mc_count > IXGB_MAX_NUM_MULTICAST_ADDRESSES) {
1081 rctl |= IXGB_RCTL_MPE;
1082 IXGB_WRITE_REG(hw, RCTL, rctl);
1083 } else {
1084 uint8_t mta[netdev->mc_count * IXGB_ETH_LENGTH_OF_ADDRESS];
1085
1086 IXGB_WRITE_REG(hw, RCTL, rctl);
1087
1088 for(i = 0, mc_ptr = netdev->mc_list; mc_ptr;
1089 i++, mc_ptr = mc_ptr->next)
1090 memcpy(&mta[i * IXGB_ETH_LENGTH_OF_ADDRESS],
1091 mc_ptr->dmi_addr, IXGB_ETH_LENGTH_OF_ADDRESS);
1092
1093 ixgb_mc_addr_list_update(hw, mta, netdev->mc_count, 0);
1094 }
1095}
1096
1097/**
1098 * ixgb_watchdog - Timer Call-back
1099 * @data: pointer to netdev cast into an unsigned long
1100 **/
1101
1102static void
1103ixgb_watchdog(unsigned long data)
1104{
1105 struct ixgb_adapter *adapter = (struct ixgb_adapter *)data;
1106 struct net_device *netdev = adapter->netdev;
1107 struct ixgb_desc_ring *txdr = &adapter->tx_ring;
1108
1109 ixgb_check_for_link(&adapter->hw);
1110
1111 if (ixgb_check_for_bad_link(&adapter->hw)) {
1112 /* force the reset path */
1113 netif_stop_queue(netdev);
1114 }
1115
1116 if(adapter->hw.link_up) {
1117 if(!netif_carrier_ok(netdev)) {
1118 printk(KERN_INFO "ixgb: %s NIC Link is Up %d Mbps %s\n",
1119 netdev->name, 10000, "Full Duplex");
1120 adapter->link_speed = 10000;
1121 adapter->link_duplex = FULL_DUPLEX;
1122 netif_carrier_on(netdev);
1123 netif_wake_queue(netdev);
1124 }
1125 } else {
1126 if(netif_carrier_ok(netdev)) {
1127 adapter->link_speed = 0;
1128 adapter->link_duplex = 0;
1129 printk(KERN_INFO
1130 "ixgb: %s NIC Link is Down\n",
1131 netdev->name);
1132 netif_carrier_off(netdev);
1133 netif_stop_queue(netdev);
1134
1135 }
1136 }
1137
1138 ixgb_update_stats(adapter);
1139
1140 if(!netif_carrier_ok(netdev)) {
1141 if(IXGB_DESC_UNUSED(txdr) + 1 < txdr->count) {
1142 /* We've lost link, so the controller stops DMA,
1143 * but we've got queued Tx work that's never going
1144 * to get done, so reset controller to flush Tx.
1145 * (Do the reset outside of interrupt context). */
1146 schedule_work(&adapter->tx_timeout_task);
1147 }
1148 }
1149
1150 /* Force detection of hung controller every watchdog period */
1151 adapter->detect_tx_hung = TRUE;
1152
1153 /* generate an interrupt to force clean up of any stragglers */
1154 IXGB_WRITE_REG(&adapter->hw, ICS, IXGB_INT_TXDW);
1155
1156 /* Reset the timer */
1157 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1158}
1159
1160#define IXGB_TX_FLAGS_CSUM 0x00000001
1161#define IXGB_TX_FLAGS_VLAN 0x00000002
1162#define IXGB_TX_FLAGS_TSO 0x00000004
1163
1164static inline int
1165ixgb_tso(struct ixgb_adapter *adapter, struct sk_buff *skb)
1166{
1167#ifdef NETIF_F_TSO
1168 struct ixgb_context_desc *context_desc;
1169 unsigned int i;
1170 uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
1171 uint16_t ipcse, tucse, mss;
1172 int err;
1173
1174 if(likely(skb_shinfo(skb)->tso_size)) {
1175 if (skb_header_cloned(skb)) {
1176 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1177 if (err)
1178 return err;
1179 }
1180
1181 hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2));
1182 mss = skb_shinfo(skb)->tso_size;
1183 skb->nh.iph->tot_len = 0;
1184 skb->nh.iph->check = 0;
1185 skb->h.th->check = ~csum_tcpudp_magic(skb->nh.iph->saddr,
1186 skb->nh.iph->daddr,
1187 0, IPPROTO_TCP, 0);
1188 ipcss = skb->nh.raw - skb->data;
1189 ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data;
1190 ipcse = skb->h.raw - skb->data - 1;
1191 tucss = skb->h.raw - skb->data;
1192 tucso = (void *)&(skb->h.th->check) - (void *)skb->data;
1193 tucse = 0;
1194
1195 i = adapter->tx_ring.next_to_use;
1196 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1197
1198 context_desc->ipcss = ipcss;
1199 context_desc->ipcso = ipcso;
1200 context_desc->ipcse = cpu_to_le16(ipcse);
1201 context_desc->tucss = tucss;
1202 context_desc->tucso = tucso;
1203 context_desc->tucse = cpu_to_le16(tucse);
1204 context_desc->mss = cpu_to_le16(mss);
1205 context_desc->hdr_len = hdr_len;
1206 context_desc->status = 0;
1207 context_desc->cmd_type_len = cpu_to_le32(
1208 IXGB_CONTEXT_DESC_TYPE
1209 | IXGB_CONTEXT_DESC_CMD_TSE
1210 | IXGB_CONTEXT_DESC_CMD_IP
1211 | IXGB_CONTEXT_DESC_CMD_TCP
1212 | IXGB_CONTEXT_DESC_CMD_RS
1213 | IXGB_CONTEXT_DESC_CMD_IDE
1214 | (skb->len - (hdr_len)));
1215
1216 if(++i == adapter->tx_ring.count) i = 0;
1217 adapter->tx_ring.next_to_use = i;
1218
1219 return 1;
1220 }
1221#endif
1222
1223 return 0;
1224}
1225
1226static inline boolean_t
1227ixgb_tx_csum(struct ixgb_adapter *adapter, struct sk_buff *skb)
1228{
1229 struct ixgb_context_desc *context_desc;
1230 unsigned int i;
1231 uint8_t css, cso;
1232
1233 if(likely(skb->ip_summed == CHECKSUM_HW)) {
1234 css = skb->h.raw - skb->data;
1235 cso = (skb->h.raw + skb->csum) - skb->data;
1236
1237 i = adapter->tx_ring.next_to_use;
1238 context_desc = IXGB_CONTEXT_DESC(adapter->tx_ring, i);
1239
1240 context_desc->tucss = css;
1241 context_desc->tucso = cso;
1242 context_desc->tucse = 0;
1243 /* zero out any previously existing data in one instruction */
1244 *(uint32_t *)&(context_desc->ipcss) = 0;
1245 context_desc->status = 0;
1246 context_desc->hdr_len = 0;
1247 context_desc->mss = 0;
1248 context_desc->cmd_type_len =
1249 cpu_to_le32(IXGB_CONTEXT_DESC_TYPE
1250 | IXGB_TX_DESC_CMD_RS
1251 | IXGB_TX_DESC_CMD_IDE);
1252
1253 if(++i == adapter->tx_ring.count) i = 0;
1254 adapter->tx_ring.next_to_use = i;
1255
1256 return TRUE;
1257 }
1258
1259 return FALSE;
1260}
1261
1262#define IXGB_MAX_TXD_PWR 14
1263#define IXGB_MAX_DATA_PER_TXD (1<<IXGB_MAX_TXD_PWR)
1264
1265static inline int
1266ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
1267 unsigned int first)
1268{
1269 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1270 struct ixgb_buffer *buffer_info;
1271 int len = skb->len;
1272 unsigned int offset = 0, size, count = 0, i;
1273
1274 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
1275 unsigned int f;
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];
1282 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1283 buffer_info->length = size;
1284 buffer_info->dma =
1285 pci_map_single(adapter->pdev,
1286 skb->data + offset,
1287 size,
1288 PCI_DMA_TODEVICE);
1289 buffer_info->time_stamp = jiffies;
1290
1291 len -= size;
1292 offset += size;
1293 count++;
1294 if(++i == tx_ring->count) i = 0;
1295 }
1296
1297 for(f = 0; f < nr_frags; f++) {
1298 struct skb_frag_struct *frag;
1299
1300 frag = &skb_shinfo(skb)->frags[f];
1301 len = frag->size;
1302 offset = 0;
1303
1304 while(len) {
1305 buffer_info = &tx_ring->buffer_info[i];
1306 size = min(len, IXGB_MAX_JUMBO_FRAME_SIZE);
1307 buffer_info->length = size;
1308 buffer_info->dma =
1309 pci_map_page(adapter->pdev,
1310 frag->page,
1311 frag->page_offset + offset,
1312 size,
1313 PCI_DMA_TODEVICE);
1314 buffer_info->time_stamp = jiffies;
1315
1316 len -= size;
1317 offset += size;
1318 count++;
1319 if(++i == tx_ring->count) i = 0;
1320 }
1321 }
1322 i = (i == 0) ? tx_ring->count - 1 : i - 1;
1323 tx_ring->buffer_info[i].skb = skb;
1324 tx_ring->buffer_info[first].next_to_watch = i;
1325
1326 return count;
1327}
1328
1329static inline void
1330ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
1331{
1332 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1333 struct ixgb_tx_desc *tx_desc = NULL;
1334 struct ixgb_buffer *buffer_info;
1335 uint32_t cmd_type_len = adapter->tx_cmd_type;
1336 uint8_t status = 0;
1337 uint8_t popts = 0;
1338 unsigned int i;
1339
1340 if(tx_flags & IXGB_TX_FLAGS_TSO) {
1341 cmd_type_len |= IXGB_TX_DESC_CMD_TSE;
1342 popts |= (IXGB_TX_DESC_POPTS_IXSM | IXGB_TX_DESC_POPTS_TXSM);
1343 }
1344
1345 if(tx_flags & IXGB_TX_FLAGS_CSUM)
1346 popts |= IXGB_TX_DESC_POPTS_TXSM;
1347
1348 if(tx_flags & IXGB_TX_FLAGS_VLAN) {
1349 cmd_type_len |= IXGB_TX_DESC_CMD_VLE;
1350 }
1351
1352 i = tx_ring->next_to_use;
1353
1354 while(count--) {
1355 buffer_info = &tx_ring->buffer_info[i];
1356 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1357 tx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1358 tx_desc->cmd_type_len =
1359 cpu_to_le32(cmd_type_len | buffer_info->length);
1360 tx_desc->status = status;
1361 tx_desc->popts = popts;
1362 tx_desc->vlan = cpu_to_le16(vlan_id);
1363
1364 if(++i == tx_ring->count) i = 0;
1365 }
1366
1367 tx_desc->cmd_type_len |= cpu_to_le32(IXGB_TX_DESC_CMD_EOP
1368 | IXGB_TX_DESC_CMD_RS );
1369
1370 /* Force memory writes to complete before letting h/w
1371 * know there are new descriptors to fetch. (Only
1372 * applicable for weak-ordered memory model archs,
1373 * such as IA-64). */
1374 wmb();
1375
1376 tx_ring->next_to_use = i;
1377 IXGB_WRITE_REG(&adapter->hw, TDT, i);
1378}
1379
1380/* Tx Descriptors needed, worst case */
1381#define TXD_USE_COUNT(S) (((S) >> IXGB_MAX_TXD_PWR) + \
1382 (((S) & (IXGB_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
1383#define DESC_NEEDED TXD_USE_COUNT(IXGB_MAX_DATA_PER_TXD) + \
1384 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1
1385
1386static int
1387ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1388{
1389 struct ixgb_adapter *adapter = netdev->priv;
1390 unsigned int first;
1391 unsigned int tx_flags = 0;
1392 unsigned long flags;
1393 int vlan_id = 0;
1394 int tso;
1395
1396 if(skb->len <= 0) {
1397 dev_kfree_skb_any(skb);
1398 return 0;
1399 }
1400
1401 spin_lock_irqsave(&adapter->tx_lock, flags);
1402 if(unlikely(IXGB_DESC_UNUSED(&adapter->tx_ring) < DESC_NEEDED)) {
1403 netif_stop_queue(netdev);
1404 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1405 return 1;
1406 }
1407 spin_unlock_irqrestore(&adapter->tx_lock, flags);
1408
1409 if(adapter->vlgrp && vlan_tx_tag_present(skb)) {
1410 tx_flags |= IXGB_TX_FLAGS_VLAN;
1411 vlan_id = vlan_tx_tag_get(skb);
1412 }
1413
1414 first = adapter->tx_ring.next_to_use;
1415
1416 tso = ixgb_tso(adapter, skb);
1417 if (tso < 0) {
1418 dev_kfree_skb_any(skb);
1419 return NETDEV_TX_OK;
1420 }
1421
1422 if (tso)
1423 tx_flags |= IXGB_TX_FLAGS_TSO;
1424 else if(ixgb_tx_csum(adapter, skb))
1425 tx_flags |= IXGB_TX_FLAGS_CSUM;
1426
1427 ixgb_tx_queue(adapter, ixgb_tx_map(adapter, skb, first), vlan_id,
1428 tx_flags);
1429
1430 netdev->trans_start = jiffies;
1431
1432 return 0;
1433}
1434
1435/**
1436 * ixgb_tx_timeout - Respond to a Tx Hang
1437 * @netdev: network interface device structure
1438 **/
1439
1440static void
1441ixgb_tx_timeout(struct net_device *netdev)
1442{
1443 struct ixgb_adapter *adapter = netdev->priv;
1444
1445 /* Do the reset outside of interrupt context */
1446 schedule_work(&adapter->tx_timeout_task);
1447}
1448
1449static void
1450ixgb_tx_timeout_task(struct net_device *netdev)
1451{
1452 struct ixgb_adapter *adapter = netdev->priv;
1453
1454 ixgb_down(adapter, TRUE);
1455 ixgb_up(adapter);
1456}
1457
1458/**
1459 * ixgb_get_stats - Get System Network Statistics
1460 * @netdev: network interface device structure
1461 *
1462 * Returns the address of the device statistics structure.
1463 * The statistics are actually updated from the timer callback.
1464 **/
1465
1466static struct net_device_stats *
1467ixgb_get_stats(struct net_device *netdev)
1468{
1469 struct ixgb_adapter *adapter = netdev->priv;
1470
1471 return &adapter->net_stats;
1472}
1473
1474/**
1475 * ixgb_change_mtu - Change the Maximum Transfer Unit
1476 * @netdev: network interface device structure
1477 * @new_mtu: new value for maximum frame size
1478 *
1479 * Returns 0 on success, negative on failure
1480 **/
1481
1482static int
1483ixgb_change_mtu(struct net_device *netdev, int new_mtu)
1484{
1485 struct ixgb_adapter *adapter = netdev->priv;
1486 int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1487 int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
1488
1489
1490 if((max_frame < IXGB_MIN_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1491 || (max_frame > IXGB_MAX_JUMBO_FRAME_SIZE + ENET_FCS_LENGTH)) {
1492 IXGB_ERR("Invalid MTU setting\n");
1493 return -EINVAL;
1494 }
1495
1496 if((max_frame <= IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH)
1497 || (max_frame <= IXGB_RXBUFFER_2048)) {
1498 adapter->rx_buffer_len = IXGB_RXBUFFER_2048;
1499
1500 } else if(max_frame <= IXGB_RXBUFFER_4096) {
1501 adapter->rx_buffer_len = IXGB_RXBUFFER_4096;
1502
1503 } else if(max_frame <= IXGB_RXBUFFER_8192) {
1504 adapter->rx_buffer_len = IXGB_RXBUFFER_8192;
1505
1506 } else {
1507 adapter->rx_buffer_len = IXGB_RXBUFFER_16384;
1508 }
1509
1510 netdev->mtu = new_mtu;
1511
1512 if(old_max_frame != max_frame && netif_running(netdev)) {
1513
1514 ixgb_down(adapter, TRUE);
1515 ixgb_up(adapter);
1516 }
1517
1518 return 0;
1519}
1520
1521/**
1522 * ixgb_update_stats - Update the board statistics counters.
1523 * @adapter: board private structure
1524 **/
1525
1526void
1527ixgb_update_stats(struct ixgb_adapter *adapter)
1528{
1529 adapter->stats.tprl += IXGB_READ_REG(&adapter->hw, TPRL);
1530 adapter->stats.tprh += IXGB_READ_REG(&adapter->hw, TPRH);
1531 adapter->stats.gprcl += IXGB_READ_REG(&adapter->hw, GPRCL);
1532 adapter->stats.gprch += IXGB_READ_REG(&adapter->hw, GPRCH);
1533 adapter->stats.bprcl += IXGB_READ_REG(&adapter->hw, BPRCL);
1534 adapter->stats.bprch += IXGB_READ_REG(&adapter->hw, BPRCH);
1535 adapter->stats.mprcl += IXGB_READ_REG(&adapter->hw, MPRCL);
1536 adapter->stats.mprch += IXGB_READ_REG(&adapter->hw, MPRCH);
1537 adapter->stats.uprcl += IXGB_READ_REG(&adapter->hw, UPRCL);
1538 adapter->stats.uprch += IXGB_READ_REG(&adapter->hw, UPRCH);
1539 adapter->stats.vprcl += IXGB_READ_REG(&adapter->hw, VPRCL);
1540 adapter->stats.vprch += IXGB_READ_REG(&adapter->hw, VPRCH);
1541 adapter->stats.jprcl += IXGB_READ_REG(&adapter->hw, JPRCL);
1542 adapter->stats.jprch += IXGB_READ_REG(&adapter->hw, JPRCH);
1543 adapter->stats.gorcl += IXGB_READ_REG(&adapter->hw, GORCL);
1544 adapter->stats.gorch += IXGB_READ_REG(&adapter->hw, GORCH);
1545 adapter->stats.torl += IXGB_READ_REG(&adapter->hw, TORL);
1546 adapter->stats.torh += IXGB_READ_REG(&adapter->hw, TORH);
1547 adapter->stats.rnbc += IXGB_READ_REG(&adapter->hw, RNBC);
1548 adapter->stats.ruc += IXGB_READ_REG(&adapter->hw, RUC);
1549 adapter->stats.roc += IXGB_READ_REG(&adapter->hw, ROC);
1550 adapter->stats.rlec += IXGB_READ_REG(&adapter->hw, RLEC);
1551 adapter->stats.crcerrs += IXGB_READ_REG(&adapter->hw, CRCERRS);
1552 adapter->stats.icbc += IXGB_READ_REG(&adapter->hw, ICBC);
1553 adapter->stats.ecbc += IXGB_READ_REG(&adapter->hw, ECBC);
1554 adapter->stats.mpc += IXGB_READ_REG(&adapter->hw, MPC);
1555 adapter->stats.tptl += IXGB_READ_REG(&adapter->hw, TPTL);
1556 adapter->stats.tpth += IXGB_READ_REG(&adapter->hw, TPTH);
1557 adapter->stats.gptcl += IXGB_READ_REG(&adapter->hw, GPTCL);
1558 adapter->stats.gptch += IXGB_READ_REG(&adapter->hw, GPTCH);
1559 adapter->stats.bptcl += IXGB_READ_REG(&adapter->hw, BPTCL);
1560 adapter->stats.bptch += IXGB_READ_REG(&adapter->hw, BPTCH);
1561 adapter->stats.mptcl += IXGB_READ_REG(&adapter->hw, MPTCL);
1562 adapter->stats.mptch += IXGB_READ_REG(&adapter->hw, MPTCH);
1563 adapter->stats.uptcl += IXGB_READ_REG(&adapter->hw, UPTCL);
1564 adapter->stats.uptch += IXGB_READ_REG(&adapter->hw, UPTCH);
1565 adapter->stats.vptcl += IXGB_READ_REG(&adapter->hw, VPTCL);
1566 adapter->stats.vptch += IXGB_READ_REG(&adapter->hw, VPTCH);
1567 adapter->stats.jptcl += IXGB_READ_REG(&adapter->hw, JPTCL);
1568 adapter->stats.jptch += IXGB_READ_REG(&adapter->hw, JPTCH);
1569 adapter->stats.gotcl += IXGB_READ_REG(&adapter->hw, GOTCL);
1570 adapter->stats.gotch += IXGB_READ_REG(&adapter->hw, GOTCH);
1571 adapter->stats.totl += IXGB_READ_REG(&adapter->hw, TOTL);
1572 adapter->stats.toth += IXGB_READ_REG(&adapter->hw, TOTH);
1573 adapter->stats.dc += IXGB_READ_REG(&adapter->hw, DC);
1574 adapter->stats.plt64c += IXGB_READ_REG(&adapter->hw, PLT64C);
1575 adapter->stats.tsctc += IXGB_READ_REG(&adapter->hw, TSCTC);
1576 adapter->stats.tsctfc += IXGB_READ_REG(&adapter->hw, TSCTFC);
1577 adapter->stats.ibic += IXGB_READ_REG(&adapter->hw, IBIC);
1578 adapter->stats.rfc += IXGB_READ_REG(&adapter->hw, RFC);
1579 adapter->stats.lfc += IXGB_READ_REG(&adapter->hw, LFC);
1580 adapter->stats.pfrc += IXGB_READ_REG(&adapter->hw, PFRC);
1581 adapter->stats.pftc += IXGB_READ_REG(&adapter->hw, PFTC);
1582 adapter->stats.mcfrc += IXGB_READ_REG(&adapter->hw, MCFRC);
1583 adapter->stats.mcftc += IXGB_READ_REG(&adapter->hw, MCFTC);
1584 adapter->stats.xonrxc += IXGB_READ_REG(&adapter->hw, XONRXC);
1585 adapter->stats.xontxc += IXGB_READ_REG(&adapter->hw, XONTXC);
1586 adapter->stats.xoffrxc += IXGB_READ_REG(&adapter->hw, XOFFRXC);
1587 adapter->stats.xofftxc += IXGB_READ_REG(&adapter->hw, XOFFTXC);
1588 adapter->stats.rjc += IXGB_READ_REG(&adapter->hw, RJC);
1589
1590 /* Fill out the OS statistics structure */
1591
1592 adapter->net_stats.rx_packets = adapter->stats.gprcl;
1593 adapter->net_stats.tx_packets = adapter->stats.gptcl;
1594 adapter->net_stats.rx_bytes = adapter->stats.gorcl;
1595 adapter->net_stats.tx_bytes = adapter->stats.gotcl;
1596 adapter->net_stats.multicast = adapter->stats.mprcl;
1597 adapter->net_stats.collisions = 0;
1598
1599 /* ignore RLEC as it reports errors for padded (<64bytes) frames
1600 * with a length in the type/len field */
1601 adapter->net_stats.rx_errors =
1602 /* adapter->stats.rnbc + */ adapter->stats.crcerrs +
1603 adapter->stats.ruc +
1604 adapter->stats.roc /*+ adapter->stats.rlec */ +
1605 adapter->stats.icbc +
1606 adapter->stats.ecbc + adapter->stats.mpc;
1607
1608 adapter->net_stats.rx_dropped = adapter->stats.mpc;
1609
1610 /* see above
1611 * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
1612 */
1613
1614 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
1615 adapter->net_stats.rx_fifo_errors = adapter->stats.mpc;
1616 adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
1617 adapter->net_stats.rx_over_errors = adapter->stats.mpc;
1618
1619 adapter->net_stats.tx_errors = 0;
1620 adapter->net_stats.rx_frame_errors = 0;
1621 adapter->net_stats.tx_aborted_errors = 0;
1622 adapter->net_stats.tx_carrier_errors = 0;
1623 adapter->net_stats.tx_fifo_errors = 0;
1624 adapter->net_stats.tx_heartbeat_errors = 0;
1625 adapter->net_stats.tx_window_errors = 0;
1626}
1627
1628#define IXGB_MAX_INTR 10
1629/**
1630 * ixgb_intr - Interrupt Handler
1631 * @irq: interrupt number
1632 * @data: pointer to a network interface device structure
1633 * @pt_regs: CPU registers structure
1634 **/
1635
1636static irqreturn_t
1637ixgb_intr(int irq, void *data, struct pt_regs *regs)
1638{
1639 struct net_device *netdev = data;
1640 struct ixgb_adapter *adapter = netdev->priv;
1641 struct ixgb_hw *hw = &adapter->hw;
1642 uint32_t icr = IXGB_READ_REG(hw, ICR);
1643#ifndef CONFIG_IXGB_NAPI
1644 unsigned int i;
1645#endif
1646
1647 if(unlikely(!icr))
1648 return IRQ_NONE; /* Not our interrupt */
1649
1650 if(unlikely(icr & (IXGB_INT_RXSEQ | IXGB_INT_LSC))) {
1651 mod_timer(&adapter->watchdog_timer, jiffies);
1652 }
1653
1654#ifdef CONFIG_IXGB_NAPI
1655 if(netif_rx_schedule_prep(netdev)) {
1656
1657 /* Disable interrupts and register for poll. The flush
1658 of the posted write is intentionally left out.
1659 */
1660
1661 atomic_inc(&adapter->irq_sem);
1662 IXGB_WRITE_REG(&adapter->hw, IMC, ~0);
1663 __netif_rx_schedule(netdev);
1664 }
1665#else
1666 /* yes, that is actually a & and it is meant to make sure that
1667 * every pass through this for loop checks both receive and
1668 * transmit queues for completed descriptors, intended to
1669 * avoid starvation issues and assist tx/rx fairness. */
1670 for(i = 0; i < IXGB_MAX_INTR; i++)
1671 if(!ixgb_clean_rx_irq(adapter) &
1672 !ixgb_clean_tx_irq(adapter))
1673 break;
1674#endif
1675 return IRQ_HANDLED;
1676}
1677
1678#ifdef CONFIG_IXGB_NAPI
1679/**
1680 * ixgb_clean - NAPI Rx polling callback
1681 * @adapter: board private structure
1682 **/
1683
1684static int
1685ixgb_clean(struct net_device *netdev, int *budget)
1686{
1687 struct ixgb_adapter *adapter = netdev->priv;
1688 int work_to_do = min(*budget, netdev->quota);
1689 int tx_cleaned;
1690 int work_done = 0;
1691
1692 tx_cleaned = ixgb_clean_tx_irq(adapter);
1693 ixgb_clean_rx_irq(adapter, &work_done, work_to_do);
1694
1695 *budget -= work_done;
1696 netdev->quota -= work_done;
1697
1698 /* if no Tx and not enough Rx work done, exit the polling mode */
1699 if((!tx_cleaned && (work_done == 0)) || !netif_running(netdev)) {
1700 netif_rx_complete(netdev);
1701 ixgb_irq_enable(adapter);
1702 return 0;
1703 }
1704
1705 return 1;
1706}
1707#endif
1708
1709/**
1710 * ixgb_clean_tx_irq - Reclaim resources after transmit completes
1711 * @adapter: board private structure
1712 **/
1713
1714static boolean_t
1715ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1716{
1717 struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
1718 struct net_device *netdev = adapter->netdev;
1719 struct ixgb_tx_desc *tx_desc, *eop_desc;
1720 struct ixgb_buffer *buffer_info;
1721 unsigned int i, eop;
1722 boolean_t cleaned = FALSE;
1723
1724 i = tx_ring->next_to_clean;
1725 eop = tx_ring->buffer_info[i].next_to_watch;
1726 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1727
1728 while(eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1729
1730 for(cleaned = FALSE; !cleaned; ) {
1731 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1732 buffer_info = &tx_ring->buffer_info[i];
1733
1734 if (tx_desc->popts
1735 & (IXGB_TX_DESC_POPTS_TXSM |
1736 IXGB_TX_DESC_POPTS_IXSM))
1737 adapter->hw_csum_tx_good++;
1738
1739 ixgb_unmap_and_free_tx_resource(adapter, buffer_info);
1740
1741 *(uint32_t *)&(tx_desc->status) = 0;
1742
1743 cleaned = (i == eop);
1744 if(++i == tx_ring->count) i = 0;
1745 }
1746
1747 eop = tx_ring->buffer_info[i].next_to_watch;
1748 eop_desc = IXGB_TX_DESC(*tx_ring, eop);
1749 }
1750
1751 tx_ring->next_to_clean = i;
1752
1753 spin_lock(&adapter->tx_lock);
1754 if(cleaned && netif_queue_stopped(netdev) && netif_carrier_ok(netdev) &&
1755 (IXGB_DESC_UNUSED(tx_ring) > IXGB_TX_QUEUE_WAKE)) {
1756
1757 netif_wake_queue(netdev);
1758 }
1759 spin_unlock(&adapter->tx_lock);
1760
1761 if(adapter->detect_tx_hung) {
1762 /* detect a transmit hang in hardware, this serializes the
1763 * check with the clearing of time_stamp and movement of i */
1764 adapter->detect_tx_hung = FALSE;
1765 if(tx_ring->buffer_info[i].dma &&
1766 time_after(jiffies, tx_ring->buffer_info[i].time_stamp + HZ)
1767 && !(IXGB_READ_REG(&adapter->hw, STATUS) &
1768 IXGB_STATUS_TXOFF))
1769 netif_stop_queue(netdev);
1770 }
1771
1772 return cleaned;
1773}
1774
1775/**
1776 * ixgb_rx_checksum - Receive Checksum Offload for 82597.
1777 * @adapter: board private structure
1778 * @rx_desc: receive descriptor
1779 * @sk_buff: socket buffer with received data
1780 **/
1781
1782static inline void
1783ixgb_rx_checksum(struct ixgb_adapter *adapter,
1784 struct ixgb_rx_desc *rx_desc,
1785 struct sk_buff *skb)
1786{
1787 /* Ignore Checksum bit is set OR
1788 * TCP Checksum has not been calculated
1789 */
1790 if((rx_desc->status & IXGB_RX_DESC_STATUS_IXSM) ||
1791 (!(rx_desc->status & IXGB_RX_DESC_STATUS_TCPCS))) {
1792 skb->ip_summed = CHECKSUM_NONE;
1793 return;
1794 }
1795
1796 /* At this point we know the hardware did the TCP checksum */
1797 /* now look at the TCP checksum error bit */
1798 if(rx_desc->errors & IXGB_RX_DESC_ERRORS_TCPE) {
1799 /* let the stack verify checksum errors */
1800 skb->ip_summed = CHECKSUM_NONE;
1801 adapter->hw_csum_rx_error++;
1802 } else {
1803 /* TCP checksum is good */
1804 skb->ip_summed = CHECKSUM_UNNECESSARY;
1805 adapter->hw_csum_rx_good++;
1806 }
1807}
1808
1809/**
1810 * ixgb_clean_rx_irq - Send received data up the network stack,
1811 * @adapter: board private structure
1812 **/
1813
1814static boolean_t
1815#ifdef CONFIG_IXGB_NAPI
1816ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1817#else
1818ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
1819#endif
1820{
1821 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1822 struct net_device *netdev = adapter->netdev;
1823 struct pci_dev *pdev = adapter->pdev;
1824 struct ixgb_rx_desc *rx_desc, *next_rxd;
1825 struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
1826 struct sk_buff *skb, *next_skb;
1827 uint32_t length;
1828 unsigned int i, j;
1829 boolean_t cleaned = FALSE;
1830
1831 i = rx_ring->next_to_clean;
1832 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1833 buffer_info = &rx_ring->buffer_info[i];
1834
1835 while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
1836
1837#ifdef CONFIG_IXGB_NAPI
1838 if(*work_done >= work_to_do)
1839 break;
1840
1841 (*work_done)++;
1842#endif
1843 skb = buffer_info->skb;
1844 prefetch(skb->data);
1845
1846 if(++i == rx_ring->count) i = 0;
1847 next_rxd = IXGB_RX_DESC(*rx_ring, i);
1848 prefetch(next_rxd);
1849
1850 if((j = i + 1) == rx_ring->count) j = 0;
1851 next2_buffer = &rx_ring->buffer_info[j];
1852 prefetch(next2_buffer);
1853
1854 next_buffer = &rx_ring->buffer_info[i];
1855 next_skb = next_buffer->skb;
1856 prefetch(next_skb);
1857
1858
1859 cleaned = TRUE;
1860
1861 pci_unmap_single(pdev,
1862 buffer_info->dma,
1863 buffer_info->length,
1864 PCI_DMA_FROMDEVICE);
1865
1866 length = le16_to_cpu(rx_desc->length);
1867
1868 if(unlikely(!(rx_desc->status & IXGB_RX_DESC_STATUS_EOP))) {
1869
1870 /* All receives must fit into a single buffer */
1871
1872 IXGB_DBG("Receive packet consumed multiple buffers "
1873 "length<%x>\n", length);
1874
1875 dev_kfree_skb_irq(skb);
1876 rx_desc->status = 0;
1877 buffer_info->skb = NULL;
1878
1879 rx_desc = next_rxd;
1880 buffer_info = next_buffer;
1881 continue;
1882 }
1883
1884 if (unlikely(rx_desc->errors
1885 & (IXGB_RX_DESC_ERRORS_CE | IXGB_RX_DESC_ERRORS_SE
1886 | IXGB_RX_DESC_ERRORS_P |
1887 IXGB_RX_DESC_ERRORS_RXE))) {
1888
1889 dev_kfree_skb_irq(skb);
1890 rx_desc->status = 0;
1891 buffer_info->skb = NULL;
1892
1893 rx_desc = next_rxd;
1894 buffer_info = next_buffer;
1895 continue;
1896 }
1897
1898 /* Good Receive */
1899 skb_put(skb, length);
1900
1901 /* Receive Checksum Offload */
1902 ixgb_rx_checksum(adapter, rx_desc, skb);
1903
1904 skb->protocol = eth_type_trans(skb, netdev);
1905#ifdef CONFIG_IXGB_NAPI
1906 if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
1907 vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
1908 le16_to_cpu(rx_desc->special) &
1909 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1910 } else {
1911 netif_receive_skb(skb);
1912 }
1913#else /* CONFIG_IXGB_NAPI */
1914 if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
1915 vlan_hwaccel_rx(skb, adapter->vlgrp,
1916 le16_to_cpu(rx_desc->special) &
1917 IXGB_RX_DESC_SPECIAL_VLAN_MASK);
1918 } else {
1919 netif_rx(skb);
1920 }
1921#endif /* CONFIG_IXGB_NAPI */
1922 netdev->last_rx = jiffies;
1923
1924 rx_desc->status = 0;
1925 buffer_info->skb = NULL;
1926
1927 rx_desc = next_rxd;
1928 buffer_info = next_buffer;
1929 }
1930
1931 rx_ring->next_to_clean = i;
1932
1933 ixgb_alloc_rx_buffers(adapter);
1934
1935 return cleaned;
1936}
1937
1938/**
1939 * ixgb_alloc_rx_buffers - Replace used receive buffers
1940 * @adapter: address of board private structure
1941 **/
1942
1943static void
1944ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
1945{
1946 struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
1947 struct net_device *netdev = adapter->netdev;
1948 struct pci_dev *pdev = adapter->pdev;
1949 struct ixgb_rx_desc *rx_desc;
1950 struct ixgb_buffer *buffer_info;
1951 struct sk_buff *skb;
1952 unsigned int i;
1953 int num_group_tail_writes;
1954 long cleancount;
1955
1956 i = rx_ring->next_to_use;
1957 buffer_info = &rx_ring->buffer_info[i];
1958 cleancount = IXGB_DESC_UNUSED(rx_ring);
1959
1960 num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
1961
1962 /* leave one descriptor unused */
1963 while(--cleancount > 0) {
1964 rx_desc = IXGB_RX_DESC(*rx_ring, i);
1965
1966 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1967
1968 if(unlikely(!skb)) {
1969 /* Better luck next round */
1970 break;
1971 }
1972
1973 /* Make buffer alignment 2 beyond a 16 byte boundary
1974 * this will result in a 16 byte aligned IP header after
1975 * the 14 byte MAC header is removed
1976 */
1977 skb_reserve(skb, NET_IP_ALIGN);
1978
1979 skb->dev = netdev;
1980
1981 buffer_info->skb = skb;
1982 buffer_info->length = adapter->rx_buffer_len;
1983 buffer_info->dma =
1984 pci_map_single(pdev,
1985 skb->data,
1986 adapter->rx_buffer_len,
1987 PCI_DMA_FROMDEVICE);
1988
1989 rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
1990
1991 if((i & ~(num_group_tail_writes- 1)) == i) {
1992 /* Force memory writes to complete before letting h/w
1993 * know there are new descriptors to fetch. (Only
1994 * applicable for weak-ordered memory model archs,
1995 * such as IA-64). */
1996 wmb();
1997
1998 IXGB_WRITE_REG(&adapter->hw, RDT, i);
1999 }
2000
2001 if(++i == rx_ring->count) i = 0;
2002 buffer_info = &rx_ring->buffer_info[i];
2003 }
2004
2005 rx_ring->next_to_use = i;
2006}
2007
2008/**
2009 * ixgb_vlan_rx_register - enables or disables vlan tagging/stripping.
2010 *
2011 * @param netdev network interface device structure
2012 * @param grp indicates to enable or disable tagging/stripping
2013 **/
2014static void
2015ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
2016{
2017 struct ixgb_adapter *adapter = netdev->priv;
2018 uint32_t ctrl, rctl;
2019
2020 ixgb_irq_disable(adapter);
2021 adapter->vlgrp = grp;
2022
2023 if(grp) {
2024 /* enable VLAN tag insert/strip */
2025 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2026 ctrl |= IXGB_CTRL0_VME;
2027 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2028
2029 /* enable VLAN receive filtering */
2030
2031 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2032 rctl |= IXGB_RCTL_VFE;
2033 rctl &= ~IXGB_RCTL_CFIEN;
2034 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2035 } else {
2036 /* disable VLAN tag insert/strip */
2037
2038 ctrl = IXGB_READ_REG(&adapter->hw, CTRL0);
2039 ctrl &= ~IXGB_CTRL0_VME;
2040 IXGB_WRITE_REG(&adapter->hw, CTRL0, ctrl);
2041
2042 /* disable VLAN filtering */
2043
2044 rctl = IXGB_READ_REG(&adapter->hw, RCTL);
2045 rctl &= ~IXGB_RCTL_VFE;
2046 IXGB_WRITE_REG(&adapter->hw, RCTL, rctl);
2047 }
2048
2049 ixgb_irq_enable(adapter);
2050}
2051
2052static void
2053ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
2054{
2055 struct ixgb_adapter *adapter = netdev->priv;
2056 uint32_t vfta, index;
2057
2058 /* add VID to filter table */
2059
2060 index = (vid >> 5) & 0x7F;
2061 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2062 vfta |= (1 << (vid & 0x1F));
2063 ixgb_write_vfta(&adapter->hw, index, vfta);
2064}
2065
2066static void
2067ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
2068{
2069 struct ixgb_adapter *adapter = netdev->priv;
2070 uint32_t vfta, index;
2071
2072 ixgb_irq_disable(adapter);
2073
2074 if(adapter->vlgrp)
2075 adapter->vlgrp->vlan_devices[vid] = NULL;
2076
2077 ixgb_irq_enable(adapter);
2078
2079 /* remove VID from filter table*/
2080
2081 index = (vid >> 5) & 0x7F;
2082 vfta = IXGB_READ_REG_ARRAY(&adapter->hw, VFTA, index);
2083 vfta &= ~(1 << (vid & 0x1F));
2084 ixgb_write_vfta(&adapter->hw, index, vfta);
2085}
2086
2087static void
2088ixgb_restore_vlan(struct ixgb_adapter *adapter)
2089{
2090 ixgb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2091
2092 if(adapter->vlgrp) {
2093 uint16_t vid;
2094 for(vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2095 if(!adapter->vlgrp->vlan_devices[vid])
2096 continue;
2097 ixgb_vlan_rx_add_vid(adapter->netdev, vid);
2098 }
2099 }
2100}
2101
2102/**
2103 * ixgb_notify_reboot - handles OS notification of reboot event.
2104 * @param nb notifier block, unused
2105 * @param event Event being passed to driver to act upon
2106 * @param p A pointer to our net device
2107 **/
2108static int
2109ixgb_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
2110{
2111 struct pci_dev *pdev = NULL;
2112
2113 switch(event) {
2114 case SYS_DOWN:
2115 case SYS_HALT:
2116 case SYS_POWER_OFF:
2117 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
2118 if (pci_dev_driver(pdev) == &ixgb_driver)
2119 ixgb_suspend(pdev, 3);
2120 }
2121 }
2122 return NOTIFY_DONE;
2123}
2124
2125/**
2126 * ixgb_suspend - driver suspend function called from notify.
2127 * @param pdev pci driver structure used for passing to
2128 * @param state power state to enter
2129 **/
2130static int
2131ixgb_suspend(struct pci_dev *pdev, uint32_t state)
2132{
2133 struct net_device *netdev = pci_get_drvdata(pdev);
2134 struct ixgb_adapter *adapter = netdev->priv;
2135
2136 netif_device_detach(netdev);
2137
2138 if(netif_running(netdev))
2139 ixgb_down(adapter, TRUE);
2140
2141 pci_save_state(pdev);
2142
2143 state = (state > 0) ? 3 : 0;
2144 pci_set_power_state(pdev, state);
2145 msec_delay(200);
2146
2147 return 0;
2148}
2149
2150#ifdef CONFIG_NET_POLL_CONTROLLER
2151/*
2152 * Polling 'interrupt' - used by things like netconsole to send skbs
2153 * without having to re-enable interrupts. It's not called while
2154 * the interrupt routine is executing.
2155 */
2156
2157static void ixgb_netpoll(struct net_device *dev)
2158{
2159 struct ixgb_adapter *adapter = dev->priv;
2160 disable_irq(adapter->pdev->irq);
2161 ixgb_intr(adapter->pdev->irq, dev, NULL);
2162 enable_irq(adapter->pdev->irq);
2163}
2164#endif
2165
2166/* ixgb_main.c */