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 | 7e72157 | 2007-01-18 09:25:33 -0800 | [diff] [blame] | 39 | #define DRV_VERSION "7.3.20-k2"DRIVERNAPI |
Stephen Hemminger | abec42a | 2007-10-29 10:46:19 -0700 | [diff] [blame] | 40 | const char e1000_driver_version[] = DRV_VERSION; |
| 41 | static const 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 | */ |
Linus Torvalds | 60e2331 | 2008-01-31 00:30:15 +1100 | [diff] [blame] | 50 | #ifdef CONFIG_E1000E_ENABLED |
| 51 | #define PCIE(x) |
| 52 | #else |
| 53 | #define PCIE(x) x, |
| 54 | #endif |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static struct pci_device_id e1000_pci_tbl[] = { |
| 57 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 58 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 59 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 60 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 61 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 62 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 63 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 64 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 65 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 66 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 67 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 68 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 69 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 70 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 71 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 72 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 73 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 74 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 75 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 76 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 78 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 79 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 80 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 81 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
Linus Torvalds | 60e2331 | 2008-01-31 00:30:15 +1100 | [diff] [blame] | 82 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1049)) |
| 83 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104A)) |
| 84 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104B)) |
| 85 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104C)) |
| 86 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x104D)) |
| 87 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x105E)) |
| 88 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x105F)) |
| 89 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1060)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 91 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 92 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 93 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 94 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 95 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 96 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 97 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
Linus Torvalds | 60e2331 | 2008-01-31 00:30:15 +1100 | [diff] [blame] | 98 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107D)) |
| 99 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107E)) |
| 100 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x107F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Linus Torvalds | 60e2331 | 2008-01-31 00:30:15 +1100 | [diff] [blame] | 102 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x108B)) |
| 103 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x108C)) |
| 104 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1096)) |
| 105 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x1098)) |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 106 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Linus Torvalds | 60e2331 | 2008-01-31 00:30:15 +1100 | [diff] [blame] | 107 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x109A)) |
| 108 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10A4)) |
| 109 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10A5)) |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 110 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Linus Torvalds | 60e2331 | 2008-01-31 00:30:15 +1100 | [diff] [blame] | 111 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10B9)) |
| 112 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BA)) |
| 113 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BB)) |
| 114 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10BC)) |
| 115 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10C4)) |
| 116 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10C5)) |
| 117 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10D5)) |
| 118 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10D9)) |
| 119 | PCIE( INTEL_E1000_ETHERNET_DEVICE(0x10DA)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | /* required last entry */ |
| 121 | {0,} |
| 122 | }; |
| 123 | |
| 124 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 125 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 126 | int e1000_up(struct e1000_adapter *adapter); |
| 127 | void e1000_down(struct e1000_adapter *adapter); |
| 128 | void e1000_reinit_locked(struct e1000_adapter *adapter); |
| 129 | void e1000_reset(struct e1000_adapter *adapter); |
| 130 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx); |
| 131 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
| 132 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
| 133 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
| 134 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 135 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 136 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 137 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 138 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 139 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 140 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 141 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 142 | struct e1000_rx_ring *rx_ring); |
| 143 | void e1000_update_stats(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | static int e1000_init_module(void); |
| 146 | static void e1000_exit_module(void); |
| 147 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 148 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 149 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 151 | static int e1000_open(struct net_device *netdev); |
| 152 | static int e1000_close(struct net_device *netdev); |
| 153 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 154 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 155 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 156 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 157 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 158 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 159 | struct e1000_tx_ring *tx_ring); |
| 160 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 161 | struct e1000_rx_ring *rx_ring); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 162 | static void e1000_set_rx_mode(struct net_device *netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | static void e1000_update_phy_info(unsigned long data); |
| 164 | static void e1000_watchdog(unsigned long data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
| 166 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 167 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 168 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 169 | static int e1000_set_mac(struct net_device *netdev, void *p); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 170 | static irqreturn_t e1000_intr(int irq, void *data); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 171 | static irqreturn_t e1000_intr_msi(int irq, void *data); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 172 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 173 | struct e1000_tx_ring *tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 175 | static int e1000_clean(struct napi_struct *napi, int budget); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 176 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 177 | struct e1000_rx_ring *rx_ring, |
| 178 | int *work_done, int work_to_do); |
| 179 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 180 | struct e1000_rx_ring *rx_ring, |
| 181 | int *work_done, int work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | #else |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 183 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 184 | struct e1000_rx_ring *rx_ring); |
| 185 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 186 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | #endif |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 188 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 189 | struct e1000_rx_ring *rx_ring, |
| 190 | int cleaned_count); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 191 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 192 | struct e1000_rx_ring *rx_ring, |
| 193 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 195 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 196 | int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 198 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 199 | static void e1000_tx_timeout(struct net_device *dev); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 200 | static void e1000_reset_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 202 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 203 | struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
| 206 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); |
| 207 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
| 208 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 209 | |
Ashutosh Naik | 977e74b | 2005-10-28 15:14:53 -0700 | [diff] [blame] | 210 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 211 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | static int e1000_resume(struct pci_dev *pdev); |
| 213 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 214 | static void e1000_shutdown(struct pci_dev *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 217 | /* for netdump / net console */ |
| 218 | static void e1000_netpoll (struct net_device *netdev); |
| 219 | #endif |
| 220 | |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 221 | #define COPYBREAK_DEFAULT 256 |
| 222 | static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT; |
| 223 | module_param(copybreak, uint, 0644); |
| 224 | MODULE_PARM_DESC(copybreak, |
| 225 | "Maximum size of packet that is copied to a new buffer on receive"); |
| 226 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 227 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 228 | pci_channel_state_t state); |
| 229 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); |
| 230 | static void e1000_io_resume(struct pci_dev *pdev); |
| 231 | |
| 232 | static struct pci_error_handlers e1000_err_handler = { |
| 233 | .error_detected = e1000_io_error_detected, |
| 234 | .slot_reset = e1000_io_slot_reset, |
| 235 | .resume = e1000_io_resume, |
| 236 | }; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 237 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | static struct pci_driver e1000_driver = { |
| 239 | .name = e1000_driver_name, |
| 240 | .id_table = e1000_pci_tbl, |
| 241 | .probe = e1000_probe, |
| 242 | .remove = __devexit_p(e1000_remove), |
Auke Kok | c4e24f0 | 2006-09-27 12:53:19 -0700 | [diff] [blame] | 243 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | /* Power Managment Hooks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | .suspend = e1000_suspend, |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 246 | .resume = e1000_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | #endif |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 248 | .shutdown = e1000_shutdown, |
| 249 | .err_handler = &e1000_err_handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 253 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 254 | MODULE_LICENSE("GPL"); |
| 255 | MODULE_VERSION(DRV_VERSION); |
| 256 | |
| 257 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 258 | module_param(debug, int, 0); |
| 259 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 260 | |
| 261 | /** |
| 262 | * e1000_init_module - Driver Registration Routine |
| 263 | * |
| 264 | * e1000_init_module is the first routine called when the driver is |
| 265 | * loaded. All it does is register with the PCI subsystem. |
| 266 | **/ |
| 267 | |
| 268 | static int __init |
| 269 | e1000_init_module(void) |
| 270 | { |
| 271 | int ret; |
| 272 | printk(KERN_INFO "%s - version %s\n", |
| 273 | e1000_driver_string, e1000_driver_version); |
| 274 | |
| 275 | printk(KERN_INFO "%s\n", e1000_copyright); |
| 276 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 277 | ret = pci_register_driver(&e1000_driver); |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 278 | if (copybreak != COPYBREAK_DEFAULT) { |
| 279 | if (copybreak == 0) |
| 280 | printk(KERN_INFO "e1000: copybreak disabled\n"); |
| 281 | else |
| 282 | printk(KERN_INFO "e1000: copybreak enabled for " |
| 283 | "packets <= %u bytes\n", copybreak); |
| 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | module_init(e1000_init_module); |
| 289 | |
| 290 | /** |
| 291 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 292 | * |
| 293 | * e1000_exit_module is called just before the driver is removed |
| 294 | * from memory. |
| 295 | **/ |
| 296 | |
| 297 | static void __exit |
| 298 | e1000_exit_module(void) |
| 299 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | pci_unregister_driver(&e1000_driver); |
| 301 | } |
| 302 | |
| 303 | module_exit(e1000_exit_module); |
| 304 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 305 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 306 | { |
| 307 | struct net_device *netdev = adapter->netdev; |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 308 | irq_handler_t handler = e1000_intr; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 309 | int irq_flags = IRQF_SHARED; |
| 310 | int err; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 311 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 312 | if (adapter->hw.mac_type >= e1000_82571) { |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 313 | adapter->have_msi = !pci_enable_msi(adapter->pdev); |
| 314 | if (adapter->have_msi) { |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 315 | handler = e1000_intr_msi; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 316 | irq_flags = 0; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 319 | |
| 320 | err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, |
| 321 | netdev); |
| 322 | if (err) { |
| 323 | if (adapter->have_msi) |
| 324 | pci_disable_msi(adapter->pdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 325 | DPRINTK(PROBE, ERR, |
| 326 | "Unable to allocate interrupt Error: %d\n", err); |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 327 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 328 | |
| 329 | return err; |
| 330 | } |
| 331 | |
| 332 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 333 | { |
| 334 | struct net_device *netdev = adapter->netdev; |
| 335 | |
| 336 | free_irq(adapter->pdev->irq, netdev); |
| 337 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 338 | if (adapter->have_msi) |
| 339 | pci_disable_msi(adapter->pdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | /** |
| 343 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 344 | * @adapter: board private structure |
| 345 | **/ |
| 346 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 347 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | e1000_irq_disable(struct e1000_adapter *adapter) |
| 349 | { |
| 350 | atomic_inc(&adapter->irq_sem); |
| 351 | E1000_WRITE_REG(&adapter->hw, IMC, ~0); |
| 352 | E1000_WRITE_FLUSH(&adapter->hw); |
| 353 | synchronize_irq(adapter->pdev->irq); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * e1000_irq_enable - Enable default interrupt generation settings |
| 358 | * @adapter: board private structure |
| 359 | **/ |
| 360 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 361 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | e1000_irq_enable(struct e1000_adapter *adapter) |
| 363 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 364 | if (likely(atomic_dec_and_test(&adapter->irq_sem))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); |
| 366 | E1000_WRITE_FLUSH(&adapter->hw); |
| 367 | } |
| 368 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 369 | |
| 370 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 371 | e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 372 | { |
| 373 | struct net_device *netdev = adapter->netdev; |
| 374 | uint16_t vid = adapter->hw.mng_cookie.vlan_id; |
| 375 | uint16_t old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 376 | if (adapter->vlgrp) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 377 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 378 | if (adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 379 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 380 | e1000_vlan_rx_add_vid(netdev, vid); |
| 381 | adapter->mng_vlan_id = vid; |
| 382 | } else |
| 383 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 384 | |
| 385 | if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && |
| 386 | (vid != old_vid) && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 387 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 388 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 389 | } else |
| 390 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 393 | |
| 394 | /** |
| 395 | * e1000_release_hw_control - release control of the h/w to f/w |
| 396 | * @adapter: address of board private structure |
| 397 | * |
| 398 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 399 | * For ASF and Pass Through versions of f/w this means that the |
| 400 | * driver is no longer loaded. For AMT version (only with 82573) i |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 401 | * 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] | 402 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 403 | **/ |
| 404 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 405 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 406 | e1000_release_hw_control(struct e1000_adapter *adapter) |
| 407 | { |
| 408 | uint32_t ctrl_ext; |
| 409 | uint32_t swsm; |
| 410 | |
| 411 | /* Let firmware taken over control of h/w */ |
| 412 | switch (adapter->hw.mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 413 | case e1000_82573: |
| 414 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 415 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 416 | swsm & ~E1000_SWSM_DRV_LOAD); |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 417 | break; |
| 418 | case e1000_82571: |
| 419 | case e1000_82572: |
| 420 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 421 | case e1000_ich8lan: |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 422 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 423 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 424 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 425 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 426 | default: |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * e1000_get_hw_control - get control of the h/w from f/w |
| 433 | * @adapter: address of board private structure |
| 434 | * |
| 435 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 436 | * For ASF and Pass Through versions of f/w this means that |
| 437 | * the driver is loaded. For AMT version (only with 82573) |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 438 | * 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] | 439 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 440 | **/ |
| 441 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 442 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 443 | e1000_get_hw_control(struct e1000_adapter *adapter) |
| 444 | { |
| 445 | uint32_t ctrl_ext; |
| 446 | uint32_t swsm; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 447 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 448 | /* Let firmware know the driver has taken over */ |
| 449 | switch (adapter->hw.mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 450 | case e1000_82573: |
| 451 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 452 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 453 | swsm | E1000_SWSM_DRV_LOAD); |
| 454 | break; |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 455 | case e1000_82571: |
| 456 | case e1000_82572: |
| 457 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 458 | case e1000_ich8lan: |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 459 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 460 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 461 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 462 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 463 | default: |
| 464 | break; |
| 465 | } |
| 466 | } |
| 467 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 468 | static void |
| 469 | e1000_init_manageability(struct e1000_adapter *adapter) |
| 470 | { |
| 471 | if (adapter->en_mng_pt) { |
| 472 | uint32_t manc = E1000_READ_REG(&adapter->hw, MANC); |
| 473 | |
| 474 | /* disable hardware interception of ARP */ |
| 475 | manc &= ~(E1000_MANC_ARP_EN); |
| 476 | |
| 477 | /* enable receiving management packets to the host */ |
| 478 | /* this will probably generate destination unreachable messages |
| 479 | * from the host OS, but the packets will be handled on SMBUS */ |
| 480 | if (adapter->hw.has_manc2h) { |
| 481 | uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H); |
| 482 | |
| 483 | manc |= E1000_MANC_EN_MNG2HOST; |
| 484 | #define E1000_MNG2HOST_PORT_623 (1 << 5) |
| 485 | #define E1000_MNG2HOST_PORT_664 (1 << 6) |
| 486 | manc2h |= E1000_MNG2HOST_PORT_623; |
| 487 | manc2h |= E1000_MNG2HOST_PORT_664; |
| 488 | E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h); |
| 489 | } |
| 490 | |
| 491 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | static void |
| 496 | e1000_release_manageability(struct e1000_adapter *adapter) |
| 497 | { |
| 498 | if (adapter->en_mng_pt) { |
| 499 | uint32_t manc = E1000_READ_REG(&adapter->hw, MANC); |
| 500 | |
| 501 | /* re-enable hardware interception of ARP */ |
| 502 | manc |= E1000_MANC_ARP_EN; |
| 503 | |
| 504 | if (adapter->hw.has_manc2h) |
| 505 | manc &= ~E1000_MANC_EN_MNG2HOST; |
| 506 | |
| 507 | /* don't explicitly have to mess with MANC2H since |
| 508 | * MANC has an enable disable that gates MANC2H */ |
| 509 | |
| 510 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 511 | } |
| 512 | } |
| 513 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 514 | /** |
| 515 | * e1000_configure - configure the hardware for RX and TX |
| 516 | * @adapter = private board structure |
| 517 | **/ |
| 518 | static void e1000_configure(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
| 520 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 521 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 523 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | e1000_restore_vlan(adapter); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 526 | e1000_init_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
| 528 | e1000_configure_tx(adapter); |
| 529 | e1000_setup_rctl(adapter); |
| 530 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 531 | /* call E1000_DESC_UNUSED which always leaves |
| 532 | * at least 1 descriptor unused to make sure |
| 533 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 534 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 535 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 536 | adapter->alloc_rx_buf(adapter, ring, |
| 537 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 540 | adapter->tx_queue_len = netdev->tx_queue_len; |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 541 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 542 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 543 | int e1000_up(struct e1000_adapter *adapter) |
| 544 | { |
| 545 | /* hardware has been reset, we need to reload some things */ |
| 546 | e1000_configure(adapter); |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 547 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 548 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 549 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 550 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 551 | napi_enable(&adapter->napi); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 552 | #endif |
| 553 | e1000_irq_enable(adapter); |
| 554 | |
Jesse Brandeburg | 79f3d39 | 2006-12-15 10:42:34 +0100 | [diff] [blame] | 555 | /* fire a link change interrupt to start the watchdog */ |
| 556 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 560 | /** |
| 561 | * e1000_power_up_phy - restore link in case the phy was powered down |
| 562 | * @adapter: address of board private structure |
| 563 | * |
| 564 | * The phy may be powered down to save power and turn off link when the |
| 565 | * driver is unloaded and wake on lan is not enabled (among others) |
| 566 | * *** this routine MUST be followed by a call to e1000_reset *** |
| 567 | * |
| 568 | **/ |
| 569 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 570 | void e1000_power_up_phy(struct e1000_adapter *adapter) |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 571 | { |
| 572 | uint16_t mii_reg = 0; |
| 573 | |
| 574 | /* Just clear the power down bit to wake the phy back up */ |
| 575 | if (adapter->hw.media_type == e1000_media_type_copper) { |
| 576 | /* according to the manual, the phy will retain its |
| 577 | * settings across a power-down/up cycle */ |
| 578 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 579 | mii_reg &= ~MII_CR_POWER_DOWN; |
| 580 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 585 | { |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 586 | /* Power down the PHY so no link is implied when interface is down * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 587 | * 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] | 588 | * (a) WoL is enabled |
| 589 | * (b) AMT is active |
| 590 | * (c) SoL/IDER session is active */ |
| 591 | if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 592 | adapter->hw.media_type == e1000_media_type_copper) { |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 593 | uint16_t mii_reg = 0; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 594 | |
| 595 | switch (adapter->hw.mac_type) { |
| 596 | case e1000_82540: |
| 597 | case e1000_82545: |
| 598 | case e1000_82545_rev_3: |
| 599 | case e1000_82546: |
| 600 | case e1000_82546_rev_3: |
| 601 | case e1000_82541: |
| 602 | case e1000_82541_rev_2: |
| 603 | case e1000_82547: |
| 604 | case e1000_82547_rev_2: |
| 605 | if (E1000_READ_REG(&adapter->hw, MANC) & |
| 606 | E1000_MANC_SMBUS_EN) |
| 607 | goto out; |
| 608 | break; |
| 609 | case e1000_82571: |
| 610 | case e1000_82572: |
| 611 | case e1000_82573: |
| 612 | case e1000_80003es2lan: |
| 613 | case e1000_ich8lan: |
| 614 | if (e1000_check_mng_mode(&adapter->hw) || |
| 615 | e1000_check_phy_reset_block(&adapter->hw)) |
| 616 | goto out; |
| 617 | break; |
| 618 | default: |
| 619 | goto out; |
| 620 | } |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 621 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 622 | mii_reg |= MII_CR_POWER_DOWN; |
| 623 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 624 | mdelay(1); |
| 625 | } |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 626 | out: |
| 627 | return; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | void |
| 631 | e1000_down(struct e1000_adapter *adapter) |
| 632 | { |
| 633 | struct net_device *netdev = adapter->netdev; |
| 634 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 635 | /* signal that we're down so the interrupt handler does not |
| 636 | * reschedule our watchdog timer */ |
| 637 | set_bit(__E1000_DOWN, &adapter->flags); |
| 638 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 639 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 640 | napi_disable(&adapter->napi); |
David S. Miller | 49d85c5 | 2008-01-18 04:21:39 -0800 | [diff] [blame] | 641 | atomic_set(&adapter->irq_sem, 0); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 642 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 646 | del_timer_sync(&adapter->watchdog_timer); |
| 647 | del_timer_sync(&adapter->phy_info_timer); |
| 648 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 649 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | adapter->link_speed = 0; |
| 651 | adapter->link_duplex = 0; |
| 652 | netif_carrier_off(netdev); |
| 653 | netif_stop_queue(netdev); |
| 654 | |
| 655 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 656 | e1000_clean_all_tx_rings(adapter); |
| 657 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | void |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 661 | e1000_reinit_locked(struct e1000_adapter *adapter) |
| 662 | { |
| 663 | WARN_ON(in_interrupt()); |
| 664 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 665 | msleep(1); |
| 666 | e1000_down(adapter); |
| 667 | e1000_up(adapter); |
| 668 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | void |
| 672 | e1000_reset(struct e1000_adapter *adapter) |
| 673 | { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 674 | uint32_t pba = 0, tx_space, min_tx_space, min_rx_space; |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 675 | uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 676 | bool legacy_pba_adjust = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | /* Repartition Pba for greater than 9k mtu |
| 679 | * To take effect CTRL.RST is required. |
| 680 | */ |
| 681 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 682 | switch (adapter->hw.mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 683 | case e1000_82542_rev2_0: |
| 684 | case e1000_82542_rev2_1: |
| 685 | case e1000_82543: |
| 686 | case e1000_82544: |
| 687 | case e1000_82540: |
| 688 | case e1000_82541: |
| 689 | case e1000_82541_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 690 | legacy_pba_adjust = true; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 691 | pba = E1000_PBA_48K; |
| 692 | break; |
| 693 | case e1000_82545: |
| 694 | case e1000_82545_rev_3: |
| 695 | case e1000_82546: |
| 696 | case e1000_82546_rev_3: |
| 697 | pba = E1000_PBA_48K; |
| 698 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 699 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 700 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 701 | legacy_pba_adjust = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 702 | pba = E1000_PBA_30K; |
| 703 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 704 | case e1000_82571: |
| 705 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 706 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 707 | pba = E1000_PBA_38K; |
| 708 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 709 | case e1000_82573: |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 710 | pba = E1000_PBA_20K; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 711 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 712 | case e1000_ich8lan: |
| 713 | pba = E1000_PBA_8K; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 714 | case e1000_undefined: |
| 715 | case e1000_num_macs: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 716 | break; |
| 717 | } |
| 718 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 719 | if (legacy_pba_adjust) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 720 | if (adapter->netdev->mtu > E1000_RXBUFFER_8192) |
| 721 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 722 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 723 | if (adapter->hw.mac_type == e1000_82547) { |
| 724 | adapter->tx_fifo_head = 0; |
| 725 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 726 | adapter->tx_fifo_size = |
| 727 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 728 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 729 | } |
| 730 | } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 731 | /* adjust PBA for jumbo frames */ |
| 732 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 733 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 734 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 735 | * large enough to accomodate two full transmit packets, |
| 736 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 737 | * the Rx FIFO should be large enough to accomodate at least |
| 738 | * one full receive packet and is similarly rounded up and |
| 739 | * expressed in KB. */ |
| 740 | pba = E1000_READ_REG(&adapter->hw, PBA); |
| 741 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 742 | tx_space = pba >> 16; |
| 743 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 744 | pba &= 0xffff; |
| 745 | /* don't include ethernet FCS because hardware appends/strips */ |
| 746 | min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE + |
| 747 | VLAN_TAG_SIZE; |
| 748 | min_tx_space = min_rx_space; |
| 749 | min_tx_space *= 2; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 750 | min_tx_space = ALIGN(min_tx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 751 | min_tx_space >>= 10; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 752 | min_rx_space = ALIGN(min_rx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 753 | min_rx_space >>= 10; |
| 754 | |
| 755 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 756 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 757 | * allocation, take space away from current Rx allocation */ |
| 758 | if (tx_space < min_tx_space && |
| 759 | ((min_tx_space - tx_space) < pba)) { |
| 760 | pba = pba - (min_tx_space - tx_space); |
| 761 | |
| 762 | /* PCI/PCIx hardware has PBA alignment constraints */ |
| 763 | switch (adapter->hw.mac_type) { |
| 764 | case e1000_82545 ... e1000_82546_rev_3: |
| 765 | pba &= ~(E1000_PBA_8K - 1); |
| 766 | break; |
| 767 | default: |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | /* if short on rx space, rx wins and must trump tx |
| 772 | * adjustment or use Early Receive if available */ |
| 773 | if (pba < min_rx_space) { |
| 774 | switch (adapter->hw.mac_type) { |
| 775 | case e1000_82573: |
| 776 | /* ERT enabled in e1000_configure_rx */ |
| 777 | break; |
| 778 | default: |
| 779 | pba = min_rx_space; |
| 780 | break; |
| 781 | } |
| 782 | } |
| 783 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
| 787 | |
| 788 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 789 | /* Set the FC high water mark to 90% of the FIFO size. |
| 790 | * Required to clear last 3 LSB */ |
| 791 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 792 | /* We can't use 90% on small FIFOs because the remainder |
| 793 | * would be less than 1 full frame. In this case, we size |
| 794 | * it to allow at least a full frame above the high water |
| 795 | * mark. */ |
| 796 | if (pba < E1000_PBA_16K) |
| 797 | fc_high_water_mark = (pba * 1024) - 1600; |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 798 | |
| 799 | adapter->hw.fc_high_water = fc_high_water_mark; |
| 800 | adapter->hw.fc_low_water = fc_high_water_mark - 8; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 801 | if (adapter->hw.mac_type == e1000_80003es2lan) |
| 802 | adapter->hw.fc_pause_time = 0xFFFF; |
| 803 | else |
| 804 | adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | adapter->hw.fc_send_xon = 1; |
| 806 | adapter->hw.fc = adapter->hw.original_fc; |
| 807 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 808 | /* Allow time for pending master requests to run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | e1000_reset_hw(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 810 | if (adapter->hw.mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 812 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 813 | if (e1000_init_hw(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 815 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 816 | |
| 817 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
| 818 | if (adapter->hw.mac_type >= e1000_82544 && |
| 819 | adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 820 | adapter->hw.autoneg == 1 && |
| 821 | adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) { |
| 822 | uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 823 | /* clear phy power management bit if we are in gig only mode, |
| 824 | * which if enabled will attempt negotiation to 100Mb, which |
| 825 | * can cause a loss of link at power off or driver unload */ |
| 826 | ctrl &= ~E1000_CTRL_SWDPIN3; |
| 827 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 828 | } |
| 829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 831 | E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); |
| 832 | |
| 833 | e1000_reset_adaptive(&adapter->hw); |
| 834 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 835 | |
| 836 | if (!adapter->smart_power_down && |
| 837 | (adapter->hw.mac_type == e1000_82571 || |
| 838 | adapter->hw.mac_type == e1000_82572)) { |
| 839 | uint16_t phy_data = 0; |
| 840 | /* speed up time to link by disabling smart power down, ignore |
| 841 | * the return value of this function because there is nothing |
| 842 | * different we would do if it failed */ |
| 843 | e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 844 | &phy_data); |
| 845 | phy_data &= ~IGP02E1000_PM_SPD; |
| 846 | e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 847 | phy_data); |
| 848 | } |
| 849 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 850 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /** |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 854 | * Dump the eeprom for users having checksum issues |
| 855 | **/ |
Adrian Bunk | b4ea895 | 2008-02-01 08:21:28 -0800 | [diff] [blame] | 856 | static void e1000_dump_eeprom(struct e1000_adapter *adapter) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 857 | { |
| 858 | struct net_device *netdev = adapter->netdev; |
| 859 | struct ethtool_eeprom eeprom; |
| 860 | const struct ethtool_ops *ops = netdev->ethtool_ops; |
| 861 | u8 *data; |
| 862 | int i; |
| 863 | u16 csum_old, csum_new = 0; |
| 864 | |
| 865 | eeprom.len = ops->get_eeprom_len(netdev); |
| 866 | eeprom.offset = 0; |
| 867 | |
| 868 | data = kmalloc(eeprom.len, GFP_KERNEL); |
| 869 | if (!data) { |
| 870 | printk(KERN_ERR "Unable to allocate memory to dump EEPROM" |
| 871 | " data\n"); |
| 872 | return; |
| 873 | } |
| 874 | |
| 875 | ops->get_eeprom(netdev, &eeprom, data); |
| 876 | |
| 877 | csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + |
| 878 | (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); |
| 879 | for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) |
| 880 | csum_new += data[i] + (data[i + 1] << 8); |
| 881 | csum_new = EEPROM_SUM - csum_new; |
| 882 | |
| 883 | printk(KERN_ERR "/*********************/\n"); |
| 884 | printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old); |
| 885 | printk(KERN_ERR "Calculated : 0x%04x\n", csum_new); |
| 886 | |
| 887 | printk(KERN_ERR "Offset Values\n"); |
| 888 | printk(KERN_ERR "======== ======\n"); |
| 889 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); |
| 890 | |
| 891 | printk(KERN_ERR "Include this output when contacting your support " |
| 892 | "provider.\n"); |
| 893 | printk(KERN_ERR "This is not a software error! Something bad " |
| 894 | "happened to your hardware or\n"); |
| 895 | printk(KERN_ERR "EEPROM image. Ignoring this " |
| 896 | "problem could result in further problems,\n"); |
| 897 | printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n"); |
| 898 | printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, " |
| 899 | "which is invalid\n"); |
| 900 | printk(KERN_ERR "and requires you to set the proper MAC " |
| 901 | "address manually before continuing\n"); |
| 902 | printk(KERN_ERR "to enable this network device.\n"); |
| 903 | printk(KERN_ERR "Please inspect the EEPROM dump and report the issue " |
| 904 | "to your hardware vendor\n"); |
| 905 | printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n"); |
| 906 | printk(KERN_ERR "/*********************/\n"); |
| 907 | |
| 908 | kfree(data); |
| 909 | } |
| 910 | |
| 911 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | * e1000_probe - Device Initialization Routine |
| 913 | * @pdev: PCI device information struct |
| 914 | * @ent: entry in e1000_pci_tbl |
| 915 | * |
| 916 | * Returns 0 on success, negative on failure |
| 917 | * |
| 918 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 919 | * The OS initialization, configuring of the adapter private structure, |
| 920 | * and a hardware reset occur. |
| 921 | **/ |
| 922 | |
| 923 | static int __devinit |
| 924 | e1000_probe(struct pci_dev *pdev, |
| 925 | const struct pci_device_id *ent) |
| 926 | { |
| 927 | struct net_device *netdev; |
| 928 | struct e1000_adapter *adapter; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 931 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 932 | int i, err, pci_using_dac; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 933 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | uint16_t eeprom_apme_mask = E1000_EEPROM_APME; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 935 | DECLARE_MAC_BUF(mac); |
| 936 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 937 | if ((err = pci_enable_device(pdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | return err; |
| 939 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 940 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) && |
| 941 | !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | pci_using_dac = 1; |
| 943 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 944 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) && |
| 945 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | E1000_ERR("No usable DMA configuration, aborting\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 947 | goto err_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | } |
| 949 | pci_using_dac = 0; |
| 950 | } |
| 951 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 952 | if ((err = pci_request_regions(pdev, e1000_driver_name))) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 953 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | pci_set_master(pdev); |
| 956 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 957 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 959 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 963 | |
| 964 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 965 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | adapter->netdev = netdev; |
| 967 | adapter->pdev = pdev; |
| 968 | adapter->hw.back = adapter; |
| 969 | adapter->msg_enable = (1 << debug) - 1; |
| 970 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 971 | err = -EIO; |
Benjamin Herrenschmidt | 3c34ac3 | 2007-11-16 18:37:38 +1100 | [diff] [blame] | 972 | adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0), |
| 973 | pci_resource_len(pdev, BAR_0)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 974 | if (!adapter->hw.hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 977 | for (i = BAR_1; i <= BAR_5; i++) { |
| 978 | if (pci_resource_len(pdev, i) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | continue; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 980 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | netdev->open = &e1000_open; |
| 987 | netdev->stop = &e1000_close; |
| 988 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 989 | netdev->get_stats = &e1000_get_stats; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 990 | netdev->set_rx_mode = &e1000_set_rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | netdev->set_mac_address = &e1000_set_mac; |
| 992 | netdev->change_mtu = &e1000_change_mtu; |
| 993 | netdev->do_ioctl = &e1000_ioctl; |
| 994 | e1000_set_ethtool_ops(netdev); |
| 995 | netdev->tx_timeout = &e1000_tx_timeout; |
| 996 | netdev->watchdog_timeo = 5 * HZ; |
| 997 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 998 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | #endif |
| 1000 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 1001 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 1002 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 1003 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1004 | netdev->poll_controller = e1000_netpoll; |
| 1005 | #endif |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 1006 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | adapter->bd_number = cards_found; |
| 1009 | |
| 1010 | /* setup the private structure */ |
| 1011 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1012 | if ((err = e1000_sw_init(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | goto err_sw_init; |
| 1014 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1015 | err = -EIO; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1016 | /* Flash BAR mapping must happen after e1000_sw_init |
| 1017 | * because it depends on mac_type */ |
| 1018 | if ((adapter->hw.mac_type == e1000_ich8lan) && |
| 1019 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
Benjamin Herrenschmidt | 3c34ac3 | 2007-11-16 18:37:38 +1100 | [diff] [blame] | 1020 | adapter->hw.flash_address = |
| 1021 | ioremap(pci_resource_start(pdev, 1), |
| 1022 | pci_resource_len(pdev, 1)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1023 | if (!adapter->hw.flash_address) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1024 | goto err_flashmap; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1027 | if (e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1028 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 1029 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1030 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | netdev->features = NETIF_F_SG | |
| 1032 | NETIF_F_HW_CSUM | |
| 1033 | NETIF_F_HW_VLAN_TX | |
| 1034 | NETIF_F_HW_VLAN_RX | |
| 1035 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1036 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 1037 | netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1040 | if ((adapter->hw.mac_type >= e1000_82544) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | (adapter->hw.mac_type != e1000_82547)) |
| 1042 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1043 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1044 | if (adapter->hw.mac_type > e1000_82547_rev_2) |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1045 | netdev->features |= NETIF_F_TSO6; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1046 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | netdev->features |= NETIF_F_HIGHDMA; |
| 1048 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1049 | netdev->features |= NETIF_F_LLTX; |
| 1050 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1051 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); |
| 1052 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1053 | /* initialize eeprom parameters */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1054 | if (e1000_init_eeprom_params(&adapter->hw)) { |
| 1055 | E1000_ERR("EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1056 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1059 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | e1000_reset_hw(&adapter->hw); |
| 1063 | |
| 1064 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1065 | if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1067 | e1000_dump_eeprom(adapter); |
| 1068 | /* |
| 1069 | * set MAC address to all zeroes to invalidate and temporary |
| 1070 | * disable this device for the user. This blocks regular |
| 1071 | * traffic while still permitting ethtool ioctls from reaching |
| 1072 | * the hardware as well as allowing the user to run the |
| 1073 | * interface after manually setting a hw addr using |
| 1074 | * `ip set address` |
| 1075 | */ |
| 1076 | memset(adapter->hw.mac_addr, 0, netdev->addr_len); |
| 1077 | } else { |
| 1078 | /* copy the MAC address out of the EEPROM */ |
| 1079 | if (e1000_read_mac_addr(&adapter->hw)) |
| 1080 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | } |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1082 | /* don't block initalization here due to bad MAC address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
John W. Linville | 9beb0ac | 2005-09-12 10:48:55 -0400 | [diff] [blame] | 1084 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1086 | if (!is_valid_ether_addr(netdev->perm_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | e1000_get_bus_info(&adapter->hw); |
| 1090 | |
| 1091 | init_timer(&adapter->tx_fifo_stall_timer); |
| 1092 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
| 1093 | adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; |
| 1094 | |
| 1095 | init_timer(&adapter->watchdog_timer); |
| 1096 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 1097 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 1098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | init_timer(&adapter->phy_info_timer); |
| 1100 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 1101 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 1102 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1103 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | e1000_check_options(adapter); |
| 1106 | |
| 1107 | /* Initial Wake on LAN setting |
| 1108 | * If APM wake is enabled in the EEPROM, |
| 1109 | * enable the ACPI Magic Packet filter |
| 1110 | */ |
| 1111 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1112 | switch (adapter->hw.mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | case e1000_82542_rev2_0: |
| 1114 | case e1000_82542_rev2_1: |
| 1115 | case e1000_82543: |
| 1116 | break; |
| 1117 | case e1000_82544: |
| 1118 | e1000_read_eeprom(&adapter->hw, |
| 1119 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1120 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 1121 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1122 | case e1000_ich8lan: |
| 1123 | e1000_read_eeprom(&adapter->hw, |
| 1124 | EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
| 1125 | eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
| 1126 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | case e1000_82546: |
| 1128 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1129 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1130 | case e1000_80003es2lan: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1131 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | e1000_read_eeprom(&adapter->hw, |
| 1133 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1134 | break; |
| 1135 | } |
| 1136 | /* Fall Through */ |
| 1137 | default: |
| 1138 | e1000_read_eeprom(&adapter->hw, |
| 1139 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1140 | break; |
| 1141 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1142 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1143 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1144 | |
| 1145 | /* now that we have the eeprom settings, apply the special cases |
| 1146 | * where the eeprom may be wrong or the board simply won't support |
| 1147 | * wake on lan on a particular port */ |
| 1148 | switch (pdev->device) { |
| 1149 | case E1000_DEV_ID_82546GB_PCIE: |
| 1150 | adapter->eeprom_wol = 0; |
| 1151 | break; |
| 1152 | case E1000_DEV_ID_82546EB_FIBER: |
| 1153 | case E1000_DEV_ID_82546GB_FIBER: |
| 1154 | case E1000_DEV_ID_82571EB_FIBER: |
| 1155 | /* Wake events only supported on port A for dual fiber |
| 1156 | * regardless of eeprom setting */ |
| 1157 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1) |
| 1158 | adapter->eeprom_wol = 0; |
| 1159 | break; |
| 1160 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1161 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 1162 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 1163 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
Auke Kok | f4ec7f9 | 2007-08-30 11:23:58 -0700 | [diff] [blame] | 1164 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1165 | /* if quad port adapter, disable WoL on all but port A */ |
| 1166 | if (global_quad_port_a != 0) |
| 1167 | adapter->eeprom_wol = 0; |
| 1168 | else |
| 1169 | adapter->quad_port_a = 1; |
| 1170 | /* Reset for multiple quad port adapters */ |
| 1171 | if (++global_quad_port_a == 4) |
| 1172 | global_quad_port_a = 0; |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | /* initialize the wol settings based on the eeprom settings */ |
| 1177 | adapter->wol = adapter->eeprom_wol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1179 | /* print bus type/speed/width info */ |
| 1180 | { |
| 1181 | struct e1000_hw *hw = &adapter->hw; |
| 1182 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 1183 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 1184 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 1185 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 1186 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 1187 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 1188 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 1189 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 1190 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 1191 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 1192 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 1193 | "32-bit")); |
| 1194 | } |
| 1195 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1196 | printk("%s\n", print_mac(mac, netdev->dev_addr)); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1197 | |
Auke Kok | 14782ca | 2008-02-11 09:25:46 -0800 | [diff] [blame] | 1198 | if (adapter->hw.bus_type == e1000_bus_type_pci_express) { |
| 1199 | DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no " |
| 1200 | "longer be supported by this driver in the future.\n", |
| 1201 | pdev->vendor, pdev->device); |
| 1202 | DPRINTK(PROBE, WARNING, "please use the \"e1000e\" " |
| 1203 | "driver instead.\n"); |
| 1204 | } |
| 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | /* reset the hardware with the new settings */ |
| 1207 | e1000_reset(adapter); |
| 1208 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1209 | /* If the controller is 82573 and f/w is AMT, do not set |
| 1210 | * DRV_LOAD until the interface is up. For all other cases, |
| 1211 | * let the f/w know that the h/w is now under the control |
| 1212 | * of the driver. */ |
| 1213 | if (adapter->hw.mac_type != e1000_82573 || |
| 1214 | !e1000_check_mng_mode(&adapter->hw)) |
| 1215 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1216 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1217 | /* tell the stack to leave us alone until e1000_open() is called */ |
| 1218 | netif_carrier_off(netdev); |
| 1219 | netif_stop_queue(netdev); |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1220 | |
| 1221 | strcpy(netdev->name, "eth%d"); |
| 1222 | if ((err = register_netdev(netdev))) |
| 1223 | goto err_register; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 1226 | |
| 1227 | cards_found++; |
| 1228 | return 0; |
| 1229 | |
| 1230 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1231 | e1000_release_hw_control(adapter); |
| 1232 | err_eeprom: |
| 1233 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
| 1234 | e1000_phy_hw_reset(&adapter->hw); |
| 1235 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1236 | if (adapter->hw.flash_address) |
| 1237 | iounmap(adapter->hw.flash_address); |
| 1238 | err_flashmap: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1239 | #ifdef CONFIG_E1000_NAPI |
| 1240 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1241 | dev_put(&adapter->polling_netdev[i]); |
| 1242 | #endif |
| 1243 | |
| 1244 | kfree(adapter->tx_ring); |
| 1245 | kfree(adapter->rx_ring); |
| 1246 | #ifdef CONFIG_E1000_NAPI |
| 1247 | kfree(adapter->polling_netdev); |
| 1248 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | err_sw_init: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | iounmap(adapter->hw.hw_addr); |
| 1251 | err_ioremap: |
| 1252 | free_netdev(netdev); |
| 1253 | err_alloc_etherdev: |
| 1254 | pci_release_regions(pdev); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1255 | err_pci_reg: |
| 1256 | err_dma: |
| 1257 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | return err; |
| 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * e1000_remove - Device Removal Routine |
| 1263 | * @pdev: PCI device information struct |
| 1264 | * |
| 1265 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1266 | * that it should release a PCI device. The could be caused by a |
| 1267 | * Hot-Plug event, or because the driver is going to be removed from |
| 1268 | * memory. |
| 1269 | **/ |
| 1270 | |
| 1271 | static void __devexit |
| 1272 | e1000_remove(struct pci_dev *pdev) |
| 1273 | { |
| 1274 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1275 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1276 | #ifdef CONFIG_E1000_NAPI |
| 1277 | int i; |
| 1278 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 1280 | cancel_work_sync(&adapter->reset_task); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1281 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1282 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1284 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1285 | * would have already happened in close and is redundant. */ |
| 1286 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1287 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1288 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1289 | for (i = 0; i < adapter->num_rx_queues; i++) |
Stephen Hemminger | 1533306 | 2006-03-20 22:32:28 -0800 | [diff] [blame] | 1290 | dev_put(&adapter->polling_netdev[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1291 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1293 | unregister_netdev(netdev); |
| 1294 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1295 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1296 | e1000_phy_hw_reset(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1298 | kfree(adapter->tx_ring); |
| 1299 | kfree(adapter->rx_ring); |
| 1300 | #ifdef CONFIG_E1000_NAPI |
| 1301 | kfree(adapter->polling_netdev); |
| 1302 | #endif |
| 1303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | iounmap(adapter->hw.hw_addr); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1305 | if (adapter->hw.flash_address) |
| 1306 | iounmap(adapter->hw.flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | pci_release_regions(pdev); |
| 1308 | |
| 1309 | free_netdev(netdev); |
| 1310 | |
| 1311 | pci_disable_device(pdev); |
| 1312 | } |
| 1313 | |
| 1314 | /** |
| 1315 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1316 | * @adapter: board private structure to initialize |
| 1317 | * |
| 1318 | * e1000_sw_init initializes the Adapter private data structure. |
| 1319 | * Fields are initialized based on PCI device information and |
| 1320 | * OS network device settings (MTU size). |
| 1321 | **/ |
| 1322 | |
| 1323 | static int __devinit |
| 1324 | e1000_sw_init(struct e1000_adapter *adapter) |
| 1325 | { |
| 1326 | struct e1000_hw *hw = &adapter->hw; |
| 1327 | struct net_device *netdev = adapter->netdev; |
| 1328 | struct pci_dev *pdev = adapter->pdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1329 | #ifdef CONFIG_E1000_NAPI |
| 1330 | int i; |
| 1331 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
| 1333 | /* PCI config space info */ |
| 1334 | |
| 1335 | hw->vendor_id = pdev->vendor; |
| 1336 | hw->device_id = pdev->device; |
| 1337 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1338 | hw->subsystem_id = pdev->subsystem_device; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1339 | hw->revision_id = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
| 1341 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 1342 | |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1343 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1344 | adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | hw->max_frame_size = netdev->mtu + |
| 1346 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1347 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 1348 | |
| 1349 | /* identify the MAC */ |
| 1350 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1351 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 1353 | return -EIO; |
| 1354 | } |
| 1355 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1356 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | default: |
| 1358 | break; |
| 1359 | case e1000_82541: |
| 1360 | case e1000_82547: |
| 1361 | case e1000_82541_rev_2: |
| 1362 | case e1000_82547_rev_2: |
| 1363 | hw->phy_init_script = 1; |
| 1364 | break; |
| 1365 | } |
| 1366 | |
| 1367 | e1000_set_media_type(hw); |
| 1368 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1369 | hw->wait_autoneg_complete = false; |
| 1370 | hw->tbi_compatibility_en = true; |
| 1371 | hw->adaptive_ifs = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | /* Copper options */ |
| 1374 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1375 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | hw->mdix = AUTO_ALL_MODES; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1377 | hw->disable_polarity_correction = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1379 | } |
| 1380 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1381 | adapter->num_tx_queues = 1; |
| 1382 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1383 | |
| 1384 | if (e1000_alloc_queues(adapter)) { |
| 1385 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1386 | return -ENOMEM; |
| 1387 | } |
| 1388 | |
| 1389 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1390 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1391 | adapter->polling_netdev[i].priv = adapter; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1392 | dev_hold(&adapter->polling_netdev[i]); |
| 1393 | set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
| 1394 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1395 | spin_lock_init(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1396 | #endif |
| 1397 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1398 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
| 1399 | atomic_set(&adapter->irq_sem, 0); |
| 1400 | e1000_irq_disable(adapter); |
| 1401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1404 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | return 0; |
| 1407 | } |
| 1408 | |
| 1409 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1410 | * e1000_alloc_queues - Allocate memory for all rings |
| 1411 | * @adapter: board private structure to initialize |
| 1412 | * |
| 1413 | * We allocate one ring per queue at run-time since we don't know the |
| 1414 | * number of queues at compile-time. The polling_netdev array is |
| 1415 | * intended for Multiqueue, but should work fine with a single queue. |
| 1416 | **/ |
| 1417 | |
| 1418 | static int __devinit |
| 1419 | e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1420 | { |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1421 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1422 | sizeof(struct e1000_tx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1423 | if (!adapter->tx_ring) |
| 1424 | return -ENOMEM; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1425 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1426 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1427 | sizeof(struct e1000_rx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1428 | if (!adapter->rx_ring) { |
| 1429 | kfree(adapter->tx_ring); |
| 1430 | return -ENOMEM; |
| 1431 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1432 | |
| 1433 | #ifdef CONFIG_E1000_NAPI |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1434 | adapter->polling_netdev = kcalloc(adapter->num_rx_queues, |
| 1435 | sizeof(struct net_device), |
| 1436 | GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1437 | if (!adapter->polling_netdev) { |
| 1438 | kfree(adapter->tx_ring); |
| 1439 | kfree(adapter->rx_ring); |
| 1440 | return -ENOMEM; |
| 1441 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1442 | #endif |
| 1443 | |
| 1444 | return E1000_SUCCESS; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | * e1000_open - Called when a network interface is made active |
| 1449 | * @netdev: network interface device structure |
| 1450 | * |
| 1451 | * Returns 0 on success, negative value on failure |
| 1452 | * |
| 1453 | * The open entry point is called when a network interface is made |
| 1454 | * active by the system (IFF_UP). At this point all resources needed |
| 1455 | * for transmit and receive operations are allocated, the interrupt |
| 1456 | * handler is registered with the OS, the watchdog timer is started, |
| 1457 | * and the stack is notified that the interface is ready. |
| 1458 | **/ |
| 1459 | |
| 1460 | static int |
| 1461 | e1000_open(struct net_device *netdev) |
| 1462 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1463 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | int err; |
| 1465 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1466 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1467 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1468 | return -EBUSY; |
| 1469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | /* allocate transmit descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1471 | err = e1000_setup_all_tx_resources(adapter); |
| 1472 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | goto err_setup_tx; |
| 1474 | |
| 1475 | /* allocate receive descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1476 | err = e1000_setup_all_rx_resources(adapter); |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1477 | if (err) |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1478 | goto err_setup_rx; |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1479 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1480 | e1000_power_up_phy(adapter); |
| 1481 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1482 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1483 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1484 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1485 | e1000_update_mng_vlan(adapter); |
| 1486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1488 | /* If AMT is enabled, let the firmware know that the network |
| 1489 | * interface is now open */ |
| 1490 | if (adapter->hw.mac_type == e1000_82573 && |
| 1491 | e1000_check_mng_mode(&adapter->hw)) |
| 1492 | e1000_get_hw_control(adapter); |
| 1493 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1494 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1495 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1496 | * as soon as we call pci_request_irq, so we have to setup our |
| 1497 | * clean_rx handler before we do so. */ |
| 1498 | e1000_configure(adapter); |
| 1499 | |
| 1500 | err = e1000_request_irq(adapter); |
| 1501 | if (err) |
| 1502 | goto err_req_irq; |
| 1503 | |
| 1504 | /* From here on the code is the same as e1000_up() */ |
| 1505 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 1506 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1507 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1508 | napi_enable(&adapter->napi); |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1509 | #endif |
| 1510 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1511 | e1000_irq_enable(adapter); |
| 1512 | |
| 1513 | /* fire a link status change interrupt to start the watchdog */ |
| 1514 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC); |
| 1515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | return E1000_SUCCESS; |
| 1517 | |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1518 | err_req_irq: |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1519 | e1000_release_hw_control(adapter); |
| 1520 | e1000_power_down_phy(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1521 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1523 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | err_setup_tx: |
| 1525 | e1000_reset(adapter); |
| 1526 | |
| 1527 | return err; |
| 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * e1000_close - Disables a network interface |
| 1532 | * @netdev: network interface device structure |
| 1533 | * |
| 1534 | * Returns 0, this is not allowed to fail |
| 1535 | * |
| 1536 | * The close entry point is called when an interface is de-activated |
| 1537 | * by the OS. The hardware is still under the drivers control, but |
| 1538 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1539 | * hardware, and all transmit and receive resources are freed. |
| 1540 | **/ |
| 1541 | |
| 1542 | static int |
| 1543 | e1000_close(struct net_device *netdev) |
| 1544 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1545 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1547 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1549 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1550 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1552 | e1000_free_all_tx_resources(adapter); |
| 1553 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1555 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1556 | * 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] | 1557 | if ((adapter->hw.mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1558 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1559 | !(adapter->vlgrp && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1560 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1561 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1562 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1563 | |
| 1564 | /* If AMT is enabled, let the firmware know that the network |
| 1565 | * interface is now closed */ |
| 1566 | if (adapter->hw.mac_type == e1000_82573 && |
| 1567 | e1000_check_mng_mode(&adapter->hw)) |
| 1568 | e1000_release_hw_control(adapter); |
| 1569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | return 0; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1575 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1576 | * @start: address of beginning of memory |
| 1577 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | **/ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1579 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | e1000_check_64k_bound(struct e1000_adapter *adapter, |
| 1581 | void *start, unsigned long len) |
| 1582 | { |
| 1583 | unsigned long begin = (unsigned long) start; |
| 1584 | unsigned long end = begin + len; |
| 1585 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1586 | /* First rev 82545 and 82546 need to not allow any memory |
| 1587 | * write location to cross 64k boundary due to errata 23 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | if (adapter->hw.mac_type == e1000_82545 || |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1589 | adapter->hw.mac_type == e1000_82546) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1590 | return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1593 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | /** |
| 1597 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1598 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1599 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | * |
| 1601 | * Return 0 on success, negative on failure |
| 1602 | **/ |
| 1603 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1604 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1605 | e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1606 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | struct pci_dev *pdev = adapter->pdev; |
| 1609 | int size; |
| 1610 | |
| 1611 | size = sizeof(struct e1000_buffer) * txdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1612 | txdr->buffer_info = vmalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1613 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1614 | DPRINTK(PROBE, ERR, |
| 1615 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | return -ENOMEM; |
| 1617 | } |
| 1618 | memset(txdr->buffer_info, 0, size); |
| 1619 | |
| 1620 | /* round up to nearest 4K */ |
| 1621 | |
| 1622 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1623 | txdr->size = ALIGN(txdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
| 1625 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1626 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1629 | DPRINTK(PROBE, ERR, |
| 1630 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | return -ENOMEM; |
| 1632 | } |
| 1633 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1634 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1636 | void *olddesc = txdr->desc; |
| 1637 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1638 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1639 | "at %p\n", txdr->size, txdr->desc); |
| 1640 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1642 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1643 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1645 | goto setup_tx_desc_die; |
| 1646 | } |
| 1647 | |
| 1648 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1649 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1650 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1651 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1653 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1654 | "Unable to allocate aligned memory " |
| 1655 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | vfree(txdr->buffer_info); |
| 1657 | return -ENOMEM; |
| 1658 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1659 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1661 | } |
| 1662 | } |
| 1663 | memset(txdr->desc, 0, txdr->size); |
| 1664 | |
| 1665 | txdr->next_to_use = 0; |
| 1666 | txdr->next_to_clean = 0; |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1667 | spin_lock_init(&txdr->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
| 1669 | return 0; |
| 1670 | } |
| 1671 | |
| 1672 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1673 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1674 | * (Descriptors) for all queues |
| 1675 | * @adapter: board private structure |
| 1676 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1677 | * Return 0 on success, negative on failure |
| 1678 | **/ |
| 1679 | |
| 1680 | int |
| 1681 | e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
| 1682 | { |
| 1683 | int i, err = 0; |
| 1684 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1685 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1686 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1687 | if (err) { |
| 1688 | DPRINTK(PROBE, ERR, |
| 1689 | "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1690 | for (i-- ; i >= 0; i--) |
| 1691 | e1000_free_tx_resources(adapter, |
| 1692 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1693 | break; |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | return err; |
| 1698 | } |
| 1699 | |
| 1700 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1702 | * @adapter: board private structure |
| 1703 | * |
| 1704 | * Configure the Tx unit of the MAC after a reset. |
| 1705 | **/ |
| 1706 | |
| 1707 | static void |
| 1708 | e1000_configure_tx(struct e1000_adapter *adapter) |
| 1709 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1710 | uint64_t tdba; |
| 1711 | struct e1000_hw *hw = &adapter->hw; |
| 1712 | uint32_t tdlen, tctl, tipg, tarc; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1713 | uint32_t ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
| 1715 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1716 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1717 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1718 | case 1: |
| 1719 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1720 | tdba = adapter->tx_ring[0].dma; |
| 1721 | tdlen = adapter->tx_ring[0].count * |
| 1722 | sizeof(struct e1000_tx_desc); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1723 | E1000_WRITE_REG(hw, TDLEN, tdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1724 | E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 1725 | E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1726 | E1000_WRITE_REG(hw, TDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1727 | E1000_WRITE_REG(hw, TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1728 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1729 | 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] | 1730 | break; |
| 1731 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
| 1733 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Jesse Brandeburg | d89b6c6 | 2006-12-15 10:38:32 +0100 | [diff] [blame] | 1734 | if (adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 1735 | (hw->media_type == e1000_media_type_fiber || |
| 1736 | hw->media_type == e1000_media_type_internal_serdes)) |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1737 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1738 | else |
| 1739 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1740 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1741 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | case e1000_82542_rev2_0: |
| 1743 | case e1000_82542_rev2_1: |
| 1744 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1745 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1746 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1748 | case e1000_80003es2lan: |
| 1749 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1750 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1751 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1753 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1754 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1755 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1757 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1758 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1759 | E1000_WRITE_REG(hw, TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
| 1761 | /* Set the Tx Interrupt Delay register */ |
| 1762 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1763 | E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 1764 | if (hw->mac_type >= e1000_82540) |
| 1765 | E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
| 1767 | /* Program the Transmit Control Register */ |
| 1768 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1769 | tctl = E1000_READ_REG(hw, TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1771 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1773 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1774 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 1775 | tarc = E1000_READ_REG(hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1776 | /* set the speed mode bit, we'll clear it if we're not at |
| 1777 | * gigabit link later */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1778 | tarc |= (1 << 21); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1779 | E1000_WRITE_REG(hw, TARC0, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1780 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 1781 | tarc = E1000_READ_REG(hw, TARC0); |
| 1782 | tarc |= 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1783 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1784 | tarc = E1000_READ_REG(hw, TARC1); |
| 1785 | tarc |= 1; |
| 1786 | E1000_WRITE_REG(hw, TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1787 | } |
| 1788 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1789 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
| 1791 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1792 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1793 | |
| 1794 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1795 | if (adapter->tx_int_delay) |
| 1796 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1798 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1800 | else |
| 1801 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1802 | |
| 1803 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1804 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1805 | if (hw->mac_type == e1000_82544 && |
| 1806 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1808 | |
| 1809 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** |
| 1814 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1815 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1816 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | * |
| 1818 | * Returns 0 on success, negative on failure |
| 1819 | **/ |
| 1820 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1821 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1822 | e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1823 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1826 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | |
| 1828 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1829 | rxdr->buffer_info = vmalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1830 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1831 | DPRINTK(PROBE, ERR, |
| 1832 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | return -ENOMEM; |
| 1834 | } |
| 1835 | memset(rxdr->buffer_info, 0, size); |
| 1836 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1837 | rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page), |
| 1838 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1839 | if (!rxdr->ps_page) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1840 | vfree(rxdr->buffer_info); |
| 1841 | DPRINTK(PROBE, ERR, |
| 1842 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1843 | return -ENOMEM; |
| 1844 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1845 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1846 | rxdr->ps_page_dma = kcalloc(rxdr->count, |
| 1847 | sizeof(struct e1000_ps_page_dma), |
| 1848 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1849 | if (!rxdr->ps_page_dma) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1850 | vfree(rxdr->buffer_info); |
| 1851 | kfree(rxdr->ps_page); |
| 1852 | DPRINTK(PROBE, ERR, |
| 1853 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1854 | return -ENOMEM; |
| 1855 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1856 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1857 | if (adapter->hw.mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1858 | desc_len = sizeof(struct e1000_rx_desc); |
| 1859 | else |
| 1860 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | /* Round up to nearest 4K */ |
| 1863 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1864 | rxdr->size = rxdr->count * desc_len; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1865 | rxdr->size = ALIGN(rxdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
| 1867 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1868 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1869 | if (!rxdr->desc) { |
| 1870 | DPRINTK(PROBE, ERR, |
| 1871 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | vfree(rxdr->buffer_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1874 | kfree(rxdr->ps_page); |
| 1875 | kfree(rxdr->ps_page_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | return -ENOMEM; |
| 1877 | } |
| 1878 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1879 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1881 | void *olddesc = rxdr->desc; |
| 1882 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1883 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1884 | "at %p\n", rxdr->size, rxdr->desc); |
| 1885 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1887 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1888 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1890 | DPRINTK(PROBE, ERR, |
| 1891 | "Unable to allocate memory " |
| 1892 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | goto setup_rx_desc_die; |
| 1894 | } |
| 1895 | |
| 1896 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1897 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1898 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1899 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1901 | DPRINTK(PROBE, ERR, |
| 1902 | "Unable to allocate aligned memory " |
| 1903 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1904 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1906 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1908 | } |
| 1909 | } |
| 1910 | memset(rxdr->desc, 0, rxdr->size); |
| 1911 | |
| 1912 | rxdr->next_to_clean = 0; |
| 1913 | rxdr->next_to_use = 0; |
| 1914 | |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1919 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1920 | * (Descriptors) for all queues |
| 1921 | * @adapter: board private structure |
| 1922 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1923 | * Return 0 on success, negative on failure |
| 1924 | **/ |
| 1925 | |
| 1926 | int |
| 1927 | e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
| 1928 | { |
| 1929 | int i, err = 0; |
| 1930 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1931 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1932 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1933 | if (err) { |
| 1934 | DPRINTK(PROBE, ERR, |
| 1935 | "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1936 | for (i-- ; i >= 0; i--) |
| 1937 | e1000_free_rx_resources(adapter, |
| 1938 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1939 | break; |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | return err; |
| 1944 | } |
| 1945 | |
| 1946 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1947 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | * @adapter: Board private structure |
| 1949 | **/ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1950 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 1951 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | static void |
| 1953 | e1000_setup_rctl(struct e1000_adapter *adapter) |
| 1954 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1955 | uint32_t rctl, rfctl; |
| 1956 | uint32_t psrctl = 0; |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1957 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1958 | uint32_t pages = 0; |
| 1959 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | |
| 1961 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1962 | |
| 1963 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1964 | |
| 1965 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1966 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1967 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1968 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1969 | if (adapter->hw.tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | rctl |= E1000_RCTL_SBP; |
| 1971 | else |
| 1972 | rctl &= ~E1000_RCTL_SBP; |
| 1973 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1974 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1975 | rctl &= ~E1000_RCTL_LPE; |
| 1976 | else |
| 1977 | rctl |= E1000_RCTL_LPE; |
| 1978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1980 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1981 | rctl |= E1000_RCTL_BSEX; |
| 1982 | switch (adapter->rx_buffer_len) { |
| 1983 | case E1000_RXBUFFER_256: |
| 1984 | rctl |= E1000_RCTL_SZ_256; |
| 1985 | rctl &= ~E1000_RCTL_BSEX; |
| 1986 | break; |
| 1987 | case E1000_RXBUFFER_512: |
| 1988 | rctl |= E1000_RCTL_SZ_512; |
| 1989 | rctl &= ~E1000_RCTL_BSEX; |
| 1990 | break; |
| 1991 | case E1000_RXBUFFER_1024: |
| 1992 | rctl |= E1000_RCTL_SZ_1024; |
| 1993 | rctl &= ~E1000_RCTL_BSEX; |
| 1994 | break; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1995 | case E1000_RXBUFFER_2048: |
| 1996 | default: |
| 1997 | rctl |= E1000_RCTL_SZ_2048; |
| 1998 | rctl &= ~E1000_RCTL_BSEX; |
| 1999 | break; |
| 2000 | case E1000_RXBUFFER_4096: |
| 2001 | rctl |= E1000_RCTL_SZ_4096; |
| 2002 | break; |
| 2003 | case E1000_RXBUFFER_8192: |
| 2004 | rctl |= E1000_RCTL_SZ_8192; |
| 2005 | break; |
| 2006 | case E1000_RXBUFFER_16384: |
| 2007 | rctl |= E1000_RCTL_SZ_16384; |
| 2008 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 2011 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2012 | /* 82571 and greater support packet-split where the protocol |
| 2013 | * header is placed in skb->data and the packet data is |
| 2014 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2015 | * In the case of a non-split, skb->data is linearly filled, |
| 2016 | * followed by the page buffers. Therefore, skb->data is |
| 2017 | * sized to hold the largest protocol header. |
| 2018 | */ |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 2019 | /* allocations using alloc_page take too long for regular MTU |
| 2020 | * so only enable packet split for jumbo frames */ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2021 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 2022 | if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) && |
| 2023 | PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE)) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2024 | adapter->rx_ps_pages = pages; |
| 2025 | else |
| 2026 | adapter->rx_ps_pages = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2027 | #endif |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2028 | if (adapter->rx_ps_pages) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2029 | /* Configure extra packet-split registers */ |
| 2030 | rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
| 2031 | rfctl |= E1000_RFCTL_EXTEN; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2032 | /* disable packet split support for IPv6 extension headers, |
| 2033 | * because some malformed IPv6 headers can hang the RX */ |
| 2034 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 2035 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 2036 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2037 | E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
| 2038 | |
Auke Kok | 7dfee0c | 2006-06-27 09:07:50 -0700 | [diff] [blame] | 2039 | rctl |= E1000_RCTL_DTYP_PS; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2040 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2041 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2042 | E1000_PSRCTL_BSIZE0_SHIFT; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2043 | |
| 2044 | switch (adapter->rx_ps_pages) { |
| 2045 | case 3: |
| 2046 | psrctl |= PAGE_SIZE << |
| 2047 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2048 | case 2: |
| 2049 | psrctl |= PAGE_SIZE << |
| 2050 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2051 | case 1: |
| 2052 | psrctl |= PAGE_SIZE >> |
| 2053 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2054 | break; |
| 2055 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2056 | |
| 2057 | E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2061 | } |
| 2062 | |
| 2063 | /** |
| 2064 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 2065 | * @adapter: board private structure |
| 2066 | * |
| 2067 | * Configure the Rx unit of the MAC after a reset. |
| 2068 | **/ |
| 2069 | |
| 2070 | static void |
| 2071 | e1000_configure_rx(struct e1000_adapter *adapter) |
| 2072 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2073 | uint64_t rdba; |
| 2074 | struct e1000_hw *hw = &adapter->hw; |
| 2075 | uint32_t rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2076 | |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2077 | if (adapter->rx_ps_pages) { |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2078 | /* this is a 32 byte descriptor */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2079 | rdlen = adapter->rx_ring[0].count * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2080 | sizeof(union e1000_rx_desc_packet_split); |
| 2081 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 2082 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
| 2083 | } else { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2084 | rdlen = adapter->rx_ring[0].count * |
| 2085 | sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2086 | adapter->clean_rx = e1000_clean_rx_irq; |
| 2087 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 2088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | |
| 2090 | /* disable receives while setting up the descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2091 | rctl = E1000_READ_REG(hw, RCTL); |
| 2092 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | |
| 2094 | /* set the Receive Delay Timer Register */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2095 | E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2097 | if (hw->mac_type >= e1000_82540) { |
| 2098 | E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2099 | if (adapter->itr_setting != 0) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2100 | E1000_WRITE_REG(hw, ITR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | 1000000000 / (adapter->itr * 256)); |
| 2102 | } |
| 2103 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2104 | if (hw->mac_type >= e1000_82571) { |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2105 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2106 | /* Reset delay timers after every interrupt */ |
Auke Kok | 6fc7a7e | 2006-04-14 19:05:12 -0700 | [diff] [blame] | 2107 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2108 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2109 | /* Auto-Mask interrupts upon ICR access */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2110 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2111 | E1000_WRITE_REG(hw, IAM, 0xffffffff); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2112 | #endif |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2113 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 2114 | E1000_WRITE_FLUSH(hw); |
| 2115 | } |
| 2116 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2117 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2118 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2119 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2120 | case 1: |
| 2121 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2122 | rdba = adapter->rx_ring[0].dma; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2123 | E1000_WRITE_REG(hw, RDLEN, rdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2124 | E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 2125 | E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2126 | E1000_WRITE_REG(hw, RDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2127 | E1000_WRITE_REG(hw, RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 2128 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 2129 | 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] | 2130 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2131 | } |
| 2132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2134 | if (hw->mac_type >= e1000_82543) { |
| 2135 | rxcsum = E1000_READ_REG(hw, RXCSUM); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2136 | if (adapter->rx_csum) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2137 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 2138 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2139 | /* Enable 82571 IPv4 payload checksum for UDP fragments |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2140 | * Must be used in conjunction with packet-split. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2141 | if ((hw->mac_type >= e1000_82571) && |
| 2142 | (adapter->rx_ps_pages)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2143 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 2144 | } |
| 2145 | } else { |
| 2146 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 2147 | /* don't need to clear IPPCSE as it defaults to 0 */ |
| 2148 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2149 | E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Auke Kok | 21c4d5e | 2006-11-01 08:47:39 -0800 | [diff] [blame] | 2152 | /* enable early receives on 82573, only takes effect if using > 2048 |
| 2153 | * byte total frame size. for example only for jumbo frames */ |
| 2154 | #define E1000_ERT_2048 0x100 |
| 2155 | if (hw->mac_type == e1000_82573) |
| 2156 | E1000_WRITE_REG(hw, ERT, E1000_ERT_2048); |
| 2157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | /* Enable Receives */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2159 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2163 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 2164 | * @adapter: board private structure |
| 2165 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2166 | * |
| 2167 | * Free all transmit software resources |
| 2168 | **/ |
| 2169 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2170 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2171 | e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 2172 | struct e1000_tx_ring *tx_ring) |
| 2173 | { |
| 2174 | struct pci_dev *pdev = adapter->pdev; |
| 2175 | |
| 2176 | e1000_clean_tx_ring(adapter, tx_ring); |
| 2177 | |
| 2178 | vfree(tx_ring->buffer_info); |
| 2179 | tx_ring->buffer_info = NULL; |
| 2180 | |
| 2181 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2182 | |
| 2183 | tx_ring->desc = NULL; |
| 2184 | } |
| 2185 | |
| 2186 | /** |
| 2187 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | * @adapter: board private structure |
| 2189 | * |
| 2190 | * Free all transmit software resources |
| 2191 | **/ |
| 2192 | |
| 2193 | void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2194 | e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2196 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2198 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2199 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2202 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 2204 | struct e1000_buffer *buffer_info) |
| 2205 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2206 | if (buffer_info->dma) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2207 | pci_unmap_page(adapter->pdev, |
| 2208 | buffer_info->dma, |
| 2209 | buffer_info->length, |
| 2210 | PCI_DMA_TODEVICE); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2211 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | } |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2213 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2215 | buffer_info->skb = NULL; |
| 2216 | } |
| 2217 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | /** |
| 2221 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2222 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2223 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | **/ |
| 2225 | |
| 2226 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2227 | e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 2228 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | struct e1000_buffer *buffer_info; |
| 2231 | unsigned long size; |
| 2232 | unsigned int i; |
| 2233 | |
| 2234 | /* Free all the Tx ring sk_buffs */ |
| 2235 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2236 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | buffer_info = &tx_ring->buffer_info[i]; |
| 2238 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2239 | } |
| 2240 | |
| 2241 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2242 | memset(tx_ring->buffer_info, 0, size); |
| 2243 | |
| 2244 | /* Zero out the descriptor ring */ |
| 2245 | |
| 2246 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2247 | |
| 2248 | tx_ring->next_to_use = 0; |
| 2249 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2250 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2252 | writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
| 2253 | writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
| 2254 | } |
| 2255 | |
| 2256 | /** |
| 2257 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2258 | * @adapter: board private structure |
| 2259 | **/ |
| 2260 | |
| 2261 | static void |
| 2262 | e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
| 2263 | { |
| 2264 | int i; |
| 2265 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2266 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2267 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /** |
| 2271 | * e1000_free_rx_resources - Free Rx Resources |
| 2272 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2273 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | * |
| 2275 | * Free all receive software resources |
| 2276 | **/ |
| 2277 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2278 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2279 | e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 2280 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | struct pci_dev *pdev = adapter->pdev; |
| 2283 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2284 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | |
| 2286 | vfree(rx_ring->buffer_info); |
| 2287 | rx_ring->buffer_info = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2288 | kfree(rx_ring->ps_page); |
| 2289 | rx_ring->ps_page = NULL; |
| 2290 | kfree(rx_ring->ps_page_dma); |
| 2291 | rx_ring->ps_page_dma = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | |
| 2293 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2294 | |
| 2295 | rx_ring->desc = NULL; |
| 2296 | } |
| 2297 | |
| 2298 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2299 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2301 | * |
| 2302 | * Free all receive software resources |
| 2303 | **/ |
| 2304 | |
| 2305 | void |
| 2306 | e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
| 2307 | { |
| 2308 | int i; |
| 2309 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2310 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2311 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2316 | * @adapter: board private structure |
| 2317 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | **/ |
| 2319 | |
| 2320 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2321 | e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2322 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | struct e1000_buffer *buffer_info; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2325 | struct e1000_ps_page *ps_page; |
| 2326 | struct e1000_ps_page_dma *ps_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | struct pci_dev *pdev = adapter->pdev; |
| 2328 | unsigned long size; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2329 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
| 2331 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2332 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2334 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | pci_unmap_single(pdev, |
| 2336 | buffer_info->dma, |
| 2337 | buffer_info->length, |
| 2338 | PCI_DMA_FROMDEVICE); |
| 2339 | |
| 2340 | dev_kfree_skb(buffer_info->skb); |
| 2341 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2342 | } |
| 2343 | ps_page = &rx_ring->ps_page[i]; |
| 2344 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 2345 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
| 2346 | if (!ps_page->ps_page[j]) break; |
| 2347 | pci_unmap_page(pdev, |
| 2348 | ps_page_dma->ps_page_dma[j], |
| 2349 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 2350 | ps_page_dma->ps_page_dma[j] = 0; |
| 2351 | put_page(ps_page->ps_page[j]); |
| 2352 | ps_page->ps_page[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2357 | memset(rx_ring->buffer_info, 0, size); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2358 | size = sizeof(struct e1000_ps_page) * rx_ring->count; |
| 2359 | memset(rx_ring->ps_page, 0, size); |
| 2360 | size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
| 2361 | memset(rx_ring->ps_page_dma, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | |
| 2363 | /* Zero out the descriptor ring */ |
| 2364 | |
| 2365 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2366 | |
| 2367 | rx_ring->next_to_clean = 0; |
| 2368 | rx_ring->next_to_use = 0; |
| 2369 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2370 | writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
| 2371 | writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
| 2372 | } |
| 2373 | |
| 2374 | /** |
| 2375 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2376 | * @adapter: board private structure |
| 2377 | **/ |
| 2378 | |
| 2379 | static void |
| 2380 | e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
| 2381 | { |
| 2382 | int i; |
| 2383 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2384 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2385 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2389 | * and memory write and invalidate disabled for certain operations |
| 2390 | */ |
| 2391 | static void |
| 2392 | e1000_enter_82542_rst(struct e1000_adapter *adapter) |
| 2393 | { |
| 2394 | struct net_device *netdev = adapter->netdev; |
| 2395 | uint32_t rctl; |
| 2396 | |
| 2397 | e1000_pci_clear_mwi(&adapter->hw); |
| 2398 | |
| 2399 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2400 | rctl |= E1000_RCTL_RST; |
| 2401 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2402 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2403 | mdelay(5); |
| 2404 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2405 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2406 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | static void |
| 2410 | e1000_leave_82542_rst(struct e1000_adapter *adapter) |
| 2411 | { |
| 2412 | struct net_device *netdev = adapter->netdev; |
| 2413 | uint32_t rctl; |
| 2414 | |
| 2415 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2416 | rctl &= ~E1000_RCTL_RST; |
| 2417 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2418 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2419 | mdelay(5); |
| 2420 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2421 | if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | e1000_pci_set_mwi(&adapter->hw); |
| 2423 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2424 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2425 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2426 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2427 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2428 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | /** |
| 2433 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2434 | * @netdev: network interface device structure |
| 2435 | * @p: pointer to an address structure |
| 2436 | * |
| 2437 | * Returns 0 on success, negative on failure |
| 2438 | **/ |
| 2439 | |
| 2440 | static int |
| 2441 | e1000_set_mac(struct net_device *netdev, void *p) |
| 2442 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2443 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | struct sockaddr *addr = p; |
| 2445 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2446 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | return -EADDRNOTAVAIL; |
| 2448 | |
| 2449 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2450 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2451 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | e1000_enter_82542_rst(adapter); |
| 2453 | |
| 2454 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2455 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 2456 | |
| 2457 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2458 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2459 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2460 | * due to controller reset from the other port. */ |
| 2461 | if (adapter->hw.mac_type == e1000_82571) { |
| 2462 | /* activate the work around */ |
| 2463 | adapter->hw.laa_is_present = 1; |
| 2464 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2465 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2466 | * between the time RAR[0] gets clobbered and the time it |
| 2467 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2468 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2469 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2470 | * RAR[14] */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2471 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2472 | E1000_RAR_ENTRIES - 1); |
| 2473 | } |
| 2474 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2475 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | e1000_leave_82542_rst(adapter); |
| 2477 | |
| 2478 | return 0; |
| 2479 | } |
| 2480 | |
| 2481 | /** |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2482 | * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | * @netdev: network interface device structure |
| 2484 | * |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2485 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 2486 | * address lists or the network interface flags are updated. This routine is |
| 2487 | * responsible for configuring the hardware for proper unicast, multicast, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | * promiscuous mode, and all-multi behavior. |
| 2489 | **/ |
| 2490 | |
| 2491 | static void |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2492 | e1000_set_rx_mode(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2494 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | struct e1000_hw *hw = &adapter->hw; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2496 | struct dev_addr_list *uc_ptr; |
| 2497 | struct dev_addr_list *mc_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | uint32_t rctl; |
| 2499 | uint32_t hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2500 | int i, rar_entries = E1000_RAR_ENTRIES; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2501 | int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
| 2502 | E1000_NUM_MTA_REGISTERS_ICH8LAN : |
| 2503 | E1000_NUM_MTA_REGISTERS; |
| 2504 | |
| 2505 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 2506 | rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2508 | /* reserve RAR[14] for LAA over-write work-around */ |
| 2509 | if (adapter->hw.mac_type == e1000_82571) |
| 2510 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2512 | /* Check for Promiscuous and All Multicast modes */ |
| 2513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | rctl = E1000_READ_REG(hw, RCTL); |
| 2515 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2516 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2518 | } else if (netdev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | rctl |= E1000_RCTL_MPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } else { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2521 | rctl &= ~E1000_RCTL_MPE; |
| 2522 | } |
| 2523 | |
| 2524 | uc_ptr = NULL; |
| 2525 | if (netdev->uc_count > rar_entries - 1) { |
| 2526 | rctl |= E1000_RCTL_UPE; |
| 2527 | } else if (!(netdev->flags & IFF_PROMISC)) { |
| 2528 | rctl &= ~E1000_RCTL_UPE; |
| 2529 | uc_ptr = netdev->uc_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 2533 | |
| 2534 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2535 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2536 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | e1000_enter_82542_rst(adapter); |
| 2538 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2539 | /* load the first 14 addresses into the exact filters 1-14. Unicast |
| 2540 | * addresses take precedence to avoid disabling unicast filtering |
| 2541 | * when possible. |
| 2542 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | * RAR 0 is used for the station MAC adddress |
| 2544 | * 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] | 2545 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | */ |
| 2547 | mc_ptr = netdev->mc_list; |
| 2548 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2549 | for (i = 1; i < rar_entries; i++) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2550 | if (uc_ptr) { |
| 2551 | e1000_rar_set(hw, uc_ptr->da_addr, i); |
| 2552 | uc_ptr = uc_ptr->next; |
| 2553 | } else if (mc_ptr) { |
| 2554 | e1000_rar_set(hw, mc_ptr->da_addr, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | mc_ptr = mc_ptr->next; |
| 2556 | } else { |
| 2557 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2558 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2560 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
| 2562 | } |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2563 | WARN_ON(uc_ptr != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | |
| 2565 | /* clear the old settings from the multicast hash table */ |
| 2566 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2567 | for (i = 0; i < mta_reg_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2569 | E1000_WRITE_FLUSH(hw); |
| 2570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | |
| 2572 | /* load any remaining addresses into the hash table */ |
| 2573 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2574 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2575 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | e1000_mta_set(hw, hash_value); |
| 2577 | } |
| 2578 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2579 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | e1000_leave_82542_rst(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2584 | * the phy */ |
| 2585 | |
| 2586 | static void |
| 2587 | e1000_update_phy_info(unsigned long data) |
| 2588 | { |
| 2589 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2590 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
| 2591 | } |
| 2592 | |
| 2593 | /** |
| 2594 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2595 | * @data: pointer to adapter cast into an unsigned long |
| 2596 | **/ |
| 2597 | |
| 2598 | static void |
| 2599 | e1000_82547_tx_fifo_stall(unsigned long data) |
| 2600 | { |
| 2601 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2602 | struct net_device *netdev = adapter->netdev; |
| 2603 | uint32_t tctl; |
| 2604 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2605 | if (atomic_read(&adapter->tx_fifo_stall)) { |
| 2606 | if ((E1000_READ_REG(&adapter->hw, TDT) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | E1000_READ_REG(&adapter->hw, TDH)) && |
| 2608 | (E1000_READ_REG(&adapter->hw, TDFT) == |
| 2609 | E1000_READ_REG(&adapter->hw, TDFH)) && |
| 2610 | (E1000_READ_REG(&adapter->hw, TDFTS) == |
| 2611 | E1000_READ_REG(&adapter->hw, TDFHS))) { |
| 2612 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2613 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 2614 | tctl & ~E1000_TCTL_EN); |
| 2615 | E1000_WRITE_REG(&adapter->hw, TDFT, |
| 2616 | adapter->tx_head_addr); |
| 2617 | E1000_WRITE_REG(&adapter->hw, TDFH, |
| 2618 | adapter->tx_head_addr); |
| 2619 | E1000_WRITE_REG(&adapter->hw, TDFTS, |
| 2620 | adapter->tx_head_addr); |
| 2621 | E1000_WRITE_REG(&adapter->hw, TDFHS, |
| 2622 | adapter->tx_head_addr); |
| 2623 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
| 2624 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2625 | |
| 2626 | adapter->tx_fifo_head = 0; |
| 2627 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2628 | netif_wake_queue(netdev); |
| 2629 | } else { |
| 2630 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2631 | } |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | /** |
| 2636 | * e1000_watchdog - Timer Call-back |
| 2637 | * @data: pointer to adapter cast into an unsigned long |
| 2638 | **/ |
| 2639 | static void |
| 2640 | e1000_watchdog(unsigned long data) |
| 2641 | { |
| 2642 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2644 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2645 | uint32_t link, tctl; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2646 | int32_t ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2648 | ret_val = e1000_check_for_link(&adapter->hw); |
| 2649 | if ((ret_val == E1000_ERR_PHY) && |
| 2650 | (adapter->hw.phy_type == e1000_phy_igp_3) && |
| 2651 | (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 2652 | /* See e1000_kumeran_lock_loss_workaround() */ |
| 2653 | DPRINTK(LINK, INFO, |
| 2654 | "Gigabit has been disabled, downgrading speed\n"); |
| 2655 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2656 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2657 | if (adapter->hw.mac_type == e1000_82573) { |
| 2658 | e1000_enable_tx_pkt_filtering(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2659 | if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2660 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2663 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
| 2665 | link = !adapter->hw.serdes_link_down; |
| 2666 | else |
| 2667 | link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
| 2668 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2669 | if (link) { |
| 2670 | if (!netif_carrier_ok(netdev)) { |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2671 | uint32_t ctrl; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2672 | bool txb2b = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | e1000_get_speed_and_duplex(&adapter->hw, |
| 2674 | &adapter->link_speed, |
| 2675 | &adapter->link_duplex); |
| 2676 | |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2677 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 2678 | DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, " |
| 2679 | "Flow Control: %s\n", |
| 2680 | adapter->link_speed, |
| 2681 | adapter->link_duplex == FULL_DUPLEX ? |
| 2682 | "Full Duplex" : "Half Duplex", |
| 2683 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2684 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2685 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2686 | E1000_CTRL_TFCE) ? "TX" : "None" ))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2688 | /* tweak tx_queue_len according to speed/duplex |
| 2689 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2690 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2691 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2692 | switch (adapter->link_speed) { |
| 2693 | case SPEED_10: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2694 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2695 | netdev->tx_queue_len = 10; |
| 2696 | adapter->tx_timeout_factor = 8; |
| 2697 | break; |
| 2698 | case SPEED_100: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2699 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2700 | netdev->tx_queue_len = 100; |
| 2701 | /* maybe add some timeout factor ? */ |
| 2702 | break; |
| 2703 | } |
| 2704 | |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2705 | if ((adapter->hw.mac_type == e1000_82571 || |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2706 | adapter->hw.mac_type == e1000_82572) && |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2707 | !txb2b) { |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2708 | uint32_t tarc0; |
| 2709 | tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2710 | tarc0 &= ~(1 << 21); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2711 | E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
| 2712 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2713 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2714 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2715 | * some hardware issues */ |
| 2716 | if (!adapter->tso_force && |
| 2717 | adapter->hw.bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2718 | switch (adapter->link_speed) { |
| 2719 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2720 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2721 | DPRINTK(PROBE,INFO, |
| 2722 | "10/100 speed: disabling TSO\n"); |
| 2723 | netdev->features &= ~NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2724 | netdev->features &= ~NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2725 | break; |
| 2726 | case SPEED_1000: |
| 2727 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2728 | netdev->features |= NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2729 | break; |
| 2730 | default: |
| 2731 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2732 | break; |
| 2733 | } |
| 2734 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2735 | |
| 2736 | /* enable transmits in the hardware, need to do this |
| 2737 | * after setting TARC0 */ |
| 2738 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2739 | tctl |= E1000_TCTL_EN; |
| 2740 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | netif_carrier_on(netdev); |
| 2743 | netif_wake_queue(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2744 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | adapter->smartspeed = 0; |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2746 | } else { |
| 2747 | /* make sure the receive unit is started */ |
| 2748 | if (adapter->hw.rx_needs_kicking) { |
| 2749 | struct e1000_hw *hw = &adapter->hw; |
| 2750 | uint32_t rctl = E1000_READ_REG(hw, RCTL); |
| 2751 | E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN); |
| 2752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | } |
| 2754 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2755 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | adapter->link_speed = 0; |
| 2757 | adapter->link_duplex = 0; |
| 2758 | DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
| 2759 | netif_carrier_off(netdev); |
| 2760 | netif_stop_queue(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2761 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2762 | |
| 2763 | /* 80003ES2LAN workaround-- |
| 2764 | * For packet buffer work-around on link down event; |
| 2765 | * disable receives in the ISR and |
| 2766 | * reset device here in the watchdog |
| 2767 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2768 | if (adapter->hw.mac_type == e1000_80003es2lan) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2769 | /* reset device */ |
| 2770 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | e1000_smartspeed(adapter); |
| 2774 | } |
| 2775 | |
| 2776 | e1000_update_stats(adapter); |
| 2777 | |
| 2778 | adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2779 | adapter->tpt_old = adapter->stats.tpt; |
| 2780 | adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2781 | adapter->colc_old = adapter->stats.colc; |
| 2782 | |
| 2783 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2784 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2785 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2786 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2787 | |
| 2788 | e1000_update_adaptive(&adapter->hw); |
| 2789 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2790 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2791 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | /* We've lost link, so the controller stops DMA, |
| 2793 | * but we've got queued Tx work that's never going |
| 2794 | * to get done, so reset controller to flush Tx. |
| 2795 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2796 | adapter->tx_timeout_count++; |
| 2797 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | } |
| 2799 | } |
| 2800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | /* Cause software interrupt to ensure rx ring is cleaned */ |
| 2802 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
| 2803 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2804 | /* Force detection of hung controller every watchdog period */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2805 | adapter->detect_tx_hung = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2807 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2808 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
| 2809 | if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
| 2810 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | /* Reset the timer */ |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2813 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2816 | enum latency_range { |
| 2817 | lowest_latency = 0, |
| 2818 | low_latency = 1, |
| 2819 | bulk_latency = 2, |
| 2820 | latency_invalid = 255 |
| 2821 | }; |
| 2822 | |
| 2823 | /** |
| 2824 | * e1000_update_itr - update the dynamic ITR value based on statistics |
| 2825 | * Stores a new ITR value based on packets and byte |
| 2826 | * counts during the last interrupt. The advantage of per interrupt |
| 2827 | * computation is faster updates and more accurate ITR for the current |
| 2828 | * traffic pattern. Constants in this function were computed |
| 2829 | * based on theoretical maximum wire speed and thresholds were set based |
| 2830 | * on testing data as well as attempting to minimize response time |
| 2831 | * while increasing bulk throughput. |
| 2832 | * this functionality is controlled by the InterruptThrottleRate module |
| 2833 | * parameter (see e1000_param.c) |
| 2834 | * @adapter: pointer to adapter |
| 2835 | * @itr_setting: current adapter->itr |
| 2836 | * @packets: the number of packets during this measurement interval |
| 2837 | * @bytes: the number of bytes during this measurement interval |
| 2838 | **/ |
| 2839 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2840 | uint16_t itr_setting, |
| 2841 | int packets, |
| 2842 | int bytes) |
| 2843 | { |
| 2844 | unsigned int retval = itr_setting; |
| 2845 | struct e1000_hw *hw = &adapter->hw; |
| 2846 | |
| 2847 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2848 | goto update_itr_done; |
| 2849 | |
| 2850 | if (packets == 0) |
| 2851 | goto update_itr_done; |
| 2852 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2853 | switch (itr_setting) { |
| 2854 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2855 | /* jumbo frames get bulk treatment*/ |
| 2856 | if (bytes/packets > 8000) |
| 2857 | retval = bulk_latency; |
| 2858 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2859 | retval = low_latency; |
| 2860 | break; |
| 2861 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2862 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2863 | /* jumbo frames need bulk latency setting */ |
| 2864 | if (bytes/packets > 8000) |
| 2865 | retval = bulk_latency; |
| 2866 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2867 | retval = bulk_latency; |
| 2868 | else if ((packets > 35)) |
| 2869 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2870 | } else if (bytes/packets > 2000) |
| 2871 | retval = bulk_latency; |
| 2872 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2873 | retval = lowest_latency; |
| 2874 | break; |
| 2875 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2876 | if (bytes > 25000) { |
| 2877 | if (packets > 35) |
| 2878 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2879 | } else if (bytes < 6000) { |
| 2880 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2881 | } |
| 2882 | break; |
| 2883 | } |
| 2884 | |
| 2885 | update_itr_done: |
| 2886 | return retval; |
| 2887 | } |
| 2888 | |
| 2889 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2890 | { |
| 2891 | struct e1000_hw *hw = &adapter->hw; |
| 2892 | uint16_t current_itr; |
| 2893 | uint32_t new_itr = adapter->itr; |
| 2894 | |
| 2895 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2896 | return; |
| 2897 | |
| 2898 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2899 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2900 | current_itr = 0; |
| 2901 | new_itr = 4000; |
| 2902 | goto set_itr_now; |
| 2903 | } |
| 2904 | |
| 2905 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2906 | adapter->tx_itr, |
| 2907 | adapter->total_tx_packets, |
| 2908 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2909 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2910 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2911 | adapter->tx_itr = low_latency; |
| 2912 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2913 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2914 | adapter->rx_itr, |
| 2915 | adapter->total_rx_packets, |
| 2916 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2917 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2918 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2919 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2920 | |
| 2921 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2922 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2923 | switch (current_itr) { |
| 2924 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2925 | case lowest_latency: |
| 2926 | new_itr = 70000; |
| 2927 | break; |
| 2928 | case low_latency: |
| 2929 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2930 | break; |
| 2931 | case bulk_latency: |
| 2932 | new_itr = 4000; |
| 2933 | break; |
| 2934 | default: |
| 2935 | break; |
| 2936 | } |
| 2937 | |
| 2938 | set_itr_now: |
| 2939 | if (new_itr != adapter->itr) { |
| 2940 | /* this attempts to bias the interrupt rate towards Bulk |
| 2941 | * by adding intermediate steps when interrupt rate is |
| 2942 | * increasing */ |
| 2943 | new_itr = new_itr > adapter->itr ? |
| 2944 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2945 | new_itr; |
| 2946 | adapter->itr = new_itr; |
| 2947 | E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256)); |
| 2948 | } |
| 2949 | |
| 2950 | return; |
| 2951 | } |
| 2952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2954 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2955 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2956 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2958 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2959 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2960 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2961 | e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2962 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2965 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | unsigned int i; |
| 2967 | uint32_t cmd_length = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2968 | uint16_t ipcse = 0, tucse, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
| 2970 | int err; |
| 2971 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2972 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | if (skb_header_cloned(skb)) { |
| 2974 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2975 | if (err) |
| 2976 | return err; |
| 2977 | } |
| 2978 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2979 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2980 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2981 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2982 | struct iphdr *iph = ip_hdr(skb); |
| 2983 | iph->tot_len = 0; |
| 2984 | iph->check = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2985 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2986 | iph->daddr, 0, |
| 2987 | IPPROTO_TCP, |
| 2988 | 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2989 | cmd_length = E1000_TXD_CMD_IP; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2990 | ipcse = skb_transport_offset(skb) - 1; |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2991 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2992 | ipv6_hdr(skb)->payload_len = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2993 | tcp_hdr(skb)->check = |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2994 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2995 | &ipv6_hdr(skb)->daddr, |
| 2996 | 0, IPPROTO_TCP, 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2997 | ipcse = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2998 | } |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 2999 | ipcss = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 3000 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 3001 | tucss = skb_transport_offset(skb); |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 3002 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | tucse = 0; |
| 3004 | |
| 3005 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3006 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3008 | i = tx_ring->next_to_use; |
| 3009 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3010 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | |
| 3012 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 3013 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 3014 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 3015 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 3016 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 3017 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 3018 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 3019 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 3020 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 3021 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3022 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3023 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3024 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3025 | if (++i == tx_ring->count) i = 0; |
| 3026 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3028 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3030 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3033 | static bool |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3034 | e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3035 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | { |
| 3037 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3038 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | unsigned int i; |
| 3040 | uint8_t css; |
| 3041 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3042 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 3043 | css = skb_transport_offset(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3045 | i = tx_ring->next_to_use; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3046 | buffer_info = &tx_ring->buffer_info[i]; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3047 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | |
Bruce Allan | f6c57ba | 2007-01-18 09:25:28 -0800 | [diff] [blame] | 3049 | context_desc->lower_setup.ip_config = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | context_desc->upper_setup.tcp_fields.tucss = css; |
Herbert Xu | 628592c | 2007-04-23 17:06:40 -0700 | [diff] [blame] | 3051 | context_desc->upper_setup.tcp_fields.tucso = |
| 3052 | css + skb->csum_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 3054 | context_desc->tcp_seg_setup.data = 0; |
| 3055 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 3056 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3057 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3058 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3059 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3060 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 3061 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3063 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3066 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | #define E1000_MAX_TXD_PWR 12 |
| 3070 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 3071 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3072 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3073 | e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3074 | struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
| 3075 | unsigned int nr_frags, unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | struct e1000_buffer *buffer_info; |
| 3078 | unsigned int len = skb->len; |
| 3079 | unsigned int offset = 0, size, count = 0, i; |
| 3080 | unsigned int f; |
| 3081 | len -= skb->data_len; |
| 3082 | |
| 3083 | i = tx_ring->next_to_use; |
| 3084 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3085 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | buffer_info = &tx_ring->buffer_info[i]; |
| 3087 | size = min(len, max_per_txd); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3088 | /* Workaround for Controller erratum -- |
| 3089 | * descriptor for non-tso packet in a linear SKB that follows a |
| 3090 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3091 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3092 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3093 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3094 | tx_ring->last_tx_tso = 0; |
| 3095 | size -= 4; |
| 3096 | } |
| 3097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | /* Workaround for premature desc write-backs |
| 3099 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3100 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | size -= 4; |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3102 | /* work-around for errata 10 and it applies |
| 3103 | * to all controllers in PCI-X mode |
| 3104 | * The fix is to make sure that the first descriptor of a |
| 3105 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 3106 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3107 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3108 | (size > 2015) && count == 0)) |
| 3109 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 3112 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3113 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 3115 | size > 4)) |
| 3116 | size -= 4; |
| 3117 | |
| 3118 | buffer_info->length = size; |
| 3119 | buffer_info->dma = |
| 3120 | pci_map_single(adapter->pdev, |
| 3121 | skb->data + offset, |
| 3122 | size, |
| 3123 | PCI_DMA_TODEVICE); |
| 3124 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3125 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | |
| 3127 | len -= size; |
| 3128 | offset += size; |
| 3129 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3130 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3133 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | struct skb_frag_struct *frag; |
| 3135 | |
| 3136 | frag = &skb_shinfo(skb)->frags[f]; |
| 3137 | len = frag->size; |
| 3138 | offset = frag->page_offset; |
| 3139 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3140 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | buffer_info = &tx_ring->buffer_info[i]; |
| 3142 | size = min(len, max_per_txd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | /* Workaround for premature desc write-backs |
| 3144 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3145 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | size -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | /* Workaround for potential 82544 hang in PCI-X. |
| 3148 | * Avoid terminating buffers within evenly-aligned |
| 3149 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3150 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 3152 | size > 4)) |
| 3153 | size -= 4; |
| 3154 | |
| 3155 | buffer_info->length = size; |
| 3156 | buffer_info->dma = |
| 3157 | pci_map_page(adapter->pdev, |
| 3158 | frag->page, |
| 3159 | offset, |
| 3160 | size, |
| 3161 | PCI_DMA_TODEVICE); |
| 3162 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3163 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | |
| 3165 | len -= size; |
| 3166 | offset += size; |
| 3167 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3168 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 3173 | tx_ring->buffer_info[i].skb = skb; |
| 3174 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3175 | |
| 3176 | return count; |
| 3177 | } |
| 3178 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3179 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3180 | e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3181 | int tx_flags, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | struct e1000_tx_desc *tx_desc = NULL; |
| 3184 | struct e1000_buffer *buffer_info; |
| 3185 | uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 3186 | unsigned int i; |
| 3187 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3188 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3190 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3191 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3192 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3193 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3194 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3197 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3199 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3200 | } |
| 3201 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3202 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3204 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3205 | } |
| 3206 | |
| 3207 | i = tx_ring->next_to_use; |
| 3208 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3209 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | buffer_info = &tx_ring->buffer_info[i]; |
| 3211 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3212 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3213 | tx_desc->lower.data = |
| 3214 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3215 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3216 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3220 | |
| 3221 | /* Force memory writes to complete before letting h/w |
| 3222 | * know there are new descriptors to fetch. (Only |
| 3223 | * applicable for weak-ordered memory model archs, |
| 3224 | * such as IA-64). */ |
| 3225 | wmb(); |
| 3226 | |
| 3227 | tx_ring->next_to_use = i; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3228 | writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 3229 | /* we need this if more than one processor can write to our tail |
| 3230 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3231 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | /** |
| 3235 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 3236 | * The workaround is to avoid queuing a large packet that would span |
| 3237 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 3238 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 3239 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 3240 | * to the beginning of the Tx FIFO. |
| 3241 | **/ |
| 3242 | |
| 3243 | #define E1000_FIFO_HDR 0x10 |
| 3244 | #define E1000_82547_PAD_LEN 0x3E0 |
| 3245 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3246 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3248 | { |
| 3249 | uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 3250 | uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR; |
| 3251 | |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 3252 | skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3254 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | goto no_fifo_stall_required; |
| 3256 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3257 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | return 1; |
| 3259 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3260 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3262 | return 1; |
| 3263 | } |
| 3264 | |
| 3265 | no_fifo_stall_required: |
| 3266 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3267 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3269 | return 0; |
| 3270 | } |
| 3271 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3272 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3273 | static int |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3274 | e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3275 | { |
| 3276 | struct e1000_hw *hw = &adapter->hw; |
| 3277 | uint16_t length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3278 | if (vlan_tx_tag_present(skb)) { |
| 3279 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3280 | ( adapter->hw.mng_cookie.status & |
| 3281 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 3282 | return 0; |
| 3283 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 3284 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3285 | struct ethhdr *eth = (struct ethhdr *) skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3286 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 3287 | const struct iphdr *ip = |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3288 | (struct iphdr *)((uint8_t *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3289 | if (IPPROTO_UDP == ip->protocol) { |
| 3290 | struct udphdr *udp = |
| 3291 | (struct udphdr *)((uint8_t *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3292 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3293 | if (ntohs(udp->dest) == 67) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3294 | offset = (uint8_t *)udp + 8 - skb->data; |
| 3295 | length = skb->len - offset; |
| 3296 | |
| 3297 | return e1000_mng_write_dhcp_info(hw, |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3298 | (uint8_t *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3299 | length); |
| 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | } |
| 3304 | return 0; |
| 3305 | } |
| 3306 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3307 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3308 | { |
| 3309 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3310 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3311 | |
| 3312 | netif_stop_queue(netdev); |
| 3313 | /* Herbert's original patch had: |
| 3314 | * smp_mb__after_netif_stop_queue(); |
| 3315 | * but since that doesn't exist yet, just open code it. */ |
| 3316 | smp_mb(); |
| 3317 | |
| 3318 | /* We need to check again in a case another CPU has just |
| 3319 | * made room available. */ |
| 3320 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3321 | return -EBUSY; |
| 3322 | |
| 3323 | /* A reprieve! */ |
| 3324 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3325 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3326 | return 0; |
| 3327 | } |
| 3328 | |
| 3329 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3330 | struct e1000_tx_ring *tx_ring, int size) |
| 3331 | { |
| 3332 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3333 | return 0; |
| 3334 | return __e1000_maybe_stop_tx(netdev, size); |
| 3335 | } |
| 3336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 3338 | static int |
| 3339 | e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 3340 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3341 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3342 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3344 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3345 | unsigned int tx_flags = 0; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3346 | unsigned int len = skb->len - skb->data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | unsigned long flags; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3348 | unsigned int nr_frags; |
| 3349 | unsigned int mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3351 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3354 | /* This goes back to the question of how to logically map a tx queue |
| 3355 | * to a flow. Right now, performance is impacted slightly negatively |
| 3356 | * if using multiple tx queues. If the stack breaks away from a |
| 3357 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3358 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3359 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3360 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | dev_kfree_skb_any(skb); |
| 3362 | return NETDEV_TX_OK; |
| 3363 | } |
| 3364 | |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3365 | /* 82571 and newer doesn't need the workaround that limited descriptor |
| 3366 | * length to 4kB */ |
| 3367 | if (adapter->hw.mac_type >= e1000_82571) |
| 3368 | max_per_txd = 8192; |
| 3369 | |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3370 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3371 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | * make sure there is enough room in the FIFO before |
| 3373 | * initiating the DMA for each buffer. The calc is: |
| 3374 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3375 | * overrun the FIFO, adjust the max buffer len if mss |
| 3376 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3377 | if (mss) { |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3378 | uint8_t hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | max_per_txd = min(mss << 2, max_per_txd); |
| 3380 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3381 | |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3382 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3383 | * points to just header, pull a few bytes of payload from |
| 3384 | * frags into skb->data */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 3385 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3386 | if (skb->data_len && hdr_len == len) { |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3387 | switch (adapter->hw.mac_type) { |
| 3388 | unsigned int pull_size; |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3389 | case e1000_82544: |
| 3390 | /* Make sure we have room to chop off 4 bytes, |
| 3391 | * and that the end alignment will work out to |
| 3392 | * this hardware's requirements |
| 3393 | * NOTE: this is a TSO only workaround |
| 3394 | * if end byte alignment not correct move us |
| 3395 | * into the next dword */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3396 | if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3397 | break; |
| 3398 | /* fall through */ |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3399 | case e1000_82571: |
| 3400 | case e1000_82572: |
| 3401 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3402 | case e1000_ich8lan: |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3403 | pull_size = min((unsigned int)4, skb->data_len); |
| 3404 | if (!__pskb_pull_tail(skb, pull_size)) { |
Auke Kok | a5eafce | 2006-06-27 09:06:49 -0700 | [diff] [blame] | 3405 | DPRINTK(DRV, ERR, |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3406 | "__pskb_pull_tail failed.\n"); |
| 3407 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc70 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3408 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3409 | } |
| 3410 | len = skb->len - skb->data_len; |
| 3411 | break; |
| 3412 | default: |
| 3413 | /* do nothing */ |
| 3414 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3415 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3419 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3420 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3422 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3423 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3424 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3425 | 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] | 3426 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3429 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3430 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | count++; |
| 3432 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3433 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3434 | * in PCI-X mode, so add one more descriptor to the count |
| 3435 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3436 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3437 | (len > 2015))) |
| 3438 | count++; |
| 3439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3441 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3443 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3444 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | count += nr_frags; |
| 3446 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3447 | |
| 3448 | if (adapter->hw.tx_pkt_filtering && |
| 3449 | (adapter->hw.mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3450 | e1000_transfer_dhcp_info(adapter, skb); |
| 3451 | |
Mark Huth | f50393f | 2007-03-06 08:57:26 -0800 | [diff] [blame] | 3452 | if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3453 | /* Collision - tell upper layer to requeue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3454 | return NETDEV_TX_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | |
| 3456 | /* need: count + 2 desc gap to keep tail from touching |
| 3457 | * head, otherwise try next time */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3458 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3459 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | return NETDEV_TX_BUSY; |
| 3461 | } |
| 3462 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3463 | if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
| 3464 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | netif_stop_queue(netdev); |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3466 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3467 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | return NETDEV_TX_BUSY; |
| 3469 | } |
| 3470 | } |
| 3471 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3472 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3474 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3475 | } |
| 3476 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3477 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3478 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3479 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | if (tso < 0) { |
| 3481 | dev_kfree_skb_any(skb); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3482 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | return NETDEV_TX_OK; |
| 3484 | } |
| 3485 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3486 | if (likely(tso)) { |
| 3487 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3489 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3491 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3492 | /* 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] | 3493 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3494 | * no longer assume, we must. */ |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3495 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3496 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3497 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3498 | e1000_tx_queue(adapter, tx_ring, tx_flags, |
| 3499 | e1000_tx_map(adapter, tx_ring, skb, first, |
| 3500 | max_per_txd, nr_frags, mss)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | |
| 3502 | netdev->trans_start = jiffies; |
| 3503 | |
| 3504 | /* Make sure there is space in the ring for the next send. */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3505 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3507 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | return NETDEV_TX_OK; |
| 3509 | } |
| 3510 | |
| 3511 | /** |
| 3512 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3513 | * @netdev: network interface device structure |
| 3514 | **/ |
| 3515 | |
| 3516 | static void |
| 3517 | e1000_tx_timeout(struct net_device *netdev) |
| 3518 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3519 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | |
| 3521 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3522 | adapter->tx_timeout_count++; |
| 3523 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | static void |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3527 | e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3529 | struct e1000_adapter *adapter = |
| 3530 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3532 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | /** |
| 3536 | * e1000_get_stats - Get System Network Statistics |
| 3537 | * @netdev: network interface device structure |
| 3538 | * |
| 3539 | * Returns the address of the device statistics structure. |
| 3540 | * The statistics are actually updated from the timer callback. |
| 3541 | **/ |
| 3542 | |
| 3543 | static struct net_device_stats * |
| 3544 | e1000_get_stats(struct net_device *netdev) |
| 3545 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3546 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3548 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | return &adapter->net_stats; |
| 3550 | } |
| 3551 | |
| 3552 | /** |
| 3553 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3554 | * @netdev: network interface device structure |
| 3555 | * @new_mtu: new value for maximum frame size |
| 3556 | * |
| 3557 | * Returns 0 on success, negative on failure |
| 3558 | **/ |
| 3559 | |
| 3560 | static int |
| 3561 | e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 3562 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3563 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3565 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3567 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3568 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3569 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3570 | return -EINVAL; |
| 3571 | } |
| 3572 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3573 | /* Adapter-specific max frame size limits. */ |
| 3574 | switch (adapter->hw.mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3575 | case e1000_undefined ... e1000_82542_rev2_1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3576 | case e1000_ich8lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3577 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3578 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3579 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3580 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3581 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3582 | case e1000_82573: |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3583 | /* Jumbo Frames not supported if: |
| 3584 | * - this is not an 82573L device |
| 3585 | * - ASPM is enabled in any way (0x1A bits 3:2) */ |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3586 | e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
| 3587 | &eeprom_data); |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3588 | if ((adapter->hw.device_id != E1000_DEV_ID_82573L) || |
| 3589 | (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3590 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3591 | DPRINTK(PROBE, ERR, |
| 3592 | "Jumbo Frames not supported.\n"); |
| 3593 | return -EINVAL; |
| 3594 | } |
| 3595 | break; |
| 3596 | } |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3597 | /* ERT will be enabled later to enable wire speed receives */ |
| 3598 | |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3599 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3600 | case e1000_82571: |
| 3601 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3602 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3603 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3604 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3605 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3606 | return -EINVAL; |
| 3607 | } |
| 3608 | break; |
| 3609 | default: |
| 3610 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3611 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3614 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3615 | * means we reserve 2 more, this pushes us to allocate from the next |
| 3616 | * larger slab size |
| 3617 | * i.e. RXBUFFER_2048 --> size-4096 slab */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3618 | |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3619 | if (max_frame <= E1000_RXBUFFER_256) |
| 3620 | adapter->rx_buffer_len = E1000_RXBUFFER_256; |
| 3621 | else if (max_frame <= E1000_RXBUFFER_512) |
| 3622 | adapter->rx_buffer_len = E1000_RXBUFFER_512; |
| 3623 | else if (max_frame <= E1000_RXBUFFER_1024) |
| 3624 | adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
| 3625 | else if (max_frame <= E1000_RXBUFFER_2048) |
| 3626 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
| 3627 | else if (max_frame <= E1000_RXBUFFER_4096) |
| 3628 | adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
| 3629 | else if (max_frame <= E1000_RXBUFFER_8192) |
| 3630 | adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
| 3631 | else if (max_frame <= E1000_RXBUFFER_16384) |
| 3632 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
| 3633 | |
| 3634 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3635 | if (!adapter->hw.tbi_compatibility_on && |
| 3636 | ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
| 3637 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3638 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3639 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3640 | netdev->mtu = new_mtu; |
Bruce Allan | 83cd827 | 2006-12-15 10:36:35 +0100 | [diff] [blame] | 3641 | adapter->hw.max_frame_size = max_frame; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3642 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3643 | if (netif_running(netdev)) |
| 3644 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | return 0; |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * e1000_update_stats - Update the board statistics counters |
| 3651 | * @adapter: board private structure |
| 3652 | **/ |
| 3653 | |
| 3654 | void |
| 3655 | e1000_update_stats(struct e1000_adapter *adapter) |
| 3656 | { |
| 3657 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3658 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | unsigned long flags; |
| 3660 | uint16_t phy_tmp; |
| 3661 | |
| 3662 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3663 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3664 | /* |
| 3665 | * Prevent stats update while adapter is being reset, or if the pci |
| 3666 | * connection is down. |
| 3667 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3668 | if (adapter->link_speed == 0) |
| 3669 | return; |
Linas Vepstas | 81b1955 | 2006-12-12 18:29:15 -0600 | [diff] [blame] | 3670 | if (pci_channel_offline(pdev)) |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3671 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3674 | |
Masatake YAMATO | 828d055 | 2007-10-20 03:06:37 +0200 | [diff] [blame] | 3675 | /* these counters are modified from e1000_tbi_adjust_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | * called from the interrupt context, so they must only |
| 3677 | * be written while holding adapter->stats_lock |
| 3678 | */ |
| 3679 | |
| 3680 | adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
| 3681 | adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
| 3682 | adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
| 3683 | adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
| 3684 | adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
| 3685 | adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
| 3686 | adapter->stats.roc += E1000_READ_REG(hw, ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3687 | |
| 3688 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3689 | adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
| 3690 | adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
| 3691 | adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
| 3692 | adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
| 3693 | adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
| 3694 | adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | |
| 3697 | adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
| 3698 | adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
| 3699 | adapter->stats.scc += E1000_READ_REG(hw, SCC); |
| 3700 | adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
| 3701 | adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
| 3702 | adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
| 3703 | adapter->stats.dc += E1000_READ_REG(hw, DC); |
| 3704 | adapter->stats.sec += E1000_READ_REG(hw, SEC); |
| 3705 | adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
| 3706 | adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
| 3707 | adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
| 3708 | adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
| 3709 | adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
| 3710 | adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
| 3711 | adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
| 3712 | adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
| 3713 | adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
| 3714 | adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
| 3715 | adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
| 3716 | adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
| 3717 | adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
| 3718 | adapter->stats.torl += E1000_READ_REG(hw, TORL); |
| 3719 | adapter->stats.torh += E1000_READ_REG(hw, TORH); |
| 3720 | adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
| 3721 | adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
| 3722 | adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3723 | |
| 3724 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3725 | adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
| 3726 | adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
| 3727 | adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
| 3728 | adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
| 3729 | adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
| 3730 | adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
| 3734 | adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
| 3735 | |
| 3736 | /* used for adaptive IFS */ |
| 3737 | |
| 3738 | hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
| 3739 | adapter->stats.tpt += hw->tx_packet_delta; |
| 3740 | hw->collision_delta = E1000_READ_REG(hw, COLC); |
| 3741 | adapter->stats.colc += hw->collision_delta; |
| 3742 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3743 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
| 3745 | adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
| 3746 | adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
| 3747 | adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
| 3748 | adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
| 3749 | adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
| 3750 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3751 | if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3752 | adapter->stats.iac += E1000_READ_REG(hw, IAC); |
| 3753 | adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3754 | |
| 3755 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3756 | adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
| 3757 | adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
| 3758 | adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
| 3759 | adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
| 3760 | adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
| 3761 | adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
| 3762 | adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3763 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | |
| 3766 | /* Fill out the OS statistics structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3768 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3769 | |
| 3770 | /* Rx Errors */ |
| 3771 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3772 | /* RLEC on some newer hardware can be incorrect so build |
| 3773 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3775 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3776 | adapter->stats.ruc + adapter->stats.roc + |
| 3777 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3778 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
| 3779 | adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3781 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3783 | |
| 3784 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3785 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
| 3786 | adapter->net_stats.tx_errors = adapter->stats.txerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3788 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3789 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3790 | if (adapter->hw.bad_tx_carr_stats_fd && |
| 3791 | adapter->link_duplex == FULL_DUPLEX) { |
| 3792 | adapter->net_stats.tx_carrier_errors = 0; |
| 3793 | adapter->stats.tncrs = 0; |
| 3794 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | |
| 3796 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3797 | |
| 3798 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3799 | if (hw->media_type == e1000_media_type_copper) { |
| 3800 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3802 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3803 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3804 | } |
| 3805 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3806 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | (hw->phy_type == e1000_phy_m88) && |
| 3808 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3809 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3810 | } |
| 3811 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3812 | /* Management Stats */ |
| 3813 | if (adapter->hw.has_smbus) { |
| 3814 | adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC); |
| 3815 | adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC); |
| 3816 | adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC); |
| 3817 | } |
| 3818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3820 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3821 | |
| 3822 | /** |
| 3823 | * e1000_intr_msi - Interrupt Handler |
| 3824 | * @irq: interrupt number |
| 3825 | * @data: pointer to a network interface device structure |
| 3826 | **/ |
| 3827 | |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3828 | static irqreturn_t |
| 3829 | e1000_intr_msi(int irq, void *data) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3830 | { |
| 3831 | struct net_device *netdev = data; |
| 3832 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3833 | struct e1000_hw *hw = &adapter->hw; |
| 3834 | #ifndef CONFIG_E1000_NAPI |
| 3835 | int i; |
| 3836 | #endif |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3837 | uint32_t icr = E1000_READ_REG(hw, ICR); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3838 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3839 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3840 | /* read ICR disables interrupts using IAM, so keep up with our |
| 3841 | * enable/disable accounting */ |
| 3842 | atomic_inc(&adapter->irq_sem); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3843 | #endif |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3844 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 3845 | hw->get_link_status = 1; |
| 3846 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
| 3847 | * link down event; disable receives here in the ISR and reset |
| 3848 | * adapter in watchdog */ |
| 3849 | if (netif_carrier_ok(netdev) && |
| 3850 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3851 | /* disable receives */ |
| 3852 | uint32_t rctl = E1000_READ_REG(hw, RCTL); |
| 3853 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3854 | } |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3855 | /* guard against interrupt when we're going down */ |
| 3856 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3857 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3861 | if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3862 | adapter->total_tx_bytes = 0; |
| 3863 | adapter->total_tx_packets = 0; |
| 3864 | adapter->total_rx_bytes = 0; |
| 3865 | adapter->total_rx_packets = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3866 | __netif_rx_schedule(netdev, &adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3867 | } else |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3868 | e1000_irq_enable(adapter); |
| 3869 | #else |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3870 | adapter->total_tx_bytes = 0; |
| 3871 | adapter->total_rx_bytes = 0; |
| 3872 | adapter->total_tx_packets = 0; |
| 3873 | adapter->total_rx_packets = 0; |
| 3874 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3875 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3876 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3877 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3878 | break; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3879 | |
| 3880 | if (likely(adapter->itr_setting & 3)) |
| 3881 | e1000_set_itr(adapter); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3882 | #endif |
| 3883 | |
| 3884 | return IRQ_HANDLED; |
| 3885 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | |
| 3887 | /** |
| 3888 | * e1000_intr - Interrupt Handler |
| 3889 | * @irq: interrupt number |
| 3890 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | **/ |
| 3892 | |
| 3893 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3894 | e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | { |
| 3896 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3897 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3899 | uint32_t rctl, icr = E1000_READ_REG(hw, ICR); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3900 | #ifndef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3901 | int i; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3902 | #endif |
| 3903 | if (unlikely(!icr)) |
| 3904 | return IRQ_NONE; /* Not our interrupt */ |
| 3905 | |
| 3906 | #ifdef CONFIG_E1000_NAPI |
| 3907 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 3908 | * not set, then the adapter didn't send an interrupt */ |
| 3909 | if (unlikely(hw->mac_type >= e1000_82571 && |
| 3910 | !(icr & E1000_ICR_INT_ASSERTED))) |
| 3911 | return IRQ_NONE; |
| 3912 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3913 | /* Interrupt Auto-Mask...upon reading ICR, |
| 3914 | * interrupts are masked. No need for the |
| 3915 | * IMC write, but it does mean we should |
| 3916 | * account for it ASAP. */ |
| 3917 | if (likely(hw->mac_type >= e1000_82571)) |
| 3918 | atomic_inc(&adapter->irq_sem); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 3919 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3921 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3923 | /* 80003ES2LAN workaround-- |
| 3924 | * For packet buffer work-around on link down event; |
| 3925 | * disable receives here in the ISR and |
| 3926 | * reset adapter in watchdog |
| 3927 | */ |
| 3928 | if (netif_carrier_ok(netdev) && |
| 3929 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3930 | /* disable receives */ |
| 3931 | rctl = E1000_READ_REG(hw, RCTL); |
| 3932 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3933 | } |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3934 | /* guard against interrupt when we're going down */ |
| 3935 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3936 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3940 | if (unlikely(hw->mac_type < e1000_82571)) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3941 | /* disable interrupts, without the synchronize_irq bit */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3942 | atomic_inc(&adapter->irq_sem); |
| 3943 | E1000_WRITE_REG(hw, IMC, ~0); |
| 3944 | E1000_WRITE_FLUSH(hw); |
| 3945 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3946 | if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3947 | adapter->total_tx_bytes = 0; |
| 3948 | adapter->total_tx_packets = 0; |
| 3949 | adapter->total_rx_bytes = 0; |
| 3950 | adapter->total_rx_packets = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3951 | __netif_rx_schedule(netdev, &adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3952 | } else |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3953 | /* this really should not happen! if it does it is basically a |
| 3954 | * bug, but not a hard error, so enable ints and continue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3955 | e1000_irq_enable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3956 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | /* Writing IMC and IMS is needed for 82547. |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3958 | * Due to Hub Link bus being occupied, an interrupt |
| 3959 | * de-assertion message is not able to be sent. |
| 3960 | * When an interrupt assertion message is generated later, |
| 3961 | * two messages are re-ordered and sent out. |
| 3962 | * That causes APIC to think 82547 is in de-assertion |
| 3963 | * state, while 82547 is in assertion state, resulting |
| 3964 | * in dead lock. Writing IMC forces 82547 into |
| 3965 | * de-assertion state. |
| 3966 | */ |
| 3967 | 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] | 3968 | atomic_inc(&adapter->irq_sem); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3969 | E1000_WRITE_REG(hw, IMC, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3972 | adapter->total_tx_bytes = 0; |
| 3973 | adapter->total_rx_bytes = 0; |
| 3974 | adapter->total_tx_packets = 0; |
| 3975 | adapter->total_rx_packets = 0; |
| 3976 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3977 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3978 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3979 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | break; |
| 3981 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3982 | if (likely(adapter->itr_setting & 3)) |
| 3983 | e1000_set_itr(adapter); |
| 3984 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3985 | 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] | 3986 | e1000_irq_enable(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3987 | |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3988 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | return IRQ_HANDLED; |
| 3990 | } |
| 3991 | |
| 3992 | #ifdef CONFIG_E1000_NAPI |
| 3993 | /** |
| 3994 | * e1000_clean - NAPI Rx polling callback |
| 3995 | * @adapter: board private structure |
| 3996 | **/ |
| 3997 | |
| 3998 | static int |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3999 | e1000_clean(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4001 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
| 4002 | struct net_device *poll_dev = adapter->netdev; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4003 | int tx_cleaned = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4004 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4005 | /* Must NOT use netdev_priv macro here. */ |
| 4006 | adapter = poll_dev->priv; |
| 4007 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 4008 | /* e1000_clean is called per-cpu. This lock protects |
| 4009 | * tx_ring[0] from being cleaned by multiple cpus |
| 4010 | * simultaneously. A failure obtaining the lock means |
| 4011 | * tx_ring[0] is currently being cleaned anyway. */ |
| 4012 | if (spin_trylock(&adapter->tx_queue_lock)) { |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4013 | tx_cleaned = e1000_clean_tx_irq(adapter, |
| 4014 | &adapter->tx_ring[0]); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 4015 | spin_unlock(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4016 | } |
| 4017 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 4018 | adapter->clean_rx(adapter, &adapter->rx_ring[0], |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4019 | &work_done, budget); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4020 | |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 4021 | if (tx_cleaned) |
| 4022 | work_done = budget; |
| 4023 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 4024 | /* If budget not fully consumed, exit the polling mode */ |
| 4025 | if (work_done < budget) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4026 | if (likely(adapter->itr_setting & 3)) |
| 4027 | e1000_set_itr(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4028 | netif_rx_complete(poll_dev, napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | } |
| 4031 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4032 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | #endif |
| 4036 | /** |
| 4037 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 4038 | * @adapter: board private structure |
| 4039 | **/ |
| 4040 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4041 | static bool |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4042 | e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 4043 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | struct net_device *netdev = adapter->netdev; |
| 4046 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 4047 | struct e1000_buffer *buffer_info; |
| 4048 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 4049 | #ifdef CONFIG_E1000_NAPI |
| 4050 | unsigned int count = 0; |
| 4051 | #endif |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4052 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4053 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | |
| 4055 | i = tx_ring->next_to_clean; |
| 4056 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 4057 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 4058 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4059 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4060 | for (cleaned = false; !cleaned; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4062 | buffer_info = &tx_ring->buffer_info[i]; |
| 4063 | cleaned = (i == eop); |
| 4064 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4065 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 4066 | struct sk_buff *skb = buffer_info->skb; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 4067 | unsigned int segs, bytecount; |
| 4068 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 4069 | /* multiply data chunks by size of headers */ |
| 4070 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 4071 | skb->len; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 4072 | total_tx_packets += segs; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 4073 | total_tx_bytes += bytecount; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4074 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 4075 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 4076 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4078 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 4082 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 4083 | #ifdef CONFIG_E1000_NAPI |
| 4084 | #define E1000_TX_WEIGHT 64 |
| 4085 | /* weight of a sort for tx, to avoid endless transmit cleanup */ |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 4086 | if (count++ == E1000_TX_WEIGHT) break; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 4087 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | tx_ring->next_to_clean = i; |
| 4091 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 4092 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 4093 | if (unlikely(cleaned && netif_carrier_ok(netdev) && |
| 4094 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 4095 | /* Make sure that anybody stopping the queue after this |
| 4096 | * sees the new next_to_clean. |
| 4097 | */ |
| 4098 | smp_mb(); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 4099 | if (netif_queue_stopped(netdev)) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 4100 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 4101 | ++adapter->restart_queue; |
| 4102 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 4103 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4104 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4105 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4106 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | * check with the clearing of time_stamp and movement of i */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4108 | adapter->detect_tx_hung = false; |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4109 | if (tx_ring->buffer_info[eop].dma && |
| 4110 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 4111 | (adapter->tx_timeout_factor * HZ)) |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4112 | && !(E1000_READ_REG(&adapter->hw, STATUS) & |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4113 | E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4114 | |
| 4115 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 4116 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 4117 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4118 | " TDH <%x>\n" |
| 4119 | " TDT <%x>\n" |
| 4120 | " next_to_use <%x>\n" |
| 4121 | " next_to_clean <%x>\n" |
| 4122 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4123 | " time_stamp <%lx>\n" |
| 4124 | " next_to_watch <%x>\n" |
| 4125 | " jiffies <%lx>\n" |
| 4126 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 4127 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 4128 | sizeof(struct e1000_tx_ring)), |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4129 | readl(adapter->hw.hw_addr + tx_ring->tdh), |
| 4130 | readl(adapter->hw.hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4131 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4132 | tx_ring->next_to_clean, |
| 4133 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4134 | eop, |
| 4135 | jiffies, |
| 4136 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4140 | adapter->total_tx_bytes += total_tx_bytes; |
| 4141 | adapter->total_tx_packets += total_tx_packets; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4142 | adapter->net_stats.tx_bytes += total_tx_bytes; |
| 4143 | adapter->net_stats.tx_packets += total_tx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | return cleaned; |
| 4145 | } |
| 4146 | |
| 4147 | /** |
| 4148 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4149 | * @adapter: board private structure |
| 4150 | * @status_err: receive descriptor status and error fields |
| 4151 | * @csum: receive descriptor csum field |
| 4152 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | **/ |
| 4154 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 4155 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | e1000_rx_checksum(struct e1000_adapter *adapter, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4157 | uint32_t status_err, uint32_t csum, |
| 4158 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4160 | uint16_t status = (uint16_t)status_err; |
| 4161 | uint8_t errors = (uint8_t)(status_err >> 24); |
| 4162 | skb->ip_summed = CHECKSUM_NONE; |
| 4163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | /* 82543 or newer only */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4165 | if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4167 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4168 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4169 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4170 | /* let the stack verify checksum errors */ |
| 4171 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | return; |
| 4173 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4174 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4175 | if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
| 4176 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4177 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4179 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4180 | return; |
| 4181 | } |
| 4182 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4183 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | /* TCP checksum is good */ |
| 4185 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4186 | } else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
| 4187 | /* IP fragment with UDP payload */ |
| 4188 | /* Hardware complements the payload checksum, so we undo it |
| 4189 | * and then put the value in host order for further stack use. |
| 4190 | */ |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 4191 | __sum16 sum = (__force __sum16)htons(csum); |
| 4192 | skb->csum = csum_unfold(~sum); |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 4193 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4195 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4199 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | * @adapter: board private structure |
| 4201 | **/ |
| 4202 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4203 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4205 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4206 | struct e1000_rx_ring *rx_ring, |
| 4207 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4209 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4210 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | #endif |
| 4212 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | struct net_device *netdev = adapter->netdev; |
| 4214 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4215 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4216 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | unsigned long flags; |
| 4218 | uint32_t length; |
| 4219 | uint8_t last_byte; |
| 4220 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4221 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4222 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4223 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | |
| 4225 | i = rx_ring->next_to_clean; |
| 4226 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4227 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4229 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4230 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4231 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4234 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | break; |
| 4236 | (*work_done)++; |
| 4237 | #endif |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4238 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4239 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4240 | buffer_info->skb = NULL; |
| 4241 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4242 | prefetch(skb->data - NET_IP_ALIGN); |
| 4243 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4244 | if (++i == rx_ring->count) i = 0; |
| 4245 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4246 | prefetch(next_rxd); |
| 4247 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4248 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4249 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4250 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4251 | cleaned_count++; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4252 | pci_unmap_single(pdev, |
| 4253 | buffer_info->dma, |
| 4254 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | PCI_DMA_FROMDEVICE); |
| 4256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | length = le16_to_cpu(rx_desc->length); |
| 4258 | |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4259 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
| 4260 | /* All receives must fit into a single buffer */ |
| 4261 | E1000_DBG("%s: Receive packet consumed multiple" |
| 4262 | " buffers\n", netdev->name); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 4263 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4264 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | goto next_desc; |
| 4266 | } |
| 4267 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4268 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | last_byte = *(skb->data + length - 1); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4270 | if (TBI_ACCEPT(&adapter->hw, status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | rx_desc->errors, length, last_byte)) { |
| 4272 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4273 | e1000_tbi_adjust_stats(&adapter->hw, |
| 4274 | &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | length, skb->data); |
| 4276 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4277 | flags); |
| 4278 | length--; |
| 4279 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4280 | /* recycle */ |
| 4281 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | goto next_desc; |
| 4283 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4286 | /* adjust length to remove Ethernet CRC, this must be |
| 4287 | * done after the TBI_ACCEPT workaround above */ |
| 4288 | length -= 4; |
| 4289 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4290 | /* probably a little skewed due to removing CRC */ |
| 4291 | total_rx_bytes += length; |
| 4292 | total_rx_packets++; |
| 4293 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4294 | /* code added for copybreak, this should improve |
| 4295 | * performance for small packets with large amounts |
| 4296 | * of reassembly being done in the stack */ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4297 | if (length < copybreak) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4298 | struct sk_buff *new_skb = |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4299 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4300 | if (new_skb) { |
| 4301 | skb_reserve(new_skb, NET_IP_ALIGN); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 4302 | skb_copy_to_linear_data_offset(new_skb, |
| 4303 | -NET_IP_ALIGN, |
| 4304 | (skb->data - |
| 4305 | NET_IP_ALIGN), |
| 4306 | (length + |
| 4307 | NET_IP_ALIGN)); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4308 | /* save the skb in buffer_info as good */ |
| 4309 | buffer_info->skb = skb; |
| 4310 | skb = new_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4311 | } |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4312 | /* else just continue with the old one */ |
| 4313 | } |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4314 | /* end copybreak code */ |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4315 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | |
| 4317 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4318 | e1000_rx_checksum(adapter, |
| 4319 | (uint32_t)(status) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4320 | ((uint32_t)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4321 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | skb->protocol = eth_type_trans(skb, netdev); |
| 4324 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4325 | if (unlikely(adapter->vlgrp && |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4326 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4328 | le16_to_cpu(rx_desc->special) & |
| 4329 | E1000_RXD_SPC_VLAN_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | } else { |
| 4331 | netif_receive_skb(skb); |
| 4332 | } |
| 4333 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4334 | if (unlikely(adapter->vlgrp && |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4335 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 4337 | le16_to_cpu(rx_desc->special) & |
| 4338 | E1000_RXD_SPC_VLAN_MASK); |
| 4339 | } else { |
| 4340 | netif_rx(skb); |
| 4341 | } |
| 4342 | #endif /* CONFIG_E1000_NAPI */ |
| 4343 | netdev->last_rx = jiffies; |
| 4344 | |
| 4345 | next_desc: |
| 4346 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4348 | /* return some buffers to hardware, one at a time is too slow */ |
| 4349 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4350 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4351 | cleaned_count = 0; |
| 4352 | } |
| 4353 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4354 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4355 | rx_desc = next_rxd; |
| 4356 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4358 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4359 | |
| 4360 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4361 | if (cleaned_count) |
| 4362 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4364 | adapter->total_rx_packets += total_rx_packets; |
| 4365 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4366 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4367 | adapter->net_stats.rx_packets += total_rx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | return cleaned; |
| 4369 | } |
| 4370 | |
| 4371 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4372 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 4373 | * @adapter: board private structure |
| 4374 | **/ |
| 4375 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4376 | static bool |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4377 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4378 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4379 | struct e1000_rx_ring *rx_ring, |
| 4380 | int *work_done, int work_to_do) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4381 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4382 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4383 | struct e1000_rx_ring *rx_ring) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4384 | #endif |
| 4385 | { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4386 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4387 | struct net_device *netdev = adapter->netdev; |
| 4388 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4389 | struct e1000_buffer *buffer_info, *next_buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4390 | struct e1000_ps_page *ps_page; |
| 4391 | struct e1000_ps_page_dma *ps_page_dma; |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4392 | struct sk_buff *skb; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4393 | unsigned int i, j; |
| 4394 | uint32_t length, staterr; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4395 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4396 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4397 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4398 | |
| 4399 | i = rx_ring->next_to_clean; |
| 4400 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4401 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4402 | buffer_info = &rx_ring->buffer_info[i]; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4403 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4404 | while (staterr & E1000_RXD_STAT_DD) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4405 | ps_page = &rx_ring->ps_page[i]; |
| 4406 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4407 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4408 | if (unlikely(*work_done >= work_to_do)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4409 | break; |
| 4410 | (*work_done)++; |
| 4411 | #endif |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4412 | skb = buffer_info->skb; |
| 4413 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4414 | /* in the packet split case this is header only */ |
| 4415 | prefetch(skb->data - NET_IP_ALIGN); |
| 4416 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4417 | if (++i == rx_ring->count) i = 0; |
| 4418 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4419 | prefetch(next_rxd); |
| 4420 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4421 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4422 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4423 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4424 | cleaned_count++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4425 | pci_unmap_single(pdev, buffer_info->dma, |
| 4426 | buffer_info->length, |
| 4427 | PCI_DMA_FROMDEVICE); |
| 4428 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4429 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4430 | E1000_DBG("%s: Packet Split buffers didn't pick up" |
| 4431 | " the full packet\n", netdev->name); |
| 4432 | dev_kfree_skb_irq(skb); |
| 4433 | goto next_desc; |
| 4434 | } |
| 4435 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4436 | if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4437 | dev_kfree_skb_irq(skb); |
| 4438 | goto next_desc; |
| 4439 | } |
| 4440 | |
| 4441 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 4442 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4443 | if (unlikely(!length)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4444 | E1000_DBG("%s: Last part of the packet spanning" |
| 4445 | " multiple descriptors\n", netdev->name); |
| 4446 | dev_kfree_skb_irq(skb); |
| 4447 | goto next_desc; |
| 4448 | } |
| 4449 | |
| 4450 | /* Good Receive */ |
| 4451 | skb_put(skb, length); |
| 4452 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4453 | { |
| 4454 | /* this looks ugly, but it seems compiler issues make it |
| 4455 | more efficient than reusing j */ |
| 4456 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 4457 | |
| 4458 | /* page alloc/put takes too long and effects small packet |
| 4459 | * throughput, so unsplit small packets and save the alloc/put*/ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4460 | if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) { |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4461 | u8 *vaddr; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 4462 | /* there is no documentation about how to call |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4463 | * kmap_atomic, so we can't hold the mapping |
| 4464 | * very long */ |
| 4465 | pci_dma_sync_single_for_cpu(pdev, |
| 4466 | ps_page_dma->ps_page_dma[0], |
| 4467 | PAGE_SIZE, |
| 4468 | PCI_DMA_FROMDEVICE); |
| 4469 | vaddr = kmap_atomic(ps_page->ps_page[0], |
| 4470 | KM_SKB_DATA_SOFTIRQ); |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 4471 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4472 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 4473 | pci_dma_sync_single_for_device(pdev, |
| 4474 | ps_page_dma->ps_page_dma[0], |
| 4475 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4476 | /* remove the CRC */ |
| 4477 | l1 -= 4; |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4478 | skb_put(skb, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4479 | goto copydone; |
| 4480 | } /* if */ |
| 4481 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4482 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4483 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4484 | if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4485 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4486 | pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
| 4487 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 4488 | ps_page_dma->ps_page_dma[j] = 0; |
Jeff Kirsher | 329bfd0 | 2006-03-02 18:20:02 -0800 | [diff] [blame] | 4489 | skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
| 4490 | length); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4491 | ps_page->ps_page[j] = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4492 | skb->len += length; |
| 4493 | skb->data_len += length; |
Auke Kok | 5d51b80 | 2006-04-14 19:05:06 -0700 | [diff] [blame] | 4494 | skb->truesize += length; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4497 | /* strip the ethernet crc, problem is we're using pages now so |
| 4498 | * this whole operation can get a little cpu intensive */ |
| 4499 | pskb_trim(skb, skb->len - 4); |
| 4500 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4501 | copydone: |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4502 | total_rx_bytes += skb->len; |
| 4503 | total_rx_packets++; |
| 4504 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4505 | e1000_rx_checksum(adapter, staterr, |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4506 | 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] | 4507 | skb->protocol = eth_type_trans(skb, netdev); |
| 4508 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4509 | if (likely(rx_desc->wb.upper.header_status & |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4510 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4511 | adapter->rx_hdr_split++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4512 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4513 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4514 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4515 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4516 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4517 | } else { |
| 4518 | netif_receive_skb(skb); |
| 4519 | } |
| 4520 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4521 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4522 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4523 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4524 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4525 | } else { |
| 4526 | netif_rx(skb); |
| 4527 | } |
| 4528 | #endif /* CONFIG_E1000_NAPI */ |
| 4529 | netdev->last_rx = jiffies; |
| 4530 | |
| 4531 | next_desc: |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4532 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4533 | buffer_info->skb = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4534 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4535 | /* return some buffers to hardware, one at a time is too slow */ |
| 4536 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4537 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4538 | cleaned_count = 0; |
| 4539 | } |
| 4540 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4541 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4542 | rx_desc = next_rxd; |
| 4543 | buffer_info = next_buffer; |
| 4544 | |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4545 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4546 | } |
| 4547 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4548 | |
| 4549 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4550 | if (cleaned_count) |
| 4551 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4552 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4553 | adapter->total_rx_packets += total_rx_packets; |
| 4554 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4555 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4556 | adapter->net_stats.rx_packets += total_rx_packets; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4557 | return cleaned; |
| 4558 | } |
| 4559 | |
| 4560 | /** |
| 4561 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | * @adapter: address of board private structure |
| 4563 | **/ |
| 4564 | |
| 4565 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4566 | e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4567 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4568 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | struct net_device *netdev = adapter->netdev; |
| 4571 | struct pci_dev *pdev = adapter->pdev; |
| 4572 | struct e1000_rx_desc *rx_desc; |
| 4573 | struct e1000_buffer *buffer_info; |
| 4574 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4575 | unsigned int i; |
| 4576 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | |
| 4578 | i = rx_ring->next_to_use; |
| 4579 | buffer_info = &rx_ring->buffer_info[i]; |
| 4580 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4581 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4582 | skb = buffer_info->skb; |
| 4583 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4584 | skb_trim(skb, 0); |
| 4585 | goto map_skb; |
| 4586 | } |
| 4587 | |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4588 | skb = netdev_alloc_skb(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4589 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4591 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | break; |
| 4593 | } |
| 4594 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4595 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4597 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4598 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 4599 | "at %p\n", bufsz, skb->data); |
| 4600 | /* Try again, without freeing the previous */ |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4601 | skb = netdev_alloc_skb(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4602 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | if (!skb) { |
| 4604 | dev_kfree_skb(oldskb); |
| 4605 | break; |
| 4606 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4609 | /* give up */ |
| 4610 | dev_kfree_skb(skb); |
| 4611 | dev_kfree_skb(oldskb); |
| 4612 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4614 | |
| 4615 | /* Use new allocation */ |
| 4616 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4619 | * this will result in a 16 byte aligned IP header after |
| 4620 | * the 14 byte MAC header is removed |
| 4621 | */ |
| 4622 | skb_reserve(skb, NET_IP_ALIGN); |
| 4623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | buffer_info->skb = skb; |
| 4625 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4626 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | buffer_info->dma = pci_map_single(pdev, |
| 4628 | skb->data, |
| 4629 | adapter->rx_buffer_len, |
| 4630 | PCI_DMA_FROMDEVICE); |
| 4631 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4632 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4633 | if (!e1000_check_64k_bound(adapter, |
| 4634 | (void *)(unsigned long)buffer_info->dma, |
| 4635 | adapter->rx_buffer_len)) { |
| 4636 | DPRINTK(RX_ERR, ERR, |
| 4637 | "dma align check failed: %u bytes at %p\n", |
| 4638 | adapter->rx_buffer_len, |
| 4639 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | dev_kfree_skb(skb); |
| 4641 | buffer_info->skb = NULL; |
| 4642 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4643 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | adapter->rx_buffer_len, |
| 4645 | PCI_DMA_FROMDEVICE); |
| 4646 | |
| 4647 | break; /* while !buffer_info->skb */ |
| 4648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4650 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4651 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4652 | if (unlikely(++i == rx_ring->count)) |
| 4653 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | buffer_info = &rx_ring->buffer_info[i]; |
| 4655 | } |
| 4656 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4657 | if (likely(rx_ring->next_to_use != i)) { |
| 4658 | rx_ring->next_to_use = i; |
| 4659 | if (unlikely(i-- == 0)) |
| 4660 | i = (rx_ring->count - 1); |
| 4661 | |
| 4662 | /* Force memory writes to complete before letting h/w |
| 4663 | * know there are new descriptors to fetch. (Only |
| 4664 | * applicable for weak-ordered memory model archs, |
| 4665 | * such as IA-64). */ |
| 4666 | wmb(); |
| 4667 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4672 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 4673 | * @adapter: address of board private structure |
| 4674 | **/ |
| 4675 | |
| 4676 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4677 | e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4678 | struct e1000_rx_ring *rx_ring, |
| 4679 | int cleaned_count) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4680 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4681 | struct net_device *netdev = adapter->netdev; |
| 4682 | struct pci_dev *pdev = adapter->pdev; |
| 4683 | union e1000_rx_desc_packet_split *rx_desc; |
| 4684 | struct e1000_buffer *buffer_info; |
| 4685 | struct e1000_ps_page *ps_page; |
| 4686 | struct e1000_ps_page_dma *ps_page_dma; |
| 4687 | struct sk_buff *skb; |
| 4688 | unsigned int i, j; |
| 4689 | |
| 4690 | i = rx_ring->next_to_use; |
| 4691 | buffer_info = &rx_ring->buffer_info[i]; |
| 4692 | ps_page = &rx_ring->ps_page[i]; |
| 4693 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4694 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4695 | while (cleaned_count--) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4696 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 4697 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4698 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4699 | if (j < adapter->rx_ps_pages) { |
| 4700 | if (likely(!ps_page->ps_page[j])) { |
| 4701 | ps_page->ps_page[j] = |
| 4702 | alloc_page(GFP_ATOMIC); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4703 | if (unlikely(!ps_page->ps_page[j])) { |
| 4704 | adapter->alloc_rx_buff_failed++; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4705 | goto no_buffers; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4706 | } |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4707 | ps_page_dma->ps_page_dma[j] = |
| 4708 | pci_map_page(pdev, |
| 4709 | ps_page->ps_page[j], |
| 4710 | 0, PAGE_SIZE, |
| 4711 | PCI_DMA_FROMDEVICE); |
| 4712 | } |
| 4713 | /* Refresh the desc even if buffer_addrs didn't |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4714 | * change because each write-back erases |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4715 | * this info. |
| 4716 | */ |
| 4717 | rx_desc->read.buffer_addr[j+1] = |
| 4718 | cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
| 4719 | } else |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 4720 | rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4723 | skb = netdev_alloc_skb(netdev, |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4724 | adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4725 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4726 | if (unlikely(!skb)) { |
| 4727 | adapter->alloc_rx_buff_failed++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4728 | break; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4729 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4730 | |
| 4731 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4732 | * this will result in a 16 byte aligned IP header after |
| 4733 | * the 14 byte MAC header is removed |
| 4734 | */ |
| 4735 | skb_reserve(skb, NET_IP_ALIGN); |
| 4736 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4737 | buffer_info->skb = skb; |
| 4738 | buffer_info->length = adapter->rx_ps_bsize0; |
| 4739 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4740 | adapter->rx_ps_bsize0, |
| 4741 | PCI_DMA_FROMDEVICE); |
| 4742 | |
| 4743 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 4744 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4745 | if (unlikely(++i == rx_ring->count)) i = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4746 | buffer_info = &rx_ring->buffer_info[i]; |
| 4747 | ps_page = &rx_ring->ps_page[i]; |
| 4748 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4749 | } |
| 4750 | |
| 4751 | no_buffers: |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4752 | if (likely(rx_ring->next_to_use != i)) { |
| 4753 | rx_ring->next_to_use = i; |
| 4754 | if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
| 4755 | |
| 4756 | /* Force memory writes to complete before letting h/w |
| 4757 | * know there are new descriptors to fetch. (Only |
| 4758 | * applicable for weak-ordered memory model archs, |
| 4759 | * such as IA-64). */ |
| 4760 | wmb(); |
| 4761 | /* Hardware increments by 16 bytes, but packet split |
| 4762 | * descriptors are 32 bytes...so we increment tail |
| 4763 | * twice as much. |
| 4764 | */ |
| 4765 | writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
| 4766 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4771 | * @adapter: |
| 4772 | **/ |
| 4773 | |
| 4774 | static void |
| 4775 | e1000_smartspeed(struct e1000_adapter *adapter) |
| 4776 | { |
| 4777 | uint16_t phy_status; |
| 4778 | uint16_t phy_ctrl; |
| 4779 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4780 | if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
| 4782 | return; |
| 4783 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4784 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | /* If Master/Slave config fault is asserted twice, |
| 4786 | * we assume back-to-back */ |
| 4787 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4788 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4790 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4791 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4792 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
| 4794 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
| 4795 | phy_ctrl); |
| 4796 | adapter->smartspeed++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4797 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
| 4799 | &phy_ctrl)) { |
| 4800 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4801 | MII_CR_RESTART_AUTO_NEG); |
| 4802 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
| 4803 | phy_ctrl); |
| 4804 | } |
| 4805 | } |
| 4806 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4807 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | /* If still no link, perhaps using 2/3 pair cable */ |
| 4809 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
| 4810 | phy_ctrl |= CR_1000T_MS_ENABLE; |
| 4811 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4812 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
| 4814 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4815 | MII_CR_RESTART_AUTO_NEG); |
| 4816 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
| 4817 | } |
| 4818 | } |
| 4819 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4820 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | adapter->smartspeed = 0; |
| 4822 | } |
| 4823 | |
| 4824 | /** |
| 4825 | * e1000_ioctl - |
| 4826 | * @netdev: |
| 4827 | * @ifreq: |
| 4828 | * @cmd: |
| 4829 | **/ |
| 4830 | |
| 4831 | static int |
| 4832 | e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4833 | { |
| 4834 | switch (cmd) { |
| 4835 | case SIOCGMIIPHY: |
| 4836 | case SIOCGMIIREG: |
| 4837 | case SIOCSMIIREG: |
| 4838 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4839 | default: |
| 4840 | return -EOPNOTSUPP; |
| 4841 | } |
| 4842 | } |
| 4843 | |
| 4844 | /** |
| 4845 | * e1000_mii_ioctl - |
| 4846 | * @netdev: |
| 4847 | * @ifreq: |
| 4848 | * @cmd: |
| 4849 | **/ |
| 4850 | |
| 4851 | static int |
| 4852 | e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4853 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4854 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4856 | int retval; |
| 4857 | uint16_t mii_reg; |
| 4858 | uint16_t spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4859 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4861 | if (adapter->hw.media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | return -EOPNOTSUPP; |
| 4863 | |
| 4864 | switch (cmd) { |
| 4865 | case SIOCGMIIPHY: |
| 4866 | data->phy_id = adapter->hw.phy_addr; |
| 4867 | break; |
| 4868 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4869 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4870 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4871 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4872 | if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4873 | &data->val_out)) { |
| 4874 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4876 | } |
| 4877 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | break; |
| 4879 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4880 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4882 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | return -EFAULT; |
| 4884 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4885 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4886 | if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4887 | mii_reg)) { |
| 4888 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4890 | } |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4891 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Auke Kok | dc86d32 | 2006-04-18 12:30:51 -0700 | [diff] [blame] | 4892 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | switch (data->reg_num) { |
| 4894 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4895 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4897 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | adapter->hw.autoneg = 1; |
| 4899 | adapter->hw.autoneg_advertised = 0x2F; |
| 4900 | } else { |
| 4901 | if (mii_reg & 0x40) |
| 4902 | spddplx = SPEED_1000; |
| 4903 | else if (mii_reg & 0x2000) |
| 4904 | spddplx = SPEED_100; |
| 4905 | else |
| 4906 | spddplx = SPEED_10; |
| 4907 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4908 | ? DUPLEX_FULL : |
| 4909 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4910 | retval = e1000_set_spd_dplx(adapter, |
| 4911 | spddplx); |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4912 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | return retval; |
| 4914 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4915 | if (netif_running(adapter->netdev)) |
| 4916 | e1000_reinit_locked(adapter); |
| 4917 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | e1000_reset(adapter); |
| 4919 | break; |
| 4920 | case M88E1000_PHY_SPEC_CTRL: |
| 4921 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4922 | if (e1000_phy_reset(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | return -EIO; |
| 4924 | break; |
| 4925 | } |
| 4926 | } else { |
| 4927 | switch (data->reg_num) { |
| 4928 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4929 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4931 | if (netif_running(adapter->netdev)) |
| 4932 | e1000_reinit_locked(adapter); |
| 4933 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | e1000_reset(adapter); |
| 4935 | break; |
| 4936 | } |
| 4937 | } |
| 4938 | break; |
| 4939 | default: |
| 4940 | return -EOPNOTSUPP; |
| 4941 | } |
| 4942 | return E1000_SUCCESS; |
| 4943 | } |
| 4944 | |
| 4945 | void |
| 4946 | e1000_pci_set_mwi(struct e1000_hw *hw) |
| 4947 | { |
| 4948 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4949 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4950 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4951 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4952 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | void |
| 4956 | e1000_pci_clear_mwi(struct e1000_hw *hw) |
| 4957 | { |
| 4958 | struct e1000_adapter *adapter = hw->back; |
| 4959 | |
| 4960 | pci_clear_mwi(adapter->pdev); |
| 4961 | } |
| 4962 | |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4963 | int |
| 4964 | e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
| 4965 | { |
| 4966 | struct e1000_adapter *adapter = hw->back; |
| 4967 | return pcix_get_mmrbc(adapter->pdev); |
| 4968 | } |
| 4969 | |
| 4970 | void |
| 4971 | e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
| 4972 | { |
| 4973 | struct e1000_adapter *adapter = hw->back; |
| 4974 | pcix_set_mmrbc(adapter->pdev, mmrbc); |
| 4975 | } |
| 4976 | |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4977 | int32_t |
| 4978 | e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4979 | { |
| 4980 | struct e1000_adapter *adapter = hw->back; |
| 4981 | uint16_t cap_offset; |
| 4982 | |
| 4983 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 4984 | if (!cap_offset) |
| 4985 | return -E1000_ERR_CONFIG; |
| 4986 | |
| 4987 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 4988 | |
| 4989 | return E1000_SUCCESS; |
| 4990 | } |
| 4991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | void |
| 4993 | e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) |
| 4994 | { |
| 4995 | outl(value, port); |
| 4996 | } |
| 4997 | |
| 4998 | static void |
| 4999 | e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 5000 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5001 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | uint32_t ctrl, rctl; |
| 5003 | |
| 5004 | e1000_irq_disable(adapter); |
| 5005 | adapter->vlgrp = grp; |
| 5006 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5007 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | /* enable VLAN tag insert/strip */ |
| 5009 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 5010 | ctrl |= E1000_CTRL_VME; |
| 5011 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 5012 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5013 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 5014 | /* enable VLAN receive filtering */ |
| 5015 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 5016 | rctl |= E1000_RCTL_VFE; |
| 5017 | rctl &= ~E1000_RCTL_CFIEN; |
| 5018 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 5019 | e1000_update_mng_vlan(adapter); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | } else { |
| 5022 | /* disable VLAN tag insert/strip */ |
| 5023 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 5024 | ctrl &= ~E1000_CTRL_VME; |
| 5025 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 5026 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5027 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 5028 | /* disable VLAN filtering */ |
| 5029 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 5030 | rctl &= ~E1000_RCTL_VFE; |
| 5031 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 5032 | if (adapter->mng_vlan_id != |
| 5033 | (uint16_t)E1000_MNG_VLAN_NONE) { |
| 5034 | e1000_vlan_rx_kill_vid(netdev, |
| 5035 | adapter->mng_vlan_id); |
| 5036 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 5037 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | e1000_irq_enable(adapter); |
| 5042 | } |
| 5043 | |
| 5044 | static void |
| 5045 | e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
| 5046 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5047 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | uint32_t vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5049 | |
| 5050 | if ((adapter->hw.mng_cookie.status & |
| 5051 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 5052 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5053 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5054 | /* add VID to filter table */ |
| 5055 | index = (vid >> 5) & 0x7F; |
| 5056 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 5057 | vfta |= (1 << (vid & 0x1F)); |
| 5058 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 5059 | } |
| 5060 | |
| 5061 | static void |
| 5062 | e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
| 5063 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5064 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | uint32_t vfta, index; |
| 5066 | |
| 5067 | e1000_irq_disable(adapter); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 5068 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5069 | e1000_irq_enable(adapter); |
| 5070 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5071 | if ((adapter->hw.mng_cookie.status & |
| 5072 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 5073 | (vid == adapter->mng_vlan_id)) { |
| 5074 | /* release control to f/w */ |
| 5075 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5076 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 5077 | } |
| 5078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | /* remove VID from filter table */ |
| 5080 | index = (vid >> 5) & 0x7F; |
| 5081 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 5082 | vfta &= ~(1 << (vid & 0x1F)); |
| 5083 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 5084 | } |
| 5085 | |
| 5086 | static void |
| 5087 | e1000_restore_vlan(struct e1000_adapter *adapter) |
| 5088 | { |
| 5089 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 5090 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5091 | if (adapter->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | uint16_t vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5093 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 5094 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | continue; |
| 5096 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 5097 | } |
| 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | int |
| 5102 | e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) |
| 5103 | { |
| 5104 | adapter->hw.autoneg = 0; |
| 5105 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 5106 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5107 | if ((adapter->hw.media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 5108 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 5109 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 5110 | return -EINVAL; |
| 5111 | } |
| 5112 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5113 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5114 | case SPEED_10 + DUPLEX_HALF: |
| 5115 | adapter->hw.forced_speed_duplex = e1000_10_half; |
| 5116 | break; |
| 5117 | case SPEED_10 + DUPLEX_FULL: |
| 5118 | adapter->hw.forced_speed_duplex = e1000_10_full; |
| 5119 | break; |
| 5120 | case SPEED_100 + DUPLEX_HALF: |
| 5121 | adapter->hw.forced_speed_duplex = e1000_100_half; |
| 5122 | break; |
| 5123 | case SPEED_100 + DUPLEX_FULL: |
| 5124 | adapter->hw.forced_speed_duplex = e1000_100_full; |
| 5125 | break; |
| 5126 | case SPEED_1000 + DUPLEX_FULL: |
| 5127 | adapter->hw.autoneg = 1; |
| 5128 | adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
| 5129 | break; |
| 5130 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 5131 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5132 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | return -EINVAL; |
| 5134 | } |
| 5135 | return 0; |
| 5136 | } |
| 5137 | |
| 5138 | static int |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 5139 | e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5140 | { |
| 5141 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5142 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5143 | uint32_t ctrl, ctrl_ext, rctl, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | uint32_t wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5145 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5146 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5147 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5148 | |
| 5149 | netif_device_detach(netdev); |
| 5150 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5151 | if (netif_running(netdev)) { |
| 5152 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5154 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5156 | #ifdef CONFIG_PM |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5157 | retval = pci_save_state(pdev); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5158 | if (retval) |
| 5159 | return retval; |
| 5160 | #endif |
| 5161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | status = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5163 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | wufc &= ~E1000_WUFC_LNKC; |
| 5165 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5166 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | e1000_setup_rctl(adapter); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 5168 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | |
| 5170 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 5171 | if (wufc & E1000_WUFC_MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 5173 | rctl |= E1000_RCTL_MPE; |
| 5174 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 5175 | } |
| 5176 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5177 | if (adapter->hw.mac_type >= e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 5179 | /* advertise wake from D3Cold */ |
| 5180 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5181 | /* phy power management enable */ |
| 5182 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5183 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 5184 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 5185 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 5186 | } |
| 5187 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5188 | if (adapter->hw.media_type == e1000_media_type_fiber || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5189 | adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 5190 | /* keep the laser running in D3 */ |
| 5191 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 5192 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 5193 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
| 5194 | } |
| 5195 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5196 | /* Allow time for pending master requests to run */ |
| 5197 | e1000_disable_pciex_master(&adapter->hw); |
| 5198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
| 5200 | E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5201 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5202 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | } else { |
| 5204 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
| 5205 | E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5206 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5207 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5210 | e1000_release_manageability(adapter); |
| 5211 | |
| 5212 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 5213 | if (adapter->en_mng_pt) { |
| 5214 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5215 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | } |
| 5217 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5218 | if (adapter->hw.phy_type == e1000_phy_igp_3) |
| 5219 | e1000_phy_powerdown_workaround(&adapter->hw); |
| 5220 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5221 | if (netif_running(netdev)) |
| 5222 | e1000_free_irq(adapter); |
| 5223 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5224 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5225 | * would have already happened in close and is redundant. */ |
| 5226 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5229 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5230 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | |
| 5232 | return 0; |
| 5233 | } |
| 5234 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5235 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | static int |
| 5237 | e1000_resume(struct pci_dev *pdev) |
| 5238 | { |
| 5239 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5240 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5241 | uint32_t err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5243 | pci_set_power_state(pdev, PCI_D0); |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5244 | pci_restore_state(pdev); |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 5245 | if ((err = pci_enable_device(pdev))) { |
| 5246 | printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
| 5247 | return err; |
| 5248 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 5249 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5250 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5251 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5252 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5253 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5254 | if (netif_running(netdev) && (err = e1000_request_irq(adapter))) |
| 5255 | return err; |
| 5256 | |
| 5257 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | e1000_reset(adapter); |
| 5259 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5260 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5261 | e1000_init_manageability(adapter); |
| 5262 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5263 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5264 | e1000_up(adapter); |
| 5265 | |
| 5266 | netif_device_attach(netdev); |
| 5267 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5268 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5269 | * DRV_LOAD until the interface is up. For all other cases, |
| 5270 | * let the f/w know that the h/w is now under the control |
| 5271 | * of the driver. */ |
| 5272 | if (adapter->hw.mac_type != e1000_82573 || |
| 5273 | !e1000_check_mng_mode(&adapter->hw)) |
| 5274 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5276 | return 0; |
| 5277 | } |
| 5278 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5279 | |
| 5280 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5281 | { |
| 5282 | e1000_suspend(pdev, PMSG_SUSPEND); |
| 5283 | } |
| 5284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5285 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5286 | /* |
| 5287 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5288 | * without having to re-enable interrupts. It's not called while |
| 5289 | * the interrupt routine is executing. |
| 5290 | */ |
| 5291 | static void |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5292 | e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5294 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 5295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5296 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5297 | e1000_intr(adapter->pdev->irq, netdev); |
Andrew Morton | c4cfe56 | 2005-10-15 00:32:29 -0700 | [diff] [blame] | 5298 | e1000_clean_tx_irq(adapter, adapter->tx_ring); |
Jeff Kirsher | e8da8be | 2006-01-12 16:51:14 -0800 | [diff] [blame] | 5299 | #ifndef CONFIG_E1000_NAPI |
| 5300 | adapter->clean_rx(adapter, adapter->rx_ring); |
| 5301 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | enable_irq(adapter->pdev->irq); |
| 5303 | } |
| 5304 | #endif |
| 5305 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5306 | /** |
| 5307 | * e1000_io_error_detected - called when PCI error is detected |
| 5308 | * @pdev: Pointer to PCI device |
| 5309 | * @state: The current pci conneection state |
| 5310 | * |
| 5311 | * This function is called after a PCI bus error affecting |
| 5312 | * this device has been detected. |
| 5313 | */ |
| 5314 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 5315 | { |
| 5316 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5317 | struct e1000_adapter *adapter = netdev->priv; |
| 5318 | |
| 5319 | netif_device_detach(netdev); |
| 5320 | |
| 5321 | if (netif_running(netdev)) |
| 5322 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 5323 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5324 | |
| 5325 | /* Request a slot slot reset. */ |
| 5326 | return PCI_ERS_RESULT_NEED_RESET; |
| 5327 | } |
| 5328 | |
| 5329 | /** |
| 5330 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5331 | * @pdev: Pointer to PCI device |
| 5332 | * |
| 5333 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5334 | * resembles the first-half of the e1000_resume routine. |
| 5335 | */ |
| 5336 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5337 | { |
| 5338 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5339 | struct e1000_adapter *adapter = netdev->priv; |
| 5340 | |
| 5341 | if (pci_enable_device(pdev)) { |
| 5342 | printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
| 5343 | return PCI_ERS_RESULT_DISCONNECT; |
| 5344 | } |
| 5345 | pci_set_master(pdev); |
| 5346 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 5347 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5348 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5349 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5350 | e1000_reset(adapter); |
| 5351 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5352 | |
| 5353 | return PCI_ERS_RESULT_RECOVERED; |
| 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * e1000_io_resume - called when traffic can start flowing again. |
| 5358 | * @pdev: Pointer to PCI device |
| 5359 | * |
| 5360 | * This callback is called when the error recovery driver tells us that |
| 5361 | * its OK to resume normal operation. Implementation resembles the |
| 5362 | * second-half of the e1000_resume routine. |
| 5363 | */ |
| 5364 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5365 | { |
| 5366 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5367 | struct e1000_adapter *adapter = netdev->priv; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5368 | |
| 5369 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5370 | |
| 5371 | if (netif_running(netdev)) { |
| 5372 | if (e1000_up(adapter)) { |
| 5373 | printk("e1000: can't bring device back up after reset\n"); |
| 5374 | return; |
| 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | netif_device_attach(netdev); |
| 5379 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5380 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5381 | * DRV_LOAD until the interface is up. For all other cases, |
| 5382 | * let the f/w know that the h/w is now under the control |
| 5383 | * of the driver. */ |
| 5384 | if (adapter->hw.mac_type != e1000_82573 || |
| 5385 | !e1000_check_mng_mode(&adapter->hw)) |
| 5386 | e1000_get_hw_control(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5387 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5388 | } |
| 5389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | /* e1000_main.c */ |