Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | Intel PRO/1000 Linux driver |
| 4 | Copyright(c) 1999 - 2006 Intel Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include "e1000.h" |
Andrew Morton | d0bb53e | 2006-11-14 10:35:03 -0500 | [diff] [blame] | 30 | #include <net/ip6_checksum.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | char e1000_driver_name[] = "e1000"; |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 33 | static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #ifndef CONFIG_E1000_NAPI |
| 35 | #define DRIVERNAPI |
| 36 | #else |
| 37 | #define DRIVERNAPI "-NAPI" |
| 38 | #endif |
Auke Kok | 25006ac | 2006-11-01 08:48:15 -0800 | [diff] [blame] | 39 | #define DRV_VERSION "7.3.15-k2"DRIVERNAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | char e1000_driver_version[] = DRV_VERSION; |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 41 | static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* e1000_pci_tbl - PCI Device ID Table |
| 44 | * |
| 45 | * Last entry must be all 0s |
| 46 | * |
| 47 | * Macro expands to... |
| 48 | * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} |
| 49 | */ |
| 50 | static struct pci_device_id e1000_pci_tbl[] = { |
| 51 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 52 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 53 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 54 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 55 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 56 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 57 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 58 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 59 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 60 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 61 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 62 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 63 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 64 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 65 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 66 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 67 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 68 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 69 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 70 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 72 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 73 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 74 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 75 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
Auke Kok | ae2c386 | 2006-06-27 09:08:30 -0700 | [diff] [blame] | 76 | INTEL_E1000_ETHERNET_DEVICE(0x1049), |
| 77 | INTEL_E1000_ETHERNET_DEVICE(0x104A), |
| 78 | INTEL_E1000_ETHERNET_DEVICE(0x104B), |
| 79 | INTEL_E1000_ETHERNET_DEVICE(0x104C), |
| 80 | INTEL_E1000_ETHERNET_DEVICE(0x104D), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 81 | INTEL_E1000_ETHERNET_DEVICE(0x105E), |
| 82 | INTEL_E1000_ETHERNET_DEVICE(0x105F), |
| 83 | INTEL_E1000_ETHERNET_DEVICE(0x1060), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 85 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 86 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 87 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 88 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 89 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 90 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 91 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 92 | INTEL_E1000_ETHERNET_DEVICE(0x107D), |
| 93 | INTEL_E1000_ETHERNET_DEVICE(0x107E), |
| 94 | INTEL_E1000_ETHERNET_DEVICE(0x107F), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 96 | INTEL_E1000_ETHERNET_DEVICE(0x108B), |
| 97 | INTEL_E1000_ETHERNET_DEVICE(0x108C), |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 98 | INTEL_E1000_ETHERNET_DEVICE(0x1096), |
| 99 | INTEL_E1000_ETHERNET_DEVICE(0x1098), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 100 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 101 | INTEL_E1000_ETHERNET_DEVICE(0x109A), |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 102 | INTEL_E1000_ETHERNET_DEVICE(0x10A4), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 103 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 104 | INTEL_E1000_ETHERNET_DEVICE(0x10B9), |
Auke Kok | ae2c386 | 2006-06-27 09:08:30 -0700 | [diff] [blame] | 105 | INTEL_E1000_ETHERNET_DEVICE(0x10BA), |
| 106 | INTEL_E1000_ETHERNET_DEVICE(0x10BB), |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 107 | INTEL_E1000_ETHERNET_DEVICE(0x10BC), |
| 108 | INTEL_E1000_ETHERNET_DEVICE(0x10C4), |
| 109 | INTEL_E1000_ETHERNET_DEVICE(0x10C5), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* required last entry */ |
| 111 | {0,} |
| 112 | }; |
| 113 | |
| 114 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 115 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 116 | int e1000_up(struct e1000_adapter *adapter); |
| 117 | void e1000_down(struct e1000_adapter *adapter); |
| 118 | void e1000_reinit_locked(struct e1000_adapter *adapter); |
| 119 | void e1000_reset(struct e1000_adapter *adapter); |
| 120 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx); |
| 121 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
| 122 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
| 123 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
| 124 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 125 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 126 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 127 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 128 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 129 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 130 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 131 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 132 | struct e1000_rx_ring *rx_ring); |
| 133 | void e1000_update_stats(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | static int e1000_init_module(void); |
| 136 | static void e1000_exit_module(void); |
| 137 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 138 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 139 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 141 | static int e1000_open(struct net_device *netdev); |
| 142 | static int e1000_close(struct net_device *netdev); |
| 143 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 144 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 145 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 146 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 147 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 148 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 149 | struct e1000_tx_ring *tx_ring); |
| 150 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 151 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | static void e1000_set_multi(struct net_device *netdev); |
| 153 | static void e1000_update_phy_info(unsigned long data); |
| 154 | static void e1000_watchdog(unsigned long data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
| 156 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 157 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 158 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 159 | static int e1000_set_mac(struct net_device *netdev, void *p); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 160 | static irqreturn_t e1000_intr(int irq, void *data); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 161 | #ifdef CONFIG_PCI_MSI |
| 162 | static irqreturn_t e1000_intr_msi(int irq, void *data); |
| 163 | #endif |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 164 | static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 165 | struct e1000_tx_ring *tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 167 | static int e1000_clean(struct net_device *poll_dev, int *budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 169 | struct e1000_rx_ring *rx_ring, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | int *work_done, int work_to_do); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 171 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 172 | struct e1000_rx_ring *rx_ring, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 173 | int *work_done, int work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 175 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 176 | struct e1000_rx_ring *rx_ring); |
| 177 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 178 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | #endif |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 180 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 181 | struct e1000_rx_ring *rx_ring, |
| 182 | int cleaned_count); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 183 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 184 | struct e1000_rx_ring *rx_ring, |
| 185 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 187 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 188 | int cmd); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 189 | void e1000_set_ethtool_ops(struct net_device *netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 191 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 192 | static void e1000_tx_timeout(struct net_device *dev); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 193 | static void e1000_reset_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 195 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 196 | struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
| 199 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); |
| 200 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
| 201 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 202 | |
Ashutosh Naik | 977e74b | 2005-10-28 15:14:53 -0700 | [diff] [blame] | 203 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 204 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | static int e1000_resume(struct pci_dev *pdev); |
| 206 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 207 | static void e1000_shutdown(struct pci_dev *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 210 | /* for netdump / net console */ |
| 211 | static void e1000_netpoll (struct net_device *netdev); |
| 212 | #endif |
| 213 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 214 | extern void e1000_check_options(struct e1000_adapter *adapter); |
| 215 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 216 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 217 | pci_channel_state_t state); |
| 218 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); |
| 219 | static void e1000_io_resume(struct pci_dev *pdev); |
| 220 | |
| 221 | static struct pci_error_handlers e1000_err_handler = { |
| 222 | .error_detected = e1000_io_error_detected, |
| 223 | .slot_reset = e1000_io_slot_reset, |
| 224 | .resume = e1000_io_resume, |
| 225 | }; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | static struct pci_driver e1000_driver = { |
| 228 | .name = e1000_driver_name, |
| 229 | .id_table = e1000_pci_tbl, |
| 230 | .probe = e1000_probe, |
| 231 | .remove = __devexit_p(e1000_remove), |
Auke Kok | c4e24f0 | 2006-09-27 12:53:19 -0700 | [diff] [blame] | 232 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* Power Managment Hooks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | .suspend = e1000_suspend, |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 235 | .resume = e1000_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | #endif |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 237 | .shutdown = e1000_shutdown, |
| 238 | .err_handler = &e1000_err_handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 242 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 243 | MODULE_LICENSE("GPL"); |
| 244 | MODULE_VERSION(DRV_VERSION); |
| 245 | |
| 246 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 247 | module_param(debug, int, 0); |
| 248 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 249 | |
| 250 | /** |
| 251 | * e1000_init_module - Driver Registration Routine |
| 252 | * |
| 253 | * e1000_init_module is the first routine called when the driver is |
| 254 | * loaded. All it does is register with the PCI subsystem. |
| 255 | **/ |
| 256 | |
| 257 | static int __init |
| 258 | e1000_init_module(void) |
| 259 | { |
| 260 | int ret; |
| 261 | printk(KERN_INFO "%s - version %s\n", |
| 262 | e1000_driver_string, e1000_driver_version); |
| 263 | |
| 264 | printk(KERN_INFO "%s\n", e1000_copyright); |
| 265 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 266 | ret = pci_register_driver(&e1000_driver); |
Tony Luck | 8b378de | 2005-07-28 01:07:38 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | module_init(e1000_init_module); |
| 272 | |
| 273 | /** |
| 274 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 275 | * |
| 276 | * e1000_exit_module is called just before the driver is removed |
| 277 | * from memory. |
| 278 | **/ |
| 279 | |
| 280 | static void __exit |
| 281 | e1000_exit_module(void) |
| 282 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | pci_unregister_driver(&e1000_driver); |
| 284 | } |
| 285 | |
| 286 | module_exit(e1000_exit_module); |
| 287 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 288 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 289 | { |
| 290 | struct net_device *netdev = adapter->netdev; |
| 291 | int flags, err = 0; |
| 292 | |
Jeff Garzik | c0bc872 | 2006-07-05 14:32:39 -0400 | [diff] [blame] | 293 | flags = IRQF_SHARED; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 294 | #ifdef CONFIG_PCI_MSI |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 295 | if (adapter->hw.mac_type >= e1000_82571) { |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 296 | adapter->have_msi = TRUE; |
| 297 | if ((err = pci_enable_msi(adapter->pdev))) { |
| 298 | DPRINTK(PROBE, ERR, |
| 299 | "Unable to allocate MSI interrupt Error: %d\n", err); |
| 300 | adapter->have_msi = FALSE; |
| 301 | } |
| 302 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 303 | if (adapter->have_msi) { |
Andrew Morton | 61ef5c0 | 2006-07-06 23:58:19 -0700 | [diff] [blame] | 304 | flags &= ~IRQF_SHARED; |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 305 | err = request_irq(adapter->pdev->irq, &e1000_intr_msi, flags, |
| 306 | netdev->name, netdev); |
| 307 | if (err) |
| 308 | DPRINTK(PROBE, ERR, |
| 309 | "Unable to allocate interrupt Error: %d\n", err); |
| 310 | } else |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 311 | #endif |
| 312 | if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags, |
| 313 | netdev->name, netdev))) |
| 314 | DPRINTK(PROBE, ERR, |
| 315 | "Unable to allocate interrupt Error: %d\n", err); |
| 316 | |
| 317 | return err; |
| 318 | } |
| 319 | |
| 320 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 321 | { |
| 322 | struct net_device *netdev = adapter->netdev; |
| 323 | |
| 324 | free_irq(adapter->pdev->irq, netdev); |
| 325 | |
| 326 | #ifdef CONFIG_PCI_MSI |
| 327 | if (adapter->have_msi) |
| 328 | pci_disable_msi(adapter->pdev); |
| 329 | #endif |
| 330 | } |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | /** |
| 333 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 334 | * @adapter: board private structure |
| 335 | **/ |
| 336 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 337 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | e1000_irq_disable(struct e1000_adapter *adapter) |
| 339 | { |
| 340 | atomic_inc(&adapter->irq_sem); |
| 341 | E1000_WRITE_REG(&adapter->hw, IMC, ~0); |
| 342 | E1000_WRITE_FLUSH(&adapter->hw); |
| 343 | synchronize_irq(adapter->pdev->irq); |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * e1000_irq_enable - Enable default interrupt generation settings |
| 348 | * @adapter: board private structure |
| 349 | **/ |
| 350 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 351 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | e1000_irq_enable(struct e1000_adapter *adapter) |
| 353 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 354 | if (likely(atomic_dec_and_test(&adapter->irq_sem))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); |
| 356 | E1000_WRITE_FLUSH(&adapter->hw); |
| 357 | } |
| 358 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 359 | |
| 360 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 361 | e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 362 | { |
| 363 | struct net_device *netdev = adapter->netdev; |
| 364 | uint16_t vid = adapter->hw.mng_cookie.vlan_id; |
| 365 | uint16_t old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 366 | if (adapter->vlgrp) { |
| 367 | if (!adapter->vlgrp->vlan_devices[vid]) { |
| 368 | if (adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 369 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 370 | e1000_vlan_rx_add_vid(netdev, vid); |
| 371 | adapter->mng_vlan_id = vid; |
| 372 | } else |
| 373 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 374 | |
| 375 | if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && |
| 376 | (vid != old_vid) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 377 | !adapter->vlgrp->vlan_devices[old_vid]) |
| 378 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 379 | } else |
| 380 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * e1000_release_hw_control - release control of the h/w to f/w |
| 386 | * @adapter: address of board private structure |
| 387 | * |
| 388 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 389 | * For ASF and Pass Through versions of f/w this means that the |
| 390 | * driver is no longer loaded. For AMT version (only with 82573) i |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 391 | * of the f/w this means that the network i/f is closed. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 392 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 393 | **/ |
| 394 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 395 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 396 | e1000_release_hw_control(struct e1000_adapter *adapter) |
| 397 | { |
| 398 | uint32_t ctrl_ext; |
| 399 | uint32_t swsm; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 400 | uint32_t extcnf; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 401 | |
| 402 | /* Let firmware taken over control of h/w */ |
| 403 | switch (adapter->hw.mac_type) { |
| 404 | case e1000_82571: |
| 405 | case e1000_82572: |
Auke Kok | 4cc15f5 | 2006-04-14 19:04:46 -0700 | [diff] [blame] | 406 | case e1000_80003es2lan: |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 407 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 408 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 409 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
| 410 | break; |
| 411 | case e1000_82573: |
| 412 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 413 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 414 | swsm & ~E1000_SWSM_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 415 | case e1000_ich8lan: |
| 416 | extcnf = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 417 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 418 | extcnf & ~E1000_CTRL_EXT_DRV_LOAD); |
| 419 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 420 | default: |
| 421 | break; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * e1000_get_hw_control - get control of the h/w from f/w |
| 427 | * @adapter: address of board private structure |
| 428 | * |
| 429 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 430 | * For ASF and Pass Through versions of f/w this means that |
| 431 | * the driver is loaded. For AMT version (only with 82573) |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 432 | * of the f/w this means that the network i/f is open. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 433 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 434 | **/ |
| 435 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 436 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 437 | e1000_get_hw_control(struct e1000_adapter *adapter) |
| 438 | { |
| 439 | uint32_t ctrl_ext; |
| 440 | uint32_t swsm; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 441 | uint32_t extcnf; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 442 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 443 | /* Let firmware know the driver has taken over */ |
| 444 | switch (adapter->hw.mac_type) { |
| 445 | case e1000_82571: |
| 446 | case e1000_82572: |
Auke Kok | 4cc15f5 | 2006-04-14 19:04:46 -0700 | [diff] [blame] | 447 | case e1000_80003es2lan: |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 448 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 449 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 450 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
| 451 | break; |
| 452 | case e1000_82573: |
| 453 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 454 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 455 | swsm | E1000_SWSM_DRV_LOAD); |
| 456 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 457 | case e1000_ich8lan: |
| 458 | extcnf = E1000_READ_REG(&adapter->hw, EXTCNF_CTRL); |
| 459 | E1000_WRITE_REG(&adapter->hw, EXTCNF_CTRL, |
| 460 | extcnf | E1000_EXTCNF_CTRL_SWFLAG); |
| 461 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 462 | default: |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 467 | static void |
| 468 | e1000_init_manageability(struct e1000_adapter *adapter) |
| 469 | { |
| 470 | if (adapter->en_mng_pt) { |
| 471 | uint32_t manc = E1000_READ_REG(&adapter->hw, MANC); |
| 472 | |
| 473 | /* disable hardware interception of ARP */ |
| 474 | manc &= ~(E1000_MANC_ARP_EN); |
| 475 | |
| 476 | /* enable receiving management packets to the host */ |
| 477 | /* this will probably generate destination unreachable messages |
| 478 | * from the host OS, but the packets will be handled on SMBUS */ |
| 479 | if (adapter->hw.has_manc2h) { |
| 480 | uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H); |
| 481 | |
| 482 | manc |= E1000_MANC_EN_MNG2HOST; |
| 483 | #define E1000_MNG2HOST_PORT_623 (1 << 5) |
| 484 | #define E1000_MNG2HOST_PORT_664 (1 << 6) |
| 485 | manc2h |= E1000_MNG2HOST_PORT_623; |
| 486 | manc2h |= E1000_MNG2HOST_PORT_664; |
| 487 | E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h); |
| 488 | } |
| 489 | |
| 490 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static void |
| 495 | e1000_release_manageability(struct e1000_adapter *adapter) |
| 496 | { |
| 497 | if (adapter->en_mng_pt) { |
| 498 | uint32_t manc = E1000_READ_REG(&adapter->hw, MANC); |
| 499 | |
| 500 | /* re-enable hardware interception of ARP */ |
| 501 | manc |= E1000_MANC_ARP_EN; |
| 502 | |
| 503 | if (adapter->hw.has_manc2h) |
| 504 | manc &= ~E1000_MANC_EN_MNG2HOST; |
| 505 | |
| 506 | /* don't explicitly have to mess with MANC2H since |
| 507 | * MANC has an enable disable that gates MANC2H */ |
| 508 | |
| 509 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 510 | } |
| 511 | } |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | int |
| 514 | e1000_up(struct e1000_adapter *adapter) |
| 515 | { |
| 516 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 517 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | /* hardware has been reset, we need to reload some things */ |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | e1000_set_multi(netdev); |
| 522 | |
| 523 | e1000_restore_vlan(adapter); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 524 | e1000_init_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | e1000_configure_tx(adapter); |
| 527 | e1000_setup_rctl(adapter); |
| 528 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 529 | /* call E1000_DESC_UNUSED which always leaves |
| 530 | * at least 1 descriptor unused to make sure |
| 531 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 532 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 533 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 534 | adapter->alloc_rx_buf(adapter, ring, |
| 535 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 538 | adapter->tx_queue_len = netdev->tx_queue_len; |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | #ifdef CONFIG_E1000_NAPI |
| 541 | netif_poll_enable(netdev); |
| 542 | #endif |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 543 | e1000_irq_enable(adapter); |
| 544 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 545 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 546 | |
| 547 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 551 | /** |
| 552 | * e1000_power_up_phy - restore link in case the phy was powered down |
| 553 | * @adapter: address of board private structure |
| 554 | * |
| 555 | * The phy may be powered down to save power and turn off link when the |
| 556 | * driver is unloaded and wake on lan is not enabled (among others) |
| 557 | * *** this routine MUST be followed by a call to e1000_reset *** |
| 558 | * |
| 559 | **/ |
| 560 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 561 | void e1000_power_up_phy(struct e1000_adapter *adapter) |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 562 | { |
| 563 | uint16_t mii_reg = 0; |
| 564 | |
| 565 | /* Just clear the power down bit to wake the phy back up */ |
| 566 | if (adapter->hw.media_type == e1000_media_type_copper) { |
| 567 | /* according to the manual, the phy will retain its |
| 568 | * settings across a power-down/up cycle */ |
| 569 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 570 | mii_reg &= ~MII_CR_POWER_DOWN; |
| 571 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 576 | { |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 577 | /* Power down the PHY so no link is implied when interface is down * |
| 578 | * The PHY cannot be powered down if any of the following is TRUE * |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 579 | * (a) WoL is enabled |
| 580 | * (b) AMT is active |
| 581 | * (c) SoL/IDER session is active */ |
| 582 | if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 583 | adapter->hw.media_type == e1000_media_type_copper) { |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 584 | uint16_t mii_reg = 0; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 585 | |
| 586 | switch (adapter->hw.mac_type) { |
| 587 | case e1000_82540: |
| 588 | case e1000_82545: |
| 589 | case e1000_82545_rev_3: |
| 590 | case e1000_82546: |
| 591 | case e1000_82546_rev_3: |
| 592 | case e1000_82541: |
| 593 | case e1000_82541_rev_2: |
| 594 | case e1000_82547: |
| 595 | case e1000_82547_rev_2: |
| 596 | if (E1000_READ_REG(&adapter->hw, MANC) & |
| 597 | E1000_MANC_SMBUS_EN) |
| 598 | goto out; |
| 599 | break; |
| 600 | case e1000_82571: |
| 601 | case e1000_82572: |
| 602 | case e1000_82573: |
| 603 | case e1000_80003es2lan: |
| 604 | case e1000_ich8lan: |
| 605 | if (e1000_check_mng_mode(&adapter->hw) || |
| 606 | e1000_check_phy_reset_block(&adapter->hw)) |
| 607 | goto out; |
| 608 | break; |
| 609 | default: |
| 610 | goto out; |
| 611 | } |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 612 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 613 | mii_reg |= MII_CR_POWER_DOWN; |
| 614 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 615 | mdelay(1); |
| 616 | } |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 617 | out: |
| 618 | return; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | void |
| 622 | e1000_down(struct e1000_adapter *adapter) |
| 623 | { |
| 624 | struct net_device *netdev = adapter->netdev; |
| 625 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 626 | /* signal that we're down so the interrupt handler does not |
| 627 | * reschedule our watchdog timer */ |
| 628 | set_bit(__E1000_DOWN, &adapter->flags); |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 633 | del_timer_sync(&adapter->watchdog_timer); |
| 634 | del_timer_sync(&adapter->phy_info_timer); |
| 635 | |
| 636 | #ifdef CONFIG_E1000_NAPI |
| 637 | netif_poll_disable(netdev); |
| 638 | #endif |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 639 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | adapter->link_speed = 0; |
| 641 | adapter->link_duplex = 0; |
| 642 | netif_carrier_off(netdev); |
| 643 | netif_stop_queue(netdev); |
| 644 | |
| 645 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 646 | e1000_clean_all_tx_rings(adapter); |
| 647 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | void |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 651 | e1000_reinit_locked(struct e1000_adapter *adapter) |
| 652 | { |
| 653 | WARN_ON(in_interrupt()); |
| 654 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 655 | msleep(1); |
| 656 | e1000_down(adapter); |
| 657 | e1000_up(adapter); |
| 658 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | void |
| 662 | e1000_reset(struct e1000_adapter *adapter) |
| 663 | { |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 664 | uint32_t pba; |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 665 | uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | /* Repartition Pba for greater than 9k mtu |
| 668 | * To take effect CTRL.RST is required. |
| 669 | */ |
| 670 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 671 | switch (adapter->hw.mac_type) { |
| 672 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 673 | case e1000_82547_rev_2: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 674 | pba = E1000_PBA_30K; |
| 675 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 676 | case e1000_82571: |
| 677 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 678 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 679 | pba = E1000_PBA_38K; |
| 680 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 681 | case e1000_82573: |
| 682 | pba = E1000_PBA_12K; |
| 683 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 684 | case e1000_ich8lan: |
| 685 | pba = E1000_PBA_8K; |
| 686 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 687 | default: |
| 688 | pba = E1000_PBA_48K; |
| 689 | break; |
| 690 | } |
| 691 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 692 | if ((adapter->hw.mac_type != e1000_82573) && |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 693 | (adapter->netdev->mtu > E1000_RXBUFFER_8192)) |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 694 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 695 | |
| 696 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 697 | if (adapter->hw.mac_type == e1000_82547) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | adapter->tx_fifo_head = 0; |
| 699 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 700 | adapter->tx_fifo_size = |
| 701 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 702 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 703 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
| 706 | |
| 707 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 708 | /* Set the FC high water mark to 90% of the FIFO size. |
| 709 | * Required to clear last 3 LSB */ |
| 710 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 711 | /* We can't use 90% on small FIFOs because the remainder |
| 712 | * would be less than 1 full frame. In this case, we size |
| 713 | * it to allow at least a full frame above the high water |
| 714 | * mark. */ |
| 715 | if (pba < E1000_PBA_16K) |
| 716 | fc_high_water_mark = (pba * 1024) - 1600; |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 717 | |
| 718 | adapter->hw.fc_high_water = fc_high_water_mark; |
| 719 | adapter->hw.fc_low_water = fc_high_water_mark - 8; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 720 | if (adapter->hw.mac_type == e1000_80003es2lan) |
| 721 | adapter->hw.fc_pause_time = 0xFFFF; |
| 722 | else |
| 723 | adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | adapter->hw.fc_send_xon = 1; |
| 725 | adapter->hw.fc = adapter->hw.original_fc; |
| 726 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 727 | /* Allow time for pending master requests to run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | e1000_reset_hw(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 729 | if (adapter->hw.mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 731 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 732 | if (e1000_init_hw(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 734 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 735 | |
| 736 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
| 737 | if (adapter->hw.mac_type >= e1000_82544 && |
| 738 | adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 739 | adapter->hw.autoneg == 1 && |
| 740 | adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) { |
| 741 | uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 742 | /* clear phy power management bit if we are in gig only mode, |
| 743 | * which if enabled will attempt negotiation to 100Mb, which |
| 744 | * can cause a loss of link at power off or driver unload */ |
| 745 | ctrl &= ~E1000_CTRL_SWDPIN3; |
| 746 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 747 | } |
| 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 750 | E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); |
| 751 | |
| 752 | e1000_reset_adaptive(&adapter->hw); |
| 753 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 754 | |
| 755 | if (!adapter->smart_power_down && |
| 756 | (adapter->hw.mac_type == e1000_82571 || |
| 757 | adapter->hw.mac_type == e1000_82572)) { |
| 758 | uint16_t phy_data = 0; |
| 759 | /* speed up time to link by disabling smart power down, ignore |
| 760 | * the return value of this function because there is nothing |
| 761 | * different we would do if it failed */ |
| 762 | e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 763 | &phy_data); |
| 764 | phy_data &= ~IGP02E1000_PM_SPD; |
| 765 | e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 766 | phy_data); |
| 767 | } |
| 768 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 769 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** |
| 773 | * e1000_probe - Device Initialization Routine |
| 774 | * @pdev: PCI device information struct |
| 775 | * @ent: entry in e1000_pci_tbl |
| 776 | * |
| 777 | * Returns 0 on success, negative on failure |
| 778 | * |
| 779 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 780 | * The OS initialization, configuring of the adapter private structure, |
| 781 | * and a hardware reset occur. |
| 782 | **/ |
| 783 | |
| 784 | static int __devinit |
| 785 | e1000_probe(struct pci_dev *pdev, |
| 786 | const struct pci_device_id *ent) |
| 787 | { |
| 788 | struct net_device *netdev; |
| 789 | struct e1000_adapter *adapter; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 790 | unsigned long mmio_start, mmio_len; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 791 | unsigned long flash_start, flash_len; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 794 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 795 | int i, err, pci_using_dac; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 796 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | uint16_t eeprom_apme_mask = E1000_EEPROM_APME; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 798 | if ((err = pci_enable_device(pdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | return err; |
| 800 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 801 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) && |
| 802 | !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | pci_using_dac = 1; |
| 804 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 805 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) && |
| 806 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | E1000_ERR("No usable DMA configuration, aborting\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 808 | goto err_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
| 810 | pci_using_dac = 0; |
| 811 | } |
| 812 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 813 | if ((err = pci_request_regions(pdev, e1000_driver_name))) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 814 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | pci_set_master(pdev); |
| 817 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 818 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 820 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | SET_MODULE_OWNER(netdev); |
| 824 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 825 | |
| 826 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 827 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | adapter->netdev = netdev; |
| 829 | adapter->pdev = pdev; |
| 830 | adapter->hw.back = adapter; |
| 831 | adapter->msg_enable = (1 << debug) - 1; |
| 832 | |
| 833 | mmio_start = pci_resource_start(pdev, BAR_0); |
| 834 | mmio_len = pci_resource_len(pdev, BAR_0); |
| 835 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 836 | err = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 838 | if (!adapter->hw.hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 841 | for (i = BAR_1; i <= BAR_5; i++) { |
| 842 | if (pci_resource_len(pdev, i) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | continue; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 844 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | netdev->open = &e1000_open; |
| 851 | netdev->stop = &e1000_close; |
| 852 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 853 | netdev->get_stats = &e1000_get_stats; |
| 854 | netdev->set_multicast_list = &e1000_set_multi; |
| 855 | netdev->set_mac_address = &e1000_set_mac; |
| 856 | netdev->change_mtu = &e1000_change_mtu; |
| 857 | netdev->do_ioctl = &e1000_ioctl; |
| 858 | e1000_set_ethtool_ops(netdev); |
| 859 | netdev->tx_timeout = &e1000_tx_timeout; |
| 860 | netdev->watchdog_timeo = 5 * HZ; |
| 861 | #ifdef CONFIG_E1000_NAPI |
| 862 | netdev->poll = &e1000_clean; |
| 863 | netdev->weight = 64; |
| 864 | #endif |
| 865 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 866 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 867 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 868 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 869 | netdev->poll_controller = e1000_netpoll; |
| 870 | #endif |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 871 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | netdev->mem_start = mmio_start; |
| 874 | netdev->mem_end = mmio_start + mmio_len; |
| 875 | netdev->base_addr = adapter->hw.io_base; |
| 876 | |
| 877 | adapter->bd_number = cards_found; |
| 878 | |
| 879 | /* setup the private structure */ |
| 880 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 881 | if ((err = e1000_sw_init(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | goto err_sw_init; |
| 883 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 884 | err = -EIO; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 885 | /* Flash BAR mapping must happen after e1000_sw_init |
| 886 | * because it depends on mac_type */ |
| 887 | if ((adapter->hw.mac_type == e1000_ich8lan) && |
| 888 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 889 | flash_start = pci_resource_start(pdev, 1); |
| 890 | flash_len = pci_resource_len(pdev, 1); |
| 891 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 892 | if (!adapter->hw.flash_address) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 893 | goto err_flashmap; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 896 | if (e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 897 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 898 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 899 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | netdev->features = NETIF_F_SG | |
| 901 | NETIF_F_HW_CSUM | |
| 902 | NETIF_F_HW_VLAN_TX | |
| 903 | NETIF_F_HW_VLAN_RX | |
| 904 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 905 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 906 | netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | #ifdef NETIF_F_TSO |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 910 | if ((adapter->hw.mac_type >= e1000_82544) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | (adapter->hw.mac_type != e1000_82547)) |
| 912 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 913 | |
Jesse Brandeburg | 72f3ab7 | 2006-12-15 10:34:46 +0100 | [diff] [blame^] | 914 | #ifdef CONFIG_DEBUG_SLAB |
| 915 | /* 82544's work arounds do not play nicely with DEBUG SLAB */ |
| 916 | if (adapter->hw.mac_type == e1000_82544) |
| 917 | netdev->features &= ~NETIF_F_TSO; |
| 918 | #endif |
| 919 | |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 920 | #ifdef NETIF_F_TSO6 |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 921 | if (adapter->hw.mac_type > e1000_82547_rev_2) |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 922 | netdev->features |= NETIF_F_TSO6; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 923 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | #endif |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 925 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | netdev->features |= NETIF_F_HIGHDMA; |
| 927 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 928 | netdev->features |= NETIF_F_LLTX; |
| 929 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 930 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); |
| 931 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 932 | /* initialize eeprom parameters */ |
| 933 | |
| 934 | if (e1000_init_eeprom_params(&adapter->hw)) { |
| 935 | E1000_ERR("EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 936 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 939 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | e1000_reset_hw(&adapter->hw); |
| 943 | |
| 944 | /* make sure the EEPROM is good */ |
| 945 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 946 | if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | goto err_eeprom; |
| 949 | } |
| 950 | |
| 951 | /* copy the MAC address out of the EEPROM */ |
| 952 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 953 | if (e1000_read_mac_addr(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
| 955 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
John W. Linville | 9beb0ac | 2005-09-12 10:48:55 -0400 | [diff] [blame] | 956 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 958 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | goto err_eeprom; |
| 961 | } |
| 962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | e1000_get_bus_info(&adapter->hw); |
| 964 | |
| 965 | init_timer(&adapter->tx_fifo_stall_timer); |
| 966 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
| 967 | adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; |
| 968 | |
| 969 | init_timer(&adapter->watchdog_timer); |
| 970 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 971 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | init_timer(&adapter->phy_info_timer); |
| 974 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 975 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 976 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 977 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | e1000_check_options(adapter); |
| 980 | |
| 981 | /* Initial Wake on LAN setting |
| 982 | * If APM wake is enabled in the EEPROM, |
| 983 | * enable the ACPI Magic Packet filter |
| 984 | */ |
| 985 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 986 | switch (adapter->hw.mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | case e1000_82542_rev2_0: |
| 988 | case e1000_82542_rev2_1: |
| 989 | case e1000_82543: |
| 990 | break; |
| 991 | case e1000_82544: |
| 992 | e1000_read_eeprom(&adapter->hw, |
| 993 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 994 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 995 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 996 | case e1000_ich8lan: |
| 997 | e1000_read_eeprom(&adapter->hw, |
| 998 | EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
| 999 | eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
| 1000 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | case e1000_82546: |
| 1002 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1003 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1004 | case e1000_80003es2lan: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1005 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | e1000_read_eeprom(&adapter->hw, |
| 1007 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1008 | break; |
| 1009 | } |
| 1010 | /* Fall Through */ |
| 1011 | default: |
| 1012 | e1000_read_eeprom(&adapter->hw, |
| 1013 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1014 | break; |
| 1015 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1016 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1017 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1018 | |
| 1019 | /* now that we have the eeprom settings, apply the special cases |
| 1020 | * where the eeprom may be wrong or the board simply won't support |
| 1021 | * wake on lan on a particular port */ |
| 1022 | switch (pdev->device) { |
| 1023 | case E1000_DEV_ID_82546GB_PCIE: |
| 1024 | adapter->eeprom_wol = 0; |
| 1025 | break; |
| 1026 | case E1000_DEV_ID_82546EB_FIBER: |
| 1027 | case E1000_DEV_ID_82546GB_FIBER: |
| 1028 | case E1000_DEV_ID_82571EB_FIBER: |
| 1029 | /* Wake events only supported on port A for dual fiber |
| 1030 | * regardless of eeprom setting */ |
| 1031 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1) |
| 1032 | adapter->eeprom_wol = 0; |
| 1033 | break; |
| 1034 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1035 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 1036 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1037 | /* if quad port adapter, disable WoL on all but port A */ |
| 1038 | if (global_quad_port_a != 0) |
| 1039 | adapter->eeprom_wol = 0; |
| 1040 | else |
| 1041 | adapter->quad_port_a = 1; |
| 1042 | /* Reset for multiple quad port adapters */ |
| 1043 | if (++global_quad_port_a == 4) |
| 1044 | global_quad_port_a = 0; |
| 1045 | break; |
| 1046 | } |
| 1047 | |
| 1048 | /* initialize the wol settings based on the eeprom settings */ |
| 1049 | adapter->wol = adapter->eeprom_wol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1051 | /* print bus type/speed/width info */ |
| 1052 | { |
| 1053 | struct e1000_hw *hw = &adapter->hw; |
| 1054 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 1055 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 1056 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 1057 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 1058 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 1059 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 1060 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 1061 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 1062 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 1063 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 1064 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 1065 | "32-bit")); |
| 1066 | } |
| 1067 | |
| 1068 | for (i = 0; i < 6; i++) |
| 1069 | printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':'); |
| 1070 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | /* reset the hardware with the new settings */ |
| 1072 | e1000_reset(adapter); |
| 1073 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1074 | /* If the controller is 82573 and f/w is AMT, do not set |
| 1075 | * DRV_LOAD until the interface is up. For all other cases, |
| 1076 | * let the f/w know that the h/w is now under the control |
| 1077 | * of the driver. */ |
| 1078 | if (adapter->hw.mac_type != e1000_82573 || |
| 1079 | !e1000_check_mng_mode(&adapter->hw)) |
| 1080 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | strcpy(netdev->name, "eth%d"); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1083 | if ((err = register_netdev(netdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | goto err_register; |
| 1085 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1086 | /* tell the stack to leave us alone until e1000_open() is called */ |
| 1087 | netif_carrier_off(netdev); |
| 1088 | netif_stop_queue(netdev); |
| 1089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 1091 | |
| 1092 | cards_found++; |
| 1093 | return 0; |
| 1094 | |
| 1095 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1096 | e1000_release_hw_control(adapter); |
| 1097 | err_eeprom: |
| 1098 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
| 1099 | e1000_phy_hw_reset(&adapter->hw); |
| 1100 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1101 | if (adapter->hw.flash_address) |
| 1102 | iounmap(adapter->hw.flash_address); |
| 1103 | err_flashmap: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1104 | #ifdef CONFIG_E1000_NAPI |
| 1105 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1106 | dev_put(&adapter->polling_netdev[i]); |
| 1107 | #endif |
| 1108 | |
| 1109 | kfree(adapter->tx_ring); |
| 1110 | kfree(adapter->rx_ring); |
| 1111 | #ifdef CONFIG_E1000_NAPI |
| 1112 | kfree(adapter->polling_netdev); |
| 1113 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | err_sw_init: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | iounmap(adapter->hw.hw_addr); |
| 1116 | err_ioremap: |
| 1117 | free_netdev(netdev); |
| 1118 | err_alloc_etherdev: |
| 1119 | pci_release_regions(pdev); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1120 | err_pci_reg: |
| 1121 | err_dma: |
| 1122 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | return err; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * e1000_remove - Device Removal Routine |
| 1128 | * @pdev: PCI device information struct |
| 1129 | * |
| 1130 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1131 | * that it should release a PCI device. The could be caused by a |
| 1132 | * Hot-Plug event, or because the driver is going to be removed from |
| 1133 | * memory. |
| 1134 | **/ |
| 1135 | |
| 1136 | static void __devexit |
| 1137 | e1000_remove(struct pci_dev *pdev) |
| 1138 | { |
| 1139 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1140 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1141 | #ifdef CONFIG_E1000_NAPI |
| 1142 | int i; |
| 1143 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1145 | flush_scheduled_work(); |
| 1146 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1147 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1149 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1150 | * would have already happened in close and is redundant. */ |
| 1151 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | unregister_netdev(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1154 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1155 | for (i = 0; i < adapter->num_rx_queues; i++) |
Stephen Hemminger | 1533306 | 2006-03-20 22:32:28 -0800 | [diff] [blame] | 1156 | dev_put(&adapter->polling_netdev[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1157 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1159 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1160 | e1000_phy_hw_reset(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1162 | kfree(adapter->tx_ring); |
| 1163 | kfree(adapter->rx_ring); |
| 1164 | #ifdef CONFIG_E1000_NAPI |
| 1165 | kfree(adapter->polling_netdev); |
| 1166 | #endif |
| 1167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | iounmap(adapter->hw.hw_addr); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1169 | if (adapter->hw.flash_address) |
| 1170 | iounmap(adapter->hw.flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | pci_release_regions(pdev); |
| 1172 | |
| 1173 | free_netdev(netdev); |
| 1174 | |
| 1175 | pci_disable_device(pdev); |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1180 | * @adapter: board private structure to initialize |
| 1181 | * |
| 1182 | * e1000_sw_init initializes the Adapter private data structure. |
| 1183 | * Fields are initialized based on PCI device information and |
| 1184 | * OS network device settings (MTU size). |
| 1185 | **/ |
| 1186 | |
| 1187 | static int __devinit |
| 1188 | e1000_sw_init(struct e1000_adapter *adapter) |
| 1189 | { |
| 1190 | struct e1000_hw *hw = &adapter->hw; |
| 1191 | struct net_device *netdev = adapter->netdev; |
| 1192 | struct pci_dev *pdev = adapter->pdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1193 | #ifdef CONFIG_E1000_NAPI |
| 1194 | int i; |
| 1195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
| 1197 | /* PCI config space info */ |
| 1198 | |
| 1199 | hw->vendor_id = pdev->vendor; |
| 1200 | hw->device_id = pdev->device; |
| 1201 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1202 | hw->subsystem_id = pdev->subsystem_device; |
| 1203 | |
| 1204 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 1205 | |
| 1206 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 1207 | |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1208 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1209 | adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | hw->max_frame_size = netdev->mtu + |
| 1211 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1212 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 1213 | |
| 1214 | /* identify the MAC */ |
| 1215 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1216 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 1218 | return -EIO; |
| 1219 | } |
| 1220 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1221 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | default: |
| 1223 | break; |
| 1224 | case e1000_82541: |
| 1225 | case e1000_82547: |
| 1226 | case e1000_82541_rev_2: |
| 1227 | case e1000_82547_rev_2: |
| 1228 | hw->phy_init_script = 1; |
| 1229 | break; |
| 1230 | } |
| 1231 | |
| 1232 | e1000_set_media_type(hw); |
| 1233 | |
| 1234 | hw->wait_autoneg_complete = FALSE; |
| 1235 | hw->tbi_compatibility_en = TRUE; |
| 1236 | hw->adaptive_ifs = TRUE; |
| 1237 | |
| 1238 | /* Copper options */ |
| 1239 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1240 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | hw->mdix = AUTO_ALL_MODES; |
| 1242 | hw->disable_polarity_correction = FALSE; |
| 1243 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1244 | } |
| 1245 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1246 | adapter->num_tx_queues = 1; |
| 1247 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1248 | |
| 1249 | if (e1000_alloc_queues(adapter)) { |
| 1250 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1251 | return -ENOMEM; |
| 1252 | } |
| 1253 | |
| 1254 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1255 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1256 | adapter->polling_netdev[i].priv = adapter; |
| 1257 | adapter->polling_netdev[i].poll = &e1000_clean; |
| 1258 | adapter->polling_netdev[i].weight = 64; |
| 1259 | dev_hold(&adapter->polling_netdev[i]); |
| 1260 | set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
| 1261 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1262 | spin_lock_init(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1263 | #endif |
| 1264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | atomic_set(&adapter->irq_sem, 1); |
| 1266 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1268 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1274 | * e1000_alloc_queues - Allocate memory for all rings |
| 1275 | * @adapter: board private structure to initialize |
| 1276 | * |
| 1277 | * We allocate one ring per queue at run-time since we don't know the |
| 1278 | * number of queues at compile-time. The polling_netdev array is |
| 1279 | * intended for Multiqueue, but should work fine with a single queue. |
| 1280 | **/ |
| 1281 | |
| 1282 | static int __devinit |
| 1283 | e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1284 | { |
| 1285 | int size; |
| 1286 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1287 | size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1288 | adapter->tx_ring = kmalloc(size, GFP_KERNEL); |
| 1289 | if (!adapter->tx_ring) |
| 1290 | return -ENOMEM; |
| 1291 | memset(adapter->tx_ring, 0, size); |
| 1292 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1293 | size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1294 | adapter->rx_ring = kmalloc(size, GFP_KERNEL); |
| 1295 | if (!adapter->rx_ring) { |
| 1296 | kfree(adapter->tx_ring); |
| 1297 | return -ENOMEM; |
| 1298 | } |
| 1299 | memset(adapter->rx_ring, 0, size); |
| 1300 | |
| 1301 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1302 | size = sizeof(struct net_device) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1303 | adapter->polling_netdev = kmalloc(size, GFP_KERNEL); |
| 1304 | if (!adapter->polling_netdev) { |
| 1305 | kfree(adapter->tx_ring); |
| 1306 | kfree(adapter->rx_ring); |
| 1307 | return -ENOMEM; |
| 1308 | } |
| 1309 | memset(adapter->polling_netdev, 0, size); |
| 1310 | #endif |
| 1311 | |
| 1312 | return E1000_SUCCESS; |
| 1313 | } |
| 1314 | |
| 1315 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | * e1000_open - Called when a network interface is made active |
| 1317 | * @netdev: network interface device structure |
| 1318 | * |
| 1319 | * Returns 0 on success, negative value on failure |
| 1320 | * |
| 1321 | * The open entry point is called when a network interface is made |
| 1322 | * active by the system (IFF_UP). At this point all resources needed |
| 1323 | * for transmit and receive operations are allocated, the interrupt |
| 1324 | * handler is registered with the OS, the watchdog timer is started, |
| 1325 | * and the stack is notified that the interface is ready. |
| 1326 | **/ |
| 1327 | |
| 1328 | static int |
| 1329 | e1000_open(struct net_device *netdev) |
| 1330 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1331 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | int err; |
| 1333 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1334 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1335 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1336 | return -EBUSY; |
| 1337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | /* allocate transmit descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1339 | if ((err = e1000_setup_all_tx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | goto err_setup_tx; |
| 1341 | |
| 1342 | /* allocate receive descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1343 | if ((err = e1000_setup_all_rx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | goto err_setup_rx; |
| 1345 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1346 | err = e1000_request_irq(adapter); |
| 1347 | if (err) |
Vasily Averin | 401a552 | 2006-08-28 14:56:19 -0700 | [diff] [blame] | 1348 | goto err_req_irq; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1349 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1350 | e1000_power_up_phy(adapter); |
| 1351 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1352 | if ((err = e1000_up(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | goto err_up; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1354 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1355 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1356 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1357 | e1000_update_mng_vlan(adapter); |
| 1358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1360 | /* If AMT is enabled, let the firmware know that the network |
| 1361 | * interface is now open */ |
| 1362 | if (adapter->hw.mac_type == e1000_82573 && |
| 1363 | e1000_check_mng_mode(&adapter->hw)) |
| 1364 | e1000_get_hw_control(adapter); |
| 1365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | return E1000_SUCCESS; |
| 1367 | |
| 1368 | err_up: |
Vasily Averin | 401a552 | 2006-08-28 14:56:19 -0700 | [diff] [blame] | 1369 | e1000_power_down_phy(adapter); |
| 1370 | e1000_free_irq(adapter); |
| 1371 | err_req_irq: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1372 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1374 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | err_setup_tx: |
| 1376 | e1000_reset(adapter); |
| 1377 | |
| 1378 | return err; |
| 1379 | } |
| 1380 | |
| 1381 | /** |
| 1382 | * e1000_close - Disables a network interface |
| 1383 | * @netdev: network interface device structure |
| 1384 | * |
| 1385 | * Returns 0, this is not allowed to fail |
| 1386 | * |
| 1387 | * The close entry point is called when an interface is de-activated |
| 1388 | * by the OS. The hardware is still under the drivers control, but |
| 1389 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1390 | * hardware, and all transmit and receive resources are freed. |
| 1391 | **/ |
| 1392 | |
| 1393 | static int |
| 1394 | e1000_close(struct net_device *netdev) |
| 1395 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1396 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1398 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1400 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1401 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1403 | e1000_free_all_tx_resources(adapter); |
| 1404 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1406 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1407 | * the same ID is registered on the host OS (let 8021q kill it) */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1408 | if ((adapter->hw.mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1409 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1410 | !(adapter->vlgrp && |
| 1411 | adapter->vlgrp->vlan_devices[adapter->mng_vlan_id])) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1412 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1413 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1414 | |
| 1415 | /* If AMT is enabled, let the firmware know that the network |
| 1416 | * interface is now closed */ |
| 1417 | if (adapter->hw.mac_type == e1000_82573 && |
| 1418 | e1000_check_mng_mode(&adapter->hw)) |
| 1419 | e1000_release_hw_control(adapter); |
| 1420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1426 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1427 | * @start: address of beginning of memory |
| 1428 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | **/ |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 1430 | static boolean_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | e1000_check_64k_bound(struct e1000_adapter *adapter, |
| 1432 | void *start, unsigned long len) |
| 1433 | { |
| 1434 | unsigned long begin = (unsigned long) start; |
| 1435 | unsigned long end = begin + len; |
| 1436 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1437 | /* First rev 82545 and 82546 need to not allow any memory |
| 1438 | * write location to cross 64k boundary due to errata 23 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | if (adapter->hw.mac_type == e1000_82545 || |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1440 | adapter->hw.mac_type == e1000_82546) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE; |
| 1442 | } |
| 1443 | |
| 1444 | return TRUE; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1449 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1450 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | * |
| 1452 | * Return 0 on success, negative on failure |
| 1453 | **/ |
| 1454 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1455 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1456 | e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1457 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | struct pci_dev *pdev = adapter->pdev; |
| 1460 | int size; |
| 1461 | |
| 1462 | size = sizeof(struct e1000_buffer) * txdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1463 | txdr->buffer_info = vmalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1464 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1465 | DPRINTK(PROBE, ERR, |
| 1466 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | return -ENOMEM; |
| 1468 | } |
| 1469 | memset(txdr->buffer_info, 0, size); |
| 1470 | |
| 1471 | /* round up to nearest 4K */ |
| 1472 | |
| 1473 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
| 1474 | E1000_ROUNDUP(txdr->size, 4096); |
| 1475 | |
| 1476 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1477 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1480 | DPRINTK(PROBE, ERR, |
| 1481 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | return -ENOMEM; |
| 1483 | } |
| 1484 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1485 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1487 | void *olddesc = txdr->desc; |
| 1488 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1489 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1490 | "at %p\n", txdr->size, txdr->desc); |
| 1491 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1493 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1494 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1496 | goto setup_tx_desc_die; |
| 1497 | } |
| 1498 | |
| 1499 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1500 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1501 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1502 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1504 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1505 | "Unable to allocate aligned memory " |
| 1506 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | vfree(txdr->buffer_info); |
| 1508 | return -ENOMEM; |
| 1509 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1510 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1512 | } |
| 1513 | } |
| 1514 | memset(txdr->desc, 0, txdr->size); |
| 1515 | |
| 1516 | txdr->next_to_use = 0; |
| 1517 | txdr->next_to_clean = 0; |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1518 | spin_lock_init(&txdr->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
| 1523 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1524 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1525 | * (Descriptors) for all queues |
| 1526 | * @adapter: board private structure |
| 1527 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1528 | * Return 0 on success, negative on failure |
| 1529 | **/ |
| 1530 | |
| 1531 | int |
| 1532 | e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
| 1533 | { |
| 1534 | int i, err = 0; |
| 1535 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1536 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1537 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1538 | if (err) { |
| 1539 | DPRINTK(PROBE, ERR, |
| 1540 | "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1541 | for (i-- ; i >= 0; i--) |
| 1542 | e1000_free_tx_resources(adapter, |
| 1543 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1544 | break; |
| 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | return err; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1553 | * @adapter: board private structure |
| 1554 | * |
| 1555 | * Configure the Tx unit of the MAC after a reset. |
| 1556 | **/ |
| 1557 | |
| 1558 | static void |
| 1559 | e1000_configure_tx(struct e1000_adapter *adapter) |
| 1560 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1561 | uint64_t tdba; |
| 1562 | struct e1000_hw *hw = &adapter->hw; |
| 1563 | uint32_t tdlen, tctl, tipg, tarc; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1564 | uint32_t ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
| 1566 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1567 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1568 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1569 | case 1: |
| 1570 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1571 | tdba = adapter->tx_ring[0].dma; |
| 1572 | tdlen = adapter->tx_ring[0].count * |
| 1573 | sizeof(struct e1000_tx_desc); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1574 | E1000_WRITE_REG(hw, TDLEN, tdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1575 | E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 1576 | E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1577 | E1000_WRITE_REG(hw, TDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1578 | E1000_WRITE_REG(hw, TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1579 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1580 | adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1581 | break; |
| 1582 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
| 1584 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 1585 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1586 | if (hw->media_type == e1000_media_type_fiber || |
| 1587 | hw->media_type == e1000_media_type_internal_serdes) |
| 1588 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1589 | else |
| 1590 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1591 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1592 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | case e1000_82542_rev2_0: |
| 1594 | case e1000_82542_rev2_1: |
| 1595 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1596 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1597 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1599 | case e1000_80003es2lan: |
| 1600 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1601 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1602 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1604 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1605 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1606 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1608 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1609 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1610 | E1000_WRITE_REG(hw, TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
| 1612 | /* Set the Tx Interrupt Delay register */ |
| 1613 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1614 | E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 1615 | if (hw->mac_type >= e1000_82540) |
| 1616 | E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | |
| 1618 | /* Program the Transmit Control Register */ |
| 1619 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1620 | tctl = E1000_READ_REG(hw, TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1622 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1624 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1625 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 1626 | tarc = E1000_READ_REG(hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1627 | /* set the speed mode bit, we'll clear it if we're not at |
| 1628 | * gigabit link later */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1629 | tarc |= (1 << 21); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1630 | E1000_WRITE_REG(hw, TARC0, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1631 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 1632 | tarc = E1000_READ_REG(hw, TARC0); |
| 1633 | tarc |= 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1634 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1635 | tarc = E1000_READ_REG(hw, TARC1); |
| 1636 | tarc |= 1; |
| 1637 | E1000_WRITE_REG(hw, TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1640 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
| 1642 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1643 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1644 | |
| 1645 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1646 | if (adapter->tx_int_delay) |
| 1647 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1649 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1651 | else |
| 1652 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1653 | |
| 1654 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1655 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1656 | if (hw->mac_type == e1000_82544 && |
| 1657 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1659 | |
| 1660 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 1661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | /** |
| 1665 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1666 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1667 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | * |
| 1669 | * Returns 0 on success, negative on failure |
| 1670 | **/ |
| 1671 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1672 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1673 | e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1674 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1677 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | |
| 1679 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1680 | rxdr->buffer_info = vmalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1681 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1682 | DPRINTK(PROBE, ERR, |
| 1683 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | return -ENOMEM; |
| 1685 | } |
| 1686 | memset(rxdr->buffer_info, 0, size); |
| 1687 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1688 | size = sizeof(struct e1000_ps_page) * rxdr->count; |
| 1689 | rxdr->ps_page = kmalloc(size, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1690 | if (!rxdr->ps_page) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1691 | vfree(rxdr->buffer_info); |
| 1692 | DPRINTK(PROBE, ERR, |
| 1693 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1694 | return -ENOMEM; |
| 1695 | } |
| 1696 | memset(rxdr->ps_page, 0, size); |
| 1697 | |
| 1698 | size = sizeof(struct e1000_ps_page_dma) * rxdr->count; |
| 1699 | rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1700 | if (!rxdr->ps_page_dma) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1701 | vfree(rxdr->buffer_info); |
| 1702 | kfree(rxdr->ps_page); |
| 1703 | DPRINTK(PROBE, ERR, |
| 1704 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1705 | return -ENOMEM; |
| 1706 | } |
| 1707 | memset(rxdr->ps_page_dma, 0, size); |
| 1708 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1709 | if (adapter->hw.mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1710 | desc_len = sizeof(struct e1000_rx_desc); |
| 1711 | else |
| 1712 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | /* Round up to nearest 4K */ |
| 1715 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1716 | rxdr->size = rxdr->count * desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | E1000_ROUNDUP(rxdr->size, 4096); |
| 1718 | |
| 1719 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1720 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1721 | if (!rxdr->desc) { |
| 1722 | DPRINTK(PROBE, ERR, |
| 1723 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | vfree(rxdr->buffer_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1726 | kfree(rxdr->ps_page); |
| 1727 | kfree(rxdr->ps_page_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | return -ENOMEM; |
| 1729 | } |
| 1730 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1731 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1733 | void *olddesc = rxdr->desc; |
| 1734 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1735 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1736 | "at %p\n", rxdr->size, rxdr->desc); |
| 1737 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1739 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1740 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1742 | DPRINTK(PROBE, ERR, |
| 1743 | "Unable to allocate memory " |
| 1744 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | goto setup_rx_desc_die; |
| 1746 | } |
| 1747 | |
| 1748 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1749 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1750 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1751 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1753 | DPRINTK(PROBE, ERR, |
| 1754 | "Unable to allocate aligned memory " |
| 1755 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1756 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1758 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1760 | } |
| 1761 | } |
| 1762 | memset(rxdr->desc, 0, rxdr->size); |
| 1763 | |
| 1764 | rxdr->next_to_clean = 0; |
| 1765 | rxdr->next_to_use = 0; |
| 1766 | |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1771 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1772 | * (Descriptors) for all queues |
| 1773 | * @adapter: board private structure |
| 1774 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1775 | * Return 0 on success, negative on failure |
| 1776 | **/ |
| 1777 | |
| 1778 | int |
| 1779 | e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
| 1780 | { |
| 1781 | int i, err = 0; |
| 1782 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1783 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1784 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1785 | if (err) { |
| 1786 | DPRINTK(PROBE, ERR, |
| 1787 | "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1788 | for (i-- ; i >= 0; i--) |
| 1789 | e1000_free_rx_resources(adapter, |
| 1790 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1791 | break; |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | return err; |
| 1796 | } |
| 1797 | |
| 1798 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1799 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | * @adapter: Board private structure |
| 1801 | **/ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1802 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 1803 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | static void |
| 1805 | e1000_setup_rctl(struct e1000_adapter *adapter) |
| 1806 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1807 | uint32_t rctl, rfctl; |
| 1808 | uint32_t psrctl = 0; |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1809 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1810 | uint32_t pages = 0; |
| 1811 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | |
| 1813 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1814 | |
| 1815 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1816 | |
| 1817 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1818 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1819 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1820 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1821 | if (adapter->hw.tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | rctl |= E1000_RCTL_SBP; |
| 1823 | else |
| 1824 | rctl &= ~E1000_RCTL_SBP; |
| 1825 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1826 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1827 | rctl &= ~E1000_RCTL_LPE; |
| 1828 | else |
| 1829 | rctl |= E1000_RCTL_LPE; |
| 1830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1832 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1833 | rctl |= E1000_RCTL_BSEX; |
| 1834 | switch (adapter->rx_buffer_len) { |
| 1835 | case E1000_RXBUFFER_256: |
| 1836 | rctl |= E1000_RCTL_SZ_256; |
| 1837 | rctl &= ~E1000_RCTL_BSEX; |
| 1838 | break; |
| 1839 | case E1000_RXBUFFER_512: |
| 1840 | rctl |= E1000_RCTL_SZ_512; |
| 1841 | rctl &= ~E1000_RCTL_BSEX; |
| 1842 | break; |
| 1843 | case E1000_RXBUFFER_1024: |
| 1844 | rctl |= E1000_RCTL_SZ_1024; |
| 1845 | rctl &= ~E1000_RCTL_BSEX; |
| 1846 | break; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1847 | case E1000_RXBUFFER_2048: |
| 1848 | default: |
| 1849 | rctl |= E1000_RCTL_SZ_2048; |
| 1850 | rctl &= ~E1000_RCTL_BSEX; |
| 1851 | break; |
| 1852 | case E1000_RXBUFFER_4096: |
| 1853 | rctl |= E1000_RCTL_SZ_4096; |
| 1854 | break; |
| 1855 | case E1000_RXBUFFER_8192: |
| 1856 | rctl |= E1000_RCTL_SZ_8192; |
| 1857 | break; |
| 1858 | case E1000_RXBUFFER_16384: |
| 1859 | rctl |= E1000_RCTL_SZ_16384; |
| 1860 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1863 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1864 | /* 82571 and greater support packet-split where the protocol |
| 1865 | * header is placed in skb->data and the packet data is |
| 1866 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 1867 | * In the case of a non-split, skb->data is linearly filled, |
| 1868 | * followed by the page buffers. Therefore, skb->data is |
| 1869 | * sized to hold the largest protocol header. |
| 1870 | */ |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 1871 | /* allocations using alloc_page take too long for regular MTU |
| 1872 | * so only enable packet split for jumbo frames */ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1873 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 1874 | if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) && |
| 1875 | PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE)) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1876 | adapter->rx_ps_pages = pages; |
| 1877 | else |
| 1878 | adapter->rx_ps_pages = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1879 | #endif |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1880 | if (adapter->rx_ps_pages) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1881 | /* Configure extra packet-split registers */ |
| 1882 | rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
| 1883 | rfctl |= E1000_RFCTL_EXTEN; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1884 | /* disable packet split support for IPv6 extension headers, |
| 1885 | * because some malformed IPv6 headers can hang the RX */ |
| 1886 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 1887 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 1888 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1889 | E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
| 1890 | |
Auke Kok | 7dfee0c | 2006-06-27 09:07:50 -0700 | [diff] [blame] | 1891 | rctl |= E1000_RCTL_DTYP_PS; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1892 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1893 | psrctl |= adapter->rx_ps_bsize0 >> |
| 1894 | E1000_PSRCTL_BSIZE0_SHIFT; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1895 | |
| 1896 | switch (adapter->rx_ps_pages) { |
| 1897 | case 3: |
| 1898 | psrctl |= PAGE_SIZE << |
| 1899 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 1900 | case 2: |
| 1901 | psrctl |= PAGE_SIZE << |
| 1902 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 1903 | case 1: |
| 1904 | psrctl |= PAGE_SIZE >> |
| 1905 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 1906 | break; |
| 1907 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1908 | |
| 1909 | E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 1913 | } |
| 1914 | |
| 1915 | /** |
| 1916 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1917 | * @adapter: board private structure |
| 1918 | * |
| 1919 | * Configure the Rx unit of the MAC after a reset. |
| 1920 | **/ |
| 1921 | |
| 1922 | static void |
| 1923 | e1000_configure_rx(struct e1000_adapter *adapter) |
| 1924 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1925 | uint64_t rdba; |
| 1926 | struct e1000_hw *hw = &adapter->hw; |
| 1927 | uint32_t rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1928 | |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1929 | if (adapter->rx_ps_pages) { |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 1930 | /* this is a 32 byte descriptor */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1931 | rdlen = adapter->rx_ring[0].count * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1932 | sizeof(union e1000_rx_desc_packet_split); |
| 1933 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 1934 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
| 1935 | } else { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1936 | rdlen = adapter->rx_ring[0].count * |
| 1937 | sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1938 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1939 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | |
| 1942 | /* disable receives while setting up the descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1943 | rctl = E1000_READ_REG(hw, RCTL); |
| 1944 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | |
| 1946 | /* set the Receive Delay Timer Register */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1947 | E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1949 | if (hw->mac_type >= e1000_82540) { |
| 1950 | E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 1951 | if (adapter->itr_setting != 0) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1952 | E1000_WRITE_REG(hw, ITR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | 1000000000 / (adapter->itr * 256)); |
| 1954 | } |
| 1955 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1956 | if (hw->mac_type >= e1000_82571) { |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1957 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1958 | /* Reset delay timers after every interrupt */ |
Auke Kok | 6fc7a7e | 2006-04-14 19:05:12 -0700 | [diff] [blame] | 1959 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1960 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 1961 | /* Auto-Mask interrupts upon ICR access */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1962 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 1963 | E1000_WRITE_REG(hw, IAM, 0xffffffff); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1964 | #endif |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1965 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 1966 | E1000_WRITE_FLUSH(hw); |
| 1967 | } |
| 1968 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1969 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1970 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1971 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1972 | case 1: |
| 1973 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1974 | rdba = adapter->rx_ring[0].dma; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1975 | E1000_WRITE_REG(hw, RDLEN, rdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1976 | E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 1977 | E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1978 | E1000_WRITE_REG(hw, RDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1979 | E1000_WRITE_REG(hw, RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1980 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 1981 | adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1982 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1983 | } |
| 1984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1986 | if (hw->mac_type >= e1000_82543) { |
| 1987 | rxcsum = E1000_READ_REG(hw, RXCSUM); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1988 | if (adapter->rx_csum == TRUE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1989 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 1990 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1991 | /* Enable 82571 IPv4 payload checksum for UDP fragments |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1992 | * Must be used in conjunction with packet-split. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1993 | if ((hw->mac_type >= e1000_82571) && |
| 1994 | (adapter->rx_ps_pages)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1995 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 1996 | } |
| 1997 | } else { |
| 1998 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 1999 | /* don't need to clear IPPCSE as it defaults to 0 */ |
| 2000 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2001 | E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Auke Kok | 21c4d5e | 2006-11-01 08:47:39 -0800 | [diff] [blame] | 2004 | /* enable early receives on 82573, only takes effect if using > 2048 |
| 2005 | * byte total frame size. for example only for jumbo frames */ |
| 2006 | #define E1000_ERT_2048 0x100 |
| 2007 | if (hw->mac_type == e1000_82573) |
| 2008 | E1000_WRITE_REG(hw, ERT, E1000_ERT_2048); |
| 2009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | /* Enable Receives */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2011 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2015 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 2016 | * @adapter: board private structure |
| 2017 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2018 | * |
| 2019 | * Free all transmit software resources |
| 2020 | **/ |
| 2021 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2022 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2023 | e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 2024 | struct e1000_tx_ring *tx_ring) |
| 2025 | { |
| 2026 | struct pci_dev *pdev = adapter->pdev; |
| 2027 | |
| 2028 | e1000_clean_tx_ring(adapter, tx_ring); |
| 2029 | |
| 2030 | vfree(tx_ring->buffer_info); |
| 2031 | tx_ring->buffer_info = NULL; |
| 2032 | |
| 2033 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2034 | |
| 2035 | tx_ring->desc = NULL; |
| 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | * @adapter: board private structure |
| 2041 | * |
| 2042 | * Free all transmit software resources |
| 2043 | **/ |
| 2044 | |
| 2045 | void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2046 | e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2048 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2050 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2051 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2054 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 2056 | struct e1000_buffer *buffer_info) |
| 2057 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2058 | if (buffer_info->dma) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2059 | pci_unmap_page(adapter->pdev, |
| 2060 | buffer_info->dma, |
| 2061 | buffer_info->length, |
| 2062 | PCI_DMA_TODEVICE); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2063 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | } |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2065 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2067 | buffer_info->skb = NULL; |
| 2068 | } |
| 2069 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | /** |
| 2073 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2074 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2075 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | **/ |
| 2077 | |
| 2078 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2079 | e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 2080 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | struct e1000_buffer *buffer_info; |
| 2083 | unsigned long size; |
| 2084 | unsigned int i; |
| 2085 | |
| 2086 | /* Free all the Tx ring sk_buffs */ |
| 2087 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2088 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | buffer_info = &tx_ring->buffer_info[i]; |
| 2090 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2091 | } |
| 2092 | |
| 2093 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2094 | memset(tx_ring->buffer_info, 0, size); |
| 2095 | |
| 2096 | /* Zero out the descriptor ring */ |
| 2097 | |
| 2098 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2099 | |
| 2100 | tx_ring->next_to_use = 0; |
| 2101 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2102 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2104 | writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
| 2105 | writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
| 2106 | } |
| 2107 | |
| 2108 | /** |
| 2109 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2110 | * @adapter: board private structure |
| 2111 | **/ |
| 2112 | |
| 2113 | static void |
| 2114 | e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
| 2115 | { |
| 2116 | int i; |
| 2117 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2118 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2119 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | /** |
| 2123 | * e1000_free_rx_resources - Free Rx Resources |
| 2124 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2125 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | * |
| 2127 | * Free all receive software resources |
| 2128 | **/ |
| 2129 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2130 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2131 | e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 2132 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | struct pci_dev *pdev = adapter->pdev; |
| 2135 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2136 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | |
| 2138 | vfree(rx_ring->buffer_info); |
| 2139 | rx_ring->buffer_info = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2140 | kfree(rx_ring->ps_page); |
| 2141 | rx_ring->ps_page = NULL; |
| 2142 | kfree(rx_ring->ps_page_dma); |
| 2143 | rx_ring->ps_page_dma = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | |
| 2145 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2146 | |
| 2147 | rx_ring->desc = NULL; |
| 2148 | } |
| 2149 | |
| 2150 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2151 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2153 | * |
| 2154 | * Free all receive software resources |
| 2155 | **/ |
| 2156 | |
| 2157 | void |
| 2158 | e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
| 2159 | { |
| 2160 | int i; |
| 2161 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2162 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2163 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2164 | } |
| 2165 | |
| 2166 | /** |
| 2167 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2168 | * @adapter: board private structure |
| 2169 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | **/ |
| 2171 | |
| 2172 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2173 | e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2174 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | struct e1000_buffer *buffer_info; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2177 | struct e1000_ps_page *ps_page; |
| 2178 | struct e1000_ps_page_dma *ps_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | struct pci_dev *pdev = adapter->pdev; |
| 2180 | unsigned long size; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2181 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
| 2183 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2184 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2186 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | pci_unmap_single(pdev, |
| 2188 | buffer_info->dma, |
| 2189 | buffer_info->length, |
| 2190 | PCI_DMA_FROMDEVICE); |
| 2191 | |
| 2192 | dev_kfree_skb(buffer_info->skb); |
| 2193 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2194 | } |
| 2195 | ps_page = &rx_ring->ps_page[i]; |
| 2196 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 2197 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
| 2198 | if (!ps_page->ps_page[j]) break; |
| 2199 | pci_unmap_page(pdev, |
| 2200 | ps_page_dma->ps_page_dma[j], |
| 2201 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 2202 | ps_page_dma->ps_page_dma[j] = 0; |
| 2203 | put_page(ps_page->ps_page[j]); |
| 2204 | ps_page->ps_page[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2209 | memset(rx_ring->buffer_info, 0, size); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2210 | size = sizeof(struct e1000_ps_page) * rx_ring->count; |
| 2211 | memset(rx_ring->ps_page, 0, size); |
| 2212 | size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
| 2213 | memset(rx_ring->ps_page_dma, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | |
| 2215 | /* Zero out the descriptor ring */ |
| 2216 | |
| 2217 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2218 | |
| 2219 | rx_ring->next_to_clean = 0; |
| 2220 | rx_ring->next_to_use = 0; |
| 2221 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2222 | writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
| 2223 | writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
| 2224 | } |
| 2225 | |
| 2226 | /** |
| 2227 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2228 | * @adapter: board private structure |
| 2229 | **/ |
| 2230 | |
| 2231 | static void |
| 2232 | e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
| 2233 | { |
| 2234 | int i; |
| 2235 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2236 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2237 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2241 | * and memory write and invalidate disabled for certain operations |
| 2242 | */ |
| 2243 | static void |
| 2244 | e1000_enter_82542_rst(struct e1000_adapter *adapter) |
| 2245 | { |
| 2246 | struct net_device *netdev = adapter->netdev; |
| 2247 | uint32_t rctl; |
| 2248 | |
| 2249 | e1000_pci_clear_mwi(&adapter->hw); |
| 2250 | |
| 2251 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2252 | rctl |= E1000_RCTL_RST; |
| 2253 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2254 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2255 | mdelay(5); |
| 2256 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2257 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2258 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | static void |
| 2262 | e1000_leave_82542_rst(struct e1000_adapter *adapter) |
| 2263 | { |
| 2264 | struct net_device *netdev = adapter->netdev; |
| 2265 | uint32_t rctl; |
| 2266 | |
| 2267 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2268 | rctl &= ~E1000_RCTL_RST; |
| 2269 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2270 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2271 | mdelay(5); |
| 2272 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2273 | if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | e1000_pci_set_mwi(&adapter->hw); |
| 2275 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2276 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2277 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2278 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2279 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2280 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2286 | * @netdev: network interface device structure |
| 2287 | * @p: pointer to an address structure |
| 2288 | * |
| 2289 | * Returns 0 on success, negative on failure |
| 2290 | **/ |
| 2291 | |
| 2292 | static int |
| 2293 | e1000_set_mac(struct net_device *netdev, void *p) |
| 2294 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2295 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | struct sockaddr *addr = p; |
| 2297 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2298 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | return -EADDRNOTAVAIL; |
| 2300 | |
| 2301 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2302 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2303 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | e1000_enter_82542_rst(adapter); |
| 2305 | |
| 2306 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2307 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 2308 | |
| 2309 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2310 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2311 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2312 | * due to controller reset from the other port. */ |
| 2313 | if (adapter->hw.mac_type == e1000_82571) { |
| 2314 | /* activate the work around */ |
| 2315 | adapter->hw.laa_is_present = 1; |
| 2316 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2317 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2318 | * between the time RAR[0] gets clobbered and the time it |
| 2319 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2320 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2321 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2322 | * RAR[14] */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2323 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2324 | E1000_RAR_ENTRIES - 1); |
| 2325 | } |
| 2326 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2327 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | e1000_leave_82542_rst(adapter); |
| 2329 | |
| 2330 | return 0; |
| 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 2335 | * @netdev: network interface device structure |
| 2336 | * |
| 2337 | * The set_multi entry point is called whenever the multicast address |
| 2338 | * list or the network interface flags are updated. This routine is |
| 2339 | * responsible for configuring the hardware for proper multicast, |
| 2340 | * promiscuous mode, and all-multi behavior. |
| 2341 | **/ |
| 2342 | |
| 2343 | static void |
| 2344 | e1000_set_multi(struct net_device *netdev) |
| 2345 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2346 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | struct e1000_hw *hw = &adapter->hw; |
| 2348 | struct dev_mc_list *mc_ptr; |
| 2349 | uint32_t rctl; |
| 2350 | uint32_t hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2351 | int i, rar_entries = E1000_RAR_ENTRIES; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2352 | int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
| 2353 | E1000_NUM_MTA_REGISTERS_ICH8LAN : |
| 2354 | E1000_NUM_MTA_REGISTERS; |
| 2355 | |
| 2356 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 2357 | rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2359 | /* reserve RAR[14] for LAA over-write work-around */ |
| 2360 | if (adapter->hw.mac_type == e1000_82571) |
| 2361 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2363 | /* Check for Promiscuous and All Multicast modes */ |
| 2364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | rctl = E1000_READ_REG(hw, RCTL); |
| 2366 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2367 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2369 | } else if (netdev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | rctl |= E1000_RCTL_MPE; |
| 2371 | rctl &= ~E1000_RCTL_UPE; |
| 2372 | } else { |
| 2373 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 2374 | } |
| 2375 | |
| 2376 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 2377 | |
| 2378 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2379 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2380 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | e1000_enter_82542_rst(adapter); |
| 2382 | |
| 2383 | /* load the first 14 multicast address into the exact filters 1-14 |
| 2384 | * RAR 0 is used for the station MAC adddress |
| 2385 | * if there are not 14 addresses, go ahead and clear the filters |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2386 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | */ |
| 2388 | mc_ptr = netdev->mc_list; |
| 2389 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2390 | for (i = 1; i < rar_entries; i++) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2391 | if (mc_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | e1000_rar_set(hw, mc_ptr->dmi_addr, i); |
| 2393 | mc_ptr = mc_ptr->next; |
| 2394 | } else { |
| 2395 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2396 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2398 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | /* clear the old settings from the multicast hash table */ |
| 2403 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2404 | for (i = 0; i < mta_reg_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2406 | E1000_WRITE_FLUSH(hw); |
| 2407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | |
| 2409 | /* load any remaining addresses into the hash table */ |
| 2410 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2411 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr); |
| 2413 | e1000_mta_set(hw, hash_value); |
| 2414 | } |
| 2415 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2416 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | e1000_leave_82542_rst(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2421 | * the phy */ |
| 2422 | |
| 2423 | static void |
| 2424 | e1000_update_phy_info(unsigned long data) |
| 2425 | { |
| 2426 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2427 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
| 2428 | } |
| 2429 | |
| 2430 | /** |
| 2431 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2432 | * @data: pointer to adapter cast into an unsigned long |
| 2433 | **/ |
| 2434 | |
| 2435 | static void |
| 2436 | e1000_82547_tx_fifo_stall(unsigned long data) |
| 2437 | { |
| 2438 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2439 | struct net_device *netdev = adapter->netdev; |
| 2440 | uint32_t tctl; |
| 2441 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2442 | if (atomic_read(&adapter->tx_fifo_stall)) { |
| 2443 | if ((E1000_READ_REG(&adapter->hw, TDT) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | E1000_READ_REG(&adapter->hw, TDH)) && |
| 2445 | (E1000_READ_REG(&adapter->hw, TDFT) == |
| 2446 | E1000_READ_REG(&adapter->hw, TDFH)) && |
| 2447 | (E1000_READ_REG(&adapter->hw, TDFTS) == |
| 2448 | E1000_READ_REG(&adapter->hw, TDFHS))) { |
| 2449 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2450 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 2451 | tctl & ~E1000_TCTL_EN); |
| 2452 | E1000_WRITE_REG(&adapter->hw, TDFT, |
| 2453 | adapter->tx_head_addr); |
| 2454 | E1000_WRITE_REG(&adapter->hw, TDFH, |
| 2455 | adapter->tx_head_addr); |
| 2456 | E1000_WRITE_REG(&adapter->hw, TDFTS, |
| 2457 | adapter->tx_head_addr); |
| 2458 | E1000_WRITE_REG(&adapter->hw, TDFHS, |
| 2459 | adapter->tx_head_addr); |
| 2460 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
| 2461 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2462 | |
| 2463 | adapter->tx_fifo_head = 0; |
| 2464 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2465 | netif_wake_queue(netdev); |
| 2466 | } else { |
| 2467 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | /** |
| 2473 | * e1000_watchdog - Timer Call-back |
| 2474 | * @data: pointer to adapter cast into an unsigned long |
| 2475 | **/ |
| 2476 | static void |
| 2477 | e1000_watchdog(unsigned long data) |
| 2478 | { |
| 2479 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2481 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2482 | uint32_t link, tctl; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2483 | int32_t ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2485 | ret_val = e1000_check_for_link(&adapter->hw); |
| 2486 | if ((ret_val == E1000_ERR_PHY) && |
| 2487 | (adapter->hw.phy_type == e1000_phy_igp_3) && |
| 2488 | (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 2489 | /* See e1000_kumeran_lock_loss_workaround() */ |
| 2490 | DPRINTK(LINK, INFO, |
| 2491 | "Gigabit has been disabled, downgrading speed\n"); |
| 2492 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2493 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2494 | if (adapter->hw.mac_type == e1000_82573) { |
| 2495 | e1000_enable_tx_pkt_filtering(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2496 | if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2497 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2500 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
| 2502 | link = !adapter->hw.serdes_link_down; |
| 2503 | else |
| 2504 | link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
| 2505 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2506 | if (link) { |
| 2507 | if (!netif_carrier_ok(netdev)) { |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2508 | boolean_t txb2b = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | e1000_get_speed_and_duplex(&adapter->hw, |
| 2510 | &adapter->link_speed, |
| 2511 | &adapter->link_duplex); |
| 2512 | |
| 2513 | DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n", |
| 2514 | adapter->link_speed, |
| 2515 | adapter->link_duplex == FULL_DUPLEX ? |
| 2516 | "Full Duplex" : "Half Duplex"); |
| 2517 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2518 | /* tweak tx_queue_len according to speed/duplex |
| 2519 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2520 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2521 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2522 | switch (adapter->link_speed) { |
| 2523 | case SPEED_10: |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2524 | txb2b = 0; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2525 | netdev->tx_queue_len = 10; |
| 2526 | adapter->tx_timeout_factor = 8; |
| 2527 | break; |
| 2528 | case SPEED_100: |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2529 | txb2b = 0; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2530 | netdev->tx_queue_len = 100; |
| 2531 | /* maybe add some timeout factor ? */ |
| 2532 | break; |
| 2533 | } |
| 2534 | |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2535 | if ((adapter->hw.mac_type == e1000_82571 || |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2536 | adapter->hw.mac_type == e1000_82572) && |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2537 | txb2b == 0) { |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2538 | uint32_t tarc0; |
| 2539 | tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2540 | tarc0 &= ~(1 << 21); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2541 | E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
| 2542 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2543 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2544 | #ifdef NETIF_F_TSO |
| 2545 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2546 | * some hardware issues */ |
| 2547 | if (!adapter->tso_force && |
| 2548 | adapter->hw.bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2549 | switch (adapter->link_speed) { |
| 2550 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2551 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2552 | DPRINTK(PROBE,INFO, |
| 2553 | "10/100 speed: disabling TSO\n"); |
| 2554 | netdev->features &= ~NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2555 | #ifdef NETIF_F_TSO6 |
| 2556 | netdev->features &= ~NETIF_F_TSO6; |
| 2557 | #endif |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2558 | break; |
| 2559 | case SPEED_1000: |
| 2560 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2561 | #ifdef NETIF_F_TSO6 |
| 2562 | netdev->features |= NETIF_F_TSO6; |
| 2563 | #endif |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2564 | break; |
| 2565 | default: |
| 2566 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2567 | break; |
| 2568 | } |
| 2569 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2570 | #endif |
| 2571 | |
| 2572 | /* enable transmits in the hardware, need to do this |
| 2573 | * after setting TARC0 */ |
| 2574 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2575 | tctl |= E1000_TCTL_EN; |
| 2576 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | netif_carrier_on(netdev); |
| 2579 | netif_wake_queue(netdev); |
| 2580 | mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
| 2581 | adapter->smartspeed = 0; |
| 2582 | } |
| 2583 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2584 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | adapter->link_speed = 0; |
| 2586 | adapter->link_duplex = 0; |
| 2587 | DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
| 2588 | netif_carrier_off(netdev); |
| 2589 | netif_stop_queue(netdev); |
| 2590 | mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2591 | |
| 2592 | /* 80003ES2LAN workaround-- |
| 2593 | * For packet buffer work-around on link down event; |
| 2594 | * disable receives in the ISR and |
| 2595 | * reset device here in the watchdog |
| 2596 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2597 | if (adapter->hw.mac_type == e1000_80003es2lan) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2598 | /* reset device */ |
| 2599 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | e1000_smartspeed(adapter); |
| 2603 | } |
| 2604 | |
| 2605 | e1000_update_stats(adapter); |
| 2606 | |
| 2607 | adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2608 | adapter->tpt_old = adapter->stats.tpt; |
| 2609 | adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2610 | adapter->colc_old = adapter->stats.colc; |
| 2611 | |
| 2612 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2613 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2614 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2615 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2616 | |
| 2617 | e1000_update_adaptive(&adapter->hw); |
| 2618 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2619 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2620 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | /* We've lost link, so the controller stops DMA, |
| 2622 | * but we've got queued Tx work that's never going |
| 2623 | * to get done, so reset controller to flush Tx. |
| 2624 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2625 | adapter->tx_timeout_count++; |
| 2626 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | /* Cause software interrupt to ensure rx ring is cleaned */ |
| 2631 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
| 2632 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2633 | /* Force detection of hung controller every watchdog period */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | adapter->detect_tx_hung = TRUE; |
| 2635 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2636 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2637 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
| 2638 | if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
| 2639 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | /* Reset the timer */ |
| 2642 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 2643 | } |
| 2644 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2645 | enum latency_range { |
| 2646 | lowest_latency = 0, |
| 2647 | low_latency = 1, |
| 2648 | bulk_latency = 2, |
| 2649 | latency_invalid = 255 |
| 2650 | }; |
| 2651 | |
| 2652 | /** |
| 2653 | * e1000_update_itr - update the dynamic ITR value based on statistics |
| 2654 | * Stores a new ITR value based on packets and byte |
| 2655 | * counts during the last interrupt. The advantage of per interrupt |
| 2656 | * computation is faster updates and more accurate ITR for the current |
| 2657 | * traffic pattern. Constants in this function were computed |
| 2658 | * based on theoretical maximum wire speed and thresholds were set based |
| 2659 | * on testing data as well as attempting to minimize response time |
| 2660 | * while increasing bulk throughput. |
| 2661 | * this functionality is controlled by the InterruptThrottleRate module |
| 2662 | * parameter (see e1000_param.c) |
| 2663 | * @adapter: pointer to adapter |
| 2664 | * @itr_setting: current adapter->itr |
| 2665 | * @packets: the number of packets during this measurement interval |
| 2666 | * @bytes: the number of bytes during this measurement interval |
| 2667 | **/ |
| 2668 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2669 | uint16_t itr_setting, |
| 2670 | int packets, |
| 2671 | int bytes) |
| 2672 | { |
| 2673 | unsigned int retval = itr_setting; |
| 2674 | struct e1000_hw *hw = &adapter->hw; |
| 2675 | |
| 2676 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2677 | goto update_itr_done; |
| 2678 | |
| 2679 | if (packets == 0) |
| 2680 | goto update_itr_done; |
| 2681 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2682 | switch (itr_setting) { |
| 2683 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2684 | /* jumbo frames get bulk treatment*/ |
| 2685 | if (bytes/packets > 8000) |
| 2686 | retval = bulk_latency; |
| 2687 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2688 | retval = low_latency; |
| 2689 | break; |
| 2690 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2691 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2692 | /* jumbo frames need bulk latency setting */ |
| 2693 | if (bytes/packets > 8000) |
| 2694 | retval = bulk_latency; |
| 2695 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2696 | retval = bulk_latency; |
| 2697 | else if ((packets > 35)) |
| 2698 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2699 | } else if (bytes/packets > 2000) |
| 2700 | retval = bulk_latency; |
| 2701 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2702 | retval = lowest_latency; |
| 2703 | break; |
| 2704 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2705 | if (bytes > 25000) { |
| 2706 | if (packets > 35) |
| 2707 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2708 | } else if (bytes < 6000) { |
| 2709 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2710 | } |
| 2711 | break; |
| 2712 | } |
| 2713 | |
| 2714 | update_itr_done: |
| 2715 | return retval; |
| 2716 | } |
| 2717 | |
| 2718 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2719 | { |
| 2720 | struct e1000_hw *hw = &adapter->hw; |
| 2721 | uint16_t current_itr; |
| 2722 | uint32_t new_itr = adapter->itr; |
| 2723 | |
| 2724 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2725 | return; |
| 2726 | |
| 2727 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2728 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2729 | current_itr = 0; |
| 2730 | new_itr = 4000; |
| 2731 | goto set_itr_now; |
| 2732 | } |
| 2733 | |
| 2734 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2735 | adapter->tx_itr, |
| 2736 | adapter->total_tx_packets, |
| 2737 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2738 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2739 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2740 | adapter->tx_itr = low_latency; |
| 2741 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2742 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2743 | adapter->rx_itr, |
| 2744 | adapter->total_rx_packets, |
| 2745 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2746 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2747 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2748 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2749 | |
| 2750 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2751 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2752 | switch (current_itr) { |
| 2753 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2754 | case lowest_latency: |
| 2755 | new_itr = 70000; |
| 2756 | break; |
| 2757 | case low_latency: |
| 2758 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2759 | break; |
| 2760 | case bulk_latency: |
| 2761 | new_itr = 4000; |
| 2762 | break; |
| 2763 | default: |
| 2764 | break; |
| 2765 | } |
| 2766 | |
| 2767 | set_itr_now: |
| 2768 | if (new_itr != adapter->itr) { |
| 2769 | /* this attempts to bias the interrupt rate towards Bulk |
| 2770 | * by adding intermediate steps when interrupt rate is |
| 2771 | * increasing */ |
| 2772 | new_itr = new_itr > adapter->itr ? |
| 2773 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2774 | new_itr; |
| 2775 | adapter->itr = new_itr; |
| 2776 | E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256)); |
| 2777 | } |
| 2778 | |
| 2779 | return; |
| 2780 | } |
| 2781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2783 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2784 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2785 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2787 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2788 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2789 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2790 | e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2791 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | { |
| 2793 | #ifdef NETIF_F_TSO |
| 2794 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2795 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | unsigned int i; |
| 2797 | uint32_t cmd_length = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2798 | uint16_t ipcse = 0, tucse, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
| 2800 | int err; |
| 2801 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2802 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | if (skb_header_cloned(skb)) { |
| 2804 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2805 | if (err) |
| 2806 | return err; |
| 2807 | } |
| 2808 | |
| 2809 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2810 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2811 | if (skb->protocol == htons(ETH_P_IP)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2812 | skb->nh.iph->tot_len = 0; |
| 2813 | skb->nh.iph->check = 0; |
| 2814 | skb->h.th->check = |
| 2815 | ~csum_tcpudp_magic(skb->nh.iph->saddr, |
| 2816 | skb->nh.iph->daddr, |
| 2817 | 0, |
| 2818 | IPPROTO_TCP, |
| 2819 | 0); |
| 2820 | cmd_length = E1000_TXD_CMD_IP; |
| 2821 | ipcse = skb->h.raw - skb->data - 1; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2822 | #ifdef NETIF_F_TSO6 |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2823 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2824 | skb->nh.ipv6h->payload_len = 0; |
| 2825 | skb->h.th->check = |
| 2826 | ~csum_ipv6_magic(&skb->nh.ipv6h->saddr, |
| 2827 | &skb->nh.ipv6h->daddr, |
| 2828 | 0, |
| 2829 | IPPROTO_TCP, |
| 2830 | 0); |
| 2831 | ipcse = 0; |
| 2832 | #endif |
| 2833 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | ipcss = skb->nh.raw - skb->data; |
| 2835 | ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | tucss = skb->h.raw - skb->data; |
| 2837 | tucso = (void *)&(skb->h.th->check) - (void *)skb->data; |
| 2838 | tucse = 0; |
| 2839 | |
| 2840 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2841 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2843 | i = tx_ring->next_to_use; |
| 2844 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2845 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | |
| 2847 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2848 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2849 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2850 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2851 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2852 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2853 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2854 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2855 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2856 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2857 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2858 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2859 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2860 | if (++i == tx_ring->count) i = 0; |
| 2861 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2863 | return TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } |
| 2865 | #endif |
| 2866 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2867 | return FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2870 | static boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2871 | e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2872 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | { |
| 2874 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2875 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | unsigned int i; |
| 2877 | uint8_t css; |
| 2878 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 2879 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | css = skb->h.raw - skb->data; |
| 2881 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2882 | i = tx_ring->next_to_use; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2883 | buffer_info = &tx_ring->buffer_info[i]; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2884 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | context_desc->upper_setup.tcp_fields.tucss = css; |
Al Viro | ff1dcad | 2006-11-20 18:07:29 -0800 | [diff] [blame] | 2887 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2889 | context_desc->tcp_seg_setup.data = 0; |
| 2890 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 2891 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2892 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2893 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2894 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2895 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2896 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | |
| 2898 | return TRUE; |
| 2899 | } |
| 2900 | |
| 2901 | return FALSE; |
| 2902 | } |
| 2903 | |
| 2904 | #define E1000_MAX_TXD_PWR 12 |
| 2905 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2906 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2907 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2908 | e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2909 | struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
| 2910 | unsigned int nr_frags, unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | struct e1000_buffer *buffer_info; |
| 2913 | unsigned int len = skb->len; |
| 2914 | unsigned int offset = 0, size, count = 0, i; |
| 2915 | unsigned int f; |
| 2916 | len -= skb->data_len; |
| 2917 | |
| 2918 | i = tx_ring->next_to_use; |
| 2919 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2920 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | buffer_info = &tx_ring->buffer_info[i]; |
| 2922 | size = min(len, max_per_txd); |
| 2923 | #ifdef NETIF_F_TSO |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2924 | /* Workaround for Controller erratum -- |
| 2925 | * descriptor for non-tso packet in a linear SKB that follows a |
| 2926 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2927 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2928 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2929 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2930 | tx_ring->last_tx_tso = 0; |
| 2931 | size -= 4; |
| 2932 | } |
| 2933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | /* Workaround for premature desc write-backs |
| 2935 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2936 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | size -= 4; |
| 2938 | #endif |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2939 | /* work-around for errata 10 and it applies |
| 2940 | * to all controllers in PCI-X mode |
| 2941 | * The fix is to make sure that the first descriptor of a |
| 2942 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 2943 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2944 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2945 | (size > 2015) && count == 0)) |
| 2946 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 2949 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2950 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 2952 | size > 4)) |
| 2953 | size -= 4; |
| 2954 | |
| 2955 | buffer_info->length = size; |
| 2956 | buffer_info->dma = |
| 2957 | pci_map_single(adapter->pdev, |
| 2958 | skb->data + offset, |
| 2959 | size, |
| 2960 | PCI_DMA_TODEVICE); |
| 2961 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2962 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | |
| 2964 | len -= size; |
| 2965 | offset += size; |
| 2966 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2967 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2970 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2971 | struct skb_frag_struct *frag; |
| 2972 | |
| 2973 | frag = &skb_shinfo(skb)->frags[f]; |
| 2974 | len = frag->size; |
| 2975 | offset = frag->page_offset; |
| 2976 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2977 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | buffer_info = &tx_ring->buffer_info[i]; |
| 2979 | size = min(len, max_per_txd); |
| 2980 | #ifdef NETIF_F_TSO |
| 2981 | /* Workaround for premature desc write-backs |
| 2982 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2983 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | size -= 4; |
| 2985 | #endif |
| 2986 | /* Workaround for potential 82544 hang in PCI-X. |
| 2987 | * Avoid terminating buffers within evenly-aligned |
| 2988 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2989 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 2991 | size > 4)) |
| 2992 | size -= 4; |
| 2993 | |
| 2994 | buffer_info->length = size; |
| 2995 | buffer_info->dma = |
| 2996 | pci_map_page(adapter->pdev, |
| 2997 | frag->page, |
| 2998 | offset, |
| 2999 | size, |
| 3000 | PCI_DMA_TODEVICE); |
| 3001 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3002 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
| 3004 | len -= size; |
| 3005 | offset += size; |
| 3006 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3007 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 3012 | tx_ring->buffer_info[i].skb = skb; |
| 3013 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3014 | |
| 3015 | return count; |
| 3016 | } |
| 3017 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3018 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3019 | e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3020 | int tx_flags, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | struct e1000_tx_desc *tx_desc = NULL; |
| 3023 | struct e1000_buffer *buffer_info; |
| 3024 | uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 3025 | unsigned int i; |
| 3026 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3027 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3029 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3030 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3031 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3032 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3033 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3036 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3038 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3039 | } |
| 3040 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3041 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3043 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3044 | } |
| 3045 | |
| 3046 | i = tx_ring->next_to_use; |
| 3047 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3048 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | buffer_info = &tx_ring->buffer_info[i]; |
| 3050 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3051 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3052 | tx_desc->lower.data = |
| 3053 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3054 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3055 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3059 | |
| 3060 | /* Force memory writes to complete before letting h/w |
| 3061 | * know there are new descriptors to fetch. (Only |
| 3062 | * applicable for weak-ordered memory model archs, |
| 3063 | * such as IA-64). */ |
| 3064 | wmb(); |
| 3065 | |
| 3066 | tx_ring->next_to_use = i; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3067 | writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 3068 | /* we need this if more than one processor can write to our tail |
| 3069 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3070 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /** |
| 3074 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 3075 | * The workaround is to avoid queuing a large packet that would span |
| 3076 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 3077 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 3078 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 3079 | * to the beginning of the Tx FIFO. |
| 3080 | **/ |
| 3081 | |
| 3082 | #define E1000_FIFO_HDR 0x10 |
| 3083 | #define E1000_82547_PAD_LEN 0x3E0 |
| 3084 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3085 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3087 | { |
| 3088 | uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 3089 | uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR; |
| 3090 | |
| 3091 | E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR); |
| 3092 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3093 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | goto no_fifo_stall_required; |
| 3095 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3096 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | return 1; |
| 3098 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3099 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3101 | return 1; |
| 3102 | } |
| 3103 | |
| 3104 | no_fifo_stall_required: |
| 3105 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3106 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3108 | return 0; |
| 3109 | } |
| 3110 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3111 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3112 | static int |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3113 | e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3114 | { |
| 3115 | struct e1000_hw *hw = &adapter->hw; |
| 3116 | uint16_t length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3117 | if (vlan_tx_tag_present(skb)) { |
| 3118 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3119 | ( adapter->hw.mng_cookie.status & |
| 3120 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 3121 | return 0; |
| 3122 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 3123 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3124 | struct ethhdr *eth = (struct ethhdr *) skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3125 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 3126 | const struct iphdr *ip = |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3127 | (struct iphdr *)((uint8_t *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3128 | if (IPPROTO_UDP == ip->protocol) { |
| 3129 | struct udphdr *udp = |
| 3130 | (struct udphdr *)((uint8_t *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3131 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3132 | if (ntohs(udp->dest) == 67) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3133 | offset = (uint8_t *)udp + 8 - skb->data; |
| 3134 | length = skb->len - offset; |
| 3135 | |
| 3136 | return e1000_mng_write_dhcp_info(hw, |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3137 | (uint8_t *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3138 | length); |
| 3139 | } |
| 3140 | } |
| 3141 | } |
| 3142 | } |
| 3143 | return 0; |
| 3144 | } |
| 3145 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3146 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3147 | { |
| 3148 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3149 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3150 | |
| 3151 | netif_stop_queue(netdev); |
| 3152 | /* Herbert's original patch had: |
| 3153 | * smp_mb__after_netif_stop_queue(); |
| 3154 | * but since that doesn't exist yet, just open code it. */ |
| 3155 | smp_mb(); |
| 3156 | |
| 3157 | /* We need to check again in a case another CPU has just |
| 3158 | * made room available. */ |
| 3159 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3160 | return -EBUSY; |
| 3161 | |
| 3162 | /* A reprieve! */ |
| 3163 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3164 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3165 | return 0; |
| 3166 | } |
| 3167 | |
| 3168 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3169 | struct e1000_tx_ring *tx_ring, int size) |
| 3170 | { |
| 3171 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3172 | return 0; |
| 3173 | return __e1000_maybe_stop_tx(netdev, size); |
| 3174 | } |
| 3175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 3177 | static int |
| 3178 | e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 3179 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3180 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3181 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3183 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3184 | unsigned int tx_flags = 0; |
| 3185 | unsigned int len = skb->len; |
| 3186 | unsigned long flags; |
| 3187 | unsigned int nr_frags = 0; |
| 3188 | unsigned int mss = 0; |
| 3189 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3190 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | unsigned int f; |
| 3192 | len -= skb->data_len; |
| 3193 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3194 | /* This goes back to the question of how to logically map a tx queue |
| 3195 | * to a flow. Right now, performance is impacted slightly negatively |
| 3196 | * if using multiple tx queues. If the stack breaks away from a |
| 3197 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3198 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3199 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3200 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | dev_kfree_skb_any(skb); |
| 3202 | return NETDEV_TX_OK; |
| 3203 | } |
| 3204 | |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3205 | /* 82571 and newer doesn't need the workaround that limited descriptor |
| 3206 | * length to 4kB */ |
| 3207 | if (adapter->hw.mac_type >= e1000_82571) |
| 3208 | max_per_txd = 8192; |
| 3209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | #ifdef NETIF_F_TSO |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3211 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3212 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | * make sure there is enough room in the FIFO before |
| 3214 | * initiating the DMA for each buffer. The calc is: |
| 3215 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3216 | * overrun the FIFO, adjust the max buffer len if mss |
| 3217 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3218 | if (mss) { |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3219 | uint8_t hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | max_per_txd = min(mss << 2, max_per_txd); |
| 3221 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3222 | |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3223 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3224 | * points to just header, pull a few bytes of payload from |
| 3225 | * frags into skb->data */ |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3226 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3227 | if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) { |
| 3228 | switch (adapter->hw.mac_type) { |
| 3229 | unsigned int pull_size; |
| 3230 | case e1000_82571: |
| 3231 | case e1000_82572: |
| 3232 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3233 | case e1000_ich8lan: |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3234 | pull_size = min((unsigned int)4, skb->data_len); |
| 3235 | if (!__pskb_pull_tail(skb, pull_size)) { |
Auke Kok | a5eafce | 2006-06-27 09:06:49 -0700 | [diff] [blame] | 3236 | DPRINTK(DRV, ERR, |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3237 | "__pskb_pull_tail failed.\n"); |
| 3238 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc70 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3239 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3240 | } |
| 3241 | len = skb->len - skb->data_len; |
| 3242 | break; |
| 3243 | default: |
| 3244 | /* do nothing */ |
| 3245 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3246 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3250 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3251 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3253 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | #else |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3255 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | count++; |
| 3257 | #endif |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3258 | |
| 3259 | #ifdef NETIF_F_TSO |
| 3260 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3261 | if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb)) |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3262 | count++; |
| 3263 | #endif |
| 3264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3266 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3267 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | count++; |
| 3269 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3270 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3271 | * in PCI-X mode, so add one more descriptor to the count |
| 3272 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3273 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3274 | (len > 2015))) |
| 3275 | count++; |
| 3276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3278 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3280 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3281 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | count += nr_frags; |
| 3283 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3284 | |
| 3285 | if (adapter->hw.tx_pkt_filtering && |
| 3286 | (adapter->hw.mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3287 | e1000_transfer_dhcp_info(adapter, skb); |
| 3288 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3289 | local_irq_save(flags); |
| 3290 | if (!spin_trylock(&tx_ring->tx_lock)) { |
| 3291 | /* Collision - tell upper layer to requeue */ |
| 3292 | local_irq_restore(flags); |
| 3293 | return NETDEV_TX_LOCKED; |
| 3294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | |
| 3296 | /* need: count + 2 desc gap to keep tail from touching |
| 3297 | * head, otherwise try next time */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3298 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3299 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | return NETDEV_TX_BUSY; |
| 3301 | } |
| 3302 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3303 | if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
| 3304 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | netif_stop_queue(netdev); |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3306 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3307 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | return NETDEV_TX_BUSY; |
| 3309 | } |
| 3310 | } |
| 3311 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3312 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3314 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3315 | } |
| 3316 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3317 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3318 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3319 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | if (tso < 0) { |
| 3321 | dev_kfree_skb_any(skb); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3322 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | return NETDEV_TX_OK; |
| 3324 | } |
| 3325 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3326 | if (likely(tso)) { |
| 3327 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3329 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3331 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3332 | /* Old method was to assume IPv4 packet by default if TSO was enabled. |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3333 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3334 | * no longer assume, we must. */ |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3335 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3336 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3337 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3338 | e1000_tx_queue(adapter, tx_ring, tx_flags, |
| 3339 | e1000_tx_map(adapter, tx_ring, skb, first, |
| 3340 | max_per_txd, nr_frags, mss)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | |
| 3342 | netdev->trans_start = jiffies; |
| 3343 | |
| 3344 | /* Make sure there is space in the ring for the next send. */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3345 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3347 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | return NETDEV_TX_OK; |
| 3349 | } |
| 3350 | |
| 3351 | /** |
| 3352 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3353 | * @netdev: network interface device structure |
| 3354 | **/ |
| 3355 | |
| 3356 | static void |
| 3357 | e1000_tx_timeout(struct net_device *netdev) |
| 3358 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3359 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | |
| 3361 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3362 | adapter->tx_timeout_count++; |
| 3363 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | static void |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3367 | e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3369 | struct e1000_adapter *adapter = |
| 3370 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3372 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | /** |
| 3376 | * e1000_get_stats - Get System Network Statistics |
| 3377 | * @netdev: network interface device structure |
| 3378 | * |
| 3379 | * Returns the address of the device statistics structure. |
| 3380 | * The statistics are actually updated from the timer callback. |
| 3381 | **/ |
| 3382 | |
| 3383 | static struct net_device_stats * |
| 3384 | e1000_get_stats(struct net_device *netdev) |
| 3385 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3386 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3388 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | return &adapter->net_stats; |
| 3390 | } |
| 3391 | |
| 3392 | /** |
| 3393 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3394 | * @netdev: network interface device structure |
| 3395 | * @new_mtu: new value for maximum frame size |
| 3396 | * |
| 3397 | * Returns 0 on success, negative on failure |
| 3398 | **/ |
| 3399 | |
| 3400 | static int |
| 3401 | e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 3402 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3403 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3405 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3407 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3408 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3409 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3410 | return -EINVAL; |
| 3411 | } |
| 3412 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3413 | /* Adapter-specific max frame size limits. */ |
| 3414 | switch (adapter->hw.mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3415 | case e1000_undefined ... e1000_82542_rev2_1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3416 | case e1000_ich8lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3417 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3418 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3419 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3420 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3421 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3422 | case e1000_82573: |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3423 | /* Jumbo Frames not supported if: |
| 3424 | * - this is not an 82573L device |
| 3425 | * - ASPM is enabled in any way (0x1A bits 3:2) */ |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3426 | e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
| 3427 | &eeprom_data); |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3428 | if ((adapter->hw.device_id != E1000_DEV_ID_82573L) || |
| 3429 | (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3430 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3431 | DPRINTK(PROBE, ERR, |
| 3432 | "Jumbo Frames not supported.\n"); |
| 3433 | return -EINVAL; |
| 3434 | } |
| 3435 | break; |
| 3436 | } |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3437 | /* ERT will be enabled later to enable wire speed receives */ |
| 3438 | |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3439 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3440 | case e1000_82571: |
| 3441 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3442 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3443 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3444 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3445 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3446 | return -EINVAL; |
| 3447 | } |
| 3448 | break; |
| 3449 | default: |
| 3450 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3451 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3454 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3455 | * means we reserve 2 more, this pushes us to allocate from the next |
| 3456 | * larger slab size |
| 3457 | * i.e. RXBUFFER_2048 --> size-4096 slab */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3458 | |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3459 | if (max_frame <= E1000_RXBUFFER_256) |
| 3460 | adapter->rx_buffer_len = E1000_RXBUFFER_256; |
| 3461 | else if (max_frame <= E1000_RXBUFFER_512) |
| 3462 | adapter->rx_buffer_len = E1000_RXBUFFER_512; |
| 3463 | else if (max_frame <= E1000_RXBUFFER_1024) |
| 3464 | adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
| 3465 | else if (max_frame <= E1000_RXBUFFER_2048) |
| 3466 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
| 3467 | else if (max_frame <= E1000_RXBUFFER_4096) |
| 3468 | adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
| 3469 | else if (max_frame <= E1000_RXBUFFER_8192) |
| 3470 | adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
| 3471 | else if (max_frame <= E1000_RXBUFFER_16384) |
| 3472 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
| 3473 | |
| 3474 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3475 | if (!adapter->hw.tbi_compatibility_on && |
| 3476 | ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
| 3477 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3478 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3479 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3480 | netdev->mtu = new_mtu; |
| 3481 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3482 | if (netif_running(netdev)) |
| 3483 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | adapter->hw.max_frame_size = max_frame; |
| 3486 | |
| 3487 | return 0; |
| 3488 | } |
| 3489 | |
| 3490 | /** |
| 3491 | * e1000_update_stats - Update the board statistics counters |
| 3492 | * @adapter: board private structure |
| 3493 | **/ |
| 3494 | |
| 3495 | void |
| 3496 | e1000_update_stats(struct e1000_adapter *adapter) |
| 3497 | { |
| 3498 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3499 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | unsigned long flags; |
| 3501 | uint16_t phy_tmp; |
| 3502 | |
| 3503 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3504 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3505 | /* |
| 3506 | * Prevent stats update while adapter is being reset, or if the pci |
| 3507 | * connection is down. |
| 3508 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3509 | if (adapter->link_speed == 0) |
| 3510 | return; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3511 | if (pdev->error_state && pdev->error_state != pci_channel_io_normal) |
| 3512 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3515 | |
| 3516 | /* these counters are modified from e1000_adjust_tbi_stats, |
| 3517 | * called from the interrupt context, so they must only |
| 3518 | * be written while holding adapter->stats_lock |
| 3519 | */ |
| 3520 | |
| 3521 | adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
| 3522 | adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
| 3523 | adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
| 3524 | adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
| 3525 | adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
| 3526 | adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
| 3527 | adapter->stats.roc += E1000_READ_REG(hw, ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3528 | |
| 3529 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3530 | adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
| 3531 | adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
| 3532 | adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
| 3533 | adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
| 3534 | adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
| 3535 | adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | |
| 3538 | adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
| 3539 | adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
| 3540 | adapter->stats.scc += E1000_READ_REG(hw, SCC); |
| 3541 | adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
| 3542 | adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
| 3543 | adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
| 3544 | adapter->stats.dc += E1000_READ_REG(hw, DC); |
| 3545 | adapter->stats.sec += E1000_READ_REG(hw, SEC); |
| 3546 | adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
| 3547 | adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
| 3548 | adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
| 3549 | adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
| 3550 | adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
| 3551 | adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
| 3552 | adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
| 3553 | adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
| 3554 | adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
| 3555 | adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
| 3556 | adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
| 3557 | adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
| 3558 | adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
| 3559 | adapter->stats.torl += E1000_READ_REG(hw, TORL); |
| 3560 | adapter->stats.torh += E1000_READ_REG(hw, TORH); |
| 3561 | adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
| 3562 | adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
| 3563 | adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3564 | |
| 3565 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3566 | adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
| 3567 | adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
| 3568 | adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
| 3569 | adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
| 3570 | adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
| 3571 | adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
| 3575 | adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
| 3576 | |
| 3577 | /* used for adaptive IFS */ |
| 3578 | |
| 3579 | hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
| 3580 | adapter->stats.tpt += hw->tx_packet_delta; |
| 3581 | hw->collision_delta = E1000_READ_REG(hw, COLC); |
| 3582 | adapter->stats.colc += hw->collision_delta; |
| 3583 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3584 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
| 3586 | adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
| 3587 | adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
| 3588 | adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
| 3589 | adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
| 3590 | adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
| 3591 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3592 | if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3593 | adapter->stats.iac += E1000_READ_REG(hw, IAC); |
| 3594 | adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3595 | |
| 3596 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3597 | adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
| 3598 | adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
| 3599 | adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
| 3600 | adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
| 3601 | adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
| 3602 | adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
| 3603 | adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3604 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3606 | |
| 3607 | /* Fill out the OS statistics structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | adapter->net_stats.rx_packets = adapter->stats.gprc; |
| 3609 | adapter->net_stats.tx_packets = adapter->stats.gptc; |
| 3610 | adapter->net_stats.rx_bytes = adapter->stats.gorcl; |
| 3611 | adapter->net_stats.tx_bytes = adapter->stats.gotcl; |
| 3612 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3613 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3614 | |
| 3615 | /* Rx Errors */ |
| 3616 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3617 | /* RLEC on some newer hardware can be incorrect so build |
| 3618 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3620 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3621 | adapter->stats.ruc + adapter->stats.roc + |
| 3622 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3623 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
| 3624 | adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3626 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3628 | |
| 3629 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3630 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
| 3631 | adapter->net_stats.tx_errors = adapter->stats.txerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3633 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3634 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3635 | if (adapter->hw.bad_tx_carr_stats_fd && |
| 3636 | adapter->link_duplex == FULL_DUPLEX) { |
| 3637 | adapter->net_stats.tx_carrier_errors = 0; |
| 3638 | adapter->stats.tncrs = 0; |
| 3639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | |
| 3641 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3642 | |
| 3643 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3644 | if (hw->media_type == e1000_media_type_copper) { |
| 3645 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3647 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3648 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3649 | } |
| 3650 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3651 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | (hw->phy_type == e1000_phy_m88) && |
| 3653 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3654 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3655 | } |
| 3656 | |
| 3657 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3658 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3659 | #ifdef CONFIG_PCI_MSI |
| 3660 | |
| 3661 | /** |
| 3662 | * e1000_intr_msi - Interrupt Handler |
| 3663 | * @irq: interrupt number |
| 3664 | * @data: pointer to a network interface device structure |
| 3665 | **/ |
| 3666 | |
| 3667 | static |
| 3668 | irqreturn_t e1000_intr_msi(int irq, void *data) |
| 3669 | { |
| 3670 | struct net_device *netdev = data; |
| 3671 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3672 | struct e1000_hw *hw = &adapter->hw; |
| 3673 | #ifndef CONFIG_E1000_NAPI |
| 3674 | int i; |
| 3675 | #endif |
| 3676 | |
| 3677 | /* this code avoids the read of ICR but has to get 1000 interrupts |
| 3678 | * at every link change event before it will notice the change */ |
| 3679 | if (++adapter->detect_link >= 1000) { |
| 3680 | uint32_t icr = E1000_READ_REG(hw, ICR); |
| 3681 | #ifdef CONFIG_E1000_NAPI |
| 3682 | /* read ICR disables interrupts using IAM, so keep up with our |
| 3683 | * enable/disable accounting */ |
| 3684 | atomic_inc(&adapter->irq_sem); |
| 3685 | #endif |
| 3686 | adapter->detect_link = 0; |
| 3687 | if ((icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) && |
| 3688 | (icr & E1000_ICR_INT_ASSERTED)) { |
| 3689 | hw->get_link_status = 1; |
| 3690 | /* 80003ES2LAN workaround-- |
| 3691 | * For packet buffer work-around on link down event; |
| 3692 | * disable receives here in the ISR and |
| 3693 | * reset adapter in watchdog |
| 3694 | */ |
| 3695 | if (netif_carrier_ok(netdev) && |
| 3696 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3697 | /* disable receives */ |
| 3698 | uint32_t rctl = E1000_READ_REG(hw, RCTL); |
| 3699 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3700 | } |
| 3701 | /* guard against interrupt when we're going down */ |
| 3702 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3703 | mod_timer(&adapter->watchdog_timer, |
| 3704 | jiffies + 1); |
| 3705 | } |
| 3706 | } else { |
| 3707 | E1000_WRITE_REG(hw, ICR, (0xffffffff & ~(E1000_ICR_RXSEQ | |
| 3708 | E1000_ICR_LSC))); |
| 3709 | /* bummer we have to flush here, but things break otherwise as |
| 3710 | * some event appears to be lost or delayed and throughput |
| 3711 | * drops. In almost all tests this flush is un-necessary */ |
| 3712 | E1000_WRITE_FLUSH(hw); |
| 3713 | #ifdef CONFIG_E1000_NAPI |
| 3714 | /* Interrupt Auto-Mask (IAM)...upon writing ICR, interrupts are |
| 3715 | * masked. No need for the IMC write, but it does mean we |
| 3716 | * should account for it ASAP. */ |
| 3717 | atomic_inc(&adapter->irq_sem); |
| 3718 | #endif |
| 3719 | } |
| 3720 | |
| 3721 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3722 | if (likely(netif_rx_schedule_prep(netdev))) { |
| 3723 | adapter->total_tx_bytes = 0; |
| 3724 | adapter->total_tx_packets = 0; |
| 3725 | adapter->total_rx_bytes = 0; |
| 3726 | adapter->total_rx_packets = 0; |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3727 | __netif_rx_schedule(netdev); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3728 | } else |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3729 | e1000_irq_enable(adapter); |
| 3730 | #else |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3731 | adapter->total_tx_bytes = 0; |
| 3732 | adapter->total_rx_bytes = 0; |
| 3733 | adapter->total_tx_packets = 0; |
| 3734 | adapter->total_rx_packets = 0; |
| 3735 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3736 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3737 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
| 3738 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
| 3739 | break; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3740 | |
| 3741 | if (likely(adapter->itr_setting & 3)) |
| 3742 | e1000_set_itr(adapter); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3743 | #endif |
| 3744 | |
| 3745 | return IRQ_HANDLED; |
| 3746 | } |
| 3747 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | |
| 3749 | /** |
| 3750 | * e1000_intr - Interrupt Handler |
| 3751 | * @irq: interrupt number |
| 3752 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | **/ |
| 3754 | |
| 3755 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3756 | e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | { |
| 3758 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3759 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3761 | uint32_t rctl, icr = E1000_READ_REG(hw, ICR); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3762 | #ifndef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3763 | int i; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3764 | #endif |
| 3765 | if (unlikely(!icr)) |
| 3766 | return IRQ_NONE; /* Not our interrupt */ |
| 3767 | |
| 3768 | #ifdef CONFIG_E1000_NAPI |
| 3769 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 3770 | * not set, then the adapter didn't send an interrupt */ |
| 3771 | if (unlikely(hw->mac_type >= e1000_82571 && |
| 3772 | !(icr & E1000_ICR_INT_ASSERTED))) |
| 3773 | return IRQ_NONE; |
| 3774 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3775 | /* Interrupt Auto-Mask...upon reading ICR, |
| 3776 | * interrupts are masked. No need for the |
| 3777 | * IMC write, but it does mean we should |
| 3778 | * account for it ASAP. */ |
| 3779 | if (likely(hw->mac_type >= e1000_82571)) |
| 3780 | atomic_inc(&adapter->irq_sem); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 3781 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3783 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3785 | /* 80003ES2LAN workaround-- |
| 3786 | * For packet buffer work-around on link down event; |
| 3787 | * disable receives here in the ISR and |
| 3788 | * reset adapter in watchdog |
| 3789 | */ |
| 3790 | if (netif_carrier_ok(netdev) && |
| 3791 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3792 | /* disable receives */ |
| 3793 | rctl = E1000_READ_REG(hw, RCTL); |
| 3794 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3795 | } |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3796 | /* guard against interrupt when we're going down */ |
| 3797 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3798 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3802 | if (unlikely(hw->mac_type < e1000_82571)) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3803 | /* disable interrupts, without the synchronize_irq bit */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3804 | atomic_inc(&adapter->irq_sem); |
| 3805 | E1000_WRITE_REG(hw, IMC, ~0); |
| 3806 | E1000_WRITE_FLUSH(hw); |
| 3807 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3808 | if (likely(netif_rx_schedule_prep(netdev))) { |
| 3809 | adapter->total_tx_bytes = 0; |
| 3810 | adapter->total_tx_packets = 0; |
| 3811 | adapter->total_rx_bytes = 0; |
| 3812 | adapter->total_rx_packets = 0; |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3813 | __netif_rx_schedule(netdev); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3814 | } else |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3815 | /* this really should not happen! if it does it is basically a |
| 3816 | * bug, but not a hard error, so enable ints and continue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3817 | e1000_irq_enable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3818 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | /* Writing IMC and IMS is needed for 82547. |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3820 | * Due to Hub Link bus being occupied, an interrupt |
| 3821 | * de-assertion message is not able to be sent. |
| 3822 | * When an interrupt assertion message is generated later, |
| 3823 | * two messages are re-ordered and sent out. |
| 3824 | * That causes APIC to think 82547 is in de-assertion |
| 3825 | * state, while 82547 is in assertion state, resulting |
| 3826 | * in dead lock. Writing IMC forces 82547 into |
| 3827 | * de-assertion state. |
| 3828 | */ |
| 3829 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | atomic_inc(&adapter->irq_sem); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3831 | E1000_WRITE_REG(hw, IMC, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3834 | adapter->total_tx_bytes = 0; |
| 3835 | adapter->total_rx_bytes = 0; |
| 3836 | adapter->total_tx_packets = 0; |
| 3837 | adapter->total_rx_packets = 0; |
| 3838 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3839 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3840 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3841 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | break; |
| 3843 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3844 | if (likely(adapter->itr_setting & 3)) |
| 3845 | e1000_set_itr(adapter); |
| 3846 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3847 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | e1000_irq_enable(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3849 | |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3850 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | return IRQ_HANDLED; |
| 3852 | } |
| 3853 | |
| 3854 | #ifdef CONFIG_E1000_NAPI |
| 3855 | /** |
| 3856 | * e1000_clean - NAPI Rx polling callback |
| 3857 | * @adapter: board private structure |
| 3858 | **/ |
| 3859 | |
| 3860 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3861 | e1000_clean(struct net_device *poll_dev, int *budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3863 | struct e1000_adapter *adapter; |
| 3864 | int work_to_do = min(*budget, poll_dev->quota); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3865 | int tx_cleaned = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3866 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3867 | /* Must NOT use netdev_priv macro here. */ |
| 3868 | adapter = poll_dev->priv; |
| 3869 | |
| 3870 | /* Keep link state information with original netdev */ |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3871 | if (!netif_carrier_ok(poll_dev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3872 | goto quit_polling; |
| 3873 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3874 | /* e1000_clean is called per-cpu. This lock protects |
| 3875 | * tx_ring[0] from being cleaned by multiple cpus |
| 3876 | * simultaneously. A failure obtaining the lock means |
| 3877 | * tx_ring[0] is currently being cleaned anyway. */ |
| 3878 | if (spin_trylock(&adapter->tx_queue_lock)) { |
| 3879 | tx_cleaned = e1000_clean_tx_irq(adapter, |
| 3880 | &adapter->tx_ring[0]); |
| 3881 | spin_unlock(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3882 | } |
| 3883 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3884 | adapter->clean_rx(adapter, &adapter->rx_ring[0], |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3885 | &work_done, work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | |
| 3887 | *budget -= work_done; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3888 | poll_dev->quota -= work_done; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3889 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 3890 | /* If no Tx and not enough Rx work done, exit the polling mode */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3891 | if ((!tx_cleaned && (work_done == 0)) || |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3892 | !netif_running(poll_dev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3893 | quit_polling: |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3894 | if (likely(adapter->itr_setting & 3)) |
| 3895 | e1000_set_itr(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3896 | netif_rx_complete(poll_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | e1000_irq_enable(adapter); |
| 3898 | return 0; |
| 3899 | } |
| 3900 | |
| 3901 | return 1; |
| 3902 | } |
| 3903 | |
| 3904 | #endif |
| 3905 | /** |
| 3906 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3907 | * @adapter: board private structure |
| 3908 | **/ |
| 3909 | |
| 3910 | static boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3911 | e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3912 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | struct net_device *netdev = adapter->netdev; |
| 3915 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3916 | struct e1000_buffer *buffer_info; |
| 3917 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3918 | #ifdef CONFIG_E1000_NAPI |
| 3919 | unsigned int count = 0; |
| 3920 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | boolean_t cleaned = FALSE; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3922 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | |
| 3924 | i = tx_ring->next_to_clean; |
| 3925 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3926 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3927 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3928 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3929 | for (cleaned = FALSE; !cleaned; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3931 | buffer_info = &tx_ring->buffer_info[i]; |
| 3932 | cleaned = (i == eop); |
| 3933 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3934 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3935 | struct sk_buff *skb = buffer_info->skb; |
| 3936 | unsigned int segs = skb_shinfo(skb)->gso_segs; |
| 3937 | total_tx_packets += segs; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3938 | total_tx_packets++; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3939 | total_tx_bytes += skb->len; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3940 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3941 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3942 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3944 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3948 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3949 | #ifdef CONFIG_E1000_NAPI |
| 3950 | #define E1000_TX_WEIGHT 64 |
| 3951 | /* weight of a sort for tx, to avoid endless transmit cleanup */ |
| 3952 | if (count++ == E1000_TX_WEIGHT) break; |
| 3953 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | tx_ring->next_to_clean = i; |
| 3957 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3958 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3959 | if (unlikely(cleaned && netif_carrier_ok(netdev) && |
| 3960 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 3961 | /* Make sure that anybody stopping the queue after this |
| 3962 | * sees the new next_to_clean. |
| 3963 | */ |
| 3964 | smp_mb(); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3965 | if (netif_queue_stopped(netdev)) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3966 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3967 | ++adapter->restart_queue; |
| 3968 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3969 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3970 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3971 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3972 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | * check with the clearing of time_stamp and movement of i */ |
| 3974 | adapter->detect_tx_hung = FALSE; |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3975 | if (tx_ring->buffer_info[eop].dma && |
| 3976 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 3977 | (adapter->tx_timeout_factor * HZ)) |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3978 | && !(E1000_READ_REG(&adapter->hw, STATUS) & |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3979 | E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3980 | |
| 3981 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 3982 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3983 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3984 | " TDH <%x>\n" |
| 3985 | " TDT <%x>\n" |
| 3986 | " next_to_use <%x>\n" |
| 3987 | " next_to_clean <%x>\n" |
| 3988 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3989 | " time_stamp <%lx>\n" |
| 3990 | " next_to_watch <%x>\n" |
| 3991 | " jiffies <%lx>\n" |
| 3992 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3993 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 3994 | sizeof(struct e1000_tx_ring)), |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3995 | readl(adapter->hw.hw_addr + tx_ring->tdh), |
| 3996 | readl(adapter->hw.hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3997 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3998 | tx_ring->next_to_clean, |
| 3999 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4000 | eop, |
| 4001 | jiffies, |
| 4002 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4004 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4006 | adapter->total_tx_bytes += total_tx_bytes; |
| 4007 | adapter->total_tx_packets += total_tx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | return cleaned; |
| 4009 | } |
| 4010 | |
| 4011 | /** |
| 4012 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4013 | * @adapter: board private structure |
| 4014 | * @status_err: receive descriptor status and error fields |
| 4015 | * @csum: receive descriptor csum field |
| 4016 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | **/ |
| 4018 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 4019 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | e1000_rx_checksum(struct e1000_adapter *adapter, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4021 | uint32_t status_err, uint32_t csum, |
| 4022 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4024 | uint16_t status = (uint16_t)status_err; |
| 4025 | uint8_t errors = (uint8_t)(status_err >> 24); |
| 4026 | skb->ip_summed = CHECKSUM_NONE; |
| 4027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | /* 82543 or newer only */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4029 | if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4031 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4032 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4033 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4034 | /* let the stack verify checksum errors */ |
| 4035 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | return; |
| 4037 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4038 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4039 | if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
| 4040 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4041 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4043 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4044 | return; |
| 4045 | } |
| 4046 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4047 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | /* TCP checksum is good */ |
| 4049 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4050 | } else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
| 4051 | /* IP fragment with UDP payload */ |
| 4052 | /* Hardware complements the payload checksum, so we undo it |
| 4053 | * and then put the value in host order for further stack use. |
| 4054 | */ |
| 4055 | csum = ntohl(csum ^ 0xFFFF); |
| 4056 | skb->csum = csum; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 4057 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4059 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4063 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | * @adapter: board private structure |
| 4065 | **/ |
| 4066 | |
| 4067 | static boolean_t |
| 4068 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4069 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4070 | struct e1000_rx_ring *rx_ring, |
| 4071 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4073 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4074 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | #endif |
| 4076 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | struct net_device *netdev = adapter->netdev; |
| 4078 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4079 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4080 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | unsigned long flags; |
| 4082 | uint32_t length; |
| 4083 | uint8_t last_byte; |
| 4084 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4085 | int cleaned_count = 0; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4086 | boolean_t cleaned = FALSE; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4087 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | |
| 4089 | i = rx_ring->next_to_clean; |
| 4090 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4091 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4093 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4094 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4095 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4098 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | break; |
| 4100 | (*work_done)++; |
| 4101 | #endif |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4102 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4103 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4104 | buffer_info->skb = NULL; |
| 4105 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4106 | prefetch(skb->data - NET_IP_ALIGN); |
| 4107 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4108 | if (++i == rx_ring->count) i = 0; |
| 4109 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4110 | prefetch(next_rxd); |
| 4111 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4112 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4113 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4114 | cleaned = TRUE; |
| 4115 | cleaned_count++; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4116 | pci_unmap_single(pdev, |
| 4117 | buffer_info->dma, |
| 4118 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | PCI_DMA_FROMDEVICE); |
| 4120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4121 | length = le16_to_cpu(rx_desc->length); |
| 4122 | |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4123 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
| 4124 | /* All receives must fit into a single buffer */ |
| 4125 | E1000_DBG("%s: Receive packet consumed multiple" |
| 4126 | " buffers\n", netdev->name); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 4127 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4128 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | goto next_desc; |
| 4130 | } |
| 4131 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4132 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | last_byte = *(skb->data + length - 1); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4134 | if (TBI_ACCEPT(&adapter->hw, status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | rx_desc->errors, length, last_byte)) { |
| 4136 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4137 | e1000_tbi_adjust_stats(&adapter->hw, |
| 4138 | &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | length, skb->data); |
| 4140 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4141 | flags); |
| 4142 | length--; |
| 4143 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4144 | /* recycle */ |
| 4145 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | goto next_desc; |
| 4147 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4150 | /* adjust length to remove Ethernet CRC, this must be |
| 4151 | * done after the TBI_ACCEPT workaround above */ |
| 4152 | length -= 4; |
| 4153 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4154 | /* probably a little skewed due to removing CRC */ |
| 4155 | total_rx_bytes += length; |
| 4156 | total_rx_packets++; |
| 4157 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4158 | /* code added for copybreak, this should improve |
| 4159 | * performance for small packets with large amounts |
| 4160 | * of reassembly being done in the stack */ |
| 4161 | #define E1000_CB_LENGTH 256 |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4162 | if (length < E1000_CB_LENGTH) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4163 | struct sk_buff *new_skb = |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4164 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4165 | if (new_skb) { |
| 4166 | skb_reserve(new_skb, NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4167 | memcpy(new_skb->data - NET_IP_ALIGN, |
| 4168 | skb->data - NET_IP_ALIGN, |
| 4169 | length + NET_IP_ALIGN); |
| 4170 | /* save the skb in buffer_info as good */ |
| 4171 | buffer_info->skb = skb; |
| 4172 | skb = new_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4173 | } |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4174 | /* else just continue with the old one */ |
| 4175 | } |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4176 | /* end copybreak code */ |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4177 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | |
| 4179 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4180 | e1000_rx_checksum(adapter, |
| 4181 | (uint32_t)(status) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4182 | ((uint32_t)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4183 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | skb->protocol = eth_type_trans(skb, netdev); |
| 4186 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4187 | if (unlikely(adapter->vlgrp && |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4188 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4190 | le16_to_cpu(rx_desc->special) & |
| 4191 | E1000_RXD_SPC_VLAN_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | } else { |
| 4193 | netif_receive_skb(skb); |
| 4194 | } |
| 4195 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4196 | if (unlikely(adapter->vlgrp && |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4197 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 4199 | le16_to_cpu(rx_desc->special) & |
| 4200 | E1000_RXD_SPC_VLAN_MASK); |
| 4201 | } else { |
| 4202 | netif_rx(skb); |
| 4203 | } |
| 4204 | #endif /* CONFIG_E1000_NAPI */ |
| 4205 | netdev->last_rx = jiffies; |
| 4206 | |
| 4207 | next_desc: |
| 4208 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4210 | /* return some buffers to hardware, one at a time is too slow */ |
| 4211 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4212 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4213 | cleaned_count = 0; |
| 4214 | } |
| 4215 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4216 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4217 | rx_desc = next_rxd; |
| 4218 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4221 | |
| 4222 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4223 | if (cleaned_count) |
| 4224 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4226 | adapter->total_rx_packets += total_rx_packets; |
| 4227 | adapter->total_rx_bytes += total_rx_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | return cleaned; |
| 4229 | } |
| 4230 | |
| 4231 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4232 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 4233 | * @adapter: board private structure |
| 4234 | **/ |
| 4235 | |
| 4236 | static boolean_t |
| 4237 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4238 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4239 | struct e1000_rx_ring *rx_ring, |
| 4240 | int *work_done, int work_to_do) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4241 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4242 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4243 | struct e1000_rx_ring *rx_ring) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4244 | #endif |
| 4245 | { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4246 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4247 | struct net_device *netdev = adapter->netdev; |
| 4248 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4249 | struct e1000_buffer *buffer_info, *next_buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4250 | struct e1000_ps_page *ps_page; |
| 4251 | struct e1000_ps_page_dma *ps_page_dma; |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4252 | struct sk_buff *skb; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4253 | unsigned int i, j; |
| 4254 | uint32_t length, staterr; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4255 | int cleaned_count = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4256 | boolean_t cleaned = FALSE; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4257 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4258 | |
| 4259 | i = rx_ring->next_to_clean; |
| 4260 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4261 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4262 | buffer_info = &rx_ring->buffer_info[i]; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4263 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4264 | while (staterr & E1000_RXD_STAT_DD) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4265 | ps_page = &rx_ring->ps_page[i]; |
| 4266 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4267 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4268 | if (unlikely(*work_done >= work_to_do)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4269 | break; |
| 4270 | (*work_done)++; |
| 4271 | #endif |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4272 | skb = buffer_info->skb; |
| 4273 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4274 | /* in the packet split case this is header only */ |
| 4275 | prefetch(skb->data - NET_IP_ALIGN); |
| 4276 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4277 | if (++i == rx_ring->count) i = 0; |
| 4278 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4279 | prefetch(next_rxd); |
| 4280 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4281 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4282 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4283 | cleaned = TRUE; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4284 | cleaned_count++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4285 | pci_unmap_single(pdev, buffer_info->dma, |
| 4286 | buffer_info->length, |
| 4287 | PCI_DMA_FROMDEVICE); |
| 4288 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4289 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4290 | E1000_DBG("%s: Packet Split buffers didn't pick up" |
| 4291 | " the full packet\n", netdev->name); |
| 4292 | dev_kfree_skb_irq(skb); |
| 4293 | goto next_desc; |
| 4294 | } |
| 4295 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4296 | if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4297 | dev_kfree_skb_irq(skb); |
| 4298 | goto next_desc; |
| 4299 | } |
| 4300 | |
| 4301 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 4302 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4303 | if (unlikely(!length)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4304 | E1000_DBG("%s: Last part of the packet spanning" |
| 4305 | " multiple descriptors\n", netdev->name); |
| 4306 | dev_kfree_skb_irq(skb); |
| 4307 | goto next_desc; |
| 4308 | } |
| 4309 | |
| 4310 | /* Good Receive */ |
| 4311 | skb_put(skb, length); |
| 4312 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4313 | { |
| 4314 | /* this looks ugly, but it seems compiler issues make it |
| 4315 | more efficient than reusing j */ |
| 4316 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 4317 | |
| 4318 | /* page alloc/put takes too long and effects small packet |
| 4319 | * throughput, so unsplit small packets and save the alloc/put*/ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4320 | if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) { |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4321 | u8 *vaddr; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 4322 | /* there is no documentation about how to call |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4323 | * kmap_atomic, so we can't hold the mapping |
| 4324 | * very long */ |
| 4325 | pci_dma_sync_single_for_cpu(pdev, |
| 4326 | ps_page_dma->ps_page_dma[0], |
| 4327 | PAGE_SIZE, |
| 4328 | PCI_DMA_FROMDEVICE); |
| 4329 | vaddr = kmap_atomic(ps_page->ps_page[0], |
| 4330 | KM_SKB_DATA_SOFTIRQ); |
| 4331 | memcpy(skb->tail, vaddr, l1); |
| 4332 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 4333 | pci_dma_sync_single_for_device(pdev, |
| 4334 | ps_page_dma->ps_page_dma[0], |
| 4335 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4336 | /* remove the CRC */ |
| 4337 | l1 -= 4; |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4338 | skb_put(skb, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4339 | goto copydone; |
| 4340 | } /* if */ |
| 4341 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4342 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4343 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4344 | if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4345 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4346 | pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
| 4347 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 4348 | ps_page_dma->ps_page_dma[j] = 0; |
Jeff Kirsher | 329bfd0 | 2006-03-02 18:20:02 -0800 | [diff] [blame] | 4349 | skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
| 4350 | length); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4351 | ps_page->ps_page[j] = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4352 | skb->len += length; |
| 4353 | skb->data_len += length; |
Auke Kok | 5d51b80 | 2006-04-14 19:05:06 -0700 | [diff] [blame] | 4354 | skb->truesize += length; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4355 | } |
| 4356 | |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4357 | /* strip the ethernet crc, problem is we're using pages now so |
| 4358 | * this whole operation can get a little cpu intensive */ |
| 4359 | pskb_trim(skb, skb->len - 4); |
| 4360 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4361 | copydone: |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4362 | total_rx_bytes += skb->len; |
| 4363 | total_rx_packets++; |
| 4364 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4365 | e1000_rx_checksum(adapter, staterr, |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4366 | le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4367 | skb->protocol = eth_type_trans(skb, netdev); |
| 4368 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4369 | if (likely(rx_desc->wb.upper.header_status & |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4370 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4371 | adapter->rx_hdr_split++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4372 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4373 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4374 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4375 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4376 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4377 | } else { |
| 4378 | netif_receive_skb(skb); |
| 4379 | } |
| 4380 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4381 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4382 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4383 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4384 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4385 | } else { |
| 4386 | netif_rx(skb); |
| 4387 | } |
| 4388 | #endif /* CONFIG_E1000_NAPI */ |
| 4389 | netdev->last_rx = jiffies; |
| 4390 | |
| 4391 | next_desc: |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4392 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4393 | buffer_info->skb = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4394 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4395 | /* return some buffers to hardware, one at a time is too slow */ |
| 4396 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4397 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4398 | cleaned_count = 0; |
| 4399 | } |
| 4400 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4401 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4402 | rx_desc = next_rxd; |
| 4403 | buffer_info = next_buffer; |
| 4404 | |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4405 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4406 | } |
| 4407 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4408 | |
| 4409 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4410 | if (cleaned_count) |
| 4411 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4412 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4413 | adapter->total_rx_packets += total_rx_packets; |
| 4414 | adapter->total_rx_bytes += total_rx_bytes; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4415 | return cleaned; |
| 4416 | } |
| 4417 | |
| 4418 | /** |
| 4419 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | * @adapter: address of board private structure |
| 4421 | **/ |
| 4422 | |
| 4423 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4424 | e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4425 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4426 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | struct net_device *netdev = adapter->netdev; |
| 4429 | struct pci_dev *pdev = adapter->pdev; |
| 4430 | struct e1000_rx_desc *rx_desc; |
| 4431 | struct e1000_buffer *buffer_info; |
| 4432 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4433 | unsigned int i; |
| 4434 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | |
| 4436 | i = rx_ring->next_to_use; |
| 4437 | buffer_info = &rx_ring->buffer_info[i]; |
| 4438 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4439 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4440 | skb = buffer_info->skb; |
| 4441 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4442 | skb_trim(skb, 0); |
| 4443 | goto map_skb; |
| 4444 | } |
| 4445 | |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4446 | skb = netdev_alloc_skb(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4447 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4449 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | break; |
| 4451 | } |
| 4452 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4453 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4455 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4456 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 4457 | "at %p\n", bufsz, skb->data); |
| 4458 | /* Try again, without freeing the previous */ |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4459 | skb = netdev_alloc_skb(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4460 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | if (!skb) { |
| 4462 | dev_kfree_skb(oldskb); |
| 4463 | break; |
| 4464 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4467 | /* give up */ |
| 4468 | dev_kfree_skb(skb); |
| 4469 | dev_kfree_skb(oldskb); |
| 4470 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4472 | |
| 4473 | /* Use new allocation */ |
| 4474 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4477 | * this will result in a 16 byte aligned IP header after |
| 4478 | * the 14 byte MAC header is removed |
| 4479 | */ |
| 4480 | skb_reserve(skb, NET_IP_ALIGN); |
| 4481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | buffer_info->skb = skb; |
| 4483 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4484 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | buffer_info->dma = pci_map_single(pdev, |
| 4486 | skb->data, |
| 4487 | adapter->rx_buffer_len, |
| 4488 | PCI_DMA_FROMDEVICE); |
| 4489 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4490 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4491 | if (!e1000_check_64k_bound(adapter, |
| 4492 | (void *)(unsigned long)buffer_info->dma, |
| 4493 | adapter->rx_buffer_len)) { |
| 4494 | DPRINTK(RX_ERR, ERR, |
| 4495 | "dma align check failed: %u bytes at %p\n", |
| 4496 | adapter->rx_buffer_len, |
| 4497 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | dev_kfree_skb(skb); |
| 4499 | buffer_info->skb = NULL; |
| 4500 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4501 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | adapter->rx_buffer_len, |
| 4503 | PCI_DMA_FROMDEVICE); |
| 4504 | |
| 4505 | break; /* while !buffer_info->skb */ |
| 4506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4508 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4509 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4510 | if (unlikely(++i == rx_ring->count)) |
| 4511 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | buffer_info = &rx_ring->buffer_info[i]; |
| 4513 | } |
| 4514 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4515 | if (likely(rx_ring->next_to_use != i)) { |
| 4516 | rx_ring->next_to_use = i; |
| 4517 | if (unlikely(i-- == 0)) |
| 4518 | i = (rx_ring->count - 1); |
| 4519 | |
| 4520 | /* Force memory writes to complete before letting h/w |
| 4521 | * know there are new descriptors to fetch. (Only |
| 4522 | * applicable for weak-ordered memory model archs, |
| 4523 | * such as IA-64). */ |
| 4524 | wmb(); |
| 4525 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4526 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4530 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 4531 | * @adapter: address of board private structure |
| 4532 | **/ |
| 4533 | |
| 4534 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4535 | e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4536 | struct e1000_rx_ring *rx_ring, |
| 4537 | int cleaned_count) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4538 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4539 | struct net_device *netdev = adapter->netdev; |
| 4540 | struct pci_dev *pdev = adapter->pdev; |
| 4541 | union e1000_rx_desc_packet_split *rx_desc; |
| 4542 | struct e1000_buffer *buffer_info; |
| 4543 | struct e1000_ps_page *ps_page; |
| 4544 | struct e1000_ps_page_dma *ps_page_dma; |
| 4545 | struct sk_buff *skb; |
| 4546 | unsigned int i, j; |
| 4547 | |
| 4548 | i = rx_ring->next_to_use; |
| 4549 | buffer_info = &rx_ring->buffer_info[i]; |
| 4550 | ps_page = &rx_ring->ps_page[i]; |
| 4551 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4552 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4553 | while (cleaned_count--) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4554 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 4555 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4556 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4557 | if (j < adapter->rx_ps_pages) { |
| 4558 | if (likely(!ps_page->ps_page[j])) { |
| 4559 | ps_page->ps_page[j] = |
| 4560 | alloc_page(GFP_ATOMIC); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4561 | if (unlikely(!ps_page->ps_page[j])) { |
| 4562 | adapter->alloc_rx_buff_failed++; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4563 | goto no_buffers; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4564 | } |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4565 | ps_page_dma->ps_page_dma[j] = |
| 4566 | pci_map_page(pdev, |
| 4567 | ps_page->ps_page[j], |
| 4568 | 0, PAGE_SIZE, |
| 4569 | PCI_DMA_FROMDEVICE); |
| 4570 | } |
| 4571 | /* Refresh the desc even if buffer_addrs didn't |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4572 | * change because each write-back erases |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4573 | * this info. |
| 4574 | */ |
| 4575 | rx_desc->read.buffer_addr[j+1] = |
| 4576 | cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
| 4577 | } else |
| 4578 | rx_desc->read.buffer_addr[j+1] = ~0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4579 | } |
| 4580 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4581 | skb = netdev_alloc_skb(netdev, |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4582 | adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4583 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4584 | if (unlikely(!skb)) { |
| 4585 | adapter->alloc_rx_buff_failed++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4586 | break; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4587 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4588 | |
| 4589 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4590 | * this will result in a 16 byte aligned IP header after |
| 4591 | * the 14 byte MAC header is removed |
| 4592 | */ |
| 4593 | skb_reserve(skb, NET_IP_ALIGN); |
| 4594 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4595 | buffer_info->skb = skb; |
| 4596 | buffer_info->length = adapter->rx_ps_bsize0; |
| 4597 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4598 | adapter->rx_ps_bsize0, |
| 4599 | PCI_DMA_FROMDEVICE); |
| 4600 | |
| 4601 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 4602 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4603 | if (unlikely(++i == rx_ring->count)) i = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4604 | buffer_info = &rx_ring->buffer_info[i]; |
| 4605 | ps_page = &rx_ring->ps_page[i]; |
| 4606 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4607 | } |
| 4608 | |
| 4609 | no_buffers: |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4610 | if (likely(rx_ring->next_to_use != i)) { |
| 4611 | rx_ring->next_to_use = i; |
| 4612 | if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
| 4613 | |
| 4614 | /* Force memory writes to complete before letting h/w |
| 4615 | * know there are new descriptors to fetch. (Only |
| 4616 | * applicable for weak-ordered memory model archs, |
| 4617 | * such as IA-64). */ |
| 4618 | wmb(); |
| 4619 | /* Hardware increments by 16 bytes, but packet split |
| 4620 | * descriptors are 32 bytes...so we increment tail |
| 4621 | * twice as much. |
| 4622 | */ |
| 4623 | writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
| 4624 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4629 | * @adapter: |
| 4630 | **/ |
| 4631 | |
| 4632 | static void |
| 4633 | e1000_smartspeed(struct e1000_adapter *adapter) |
| 4634 | { |
| 4635 | uint16_t phy_status; |
| 4636 | uint16_t phy_ctrl; |
| 4637 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4638 | if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
| 4640 | return; |
| 4641 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4642 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | /* If Master/Slave config fault is asserted twice, |
| 4644 | * we assume back-to-back */ |
| 4645 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4646 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4648 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4650 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
| 4652 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
| 4653 | phy_ctrl); |
| 4654 | adapter->smartspeed++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4655 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
| 4657 | &phy_ctrl)) { |
| 4658 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4659 | MII_CR_RESTART_AUTO_NEG); |
| 4660 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
| 4661 | phy_ctrl); |
| 4662 | } |
| 4663 | } |
| 4664 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4665 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | /* If still no link, perhaps using 2/3 pair cable */ |
| 4667 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
| 4668 | phy_ctrl |= CR_1000T_MS_ENABLE; |
| 4669 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4670 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
| 4672 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4673 | MII_CR_RESTART_AUTO_NEG); |
| 4674 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
| 4675 | } |
| 4676 | } |
| 4677 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4678 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | adapter->smartspeed = 0; |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * e1000_ioctl - |
| 4684 | * @netdev: |
| 4685 | * @ifreq: |
| 4686 | * @cmd: |
| 4687 | **/ |
| 4688 | |
| 4689 | static int |
| 4690 | e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4691 | { |
| 4692 | switch (cmd) { |
| 4693 | case SIOCGMIIPHY: |
| 4694 | case SIOCGMIIREG: |
| 4695 | case SIOCSMIIREG: |
| 4696 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4697 | default: |
| 4698 | return -EOPNOTSUPP; |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | /** |
| 4703 | * e1000_mii_ioctl - |
| 4704 | * @netdev: |
| 4705 | * @ifreq: |
| 4706 | * @cmd: |
| 4707 | **/ |
| 4708 | |
| 4709 | static int |
| 4710 | e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4711 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4712 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4714 | int retval; |
| 4715 | uint16_t mii_reg; |
| 4716 | uint16_t spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4717 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4719 | if (adapter->hw.media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | return -EOPNOTSUPP; |
| 4721 | |
| 4722 | switch (cmd) { |
| 4723 | case SIOCGMIIPHY: |
| 4724 | data->phy_id = adapter->hw.phy_addr; |
| 4725 | break; |
| 4726 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4727 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4729 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4730 | if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4731 | &data->val_out)) { |
| 4732 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4734 | } |
| 4735 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4736 | break; |
| 4737 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4738 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4739 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4740 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | return -EFAULT; |
| 4742 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4743 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4744 | if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4745 | mii_reg)) { |
| 4746 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4748 | } |
Auke Kok | dc86d32 | 2006-04-18 12:30:51 -0700 | [diff] [blame] | 4749 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | switch (data->reg_num) { |
| 4751 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4752 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4754 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | adapter->hw.autoneg = 1; |
| 4756 | adapter->hw.autoneg_advertised = 0x2F; |
| 4757 | } else { |
| 4758 | if (mii_reg & 0x40) |
| 4759 | spddplx = SPEED_1000; |
| 4760 | else if (mii_reg & 0x2000) |
| 4761 | spddplx = SPEED_100; |
| 4762 | else |
| 4763 | spddplx = SPEED_10; |
| 4764 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4765 | ? DUPLEX_FULL : |
| 4766 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | retval = e1000_set_spd_dplx(adapter, |
| 4768 | spddplx); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4769 | if (retval) { |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4770 | spin_unlock_irqrestore( |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4771 | &adapter->stats_lock, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4772 | flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | return retval; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4776 | if (netif_running(adapter->netdev)) |
| 4777 | e1000_reinit_locked(adapter); |
| 4778 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | e1000_reset(adapter); |
| 4780 | break; |
| 4781 | case M88E1000_PHY_SPEC_CTRL: |
| 4782 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4783 | if (e1000_phy_reset(&adapter->hw)) { |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4784 | spin_unlock_irqrestore( |
| 4785 | &adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4788 | break; |
| 4789 | } |
| 4790 | } else { |
| 4791 | switch (data->reg_num) { |
| 4792 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4793 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4795 | if (netif_running(adapter->netdev)) |
| 4796 | e1000_reinit_locked(adapter); |
| 4797 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | e1000_reset(adapter); |
| 4799 | break; |
| 4800 | } |
| 4801 | } |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4802 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | break; |
| 4804 | default: |
| 4805 | return -EOPNOTSUPP; |
| 4806 | } |
| 4807 | return E1000_SUCCESS; |
| 4808 | } |
| 4809 | |
| 4810 | void |
| 4811 | e1000_pci_set_mwi(struct e1000_hw *hw) |
| 4812 | { |
| 4813 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4814 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4815 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4816 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4817 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | void |
| 4821 | e1000_pci_clear_mwi(struct e1000_hw *hw) |
| 4822 | { |
| 4823 | struct e1000_adapter *adapter = hw->back; |
| 4824 | |
| 4825 | pci_clear_mwi(adapter->pdev); |
| 4826 | } |
| 4827 | |
| 4828 | void |
| 4829 | e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4830 | { |
| 4831 | struct e1000_adapter *adapter = hw->back; |
| 4832 | |
| 4833 | pci_read_config_word(adapter->pdev, reg, value); |
| 4834 | } |
| 4835 | |
| 4836 | void |
| 4837 | e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4838 | { |
| 4839 | struct e1000_adapter *adapter = hw->back; |
| 4840 | |
| 4841 | pci_write_config_word(adapter->pdev, reg, *value); |
| 4842 | } |
| 4843 | |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4844 | int32_t |
| 4845 | e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4846 | { |
| 4847 | struct e1000_adapter *adapter = hw->back; |
| 4848 | uint16_t cap_offset; |
| 4849 | |
| 4850 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 4851 | if (!cap_offset) |
| 4852 | return -E1000_ERR_CONFIG; |
| 4853 | |
| 4854 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 4855 | |
| 4856 | return E1000_SUCCESS; |
| 4857 | } |
| 4858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | void |
| 4860 | e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) |
| 4861 | { |
| 4862 | outl(value, port); |
| 4863 | } |
| 4864 | |
| 4865 | static void |
| 4866 | e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 4867 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4868 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | uint32_t ctrl, rctl; |
| 4870 | |
| 4871 | e1000_irq_disable(adapter); |
| 4872 | adapter->vlgrp = grp; |
| 4873 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4874 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | /* enable VLAN tag insert/strip */ |
| 4876 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4877 | ctrl |= E1000_CTRL_VME; |
| 4878 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4879 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4880 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4881 | /* enable VLAN receive filtering */ |
| 4882 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4883 | rctl |= E1000_RCTL_VFE; |
| 4884 | rctl &= ~E1000_RCTL_CFIEN; |
| 4885 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4886 | e1000_update_mng_vlan(adapter); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | } else { |
| 4889 | /* disable VLAN tag insert/strip */ |
| 4890 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4891 | ctrl &= ~E1000_CTRL_VME; |
| 4892 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4893 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4894 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4895 | /* disable VLAN filtering */ |
| 4896 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4897 | rctl &= ~E1000_RCTL_VFE; |
| 4898 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4899 | if (adapter->mng_vlan_id != |
| 4900 | (uint16_t)E1000_MNG_VLAN_NONE) { |
| 4901 | e1000_vlan_rx_kill_vid(netdev, |
| 4902 | adapter->mng_vlan_id); |
| 4903 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4904 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | e1000_irq_enable(adapter); |
| 4909 | } |
| 4910 | |
| 4911 | static void |
| 4912 | e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
| 4913 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4914 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | uint32_t vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4916 | |
| 4917 | if ((adapter->hw.mng_cookie.status & |
| 4918 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4919 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4920 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | /* add VID to filter table */ |
| 4922 | index = (vid >> 5) & 0x7F; |
| 4923 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4924 | vfta |= (1 << (vid & 0x1F)); |
| 4925 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4926 | } |
| 4927 | |
| 4928 | static void |
| 4929 | e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
| 4930 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4931 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | uint32_t vfta, index; |
| 4933 | |
| 4934 | e1000_irq_disable(adapter); |
| 4935 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4936 | if (adapter->vlgrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | adapter->vlgrp->vlan_devices[vid] = NULL; |
| 4938 | |
| 4939 | e1000_irq_enable(adapter); |
| 4940 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4941 | if ((adapter->hw.mng_cookie.status & |
| 4942 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4943 | (vid == adapter->mng_vlan_id)) { |
| 4944 | /* release control to f/w */ |
| 4945 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4946 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4947 | } |
| 4948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | /* remove VID from filter table */ |
| 4950 | index = (vid >> 5) & 0x7F; |
| 4951 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4952 | vfta &= ~(1 << (vid & 0x1F)); |
| 4953 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4954 | } |
| 4955 | |
| 4956 | static void |
| 4957 | e1000_restore_vlan(struct e1000_adapter *adapter) |
| 4958 | { |
| 4959 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4960 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4961 | if (adapter->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | uint16_t vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4963 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 4964 | if (!adapter->vlgrp->vlan_devices[vid]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | continue; |
| 4966 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 4967 | } |
| 4968 | } |
| 4969 | } |
| 4970 | |
| 4971 | int |
| 4972 | e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) |
| 4973 | { |
| 4974 | adapter->hw.autoneg = 0; |
| 4975 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4976 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4977 | if ((adapter->hw.media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4978 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 4979 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 4980 | return -EINVAL; |
| 4981 | } |
| 4982 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4983 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4984 | case SPEED_10 + DUPLEX_HALF: |
| 4985 | adapter->hw.forced_speed_duplex = e1000_10_half; |
| 4986 | break; |
| 4987 | case SPEED_10 + DUPLEX_FULL: |
| 4988 | adapter->hw.forced_speed_duplex = e1000_10_full; |
| 4989 | break; |
| 4990 | case SPEED_100 + DUPLEX_HALF: |
| 4991 | adapter->hw.forced_speed_duplex = e1000_100_half; |
| 4992 | break; |
| 4993 | case SPEED_100 + DUPLEX_FULL: |
| 4994 | adapter->hw.forced_speed_duplex = e1000_100_full; |
| 4995 | break; |
| 4996 | case SPEED_1000 + DUPLEX_FULL: |
| 4997 | adapter->hw.autoneg = 1; |
| 4998 | adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
| 4999 | break; |
| 5000 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 5001 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5002 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | return -EINVAL; |
| 5004 | } |
| 5005 | return 0; |
| 5006 | } |
| 5007 | |
Martin J. Bligh | b6a1d5f | 2005-10-28 15:14:44 -0700 | [diff] [blame] | 5008 | #ifdef CONFIG_PM |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 5009 | /* Save/restore 16 or 64 dwords of PCI config space depending on which |
| 5010 | * bus we're on (PCI(X) vs. PCI-E) |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5011 | */ |
| 5012 | #define PCIE_CONFIG_SPACE_LEN 256 |
| 5013 | #define PCI_CONFIG_SPACE_LEN 64 |
| 5014 | static int |
| 5015 | e1000_pci_save_state(struct e1000_adapter *adapter) |
| 5016 | { |
| 5017 | struct pci_dev *dev = adapter->pdev; |
| 5018 | int size; |
| 5019 | int i; |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 5020 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5021 | if (adapter->hw.mac_type >= e1000_82571) |
| 5022 | size = PCIE_CONFIG_SPACE_LEN; |
| 5023 | else |
| 5024 | size = PCI_CONFIG_SPACE_LEN; |
| 5025 | |
| 5026 | WARN_ON(adapter->config_space != NULL); |
| 5027 | |
| 5028 | adapter->config_space = kmalloc(size, GFP_KERNEL); |
| 5029 | if (!adapter->config_space) { |
| 5030 | DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size); |
| 5031 | return -ENOMEM; |
| 5032 | } |
| 5033 | for (i = 0; i < (size / 4); i++) |
| 5034 | pci_read_config_dword(dev, i * 4, &adapter->config_space[i]); |
| 5035 | return 0; |
| 5036 | } |
| 5037 | |
| 5038 | static void |
| 5039 | e1000_pci_restore_state(struct e1000_adapter *adapter) |
| 5040 | { |
| 5041 | struct pci_dev *dev = adapter->pdev; |
| 5042 | int size; |
| 5043 | int i; |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 5044 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5045 | if (adapter->config_space == NULL) |
| 5046 | return; |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 5047 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5048 | if (adapter->hw.mac_type >= e1000_82571) |
| 5049 | size = PCIE_CONFIG_SPACE_LEN; |
| 5050 | else |
| 5051 | size = PCI_CONFIG_SPACE_LEN; |
| 5052 | for (i = 0; i < (size / 4); i++) |
| 5053 | pci_write_config_dword(dev, i * 4, adapter->config_space[i]); |
| 5054 | kfree(adapter->config_space); |
| 5055 | adapter->config_space = NULL; |
| 5056 | return; |
| 5057 | } |
| 5058 | #endif /* CONFIG_PM */ |
| 5059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | static int |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 5061 | e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | { |
| 5063 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5064 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5065 | uint32_t ctrl, ctrl_ext, rctl, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | uint32_t wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5067 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5068 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5069 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | |
| 5071 | netif_device_detach(netdev); |
| 5072 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5073 | if (netif_running(netdev)) { |
| 5074 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5076 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5078 | #ifdef CONFIG_PM |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 5079 | /* Implement our own version of pci_save_state(pdev) because pci- |
| 5080 | * express adapters have 256-byte config spaces. */ |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5081 | retval = e1000_pci_save_state(adapter); |
| 5082 | if (retval) |
| 5083 | return retval; |
| 5084 | #endif |
| 5085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | status = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5087 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | wufc &= ~E1000_WUFC_LNKC; |
| 5089 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5090 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5091 | e1000_setup_rctl(adapter); |
| 5092 | e1000_set_multi(netdev); |
| 5093 | |
| 5094 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 5095 | if (wufc & E1000_WUFC_MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 5097 | rctl |= E1000_RCTL_MPE; |
| 5098 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 5099 | } |
| 5100 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5101 | if (adapter->hw.mac_type >= e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 5103 | /* advertise wake from D3Cold */ |
| 5104 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5105 | /* phy power management enable */ |
| 5106 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5107 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 5108 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 5109 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 5110 | } |
| 5111 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5112 | if (adapter->hw.media_type == e1000_media_type_fiber || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 5114 | /* keep the laser running in D3 */ |
| 5115 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 5116 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 5117 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
| 5118 | } |
| 5119 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5120 | /* Allow time for pending master requests to run */ |
| 5121 | e1000_disable_pciex_master(&adapter->hw); |
| 5122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
| 5124 | E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5125 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5126 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | } else { |
| 5128 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
| 5129 | E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5130 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5131 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5134 | e1000_release_manageability(adapter); |
| 5135 | |
| 5136 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 5137 | if (adapter->en_mng_pt) { |
| 5138 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5139 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5142 | if (adapter->hw.phy_type == e1000_phy_igp_3) |
| 5143 | e1000_phy_powerdown_workaround(&adapter->hw); |
| 5144 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5145 | if (netif_running(netdev)) |
| 5146 | e1000_free_irq(adapter); |
| 5147 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5148 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5149 | * would have already happened in close and is redundant. */ |
| 5150 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5153 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5154 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | |
| 5156 | return 0; |
| 5157 | } |
| 5158 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5159 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5160 | static int |
| 5161 | e1000_resume(struct pci_dev *pdev) |
| 5162 | { |
| 5163 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5164 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5165 | uint32_t err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5167 | pci_set_power_state(pdev, PCI_D0); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5168 | e1000_pci_restore_state(adapter); |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 5169 | if ((err = pci_enable_device(pdev))) { |
| 5170 | printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
| 5171 | return err; |
| 5172 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 5173 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5175 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5176 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5178 | if (netif_running(netdev) && (err = e1000_request_irq(adapter))) |
| 5179 | return err; |
| 5180 | |
| 5181 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | e1000_reset(adapter); |
| 5183 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5184 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5185 | e1000_init_manageability(adapter); |
| 5186 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5187 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | e1000_up(adapter); |
| 5189 | |
| 5190 | netif_device_attach(netdev); |
| 5191 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5192 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5193 | * DRV_LOAD until the interface is up. For all other cases, |
| 5194 | * let the f/w know that the h/w is now under the control |
| 5195 | * of the driver. */ |
| 5196 | if (adapter->hw.mac_type != e1000_82573 || |
| 5197 | !e1000_check_mng_mode(&adapter->hw)) |
| 5198 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | return 0; |
| 5201 | } |
| 5202 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5203 | |
| 5204 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5205 | { |
| 5206 | e1000_suspend(pdev, PMSG_SUSPEND); |
| 5207 | } |
| 5208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5210 | /* |
| 5211 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5212 | * without having to re-enable interrupts. It's not called while |
| 5213 | * the interrupt routine is executing. |
| 5214 | */ |
| 5215 | static void |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5216 | e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5218 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 5219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5221 | e1000_intr(adapter->pdev->irq, netdev); |
Andrew Morton | c4cfe56 | 2005-10-15 00:32:29 -0700 | [diff] [blame] | 5222 | e1000_clean_tx_irq(adapter, adapter->tx_ring); |
Jeff Kirsher | e8da8be | 2006-01-12 16:51:14 -0800 | [diff] [blame] | 5223 | #ifndef CONFIG_E1000_NAPI |
| 5224 | adapter->clean_rx(adapter, adapter->rx_ring); |
| 5225 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | enable_irq(adapter->pdev->irq); |
| 5227 | } |
| 5228 | #endif |
| 5229 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5230 | /** |
| 5231 | * e1000_io_error_detected - called when PCI error is detected |
| 5232 | * @pdev: Pointer to PCI device |
| 5233 | * @state: The current pci conneection state |
| 5234 | * |
| 5235 | * This function is called after a PCI bus error affecting |
| 5236 | * this device has been detected. |
| 5237 | */ |
| 5238 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 5239 | { |
| 5240 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5241 | struct e1000_adapter *adapter = netdev->priv; |
| 5242 | |
| 5243 | netif_device_detach(netdev); |
| 5244 | |
| 5245 | if (netif_running(netdev)) |
| 5246 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 5247 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5248 | |
| 5249 | /* Request a slot slot reset. */ |
| 5250 | return PCI_ERS_RESULT_NEED_RESET; |
| 5251 | } |
| 5252 | |
| 5253 | /** |
| 5254 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5255 | * @pdev: Pointer to PCI device |
| 5256 | * |
| 5257 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5258 | * resembles the first-half of the e1000_resume routine. |
| 5259 | */ |
| 5260 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5261 | { |
| 5262 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5263 | struct e1000_adapter *adapter = netdev->priv; |
| 5264 | |
| 5265 | if (pci_enable_device(pdev)) { |
| 5266 | printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
| 5267 | return PCI_ERS_RESULT_DISCONNECT; |
| 5268 | } |
| 5269 | pci_set_master(pdev); |
| 5270 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 5271 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5272 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5273 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5274 | e1000_reset(adapter); |
| 5275 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5276 | |
| 5277 | return PCI_ERS_RESULT_RECOVERED; |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * e1000_io_resume - called when traffic can start flowing again. |
| 5282 | * @pdev: Pointer to PCI device |
| 5283 | * |
| 5284 | * This callback is called when the error recovery driver tells us that |
| 5285 | * its OK to resume normal operation. Implementation resembles the |
| 5286 | * second-half of the e1000_resume routine. |
| 5287 | */ |
| 5288 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5289 | { |
| 5290 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5291 | struct e1000_adapter *adapter = netdev->priv; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5292 | |
| 5293 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5294 | |
| 5295 | if (netif_running(netdev)) { |
| 5296 | if (e1000_up(adapter)) { |
| 5297 | printk("e1000: can't bring device back up after reset\n"); |
| 5298 | return; |
| 5299 | } |
| 5300 | } |
| 5301 | |
| 5302 | netif_device_attach(netdev); |
| 5303 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5304 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5305 | * DRV_LOAD until the interface is up. For all other cases, |
| 5306 | * let the f/w know that the h/w is now under the control |
| 5307 | * of the driver. */ |
| 5308 | if (adapter->hw.mac_type != e1000_82573 || |
| 5309 | !e1000_check_mng_mode(&adapter->hw)) |
| 5310 | e1000_get_hw_control(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5311 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | /* e1000_main.c */ |