1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include "e1000.h"
30#include <net/ip6_checksum.h>
31#include <linux/io.h>
32#include <linux/prefetch.h>
33#include <linux/bitops.h>
34#include <linux/if_vlan.h>
35
36char e1000_driver_name[] = "e1000";
37static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
38#define DRV_VERSION "7.3.21-k8-NAPI"
39const char e1000_driver_version[] = DRV_VERSION;
40static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
41
42
43
44
45
46
47
48
49static const struct pci_device_id e1000_pci_tbl[] = {
50 INTEL_E1000_ETHERNET_DEVICE(0x1000),
51 INTEL_E1000_ETHERNET_DEVICE(0x1001),
52 INTEL_E1000_ETHERNET_DEVICE(0x1004),
53 INTEL_E1000_ETHERNET_DEVICE(0x1008),
54 INTEL_E1000_ETHERNET_DEVICE(0x1009),
55 INTEL_E1000_ETHERNET_DEVICE(0x100C),
56 INTEL_E1000_ETHERNET_DEVICE(0x100D),
57 INTEL_E1000_ETHERNET_DEVICE(0x100E),
58 INTEL_E1000_ETHERNET_DEVICE(0x100F),
59 INTEL_E1000_ETHERNET_DEVICE(0x1010),
60 INTEL_E1000_ETHERNET_DEVICE(0x1011),
61 INTEL_E1000_ETHERNET_DEVICE(0x1012),
62 INTEL_E1000_ETHERNET_DEVICE(0x1013),
63 INTEL_E1000_ETHERNET_DEVICE(0x1014),
64 INTEL_E1000_ETHERNET_DEVICE(0x1015),
65 INTEL_E1000_ETHERNET_DEVICE(0x1016),
66 INTEL_E1000_ETHERNET_DEVICE(0x1017),
67 INTEL_E1000_ETHERNET_DEVICE(0x1018),
68 INTEL_E1000_ETHERNET_DEVICE(0x1019),
69 INTEL_E1000_ETHERNET_DEVICE(0x101A),
70 INTEL_E1000_ETHERNET_DEVICE(0x101D),
71 INTEL_E1000_ETHERNET_DEVICE(0x101E),
72 INTEL_E1000_ETHERNET_DEVICE(0x1026),
73 INTEL_E1000_ETHERNET_DEVICE(0x1027),
74 INTEL_E1000_ETHERNET_DEVICE(0x1028),
75 INTEL_E1000_ETHERNET_DEVICE(0x1075),
76 INTEL_E1000_ETHERNET_DEVICE(0x1076),
77 INTEL_E1000_ETHERNET_DEVICE(0x1077),
78 INTEL_E1000_ETHERNET_DEVICE(0x1078),
79 INTEL_E1000_ETHERNET_DEVICE(0x1079),
80 INTEL_E1000_ETHERNET_DEVICE(0x107A),
81 INTEL_E1000_ETHERNET_DEVICE(0x107B),
82 INTEL_E1000_ETHERNET_DEVICE(0x107C),
83 INTEL_E1000_ETHERNET_DEVICE(0x108A),
84 INTEL_E1000_ETHERNET_DEVICE(0x1099),
85 INTEL_E1000_ETHERNET_DEVICE(0x10B5),
86 INTEL_E1000_ETHERNET_DEVICE(0x2E6E),
87
88 {0,}
89};
90
91MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
92
93int e1000_up(struct e1000_adapter *adapter);
94void e1000_down(struct e1000_adapter *adapter);
95void e1000_reinit_locked(struct e1000_adapter *adapter);
96void e1000_reset(struct e1000_adapter *adapter);
97int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
98int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
99void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
100void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
101static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
102 struct e1000_tx_ring *txdr);
103static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
104 struct e1000_rx_ring *rxdr);
105static void e1000_free_tx_resources(struct e1000_adapter *adapter,
106 struct e1000_tx_ring *tx_ring);
107static void e1000_free_rx_resources(struct e1000_adapter *adapter,
108 struct e1000_rx_ring *rx_ring);
109void e1000_update_stats(struct e1000_adapter *adapter);
110
111static int e1000_init_module(void);
112static void e1000_exit_module(void);
113static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
114static void e1000_remove(struct pci_dev *pdev);
115static int e1000_alloc_queues(struct e1000_adapter *adapter);
116static int e1000_sw_init(struct e1000_adapter *adapter);
117int e1000_open(struct net_device *netdev);
118int e1000_close(struct net_device *netdev);
119static void e1000_configure_tx(struct e1000_adapter *adapter);
120static void e1000_configure_rx(struct e1000_adapter *adapter);
121static void e1000_setup_rctl(struct e1000_adapter *adapter);
122static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
123static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
124static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
125 struct e1000_tx_ring *tx_ring);
126static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
127 struct e1000_rx_ring *rx_ring);
128static void e1000_set_rx_mode(struct net_device *netdev);
129static void e1000_update_phy_info_task(struct work_struct *work);
130static void e1000_watchdog(struct work_struct *work);
131static void e1000_82547_tx_fifo_stall_task(struct work_struct *work);
132static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
133 struct net_device *netdev);
134static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
135static int e1000_set_mac(struct net_device *netdev, void *p);
136static irqreturn_t e1000_intr(int irq, void *data);
137static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
138 struct e1000_tx_ring *tx_ring);
139static int e1000_clean(struct napi_struct *napi, int budget);
140static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
141 struct e1000_rx_ring *rx_ring,
142 int *work_done, int work_to_do);
143static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
144 struct e1000_rx_ring *rx_ring,
145 int *work_done, int work_to_do);
146static void e1000_alloc_dummy_rx_buffers(struct e1000_adapter *adapter,
147 struct e1000_rx_ring *rx_ring,
148 int cleaned_count)
149{
150}
151static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
152 struct e1000_rx_ring *rx_ring,
153 int cleaned_count);
154static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
155 struct e1000_rx_ring *rx_ring,
156 int cleaned_count);
157static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
158static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
159 int cmd);
160static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
161static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
162static void e1000_tx_timeout(struct net_device *dev);
163static void e1000_reset_task(struct work_struct *work);
164static void e1000_smartspeed(struct e1000_adapter *adapter);
165static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
166 struct sk_buff *skb);
167
168static bool e1000_vlan_used(struct e1000_adapter *adapter);
169static void e1000_vlan_mode(struct net_device *netdev,
170 netdev_features_t features);
171static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
172 bool filter_on);
173static int e1000_vlan_rx_add_vid(struct net_device *netdev,
174 __be16 proto, u16 vid);
175static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
176 __be16 proto, u16 vid);
177static void e1000_restore_vlan(struct e1000_adapter *adapter);
178
179#ifdef CONFIG_PM
180static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
181static int e1000_resume(struct pci_dev *pdev);
182#endif
183static void e1000_shutdown(struct pci_dev *pdev);
184
185#ifdef CONFIG_NET_POLL_CONTROLLER
186
187static void e1000_netpoll (struct net_device *netdev);
188#endif
189
190#define COPYBREAK_DEFAULT 256
191static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
192module_param(copybreak, uint, 0644);
193MODULE_PARM_DESC(copybreak,
194 "Maximum size of packet that is copied to a new buffer on receive");
195
196static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
197 pci_channel_state_t state);
198static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
199static void e1000_io_resume(struct pci_dev *pdev);
200
201static const struct pci_error_handlers e1000_err_handler = {
202 .error_detected = e1000_io_error_detected,
203 .slot_reset = e1000_io_slot_reset,
204 .resume = e1000_io_resume,
205};
206
207static struct pci_driver e1000_driver = {
208 .name = e1000_driver_name,
209 .id_table = e1000_pci_tbl,
210 .probe = e1000_probe,
211 .remove = e1000_remove,
212#ifdef CONFIG_PM
213
214 .suspend = e1000_suspend,
215 .resume = e1000_resume,
216#endif
217 .shutdown = e1000_shutdown,
218 .err_handler = &e1000_err_handler
219};
220
221MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
222MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
223MODULE_LICENSE("GPL");
224MODULE_VERSION(DRV_VERSION);
225
226#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
227static int debug = -1;
228module_param(debug, int, 0);
229MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
230
231
232
233
234
235
236struct net_device *e1000_get_hw_dev(struct e1000_hw *hw)
237{
238 struct e1000_adapter *adapter = hw->back;
239 return adapter->netdev;
240}
241
242
243
244
245
246
247
248static int __init e1000_init_module(void)
249{
250 int ret;
251 pr_info("%s - version %s\n", e1000_driver_string, e1000_driver_version);
252
253 pr_info("%s\n", e1000_copyright);
254
255 ret = pci_register_driver(&e1000_driver);
256 if (copybreak != COPYBREAK_DEFAULT) {
257 if (copybreak == 0)
258 pr_info("copybreak disabled\n");
259 else
260 pr_info("copybreak enabled for "
261 "packets <= %u bytes\n", copybreak);
262 }
263 return ret;
264}
265
266module_init(e1000_init_module);
267
268
269
270
271
272
273
274static void __exit e1000_exit_module(void)
275{
276 pci_unregister_driver(&e1000_driver);
277}
278
279module_exit(e1000_exit_module);
280
281static int e1000_request_irq(struct e1000_adapter *adapter)
282{
283 struct net_device *netdev = adapter->netdev;
284 irq_handler_t handler = e1000_intr;
285 int irq_flags = IRQF_SHARED;
286 int err;
287
288 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
289 netdev);
290 if (err) {
291 e_err(probe, "Unable to allocate interrupt Error: %d\n", err);
292 }
293
294 return err;
295}
296
297static void e1000_free_irq(struct e1000_adapter *adapter)
298{
299 struct net_device *netdev = adapter->netdev;
300
301 free_irq(adapter->pdev->irq, netdev);
302}
303
304
305
306
307
308static void e1000_irq_disable(struct e1000_adapter *adapter)
309{
310 struct e1000_hw *hw = &adapter->hw;
311
312 ew32(IMC, ~0);
313 E1000_WRITE_FLUSH();
314 synchronize_irq(adapter->pdev->irq);
315}
316
317
318
319
320
321static void e1000_irq_enable(struct e1000_adapter *adapter)
322{
323 struct e1000_hw *hw = &adapter->hw;
324
325 ew32(IMS, IMS_ENABLE_MASK);
326 E1000_WRITE_FLUSH();
327}
328
329static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
330{
331 struct e1000_hw *hw = &adapter->hw;
332 struct net_device *netdev = adapter->netdev;
333 u16 vid = hw->mng_cookie.vlan_id;
334 u16 old_vid = adapter->mng_vlan_id;
335
336 if (!e1000_vlan_used(adapter))
337 return;
338
339 if (!test_bit(vid, adapter->active_vlans)) {
340 if (hw->mng_cookie.status &
341 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
342 e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
343 adapter->mng_vlan_id = vid;
344 } else {
345 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
346 }
347 if ((old_vid != (u16)E1000_MNG_VLAN_NONE) &&
348 (vid != old_vid) &&
349 !test_bit(old_vid, adapter->active_vlans))
350 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
351 old_vid);
352 } else {
353 adapter->mng_vlan_id = vid;
354 }
355}
356
357static void e1000_init_manageability(struct e1000_adapter *adapter)
358{
359 struct e1000_hw *hw = &adapter->hw;
360
361 if (adapter->en_mng_pt) {
362 u32 manc = er32(MANC);
363
364
365 manc &= ~(E1000_MANC_ARP_EN);
366
367 ew32(MANC, manc);
368 }
369}
370
371static void e1000_release_manageability(struct e1000_adapter *adapter)
372{
373 struct e1000_hw *hw = &adapter->hw;
374
375 if (adapter->en_mng_pt) {
376 u32 manc = er32(MANC);
377
378
379 manc |= E1000_MANC_ARP_EN;
380
381 ew32(MANC, manc);
382 }
383}
384
385
386
387
388
389static void e1000_configure(struct e1000_adapter *adapter)
390{
391 struct net_device *netdev = adapter->netdev;
392 int i;
393
394 e1000_set_rx_mode(netdev);
395
396 e1000_restore_vlan(adapter);
397 e1000_init_manageability(adapter);
398
399 e1000_configure_tx(adapter);
400 e1000_setup_rctl(adapter);
401 e1000_configure_rx(adapter);
402
403
404
405
406 for (i = 0; i < adapter->num_rx_queues; i++) {
407 struct e1000_rx_ring *ring = &adapter->rx_ring[i];
408 adapter->alloc_rx_buf(adapter, ring,
409 E1000_DESC_UNUSED(ring));
410 }
411}
412
413int e1000_up(struct e1000_adapter *adapter)
414{
415 struct e1000_hw *hw = &adapter->hw;
416
417
418 e1000_configure(adapter);
419
420 clear_bit(__E1000_DOWN, &adapter->flags);
421
422 napi_enable(&adapter->napi);
423
424 e1000_irq_enable(adapter);
425
426 netif_wake_queue(adapter->netdev);
427
428
429 ew32(ICS, E1000_ICS_LSC);
430 return 0;
431}
432
433
434
435
436
437
438
439
440
441void e1000_power_up_phy(struct e1000_adapter *adapter)
442{
443 struct e1000_hw *hw = &adapter->hw;
444 u16 mii_reg = 0;
445
446
447 if (hw->media_type == e1000_media_type_copper) {
448
449
450
451 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
452 mii_reg &= ~MII_CR_POWER_DOWN;
453 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
454 }
455}
456
457static void e1000_power_down_phy(struct e1000_adapter *adapter)
458{
459 struct e1000_hw *hw = &adapter->hw;
460
461
462
463
464
465
466
467 if (!adapter->wol && hw->mac_type >= e1000_82540 &&
468 hw->media_type == e1000_media_type_copper) {
469 u16 mii_reg = 0;
470
471 switch (hw->mac_type) {
472 case e1000_82540:
473 case e1000_82545:
474 case e1000_82545_rev_3:
475 case e1000_82546:
476 case e1000_ce4100:
477 case e1000_82546_rev_3:
478 case e1000_82541:
479 case e1000_82541_rev_2:
480 case e1000_82547:
481 case e1000_82547_rev_2:
482 if (er32(MANC) & E1000_MANC_SMBUS_EN)
483 goto out;
484 break;
485 default:
486 goto out;
487 }
488 e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg);
489 mii_reg |= MII_CR_POWER_DOWN;
490 e1000_write_phy_reg(hw, PHY_CTRL, mii_reg);
491 msleep(1);
492 }
493out:
494 return;
495}
496
497static void e1000_down_and_stop(struct e1000_adapter *adapter)
498{
499 set_bit(__E1000_DOWN, &adapter->flags);
500
501 cancel_delayed_work_sync(&adapter->watchdog_task);
502
503
504
505
506
507
508
509 cancel_delayed_work_sync(&adapter->phy_info_task);
510 cancel_delayed_work_sync(&adapter->fifo_stall_task);
511
512
513 if (!test_bit(__E1000_RESETTING, &adapter->flags))
514 cancel_work_sync(&adapter->reset_task);
515}
516
517void e1000_down(struct e1000_adapter *adapter)
518{
519 struct e1000_hw *hw = &adapter->hw;
520 struct net_device *netdev = adapter->netdev;
521 u32 rctl, tctl;
522
523
524 rctl = er32(RCTL);
525 ew32(RCTL, rctl & ~E1000_RCTL_EN);
526
527
528 netif_tx_disable(netdev);
529
530
531 tctl = er32(TCTL);
532 tctl &= ~E1000_TCTL_EN;
533 ew32(TCTL, tctl);
534
535 E1000_WRITE_FLUSH();
536 msleep(10);
537
538
539
540
541
542
543
544
545 netif_carrier_off(netdev);
546
547 napi_disable(&adapter->napi);
548
549 e1000_irq_disable(adapter);
550
551
552
553
554
555 e1000_down_and_stop(adapter);
556
557 adapter->link_speed = 0;
558 adapter->link_duplex = 0;
559
560 e1000_reset(adapter);
561 e1000_clean_all_tx_rings(adapter);
562 e1000_clean_all_rx_rings(adapter);
563}
564
565void e1000_reinit_locked(struct e1000_adapter *adapter)
566{
567 WARN_ON(in_interrupt());
568 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
569 msleep(1);
570 e1000_down(adapter);
571 e1000_up(adapter);
572 clear_bit(__E1000_RESETTING, &adapter->flags);
573}
574
575void e1000_reset(struct e1000_adapter *adapter)
576{
577 struct e1000_hw *hw = &adapter->hw;
578 u32 pba = 0, tx_space, min_tx_space, min_rx_space;
579 bool legacy_pba_adjust = false;
580 u16 hwm;
581
582
583
584
585
586 switch (hw->mac_type) {
587 case e1000_82542_rev2_0:
588 case e1000_82542_rev2_1:
589 case e1000_82543:
590 case e1000_82544:
591 case e1000_82540:
592 case e1000_82541:
593 case e1000_82541_rev_2:
594 legacy_pba_adjust = true;
595 pba = E1000_PBA_48K;
596 break;
597 case e1000_82545:
598 case e1000_82545_rev_3:
599 case e1000_82546:
600 case e1000_ce4100:
601 case e1000_82546_rev_3:
602 pba = E1000_PBA_48K;
603 break;
604 case e1000_82547:
605 case e1000_82547_rev_2:
606 legacy_pba_adjust = true;
607 pba = E1000_PBA_30K;
608 break;
609 case e1000_undefined:
610 case e1000_num_macs:
611 break;
612 }
613
614 if (legacy_pba_adjust) {
615 if (hw->max_frame_size > E1000_RXBUFFER_8192)
616 pba -= 8;
617
618 if (hw->mac_type == e1000_82547) {
619 adapter->tx_fifo_head = 0;
620 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
621 adapter->tx_fifo_size =
622 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
623 atomic_set(&adapter->tx_fifo_stall, 0);
624 }
625 } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) {
626
627 ew32(PBA, pba);
628
629
630
631
632
633
634
635
636 pba = er32(PBA);
637
638 tx_space = pba >> 16;
639
640 pba &= 0xffff;
641
642
643
644 min_tx_space = (hw->max_frame_size +
645 sizeof(struct e1000_tx_desc) -
646 ETH_FCS_LEN) * 2;
647 min_tx_space = ALIGN(min_tx_space, 1024);
648 min_tx_space >>= 10;
649
650 min_rx_space = hw->max_frame_size;
651 min_rx_space = ALIGN(min_rx_space, 1024);
652 min_rx_space >>= 10;
653
654
655
656
657
658 if (tx_space < min_tx_space &&
659 ((min_tx_space - tx_space) < pba)) {
660 pba = pba - (min_tx_space - tx_space);
661
662
663 switch (hw->mac_type) {
664 case e1000_82545 ... e1000_82546_rev_3:
665 pba &= ~(E1000_PBA_8K - 1);
666 break;
667 default:
668 break;
669 }
670
671
672
673
674 if (pba < min_rx_space)
675 pba = min_rx_space;
676 }
677 }
678
679 ew32(PBA, pba);
680
681
682
683
684
685
686
687
688
689
690 hwm = min(((pba << 10) * 9 / 10),
691 ((pba << 10) - hw->max_frame_size));
692
693 hw->fc_high_water = hwm & 0xFFF8;
694 hw->fc_low_water = hw->fc_high_water - 8;
695 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
696 hw->fc_send_xon = 1;
697 hw->fc = hw->original_fc;
698
699
700 e1000_reset_hw(hw);
701 if (hw->mac_type >= e1000_82544)
702 ew32(WUC, 0);
703
704 if (e1000_init_hw(hw))
705 e_dev_err("Hardware Error\n");
706 e1000_update_mng_vlan(adapter);
707
708
709 if (hw->mac_type >= e1000_82544 &&
710 hw->autoneg == 1 &&
711 hw->autoneg_advertised == ADVERTISE_1000_FULL) {
712 u32 ctrl = er32(CTRL);
713
714
715
716
717 ctrl &= ~E1000_CTRL_SWDPIN3;
718 ew32(CTRL, ctrl);
719 }
720
721
722 ew32(VET, ETHERNET_IEEE_VLAN_TYPE);
723
724 e1000_reset_adaptive(hw);
725 e1000_phy_get_info(hw, &adapter->phy_info);
726
727 e1000_release_manageability(adapter);
728}
729
730
731static void e1000_dump_eeprom(struct e1000_adapter *adapter)
732{
733 struct net_device *netdev = adapter->netdev;
734 struct ethtool_eeprom eeprom;
735 const struct ethtool_ops *ops = netdev->ethtool_ops;
736 u8 *data;
737 int i;
738 u16 csum_old, csum_new = 0;
739
740 eeprom.len = ops->get_eeprom_len(netdev);
741 eeprom.offset = 0;
742
743 data = kmalloc(eeprom.len, GFP_KERNEL);
744 if (!data)
745 return;
746
747 ops->get_eeprom(netdev, &eeprom, data);
748
749 csum_old = (data[EEPROM_CHECKSUM_REG * 2]) +
750 (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8);
751 for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2)
752 csum_new += data[i] + (data[i + 1] << 8);
753 csum_new = EEPROM_SUM - csum_new;
754
755 pr_err("/*********************/\n");
756 pr_err("Current EEPROM Checksum : 0x%04x\n", csum_old);
757 pr_err("Calculated : 0x%04x\n", csum_new);
758
759 pr_err("Offset Values\n");
760 pr_err("======== ======\n");
761 print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0);
762
763 pr_err("Include this output when contacting your support provider.\n");
764 pr_err("This is not a software error! Something bad happened to\n");
765 pr_err("your hardware or EEPROM image. Ignoring this problem could\n");
766 pr_err("result in further problems, possibly loss of data,\n");
767 pr_err("corruption or system hangs!\n");
768 pr_err("The MAC Address will be reset to 00:00:00:00:00:00,\n");
769 pr_err("which is invalid and requires you to set the proper MAC\n");
770 pr_err("address manually before continuing to enable this network\n");
771 pr_err("device. Please inspect the EEPROM dump and report the\n");
772 pr_err("issue to your hardware vendor or Intel Customer Support.\n");
773 pr_err("/*********************/\n");
774
775 kfree(data);
776}
777
778
779
780
781
782
783
784static int e1000_is_need_ioport(struct pci_dev *pdev)
785{
786 switch (pdev->device) {
787 case E1000_DEV_ID_82540EM:
788 case E1000_DEV_ID_82540EM_LOM:
789 case E1000_DEV_ID_82540EP:
790 case E1000_DEV_ID_82540EP_LOM:
791 case E1000_DEV_ID_82540EP_LP:
792 case E1000_DEV_ID_82541EI:
793 case E1000_DEV_ID_82541EI_MOBILE:
794 case E1000_DEV_ID_82541ER:
795 case E1000_DEV_ID_82541ER_LOM:
796 case E1000_DEV_ID_82541GI:
797 case E1000_DEV_ID_82541GI_LF:
798 case E1000_DEV_ID_82541GI_MOBILE:
799 case E1000_DEV_ID_82544EI_COPPER:
800 case E1000_DEV_ID_82544EI_FIBER:
801 case E1000_DEV_ID_82544GC_COPPER:
802 case E1000_DEV_ID_82544GC_LOM:
803 case E1000_DEV_ID_82545EM_COPPER:
804 case E1000_DEV_ID_82545EM_FIBER:
805 case E1000_DEV_ID_82546EB_COPPER:
806 case E1000_DEV_ID_82546EB_FIBER:
807 case E1000_DEV_ID_82546EB_QUAD_COPPER:
808 return true;
809 default:
810 return false;
811 }
812}
813
814static netdev_features_t e1000_fix_features(struct net_device *netdev,
815 netdev_features_t features)
816{
817
818
819
820 if (features & NETIF_F_HW_VLAN_CTAG_RX)
821 features |= NETIF_F_HW_VLAN_CTAG_TX;
822 else
823 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
824
825 return features;
826}
827
828static int e1000_set_features(struct net_device *netdev,
829 netdev_features_t features)
830{
831 struct e1000_adapter *adapter = netdev_priv(netdev);
832 netdev_features_t changed = features ^ netdev->features;
833
834 if (changed & NETIF_F_HW_VLAN_CTAG_RX)
835 e1000_vlan_mode(netdev, features);
836
837 if (!(changed & (NETIF_F_RXCSUM | NETIF_F_RXALL)))
838 return 0;
839
840 netdev->features = features;
841 adapter->rx_csum = !!(features & NETIF_F_RXCSUM);
842
843 if (netif_running(netdev))
844 e1000_reinit_locked(adapter);
845 else
846 e1000_reset(adapter);
847
848 return 0;
849}
850
851static const struct net_device_ops e1000_netdev_ops = {
852 .ndo_open = e1000_open,
853 .ndo_stop = e1000_close,
854 .ndo_start_xmit = e1000_xmit_frame,
855 .ndo_set_rx_mode = e1000_set_rx_mode,
856 .ndo_set_mac_address = e1000_set_mac,
857 .ndo_tx_timeout = e1000_tx_timeout,
858 .ndo_change_mtu = e1000_change_mtu,
859 .ndo_do_ioctl = e1000_ioctl,
860 .ndo_validate_addr = eth_validate_addr,
861 .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
862 .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
863#ifdef CONFIG_NET_POLL_CONTROLLER
864 .ndo_poll_controller = e1000_netpoll,
865#endif
866 .ndo_fix_features = e1000_fix_features,
867 .ndo_set_features = e1000_set_features,
868};
869
870
871
872
873
874
875
876
877
878
879
880
881static int e1000_init_hw_struct(struct e1000_adapter *adapter,
882 struct e1000_hw *hw)
883{
884 struct pci_dev *pdev = adapter->pdev;
885
886
887 hw->vendor_id = pdev->vendor;
888 hw->device_id = pdev->device;
889 hw->subsystem_vendor_id = pdev->subsystem_vendor;
890 hw->subsystem_id = pdev->subsystem_device;
891 hw->revision_id = pdev->revision;
892
893 pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
894
895 hw->max_frame_size = adapter->netdev->mtu +
896 ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
897 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
898
899
900 if (e1000_set_mac_type(hw)) {
901 e_err(probe, "Unknown MAC Type\n");
902 return -EIO;
903 }
904
905 switch (hw->mac_type) {
906 default:
907 break;
908 case e1000_82541:
909 case e1000_82547:
910 case e1000_82541_rev_2:
911 case e1000_82547_rev_2:
912 hw->phy_init_script = 1;
913 break;
914 }
915
916 e1000_set_media_type(hw);
917 e1000_get_bus_info(hw);
918
919 hw->wait_autoneg_complete = false;
920 hw->tbi_compatibility_en = true;
921 hw->adaptive_ifs = true;
922
923
924
925 if (hw->media_type == e1000_media_type_copper) {
926 hw->mdix = AUTO_ALL_MODES;
927 hw->disable_polarity_correction = false;
928 hw->master_slave = E1000_MASTER_SLAVE;
929 }
930
931 return 0;
932}
933
934
935
936
937
938
939
940
941
942
943
944
945static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
946{
947 struct net_device *netdev;
948 struct e1000_adapter *adapter;
949 struct e1000_hw *hw;
950
951 static int cards_found;
952 static int global_quad_port_a;
953 int i, err, pci_using_dac;
954 u16 eeprom_data = 0;
955 u16 tmp = 0;
956 u16 eeprom_apme_mask = E1000_EEPROM_APME;
957 int bars, need_ioport;
958
959
960 need_ioport = e1000_is_need_ioport(pdev);
961 if (need_ioport) {
962 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
963 err = pci_enable_device(pdev);
964 } else {
965 bars = pci_select_bars(pdev, IORESOURCE_MEM);
966 err = pci_enable_device_mem(pdev);
967 }
968 if (err)
969 return err;
970
971 err = pci_request_selected_regions(pdev, bars, e1000_driver_name);
972 if (err)
973 goto err_pci_reg;
974
975 pci_set_master(pdev);
976 err = pci_save_state(pdev);
977 if (err)
978 goto err_alloc_etherdev;
979
980 err = -ENOMEM;
981 netdev = alloc_etherdev(sizeof(struct e1000_adapter));
982 if (!netdev)
983 goto err_alloc_etherdev;
984
985 SET_NETDEV_DEV(netdev, &pdev->dev);
986
987 pci_set_drvdata(pdev, netdev);
988 adapter = netdev_priv(netdev);
989 adapter->netdev = netdev;
990 adapter->pdev = pdev;
991 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
992 adapter->bars = bars;
993 adapter->need_ioport = need_ioport;
994
995 hw = &adapter->hw;
996 hw->back = adapter;
997
998 err = -EIO;
999 hw->hw_addr = pci_ioremap_bar(pdev, BAR_0);
1000 if (!hw->hw_addr)
1001 goto err_ioremap;
1002
1003 if (adapter->need_ioport) {
1004 for (i = BAR_1; i <= BAR_5; i++) {
1005 if (pci_resource_len(pdev, i) == 0)
1006 continue;
1007 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1008 hw->io_base = pci_resource_start(pdev, i);
1009 break;
1010 }
1011 }
1012 }
1013
1014
1015 err = e1000_init_hw_struct(adapter, hw);
1016 if (err)
1017 goto err_sw_init;
1018
1019
1020
1021
1022
1023 pci_using_dac = 0;
1024 if ((hw->bus_type == e1000_bus_type_pcix) &&
1025 !dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
1026 pci_using_dac = 1;
1027 } else {
1028 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1029 if (err) {
1030 pr_err("No usable DMA config, aborting\n");
1031 goto err_dma;
1032 }
1033 }
1034
1035 netdev->netdev_ops = &e1000_netdev_ops;
1036 e1000_set_ethtool_ops(netdev);
1037 netdev->watchdog_timeo = 5 * HZ;
1038 netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
1039
1040 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
1041
1042 adapter->bd_number = cards_found;
1043
1044
1045
1046 err = e1000_sw_init(adapter);
1047 if (err)
1048 goto err_sw_init;
1049
1050 err = -EIO;
1051 if (hw->mac_type == e1000_ce4100) {
1052 hw->ce4100_gbe_mdio_base_virt =
1053 ioremap(pci_resource_start(pdev, BAR_1),
1054 pci_resource_len(pdev, BAR_1));
1055
1056 if (!hw->ce4100_gbe_mdio_base_virt)
1057 goto err_mdio_ioremap;
1058 }
1059
1060 if (hw->mac_type >= e1000_82543) {
1061 netdev->hw_features = NETIF_F_SG |
1062 NETIF_F_HW_CSUM |
1063 NETIF_F_HW_VLAN_CTAG_RX;
1064 netdev->features = NETIF_F_HW_VLAN_CTAG_TX |
1065 NETIF_F_HW_VLAN_CTAG_FILTER;
1066 }
1067
1068 if ((hw->mac_type >= e1000_82544) &&
1069 (hw->mac_type != e1000_82547))
1070 netdev->hw_features |= NETIF_F_TSO;
1071
1072 netdev->priv_flags |= IFF_SUPP_NOFCS;
1073
1074 netdev->features |= netdev->hw_features;
1075 netdev->hw_features |= (NETIF_F_RXCSUM |
1076 NETIF_F_RXALL |
1077 NETIF_F_RXFCS);
1078
1079 if (pci_using_dac) {
1080 netdev->features |= NETIF_F_HIGHDMA;
1081 netdev->vlan_features |= NETIF_F_HIGHDMA;
1082 }
1083
1084 netdev->vlan_features |= (NETIF_F_TSO |
1085 NETIF_F_HW_CSUM |
1086 NETIF_F_SG);
1087
1088
1089 if (hw->device_id != E1000_DEV_ID_82545EM_COPPER ||
1090 hw->subsystem_vendor_id != PCI_VENDOR_ID_VMWARE)
1091 netdev->priv_flags |= IFF_UNICAST_FLT;
1092
1093
1094 netdev->min_mtu = ETH_ZLEN - ETH_HLEN;
1095 netdev->max_mtu = MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
1096
1097 adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw);
1098
1099
1100 if (e1000_init_eeprom_params(hw)) {
1101 e_err(probe, "EEPROM initialization failed\n");
1102 goto err_eeprom;
1103 }
1104
1105
1106
1107
1108
1109 e1000_reset_hw(hw);
1110
1111
1112 if (e1000_validate_eeprom_checksum(hw) < 0) {
1113 e_err(probe, "The EEPROM Checksum Is Not Valid\n");
1114 e1000_dump_eeprom(adapter);
1115
1116
1117
1118
1119
1120
1121
1122 memset(hw->mac_addr, 0, netdev->addr_len);
1123 } else {
1124
1125 if (e1000_read_mac_addr(hw))
1126 e_err(probe, "EEPROM Read Error\n");
1127 }
1128
1129 memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len);
1130
1131 if (!is_valid_ether_addr(netdev->dev_addr))
1132 e_err(probe, "Invalid MAC Address\n");
1133
1134
1135 INIT_DELAYED_WORK(&adapter->watchdog_task, e1000_watchdog);
1136 INIT_DELAYED_WORK(&adapter->fifo_stall_task,
1137 e1000_82547_tx_fifo_stall_task);
1138 INIT_DELAYED_WORK(&adapter->phy_info_task, e1000_update_phy_info_task);
1139 INIT_WORK(&adapter->reset_task, e1000_reset_task);
1140
1141 e1000_check_options(adapter);
1142
1143
1144
1145
1146
1147
1148 switch (hw->mac_type) {
1149 case e1000_82542_rev2_0:
1150 case e1000_82542_rev2_1:
1151 case e1000_82543:
1152 break;
1153 case e1000_82544:
1154 e1000_read_eeprom(hw,
1155 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
1156 eeprom_apme_mask = E1000_EEPROM_82544_APM;
1157 break;
1158 case e1000_82546:
1159 case e1000_82546_rev_3:
1160 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
1161 e1000_read_eeprom(hw,
1162 EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
1163 break;
1164 }
1165
1166 default:
1167 e1000_read_eeprom(hw,
1168 EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
1169 break;
1170 }
1171 if (eeprom_data & eeprom_apme_mask)
1172 adapter->eeprom_wol |= E1000_WUFC_MAG;
1173
1174
1175
1176
1177
1178 switch (pdev->device) {
1179 case E1000_DEV_ID_82546GB_PCIE:
1180 adapter->eeprom_wol = 0;
1181 break;
1182 case E1000_DEV_ID_82546EB_FIBER:
1183 case E1000_DEV_ID_82546GB_FIBER:
1184
1185
1186
1187 if (er32(STATUS) & E1000_STATUS_FUNC_1)
1188 adapter->eeprom_wol = 0;
1189 break;
1190 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1191
1192 if (global_quad_port_a != 0)
1193 adapter->eeprom_wol = 0;
1194 else
1195 adapter->quad_port_a = true;
1196
1197 if (++global_quad_port_a == 4)
1198 global_quad_port_a = 0;
1199 break;
1200 }
1201
1202
1203 adapter->wol = adapter->eeprom_wol;
1204 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1205
1206
1207 if (hw->mac_type == e1000_ce4100) {
1208 for (i = 0; i < 32; i++) {
1209 hw->phy_addr = i;
1210 e1000_read_phy_reg(hw, PHY_ID2, &tmp);
1211
1212 if (tmp != 0 && tmp != 0xFF)
1213 break;
1214 }
1215
1216 if (i >= 32)
1217 goto err_eeprom;
1218 }
1219
1220
1221 e1000_reset(adapter);
1222
1223 strcpy(netdev->name, "eth%d");
1224 err = register_netdev(netdev);
1225 if (err)
1226 goto err_register;
1227
1228 e1000_vlan_filter_on_off(adapter, false);
1229
1230
1231 e_info(probe, "(PCI%s:%dMHz:%d-bit) %pM\n",
1232 ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : ""),
1233 ((hw->bus_speed == e1000_bus_speed_133) ? 133 :
1234 (hw->bus_speed == e1000_bus_speed_120) ? 120 :
1235 (hw->bus_speed == e1000_bus_speed_100) ? 100 :
1236 (hw->bus_speed == e1000_bus_speed_66) ? 66 : 33),
1237 ((hw->bus_width == e1000_bus_width_64) ? 64 : 32),
1238 netdev->dev_addr);
1239
1240
1241 netif_carrier_off(netdev);
1242
1243 e_info(probe, "Intel(R) PRO/1000 Network Connection\n");
1244
1245 cards_found++;
1246 return 0;
1247
1248err_register:
1249err_eeprom:
1250 e1000_phy_hw_reset(hw);
1251
1252 if (hw->flash_address)
1253 iounmap(hw->flash_address);
1254 kfree(adapter->tx_ring);
1255 kfree(adapter->rx_ring);
1256err_dma:
1257err_sw_init:
1258err_mdio_ioremap:
1259 iounmap(hw->ce4100_gbe_mdio_base_virt);
1260 iounmap(hw->hw_addr);
1261err_ioremap:
1262 free_netdev(netdev);
1263err_alloc_etherdev:
1264 pci_release_selected_regions(pdev, bars);
1265err_pci_reg:
1266 pci_disable_device(pdev);
1267 return err;
1268}
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279static void e1000_remove(struct pci_dev *pdev)
1280{
1281 struct net_device *netdev = pci_get_drvdata(pdev);
1282 struct e1000_adapter *adapter = netdev_priv(netdev);
1283 struct e1000_hw *hw = &adapter->hw;
1284
1285 e1000_down_and_stop(adapter);
1286 e1000_release_manageability(adapter);
1287
1288 unregister_netdev(netdev);
1289
1290 e1000_phy_hw_reset(hw);
1291
1292 kfree(adapter->tx_ring);
1293 kfree(adapter->rx_ring);
1294
1295 if (hw->mac_type == e1000_ce4100)
1296 iounmap(hw->ce4100_gbe_mdio_base_virt);
1297 iounmap(hw->hw_addr);
1298 if (hw->flash_address)
1299 iounmap(hw->flash_address);
1300 pci_release_selected_regions(pdev, adapter->bars);
1301
1302 free_netdev(netdev);
1303
1304 pci_disable_device(pdev);
1305}
1306
1307
1308
1309
1310
1311
1312
1313
1314static int e1000_sw_init(struct e1000_adapter *adapter)
1315{
1316 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
1317
1318 adapter->num_tx_queues = 1;
1319 adapter->num_rx_queues = 1;
1320
1321 if (e1000_alloc_queues(adapter)) {
1322 e_err(probe, "Unable to allocate memory for queues\n");
1323 return -ENOMEM;
1324 }
1325
1326
1327 e1000_irq_disable(adapter);
1328
1329 spin_lock_init(&adapter->stats_lock);
1330
1331 set_bit(__E1000_DOWN, &adapter->flags);
1332
1333 return 0;
1334}
1335
1336
1337
1338
1339
1340
1341
1342
1343static int e1000_alloc_queues(struct e1000_adapter *adapter)
1344{
1345 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
1346 sizeof(struct e1000_tx_ring), GFP_KERNEL);
1347 if (!adapter->tx_ring)
1348 return -ENOMEM;
1349
1350 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
1351 sizeof(struct e1000_rx_ring), GFP_KERNEL);
1352 if (!adapter->rx_ring) {
1353 kfree(adapter->tx_ring);
1354 return -ENOMEM;
1355 }
1356
1357 return E1000_SUCCESS;
1358}
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372int e1000_open(struct net_device *netdev)
1373{
1374 struct e1000_adapter *adapter = netdev_priv(netdev);
1375 struct e1000_hw *hw = &adapter->hw;
1376 int err;
1377
1378
1379 if (test_bit(__E1000_TESTING, &adapter->flags))
1380 return -EBUSY;
1381
1382 netif_carrier_off(netdev);
1383
1384
1385 err = e1000_setup_all_tx_resources(adapter);
1386 if (err)
1387 goto err_setup_tx;
1388
1389
1390 err = e1000_setup_all_rx_resources(adapter);
1391 if (err)
1392 goto err_setup_rx;
1393
1394 e1000_power_up_phy(adapter);
1395
1396 adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
1397 if ((hw->mng_cookie.status &
1398 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
1399 e1000_update_mng_vlan(adapter);
1400 }
1401
1402
1403
1404
1405
1406
1407 e1000_configure(adapter);
1408
1409 err = e1000_request_irq(adapter);
1410 if (err)
1411 goto err_req_irq;
1412
1413
1414 clear_bit(__E1000_DOWN, &adapter->flags);
1415
1416 napi_enable(&adapter->napi);
1417
1418 e1000_irq_enable(adapter);
1419
1420 netif_start_queue(netdev);
1421
1422
1423 ew32(ICS, E1000_ICS_LSC);
1424
1425 return E1000_SUCCESS;
1426
1427err_req_irq:
1428 e1000_power_down_phy(adapter);
1429 e1000_free_all_rx_resources(adapter);
1430err_setup_rx:
1431 e1000_free_all_tx_resources(adapter);
1432err_setup_tx:
1433 e1000_reset(adapter);
1434
1435 return err;
1436}
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449int e1000_close(struct net_device *netdev)
1450{
1451 struct e1000_adapter *adapter = netdev_priv(netdev);
1452 struct e1000_hw *hw = &adapter->hw;
1453 int count = E1000_CHECK_RESET_COUNT;
1454
1455 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
1456 usleep_range(10000, 20000);
1457
1458 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
1459 e1000_down(adapter);
1460 e1000_power_down_phy(adapter);
1461 e1000_free_irq(adapter);
1462
1463 e1000_free_all_tx_resources(adapter);
1464 e1000_free_all_rx_resources(adapter);
1465
1466
1467
1468
1469 if ((hw->mng_cookie.status &
1470 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
1471 !test_bit(adapter->mng_vlan_id, adapter->active_vlans)) {
1472 e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
1473 adapter->mng_vlan_id);
1474 }
1475
1476 return 0;
1477}
1478
1479
1480
1481
1482
1483
1484
1485static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start,
1486 unsigned long len)
1487{
1488 struct e1000_hw *hw = &adapter->hw;
1489 unsigned long begin = (unsigned long)start;
1490 unsigned long end = begin + len;
1491
1492
1493
1494
1495 if (hw->mac_type == e1000_82545 ||
1496 hw->mac_type == e1000_ce4100 ||
1497 hw->mac_type == e1000_82546) {
1498 return ((begin ^ (end - 1)) >> 16) != 0 ? false : true;
1499 }
1500
1501 return true;
1502}
1503
1504
1505
1506
1507
1508
1509
1510
1511static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
1512 struct e1000_tx_ring *txdr)
1513{
1514 struct pci_dev *pdev = adapter->pdev;
1515 int size;
1516
1517 size = sizeof(struct e1000_tx_buffer) * txdr->count;
1518 txdr->buffer_info = vzalloc(size);
1519 if (!txdr->buffer_info)
1520 return -ENOMEM;
1521
1522
1523
1524 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1525 txdr->size = ALIGN(txdr->size, 4096);
1526
1527 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
1528 GFP_KERNEL);
1529 if (!txdr->desc) {
1530setup_tx_desc_die:
1531 vfree(txdr->buffer_info);
1532 return -ENOMEM;
1533 }
1534
1535
1536 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1537 void *olddesc = txdr->desc;
1538 dma_addr_t olddma = txdr->dma;
1539 e_err(tx_err, "txdr align check failed: %u bytes at %p\n",
1540 txdr->size, txdr->desc);
1541
1542 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size,
1543 &txdr->dma, GFP_KERNEL);
1544
1545 if (!txdr->desc) {
1546 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1547 olddma);
1548 goto setup_tx_desc_die;
1549 }
1550
1551 if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
1552
1553 dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
1554 txdr->dma);
1555 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1556 olddma);
1557 e_err(probe, "Unable to allocate aligned memory "
1558 "for the transmit descriptor ring\n");
1559 vfree(txdr->buffer_info);
1560 return -ENOMEM;
1561 } else {
1562
1563 dma_free_coherent(&pdev->dev, txdr->size, olddesc,
1564 olddma);
1565 }
1566 }
1567 memset(txdr->desc, 0, txdr->size);
1568
1569 txdr->next_to_use = 0;
1570 txdr->next_to_clean = 0;
1571
1572 return 0;
1573}
1574
1575
1576
1577
1578
1579
1580
1581
1582int e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
1583{
1584 int i, err = 0;
1585
1586 for (i = 0; i < adapter->num_tx_queues; i++) {
1587 err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
1588 if (err) {
1589 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
1590 for (i-- ; i >= 0; i--)
1591 e1000_free_tx_resources(adapter,
1592 &adapter->tx_ring[i]);
1593 break;
1594 }
1595 }
1596
1597 return err;
1598}
1599
1600
1601
1602
1603
1604
1605
1606static void e1000_configure_tx(struct e1000_adapter *adapter)
1607{
1608 u64 tdba;
1609 struct e1000_hw *hw = &adapter->hw;
1610 u32 tdlen, tctl, tipg;
1611 u32 ipgr1, ipgr2;
1612
1613
1614
1615 switch (adapter->num_tx_queues) {
1616 case 1:
1617 default:
1618 tdba = adapter->tx_ring[0].dma;
1619 tdlen = adapter->tx_ring[0].count *
1620 sizeof(struct e1000_tx_desc);
1621 ew32(TDLEN, tdlen);
1622 ew32(TDBAH, (tdba >> 32));
1623 ew32(TDBAL, (tdba & 0x00000000ffffffffULL));
1624 ew32(TDT, 0);
1625 ew32(TDH, 0);
1626 adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ?
1627 E1000_TDH : E1000_82542_TDH);
1628 adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ?
1629 E1000_TDT : E1000_82542_TDT);
1630 break;
1631 }
1632
1633
1634 if ((hw->media_type == e1000_media_type_fiber ||
1635 hw->media_type == e1000_media_type_internal_serdes))
1636 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1637 else
1638 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
1639
1640 switch (hw->mac_type) {
1641 case e1000_82542_rev2_0:
1642 case e1000_82542_rev2_1:
1643 tipg = DEFAULT_82542_TIPG_IPGT;
1644 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
1645 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
1646 break;
1647 default:
1648 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
1649 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
1650 break;
1651 }
1652 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
1653 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
1654 ew32(TIPG, tipg);
1655
1656
1657
1658 ew32(TIDV, adapter->tx_int_delay);
1659 if (hw->mac_type >= e1000_82540)
1660 ew32(TADV, adapter->tx_abs_int_delay);
1661
1662
1663
1664 tctl = er32(TCTL);
1665 tctl &= ~E1000_TCTL_CT;
1666 tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
1667 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
1668
1669 e1000_config_collision_dist(hw);
1670
1671
1672 adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
1673
1674
1675 if (adapter->tx_int_delay)
1676 adapter->txd_cmd |= E1000_TXD_CMD_IDE;
1677
1678 if (hw->mac_type < e1000_82543)
1679 adapter->txd_cmd |= E1000_TXD_CMD_RPS;
1680 else
1681 adapter->txd_cmd |= E1000_TXD_CMD_RS;
1682
1683
1684
1685
1686 if (hw->mac_type == e1000_82544 &&
1687 hw->bus_type == e1000_bus_type_pcix)
1688 adapter->pcix_82544 = true;
1689
1690 ew32(TCTL, tctl);
1691
1692}
1693
1694
1695
1696
1697
1698
1699
1700
1701static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
1702 struct e1000_rx_ring *rxdr)
1703{
1704 struct pci_dev *pdev = adapter->pdev;
1705 int size, desc_len;
1706
1707 size = sizeof(struct e1000_rx_buffer) * rxdr->count;
1708 rxdr->buffer_info = vzalloc(size);
1709 if (!rxdr->buffer_info)
1710 return -ENOMEM;
1711
1712 desc_len = sizeof(struct e1000_rx_desc);
1713
1714
1715
1716 rxdr->size = rxdr->count * desc_len;
1717 rxdr->size = ALIGN(rxdr->size, 4096);
1718
1719 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
1720 GFP_KERNEL);
1721 if (!rxdr->desc) {
1722setup_rx_desc_die:
1723 vfree(rxdr->buffer_info);
1724 return -ENOMEM;
1725 }
1726
1727
1728 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1729 void *olddesc = rxdr->desc;
1730 dma_addr_t olddma = rxdr->dma;
1731 e_err(rx_err, "rxdr align check failed: %u bytes at %p\n",
1732 rxdr->size, rxdr->desc);
1733
1734 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size,
1735 &rxdr->dma, GFP_KERNEL);
1736
1737 if (!rxdr->desc) {
1738 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1739 olddma);
1740 goto setup_rx_desc_die;
1741 }
1742
1743 if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
1744
1745 dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
1746 rxdr->dma);
1747 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1748 olddma);
1749 e_err(probe, "Unable to allocate aligned memory for "
1750 "the Rx descriptor ring\n");
1751 goto setup_rx_desc_die;
1752 } else {
1753
1754 dma_free_coherent(&pdev->dev, rxdr->size, olddesc,
1755 olddma);
1756 }
1757 }
1758 memset(rxdr->desc, 0, rxdr->size);
1759
1760 rxdr->next_to_clean = 0;
1761 rxdr->next_to_use = 0;
1762 rxdr->rx_skb_top = NULL;
1763
1764 return 0;
1765}
1766
1767
1768
1769
1770
1771
1772
1773
1774int e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
1775{
1776 int i, err = 0;
1777
1778 for (i = 0; i < adapter->num_rx_queues; i++) {
1779 err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
1780 if (err) {
1781 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
1782 for (i-- ; i >= 0; i--)
1783 e1000_free_rx_resources(adapter,
1784 &adapter->rx_ring[i]);
1785 break;
1786 }
1787 }
1788
1789 return err;
1790}
1791
1792
1793
1794
1795
1796static void e1000_setup_rctl(struct e1000_adapter *adapter)
1797{
1798 struct e1000_hw *hw = &adapter->hw;
1799 u32 rctl;
1800
1801 rctl = er32(RCTL);
1802
1803 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
1804
1805 rctl |= E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
1806 E1000_RCTL_RDMTS_HALF |
1807 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1808
1809 if (hw->tbi_compatibility_on == 1)
1810 rctl |= E1000_RCTL_SBP;
1811 else
1812 rctl &= ~E1000_RCTL_SBP;
1813
1814 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1815 rctl &= ~E1000_RCTL_LPE;
1816 else
1817 rctl |= E1000_RCTL_LPE;
1818
1819
1820 rctl &= ~E1000_RCTL_SZ_4096;
1821 rctl |= E1000_RCTL_BSEX;
1822 switch (adapter->rx_buffer_len) {
1823 case E1000_RXBUFFER_2048:
1824 default:
1825 rctl |= E1000_RCTL_SZ_2048;
1826 rctl &= ~E1000_RCTL_BSEX;
1827 break;
1828 case E1000_RXBUFFER_4096:
1829 rctl |= E1000_RCTL_SZ_4096;
1830 break;
1831 case E1000_RXBUFFER_8192:
1832 rctl |= E1000_RCTL_SZ_8192;
1833 break;
1834 case E1000_RXBUFFER_16384:
1835 rctl |= E1000_RCTL_SZ_16384;
1836 break;
1837 }
1838
1839
1840 if (adapter->netdev->features & NETIF_F_RXALL) {
1841
1842
1843
1844 rctl |= (E1000_RCTL_SBP |
1845 E1000_RCTL_BAM |
1846 E1000_RCTL_PMCF);
1847
1848 rctl &= ~(E1000_RCTL_VFE |
1849 E1000_RCTL_DPF |
1850 E1000_RCTL_CFIEN);
1851
1852
1853
1854 }
1855
1856 ew32(RCTL, rctl);
1857}
1858
1859
1860
1861
1862
1863
1864
1865static void e1000_configure_rx(struct e1000_adapter *adapter)
1866{
1867 u64 rdba;
1868 struct e1000_hw *hw = &adapter->hw;
1869 u32 rdlen, rctl, rxcsum;
1870
1871 if (adapter->netdev->mtu > ETH_DATA_LEN) {
1872 rdlen = adapter->rx_ring[0].count *
1873 sizeof(struct e1000_rx_desc);
1874 adapter->clean_rx = e1000_clean_jumbo_rx_irq;
1875 adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
1876 } else {
1877 rdlen = adapter->rx_ring[0].count *
1878 sizeof(struct e1000_rx_desc);
1879 adapter->clean_rx = e1000_clean_rx_irq;
1880 adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
1881 }
1882
1883
1884 rctl = er32(RCTL);
1885 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1886
1887
1888 ew32(RDTR, adapter->rx_int_delay);
1889
1890 if (hw->mac_type >= e1000_82540) {
1891 ew32(RADV, adapter->rx_abs_int_delay);
1892 if (adapter->itr_setting != 0)
1893 ew32(ITR, 1000000000 / (adapter->itr * 256));
1894 }
1895
1896
1897
1898
1899 switch (adapter->num_rx_queues) {
1900 case 1:
1901 default:
1902 rdba = adapter->rx_ring[0].dma;
1903 ew32(RDLEN, rdlen);
1904 ew32(RDBAH, (rdba >> 32));
1905 ew32(RDBAL, (rdba & 0x00000000ffffffffULL));
1906 ew32(RDT, 0);
1907 ew32(RDH, 0);
1908 adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ?
1909 E1000_RDH : E1000_82542_RDH);
1910 adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ?
1911 E1000_RDT : E1000_82542_RDT);
1912 break;
1913 }
1914
1915
1916 if (hw->mac_type >= e1000_82543) {
1917 rxcsum = er32(RXCSUM);
1918 if (adapter->rx_csum)
1919 rxcsum |= E1000_RXCSUM_TUOFL;
1920 else
1921
1922 rxcsum &= ~E1000_RXCSUM_TUOFL;
1923 ew32(RXCSUM, rxcsum);
1924 }
1925
1926
1927 ew32(RCTL, rctl | E1000_RCTL_EN);
1928}
1929
1930
1931
1932
1933
1934
1935
1936
1937static void e1000_free_tx_resources(struct e1000_adapter *adapter,
1938 struct e1000_tx_ring *tx_ring)
1939{
1940 struct pci_dev *pdev = adapter->pdev;
1941
1942 e1000_clean_tx_ring(adapter, tx_ring);
1943
1944 vfree(tx_ring->buffer_info);
1945 tx_ring->buffer_info = NULL;
1946
1947 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1948 tx_ring->dma);
1949
1950 tx_ring->desc = NULL;
1951}
1952
1953
1954
1955
1956
1957
1958
1959void e1000_free_all_tx_resources(struct e1000_adapter *adapter)
1960{
1961 int i;
1962
1963 for (i = 0; i < adapter->num_tx_queues; i++)
1964 e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
1965}
1966
1967static void
1968e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
1969 struct e1000_tx_buffer *buffer_info)
1970{
1971 if (buffer_info->dma) {
1972 if (buffer_info->mapped_as_page)
1973 dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
1974 buffer_info->length, DMA_TO_DEVICE);
1975 else
1976 dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
1977 buffer_info->length,
1978 DMA_TO_DEVICE);
1979 buffer_info->dma = 0;
1980 }
1981 if (buffer_info->skb) {
1982 dev_kfree_skb_any(buffer_info->skb);
1983 buffer_info->skb = NULL;
1984 }
1985 buffer_info->time_stamp = 0;
1986
1987}
1988
1989
1990
1991
1992
1993
1994static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
1995 struct e1000_tx_ring *tx_ring)
1996{
1997 struct e1000_hw *hw = &adapter->hw;
1998 struct e1000_tx_buffer *buffer_info;
1999 unsigned long size;
2000 unsigned int i;
2001
2002
2003
2004 for (i = 0; i < tx_ring->count; i++) {
2005 buffer_info = &tx_ring->buffer_info[i];
2006 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2007 }
2008
2009 netdev_reset_queue(adapter->netdev);
2010 size = sizeof(struct e1000_tx_buffer) * tx_ring->count;
2011 memset(tx_ring->buffer_info, 0, size);
2012
2013
2014
2015 memset(tx_ring->desc, 0, tx_ring->size);
2016
2017 tx_ring->next_to_use = 0;
2018 tx_ring->next_to_clean = 0;
2019 tx_ring->last_tx_tso = false;
2020
2021 writel(0, hw->hw_addr + tx_ring->tdh);
2022 writel(0, hw->hw_addr + tx_ring->tdt);
2023}
2024
2025
2026
2027
2028
2029static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
2030{
2031 int i;
2032
2033 for (i = 0; i < adapter->num_tx_queues; i++)
2034 e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2035}
2036
2037
2038
2039
2040
2041
2042
2043
2044static void e1000_free_rx_resources(struct e1000_adapter *adapter,
2045 struct e1000_rx_ring *rx_ring)
2046{
2047 struct pci_dev *pdev = adapter->pdev;
2048
2049 e1000_clean_rx_ring(adapter, rx_ring);
2050
2051 vfree(rx_ring->buffer_info);
2052 rx_ring->buffer_info = NULL;
2053
2054 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
2055 rx_ring->dma);
2056
2057 rx_ring->desc = NULL;
2058}
2059
2060
2061
2062
2063
2064
2065
2066void e1000_free_all_rx_resources(struct e1000_adapter *adapter)
2067{
2068 int i;
2069
2070 for (i = 0; i < adapter->num_rx_queues; i++)
2071 e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
2072}
2073
2074#define E1000_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN)
2075static unsigned int e1000_frag_len(const struct e1000_adapter *a)
2076{
2077 return SKB_DATA_ALIGN(a->rx_buffer_len + E1000_HEADROOM) +
2078 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
2079}
2080
2081static void *e1000_alloc_frag(const struct e1000_adapter *a)
2082{
2083 unsigned int len = e1000_frag_len(a);
2084 u8 *data = netdev_alloc_frag(len);
2085
2086 if (likely(data))
2087 data += E1000_HEADROOM;
2088 return data;
2089}
2090
2091
2092
2093
2094
2095
2096static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
2097 struct e1000_rx_ring *rx_ring)
2098{
2099 struct e1000_hw *hw = &adapter->hw;
2100 struct e1000_rx_buffer *buffer_info;
2101 struct pci_dev *pdev = adapter->pdev;
2102 unsigned long size;
2103 unsigned int i;
2104
2105
2106 for (i = 0; i < rx_ring->count; i++) {
2107 buffer_info = &rx_ring->buffer_info[i];
2108 if (adapter->clean_rx == e1000_clean_rx_irq) {
2109 if (buffer_info->dma)
2110 dma_unmap_single(&pdev->dev, buffer_info->dma,
2111 adapter->rx_buffer_len,
2112 DMA_FROM_DEVICE);
2113 if (buffer_info->rxbuf.data) {
2114 skb_free_frag(buffer_info->rxbuf.data);
2115 buffer_info->rxbuf.data = NULL;
2116 }
2117 } else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq) {
2118 if (buffer_info->dma)
2119 dma_unmap_page(&pdev->dev, buffer_info->dma,
2120 adapter->rx_buffer_len,
2121 DMA_FROM_DEVICE);
2122 if (buffer_info->rxbuf.page) {
2123 put_page(buffer_info->rxbuf.page);
2124 buffer_info->rxbuf.page = NULL;
2125 }
2126 }
2127
2128 buffer_info->dma = 0;
2129 }
2130
2131
2132 napi_free_frags(&adapter->napi);
2133 rx_ring->rx_skb_top = NULL;
2134
2135 size = sizeof(struct e1000_rx_buffer) * rx_ring->count;
2136 memset(rx_ring->buffer_info, 0, size);
2137
2138
2139 memset(rx_ring->desc, 0, rx_ring->size);
2140
2141 rx_ring->next_to_clean = 0;
2142 rx_ring->next_to_use = 0;
2143
2144 writel(0, hw->hw_addr + rx_ring->rdh);
2145 writel(0, hw->hw_addr + rx_ring->rdt);
2146}
2147
2148
2149
2150
2151
2152static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
2153{
2154 int i;
2155
2156 for (i = 0; i < adapter->num_rx_queues; i++)
2157 e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2158}
2159
2160
2161
2162
2163static void e1000_enter_82542_rst(struct e1000_adapter *adapter)
2164{
2165 struct e1000_hw *hw = &adapter->hw;
2166 struct net_device *netdev = adapter->netdev;
2167 u32 rctl;
2168
2169 e1000_pci_clear_mwi(hw);
2170
2171 rctl = er32(RCTL);
2172 rctl |= E1000_RCTL_RST;
2173 ew32(RCTL, rctl);
2174 E1000_WRITE_FLUSH();
2175 mdelay(5);
2176
2177 if (netif_running(netdev))
2178 e1000_clean_all_rx_rings(adapter);
2179}
2180
2181static void e1000_leave_82542_rst(struct e1000_adapter *adapter)
2182{
2183 struct e1000_hw *hw = &adapter->hw;
2184 struct net_device *netdev = adapter->netdev;
2185 u32 rctl;
2186
2187 rctl = er32(RCTL);
2188 rctl &= ~E1000_RCTL_RST;
2189 ew32(RCTL, rctl);
2190 E1000_WRITE_FLUSH();
2191 mdelay(5);
2192
2193 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
2194 e1000_pci_set_mwi(hw);
2195
2196 if (netif_running(netdev)) {
2197
2198 struct e1000_rx_ring *ring = &adapter->rx_ring[0];
2199 e1000_configure_rx(adapter);
2200 adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
2201 }
2202}
2203
2204
2205
2206
2207
2208
2209
2210
2211static int e1000_set_mac(struct net_device *netdev, void *p)
2212{
2213 struct e1000_adapter *adapter = netdev_priv(netdev);
2214 struct e1000_hw *hw = &adapter->hw;
2215 struct sockaddr *addr = p;
2216
2217 if (!is_valid_ether_addr(addr->sa_data))
2218 return -EADDRNOTAVAIL;
2219
2220
2221
2222 if (hw->mac_type == e1000_82542_rev2_0)
2223 e1000_enter_82542_rst(adapter);
2224
2225 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2226 memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len);
2227
2228 e1000_rar_set(hw, hw->mac_addr, 0);
2229
2230 if (hw->mac_type == e1000_82542_rev2_0)
2231 e1000_leave_82542_rst(adapter);
2232
2233 return 0;
2234}
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245static void e1000_set_rx_mode(struct net_device *netdev)
2246{
2247 struct e1000_adapter *adapter = netdev_priv(netdev);
2248 struct e1000_hw *hw = &adapter->hw;
2249 struct netdev_hw_addr *ha;
2250 bool use_uc = false;
2251 u32 rctl;
2252 u32 hash_value;
2253 int i, rar_entries = E1000_RAR_ENTRIES;
2254 int mta_reg_count = E1000_NUM_MTA_REGISTERS;
2255 u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC);
2256
2257 if (!mcarray)
2258 return;
2259
2260
2261
2262 rctl = er32(RCTL);
2263
2264 if (netdev->flags & IFF_PROMISC) {
2265 rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
2266 rctl &= ~E1000_RCTL_VFE;
2267 } else {
2268 if (netdev->flags & IFF_ALLMULTI)
2269 rctl |= E1000_RCTL_MPE;
2270 else
2271 rctl &= ~E1000_RCTL_MPE;
2272
2273 if (e1000_vlan_used(adapter))
2274 rctl |= E1000_RCTL_VFE;
2275 }
2276
2277 if (netdev_uc_count(netdev) > rar_entries - 1) {
2278 rctl |= E1000_RCTL_UPE;
2279 } else if (!(netdev->flags & IFF_PROMISC)) {
2280 rctl &= ~E1000_RCTL_UPE;
2281 use_uc = true;
2282 }
2283
2284 ew32(RCTL, rctl);
2285
2286
2287
2288 if (hw->mac_type == e1000_82542_rev2_0)
2289 e1000_enter_82542_rst(adapter);
2290
2291
2292
2293
2294
2295
2296
2297
2298 i = 1;
2299 if (use_uc)
2300 netdev_for_each_uc_addr(ha, netdev) {
2301 if (i == rar_entries)
2302 break;
2303 e1000_rar_set(hw, ha->addr, i++);
2304 }
2305
2306 netdev_for_each_mc_addr(ha, netdev) {
2307 if (i == rar_entries) {
2308
2309 u32 hash_reg, hash_bit, mta;
2310 hash_value = e1000_hash_mc_addr(hw, ha->addr);
2311 hash_reg = (hash_value >> 5) & 0x7F;
2312 hash_bit = hash_value & 0x1F;
2313 mta = (1 << hash_bit);
2314 mcarray[hash_reg] |= mta;
2315 } else {
2316 e1000_rar_set(hw, ha->addr, i++);
2317 }
2318 }
2319
2320 for (; i < rar_entries; i++) {
2321 E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
2322 E1000_WRITE_FLUSH();
2323 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
2324 E1000_WRITE_FLUSH();
2325 }
2326
2327
2328
2329
2330 for (i = mta_reg_count - 1; i >= 0 ; i--) {
2331
2332
2333
2334
2335
2336 E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]);
2337 }
2338 E1000_WRITE_FLUSH();
2339
2340 if (hw->mac_type == e1000_82542_rev2_0)
2341 e1000_leave_82542_rst(adapter);
2342
2343 kfree(mcarray);
2344}
2345
2346
2347
2348
2349
2350
2351
2352
2353static void e1000_update_phy_info_task(struct work_struct *work)
2354{
2355 struct e1000_adapter *adapter = container_of(work,
2356 struct e1000_adapter,
2357 phy_info_task.work);
2358
2359 e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
2360}
2361
2362
2363
2364
2365
2366static void e1000_82547_tx_fifo_stall_task(struct work_struct *work)
2367{
2368 struct e1000_adapter *adapter = container_of(work,
2369 struct e1000_adapter,
2370 fifo_stall_task.work);
2371 struct e1000_hw *hw = &adapter->hw;
2372 struct net_device *netdev = adapter->netdev;
2373 u32 tctl;
2374
2375 if (atomic_read(&adapter->tx_fifo_stall)) {
2376 if ((er32(TDT) == er32(TDH)) &&
2377 (er32(TDFT) == er32(TDFH)) &&
2378 (er32(TDFTS) == er32(TDFHS))) {
2379 tctl = er32(TCTL);
2380 ew32(TCTL, tctl & ~E1000_TCTL_EN);
2381 ew32(TDFT, adapter->tx_head_addr);
2382 ew32(TDFH, adapter->tx_head_addr);
2383 ew32(TDFTS, adapter->tx_head_addr);
2384 ew32(TDFHS, adapter->tx_head_addr);
2385 ew32(TCTL, tctl);
2386 E1000_WRITE_FLUSH();
2387
2388 adapter->tx_fifo_head = 0;
2389 atomic_set(&adapter->tx_fifo_stall, 0);
2390 netif_wake_queue(netdev);
2391 } else if (!test_bit(__E1000_DOWN, &adapter->flags)) {
2392 schedule_delayed_work(&adapter->fifo_stall_task, 1);
2393 }
2394 }
2395}
2396
2397bool e1000_has_link(struct e1000_adapter *adapter)
2398{
2399 struct e1000_hw *hw = &adapter->hw;
2400 bool link_active = false;
2401
2402
2403
2404
2405
2406
2407
2408 switch (hw->media_type) {
2409 case e1000_media_type_copper:
2410 if (hw->mac_type == e1000_ce4100)
2411 hw->get_link_status = 1;
2412 if (hw->get_link_status) {
2413 e1000_check_for_link(hw);
2414 link_active = !hw->get_link_status;
2415 } else {
2416 link_active = true;
2417 }
2418 break;
2419 case e1000_media_type_fiber:
2420 e1000_check_for_link(hw);
2421 link_active = !!(er32(STATUS) & E1000_STATUS_LU);
2422 break;
2423 case e1000_media_type_internal_serdes:
2424 e1000_check_for_link(hw);
2425 link_active = hw->serdes_has_link;
2426 break;
2427 default:
2428 break;
2429 }
2430
2431 return link_active;
2432}
2433
2434
2435
2436
2437
2438static void e1000_watchdog(struct work_struct *work)
2439{
2440 struct e1000_adapter *adapter = container_of(work,
2441 struct e1000_adapter,
2442 watchdog_task.work);
2443 struct e1000_hw *hw = &adapter->hw;
2444 struct net_device *netdev = adapter->netdev;
2445 struct e1000_tx_ring *txdr = adapter->tx_ring;
2446 u32 link, tctl;
2447
2448 link = e1000_has_link(adapter);
2449 if ((netif_carrier_ok(netdev)) && link)
2450 goto link_up;
2451
2452 if (link) {
2453 if (!netif_carrier_ok(netdev)) {
2454 u32 ctrl;
2455 bool txb2b = true;
2456
2457 e1000_get_speed_and_duplex(hw,
2458 &adapter->link_speed,
2459 &adapter->link_duplex);
2460
2461 ctrl = er32(CTRL);
2462 pr_info("%s NIC Link is Up %d Mbps %s, "
2463 "Flow Control: %s\n",
2464 netdev->name,
2465 adapter->link_speed,
2466 adapter->link_duplex == FULL_DUPLEX ?
2467 "Full Duplex" : "Half Duplex",
2468 ((ctrl & E1000_CTRL_TFCE) && (ctrl &
2469 E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
2470 E1000_CTRL_RFCE) ? "RX" : ((ctrl &
2471 E1000_CTRL_TFCE) ? "TX" : "None")));
2472
2473
2474 adapter->tx_timeout_factor = 1;
2475 switch (adapter->link_speed) {
2476 case SPEED_10:
2477 txb2b = false;
2478 adapter->tx_timeout_factor = 16;
2479 break;
2480 case SPEED_100:
2481 txb2b = false;
2482
2483 break;
2484 }
2485
2486
2487 tctl = er32(TCTL);
2488 tctl |= E1000_TCTL_EN;
2489 ew32(TCTL, tctl);
2490
2491 netif_carrier_on(netdev);
2492 if (!test_bit(__E1000_DOWN, &adapter->flags))
2493 schedule_delayed_work(&adapter->phy_info_task,
2494 2 * HZ);
2495 adapter->smartspeed = 0;
2496 }
2497 } else {
2498 if (netif_carrier_ok(netdev)) {
2499 adapter->link_speed = 0;
2500 adapter->link_duplex = 0;
2501 pr_info("%s NIC Link is Down\n",
2502 netdev->name);
2503 netif_carrier_off(netdev);
2504
2505 if (!test_bit(__E1000_DOWN, &adapter->flags))
2506 schedule_delayed_work(&adapter->phy_info_task,
2507 2 * HZ);
2508 }
2509
2510 e1000_smartspeed(adapter);
2511 }
2512
2513link_up:
2514 e1000_update_stats(adapter);
2515
2516 hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
2517 adapter->tpt_old = adapter->stats.tpt;
2518 hw->collision_delta = adapter->stats.colc - adapter->colc_old;
2519 adapter->colc_old = adapter->stats.colc;
2520
2521 adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
2522 adapter->gorcl_old = adapter->stats.gorcl;
2523 adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
2524 adapter->gotcl_old = adapter->stats.gotcl;
2525
2526 e1000_update_adaptive(hw);
2527
2528 if (!netif_carrier_ok(netdev)) {
2529 if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
2530
2531
2532
2533
2534
2535 adapter->tx_timeout_count++;
2536 schedule_work(&adapter->reset_task);
2537
2538 return;
2539 }
2540 }
2541
2542
2543 if (hw->mac_type >= e1000_82540 && adapter->itr_setting == 4) {
2544
2545
2546
2547
2548 u32 goc = (adapter->gotcl + adapter->gorcl) / 10000;
2549 u32 dif = (adapter->gotcl > adapter->gorcl ?
2550 adapter->gotcl - adapter->gorcl :
2551 adapter->gorcl - adapter->gotcl) / 10000;
2552 u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
2553
2554 ew32(ITR, 1000000000 / (itr * 256));
2555 }
2556
2557
2558 ew32(ICS, E1000_ICS_RXDMT0);
2559
2560
2561 adapter->detect_tx_hung = true;
2562
2563
2564 if (!test_bit(__E1000_DOWN, &adapter->flags))
2565 schedule_delayed_work(&adapter->watchdog_task, 2 * HZ);
2566}
2567
2568enum latency_range {
2569 lowest_latency = 0,
2570 low_latency = 1,
2571 bulk_latency = 2,
2572 latency_invalid = 255
2573};
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2593 u16 itr_setting, int packets, int bytes)
2594{
2595 unsigned int retval = itr_setting;
2596 struct e1000_hw *hw = &adapter->hw;
2597
2598 if (unlikely(hw->mac_type < e1000_82540))
2599 goto update_itr_done;
2600
2601 if (packets == 0)
2602 goto update_itr_done;
2603
2604 switch (itr_setting) {
2605 case lowest_latency:
2606
2607 if (bytes/packets > 8000)
2608 retval = bulk_latency;
2609 else if ((packets < 5) && (bytes > 512))
2610 retval = low_latency;
2611 break;
2612 case low_latency:
2613 if (bytes > 10000) {
2614
2615 if (bytes/packets > 8000)
2616 retval = bulk_latency;
2617 else if ((packets < 10) || ((bytes/packets) > 1200))
2618 retval = bulk_latency;
2619 else if ((packets > 35))
2620 retval = lowest_latency;
2621 } else if (bytes/packets > 2000)
2622 retval = bulk_latency;
2623 else if (packets <= 2 && bytes < 512)
2624 retval = lowest_latency;
2625 break;
2626 case bulk_latency:
2627 if (bytes > 25000) {
2628 if (packets > 35)
2629 retval = low_latency;
2630 } else if (bytes < 6000) {
2631 retval = low_latency;
2632 }
2633 break;
2634 }
2635
2636update_itr_done:
2637 return retval;
2638}
2639
2640static void e1000_set_itr(struct e1000_adapter *adapter)
2641{
2642 struct e1000_hw *hw = &adapter->hw;
2643 u16 current_itr;
2644 u32 new_itr = adapter->itr;
2645
2646 if (unlikely(hw->mac_type < e1000_82540))
2647 return;
2648
2649
2650 if (unlikely(adapter->link_speed != SPEED_1000)) {
2651 current_itr = 0;
2652 new_itr = 4000;
2653 goto set_itr_now;
2654 }
2655
2656 adapter->tx_itr = e1000_update_itr(adapter, adapter->tx_itr,
2657 adapter->total_tx_packets,
2658 adapter->total_tx_bytes);
2659
2660 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2661 adapter->tx_itr = low_latency;
2662
2663 adapter->rx_itr = e1000_update_itr(adapter, adapter->rx_itr,
2664 adapter->total_rx_packets,
2665 adapter->total_rx_bytes);
2666
2667 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2668 adapter->rx_itr = low_latency;
2669
2670 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2671
2672 switch (current_itr) {
2673
2674 case lowest_latency:
2675 new_itr = 70000;
2676 break;
2677 case low_latency:
2678 new_itr = 20000;
2679 break;
2680 case bulk_latency:
2681 new_itr = 4000;
2682 break;
2683 default:
2684 break;
2685 }
2686
2687set_itr_now:
2688 if (new_itr != adapter->itr) {
2689
2690
2691
2692
2693 new_itr = new_itr > adapter->itr ?
2694 min(adapter->itr + (new_itr >> 2), new_itr) :
2695 new_itr;
2696 adapter->itr = new_itr;
2697 ew32(ITR, 1000000000 / (new_itr * 256));
2698 }
2699}
2700
2701#define E1000_TX_FLAGS_CSUM 0x00000001
2702#define E1000_TX_FLAGS_VLAN 0x00000002
2703#define E1000_TX_FLAGS_TSO 0x00000004
2704#define E1000_TX_FLAGS_IPV4 0x00000008
2705#define E1000_TX_FLAGS_NO_FCS 0x00000010
2706#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
2707#define E1000_TX_FLAGS_VLAN_SHIFT 16
2708
2709static int e1000_tso(struct e1000_adapter *adapter,
2710 struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
2711 __be16 protocol)
2712{
2713 struct e1000_context_desc *context_desc;
2714 struct e1000_tx_buffer *buffer_info;
2715 unsigned int i;
2716 u32 cmd_length = 0;
2717 u16 ipcse = 0, tucse, mss;
2718 u8 ipcss, ipcso, tucss, tucso, hdr_len;
2719
2720 if (skb_is_gso(skb)) {
2721 int err;
2722
2723 err = skb_cow_head(skb, 0);
2724 if (err < 0)
2725 return err;
2726
2727 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
2728 mss = skb_shinfo(skb)->gso_size;
2729 if (protocol == htons(ETH_P_IP)) {
2730 struct iphdr *iph = ip_hdr(skb);
2731 iph->tot_len = 0;
2732 iph->check = 0;
2733 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
2734 iph->daddr, 0,
2735 IPPROTO_TCP,
2736 0);
2737 cmd_length = E1000_TXD_CMD_IP;
2738 ipcse = skb_transport_offset(skb) - 1;
2739 } else if (skb_is_gso_v6(skb)) {
2740 ipv6_hdr(skb)->payload_len = 0;
2741 tcp_hdr(skb)->check =
2742 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2743 &ipv6_hdr(skb)->daddr,
2744 0, IPPROTO_TCP, 0);
2745 ipcse = 0;
2746 }
2747 ipcss = skb_network_offset(skb);
2748 ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
2749 tucss = skb_transport_offset(skb);
2750 tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
2751 tucse = 0;
2752
2753 cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
2754 E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
2755
2756 i = tx_ring->next_to_use;
2757 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2758 buffer_info = &tx_ring->buffer_info[i];
2759
2760 context_desc->lower_setup.ip_fields.ipcss = ipcss;
2761 context_desc->lower_setup.ip_fields.ipcso = ipcso;
2762 context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
2763 context_desc->upper_setup.tcp_fields.tucss = tucss;
2764 context_desc->upper_setup.tcp_fields.tucso = tucso;
2765 context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
2766 context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
2767 context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
2768 context_desc->cmd_and_length = cpu_to_le32(cmd_length);
2769
2770 buffer_info->time_stamp = jiffies;
2771 buffer_info->next_to_watch = i;
2772
2773 if (++i == tx_ring->count)
2774 i = 0;
2775
2776 tx_ring->next_to_use = i;
2777
2778 return true;
2779 }
2780 return false;
2781}
2782
2783static bool e1000_tx_csum(struct e1000_adapter *adapter,
2784 struct e1000_tx_ring *tx_ring, struct sk_buff *skb,
2785 __be16 protocol)
2786{
2787 struct e1000_context_desc *context_desc;
2788 struct e1000_tx_buffer *buffer_info;
2789 unsigned int i;
2790 u8 css;
2791 u32 cmd_len = E1000_TXD_CMD_DEXT;
2792
2793 if (skb->ip_summed != CHECKSUM_PARTIAL)
2794 return false;
2795
2796 switch (protocol) {
2797 case cpu_to_be16(ETH_P_IP):
2798 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2799 cmd_len |= E1000_TXD_CMD_TCP;
2800 break;
2801 case cpu_to_be16(ETH_P_IPV6):
2802
2803 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2804 cmd_len |= E1000_TXD_CMD_TCP;
2805 break;
2806 default:
2807 if (unlikely(net_ratelimit()))
2808 e_warn(drv, "checksum_partial proto=%x!\n",
2809 skb->protocol);
2810 break;
2811 }
2812
2813 css = skb_checksum_start_offset(skb);
2814
2815 i = tx_ring->next_to_use;
2816 buffer_info = &tx_ring->buffer_info[i];
2817 context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
2818
2819 context_desc->lower_setup.ip_config = 0;
2820 context_desc->upper_setup.tcp_fields.tucss = css;
2821 context_desc->upper_setup.tcp_fields.tucso =
2822 css + skb->csum_offset;
2823 context_desc->upper_setup.tcp_fields.tucse = 0;
2824 context_desc->tcp_seg_setup.data = 0;
2825 context_desc->cmd_and_length = cpu_to_le32(cmd_len);
2826
2827 buffer_info->time_stamp = jiffies;
2828 buffer_info->next_to_watch = i;
2829
2830 if (unlikely(++i == tx_ring->count))
2831 i = 0;
2832
2833 tx_ring->next_to_use = i;
2834
2835 return true;
2836}
2837
2838#define E1000_MAX_TXD_PWR 12
2839#define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
2840
2841static int e1000_tx_map(struct e1000_adapter *adapter,
2842 struct e1000_tx_ring *tx_ring,
2843 struct sk_buff *skb, unsigned int first,
2844 unsigned int max_per_txd, unsigned int nr_frags,
2845 unsigned int mss)
2846{
2847 struct e1000_hw *hw = &adapter->hw;
2848 struct pci_dev *pdev = adapter->pdev;
2849 struct e1000_tx_buffer *buffer_info;
2850 unsigned int len = skb_headlen(skb);
2851 unsigned int offset = 0, size, count = 0, i;
2852 unsigned int f, bytecount, segs;
2853
2854 i = tx_ring->next_to_use;
2855
2856 while (len) {
2857 buffer_info = &tx_ring->buffer_info[i];
2858 size = min(len, max_per_txd);
2859
2860
2861
2862
2863
2864 if (!skb->data_len && tx_ring->last_tx_tso &&
2865 !skb_is_gso(skb)) {
2866 tx_ring->last_tx_tso = false;
2867 size -= 4;
2868 }
2869
2870
2871
2872
2873 if (unlikely(mss && !nr_frags && size == len && size > 8))
2874 size -= 4;
2875
2876
2877
2878
2879
2880 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
2881 (size > 2015) && count == 0))
2882 size = 2015;
2883
2884
2885
2886
2887 if (unlikely(adapter->pcix_82544 &&
2888 !((unsigned long)(skb->data + offset + size - 1) & 4) &&
2889 size > 4))
2890 size -= 4;
2891
2892 buffer_info->length = size;
2893
2894 buffer_info->time_stamp = jiffies;
2895 buffer_info->mapped_as_page = false;
2896 buffer_info->dma = dma_map_single(&pdev->dev,
2897 skb->data + offset,
2898 size, DMA_TO_DEVICE);
2899 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2900 goto dma_error;
2901 buffer_info->next_to_watch = i;
2902
2903 len -= size;
2904 offset += size;
2905 count++;
2906 if (len) {
2907 i++;
2908 if (unlikely(i == tx_ring->count))
2909 i = 0;
2910 }
2911 }
2912
2913 for (f = 0; f < nr_frags; f++) {
2914 const struct skb_frag_struct *frag;
2915
2916 frag = &skb_shinfo(skb)->frags[f];
2917 len = skb_frag_size(frag);
2918 offset = 0;
2919
2920 while (len) {
2921 unsigned long bufend;
2922 i++;
2923 if (unlikely(i == tx_ring->count))
2924 i = 0;
2925
2926 buffer_info = &tx_ring->buffer_info[i];
2927 size = min(len, max_per_txd);
2928
2929
2930
2931 if (unlikely(mss && f == (nr_frags-1) &&
2932 size == len && size > 8))
2933 size -= 4;
2934
2935
2936
2937
2938 bufend = (unsigned long)
2939 page_to_phys(skb_frag_page(frag));
2940 bufend += offset + size - 1;
2941 if (unlikely(adapter->pcix_82544 &&
2942 !(bufend & 4) &&
2943 size > 4))
2944 size -= 4;
2945
2946 buffer_info->length = size;
2947 buffer_info->time_stamp = jiffies;
2948 buffer_info->mapped_as_page = true;
2949 buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
2950 offset, size, DMA_TO_DEVICE);
2951 if (dma_mapping_error(&pdev->dev, buffer_info->dma))
2952 goto dma_error;
2953 buffer_info->next_to_watch = i;
2954
2955 len -= size;
2956 offset += size;
2957 count++;
2958 }
2959 }
2960
2961 segs = skb_shinfo(skb)->gso_segs ?: 1;
2962
2963 bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
2964
2965 tx_ring->buffer_info[i].skb = skb;
2966 tx_ring->buffer_info[i].segs = segs;
2967 tx_ring->buffer_info[i].bytecount = bytecount;
2968 tx_ring->buffer_info[first].next_to_watch = i;
2969
2970 return count;
2971
2972dma_error:
2973 dev_err(&pdev->dev, "TX DMA map failed\n");
2974 buffer_info->dma = 0;
2975 if (count)
2976 count--;
2977
2978 while (count--) {
2979 if (i == 0)
2980 i += tx_ring->count;
2981 i--;
2982 buffer_info = &tx_ring->buffer_info[i];
2983 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
2984 }
2985
2986 return 0;
2987}
2988
2989static void e1000_tx_queue(struct e1000_adapter *adapter,
2990 struct e1000_tx_ring *tx_ring, int tx_flags,
2991 int count)
2992{
2993 struct e1000_tx_desc *tx_desc = NULL;
2994 struct e1000_tx_buffer *buffer_info;
2995 u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
2996 unsigned int i;
2997
2998 if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
2999 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
3000 E1000_TXD_CMD_TSE;
3001 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3002
3003 if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
3004 txd_upper |= E1000_TXD_POPTS_IXSM << 8;
3005 }
3006
3007 if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
3008 txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
3009 txd_upper |= E1000_TXD_POPTS_TXSM << 8;
3010 }
3011
3012 if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
3013 txd_lower |= E1000_TXD_CMD_VLE;
3014 txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
3015 }
3016
3017 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
3018 txd_lower &= ~(E1000_TXD_CMD_IFCS);
3019
3020 i = tx_ring->next_to_use;
3021
3022 while (count--) {
3023 buffer_info = &tx_ring->buffer_info[i];
3024 tx_desc = E1000_TX_DESC(*tx_ring, i);
3025 tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
3026 tx_desc->lower.data =
3027 cpu_to_le32(txd_lower | buffer_info->length);
3028 tx_desc->upper.data = cpu_to_le32(txd_upper);
3029 if (unlikely(++i == tx_ring->count))
3030 i = 0;
3031 }
3032
3033 tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
3034
3035
3036 if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
3037 tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
3038
3039
3040
3041
3042
3043
3044 wmb();
3045
3046 tx_ring->next_to_use = i;
3047}
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057#define E1000_FIFO_HDR 0x10
3058#define E1000_82547_PAD_LEN 0x3E0
3059
3060static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
3061 struct sk_buff *skb)
3062{
3063 u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
3064 u32 skb_fifo_len = skb->len + E1000_FIFO_HDR;
3065
3066 skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
3067
3068 if (adapter->link_duplex != HALF_DUPLEX)
3069 goto no_fifo_stall_required;
3070
3071 if (atomic_read(&adapter->tx_fifo_stall))
3072 return 1;
3073
3074 if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
3075 atomic_set(&adapter->tx_fifo_stall, 1);
3076 return 1;
3077 }
3078
3079no_fifo_stall_required:
3080 adapter->tx_fifo_head += skb_fifo_len;
3081 if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
3082 adapter->tx_fifo_head -= adapter->tx_fifo_size;
3083 return 0;
3084}
3085
3086static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
3087{
3088 struct e1000_adapter *adapter = netdev_priv(netdev);
3089 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3090
3091 netif_stop_queue(netdev);
3092
3093
3094
3095
3096 smp_mb();
3097
3098
3099
3100
3101 if (likely(E1000_DESC_UNUSED(tx_ring) < size))
3102 return -EBUSY;
3103
3104
3105 netif_start_queue(netdev);
3106 ++adapter->restart_queue;
3107 return 0;
3108}
3109
3110static int e1000_maybe_stop_tx(struct net_device *netdev,
3111 struct e1000_tx_ring *tx_ring, int size)
3112{
3113 if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
3114 return 0;
3115 return __e1000_maybe_stop_tx(netdev, size);
3116}
3117
3118#define TXD_USE_COUNT(S, X) (((S) + ((1 << (X)) - 1)) >> (X))
3119static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
3120 struct net_device *netdev)
3121{
3122 struct e1000_adapter *adapter = netdev_priv(netdev);
3123 struct e1000_hw *hw = &adapter->hw;
3124 struct e1000_tx_ring *tx_ring;
3125 unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
3126 unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
3127 unsigned int tx_flags = 0;
3128 unsigned int len = skb_headlen(skb);
3129 unsigned int nr_frags;
3130 unsigned int mss;
3131 int count = 0;
3132 int tso;
3133 unsigned int f;
3134 __be16 protocol = vlan_get_protocol(skb);
3135
3136
3137
3138
3139
3140
3141 tx_ring = adapter->tx_ring;
3142
3143
3144
3145
3146
3147 if (eth_skb_pad(skb))
3148 return NETDEV_TX_OK;
3149
3150 mss = skb_shinfo(skb)->gso_size;
3151
3152
3153
3154
3155
3156
3157
3158 if (mss) {
3159 u8 hdr_len;
3160 max_per_txd = min(mss << 2, max_per_txd);
3161 max_txd_pwr = fls(max_per_txd) - 1;
3162
3163 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
3164 if (skb->data_len && hdr_len == len) {
3165 switch (hw->mac_type) {
3166 unsigned int pull_size;
3167 case e1000_82544:
3168
3169
3170
3171
3172
3173
3174
3175 if ((unsigned long)(skb_tail_pointer(skb) - 1)
3176 & 4)
3177 break;
3178
3179 pull_size = min((unsigned int)4, skb->data_len);
3180 if (!__pskb_pull_tail(skb, pull_size)) {
3181 e_err(drv, "__pskb_pull_tail "
3182 "failed.\n");
3183 dev_kfree_skb_any(skb);
3184 return NETDEV_TX_OK;
3185 }
3186 len = skb_headlen(skb);
3187 break;
3188 default:
3189
3190 break;
3191 }
3192 }
3193 }
3194
3195
3196 if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
3197 count++;
3198 count++;
3199
3200
3201 if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
3202 count++;
3203
3204 count += TXD_USE_COUNT(len, max_txd_pwr);
3205
3206 if (adapter->pcix_82544)
3207 count++;
3208
3209
3210
3211
3212 if (unlikely((hw->bus_type == e1000_bus_type_pcix) &&
3213 (len > 2015)))
3214 count++;
3215
3216 nr_frags = skb_shinfo(skb)->nr_frags;
3217 for (f = 0; f < nr_frags; f++)
3218 count += TXD_USE_COUNT(skb_frag_size(&skb_shinfo(skb)->frags[f]),
3219 max_txd_pwr);
3220 if (adapter->pcix_82544)
3221 count += nr_frags;
3222
3223
3224
3225
3226 if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2)))
3227 return NETDEV_TX_BUSY;
3228
3229 if (unlikely((hw->mac_type == e1000_82547) &&
3230 (e1000_82547_fifo_workaround(adapter, skb)))) {
3231 netif_stop_queue(netdev);
3232 if (!test_bit(__E1000_DOWN, &adapter->flags))
3233 schedule_delayed_work(&adapter->fifo_stall_task, 1);
3234 return NETDEV_TX_BUSY;
3235 }
3236
3237 if (skb_vlan_tag_present(skb)) {
3238 tx_flags |= E1000_TX_FLAGS_VLAN;
3239 tx_flags |= (skb_vlan_tag_get(skb) <<
3240 E1000_TX_FLAGS_VLAN_SHIFT);
3241 }
3242
3243 first = tx_ring->next_to_use;
3244
3245 tso = e1000_tso(adapter, tx_ring, skb, protocol);
3246 if (tso < 0) {
3247 dev_kfree_skb_any(skb);
3248 return NETDEV_TX_OK;
3249 }
3250
3251 if (likely(tso)) {
3252 if (likely(hw->mac_type != e1000_82544))
3253 tx_ring->last_tx_tso = true;
3254 tx_flags |= E1000_TX_FLAGS_TSO;
3255 } else if (likely(e1000_tx_csum(adapter, tx_ring, skb, protocol)))
3256 tx_flags |= E1000_TX_FLAGS_CSUM;
3257
3258 if (protocol == htons(ETH_P_IP))
3259 tx_flags |= E1000_TX_FLAGS_IPV4;
3260
3261 if (unlikely(skb->no_fcs))
3262 tx_flags |= E1000_TX_FLAGS_NO_FCS;
3263
3264 count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd,
3265 nr_frags, mss);
3266
3267 if (count) {
3268
3269
3270
3271
3272
3273
3274
3275 int desc_needed = MAX_SKB_FRAGS + 7;
3276
3277 netdev_sent_queue(netdev, skb->len);
3278 skb_tx_timestamp(skb);
3279
3280 e1000_tx_queue(adapter, tx_ring, tx_flags, count);
3281
3282
3283
3284
3285
3286 if (adapter->pcix_82544)
3287 desc_needed += MAX_SKB_FRAGS + 1;
3288
3289
3290 e1000_maybe_stop_tx(netdev, tx_ring, desc_needed);
3291
3292 if (!skb->xmit_more ||
3293 netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
3294 writel(tx_ring->next_to_use, hw->hw_addr + tx_ring->tdt);
3295
3296
3297
3298
3299 mmiowb();
3300 }
3301 } else {
3302 dev_kfree_skb_any(skb);
3303 tx_ring->buffer_info[first].time_stamp = 0;
3304 tx_ring->next_to_use = first;
3305 }
3306
3307 return NETDEV_TX_OK;
3308}
3309
3310#define NUM_REGS 38
3311static void e1000_regdump(struct e1000_adapter *adapter)
3312{
3313 struct e1000_hw *hw = &adapter->hw;
3314 u32 regs[NUM_REGS];
3315 u32 *regs_buff = regs;
3316 int i = 0;
3317
3318 static const char * const reg_name[] = {
3319 "CTRL", "STATUS",
3320 "RCTL", "RDLEN", "RDH", "RDT", "RDTR",
3321 "TCTL", "TDBAL", "TDBAH", "TDLEN", "TDH", "TDT",
3322 "TIDV", "TXDCTL", "TADV", "TARC0",
3323 "TDBAL1", "TDBAH1", "TDLEN1", "TDH1", "TDT1",
3324 "TXDCTL1", "TARC1",
3325 "CTRL_EXT", "ERT", "RDBAL", "RDBAH",
3326 "TDFH", "TDFT", "TDFHS", "TDFTS", "TDFPC",
3327 "RDFH", "RDFT", "RDFHS", "RDFTS", "RDFPC"
3328 };
3329
3330 regs_buff[0] = er32(CTRL);
3331 regs_buff[1] = er32(STATUS);
3332
3333 regs_buff[2] = er32(RCTL);
3334 regs_buff[3] = er32(RDLEN);
3335 regs_buff[4] = er32(RDH);
3336 regs_buff[5] = er32(RDT);
3337 regs_buff[6] = er32(RDTR);
3338
3339 regs_buff[7] = er32(TCTL);
3340 regs_buff[8] = er32(TDBAL);
3341 regs_buff[9] = er32(TDBAH);
3342 regs_buff[10] = er32(TDLEN);
3343 regs_buff[11] = er32(TDH);
3344 regs_buff[12] = er32(TDT);
3345 regs_buff[13] = er32(TIDV);
3346 regs_buff[14] = er32(TXDCTL);
3347 regs_buff[15] = er32(TADV);
3348 regs_buff[16] = er32(TARC0);
3349
3350 regs_buff[17] = er32(TDBAL1);
3351 regs_buff[18] = er32(TDBAH1);
3352 regs_buff[19] = er32(TDLEN1);
3353 regs_buff[20] = er32(TDH1);
3354 regs_buff[21] = er32(TDT1);
3355 regs_buff[22] = er32(TXDCTL1);
3356 regs_buff[23] = er32(TARC1);
3357 regs_buff[24] = er32(CTRL_EXT);
3358 regs_buff[25] = er32(ERT);
3359 regs_buff[26] = er32(RDBAL0);
3360 regs_buff[27] = er32(RDBAH0);
3361 regs_buff[28] = er32(TDFH);
3362 regs_buff[29] = er32(TDFT);
3363 regs_buff[30] = er32(TDFHS);
3364 regs_buff[31] = er32(TDFTS);
3365 regs_buff[32] = er32(TDFPC);
3366 regs_buff[33] = er32(RDFH);
3367 regs_buff[34] = er32(RDFT);
3368 regs_buff[35] = er32(RDFHS);
3369 regs_buff[36] = er32(RDFTS);
3370 regs_buff[37] = er32(RDFPC);
3371
3372 pr_info("Register dump\n");
3373 for (i = 0; i < NUM_REGS; i++)
3374 pr_info("%-15s %08x\n", reg_name[i], regs_buff[i]);
3375}
3376
3377
3378
3379
3380static void e1000_dump(struct e1000_adapter *adapter)
3381{
3382
3383 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
3384 struct e1000_rx_ring *rx_ring = adapter->rx_ring;
3385 int i;
3386
3387 if (!netif_msg_hw(adapter))
3388 return;
3389
3390
3391 e1000_regdump(adapter);
3392
3393
3394 pr_info("TX Desc ring0 dump\n");
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423 pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestmp bi->skb\n");
3424 pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestmp bi->skb\n");
3425
3426 if (!netif_msg_tx_done(adapter))
3427 goto rx_ring_summary;
3428
3429 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
3430 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
3431 struct e1000_tx_buffer *buffer_info = &tx_ring->buffer_info[i];
3432 struct my_u { __le64 a; __le64 b; };
3433 struct my_u *u = (struct my_u *)tx_desc;
3434 const char *type;
3435
3436 if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
3437 type = "NTC/U";
3438 else if (i == tx_ring->next_to_use)
3439 type = "NTU";
3440 else if (i == tx_ring->next_to_clean)
3441 type = "NTC";
3442 else
3443 type = "";
3444
3445 pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p %s\n",
3446 ((le64_to_cpu(u->b) & (1<<20)) ? 'd' : 'c'), i,
3447 le64_to_cpu(u->a), le64_to_cpu(u->b),
3448 (u64)buffer_info->dma, buffer_info->length,
3449 buffer_info->next_to_watch,
3450 (u64)buffer_info->time_stamp, buffer_info->skb, type);
3451 }
3452
3453rx_ring_summary:
3454
3455 pr_info("\nRX Desc ring dump\n");
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466 pr_info("R[desc] [address 63:0 ] [vl er S cks ln] [bi->dma ] [bi->skb]\n");
3467
3468 if (!netif_msg_rx_status(adapter))
3469 goto exit;
3470
3471 for (i = 0; rx_ring->desc && (i < rx_ring->count); i++) {
3472 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
3473 struct e1000_rx_buffer *buffer_info = &rx_ring->buffer_info[i];
3474 struct my_u { __le64 a; __le64 b; };
3475 struct my_u *u = (struct my_u *)rx_desc;
3476 const char *type;
3477
3478 if (i == rx_ring->next_to_use)
3479 type = "NTU";
3480 else if (i == rx_ring->next_to_clean)
3481 type = "NTC";
3482 else
3483 type = "";
3484
3485 pr_info("R[0x%03X] %016llX %016llX %016llX %p %s\n",
3486 i, le64_to_cpu(u->a), le64_to_cpu(u->b),
3487 (u64)buffer_info->dma, buffer_info->rxbuf.data, type);
3488 }
3489
3490
3491
3492 pr_info("Rx descriptor cache in 64bit format\n");
3493 for (i = 0x6000; i <= 0x63FF ; i += 0x10) {
3494 pr_info("R%04X: %08X|%08X %08X|%08X\n",
3495 i,
3496 readl(adapter->hw.hw_addr + i+4),
3497 readl(adapter->hw.hw_addr + i),
3498 readl(adapter->hw.hw_addr + i+12),
3499 readl(adapter->hw.hw_addr + i+8));
3500 }
3501
3502 pr_info("Tx descriptor cache in 64bit format\n");
3503 for (i = 0x7000; i <= 0x73FF ; i += 0x10) {
3504 pr_info("T%04X: %08X|%08X %08X|%08X\n",
3505 i,
3506 readl(adapter->hw.hw_addr + i+4),
3507 readl(adapter->hw.hw_addr + i),
3508 readl(adapter->hw.hw_addr + i+12),
3509 readl(adapter->hw.hw_addr + i+8));
3510 }
3511exit:
3512 return;
3513}
3514
3515
3516
3517
3518
3519static void e1000_tx_timeout(struct net_device *netdev)
3520{
3521 struct e1000_adapter *adapter = netdev_priv(netdev);
3522
3523
3524 adapter->tx_timeout_count++;
3525 schedule_work(&adapter->reset_task);
3526}
3527
3528static void e1000_reset_task(struct work_struct *work)
3529{
3530 struct e1000_adapter *adapter =
3531 container_of(work, struct e1000_adapter, reset_task);
3532
3533 e_err(drv, "Reset adapter\n");
3534 e1000_reinit_locked(adapter);
3535}
3536
3537
3538
3539
3540
3541
3542
3543
3544static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
3545{
3546 struct e1000_adapter *adapter = netdev_priv(netdev);
3547 struct e1000_hw *hw = &adapter->hw;
3548 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3549
3550
3551 switch (hw->mac_type) {
3552 case e1000_undefined ... e1000_82542_rev2_1:
3553 if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) {
3554 e_err(probe, "Jumbo Frames not supported.\n");
3555 return -EINVAL;
3556 }
3557 break;
3558 default:
3559
3560 break;
3561 }
3562
3563 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
3564 msleep(1);
3565
3566 hw->max_frame_size = max_frame;
3567 if (netif_running(netdev)) {
3568
3569 adapter->alloc_rx_buf = e1000_alloc_dummy_rx_buffers;
3570 e1000_down(adapter);
3571 }
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581 if (max_frame <= E1000_RXBUFFER_2048)
3582 adapter->rx_buffer_len = E1000_RXBUFFER_2048;
3583 else
3584#if (PAGE_SIZE >= E1000_RXBUFFER_16384)
3585 adapter->rx_buffer_len = E1000_RXBUFFER_16384;
3586#elif (PAGE_SIZE >= E1000_RXBUFFER_4096)
3587 adapter->rx_buffer_len = PAGE_SIZE;
3588#endif
3589
3590
3591 if (!hw->tbi_compatibility_on &&
3592 ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
3593 (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
3594 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3595
3596 pr_info("%s changing MTU from %d to %d\n",
3597 netdev->name, netdev->mtu, new_mtu);
3598 netdev->mtu = new_mtu;
3599
3600 if (netif_running(netdev))
3601 e1000_up(adapter);
3602 else
3603 e1000_reset(adapter);
3604
3605 clear_bit(__E1000_RESETTING, &adapter->flags);
3606
3607 return 0;
3608}
3609
3610
3611
3612
3613
3614void e1000_update_stats(struct e1000_adapter *adapter)
3615{
3616 struct net_device *netdev = adapter->netdev;
3617 struct e1000_hw *hw = &adapter->hw;
3618 struct pci_dev *pdev = adapter->pdev;
3619 unsigned long flags;
3620 u16 phy_tmp;
3621
3622#define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
3623
3624
3625
3626
3627 if (adapter->link_speed == 0)
3628 return;
3629 if (pci_channel_offline(pdev))
3630 return;
3631
3632 spin_lock_irqsave(&adapter->stats_lock, flags);
3633
3634
3635
3636
3637
3638
3639 adapter->stats.crcerrs += er32(CRCERRS);
3640 adapter->stats.gprc += er32(GPRC);
3641 adapter->stats.gorcl += er32(GORCL);
3642 adapter->stats.gorch += er32(GORCH);
3643 adapter->stats.bprc += er32(BPRC);
3644 adapter->stats.mprc += er32(MPRC);
3645 adapter->stats.roc += er32(ROC);
3646
3647 adapter->stats.prc64 += er32(PRC64);
3648 adapter->stats.prc127 += er32(PRC127);
3649 adapter->stats.prc255 += er32(PRC255);
3650 adapter->stats.prc511 += er32(PRC511);
3651 adapter->stats.prc1023 += er32(PRC1023);
3652 adapter->stats.prc1522 += er32(PRC1522);
3653
3654 adapter->stats.symerrs += er32(SYMERRS);
3655 adapter->stats.mpc += er32(MPC);
3656 adapter->stats.scc += er32(SCC);
3657 adapter->stats.ecol += er32(ECOL);
3658 adapter->stats.mcc += er32(MCC);
3659 adapter->stats.latecol += er32(LATECOL);
3660 adapter->stats.dc += er32(DC);
3661 adapter->stats.sec += er32(SEC);
3662 adapter->stats.rlec += er32(RLEC);
3663 adapter->stats.xonrxc += er32(XONRXC);
3664 adapter->stats.xontxc += er32(XONTXC);
3665 adapter->stats.xoffrxc += er32(XOFFRXC);
3666 adapter->stats.xofftxc += er32(XOFFTXC);
3667 adapter->stats.fcruc += er32(FCRUC);
3668 adapter->stats.gptc += er32(GPTC);
3669 adapter->stats.gotcl += er32(GOTCL);
3670 adapter->stats.gotch += er32(GOTCH);
3671 adapter->stats.rnbc += er32(RNBC);
3672 adapter->stats.ruc += er32(RUC);
3673 adapter->stats.rfc += er32(RFC);
3674 adapter->stats.rjc += er32(RJC);
3675 adapter->stats.torl += er32(TORL);
3676 adapter->stats.torh += er32(TORH);
3677 adapter->stats.totl += er32(TOTL);
3678 adapter->stats.toth += er32(TOTH);
3679 adapter->stats.tpr += er32(TPR);
3680
3681 adapter->stats.ptc64 += er32(PTC64);
3682 adapter->stats.ptc127 += er32(PTC127);
3683 adapter->stats.ptc255 += er32(PTC255);
3684 adapter->stats.ptc511 += er32(PTC511);
3685 adapter->stats.ptc1023 += er32(PTC1023);
3686 adapter->stats.ptc1522 += er32(PTC1522);
3687
3688 adapter->stats.mptc += er32(MPTC);
3689 adapter->stats.bptc += er32(BPTC);
3690
3691
3692
3693 hw->tx_packet_delta = er32(TPT);
3694 adapter->stats.tpt += hw->tx_packet_delta;
3695 hw->collision_delta = er32(COLC);
3696 adapter->stats.colc += hw->collision_delta;
3697
3698 if (hw->mac_type >= e1000_82543) {
3699 adapter->stats.algnerrc += er32(ALGNERRC);
3700 adapter->stats.rxerrc += er32(RXERRC);
3701 adapter->stats.tncrs += er32(TNCRS);
3702 adapter->stats.cexterr += er32(CEXTERR);
3703 adapter->stats.tsctc += er32(TSCTC);
3704 adapter->stats.tsctfc += er32(TSCTFC);
3705 }
3706
3707
3708 netdev->stats.multicast = adapter->stats.mprc;
3709 netdev->stats.collisions = adapter->stats.colc;
3710
3711
3712
3713
3714
3715
3716 netdev->stats.rx_errors = adapter->stats.rxerrc +
3717 adapter->stats.crcerrs + adapter->stats.algnerrc +
3718 adapter->stats.ruc + adapter->stats.roc +
3719 adapter->stats.cexterr;
3720 adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
3721 netdev->stats.rx_length_errors = adapter->stats.rlerrc;
3722 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
3723 netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
3724 netdev->stats.rx_missed_errors = adapter->stats.mpc;
3725
3726
3727 adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
3728 netdev->stats.tx_errors = adapter->stats.txerrc;
3729 netdev->stats.tx_aborted_errors = adapter->stats.ecol;
3730 netdev->stats.tx_window_errors = adapter->stats.latecol;
3731 netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
3732 if (hw->bad_tx_carr_stats_fd &&
3733 adapter->link_duplex == FULL_DUPLEX) {
3734 netdev->stats.tx_carrier_errors = 0;
3735 adapter->stats.tncrs = 0;
3736 }
3737
3738
3739
3740
3741 if (hw->media_type == e1000_media_type_copper) {
3742 if ((adapter->link_speed == SPEED_1000) &&
3743 (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
3744 phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
3745 adapter->phy_stats.idle_errors += phy_tmp;
3746 }
3747
3748 if ((hw->mac_type <= e1000_82546) &&
3749 (hw->phy_type == e1000_phy_m88) &&
3750 !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
3751 adapter->phy_stats.receive_errors += phy_tmp;
3752 }
3753
3754
3755 if (hw->has_smbus) {
3756 adapter->stats.mgptc += er32(MGTPTC);
3757 adapter->stats.mgprc += er32(MGTPRC);
3758 adapter->stats.mgpdc += er32(MGTPDC);
3759 }
3760
3761 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3762}
3763
3764
3765
3766
3767
3768
3769static irqreturn_t e1000_intr(int irq, void *data)
3770{
3771 struct net_device *netdev = data;
3772 struct e1000_adapter *adapter = netdev_priv(netdev);
3773 struct e1000_hw *hw = &adapter->hw;
3774 u32 icr = er32(ICR);
3775
3776 if (unlikely((!icr)))
3777 return IRQ_NONE;
3778
3779
3780
3781
3782
3783 if (unlikely(test_bit(__E1000_DOWN, &adapter->flags)))
3784 return IRQ_HANDLED;
3785
3786 if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
3787 hw->get_link_status = 1;
3788
3789 if (!test_bit(__E1000_DOWN, &adapter->flags))
3790 schedule_delayed_work(&adapter->watchdog_task, 1);
3791 }
3792
3793
3794 ew32(IMC, ~0);
3795 E1000_WRITE_FLUSH();
3796
3797 if (likely(napi_schedule_prep(&adapter->napi))) {
3798 adapter->total_tx_bytes = 0;
3799 adapter->total_tx_packets = 0;
3800 adapter->total_rx_bytes = 0;
3801 adapter->total_rx_packets = 0;
3802 __napi_schedule(&adapter->napi);
3803 } else {
3804
3805
3806
3807 if (!test_bit(__E1000_DOWN, &adapter->flags))
3808 e1000_irq_enable(adapter);
3809 }
3810
3811 return IRQ_HANDLED;
3812}
3813
3814
3815
3816
3817
3818static int e1000_clean(struct napi_struct *napi, int budget)
3819{
3820 struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
3821 napi);
3822 int tx_clean_complete = 0, work_done = 0;
3823
3824 tx_clean_complete = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]);
3825
3826 adapter->clean_rx(adapter, &adapter->rx_ring[0], &work_done, budget);
3827
3828 if (!tx_clean_complete)
3829 work_done = budget;
3830
3831
3832 if (work_done < budget) {
3833 if (likely(adapter->itr_setting & 3))
3834 e1000_set_itr(adapter);
3835 napi_complete_done(napi, work_done);
3836 if (!test_bit(__E1000_DOWN, &adapter->flags))
3837 e1000_irq_enable(adapter);
3838 }
3839
3840 return work_done;
3841}
3842
3843
3844
3845
3846
3847static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3848 struct e1000_tx_ring *tx_ring)
3849{
3850 struct e1000_hw *hw = &adapter->hw;
3851 struct net_device *netdev = adapter->netdev;
3852 struct e1000_tx_desc *tx_desc, *eop_desc;
3853 struct e1000_tx_buffer *buffer_info;
3854 unsigned int i, eop;
3855 unsigned int count = 0;
3856 unsigned int total_tx_bytes = 0, total_tx_packets = 0;
3857 unsigned int bytes_compl = 0, pkts_compl = 0;
3858
3859 i = tx_ring->next_to_clean;
3860 eop = tx_ring->buffer_info[i].next_to_watch;
3861 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3862
3863 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3864 (count < tx_ring->count)) {
3865 bool cleaned = false;
3866 dma_rmb();
3867 for ( ; !cleaned; count++) {
3868 tx_desc = E1000_TX_DESC(*tx_ring, i);
3869 buffer_info = &tx_ring->buffer_info[i];
3870 cleaned = (i == eop);
3871
3872 if (cleaned) {
3873 total_tx_packets += buffer_info->segs;
3874 total_tx_bytes += buffer_info->bytecount;
3875 if (buffer_info->skb) {
3876 bytes_compl += buffer_info->skb->len;
3877 pkts_compl++;
3878 }
3879
3880 }
3881 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3882 tx_desc->upper.data = 0;
3883
3884 if (unlikely(++i == tx_ring->count))
3885 i = 0;
3886 }
3887
3888 eop = tx_ring->buffer_info[i].next_to_watch;
3889 eop_desc = E1000_TX_DESC(*tx_ring, eop);
3890 }
3891
3892
3893
3894
3895 smp_store_release(&tx_ring->next_to_clean, i);
3896
3897 netdev_completed_queue(netdev, pkts_compl, bytes_compl);
3898
3899#define TX_WAKE_THRESHOLD 32
3900 if (unlikely(count && netif_carrier_ok(netdev) &&
3901 E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
3902
3903
3904
3905 smp_mb();
3906
3907 if (netif_queue_stopped(netdev) &&
3908 !(test_bit(__E1000_DOWN, &adapter->flags))) {
3909 netif_wake_queue(netdev);
3910 ++adapter->restart_queue;
3911 }
3912 }
3913
3914 if (adapter->detect_tx_hung) {
3915
3916
3917
3918 adapter->detect_tx_hung = false;
3919 if (tx_ring->buffer_info[eop].time_stamp &&
3920 time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
3921 (adapter->tx_timeout_factor * HZ)) &&
3922 !(er32(STATUS) & E1000_STATUS_TXOFF)) {
3923
3924
3925 e_err(drv, "Detected Tx Unit Hang\n"
3926 " Tx Queue <%lu>\n"
3927 " TDH <%x>\n"
3928 " TDT <%x>\n"
3929 " next_to_use <%x>\n"
3930 " next_to_clean <%x>\n"
3931 "buffer_info[next_to_clean]\n"
3932 " time_stamp <%lx>\n"
3933 " next_to_watch <%x>\n"
3934 " jiffies <%lx>\n"
3935 " next_to_watch.status <%x>\n",
3936 (unsigned long)(tx_ring - adapter->tx_ring),
3937 readl(hw->hw_addr + tx_ring->tdh),
3938 readl(hw->hw_addr + tx_ring->tdt),
3939 tx_ring->next_to_use,
3940 tx_ring->next_to_clean,
3941 tx_ring->buffer_info[eop].time_stamp,
3942 eop,
3943 jiffies,
3944 eop_desc->upper.fields.status);
3945 e1000_dump(adapter);
3946 netif_stop_queue(netdev);
3947 }
3948 }
3949 adapter->total_tx_bytes += total_tx_bytes;
3950 adapter->total_tx_packets += total_tx_packets;
3951 netdev->stats.tx_bytes += total_tx_bytes;
3952 netdev->stats.tx_packets += total_tx_packets;
3953 return count < tx_ring->count;
3954}
3955
3956
3957
3958
3959
3960
3961
3962
3963static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
3964 u32 csum, struct sk_buff *skb)
3965{
3966 struct e1000_hw *hw = &adapter->hw;
3967 u16 status = (u16)status_err;
3968 u8 errors = (u8)(status_err >> 24);
3969
3970 skb_checksum_none_assert(skb);
3971
3972
3973 if (unlikely(hw->mac_type < e1000_82543))
3974 return;
3975
3976 if (unlikely(status & E1000_RXD_STAT_IXSM))
3977 return;
3978
3979 if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
3980
3981 adapter->hw_csum_err++;
3982 return;
3983 }
3984
3985 if (!(status & E1000_RXD_STAT_TCPCS))
3986 return;
3987
3988
3989 if (likely(status & E1000_RXD_STAT_TCPCS)) {
3990
3991 skb->ip_summed = CHECKSUM_UNNECESSARY;
3992 }
3993 adapter->hw_csum_good++;
3994}
3995
3996
3997
3998
3999static void e1000_consume_page(struct e1000_rx_buffer *bi, struct sk_buff *skb,
4000 u16 length)
4001{
4002 bi->rxbuf.page = NULL;
4003 skb->len += length;
4004 skb->data_len += length;
4005 skb->truesize += PAGE_SIZE;
4006}
4007
4008
4009
4010
4011
4012
4013
4014
4015static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status,
4016 __le16 vlan, struct sk_buff *skb)
4017{
4018 skb->protocol = eth_type_trans(skb, adapter->netdev);
4019
4020 if (status & E1000_RXD_STAT_VP) {
4021 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
4022
4023 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
4024 }
4025 napi_gro_receive(&adapter->napi, skb);
4026}
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036static void e1000_tbi_adjust_stats(struct e1000_hw *hw,
4037 struct e1000_hw_stats *stats,
4038 u32 frame_len, const u8 *mac_addr)
4039{
4040 u64 carry_bit;
4041
4042
4043 frame_len--;
4044
4045
4046
4047
4048
4049 stats->crcerrs--;
4050
4051 stats->gprc++;
4052
4053
4054 carry_bit = 0x80000000 & stats->gorcl;
4055 stats->gorcl += frame_len;
4056
4057
4058
4059
4060
4061
4062
4063 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4064 stats->gorch++;
4065
4066
4067
4068
4069 if (is_broadcast_ether_addr(mac_addr))
4070 stats->bprc++;
4071 else if (is_multicast_ether_addr(mac_addr))
4072 stats->mprc++;
4073
4074 if (frame_len == hw->max_frame_size) {
4075
4076
4077
4078 if (stats->roc > 0)
4079 stats->roc--;
4080 }
4081
4082
4083
4084
4085 if (frame_len == 64) {
4086 stats->prc64++;
4087 stats->prc127--;
4088 } else if (frame_len == 127) {
4089 stats->prc127++;
4090 stats->prc255--;
4091 } else if (frame_len == 255) {
4092 stats->prc255++;
4093 stats->prc511--;
4094 } else if (frame_len == 511) {
4095 stats->prc511++;
4096 stats->prc1023--;
4097 } else if (frame_len == 1023) {
4098 stats->prc1023++;
4099 stats->prc1522--;
4100 } else if (frame_len == 1522) {
4101 stats->prc1522++;
4102 }
4103}
4104
4105static bool e1000_tbi_should_accept(struct e1000_adapter *adapter,
4106 u8 status, u8 errors,
4107 u32 length, const u8 *data)
4108{
4109 struct e1000_hw *hw = &adapter->hw;
4110 u8 last_byte = *(data + length - 1);
4111
4112 if (TBI_ACCEPT(hw, status, errors, length, last_byte)) {
4113 unsigned long irq_flags;
4114
4115 spin_lock_irqsave(&adapter->stats_lock, irq_flags);
4116 e1000_tbi_adjust_stats(hw, &adapter->stats, length, data);
4117 spin_unlock_irqrestore(&adapter->stats_lock, irq_flags);
4118
4119 return true;
4120 }
4121
4122 return false;
4123}
4124
4125static struct sk_buff *e1000_alloc_rx_skb(struct e1000_adapter *adapter,
4126 unsigned int bufsz)
4127{
4128 struct sk_buff *skb = napi_alloc_skb(&adapter->napi, bufsz);
4129
4130 if (unlikely(!skb))
4131 adapter->alloc_rx_buff_failed++;
4132 return skb;
4133}
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
4146 struct e1000_rx_ring *rx_ring,
4147 int *work_done, int work_to_do)
4148{
4149 struct net_device *netdev = adapter->netdev;
4150 struct pci_dev *pdev = adapter->pdev;
4151 struct e1000_rx_desc *rx_desc, *next_rxd;
4152 struct e1000_rx_buffer *buffer_info, *next_buffer;
4153 u32 length;
4154 unsigned int i;
4155 int cleaned_count = 0;
4156 bool cleaned = false;
4157 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
4158
4159 i = rx_ring->next_to_clean;
4160 rx_desc = E1000_RX_DESC(*rx_ring, i);
4161 buffer_info = &rx_ring->buffer_info[i];
4162
4163 while (rx_desc->status & E1000_RXD_STAT_DD) {
4164 struct sk_buff *skb;
4165 u8 status;
4166
4167 if (*work_done >= work_to_do)
4168 break;
4169 (*work_done)++;
4170 dma_rmb();
4171
4172 status = rx_desc->status;
4173
4174 if (++i == rx_ring->count)
4175 i = 0;
4176
4177 next_rxd = E1000_RX_DESC(*rx_ring, i);
4178 prefetch(next_rxd);
4179
4180 next_buffer = &rx_ring->buffer_info[i];
4181
4182 cleaned = true;
4183 cleaned_count++;
4184 dma_unmap_page(&pdev->dev, buffer_info->dma,
4185 adapter->rx_buffer_len, DMA_FROM_DEVICE);
4186 buffer_info->dma = 0;
4187
4188 length = le16_to_cpu(rx_desc->length);
4189
4190
4191 if (unlikely((status & E1000_RXD_STAT_EOP) &&
4192 (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) {
4193 u8 *mapped = page_address(buffer_info->rxbuf.page);
4194
4195 if (e1000_tbi_should_accept(adapter, status,
4196 rx_desc->errors,
4197 length, mapped)) {
4198 length--;
4199 } else if (netdev->features & NETIF_F_RXALL) {
4200 goto process_skb;
4201 } else {
4202
4203
4204
4205 if (rx_ring->rx_skb_top)
4206 dev_kfree_skb(rx_ring->rx_skb_top);
4207 rx_ring->rx_skb_top = NULL;
4208 goto next_desc;
4209 }
4210 }
4211
4212#define rxtop rx_ring->rx_skb_top
4213process_skb:
4214 if (!(status & E1000_RXD_STAT_EOP)) {
4215
4216 if (!rxtop) {
4217
4218 rxtop = napi_get_frags(&adapter->napi);
4219 if (!rxtop)
4220 break;
4221
4222 skb_fill_page_desc(rxtop, 0,
4223 buffer_info->rxbuf.page,
4224 0, length);
4225 } else {
4226
4227 skb_fill_page_desc(rxtop,
4228 skb_shinfo(rxtop)->nr_frags,
4229 buffer_info->rxbuf.page, 0, length);
4230 }
4231 e1000_consume_page(buffer_info, rxtop, length);
4232 goto next_desc;
4233 } else {
4234 if (rxtop) {
4235
4236 skb_fill_page_desc(rxtop,
4237 skb_shinfo(rxtop)->nr_frags,
4238 buffer_info->rxbuf.page, 0, length);
4239 skb = rxtop;
4240 rxtop = NULL;
4241 e1000_consume_page(buffer_info, skb, length);
4242 } else {
4243 struct page *p;
4244
4245
4246
4247 p = buffer_info->rxbuf.page;
4248 if (length <= copybreak) {
4249 u8 *vaddr;
4250
4251 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4252 length -= 4;
4253 skb = e1000_alloc_rx_skb(adapter,
4254 length);
4255 if (!skb)
4256 break;
4257
4258 vaddr = kmap_atomic(p);
4259 memcpy(skb_tail_pointer(skb), vaddr,
4260 length);
4261 kunmap_atomic(vaddr);
4262
4263
4264
4265 skb_put(skb, length);
4266 e1000_rx_checksum(adapter,
4267 status | rx_desc->errors << 24,
4268 le16_to_cpu(rx_desc->csum), skb);
4269
4270 total_rx_bytes += skb->len;
4271 total_rx_packets++;
4272
4273 e1000_receive_skb(adapter, status,
4274 rx_desc->special, skb);
4275 goto next_desc;
4276 } else {
4277 skb = napi_get_frags(&adapter->napi);
4278 if (!skb) {
4279 adapter->alloc_rx_buff_failed++;
4280 break;
4281 }
4282 skb_fill_page_desc(skb, 0, p, 0,
4283 length);
4284 e1000_consume_page(buffer_info, skb,
4285 length);
4286 }
4287 }
4288 }
4289
4290
4291 e1000_rx_checksum(adapter,
4292 (u32)(status) |
4293 ((u32)(rx_desc->errors) << 24),
4294 le16_to_cpu(rx_desc->csum), skb);
4295
4296 total_rx_bytes += (skb->len - 4);
4297 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4298 pskb_trim(skb, skb->len - 4);
4299 total_rx_packets++;
4300
4301 if (status & E1000_RXD_STAT_VP) {
4302 __le16 vlan = rx_desc->special;
4303 u16 vid = le16_to_cpu(vlan) & E1000_RXD_SPC_VLAN_MASK;
4304
4305 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
4306 }
4307
4308 napi_gro_frags(&adapter->napi);
4309
4310next_desc:
4311 rx_desc->status = 0;
4312
4313
4314 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4315 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4316 cleaned_count = 0;
4317 }
4318
4319
4320 rx_desc = next_rxd;
4321 buffer_info = next_buffer;
4322 }
4323 rx_ring->next_to_clean = i;
4324
4325 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4326 if (cleaned_count)
4327 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4328
4329 adapter->total_rx_packets += total_rx_packets;
4330 adapter->total_rx_bytes += total_rx_bytes;
4331 netdev->stats.rx_bytes += total_rx_bytes;
4332 netdev->stats.rx_packets += total_rx_packets;
4333 return cleaned;
4334}
4335
4336
4337
4338
4339static struct sk_buff *e1000_copybreak(struct e1000_adapter *adapter,
4340 struct e1000_rx_buffer *buffer_info,
4341 u32 length, const void *data)
4342{
4343 struct sk_buff *skb;
4344
4345 if (length > copybreak)
4346 return NULL;
4347
4348 skb = e1000_alloc_rx_skb(adapter, length);
4349 if (!skb)
4350 return NULL;
4351
4352 dma_sync_single_for_cpu(&adapter->pdev->dev, buffer_info->dma,
4353 length, DMA_FROM_DEVICE);
4354
4355 skb_put_data(skb, data, length);
4356
4357 return skb;
4358}
4359
4360
4361
4362
4363
4364
4365
4366
4367static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
4368 struct e1000_rx_ring *rx_ring,
4369 int *work_done, int work_to_do)
4370{
4371 struct net_device *netdev = adapter->netdev;
4372 struct pci_dev *pdev = adapter->pdev;
4373 struct e1000_rx_desc *rx_desc, *next_rxd;
4374 struct e1000_rx_buffer *buffer_info, *next_buffer;
4375 u32 length;
4376 unsigned int i;
4377 int cleaned_count = 0;
4378 bool cleaned = false;
4379 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
4380
4381 i = rx_ring->next_to_clean;
4382 rx_desc = E1000_RX_DESC(*rx_ring, i);
4383 buffer_info = &rx_ring->buffer_info[i];
4384
4385 while (rx_desc->status & E1000_RXD_STAT_DD) {
4386 struct sk_buff *skb;
4387 u8 *data;
4388 u8 status;
4389
4390 if (*work_done >= work_to_do)
4391 break;
4392 (*work_done)++;
4393 dma_rmb();
4394
4395 status = rx_desc->status;
4396 length = le16_to_cpu(rx_desc->length);
4397
4398 data = buffer_info->rxbuf.data;
4399 prefetch(data);
4400 skb = e1000_copybreak(adapter, buffer_info, length, data);
4401 if (!skb) {
4402 unsigned int frag_len = e1000_frag_len(adapter);
4403
4404 skb = build_skb(data - E1000_HEADROOM, frag_len);
4405 if (!skb) {
4406 adapter->alloc_rx_buff_failed++;
4407 break;
4408 }
4409
4410 skb_reserve(skb, E1000_HEADROOM);
4411 dma_unmap_single(&pdev->dev, buffer_info->dma,
4412 adapter->rx_buffer_len,
4413 DMA_FROM_DEVICE);
4414 buffer_info->dma = 0;
4415 buffer_info->rxbuf.data = NULL;
4416 }
4417
4418 if (++i == rx_ring->count)
4419 i = 0;
4420
4421 next_rxd = E1000_RX_DESC(*rx_ring, i);
4422 prefetch(next_rxd);
4423
4424 next_buffer = &rx_ring->buffer_info[i];
4425
4426 cleaned = true;
4427 cleaned_count++;
4428
4429
4430
4431
4432
4433
4434
4435 if (unlikely(!(status & E1000_RXD_STAT_EOP)))
4436 adapter->discarding = true;
4437
4438 if (adapter->discarding) {
4439
4440 netdev_dbg(netdev, "Receive packet consumed multiple buffers\n");
4441 dev_kfree_skb(skb);
4442 if (status & E1000_RXD_STAT_EOP)
4443 adapter->discarding = false;
4444 goto next_desc;
4445 }
4446
4447 if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
4448 if (e1000_tbi_should_accept(adapter, status,
4449 rx_desc->errors,
4450 length, data)) {
4451 length--;
4452 } else if (netdev->features & NETIF_F_RXALL) {
4453 goto process_skb;
4454 } else {
4455 dev_kfree_skb(skb);
4456 goto next_desc;
4457 }
4458 }
4459
4460process_skb:
4461 total_rx_bytes += (length - 4);
4462 total_rx_packets++;
4463
4464 if (likely(!(netdev->features & NETIF_F_RXFCS)))
4465
4466
4467
4468 length -= 4;
4469
4470 if (buffer_info->rxbuf.data == NULL)
4471 skb_put(skb, length);
4472 else
4473 skb_trim(skb, length);
4474
4475
4476 e1000_rx_checksum(adapter,
4477 (u32)(status) |
4478 ((u32)(rx_desc->errors) << 24),
4479 le16_to_cpu(rx_desc->csum), skb);
4480
4481 e1000_receive_skb(adapter, status, rx_desc->special, skb);
4482
4483next_desc:
4484 rx_desc->status = 0;
4485
4486
4487 if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
4488 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4489 cleaned_count = 0;
4490 }
4491
4492
4493 rx_desc = next_rxd;
4494 buffer_info = next_buffer;
4495 }
4496 rx_ring->next_to_clean = i;
4497
4498 cleaned_count = E1000_DESC_UNUSED(rx_ring);
4499 if (cleaned_count)
4500 adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
4501
4502 adapter->total_rx_packets += total_rx_packets;
4503 adapter->total_rx_bytes += total_rx_bytes;
4504 netdev->stats.rx_bytes += total_rx_bytes;
4505 netdev->stats.rx_packets += total_rx_packets;
4506 return cleaned;
4507}
4508
4509
4510
4511
4512
4513
4514
4515static void
4516e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter,
4517 struct e1000_rx_ring *rx_ring, int cleaned_count)
4518{
4519 struct pci_dev *pdev = adapter->pdev;
4520 struct e1000_rx_desc *rx_desc;
4521 struct e1000_rx_buffer *buffer_info;
4522 unsigned int i;
4523
4524 i = rx_ring->next_to_use;
4525 buffer_info = &rx_ring->buffer_info[i];
4526
4527 while (cleaned_count--) {
4528
4529 if (!buffer_info->rxbuf.page) {
4530 buffer_info->rxbuf.page = alloc_page(GFP_ATOMIC);
4531 if (unlikely(!buffer_info->rxbuf.page)) {
4532 adapter->alloc_rx_buff_failed++;
4533 break;
4534 }
4535 }
4536
4537 if (!buffer_info->dma) {
4538 buffer_info->dma = dma_map_page(&pdev->dev,
4539 buffer_info->rxbuf.page, 0,
4540 adapter->rx_buffer_len,
4541 DMA_FROM_DEVICE);
4542 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4543 put_page(buffer_info->rxbuf.page);
4544 buffer_info->rxbuf.page = NULL;
4545 buffer_info->dma = 0;
4546 adapter->alloc_rx_buff_failed++;
4547 break;
4548 }
4549 }
4550
4551 rx_desc = E1000_RX_DESC(*rx_ring, i);
4552 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4553
4554 if (unlikely(++i == rx_ring->count))
4555 i = 0;
4556 buffer_info = &rx_ring->buffer_info[i];
4557 }
4558
4559 if (likely(rx_ring->next_to_use != i)) {
4560 rx_ring->next_to_use = i;
4561 if (unlikely(i-- == 0))
4562 i = (rx_ring->count - 1);
4563
4564
4565
4566
4567
4568
4569 wmb();
4570 writel(i, adapter->hw.hw_addr + rx_ring->rdt);
4571 }
4572}
4573
4574
4575
4576
4577
4578static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
4579 struct e1000_rx_ring *rx_ring,
4580 int cleaned_count)
4581{
4582 struct e1000_hw *hw = &adapter->hw;
4583 struct pci_dev *pdev = adapter->pdev;
4584 struct e1000_rx_desc *rx_desc;
4585 struct e1000_rx_buffer *buffer_info;
4586 unsigned int i;
4587 unsigned int bufsz = adapter->rx_buffer_len;
4588
4589 i = rx_ring->next_to_use;
4590 buffer_info = &rx_ring->buffer_info[i];
4591
4592 while (cleaned_count--) {
4593 void *data;
4594
4595 if (buffer_info->rxbuf.data)
4596 goto skip;
4597
4598 data = e1000_alloc_frag(adapter);
4599 if (!data) {
4600
4601 adapter->alloc_rx_buff_failed++;
4602 break;
4603 }
4604
4605
4606 if (!e1000_check_64k_bound(adapter, data, bufsz)) {
4607 void *olddata = data;
4608 e_err(rx_err, "skb align check failed: %u bytes at "
4609 "%p\n", bufsz, data);
4610
4611 data = e1000_alloc_frag(adapter);
4612
4613 if (!data) {
4614 skb_free_frag(olddata);
4615 adapter->alloc_rx_buff_failed++;
4616 break;
4617 }
4618
4619 if (!e1000_check_64k_bound(adapter, data, bufsz)) {
4620
4621 skb_free_frag(data);
4622 skb_free_frag(olddata);
4623 adapter->alloc_rx_buff_failed++;
4624 break;
4625 }
4626
4627
4628 skb_free_frag(olddata);
4629 }
4630 buffer_info->dma = dma_map_single(&pdev->dev,
4631 data,
4632 adapter->rx_buffer_len,
4633 DMA_FROM_DEVICE);
4634 if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
4635 skb_free_frag(data);
4636 buffer_info->dma = 0;
4637 adapter->alloc_rx_buff_failed++;
4638 break;
4639 }
4640
4641
4642
4643
4644
4645
4646 if (!e1000_check_64k_bound(adapter,
4647 (void *)(unsigned long)buffer_info->dma,
4648 adapter->rx_buffer_len)) {
4649 e_err(rx_err, "dma align check failed: %u bytes at "
4650 "%p\n", adapter->rx_buffer_len,
4651 (void *)(unsigned long)buffer_info->dma);
4652
4653 dma_unmap_single(&pdev->dev, buffer_info->dma,
4654 adapter->rx_buffer_len,
4655 DMA_FROM_DEVICE);
4656
4657 skb_free_frag(data);
4658 buffer_info->rxbuf.data = NULL;
4659 buffer_info->dma = 0;
4660
4661 adapter->alloc_rx_buff_failed++;
4662 break;
4663 }
4664 buffer_info->rxbuf.data = data;
4665 skip:
4666 rx_desc = E1000_RX_DESC(*rx_ring, i);
4667 rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
4668
4669 if (unlikely(++i == rx_ring->count))
4670 i = 0;
4671 buffer_info = &rx_ring->buffer_info[i];
4672 }
4673
4674 if (likely(rx_ring->next_to_use != i)) {
4675 rx_ring->next_to_use = i;
4676 if (unlikely(i-- == 0))
4677 i = (rx_ring->count - 1);
4678
4679
4680
4681
4682
4683
4684 wmb();
4685 writel(i, hw->hw_addr + rx_ring->rdt);
4686 }
4687}
4688
4689
4690
4691
4692
4693static void e1000_smartspeed(struct e1000_adapter *adapter)
4694{
4695 struct e1000_hw *hw = &adapter->hw;
4696 u16 phy_status;
4697 u16 phy_ctrl;
4698
4699 if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg ||
4700 !(hw->autoneg_advertised & ADVERTISE_1000_FULL))
4701 return;
4702
4703 if (adapter->smartspeed == 0) {
4704
4705
4706
4707 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4708 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
4709 return;
4710 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status);
4711 if (!(phy_status & SR_1000T_MS_CONFIG_FAULT))
4712 return;
4713 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4714 if (phy_ctrl & CR_1000T_MS_ENABLE) {
4715 phy_ctrl &= ~CR_1000T_MS_ENABLE;
4716 e1000_write_phy_reg(hw, PHY_1000T_CTRL,
4717 phy_ctrl);
4718 adapter->smartspeed++;
4719 if (!e1000_phy_setup_autoneg(hw) &&
4720 !e1000_read_phy_reg(hw, PHY_CTRL,
4721 &phy_ctrl)) {
4722 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4723 MII_CR_RESTART_AUTO_NEG);
4724 e1000_write_phy_reg(hw, PHY_CTRL,
4725 phy_ctrl);
4726 }
4727 }
4728 return;
4729 } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
4730
4731 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl);
4732 phy_ctrl |= CR_1000T_MS_ENABLE;
4733 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl);
4734 if (!e1000_phy_setup_autoneg(hw) &&
4735 !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) {
4736 phy_ctrl |= (MII_CR_AUTO_NEG_EN |
4737 MII_CR_RESTART_AUTO_NEG);
4738 e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl);
4739 }
4740 }
4741
4742 if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
4743 adapter->smartspeed = 0;
4744}
4745
4746
4747
4748
4749
4750
4751
4752static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
4753{
4754 switch (cmd) {
4755 case SIOCGMIIPHY:
4756 case SIOCGMIIREG:
4757 case SIOCSMIIREG:
4758 return e1000_mii_ioctl(netdev, ifr, cmd);
4759 default:
4760 return -EOPNOTSUPP;
4761 }
4762}
4763
4764
4765
4766
4767
4768
4769
4770static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
4771 int cmd)
4772{
4773 struct e1000_adapter *adapter = netdev_priv(netdev);
4774 struct e1000_hw *hw = &adapter->hw;
4775 struct mii_ioctl_data *data = if_mii(ifr);
4776 int retval;
4777 u16 mii_reg;
4778 unsigned long flags;
4779
4780 if (hw->media_type != e1000_media_type_copper)
4781 return -EOPNOTSUPP;
4782
4783 switch (cmd) {
4784 case SIOCGMIIPHY:
4785 data->phy_id = hw->phy_addr;
4786 break;
4787 case SIOCGMIIREG:
4788 spin_lock_irqsave(&adapter->stats_lock, flags);
4789 if (e1000_read_phy_reg(hw, data->reg_num & 0x1F,
4790 &data->val_out)) {
4791 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4792 return -EIO;
4793 }
4794 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4795 break;
4796 case SIOCSMIIREG:
4797 if (data->reg_num & ~(0x1F))
4798 return -EFAULT;
4799 mii_reg = data->val_in;
4800 spin_lock_irqsave(&adapter->stats_lock, flags);
4801 if (e1000_write_phy_reg(hw, data->reg_num,
4802 mii_reg)) {
4803 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4804 return -EIO;
4805 }
4806 spin_unlock_irqrestore(&adapter->stats_lock, flags);
4807 if (hw->media_type == e1000_media_type_copper) {
4808 switch (data->reg_num) {
4809 case PHY_CTRL:
4810 if (mii_reg & MII_CR_POWER_DOWN)
4811 break;
4812 if (mii_reg & MII_CR_AUTO_NEG_EN) {
4813 hw->autoneg = 1;
4814 hw->autoneg_advertised = 0x2F;
4815 } else {
4816 u32 speed;
4817 if (mii_reg & 0x40)
4818 speed = SPEED_1000;
4819 else if (mii_reg & 0x2000)
4820 speed = SPEED_100;
4821 else
4822 speed = SPEED_10;
4823 retval = e1000_set_spd_dplx(
4824 adapter, speed,
4825 ((mii_reg & 0x100)
4826 ? DUPLEX_FULL :
4827 DUPLEX_HALF));
4828 if (retval)
4829 return retval;
4830 }
4831 if (netif_running(adapter->netdev))
4832 e1000_reinit_locked(adapter);
4833 else
4834 e1000_reset(adapter);
4835 break;
4836 case M88E1000_PHY_SPEC_CTRL:
4837 case M88E1000_EXT_PHY_SPEC_CTRL:
4838 if (e1000_phy_reset(hw))
4839 return -EIO;
4840 break;
4841 }
4842 } else {
4843 switch (data->reg_num) {
4844 case PHY_CTRL:
4845 if (mii_reg & MII_CR_POWER_DOWN)
4846 break;
4847 if (netif_running(adapter->netdev))
4848 e1000_reinit_locked(adapter);
4849 else
4850 e1000_reset(adapter);
4851 break;
4852 }
4853 }
4854 break;
4855 default:
4856 return -EOPNOTSUPP;
4857 }
4858 return E1000_SUCCESS;
4859}
4860
4861void e1000_pci_set_mwi(struct e1000_hw *hw)
4862{
4863 struct e1000_adapter *adapter = hw->back;
4864 int ret_val = pci_set_mwi(adapter->pdev);
4865
4866 if (ret_val)
4867 e_err(probe, "Error in setting MWI\n");
4868}
4869
4870void e1000_pci_clear_mwi(struct e1000_hw *hw)
4871{
4872 struct e1000_adapter *adapter = hw->back;
4873
4874 pci_clear_mwi(adapter->pdev);
4875}
4876
4877int e1000_pcix_get_mmrbc(struct e1000_hw *hw)
4878{
4879 struct e1000_adapter *adapter = hw->back;
4880 return pcix_get_mmrbc(adapter->pdev);
4881}
4882
4883void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
4884{
4885 struct e1000_adapter *adapter = hw->back;
4886 pcix_set_mmrbc(adapter->pdev, mmrbc);
4887}
4888
4889void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value)
4890{
4891 outl(value, port);
4892}
4893
4894static bool e1000_vlan_used(struct e1000_adapter *adapter)
4895{
4896 u16 vid;
4897
4898 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
4899 return true;
4900 return false;
4901}
4902
4903static void __e1000_vlan_mode(struct e1000_adapter *adapter,
4904 netdev_features_t features)
4905{
4906 struct e1000_hw *hw = &adapter->hw;
4907 u32 ctrl;
4908
4909 ctrl = er32(CTRL);
4910 if (features & NETIF_F_HW_VLAN_CTAG_RX) {
4911
4912 ctrl |= E1000_CTRL_VME;
4913 } else {
4914
4915 ctrl &= ~E1000_CTRL_VME;
4916 }
4917 ew32(CTRL, ctrl);
4918}
4919static void e1000_vlan_filter_on_off(struct e1000_adapter *adapter,
4920 bool filter_on)
4921{
4922 struct e1000_hw *hw = &adapter->hw;
4923 u32 rctl;
4924
4925 if (!test_bit(__E1000_DOWN, &adapter->flags))
4926 e1000_irq_disable(adapter);
4927
4928 __e1000_vlan_mode(adapter, adapter->netdev->features);
4929 if (filter_on) {
4930
4931 rctl = er32(RCTL);
4932 rctl &= ~E1000_RCTL_CFIEN;
4933 if (!(adapter->netdev->flags & IFF_PROMISC))
4934 rctl |= E1000_RCTL_VFE;
4935 ew32(RCTL, rctl);
4936 e1000_update_mng_vlan(adapter);
4937 } else {
4938
4939 rctl = er32(RCTL);
4940 rctl &= ~E1000_RCTL_VFE;
4941 ew32(RCTL, rctl);
4942 }
4943
4944 if (!test_bit(__E1000_DOWN, &adapter->flags))
4945 e1000_irq_enable(adapter);
4946}
4947
4948static void e1000_vlan_mode(struct net_device *netdev,
4949 netdev_features_t features)
4950{
4951 struct e1000_adapter *adapter = netdev_priv(netdev);
4952
4953 if (!test_bit(__E1000_DOWN, &adapter->flags))
4954 e1000_irq_disable(adapter);
4955
4956 __e1000_vlan_mode(adapter, features);
4957
4958 if (!test_bit(__E1000_DOWN, &adapter->flags))
4959 e1000_irq_enable(adapter);
4960}
4961
4962static int e1000_vlan_rx_add_vid(struct net_device *netdev,
4963 __be16 proto, u16 vid)
4964{
4965 struct e1000_adapter *adapter = netdev_priv(netdev);
4966 struct e1000_hw *hw = &adapter->hw;
4967 u32 vfta, index;
4968
4969 if ((hw->mng_cookie.status &
4970 E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
4971 (vid == adapter->mng_vlan_id))
4972 return 0;
4973
4974 if (!e1000_vlan_used(adapter))
4975 e1000_vlan_filter_on_off(adapter, true);
4976
4977
4978 index = (vid >> 5) & 0x7F;
4979 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
4980 vfta |= (1 << (vid & 0x1F));
4981 e1000_write_vfta(hw, index, vfta);
4982
4983 set_bit(vid, adapter->active_vlans);
4984
4985 return 0;
4986}
4987
4988static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
4989 __be16 proto, u16 vid)
4990{
4991 struct e1000_adapter *adapter = netdev_priv(netdev);
4992 struct e1000_hw *hw = &adapter->hw;
4993 u32 vfta, index;
4994
4995 if (!test_bit(__E1000_DOWN, &adapter->flags))
4996 e1000_irq_disable(adapter);
4997 if (!test_bit(__E1000_DOWN, &adapter->flags))
4998 e1000_irq_enable(adapter);
4999
5000
5001 index = (vid >> 5) & 0x7F;
5002 vfta = E1000_READ_REG_ARRAY(hw, VFTA, index);
5003 vfta &= ~(1 << (vid & 0x1F));
5004 e1000_write_vfta(hw, index, vfta);
5005
5006 clear_bit(vid, adapter->active_vlans);
5007
5008 if (!e1000_vlan_used(adapter))
5009 e1000_vlan_filter_on_off(adapter, false);
5010
5011 return 0;
5012}
5013
5014static void e1000_restore_vlan(struct e1000_adapter *adapter)
5015{
5016 u16 vid;
5017
5018 if (!e1000_vlan_used(adapter))
5019 return;
5020
5021 e1000_vlan_filter_on_off(adapter, true);
5022 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
5023 e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
5024}
5025
5026int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
5027{
5028 struct e1000_hw *hw = &adapter->hw;
5029
5030 hw->autoneg = 0;
5031
5032
5033
5034
5035 if ((spd & 1) || (dplx & ~1))
5036 goto err_inval;
5037
5038
5039 if ((hw->media_type == e1000_media_type_fiber) &&
5040 spd != SPEED_1000 &&
5041 dplx != DUPLEX_FULL)
5042 goto err_inval;
5043
5044 switch (spd + dplx) {
5045 case SPEED_10 + DUPLEX_HALF:
5046 hw->forced_speed_duplex = e1000_10_half;
5047 break;
5048 case SPEED_10 + DUPLEX_FULL:
5049 hw->forced_speed_duplex = e1000_10_full;
5050 break;
5051 case SPEED_100 + DUPLEX_HALF:
5052 hw->forced_speed_duplex = e1000_100_half;
5053 break;
5054 case SPEED_100 + DUPLEX_FULL:
5055 hw->forced_speed_duplex = e1000_100_full;
5056 break;
5057 case SPEED_1000 + DUPLEX_FULL:
5058 hw->autoneg = 1;
5059 hw->autoneg_advertised = ADVERTISE_1000_FULL;
5060 break;
5061 case SPEED_1000 + DUPLEX_HALF:
5062 default:
5063 goto err_inval;
5064 }
5065
5066
5067 hw->mdix = AUTO_ALL_MODES;
5068
5069 return 0;
5070
5071err_inval:
5072 e_err(probe, "Unsupported Speed/Duplex configuration\n");
5073 return -EINVAL;
5074}
5075
5076static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake)
5077{
5078 struct net_device *netdev = pci_get_drvdata(pdev);
5079 struct e1000_adapter *adapter = netdev_priv(netdev);
5080 struct e1000_hw *hw = &adapter->hw;
5081 u32 ctrl, ctrl_ext, rctl, status;
5082 u32 wufc = adapter->wol;
5083#ifdef CONFIG_PM
5084 int retval = 0;
5085#endif
5086
5087 netif_device_detach(netdev);
5088
5089 if (netif_running(netdev)) {
5090 int count = E1000_CHECK_RESET_COUNT;
5091
5092 while (test_bit(__E1000_RESETTING, &adapter->flags) && count--)
5093 usleep_range(10000, 20000);
5094
5095 WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
5096 e1000_down(adapter);
5097 }
5098
5099#ifdef CONFIG_PM
5100 retval = pci_save_state(pdev);
5101 if (retval)
5102 return retval;
5103#endif
5104
5105 status = er32(STATUS);
5106 if (status & E1000_STATUS_LU)
5107 wufc &= ~E1000_WUFC_LNKC;
5108
5109 if (wufc) {
5110 e1000_setup_rctl(adapter);
5111 e1000_set_rx_mode(netdev);
5112
5113 rctl = er32(RCTL);
5114
5115
5116 if (wufc & E1000_WUFC_MC)
5117 rctl |= E1000_RCTL_MPE;
5118
5119
5120 ew32(RCTL, rctl | E1000_RCTL_EN);
5121
5122 if (hw->mac_type >= e1000_82540) {
5123 ctrl = er32(CTRL);
5124
5125 #define E1000_CTRL_ADVD3WUC 0x00100000
5126
5127 #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
5128 ctrl |= E1000_CTRL_ADVD3WUC |
5129 E1000_CTRL_EN_PHY_PWR_MGMT;
5130 ew32(CTRL, ctrl);
5131 }
5132
5133 if (hw->media_type == e1000_media_type_fiber ||
5134 hw->media_type == e1000_media_type_internal_serdes) {
5135
5136 ctrl_ext = er32(CTRL_EXT);
5137 ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
5138 ew32(CTRL_EXT, ctrl_ext);
5139 }
5140
5141 ew32(WUC, E1000_WUC_PME_EN);
5142 ew32(WUFC, wufc);
5143 } else {
5144 ew32(WUC, 0);
5145 ew32(WUFC, 0);
5146 }
5147
5148 e1000_release_manageability(adapter);
5149
5150 *enable_wake = !!wufc;
5151
5152
5153 if (adapter->en_mng_pt)
5154 *enable_wake = true;
5155
5156 if (netif_running(netdev))
5157 e1000_free_irq(adapter);
5158
5159 pci_disable_device(pdev);
5160
5161 return 0;
5162}
5163
5164#ifdef CONFIG_PM
5165static int e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5166{
5167 int retval;
5168 bool wake;
5169
5170 retval = __e1000_shutdown(pdev, &wake);
5171 if (retval)
5172 return retval;
5173
5174 if (wake) {
5175 pci_prepare_to_sleep(pdev);
5176 } else {
5177 pci_wake_from_d3(pdev, false);
5178 pci_set_power_state(pdev, PCI_D3hot);
5179 }
5180
5181 return 0;
5182}
5183
5184static int e1000_resume(struct pci_dev *pdev)
5185{
5186 struct net_device *netdev = pci_get_drvdata(pdev);
5187 struct e1000_adapter *adapter = netdev_priv(netdev);
5188 struct e1000_hw *hw = &adapter->hw;
5189 u32 err;
5190
5191 pci_set_power_state(pdev, PCI_D0);
5192 pci_restore_state(pdev);
5193 pci_save_state(pdev);
5194
5195 if (adapter->need_ioport)
5196 err = pci_enable_device(pdev);
5197 else
5198 err = pci_enable_device_mem(pdev);
5199 if (err) {
5200 pr_err("Cannot enable PCI device from suspend\n");
5201 return err;
5202 }
5203 pci_set_master(pdev);
5204
5205 pci_enable_wake(pdev, PCI_D3hot, 0);
5206 pci_enable_wake(pdev, PCI_D3cold, 0);
5207
5208 if (netif_running(netdev)) {
5209 err = e1000_request_irq(adapter);
5210 if (err)
5211 return err;
5212 }
5213
5214 e1000_power_up_phy(adapter);
5215 e1000_reset(adapter);
5216 ew32(WUS, ~0);
5217
5218 e1000_init_manageability(adapter);
5219
5220 if (netif_running(netdev))
5221 e1000_up(adapter);
5222
5223 netif_device_attach(netdev);
5224
5225 return 0;
5226}
5227#endif
5228
5229static void e1000_shutdown(struct pci_dev *pdev)
5230{
5231 bool wake;
5232
5233 __e1000_shutdown(pdev, &wake);
5234
5235 if (system_state == SYSTEM_POWER_OFF) {
5236 pci_wake_from_d3(pdev, wake);
5237 pci_set_power_state(pdev, PCI_D3hot);
5238 }
5239}
5240
5241#ifdef CONFIG_NET_POLL_CONTROLLER
5242
5243
5244
5245
5246static void e1000_netpoll(struct net_device *netdev)
5247{
5248 struct e1000_adapter *adapter = netdev_priv(netdev);
5249
5250 if (disable_hardirq(adapter->pdev->irq))
5251 e1000_intr(adapter->pdev->irq, netdev);
5252 enable_irq(adapter->pdev->irq);
5253}
5254#endif
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
5265 pci_channel_state_t state)
5266{
5267 struct net_device *netdev = pci_get_drvdata(pdev);
5268 struct e1000_adapter *adapter = netdev_priv(netdev);
5269
5270 netif_device_detach(netdev);
5271
5272 if (state == pci_channel_io_perm_failure)
5273 return PCI_ERS_RESULT_DISCONNECT;
5274
5275 if (netif_running(netdev))
5276 e1000_down(adapter);
5277 pci_disable_device(pdev);
5278
5279
5280 return PCI_ERS_RESULT_NEED_RESET;
5281}
5282
5283
5284
5285
5286
5287
5288
5289
5290static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
5291{
5292 struct net_device *netdev = pci_get_drvdata(pdev);
5293 struct e1000_adapter *adapter = netdev_priv(netdev);
5294 struct e1000_hw *hw = &adapter->hw;
5295 int err;
5296
5297 if (adapter->need_ioport)
5298 err = pci_enable_device(pdev);
5299 else
5300 err = pci_enable_device_mem(pdev);
5301 if (err) {
5302 pr_err("Cannot re-enable PCI device after reset.\n");
5303 return PCI_ERS_RESULT_DISCONNECT;
5304 }
5305 pci_set_master(pdev);
5306
5307 pci_enable_wake(pdev, PCI_D3hot, 0);
5308 pci_enable_wake(pdev, PCI_D3cold, 0);
5309
5310 e1000_reset(adapter);
5311 ew32(WUS, ~0);
5312
5313 return PCI_ERS_RESULT_RECOVERED;
5314}
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324static void e1000_io_resume(struct pci_dev *pdev)
5325{
5326 struct net_device *netdev = pci_get_drvdata(pdev);
5327 struct e1000_adapter *adapter = netdev_priv(netdev);
5328
5329 e1000_init_manageability(adapter);
5330
5331 if (netif_running(netdev)) {
5332 if (e1000_up(adapter)) {
5333 pr_info("can't bring device back up after reset\n");
5334 return;
5335 }
5336 }
5337
5338 netif_device_attach(netdev);
5339}
5340
5341
5342