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); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 97 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 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); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 129 | static void e1000_set_rx_mode(struct net_device *netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 139 | static bool 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); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 143 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 144 | struct e1000_rx_ring *rx_ring, |
| 145 | int *work_done, int work_to_do); |
| 146 | static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 147 | struct e1000_rx_ring *rx_ring, |
| 148 | int *work_done, int work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #else |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 150 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 151 | struct e1000_rx_ring *rx_ring); |
| 152 | static bool 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); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 173 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); |
| 174 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 275 | irq_handler_t handler = e1000_intr; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 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) { |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 282 | handler = e1000_intr_msi; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 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 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | E1000_WRITE_REG(&adapter->hw, IMC, ~0); |
| 318 | E1000_WRITE_FLUSH(&adapter->hw); |
| 319 | synchronize_irq(adapter->pdev->irq); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * e1000_irq_enable - Enable default interrupt generation settings |
| 324 | * @adapter: board private structure |
| 325 | **/ |
| 326 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 327 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | e1000_irq_enable(struct e1000_adapter *adapter) |
| 329 | { |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 330 | E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); |
| 331 | E1000_WRITE_FLUSH(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 333 | |
| 334 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 335 | e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 336 | { |
| 337 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 338 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 339 | u16 old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 340 | if (adapter->vlgrp) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 341 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 342 | if (adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 343 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 344 | e1000_vlan_rx_add_vid(netdev, vid); |
| 345 | adapter->mng_vlan_id = vid; |
| 346 | } else |
| 347 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 348 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 349 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 350 | (vid != old_vid) && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 351 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 352 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 353 | } else |
| 354 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 357 | |
| 358 | /** |
| 359 | * e1000_release_hw_control - release control of the h/w to f/w |
| 360 | * @adapter: address of board private structure |
| 361 | * |
| 362 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 363 | * For ASF and Pass Through versions of f/w this means that the |
| 364 | * driver is no longer loaded. For AMT version (only with 82573) i |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 365 | * 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] | 366 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 367 | **/ |
| 368 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 369 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 370 | e1000_release_hw_control(struct e1000_adapter *adapter) |
| 371 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 372 | u32 ctrl_ext; |
| 373 | u32 swsm; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 374 | |
| 375 | /* Let firmware taken over control of h/w */ |
| 376 | switch (adapter->hw.mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 377 | case e1000_82573: |
| 378 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 379 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 380 | swsm & ~E1000_SWSM_DRV_LOAD); |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 381 | break; |
| 382 | case e1000_82571: |
| 383 | case e1000_82572: |
| 384 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 385 | case e1000_ich8lan: |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 386 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 387 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 388 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 389 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 390 | default: |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * e1000_get_hw_control - get control of the h/w from f/w |
| 397 | * @adapter: address of board private structure |
| 398 | * |
| 399 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 400 | * For ASF and Pass Through versions of f/w this means that |
| 401 | * the driver is loaded. For AMT version (only with 82573) |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 402 | * 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] | 403 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 404 | **/ |
| 405 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 406 | static void |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 407 | e1000_get_hw_control(struct e1000_adapter *adapter) |
| 408 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 409 | u32 ctrl_ext; |
| 410 | u32 swsm; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 411 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 412 | /* Let firmware know the driver has taken over */ |
| 413 | switch (adapter->hw.mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 414 | case e1000_82573: |
| 415 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 416 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 417 | swsm | E1000_SWSM_DRV_LOAD); |
| 418 | break; |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 419 | case e1000_82571: |
| 420 | case e1000_82572: |
| 421 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 422 | case e1000_ich8lan: |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 423 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 424 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 425 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 426 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 427 | default: |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 432 | static void |
| 433 | e1000_init_manageability(struct e1000_adapter *adapter) |
| 434 | { |
| 435 | if (adapter->en_mng_pt) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 436 | u32 manc = E1000_READ_REG(&adapter->hw, MANC); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 437 | |
| 438 | /* disable hardware interception of ARP */ |
| 439 | manc &= ~(E1000_MANC_ARP_EN); |
| 440 | |
| 441 | /* enable receiving management packets to the host */ |
| 442 | /* this will probably generate destination unreachable messages |
| 443 | * from the host OS, but the packets will be handled on SMBUS */ |
| 444 | if (adapter->hw.has_manc2h) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 445 | u32 manc2h = E1000_READ_REG(&adapter->hw, MANC2H); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 446 | |
| 447 | manc |= E1000_MANC_EN_MNG2HOST; |
| 448 | #define E1000_MNG2HOST_PORT_623 (1 << 5) |
| 449 | #define E1000_MNG2HOST_PORT_664 (1 << 6) |
| 450 | manc2h |= E1000_MNG2HOST_PORT_623; |
| 451 | manc2h |= E1000_MNG2HOST_PORT_664; |
| 452 | E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h); |
| 453 | } |
| 454 | |
| 455 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | e1000_release_manageability(struct e1000_adapter *adapter) |
| 461 | { |
| 462 | if (adapter->en_mng_pt) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 463 | u32 manc = E1000_READ_REG(&adapter->hw, MANC); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 464 | |
| 465 | /* re-enable hardware interception of ARP */ |
| 466 | manc |= E1000_MANC_ARP_EN; |
| 467 | |
| 468 | if (adapter->hw.has_manc2h) |
| 469 | manc &= ~E1000_MANC_EN_MNG2HOST; |
| 470 | |
| 471 | /* don't explicitly have to mess with MANC2H since |
| 472 | * MANC has an enable disable that gates MANC2H */ |
| 473 | |
| 474 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 475 | } |
| 476 | } |
| 477 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 478 | /** |
| 479 | * e1000_configure - configure the hardware for RX and TX |
| 480 | * @adapter = private board structure |
| 481 | **/ |
| 482 | static void e1000_configure(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
| 484 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 485 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 487 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | e1000_restore_vlan(adapter); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 490 | e1000_init_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | e1000_configure_tx(adapter); |
| 493 | e1000_setup_rctl(adapter); |
| 494 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 495 | /* call E1000_DESC_UNUSED which always leaves |
| 496 | * at least 1 descriptor unused to make sure |
| 497 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 498 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 499 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 500 | adapter->alloc_rx_buf(adapter, ring, |
| 501 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 504 | adapter->tx_queue_len = netdev->tx_queue_len; |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 505 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 506 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 507 | int e1000_up(struct e1000_adapter *adapter) |
| 508 | { |
| 509 | /* hardware has been reset, we need to reload some things */ |
| 510 | e1000_configure(adapter); |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 511 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 512 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 513 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 514 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 515 | napi_enable(&adapter->napi); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 516 | #endif |
| 517 | e1000_irq_enable(adapter); |
| 518 | |
Jesse Brandeburg | 79f3d39 | 2006-12-15 10:42:34 +0100 | [diff] [blame] | 519 | /* fire a link change interrupt to start the watchdog */ |
| 520 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | return 0; |
| 522 | } |
| 523 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 524 | /** |
| 525 | * e1000_power_up_phy - restore link in case the phy was powered down |
| 526 | * @adapter: address of board private structure |
| 527 | * |
| 528 | * The phy may be powered down to save power and turn off link when the |
| 529 | * driver is unloaded and wake on lan is not enabled (among others) |
| 530 | * *** this routine MUST be followed by a call to e1000_reset *** |
| 531 | * |
| 532 | **/ |
| 533 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 534 | void e1000_power_up_phy(struct e1000_adapter *adapter) |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 535 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 536 | u16 mii_reg = 0; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 537 | |
| 538 | /* Just clear the power down bit to wake the phy back up */ |
| 539 | if (adapter->hw.media_type == e1000_media_type_copper) { |
| 540 | /* according to the manual, the phy will retain its |
| 541 | * settings across a power-down/up cycle */ |
| 542 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 543 | mii_reg &= ~MII_CR_POWER_DOWN; |
| 544 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 549 | { |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 550 | /* Power down the PHY so no link is implied when interface is down * |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 551 | * 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] | 552 | * (a) WoL is enabled |
| 553 | * (b) AMT is active |
| 554 | * (c) SoL/IDER session is active */ |
| 555 | if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 556 | adapter->hw.media_type == e1000_media_type_copper) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 557 | u16 mii_reg = 0; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 558 | |
| 559 | switch (adapter->hw.mac_type) { |
| 560 | case e1000_82540: |
| 561 | case e1000_82545: |
| 562 | case e1000_82545_rev_3: |
| 563 | case e1000_82546: |
| 564 | case e1000_82546_rev_3: |
| 565 | case e1000_82541: |
| 566 | case e1000_82541_rev_2: |
| 567 | case e1000_82547: |
| 568 | case e1000_82547_rev_2: |
| 569 | if (E1000_READ_REG(&adapter->hw, MANC) & |
| 570 | E1000_MANC_SMBUS_EN) |
| 571 | goto out; |
| 572 | break; |
| 573 | case e1000_82571: |
| 574 | case e1000_82572: |
| 575 | case e1000_82573: |
| 576 | case e1000_80003es2lan: |
| 577 | case e1000_ich8lan: |
| 578 | if (e1000_check_mng_mode(&adapter->hw) || |
| 579 | e1000_check_phy_reset_block(&adapter->hw)) |
| 580 | goto out; |
| 581 | break; |
| 582 | default: |
| 583 | goto out; |
| 584 | } |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 585 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 586 | mii_reg |= MII_CR_POWER_DOWN; |
| 587 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
| 588 | mdelay(1); |
| 589 | } |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 590 | out: |
| 591 | return; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | void |
| 595 | e1000_down(struct e1000_adapter *adapter) |
| 596 | { |
| 597 | struct net_device *netdev = adapter->netdev; |
| 598 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 599 | /* signal that we're down so the interrupt handler does not |
| 600 | * reschedule our watchdog timer */ |
| 601 | set_bit(__E1000_DOWN, &adapter->flags); |
| 602 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 603 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 604 | napi_disable(&adapter->napi); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 605 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 609 | del_timer_sync(&adapter->watchdog_timer); |
| 610 | del_timer_sync(&adapter->phy_info_timer); |
| 611 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 612 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | adapter->link_speed = 0; |
| 614 | adapter->link_duplex = 0; |
| 615 | netif_carrier_off(netdev); |
| 616 | netif_stop_queue(netdev); |
| 617 | |
| 618 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 619 | e1000_clean_all_tx_rings(adapter); |
| 620 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | void |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 624 | e1000_reinit_locked(struct e1000_adapter *adapter) |
| 625 | { |
| 626 | WARN_ON(in_interrupt()); |
| 627 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 628 | msleep(1); |
| 629 | e1000_down(adapter); |
| 630 | e1000_up(adapter); |
| 631 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void |
| 635 | e1000_reset(struct e1000_adapter *adapter) |
| 636 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 637 | u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
| 638 | u16 fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 639 | bool legacy_pba_adjust = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | /* Repartition Pba for greater than 9k mtu |
| 642 | * To take effect CTRL.RST is required. |
| 643 | */ |
| 644 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 645 | switch (adapter->hw.mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 646 | case e1000_82542_rev2_0: |
| 647 | case e1000_82542_rev2_1: |
| 648 | case e1000_82543: |
| 649 | case e1000_82544: |
| 650 | case e1000_82540: |
| 651 | case e1000_82541: |
| 652 | case e1000_82541_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 653 | legacy_pba_adjust = true; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 654 | pba = E1000_PBA_48K; |
| 655 | break; |
| 656 | case e1000_82545: |
| 657 | case e1000_82545_rev_3: |
| 658 | case e1000_82546: |
| 659 | case e1000_82546_rev_3: |
| 660 | pba = E1000_PBA_48K; |
| 661 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 662 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 663 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 664 | legacy_pba_adjust = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 665 | pba = E1000_PBA_30K; |
| 666 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 667 | case e1000_82571: |
| 668 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 669 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 670 | pba = E1000_PBA_38K; |
| 671 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 672 | case e1000_82573: |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 673 | pba = E1000_PBA_20K; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 674 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 675 | case e1000_ich8lan: |
| 676 | pba = E1000_PBA_8K; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 677 | case e1000_undefined: |
| 678 | case e1000_num_macs: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 679 | break; |
| 680 | } |
| 681 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 682 | if (legacy_pba_adjust) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 683 | if (adapter->netdev->mtu > E1000_RXBUFFER_8192) |
| 684 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 685 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 686 | if (adapter->hw.mac_type == e1000_82547) { |
| 687 | adapter->tx_fifo_head = 0; |
| 688 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 689 | adapter->tx_fifo_size = |
| 690 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 691 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 692 | } |
| 693 | } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 694 | /* adjust PBA for jumbo frames */ |
| 695 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 696 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 697 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 698 | * large enough to accomodate two full transmit packets, |
| 699 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 700 | * the Rx FIFO should be large enough to accomodate at least |
| 701 | * one full receive packet and is similarly rounded up and |
| 702 | * expressed in KB. */ |
| 703 | pba = E1000_READ_REG(&adapter->hw, PBA); |
| 704 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 705 | tx_space = pba >> 16; |
| 706 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 707 | pba &= 0xffff; |
| 708 | /* don't include ethernet FCS because hardware appends/strips */ |
| 709 | min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE + |
| 710 | VLAN_TAG_SIZE; |
| 711 | min_tx_space = min_rx_space; |
| 712 | min_tx_space *= 2; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 713 | min_tx_space = ALIGN(min_tx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 714 | min_tx_space >>= 10; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 715 | min_rx_space = ALIGN(min_rx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 716 | min_rx_space >>= 10; |
| 717 | |
| 718 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 719 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 720 | * allocation, take space away from current Rx allocation */ |
| 721 | if (tx_space < min_tx_space && |
| 722 | ((min_tx_space - tx_space) < pba)) { |
| 723 | pba = pba - (min_tx_space - tx_space); |
| 724 | |
| 725 | /* PCI/PCIx hardware has PBA alignment constraints */ |
| 726 | switch (adapter->hw.mac_type) { |
| 727 | case e1000_82545 ... e1000_82546_rev_3: |
| 728 | pba &= ~(E1000_PBA_8K - 1); |
| 729 | break; |
| 730 | default: |
| 731 | break; |
| 732 | } |
| 733 | |
| 734 | /* if short on rx space, rx wins and must trump tx |
| 735 | * adjustment or use Early Receive if available */ |
| 736 | if (pba < min_rx_space) { |
| 737 | switch (adapter->hw.mac_type) { |
| 738 | case e1000_82573: |
| 739 | /* ERT enabled in e1000_configure_rx */ |
| 740 | break; |
| 741 | default: |
| 742 | pba = min_rx_space; |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
| 750 | |
| 751 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 752 | /* Set the FC high water mark to 90% of the FIFO size. |
| 753 | * Required to clear last 3 LSB */ |
| 754 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 755 | /* We can't use 90% on small FIFOs because the remainder |
| 756 | * would be less than 1 full frame. In this case, we size |
| 757 | * it to allow at least a full frame above the high water |
| 758 | * mark. */ |
| 759 | if (pba < E1000_PBA_16K) |
| 760 | fc_high_water_mark = (pba * 1024) - 1600; |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 761 | |
| 762 | adapter->hw.fc_high_water = fc_high_water_mark; |
| 763 | adapter->hw.fc_low_water = fc_high_water_mark - 8; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 764 | if (adapter->hw.mac_type == e1000_80003es2lan) |
| 765 | adapter->hw.fc_pause_time = 0xFFFF; |
| 766 | else |
| 767 | adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | adapter->hw.fc_send_xon = 1; |
| 769 | adapter->hw.fc = adapter->hw.original_fc; |
| 770 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 771 | /* Allow time for pending master requests to run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | e1000_reset_hw(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 773 | if (adapter->hw.mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 775 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 776 | if (e1000_init_hw(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 778 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 779 | |
| 780 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
| 781 | if (adapter->hw.mac_type >= e1000_82544 && |
| 782 | adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 783 | adapter->hw.autoneg == 1 && |
| 784 | adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 785 | u32 ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 786 | /* clear phy power management bit if we are in gig only mode, |
| 787 | * which if enabled will attempt negotiation to 100Mb, which |
| 788 | * can cause a loss of link at power off or driver unload */ |
| 789 | ctrl &= ~E1000_CTRL_SWDPIN3; |
| 790 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 791 | } |
| 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 794 | E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); |
| 795 | |
| 796 | e1000_reset_adaptive(&adapter->hw); |
| 797 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 798 | |
| 799 | if (!adapter->smart_power_down && |
| 800 | (adapter->hw.mac_type == e1000_82571 || |
| 801 | adapter->hw.mac_type == e1000_82572)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 802 | u16 phy_data = 0; |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 803 | /* speed up time to link by disabling smart power down, ignore |
| 804 | * the return value of this function because there is nothing |
| 805 | * different we would do if it failed */ |
| 806 | e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 807 | &phy_data); |
| 808 | phy_data &= ~IGP02E1000_PM_SPD; |
| 809 | e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT, |
| 810 | phy_data); |
| 811 | } |
| 812 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 813 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 817 | * Dump the eeprom for users having checksum issues |
| 818 | **/ |
Adrian Bunk | b4ea895 | 2008-02-01 08:21:28 -0800 | [diff] [blame] | 819 | static void e1000_dump_eeprom(struct e1000_adapter *adapter) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 820 | { |
| 821 | struct net_device *netdev = adapter->netdev; |
| 822 | struct ethtool_eeprom eeprom; |
| 823 | const struct ethtool_ops *ops = netdev->ethtool_ops; |
| 824 | u8 *data; |
| 825 | int i; |
| 826 | u16 csum_old, csum_new = 0; |
| 827 | |
| 828 | eeprom.len = ops->get_eeprom_len(netdev); |
| 829 | eeprom.offset = 0; |
| 830 | |
| 831 | data = kmalloc(eeprom.len, GFP_KERNEL); |
| 832 | if (!data) { |
| 833 | printk(KERN_ERR "Unable to allocate memory to dump EEPROM" |
| 834 | " data\n"); |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | ops->get_eeprom(netdev, &eeprom, data); |
| 839 | |
| 840 | csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + |
| 841 | (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); |
| 842 | for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) |
| 843 | csum_new += data[i] + (data[i + 1] << 8); |
| 844 | csum_new = EEPROM_SUM - csum_new; |
| 845 | |
| 846 | printk(KERN_ERR "/*********************/\n"); |
| 847 | printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old); |
| 848 | printk(KERN_ERR "Calculated : 0x%04x\n", csum_new); |
| 849 | |
| 850 | printk(KERN_ERR "Offset Values\n"); |
| 851 | printk(KERN_ERR "======== ======\n"); |
| 852 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); |
| 853 | |
| 854 | printk(KERN_ERR "Include this output when contacting your support " |
| 855 | "provider.\n"); |
| 856 | printk(KERN_ERR "This is not a software error! Something bad " |
| 857 | "happened to your hardware or\n"); |
| 858 | printk(KERN_ERR "EEPROM image. Ignoring this " |
| 859 | "problem could result in further problems,\n"); |
| 860 | printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n"); |
| 861 | printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, " |
| 862 | "which is invalid\n"); |
| 863 | printk(KERN_ERR "and requires you to set the proper MAC " |
| 864 | "address manually before continuing\n"); |
| 865 | printk(KERN_ERR "to enable this network device.\n"); |
| 866 | printk(KERN_ERR "Please inspect the EEPROM dump and report the issue " |
| 867 | "to your hardware vendor\n"); |
| 868 | printk(KERN_ERR "or Intel Customer Support: linux-nics@intel.com\n"); |
| 869 | printk(KERN_ERR "/*********************/\n"); |
| 870 | |
| 871 | kfree(data); |
| 872 | } |
| 873 | |
| 874 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | * e1000_probe - Device Initialization Routine |
| 876 | * @pdev: PCI device information struct |
| 877 | * @ent: entry in e1000_pci_tbl |
| 878 | * |
| 879 | * Returns 0 on success, negative on failure |
| 880 | * |
| 881 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 882 | * The OS initialization, configuring of the adapter private structure, |
| 883 | * and a hardware reset occur. |
| 884 | **/ |
| 885 | |
| 886 | static int __devinit |
| 887 | e1000_probe(struct pci_dev *pdev, |
| 888 | const struct pci_device_id *ent) |
| 889 | { |
| 890 | struct net_device *netdev; |
| 891 | struct e1000_adapter *adapter; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 894 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 895 | int i, err, pci_using_dac; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 896 | u16 eeprom_data = 0; |
| 897 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 898 | DECLARE_MAC_BUF(mac); |
| 899 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 900 | if ((err = pci_enable_device(pdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | return err; |
| 902 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 903 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) && |
| 904 | !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | pci_using_dac = 1; |
| 906 | } else { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 907 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) && |
| 908 | (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | E1000_ERR("No usable DMA configuration, aborting\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 910 | goto err_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
| 912 | pci_using_dac = 0; |
| 913 | } |
| 914 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 915 | if ((err = pci_request_regions(pdev, e1000_driver_name))) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 916 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | pci_set_master(pdev); |
| 919 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 920 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 922 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 926 | |
| 927 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 928 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | adapter->netdev = netdev; |
| 930 | adapter->pdev = pdev; |
| 931 | adapter->hw.back = adapter; |
| 932 | adapter->msg_enable = (1 << debug) - 1; |
| 933 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 934 | err = -EIO; |
Benjamin Herrenschmidt | 3c34ac3 | 2007-11-16 18:37:38 +1100 | [diff] [blame] | 935 | adapter->hw.hw_addr = ioremap(pci_resource_start(pdev, BAR_0), |
| 936 | pci_resource_len(pdev, BAR_0)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 937 | if (!adapter->hw.hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 940 | for (i = BAR_1; i <= BAR_5; i++) { |
| 941 | if (pci_resource_len(pdev, i) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | continue; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 943 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 945 | break; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | netdev->open = &e1000_open; |
| 950 | netdev->stop = &e1000_close; |
| 951 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 952 | netdev->get_stats = &e1000_get_stats; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 953 | netdev->set_rx_mode = &e1000_set_rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | netdev->set_mac_address = &e1000_set_mac; |
| 955 | netdev->change_mtu = &e1000_change_mtu; |
| 956 | netdev->do_ioctl = &e1000_ioctl; |
| 957 | e1000_set_ethtool_ops(netdev); |
| 958 | netdev->tx_timeout = &e1000_tx_timeout; |
| 959 | netdev->watchdog_timeo = 5 * HZ; |
| 960 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 961 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | #endif |
| 963 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 964 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 965 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 966 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 967 | netdev->poll_controller = e1000_netpoll; |
| 968 | #endif |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 969 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | adapter->bd_number = cards_found; |
| 972 | |
| 973 | /* setup the private structure */ |
| 974 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 975 | if ((err = e1000_sw_init(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | goto err_sw_init; |
| 977 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 978 | err = -EIO; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 979 | /* Flash BAR mapping must happen after e1000_sw_init |
| 980 | * because it depends on mac_type */ |
| 981 | if ((adapter->hw.mac_type == e1000_ich8lan) && |
| 982 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
Benjamin Herrenschmidt | 3c34ac3 | 2007-11-16 18:37:38 +1100 | [diff] [blame] | 983 | adapter->hw.flash_address = |
| 984 | ioremap(pci_resource_start(pdev, 1), |
| 985 | pci_resource_len(pdev, 1)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 986 | if (!adapter->hw.flash_address) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 987 | goto err_flashmap; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 990 | if (e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 991 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 992 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 993 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | netdev->features = NETIF_F_SG | |
| 995 | NETIF_F_HW_CSUM | |
| 996 | NETIF_F_HW_VLAN_TX | |
| 997 | NETIF_F_HW_VLAN_RX | |
| 998 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 999 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 1000 | netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1003 | if ((adapter->hw.mac_type >= e1000_82544) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | (adapter->hw.mac_type != e1000_82547)) |
| 1005 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1006 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1007 | if (adapter->hw.mac_type > e1000_82547_rev_2) |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1008 | netdev->features |= NETIF_F_TSO6; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1009 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | netdev->features |= NETIF_F_HIGHDMA; |
| 1011 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 1012 | netdev->features |= NETIF_F_LLTX; |
| 1013 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1014 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); |
| 1015 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1016 | /* initialize eeprom parameters */ |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1017 | if (e1000_init_eeprom_params(&adapter->hw)) { |
| 1018 | E1000_ERR("EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1019 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1022 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | e1000_reset_hw(&adapter->hw); |
| 1026 | |
| 1027 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1028 | if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1030 | e1000_dump_eeprom(adapter); |
| 1031 | /* |
| 1032 | * set MAC address to all zeroes to invalidate and temporary |
| 1033 | * disable this device for the user. This blocks regular |
| 1034 | * traffic while still permitting ethtool ioctls from reaching |
| 1035 | * the hardware as well as allowing the user to run the |
| 1036 | * interface after manually setting a hw addr using |
| 1037 | * `ip set address` |
| 1038 | */ |
| 1039 | memset(adapter->hw.mac_addr, 0, netdev->addr_len); |
| 1040 | } else { |
| 1041 | /* copy the MAC address out of the EEPROM */ |
| 1042 | if (e1000_read_mac_addr(&adapter->hw)) |
| 1043 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | } |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1045 | /* don't block initalization here due to bad MAC address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
John W. Linville | 9beb0ac | 2005-09-12 10:48:55 -0400 | [diff] [blame] | 1047 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1049 | if (!is_valid_ether_addr(netdev->perm_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | e1000_get_bus_info(&adapter->hw); |
| 1053 | |
| 1054 | init_timer(&adapter->tx_fifo_stall_timer); |
| 1055 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
| 1056 | adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; |
| 1057 | |
| 1058 | init_timer(&adapter->watchdog_timer); |
| 1059 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 1060 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 1061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | init_timer(&adapter->phy_info_timer); |
| 1063 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 1064 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 1065 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1066 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | e1000_check_options(adapter); |
| 1069 | |
| 1070 | /* Initial Wake on LAN setting |
| 1071 | * If APM wake is enabled in the EEPROM, |
| 1072 | * enable the ACPI Magic Packet filter |
| 1073 | */ |
| 1074 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1075 | switch (adapter->hw.mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | case e1000_82542_rev2_0: |
| 1077 | case e1000_82542_rev2_1: |
| 1078 | case e1000_82543: |
| 1079 | break; |
| 1080 | case e1000_82544: |
| 1081 | e1000_read_eeprom(&adapter->hw, |
| 1082 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1083 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 1084 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1085 | case e1000_ich8lan: |
| 1086 | e1000_read_eeprom(&adapter->hw, |
| 1087 | EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
| 1088 | eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
| 1089 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | case e1000_82546: |
| 1091 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1092 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1093 | case e1000_80003es2lan: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1094 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | e1000_read_eeprom(&adapter->hw, |
| 1096 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1097 | break; |
| 1098 | } |
| 1099 | /* Fall Through */ |
| 1100 | default: |
| 1101 | e1000_read_eeprom(&adapter->hw, |
| 1102 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1103 | break; |
| 1104 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1105 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1106 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1107 | |
| 1108 | /* now that we have the eeprom settings, apply the special cases |
| 1109 | * where the eeprom may be wrong or the board simply won't support |
| 1110 | * wake on lan on a particular port */ |
| 1111 | switch (pdev->device) { |
| 1112 | case E1000_DEV_ID_82546GB_PCIE: |
| 1113 | adapter->eeprom_wol = 0; |
| 1114 | break; |
| 1115 | case E1000_DEV_ID_82546EB_FIBER: |
| 1116 | case E1000_DEV_ID_82546GB_FIBER: |
| 1117 | case E1000_DEV_ID_82571EB_FIBER: |
| 1118 | /* Wake events only supported on port A for dual fiber |
| 1119 | * regardless of eeprom setting */ |
| 1120 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1) |
| 1121 | adapter->eeprom_wol = 0; |
| 1122 | break; |
| 1123 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1124 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 1125 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 1126 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
Auke Kok | f4ec7f9 | 2007-08-30 11:23:58 -0700 | [diff] [blame] | 1127 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1128 | /* if quad port adapter, disable WoL on all but port A */ |
| 1129 | if (global_quad_port_a != 0) |
| 1130 | adapter->eeprom_wol = 0; |
| 1131 | else |
| 1132 | adapter->quad_port_a = 1; |
| 1133 | /* Reset for multiple quad port adapters */ |
| 1134 | if (++global_quad_port_a == 4) |
| 1135 | global_quad_port_a = 0; |
| 1136 | break; |
| 1137 | } |
| 1138 | |
| 1139 | /* initialize the wol settings based on the eeprom settings */ |
| 1140 | adapter->wol = adapter->eeprom_wol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1142 | /* print bus type/speed/width info */ |
| 1143 | { |
| 1144 | struct e1000_hw *hw = &adapter->hw; |
| 1145 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 1146 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 1147 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 1148 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 1149 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 1150 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 1151 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 1152 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 1153 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 1154 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 1155 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 1156 | "32-bit")); |
| 1157 | } |
| 1158 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1159 | printk("%s\n", print_mac(mac, netdev->dev_addr)); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1160 | |
Auke Kok | 14782ca | 2008-02-11 09:25:46 -0800 | [diff] [blame] | 1161 | if (adapter->hw.bus_type == e1000_bus_type_pci_express) { |
| 1162 | DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no " |
| 1163 | "longer be supported by this driver in the future.\n", |
| 1164 | pdev->vendor, pdev->device); |
| 1165 | DPRINTK(PROBE, WARNING, "please use the \"e1000e\" " |
| 1166 | "driver instead.\n"); |
| 1167 | } |
| 1168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | /* reset the hardware with the new settings */ |
| 1170 | e1000_reset(adapter); |
| 1171 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1172 | /* If the controller is 82573 and f/w is AMT, do not set |
| 1173 | * DRV_LOAD until the interface is up. For all other cases, |
| 1174 | * let the f/w know that the h/w is now under the control |
| 1175 | * of the driver. */ |
| 1176 | if (adapter->hw.mac_type != e1000_82573 || |
| 1177 | !e1000_check_mng_mode(&adapter->hw)) |
| 1178 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1179 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1180 | /* tell the stack to leave us alone until e1000_open() is called */ |
| 1181 | netif_carrier_off(netdev); |
| 1182 | netif_stop_queue(netdev); |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1183 | |
| 1184 | strcpy(netdev->name, "eth%d"); |
| 1185 | if ((err = register_netdev(netdev))) |
| 1186 | goto err_register; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 1189 | |
| 1190 | cards_found++; |
| 1191 | return 0; |
| 1192 | |
| 1193 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1194 | e1000_release_hw_control(adapter); |
| 1195 | err_eeprom: |
| 1196 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
| 1197 | e1000_phy_hw_reset(&adapter->hw); |
| 1198 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1199 | if (adapter->hw.flash_address) |
| 1200 | iounmap(adapter->hw.flash_address); |
| 1201 | err_flashmap: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1202 | #ifdef CONFIG_E1000_NAPI |
| 1203 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1204 | dev_put(&adapter->polling_netdev[i]); |
| 1205 | #endif |
| 1206 | |
| 1207 | kfree(adapter->tx_ring); |
| 1208 | kfree(adapter->rx_ring); |
| 1209 | #ifdef CONFIG_E1000_NAPI |
| 1210 | kfree(adapter->polling_netdev); |
| 1211 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | err_sw_init: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | iounmap(adapter->hw.hw_addr); |
| 1214 | err_ioremap: |
| 1215 | free_netdev(netdev); |
| 1216 | err_alloc_etherdev: |
| 1217 | pci_release_regions(pdev); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1218 | err_pci_reg: |
| 1219 | err_dma: |
| 1220 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | return err; |
| 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * e1000_remove - Device Removal Routine |
| 1226 | * @pdev: PCI device information struct |
| 1227 | * |
| 1228 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1229 | * that it should release a PCI device. The could be caused by a |
| 1230 | * Hot-Plug event, or because the driver is going to be removed from |
| 1231 | * memory. |
| 1232 | **/ |
| 1233 | |
| 1234 | static void __devexit |
| 1235 | e1000_remove(struct pci_dev *pdev) |
| 1236 | { |
| 1237 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1238 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1239 | #ifdef CONFIG_E1000_NAPI |
| 1240 | int i; |
| 1241 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 1243 | cancel_work_sync(&adapter->reset_task); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1244 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1245 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1247 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1248 | * would have already happened in close and is redundant. */ |
| 1249 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1250 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1251 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1252 | for (i = 0; i < adapter->num_rx_queues; i++) |
Stephen Hemminger | 1533306 | 2006-03-20 22:32:28 -0800 | [diff] [blame] | 1253 | dev_put(&adapter->polling_netdev[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1254 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1256 | unregister_netdev(netdev); |
| 1257 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1258 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1259 | e1000_phy_hw_reset(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1261 | kfree(adapter->tx_ring); |
| 1262 | kfree(adapter->rx_ring); |
| 1263 | #ifdef CONFIG_E1000_NAPI |
| 1264 | kfree(adapter->polling_netdev); |
| 1265 | #endif |
| 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | iounmap(adapter->hw.hw_addr); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1268 | if (adapter->hw.flash_address) |
| 1269 | iounmap(adapter->hw.flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | pci_release_regions(pdev); |
| 1271 | |
| 1272 | free_netdev(netdev); |
| 1273 | |
| 1274 | pci_disable_device(pdev); |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1279 | * @adapter: board private structure to initialize |
| 1280 | * |
| 1281 | * e1000_sw_init initializes the Adapter private data structure. |
| 1282 | * Fields are initialized based on PCI device information and |
| 1283 | * OS network device settings (MTU size). |
| 1284 | **/ |
| 1285 | |
| 1286 | static int __devinit |
| 1287 | e1000_sw_init(struct e1000_adapter *adapter) |
| 1288 | { |
| 1289 | struct e1000_hw *hw = &adapter->hw; |
| 1290 | struct net_device *netdev = adapter->netdev; |
| 1291 | struct pci_dev *pdev = adapter->pdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1292 | #ifdef CONFIG_E1000_NAPI |
| 1293 | int i; |
| 1294 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
| 1296 | /* PCI config space info */ |
| 1297 | |
| 1298 | hw->vendor_id = pdev->vendor; |
| 1299 | hw->device_id = pdev->device; |
| 1300 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1301 | hw->subsystem_id = pdev->subsystem_device; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1302 | hw->revision_id = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 1305 | |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1306 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1307 | adapter->rx_ps_bsize0 = E1000_RXBUFFER_128; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | hw->max_frame_size = netdev->mtu + |
| 1309 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1310 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 1311 | |
| 1312 | /* identify the MAC */ |
| 1313 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1314 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 1316 | return -EIO; |
| 1317 | } |
| 1318 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1319 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | default: |
| 1321 | break; |
| 1322 | case e1000_82541: |
| 1323 | case e1000_82547: |
| 1324 | case e1000_82541_rev_2: |
| 1325 | case e1000_82547_rev_2: |
| 1326 | hw->phy_init_script = 1; |
| 1327 | break; |
| 1328 | } |
| 1329 | |
| 1330 | e1000_set_media_type(hw); |
| 1331 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1332 | hw->wait_autoneg_complete = false; |
| 1333 | hw->tbi_compatibility_en = true; |
| 1334 | hw->adaptive_ifs = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
| 1336 | /* Copper options */ |
| 1337 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1338 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | hw->mdix = AUTO_ALL_MODES; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1340 | hw->disable_polarity_correction = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1342 | } |
| 1343 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1344 | adapter->num_tx_queues = 1; |
| 1345 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1346 | |
| 1347 | if (e1000_alloc_queues(adapter)) { |
| 1348 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1349 | return -ENOMEM; |
| 1350 | } |
| 1351 | |
| 1352 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1353 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1354 | adapter->polling_netdev[i].priv = adapter; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1355 | dev_hold(&adapter->polling_netdev[i]); |
| 1356 | set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
| 1357 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1358 | spin_lock_init(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1359 | #endif |
| 1360 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1361 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1362 | e1000_irq_disable(adapter); |
| 1363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1366 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | return 0; |
| 1369 | } |
| 1370 | |
| 1371 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1372 | * e1000_alloc_queues - Allocate memory for all rings |
| 1373 | * @adapter: board private structure to initialize |
| 1374 | * |
| 1375 | * We allocate one ring per queue at run-time since we don't know the |
| 1376 | * number of queues at compile-time. The polling_netdev array is |
| 1377 | * intended for Multiqueue, but should work fine with a single queue. |
| 1378 | **/ |
| 1379 | |
| 1380 | static int __devinit |
| 1381 | e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1382 | { |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1383 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1384 | sizeof(struct e1000_tx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1385 | if (!adapter->tx_ring) |
| 1386 | return -ENOMEM; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1387 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1388 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1389 | sizeof(struct e1000_rx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1390 | if (!adapter->rx_ring) { |
| 1391 | kfree(adapter->tx_ring); |
| 1392 | return -ENOMEM; |
| 1393 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1394 | |
| 1395 | #ifdef CONFIG_E1000_NAPI |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1396 | adapter->polling_netdev = kcalloc(adapter->num_rx_queues, |
| 1397 | sizeof(struct net_device), |
| 1398 | GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1399 | if (!adapter->polling_netdev) { |
| 1400 | kfree(adapter->tx_ring); |
| 1401 | kfree(adapter->rx_ring); |
| 1402 | return -ENOMEM; |
| 1403 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1404 | #endif |
| 1405 | |
| 1406 | return E1000_SUCCESS; |
| 1407 | } |
| 1408 | |
| 1409 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | * e1000_open - Called when a network interface is made active |
| 1411 | * @netdev: network interface device structure |
| 1412 | * |
| 1413 | * Returns 0 on success, negative value on failure |
| 1414 | * |
| 1415 | * The open entry point is called when a network interface is made |
| 1416 | * active by the system (IFF_UP). At this point all resources needed |
| 1417 | * for transmit and receive operations are allocated, the interrupt |
| 1418 | * handler is registered with the OS, the watchdog timer is started, |
| 1419 | * and the stack is notified that the interface is ready. |
| 1420 | **/ |
| 1421 | |
| 1422 | static int |
| 1423 | e1000_open(struct net_device *netdev) |
| 1424 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1425 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | int err; |
| 1427 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1428 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1429 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1430 | return -EBUSY; |
| 1431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | /* allocate transmit descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1433 | err = e1000_setup_all_tx_resources(adapter); |
| 1434 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | goto err_setup_tx; |
| 1436 | |
| 1437 | /* allocate receive descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1438 | err = e1000_setup_all_rx_resources(adapter); |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1439 | if (err) |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1440 | goto err_setup_rx; |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1441 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1442 | e1000_power_up_phy(adapter); |
| 1443 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1444 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1445 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1446 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1447 | e1000_update_mng_vlan(adapter); |
| 1448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1450 | /* If AMT is enabled, let the firmware know that the network |
| 1451 | * interface is now open */ |
| 1452 | if (adapter->hw.mac_type == e1000_82573 && |
| 1453 | e1000_check_mng_mode(&adapter->hw)) |
| 1454 | e1000_get_hw_control(adapter); |
| 1455 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1456 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1457 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1458 | * as soon as we call pci_request_irq, so we have to setup our |
| 1459 | * clean_rx handler before we do so. */ |
| 1460 | e1000_configure(adapter); |
| 1461 | |
| 1462 | err = e1000_request_irq(adapter); |
| 1463 | if (err) |
| 1464 | goto err_req_irq; |
| 1465 | |
| 1466 | /* From here on the code is the same as e1000_up() */ |
| 1467 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 1468 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1469 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1470 | napi_enable(&adapter->napi); |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1471 | #endif |
| 1472 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1473 | e1000_irq_enable(adapter); |
| 1474 | |
| 1475 | /* fire a link status change interrupt to start the watchdog */ |
| 1476 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC); |
| 1477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | return E1000_SUCCESS; |
| 1479 | |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1480 | err_req_irq: |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1481 | e1000_release_hw_control(adapter); |
| 1482 | e1000_power_down_phy(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1483 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1485 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | err_setup_tx: |
| 1487 | e1000_reset(adapter); |
| 1488 | |
| 1489 | return err; |
| 1490 | } |
| 1491 | |
| 1492 | /** |
| 1493 | * e1000_close - Disables a network interface |
| 1494 | * @netdev: network interface device structure |
| 1495 | * |
| 1496 | * Returns 0, this is not allowed to fail |
| 1497 | * |
| 1498 | * The close entry point is called when an interface is de-activated |
| 1499 | * by the OS. The hardware is still under the drivers control, but |
| 1500 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1501 | * hardware, and all transmit and receive resources are freed. |
| 1502 | **/ |
| 1503 | |
| 1504 | static int |
| 1505 | e1000_close(struct net_device *netdev) |
| 1506 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1507 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1509 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1511 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1512 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1514 | e1000_free_all_tx_resources(adapter); |
| 1515 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1517 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1518 | * 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] | 1519 | if ((adapter->hw.mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1520 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1521 | !(adapter->vlgrp && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1522 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1523 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1524 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1525 | |
| 1526 | /* If AMT is enabled, let the firmware know that the network |
| 1527 | * interface is now closed */ |
| 1528 | if (adapter->hw.mac_type == e1000_82573 && |
| 1529 | e1000_check_mng_mode(&adapter->hw)) |
| 1530 | e1000_release_hw_control(adapter); |
| 1531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | return 0; |
| 1533 | } |
| 1534 | |
| 1535 | /** |
| 1536 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1537 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1538 | * @start: address of beginning of memory |
| 1539 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | **/ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1541 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | e1000_check_64k_bound(struct e1000_adapter *adapter, |
| 1543 | void *start, unsigned long len) |
| 1544 | { |
| 1545 | unsigned long begin = (unsigned long) start; |
| 1546 | unsigned long end = begin + len; |
| 1547 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1548 | /* First rev 82545 and 82546 need to not allow any memory |
| 1549 | * write location to cross 64k boundary due to errata 23 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | if (adapter->hw.mac_type == e1000_82545 || |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1551 | adapter->hw.mac_type == e1000_82546) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1552 | return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1555 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1560 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1561 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | * |
| 1563 | * Return 0 on success, negative on failure |
| 1564 | **/ |
| 1565 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1566 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1567 | e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1568 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | struct pci_dev *pdev = adapter->pdev; |
| 1571 | int size; |
| 1572 | |
| 1573 | size = sizeof(struct e1000_buffer) * txdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1574 | txdr->buffer_info = vmalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1575 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1576 | DPRINTK(PROBE, ERR, |
| 1577 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | return -ENOMEM; |
| 1579 | } |
| 1580 | memset(txdr->buffer_info, 0, size); |
| 1581 | |
| 1582 | /* round up to nearest 4K */ |
| 1583 | |
| 1584 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1585 | txdr->size = ALIGN(txdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
| 1587 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1588 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1591 | DPRINTK(PROBE, ERR, |
| 1592 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | return -ENOMEM; |
| 1594 | } |
| 1595 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1596 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1598 | void *olddesc = txdr->desc; |
| 1599 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1600 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1601 | "at %p\n", txdr->size, txdr->desc); |
| 1602 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1604 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1605 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1607 | goto setup_tx_desc_die; |
| 1608 | } |
| 1609 | |
| 1610 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1611 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1612 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1613 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1615 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1616 | "Unable to allocate aligned memory " |
| 1617 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | vfree(txdr->buffer_info); |
| 1619 | return -ENOMEM; |
| 1620 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1621 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1623 | } |
| 1624 | } |
| 1625 | memset(txdr->desc, 0, txdr->size); |
| 1626 | |
| 1627 | txdr->next_to_use = 0; |
| 1628 | txdr->next_to_clean = 0; |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1629 | spin_lock_init(&txdr->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
| 1634 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1635 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1636 | * (Descriptors) for all queues |
| 1637 | * @adapter: board private structure |
| 1638 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1639 | * Return 0 on success, negative on failure |
| 1640 | **/ |
| 1641 | |
| 1642 | int |
| 1643 | e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
| 1644 | { |
| 1645 | int i, err = 0; |
| 1646 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1647 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1648 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1649 | if (err) { |
| 1650 | DPRINTK(PROBE, ERR, |
| 1651 | "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1652 | for (i-- ; i >= 0; i--) |
| 1653 | e1000_free_tx_resources(adapter, |
| 1654 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1655 | break; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | return err; |
| 1660 | } |
| 1661 | |
| 1662 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1664 | * @adapter: board private structure |
| 1665 | * |
| 1666 | * Configure the Tx unit of the MAC after a reset. |
| 1667 | **/ |
| 1668 | |
| 1669 | static void |
| 1670 | e1000_configure_tx(struct e1000_adapter *adapter) |
| 1671 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1672 | u64 tdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1673 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1674 | u32 tdlen, tctl, tipg, tarc; |
| 1675 | u32 ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
| 1677 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1678 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1679 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1680 | case 1: |
| 1681 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1682 | tdba = adapter->tx_ring[0].dma; |
| 1683 | tdlen = adapter->tx_ring[0].count * |
| 1684 | sizeof(struct e1000_tx_desc); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1685 | E1000_WRITE_REG(hw, TDLEN, tdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1686 | E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 1687 | E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1688 | E1000_WRITE_REG(hw, TDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 1689 | E1000_WRITE_REG(hw, TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1690 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1691 | 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] | 1692 | break; |
| 1693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | |
| 1695 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Jesse Brandeburg | d89b6c6 | 2006-12-15 10:38:32 +0100 | [diff] [blame] | 1696 | if (adapter->hw.mac_type <= e1000_82547_rev_2 && |
| 1697 | (hw->media_type == e1000_media_type_fiber || |
| 1698 | hw->media_type == e1000_media_type_internal_serdes)) |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1699 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1700 | else |
| 1701 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1702 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1703 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | case e1000_82542_rev2_0: |
| 1705 | case e1000_82542_rev2_1: |
| 1706 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1707 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1708 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1710 | case e1000_80003es2lan: |
| 1711 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1712 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1713 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1715 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1716 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1717 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1719 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1720 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1721 | E1000_WRITE_REG(hw, TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
| 1723 | /* Set the Tx Interrupt Delay register */ |
| 1724 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1725 | E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 1726 | if (hw->mac_type >= e1000_82540) |
| 1727 | E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
| 1729 | /* Program the Transmit Control Register */ |
| 1730 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1731 | tctl = E1000_READ_REG(hw, TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1733 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1735 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1736 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 1737 | tarc = E1000_READ_REG(hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1738 | /* set the speed mode bit, we'll clear it if we're not at |
| 1739 | * gigabit link later */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1740 | tarc |= (1 << 21); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1741 | E1000_WRITE_REG(hw, TARC0, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1742 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 1743 | tarc = E1000_READ_REG(hw, TARC0); |
| 1744 | tarc |= 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1745 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1746 | tarc = E1000_READ_REG(hw, TARC1); |
| 1747 | tarc |= 1; |
| 1748 | E1000_WRITE_REG(hw, TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1749 | } |
| 1750 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1751 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
| 1753 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1754 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1755 | |
| 1756 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1757 | if (adapter->tx_int_delay) |
| 1758 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1760 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1762 | else |
| 1763 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1764 | |
| 1765 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1766 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1767 | if (hw->mac_type == e1000_82544 && |
| 1768 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1770 | |
| 1771 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | /** |
| 1776 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1777 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1778 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | * |
| 1780 | * Returns 0 on success, negative on failure |
| 1781 | **/ |
| 1782 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1783 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1784 | e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1785 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1788 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
| 1790 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1791 | rxdr->buffer_info = vmalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1792 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1793 | DPRINTK(PROBE, ERR, |
| 1794 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | return -ENOMEM; |
| 1796 | } |
| 1797 | memset(rxdr->buffer_info, 0, size); |
| 1798 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1799 | rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page), |
| 1800 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1801 | if (!rxdr->ps_page) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1802 | vfree(rxdr->buffer_info); |
| 1803 | DPRINTK(PROBE, ERR, |
| 1804 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1805 | return -ENOMEM; |
| 1806 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1807 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1808 | rxdr->ps_page_dma = kcalloc(rxdr->count, |
| 1809 | sizeof(struct e1000_ps_page_dma), |
| 1810 | GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1811 | if (!rxdr->ps_page_dma) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1812 | vfree(rxdr->buffer_info); |
| 1813 | kfree(rxdr->ps_page); |
| 1814 | DPRINTK(PROBE, ERR, |
| 1815 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1816 | return -ENOMEM; |
| 1817 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1818 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1819 | if (adapter->hw.mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1820 | desc_len = sizeof(struct e1000_rx_desc); |
| 1821 | else |
| 1822 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | /* Round up to nearest 4K */ |
| 1825 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1826 | rxdr->size = rxdr->count * desc_len; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1827 | rxdr->size = ALIGN(rxdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
| 1829 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1830 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1831 | if (!rxdr->desc) { |
| 1832 | DPRINTK(PROBE, ERR, |
| 1833 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | vfree(rxdr->buffer_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1836 | kfree(rxdr->ps_page); |
| 1837 | kfree(rxdr->ps_page_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | return -ENOMEM; |
| 1839 | } |
| 1840 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1841 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1843 | void *olddesc = rxdr->desc; |
| 1844 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1845 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1846 | "at %p\n", rxdr->size, rxdr->desc); |
| 1847 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1849 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1850 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1852 | DPRINTK(PROBE, ERR, |
| 1853 | "Unable to allocate memory " |
| 1854 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | goto setup_rx_desc_die; |
| 1856 | } |
| 1857 | |
| 1858 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1859 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1860 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1861 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1863 | DPRINTK(PROBE, ERR, |
| 1864 | "Unable to allocate aligned memory " |
| 1865 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1866 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1868 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1870 | } |
| 1871 | } |
| 1872 | memset(rxdr->desc, 0, rxdr->size); |
| 1873 | |
| 1874 | rxdr->next_to_clean = 0; |
| 1875 | rxdr->next_to_use = 0; |
| 1876 | |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
| 1880 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1881 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1882 | * (Descriptors) for all queues |
| 1883 | * @adapter: board private structure |
| 1884 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1885 | * Return 0 on success, negative on failure |
| 1886 | **/ |
| 1887 | |
| 1888 | int |
| 1889 | e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
| 1890 | { |
| 1891 | int i, err = 0; |
| 1892 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1893 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1894 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1895 | if (err) { |
| 1896 | DPRINTK(PROBE, ERR, |
| 1897 | "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1898 | for (i-- ; i >= 0; i--) |
| 1899 | e1000_free_rx_resources(adapter, |
| 1900 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1901 | break; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | return err; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1909 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | * @adapter: Board private structure |
| 1911 | **/ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1912 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 1913 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | static void |
| 1915 | e1000_setup_rctl(struct e1000_adapter *adapter) |
| 1916 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1917 | u32 rctl, rfctl; |
| 1918 | u32 psrctl = 0; |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1919 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1920 | u32 pages = 0; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1921 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
| 1923 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1924 | |
| 1925 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1926 | |
| 1927 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1928 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1929 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1930 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1931 | if (adapter->hw.tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | rctl |= E1000_RCTL_SBP; |
| 1933 | else |
| 1934 | rctl &= ~E1000_RCTL_SBP; |
| 1935 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1936 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1937 | rctl &= ~E1000_RCTL_LPE; |
| 1938 | else |
| 1939 | rctl |= E1000_RCTL_LPE; |
| 1940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1942 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1943 | rctl |= E1000_RCTL_BSEX; |
| 1944 | switch (adapter->rx_buffer_len) { |
| 1945 | case E1000_RXBUFFER_256: |
| 1946 | rctl |= E1000_RCTL_SZ_256; |
| 1947 | rctl &= ~E1000_RCTL_BSEX; |
| 1948 | break; |
| 1949 | case E1000_RXBUFFER_512: |
| 1950 | rctl |= E1000_RCTL_SZ_512; |
| 1951 | rctl &= ~E1000_RCTL_BSEX; |
| 1952 | break; |
| 1953 | case E1000_RXBUFFER_1024: |
| 1954 | rctl |= E1000_RCTL_SZ_1024; |
| 1955 | rctl &= ~E1000_RCTL_BSEX; |
| 1956 | break; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1957 | case E1000_RXBUFFER_2048: |
| 1958 | default: |
| 1959 | rctl |= E1000_RCTL_SZ_2048; |
| 1960 | rctl &= ~E1000_RCTL_BSEX; |
| 1961 | break; |
| 1962 | case E1000_RXBUFFER_4096: |
| 1963 | rctl |= E1000_RCTL_SZ_4096; |
| 1964 | break; |
| 1965 | case E1000_RXBUFFER_8192: |
| 1966 | rctl |= E1000_RCTL_SZ_8192; |
| 1967 | break; |
| 1968 | case E1000_RXBUFFER_16384: |
| 1969 | rctl |= E1000_RCTL_SZ_16384; |
| 1970 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1973 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1974 | /* 82571 and greater support packet-split where the protocol |
| 1975 | * header is placed in skb->data and the packet data is |
| 1976 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 1977 | * In the case of a non-split, skb->data is linearly filled, |
| 1978 | * followed by the page buffers. Therefore, skb->data is |
| 1979 | * sized to hold the largest protocol header. |
| 1980 | */ |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 1981 | /* allocations using alloc_page take too long for regular MTU |
| 1982 | * so only enable packet split for jumbo frames */ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1983 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
Jesse Brandeburg | e64d7d0 | 2006-10-24 14:46:01 -0700 | [diff] [blame] | 1984 | if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) && |
| 1985 | PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE)) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1986 | adapter->rx_ps_pages = pages; |
| 1987 | else |
| 1988 | adapter->rx_ps_pages = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1989 | #endif |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1990 | if (adapter->rx_ps_pages) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1991 | /* Configure extra packet-split registers */ |
| 1992 | rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
| 1993 | rfctl |= E1000_RFCTL_EXTEN; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1994 | /* disable packet split support for IPv6 extension headers, |
| 1995 | * because some malformed IPv6 headers can hang the RX */ |
| 1996 | rfctl |= (E1000_RFCTL_IPV6_EX_DIS | |
| 1997 | E1000_RFCTL_NEW_IPV6_EXT_DIS); |
| 1998 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1999 | E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
| 2000 | |
Auke Kok | 7dfee0c | 2006-06-27 09:07:50 -0700 | [diff] [blame] | 2001 | rctl |= E1000_RCTL_DTYP_PS; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2002 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2003 | psrctl |= adapter->rx_ps_bsize0 >> |
| 2004 | E1000_PSRCTL_BSIZE0_SHIFT; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2005 | |
| 2006 | switch (adapter->rx_ps_pages) { |
| 2007 | case 3: |
| 2008 | psrctl |= PAGE_SIZE << |
| 2009 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 2010 | case 2: |
| 2011 | psrctl |= PAGE_SIZE << |
| 2012 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 2013 | case 1: |
| 2014 | psrctl |= PAGE_SIZE >> |
| 2015 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 2016 | break; |
| 2017 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2018 | |
| 2019 | E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2023 | } |
| 2024 | |
| 2025 | /** |
| 2026 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 2027 | * @adapter: board private structure |
| 2028 | * |
| 2029 | * Configure the Rx unit of the MAC after a reset. |
| 2030 | **/ |
| 2031 | |
| 2032 | static void |
| 2033 | e1000_configure_rx(struct e1000_adapter *adapter) |
| 2034 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2035 | u64 rdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2036 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2037 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2038 | |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 2039 | if (adapter->rx_ps_pages) { |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2040 | /* this is a 32 byte descriptor */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2041 | rdlen = adapter->rx_ring[0].count * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2042 | sizeof(union e1000_rx_desc_packet_split); |
| 2043 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 2044 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
| 2045 | } else { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2046 | rdlen = adapter->rx_ring[0].count * |
| 2047 | sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2048 | adapter->clean_rx = e1000_clean_rx_irq; |
| 2049 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 2050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
| 2052 | /* disable receives while setting up the descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2053 | rctl = E1000_READ_REG(hw, RCTL); |
| 2054 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
| 2056 | /* set the Receive Delay Timer Register */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2057 | E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2059 | if (hw->mac_type >= e1000_82540) { |
| 2060 | E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2061 | if (adapter->itr_setting != 0) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2062 | E1000_WRITE_REG(hw, ITR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | 1000000000 / (adapter->itr * 256)); |
| 2064 | } |
| 2065 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2066 | if (hw->mac_type >= e1000_82571) { |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2067 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2068 | /* Reset delay timers after every interrupt */ |
Auke Kok | 6fc7a7e | 2006-04-14 19:05:12 -0700 | [diff] [blame] | 2069 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2070 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2071 | /* Auto-Mask interrupts upon ICR access */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2072 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2073 | E1000_WRITE_REG(hw, IAM, 0xffffffff); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2074 | #endif |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2075 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
| 2076 | E1000_WRITE_FLUSH(hw); |
| 2077 | } |
| 2078 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2079 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2080 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2081 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2082 | case 1: |
| 2083 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2084 | rdba = adapter->rx_ring[0].dma; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2085 | E1000_WRITE_REG(hw, RDLEN, rdlen); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2086 | E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 2087 | E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2088 | E1000_WRITE_REG(hw, RDT, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2089 | E1000_WRITE_REG(hw, RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 2090 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 2091 | 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] | 2092 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2093 | } |
| 2094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2096 | if (hw->mac_type >= e1000_82543) { |
| 2097 | rxcsum = E1000_READ_REG(hw, RXCSUM); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2098 | if (adapter->rx_csum) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2099 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 2100 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2101 | /* Enable 82571 IPv4 payload checksum for UDP fragments |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2102 | * Must be used in conjunction with packet-split. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2103 | if ((hw->mac_type >= e1000_82571) && |
| 2104 | (adapter->rx_ps_pages)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2105 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 2106 | } |
| 2107 | } else { |
| 2108 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 2109 | /* don't need to clear IPPCSE as it defaults to 0 */ |
| 2110 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2111 | E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Auke Kok | 21c4d5e | 2006-11-01 08:47:39 -0800 | [diff] [blame] | 2114 | /* enable early receives on 82573, only takes effect if using > 2048 |
| 2115 | * byte total frame size. for example only for jumbo frames */ |
| 2116 | #define E1000_ERT_2048 0x100 |
| 2117 | if (hw->mac_type == e1000_82573) |
| 2118 | E1000_WRITE_REG(hw, ERT, E1000_ERT_2048); |
| 2119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | /* Enable Receives */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2121 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2125 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 2126 | * @adapter: board private structure |
| 2127 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2128 | * |
| 2129 | * Free all transmit software resources |
| 2130 | **/ |
| 2131 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2132 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2133 | e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 2134 | struct e1000_tx_ring *tx_ring) |
| 2135 | { |
| 2136 | struct pci_dev *pdev = adapter->pdev; |
| 2137 | |
| 2138 | e1000_clean_tx_ring(adapter, tx_ring); |
| 2139 | |
| 2140 | vfree(tx_ring->buffer_info); |
| 2141 | tx_ring->buffer_info = NULL; |
| 2142 | |
| 2143 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2144 | |
| 2145 | tx_ring->desc = NULL; |
| 2146 | } |
| 2147 | |
| 2148 | /** |
| 2149 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | * @adapter: board private structure |
| 2151 | * |
| 2152 | * Free all transmit software resources |
| 2153 | **/ |
| 2154 | |
| 2155 | void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2156 | e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2158 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2160 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2161 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2164 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 2166 | struct e1000_buffer *buffer_info) |
| 2167 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2168 | if (buffer_info->dma) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2169 | pci_unmap_page(adapter->pdev, |
| 2170 | buffer_info->dma, |
| 2171 | buffer_info->length, |
| 2172 | PCI_DMA_TODEVICE); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2173 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | } |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2175 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2177 | buffer_info->skb = NULL; |
| 2178 | } |
| 2179 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /** |
| 2183 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2184 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2185 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | **/ |
| 2187 | |
| 2188 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2189 | e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 2190 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | struct e1000_buffer *buffer_info; |
| 2193 | unsigned long size; |
| 2194 | unsigned int i; |
| 2195 | |
| 2196 | /* Free all the Tx ring sk_buffs */ |
| 2197 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2198 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | buffer_info = &tx_ring->buffer_info[i]; |
| 2200 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2201 | } |
| 2202 | |
| 2203 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2204 | memset(tx_ring->buffer_info, 0, size); |
| 2205 | |
| 2206 | /* Zero out the descriptor ring */ |
| 2207 | |
| 2208 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2209 | |
| 2210 | tx_ring->next_to_use = 0; |
| 2211 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2212 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2214 | writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
| 2215 | writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2220 | * @adapter: board private structure |
| 2221 | **/ |
| 2222 | |
| 2223 | static void |
| 2224 | e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
| 2225 | { |
| 2226 | int i; |
| 2227 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2228 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2229 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * e1000_free_rx_resources - Free Rx Resources |
| 2234 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2235 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | * |
| 2237 | * Free all receive software resources |
| 2238 | **/ |
| 2239 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 2240 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2241 | e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 2242 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | struct pci_dev *pdev = adapter->pdev; |
| 2245 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2246 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | |
| 2248 | vfree(rx_ring->buffer_info); |
| 2249 | rx_ring->buffer_info = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2250 | kfree(rx_ring->ps_page); |
| 2251 | rx_ring->ps_page = NULL; |
| 2252 | kfree(rx_ring->ps_page_dma); |
| 2253 | rx_ring->ps_page_dma = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | |
| 2255 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2256 | |
| 2257 | rx_ring->desc = NULL; |
| 2258 | } |
| 2259 | |
| 2260 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2261 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2263 | * |
| 2264 | * Free all receive software resources |
| 2265 | **/ |
| 2266 | |
| 2267 | void |
| 2268 | e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
| 2269 | { |
| 2270 | int i; |
| 2271 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2272 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2273 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2278 | * @adapter: board private structure |
| 2279 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | **/ |
| 2281 | |
| 2282 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2283 | e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2284 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | struct e1000_buffer *buffer_info; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2287 | struct e1000_ps_page *ps_page; |
| 2288 | struct e1000_ps_page_dma *ps_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | struct pci_dev *pdev = adapter->pdev; |
| 2290 | unsigned long size; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2291 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | |
| 2293 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2294 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2296 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | pci_unmap_single(pdev, |
| 2298 | buffer_info->dma, |
| 2299 | buffer_info->length, |
| 2300 | PCI_DMA_FROMDEVICE); |
| 2301 | |
| 2302 | dev_kfree_skb(buffer_info->skb); |
| 2303 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2304 | } |
| 2305 | ps_page = &rx_ring->ps_page[i]; |
| 2306 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 2307 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
| 2308 | if (!ps_page->ps_page[j]) break; |
| 2309 | pci_unmap_page(pdev, |
| 2310 | ps_page_dma->ps_page_dma[j], |
| 2311 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 2312 | ps_page_dma->ps_page_dma[j] = 0; |
| 2313 | put_page(ps_page->ps_page[j]); |
| 2314 | ps_page->ps_page[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | |
| 2318 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2319 | memset(rx_ring->buffer_info, 0, size); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2320 | size = sizeof(struct e1000_ps_page) * rx_ring->count; |
| 2321 | memset(rx_ring->ps_page, 0, size); |
| 2322 | size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
| 2323 | memset(rx_ring->ps_page_dma, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | |
| 2325 | /* Zero out the descriptor ring */ |
| 2326 | |
| 2327 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2328 | |
| 2329 | rx_ring->next_to_clean = 0; |
| 2330 | rx_ring->next_to_use = 0; |
| 2331 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2332 | writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
| 2333 | writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
| 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2338 | * @adapter: board private structure |
| 2339 | **/ |
| 2340 | |
| 2341 | static void |
| 2342 | e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
| 2343 | { |
| 2344 | int i; |
| 2345 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2346 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2347 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2351 | * and memory write and invalidate disabled for certain operations |
| 2352 | */ |
| 2353 | static void |
| 2354 | e1000_enter_82542_rst(struct e1000_adapter *adapter) |
| 2355 | { |
| 2356 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2357 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | |
| 2359 | e1000_pci_clear_mwi(&adapter->hw); |
| 2360 | |
| 2361 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2362 | rctl |= E1000_RCTL_RST; |
| 2363 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2364 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2365 | mdelay(5); |
| 2366 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2367 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2368 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | static void |
| 2372 | e1000_leave_82542_rst(struct e1000_adapter *adapter) |
| 2373 | { |
| 2374 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2375 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | |
| 2377 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2378 | rctl &= ~E1000_RCTL_RST; |
| 2379 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2380 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2381 | mdelay(5); |
| 2382 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2383 | if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | e1000_pci_set_mwi(&adapter->hw); |
| 2385 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2386 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2387 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2388 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2389 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2390 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } |
| 2392 | } |
| 2393 | |
| 2394 | /** |
| 2395 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2396 | * @netdev: network interface device structure |
| 2397 | * @p: pointer to an address structure |
| 2398 | * |
| 2399 | * Returns 0 on success, negative on failure |
| 2400 | **/ |
| 2401 | |
| 2402 | static int |
| 2403 | e1000_set_mac(struct net_device *netdev, void *p) |
| 2404 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2405 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | struct sockaddr *addr = p; |
| 2407 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2408 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | return -EADDRNOTAVAIL; |
| 2410 | |
| 2411 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2412 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2413 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | e1000_enter_82542_rst(adapter); |
| 2415 | |
| 2416 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2417 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 2418 | |
| 2419 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2420 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2421 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2422 | * due to controller reset from the other port. */ |
| 2423 | if (adapter->hw.mac_type == e1000_82571) { |
| 2424 | /* activate the work around */ |
| 2425 | adapter->hw.laa_is_present = 1; |
| 2426 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2427 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2428 | * between the time RAR[0] gets clobbered and the time it |
| 2429 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2430 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2431 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2432 | * RAR[14] */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2433 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2434 | E1000_RAR_ENTRIES - 1); |
| 2435 | } |
| 2436 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2437 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | e1000_leave_82542_rst(adapter); |
| 2439 | |
| 2440 | return 0; |
| 2441 | } |
| 2442 | |
| 2443 | /** |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2444 | * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | * @netdev: network interface device structure |
| 2446 | * |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2447 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 2448 | * address lists or the network interface flags are updated. This routine is |
| 2449 | * responsible for configuring the hardware for proper unicast, multicast, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | * promiscuous mode, and all-multi behavior. |
| 2451 | **/ |
| 2452 | |
| 2453 | static void |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2454 | e1000_set_rx_mode(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2456 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | struct e1000_hw *hw = &adapter->hw; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2458 | struct dev_addr_list *uc_ptr; |
| 2459 | struct dev_addr_list *mc_ptr; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2460 | u32 rctl; |
| 2461 | u32 hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2462 | int i, rar_entries = E1000_RAR_ENTRIES; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2463 | int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
| 2464 | E1000_NUM_MTA_REGISTERS_ICH8LAN : |
| 2465 | E1000_NUM_MTA_REGISTERS; |
| 2466 | |
| 2467 | if (adapter->hw.mac_type == e1000_ich8lan) |
| 2468 | rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2470 | /* reserve RAR[14] for LAA over-write work-around */ |
| 2471 | if (adapter->hw.mac_type == e1000_82571) |
| 2472 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2474 | /* Check for Promiscuous and All Multicast modes */ |
| 2475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | rctl = E1000_READ_REG(hw, RCTL); |
| 2477 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2478 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2480 | } else if (netdev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | rctl |= E1000_RCTL_MPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | } else { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2483 | rctl &= ~E1000_RCTL_MPE; |
| 2484 | } |
| 2485 | |
| 2486 | uc_ptr = NULL; |
| 2487 | if (netdev->uc_count > rar_entries - 1) { |
| 2488 | rctl |= E1000_RCTL_UPE; |
| 2489 | } else if (!(netdev->flags & IFF_PROMISC)) { |
| 2490 | rctl &= ~E1000_RCTL_UPE; |
| 2491 | uc_ptr = netdev->uc_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 2495 | |
| 2496 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2497 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2498 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | e1000_enter_82542_rst(adapter); |
| 2500 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2501 | /* load the first 14 addresses into the exact filters 1-14. Unicast |
| 2502 | * addresses take precedence to avoid disabling unicast filtering |
| 2503 | * when possible. |
| 2504 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | * RAR 0 is used for the station MAC adddress |
| 2506 | * 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] | 2507 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | */ |
| 2509 | mc_ptr = netdev->mc_list; |
| 2510 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2511 | for (i = 1; i < rar_entries; i++) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2512 | if (uc_ptr) { |
| 2513 | e1000_rar_set(hw, uc_ptr->da_addr, i); |
| 2514 | uc_ptr = uc_ptr->next; |
| 2515 | } else if (mc_ptr) { |
| 2516 | e1000_rar_set(hw, mc_ptr->da_addr, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | mc_ptr = mc_ptr->next; |
| 2518 | } else { |
| 2519 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2520 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2522 | E1000_WRITE_FLUSH(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | } |
| 2524 | } |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2525 | WARN_ON(uc_ptr != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
| 2527 | /* clear the old settings from the multicast hash table */ |
| 2528 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2529 | for (i = 0; i < mta_reg_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
Auke Kok | 4ca213a | 2006-06-27 09:07:08 -0700 | [diff] [blame] | 2531 | E1000_WRITE_FLUSH(hw); |
| 2532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | |
| 2534 | /* load any remaining addresses into the hash table */ |
| 2535 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2536 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2537 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | e1000_mta_set(hw, hash_value); |
| 2539 | } |
| 2540 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2541 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | e1000_leave_82542_rst(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2546 | * the phy */ |
| 2547 | |
| 2548 | static void |
| 2549 | e1000_update_phy_info(unsigned long data) |
| 2550 | { |
| 2551 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2552 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
| 2553 | } |
| 2554 | |
| 2555 | /** |
| 2556 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2557 | * @data: pointer to adapter cast into an unsigned long |
| 2558 | **/ |
| 2559 | |
| 2560 | static void |
| 2561 | e1000_82547_tx_fifo_stall(unsigned long data) |
| 2562 | { |
| 2563 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2564 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2565 | u32 tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2567 | if (atomic_read(&adapter->tx_fifo_stall)) { |
| 2568 | if ((E1000_READ_REG(&adapter->hw, TDT) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | E1000_READ_REG(&adapter->hw, TDH)) && |
| 2570 | (E1000_READ_REG(&adapter->hw, TDFT) == |
| 2571 | E1000_READ_REG(&adapter->hw, TDFH)) && |
| 2572 | (E1000_READ_REG(&adapter->hw, TDFTS) == |
| 2573 | E1000_READ_REG(&adapter->hw, TDFHS))) { |
| 2574 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2575 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 2576 | tctl & ~E1000_TCTL_EN); |
| 2577 | E1000_WRITE_REG(&adapter->hw, TDFT, |
| 2578 | adapter->tx_head_addr); |
| 2579 | E1000_WRITE_REG(&adapter->hw, TDFH, |
| 2580 | adapter->tx_head_addr); |
| 2581 | E1000_WRITE_REG(&adapter->hw, TDFTS, |
| 2582 | adapter->tx_head_addr); |
| 2583 | E1000_WRITE_REG(&adapter->hw, TDFHS, |
| 2584 | adapter->tx_head_addr); |
| 2585 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
| 2586 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2587 | |
| 2588 | adapter->tx_fifo_head = 0; |
| 2589 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2590 | netif_wake_queue(netdev); |
| 2591 | } else { |
| 2592 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2593 | } |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | /** |
| 2598 | * e1000_watchdog - Timer Call-back |
| 2599 | * @data: pointer to adapter cast into an unsigned long |
| 2600 | **/ |
| 2601 | static void |
| 2602 | e1000_watchdog(unsigned long data) |
| 2603 | { |
| 2604 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2606 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2607 | u32 link, tctl; |
| 2608 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2610 | ret_val = e1000_check_for_link(&adapter->hw); |
| 2611 | if ((ret_val == E1000_ERR_PHY) && |
| 2612 | (adapter->hw.phy_type == e1000_phy_igp_3) && |
| 2613 | (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
| 2614 | /* See e1000_kumeran_lock_loss_workaround() */ |
| 2615 | DPRINTK(LINK, INFO, |
| 2616 | "Gigabit has been disabled, downgrading speed\n"); |
| 2617 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2618 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2619 | if (adapter->hw.mac_type == e1000_82573) { |
| 2620 | e1000_enable_tx_pkt_filtering(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2621 | if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2622 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2625 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
| 2627 | link = !adapter->hw.serdes_link_down; |
| 2628 | else |
| 2629 | link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
| 2630 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2631 | if (link) { |
| 2632 | if (!netif_carrier_ok(netdev)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2633 | u32 ctrl; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2634 | bool txb2b = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | e1000_get_speed_and_duplex(&adapter->hw, |
| 2636 | &adapter->link_speed, |
| 2637 | &adapter->link_duplex); |
| 2638 | |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2639 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 2640 | DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, " |
| 2641 | "Flow Control: %s\n", |
| 2642 | adapter->link_speed, |
| 2643 | adapter->link_duplex == FULL_DUPLEX ? |
| 2644 | "Full Duplex" : "Half Duplex", |
| 2645 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2646 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2647 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2648 | E1000_CTRL_TFCE) ? "TX" : "None" ))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2650 | /* tweak tx_queue_len according to speed/duplex |
| 2651 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2652 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2653 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2654 | switch (adapter->link_speed) { |
| 2655 | case SPEED_10: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2656 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2657 | netdev->tx_queue_len = 10; |
| 2658 | adapter->tx_timeout_factor = 8; |
| 2659 | break; |
| 2660 | case SPEED_100: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2661 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2662 | netdev->tx_queue_len = 100; |
| 2663 | /* maybe add some timeout factor ? */ |
| 2664 | break; |
| 2665 | } |
| 2666 | |
Auke Kok | fe7fe28 | 2006-04-14 19:04:59 -0700 | [diff] [blame] | 2667 | if ((adapter->hw.mac_type == e1000_82571 || |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2668 | adapter->hw.mac_type == e1000_82572) && |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2669 | !txb2b) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2670 | u32 tarc0; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2671 | tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2672 | tarc0 &= ~(1 << 21); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2673 | E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
| 2674 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2675 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2676 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2677 | * some hardware issues */ |
| 2678 | if (!adapter->tso_force && |
| 2679 | adapter->hw.bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2680 | switch (adapter->link_speed) { |
| 2681 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2682 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2683 | DPRINTK(PROBE,INFO, |
| 2684 | "10/100 speed: disabling TSO\n"); |
| 2685 | netdev->features &= ~NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2686 | netdev->features &= ~NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2687 | break; |
| 2688 | case SPEED_1000: |
| 2689 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2690 | netdev->features |= NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2691 | break; |
| 2692 | default: |
| 2693 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2694 | break; |
| 2695 | } |
| 2696 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2697 | |
| 2698 | /* enable transmits in the hardware, need to do this |
| 2699 | * after setting TARC0 */ |
| 2700 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2701 | tctl |= E1000_TCTL_EN; |
| 2702 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | netif_carrier_on(netdev); |
| 2705 | netif_wake_queue(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2706 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | adapter->smartspeed = 0; |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2708 | } else { |
| 2709 | /* make sure the receive unit is started */ |
| 2710 | if (adapter->hw.rx_needs_kicking) { |
| 2711 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2712 | u32 rctl = E1000_READ_REG(hw, RCTL); |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2713 | E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN); |
| 2714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | } |
| 2716 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2717 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | adapter->link_speed = 0; |
| 2719 | adapter->link_duplex = 0; |
| 2720 | DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
| 2721 | netif_carrier_off(netdev); |
| 2722 | netif_stop_queue(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2723 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2724 | |
| 2725 | /* 80003ES2LAN workaround-- |
| 2726 | * For packet buffer work-around on link down event; |
| 2727 | * disable receives in the ISR and |
| 2728 | * reset device here in the watchdog |
| 2729 | */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 2730 | if (adapter->hw.mac_type == e1000_80003es2lan) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2731 | /* reset device */ |
| 2732 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | e1000_smartspeed(adapter); |
| 2736 | } |
| 2737 | |
| 2738 | e1000_update_stats(adapter); |
| 2739 | |
| 2740 | adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2741 | adapter->tpt_old = adapter->stats.tpt; |
| 2742 | adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2743 | adapter->colc_old = adapter->stats.colc; |
| 2744 | |
| 2745 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2746 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2747 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2748 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2749 | |
| 2750 | e1000_update_adaptive(&adapter->hw); |
| 2751 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2752 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2753 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | /* We've lost link, so the controller stops DMA, |
| 2755 | * but we've got queued Tx work that's never going |
| 2756 | * to get done, so reset controller to flush Tx. |
| 2757 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2758 | adapter->tx_timeout_count++; |
| 2759 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | } |
| 2761 | } |
| 2762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | /* Cause software interrupt to ensure rx ring is cleaned */ |
| 2764 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
| 2765 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2766 | /* Force detection of hung controller every watchdog period */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2767 | adapter->detect_tx_hung = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2769 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2770 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
| 2771 | if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
| 2772 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | /* Reset the timer */ |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2775 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2778 | enum latency_range { |
| 2779 | lowest_latency = 0, |
| 2780 | low_latency = 1, |
| 2781 | bulk_latency = 2, |
| 2782 | latency_invalid = 255 |
| 2783 | }; |
| 2784 | |
| 2785 | /** |
| 2786 | * e1000_update_itr - update the dynamic ITR value based on statistics |
| 2787 | * Stores a new ITR value based on packets and byte |
| 2788 | * counts during the last interrupt. The advantage of per interrupt |
| 2789 | * computation is faster updates and more accurate ITR for the current |
| 2790 | * traffic pattern. Constants in this function were computed |
| 2791 | * based on theoretical maximum wire speed and thresholds were set based |
| 2792 | * on testing data as well as attempting to minimize response time |
| 2793 | * while increasing bulk throughput. |
| 2794 | * this functionality is controlled by the InterruptThrottleRate module |
| 2795 | * parameter (see e1000_param.c) |
| 2796 | * @adapter: pointer to adapter |
| 2797 | * @itr_setting: current adapter->itr |
| 2798 | * @packets: the number of packets during this measurement interval |
| 2799 | * @bytes: the number of bytes during this measurement interval |
| 2800 | **/ |
| 2801 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2802 | u16 itr_setting, |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2803 | int packets, |
| 2804 | int bytes) |
| 2805 | { |
| 2806 | unsigned int retval = itr_setting; |
| 2807 | struct e1000_hw *hw = &adapter->hw; |
| 2808 | |
| 2809 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2810 | goto update_itr_done; |
| 2811 | |
| 2812 | if (packets == 0) |
| 2813 | goto update_itr_done; |
| 2814 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2815 | switch (itr_setting) { |
| 2816 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2817 | /* jumbo frames get bulk treatment*/ |
| 2818 | if (bytes/packets > 8000) |
| 2819 | retval = bulk_latency; |
| 2820 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2821 | retval = low_latency; |
| 2822 | break; |
| 2823 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2824 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2825 | /* jumbo frames need bulk latency setting */ |
| 2826 | if (bytes/packets > 8000) |
| 2827 | retval = bulk_latency; |
| 2828 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2829 | retval = bulk_latency; |
| 2830 | else if ((packets > 35)) |
| 2831 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2832 | } else if (bytes/packets > 2000) |
| 2833 | retval = bulk_latency; |
| 2834 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2835 | retval = lowest_latency; |
| 2836 | break; |
| 2837 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2838 | if (bytes > 25000) { |
| 2839 | if (packets > 35) |
| 2840 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2841 | } else if (bytes < 6000) { |
| 2842 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2843 | } |
| 2844 | break; |
| 2845 | } |
| 2846 | |
| 2847 | update_itr_done: |
| 2848 | return retval; |
| 2849 | } |
| 2850 | |
| 2851 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2852 | { |
| 2853 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2854 | u16 current_itr; |
| 2855 | u32 new_itr = adapter->itr; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2856 | |
| 2857 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2858 | return; |
| 2859 | |
| 2860 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2861 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2862 | current_itr = 0; |
| 2863 | new_itr = 4000; |
| 2864 | goto set_itr_now; |
| 2865 | } |
| 2866 | |
| 2867 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2868 | adapter->tx_itr, |
| 2869 | adapter->total_tx_packets, |
| 2870 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2871 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2872 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2873 | adapter->tx_itr = low_latency; |
| 2874 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2875 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2876 | adapter->rx_itr, |
| 2877 | adapter->total_rx_packets, |
| 2878 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2879 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2880 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2881 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2882 | |
| 2883 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2884 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2885 | switch (current_itr) { |
| 2886 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2887 | case lowest_latency: |
| 2888 | new_itr = 70000; |
| 2889 | break; |
| 2890 | case low_latency: |
| 2891 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2892 | break; |
| 2893 | case bulk_latency: |
| 2894 | new_itr = 4000; |
| 2895 | break; |
| 2896 | default: |
| 2897 | break; |
| 2898 | } |
| 2899 | |
| 2900 | set_itr_now: |
| 2901 | if (new_itr != adapter->itr) { |
| 2902 | /* this attempts to bias the interrupt rate towards Bulk |
| 2903 | * by adding intermediate steps when interrupt rate is |
| 2904 | * increasing */ |
| 2905 | new_itr = new_itr > adapter->itr ? |
| 2906 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2907 | new_itr; |
| 2908 | adapter->itr = new_itr; |
| 2909 | E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256)); |
| 2910 | } |
| 2911 | |
| 2912 | return; |
| 2913 | } |
| 2914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2916 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2917 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2918 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2920 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2921 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 2922 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2923 | e1000_tso(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 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2929 | u32 cmd_length = 0; |
| 2930 | u16 ipcse = 0, tucse, mss; |
| 2931 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | int err; |
| 2933 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2934 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | if (skb_header_cloned(skb)) { |
| 2936 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2937 | if (err) |
| 2938 | return err; |
| 2939 | } |
| 2940 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2941 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2942 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2943 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2944 | struct iphdr *iph = ip_hdr(skb); |
| 2945 | iph->tot_len = 0; |
| 2946 | iph->check = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2947 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2948 | iph->daddr, 0, |
| 2949 | IPPROTO_TCP, |
| 2950 | 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2951 | cmd_length = E1000_TXD_CMD_IP; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2952 | ipcse = skb_transport_offset(skb) - 1; |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2953 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2954 | ipv6_hdr(skb)->payload_len = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2955 | tcp_hdr(skb)->check = |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2956 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2957 | &ipv6_hdr(skb)->daddr, |
| 2958 | 0, IPPROTO_TCP, 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2959 | ipcse = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2960 | } |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 2961 | ipcss = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2962 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2963 | tucss = skb_transport_offset(skb); |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2964 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | tucse = 0; |
| 2966 | |
| 2967 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2968 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2970 | i = tx_ring->next_to_use; |
| 2971 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2972 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | |
| 2974 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2975 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2976 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2977 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2978 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2979 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2980 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2981 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2982 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2983 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2984 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2985 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2986 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2987 | if (++i == tx_ring->count) i = 0; |
| 2988 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2990 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2992 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2995 | static bool |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2996 | e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2997 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | { |
| 2999 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3000 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3002 | u8 css; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3004 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 3005 | css = skb_transport_offset(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3007 | i = tx_ring->next_to_use; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3008 | buffer_info = &tx_ring->buffer_info[i]; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3009 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
Bruce Allan | f6c57ba | 2007-01-18 09:25:28 -0800 | [diff] [blame] | 3011 | context_desc->lower_setup.ip_config = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | context_desc->upper_setup.tcp_fields.tucss = css; |
Herbert Xu | 628592c | 2007-04-23 17:06:40 -0700 | [diff] [blame] | 3013 | context_desc->upper_setup.tcp_fields.tucso = |
| 3014 | css + skb->csum_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 3016 | context_desc->tcp_seg_setup.data = 0; |
| 3017 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 3018 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3019 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3020 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 3021 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3022 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 3023 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3025 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3028 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | #define E1000_MAX_TXD_PWR 12 |
| 3032 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 3033 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3034 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3035 | e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3036 | struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
| 3037 | unsigned int nr_frags, unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | struct e1000_buffer *buffer_info; |
| 3040 | unsigned int len = skb->len; |
| 3041 | unsigned int offset = 0, size, count = 0, i; |
| 3042 | unsigned int f; |
| 3043 | len -= skb->data_len; |
| 3044 | |
| 3045 | i = tx_ring->next_to_use; |
| 3046 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3047 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | buffer_info = &tx_ring->buffer_info[i]; |
| 3049 | size = min(len, max_per_txd); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3050 | /* Workaround for Controller erratum -- |
| 3051 | * descriptor for non-tso packet in a linear SKB that follows a |
| 3052 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3053 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3054 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3055 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3056 | tx_ring->last_tx_tso = 0; |
| 3057 | size -= 4; |
| 3058 | } |
| 3059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | /* Workaround for premature desc write-backs |
| 3061 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3062 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | size -= 4; |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3064 | /* work-around for errata 10 and it applies |
| 3065 | * to all controllers in PCI-X mode |
| 3066 | * The fix is to make sure that the first descriptor of a |
| 3067 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 3068 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3069 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3070 | (size > 2015) && count == 0)) |
| 3071 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 3074 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3075 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 3077 | size > 4)) |
| 3078 | size -= 4; |
| 3079 | |
| 3080 | buffer_info->length = size; |
| 3081 | buffer_info->dma = |
| 3082 | pci_map_single(adapter->pdev, |
| 3083 | skb->data + offset, |
| 3084 | size, |
| 3085 | PCI_DMA_TODEVICE); |
| 3086 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3087 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | |
| 3089 | len -= size; |
| 3090 | offset += size; |
| 3091 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3092 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3095 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | struct skb_frag_struct *frag; |
| 3097 | |
| 3098 | frag = &skb_shinfo(skb)->frags[f]; |
| 3099 | len = frag->size; |
| 3100 | offset = frag->page_offset; |
| 3101 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3102 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | buffer_info = &tx_ring->buffer_info[i]; |
| 3104 | size = min(len, max_per_txd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | /* Workaround for premature desc write-backs |
| 3106 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3107 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | size -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | /* Workaround for potential 82544 hang in PCI-X. |
| 3110 | * Avoid terminating buffers within evenly-aligned |
| 3111 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3112 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 3114 | size > 4)) |
| 3115 | size -= 4; |
| 3116 | |
| 3117 | buffer_info->length = size; |
| 3118 | buffer_info->dma = |
| 3119 | pci_map_page(adapter->pdev, |
| 3120 | frag->page, |
| 3121 | offset, |
| 3122 | size, |
| 3123 | PCI_DMA_TODEVICE); |
| 3124 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3125 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | |
| 3127 | len -= size; |
| 3128 | offset += size; |
| 3129 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3130 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 3135 | tx_ring->buffer_info[i].skb = skb; |
| 3136 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3137 | |
| 3138 | return count; |
| 3139 | } |
| 3140 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3141 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3142 | e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 3143 | int tx_flags, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | struct e1000_tx_desc *tx_desc = NULL; |
| 3146 | struct e1000_buffer *buffer_info; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3147 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | unsigned int i; |
| 3149 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3150 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3152 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3153 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3154 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3155 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3156 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3159 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3161 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3162 | } |
| 3163 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3164 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3166 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3167 | } |
| 3168 | |
| 3169 | i = tx_ring->next_to_use; |
| 3170 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3171 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | buffer_info = &tx_ring->buffer_info[i]; |
| 3173 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3174 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3175 | tx_desc->lower.data = |
| 3176 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3177 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3178 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3182 | |
| 3183 | /* Force memory writes to complete before letting h/w |
| 3184 | * know there are new descriptors to fetch. (Only |
| 3185 | * applicable for weak-ordered memory model archs, |
| 3186 | * such as IA-64). */ |
| 3187 | wmb(); |
| 3188 | |
| 3189 | tx_ring->next_to_use = i; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3190 | writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 3191 | /* we need this if more than one processor can write to our tail |
| 3192 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3193 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | /** |
| 3197 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 3198 | * The workaround is to avoid queuing a large packet that would span |
| 3199 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 3200 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 3201 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 3202 | * to the beginning of the Tx FIFO. |
| 3203 | **/ |
| 3204 | |
| 3205 | #define E1000_FIFO_HDR 0x10 |
| 3206 | #define E1000_82547_PAD_LEN 0x3E0 |
| 3207 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3208 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3210 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3211 | u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 3212 | u32 skb_fifo_len = skb->len + E1000_FIFO_HDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 3214 | skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3216 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | goto no_fifo_stall_required; |
| 3218 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3219 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | return 1; |
| 3221 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3222 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3224 | return 1; |
| 3225 | } |
| 3226 | |
| 3227 | no_fifo_stall_required: |
| 3228 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3229 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3231 | return 0; |
| 3232 | } |
| 3233 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3234 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 3235 | static int |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3236 | e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 3237 | { |
| 3238 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3239 | u16 length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3240 | if (vlan_tx_tag_present(skb)) { |
| 3241 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3242 | ( adapter->hw.mng_cookie.status & |
| 3243 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 3244 | return 0; |
| 3245 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 3246 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3247 | struct ethhdr *eth = (struct ethhdr *) skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3248 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 3249 | const struct iphdr *ip = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3250 | (struct iphdr *)((u8 *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3251 | if (IPPROTO_UDP == ip->protocol) { |
| 3252 | struct udphdr *udp = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3253 | (struct udphdr *)((u8 *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3254 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3255 | if (ntohs(udp->dest) == 67) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3256 | offset = (u8 *)udp + 8 - skb->data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3257 | length = skb->len - offset; |
| 3258 | |
| 3259 | return e1000_mng_write_dhcp_info(hw, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3260 | (u8 *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3261 | length); |
| 3262 | } |
| 3263 | } |
| 3264 | } |
| 3265 | } |
| 3266 | return 0; |
| 3267 | } |
| 3268 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3269 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3270 | { |
| 3271 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3272 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3273 | |
| 3274 | netif_stop_queue(netdev); |
| 3275 | /* Herbert's original patch had: |
| 3276 | * smp_mb__after_netif_stop_queue(); |
| 3277 | * but since that doesn't exist yet, just open code it. */ |
| 3278 | smp_mb(); |
| 3279 | |
| 3280 | /* We need to check again in a case another CPU has just |
| 3281 | * made room available. */ |
| 3282 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3283 | return -EBUSY; |
| 3284 | |
| 3285 | /* A reprieve! */ |
| 3286 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3287 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3288 | return 0; |
| 3289 | } |
| 3290 | |
| 3291 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3292 | struct e1000_tx_ring *tx_ring, int size) |
| 3293 | { |
| 3294 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3295 | return 0; |
| 3296 | return __e1000_maybe_stop_tx(netdev, size); |
| 3297 | } |
| 3298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 3300 | static int |
| 3301 | e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 3302 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3303 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3304 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3306 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3307 | unsigned int tx_flags = 0; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3308 | unsigned int len = skb->len - skb->data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | unsigned long flags; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3310 | unsigned int nr_frags; |
| 3311 | unsigned int mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3313 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3316 | /* This goes back to the question of how to logically map a tx queue |
| 3317 | * to a flow. Right now, performance is impacted slightly negatively |
| 3318 | * if using multiple tx queues. If the stack breaks away from a |
| 3319 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3320 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3321 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3322 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | dev_kfree_skb_any(skb); |
| 3324 | return NETDEV_TX_OK; |
| 3325 | } |
| 3326 | |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3327 | /* 82571 and newer doesn't need the workaround that limited descriptor |
| 3328 | * length to 4kB */ |
| 3329 | if (adapter->hw.mac_type >= e1000_82571) |
| 3330 | max_per_txd = 8192; |
| 3331 | |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3332 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3333 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | * make sure there is enough room in the FIFO before |
| 3335 | * initiating the DMA for each buffer. The calc is: |
| 3336 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3337 | * overrun the FIFO, adjust the max buffer len if mss |
| 3338 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3339 | if (mss) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3340 | u8 hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | max_per_txd = min(mss << 2, max_per_txd); |
| 3342 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3343 | |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3344 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3345 | * points to just header, pull a few bytes of payload from |
| 3346 | * frags into skb->data */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 3347 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3348 | if (skb->data_len && hdr_len == len) { |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3349 | switch (adapter->hw.mac_type) { |
| 3350 | unsigned int pull_size; |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3351 | case e1000_82544: |
| 3352 | /* Make sure we have room to chop off 4 bytes, |
| 3353 | * and that the end alignment will work out to |
| 3354 | * this hardware's requirements |
| 3355 | * NOTE: this is a TSO only workaround |
| 3356 | * if end byte alignment not correct move us |
| 3357 | * into the next dword */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3358 | if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3359 | break; |
| 3360 | /* fall through */ |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3361 | case e1000_82571: |
| 3362 | case e1000_82572: |
| 3363 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3364 | case e1000_ich8lan: |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3365 | pull_size = min((unsigned int)4, skb->data_len); |
| 3366 | if (!__pskb_pull_tail(skb, pull_size)) { |
Auke Kok | a5eafce | 2006-06-27 09:06:49 -0700 | [diff] [blame] | 3367 | DPRINTK(DRV, ERR, |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3368 | "__pskb_pull_tail failed.\n"); |
| 3369 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc70 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3370 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3371 | } |
| 3372 | len = skb->len - skb->data_len; |
| 3373 | break; |
| 3374 | default: |
| 3375 | /* do nothing */ |
| 3376 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3377 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3381 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3382 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3384 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3385 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3386 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3387 | 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] | 3388 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3391 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3392 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | count++; |
| 3394 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3395 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3396 | * in PCI-X mode, so add one more descriptor to the count |
| 3397 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3398 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3399 | (len > 2015))) |
| 3400 | count++; |
| 3401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3403 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3405 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3406 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | count += nr_frags; |
| 3408 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3409 | |
| 3410 | if (adapter->hw.tx_pkt_filtering && |
| 3411 | (adapter->hw.mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3412 | e1000_transfer_dhcp_info(adapter, skb); |
| 3413 | |
Mark Huth | f50393f | 2007-03-06 08:57:26 -0800 | [diff] [blame] | 3414 | if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3415 | /* Collision - tell upper layer to requeue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3416 | return NETDEV_TX_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | |
| 3418 | /* need: count + 2 desc gap to keep tail from touching |
| 3419 | * head, otherwise try next time */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3420 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3421 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | return NETDEV_TX_BUSY; |
| 3423 | } |
| 3424 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3425 | if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
| 3426 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | netif_stop_queue(netdev); |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3428 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3429 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | return NETDEV_TX_BUSY; |
| 3431 | } |
| 3432 | } |
| 3433 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3434 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3436 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3437 | } |
| 3438 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3439 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3440 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3441 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | if (tso < 0) { |
| 3443 | dev_kfree_skb_any(skb); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3444 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | return NETDEV_TX_OK; |
| 3446 | } |
| 3447 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3448 | if (likely(tso)) { |
| 3449 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3451 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3453 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3454 | /* 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] | 3455 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3456 | * no longer assume, we must. */ |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3457 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3458 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3459 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3460 | e1000_tx_queue(adapter, tx_ring, tx_flags, |
| 3461 | e1000_tx_map(adapter, tx_ring, skb, first, |
| 3462 | max_per_txd, nr_frags, mss)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | |
| 3464 | netdev->trans_start = jiffies; |
| 3465 | |
| 3466 | /* Make sure there is space in the ring for the next send. */ |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3467 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3469 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | return NETDEV_TX_OK; |
| 3471 | } |
| 3472 | |
| 3473 | /** |
| 3474 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3475 | * @netdev: network interface device structure |
| 3476 | **/ |
| 3477 | |
| 3478 | static void |
| 3479 | e1000_tx_timeout(struct net_device *netdev) |
| 3480 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3481 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | |
| 3483 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3484 | adapter->tx_timeout_count++; |
| 3485 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | static void |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3489 | e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3491 | struct e1000_adapter *adapter = |
| 3492 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3494 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | /** |
| 3498 | * e1000_get_stats - Get System Network Statistics |
| 3499 | * @netdev: network interface device structure |
| 3500 | * |
| 3501 | * Returns the address of the device statistics structure. |
| 3502 | * The statistics are actually updated from the timer callback. |
| 3503 | **/ |
| 3504 | |
| 3505 | static struct net_device_stats * |
| 3506 | e1000_get_stats(struct net_device *netdev) |
| 3507 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3508 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3510 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | return &adapter->net_stats; |
| 3512 | } |
| 3513 | |
| 3514 | /** |
| 3515 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3516 | * @netdev: network interface device structure |
| 3517 | * @new_mtu: new value for maximum frame size |
| 3518 | * |
| 3519 | * Returns 0 on success, negative on failure |
| 3520 | **/ |
| 3521 | |
| 3522 | static int |
| 3523 | e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 3524 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3525 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3527 | u16 eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3529 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3530 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3531 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3532 | return -EINVAL; |
| 3533 | } |
| 3534 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3535 | /* Adapter-specific max frame size limits. */ |
| 3536 | switch (adapter->hw.mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3537 | case e1000_undefined ... e1000_82542_rev2_1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3538 | case e1000_ich8lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3539 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3540 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3541 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3542 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3543 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3544 | case e1000_82573: |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3545 | /* Jumbo Frames not supported if: |
| 3546 | * - this is not an 82573L device |
| 3547 | * - ASPM is enabled in any way (0x1A bits 3:2) */ |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3548 | e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
| 3549 | &eeprom_data); |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3550 | if ((adapter->hw.device_id != E1000_DEV_ID_82573L) || |
| 3551 | (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3552 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3553 | DPRINTK(PROBE, ERR, |
| 3554 | "Jumbo Frames not supported.\n"); |
| 3555 | return -EINVAL; |
| 3556 | } |
| 3557 | break; |
| 3558 | } |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3559 | /* ERT will be enabled later to enable wire speed receives */ |
| 3560 | |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3561 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3562 | case e1000_82571: |
| 3563 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3564 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3565 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3566 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3567 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3568 | return -EINVAL; |
| 3569 | } |
| 3570 | break; |
| 3571 | default: |
| 3572 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3573 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3576 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3577 | * means we reserve 2 more, this pushes us to allocate from the next |
| 3578 | * larger slab size |
| 3579 | * i.e. RXBUFFER_2048 --> size-4096 slab */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3580 | |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3581 | if (max_frame <= E1000_RXBUFFER_256) |
| 3582 | adapter->rx_buffer_len = E1000_RXBUFFER_256; |
| 3583 | else if (max_frame <= E1000_RXBUFFER_512) |
| 3584 | adapter->rx_buffer_len = E1000_RXBUFFER_512; |
| 3585 | else if (max_frame <= E1000_RXBUFFER_1024) |
| 3586 | adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
| 3587 | else if (max_frame <= E1000_RXBUFFER_2048) |
| 3588 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
| 3589 | else if (max_frame <= E1000_RXBUFFER_4096) |
| 3590 | adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
| 3591 | else if (max_frame <= E1000_RXBUFFER_8192) |
| 3592 | adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
| 3593 | else if (max_frame <= E1000_RXBUFFER_16384) |
| 3594 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
| 3595 | |
| 3596 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3597 | if (!adapter->hw.tbi_compatibility_on && |
| 3598 | ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
| 3599 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3600 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3601 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3602 | netdev->mtu = new_mtu; |
Bruce Allan | 83cd827 | 2006-12-15 10:36:35 +0100 | [diff] [blame] | 3603 | adapter->hw.max_frame_size = max_frame; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3604 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3605 | if (netif_running(netdev)) |
| 3606 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | return 0; |
| 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * e1000_update_stats - Update the board statistics counters |
| 3613 | * @adapter: board private structure |
| 3614 | **/ |
| 3615 | |
| 3616 | void |
| 3617 | e1000_update_stats(struct e1000_adapter *adapter) |
| 3618 | { |
| 3619 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3620 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3622 | u16 phy_tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | |
| 3624 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3625 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3626 | /* |
| 3627 | * Prevent stats update while adapter is being reset, or if the pci |
| 3628 | * connection is down. |
| 3629 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3630 | if (adapter->link_speed == 0) |
| 3631 | return; |
Linas Vepstas | 81b1955 | 2006-12-12 18:29:15 -0600 | [diff] [blame] | 3632 | if (pci_channel_offline(pdev)) |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3633 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3636 | |
Masatake YAMATO | 828d055 | 2007-10-20 03:06:37 +0200 | [diff] [blame] | 3637 | /* these counters are modified from e1000_tbi_adjust_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | * called from the interrupt context, so they must only |
| 3639 | * be written while holding adapter->stats_lock |
| 3640 | */ |
| 3641 | |
| 3642 | adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
| 3643 | adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
| 3644 | adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
| 3645 | adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
| 3646 | adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
| 3647 | adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
| 3648 | adapter->stats.roc += E1000_READ_REG(hw, ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3649 | |
| 3650 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3651 | adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
| 3652 | adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
| 3653 | adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
| 3654 | adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
| 3655 | adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
| 3656 | adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | |
| 3659 | adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
| 3660 | adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
| 3661 | adapter->stats.scc += E1000_READ_REG(hw, SCC); |
| 3662 | adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
| 3663 | adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
| 3664 | adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
| 3665 | adapter->stats.dc += E1000_READ_REG(hw, DC); |
| 3666 | adapter->stats.sec += E1000_READ_REG(hw, SEC); |
| 3667 | adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
| 3668 | adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
| 3669 | adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
| 3670 | adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
| 3671 | adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
| 3672 | adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
| 3673 | adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
| 3674 | adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
| 3675 | adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
| 3676 | adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
| 3677 | adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
| 3678 | adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
| 3679 | adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
| 3680 | adapter->stats.torl += E1000_READ_REG(hw, TORL); |
| 3681 | adapter->stats.torh += E1000_READ_REG(hw, TORH); |
| 3682 | adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
| 3683 | adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
| 3684 | adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3685 | |
| 3686 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3687 | adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
| 3688 | adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
| 3689 | adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
| 3690 | adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
| 3691 | adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
| 3692 | adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
| 3696 | adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
| 3697 | |
| 3698 | /* used for adaptive IFS */ |
| 3699 | |
| 3700 | hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
| 3701 | adapter->stats.tpt += hw->tx_packet_delta; |
| 3702 | hw->collision_delta = E1000_READ_REG(hw, COLC); |
| 3703 | adapter->stats.colc += hw->collision_delta; |
| 3704 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3705 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
| 3707 | adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
| 3708 | adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
| 3709 | adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
| 3710 | adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
| 3711 | adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
| 3712 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3713 | if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3714 | adapter->stats.iac += E1000_READ_REG(hw, IAC); |
| 3715 | adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3716 | |
| 3717 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3718 | adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
| 3719 | adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
| 3720 | adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
| 3721 | adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
| 3722 | adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
| 3723 | adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
| 3724 | adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3725 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | |
| 3728 | /* Fill out the OS statistics structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3730 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3731 | |
| 3732 | /* Rx Errors */ |
| 3733 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3734 | /* RLEC on some newer hardware can be incorrect so build |
| 3735 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3737 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3738 | adapter->stats.ruc + adapter->stats.roc + |
| 3739 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3740 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
| 3741 | adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3743 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3745 | |
| 3746 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3747 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
| 3748 | adapter->net_stats.tx_errors = adapter->stats.txerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3750 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3751 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3752 | if (adapter->hw.bad_tx_carr_stats_fd && |
| 3753 | adapter->link_duplex == FULL_DUPLEX) { |
| 3754 | adapter->net_stats.tx_carrier_errors = 0; |
| 3755 | adapter->stats.tncrs = 0; |
| 3756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | |
| 3758 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3759 | |
| 3760 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3761 | if (hw->media_type == e1000_media_type_copper) { |
| 3762 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3764 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3765 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3766 | } |
| 3767 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3768 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | (hw->phy_type == e1000_phy_m88) && |
| 3770 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3771 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3772 | } |
| 3773 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3774 | /* Management Stats */ |
| 3775 | if (adapter->hw.has_smbus) { |
| 3776 | adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC); |
| 3777 | adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC); |
| 3778 | adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC); |
| 3779 | } |
| 3780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3782 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3783 | |
| 3784 | /** |
| 3785 | * e1000_intr_msi - Interrupt Handler |
| 3786 | * @irq: interrupt number |
| 3787 | * @data: pointer to a network interface device structure |
| 3788 | **/ |
| 3789 | |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3790 | static irqreturn_t |
| 3791 | e1000_intr_msi(int irq, void *data) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3792 | { |
| 3793 | struct net_device *netdev = data; |
| 3794 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3795 | struct e1000_hw *hw = &adapter->hw; |
| 3796 | #ifndef CONFIG_E1000_NAPI |
| 3797 | int i; |
| 3798 | #endif |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3799 | u32 icr = E1000_READ_REG(hw, ICR); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3800 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3801 | /* in NAPI mode read ICR disables interrupts using IAM */ |
| 3802 | |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3803 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 3804 | hw->get_link_status = 1; |
| 3805 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
| 3806 | * link down event; disable receives here in the ISR and reset |
| 3807 | * adapter in watchdog */ |
| 3808 | if (netif_carrier_ok(netdev) && |
| 3809 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3810 | /* disable receives */ |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3811 | u32 rctl = E1000_READ_REG(hw, RCTL); |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3812 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3813 | } |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3814 | /* guard against interrupt when we're going down */ |
| 3815 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3816 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | #ifdef CONFIG_E1000_NAPI |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3820 | if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3821 | adapter->total_tx_bytes = 0; |
| 3822 | adapter->total_tx_packets = 0; |
| 3823 | adapter->total_rx_bytes = 0; |
| 3824 | adapter->total_rx_packets = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3825 | __netif_rx_schedule(netdev, &adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3826 | } else |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3827 | e1000_irq_enable(adapter); |
| 3828 | #else |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3829 | adapter->total_tx_bytes = 0; |
| 3830 | adapter->total_rx_bytes = 0; |
| 3831 | adapter->total_tx_packets = 0; |
| 3832 | adapter->total_rx_packets = 0; |
| 3833 | |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3834 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3835 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3836 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3837 | break; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3838 | |
| 3839 | if (likely(adapter->itr_setting & 3)) |
| 3840 | e1000_set_itr(adapter); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3841 | #endif |
| 3842 | |
| 3843 | return IRQ_HANDLED; |
| 3844 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | |
| 3846 | /** |
| 3847 | * e1000_intr - Interrupt Handler |
| 3848 | * @irq: interrupt number |
| 3849 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | **/ |
| 3851 | |
| 3852 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3853 | e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3854 | { |
| 3855 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3856 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3858 | u32 rctl, icr = E1000_READ_REG(hw, ICR); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3859 | #ifndef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3860 | int i; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3861 | #endif |
| 3862 | if (unlikely(!icr)) |
| 3863 | return IRQ_NONE; /* Not our interrupt */ |
| 3864 | |
| 3865 | #ifdef CONFIG_E1000_NAPI |
| 3866 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 3867 | * not set, then the adapter didn't send an interrupt */ |
| 3868 | if (unlikely(hw->mac_type >= e1000_82571 && |
| 3869 | !(icr & E1000_ICR_INT_ASSERTED))) |
| 3870 | return IRQ_NONE; |
| 3871 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3872 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
| 3873 | * need for the IMC write */ |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 3874 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3876 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3878 | /* 80003ES2LAN workaround-- |
| 3879 | * For packet buffer work-around on link down event; |
| 3880 | * disable receives here in the ISR and |
| 3881 | * reset adapter in watchdog |
| 3882 | */ |
| 3883 | if (netif_carrier_ok(netdev) && |
| 3884 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3885 | /* disable receives */ |
| 3886 | rctl = E1000_READ_REG(hw, RCTL); |
| 3887 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3888 | } |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3889 | /* guard against interrupt when we're going down */ |
| 3890 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3891 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3895 | if (unlikely(hw->mac_type < e1000_82571)) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3896 | /* disable interrupts, without the synchronize_irq bit */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3897 | E1000_WRITE_REG(hw, IMC, ~0); |
| 3898 | E1000_WRITE_FLUSH(hw); |
| 3899 | } |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3900 | if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3901 | adapter->total_tx_bytes = 0; |
| 3902 | adapter->total_tx_packets = 0; |
| 3903 | adapter->total_rx_bytes = 0; |
| 3904 | adapter->total_rx_packets = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3905 | __netif_rx_schedule(netdev, &adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3906 | } else |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3907 | /* this really should not happen! if it does it is basically a |
| 3908 | * bug, but not a hard error, so enable ints and continue */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3909 | e1000_irq_enable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3910 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | /* Writing IMC and IMS is needed for 82547. |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3912 | * Due to Hub Link bus being occupied, an interrupt |
| 3913 | * de-assertion message is not able to be sent. |
| 3914 | * When an interrupt assertion message is generated later, |
| 3915 | * two messages are re-ordered and sent out. |
| 3916 | * That causes APIC to think 82547 is in de-assertion |
| 3917 | * state, while 82547 is in assertion state, resulting |
| 3918 | * in dead lock. Writing IMC forces 82547 into |
| 3919 | * de-assertion state. |
| 3920 | */ |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3921 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3922 | E1000_WRITE_REG(hw, IMC, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3924 | adapter->total_tx_bytes = 0; |
| 3925 | adapter->total_rx_bytes = 0; |
| 3926 | adapter->total_tx_packets = 0; |
| 3927 | adapter->total_rx_packets = 0; |
| 3928 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3929 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3930 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 3931 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | break; |
| 3933 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3934 | if (likely(adapter->itr_setting & 3)) |
| 3935 | e1000_set_itr(adapter); |
| 3936 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3937 | 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] | 3938 | e1000_irq_enable(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3939 | |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3940 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | return IRQ_HANDLED; |
| 3942 | } |
| 3943 | |
| 3944 | #ifdef CONFIG_E1000_NAPI |
| 3945 | /** |
| 3946 | * e1000_clean - NAPI Rx polling callback |
| 3947 | * @adapter: board private structure |
| 3948 | **/ |
| 3949 | |
| 3950 | static int |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3951 | e1000_clean(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3953 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
| 3954 | struct net_device *poll_dev = adapter->netdev; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3955 | int tx_cleaned = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3956 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3957 | /* Must NOT use netdev_priv macro here. */ |
| 3958 | adapter = poll_dev->priv; |
| 3959 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3960 | /* e1000_clean is called per-cpu. This lock protects |
| 3961 | * tx_ring[0] from being cleaned by multiple cpus |
| 3962 | * simultaneously. A failure obtaining the lock means |
| 3963 | * tx_ring[0] is currently being cleaned anyway. */ |
| 3964 | if (spin_trylock(&adapter->tx_queue_lock)) { |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3965 | tx_cleaned = e1000_clean_tx_irq(adapter, |
| 3966 | &adapter->tx_ring[0]); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3967 | spin_unlock(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3968 | } |
| 3969 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3970 | adapter->clean_rx(adapter, &adapter->rx_ring[0], |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3971 | &work_done, budget); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3972 | |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3973 | if (tx_cleaned) |
| 3974 | work_done = budget; |
| 3975 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3976 | /* If budget not fully consumed, exit the polling mode */ |
| 3977 | if (work_done < budget) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3978 | if (likely(adapter->itr_setting & 3)) |
| 3979 | e1000_set_itr(adapter); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3980 | netif_rx_complete(poll_dev, napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3984 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | #endif |
| 3988 | /** |
| 3989 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3990 | * @adapter: board private structure |
| 3991 | **/ |
| 3992 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3993 | static bool |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3994 | e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3995 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | struct net_device *netdev = adapter->netdev; |
| 3998 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3999 | struct e1000_buffer *buffer_info; |
| 4000 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 4001 | #ifdef CONFIG_E1000_NAPI |
| 4002 | unsigned int count = 0; |
| 4003 | #endif |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4004 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4005 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | |
| 4007 | i = tx_ring->next_to_clean; |
| 4008 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 4009 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 4010 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4011 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4012 | for (cleaned = false; !cleaned; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 4014 | buffer_info = &tx_ring->buffer_info[i]; |
| 4015 | cleaned = (i == eop); |
| 4016 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4017 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 4018 | struct sk_buff *skb = buffer_info->skb; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 4019 | unsigned int segs, bytecount; |
| 4020 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 4021 | /* multiply data chunks by size of headers */ |
| 4022 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 4023 | skb->len; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 4024 | total_tx_packets += segs; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 4025 | total_tx_bytes += bytecount; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4026 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 4027 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 4028 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4030 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 4034 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 4035 | #ifdef CONFIG_E1000_NAPI |
| 4036 | #define E1000_TX_WEIGHT 64 |
| 4037 | /* weight of a sort for tx, to avoid endless transmit cleanup */ |
Linus Torvalds | 46fcc86 | 2007-04-19 18:21:01 -0700 | [diff] [blame] | 4038 | if (count++ == E1000_TX_WEIGHT) break; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 4039 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | tx_ring->next_to_clean = i; |
| 4043 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 4044 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 4045 | if (unlikely(cleaned && netif_carrier_ok(netdev) && |
| 4046 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 4047 | /* Make sure that anybody stopping the queue after this |
| 4048 | * sees the new next_to_clean. |
| 4049 | */ |
| 4050 | smp_mb(); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 4051 | if (netif_queue_stopped(netdev)) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 4052 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 4053 | ++adapter->restart_queue; |
| 4054 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 4055 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4056 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4057 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4058 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | * check with the clearing of time_stamp and movement of i */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4060 | adapter->detect_tx_hung = false; |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4061 | if (tx_ring->buffer_info[eop].dma && |
| 4062 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 4063 | (adapter->tx_timeout_factor * HZ)) |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4064 | && !(E1000_READ_REG(&adapter->hw, STATUS) & |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4065 | E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4066 | |
| 4067 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 4068 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 4069 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4070 | " TDH <%x>\n" |
| 4071 | " TDT <%x>\n" |
| 4072 | " next_to_use <%x>\n" |
| 4073 | " next_to_clean <%x>\n" |
| 4074 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4075 | " time_stamp <%lx>\n" |
| 4076 | " next_to_watch <%x>\n" |
| 4077 | " jiffies <%lx>\n" |
| 4078 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 4079 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 4080 | sizeof(struct e1000_tx_ring)), |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4081 | readl(adapter->hw.hw_addr + tx_ring->tdh), |
| 4082 | readl(adapter->hw.hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4083 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 4084 | tx_ring->next_to_clean, |
| 4085 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4086 | eop, |
| 4087 | jiffies, |
| 4088 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 4090 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4092 | adapter->total_tx_bytes += total_tx_bytes; |
| 4093 | adapter->total_tx_packets += total_tx_packets; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4094 | adapter->net_stats.tx_bytes += total_tx_bytes; |
| 4095 | adapter->net_stats.tx_packets += total_tx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | return cleaned; |
| 4097 | } |
| 4098 | |
| 4099 | /** |
| 4100 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4101 | * @adapter: board private structure |
| 4102 | * @status_err: receive descriptor status and error fields |
| 4103 | * @csum: receive descriptor csum field |
| 4104 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | **/ |
| 4106 | |
Auke Kok | e619d52 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 4107 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | e1000_rx_checksum(struct e1000_adapter *adapter, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4109 | u32 status_err, u32 csum, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4110 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4112 | u16 status = (u16)status_err; |
| 4113 | u8 errors = (u8)(status_err >> 24); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4114 | skb->ip_summed = CHECKSUM_NONE; |
| 4115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | /* 82543 or newer only */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4117 | if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4119 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4120 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4121 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4122 | /* let the stack verify checksum errors */ |
| 4123 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | return; |
| 4125 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4126 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4127 | if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
| 4128 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4129 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4131 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4132 | return; |
| 4133 | } |
| 4134 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4135 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | /* TCP checksum is good */ |
| 4137 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4138 | } else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
| 4139 | /* IP fragment with UDP payload */ |
| 4140 | /* Hardware complements the payload checksum, so we undo it |
| 4141 | * and then put the value in host order for further stack use. |
| 4142 | */ |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 4143 | __sum16 sum = (__force __sum16)htons(csum); |
| 4144 | skb->csum = csum_unfold(~sum); |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 4145 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4147 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4151 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | * @adapter: board private structure |
| 4153 | **/ |
| 4154 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4155 | static bool |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4157 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4158 | struct e1000_rx_ring *rx_ring, |
| 4159 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4161 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4162 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | #endif |
| 4164 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | struct net_device *netdev = adapter->netdev; |
| 4166 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4167 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4168 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4170 | u32 length; |
| 4171 | u8 last_byte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4173 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4174 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4175 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | |
| 4177 | i = rx_ring->next_to_clean; |
| 4178 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4179 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4181 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4182 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4183 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4186 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | break; |
| 4188 | (*work_done)++; |
| 4189 | #endif |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4190 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4191 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4192 | buffer_info->skb = NULL; |
| 4193 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4194 | prefetch(skb->data - NET_IP_ALIGN); |
| 4195 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4196 | if (++i == rx_ring->count) i = 0; |
| 4197 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4198 | prefetch(next_rxd); |
| 4199 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4200 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4201 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4202 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4203 | cleaned_count++; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4204 | pci_unmap_single(pdev, |
| 4205 | buffer_info->dma, |
| 4206 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | PCI_DMA_FROMDEVICE); |
| 4208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | length = le16_to_cpu(rx_desc->length); |
| 4210 | |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4211 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
| 4212 | /* All receives must fit into a single buffer */ |
| 4213 | E1000_DBG("%s: Receive packet consumed multiple" |
| 4214 | " buffers\n", netdev->name); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 4215 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4216 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | goto next_desc; |
| 4218 | } |
| 4219 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4220 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | last_byte = *(skb->data + length - 1); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4222 | if (TBI_ACCEPT(&adapter->hw, status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | rx_desc->errors, length, last_byte)) { |
| 4224 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4225 | e1000_tbi_adjust_stats(&adapter->hw, |
| 4226 | &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | length, skb->data); |
| 4228 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4229 | flags); |
| 4230 | length--; |
| 4231 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4232 | /* recycle */ |
| 4233 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4234 | goto next_desc; |
| 4235 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4238 | /* adjust length to remove Ethernet CRC, this must be |
| 4239 | * done after the TBI_ACCEPT workaround above */ |
| 4240 | length -= 4; |
| 4241 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4242 | /* probably a little skewed due to removing CRC */ |
| 4243 | total_rx_bytes += length; |
| 4244 | total_rx_packets++; |
| 4245 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4246 | /* code added for copybreak, this should improve |
| 4247 | * performance for small packets with large amounts |
| 4248 | * of reassembly being done in the stack */ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4249 | if (length < copybreak) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4250 | struct sk_buff *new_skb = |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4251 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4252 | if (new_skb) { |
| 4253 | skb_reserve(new_skb, NET_IP_ALIGN); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 4254 | skb_copy_to_linear_data_offset(new_skb, |
| 4255 | -NET_IP_ALIGN, |
| 4256 | (skb->data - |
| 4257 | NET_IP_ALIGN), |
| 4258 | (length + |
| 4259 | NET_IP_ALIGN)); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4260 | /* save the skb in buffer_info as good */ |
| 4261 | buffer_info->skb = skb; |
| 4262 | skb = new_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4263 | } |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4264 | /* else just continue with the old one */ |
| 4265 | } |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4266 | /* end copybreak code */ |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4267 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | |
| 4269 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4270 | e1000_rx_checksum(adapter, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4271 | (u32)(status) | |
| 4272 | ((u32)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4273 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | skb->protocol = eth_type_trans(skb, netdev); |
| 4276 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4277 | if (unlikely(adapter->vlgrp && |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4278 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4280 | le16_to_cpu(rx_desc->special) & |
| 4281 | E1000_RXD_SPC_VLAN_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } else { |
| 4283 | netif_receive_skb(skb); |
| 4284 | } |
| 4285 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4286 | if (unlikely(adapter->vlgrp && |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4287 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 4289 | le16_to_cpu(rx_desc->special) & |
| 4290 | E1000_RXD_SPC_VLAN_MASK); |
| 4291 | } else { |
| 4292 | netif_rx(skb); |
| 4293 | } |
| 4294 | #endif /* CONFIG_E1000_NAPI */ |
| 4295 | netdev->last_rx = jiffies; |
| 4296 | |
| 4297 | next_desc: |
| 4298 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4300 | /* return some buffers to hardware, one at a time is too slow */ |
| 4301 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4302 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4303 | cleaned_count = 0; |
| 4304 | } |
| 4305 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4306 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4307 | rx_desc = next_rxd; |
| 4308 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4311 | |
| 4312 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4313 | if (cleaned_count) |
| 4314 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4316 | adapter->total_rx_packets += total_rx_packets; |
| 4317 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4318 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4319 | adapter->net_stats.rx_packets += total_rx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4320 | return cleaned; |
| 4321 | } |
| 4322 | |
| 4323 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4324 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 4325 | * @adapter: board private structure |
| 4326 | **/ |
| 4327 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4328 | static bool |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4329 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4330 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4331 | struct e1000_rx_ring *rx_ring, |
| 4332 | int *work_done, int work_to_do) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4333 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4334 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 4335 | struct e1000_rx_ring *rx_ring) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4336 | #endif |
| 4337 | { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4338 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4339 | struct net_device *netdev = adapter->netdev; |
| 4340 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4341 | struct e1000_buffer *buffer_info, *next_buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4342 | struct e1000_ps_page *ps_page; |
| 4343 | struct e1000_ps_page_dma *ps_page_dma; |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4344 | struct sk_buff *skb; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4345 | unsigned int i, j; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4346 | u32 length, staterr; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4347 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4348 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4349 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4350 | |
| 4351 | i = rx_ring->next_to_clean; |
| 4352 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4353 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4354 | buffer_info = &rx_ring->buffer_info[i]; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4355 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4356 | while (staterr & E1000_RXD_STAT_DD) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4357 | ps_page = &rx_ring->ps_page[i]; |
| 4358 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4359 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4360 | if (unlikely(*work_done >= work_to_do)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4361 | break; |
| 4362 | (*work_done)++; |
| 4363 | #endif |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4364 | skb = buffer_info->skb; |
| 4365 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4366 | /* in the packet split case this is header only */ |
| 4367 | prefetch(skb->data - NET_IP_ALIGN); |
| 4368 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4369 | if (++i == rx_ring->count) i = 0; |
| 4370 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4371 | prefetch(next_rxd); |
| 4372 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4373 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4374 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4375 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4376 | cleaned_count++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4377 | pci_unmap_single(pdev, buffer_info->dma, |
| 4378 | buffer_info->length, |
| 4379 | PCI_DMA_FROMDEVICE); |
| 4380 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4381 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4382 | E1000_DBG("%s: Packet Split buffers didn't pick up" |
| 4383 | " the full packet\n", netdev->name); |
| 4384 | dev_kfree_skb_irq(skb); |
| 4385 | goto next_desc; |
| 4386 | } |
| 4387 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4388 | if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4389 | dev_kfree_skb_irq(skb); |
| 4390 | goto next_desc; |
| 4391 | } |
| 4392 | |
| 4393 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 4394 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4395 | if (unlikely(!length)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4396 | E1000_DBG("%s: Last part of the packet spanning" |
| 4397 | " multiple descriptors\n", netdev->name); |
| 4398 | dev_kfree_skb_irq(skb); |
| 4399 | goto next_desc; |
| 4400 | } |
| 4401 | |
| 4402 | /* Good Receive */ |
| 4403 | skb_put(skb, length); |
| 4404 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4405 | { |
| 4406 | /* this looks ugly, but it seems compiler issues make it |
| 4407 | more efficient than reusing j */ |
| 4408 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 4409 | |
| 4410 | /* page alloc/put takes too long and effects small packet |
| 4411 | * throughput, so unsplit small packets and save the alloc/put*/ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4412 | if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) { |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4413 | u8 *vaddr; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 4414 | /* there is no documentation about how to call |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4415 | * kmap_atomic, so we can't hold the mapping |
| 4416 | * very long */ |
| 4417 | pci_dma_sync_single_for_cpu(pdev, |
| 4418 | ps_page_dma->ps_page_dma[0], |
| 4419 | PAGE_SIZE, |
| 4420 | PCI_DMA_FROMDEVICE); |
| 4421 | vaddr = kmap_atomic(ps_page->ps_page[0], |
| 4422 | KM_SKB_DATA_SOFTIRQ); |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 4423 | memcpy(skb_tail_pointer(skb), vaddr, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4424 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 4425 | pci_dma_sync_single_for_device(pdev, |
| 4426 | ps_page_dma->ps_page_dma[0], |
| 4427 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4428 | /* remove the CRC */ |
| 4429 | l1 -= 4; |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4430 | skb_put(skb, l1); |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4431 | goto copydone; |
| 4432 | } /* if */ |
| 4433 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4434 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4435 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4436 | if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4437 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4438 | pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
| 4439 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 4440 | ps_page_dma->ps_page_dma[j] = 0; |
Jeff Kirsher | 329bfd0 | 2006-03-02 18:20:02 -0800 | [diff] [blame] | 4441 | skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
| 4442 | length); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4443 | ps_page->ps_page[j] = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4444 | skb->len += length; |
| 4445 | skb->data_len += length; |
Auke Kok | 5d51b80 | 2006-04-14 19:05:06 -0700 | [diff] [blame] | 4446 | skb->truesize += length; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Auke Kok | f235a2a | 2006-07-14 16:14:34 -0700 | [diff] [blame] | 4449 | /* strip the ethernet crc, problem is we're using pages now so |
| 4450 | * this whole operation can get a little cpu intensive */ |
| 4451 | pskb_trim(skb, skb->len - 4); |
| 4452 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 4453 | copydone: |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4454 | total_rx_bytes += skb->len; |
| 4455 | total_rx_packets++; |
| 4456 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4457 | e1000_rx_checksum(adapter, staterr, |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4458 | 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] | 4459 | skb->protocol = eth_type_trans(skb, netdev); |
| 4460 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4461 | if (likely(rx_desc->wb.upper.header_status & |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4462 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4463 | adapter->rx_hdr_split++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4464 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4465 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4466 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4467 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4468 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4469 | } else { |
| 4470 | netif_receive_skb(skb); |
| 4471 | } |
| 4472 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4473 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4474 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4475 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 4476 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4477 | } else { |
| 4478 | netif_rx(skb); |
| 4479 | } |
| 4480 | #endif /* CONFIG_E1000_NAPI */ |
| 4481 | netdev->last_rx = jiffies; |
| 4482 | |
| 4483 | next_desc: |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4484 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4485 | buffer_info->skb = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4486 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4487 | /* return some buffers to hardware, one at a time is too slow */ |
| 4488 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4489 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4490 | cleaned_count = 0; |
| 4491 | } |
| 4492 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4493 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4494 | rx_desc = next_rxd; |
| 4495 | buffer_info = next_buffer; |
| 4496 | |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 4497 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4498 | } |
| 4499 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4500 | |
| 4501 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4502 | if (cleaned_count) |
| 4503 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4504 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4505 | adapter->total_rx_packets += total_rx_packets; |
| 4506 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4507 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4508 | adapter->net_stats.rx_packets += total_rx_packets; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4509 | return cleaned; |
| 4510 | } |
| 4511 | |
| 4512 | /** |
| 4513 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | * @adapter: address of board private structure |
| 4515 | **/ |
| 4516 | |
| 4517 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4518 | e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4519 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4520 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | struct net_device *netdev = adapter->netdev; |
| 4523 | struct pci_dev *pdev = adapter->pdev; |
| 4524 | struct e1000_rx_desc *rx_desc; |
| 4525 | struct e1000_buffer *buffer_info; |
| 4526 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4527 | unsigned int i; |
| 4528 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | |
| 4530 | i = rx_ring->next_to_use; |
| 4531 | buffer_info = &rx_ring->buffer_info[i]; |
| 4532 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4533 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4534 | skb = buffer_info->skb; |
| 4535 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4536 | skb_trim(skb, 0); |
| 4537 | goto map_skb; |
| 4538 | } |
| 4539 | |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4540 | skb = netdev_alloc_skb(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4541 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4543 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | break; |
| 4545 | } |
| 4546 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4547 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4549 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4550 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 4551 | "at %p\n", bufsz, skb->data); |
| 4552 | /* Try again, without freeing the previous */ |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4553 | skb = netdev_alloc_skb(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4554 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | if (!skb) { |
| 4556 | dev_kfree_skb(oldskb); |
| 4557 | break; |
| 4558 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4561 | /* give up */ |
| 4562 | dev_kfree_skb(skb); |
| 4563 | dev_kfree_skb(oldskb); |
| 4564 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4566 | |
| 4567 | /* Use new allocation */ |
| 4568 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4571 | * this will result in a 16 byte aligned IP header after |
| 4572 | * the 14 byte MAC header is removed |
| 4573 | */ |
| 4574 | skb_reserve(skb, NET_IP_ALIGN); |
| 4575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | buffer_info->skb = skb; |
| 4577 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4578 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | buffer_info->dma = pci_map_single(pdev, |
| 4580 | skb->data, |
| 4581 | adapter->rx_buffer_len, |
| 4582 | PCI_DMA_FROMDEVICE); |
| 4583 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4584 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4585 | if (!e1000_check_64k_bound(adapter, |
| 4586 | (void *)(unsigned long)buffer_info->dma, |
| 4587 | adapter->rx_buffer_len)) { |
| 4588 | DPRINTK(RX_ERR, ERR, |
| 4589 | "dma align check failed: %u bytes at %p\n", |
| 4590 | adapter->rx_buffer_len, |
| 4591 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | dev_kfree_skb(skb); |
| 4593 | buffer_info->skb = NULL; |
| 4594 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4595 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | adapter->rx_buffer_len, |
| 4597 | PCI_DMA_FROMDEVICE); |
| 4598 | |
| 4599 | break; /* while !buffer_info->skb */ |
| 4600 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4602 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4603 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4604 | if (unlikely(++i == rx_ring->count)) |
| 4605 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | buffer_info = &rx_ring->buffer_info[i]; |
| 4607 | } |
| 4608 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4609 | if (likely(rx_ring->next_to_use != i)) { |
| 4610 | rx_ring->next_to_use = i; |
| 4611 | if (unlikely(i-- == 0)) |
| 4612 | i = (rx_ring->count - 1); |
| 4613 | |
| 4614 | /* Force memory writes to complete before letting h/w |
| 4615 | * know there are new descriptors to fetch. (Only |
| 4616 | * applicable for weak-ordered memory model archs, |
| 4617 | * such as IA-64). */ |
| 4618 | wmb(); |
| 4619 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4620 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4624 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 4625 | * @adapter: address of board private structure |
| 4626 | **/ |
| 4627 | |
| 4628 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 4629 | e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4630 | struct e1000_rx_ring *rx_ring, |
| 4631 | int cleaned_count) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4632 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4633 | struct net_device *netdev = adapter->netdev; |
| 4634 | struct pci_dev *pdev = adapter->pdev; |
| 4635 | union e1000_rx_desc_packet_split *rx_desc; |
| 4636 | struct e1000_buffer *buffer_info; |
| 4637 | struct e1000_ps_page *ps_page; |
| 4638 | struct e1000_ps_page_dma *ps_page_dma; |
| 4639 | struct sk_buff *skb; |
| 4640 | unsigned int i, j; |
| 4641 | |
| 4642 | i = rx_ring->next_to_use; |
| 4643 | buffer_info = &rx_ring->buffer_info[i]; |
| 4644 | ps_page = &rx_ring->ps_page[i]; |
| 4645 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4646 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4647 | while (cleaned_count--) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4648 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 4649 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4650 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4651 | if (j < adapter->rx_ps_pages) { |
| 4652 | if (likely(!ps_page->ps_page[j])) { |
| 4653 | ps_page->ps_page[j] = |
| 4654 | alloc_page(GFP_ATOMIC); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4655 | if (unlikely(!ps_page->ps_page[j])) { |
| 4656 | adapter->alloc_rx_buff_failed++; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4657 | goto no_buffers; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4658 | } |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4659 | ps_page_dma->ps_page_dma[j] = |
| 4660 | pci_map_page(pdev, |
| 4661 | ps_page->ps_page[j], |
| 4662 | 0, PAGE_SIZE, |
| 4663 | PCI_DMA_FROMDEVICE); |
| 4664 | } |
| 4665 | /* Refresh the desc even if buffer_addrs didn't |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4666 | * change because each write-back erases |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 4667 | * this info. |
| 4668 | */ |
| 4669 | rx_desc->read.buffer_addr[j+1] = |
| 4670 | cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
| 4671 | } else |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 4672 | rx_desc->read.buffer_addr[j+1] = ~cpu_to_le64(0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4675 | skb = netdev_alloc_skb(netdev, |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4676 | adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4677 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4678 | if (unlikely(!skb)) { |
| 4679 | adapter->alloc_rx_buff_failed++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4680 | break; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4681 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4682 | |
| 4683 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4684 | * this will result in a 16 byte aligned IP header after |
| 4685 | * the 14 byte MAC header is removed |
| 4686 | */ |
| 4687 | skb_reserve(skb, NET_IP_ALIGN); |
| 4688 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4689 | buffer_info->skb = skb; |
| 4690 | buffer_info->length = adapter->rx_ps_bsize0; |
| 4691 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4692 | adapter->rx_ps_bsize0, |
| 4693 | PCI_DMA_FROMDEVICE); |
| 4694 | |
| 4695 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 4696 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4697 | if (unlikely(++i == rx_ring->count)) i = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4698 | buffer_info = &rx_ring->buffer_info[i]; |
| 4699 | ps_page = &rx_ring->ps_page[i]; |
| 4700 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4701 | } |
| 4702 | |
| 4703 | no_buffers: |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4704 | if (likely(rx_ring->next_to_use != i)) { |
| 4705 | rx_ring->next_to_use = i; |
| 4706 | if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
| 4707 | |
| 4708 | /* Force memory writes to complete before letting h/w |
| 4709 | * know there are new descriptors to fetch. (Only |
| 4710 | * applicable for weak-ordered memory model archs, |
| 4711 | * such as IA-64). */ |
| 4712 | wmb(); |
| 4713 | /* Hardware increments by 16 bytes, but packet split |
| 4714 | * descriptors are 32 bytes...so we increment tail |
| 4715 | * twice as much. |
| 4716 | */ |
| 4717 | writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
| 4718 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4723 | * @adapter: |
| 4724 | **/ |
| 4725 | |
| 4726 | static void |
| 4727 | e1000_smartspeed(struct e1000_adapter *adapter) |
| 4728 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4729 | u16 phy_status; |
| 4730 | u16 phy_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4732 | if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
| 4734 | return; |
| 4735 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4736 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | /* If Master/Slave config fault is asserted twice, |
| 4738 | * we assume back-to-back */ |
| 4739 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4740 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4742 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4744 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
| 4746 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
| 4747 | phy_ctrl); |
| 4748 | adapter->smartspeed++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4749 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4750 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
| 4751 | &phy_ctrl)) { |
| 4752 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4753 | MII_CR_RESTART_AUTO_NEG); |
| 4754 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
| 4755 | phy_ctrl); |
| 4756 | } |
| 4757 | } |
| 4758 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4759 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | /* If still no link, perhaps using 2/3 pair cable */ |
| 4761 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
| 4762 | phy_ctrl |= CR_1000T_MS_ENABLE; |
| 4763 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4764 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
| 4766 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4767 | MII_CR_RESTART_AUTO_NEG); |
| 4768 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
| 4769 | } |
| 4770 | } |
| 4771 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4772 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | adapter->smartspeed = 0; |
| 4774 | } |
| 4775 | |
| 4776 | /** |
| 4777 | * e1000_ioctl - |
| 4778 | * @netdev: |
| 4779 | * @ifreq: |
| 4780 | * @cmd: |
| 4781 | **/ |
| 4782 | |
| 4783 | static int |
| 4784 | e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4785 | { |
| 4786 | switch (cmd) { |
| 4787 | case SIOCGMIIPHY: |
| 4788 | case SIOCGMIIREG: |
| 4789 | case SIOCSMIIREG: |
| 4790 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4791 | default: |
| 4792 | return -EOPNOTSUPP; |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | /** |
| 4797 | * e1000_mii_ioctl - |
| 4798 | * @netdev: |
| 4799 | * @ifreq: |
| 4800 | * @cmd: |
| 4801 | **/ |
| 4802 | |
| 4803 | static int |
| 4804 | e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4805 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4806 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4808 | int retval; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4809 | u16 mii_reg; |
| 4810 | u16 spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4811 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4813 | if (adapter->hw.media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | return -EOPNOTSUPP; |
| 4815 | |
| 4816 | switch (cmd) { |
| 4817 | case SIOCGMIIPHY: |
| 4818 | data->phy_id = adapter->hw.phy_addr; |
| 4819 | break; |
| 4820 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4821 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4823 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4824 | if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4825 | &data->val_out)) { |
| 4826 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4828 | } |
| 4829 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | break; |
| 4831 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4832 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4833 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4834 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | return -EFAULT; |
| 4836 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4837 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4838 | if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4839 | mii_reg)) { |
| 4840 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4841 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4842 | } |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4843 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Auke Kok | dc86d32 | 2006-04-18 12:30:51 -0700 | [diff] [blame] | 4844 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | switch (data->reg_num) { |
| 4846 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4847 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4849 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | adapter->hw.autoneg = 1; |
| 4851 | adapter->hw.autoneg_advertised = 0x2F; |
| 4852 | } else { |
| 4853 | if (mii_reg & 0x40) |
| 4854 | spddplx = SPEED_1000; |
| 4855 | else if (mii_reg & 0x2000) |
| 4856 | spddplx = SPEED_100; |
| 4857 | else |
| 4858 | spddplx = SPEED_10; |
| 4859 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4860 | ? DUPLEX_FULL : |
| 4861 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | retval = e1000_set_spd_dplx(adapter, |
| 4863 | spddplx); |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4864 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | return retval; |
| 4866 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4867 | if (netif_running(adapter->netdev)) |
| 4868 | e1000_reinit_locked(adapter); |
| 4869 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4870 | e1000_reset(adapter); |
| 4871 | break; |
| 4872 | case M88E1000_PHY_SPEC_CTRL: |
| 4873 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4874 | if (e1000_phy_reset(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | return -EIO; |
| 4876 | break; |
| 4877 | } |
| 4878 | } else { |
| 4879 | switch (data->reg_num) { |
| 4880 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4881 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4883 | if (netif_running(adapter->netdev)) |
| 4884 | e1000_reinit_locked(adapter); |
| 4885 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | e1000_reset(adapter); |
| 4887 | break; |
| 4888 | } |
| 4889 | } |
| 4890 | break; |
| 4891 | default: |
| 4892 | return -EOPNOTSUPP; |
| 4893 | } |
| 4894 | return E1000_SUCCESS; |
| 4895 | } |
| 4896 | |
| 4897 | void |
| 4898 | e1000_pci_set_mwi(struct e1000_hw *hw) |
| 4899 | { |
| 4900 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4901 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4903 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4904 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | void |
| 4908 | e1000_pci_clear_mwi(struct e1000_hw *hw) |
| 4909 | { |
| 4910 | struct e1000_adapter *adapter = hw->back; |
| 4911 | |
| 4912 | pci_clear_mwi(adapter->pdev); |
| 4913 | } |
| 4914 | |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4915 | int |
| 4916 | e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
| 4917 | { |
| 4918 | struct e1000_adapter *adapter = hw->back; |
| 4919 | return pcix_get_mmrbc(adapter->pdev); |
| 4920 | } |
| 4921 | |
| 4922 | void |
| 4923 | e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
| 4924 | { |
| 4925 | struct e1000_adapter *adapter = hw->back; |
| 4926 | pcix_set_mmrbc(adapter->pdev, mmrbc); |
| 4927 | } |
| 4928 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4929 | s32 |
| 4930 | e1000_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4931 | { |
| 4932 | struct e1000_adapter *adapter = hw->back; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4933 | u16 cap_offset; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4934 | |
| 4935 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 4936 | if (!cap_offset) |
| 4937 | return -E1000_ERR_CONFIG; |
| 4938 | |
| 4939 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 4940 | |
| 4941 | return E1000_SUCCESS; |
| 4942 | } |
| 4943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | void |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4945 | e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | { |
| 4947 | outl(value, port); |
| 4948 | } |
| 4949 | |
| 4950 | static void |
| 4951 | e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 4952 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4953 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4954 | u32 ctrl, rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4956 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4957 | e1000_irq_disable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | adapter->vlgrp = grp; |
| 4959 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4960 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | /* enable VLAN tag insert/strip */ |
| 4962 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4963 | ctrl |= E1000_CTRL_VME; |
| 4964 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4965 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4966 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4967 | /* enable VLAN receive filtering */ |
| 4968 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4969 | rctl |= E1000_RCTL_VFE; |
| 4970 | rctl &= ~E1000_RCTL_CFIEN; |
| 4971 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4972 | e1000_update_mng_vlan(adapter); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4973 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | } else { |
| 4975 | /* disable VLAN tag insert/strip */ |
| 4976 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4977 | ctrl &= ~E1000_CTRL_VME; |
| 4978 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4979 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4980 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4981 | /* disable VLAN filtering */ |
| 4982 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4983 | rctl &= ~E1000_RCTL_VFE; |
| 4984 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4985 | if (adapter->mng_vlan_id != |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4986 | (u16)E1000_MNG_VLAN_NONE) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4987 | e1000_vlan_rx_kill_vid(netdev, |
| 4988 | adapter->mng_vlan_id); |
| 4989 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4990 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4994 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4995 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | static void |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4999 | e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5001 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5002 | u32 vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5003 | |
| 5004 | if ((adapter->hw.mng_cookie.status & |
| 5005 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 5006 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5007 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | /* add VID to filter table */ |
| 5009 | index = (vid >> 5) & 0x7F; |
| 5010 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 5011 | vfta |= (1 << (vid & 0x1F)); |
| 5012 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 5013 | } |
| 5014 | |
| 5015 | static void |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5016 | e1000_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5018 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5019 | u32 vfta, index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 5021 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 5022 | e1000_irq_disable(adapter); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 5023 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 5024 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 5025 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5027 | if ((adapter->hw.mng_cookie.status & |
| 5028 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 5029 | (vid == adapter->mng_vlan_id)) { |
| 5030 | /* release control to f/w */ |
| 5031 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5032 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | /* remove VID from filter table */ |
| 5036 | index = (vid >> 5) & 0x7F; |
| 5037 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 5038 | vfta &= ~(1 << (vid & 0x1F)); |
| 5039 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 5040 | } |
| 5041 | |
| 5042 | static void |
| 5043 | e1000_restore_vlan(struct e1000_adapter *adapter) |
| 5044 | { |
| 5045 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 5046 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5047 | if (adapter->vlgrp) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5048 | u16 vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5049 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 5050 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | continue; |
| 5052 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 5053 | } |
| 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | int |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5058 | e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | { |
| 5060 | adapter->hw.autoneg = 0; |
| 5061 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 5062 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5063 | if ((adapter->hw.media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 5064 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 5065 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 5066 | return -EINVAL; |
| 5067 | } |
| 5068 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5069 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | case SPEED_10 + DUPLEX_HALF: |
| 5071 | adapter->hw.forced_speed_duplex = e1000_10_half; |
| 5072 | break; |
| 5073 | case SPEED_10 + DUPLEX_FULL: |
| 5074 | adapter->hw.forced_speed_duplex = e1000_10_full; |
| 5075 | break; |
| 5076 | case SPEED_100 + DUPLEX_HALF: |
| 5077 | adapter->hw.forced_speed_duplex = e1000_100_half; |
| 5078 | break; |
| 5079 | case SPEED_100 + DUPLEX_FULL: |
| 5080 | adapter->hw.forced_speed_duplex = e1000_100_full; |
| 5081 | break; |
| 5082 | case SPEED_1000 + DUPLEX_FULL: |
| 5083 | adapter->hw.autoneg = 1; |
| 5084 | adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
| 5085 | break; |
| 5086 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 5087 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5088 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | return -EINVAL; |
| 5090 | } |
| 5091 | return 0; |
| 5092 | } |
| 5093 | |
| 5094 | static int |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 5095 | e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | { |
| 5097 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5098 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5099 | u32 ctrl, ctrl_ext, rctl, status; |
| 5100 | u32 wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5101 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5102 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 5103 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | |
| 5105 | netif_device_detach(netdev); |
| 5106 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5107 | if (netif_running(netdev)) { |
| 5108 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5109 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 5110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5112 | #ifdef CONFIG_PM |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5113 | retval = pci_save_state(pdev); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5114 | if (retval) |
| 5115 | return retval; |
| 5116 | #endif |
| 5117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | status = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5119 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5120 | wufc &= ~E1000_WUFC_LNKC; |
| 5121 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5122 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | e1000_setup_rctl(adapter); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 5124 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | |
| 5126 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 5127 | if (wufc & E1000_WUFC_MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 5129 | rctl |= E1000_RCTL_MPE; |
| 5130 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 5131 | } |
| 5132 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5133 | if (adapter->hw.mac_type >= e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 5135 | /* advertise wake from D3Cold */ |
| 5136 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5137 | /* phy power management enable */ |
| 5138 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5139 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 5140 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 5141 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 5142 | } |
| 5143 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5144 | if (adapter->hw.media_type == e1000_media_type_fiber || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 5146 | /* keep the laser running in D3 */ |
| 5147 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 5148 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 5149 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
| 5150 | } |
| 5151 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5152 | /* Allow time for pending master requests to run */ |
| 5153 | e1000_disable_pciex_master(&adapter->hw); |
| 5154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
| 5156 | E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5157 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5158 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | } else { |
| 5160 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
| 5161 | E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5162 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5163 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5166 | e1000_release_manageability(adapter); |
| 5167 | |
| 5168 | /* make sure adapter isn't asleep if manageability is enabled */ |
| 5169 | if (adapter->en_mng_pt) { |
| 5170 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 5171 | pci_enable_wake(pdev, PCI_D3cold, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | } |
| 5173 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5174 | if (adapter->hw.phy_type == e1000_phy_igp_3) |
| 5175 | e1000_phy_powerdown_workaround(&adapter->hw); |
| 5176 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5177 | if (netif_running(netdev)) |
| 5178 | e1000_free_irq(adapter); |
| 5179 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5180 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5181 | * would have already happened in close and is redundant. */ |
| 5182 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5185 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5186 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | |
| 5188 | return 0; |
| 5189 | } |
| 5190 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5191 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | static int |
| 5193 | e1000_resume(struct pci_dev *pdev) |
| 5194 | { |
| 5195 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5196 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5197 | u32 err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5199 | pci_set_power_state(pdev, PCI_D0); |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5200 | pci_restore_state(pdev); |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 5201 | if ((err = pci_enable_device(pdev))) { |
| 5202 | printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
| 5203 | return err; |
| 5204 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 5205 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5207 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5208 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5210 | if (netif_running(netdev) && (err = e1000_request_irq(adapter))) |
| 5211 | return err; |
| 5212 | |
| 5213 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 | e1000_reset(adapter); |
| 5215 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5216 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5217 | e1000_init_manageability(adapter); |
| 5218 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5219 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5220 | e1000_up(adapter); |
| 5221 | |
| 5222 | netif_device_attach(netdev); |
| 5223 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5224 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5225 | * DRV_LOAD until the interface is up. For all other cases, |
| 5226 | * let the f/w know that the h/w is now under the control |
| 5227 | * of the driver. */ |
| 5228 | if (adapter->hw.mac_type != e1000_82573 || |
| 5229 | !e1000_check_mng_mode(&adapter->hw)) |
| 5230 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | return 0; |
| 5233 | } |
| 5234 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5235 | |
| 5236 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5237 | { |
| 5238 | e1000_suspend(pdev, PMSG_SUSPEND); |
| 5239 | } |
| 5240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5241 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5242 | /* |
| 5243 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5244 | * without having to re-enable interrupts. It's not called while |
| 5245 | * the interrupt routine is executing. |
| 5246 | */ |
| 5247 | static void |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 5248 | e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5250 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 5251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5252 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5253 | e1000_intr(adapter->pdev->irq, netdev); |
Jeff Kirsher | e8da8be | 2006-01-12 16:51:14 -0800 | [diff] [blame] | 5254 | #ifndef CONFIG_E1000_NAPI |
| 5255 | adapter->clean_rx(adapter, adapter->rx_ring); |
| 5256 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | enable_irq(adapter->pdev->irq); |
| 5258 | } |
| 5259 | #endif |
| 5260 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5261 | /** |
| 5262 | * e1000_io_error_detected - called when PCI error is detected |
| 5263 | * @pdev: Pointer to PCI device |
| 5264 | * @state: The current pci conneection state |
| 5265 | * |
| 5266 | * This function is called after a PCI bus error affecting |
| 5267 | * this device has been detected. |
| 5268 | */ |
| 5269 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 5270 | { |
| 5271 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5272 | struct e1000_adapter *adapter = netdev->priv; |
| 5273 | |
| 5274 | netif_device_detach(netdev); |
| 5275 | |
| 5276 | if (netif_running(netdev)) |
| 5277 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 5278 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5279 | |
| 5280 | /* Request a slot slot reset. */ |
| 5281 | return PCI_ERS_RESULT_NEED_RESET; |
| 5282 | } |
| 5283 | |
| 5284 | /** |
| 5285 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5286 | * @pdev: Pointer to PCI device |
| 5287 | * |
| 5288 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5289 | * resembles the first-half of the e1000_resume routine. |
| 5290 | */ |
| 5291 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5292 | { |
| 5293 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5294 | struct e1000_adapter *adapter = netdev->priv; |
| 5295 | |
| 5296 | if (pci_enable_device(pdev)) { |
| 5297 | printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
| 5298 | return PCI_ERS_RESULT_DISCONNECT; |
| 5299 | } |
| 5300 | pci_set_master(pdev); |
| 5301 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 5302 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5303 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5304 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5305 | e1000_reset(adapter); |
| 5306 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 5307 | |
| 5308 | return PCI_ERS_RESULT_RECOVERED; |
| 5309 | } |
| 5310 | |
| 5311 | /** |
| 5312 | * e1000_io_resume - called when traffic can start flowing again. |
| 5313 | * @pdev: Pointer to PCI device |
| 5314 | * |
| 5315 | * This callback is called when the error recovery driver tells us that |
| 5316 | * its OK to resume normal operation. Implementation resembles the |
| 5317 | * second-half of the e1000_resume routine. |
| 5318 | */ |
| 5319 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5320 | { |
| 5321 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5322 | struct e1000_adapter *adapter = netdev->priv; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5323 | |
| 5324 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5325 | |
| 5326 | if (netif_running(netdev)) { |
| 5327 | if (e1000_up(adapter)) { |
| 5328 | printk("e1000: can't bring device back up after reset\n"); |
| 5329 | return; |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | netif_device_attach(netdev); |
| 5334 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5335 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5336 | * DRV_LOAD until the interface is up. For all other cases, |
| 5337 | * let the f/w know that the h/w is now under the control |
| 5338 | * of the driver. */ |
| 5339 | if (adapter->hw.mac_type != e1000_82573 || |
| 5340 | !e1000_check_mng_mode(&adapter->hw)) |
| 5341 | e1000_get_hw_control(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5342 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5343 | } |
| 5344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5345 | /* e1000_main.c */ |