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 | */ |
| 50 | static struct pci_device_id e1000_pci_tbl[] = { |
| 51 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 52 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 53 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 54 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 55 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 56 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 57 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 58 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 59 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 60 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 61 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 62 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 63 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 64 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 65 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 66 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 67 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 68 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 69 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 70 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 72 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 73 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 74 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 75 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
| 76 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 77 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 78 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 79 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 80 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 81 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 82 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 83 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
| 84 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 85 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 86 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* required last entry */ |
| 88 | {0,} |
| 89 | }; |
| 90 | |
| 91 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 92 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 93 | int e1000_up(struct e1000_adapter *adapter); |
| 94 | void e1000_down(struct e1000_adapter *adapter); |
| 95 | void e1000_reinit_locked(struct e1000_adapter *adapter); |
| 96 | void e1000_reset(struct e1000_adapter *adapter); |
| 97 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx); |
| 98 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
| 99 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
| 100 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
| 101 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 102 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 103 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 104 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 105 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 106 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 107 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 108 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 109 | struct e1000_rx_ring *rx_ring); |
| 110 | void e1000_update_stats(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | static int e1000_init_module(void); |
| 113 | static void e1000_exit_module(void); |
| 114 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 115 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 116 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 118 | static int e1000_open(struct net_device *netdev); |
| 119 | static int e1000_close(struct net_device *netdev); |
| 120 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 121 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 122 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 123 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 124 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 125 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 126 | struct e1000_tx_ring *tx_ring); |
| 127 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 128 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | static void e1000_set_multi(struct net_device *netdev); |
| 130 | static void e1000_update_phy_info(unsigned long data); |
| 131 | static void e1000_watchdog(unsigned long data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
| 133 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 134 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 135 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 136 | static int e1000_set_mac(struct net_device *netdev, void *p); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 137 | static irqreturn_t e1000_intr(int irq, void *data); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 138 | static irqreturn_t e1000_intr_msi(int irq, void *data); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 139 | static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 140 | struct e1000_tx_ring *tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 142 | static int e1000_clean(struct napi_struct *napi, int budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 144 | struct e1000_rx_ring *rx_ring, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | int *work_done, int work_to_do); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 146 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 147 | struct e1000_rx_ring *rx_ring, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 148 | int *work_done, int work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 150 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 151 | struct e1000_rx_ring *rx_ring); |
| 152 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 153 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #endif |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 155 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 156 | struct e1000_rx_ring *rx_ring, |
| 157 | int cleaned_count); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 158 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 159 | struct e1000_rx_ring *rx_ring, |
| 160 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 162 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 163 | int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 165 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 166 | static void e1000_tx_timeout(struct net_device *dev); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 167 | static void e1000_reset_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 169 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 170 | struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
| 173 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); |
| 174 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
| 175 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 176 | |
Ashutosh Naik | 977e74b | 2005-10-28 15:14:53 -0700 | [diff] [blame] | 177 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 178 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | static int e1000_resume(struct pci_dev *pdev); |
| 180 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 181 | static void e1000_shutdown(struct pci_dev *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 184 | /* for netdump / net console */ |
| 185 | static void e1000_netpoll (struct net_device *netdev); |
| 186 | #endif |
| 187 | |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 188 | #define COPYBREAK_DEFAULT 256 |
| 189 | static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT; |
| 190 | module_param(copybreak, uint, 0644); |
| 191 | MODULE_PARM_DESC(copybreak, |
| 192 | "Maximum size of packet that is copied to a new buffer on receive"); |
| 193 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 194 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 195 | pci_channel_state_t state); |
| 196 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); |
| 197 | static void e1000_io_resume(struct pci_dev *pdev); |
| 198 | |
| 199 | static struct pci_error_handlers e1000_err_handler = { |
| 200 | .error_detected = e1000_io_error_detected, |
| 201 | .slot_reset = e1000_io_slot_reset, |
| 202 | .resume = e1000_io_resume, |
| 203 | }; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | static struct pci_driver e1000_driver = { |
| 206 | .name = e1000_driver_name, |
| 207 | .id_table = e1000_pci_tbl, |
| 208 | .probe = e1000_probe, |
| 209 | .remove = __devexit_p(e1000_remove), |
Auke Kok | c4e24f0 | 2006-09-27 12:53:19 -0700 | [diff] [blame] | 210 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* Power Managment Hooks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | .suspend = e1000_suspend, |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 213 | .resume = e1000_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | #endif |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 215 | .shutdown = e1000_shutdown, |
| 216 | .err_handler = &e1000_err_handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 220 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 221 | MODULE_LICENSE("GPL"); |
| 222 | MODULE_VERSION(DRV_VERSION); |
| 223 | |
| 224 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 225 | module_param(debug, int, 0); |
| 226 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 227 | |
| 228 | /** |
| 229 | * e1000_init_module - Driver Registration Routine |
| 230 | * |
| 231 | * e1000_init_module is the first routine called when the driver is |
| 232 | * loaded. All it does is register with the PCI subsystem. |
| 233 | **/ |
| 234 | |
| 235 | static int __init |
| 236 | e1000_init_module(void) |
| 237 | { |
| 238 | int ret; |
| 239 | printk(KERN_INFO "%s - version %s\n", |
| 240 | e1000_driver_string, e1000_driver_version); |
| 241 | |
| 242 | printk(KERN_INFO "%s\n", e1000_copyright); |
| 243 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 244 | ret = pci_register_driver(&e1000_driver); |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 245 | if (copybreak != COPYBREAK_DEFAULT) { |
| 246 | if (copybreak == 0) |
| 247 | printk(KERN_INFO "e1000: copybreak disabled\n"); |
| 248 | else |
| 249 | printk(KERN_INFO "e1000: copybreak enabled for " |
| 250 | "packets <= %u bytes\n", copybreak); |
| 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return ret; |
| 253 | } |
| 254 | |
| 255 | module_init(e1000_init_module); |
| 256 | |
| 257 | /** |
| 258 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 259 | * |
| 260 | * e1000_exit_module is called just before the driver is removed |
| 261 | * from memory. |
| 262 | **/ |
| 263 | |
| 264 | static void __exit |
| 265 | e1000_exit_module(void) |
| 266 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | pci_unregister_driver(&e1000_driver); |
| 268 | } |
| 269 | |
| 270 | module_exit(e1000_exit_module); |
| 271 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 272 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 273 | { |
| 274 | struct net_device *netdev = adapter->netdev; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 275 | void (*handler) = &e1000_intr; |
| 276 | int irq_flags = IRQF_SHARED; |
| 277 | int err; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 278 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 279 | if (adapter->hw.mac_type >= e1000_82571) { |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 280 | adapter->have_msi = !pci_enable_msi(adapter->pdev); |
| 281 | if (adapter->have_msi) { |
| 282 | handler = &e1000_intr_msi; |
| 283 | irq_flags = 0; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 286 | |
| 287 | err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, |
| 288 | netdev); |
| 289 | if (err) { |
| 290 | if (adapter->have_msi) |
| 291 | pci_disable_msi(adapter->pdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 292 | DPRINTK(PROBE, ERR, |
| 293 | "Unable to allocate interrupt Error: %d\n", err); |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 294 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 295 | |
| 296 | return err; |
| 297 | } |
| 298 | |
| 299 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 300 | { |
| 301 | struct net_device *netdev = adapter->netdev; |
| 302 | |
| 303 | free_irq(adapter->pdev->irq, netdev); |
| 304 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 305 | if (adapter->have_msi) |
| 306 | pci_disable_msi(adapter->pdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /** |
| 310 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 311 | * @adapter: board private structure |
| 312 | **/ |
| 313 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 314 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | e1000_irq_disable(struct e1000_adapter *adapter) |
| 316 | { |
| 317 | atomic_inc(&adapter->irq_sem); |
| 318 | E1000_WRITE_REG(&adapter->hw, IMC, ~0); |
| 319 | E1000_WRITE_FLUSH(&adapter->hw); |
| 320 | synchronize_irq(adapter->pdev->irq); |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * e1000_irq_enable - Enable default interrupt generation settings |
| 325 | * @adapter: board private structure |
| 326 | **/ |
| 327 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 328 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | e1000_irq_enable(struct e1000_adapter *adapter) |
| 330 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 331 | if (likely(atomic_dec_and_test(&adapter->irq_sem))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); |
| 333 | E1000_WRITE_FLUSH(&adapter->hw); |
| 334 | } |
| 335 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 336 | |
| 337 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 338 | e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 339 | { |
| 340 | struct net_device *netdev = adapter->netdev; |
| 341 | uint16_t vid = adapter->hw.mng_cookie.vlan_id; |
| 342 | uint16_t old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 343 | if (adapter->vlgrp) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 344 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 345 | if (adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 346 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 347 | e1000_vlan_rx_add_vid(netdev, vid); |
| 348 | adapter->mng_vlan_id = vid; |
| 349 | } else |
| 350 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 351 | |
| 352 | if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && |
| 353 | (vid != old_vid) && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 354 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 355 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 356 | } else |
| 357 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 358 | } |
| 359 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 360 | |
| 361 | /** |
| 362 | * e1000_release_hw_control - release control of the h/w to f/w |
| 363 | * @adapter: address of board private structure |
| 364 | * |
| 365 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 366 | * For ASF and Pass Through versions of f/w this means that the |
| 367 | * driver is no longer loaded. For AMT version (only with 82573) i |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 368 | * 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] | 369 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 370 | **/ |
| 371 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 372 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 373 | e1000_release_hw_control(struct e1000_adapter *adapter) |
| 374 | { |
| 375 | uint32_t ctrl_ext; |
| 376 | uint32_t swsm; |
| 377 | |
| 378 | /* Let firmware taken over control of h/w */ |
| 379 | switch (adapter->hw.mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 380 | case e1000_82573: |
| 381 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 382 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 383 | swsm & ~E1000_SWSM_DRV_LOAD); |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 384 | break; |
| 385 | case e1000_82571: |
| 386 | case e1000_82572: |
| 387 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 388 | case e1000_ich8lan: |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 389 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 390 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 391 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 392 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 393 | default: |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * e1000_get_hw_control - get control of the h/w from f/w |
| 400 | * @adapter: address of board private structure |
| 401 | * |
| 402 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 403 | * For ASF and Pass Through versions of f/w this means that |
| 404 | * the driver is loaded. For AMT version (only with 82573) |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 405 | * 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] | 406 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 407 | **/ |
| 408 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 409 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 410 | e1000_get_hw_control(struct e1000_adapter *adapter) |
| 411 | { |
| 412 | uint32_t ctrl_ext; |
| 413 | uint32_t swsm; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 414 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 415 | /* Let firmware know the driver has taken over */ |
| 416 | switch (adapter->hw.mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 417 | case e1000_82573: |
| 418 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 419 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 420 | swsm | E1000_SWSM_DRV_LOAD); |
| 421 | break; |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 422 | case e1000_82571: |
| 423 | case e1000_82572: |
| 424 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 425 | case e1000_ich8lan: |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 426 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 427 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 428 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 429 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 430 | default: |
| 431 | break; |
| 432 | } |
| 433 | } |
| 434 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 435 | static void |
| 436 | e1000_init_manageability(struct e1000_adapter *adapter) |
| 437 | { |
| 438 | if (adapter->en_mng_pt) { |
| 439 | uint32_t manc = E1000_READ_REG(&adapter->hw, MANC); |
| 440 | |
| 441 | /* disable hardware interception of ARP */ |
| 442 | manc &= ~(E1000_MANC_ARP_EN); |
| 443 | |
| 444 | /* enable receiving management packets to the host */ |
| 445 | /* this will probably generate destination unreachable messages |
| 446 | * from the host OS, but the packets will be handled on SMBUS */ |
| 447 | if (adapter->hw.has_manc2h) { |
| 448 | uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H); |
| 449 | |
| 450 | manc |= E1000_MANC_EN_MNG2HOST; |
| 451 | #define E1000_MNG2HOST_PORT_623 (1 << 5) |
| 452 | #define E1000_MNG2HOST_PORT_664 (1 << 6) |
| 453 | manc2h |= E1000_MNG2HOST_PORT_623; |
| 454 | manc2h |= E1000_MNG2HOST_PORT_664; |
| 455 | E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h); |
| 456 | } |
| 457 | |
| 458 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | static void |
| 463 | e1000_release_manageability(struct e1000_adapter *adapter) |
| 464 | { |
| 465 | if (adapter->en_mng_pt) { |
| 466 | uint32_t manc = E1000_READ_REG(&adapter->hw, MANC); |
| 467 | |
| 468 | /* re-enable hardware interception of ARP */ |
| 469 | manc |= E1000_MANC_ARP_EN; |
| 470 | |
| 471 | if (adapter->hw.has_manc2h) |
| 472 | manc &= ~E1000_MANC_EN_MNG2HOST; |
| 473 | |
| 474 | /* don't explicitly have to mess with MANC2H since |
| 475 | * MANC has an enable disable that gates MANC2H */ |
| 476 | |
| 477 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 478 | } |
| 479 | } |
| 480 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 481 | /** |
| 482 | * e1000_configure - configure the hardware for RX and TX |
| 483 | * @adapter = private board structure |
| 484 | **/ |
| 485 | static void e1000_configure(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
| 487 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 488 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | e1000_set_multi(netdev); |
| 491 | |
| 492 | e1000_restore_vlan(adapter); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 493 | e1000_init_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | e1000_configure_tx(adapter); |
| 496 | e1000_setup_rctl(adapter); |
| 497 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 498 | /* call E1000_DESC_UNUSED which always leaves |
| 499 | * at least 1 descriptor unused to make sure |
| 500 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 501 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 502 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 503 | adapter->alloc_rx_buf(adapter, ring, |
| 504 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 507 | adapter->tx_queue_len = netdev->tx_queue_len; |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 508 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 509 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 510 | int e1000_up(struct e1000_adapter *adapter) |
| 511 | { |
| 512 | /* hardware has been reset, we need to reload some things */ |
| 513 | e1000_configure(adapter); |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 514 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 515 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 516 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 517 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 518 | napi_enable(&adapter->napi); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 519 | #endif |
| 520 | e1000_irq_enable(adapter); |
| 521 | |
Jesse Brandeburg | 79f3d39 | 2006-12-15 10:42:34 +0100 | [diff] [blame] | 522 | /* fire a link change interrupt to start the watchdog */ |
| 523 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | return 0; |
| 525 | } |
| 526 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 527 | /** |
| 528 | * e1000_power_up_phy - restore link in case the phy was powered down |
| 529 | * @adapter: address of board private structure |
| 530 | * |
| 531 | * The phy may be powered down to save power and turn off link when the |
| 532 | * driver is unloaded and wake on lan is not enabled (among others) |
| 533 | * *** this routine MUST be followed by a call to e1000_reset *** |
| 534 | * |
| 535 | **/ |
| 536 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 537 | void e1000_power_up_phy(struct e1000_adapter *adapter) |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 538 | { |
| 539 | uint16_t mii_reg = 0; |
| 540 | |
| 541 | /* Just clear the power down bit to wake the phy back up */ |
| 542 | if (adapter->hw.media_type == e1000_media_type_copper) { |
| 543 | /* according to the manual, the phy will retain its |
| 544 | * settings across a power-down/up cycle */ |
| 545 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 546 | mii_reg &= ~MII_CR_POWER_DOWN; |
| 547 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 552 | { |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 553 | /* Power down the PHY so no link is implied when interface is down * |
| 554 | * 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] | 555 | * (a) WoL is enabled |
| 556 | * (b) AMT is active |
| 557 | * (c) SoL/IDER session is active */ |
| 558 | if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 559 | adapter->hw.media_type == e1000_media_type_copper) { |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 560 | uint16_t mii_reg = 0; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 561 | |
| 562 | switch (adapter->hw.mac_type) { |
| 563 | case e1000_82540: |
| 564 | case e1000_82545: |
| 565 | case e1000_82545_rev_3: |
| 566 | case e1000_82546: |
| 567 | case e1000_82546_rev_3: |
| 568 | case e1000_82541: |
| 569 | case e1000_82541_rev_2: |
| 570 | case e1000_82547: |
| 571 | case e1000_82547_rev_2: |
| 572 | if (E1000_READ_REG(&adapter->hw, MANC) & |
| 573 | E1000_MANC_SMBUS_EN) |
| 574 | goto out; |
| 575 | break; |
| 576 | case e1000_82571: |
| 577 | case e1000_82572: |
| 578 | case e1000_82573: |
| 579 | case e1000_80003es2lan: |
| 580 | case e1000_ich8lan: |
| 581 | if (e1000_check_mng_mode(&adapter->hw) || |
| 582 | e1000_check_phy_reset_block(&adapter->hw)) |
| 583 | goto out; |
| 584 | break; |
| 585 | default: |
| 586 | goto out; |
| 587 | } |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 588 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 589 | mii_reg |= MII_CR_POWER_DOWN; |
| 590 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 591 | mdelay(1); |
| 592 | } |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 593 | out: |
| 594 | return; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | void |
| 598 | e1000_down(struct e1000_adapter *adapter) |
| 599 | { |
| 600 | struct net_device *netdev = adapter->netdev; |
| 601 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 602 | /* signal that we're down so the interrupt handler does not |
| 603 | * reschedule our watchdog timer */ |
| 604 | set_bit(__E1000_DOWN, &adapter->flags); |
| 605 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 606 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 607 | napi_disable(&adapter->napi); |
David S. Miller | 49d85c5 | 2008-01-18 04:21:39 -0800 | [diff] [blame] | 608 | atomic_set(&adapter->irq_sem, 0); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 609 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 613 | del_timer_sync(&adapter->watchdog_timer); |
| 614 | del_timer_sync(&adapter->phy_info_timer); |
| 615 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 616 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | adapter->link_speed = 0; |
| 618 | adapter->link_duplex = 0; |
| 619 | netif_carrier_off(netdev); |
| 620 | netif_stop_queue(netdev); |
| 621 | |
| 622 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 623 | e1000_clean_all_tx_rings(adapter); |
| 624 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | void |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 628 | e1000_reinit_locked(struct e1000_adapter *adapter) |
| 629 | { |
| 630 | WARN_ON(in_interrupt()); |
| 631 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 632 | msleep(1); |
| 633 | e1000_down(adapter); |
| 634 | e1000_up(adapter); |
| 635 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | void |
| 639 | e1000_reset(struct e1000_adapter *adapter) |
| 640 | { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 641 | uint32_t pba = 0, tx_space, min_tx_space, min_rx_space; |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 642 | uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 643 | boolean_t legacy_pba_adjust = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | /* Repartition Pba for greater than 9k mtu |
| 646 | * To take effect CTRL.RST is required. |
| 647 | */ |
| 648 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 649 | switch (adapter->hw.mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 650 | case e1000_82542_rev2_0: |
| 651 | case e1000_82542_rev2_1: |
| 652 | case e1000_82543: |
| 653 | case e1000_82544: |
| 654 | case e1000_82540: |
| 655 | case e1000_82541: |
| 656 | case e1000_82541_rev_2: |
| 657 | legacy_pba_adjust = TRUE; |
| 658 | pba = E1000_PBA_48K; |
| 659 | break; |
| 660 | case e1000_82545: |
| 661 | case e1000_82545_rev_3: |
| 662 | case e1000_82546: |
| 663 | case e1000_82546_rev_3: |
| 664 | pba = E1000_PBA_48K; |
| 665 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 666 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 667 | case e1000_82547_rev_2: |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 668 | legacy_pba_adjust = TRUE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 669 | pba = E1000_PBA_30K; |
| 670 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 671 | case e1000_82571: |
| 672 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 673 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 674 | pba = E1000_PBA_38K; |
| 675 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 676 | case e1000_82573: |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 677 | pba = E1000_PBA_20K; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 678 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 679 | case e1000_ich8lan: |
| 680 | pba = E1000_PBA_8K; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 681 | case e1000_undefined: |
| 682 | case e1000_num_macs: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 683 | break; |
| 684 | } |
| 685 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 686 | if (legacy_pba_adjust == TRUE) { |
| 687 | if (adapter->netdev->mtu > E1000_RXBUFFER_8192) |
| 688 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 689 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 690 | if (adapter->hw.mac_type == e1000_82547) { |
| 691 | adapter->tx_fifo_head = 0; |
| 692 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 693 | adapter->tx_fifo_size = |
| 694 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 695 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 696 | } |
| 697 | } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 698 | /* adjust PBA for jumbo frames */ |
| 699 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 700 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 701 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 702 | * large enough to accomodate two full transmit packets, |
| 703 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 704 | * the Rx FIFO should be large enough to accomodate at least |
| 705 | * one full receive packet and is similarly rounded up and |
| 706 | * expressed in KB. */ |
| 707 | pba = E1000_READ_REG(&adapter->hw, PBA); |
| 708 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 709 | tx_space = pba >> 16; |
| 710 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 711 | pba &= 0xffff; |
| 712 | /* don't include ethernet FCS because hardware appends/strips */ |
| 713 | min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE + |
| 714 | VLAN_TAG_SIZE; |
| 715 | min_tx_space = min_rx_space; |
| 716 | min_tx_space *= 2; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 717 | min_tx_space = ALIGN(min_tx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 718 | min_tx_space >>= 10; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 719 | min_rx_space = ALIGN(min_rx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 720 | min_rx_space >>= 10; |
| 721 | |
| 722 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 723 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 724 | * allocation, take space away from current Rx allocation */ |
| 725 | if (tx_space < min_tx_space && |
| 726 | ((min_tx_space - tx_space) < pba)) { |
| 727 | pba = pba - (min_tx_space - tx_space); |
| 728 | |
| 729 | /* PCI/PCIx hardware has PBA alignment constraints */ |
| 730 | switch (adapter->hw.mac_type) { |
| 731 | case e1000_82545 ... e1000_82546_rev_3: |
| 732 | pba &= ~(E1000_PBA_8K - 1); |
| 733 | break; |
| 734 | default: |
| 735 | break; |
| 736 | } |
| 737 | |
| 738 | /* if short on rx space, rx wins and must trump tx |
| 739 | * adjustment or use Early Receive if available */ |
| 740 | if (pba < min_rx_space) { |
| 741 | switch (adapter->hw.mac_type) { |
| 742 | case e1000_82573: |
| 743 | /* ERT enabled in e1000_configure_rx */ |
| 744 | break; |
| 745 | default: |
| 746 | pba = min_rx_space; |
| 747 | break; |
| 748 | } |
| 749 | } |
| 750 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
| 754 | |
| 755 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 756 | /* Set the FC high water mark to 90% of the FIFO size. |
| 757 | * Required to clear last 3 LSB */ |
| 758 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 759 | /* We can't use 90% on small FIFOs because the remainder |
| 760 | * would be less than 1 full frame. In this case, we size |
| 761 | * it to allow at least a full frame above the high water |
| 762 | * mark. */ |
| 763 | if (pba < E1000_PBA_16K) |
| 764 | fc_high_water_mark = (pba * 1024) - 1600; |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 765 | |
| 766 | adapter->hw.fc_high_water = fc_high_water_mark; |
| 767 | adapter->hw.fc_low_water = fc_high_water_mark - 8; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 768 | if (adapter->hw.mac_type == e1000_80003es2lan) |
| 769 | adapter->hw.fc_pause_time = 0xFFFF; |
| 770 | else |
| 771 | adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | adapter->hw.fc_send_xon = 1; |
| 773 | adapter->hw.fc = adapter->hw.original_fc; |
| 774 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 775 | /* Allow time for pending master requests to run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | e1000_reset_hw(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 777 | if (adapter->hw.mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 779 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 780 | if (e1000_init_hw(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 782 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 783 | |
| 784 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
| 785 | if (adapter->hw.mac_type >= e1000_82544 && |
| 786 | adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 787 | adapter->hw.autoneg == 1 && |
| 788 | adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) { |
| 789 | uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 790 | /* clear phy power management bit if we are in gig only mode, |
| 791 | * which if enabled will attempt negotiation to 100Mb, which |
| 792 | * can cause a loss of link at power off or driver unload */ |
| 793 | ctrl &= ~E1000_CTRL_SWDPIN3; |
| 794 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 795 | } |
| 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 798 | E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); |
| 799 | |
| 800 | e1000_reset_adaptive(&adapter->hw); |
| 801 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 802 | |
| 803 | if (!adapter->smart_power_down && |
| 804 | (adapter->hw.mac_type == e1000_82571 || |
| 805 | adapter->hw.mac_type == e1000_82572)) { |
| 806 | uint16_t phy_data = 0; |
| 807 | /* speed up time to link by disabling smart power down, ignore |
| 808 | * the return value of this function because there is nothing |
| 809 | * different we would do if it failed */ |
| 810 | e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 811 | &phy_data); |
| 812 | phy_data &= ~IGP02E1000_PM_SPD; |
| 813 | e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 814 | phy_data); |
| 815 | } |
| 816 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 817 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
| 821 | * e1000_probe - Device Initialization Routine |
| 822 | * @pdev: PCI device information struct |
| 823 | * @ent: entry in e1000_pci_tbl |
| 824 | * |
| 825 | * Returns 0 on success, negative on failure |
| 826 | * |
| 827 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 828 | * The OS initialization, configuring of the adapter private structure, |
| 829 | * and a hardware reset occur. |
| 830 | **/ |
| 831 | |
| 832 | static int __devinit |
| 833 | e1000_probe(struct pci_dev *pdev, |
| 834 | const struct pci_device_id *ent) |
| 835 | { |
| 836 | struct net_device *netdev; |
| 837 | struct e1000_adapter *adapter; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 838 | unsigned long mmio_start, mmio_len; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 839 | unsigned long flash_start, flash_len; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 842 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 843 | int i, err, pci_using_dac; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 844 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | uint16_t eeprom_apme_mask = E1000_EEPROM_APME; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 846 | DECLARE_MAC_BUF(mac); |
| 847 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 848 | if ((err = pci_enable_device(pdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | return err; |
| 850 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 851 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) && |
| 852 | !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | pci_using_dac = 1; |
| 854 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 855 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) && |
| 856 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | E1000_ERR("No usable DMA configuration, aborting\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 858 | goto err_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | pci_using_dac = 0; |
| 861 | } |
| 862 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 863 | if ((err = pci_request_regions(pdev, e1000_driver_name))) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 864 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | pci_set_master(pdev); |
| 867 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 868 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 870 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 874 | |
| 875 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 876 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | adapter->netdev = netdev; |
| 878 | adapter->pdev = pdev; |
| 879 | adapter->hw.back = adapter; |
| 880 | adapter->msg_enable = (1 << debug) - 1; |
| 881 | |
| 882 | mmio_start = pci_resource_start(pdev, BAR_0); |
| 883 | mmio_len = pci_resource_len(pdev, BAR_0); |
| 884 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 885 | err = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 887 | if (!adapter->hw.hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 890 | for (i = BAR_1; i <= BAR_5; i++) { |
| 891 | if (pci_resource_len(pdev, i) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | continue; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 893 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 895 | break; |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | netdev->open = &e1000_open; |
| 900 | netdev->stop = &e1000_close; |
| 901 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 902 | netdev->get_stats = &e1000_get_stats; |
| 903 | netdev->set_multicast_list = &e1000_set_multi; |
| 904 | netdev->set_mac_address = &e1000_set_mac; |
| 905 | netdev->change_mtu = &e1000_change_mtu; |
| 906 | netdev->do_ioctl = &e1000_ioctl; |
| 907 | e1000_set_ethtool_ops(netdev); |
| 908 | netdev->tx_timeout = &e1000_tx_timeout; |
| 909 | netdev->watchdog_timeo = 5 * HZ; |
| 910 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 911 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | #endif |
| 913 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 914 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 915 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 916 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 917 | netdev->poll_controller = e1000_netpoll; |
| 918 | #endif |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 919 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | netdev->mem_start = mmio_start; |
| 922 | netdev->mem_end = mmio_start + mmio_len; |
| 923 | netdev->base_addr = adapter->hw.io_base; |
| 924 | |
| 925 | adapter->bd_number = cards_found; |
| 926 | |
| 927 | /* setup the private structure */ |
| 928 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 929 | if ((err = e1000_sw_init(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | goto err_sw_init; |
| 931 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 932 | err = -EIO; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 933 | /* Flash BAR mapping must happen after e1000_sw_init |
| 934 | * because it depends on mac_type */ |
| 935 | if ((adapter->hw.mac_type == e1000_ich8lan) && |
| 936 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
| 937 | flash_start = pci_resource_start(pdev, 1); |
| 938 | flash_len = pci_resource_len(pdev, 1); |
| 939 | adapter->hw.flash_address = ioremap(flash_start, flash_len); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 940 | if (!adapter->hw.flash_address) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 941 | goto err_flashmap; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 944 | if (e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 945 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 946 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 947 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | netdev->features = NETIF_F_SG | |
| 949 | NETIF_F_HW_CSUM | |
| 950 | NETIF_F_HW_VLAN_TX | |
| 951 | NETIF_F_HW_VLAN_RX | |
| 952 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 953 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 954 | netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | } |
| 956 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 957 | if ((adapter->hw.mac_type >= e1000_82544) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | (adapter->hw.mac_type != e1000_82547)) |
| 959 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 960 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 961 | if (adapter->hw.mac_type > e1000_82547_rev_2) |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 962 | netdev->features |= NETIF_F_TSO6; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 963 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | netdev->features |= NETIF_F_HIGHDMA; |
| 965 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 966 | netdev->features |= NETIF_F_LLTX; |
| 967 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 968 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); |
| 969 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 970 | /* initialize eeprom parameters */ |
| 971 | |
| 972 | if (e1000_init_eeprom_params(&adapter->hw)) { |
| 973 | E1000_ERR("EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 974 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 977 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | e1000_reset_hw(&adapter->hw); |
| 981 | |
| 982 | /* make sure the EEPROM is good */ |
| 983 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 984 | if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | goto err_eeprom; |
| 987 | } |
| 988 | |
| 989 | /* copy the MAC address out of the EEPROM */ |
| 990 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 991 | if (e1000_read_mac_addr(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
| 993 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
John W. Linville | 9beb0ac | 2005-09-12 10:48:55 -0400 | [diff] [blame] | 994 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 996 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | goto err_eeprom; |
| 999 | } |
| 1000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | e1000_get_bus_info(&adapter->hw); |
| 1002 | |
| 1003 | init_timer(&adapter->tx_fifo_stall_timer); |
| 1004 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
| 1005 | adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; |
| 1006 | |
| 1007 | init_timer(&adapter->watchdog_timer); |
| 1008 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 1009 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 1010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | init_timer(&adapter->phy_info_timer); |
| 1012 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 1013 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 1014 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1015 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | e1000_check_options(adapter); |
| 1018 | |
| 1019 | /* Initial Wake on LAN setting |
| 1020 | * If APM wake is enabled in the EEPROM, |
| 1021 | * enable the ACPI Magic Packet filter |
| 1022 | */ |
| 1023 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1024 | switch (adapter->hw.mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | case e1000_82542_rev2_0: |
| 1026 | case e1000_82542_rev2_1: |
| 1027 | case e1000_82543: |
| 1028 | break; |
| 1029 | case e1000_82544: |
| 1030 | e1000_read_eeprom(&adapter->hw, |
| 1031 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1032 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 1033 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1034 | case e1000_ich8lan: |
| 1035 | e1000_read_eeprom(&adapter->hw, |
| 1036 | EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
| 1037 | eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
| 1038 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | case e1000_82546: |
| 1040 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1041 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1042 | case e1000_80003es2lan: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1043 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | e1000_read_eeprom(&adapter->hw, |
| 1045 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1046 | break; |
| 1047 | } |
| 1048 | /* Fall Through */ |
| 1049 | default: |
| 1050 | e1000_read_eeprom(&adapter->hw, |
| 1051 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1052 | break; |
| 1053 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1054 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1055 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1056 | |
| 1057 | /* now that we have the eeprom settings, apply the special cases |
| 1058 | * where the eeprom may be wrong or the board simply won't support |
| 1059 | * wake on lan on a particular port */ |
| 1060 | switch (pdev->device) { |
| 1061 | case E1000_DEV_ID_82546GB_PCIE: |
| 1062 | adapter->eeprom_wol = 0; |
| 1063 | break; |
| 1064 | case E1000_DEV_ID_82546EB_FIBER: |
| 1065 | case E1000_DEV_ID_82546GB_FIBER: |
| 1066 | case E1000_DEV_ID_82571EB_FIBER: |
| 1067 | /* Wake events only supported on port A for dual fiber |
| 1068 | * regardless of eeprom setting */ |
| 1069 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1) |
| 1070 | adapter->eeprom_wol = 0; |
| 1071 | break; |
| 1072 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1073 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 1074 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 1075 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
Auke Kok | f4ec7f9 | 2007-08-30 11:23:58 -0700 | [diff] [blame] | 1076 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1077 | /* if quad port adapter, disable WoL on all but port A */ |
| 1078 | if (global_quad_port_a != 0) |
| 1079 | adapter->eeprom_wol = 0; |
| 1080 | else |
| 1081 | adapter->quad_port_a = 1; |
| 1082 | /* Reset for multiple quad port adapters */ |
| 1083 | if (++global_quad_port_a == 4) |
| 1084 | global_quad_port_a = 0; |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | /* initialize the wol settings based on the eeprom settings */ |
| 1089 | adapter->wol = adapter->eeprom_wol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1091 | /* print bus type/speed/width info */ |
| 1092 | { |
| 1093 | struct e1000_hw *hw = &adapter->hw; |
| 1094 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 1095 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 1096 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 1097 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 1098 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 1099 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 1100 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 1101 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 1102 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 1103 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 1104 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 1105 | "32-bit")); |
| 1106 | } |
| 1107 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1108 | printk("%s\n", print_mac(mac, netdev->dev_addr)); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | /* reset the hardware with the new settings */ |
| 1111 | e1000_reset(adapter); |
| 1112 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1113 | /* If the controller is 82573 and f/w is AMT, do not set |
| 1114 | * DRV_LOAD until the interface is up. For all other cases, |
| 1115 | * let the f/w know that the h/w is now under the control |
| 1116 | * of the driver. */ |
| 1117 | if (adapter->hw.mac_type != e1000_82573 || |
| 1118 | !e1000_check_mng_mode(&adapter->hw)) |
| 1119 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1120 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1121 | /* tell the stack to leave us alone until e1000_open() is called */ |
| 1122 | netif_carrier_off(netdev); |
| 1123 | netif_stop_queue(netdev); |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1124 | |
| 1125 | strcpy(netdev->name, "eth%d"); |
| 1126 | if ((err = register_netdev(netdev))) |
| 1127 | goto err_register; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 1130 | |
| 1131 | cards_found++; |
| 1132 | return 0; |
| 1133 | |
| 1134 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1135 | e1000_release_hw_control(adapter); |
| 1136 | err_eeprom: |
| 1137 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
| 1138 | e1000_phy_hw_reset(&adapter->hw); |
| 1139 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1140 | if (adapter->hw.flash_address) |
| 1141 | iounmap(adapter->hw.flash_address); |
| 1142 | err_flashmap: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1143 | #ifdef CONFIG_E1000_NAPI |
| 1144 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1145 | dev_put(&adapter->polling_netdev[i]); |
| 1146 | #endif |
| 1147 | |
| 1148 | kfree(adapter->tx_ring); |
| 1149 | kfree(adapter->rx_ring); |
| 1150 | #ifdef CONFIG_E1000_NAPI |
| 1151 | kfree(adapter->polling_netdev); |
| 1152 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | err_sw_init: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | iounmap(adapter->hw.hw_addr); |
| 1155 | err_ioremap: |
| 1156 | free_netdev(netdev); |
| 1157 | err_alloc_etherdev: |
| 1158 | pci_release_regions(pdev); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1159 | err_pci_reg: |
| 1160 | err_dma: |
| 1161 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | return err; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * e1000_remove - Device Removal Routine |
| 1167 | * @pdev: PCI device information struct |
| 1168 | * |
| 1169 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1170 | * that it should release a PCI device. The could be caused by a |
| 1171 | * Hot-Plug event, or because the driver is going to be removed from |
| 1172 | * memory. |
| 1173 | **/ |
| 1174 | |
| 1175 | static void __devexit |
| 1176 | e1000_remove(struct pci_dev *pdev) |
| 1177 | { |
| 1178 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1179 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1180 | #ifdef CONFIG_E1000_NAPI |
| 1181 | int i; |
| 1182 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 1184 | cancel_work_sync(&adapter->reset_task); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1185 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1186 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1188 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1189 | * would have already happened in close and is redundant. */ |
| 1190 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1191 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1192 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1193 | for (i = 0; i < adapter->num_rx_queues; i++) |
Stephen Hemminger | 1533306 | 2006-03-20 22:32:28 -0800 | [diff] [blame] | 1194 | dev_put(&adapter->polling_netdev[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1195 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1197 | unregister_netdev(netdev); |
| 1198 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1199 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1200 | e1000_phy_hw_reset(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1202 | kfree(adapter->tx_ring); |
| 1203 | kfree(adapter->rx_ring); |
| 1204 | #ifdef CONFIG_E1000_NAPI |
| 1205 | kfree(adapter->polling_netdev); |
| 1206 | #endif |
| 1207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | iounmap(adapter->hw.hw_addr); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1209 | if (adapter->hw.flash_address) |
| 1210 | iounmap(adapter->hw.flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | pci_release_regions(pdev); |
| 1212 | |
| 1213 | free_netdev(netdev); |
| 1214 | |
| 1215 | pci_disable_device(pdev); |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1220 | * @adapter: board private structure to initialize |
| 1221 | * |
| 1222 | * e1000_sw_init initializes the Adapter private data structure. |
| 1223 | * Fields are initialized based on PCI device information and |
| 1224 | * OS network device settings (MTU size). |
| 1225 | **/ |
| 1226 | |
| 1227 | static int __devinit |
| 1228 | e1000_sw_init(struct e1000_adapter *adapter) |
| 1229 | { |
| 1230 | struct e1000_hw *hw = &adapter->hw; |
| 1231 | struct net_device *netdev = adapter->netdev; |
| 1232 | struct pci_dev *pdev = adapter->pdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1233 | #ifdef CONFIG_E1000_NAPI |
| 1234 | int i; |
| 1235 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
| 1237 | /* PCI config space info */ |
| 1238 | |
| 1239 | hw->vendor_id = pdev->vendor; |
| 1240 | hw->device_id = pdev->device; |
| 1241 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1242 | hw->subsystem_id = pdev->subsystem_device; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1243 | hw->revision_id = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
| 1245 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 1246 | |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1247 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1248 | adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | hw->max_frame_size = netdev->mtu + |
| 1250 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1251 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 1252 | |
| 1253 | /* identify the MAC */ |
| 1254 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1255 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 1257 | return -EIO; |
| 1258 | } |
| 1259 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1260 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | default: |
| 1262 | break; |
| 1263 | case e1000_82541: |
| 1264 | case e1000_82547: |
| 1265 | case e1000_82541_rev_2: |
| 1266 | case e1000_82547_rev_2: |
| 1267 | hw->phy_init_script = 1; |
| 1268 | break; |
| 1269 | } |
| 1270 | |
| 1271 | e1000_set_media_type(hw); |
| 1272 | |
| 1273 | hw->wait_autoneg_complete = FALSE; |
| 1274 | hw->tbi_compatibility_en = TRUE; |
| 1275 | hw->adaptive_ifs = TRUE; |
| 1276 | |
| 1277 | /* Copper options */ |
| 1278 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1279 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | hw->mdix = AUTO_ALL_MODES; |
| 1281 | hw->disable_polarity_correction = FALSE; |
| 1282 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1283 | } |
| 1284 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1285 | adapter->num_tx_queues = 1; |
| 1286 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1287 | |
| 1288 | if (e1000_alloc_queues(adapter)) { |
| 1289 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1290 | return -ENOMEM; |
| 1291 | } |
| 1292 | |
| 1293 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1294 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1295 | adapter->polling_netdev[i].priv = adapter; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1296 | dev_hold(&adapter->polling_netdev[i]); |
| 1297 | set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
| 1298 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1299 | spin_lock_init(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1300 | #endif |
| 1301 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1302 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
| 1303 | atomic_set(&adapter->irq_sem, 0); |
| 1304 | e1000_irq_disable(adapter); |
| 1305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1308 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | return 0; |
| 1311 | } |
| 1312 | |
| 1313 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1314 | * e1000_alloc_queues - Allocate memory for all rings |
| 1315 | * @adapter: board private structure to initialize |
| 1316 | * |
| 1317 | * We allocate one ring per queue at run-time since we don't know the |
| 1318 | * number of queues at compile-time. The polling_netdev array is |
| 1319 | * intended for Multiqueue, but should work fine with a single queue. |
| 1320 | **/ |
| 1321 | |
| 1322 | static int __devinit |
| 1323 | e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1324 | { |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1325 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1326 | sizeof(struct e1000_tx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1327 | if (!adapter->tx_ring) |
| 1328 | return -ENOMEM; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1329 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1330 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1331 | sizeof(struct e1000_rx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1332 | if (!adapter->rx_ring) { |
| 1333 | kfree(adapter->tx_ring); |
| 1334 | return -ENOMEM; |
| 1335 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1336 | |
| 1337 | #ifdef CONFIG_E1000_NAPI |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1338 | adapter->polling_netdev = kcalloc(adapter->num_rx_queues, |
| 1339 | sizeof(struct net_device), |
| 1340 | GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1341 | if (!adapter->polling_netdev) { |
| 1342 | kfree(adapter->tx_ring); |
| 1343 | kfree(adapter->rx_ring); |
| 1344 | return -ENOMEM; |
| 1345 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1346 | #endif |
| 1347 | |
| 1348 | return E1000_SUCCESS; |
| 1349 | } |
| 1350 | |
| 1351 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | * e1000_open - Called when a network interface is made active |
| 1353 | * @netdev: network interface device structure |
| 1354 | * |
| 1355 | * Returns 0 on success, negative value on failure |
| 1356 | * |
| 1357 | * The open entry point is called when a network interface is made |
| 1358 | * active by the system (IFF_UP). At this point all resources needed |
| 1359 | * for transmit and receive operations are allocated, the interrupt |
| 1360 | * handler is registered with the OS, the watchdog timer is started, |
| 1361 | * and the stack is notified that the interface is ready. |
| 1362 | **/ |
| 1363 | |
| 1364 | static int |
| 1365 | e1000_open(struct net_device *netdev) |
| 1366 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1367 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | int err; |
| 1369 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1370 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1371 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1372 | return -EBUSY; |
| 1373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | /* allocate transmit descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1375 | err = e1000_setup_all_tx_resources(adapter); |
| 1376 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | goto err_setup_tx; |
| 1378 | |
| 1379 | /* allocate receive descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1380 | err = e1000_setup_all_rx_resources(adapter); |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1381 | if (err) |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1382 | goto err_setup_rx; |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1383 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1384 | e1000_power_up_phy(adapter); |
| 1385 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1386 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1387 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1388 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1389 | e1000_update_mng_vlan(adapter); |
| 1390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1392 | /* If AMT is enabled, let the firmware know that the network |
| 1393 | * interface is now open */ |
| 1394 | if (adapter->hw.mac_type == e1000_82573 && |
| 1395 | e1000_check_mng_mode(&adapter->hw)) |
| 1396 | e1000_get_hw_control(adapter); |
| 1397 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1398 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1399 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1400 | * as soon as we call pci_request_irq, so we have to setup our |
| 1401 | * clean_rx handler before we do so. */ |
| 1402 | e1000_configure(adapter); |
| 1403 | |
| 1404 | err = e1000_request_irq(adapter); |
| 1405 | if (err) |
| 1406 | goto err_req_irq; |
| 1407 | |
| 1408 | /* From here on the code is the same as e1000_up() */ |
| 1409 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 1410 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1411 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1412 | napi_enable(&adapter->napi); |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1413 | #endif |
| 1414 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1415 | e1000_irq_enable(adapter); |
| 1416 | |
| 1417 | /* fire a link status change interrupt to start the watchdog */ |
| 1418 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC); |
| 1419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | return E1000_SUCCESS; |
| 1421 | |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1422 | err_req_irq: |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1423 | e1000_release_hw_control(adapter); |
| 1424 | e1000_power_down_phy(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1425 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1427 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | err_setup_tx: |
| 1429 | e1000_reset(adapter); |
| 1430 | |
| 1431 | return err; |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * e1000_close - Disables a network interface |
| 1436 | * @netdev: network interface device structure |
| 1437 | * |
| 1438 | * Returns 0, this is not allowed to fail |
| 1439 | * |
| 1440 | * The close entry point is called when an interface is de-activated |
| 1441 | * by the OS. The hardware is still under the drivers control, but |
| 1442 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1443 | * hardware, and all transmit and receive resources are freed. |
| 1444 | **/ |
| 1445 | |
| 1446 | static int |
| 1447 | e1000_close(struct net_device *netdev) |
| 1448 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1449 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1451 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1453 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1454 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1456 | e1000_free_all_tx_resources(adapter); |
| 1457 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1459 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1460 | * 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] | 1461 | if ((adapter->hw.mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1462 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1463 | !(adapter->vlgrp && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1464 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1465 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1466 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1467 | |
| 1468 | /* If AMT is enabled, let the firmware know that the network |
| 1469 | * interface is now closed */ |
| 1470 | if (adapter->hw.mac_type == e1000_82573 && |
| 1471 | e1000_check_mng_mode(&adapter->hw)) |
| 1472 | e1000_release_hw_control(adapter); |
| 1473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | /** |
| 1478 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1479 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1480 | * @start: address of beginning of memory |
| 1481 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | **/ |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 1483 | static boolean_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | e1000_check_64k_bound(struct e1000_adapter *adapter, |
| 1485 | void *start, unsigned long len) |
| 1486 | { |
| 1487 | unsigned long begin = (unsigned long) start; |
| 1488 | unsigned long end = begin + len; |
| 1489 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1490 | /* First rev 82545 and 82546 need to not allow any memory |
| 1491 | * write location to cross 64k boundary due to errata 23 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | if (adapter->hw.mac_type == e1000_82545 || |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1493 | adapter->hw.mac_type == e1000_82546) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE; |
| 1495 | } |
| 1496 | |
| 1497 | return TRUE; |
| 1498 | } |
| 1499 | |
| 1500 | /** |
| 1501 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1502 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1503 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | * |
| 1505 | * Return 0 on success, negative on failure |
| 1506 | **/ |
| 1507 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1508 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1509 | e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1510 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | struct pci_dev *pdev = adapter->pdev; |
| 1513 | int size; |
| 1514 | |
| 1515 | size = sizeof(struct e1000_buffer) * txdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1516 | txdr->buffer_info = vmalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1517 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1518 | DPRINTK(PROBE, ERR, |
| 1519 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | return -ENOMEM; |
| 1521 | } |
| 1522 | memset(txdr->buffer_info, 0, size); |
| 1523 | |
| 1524 | /* round up to nearest 4K */ |
| 1525 | |
| 1526 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1527 | txdr->size = ALIGN(txdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
| 1529 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1530 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1533 | DPRINTK(PROBE, ERR, |
| 1534 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | return -ENOMEM; |
| 1536 | } |
| 1537 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1538 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1540 | void *olddesc = txdr->desc; |
| 1541 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1542 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1543 | "at %p\n", txdr->size, txdr->desc); |
| 1544 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1546 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1547 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1549 | goto setup_tx_desc_die; |
| 1550 | } |
| 1551 | |
| 1552 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1553 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1554 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1555 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1557 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1558 | "Unable to allocate aligned memory " |
| 1559 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | vfree(txdr->buffer_info); |
| 1561 | return -ENOMEM; |
| 1562 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1563 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1565 | } |
| 1566 | } |
| 1567 | memset(txdr->desc, 0, txdr->size); |
| 1568 | |
| 1569 | txdr->next_to_use = 0; |
| 1570 | txdr->next_to_clean = 0; |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1571 | spin_lock_init(&txdr->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1577 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1578 | * (Descriptors) for all queues |
| 1579 | * @adapter: board private structure |
| 1580 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1581 | * Return 0 on success, negative on failure |
| 1582 | **/ |
| 1583 | |
| 1584 | int |
| 1585 | e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
| 1586 | { |
| 1587 | int i, err = 0; |
| 1588 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1589 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1590 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1591 | if (err) { |
| 1592 | DPRINTK(PROBE, ERR, |
| 1593 | "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1594 | for (i-- ; i >= 0; i--) |
| 1595 | e1000_free_tx_resources(adapter, |
| 1596 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1597 | break; |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | return err; |
| 1602 | } |
| 1603 | |
| 1604 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1606 | * @adapter: board private structure |
| 1607 | * |
| 1608 | * Configure the Tx unit of the MAC after a reset. |
| 1609 | **/ |
| 1610 | |
| 1611 | static void |
| 1612 | e1000_configure_tx(struct e1000_adapter *adapter) |
| 1613 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1614 | uint64_t tdba; |
| 1615 | struct e1000_hw *hw = &adapter->hw; |
| 1616 | uint32_t tdlen, tctl, tipg, tarc; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1617 | uint32_t ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
| 1619 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1620 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1621 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1622 | case 1: |
| 1623 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1624 | tdba = adapter->tx_ring[0].dma; |
| 1625 | tdlen = adapter->tx_ring[0].count * |
| 1626 | sizeof(struct e1000_tx_desc); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1627 | E1000_WRITE_REG(hw, TDLEN, tdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1628 | E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 1629 | E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1630 | E1000_WRITE_REG(hw, TDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1631 | E1000_WRITE_REG(hw, TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1632 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1633 | 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] | 1634 | break; |
| 1635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | |
| 1637 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Jesse Brandeburg | d89b6c6 | 2006-12-15 10:38:32 +0100 | [diff] [blame] | 1638 | if (adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 1639 | (hw->media_type == e1000_media_type_fiber || |
| 1640 | hw->media_type == e1000_media_type_internal_serdes)) |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1641 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1642 | else |
| 1643 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1644 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1645 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | case e1000_82542_rev2_0: |
| 1647 | case e1000_82542_rev2_1: |
| 1648 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1649 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1650 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1652 | case e1000_80003es2lan: |
| 1653 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1654 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1655 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1657 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1658 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1659 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1661 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1662 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1663 | E1000_WRITE_REG(hw, TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | |
| 1665 | /* Set the Tx Interrupt Delay register */ |
| 1666 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1667 | E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 1668 | if (hw->mac_type >= e1000_82540) |
| 1669 | E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | |
| 1671 | /* Program the Transmit Control Register */ |
| 1672 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1673 | tctl = E1000_READ_REG(hw, TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1675 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1677 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1678 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 1679 | tarc = E1000_READ_REG(hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1680 | /* set the speed mode bit, we'll clear it if we're not at |
| 1681 | * gigabit link later */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1682 | tarc |= (1 << 21); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1683 | E1000_WRITE_REG(hw, TARC0, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1684 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 1685 | tarc = E1000_READ_REG(hw, TARC0); |
| 1686 | tarc |= 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1687 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1688 | tarc = E1000_READ_REG(hw, TARC1); |
| 1689 | tarc |= 1; |
| 1690 | E1000_WRITE_REG(hw, TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1691 | } |
| 1692 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1693 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | |
| 1695 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1696 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1697 | |
| 1698 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1699 | if (adapter->tx_int_delay) |
| 1700 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1702 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1704 | else |
| 1705 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1706 | |
| 1707 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1708 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1709 | if (hw->mac_type == e1000_82544 && |
| 1710 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1712 | |
| 1713 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 1714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /** |
| 1718 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1719 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1720 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | * |
| 1722 | * Returns 0 on success, negative on failure |
| 1723 | **/ |
| 1724 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1725 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1726 | e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1727 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1730 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
| 1732 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1733 | rxdr->buffer_info = vmalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1734 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1735 | DPRINTK(PROBE, ERR, |
| 1736 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | return -ENOMEM; |
| 1738 | } |
| 1739 | memset(rxdr->buffer_info, 0, size); |
| 1740 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1741 | rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page), |
| 1742 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1743 | if (!rxdr->ps_page) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1744 | vfree(rxdr->buffer_info); |
| 1745 | DPRINTK(PROBE, ERR, |
| 1746 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1747 | return -ENOMEM; |
| 1748 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1749 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1750 | rxdr->ps_page_dma = kcalloc(rxdr->count, |
| 1751 | sizeof(struct e1000_ps_page_dma), |
| 1752 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1753 | if (!rxdr->ps_page_dma) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1754 | vfree(rxdr->buffer_info); |
| 1755 | kfree(rxdr->ps_page); |
| 1756 | DPRINTK(PROBE, ERR, |
| 1757 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1758 | return -ENOMEM; |
| 1759 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1760 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1761 | if (adapter->hw.mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1762 | desc_len = sizeof(struct e1000_rx_desc); |
| 1763 | else |
| 1764 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | /* Round up to nearest 4K */ |
| 1767 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1768 | rxdr->size = rxdr->count * desc_len; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1769 | rxdr->size = ALIGN(rxdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
| 1771 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1772 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1773 | if (!rxdr->desc) { |
| 1774 | DPRINTK(PROBE, ERR, |
| 1775 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | vfree(rxdr->buffer_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1778 | kfree(rxdr->ps_page); |
| 1779 | kfree(rxdr->ps_page_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | return -ENOMEM; |
| 1781 | } |
| 1782 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1783 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1785 | void *olddesc = rxdr->desc; |
| 1786 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1787 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1788 | "at %p\n", rxdr->size, rxdr->desc); |
| 1789 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1791 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1792 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1794 | DPRINTK(PROBE, ERR, |
| 1795 | "Unable to allocate memory " |
| 1796 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | goto setup_rx_desc_die; |
| 1798 | } |
| 1799 | |
| 1800 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1801 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1802 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1803 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1805 | DPRINTK(PROBE, ERR, |
| 1806 | "Unable to allocate aligned memory " |
| 1807 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1808 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1810 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1812 | } |
| 1813 | } |
| 1814 | memset(rxdr->desc, 0, rxdr->size); |
| 1815 | |
| 1816 | rxdr->next_to_clean = 0; |
| 1817 | rxdr->next_to_use = 0; |
| 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1823 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1824 | * (Descriptors) for all queues |
| 1825 | * @adapter: board private structure |
| 1826 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1827 | * Return 0 on success, negative on failure |
| 1828 | **/ |
| 1829 | |
| 1830 | int |
| 1831 | e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
| 1832 | { |
| 1833 | int i, err = 0; |
| 1834 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1835 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1836 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1837 | if (err) { |
| 1838 | DPRINTK(PROBE, ERR, |
| 1839 | "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1840 | for (i-- ; i >= 0; i--) |
| 1841 | e1000_free_rx_resources(adapter, |
| 1842 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1843 | break; |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | return err; |
| 1848 | } |
| 1849 | |
| 1850 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1851 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | * @adapter: Board private structure |
| 1853 | **/ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1854 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 1855 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | static void |
| 1857 | e1000_setup_rctl(struct e1000_adapter *adapter) |
| 1858 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1859 | uint32_t rctl, rfctl; |
| 1860 | uint32_t psrctl = 0; |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1861 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1862 | uint32_t pages = 0; |
| 1863 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
| 1865 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1866 | |
| 1867 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1868 | |
| 1869 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1870 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1871 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1872 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1873 | if (adapter->hw.tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | rctl |= E1000_RCTL_SBP; |
| 1875 | else |
| 1876 | rctl &= ~E1000_RCTL_SBP; |
| 1877 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1878 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1879 | rctl &= ~E1000_RCTL_LPE; |
| 1880 | else |
| 1881 | rctl |= E1000_RCTL_LPE; |
| 1882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1884 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1885 | rctl |= E1000_RCTL_BSEX; |
| 1886 | switch (adapter->rx_buffer_len) { |
| 1887 | case E1000_RXBUFFER_256: |
| 1888 | rctl |= E1000_RCTL_SZ_256; |
| 1889 | rctl &= ~E1000_RCTL_BSEX; |
| 1890 | break; |
| 1891 | case E1000_RXBUFFER_512: |
| 1892 | rctl |= E1000_RCTL_SZ_512; |
| 1893 | rctl &= ~E1000_RCTL_BSEX; |
| 1894 | break; |
| 1895 | case E1000_RXBUFFER_1024: |
| 1896 | rctl |= E1000_RCTL_SZ_1024; |
| 1897 | rctl &= ~E1000_RCTL_BSEX; |
| 1898 | break; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1899 | case E1000_RXBUFFER_2048: |
| 1900 | default: |
| 1901 | rctl |= E1000_RCTL_SZ_2048; |
| 1902 | rctl &= ~E1000_RCTL_BSEX; |
| 1903 | break; |
| 1904 | case E1000_RXBUFFER_4096: |
| 1905 | rctl |= E1000_RCTL_SZ_4096; |
| 1906 | break; |
| 1907 | case E1000_RXBUFFER_8192: |
| 1908 | rctl |= E1000_RCTL_SZ_8192; |
| 1909 | break; |
| 1910 | case E1000_RXBUFFER_16384: |
| 1911 | rctl |= E1000_RCTL_SZ_16384; |
| 1912 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1915 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1916 | /* 82571 and greater support packet-split where the protocol |
| 1917 | * header is placed in skb->data and the packet data is |
| 1918 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 1919 | * In the case of a non-split, skb->data is linearly filled, |
| 1920 | * followed by the page buffers. Therefore, skb->data is |
| 1921 | * sized to hold the largest protocol header. |
| 1922 | */ |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 1923 | /* allocations using alloc_page take too long for regular MTU |
| 1924 | * so only enable packet split for jumbo frames */ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1925 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 1926 | if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) && |
| 1927 | PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE)) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1928 | adapter->rx_ps_pages = pages; |
| 1929 | else |
| 1930 | adapter->rx_ps_pages = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1931 | #endif |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1932 | if (adapter->rx_ps_pages) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1933 | /* Configure extra packet-split registers */ |
| 1934 | rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
| 1935 | rfctl |= E1000_RFCTL_EXTEN; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1936 | /* disable packet split support for IPv6 extension headers, |
| 1937 | * because some malformed IPv6 headers can hang the RX */ |
| 1938 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 1939 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 1940 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1941 | E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
| 1942 | |
Auke Kok | 7dfee0c | 2006-06-27 09:07:50 -0700 | [diff] [blame] | 1943 | rctl |= E1000_RCTL_DTYP_PS; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1944 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1945 | psrctl |= adapter->rx_ps_bsize0 >> |
| 1946 | E1000_PSRCTL_BSIZE0_SHIFT; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1947 | |
| 1948 | switch (adapter->rx_ps_pages) { |
| 1949 | case 3: |
| 1950 | psrctl |= PAGE_SIZE << |
| 1951 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 1952 | case 2: |
| 1953 | psrctl |= PAGE_SIZE << |
| 1954 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 1955 | case 1: |
| 1956 | psrctl |= PAGE_SIZE >> |
| 1957 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 1958 | break; |
| 1959 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1960 | |
| 1961 | E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1969 | * @adapter: board private structure |
| 1970 | * |
| 1971 | * Configure the Rx unit of the MAC after a reset. |
| 1972 | **/ |
| 1973 | |
| 1974 | static void |
| 1975 | e1000_configure_rx(struct e1000_adapter *adapter) |
| 1976 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1977 | uint64_t rdba; |
| 1978 | struct e1000_hw *hw = &adapter->hw; |
| 1979 | uint32_t rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1980 | |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1981 | if (adapter->rx_ps_pages) { |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 1982 | /* this is a 32 byte descriptor */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1983 | rdlen = adapter->rx_ring[0].count * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1984 | sizeof(union e1000_rx_desc_packet_split); |
| 1985 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 1986 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
| 1987 | } else { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1988 | rdlen = adapter->rx_ring[0].count * |
| 1989 | sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1990 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1991 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
| 1994 | /* disable receives while setting up the descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1995 | rctl = E1000_READ_REG(hw, RCTL); |
| 1996 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | |
| 1998 | /* set the Receive Delay Timer Register */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1999 | E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2001 | if (hw->mac_type >= e1000_82540) { |
| 2002 | E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2003 | if (adapter->itr_setting != 0) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2004 | E1000_WRITE_REG(hw, ITR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | 1000000000 / (adapter->itr * 256)); |
| 2006 | } |
| 2007 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2008 | if (hw->mac_type >= e1000_82571) { |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2009 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2010 | /* Reset delay timers after every interrupt */ |
Auke Kok | 6fc7a7e | 2006-04-14 19:05:12 -0700 | [diff] [blame] | 2011 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2012 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2013 | /* Auto-Mask interrupts upon ICR access */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2014 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2015 | E1000_WRITE_REG(hw, IAM, 0xffffffff); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2016 | #endif |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2017 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 2018 | E1000_WRITE_FLUSH(hw); |
| 2019 | } |
| 2020 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2021 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2022 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2023 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2024 | case 1: |
| 2025 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2026 | rdba = adapter->rx_ring[0].dma; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2027 | E1000_WRITE_REG(hw, RDLEN, rdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2028 | E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 2029 | E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2030 | E1000_WRITE_REG(hw, RDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2031 | E1000_WRITE_REG(hw, RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 2032 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 2033 | 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] | 2034 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2035 | } |
| 2036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2038 | if (hw->mac_type >= e1000_82543) { |
| 2039 | rxcsum = E1000_READ_REG(hw, RXCSUM); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2040 | if (adapter->rx_csum == TRUE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2041 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 2042 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2043 | /* Enable 82571 IPv4 payload checksum for UDP fragments |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2044 | * Must be used in conjunction with packet-split. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2045 | if ((hw->mac_type >= e1000_82571) && |
| 2046 | (adapter->rx_ps_pages)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2047 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 2048 | } |
| 2049 | } else { |
| 2050 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 2051 | /* don't need to clear IPPCSE as it defaults to 0 */ |
| 2052 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2053 | E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | } |
| 2055 | |
Auke Kok | 21c4d5e | 2006-11-01 08:47:39 -0800 | [diff] [blame] | 2056 | /* enable early receives on 82573, only takes effect if using > 2048 |
| 2057 | * byte total frame size. for example only for jumbo frames */ |
| 2058 | #define E1000_ERT_2048 0x100 |
| 2059 | if (hw->mac_type == e1000_82573) |
| 2060 | E1000_WRITE_REG(hw, ERT, E1000_ERT_2048); |
| 2061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | /* Enable Receives */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2063 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2067 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 2068 | * @adapter: board private structure |
| 2069 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2070 | * |
| 2071 | * Free all transmit software resources |
| 2072 | **/ |
| 2073 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2074 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2075 | e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 2076 | struct e1000_tx_ring *tx_ring) |
| 2077 | { |
| 2078 | struct pci_dev *pdev = adapter->pdev; |
| 2079 | |
| 2080 | e1000_clean_tx_ring(adapter, tx_ring); |
| 2081 | |
| 2082 | vfree(tx_ring->buffer_info); |
| 2083 | tx_ring->buffer_info = NULL; |
| 2084 | |
| 2085 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2086 | |
| 2087 | tx_ring->desc = NULL; |
| 2088 | } |
| 2089 | |
| 2090 | /** |
| 2091 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | * @adapter: board private structure |
| 2093 | * |
| 2094 | * Free all transmit software resources |
| 2095 | **/ |
| 2096 | |
| 2097 | void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2098 | e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2100 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2102 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2103 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2106 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 2108 | struct e1000_buffer *buffer_info) |
| 2109 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2110 | if (buffer_info->dma) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2111 | pci_unmap_page(adapter->pdev, |
| 2112 | buffer_info->dma, |
| 2113 | buffer_info->length, |
| 2114 | PCI_DMA_TODEVICE); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2115 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | } |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2117 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2119 | buffer_info->skb = NULL; |
| 2120 | } |
| 2121 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2126 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2127 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | **/ |
| 2129 | |
| 2130 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2131 | e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 2132 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | struct e1000_buffer *buffer_info; |
| 2135 | unsigned long size; |
| 2136 | unsigned int i; |
| 2137 | |
| 2138 | /* Free all the Tx ring sk_buffs */ |
| 2139 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2140 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | buffer_info = &tx_ring->buffer_info[i]; |
| 2142 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2143 | } |
| 2144 | |
| 2145 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2146 | memset(tx_ring->buffer_info, 0, size); |
| 2147 | |
| 2148 | /* Zero out the descriptor ring */ |
| 2149 | |
| 2150 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2151 | |
| 2152 | tx_ring->next_to_use = 0; |
| 2153 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2154 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2156 | writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
| 2157 | writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
| 2158 | } |
| 2159 | |
| 2160 | /** |
| 2161 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2162 | * @adapter: board private structure |
| 2163 | **/ |
| 2164 | |
| 2165 | static void |
| 2166 | e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
| 2167 | { |
| 2168 | int i; |
| 2169 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2170 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2171 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * e1000_free_rx_resources - Free Rx Resources |
| 2176 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2177 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | * |
| 2179 | * Free all receive software resources |
| 2180 | **/ |
| 2181 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2182 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2183 | e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 2184 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | struct pci_dev *pdev = adapter->pdev; |
| 2187 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2188 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | |
| 2190 | vfree(rx_ring->buffer_info); |
| 2191 | rx_ring->buffer_info = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2192 | kfree(rx_ring->ps_page); |
| 2193 | rx_ring->ps_page = NULL; |
| 2194 | kfree(rx_ring->ps_page_dma); |
| 2195 | rx_ring->ps_page_dma = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | |
| 2197 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2198 | |
| 2199 | rx_ring->desc = NULL; |
| 2200 | } |
| 2201 | |
| 2202 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2203 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2205 | * |
| 2206 | * Free all receive software resources |
| 2207 | **/ |
| 2208 | |
| 2209 | void |
| 2210 | e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
| 2211 | { |
| 2212 | int i; |
| 2213 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2214 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2215 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2220 | * @adapter: board private structure |
| 2221 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | **/ |
| 2223 | |
| 2224 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2225 | e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2226 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | struct e1000_buffer *buffer_info; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2229 | struct e1000_ps_page *ps_page; |
| 2230 | struct e1000_ps_page_dma *ps_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | struct pci_dev *pdev = adapter->pdev; |
| 2232 | unsigned long size; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2233 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | |
| 2235 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2236 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2238 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | pci_unmap_single(pdev, |
| 2240 | buffer_info->dma, |
| 2241 | buffer_info->length, |
| 2242 | PCI_DMA_FROMDEVICE); |
| 2243 | |
| 2244 | dev_kfree_skb(buffer_info->skb); |
| 2245 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2246 | } |
| 2247 | ps_page = &rx_ring->ps_page[i]; |
| 2248 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 2249 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
| 2250 | if (!ps_page->ps_page[j]) break; |
| 2251 | pci_unmap_page(pdev, |
| 2252 | ps_page_dma->ps_page_dma[j], |
| 2253 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 2254 | ps_page_dma->ps_page_dma[j] = 0; |
| 2255 | put_page(ps_page->ps_page[j]); |
| 2256 | ps_page->ps_page[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2261 | memset(rx_ring->buffer_info, 0, size); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2262 | size = sizeof(struct e1000_ps_page) * rx_ring->count; |
| 2263 | memset(rx_ring->ps_page, 0, size); |
| 2264 | size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
| 2265 | memset(rx_ring->ps_page_dma, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
| 2267 | /* Zero out the descriptor ring */ |
| 2268 | |
| 2269 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2270 | |
| 2271 | rx_ring->next_to_clean = 0; |
| 2272 | rx_ring->next_to_use = 0; |
| 2273 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2274 | writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
| 2275 | writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
| 2276 | } |
| 2277 | |
| 2278 | /** |
| 2279 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2280 | * @adapter: board private structure |
| 2281 | **/ |
| 2282 | |
| 2283 | static void |
| 2284 | e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
| 2285 | { |
| 2286 | int i; |
| 2287 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2288 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2289 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2293 | * and memory write and invalidate disabled for certain operations |
| 2294 | */ |
| 2295 | static void |
| 2296 | e1000_enter_82542_rst(struct e1000_adapter *adapter) |
| 2297 | { |
| 2298 | struct net_device *netdev = adapter->netdev; |
| 2299 | uint32_t rctl; |
| 2300 | |
| 2301 | e1000_pci_clear_mwi(&adapter->hw); |
| 2302 | |
| 2303 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2304 | rctl |= E1000_RCTL_RST; |
| 2305 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2306 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2307 | mdelay(5); |
| 2308 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2309 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2310 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | static void |
| 2314 | e1000_leave_82542_rst(struct e1000_adapter *adapter) |
| 2315 | { |
| 2316 | struct net_device *netdev = adapter->netdev; |
| 2317 | uint32_t rctl; |
| 2318 | |
| 2319 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2320 | rctl &= ~E1000_RCTL_RST; |
| 2321 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2322 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2323 | mdelay(5); |
| 2324 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2325 | if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | e1000_pci_set_mwi(&adapter->hw); |
| 2327 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2328 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2329 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2330 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2331 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2332 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2338 | * @netdev: network interface device structure |
| 2339 | * @p: pointer to an address structure |
| 2340 | * |
| 2341 | * Returns 0 on success, negative on failure |
| 2342 | **/ |
| 2343 | |
| 2344 | static int |
| 2345 | e1000_set_mac(struct net_device *netdev, void *p) |
| 2346 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2347 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | struct sockaddr *addr = p; |
| 2349 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2350 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | return -EADDRNOTAVAIL; |
| 2352 | |
| 2353 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2354 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2355 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | e1000_enter_82542_rst(adapter); |
| 2357 | |
| 2358 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2359 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 2360 | |
| 2361 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2362 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2363 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2364 | * due to controller reset from the other port. */ |
| 2365 | if (adapter->hw.mac_type == e1000_82571) { |
| 2366 | /* activate the work around */ |
| 2367 | adapter->hw.laa_is_present = 1; |
| 2368 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2369 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2370 | * between the time RAR[0] gets clobbered and the time it |
| 2371 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2372 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2373 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2374 | * RAR[14] */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2375 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2376 | E1000_RAR_ENTRIES - 1); |
| 2377 | } |
| 2378 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2379 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | e1000_leave_82542_rst(adapter); |
| 2381 | |
| 2382 | return 0; |
| 2383 | } |
| 2384 | |
| 2385 | /** |
| 2386 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 2387 | * @netdev: network interface device structure |
| 2388 | * |
| 2389 | * The set_multi entry point is called whenever the multicast address |
| 2390 | * list or the network interface flags are updated. This routine is |
| 2391 | * responsible for configuring the hardware for proper multicast, |
| 2392 | * promiscuous mode, and all-multi behavior. |
| 2393 | **/ |
| 2394 | |
| 2395 | static void |
| 2396 | e1000_set_multi(struct net_device *netdev) |
| 2397 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2398 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | struct e1000_hw *hw = &adapter->hw; |
| 2400 | struct dev_mc_list *mc_ptr; |
| 2401 | uint32_t rctl; |
| 2402 | uint32_t hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2403 | int i, rar_entries = E1000_RAR_ENTRIES; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2404 | int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
| 2405 | E1000_NUM_MTA_REGISTERS_ICH8LAN : |
| 2406 | E1000_NUM_MTA_REGISTERS; |
| 2407 | |
| 2408 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 2409 | rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2411 | /* reserve RAR[14] for LAA over-write work-around */ |
| 2412 | if (adapter->hw.mac_type == e1000_82571) |
| 2413 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2415 | /* Check for Promiscuous and All Multicast modes */ |
| 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | rctl = E1000_READ_REG(hw, RCTL); |
| 2418 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2419 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2421 | } else if (netdev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | rctl |= E1000_RCTL_MPE; |
| 2423 | rctl &= ~E1000_RCTL_UPE; |
| 2424 | } else { |
| 2425 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 2426 | } |
| 2427 | |
| 2428 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 2429 | |
| 2430 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2431 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2432 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | e1000_enter_82542_rst(adapter); |
| 2434 | |
| 2435 | /* load the first 14 multicast address into the exact filters 1-14 |
| 2436 | * RAR 0 is used for the station MAC adddress |
| 2437 | * 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] | 2438 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | */ |
| 2440 | mc_ptr = netdev->mc_list; |
| 2441 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2442 | for (i = 1; i < rar_entries; i++) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2443 | if (mc_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | e1000_rar_set(hw, mc_ptr->dmi_addr, i); |
| 2445 | mc_ptr = mc_ptr->next; |
| 2446 | } else { |
| 2447 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2448 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2450 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | /* clear the old settings from the multicast hash table */ |
| 2455 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2456 | for (i = 0; i < mta_reg_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2458 | E1000_WRITE_FLUSH(hw); |
| 2459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | |
| 2461 | /* load any remaining addresses into the hash table */ |
| 2462 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2463 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr); |
| 2465 | e1000_mta_set(hw, hash_value); |
| 2466 | } |
| 2467 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2468 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | e1000_leave_82542_rst(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2473 | * the phy */ |
| 2474 | |
| 2475 | static void |
| 2476 | e1000_update_phy_info(unsigned long data) |
| 2477 | { |
| 2478 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2479 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
| 2480 | } |
| 2481 | |
| 2482 | /** |
| 2483 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2484 | * @data: pointer to adapter cast into an unsigned long |
| 2485 | **/ |
| 2486 | |
| 2487 | static void |
| 2488 | e1000_82547_tx_fifo_stall(unsigned long data) |
| 2489 | { |
| 2490 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2491 | struct net_device *netdev = adapter->netdev; |
| 2492 | uint32_t tctl; |
| 2493 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2494 | if (atomic_read(&adapter->tx_fifo_stall)) { |
| 2495 | if ((E1000_READ_REG(&adapter->hw, TDT) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | E1000_READ_REG(&adapter->hw, TDH)) && |
| 2497 | (E1000_READ_REG(&adapter->hw, TDFT) == |
| 2498 | E1000_READ_REG(&adapter->hw, TDFH)) && |
| 2499 | (E1000_READ_REG(&adapter->hw, TDFTS) == |
| 2500 | E1000_READ_REG(&adapter->hw, TDFHS))) { |
| 2501 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2502 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 2503 | tctl & ~E1000_TCTL_EN); |
| 2504 | E1000_WRITE_REG(&adapter->hw, TDFT, |
| 2505 | adapter->tx_head_addr); |
| 2506 | E1000_WRITE_REG(&adapter->hw, TDFH, |
| 2507 | adapter->tx_head_addr); |
| 2508 | E1000_WRITE_REG(&adapter->hw, TDFTS, |
| 2509 | adapter->tx_head_addr); |
| 2510 | E1000_WRITE_REG(&adapter->hw, TDFHS, |
| 2511 | adapter->tx_head_addr); |
| 2512 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
| 2513 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2514 | |
| 2515 | adapter->tx_fifo_head = 0; |
| 2516 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2517 | netif_wake_queue(netdev); |
| 2518 | } else { |
| 2519 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | /** |
| 2525 | * e1000_watchdog - Timer Call-back |
| 2526 | * @data: pointer to adapter cast into an unsigned long |
| 2527 | **/ |
| 2528 | static void |
| 2529 | e1000_watchdog(unsigned long data) |
| 2530 | { |
| 2531 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2533 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2534 | uint32_t link, tctl; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2535 | int32_t ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2537 | ret_val = e1000_check_for_link(&adapter->hw); |
| 2538 | if ((ret_val == E1000_ERR_PHY) && |
| 2539 | (adapter->hw.phy_type == e1000_phy_igp_3) && |
| 2540 | (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 2541 | /* See e1000_kumeran_lock_loss_workaround() */ |
| 2542 | DPRINTK(LINK, INFO, |
| 2543 | "Gigabit has been disabled, downgrading speed\n"); |
| 2544 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2545 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2546 | if (adapter->hw.mac_type == e1000_82573) { |
| 2547 | e1000_enable_tx_pkt_filtering(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2548 | if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2549 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2552 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
| 2554 | link = !adapter->hw.serdes_link_down; |
| 2555 | else |
| 2556 | link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
| 2557 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2558 | if (link) { |
| 2559 | if (!netif_carrier_ok(netdev)) { |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2560 | uint32_t ctrl; |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2561 | boolean_t txb2b = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | e1000_get_speed_and_duplex(&adapter->hw, |
| 2563 | &adapter->link_speed, |
| 2564 | &adapter->link_duplex); |
| 2565 | |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2566 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 2567 | DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, " |
| 2568 | "Flow Control: %s\n", |
| 2569 | adapter->link_speed, |
| 2570 | adapter->link_duplex == FULL_DUPLEX ? |
| 2571 | "Full Duplex" : "Half Duplex", |
| 2572 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2573 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2574 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2575 | E1000_CTRL_TFCE) ? "TX" : "None" ))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2577 | /* tweak tx_queue_len according to speed/duplex |
| 2578 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2579 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2580 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2581 | switch (adapter->link_speed) { |
| 2582 | case SPEED_10: |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2583 | txb2b = 0; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2584 | netdev->tx_queue_len = 10; |
| 2585 | adapter->tx_timeout_factor = 8; |
| 2586 | break; |
| 2587 | case SPEED_100: |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2588 | txb2b = 0; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2589 | netdev->tx_queue_len = 100; |
| 2590 | /* maybe add some timeout factor ? */ |
| 2591 | break; |
| 2592 | } |
| 2593 | |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2594 | if ((adapter->hw.mac_type == e1000_82571 || |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2595 | adapter->hw.mac_type == e1000_82572) && |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2596 | txb2b == 0) { |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2597 | uint32_t tarc0; |
| 2598 | tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2599 | tarc0 &= ~(1 << 21); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2600 | E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
| 2601 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2602 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2603 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2604 | * some hardware issues */ |
| 2605 | if (!adapter->tso_force && |
| 2606 | adapter->hw.bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2607 | switch (adapter->link_speed) { |
| 2608 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2609 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2610 | DPRINTK(PROBE,INFO, |
| 2611 | "10/100 speed: disabling TSO\n"); |
| 2612 | netdev->features &= ~NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2613 | netdev->features &= ~NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2614 | break; |
| 2615 | case SPEED_1000: |
| 2616 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2617 | netdev->features |= NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2618 | break; |
| 2619 | default: |
| 2620 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2621 | break; |
| 2622 | } |
| 2623 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2624 | |
| 2625 | /* enable transmits in the hardware, need to do this |
| 2626 | * after setting TARC0 */ |
| 2627 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2628 | tctl |= E1000_TCTL_EN; |
| 2629 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | netif_carrier_on(netdev); |
| 2632 | netif_wake_queue(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2633 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | adapter->smartspeed = 0; |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2635 | } else { |
| 2636 | /* make sure the receive unit is started */ |
| 2637 | if (adapter->hw.rx_needs_kicking) { |
| 2638 | struct e1000_hw *hw = &adapter->hw; |
| 2639 | uint32_t rctl = E1000_READ_REG(hw, RCTL); |
| 2640 | E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN); |
| 2641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | } |
| 2643 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2644 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | adapter->link_speed = 0; |
| 2646 | adapter->link_duplex = 0; |
| 2647 | DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
| 2648 | netif_carrier_off(netdev); |
| 2649 | netif_stop_queue(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2650 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2651 | |
| 2652 | /* 80003ES2LAN workaround-- |
| 2653 | * For packet buffer work-around on link down event; |
| 2654 | * disable receives in the ISR and |
| 2655 | * reset device here in the watchdog |
| 2656 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2657 | if (adapter->hw.mac_type == e1000_80003es2lan) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2658 | /* reset device */ |
| 2659 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | e1000_smartspeed(adapter); |
| 2663 | } |
| 2664 | |
| 2665 | e1000_update_stats(adapter); |
| 2666 | |
| 2667 | adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2668 | adapter->tpt_old = adapter->stats.tpt; |
| 2669 | adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2670 | adapter->colc_old = adapter->stats.colc; |
| 2671 | |
| 2672 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2673 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2674 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2675 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2676 | |
| 2677 | e1000_update_adaptive(&adapter->hw); |
| 2678 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2679 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2680 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | /* We've lost link, so the controller stops DMA, |
| 2682 | * but we've got queued Tx work that's never going |
| 2683 | * to get done, so reset controller to flush Tx. |
| 2684 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2685 | adapter->tx_timeout_count++; |
| 2686 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | /* Cause software interrupt to ensure rx ring is cleaned */ |
| 2691 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
| 2692 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2693 | /* Force detection of hung controller every watchdog period */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | adapter->detect_tx_hung = TRUE; |
| 2695 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2696 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2697 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
| 2698 | if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
| 2699 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | /* Reset the timer */ |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2702 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2705 | enum latency_range { |
| 2706 | lowest_latency = 0, |
| 2707 | low_latency = 1, |
| 2708 | bulk_latency = 2, |
| 2709 | latency_invalid = 255 |
| 2710 | }; |
| 2711 | |
| 2712 | /** |
| 2713 | * e1000_update_itr - update the dynamic ITR value based on statistics |
| 2714 | * Stores a new ITR value based on packets and byte |
| 2715 | * counts during the last interrupt. The advantage of per interrupt |
| 2716 | * computation is faster updates and more accurate ITR for the current |
| 2717 | * traffic pattern. Constants in this function were computed |
| 2718 | * based on theoretical maximum wire speed and thresholds were set based |
| 2719 | * on testing data as well as attempting to minimize response time |
| 2720 | * while increasing bulk throughput. |
| 2721 | * this functionality is controlled by the InterruptThrottleRate module |
| 2722 | * parameter (see e1000_param.c) |
| 2723 | * @adapter: pointer to adapter |
| 2724 | * @itr_setting: current adapter->itr |
| 2725 | * @packets: the number of packets during this measurement interval |
| 2726 | * @bytes: the number of bytes during this measurement interval |
| 2727 | **/ |
| 2728 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
| 2729 | uint16_t itr_setting, |
| 2730 | int packets, |
| 2731 | int bytes) |
| 2732 | { |
| 2733 | unsigned int retval = itr_setting; |
| 2734 | struct e1000_hw *hw = &adapter->hw; |
| 2735 | |
| 2736 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2737 | goto update_itr_done; |
| 2738 | |
| 2739 | if (packets == 0) |
| 2740 | goto update_itr_done; |
| 2741 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2742 | switch (itr_setting) { |
| 2743 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2744 | /* jumbo frames get bulk treatment*/ |
| 2745 | if (bytes/packets > 8000) |
| 2746 | retval = bulk_latency; |
| 2747 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2748 | retval = low_latency; |
| 2749 | break; |
| 2750 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2751 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2752 | /* jumbo frames need bulk latency setting */ |
| 2753 | if (bytes/packets > 8000) |
| 2754 | retval = bulk_latency; |
| 2755 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2756 | retval = bulk_latency; |
| 2757 | else if ((packets > 35)) |
| 2758 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2759 | } else if (bytes/packets > 2000) |
| 2760 | retval = bulk_latency; |
| 2761 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2762 | retval = lowest_latency; |
| 2763 | break; |
| 2764 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2765 | if (bytes > 25000) { |
| 2766 | if (packets > 35) |
| 2767 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2768 | } else if (bytes < 6000) { |
| 2769 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2770 | } |
| 2771 | break; |
| 2772 | } |
| 2773 | |
| 2774 | update_itr_done: |
| 2775 | return retval; |
| 2776 | } |
| 2777 | |
| 2778 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2779 | { |
| 2780 | struct e1000_hw *hw = &adapter->hw; |
| 2781 | uint16_t current_itr; |
| 2782 | uint32_t new_itr = adapter->itr; |
| 2783 | |
| 2784 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2785 | return; |
| 2786 | |
| 2787 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2788 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2789 | current_itr = 0; |
| 2790 | new_itr = 4000; |
| 2791 | goto set_itr_now; |
| 2792 | } |
| 2793 | |
| 2794 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2795 | adapter->tx_itr, |
| 2796 | adapter->total_tx_packets, |
| 2797 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2798 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2799 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2800 | adapter->tx_itr = low_latency; |
| 2801 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2802 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2803 | adapter->rx_itr, |
| 2804 | adapter->total_rx_packets, |
| 2805 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2806 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2807 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2808 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2809 | |
| 2810 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2811 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2812 | switch (current_itr) { |
| 2813 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2814 | case lowest_latency: |
| 2815 | new_itr = 70000; |
| 2816 | break; |
| 2817 | case low_latency: |
| 2818 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2819 | break; |
| 2820 | case bulk_latency: |
| 2821 | new_itr = 4000; |
| 2822 | break; |
| 2823 | default: |
| 2824 | break; |
| 2825 | } |
| 2826 | |
| 2827 | set_itr_now: |
| 2828 | if (new_itr != adapter->itr) { |
| 2829 | /* this attempts to bias the interrupt rate towards Bulk |
| 2830 | * by adding intermediate steps when interrupt rate is |
| 2831 | * increasing */ |
| 2832 | new_itr = new_itr > adapter->itr ? |
| 2833 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2834 | new_itr; |
| 2835 | adapter->itr = new_itr; |
| 2836 | E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256)); |
| 2837 | } |
| 2838 | |
| 2839 | return; |
| 2840 | } |
| 2841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2843 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2844 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2845 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2847 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2848 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2849 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2850 | e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2851 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2854 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | unsigned int i; |
| 2856 | uint32_t cmd_length = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2857 | uint16_t ipcse = 0, tucse, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
| 2859 | int err; |
| 2860 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2861 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | if (skb_header_cloned(skb)) { |
| 2863 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2864 | if (err) |
| 2865 | return err; |
| 2866 | } |
| 2867 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2868 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2869 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2870 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2871 | struct iphdr *iph = ip_hdr(skb); |
| 2872 | iph->tot_len = 0; |
| 2873 | iph->check = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2874 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2875 | iph->daddr, 0, |
| 2876 | IPPROTO_TCP, |
| 2877 | 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2878 | cmd_length = E1000_TXD_CMD_IP; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2879 | ipcse = skb_transport_offset(skb) - 1; |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2880 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2881 | ipv6_hdr(skb)->payload_len = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2882 | tcp_hdr(skb)->check = |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2883 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2884 | &ipv6_hdr(skb)->daddr, |
| 2885 | 0, IPPROTO_TCP, 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2886 | ipcse = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2887 | } |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 2888 | ipcss = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2889 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2890 | tucss = skb_transport_offset(skb); |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2891 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | tucse = 0; |
| 2893 | |
| 2894 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2895 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2897 | i = tx_ring->next_to_use; |
| 2898 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2899 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | |
| 2901 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2902 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2903 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2904 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2905 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2906 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2907 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2908 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2909 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2910 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2911 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2912 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2913 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2914 | if (++i == tx_ring->count) i = 0; |
| 2915 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2917 | return TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | } |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2919 | return FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2922 | static boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2923 | e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2924 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | { |
| 2926 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2927 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | unsigned int i; |
| 2929 | uint8_t css; |
| 2930 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 2931 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2932 | css = skb_transport_offset(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2934 | i = tx_ring->next_to_use; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2935 | buffer_info = &tx_ring->buffer_info[i]; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2936 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | |
Bruce Allan | f6c57ba | 2007-01-18 09:25:28 -0800 | [diff] [blame] | 2938 | context_desc->lower_setup.ip_config = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | context_desc->upper_setup.tcp_fields.tucss = css; |
Herbert Xu | 628592c | 2007-04-23 17:06:40 -0700 | [diff] [blame] | 2940 | context_desc->upper_setup.tcp_fields.tucso = |
| 2941 | css + skb->csum_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2943 | context_desc->tcp_seg_setup.data = 0; |
| 2944 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 2945 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2946 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2947 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2948 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2949 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2950 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | |
| 2952 | return TRUE; |
| 2953 | } |
| 2954 | |
| 2955 | return FALSE; |
| 2956 | } |
| 2957 | |
| 2958 | #define E1000_MAX_TXD_PWR 12 |
| 2959 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2960 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2961 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2962 | e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2963 | struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
| 2964 | unsigned int nr_frags, unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | struct e1000_buffer *buffer_info; |
| 2967 | unsigned int len = skb->len; |
| 2968 | unsigned int offset = 0, size, count = 0, i; |
| 2969 | unsigned int f; |
| 2970 | len -= skb->data_len; |
| 2971 | |
| 2972 | i = tx_ring->next_to_use; |
| 2973 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2974 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | buffer_info = &tx_ring->buffer_info[i]; |
| 2976 | size = min(len, max_per_txd); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2977 | /* Workaround for Controller erratum -- |
| 2978 | * descriptor for non-tso packet in a linear SKB that follows a |
| 2979 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2980 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2981 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2982 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2983 | tx_ring->last_tx_tso = 0; |
| 2984 | size -= 4; |
| 2985 | } |
| 2986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | /* Workaround for premature desc write-backs |
| 2988 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2989 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | size -= 4; |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2991 | /* work-around for errata 10 and it applies |
| 2992 | * to all controllers in PCI-X mode |
| 2993 | * The fix is to make sure that the first descriptor of a |
| 2994 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 2995 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2996 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2997 | (size > 2015) && count == 0)) |
| 2998 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 3001 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3002 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 3004 | size > 4)) |
| 3005 | size -= 4; |
| 3006 | |
| 3007 | buffer_info->length = size; |
| 3008 | buffer_info->dma = |
| 3009 | pci_map_single(adapter->pdev, |
| 3010 | skb->data + offset, |
| 3011 | size, |
| 3012 | PCI_DMA_TODEVICE); |
| 3013 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3014 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | |
| 3016 | len -= size; |
| 3017 | offset += size; |
| 3018 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3019 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3022 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | struct skb_frag_struct *frag; |
| 3024 | |
| 3025 | frag = &skb_shinfo(skb)->frags[f]; |
| 3026 | len = frag->size; |
| 3027 | offset = frag->page_offset; |
| 3028 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3029 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | buffer_info = &tx_ring->buffer_info[i]; |
| 3031 | size = min(len, max_per_txd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | /* Workaround for premature desc write-backs |
| 3033 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3034 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | size -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | /* Workaround for potential 82544 hang in PCI-X. |
| 3037 | * Avoid terminating buffers within evenly-aligned |
| 3038 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3039 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 3041 | size > 4)) |
| 3042 | size -= 4; |
| 3043 | |
| 3044 | buffer_info->length = size; |
| 3045 | buffer_info->dma = |
| 3046 | pci_map_page(adapter->pdev, |
| 3047 | frag->page, |
| 3048 | offset, |
| 3049 | size, |
| 3050 | PCI_DMA_TODEVICE); |
| 3051 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3052 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | |
| 3054 | len -= size; |
| 3055 | offset += size; |
| 3056 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3057 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 3062 | tx_ring->buffer_info[i].skb = skb; |
| 3063 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3064 | |
| 3065 | return count; |
| 3066 | } |
| 3067 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3068 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3069 | e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3070 | int tx_flags, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | struct e1000_tx_desc *tx_desc = NULL; |
| 3073 | struct e1000_buffer *buffer_info; |
| 3074 | uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 3075 | unsigned int i; |
| 3076 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3077 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3079 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3080 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3081 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3082 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3083 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3086 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3088 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3089 | } |
| 3090 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3091 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3093 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3094 | } |
| 3095 | |
| 3096 | i = tx_ring->next_to_use; |
| 3097 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3098 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | buffer_info = &tx_ring->buffer_info[i]; |
| 3100 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3101 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3102 | tx_desc->lower.data = |
| 3103 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3104 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3105 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3109 | |
| 3110 | /* Force memory writes to complete before letting h/w |
| 3111 | * know there are new descriptors to fetch. (Only |
| 3112 | * applicable for weak-ordered memory model archs, |
| 3113 | * such as IA-64). */ |
| 3114 | wmb(); |
| 3115 | |
| 3116 | tx_ring->next_to_use = i; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3117 | writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 3118 | /* we need this if more than one processor can write to our tail |
| 3119 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3120 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | /** |
| 3124 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 3125 | * The workaround is to avoid queuing a large packet that would span |
| 3126 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 3127 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 3128 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 3129 | * to the beginning of the Tx FIFO. |
| 3130 | **/ |
| 3131 | |
| 3132 | #define E1000_FIFO_HDR 0x10 |
| 3133 | #define E1000_82547_PAD_LEN 0x3E0 |
| 3134 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3135 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3137 | { |
| 3138 | uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 3139 | uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR; |
| 3140 | |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 3141 | skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3143 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | goto no_fifo_stall_required; |
| 3145 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3146 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | return 1; |
| 3148 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3149 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3151 | return 1; |
| 3152 | } |
| 3153 | |
| 3154 | no_fifo_stall_required: |
| 3155 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3156 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3158 | return 0; |
| 3159 | } |
| 3160 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3161 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3162 | static int |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3163 | e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3164 | { |
| 3165 | struct e1000_hw *hw = &adapter->hw; |
| 3166 | uint16_t length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3167 | if (vlan_tx_tag_present(skb)) { |
| 3168 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3169 | ( adapter->hw.mng_cookie.status & |
| 3170 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 3171 | return 0; |
| 3172 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 3173 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3174 | struct ethhdr *eth = (struct ethhdr *) skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3175 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 3176 | const struct iphdr *ip = |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3177 | (struct iphdr *)((uint8_t *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3178 | if (IPPROTO_UDP == ip->protocol) { |
| 3179 | struct udphdr *udp = |
| 3180 | (struct udphdr *)((uint8_t *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3181 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3182 | if (ntohs(udp->dest) == 67) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3183 | offset = (uint8_t *)udp + 8 - skb->data; |
| 3184 | length = skb->len - offset; |
| 3185 | |
| 3186 | return e1000_mng_write_dhcp_info(hw, |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3187 | (uint8_t *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3188 | length); |
| 3189 | } |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | return 0; |
| 3194 | } |
| 3195 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3196 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3197 | { |
| 3198 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3199 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3200 | |
| 3201 | netif_stop_queue(netdev); |
| 3202 | /* Herbert's original patch had: |
| 3203 | * smp_mb__after_netif_stop_queue(); |
| 3204 | * but since that doesn't exist yet, just open code it. */ |
| 3205 | smp_mb(); |
| 3206 | |
| 3207 | /* We need to check again in a case another CPU has just |
| 3208 | * made room available. */ |
| 3209 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3210 | return -EBUSY; |
| 3211 | |
| 3212 | /* A reprieve! */ |
| 3213 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3214 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3215 | return 0; |
| 3216 | } |
| 3217 | |
| 3218 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3219 | struct e1000_tx_ring *tx_ring, int size) |
| 3220 | { |
| 3221 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3222 | return 0; |
| 3223 | return __e1000_maybe_stop_tx(netdev, size); |
| 3224 | } |
| 3225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 3227 | static int |
| 3228 | e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 3229 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3230 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3231 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3233 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3234 | unsigned int tx_flags = 0; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3235 | unsigned int len = skb->len - skb->data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | unsigned long flags; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3237 | unsigned int nr_frags; |
| 3238 | unsigned int mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3240 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3243 | /* This goes back to the question of how to logically map a tx queue |
| 3244 | * to a flow. Right now, performance is impacted slightly negatively |
| 3245 | * if using multiple tx queues. If the stack breaks away from a |
| 3246 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3247 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3248 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3249 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | dev_kfree_skb_any(skb); |
| 3251 | return NETDEV_TX_OK; |
| 3252 | } |
| 3253 | |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3254 | /* 82571 and newer doesn't need the workaround that limited descriptor |
| 3255 | * length to 4kB */ |
| 3256 | if (adapter->hw.mac_type >= e1000_82571) |
| 3257 | max_per_txd = 8192; |
| 3258 | |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3259 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3260 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | * make sure there is enough room in the FIFO before |
| 3262 | * initiating the DMA for each buffer. The calc is: |
| 3263 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3264 | * overrun the FIFO, adjust the max buffer len if mss |
| 3265 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3266 | if (mss) { |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3267 | uint8_t hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | max_per_txd = min(mss << 2, max_per_txd); |
| 3269 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3270 | |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3271 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3272 | * points to just header, pull a few bytes of payload from |
| 3273 | * frags into skb->data */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 3274 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3275 | if (skb->data_len && hdr_len == len) { |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3276 | switch (adapter->hw.mac_type) { |
| 3277 | unsigned int pull_size; |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3278 | case e1000_82544: |
| 3279 | /* Make sure we have room to chop off 4 bytes, |
| 3280 | * and that the end alignment will work out to |
| 3281 | * this hardware's requirements |
| 3282 | * NOTE: this is a TSO only workaround |
| 3283 | * if end byte alignment not correct move us |
| 3284 | * into the next dword */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3285 | if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3286 | break; |
| 3287 | /* fall through */ |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3288 | case e1000_82571: |
| 3289 | case e1000_82572: |
| 3290 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3291 | case e1000_ich8lan: |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3292 | pull_size = min((unsigned int)4, skb->data_len); |
| 3293 | if (!__pskb_pull_tail(skb, pull_size)) { |
Auke Kok | a5eafce | 2006-06-27 09:06:49 -0700 | [diff] [blame] | 3294 | DPRINTK(DRV, ERR, |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3295 | "__pskb_pull_tail failed.\n"); |
| 3296 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc70 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3297 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3298 | } |
| 3299 | len = skb->len - skb->data_len; |
| 3300 | break; |
| 3301 | default: |
| 3302 | /* do nothing */ |
| 3303 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3304 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3308 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3309 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3311 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3312 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3313 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3314 | 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] | 3315 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3318 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3319 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | count++; |
| 3321 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3322 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3323 | * in PCI-X mode, so add one more descriptor to the count |
| 3324 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3325 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3326 | (len > 2015))) |
| 3327 | count++; |
| 3328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3330 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3332 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3333 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | count += nr_frags; |
| 3335 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3336 | |
| 3337 | if (adapter->hw.tx_pkt_filtering && |
| 3338 | (adapter->hw.mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3339 | e1000_transfer_dhcp_info(adapter, skb); |
| 3340 | |
Mark Huth | f50393f | 2007-03-06 08:57:26 -0800 | [diff] [blame] | 3341 | if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3342 | /* Collision - tell upper layer to requeue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3343 | return NETDEV_TX_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | |
| 3345 | /* need: count + 2 desc gap to keep tail from touching |
| 3346 | * head, otherwise try next time */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3347 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3348 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | return NETDEV_TX_BUSY; |
| 3350 | } |
| 3351 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3352 | if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
| 3353 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | netif_stop_queue(netdev); |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3355 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3356 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | return NETDEV_TX_BUSY; |
| 3358 | } |
| 3359 | } |
| 3360 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3361 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3363 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3364 | } |
| 3365 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3366 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3367 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3368 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | if (tso < 0) { |
| 3370 | dev_kfree_skb_any(skb); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3371 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | return NETDEV_TX_OK; |
| 3373 | } |
| 3374 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3375 | if (likely(tso)) { |
| 3376 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3378 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3380 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3381 | /* 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] | 3382 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3383 | * no longer assume, we must. */ |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3384 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3385 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3386 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3387 | e1000_tx_queue(adapter, tx_ring, tx_flags, |
| 3388 | e1000_tx_map(adapter, tx_ring, skb, first, |
| 3389 | max_per_txd, nr_frags, mss)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | |
| 3391 | netdev->trans_start = jiffies; |
| 3392 | |
| 3393 | /* Make sure there is space in the ring for the next send. */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3394 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3396 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | return NETDEV_TX_OK; |
| 3398 | } |
| 3399 | |
| 3400 | /** |
| 3401 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3402 | * @netdev: network interface device structure |
| 3403 | **/ |
| 3404 | |
| 3405 | static void |
| 3406 | e1000_tx_timeout(struct net_device *netdev) |
| 3407 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3408 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | |
| 3410 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3411 | adapter->tx_timeout_count++; |
| 3412 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | static void |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3416 | e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3418 | struct e1000_adapter *adapter = |
| 3419 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3421 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | /** |
| 3425 | * e1000_get_stats - Get System Network Statistics |
| 3426 | * @netdev: network interface device structure |
| 3427 | * |
| 3428 | * Returns the address of the device statistics structure. |
| 3429 | * The statistics are actually updated from the timer callback. |
| 3430 | **/ |
| 3431 | |
| 3432 | static struct net_device_stats * |
| 3433 | e1000_get_stats(struct net_device *netdev) |
| 3434 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3435 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3437 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | return &adapter->net_stats; |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3443 | * @netdev: network interface device structure |
| 3444 | * @new_mtu: new value for maximum frame size |
| 3445 | * |
| 3446 | * Returns 0 on success, negative on failure |
| 3447 | **/ |
| 3448 | |
| 3449 | static int |
| 3450 | e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 3451 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3452 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3454 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3456 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3457 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3458 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3459 | return -EINVAL; |
| 3460 | } |
| 3461 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3462 | /* Adapter-specific max frame size limits. */ |
| 3463 | switch (adapter->hw.mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3464 | case e1000_undefined ... e1000_82542_rev2_1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3465 | case e1000_ich8lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3466 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3467 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3468 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3469 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3470 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3471 | case e1000_82573: |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3472 | /* Jumbo Frames not supported if: |
| 3473 | * - this is not an 82573L device |
| 3474 | * - ASPM is enabled in any way (0x1A bits 3:2) */ |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3475 | e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
| 3476 | &eeprom_data); |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3477 | if ((adapter->hw.device_id != E1000_DEV_ID_82573L) || |
| 3478 | (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3479 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3480 | DPRINTK(PROBE, ERR, |
| 3481 | "Jumbo Frames not supported.\n"); |
| 3482 | return -EINVAL; |
| 3483 | } |
| 3484 | break; |
| 3485 | } |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3486 | /* ERT will be enabled later to enable wire speed receives */ |
| 3487 | |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3488 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3489 | case e1000_82571: |
| 3490 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3491 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3492 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3493 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3494 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3495 | return -EINVAL; |
| 3496 | } |
| 3497 | break; |
| 3498 | default: |
| 3499 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3500 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3503 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3504 | * means we reserve 2 more, this pushes us to allocate from the next |
| 3505 | * larger slab size |
| 3506 | * i.e. RXBUFFER_2048 --> size-4096 slab */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3507 | |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3508 | if (max_frame <= E1000_RXBUFFER_256) |
| 3509 | adapter->rx_buffer_len = E1000_RXBUFFER_256; |
| 3510 | else if (max_frame <= E1000_RXBUFFER_512) |
| 3511 | adapter->rx_buffer_len = E1000_RXBUFFER_512; |
| 3512 | else if (max_frame <= E1000_RXBUFFER_1024) |
| 3513 | adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
| 3514 | else if (max_frame <= E1000_RXBUFFER_2048) |
| 3515 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
| 3516 | else if (max_frame <= E1000_RXBUFFER_4096) |
| 3517 | adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
| 3518 | else if (max_frame <= E1000_RXBUFFER_8192) |
| 3519 | adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
| 3520 | else if (max_frame <= E1000_RXBUFFER_16384) |
| 3521 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
| 3522 | |
| 3523 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3524 | if (!adapter->hw.tbi_compatibility_on && |
| 3525 | ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
| 3526 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3527 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3528 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3529 | netdev->mtu = new_mtu; |
Bruce Allan | 83cd827 | 2006-12-15 10:36:35 +0100 | [diff] [blame] | 3530 | adapter->hw.max_frame_size = max_frame; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3531 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3532 | if (netif_running(netdev)) |
| 3533 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | return 0; |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * e1000_update_stats - Update the board statistics counters |
| 3540 | * @adapter: board private structure |
| 3541 | **/ |
| 3542 | |
| 3543 | void |
| 3544 | e1000_update_stats(struct e1000_adapter *adapter) |
| 3545 | { |
| 3546 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3547 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | unsigned long flags; |
| 3549 | uint16_t phy_tmp; |
| 3550 | |
| 3551 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3552 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3553 | /* |
| 3554 | * Prevent stats update while adapter is being reset, or if the pci |
| 3555 | * connection is down. |
| 3556 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3557 | if (adapter->link_speed == 0) |
| 3558 | return; |
Linas Vepstas | 81b1955 | 2006-12-12 18:29:15 -0600 | [diff] [blame] | 3559 | if (pci_channel_offline(pdev)) |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3560 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3563 | |
Masatake YAMATO | 828d055 | 2007-10-20 03:06:37 +0200 | [diff] [blame] | 3564 | /* these counters are modified from e1000_tbi_adjust_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | * called from the interrupt context, so they must only |
| 3566 | * be written while holding adapter->stats_lock |
| 3567 | */ |
| 3568 | |
| 3569 | adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
| 3570 | adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
| 3571 | adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
| 3572 | adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
| 3573 | adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
| 3574 | adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
| 3575 | adapter->stats.roc += E1000_READ_REG(hw, ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3576 | |
| 3577 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3578 | adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
| 3579 | adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
| 3580 | adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
| 3581 | adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
| 3582 | adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
| 3583 | adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | |
| 3586 | adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
| 3587 | adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
| 3588 | adapter->stats.scc += E1000_READ_REG(hw, SCC); |
| 3589 | adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
| 3590 | adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
| 3591 | adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
| 3592 | adapter->stats.dc += E1000_READ_REG(hw, DC); |
| 3593 | adapter->stats.sec += E1000_READ_REG(hw, SEC); |
| 3594 | adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
| 3595 | adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
| 3596 | adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
| 3597 | adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
| 3598 | adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
| 3599 | adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
| 3600 | adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
| 3601 | adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
| 3602 | adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
| 3603 | adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
| 3604 | adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
| 3605 | adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
| 3606 | adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
| 3607 | adapter->stats.torl += E1000_READ_REG(hw, TORL); |
| 3608 | adapter->stats.torh += E1000_READ_REG(hw, TORH); |
| 3609 | adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
| 3610 | adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
| 3611 | adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3612 | |
| 3613 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3614 | adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
| 3615 | adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
| 3616 | adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
| 3617 | adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
| 3618 | adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
| 3619 | adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
| 3623 | adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
| 3624 | |
| 3625 | /* used for adaptive IFS */ |
| 3626 | |
| 3627 | hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
| 3628 | adapter->stats.tpt += hw->tx_packet_delta; |
| 3629 | hw->collision_delta = E1000_READ_REG(hw, COLC); |
| 3630 | adapter->stats.colc += hw->collision_delta; |
| 3631 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3632 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
| 3634 | adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
| 3635 | adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
| 3636 | adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
| 3637 | adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
| 3638 | adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
| 3639 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3640 | if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3641 | adapter->stats.iac += E1000_READ_REG(hw, IAC); |
| 3642 | adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3643 | |
| 3644 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3645 | adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
| 3646 | adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
| 3647 | adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
| 3648 | adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
| 3649 | adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
| 3650 | adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
| 3651 | adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3652 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | |
| 3655 | /* Fill out the OS statistics structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | adapter->net_stats.rx_packets = adapter->stats.gprc; |
| 3657 | adapter->net_stats.tx_packets = adapter->stats.gptc; |
| 3658 | adapter->net_stats.rx_bytes = adapter->stats.gorcl; |
| 3659 | adapter->net_stats.tx_bytes = adapter->stats.gotcl; |
| 3660 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3661 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3662 | |
| 3663 | /* Rx Errors */ |
| 3664 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3665 | /* RLEC on some newer hardware can be incorrect so build |
| 3666 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3668 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3669 | adapter->stats.ruc + adapter->stats.roc + |
| 3670 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3671 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
| 3672 | adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3674 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3676 | |
| 3677 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3678 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
| 3679 | adapter->net_stats.tx_errors = adapter->stats.txerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3681 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3682 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3683 | if (adapter->hw.bad_tx_carr_stats_fd && |
| 3684 | adapter->link_duplex == FULL_DUPLEX) { |
| 3685 | adapter->net_stats.tx_carrier_errors = 0; |
| 3686 | adapter->stats.tncrs = 0; |
| 3687 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | |
| 3689 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3690 | |
| 3691 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3692 | if (hw->media_type == e1000_media_type_copper) { |
| 3693 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3695 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3696 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3697 | } |
| 3698 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3699 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | (hw->phy_type == e1000_phy_m88) && |
| 3701 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3702 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3703 | } |
| 3704 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3705 | /* Management Stats */ |
| 3706 | if (adapter->hw.has_smbus) { |
| 3707 | adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC); |
| 3708 | adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC); |
| 3709 | adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC); |
| 3710 | } |
| 3711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3713 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3714 | |
| 3715 | /** |
| 3716 | * e1000_intr_msi - Interrupt Handler |
| 3717 | * @irq: interrupt number |
| 3718 | * @data: pointer to a network interface device structure |
| 3719 | **/ |
| 3720 | |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3721 | static irqreturn_t |
| 3722 | e1000_intr_msi(int irq, void *data) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3723 | { |
| 3724 | struct net_device *netdev = data; |
| 3725 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3726 | struct e1000_hw *hw = &adapter->hw; |
| 3727 | #ifndef CONFIG_E1000_NAPI |
| 3728 | int i; |
| 3729 | #endif |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3730 | uint32_t icr = E1000_READ_REG(hw, ICR); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3731 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3732 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3733 | /* read ICR disables interrupts using IAM, so keep up with our |
| 3734 | * enable/disable accounting */ |
| 3735 | atomic_inc(&adapter->irq_sem); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3736 | #endif |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3737 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 3738 | hw->get_link_status = 1; |
| 3739 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
| 3740 | * link down event; disable receives here in the ISR and reset |
| 3741 | * adapter in watchdog */ |
| 3742 | if (netif_carrier_ok(netdev) && |
| 3743 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3744 | /* disable receives */ |
| 3745 | uint32_t rctl = E1000_READ_REG(hw, RCTL); |
| 3746 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3747 | } |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3748 | /* guard against interrupt when we're going down */ |
| 3749 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3750 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3754 | if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3755 | adapter->total_tx_bytes = 0; |
| 3756 | adapter->total_tx_packets = 0; |
| 3757 | adapter->total_rx_bytes = 0; |
| 3758 | adapter->total_rx_packets = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3759 | __netif_rx_schedule(netdev, &adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3760 | } else |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3761 | e1000_irq_enable(adapter); |
| 3762 | #else |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3763 | adapter->total_tx_bytes = 0; |
| 3764 | adapter->total_rx_bytes = 0; |
| 3765 | adapter->total_tx_packets = 0; |
| 3766 | adapter->total_rx_packets = 0; |
| 3767 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3768 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3769 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3770 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3771 | break; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3772 | |
| 3773 | if (likely(adapter->itr_setting & 3)) |
| 3774 | e1000_set_itr(adapter); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3775 | #endif |
| 3776 | |
| 3777 | return IRQ_HANDLED; |
| 3778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | |
| 3780 | /** |
| 3781 | * e1000_intr - Interrupt Handler |
| 3782 | * @irq: interrupt number |
| 3783 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | **/ |
| 3785 | |
| 3786 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3787 | e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | { |
| 3789 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3790 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3792 | uint32_t rctl, icr = E1000_READ_REG(hw, ICR); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3793 | #ifndef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3794 | int i; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3795 | #endif |
| 3796 | if (unlikely(!icr)) |
| 3797 | return IRQ_NONE; /* Not our interrupt */ |
| 3798 | |
| 3799 | #ifdef CONFIG_E1000_NAPI |
| 3800 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 3801 | * not set, then the adapter didn't send an interrupt */ |
| 3802 | if (unlikely(hw->mac_type >= e1000_82571 && |
| 3803 | !(icr & E1000_ICR_INT_ASSERTED))) |
| 3804 | return IRQ_NONE; |
| 3805 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3806 | /* Interrupt Auto-Mask...upon reading ICR, |
| 3807 | * interrupts are masked. No need for the |
| 3808 | * IMC write, but it does mean we should |
| 3809 | * account for it ASAP. */ |
| 3810 | if (likely(hw->mac_type >= e1000_82571)) |
| 3811 | atomic_inc(&adapter->irq_sem); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 3812 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3814 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3816 | /* 80003ES2LAN workaround-- |
| 3817 | * For packet buffer work-around on link down event; |
| 3818 | * disable receives here in the ISR and |
| 3819 | * reset adapter in watchdog |
| 3820 | */ |
| 3821 | if (netif_carrier_ok(netdev) && |
| 3822 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3823 | /* disable receives */ |
| 3824 | rctl = E1000_READ_REG(hw, RCTL); |
| 3825 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3826 | } |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3827 | /* guard against interrupt when we're going down */ |
| 3828 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3829 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3833 | if (unlikely(hw->mac_type < e1000_82571)) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3834 | /* disable interrupts, without the synchronize_irq bit */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3835 | atomic_inc(&adapter->irq_sem); |
| 3836 | E1000_WRITE_REG(hw, IMC, ~0); |
| 3837 | E1000_WRITE_FLUSH(hw); |
| 3838 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3839 | if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3840 | adapter->total_tx_bytes = 0; |
| 3841 | adapter->total_tx_packets = 0; |
| 3842 | adapter->total_rx_bytes = 0; |
| 3843 | adapter->total_rx_packets = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3844 | __netif_rx_schedule(netdev, &adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3845 | } else |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3846 | /* this really should not happen! if it does it is basically a |
| 3847 | * bug, but not a hard error, so enable ints and continue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3848 | e1000_irq_enable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3849 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | /* Writing IMC and IMS is needed for 82547. |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3851 | * Due to Hub Link bus being occupied, an interrupt |
| 3852 | * de-assertion message is not able to be sent. |
| 3853 | * When an interrupt assertion message is generated later, |
| 3854 | * two messages are re-ordered and sent out. |
| 3855 | * That causes APIC to think 82547 is in de-assertion |
| 3856 | * state, while 82547 is in assertion state, resulting |
| 3857 | * in dead lock. Writing IMC forces 82547 into |
| 3858 | * de-assertion state. |
| 3859 | */ |
| 3860 | 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] | 3861 | atomic_inc(&adapter->irq_sem); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3862 | E1000_WRITE_REG(hw, IMC, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3865 | adapter->total_tx_bytes = 0; |
| 3866 | adapter->total_rx_bytes = 0; |
| 3867 | adapter->total_tx_packets = 0; |
| 3868 | adapter->total_rx_packets = 0; |
| 3869 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3870 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3871 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3872 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | break; |
| 3874 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3875 | if (likely(adapter->itr_setting & 3)) |
| 3876 | e1000_set_itr(adapter); |
| 3877 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3878 | 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] | 3879 | e1000_irq_enable(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3880 | |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3881 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | return IRQ_HANDLED; |
| 3883 | } |
| 3884 | |
| 3885 | #ifdef CONFIG_E1000_NAPI |
| 3886 | /** |
| 3887 | * e1000_clean - NAPI Rx polling callback |
| 3888 | * @adapter: board private structure |
| 3889 | **/ |
| 3890 | |
| 3891 | static int |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3892 | e1000_clean(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3894 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
| 3895 | struct net_device *poll_dev = adapter->netdev; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3896 | int tx_cleaned = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3897 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3898 | /* Must NOT use netdev_priv macro here. */ |
| 3899 | adapter = poll_dev->priv; |
| 3900 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3901 | /* e1000_clean is called per-cpu. This lock protects |
| 3902 | * tx_ring[0] from being cleaned by multiple cpus |
| 3903 | * simultaneously. A failure obtaining the lock means |
| 3904 | * tx_ring[0] is currently being cleaned anyway. */ |
| 3905 | if (spin_trylock(&adapter->tx_queue_lock)) { |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3906 | tx_cleaned = e1000_clean_tx_irq(adapter, |
| 3907 | &adapter->tx_ring[0]); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3908 | spin_unlock(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3909 | } |
| 3910 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3911 | adapter->clean_rx(adapter, &adapter->rx_ring[0], |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3912 | &work_done, budget); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3913 | |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3914 | if (tx_cleaned) |
| 3915 | work_done = budget; |
| 3916 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3917 | /* If budget not fully consumed, exit the polling mode */ |
| 3918 | if (work_done < budget) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3919 | if (likely(adapter->itr_setting & 3)) |
| 3920 | e1000_set_itr(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3921 | netif_rx_complete(poll_dev, napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3925 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | #endif |
| 3929 | /** |
| 3930 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3931 | * @adapter: board private structure |
| 3932 | **/ |
| 3933 | |
| 3934 | static boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3935 | e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3936 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | struct net_device *netdev = adapter->netdev; |
| 3939 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3940 | struct e1000_buffer *buffer_info; |
| 3941 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3942 | #ifdef CONFIG_E1000_NAPI |
| 3943 | unsigned int count = 0; |
| 3944 | #endif |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3945 | boolean_t cleaned = FALSE; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3946 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | |
| 3948 | i = tx_ring->next_to_clean; |
| 3949 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3950 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3951 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3952 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3953 | for (cleaned = FALSE; !cleaned; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3955 | buffer_info = &tx_ring->buffer_info[i]; |
| 3956 | cleaned = (i == eop); |
| 3957 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3958 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3959 | struct sk_buff *skb = buffer_info->skb; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3960 | unsigned int segs, bytecount; |
| 3961 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 3962 | /* multiply data chunks by size of headers */ |
| 3963 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 3964 | skb->len; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3965 | total_tx_packets += segs; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3966 | total_tx_bytes += bytecount; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3967 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3968 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3969 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3971 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3975 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3976 | #ifdef CONFIG_E1000_NAPI |
| 3977 | #define E1000_TX_WEIGHT 64 |
| 3978 | /* weight of a sort for tx, to avoid endless transmit cleanup */ |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3979 | if (count++ == E1000_TX_WEIGHT) break; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3980 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | tx_ring->next_to_clean = i; |
| 3984 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3985 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3986 | if (unlikely(cleaned && netif_carrier_ok(netdev) && |
| 3987 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 3988 | /* Make sure that anybody stopping the queue after this |
| 3989 | * sees the new next_to_clean. |
| 3990 | */ |
| 3991 | smp_mb(); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3992 | if (netif_queue_stopped(netdev)) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3993 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3994 | ++adapter->restart_queue; |
| 3995 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3996 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3997 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3998 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3999 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | * check with the clearing of time_stamp and movement of i */ |
| 4001 | adapter->detect_tx_hung = FALSE; |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4002 | if (tx_ring->buffer_info[eop].dma && |
| 4003 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 4004 | (adapter->tx_timeout_factor * HZ)) |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4005 | && !(E1000_READ_REG(&adapter->hw, STATUS) & |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4006 | E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4007 | |
| 4008 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 4009 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 4010 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4011 | " TDH <%x>\n" |
| 4012 | " TDT <%x>\n" |
| 4013 | " next_to_use <%x>\n" |
| 4014 | " next_to_clean <%x>\n" |
| 4015 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4016 | " time_stamp <%lx>\n" |
| 4017 | " next_to_watch <%x>\n" |
| 4018 | " jiffies <%lx>\n" |
| 4019 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 4020 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 4021 | sizeof(struct e1000_tx_ring)), |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4022 | readl(adapter->hw.hw_addr + tx_ring->tdh), |
| 4023 | readl(adapter->hw.hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4024 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4025 | tx_ring->next_to_clean, |
| 4026 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4027 | eop, |
| 4028 | jiffies, |
| 4029 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4031 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4033 | adapter->total_tx_bytes += total_tx_bytes; |
| 4034 | adapter->total_tx_packets += total_tx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | return cleaned; |
| 4036 | } |
| 4037 | |
| 4038 | /** |
| 4039 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4040 | * @adapter: board private structure |
| 4041 | * @status_err: receive descriptor status and error fields |
| 4042 | * @csum: receive descriptor csum field |
| 4043 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | **/ |
| 4045 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 4046 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | e1000_rx_checksum(struct e1000_adapter *adapter, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4048 | uint32_t status_err, uint32_t csum, |
| 4049 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4051 | uint16_t status = (uint16_t)status_err; |
| 4052 | uint8_t errors = (uint8_t)(status_err >> 24); |
| 4053 | skb->ip_summed = CHECKSUM_NONE; |
| 4054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | /* 82543 or newer only */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4056 | if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4058 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4059 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4060 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4061 | /* let the stack verify checksum errors */ |
| 4062 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | return; |
| 4064 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4065 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4066 | if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
| 4067 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4068 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4070 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4071 | return; |
| 4072 | } |
| 4073 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4074 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4075 | /* TCP checksum is good */ |
| 4076 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4077 | } else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
| 4078 | /* IP fragment with UDP payload */ |
| 4079 | /* Hardware complements the payload checksum, so we undo it |
| 4080 | * and then put the value in host order for further stack use. |
| 4081 | */ |
| 4082 | csum = ntohl(csum ^ 0xFFFF); |
| 4083 | skb->csum = csum; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 4084 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4086 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4090 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | * @adapter: board private structure |
| 4092 | **/ |
| 4093 | |
| 4094 | static boolean_t |
| 4095 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4096 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4097 | struct e1000_rx_ring *rx_ring, |
| 4098 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4100 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4101 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | #endif |
| 4103 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | struct net_device *netdev = adapter->netdev; |
| 4105 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4106 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4107 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | unsigned long flags; |
| 4109 | uint32_t length; |
| 4110 | uint8_t last_byte; |
| 4111 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4112 | int cleaned_count = 0; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4113 | boolean_t cleaned = FALSE; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4114 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | |
| 4116 | i = rx_ring->next_to_clean; |
| 4117 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4118 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4120 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4121 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4122 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4125 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | break; |
| 4127 | (*work_done)++; |
| 4128 | #endif |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4129 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4130 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4131 | buffer_info->skb = NULL; |
| 4132 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4133 | prefetch(skb->data - NET_IP_ALIGN); |
| 4134 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4135 | if (++i == rx_ring->count) i = 0; |
| 4136 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4137 | prefetch(next_rxd); |
| 4138 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4139 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4140 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4141 | cleaned = TRUE; |
| 4142 | cleaned_count++; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4143 | pci_unmap_single(pdev, |
| 4144 | buffer_info->dma, |
| 4145 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | PCI_DMA_FROMDEVICE); |
| 4147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | length = le16_to_cpu(rx_desc->length); |
| 4149 | |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4150 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
| 4151 | /* All receives must fit into a single buffer */ |
| 4152 | E1000_DBG("%s: Receive packet consumed multiple" |
| 4153 | " buffers\n", netdev->name); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 4154 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4155 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | goto next_desc; |
| 4157 | } |
| 4158 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4159 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | last_byte = *(skb->data + length - 1); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4161 | if (TBI_ACCEPT(&adapter->hw, status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | rx_desc->errors, length, last_byte)) { |
| 4163 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4164 | e1000_tbi_adjust_stats(&adapter->hw, |
| 4165 | &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | length, skb->data); |
| 4167 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4168 | flags); |
| 4169 | length--; |
| 4170 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4171 | /* recycle */ |
| 4172 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | goto next_desc; |
| 4174 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4177 | /* adjust length to remove Ethernet CRC, this must be |
| 4178 | * done after the TBI_ACCEPT workaround above */ |
| 4179 | length -= 4; |
| 4180 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4181 | /* probably a little skewed due to removing CRC */ |
| 4182 | total_rx_bytes += length; |
| 4183 | total_rx_packets++; |
| 4184 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4185 | /* code added for copybreak, this should improve |
| 4186 | * performance for small packets with large amounts |
| 4187 | * of reassembly being done in the stack */ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4188 | if (length < copybreak) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4189 | struct sk_buff *new_skb = |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4190 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4191 | if (new_skb) { |
| 4192 | skb_reserve(new_skb, NET_IP_ALIGN); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 4193 | skb_copy_to_linear_data_offset(new_skb, |
| 4194 | -NET_IP_ALIGN, |
| 4195 | (skb->data - |
| 4196 | NET_IP_ALIGN), |
| 4197 | (length + |
| 4198 | NET_IP_ALIGN)); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4199 | /* save the skb in buffer_info as good */ |
| 4200 | buffer_info->skb = skb; |
| 4201 | skb = new_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4202 | } |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4203 | /* else just continue with the old one */ |
| 4204 | } |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4205 | /* end copybreak code */ |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4206 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | |
| 4208 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4209 | e1000_rx_checksum(adapter, |
| 4210 | (uint32_t)(status) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4211 | ((uint32_t)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4212 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | skb->protocol = eth_type_trans(skb, netdev); |
| 4215 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4216 | if (unlikely(adapter->vlgrp && |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4217 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4219 | le16_to_cpu(rx_desc->special) & |
| 4220 | E1000_RXD_SPC_VLAN_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | } else { |
| 4222 | netif_receive_skb(skb); |
| 4223 | } |
| 4224 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4225 | if (unlikely(adapter->vlgrp && |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4226 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 4228 | le16_to_cpu(rx_desc->special) & |
| 4229 | E1000_RXD_SPC_VLAN_MASK); |
| 4230 | } else { |
| 4231 | netif_rx(skb); |
| 4232 | } |
| 4233 | #endif /* CONFIG_E1000_NAPI */ |
| 4234 | netdev->last_rx = jiffies; |
| 4235 | |
| 4236 | next_desc: |
| 4237 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4239 | /* return some buffers to hardware, one at a time is too slow */ |
| 4240 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4241 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4242 | cleaned_count = 0; |
| 4243 | } |
| 4244 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4245 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4246 | rx_desc = next_rxd; |
| 4247 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4250 | |
| 4251 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4252 | if (cleaned_count) |
| 4253 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4255 | adapter->total_rx_packets += total_rx_packets; |
| 4256 | adapter->total_rx_bytes += total_rx_bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4257 | return cleaned; |
| 4258 | } |
| 4259 | |
| 4260 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4261 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 4262 | * @adapter: board private structure |
| 4263 | **/ |
| 4264 | |
| 4265 | static boolean_t |
| 4266 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4267 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4268 | struct e1000_rx_ring *rx_ring, |
| 4269 | int *work_done, int work_to_do) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4270 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4271 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4272 | struct e1000_rx_ring *rx_ring) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4273 | #endif |
| 4274 | { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4275 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4276 | struct net_device *netdev = adapter->netdev; |
| 4277 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4278 | struct e1000_buffer *buffer_info, *next_buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4279 | struct e1000_ps_page *ps_page; |
| 4280 | struct e1000_ps_page_dma *ps_page_dma; |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4281 | struct sk_buff *skb; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4282 | unsigned int i, j; |
| 4283 | uint32_t length, staterr; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4284 | int cleaned_count = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4285 | boolean_t cleaned = FALSE; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4286 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4287 | |
| 4288 | i = rx_ring->next_to_clean; |
| 4289 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4290 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4291 | buffer_info = &rx_ring->buffer_info[i]; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4292 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4293 | while (staterr & E1000_RXD_STAT_DD) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4294 | ps_page = &rx_ring->ps_page[i]; |
| 4295 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4296 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4297 | if (unlikely(*work_done >= work_to_do)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4298 | break; |
| 4299 | (*work_done)++; |
| 4300 | #endif |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4301 | skb = buffer_info->skb; |
| 4302 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4303 | /* in the packet split case this is header only */ |
| 4304 | prefetch(skb->data - NET_IP_ALIGN); |
| 4305 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4306 | if (++i == rx_ring->count) i = 0; |
| 4307 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4308 | prefetch(next_rxd); |
| 4309 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4310 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4311 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4312 | cleaned = TRUE; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4313 | cleaned_count++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4314 | pci_unmap_single(pdev, buffer_info->dma, |
| 4315 | buffer_info->length, |
| 4316 | PCI_DMA_FROMDEVICE); |
| 4317 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4318 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4319 | E1000_DBG("%s: Packet Split buffers didn't pick up" |
| 4320 | " the full packet\n", netdev->name); |
| 4321 | dev_kfree_skb_irq(skb); |
| 4322 | goto next_desc; |
| 4323 | } |
| 4324 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4325 | if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4326 | dev_kfree_skb_irq(skb); |
| 4327 | goto next_desc; |
| 4328 | } |
| 4329 | |
| 4330 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 4331 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4332 | if (unlikely(!length)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4333 | E1000_DBG("%s: Last part of the packet spanning" |
| 4334 | " multiple descriptors\n", netdev->name); |
| 4335 | dev_kfree_skb_irq(skb); |
| 4336 | goto next_desc; |
| 4337 | } |
| 4338 | |
| 4339 | /* Good Receive */ |
| 4340 | skb_put(skb, length); |
| 4341 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4342 | { |
| 4343 | /* this looks ugly, but it seems compiler issues make it |
| 4344 | more efficient than reusing j */ |
| 4345 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 4346 | |
| 4347 | /* page alloc/put takes too long and effects small packet |
| 4348 | * throughput, so unsplit small packets and save the alloc/put*/ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4349 | if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) { |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4350 | u8 *vaddr; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 4351 | /* there is no documentation about how to call |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4352 | * kmap_atomic, so we can't hold the mapping |
| 4353 | * very long */ |
| 4354 | pci_dma_sync_single_for_cpu(pdev, |
| 4355 | ps_page_dma->ps_page_dma[0], |
| 4356 | PAGE_SIZE, |
| 4357 | PCI_DMA_FROMDEVICE); |
| 4358 | vaddr = kmap_atomic(ps_page->ps_page[0], |
| 4359 | KM_SKB_DATA_SOFTIRQ); |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 4360 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4361 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 4362 | pci_dma_sync_single_for_device(pdev, |
| 4363 | ps_page_dma->ps_page_dma[0], |
| 4364 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4365 | /* remove the CRC */ |
| 4366 | l1 -= 4; |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4367 | skb_put(skb, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4368 | goto copydone; |
| 4369 | } /* if */ |
| 4370 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4371 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4372 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4373 | if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4374 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4375 | pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
| 4376 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 4377 | ps_page_dma->ps_page_dma[j] = 0; |
Jeff Kirsher | 329bfd0 | 2006-03-02 18:20:02 -0800 | [diff] [blame] | 4378 | skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
| 4379 | length); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4380 | ps_page->ps_page[j] = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4381 | skb->len += length; |
| 4382 | skb->data_len += length; |
Auke Kok | 5d51b80 | 2006-04-14 19:05:06 -0700 | [diff] [blame] | 4383 | skb->truesize += length; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4386 | /* strip the ethernet crc, problem is we're using pages now so |
| 4387 | * this whole operation can get a little cpu intensive */ |
| 4388 | pskb_trim(skb, skb->len - 4); |
| 4389 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4390 | copydone: |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4391 | total_rx_bytes += skb->len; |
| 4392 | total_rx_packets++; |
| 4393 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4394 | e1000_rx_checksum(adapter, staterr, |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4395 | 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] | 4396 | skb->protocol = eth_type_trans(skb, netdev); |
| 4397 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4398 | if (likely(rx_desc->wb.upper.header_status & |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4399 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4400 | adapter->rx_hdr_split++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4401 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4402 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4403 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4404 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4405 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4406 | } else { |
| 4407 | netif_receive_skb(skb); |
| 4408 | } |
| 4409 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4410 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4411 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4412 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4413 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4414 | } else { |
| 4415 | netif_rx(skb); |
| 4416 | } |
| 4417 | #endif /* CONFIG_E1000_NAPI */ |
| 4418 | netdev->last_rx = jiffies; |
| 4419 | |
| 4420 | next_desc: |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4421 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4422 | buffer_info->skb = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4423 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4424 | /* return some buffers to hardware, one at a time is too slow */ |
| 4425 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4426 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4427 | cleaned_count = 0; |
| 4428 | } |
| 4429 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4430 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4431 | rx_desc = next_rxd; |
| 4432 | buffer_info = next_buffer; |
| 4433 | |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4434 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4435 | } |
| 4436 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4437 | |
| 4438 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4439 | if (cleaned_count) |
| 4440 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4441 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4442 | adapter->total_rx_packets += total_rx_packets; |
| 4443 | adapter->total_rx_bytes += total_rx_bytes; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4444 | return cleaned; |
| 4445 | } |
| 4446 | |
| 4447 | /** |
| 4448 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | * @adapter: address of board private structure |
| 4450 | **/ |
| 4451 | |
| 4452 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4453 | e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4454 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4455 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | struct net_device *netdev = adapter->netdev; |
| 4458 | struct pci_dev *pdev = adapter->pdev; |
| 4459 | struct e1000_rx_desc *rx_desc; |
| 4460 | struct e1000_buffer *buffer_info; |
| 4461 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4462 | unsigned int i; |
| 4463 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | |
| 4465 | i = rx_ring->next_to_use; |
| 4466 | buffer_info = &rx_ring->buffer_info[i]; |
| 4467 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4468 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4469 | skb = buffer_info->skb; |
| 4470 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4471 | skb_trim(skb, 0); |
| 4472 | goto map_skb; |
| 4473 | } |
| 4474 | |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4475 | skb = netdev_alloc_skb(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4476 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4478 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | break; |
| 4480 | } |
| 4481 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4482 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4484 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4485 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 4486 | "at %p\n", bufsz, skb->data); |
| 4487 | /* Try again, without freeing the previous */ |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4488 | skb = netdev_alloc_skb(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4489 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | if (!skb) { |
| 4491 | dev_kfree_skb(oldskb); |
| 4492 | break; |
| 4493 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4496 | /* give up */ |
| 4497 | dev_kfree_skb(skb); |
| 4498 | dev_kfree_skb(oldskb); |
| 4499 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4501 | |
| 4502 | /* Use new allocation */ |
| 4503 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4506 | * this will result in a 16 byte aligned IP header after |
| 4507 | * the 14 byte MAC header is removed |
| 4508 | */ |
| 4509 | skb_reserve(skb, NET_IP_ALIGN); |
| 4510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | buffer_info->skb = skb; |
| 4512 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4513 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | buffer_info->dma = pci_map_single(pdev, |
| 4515 | skb->data, |
| 4516 | adapter->rx_buffer_len, |
| 4517 | PCI_DMA_FROMDEVICE); |
| 4518 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4519 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4520 | if (!e1000_check_64k_bound(adapter, |
| 4521 | (void *)(unsigned long)buffer_info->dma, |
| 4522 | adapter->rx_buffer_len)) { |
| 4523 | DPRINTK(RX_ERR, ERR, |
| 4524 | "dma align check failed: %u bytes at %p\n", |
| 4525 | adapter->rx_buffer_len, |
| 4526 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | dev_kfree_skb(skb); |
| 4528 | buffer_info->skb = NULL; |
| 4529 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4530 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | adapter->rx_buffer_len, |
| 4532 | PCI_DMA_FROMDEVICE); |
| 4533 | |
| 4534 | break; /* while !buffer_info->skb */ |
| 4535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4537 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4538 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4539 | if (unlikely(++i == rx_ring->count)) |
| 4540 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | buffer_info = &rx_ring->buffer_info[i]; |
| 4542 | } |
| 4543 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4544 | if (likely(rx_ring->next_to_use != i)) { |
| 4545 | rx_ring->next_to_use = i; |
| 4546 | if (unlikely(i-- == 0)) |
| 4547 | i = (rx_ring->count - 1); |
| 4548 | |
| 4549 | /* Force memory writes to complete before letting h/w |
| 4550 | * know there are new descriptors to fetch. (Only |
| 4551 | * applicable for weak-ordered memory model archs, |
| 4552 | * such as IA-64). */ |
| 4553 | wmb(); |
| 4554 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4559 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 4560 | * @adapter: address of board private structure |
| 4561 | **/ |
| 4562 | |
| 4563 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4564 | e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4565 | struct e1000_rx_ring *rx_ring, |
| 4566 | int cleaned_count) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4567 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4568 | struct net_device *netdev = adapter->netdev; |
| 4569 | struct pci_dev *pdev = adapter->pdev; |
| 4570 | union e1000_rx_desc_packet_split *rx_desc; |
| 4571 | struct e1000_buffer *buffer_info; |
| 4572 | struct e1000_ps_page *ps_page; |
| 4573 | struct e1000_ps_page_dma *ps_page_dma; |
| 4574 | struct sk_buff *skb; |
| 4575 | unsigned int i, j; |
| 4576 | |
| 4577 | i = rx_ring->next_to_use; |
| 4578 | buffer_info = &rx_ring->buffer_info[i]; |
| 4579 | ps_page = &rx_ring->ps_page[i]; |
| 4580 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4581 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4582 | while (cleaned_count--) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4583 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 4584 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4585 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4586 | if (j < adapter->rx_ps_pages) { |
| 4587 | if (likely(!ps_page->ps_page[j])) { |
| 4588 | ps_page->ps_page[j] = |
| 4589 | alloc_page(GFP_ATOMIC); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4590 | if (unlikely(!ps_page->ps_page[j])) { |
| 4591 | adapter->alloc_rx_buff_failed++; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4592 | goto no_buffers; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4593 | } |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4594 | ps_page_dma->ps_page_dma[j] = |
| 4595 | pci_map_page(pdev, |
| 4596 | ps_page->ps_page[j], |
| 4597 | 0, PAGE_SIZE, |
| 4598 | PCI_DMA_FROMDEVICE); |
| 4599 | } |
| 4600 | /* Refresh the desc even if buffer_addrs didn't |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4601 | * change because each write-back erases |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4602 | * this info. |
| 4603 | */ |
| 4604 | rx_desc->read.buffer_addr[j+1] = |
| 4605 | cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
| 4606 | } else |
| 4607 | rx_desc->read.buffer_addr[j+1] = ~0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4610 | skb = netdev_alloc_skb(netdev, |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4611 | adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4612 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4613 | if (unlikely(!skb)) { |
| 4614 | adapter->alloc_rx_buff_failed++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4615 | break; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4616 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4617 | |
| 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 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4624 | buffer_info->skb = skb; |
| 4625 | buffer_info->length = adapter->rx_ps_bsize0; |
| 4626 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4627 | adapter->rx_ps_bsize0, |
| 4628 | PCI_DMA_FROMDEVICE); |
| 4629 | |
| 4630 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 4631 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4632 | if (unlikely(++i == rx_ring->count)) i = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4633 | buffer_info = &rx_ring->buffer_info[i]; |
| 4634 | ps_page = &rx_ring->ps_page[i]; |
| 4635 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4636 | } |
| 4637 | |
| 4638 | no_buffers: |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4639 | if (likely(rx_ring->next_to_use != i)) { |
| 4640 | rx_ring->next_to_use = i; |
| 4641 | if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
| 4642 | |
| 4643 | /* Force memory writes to complete before letting h/w |
| 4644 | * know there are new descriptors to fetch. (Only |
| 4645 | * applicable for weak-ordered memory model archs, |
| 4646 | * such as IA-64). */ |
| 4647 | wmb(); |
| 4648 | /* Hardware increments by 16 bytes, but packet split |
| 4649 | * descriptors are 32 bytes...so we increment tail |
| 4650 | * twice as much. |
| 4651 | */ |
| 4652 | writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
| 4653 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4658 | * @adapter: |
| 4659 | **/ |
| 4660 | |
| 4661 | static void |
| 4662 | e1000_smartspeed(struct e1000_adapter *adapter) |
| 4663 | { |
| 4664 | uint16_t phy_status; |
| 4665 | uint16_t phy_ctrl; |
| 4666 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4667 | if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4668 | !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
| 4669 | return; |
| 4670 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4671 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | /* If Master/Slave config fault is asserted twice, |
| 4673 | * we assume back-to-back */ |
| 4674 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4675 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4677 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4679 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
| 4681 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
| 4682 | phy_ctrl); |
| 4683 | adapter->smartspeed++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4684 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4685 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
| 4686 | &phy_ctrl)) { |
| 4687 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4688 | MII_CR_RESTART_AUTO_NEG); |
| 4689 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
| 4690 | phy_ctrl); |
| 4691 | } |
| 4692 | } |
| 4693 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4694 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | /* If still no link, perhaps using 2/3 pair cable */ |
| 4696 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
| 4697 | phy_ctrl |= CR_1000T_MS_ENABLE; |
| 4698 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4699 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
| 4701 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4702 | MII_CR_RESTART_AUTO_NEG); |
| 4703 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
| 4704 | } |
| 4705 | } |
| 4706 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4707 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | adapter->smartspeed = 0; |
| 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * e1000_ioctl - |
| 4713 | * @netdev: |
| 4714 | * @ifreq: |
| 4715 | * @cmd: |
| 4716 | **/ |
| 4717 | |
| 4718 | static int |
| 4719 | e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4720 | { |
| 4721 | switch (cmd) { |
| 4722 | case SIOCGMIIPHY: |
| 4723 | case SIOCGMIIREG: |
| 4724 | case SIOCSMIIREG: |
| 4725 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4726 | default: |
| 4727 | return -EOPNOTSUPP; |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | /** |
| 4732 | * e1000_mii_ioctl - |
| 4733 | * @netdev: |
| 4734 | * @ifreq: |
| 4735 | * @cmd: |
| 4736 | **/ |
| 4737 | |
| 4738 | static int |
| 4739 | e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4740 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4741 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4743 | int retval; |
| 4744 | uint16_t mii_reg; |
| 4745 | uint16_t spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4746 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4748 | if (adapter->hw.media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | return -EOPNOTSUPP; |
| 4750 | |
| 4751 | switch (cmd) { |
| 4752 | case SIOCGMIIPHY: |
| 4753 | data->phy_id = adapter->hw.phy_addr; |
| 4754 | break; |
| 4755 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4756 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4758 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4759 | if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4760 | &data->val_out)) { |
| 4761 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4763 | } |
| 4764 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | break; |
| 4766 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4767 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4769 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4770 | return -EFAULT; |
| 4771 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4772 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4773 | if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4774 | mii_reg)) { |
| 4775 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4777 | } |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4778 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Auke Kok | dc86d32 | 2006-04-18 12:30:51 -0700 | [diff] [blame] | 4779 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | switch (data->reg_num) { |
| 4781 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4782 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4784 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | adapter->hw.autoneg = 1; |
| 4786 | adapter->hw.autoneg_advertised = 0x2F; |
| 4787 | } else { |
| 4788 | if (mii_reg & 0x40) |
| 4789 | spddplx = SPEED_1000; |
| 4790 | else if (mii_reg & 0x2000) |
| 4791 | spddplx = SPEED_100; |
| 4792 | else |
| 4793 | spddplx = SPEED_10; |
| 4794 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4795 | ? DUPLEX_FULL : |
| 4796 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | retval = e1000_set_spd_dplx(adapter, |
| 4798 | spddplx); |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4799 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | return retval; |
| 4801 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4802 | if (netif_running(adapter->netdev)) |
| 4803 | e1000_reinit_locked(adapter); |
| 4804 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4805 | e1000_reset(adapter); |
| 4806 | break; |
| 4807 | case M88E1000_PHY_SPEC_CTRL: |
| 4808 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4809 | if (e1000_phy_reset(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | return -EIO; |
| 4811 | break; |
| 4812 | } |
| 4813 | } else { |
| 4814 | switch (data->reg_num) { |
| 4815 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4816 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4818 | if (netif_running(adapter->netdev)) |
| 4819 | e1000_reinit_locked(adapter); |
| 4820 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | e1000_reset(adapter); |
| 4822 | break; |
| 4823 | } |
| 4824 | } |
| 4825 | break; |
| 4826 | default: |
| 4827 | return -EOPNOTSUPP; |
| 4828 | } |
| 4829 | return E1000_SUCCESS; |
| 4830 | } |
| 4831 | |
| 4832 | void |
| 4833 | e1000_pci_set_mwi(struct e1000_hw *hw) |
| 4834 | { |
| 4835 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4836 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4838 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4839 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | void |
| 4843 | e1000_pci_clear_mwi(struct e1000_hw *hw) |
| 4844 | { |
| 4845 | struct e1000_adapter *adapter = hw->back; |
| 4846 | |
| 4847 | pci_clear_mwi(adapter->pdev); |
| 4848 | } |
| 4849 | |
| 4850 | void |
| 4851 | e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4852 | { |
| 4853 | struct e1000_adapter *adapter = hw->back; |
| 4854 | |
| 4855 | pci_read_config_word(adapter->pdev, reg, value); |
| 4856 | } |
| 4857 | |
| 4858 | void |
| 4859 | e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4860 | { |
| 4861 | struct e1000_adapter *adapter = hw->back; |
| 4862 | |
| 4863 | pci_write_config_word(adapter->pdev, reg, *value); |
| 4864 | } |
| 4865 | |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4866 | int |
| 4867 | e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
| 4868 | { |
| 4869 | struct e1000_adapter *adapter = hw->back; |
| 4870 | return pcix_get_mmrbc(adapter->pdev); |
| 4871 | } |
| 4872 | |
| 4873 | void |
| 4874 | e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
| 4875 | { |
| 4876 | struct e1000_adapter *adapter = hw->back; |
| 4877 | pcix_set_mmrbc(adapter->pdev, mmrbc); |
| 4878 | } |
| 4879 | |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4880 | int32_t |
| 4881 | e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4882 | { |
| 4883 | struct e1000_adapter *adapter = hw->back; |
| 4884 | uint16_t cap_offset; |
| 4885 | |
| 4886 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 4887 | if (!cap_offset) |
| 4888 | return -E1000_ERR_CONFIG; |
| 4889 | |
| 4890 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 4891 | |
| 4892 | return E1000_SUCCESS; |
| 4893 | } |
| 4894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4895 | void |
| 4896 | e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) |
| 4897 | { |
| 4898 | outl(value, port); |
| 4899 | } |
| 4900 | |
| 4901 | static void |
| 4902 | e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 4903 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4904 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | uint32_t ctrl, rctl; |
| 4906 | |
| 4907 | e1000_irq_disable(adapter); |
| 4908 | adapter->vlgrp = grp; |
| 4909 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4910 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | /* enable VLAN tag insert/strip */ |
| 4912 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4913 | ctrl |= E1000_CTRL_VME; |
| 4914 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4915 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4916 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4917 | /* enable VLAN receive filtering */ |
| 4918 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4919 | rctl |= E1000_RCTL_VFE; |
| 4920 | rctl &= ~E1000_RCTL_CFIEN; |
| 4921 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4922 | e1000_update_mng_vlan(adapter); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4923 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | } else { |
| 4925 | /* disable VLAN tag insert/strip */ |
| 4926 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4927 | ctrl &= ~E1000_CTRL_VME; |
| 4928 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4929 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4930 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4931 | /* disable VLAN filtering */ |
| 4932 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4933 | rctl &= ~E1000_RCTL_VFE; |
| 4934 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4935 | if (adapter->mng_vlan_id != |
| 4936 | (uint16_t)E1000_MNG_VLAN_NONE) { |
| 4937 | e1000_vlan_rx_kill_vid(netdev, |
| 4938 | adapter->mng_vlan_id); |
| 4939 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4940 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4941 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | e1000_irq_enable(adapter); |
| 4945 | } |
| 4946 | |
| 4947 | static void |
| 4948 | e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
| 4949 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4950 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | uint32_t vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4952 | |
| 4953 | if ((adapter->hw.mng_cookie.status & |
| 4954 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4955 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4956 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | /* add VID to filter table */ |
| 4958 | index = (vid >> 5) & 0x7F; |
| 4959 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4960 | vfta |= (1 << (vid & 0x1F)); |
| 4961 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4962 | } |
| 4963 | |
| 4964 | static void |
| 4965 | e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
| 4966 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4967 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | uint32_t vfta, index; |
| 4969 | |
| 4970 | e1000_irq_disable(adapter); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4971 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | e1000_irq_enable(adapter); |
| 4973 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4974 | if ((adapter->hw.mng_cookie.status & |
| 4975 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4976 | (vid == adapter->mng_vlan_id)) { |
| 4977 | /* release control to f/w */ |
| 4978 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4979 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4980 | } |
| 4981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | /* remove VID from filter table */ |
| 4983 | index = (vid >> 5) & 0x7F; |
| 4984 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4985 | vfta &= ~(1 << (vid & 0x1F)); |
| 4986 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4987 | } |
| 4988 | |
| 4989 | static void |
| 4990 | e1000_restore_vlan(struct e1000_adapter *adapter) |
| 4991 | { |
| 4992 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4993 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4994 | if (adapter->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | uint16_t vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4996 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4997 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | continue; |
| 4999 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 5000 | } |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | int |
| 5005 | e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) |
| 5006 | { |
| 5007 | adapter->hw.autoneg = 0; |
| 5008 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 5009 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5010 | if ((adapter->hw.media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 5011 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 5012 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 5013 | return -EINVAL; |
| 5014 | } |
| 5015 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5016 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | case SPEED_10 + DUPLEX_HALF: |
| 5018 | adapter->hw.forced_speed_duplex = e1000_10_half; |
| 5019 | break; |
| 5020 | case SPEED_10 + DUPLEX_FULL: |
| 5021 | adapter->hw.forced_speed_duplex = e1000_10_full; |
| 5022 | break; |
| 5023 | case SPEED_100 + DUPLEX_HALF: |
| 5024 | adapter->hw.forced_speed_duplex = e1000_100_half; |
| 5025 | break; |
| 5026 | case SPEED_100 + DUPLEX_FULL: |
| 5027 | adapter->hw.forced_speed_duplex = e1000_100_full; |
| 5028 | break; |
| 5029 | case SPEED_1000 + DUPLEX_FULL: |
| 5030 | adapter->hw.autoneg = 1; |
| 5031 | adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
| 5032 | break; |
| 5033 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 5034 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5035 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | return -EINVAL; |
| 5037 | } |
| 5038 | return 0; |
| 5039 | } |
| 5040 | |
| 5041 | static int |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 5042 | e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | { |
| 5044 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5045 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5046 | uint32_t ctrl, ctrl_ext, rctl, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | uint32_t wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5048 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5049 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5050 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | |
| 5052 | netif_device_detach(netdev); |
| 5053 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5054 | if (netif_running(netdev)) { |
| 5055 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5057 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5059 | #ifdef CONFIG_PM |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5060 | retval = pci_save_state(pdev); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5061 | if (retval) |
| 5062 | return retval; |
| 5063 | #endif |
| 5064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | status = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5066 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | wufc &= ~E1000_WUFC_LNKC; |
| 5068 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5069 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | e1000_setup_rctl(adapter); |
| 5071 | e1000_set_multi(netdev); |
| 5072 | |
| 5073 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 5074 | if (wufc & E1000_WUFC_MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5075 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 5076 | rctl |= E1000_RCTL_MPE; |
| 5077 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 5078 | } |
| 5079 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5080 | if (adapter->hw.mac_type >= e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5081 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 5082 | /* advertise wake from D3Cold */ |
| 5083 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5084 | /* phy power management enable */ |
| 5085 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5086 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 5087 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 5088 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 5089 | } |
| 5090 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5091 | if (adapter->hw.media_type == e1000_media_type_fiber || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 5093 | /* keep the laser running in D3 */ |
| 5094 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 5095 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 5096 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
| 5097 | } |
| 5098 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5099 | /* Allow time for pending master requests to run */ |
| 5100 | e1000_disable_pciex_master(&adapter->hw); |
| 5101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
| 5103 | E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5104 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5105 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | } else { |
| 5107 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
| 5108 | E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5109 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5110 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | } |
| 5112 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5113 | e1000_release_manageability(adapter); |
| 5114 | |
| 5115 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 5116 | if (adapter->en_mng_pt) { |
| 5117 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5118 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5121 | if (adapter->hw.phy_type == e1000_phy_igp_3) |
| 5122 | e1000_phy_powerdown_workaround(&adapter->hw); |
| 5123 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5124 | if (netif_running(netdev)) |
| 5125 | e1000_free_irq(adapter); |
| 5126 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5127 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5128 | * would have already happened in close and is redundant. */ |
| 5129 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5132 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5133 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | |
| 5135 | return 0; |
| 5136 | } |
| 5137 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5138 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5139 | static int |
| 5140 | e1000_resume(struct pci_dev *pdev) |
| 5141 | { |
| 5142 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5143 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5144 | uint32_t err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5146 | pci_set_power_state(pdev, PCI_D0); |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5147 | pci_restore_state(pdev); |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 5148 | if ((err = pci_enable_device(pdev))) { |
| 5149 | printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
| 5150 | return err; |
| 5151 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 5152 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5154 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5155 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5157 | if (netif_running(netdev) && (err = e1000_request_irq(adapter))) |
| 5158 | return err; |
| 5159 | |
| 5160 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | e1000_reset(adapter); |
| 5162 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5163 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5164 | e1000_init_manageability(adapter); |
| 5165 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5166 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | e1000_up(adapter); |
| 5168 | |
| 5169 | netif_device_attach(netdev); |
| 5170 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5171 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5172 | * DRV_LOAD until the interface is up. For all other cases, |
| 5173 | * let the f/w know that the h/w is now under the control |
| 5174 | * of the driver. */ |
| 5175 | if (adapter->hw.mac_type != e1000_82573 || |
| 5176 | !e1000_check_mng_mode(&adapter->hw)) |
| 5177 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | return 0; |
| 5180 | } |
| 5181 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5182 | |
| 5183 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5184 | { |
| 5185 | e1000_suspend(pdev, PMSG_SUSPEND); |
| 5186 | } |
| 5187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5189 | /* |
| 5190 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5191 | * without having to re-enable interrupts. It's not called while |
| 5192 | * the interrupt routine is executing. |
| 5193 | */ |
| 5194 | static void |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5195 | e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5197 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 5198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5200 | e1000_intr(adapter->pdev->irq, netdev); |
Andrew Morton | c4cfe56 | 2005-10-15 00:32:29 -0700 | [diff] [blame] | 5201 | e1000_clean_tx_irq(adapter, adapter->tx_ring); |
Jeff Kirsher | e8da8be | 2006-01-12 16:51:14 -0800 | [diff] [blame] | 5202 | #ifndef CONFIG_E1000_NAPI |
| 5203 | adapter->clean_rx(adapter, adapter->rx_ring); |
| 5204 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | enable_irq(adapter->pdev->irq); |
| 5206 | } |
| 5207 | #endif |
| 5208 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5209 | /** |
| 5210 | * e1000_io_error_detected - called when PCI error is detected |
| 5211 | * @pdev: Pointer to PCI device |
| 5212 | * @state: The current pci conneection state |
| 5213 | * |
| 5214 | * This function is called after a PCI bus error affecting |
| 5215 | * this device has been detected. |
| 5216 | */ |
| 5217 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 5218 | { |
| 5219 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5220 | struct e1000_adapter *adapter = netdev->priv; |
| 5221 | |
| 5222 | netif_device_detach(netdev); |
| 5223 | |
| 5224 | if (netif_running(netdev)) |
| 5225 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 5226 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5227 | |
| 5228 | /* Request a slot slot reset. */ |
| 5229 | return PCI_ERS_RESULT_NEED_RESET; |
| 5230 | } |
| 5231 | |
| 5232 | /** |
| 5233 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5234 | * @pdev: Pointer to PCI device |
| 5235 | * |
| 5236 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5237 | * resembles the first-half of the e1000_resume routine. |
| 5238 | */ |
| 5239 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5240 | { |
| 5241 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5242 | struct e1000_adapter *adapter = netdev->priv; |
| 5243 | |
| 5244 | if (pci_enable_device(pdev)) { |
| 5245 | printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
| 5246 | return PCI_ERS_RESULT_DISCONNECT; |
| 5247 | } |
| 5248 | pci_set_master(pdev); |
| 5249 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 5250 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5251 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5252 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5253 | e1000_reset(adapter); |
| 5254 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5255 | |
| 5256 | return PCI_ERS_RESULT_RECOVERED; |
| 5257 | } |
| 5258 | |
| 5259 | /** |
| 5260 | * e1000_io_resume - called when traffic can start flowing again. |
| 5261 | * @pdev: Pointer to PCI device |
| 5262 | * |
| 5263 | * This callback is called when the error recovery driver tells us that |
| 5264 | * its OK to resume normal operation. Implementation resembles the |
| 5265 | * second-half of the e1000_resume routine. |
| 5266 | */ |
| 5267 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5268 | { |
| 5269 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5270 | struct e1000_adapter *adapter = netdev->priv; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5271 | |
| 5272 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5273 | |
| 5274 | if (netif_running(netdev)) { |
| 5275 | if (e1000_up(adapter)) { |
| 5276 | printk("e1000: can't bring device back up after reset\n"); |
| 5277 | return; |
| 5278 | } |
| 5279 | } |
| 5280 | |
| 5281 | netif_device_attach(netdev); |
| 5282 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5283 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5284 | * DRV_LOAD until the interface is up. For all other cases, |
| 5285 | * let the f/w know that the h/w is now under the control |
| 5286 | * of the driver. */ |
| 5287 | if (adapter->hw.mac_type != e1000_82573 || |
| 5288 | !e1000_check_mng_mode(&adapter->hw)) |
| 5289 | e1000_get_hw_control(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5290 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | /* e1000_main.c */ |