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"; |
Jesse Brandeburg | 15b2bee | 2009-01-27 16:41:58 -0800 | [diff] [blame] | 34 | #define DRV_VERSION "7.3.21-k3-NAPI" |
Stephen Hemminger | abec42a | 2007-10-29 10:46:19 -0700 | [diff] [blame] | 35 | const char e1000_driver_version[] = DRV_VERSION; |
| 36 | static const char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation."; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* e1000_pci_tbl - PCI Device ID Table |
| 39 | * |
| 40 | * Last entry must be all 0s |
| 41 | * |
| 42 | * Macro expands to... |
| 43 | * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} |
| 44 | */ |
| 45 | static struct pci_device_id e1000_pci_tbl[] = { |
| 46 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 47 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 48 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 49 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 50 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 51 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 52 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 53 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 54 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 55 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 56 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 57 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 58 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 59 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 60 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 61 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 62 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 63 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 64 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 65 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 67 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 68 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 69 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 70 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
| 71 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 72 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 73 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 74 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 75 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 76 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 77 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 78 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
| 79 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 80 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 81 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* required last entry */ |
| 83 | {0,} |
| 84 | }; |
| 85 | |
| 86 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 87 | |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 88 | int e1000_up(struct e1000_adapter *adapter); |
| 89 | void e1000_down(struct e1000_adapter *adapter); |
| 90 | void e1000_reinit_locked(struct e1000_adapter *adapter); |
| 91 | void e1000_reset(struct e1000_adapter *adapter); |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 92 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx); |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 93 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter); |
| 94 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter); |
| 95 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter); |
| 96 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 97 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 98 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 99 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 100 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 101 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 102 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 103 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Nicholas Nunley | 3557476 | 2006-09-27 12:53:34 -0700 | [diff] [blame] | 104 | struct e1000_rx_ring *rx_ring); |
| 105 | void e1000_update_stats(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | static int e1000_init_module(void); |
| 108 | static void e1000_exit_module(void); |
| 109 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 110 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 111 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 113 | static int e1000_open(struct net_device *netdev); |
| 114 | static int e1000_close(struct net_device *netdev); |
| 115 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 116 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 117 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 118 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 119 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 120 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 121 | struct e1000_tx_ring *tx_ring); |
| 122 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 123 | struct e1000_rx_ring *rx_ring); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 124 | static void e1000_set_rx_mode(struct net_device *netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | static void e1000_update_phy_info(unsigned long data); |
| 126 | static void e1000_watchdog(unsigned long data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
| 128 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 129 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 130 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 131 | static int e1000_set_mac(struct net_device *netdev, void *p); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 132 | static irqreturn_t e1000_intr(int irq, void *data); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 133 | static irqreturn_t e1000_intr_msi(int irq, void *data); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 134 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 135 | struct e1000_tx_ring *tx_ring); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 136 | static int e1000_clean(struct napi_struct *napi, int budget); |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 137 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 138 | struct e1000_rx_ring *rx_ring, |
| 139 | int *work_done, int work_to_do); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 140 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 141 | struct e1000_rx_ring *rx_ring, |
| 142 | int *work_done, int work_to_do); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 143 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 144 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 145 | int cleaned_count); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 146 | static void e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 147 | struct e1000_rx_ring *rx_ring, |
| 148 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 150 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 151 | int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 153 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 154 | static void e1000_tx_timeout(struct net_device *dev); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 155 | static void e1000_reset_task(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
Auke Kok | e619d523 | 2006-04-14 19:04:52 -0700 | [diff] [blame] | 157 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 158 | struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | 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] | 161 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid); |
| 162 | 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] | 163 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 164 | |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 165 | #ifdef CONFIG_PM |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 166 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | static int e1000_resume(struct pci_dev *pdev); |
| 168 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 169 | static void e1000_shutdown(struct pci_dev *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 172 | /* for netdump / net console */ |
| 173 | static void e1000_netpoll (struct net_device *netdev); |
| 174 | #endif |
| 175 | |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 176 | #define COPYBREAK_DEFAULT 256 |
| 177 | static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT; |
| 178 | module_param(copybreak, uint, 0644); |
| 179 | MODULE_PARM_DESC(copybreak, |
| 180 | "Maximum size of packet that is copied to a new buffer on receive"); |
| 181 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 182 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 183 | pci_channel_state_t state); |
| 184 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); |
| 185 | static void e1000_io_resume(struct pci_dev *pdev); |
| 186 | |
| 187 | static struct pci_error_handlers e1000_err_handler = { |
| 188 | .error_detected = e1000_io_error_detected, |
| 189 | .slot_reset = e1000_io_slot_reset, |
| 190 | .resume = e1000_io_resume, |
| 191 | }; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | static struct pci_driver e1000_driver = { |
| 194 | .name = e1000_driver_name, |
| 195 | .id_table = e1000_pci_tbl, |
| 196 | .probe = e1000_probe, |
| 197 | .remove = __devexit_p(e1000_remove), |
Auke Kok | c4e24f0 | 2006-09-27 12:53:19 -0700 | [diff] [blame] | 198 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | /* Power Managment Hooks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | .suspend = e1000_suspend, |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 201 | .resume = e1000_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | #endif |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 203 | .shutdown = e1000_shutdown, |
| 204 | .err_handler = &e1000_err_handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 208 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 209 | MODULE_LICENSE("GPL"); |
| 210 | MODULE_VERSION(DRV_VERSION); |
| 211 | |
| 212 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 213 | module_param(debug, int, 0); |
| 214 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 215 | |
| 216 | /** |
| 217 | * e1000_init_module - Driver Registration Routine |
| 218 | * |
| 219 | * e1000_init_module is the first routine called when the driver is |
| 220 | * loaded. All it does is register with the PCI subsystem. |
| 221 | **/ |
| 222 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 223 | static int __init e1000_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | int ret; |
| 226 | printk(KERN_INFO "%s - version %s\n", |
| 227 | e1000_driver_string, e1000_driver_version); |
| 228 | |
| 229 | printk(KERN_INFO "%s\n", e1000_copyright); |
| 230 | |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 231 | ret = pci_register_driver(&e1000_driver); |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 232 | if (copybreak != COPYBREAK_DEFAULT) { |
| 233 | if (copybreak == 0) |
| 234 | printk(KERN_INFO "e1000: copybreak disabled\n"); |
| 235 | else |
| 236 | printk(KERN_INFO "e1000: copybreak enabled for " |
| 237 | "packets <= %u bytes\n", copybreak); |
| 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return ret; |
| 240 | } |
| 241 | |
| 242 | module_init(e1000_init_module); |
| 243 | |
| 244 | /** |
| 245 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 246 | * |
| 247 | * e1000_exit_module is called just before the driver is removed |
| 248 | * from memory. |
| 249 | **/ |
| 250 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 251 | static void __exit e1000_exit_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | pci_unregister_driver(&e1000_driver); |
| 254 | } |
| 255 | |
| 256 | module_exit(e1000_exit_module); |
| 257 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 258 | static int e1000_request_irq(struct e1000_adapter *adapter) |
| 259 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 260 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 261 | struct net_device *netdev = adapter->netdev; |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 262 | irq_handler_t handler = e1000_intr; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 263 | int irq_flags = IRQF_SHARED; |
| 264 | int err; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 265 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 266 | if (hw->mac_type >= e1000_82571) { |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 267 | adapter->have_msi = !pci_enable_msi(adapter->pdev); |
| 268 | if (adapter->have_msi) { |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 269 | handler = e1000_intr_msi; |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 270 | irq_flags = 0; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 273 | |
| 274 | err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name, |
| 275 | netdev); |
| 276 | if (err) { |
| 277 | if (adapter->have_msi) |
| 278 | pci_disable_msi(adapter->pdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 279 | DPRINTK(PROBE, ERR, |
| 280 | "Unable to allocate interrupt Error: %d\n", err); |
Auke Kok | e94bd23 | 2007-05-16 01:49:46 -0700 | [diff] [blame] | 281 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 282 | |
| 283 | return err; |
| 284 | } |
| 285 | |
| 286 | static void e1000_free_irq(struct e1000_adapter *adapter) |
| 287 | { |
| 288 | struct net_device *netdev = adapter->netdev; |
| 289 | |
| 290 | free_irq(adapter->pdev->irq, netdev); |
| 291 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 292 | if (adapter->have_msi) |
| 293 | pci_disable_msi(adapter->pdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /** |
| 297 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 298 | * @adapter: board private structure |
| 299 | **/ |
| 300 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 301 | static void e1000_irq_disable(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 303 | struct e1000_hw *hw = &adapter->hw; |
| 304 | |
| 305 | ew32(IMC, ~0); |
| 306 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | synchronize_irq(adapter->pdev->irq); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * e1000_irq_enable - Enable default interrupt generation settings |
| 312 | * @adapter: board private structure |
| 313 | **/ |
| 314 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 315 | static void e1000_irq_enable(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 317 | struct e1000_hw *hw = &adapter->hw; |
| 318 | |
| 319 | ew32(IMS, IMS_ENABLE_MASK); |
| 320 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 322 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 323 | static void e1000_update_mng_vlan(struct e1000_adapter *adapter) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 324 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 325 | struct e1000_hw *hw = &adapter->hw; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 326 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 327 | u16 vid = hw->mng_cookie.vlan_id; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 328 | u16 old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 329 | if (adapter->vlgrp) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 330 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 331 | if (hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 332 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 333 | e1000_vlan_rx_add_vid(netdev, vid); |
| 334 | adapter->mng_vlan_id = vid; |
| 335 | } else |
| 336 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 337 | |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 338 | if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 339 | (vid != old_vid) && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 340 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 341 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 342 | } else |
| 343 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 346 | |
| 347 | /** |
| 348 | * e1000_release_hw_control - release control of the h/w to f/w |
| 349 | * @adapter: address of board private structure |
| 350 | * |
| 351 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 352 | * For ASF and Pass Through versions of f/w this means that the |
| 353 | * driver is no longer loaded. For AMT version (only with 82573) i |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 354 | * 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] | 355 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 356 | **/ |
| 357 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 358 | static void e1000_release_hw_control(struct e1000_adapter *adapter) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 359 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 360 | u32 ctrl_ext; |
| 361 | u32 swsm; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 362 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 363 | |
| 364 | /* Let firmware taken over control of h/w */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 365 | switch (hw->mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 366 | case e1000_82573: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 367 | swsm = er32(SWSM); |
| 368 | ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD); |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 369 | break; |
| 370 | case e1000_82571: |
| 371 | case e1000_82572: |
| 372 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 373 | case e1000_ich8lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 374 | ctrl_ext = er32(CTRL_EXT); |
| 375 | ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 376 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 377 | default: |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * e1000_get_hw_control - get control of the h/w from f/w |
| 384 | * @adapter: address of board private structure |
| 385 | * |
| 386 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 387 | * For ASF and Pass Through versions of f/w this means that |
| 388 | * the driver is loaded. For AMT version (only with 82573) |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 389 | * 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] | 390 | * |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 391 | **/ |
| 392 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 393 | static void e1000_get_hw_control(struct e1000_adapter *adapter) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 394 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 395 | u32 ctrl_ext; |
| 396 | u32 swsm; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 397 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 398 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 399 | /* Let firmware know the driver has taken over */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 400 | switch (hw->mac_type) { |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 401 | case e1000_82573: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 402 | swsm = er32(SWSM); |
| 403 | ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 404 | break; |
Bruce Allan | 31d7644 | 2007-03-06 08:57:24 -0800 | [diff] [blame] | 405 | case e1000_82571: |
| 406 | case e1000_82572: |
| 407 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 408 | case e1000_ich8lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 409 | ctrl_ext = er32(CTRL_EXT); |
| 410 | ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 411 | break; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 412 | default: |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 417 | static void e1000_init_manageability(struct e1000_adapter *adapter) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 418 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 419 | struct e1000_hw *hw = &adapter->hw; |
| 420 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 421 | if (adapter->en_mng_pt) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 422 | u32 manc = er32(MANC); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 423 | |
| 424 | /* disable hardware interception of ARP */ |
| 425 | manc &= ~(E1000_MANC_ARP_EN); |
| 426 | |
| 427 | /* enable receiving management packets to the host */ |
| 428 | /* this will probably generate destination unreachable messages |
| 429 | * from the host OS, but the packets will be handled on SMBUS */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 430 | if (hw->has_manc2h) { |
| 431 | u32 manc2h = er32(MANC2H); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 432 | |
| 433 | manc |= E1000_MANC_EN_MNG2HOST; |
| 434 | #define E1000_MNG2HOST_PORT_623 (1 << 5) |
| 435 | #define E1000_MNG2HOST_PORT_664 (1 << 6) |
| 436 | manc2h |= E1000_MNG2HOST_PORT_623; |
| 437 | manc2h |= E1000_MNG2HOST_PORT_664; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 438 | ew32(MANC2H, manc2h); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 439 | } |
| 440 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 441 | ew32(MANC, manc); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 445 | static void e1000_release_manageability(struct e1000_adapter *adapter) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 446 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 447 | struct e1000_hw *hw = &adapter->hw; |
| 448 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 449 | if (adapter->en_mng_pt) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 450 | u32 manc = er32(MANC); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 451 | |
| 452 | /* re-enable hardware interception of ARP */ |
| 453 | manc |= E1000_MANC_ARP_EN; |
| 454 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 455 | if (hw->has_manc2h) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 456 | manc &= ~E1000_MANC_EN_MNG2HOST; |
| 457 | |
| 458 | /* don't explicitly have to mess with MANC2H since |
| 459 | * MANC has an enable disable that gates MANC2H */ |
| 460 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 461 | ew32(MANC, manc); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 465 | /** |
| 466 | * e1000_configure - configure the hardware for RX and TX |
| 467 | * @adapter = private board structure |
| 468 | **/ |
| 469 | static void e1000_configure(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
| 471 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 472 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 474 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | e1000_restore_vlan(adapter); |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 477 | e1000_init_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | e1000_configure_tx(adapter); |
| 480 | e1000_setup_rctl(adapter); |
| 481 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 482 | /* call E1000_DESC_UNUSED which always leaves |
| 483 | * at least 1 descriptor unused to make sure |
| 484 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 485 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 486 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 487 | adapter->alloc_rx_buf(adapter, ring, |
| 488 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 491 | adapter->tx_queue_len = netdev->tx_queue_len; |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 492 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 493 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 494 | int e1000_up(struct e1000_adapter *adapter) |
| 495 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 496 | struct e1000_hw *hw = &adapter->hw; |
| 497 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 498 | /* hardware has been reset, we need to reload some things */ |
| 499 | e1000_configure(adapter); |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 500 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 501 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 502 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 503 | napi_enable(&adapter->napi); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 504 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 505 | e1000_irq_enable(adapter); |
| 506 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 507 | netif_wake_queue(adapter->netdev); |
| 508 | |
Jesse Brandeburg | 79f3d39 | 2006-12-15 10:42:34 +0100 | [diff] [blame] | 509 | /* fire a link change interrupt to start the watchdog */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 510 | ew32(ICS, E1000_ICS_LSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 514 | /** |
| 515 | * e1000_power_up_phy - restore link in case the phy was powered down |
| 516 | * @adapter: address of board private structure |
| 517 | * |
| 518 | * The phy may be powered down to save power and turn off link when the |
| 519 | * driver is unloaded and wake on lan is not enabled (among others) |
| 520 | * *** this routine MUST be followed by a call to e1000_reset *** |
| 521 | * |
| 522 | **/ |
| 523 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 524 | void e1000_power_up_phy(struct e1000_adapter *adapter) |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 525 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 526 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 527 | u16 mii_reg = 0; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 528 | |
| 529 | /* Just clear the power down bit to wake the phy back up */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 530 | if (hw->media_type == e1000_media_type_copper) { |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 531 | /* according to the manual, the phy will retain its |
| 532 | * settings across a power-down/up cycle */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 533 | e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 534 | mii_reg &= ~MII_CR_POWER_DOWN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 535 | e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
| 539 | static void e1000_power_down_phy(struct e1000_adapter *adapter) |
| 540 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 541 | struct e1000_hw *hw = &adapter->hw; |
| 542 | |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 543 | /* 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] | 544 | * 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] | 545 | * (a) WoL is enabled |
| 546 | * (b) AMT is active |
| 547 | * (c) SoL/IDER session is active */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 548 | if (!adapter->wol && hw->mac_type >= e1000_82540 && |
| 549 | hw->media_type == e1000_media_type_copper) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 550 | u16 mii_reg = 0; |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 551 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 552 | switch (hw->mac_type) { |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 553 | case e1000_82540: |
| 554 | case e1000_82545: |
| 555 | case e1000_82545_rev_3: |
| 556 | case e1000_82546: |
| 557 | case e1000_82546_rev_3: |
| 558 | case e1000_82541: |
| 559 | case e1000_82541_rev_2: |
| 560 | case e1000_82547: |
| 561 | case e1000_82547_rev_2: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 562 | if (er32(MANC) & E1000_MANC_SMBUS_EN) |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 563 | goto out; |
| 564 | break; |
| 565 | case e1000_82571: |
| 566 | case e1000_82572: |
| 567 | case e1000_82573: |
| 568 | case e1000_80003es2lan: |
| 569 | case e1000_ich8lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 570 | if (e1000_check_mng_mode(hw) || |
| 571 | e1000_check_phy_reset_block(hw)) |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 572 | goto out; |
| 573 | break; |
| 574 | default: |
| 575 | goto out; |
| 576 | } |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 577 | e1000_read_phy_reg(hw, PHY_CTRL, &mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 578 | mii_reg |= MII_CR_POWER_DOWN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 579 | e1000_write_phy_reg(hw, PHY_CTRL, mii_reg); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 580 | mdelay(1); |
| 581 | } |
Bruce Allan | 61c2505 | 2006-09-27 12:53:54 -0700 | [diff] [blame] | 582 | out: |
| 583 | return; |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 586 | void e1000_down(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 588 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 590 | u32 rctl, tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 592 | /* signal that we're down so the interrupt handler does not |
| 593 | * reschedule our watchdog timer */ |
| 594 | set_bit(__E1000_DOWN, &adapter->flags); |
| 595 | |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 596 | /* disable receives in the hardware */ |
| 597 | rctl = er32(RCTL); |
| 598 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
| 599 | /* flush and sleep below */ |
| 600 | |
| 601 | /* can be netif_tx_disable when NETIF_F_LLTX is removed */ |
| 602 | netif_stop_queue(netdev); |
| 603 | |
| 604 | /* disable transmits in the hardware */ |
| 605 | tctl = er32(TCTL); |
| 606 | tctl &= ~E1000_TCTL_EN; |
| 607 | ew32(TCTL, tctl); |
| 608 | /* flush both disables and wait for them to finish */ |
| 609 | E1000_WRITE_FLUSH(); |
| 610 | msleep(10); |
| 611 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 612 | napi_disable(&adapter->napi); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 617 | del_timer_sync(&adapter->watchdog_timer); |
| 618 | del_timer_sync(&adapter->phy_info_timer); |
| 619 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 620 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | adapter->link_speed = 0; |
| 622 | adapter->link_duplex = 0; |
| 623 | netif_carrier_off(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 626 | e1000_clean_all_tx_rings(adapter); |
| 627 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 630 | void e1000_reinit_locked(struct e1000_adapter *adapter) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 631 | { |
| 632 | WARN_ON(in_interrupt()); |
| 633 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 634 | msleep(1); |
| 635 | e1000_down(adapter); |
| 636 | e1000_up(adapter); |
| 637 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 640 | void e1000_reset(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 642 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 643 | u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
| 644 | u16 fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 645 | bool legacy_pba_adjust = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | /* Repartition Pba for greater than 9k mtu |
| 648 | * To take effect CTRL.RST is required. |
| 649 | */ |
| 650 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 651 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 652 | case e1000_82542_rev2_0: |
| 653 | case e1000_82542_rev2_1: |
| 654 | case e1000_82543: |
| 655 | case e1000_82544: |
| 656 | case e1000_82540: |
| 657 | case e1000_82541: |
| 658 | case e1000_82541_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 659 | legacy_pba_adjust = true; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 660 | pba = E1000_PBA_48K; |
| 661 | break; |
| 662 | case e1000_82545: |
| 663 | case e1000_82545_rev_3: |
| 664 | case e1000_82546: |
| 665 | case e1000_82546_rev_3: |
| 666 | pba = E1000_PBA_48K; |
| 667 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 668 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 669 | case e1000_82547_rev_2: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 670 | legacy_pba_adjust = true; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 671 | pba = E1000_PBA_30K; |
| 672 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 673 | case e1000_82571: |
| 674 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 675 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 676 | pba = E1000_PBA_38K; |
| 677 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 678 | case e1000_82573: |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 679 | pba = E1000_PBA_20K; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 680 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 681 | case e1000_ich8lan: |
| 682 | pba = E1000_PBA_8K; |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 683 | case e1000_undefined: |
| 684 | case e1000_num_macs: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 685 | break; |
| 686 | } |
| 687 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 688 | if (legacy_pba_adjust) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 689 | if (adapter->netdev->mtu > E1000_RXBUFFER_8192) |
| 690 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 691 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 692 | if (hw->mac_type == e1000_82547) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 693 | adapter->tx_fifo_head = 0; |
| 694 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 695 | adapter->tx_fifo_size = |
| 696 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 697 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 698 | } |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 699 | } else if (hw->max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 700 | /* adjust PBA for jumbo frames */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 701 | ew32(PBA, pba); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 702 | |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 703 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 704 | * large enough to accomodate two full transmit packets, |
| 705 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 706 | * the Rx FIFO should be large enough to accomodate at least |
| 707 | * one full receive packet and is similarly rounded up and |
| 708 | * expressed in KB. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 709 | pba = er32(PBA); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 710 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 711 | tx_space = pba >> 16; |
| 712 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 713 | pba &= 0xffff; |
| 714 | /* don't include ethernet FCS because hardware appends/strips */ |
| 715 | min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE + |
| 716 | VLAN_TAG_SIZE; |
| 717 | min_tx_space = min_rx_space; |
| 718 | min_tx_space *= 2; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 719 | min_tx_space = ALIGN(min_tx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 720 | min_tx_space >>= 10; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 721 | min_rx_space = ALIGN(min_rx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 722 | min_rx_space >>= 10; |
| 723 | |
| 724 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 725 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 726 | * allocation, take space away from current Rx allocation */ |
| 727 | if (tx_space < min_tx_space && |
| 728 | ((min_tx_space - tx_space) < pba)) { |
| 729 | pba = pba - (min_tx_space - tx_space); |
| 730 | |
| 731 | /* PCI/PCIx hardware has PBA alignment constraints */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 732 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 733 | case e1000_82545 ... e1000_82546_rev_3: |
| 734 | pba &= ~(E1000_PBA_8K - 1); |
| 735 | break; |
| 736 | default: |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | /* if short on rx space, rx wins and must trump tx |
| 741 | * adjustment or use Early Receive if available */ |
| 742 | if (pba < min_rx_space) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 743 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 744 | case e1000_82573: |
| 745 | /* ERT enabled in e1000_configure_rx */ |
| 746 | break; |
| 747 | default: |
| 748 | pba = min_rx_space; |
| 749 | break; |
| 750 | } |
| 751 | } |
| 752 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 754 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 755 | ew32(PBA, pba); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 758 | /* Set the FC high water mark to 90% of the FIFO size. |
| 759 | * Required to clear last 3 LSB */ |
| 760 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 761 | /* We can't use 90% on small FIFOs because the remainder |
| 762 | * would be less than 1 full frame. In this case, we size |
| 763 | * it to allow at least a full frame above the high water |
| 764 | * mark. */ |
| 765 | if (pba < E1000_PBA_16K) |
| 766 | fc_high_water_mark = (pba * 1024) - 1600; |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 767 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 768 | hw->fc_high_water = fc_high_water_mark; |
| 769 | hw->fc_low_water = fc_high_water_mark - 8; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 770 | hw->fc_pause_time = E1000_FC_PAUSE_TIME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 771 | hw->fc_send_xon = 1; |
| 772 | hw->fc = hw->original_fc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 774 | /* Allow time for pending master requests to run */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 775 | e1000_reset_hw(hw); |
| 776 | if (hw->mac_type >= e1000_82544) |
| 777 | ew32(WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 778 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 779 | if (e1000_init_hw(hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 781 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 782 | |
| 783 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 784 | if (hw->mac_type >= e1000_82544 && |
| 785 | hw->mac_type <= e1000_82547_rev_2 && |
| 786 | hw->autoneg == 1 && |
| 787 | hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 788 | u32 ctrl = er32(CTRL); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 789 | /* clear phy power management bit if we are in gig only mode, |
| 790 | * which if enabled will attempt negotiation to 100Mb, which |
| 791 | * can cause a loss of link at power off or driver unload */ |
| 792 | ctrl &= ~E1000_CTRL_SWDPIN3; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 793 | ew32(CTRL, ctrl); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 794 | } |
| 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 797 | ew32(VET, ETHERNET_IEEE_VLAN_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 799 | e1000_reset_adaptive(hw); |
| 800 | e1000_phy_get_info(hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 801 | |
| 802 | if (!adapter->smart_power_down && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 803 | (hw->mac_type == e1000_82571 || |
| 804 | hw->mac_type == e1000_82572)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 805 | u16 phy_data = 0; |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 806 | /* speed up time to link by disabling smart power down, ignore |
| 807 | * the return value of this function because there is nothing |
| 808 | * different we would do if it failed */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 809 | e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 810 | &phy_data); |
| 811 | phy_data &= ~IGP02E1000_PM_SPD; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 812 | e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 813 | phy_data); |
| 814 | } |
| 815 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 816 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | /** |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 820 | * Dump the eeprom for users having checksum issues |
| 821 | **/ |
Adrian Bunk | b4ea895 | 2008-02-01 08:21:28 -0800 | [diff] [blame] | 822 | static void e1000_dump_eeprom(struct e1000_adapter *adapter) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 823 | { |
| 824 | struct net_device *netdev = adapter->netdev; |
| 825 | struct ethtool_eeprom eeprom; |
| 826 | const struct ethtool_ops *ops = netdev->ethtool_ops; |
| 827 | u8 *data; |
| 828 | int i; |
| 829 | u16 csum_old, csum_new = 0; |
| 830 | |
| 831 | eeprom.len = ops->get_eeprom_len(netdev); |
| 832 | eeprom.offset = 0; |
| 833 | |
| 834 | data = kmalloc(eeprom.len, GFP_KERNEL); |
| 835 | if (!data) { |
| 836 | printk(KERN_ERR "Unable to allocate memory to dump EEPROM" |
| 837 | " data\n"); |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | ops->get_eeprom(netdev, &eeprom, data); |
| 842 | |
| 843 | csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + |
| 844 | (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); |
| 845 | for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) |
| 846 | csum_new += data[i] + (data[i + 1] << 8); |
| 847 | csum_new = EEPROM_SUM - csum_new; |
| 848 | |
| 849 | printk(KERN_ERR "/*********************/\n"); |
| 850 | printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old); |
| 851 | printk(KERN_ERR "Calculated : 0x%04x\n", csum_new); |
| 852 | |
| 853 | printk(KERN_ERR "Offset Values\n"); |
| 854 | printk(KERN_ERR "======== ======\n"); |
| 855 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); |
| 856 | |
| 857 | printk(KERN_ERR "Include this output when contacting your support " |
| 858 | "provider.\n"); |
| 859 | printk(KERN_ERR "This is not a software error! Something bad " |
| 860 | "happened to your hardware or\n"); |
| 861 | printk(KERN_ERR "EEPROM image. Ignoring this " |
| 862 | "problem could result in further problems,\n"); |
| 863 | printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n"); |
| 864 | printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, " |
| 865 | "which is invalid\n"); |
| 866 | printk(KERN_ERR "and requires you to set the proper MAC " |
| 867 | "address manually before continuing\n"); |
| 868 | printk(KERN_ERR "to enable this network device.\n"); |
| 869 | printk(KERN_ERR "Please inspect the EEPROM dump and report the issue " |
| 870 | "to your hardware vendor\n"); |
Jeff Kirsher | 63cd31f | 2008-07-11 15:17:33 -0700 | [diff] [blame] | 871 | printk(KERN_ERR "or Intel Customer Support.\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 872 | printk(KERN_ERR "/*********************/\n"); |
| 873 | |
| 874 | kfree(data); |
| 875 | } |
| 876 | |
| 877 | /** |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 878 | * e1000_is_need_ioport - determine if an adapter needs ioport resources or not |
| 879 | * @pdev: PCI device information struct |
| 880 | * |
| 881 | * Return true if an adapter needs ioport resources |
| 882 | **/ |
| 883 | static int e1000_is_need_ioport(struct pci_dev *pdev) |
| 884 | { |
| 885 | switch (pdev->device) { |
| 886 | case E1000_DEV_ID_82540EM: |
| 887 | case E1000_DEV_ID_82540EM_LOM: |
| 888 | case E1000_DEV_ID_82540EP: |
| 889 | case E1000_DEV_ID_82540EP_LOM: |
| 890 | case E1000_DEV_ID_82540EP_LP: |
| 891 | case E1000_DEV_ID_82541EI: |
| 892 | case E1000_DEV_ID_82541EI_MOBILE: |
| 893 | case E1000_DEV_ID_82541ER: |
| 894 | case E1000_DEV_ID_82541ER_LOM: |
| 895 | case E1000_DEV_ID_82541GI: |
| 896 | case E1000_DEV_ID_82541GI_LF: |
| 897 | case E1000_DEV_ID_82541GI_MOBILE: |
| 898 | case E1000_DEV_ID_82544EI_COPPER: |
| 899 | case E1000_DEV_ID_82544EI_FIBER: |
| 900 | case E1000_DEV_ID_82544GC_COPPER: |
| 901 | case E1000_DEV_ID_82544GC_LOM: |
| 902 | case E1000_DEV_ID_82545EM_COPPER: |
| 903 | case E1000_DEV_ID_82545EM_FIBER: |
| 904 | case E1000_DEV_ID_82546EB_COPPER: |
| 905 | case E1000_DEV_ID_82546EB_FIBER: |
| 906 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 907 | return true; |
| 908 | default: |
| 909 | return false; |
| 910 | } |
| 911 | } |
| 912 | |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 913 | static const struct net_device_ops e1000_netdev_ops = { |
| 914 | .ndo_open = e1000_open, |
| 915 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 916 | .ndo_start_xmit = e1000_xmit_frame, |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 917 | .ndo_get_stats = e1000_get_stats, |
| 918 | .ndo_set_rx_mode = e1000_set_rx_mode, |
| 919 | .ndo_set_mac_address = e1000_set_mac, |
| 920 | .ndo_tx_timeout = e1000_tx_timeout, |
| 921 | .ndo_change_mtu = e1000_change_mtu, |
| 922 | .ndo_do_ioctl = e1000_ioctl, |
| 923 | .ndo_validate_addr = eth_validate_addr, |
| 924 | |
| 925 | .ndo_vlan_rx_register = e1000_vlan_rx_register, |
| 926 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 927 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 928 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 929 | .ndo_poll_controller = e1000_netpoll, |
| 930 | #endif |
| 931 | }; |
| 932 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 933 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | * e1000_probe - Device Initialization Routine |
| 935 | * @pdev: PCI device information struct |
| 936 | * @ent: entry in e1000_pci_tbl |
| 937 | * |
| 938 | * Returns 0 on success, negative on failure |
| 939 | * |
| 940 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 941 | * The OS initialization, configuring of the adapter private structure, |
| 942 | * and a hardware reset occur. |
| 943 | **/ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 944 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 945 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { |
| 947 | struct net_device *netdev; |
| 948 | struct e1000_adapter *adapter; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 949 | struct e1000_hw *hw; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 952 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 953 | int i, err, pci_using_dac; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 954 | u16 eeprom_data = 0; |
| 955 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 956 | int bars, need_ioport; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 957 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 958 | /* do not allocate ioport bars when not needed */ |
| 959 | need_ioport = e1000_is_need_ioport(pdev); |
| 960 | if (need_ioport) { |
| 961 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
| 962 | err = pci_enable_device(pdev); |
| 963 | } else { |
| 964 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
Karsten Keil | 4d7155b | 2009-02-03 15:18:01 -0800 | [diff] [blame] | 965 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 966 | } |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 967 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | return err; |
| 969 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 970 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 971 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | pci_using_dac = 1; |
| 973 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 974 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 975 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 976 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 977 | if (err) { |
| 978 | E1000_ERR("No usable DMA configuration, " |
| 979 | "aborting\n"); |
| 980 | goto err_dma; |
| 981 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | pci_using_dac = 0; |
| 984 | } |
| 985 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 986 | err = pci_request_selected_regions(pdev, bars, e1000_driver_name); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 987 | if (err) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 988 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | pci_set_master(pdev); |
| 991 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 992 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 994 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 998 | |
| 999 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1000 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | adapter->netdev = netdev; |
| 1002 | adapter->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | adapter->msg_enable = (1 << debug) - 1; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1004 | adapter->bars = bars; |
| 1005 | adapter->need_ioport = need_ioport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1007 | hw = &adapter->hw; |
| 1008 | hw->back = adapter; |
| 1009 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1010 | err = -EIO; |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 1011 | hw->hw_addr = pci_ioremap_bar(pdev, BAR_0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1012 | if (!hw->hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1015 | if (adapter->need_ioport) { |
| 1016 | for (i = BAR_1; i <= BAR_5; i++) { |
| 1017 | if (pci_resource_len(pdev, i) == 0) |
| 1018 | continue; |
| 1019 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
| 1020 | hw->io_base = pci_resource_start(pdev, i); |
| 1021 | break; |
| 1022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 1026 | netdev->netdev_ops = &e1000_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | e1000_set_ethtool_ops(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | netdev->watchdog_timeo = 5 * HZ; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1029 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 1030 | |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 1031 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | adapter->bd_number = cards_found; |
| 1034 | |
| 1035 | /* setup the private structure */ |
| 1036 | |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 1037 | err = e1000_sw_init(adapter); |
| 1038 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | goto err_sw_init; |
| 1040 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1041 | err = -EIO; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1042 | /* Flash BAR mapping must happen after e1000_sw_init |
| 1043 | * because it depends on mac_type */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1044 | if ((hw->mac_type == e1000_ich8lan) && |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1045 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 1046 | hw->flash_address = pci_ioremap_bar(pdev, 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1047 | if (!hw->flash_address) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1048 | goto err_flashmap; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1051 | if (e1000_check_phy_reset_block(hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1052 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 1053 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1054 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | netdev->features = NETIF_F_SG | |
| 1056 | NETIF_F_HW_CSUM | |
| 1057 | NETIF_F_HW_VLAN_TX | |
| 1058 | NETIF_F_HW_VLAN_RX | |
| 1059 | NETIF_F_HW_VLAN_FILTER; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1060 | if (hw->mac_type == e1000_ich8lan) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1061 | netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1064 | if ((hw->mac_type >= e1000_82544) && |
| 1065 | (hw->mac_type != e1000_82547)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1067 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1068 | if (hw->mac_type > e1000_82547_rev_2) |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1069 | netdev->features |= NETIF_F_TSO6; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1070 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | netdev->features |= NETIF_F_HIGHDMA; |
| 1072 | |
Patrick McHardy | 20501a6 | 2008-10-11 12:25:59 -0700 | [diff] [blame] | 1073 | netdev->vlan_features |= NETIF_F_TSO; |
| 1074 | netdev->vlan_features |= NETIF_F_TSO6; |
| 1075 | netdev->vlan_features |= NETIF_F_HW_CSUM; |
| 1076 | netdev->vlan_features |= NETIF_F_SG; |
| 1077 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1078 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1079 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1080 | /* initialize eeprom parameters */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1081 | if (e1000_init_eeprom_params(hw)) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1082 | E1000_ERR("EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1083 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1086 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1088 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1089 | e1000_reset_hw(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
| 1091 | /* make sure the EEPROM is good */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1092 | if (e1000_validate_eeprom_checksum(hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1094 | e1000_dump_eeprom(adapter); |
| 1095 | /* |
| 1096 | * set MAC address to all zeroes to invalidate and temporary |
| 1097 | * disable this device for the user. This blocks regular |
| 1098 | * traffic while still permitting ethtool ioctls from reaching |
| 1099 | * the hardware as well as allowing the user to run the |
| 1100 | * interface after manually setting a hw addr using |
| 1101 | * `ip set address` |
| 1102 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1103 | memset(hw->mac_addr, 0, netdev->addr_len); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1104 | } else { |
| 1105 | /* copy the MAC address out of the EEPROM */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1106 | if (e1000_read_mac_addr(hw)) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1107 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | } |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1109 | /* don't block initalization here due to bad MAC address */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1110 | memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len); |
| 1111 | memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1113 | if (!is_valid_ether_addr(netdev->perm_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1116 | e1000_get_bus_info(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
| 1118 | init_timer(&adapter->tx_fifo_stall_timer); |
| 1119 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1120 | adapter->tx_fifo_stall_timer.data = (unsigned long)adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
| 1122 | init_timer(&adapter->watchdog_timer); |
| 1123 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 1124 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 1125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | init_timer(&adapter->phy_info_timer); |
| 1127 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1128 | adapter->phy_info_timer.data = (unsigned long)adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1130 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | e1000_check_options(adapter); |
| 1133 | |
| 1134 | /* Initial Wake on LAN setting |
| 1135 | * If APM wake is enabled in the EEPROM, |
| 1136 | * enable the ACPI Magic Packet filter |
| 1137 | */ |
| 1138 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1139 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | case e1000_82542_rev2_0: |
| 1141 | case e1000_82542_rev2_1: |
| 1142 | case e1000_82543: |
| 1143 | break; |
| 1144 | case e1000_82544: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1145 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1147 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 1148 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1149 | case e1000_ich8lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1150 | e1000_read_eeprom(hw, |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1151 | EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
| 1152 | eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
| 1153 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | case e1000_82546: |
| 1155 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1156 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1157 | case e1000_80003es2lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1158 | if (er32(STATUS) & E1000_STATUS_FUNC_1){ |
| 1159 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1161 | break; |
| 1162 | } |
| 1163 | /* Fall Through */ |
| 1164 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1165 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1167 | break; |
| 1168 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1169 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1170 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1171 | |
| 1172 | /* now that we have the eeprom settings, apply the special cases |
| 1173 | * where the eeprom may be wrong or the board simply won't support |
| 1174 | * wake on lan on a particular port */ |
| 1175 | switch (pdev->device) { |
| 1176 | case E1000_DEV_ID_82546GB_PCIE: |
| 1177 | adapter->eeprom_wol = 0; |
| 1178 | break; |
| 1179 | case E1000_DEV_ID_82546EB_FIBER: |
| 1180 | case E1000_DEV_ID_82546GB_FIBER: |
| 1181 | case E1000_DEV_ID_82571EB_FIBER: |
| 1182 | /* Wake events only supported on port A for dual fiber |
| 1183 | * regardless of eeprom setting */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1184 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1185 | adapter->eeprom_wol = 0; |
| 1186 | break; |
| 1187 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1188 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 1189 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 1190 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
Auke Kok | f4ec7f9 | 2007-08-30 11:23:58 -0700 | [diff] [blame] | 1191 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1192 | /* if quad port adapter, disable WoL on all but port A */ |
| 1193 | if (global_quad_port_a != 0) |
| 1194 | adapter->eeprom_wol = 0; |
| 1195 | else |
| 1196 | adapter->quad_port_a = 1; |
| 1197 | /* Reset for multiple quad port adapters */ |
| 1198 | if (++global_quad_port_a == 4) |
| 1199 | global_quad_port_a = 0; |
| 1200 | break; |
| 1201 | } |
| 1202 | |
| 1203 | /* initialize the wol settings based on the eeprom settings */ |
| 1204 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | de12648 | 2008-11-07 20:30:19 +0000 | [diff] [blame] | 1205 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1207 | /* print bus type/speed/width info */ |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1208 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 1209 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 1210 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 1211 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 1212 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 1213 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 1214 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 1215 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 1216 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 1217 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 1218 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 1219 | "32-bit")); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1220 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1221 | printk("%pM\n", netdev->dev_addr); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1222 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1223 | if (hw->bus_type == e1000_bus_type_pci_express) { |
Auke Kok | 14782ca | 2008-02-11 09:25:46 -0800 | [diff] [blame] | 1224 | DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no " |
| 1225 | "longer be supported by this driver in the future.\n", |
| 1226 | pdev->vendor, pdev->device); |
| 1227 | DPRINTK(PROBE, WARNING, "please use the \"e1000e\" " |
| 1228 | "driver instead.\n"); |
| 1229 | } |
| 1230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | /* reset the hardware with the new settings */ |
| 1232 | e1000_reset(adapter); |
| 1233 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1234 | /* If the controller is 82573 and f/w is AMT, do not set |
| 1235 | * DRV_LOAD until the interface is up. For all other cases, |
| 1236 | * let the f/w know that the h/w is now under the control |
| 1237 | * of the driver. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1238 | if (hw->mac_type != e1000_82573 || |
| 1239 | !e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1240 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1241 | |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1242 | strcpy(netdev->name, "eth%d"); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 1243 | err = register_netdev(netdev); |
| 1244 | if (err) |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1245 | goto err_register; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1246 | |
Jesse Brandeburg | eb62efd | 2009-04-17 20:44:36 +0000 | [diff] [blame] | 1247 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 1248 | netif_carrier_off(netdev); |
| 1249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 1251 | |
| 1252 | cards_found++; |
| 1253 | return 0; |
| 1254 | |
| 1255 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1256 | e1000_release_hw_control(adapter); |
| 1257 | err_eeprom: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1258 | if (!e1000_check_phy_reset_block(hw)) |
| 1259 | e1000_phy_hw_reset(hw); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1260 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1261 | if (hw->flash_address) |
| 1262 | iounmap(hw->flash_address); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1263 | err_flashmap: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1264 | kfree(adapter->tx_ring); |
| 1265 | kfree(adapter->rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | err_sw_init: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1267 | iounmap(hw->hw_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | err_ioremap: |
| 1269 | free_netdev(netdev); |
| 1270 | err_alloc_etherdev: |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1271 | pci_release_selected_regions(pdev, bars); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1272 | err_pci_reg: |
| 1273 | err_dma: |
| 1274 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return err; |
| 1276 | } |
| 1277 | |
| 1278 | /** |
| 1279 | * e1000_remove - Device Removal Routine |
| 1280 | * @pdev: PCI device information struct |
| 1281 | * |
| 1282 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1283 | * that it should release a PCI device. The could be caused by a |
| 1284 | * Hot-Plug event, or because the driver is going to be removed from |
| 1285 | * memory. |
| 1286 | **/ |
| 1287 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1288 | static void __devexit e1000_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | { |
| 1290 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1291 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1292 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 1294 | cancel_work_sync(&adapter->reset_task); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1295 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1296 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1298 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1299 | * would have already happened in close and is redundant. */ |
| 1300 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1301 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1302 | unregister_netdev(netdev); |
| 1303 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1304 | if (!e1000_check_phy_reset_block(hw)) |
| 1305 | e1000_phy_hw_reset(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1307 | kfree(adapter->tx_ring); |
| 1308 | kfree(adapter->rx_ring); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1309 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1310 | iounmap(hw->hw_addr); |
| 1311 | if (hw->flash_address) |
| 1312 | iounmap(hw->flash_address); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1313 | pci_release_selected_regions(pdev, adapter->bars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
| 1315 | free_netdev(netdev); |
| 1316 | |
| 1317 | pci_disable_device(pdev); |
| 1318 | } |
| 1319 | |
| 1320 | /** |
| 1321 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1322 | * @adapter: board private structure to initialize |
| 1323 | * |
| 1324 | * e1000_sw_init initializes the Adapter private data structure. |
| 1325 | * Fields are initialized based on PCI device information and |
| 1326 | * OS network device settings (MTU size). |
| 1327 | **/ |
| 1328 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1329 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | { |
| 1331 | struct e1000_hw *hw = &adapter->hw; |
| 1332 | struct net_device *netdev = adapter->netdev; |
| 1333 | struct pci_dev *pdev = adapter->pdev; |
| 1334 | |
| 1335 | /* PCI config space info */ |
| 1336 | |
| 1337 | hw->vendor_id = pdev->vendor; |
| 1338 | hw->device_id = pdev->device; |
| 1339 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1340 | hw->subsystem_id = pdev->subsystem_device; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1341 | hw->revision_id = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 1344 | |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1345 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | hw->max_frame_size = netdev->mtu + |
| 1347 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1348 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 1349 | |
| 1350 | /* identify the MAC */ |
| 1351 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1352 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 1354 | return -EIO; |
| 1355 | } |
| 1356 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1357 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | default: |
| 1359 | break; |
| 1360 | case e1000_82541: |
| 1361 | case e1000_82547: |
| 1362 | case e1000_82541_rev_2: |
| 1363 | case e1000_82547_rev_2: |
| 1364 | hw->phy_init_script = 1; |
| 1365 | break; |
| 1366 | } |
| 1367 | |
| 1368 | e1000_set_media_type(hw); |
| 1369 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1370 | hw->wait_autoneg_complete = false; |
| 1371 | hw->tbi_compatibility_en = true; |
| 1372 | hw->adaptive_ifs = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
| 1374 | /* Copper options */ |
| 1375 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1376 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | hw->mdix = AUTO_ALL_MODES; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1378 | hw->disable_polarity_correction = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1380 | } |
| 1381 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1382 | adapter->num_tx_queues = 1; |
| 1383 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1384 | |
| 1385 | if (e1000_alloc_queues(adapter)) { |
| 1386 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1387 | return -ENOMEM; |
| 1388 | } |
| 1389 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1390 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1391 | e1000_irq_disable(adapter); |
| 1392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1395 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | return 0; |
| 1398 | } |
| 1399 | |
| 1400 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1401 | * e1000_alloc_queues - Allocate memory for all rings |
| 1402 | * @adapter: board private structure to initialize |
| 1403 | * |
| 1404 | * We allocate one ring per queue at run-time since we don't know the |
Wang Chen | 3e1d7cd | 2008-12-03 22:07:10 -0800 | [diff] [blame] | 1405 | * number of queues at compile-time. |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1406 | **/ |
| 1407 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1408 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1409 | { |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1410 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1411 | sizeof(struct e1000_tx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1412 | if (!adapter->tx_ring) |
| 1413 | return -ENOMEM; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1414 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1415 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1416 | sizeof(struct e1000_rx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1417 | if (!adapter->rx_ring) { |
| 1418 | kfree(adapter->tx_ring); |
| 1419 | return -ENOMEM; |
| 1420 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1421 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1422 | return E1000_SUCCESS; |
| 1423 | } |
| 1424 | |
| 1425 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | * e1000_open - Called when a network interface is made active |
| 1427 | * @netdev: network interface device structure |
| 1428 | * |
| 1429 | * Returns 0 on success, negative value on failure |
| 1430 | * |
| 1431 | * The open entry point is called when a network interface is made |
| 1432 | * active by the system (IFF_UP). At this point all resources needed |
| 1433 | * for transmit and receive operations are allocated, the interrupt |
| 1434 | * handler is registered with the OS, the watchdog timer is started, |
| 1435 | * and the stack is notified that the interface is ready. |
| 1436 | **/ |
| 1437 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1438 | static int e1000_open(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1440 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1441 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | int err; |
| 1443 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1444 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1445 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1446 | return -EBUSY; |
| 1447 | |
Jesse Brandeburg | eb62efd | 2009-04-17 20:44:36 +0000 | [diff] [blame] | 1448 | netif_carrier_off(netdev); |
| 1449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | /* allocate transmit descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1451 | err = e1000_setup_all_tx_resources(adapter); |
| 1452 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | goto err_setup_tx; |
| 1454 | |
| 1455 | /* allocate receive descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1456 | err = e1000_setup_all_rx_resources(adapter); |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1457 | if (err) |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1458 | goto err_setup_rx; |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1459 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1460 | e1000_power_up_phy(adapter); |
| 1461 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1462 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1463 | if ((hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1464 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1465 | e1000_update_mng_vlan(adapter); |
| 1466 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1468 | /* If AMT is enabled, let the firmware know that the network |
| 1469 | * interface is now open */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1470 | if (hw->mac_type == e1000_82573 && |
| 1471 | e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1472 | e1000_get_hw_control(adapter); |
| 1473 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1474 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1475 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1476 | * as soon as we call pci_request_irq, so we have to setup our |
| 1477 | * clean_rx handler before we do so. */ |
| 1478 | e1000_configure(adapter); |
| 1479 | |
| 1480 | err = e1000_request_irq(adapter); |
| 1481 | if (err) |
| 1482 | goto err_req_irq; |
| 1483 | |
| 1484 | /* From here on the code is the same as e1000_up() */ |
| 1485 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 1486 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1487 | napi_enable(&adapter->napi); |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1488 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1489 | e1000_irq_enable(adapter); |
| 1490 | |
Ben Hutchings | 076152d | 2008-07-18 17:50:57 -0700 | [diff] [blame] | 1491 | netif_start_queue(netdev); |
| 1492 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1493 | /* fire a link status change interrupt to start the watchdog */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1494 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | return E1000_SUCCESS; |
| 1497 | |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1498 | err_req_irq: |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1499 | e1000_release_hw_control(adapter); |
| 1500 | e1000_power_down_phy(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1501 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1503 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | err_setup_tx: |
| 1505 | e1000_reset(adapter); |
| 1506 | |
| 1507 | return err; |
| 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * e1000_close - Disables a network interface |
| 1512 | * @netdev: network interface device structure |
| 1513 | * |
| 1514 | * Returns 0, this is not allowed to fail |
| 1515 | * |
| 1516 | * The close entry point is called when an interface is de-activated |
| 1517 | * by the OS. The hardware is still under the drivers control, but |
| 1518 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1519 | * hardware, and all transmit and receive resources are freed. |
| 1520 | **/ |
| 1521 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1522 | static int e1000_close(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1524 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1525 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1527 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1529 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1530 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1532 | e1000_free_all_tx_resources(adapter); |
| 1533 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1535 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1536 | * the same ID is registered on the host OS (let 8021q kill it) */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1537 | if ((hw->mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1538 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1539 | !(adapter->vlgrp && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1540 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1541 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1542 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1543 | |
| 1544 | /* If AMT is enabled, let the firmware know that the network |
| 1545 | * interface is now closed */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1546 | if (hw->mac_type == e1000_82573 && |
| 1547 | e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1548 | e1000_release_hw_control(adapter); |
| 1549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1555 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1556 | * @start: address of beginning of memory |
| 1557 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1559 | static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start, |
| 1560 | unsigned long len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1562 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1563 | unsigned long begin = (unsigned long)start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | unsigned long end = begin + len; |
| 1565 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1566 | /* First rev 82545 and 82546 need to not allow any memory |
| 1567 | * write location to cross 64k boundary due to errata 23 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1568 | if (hw->mac_type == e1000_82545 || |
| 1569 | hw->mac_type == e1000_82546) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1570 | return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1573 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1578 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1579 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | * |
| 1581 | * Return 0 on success, negative on failure |
| 1582 | **/ |
| 1583 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1584 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1585 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | struct pci_dev *pdev = adapter->pdev; |
| 1588 | int size; |
| 1589 | |
| 1590 | size = sizeof(struct e1000_buffer) * txdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1591 | txdr->buffer_info = vmalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1592 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1593 | DPRINTK(PROBE, ERR, |
| 1594 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | return -ENOMEM; |
| 1596 | } |
| 1597 | memset(txdr->buffer_info, 0, size); |
| 1598 | |
| 1599 | /* round up to nearest 4K */ |
| 1600 | |
| 1601 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1602 | txdr->size = ALIGN(txdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | |
| 1604 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
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 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1608 | DPRINTK(PROBE, ERR, |
| 1609 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | return -ENOMEM; |
| 1611 | } |
| 1612 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1613 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1615 | void *olddesc = txdr->desc; |
| 1616 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1617 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1618 | "at %p\n", txdr->size, txdr->desc); |
| 1619 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1621 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1622 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1624 | goto setup_tx_desc_die; |
| 1625 | } |
| 1626 | |
| 1627 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1628 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1629 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1630 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1632 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1633 | "Unable to allocate aligned memory " |
| 1634 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | vfree(txdr->buffer_info); |
| 1636 | return -ENOMEM; |
| 1637 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1638 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1640 | } |
| 1641 | } |
| 1642 | memset(txdr->desc, 0, txdr->size); |
| 1643 | |
| 1644 | txdr->next_to_use = 0; |
| 1645 | txdr->next_to_clean = 0; |
| 1646 | |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
| 1650 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1651 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1652 | * (Descriptors) for all queues |
| 1653 | * @adapter: board private structure |
| 1654 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1655 | * Return 0 on success, negative on failure |
| 1656 | **/ |
| 1657 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1658 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1659 | { |
| 1660 | int i, err = 0; |
| 1661 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1662 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1663 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1664 | if (err) { |
| 1665 | DPRINTK(PROBE, ERR, |
| 1666 | "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1667 | for (i-- ; i >= 0; i--) |
| 1668 | e1000_free_tx_resources(adapter, |
| 1669 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1670 | break; |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | return err; |
| 1675 | } |
| 1676 | |
| 1677 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1679 | * @adapter: board private structure |
| 1680 | * |
| 1681 | * Configure the Tx unit of the MAC after a reset. |
| 1682 | **/ |
| 1683 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1684 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1686 | u64 tdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1687 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1688 | u32 tdlen, tctl, tipg, tarc; |
| 1689 | u32 ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
| 1691 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1692 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1693 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1694 | case 1: |
| 1695 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1696 | tdba = adapter->tx_ring[0].dma; |
| 1697 | tdlen = adapter->tx_ring[0].count * |
| 1698 | sizeof(struct e1000_tx_desc); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1699 | ew32(TDLEN, tdlen); |
| 1700 | ew32(TDBAH, (tdba >> 32)); |
| 1701 | ew32(TDBAL, (tdba & 0x00000000ffffffffULL)); |
| 1702 | ew32(TDT, 0); |
| 1703 | ew32(TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1704 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1705 | 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] | 1706 | break; |
| 1707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | |
| 1709 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1710 | if (hw->mac_type <= e1000_82547_rev_2 && |
Jesse Brandeburg | d89b6c6 | 2006-12-15 10:38:32 +0100 | [diff] [blame] | 1711 | (hw->media_type == e1000_media_type_fiber || |
| 1712 | hw->media_type == e1000_media_type_internal_serdes)) |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1713 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1714 | else |
| 1715 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1716 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1717 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | case e1000_82542_rev2_0: |
| 1719 | case e1000_82542_rev2_1: |
| 1720 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1721 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1722 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1724 | case e1000_80003es2lan: |
| 1725 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1726 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1727 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1729 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1730 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1731 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1733 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1734 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1735 | ew32(TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | |
| 1737 | /* Set the Tx Interrupt Delay register */ |
| 1738 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1739 | ew32(TIDV, adapter->tx_int_delay); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1740 | if (hw->mac_type >= e1000_82540) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1741 | ew32(TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
| 1743 | /* Program the Transmit Control Register */ |
| 1744 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1745 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1747 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1749 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1750 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1751 | tarc = er32(TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1752 | /* set the speed mode bit, we'll clear it if we're not at |
| 1753 | * gigabit link later */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1754 | tarc |= (1 << 21); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1755 | ew32(TARC0, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1756 | } else if (hw->mac_type == e1000_80003es2lan) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1757 | tarc = er32(TARC0); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1758 | tarc |= 1; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1759 | ew32(TARC0, tarc); |
| 1760 | tarc = er32(TARC1); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1761 | tarc |= 1; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1762 | ew32(TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1763 | } |
| 1764 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1765 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
| 1767 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1768 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1769 | |
| 1770 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1771 | if (adapter->tx_int_delay) |
| 1772 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1774 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1776 | else |
| 1777 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1778 | |
| 1779 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1780 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1781 | if (hw->mac_type == e1000_82544 && |
| 1782 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1784 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1785 | ew32(TCTL, tctl); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | /** |
| 1790 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1791 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1792 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | * |
| 1794 | * Returns 0 on success, negative on failure |
| 1795 | **/ |
| 1796 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1797 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1798 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1800 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1802 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | |
| 1804 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1805 | rxdr->buffer_info = vmalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1806 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1807 | DPRINTK(PROBE, ERR, |
| 1808 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | return -ENOMEM; |
| 1810 | } |
| 1811 | memset(rxdr->buffer_info, 0, size); |
| 1812 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1813 | if (hw->mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1814 | desc_len = sizeof(struct e1000_rx_desc); |
| 1815 | else |
| 1816 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | /* Round up to nearest 4K */ |
| 1819 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1820 | rxdr->size = rxdr->count * desc_len; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1821 | rxdr->size = ALIGN(rxdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
| 1823 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1824 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1825 | if (!rxdr->desc) { |
| 1826 | DPRINTK(PROBE, ERR, |
| 1827 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | vfree(rxdr->buffer_info); |
| 1830 | return -ENOMEM; |
| 1831 | } |
| 1832 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1833 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1835 | void *olddesc = rxdr->desc; |
| 1836 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1837 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1838 | "at %p\n", rxdr->size, rxdr->desc); |
| 1839 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1841 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1842 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1844 | DPRINTK(PROBE, ERR, |
| 1845 | "Unable to allocate memory " |
| 1846 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | goto setup_rx_desc_die; |
| 1848 | } |
| 1849 | |
| 1850 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1851 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1852 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1853 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1855 | DPRINTK(PROBE, ERR, |
| 1856 | "Unable to allocate aligned memory " |
| 1857 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1858 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1860 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1862 | } |
| 1863 | } |
| 1864 | memset(rxdr->desc, 0, rxdr->size); |
| 1865 | |
| 1866 | rxdr->next_to_clean = 0; |
| 1867 | rxdr->next_to_use = 0; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 1868 | rxdr->rx_skb_top = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
| 1870 | return 0; |
| 1871 | } |
| 1872 | |
| 1873 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1874 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1875 | * (Descriptors) for all queues |
| 1876 | * @adapter: board private structure |
| 1877 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1878 | * Return 0 on success, negative on failure |
| 1879 | **/ |
| 1880 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1881 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1882 | { |
| 1883 | int i, err = 0; |
| 1884 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1885 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1886 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1887 | if (err) { |
| 1888 | DPRINTK(PROBE, ERR, |
| 1889 | "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1890 | for (i-- ; i >= 0; i--) |
| 1891 | e1000_free_rx_resources(adapter, |
| 1892 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1893 | break; |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | return err; |
| 1898 | } |
| 1899 | |
| 1900 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1901 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | * @adapter: Board private structure |
| 1903 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1904 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1906 | struct e1000_hw *hw = &adapter->hw; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 1907 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1909 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
| 1911 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1912 | |
| 1913 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1914 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1915 | (hw->mc_filter_type << E1000_RCTL_MO_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1917 | if (hw->tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | rctl |= E1000_RCTL_SBP; |
| 1919 | else |
| 1920 | rctl &= ~E1000_RCTL_SBP; |
| 1921 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1922 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1923 | rctl &= ~E1000_RCTL_LPE; |
| 1924 | else |
| 1925 | rctl |= E1000_RCTL_LPE; |
| 1926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1928 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1929 | rctl |= E1000_RCTL_BSEX; |
| 1930 | switch (adapter->rx_buffer_len) { |
| 1931 | case E1000_RXBUFFER_256: |
| 1932 | rctl |= E1000_RCTL_SZ_256; |
| 1933 | rctl &= ~E1000_RCTL_BSEX; |
| 1934 | break; |
| 1935 | case E1000_RXBUFFER_512: |
| 1936 | rctl |= E1000_RCTL_SZ_512; |
| 1937 | rctl &= ~E1000_RCTL_BSEX; |
| 1938 | break; |
| 1939 | case E1000_RXBUFFER_1024: |
| 1940 | rctl |= E1000_RCTL_SZ_1024; |
| 1941 | rctl &= ~E1000_RCTL_BSEX; |
| 1942 | break; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1943 | case E1000_RXBUFFER_2048: |
| 1944 | default: |
| 1945 | rctl |= E1000_RCTL_SZ_2048; |
| 1946 | rctl &= ~E1000_RCTL_BSEX; |
| 1947 | break; |
| 1948 | case E1000_RXBUFFER_4096: |
| 1949 | rctl |= E1000_RCTL_SZ_4096; |
| 1950 | break; |
| 1951 | case E1000_RXBUFFER_8192: |
| 1952 | rctl |= E1000_RCTL_SZ_8192; |
| 1953 | break; |
| 1954 | case E1000_RXBUFFER_16384: |
| 1955 | rctl |= E1000_RCTL_SZ_16384; |
| 1956 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1959 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1964 | * @adapter: board private structure |
| 1965 | * |
| 1966 | * Configure the Rx unit of the MAC after a reset. |
| 1967 | **/ |
| 1968 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1969 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1971 | u64 rdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1972 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1973 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1974 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 1975 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 1976 | rdlen = adapter->rx_ring[0].count * |
| 1977 | sizeof(struct e1000_rx_desc); |
| 1978 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 1979 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
| 1980 | } else { |
| 1981 | rdlen = adapter->rx_ring[0].count * |
| 1982 | sizeof(struct e1000_rx_desc); |
| 1983 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1984 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1985 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | |
| 1987 | /* disable receives while setting up the descriptors */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1988 | rctl = er32(RCTL); |
| 1989 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | |
| 1991 | /* set the Receive Delay Timer Register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1992 | ew32(RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1994 | if (hw->mac_type >= e1000_82540) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1995 | ew32(RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 1996 | if (adapter->itr_setting != 0) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1997 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2000 | if (hw->mac_type >= e1000_82571) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2001 | ctrl_ext = er32(CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2002 | /* Reset delay timers after every interrupt */ |
Auke Kok | 6fc7a7e | 2006-04-14 19:05:12 -0700 | [diff] [blame] | 2003 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2004 | /* Auto-Mask interrupts upon ICR access */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2005 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2006 | ew32(IAM, 0xffffffff); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2007 | ew32(CTRL_EXT, ctrl_ext); |
| 2008 | E1000_WRITE_FLUSH(); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2009 | } |
| 2010 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2011 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2012 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2013 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2014 | case 1: |
| 2015 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2016 | rdba = adapter->rx_ring[0].dma; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2017 | ew32(RDLEN, rdlen); |
| 2018 | ew32(RDBAH, (rdba >> 32)); |
| 2019 | ew32(RDBAL, (rdba & 0x00000000ffffffffULL)); |
| 2020 | ew32(RDT, 0); |
| 2021 | ew32(RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 2022 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 2023 | 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] | 2024 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2025 | } |
| 2026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2028 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2029 | rxcsum = er32(RXCSUM); |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2030 | if (adapter->rx_csum) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2031 | rxcsum |= E1000_RXCSUM_TUOFL; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2032 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2033 | /* don't need to clear IPPCSE as it defaults to 0 */ |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2034 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2035 | ew32(RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | /* Enable Receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2039 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2043 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 2044 | * @adapter: board private structure |
| 2045 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2046 | * |
| 2047 | * Free all transmit software resources |
| 2048 | **/ |
| 2049 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2050 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 2051 | struct e1000_tx_ring *tx_ring) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2052 | { |
| 2053 | struct pci_dev *pdev = adapter->pdev; |
| 2054 | |
| 2055 | e1000_clean_tx_ring(adapter, tx_ring); |
| 2056 | |
| 2057 | vfree(tx_ring->buffer_info); |
| 2058 | tx_ring->buffer_info = NULL; |
| 2059 | |
| 2060 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2061 | |
| 2062 | tx_ring->desc = NULL; |
| 2063 | } |
| 2064 | |
| 2065 | /** |
| 2066 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | * @adapter: board private structure |
| 2068 | * |
| 2069 | * Free all transmit software resources |
| 2070 | **/ |
| 2071 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2072 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2074 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2076 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2077 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2080 | static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 2081 | struct e1000_buffer *buffer_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | { |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2083 | buffer_info->dma = 0; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2084 | if (buffer_info->skb) { |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2085 | skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb, |
| 2086 | DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2088 | buffer_info->skb = NULL; |
| 2089 | } |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2090 | buffer_info->time_stamp = 0; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2091 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | /** |
| 2095 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2096 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2097 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | **/ |
| 2099 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2100 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 2101 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2103 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | struct e1000_buffer *buffer_info; |
| 2105 | unsigned long size; |
| 2106 | unsigned int i; |
| 2107 | |
| 2108 | /* Free all the Tx ring sk_buffs */ |
| 2109 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2110 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | buffer_info = &tx_ring->buffer_info[i]; |
| 2112 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2113 | } |
| 2114 | |
| 2115 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2116 | memset(tx_ring->buffer_info, 0, size); |
| 2117 | |
| 2118 | /* Zero out the descriptor ring */ |
| 2119 | |
| 2120 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2121 | |
| 2122 | tx_ring->next_to_use = 0; |
| 2123 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2124 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2126 | writel(0, hw->hw_addr + tx_ring->tdh); |
| 2127 | writel(0, hw->hw_addr + tx_ring->tdt); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2132 | * @adapter: board private structure |
| 2133 | **/ |
| 2134 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2135 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2136 | { |
| 2137 | int i; |
| 2138 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2139 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2140 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | /** |
| 2144 | * e1000_free_rx_resources - Free Rx Resources |
| 2145 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2146 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | * |
| 2148 | * Free all receive software resources |
| 2149 | **/ |
| 2150 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2151 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 2152 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | struct pci_dev *pdev = adapter->pdev; |
| 2155 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2156 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
| 2158 | vfree(rx_ring->buffer_info); |
| 2159 | rx_ring->buffer_info = NULL; |
| 2160 | |
| 2161 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2162 | |
| 2163 | rx_ring->desc = NULL; |
| 2164 | } |
| 2165 | |
| 2166 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2167 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2169 | * |
| 2170 | * Free all receive software resources |
| 2171 | **/ |
| 2172 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2173 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2174 | { |
| 2175 | int i; |
| 2176 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2177 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2178 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2179 | } |
| 2180 | |
| 2181 | /** |
| 2182 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2183 | * @adapter: board private structure |
| 2184 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | **/ |
| 2186 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2187 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2188 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2190 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | struct e1000_buffer *buffer_info; |
| 2192 | struct pci_dev *pdev = adapter->pdev; |
| 2193 | unsigned long size; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2194 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | |
| 2196 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2197 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 2199 | if (buffer_info->dma && |
| 2200 | adapter->clean_rx == e1000_clean_rx_irq) { |
| 2201 | pci_unmap_single(pdev, buffer_info->dma, |
| 2202 | buffer_info->length, |
| 2203 | PCI_DMA_FROMDEVICE); |
| 2204 | } else if (buffer_info->dma && |
| 2205 | adapter->clean_rx == e1000_clean_jumbo_rx_irq) { |
| 2206 | pci_unmap_page(pdev, buffer_info->dma, |
| 2207 | buffer_info->length, |
| 2208 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2211 | buffer_info->dma = 0; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 2212 | if (buffer_info->page) { |
| 2213 | put_page(buffer_info->page); |
| 2214 | buffer_info->page = NULL; |
| 2215 | } |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2216 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | dev_kfree_skb(buffer_info->skb); |
| 2218 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 2222 | /* there also may be some cached data from a chained receive */ |
| 2223 | if (rx_ring->rx_skb_top) { |
| 2224 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 2225 | rx_ring->rx_skb_top = NULL; |
| 2226 | } |
| 2227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2229 | memset(rx_ring->buffer_info, 0, size); |
| 2230 | |
| 2231 | /* Zero out the descriptor ring */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2233 | |
| 2234 | rx_ring->next_to_clean = 0; |
| 2235 | rx_ring->next_to_use = 0; |
| 2236 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2237 | writel(0, hw->hw_addr + rx_ring->rdh); |
| 2238 | writel(0, hw->hw_addr + rx_ring->rdt); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | /** |
| 2242 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2243 | * @adapter: board private structure |
| 2244 | **/ |
| 2245 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2246 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2247 | { |
| 2248 | int i; |
| 2249 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2250 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2251 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2255 | * and memory write and invalidate disabled for certain operations |
| 2256 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2257 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2259 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2261 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2263 | e1000_pci_clear_mwi(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2265 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | rctl |= E1000_RCTL_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2267 | ew32(RCTL, rctl); |
| 2268 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | mdelay(5); |
| 2270 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2271 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2272 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2275 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2277 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2279 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2281 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | rctl &= ~E1000_RCTL_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2283 | ew32(RCTL, rctl); |
| 2284 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | mdelay(5); |
| 2286 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2287 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 2288 | e1000_pci_set_mwi(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2290 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2291 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2292 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2293 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2294 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | /** |
| 2299 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2300 | * @netdev: network interface device structure |
| 2301 | * @p: pointer to an address structure |
| 2302 | * |
| 2303 | * Returns 0 on success, negative on failure |
| 2304 | **/ |
| 2305 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2306 | static int e1000_set_mac(struct net_device *netdev, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2308 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2309 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | struct sockaddr *addr = p; |
| 2311 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2312 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | return -EADDRNOTAVAIL; |
| 2314 | |
| 2315 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2316 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2317 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | e1000_enter_82542_rst(adapter); |
| 2319 | |
| 2320 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2321 | memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2323 | e1000_rar_set(hw, hw->mac_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2325 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2326 | * due to controller reset from the other port. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2327 | if (hw->mac_type == e1000_82571) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2328 | /* activate the work around */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2329 | hw->laa_is_present = 1; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2330 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2331 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2332 | * between the time RAR[0] gets clobbered and the time it |
| 2333 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2334 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2335 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2336 | * RAR[14] */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2337 | e1000_rar_set(hw, hw->mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2338 | E1000_RAR_ENTRIES - 1); |
| 2339 | } |
| 2340 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2341 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | e1000_leave_82542_rst(adapter); |
| 2343 | |
| 2344 | return 0; |
| 2345 | } |
| 2346 | |
| 2347 | /** |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2348 | * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | * @netdev: network interface device structure |
| 2350 | * |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2351 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 2352 | * address lists or the network interface flags are updated. This routine is |
| 2353 | * responsible for configuring the hardware for proper unicast, multicast, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | * promiscuous mode, and all-multi behavior. |
| 2355 | **/ |
| 2356 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2357 | static void e1000_set_rx_mode(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2359 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2361 | struct netdev_hw_addr *ha; |
| 2362 | bool use_uc = false; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2363 | struct dev_addr_list *mc_ptr; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2364 | u32 rctl; |
| 2365 | u32 hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2366 | int i, rar_entries = E1000_RAR_ENTRIES; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2367 | int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
| 2368 | E1000_NUM_MTA_REGISTERS_ICH8LAN : |
| 2369 | E1000_NUM_MTA_REGISTERS; |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2370 | u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC); |
| 2371 | |
| 2372 | if (!mcarray) { |
| 2373 | DPRINTK(PROBE, ERR, "memory allocation failed\n"); |
| 2374 | return; |
| 2375 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2376 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2377 | if (hw->mac_type == e1000_ich8lan) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2378 | rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2380 | /* reserve RAR[14] for LAA over-write work-around */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2381 | if (hw->mac_type == e1000_82571) |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2382 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2384 | /* Check for Promiscuous and All Multicast modes */ |
| 2385 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2386 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2388 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2390 | rctl &= ~E1000_RCTL_VFE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2392 | if (netdev->flags & IFF_ALLMULTI) { |
| 2393 | rctl |= E1000_RCTL_MPE; |
| 2394 | } else { |
| 2395 | rctl &= ~E1000_RCTL_MPE; |
| 2396 | } |
Patrick McHardy | 78ed11a | 2008-07-16 20:16:14 -0700 | [diff] [blame] | 2397 | if (adapter->hw.mac_type != e1000_ich8lan) |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2398 | rctl |= E1000_RCTL_VFE; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2399 | } |
| 2400 | |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2401 | if (netdev->uc.count > rar_entries - 1) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2402 | rctl |= E1000_RCTL_UPE; |
| 2403 | } else if (!(netdev->flags & IFF_PROMISC)) { |
| 2404 | rctl &= ~E1000_RCTL_UPE; |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2405 | use_uc = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2408 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
| 2410 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2411 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2412 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | e1000_enter_82542_rst(adapter); |
| 2414 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2415 | /* load the first 14 addresses into the exact filters 1-14. Unicast |
| 2416 | * addresses take precedence to avoid disabling unicast filtering |
| 2417 | * when possible. |
| 2418 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | * RAR 0 is used for the station MAC adddress |
| 2420 | * 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] | 2421 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | */ |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2423 | i = 1; |
| 2424 | if (use_uc) |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2425 | list_for_each_entry(ha, &netdev->uc.list, list) { |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2426 | if (i == rar_entries) |
| 2427 | break; |
| 2428 | e1000_rar_set(hw, ha->addr, i++); |
| 2429 | } |
| 2430 | |
| 2431 | WARN_ON(i == rar_entries); |
| 2432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | mc_ptr = netdev->mc_list; |
| 2434 | |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2435 | for (; i < rar_entries; i++) { |
| 2436 | if (mc_ptr) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2437 | e1000_rar_set(hw, mc_ptr->da_addr, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | mc_ptr = mc_ptr->next; |
| 2439 | } else { |
| 2440 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2441 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2443 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | } |
| 2445 | } |
| 2446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | /* load any remaining addresses into the hash table */ |
| 2448 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2449 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2450 | u32 hash_reg, hash_bit, mta; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2451 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr); |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2452 | hash_reg = (hash_value >> 5) & 0x7F; |
| 2453 | hash_bit = hash_value & 0x1F; |
| 2454 | mta = (1 << hash_bit); |
| 2455 | mcarray[hash_reg] |= mta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2458 | /* write the hash table completely, write from bottom to avoid |
| 2459 | * both stupid write combining chipsets, and flushing each write */ |
| 2460 | for (i = mta_reg_count - 1; i >= 0 ; i--) { |
| 2461 | /* |
| 2462 | * If we are on an 82544 has an errata where writing odd |
| 2463 | * offsets overwrites the previous even offset, but writing |
| 2464 | * backwards over the range solves the issue by always |
| 2465 | * writing the odd offset first |
| 2466 | */ |
| 2467 | E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]); |
| 2468 | } |
| 2469 | E1000_WRITE_FLUSH(); |
| 2470 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2471 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | e1000_leave_82542_rst(adapter); |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2473 | |
| 2474 | kfree(mcarray); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2478 | * the phy */ |
| 2479 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2480 | static void e1000_update_phy_info(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2482 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2483 | struct e1000_hw *hw = &adapter->hw; |
| 2484 | e1000_phy_get_info(hw, &adapter->phy_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2489 | * @data: pointer to adapter cast into an unsigned long |
| 2490 | **/ |
| 2491 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2492 | static void e1000_82547_tx_fifo_stall(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2494 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2495 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2497 | u32 tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2499 | if (atomic_read(&adapter->tx_fifo_stall)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2500 | if ((er32(TDT) == er32(TDH)) && |
| 2501 | (er32(TDFT) == er32(TDFH)) && |
| 2502 | (er32(TDFTS) == er32(TDFHS))) { |
| 2503 | tctl = er32(TCTL); |
| 2504 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 2505 | ew32(TDFT, adapter->tx_head_addr); |
| 2506 | ew32(TDFH, adapter->tx_head_addr); |
| 2507 | ew32(TDFTS, adapter->tx_head_addr); |
| 2508 | ew32(TDFHS, adapter->tx_head_addr); |
| 2509 | ew32(TCTL, tctl); |
| 2510 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
| 2512 | adapter->tx_fifo_head = 0; |
| 2513 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2514 | netif_wake_queue(netdev); |
| 2515 | } else { |
| 2516 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2517 | } |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | /** |
| 2522 | * e1000_watchdog - Timer Call-back |
| 2523 | * @data: pointer to adapter cast into an unsigned long |
| 2524 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2525 | static void e1000_watchdog(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2527 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2528 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2530 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2531 | u32 link, tctl; |
| 2532 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2534 | ret_val = e1000_check_for_link(hw); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2535 | if ((ret_val == E1000_ERR_PHY) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2536 | (hw->phy_type == e1000_phy_igp_3) && |
| 2537 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2538 | /* See e1000_kumeran_lock_loss_workaround() */ |
| 2539 | DPRINTK(LINK, INFO, |
| 2540 | "Gigabit has been disabled, downgrading speed\n"); |
| 2541 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2542 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2543 | if (hw->mac_type == e1000_82573) { |
| 2544 | e1000_enable_tx_pkt_filtering(hw); |
| 2545 | if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2546 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2549 | if ((hw->media_type == e1000_media_type_internal_serdes) && |
| 2550 | !(er32(TXCW) & E1000_TXCW_ANE)) |
| 2551 | link = !hw->serdes_link_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | else |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2553 | link = er32(STATUS) & E1000_STATUS_LU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2555 | if (link) { |
| 2556 | if (!netif_carrier_ok(netdev)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2557 | u32 ctrl; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2558 | bool txb2b = true; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2559 | e1000_get_speed_and_duplex(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | &adapter->link_speed, |
| 2561 | &adapter->link_duplex); |
| 2562 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2563 | ctrl = er32(CTRL); |
Jeff Kirsher | b30c4d8f | 2008-11-27 00:22:45 -0800 | [diff] [blame] | 2564 | printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, " |
| 2565 | "Flow Control: %s\n", |
| 2566 | netdev->name, |
| 2567 | adapter->link_speed, |
| 2568 | adapter->link_duplex == FULL_DUPLEX ? |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2569 | "Full Duplex" : "Half Duplex", |
| 2570 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2571 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2572 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2573 | E1000_CTRL_TFCE) ? "TX" : "None" ))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2575 | /* tweak tx_queue_len according to speed/duplex |
| 2576 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2577 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2578 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2579 | switch (adapter->link_speed) { |
| 2580 | case SPEED_10: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2581 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2582 | netdev->tx_queue_len = 10; |
| 2583 | adapter->tx_timeout_factor = 8; |
| 2584 | break; |
| 2585 | case SPEED_100: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2586 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2587 | netdev->tx_queue_len = 100; |
| 2588 | /* maybe add some timeout factor ? */ |
| 2589 | break; |
| 2590 | } |
| 2591 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2592 | if ((hw->mac_type == e1000_82571 || |
| 2593 | hw->mac_type == e1000_82572) && |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2594 | !txb2b) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2595 | u32 tarc0; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2596 | tarc0 = er32(TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2597 | tarc0 &= ~(1 << 21); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2598 | ew32(TARC0, tarc0); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2599 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2600 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2601 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2602 | * some hardware issues */ |
| 2603 | if (!adapter->tso_force && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2604 | hw->bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2605 | switch (adapter->link_speed) { |
| 2606 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2607 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2608 | DPRINTK(PROBE,INFO, |
| 2609 | "10/100 speed: disabling TSO\n"); |
| 2610 | netdev->features &= ~NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2611 | netdev->features &= ~NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2612 | break; |
| 2613 | case SPEED_1000: |
| 2614 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2615 | netdev->features |= NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2616 | break; |
| 2617 | default: |
| 2618 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2619 | break; |
| 2620 | } |
| 2621 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2622 | |
| 2623 | /* enable transmits in the hardware, need to do this |
| 2624 | * after setting TARC0 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2625 | tctl = er32(TCTL); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2626 | tctl |= E1000_TCTL_EN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2627 | ew32(TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | netif_carrier_on(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2630 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | adapter->smartspeed = 0; |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2632 | } else { |
| 2633 | /* make sure the receive unit is started */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2634 | if (hw->rx_needs_kicking) { |
| 2635 | u32 rctl = er32(RCTL); |
| 2636 | ew32(RCTL, rctl | E1000_RCTL_EN); |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | } |
| 2639 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2640 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | adapter->link_speed = 0; |
| 2642 | adapter->link_duplex = 0; |
Jeff Kirsher | b30c4d8f | 2008-11-27 00:22:45 -0800 | [diff] [blame] | 2643 | printk(KERN_INFO "e1000: %s NIC Link is Down\n", |
| 2644 | netdev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | netif_carrier_off(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2646 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2647 | |
| 2648 | /* 80003ES2LAN workaround-- |
| 2649 | * For packet buffer work-around on link down event; |
| 2650 | * disable receives in the ISR and |
| 2651 | * reset device here in the watchdog |
| 2652 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2653 | if (hw->mac_type == e1000_80003es2lan) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2654 | /* reset device */ |
| 2655 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | e1000_smartspeed(adapter); |
| 2659 | } |
| 2660 | |
| 2661 | e1000_update_stats(adapter); |
| 2662 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2663 | hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | adapter->tpt_old = adapter->stats.tpt; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2665 | hw->collision_delta = adapter->stats.colc - adapter->colc_old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | adapter->colc_old = adapter->stats.colc; |
| 2667 | |
| 2668 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2669 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2670 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2671 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2672 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2673 | e1000_update_adaptive(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2675 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2676 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | /* We've lost link, so the controller stops DMA, |
| 2678 | * but we've got queued Tx work that's never going |
| 2679 | * to get done, so reset controller to flush Tx. |
| 2680 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2681 | adapter->tx_timeout_count++; |
| 2682 | schedule_work(&adapter->reset_task); |
Jesse Brandeburg | c2d5ab4 | 2009-05-07 11:07:35 +0000 | [diff] [blame] | 2683 | /* return immediately since reset is imminent */ |
| 2684 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | /* Cause software interrupt to ensure rx ring is cleaned */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2689 | ew32(ICS, E1000_ICS_RXDMT0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2691 | /* Force detection of hung controller every watchdog period */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2692 | adapter->detect_tx_hung = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2694 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2695 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2696 | if (hw->mac_type == e1000_82571 && hw->laa_is_present) |
| 2697 | e1000_rar_set(hw, hw->mac_addr, 0); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | /* Reset the timer */ |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2700 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2703 | enum latency_range { |
| 2704 | lowest_latency = 0, |
| 2705 | low_latency = 1, |
| 2706 | bulk_latency = 2, |
| 2707 | latency_invalid = 255 |
| 2708 | }; |
| 2709 | |
| 2710 | /** |
| 2711 | * e1000_update_itr - update the dynamic ITR value based on statistics |
| 2712 | * Stores a new ITR value based on packets and byte |
| 2713 | * counts during the last interrupt. The advantage of per interrupt |
| 2714 | * computation is faster updates and more accurate ITR for the current |
| 2715 | * traffic pattern. Constants in this function were computed |
| 2716 | * based on theoretical maximum wire speed and thresholds were set based |
| 2717 | * on testing data as well as attempting to minimize response time |
| 2718 | * while increasing bulk throughput. |
| 2719 | * this functionality is controlled by the InterruptThrottleRate module |
| 2720 | * parameter (see e1000_param.c) |
| 2721 | * @adapter: pointer to adapter |
| 2722 | * @itr_setting: current adapter->itr |
| 2723 | * @packets: the number of packets during this measurement interval |
| 2724 | * @bytes: the number of bytes during this measurement interval |
| 2725 | **/ |
| 2726 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2727 | u16 itr_setting, int packets, int bytes) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2728 | { |
| 2729 | unsigned int retval = itr_setting; |
| 2730 | struct e1000_hw *hw = &adapter->hw; |
| 2731 | |
| 2732 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2733 | goto update_itr_done; |
| 2734 | |
| 2735 | if (packets == 0) |
| 2736 | goto update_itr_done; |
| 2737 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2738 | switch (itr_setting) { |
| 2739 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2740 | /* jumbo frames get bulk treatment*/ |
| 2741 | if (bytes/packets > 8000) |
| 2742 | retval = bulk_latency; |
| 2743 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2744 | retval = low_latency; |
| 2745 | break; |
| 2746 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2747 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2748 | /* jumbo frames need bulk latency setting */ |
| 2749 | if (bytes/packets > 8000) |
| 2750 | retval = bulk_latency; |
| 2751 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2752 | retval = bulk_latency; |
| 2753 | else if ((packets > 35)) |
| 2754 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2755 | } else if (bytes/packets > 2000) |
| 2756 | retval = bulk_latency; |
| 2757 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2758 | retval = lowest_latency; |
| 2759 | break; |
| 2760 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2761 | if (bytes > 25000) { |
| 2762 | if (packets > 35) |
| 2763 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2764 | } else if (bytes < 6000) { |
| 2765 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2766 | } |
| 2767 | break; |
| 2768 | } |
| 2769 | |
| 2770 | update_itr_done: |
| 2771 | return retval; |
| 2772 | } |
| 2773 | |
| 2774 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2775 | { |
| 2776 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2777 | u16 current_itr; |
| 2778 | u32 new_itr = adapter->itr; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2779 | |
| 2780 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2781 | return; |
| 2782 | |
| 2783 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2784 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2785 | current_itr = 0; |
| 2786 | new_itr = 4000; |
| 2787 | goto set_itr_now; |
| 2788 | } |
| 2789 | |
| 2790 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2791 | adapter->tx_itr, |
| 2792 | adapter->total_tx_packets, |
| 2793 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2794 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2795 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2796 | adapter->tx_itr = low_latency; |
| 2797 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2798 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2799 | adapter->rx_itr, |
| 2800 | adapter->total_rx_packets, |
| 2801 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2802 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2803 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2804 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2805 | |
| 2806 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2807 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2808 | switch (current_itr) { |
| 2809 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2810 | case lowest_latency: |
| 2811 | new_itr = 70000; |
| 2812 | break; |
| 2813 | case low_latency: |
| 2814 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2815 | break; |
| 2816 | case bulk_latency: |
| 2817 | new_itr = 4000; |
| 2818 | break; |
| 2819 | default: |
| 2820 | break; |
| 2821 | } |
| 2822 | |
| 2823 | set_itr_now: |
| 2824 | if (new_itr != adapter->itr) { |
| 2825 | /* this attempts to bias the interrupt rate towards Bulk |
| 2826 | * by adding intermediate steps when interrupt rate is |
| 2827 | * increasing */ |
| 2828 | new_itr = new_itr > adapter->itr ? |
| 2829 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2830 | new_itr; |
| 2831 | adapter->itr = new_itr; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2832 | ew32(ITR, 1000000000 / (new_itr * 256)); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | return; |
| 2836 | } |
| 2837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2839 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2840 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2841 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2843 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2844 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2845 | static int e1000_tso(struct e1000_adapter *adapter, |
| 2846 | struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2849 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2851 | u32 cmd_length = 0; |
| 2852 | u16 ipcse = 0, tucse, mss; |
| 2853 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | int err; |
| 2855 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2856 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | if (skb_header_cloned(skb)) { |
| 2858 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2859 | if (err) |
| 2860 | return err; |
| 2861 | } |
| 2862 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2863 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2864 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2865 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2866 | struct iphdr *iph = ip_hdr(skb); |
| 2867 | iph->tot_len = 0; |
| 2868 | iph->check = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2869 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2870 | iph->daddr, 0, |
| 2871 | IPPROTO_TCP, |
| 2872 | 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2873 | cmd_length = E1000_TXD_CMD_IP; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2874 | ipcse = skb_transport_offset(skb) - 1; |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2875 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2876 | ipv6_hdr(skb)->payload_len = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2877 | tcp_hdr(skb)->check = |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2878 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2879 | &ipv6_hdr(skb)->daddr, |
| 2880 | 0, IPPROTO_TCP, 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2881 | ipcse = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2882 | } |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 2883 | ipcss = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2884 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2885 | tucss = skb_transport_offset(skb); |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2886 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | tucse = 0; |
| 2888 | |
| 2889 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2890 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2892 | i = tx_ring->next_to_use; |
| 2893 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2894 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
| 2896 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2897 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2898 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2899 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2900 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2901 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2902 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2903 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2904 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2905 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2906 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2907 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2908 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2909 | if (++i == tx_ring->count) i = 0; |
| 2910 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2912 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2914 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | } |
| 2916 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2917 | static bool e1000_tx_csum(struct e1000_adapter *adapter, |
| 2918 | struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | { |
| 2920 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2921 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2923 | u8 css; |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2924 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2926 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 2927 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2929 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 2930 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2931 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 2932 | cmd_len |= E1000_TXD_CMD_TCP; |
| 2933 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 2934 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2935 | /* XXX not handling all IPV6 headers */ |
| 2936 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 2937 | cmd_len |= E1000_TXD_CMD_TCP; |
| 2938 | break; |
| 2939 | default: |
| 2940 | if (unlikely(net_ratelimit())) |
| 2941 | DPRINTK(DRV, WARNING, |
| 2942 | "checksum_partial proto=%x!\n", skb->protocol); |
| 2943 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | } |
| 2945 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2946 | css = skb_transport_offset(skb); |
| 2947 | |
| 2948 | i = tx_ring->next_to_use; |
| 2949 | buffer_info = &tx_ring->buffer_info[i]; |
| 2950 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 2951 | |
| 2952 | context_desc->lower_setup.ip_config = 0; |
| 2953 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 2954 | context_desc->upper_setup.tcp_fields.tucso = |
| 2955 | css + skb->csum_offset; |
| 2956 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2957 | context_desc->tcp_seg_setup.data = 0; |
| 2958 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 2959 | |
| 2960 | buffer_info->time_stamp = jiffies; |
| 2961 | buffer_info->next_to_watch = i; |
| 2962 | |
| 2963 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2964 | tx_ring->next_to_use = i; |
| 2965 | |
| 2966 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | #define E1000_MAX_TXD_PWR 12 |
| 2970 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2971 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2972 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 2973 | struct e1000_tx_ring *tx_ring, |
| 2974 | struct sk_buff *skb, unsigned int first, |
| 2975 | unsigned int max_per_txd, unsigned int nr_frags, |
| 2976 | unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2978 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2979 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2980 | unsigned int len = skb_headlen(skb); |
| 2981 | unsigned int offset, size, count = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | unsigned int f; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2983 | dma_addr_t *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | |
| 2985 | i = tx_ring->next_to_use; |
| 2986 | |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2987 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 2988 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2989 | return 0; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2990 | } |
| 2991 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2992 | map = skb_shinfo(skb)->dma_maps; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2993 | offset = 0; |
| 2994 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2995 | while (len) { |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2996 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | size = min(len, max_per_txd); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2998 | /* Workaround for Controller erratum -- |
| 2999 | * descriptor for non-tso packet in a linear SKB that follows a |
| 3000 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3001 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3002 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3003 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3004 | tx_ring->last_tx_tso = 0; |
| 3005 | size -= 4; |
| 3006 | } |
| 3007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | /* Workaround for premature desc write-backs |
| 3009 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3010 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | size -= 4; |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3012 | /* work-around for errata 10 and it applies |
| 3013 | * to all controllers in PCI-X mode |
| 3014 | * The fix is to make sure that the first descriptor of a |
| 3015 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 3016 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3017 | if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3018 | (size > 2015) && count == 0)) |
| 3019 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 3022 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3023 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 3025 | size > 4)) |
| 3026 | size -= 4; |
| 3027 | |
| 3028 | buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3029 | buffer_info->dma = skb_shinfo(skb)->dma_head + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3031 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | |
| 3033 | len -= size; |
| 3034 | offset += size; |
| 3035 | count++; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3036 | if (len) { |
| 3037 | i++; |
| 3038 | if (unlikely(i == tx_ring->count)) |
| 3039 | i = 0; |
| 3040 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3043 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | struct skb_frag_struct *frag; |
| 3045 | |
| 3046 | frag = &skb_shinfo(skb)->frags[f]; |
| 3047 | len = frag->size; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 3048 | offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3050 | while (len) { |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3051 | i++; |
| 3052 | if (unlikely(i == tx_ring->count)) |
| 3053 | i = 0; |
| 3054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | buffer_info = &tx_ring->buffer_info[i]; |
| 3056 | size = min(len, max_per_txd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | /* Workaround for premature desc write-backs |
| 3058 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3059 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | size -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | /* Workaround for potential 82544 hang in PCI-X. |
| 3062 | * Avoid terminating buffers within evenly-aligned |
| 3063 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3064 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 3066 | size > 4)) |
| 3067 | size -= 4; |
| 3068 | |
| 3069 | buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3070 | buffer_info->dma = map[f] + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3072 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
| 3074 | len -= size; |
| 3075 | offset += size; |
| 3076 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | tx_ring->buffer_info[i].skb = skb; |
| 3081 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3082 | |
| 3083 | return count; |
| 3084 | } |
| 3085 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3086 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 3087 | struct e1000_tx_ring *tx_ring, int tx_flags, |
| 3088 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3090 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | struct e1000_tx_desc *tx_desc = NULL; |
| 3092 | struct e1000_buffer *buffer_info; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3093 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | unsigned int i; |
| 3095 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3096 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3098 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3099 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3100 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3101 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3102 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3105 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3107 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3108 | } |
| 3109 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3110 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3112 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3113 | } |
| 3114 | |
| 3115 | i = tx_ring->next_to_use; |
| 3116 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3117 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | buffer_info = &tx_ring->buffer_info[i]; |
| 3119 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3120 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3121 | tx_desc->lower.data = |
| 3122 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3123 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3124 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3128 | |
| 3129 | /* Force memory writes to complete before letting h/w |
| 3130 | * know there are new descriptors to fetch. (Only |
| 3131 | * applicable for weak-ordered memory model archs, |
| 3132 | * such as IA-64). */ |
| 3133 | wmb(); |
| 3134 | |
| 3135 | tx_ring->next_to_use = i; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3136 | writel(i, hw->hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 3137 | /* we need this if more than one processor can write to our tail |
| 3138 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3139 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | /** |
| 3143 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 3144 | * The workaround is to avoid queuing a large packet that would span |
| 3145 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 3146 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 3147 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 3148 | * to the beginning of the Tx FIFO. |
| 3149 | **/ |
| 3150 | |
| 3151 | #define E1000_FIFO_HDR 0x10 |
| 3152 | #define E1000_82547_PAD_LEN 0x3E0 |
| 3153 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3154 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 3155 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3157 | u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 3158 | u32 skb_fifo_len = skb->len + E1000_FIFO_HDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 3160 | skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3162 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | goto no_fifo_stall_required; |
| 3164 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3165 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | return 1; |
| 3167 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3168 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3170 | return 1; |
| 3171 | } |
| 3172 | |
| 3173 | no_fifo_stall_required: |
| 3174 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3175 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3177 | return 0; |
| 3178 | } |
| 3179 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3180 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3181 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 3182 | struct sk_buff *skb) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3183 | { |
| 3184 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3185 | u16 length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3186 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3187 | if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) && |
| 3188 | ( hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3189 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 3190 | return 0; |
| 3191 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 3192 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3193 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3194 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 3195 | const struct iphdr *ip = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3196 | (struct iphdr *)((u8 *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3197 | if (IPPROTO_UDP == ip->protocol) { |
| 3198 | struct udphdr *udp = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3199 | (struct udphdr *)((u8 *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3200 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3201 | if (ntohs(udp->dest) == 67) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3202 | offset = (u8 *)udp + 8 - skb->data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3203 | length = skb->len - offset; |
| 3204 | |
| 3205 | return e1000_mng_write_dhcp_info(hw, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3206 | (u8 *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3207 | length); |
| 3208 | } |
| 3209 | } |
| 3210 | } |
| 3211 | } |
| 3212 | return 0; |
| 3213 | } |
| 3214 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3215 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3216 | { |
| 3217 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3218 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3219 | |
| 3220 | netif_stop_queue(netdev); |
| 3221 | /* Herbert's original patch had: |
| 3222 | * smp_mb__after_netif_stop_queue(); |
| 3223 | * but since that doesn't exist yet, just open code it. */ |
| 3224 | smp_mb(); |
| 3225 | |
| 3226 | /* We need to check again in a case another CPU has just |
| 3227 | * made room available. */ |
| 3228 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3229 | return -EBUSY; |
| 3230 | |
| 3231 | /* A reprieve! */ |
| 3232 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3233 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3234 | return 0; |
| 3235 | } |
| 3236 | |
| 3237 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3238 | struct e1000_tx_ring *tx_ring, int size) |
| 3239 | { |
| 3240 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3241 | return 0; |
| 3242 | return __e1000_maybe_stop_tx(netdev, size); |
| 3243 | } |
| 3244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3246 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3248 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3249 | struct e1000_hw *hw = &adapter->hw; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3250 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3252 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3253 | unsigned int tx_flags = 0; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3254 | unsigned int len = skb->len - skb->data_len; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3255 | unsigned int nr_frags; |
| 3256 | unsigned int mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3258 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3261 | /* This goes back to the question of how to logically map a tx queue |
| 3262 | * to a flow. Right now, performance is impacted slightly negatively |
| 3263 | * if using multiple tx queues. If the stack breaks away from a |
| 3264 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3265 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3266 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3267 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | dev_kfree_skb_any(skb); |
| 3269 | return NETDEV_TX_OK; |
| 3270 | } |
| 3271 | |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3272 | /* 82571 and newer doesn't need the workaround that limited descriptor |
| 3273 | * length to 4kB */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3274 | if (hw->mac_type >= e1000_82571) |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3275 | max_per_txd = 8192; |
| 3276 | |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3277 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3278 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | * make sure there is enough room in the FIFO before |
| 3280 | * initiating the DMA for each buffer. The calc is: |
| 3281 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3282 | * overrun the FIFO, adjust the max buffer len if mss |
| 3283 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3284 | if (mss) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3285 | u8 hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | max_per_txd = min(mss << 2, max_per_txd); |
| 3287 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3288 | |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3289 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3290 | * points to just header, pull a few bytes of payload from |
| 3291 | * frags into skb->data */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 3292 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3293 | if (skb->data_len && hdr_len == len) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3294 | switch (hw->mac_type) { |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3295 | unsigned int pull_size; |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3296 | case e1000_82544: |
| 3297 | /* Make sure we have room to chop off 4 bytes, |
| 3298 | * and that the end alignment will work out to |
| 3299 | * this hardware's requirements |
| 3300 | * NOTE: this is a TSO only workaround |
| 3301 | * if end byte alignment not correct move us |
| 3302 | * into the next dword */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3303 | if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3304 | break; |
| 3305 | /* fall through */ |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3306 | case e1000_82571: |
| 3307 | case e1000_82572: |
| 3308 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3309 | case e1000_ich8lan: |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3310 | pull_size = min((unsigned int)4, skb->data_len); |
| 3311 | if (!__pskb_pull_tail(skb, pull_size)) { |
Auke Kok | a5eafce | 2006-06-27 09:06:49 -0700 | [diff] [blame] | 3312 | DPRINTK(DRV, ERR, |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3313 | "__pskb_pull_tail failed.\n"); |
| 3314 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc7 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3315 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3316 | } |
| 3317 | len = skb->len - skb->data_len; |
| 3318 | break; |
| 3319 | default: |
| 3320 | /* do nothing */ |
| 3321 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3322 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | } |
| 3325 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3326 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3327 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3329 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3330 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3331 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3332 | 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] | 3333 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3336 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3337 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | count++; |
| 3339 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3340 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3341 | * in PCI-X mode, so add one more descriptor to the count |
| 3342 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3343 | if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3344 | (len > 2015))) |
| 3345 | count++; |
| 3346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3348 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3350 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3351 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | count += nr_frags; |
| 3353 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3354 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3355 | if (hw->tx_pkt_filtering && |
| 3356 | (hw->mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3357 | e1000_transfer_dhcp_info(adapter, skb); |
| 3358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | /* need: count + 2 desc gap to keep tail from touching |
| 3360 | * head, otherwise try next time */ |
Alexander Duyck | 8017943 | 2009-01-21 14:42:47 -0800 | [diff] [blame] | 3361 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3364 | if (unlikely(hw->mac_type == e1000_82547)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3365 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | netif_stop_queue(netdev); |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3367 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | return NETDEV_TX_BUSY; |
| 3369 | } |
| 3370 | } |
| 3371 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3372 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3374 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3375 | } |
| 3376 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3377 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3378 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3379 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | if (tso < 0) { |
| 3381 | dev_kfree_skb_any(skb); |
| 3382 | return NETDEV_TX_OK; |
| 3383 | } |
| 3384 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3385 | if (likely(tso)) { |
| 3386 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3388 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3390 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3391 | /* 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] | 3392 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3393 | * no longer assume, we must. */ |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3394 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3395 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3396 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3397 | count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd, |
| 3398 | nr_frags, mss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3400 | if (count) { |
| 3401 | e1000_tx_queue(adapter, tx_ring, tx_flags, count); |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3402 | /* Make sure there is space in the ring for the next send. */ |
| 3403 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3405 | } else { |
| 3406 | dev_kfree_skb_any(skb); |
| 3407 | tx_ring->buffer_info[first].time_stamp = 0; |
| 3408 | tx_ring->next_to_use = first; |
| 3409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | return NETDEV_TX_OK; |
| 3412 | } |
| 3413 | |
| 3414 | /** |
| 3415 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3416 | * @netdev: network interface device structure |
| 3417 | **/ |
| 3418 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3419 | static void e1000_tx_timeout(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3421 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | |
| 3423 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3424 | adapter->tx_timeout_count++; |
| 3425 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3428 | static void e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3430 | struct e1000_adapter *adapter = |
| 3431 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3433 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | /** |
| 3437 | * e1000_get_stats - Get System Network Statistics |
| 3438 | * @netdev: network interface device structure |
| 3439 | * |
| 3440 | * Returns the address of the device statistics structure. |
| 3441 | * The statistics are actually updated from the timer callback. |
| 3442 | **/ |
| 3443 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3444 | static struct net_device_stats *e1000_get_stats(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3446 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3448 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | return &adapter->net_stats; |
| 3450 | } |
| 3451 | |
| 3452 | /** |
| 3453 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3454 | * @netdev: network interface device structure |
| 3455 | * @new_mtu: new value for maximum frame size |
| 3456 | * |
| 3457 | * Returns 0 on success, negative on failure |
| 3458 | **/ |
| 3459 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3460 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3462 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3463 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3465 | u16 eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3467 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3468 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3469 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3470 | return -EINVAL; |
| 3471 | } |
| 3472 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3473 | /* Adapter-specific max frame size limits. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3474 | switch (hw->mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3475 | case e1000_undefined ... e1000_82542_rev2_1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3476 | case e1000_ich8lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3477 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3478 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3479 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3480 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3481 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3482 | case e1000_82573: |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3483 | /* Jumbo Frames not supported if: |
| 3484 | * - this is not an 82573L device |
| 3485 | * - ASPM is enabled in any way (0x1A bits 3:2) */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3486 | e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1, |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3487 | &eeprom_data); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3488 | if ((hw->device_id != E1000_DEV_ID_82573L) || |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3489 | (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3490 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 3491 | DPRINTK(PROBE, ERR, |
| 3492 | "Jumbo Frames not supported.\n"); |
| 3493 | return -EINVAL; |
| 3494 | } |
| 3495 | break; |
| 3496 | } |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3497 | /* ERT will be enabled later to enable wire speed receives */ |
| 3498 | |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3499 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3500 | case e1000_82571: |
| 3501 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3502 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3503 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3504 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3505 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3506 | return -EINVAL; |
| 3507 | } |
| 3508 | break; |
| 3509 | default: |
| 3510 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3511 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3514 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3515 | * means we reserve 2 more, this pushes us to allocate from the next |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 3516 | * larger slab size. |
| 3517 | * i.e. RXBUFFER_2048 --> size-4096 slab |
| 3518 | * however with the new *_jumbo_rx* routines, jumbo receives will use |
| 3519 | * fragmented skbs */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3520 | |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3521 | if (max_frame <= E1000_RXBUFFER_256) |
| 3522 | adapter->rx_buffer_len = E1000_RXBUFFER_256; |
| 3523 | else if (max_frame <= E1000_RXBUFFER_512) |
| 3524 | adapter->rx_buffer_len = E1000_RXBUFFER_512; |
| 3525 | else if (max_frame <= E1000_RXBUFFER_1024) |
| 3526 | adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
| 3527 | else if (max_frame <= E1000_RXBUFFER_2048) |
| 3528 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 3529 | else |
| 3530 | #if (PAGE_SIZE >= E1000_RXBUFFER_16384) |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3531 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 3532 | #elif (PAGE_SIZE >= E1000_RXBUFFER_4096) |
| 3533 | adapter->rx_buffer_len = PAGE_SIZE; |
| 3534 | #endif |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3535 | |
| 3536 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3537 | if (!hw->tbi_compatibility_on && |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3538 | ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) || |
| 3539 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3540 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3541 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3542 | netdev->mtu = new_mtu; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3543 | hw->max_frame_size = max_frame; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3544 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3545 | if (netif_running(netdev)) |
| 3546 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | return 0; |
| 3549 | } |
| 3550 | |
| 3551 | /** |
| 3552 | * e1000_update_stats - Update the board statistics counters |
| 3553 | * @adapter: board private structure |
| 3554 | **/ |
| 3555 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3556 | void e1000_update_stats(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | { |
| 3558 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3559 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3561 | u16 phy_tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | |
| 3563 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3564 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3565 | /* |
| 3566 | * Prevent stats update while adapter is being reset, or if the pci |
| 3567 | * connection is down. |
| 3568 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3569 | if (adapter->link_speed == 0) |
| 3570 | return; |
Linas Vepstas | 81b1955 | 2006-12-12 18:29:15 -0600 | [diff] [blame] | 3571 | if (pci_channel_offline(pdev)) |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3572 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3575 | |
Masatake YAMATO | 828d055 | 2007-10-20 03:06:37 +0200 | [diff] [blame] | 3576 | /* these counters are modified from e1000_tbi_adjust_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | * called from the interrupt context, so they must only |
| 3578 | * be written while holding adapter->stats_lock |
| 3579 | */ |
| 3580 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3581 | adapter->stats.crcerrs += er32(CRCERRS); |
| 3582 | adapter->stats.gprc += er32(GPRC); |
| 3583 | adapter->stats.gorcl += er32(GORCL); |
| 3584 | adapter->stats.gorch += er32(GORCH); |
| 3585 | adapter->stats.bprc += er32(BPRC); |
| 3586 | adapter->stats.mprc += er32(MPRC); |
| 3587 | adapter->stats.roc += er32(ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3588 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3589 | if (hw->mac_type != e1000_ich8lan) { |
| 3590 | adapter->stats.prc64 += er32(PRC64); |
| 3591 | adapter->stats.prc127 += er32(PRC127); |
| 3592 | adapter->stats.prc255 += er32(PRC255); |
| 3593 | adapter->stats.prc511 += er32(PRC511); |
| 3594 | adapter->stats.prc1023 += er32(PRC1023); |
| 3595 | adapter->stats.prc1522 += er32(PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3598 | adapter->stats.symerrs += er32(SYMERRS); |
| 3599 | adapter->stats.mpc += er32(MPC); |
| 3600 | adapter->stats.scc += er32(SCC); |
| 3601 | adapter->stats.ecol += er32(ECOL); |
| 3602 | adapter->stats.mcc += er32(MCC); |
| 3603 | adapter->stats.latecol += er32(LATECOL); |
| 3604 | adapter->stats.dc += er32(DC); |
| 3605 | adapter->stats.sec += er32(SEC); |
| 3606 | adapter->stats.rlec += er32(RLEC); |
| 3607 | adapter->stats.xonrxc += er32(XONRXC); |
| 3608 | adapter->stats.xontxc += er32(XONTXC); |
| 3609 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 3610 | adapter->stats.xofftxc += er32(XOFFTXC); |
| 3611 | adapter->stats.fcruc += er32(FCRUC); |
| 3612 | adapter->stats.gptc += er32(GPTC); |
| 3613 | adapter->stats.gotcl += er32(GOTCL); |
| 3614 | adapter->stats.gotch += er32(GOTCH); |
| 3615 | adapter->stats.rnbc += er32(RNBC); |
| 3616 | adapter->stats.ruc += er32(RUC); |
| 3617 | adapter->stats.rfc += er32(RFC); |
| 3618 | adapter->stats.rjc += er32(RJC); |
| 3619 | adapter->stats.torl += er32(TORL); |
| 3620 | adapter->stats.torh += er32(TORH); |
| 3621 | adapter->stats.totl += er32(TOTL); |
| 3622 | adapter->stats.toth += er32(TOTH); |
| 3623 | adapter->stats.tpr += er32(TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3624 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3625 | if (hw->mac_type != e1000_ich8lan) { |
| 3626 | adapter->stats.ptc64 += er32(PTC64); |
| 3627 | adapter->stats.ptc127 += er32(PTC127); |
| 3628 | adapter->stats.ptc255 += er32(PTC255); |
| 3629 | adapter->stats.ptc511 += er32(PTC511); |
| 3630 | adapter->stats.ptc1023 += er32(PTC1023); |
| 3631 | adapter->stats.ptc1522 += er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3634 | adapter->stats.mptc += er32(MPTC); |
| 3635 | adapter->stats.bptc += er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | |
| 3637 | /* used for adaptive IFS */ |
| 3638 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3639 | hw->tx_packet_delta = er32(TPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | adapter->stats.tpt += hw->tx_packet_delta; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3641 | hw->collision_delta = er32(COLC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | adapter->stats.colc += hw->collision_delta; |
| 3643 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3644 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3645 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 3646 | adapter->stats.rxerrc += er32(RXERRC); |
| 3647 | adapter->stats.tncrs += er32(TNCRS); |
| 3648 | adapter->stats.cexterr += er32(CEXTERR); |
| 3649 | adapter->stats.tsctc += er32(TSCTC); |
| 3650 | adapter->stats.tsctfc += er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3652 | if (hw->mac_type > e1000_82547_rev_2) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3653 | adapter->stats.iac += er32(IAC); |
| 3654 | adapter->stats.icrxoc += er32(ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3655 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3656 | if (hw->mac_type != e1000_ich8lan) { |
| 3657 | adapter->stats.icrxptc += er32(ICRXPTC); |
| 3658 | adapter->stats.icrxatc += er32(ICRXATC); |
| 3659 | adapter->stats.ictxptc += er32(ICTXPTC); |
| 3660 | adapter->stats.ictxatc += er32(ICTXATC); |
| 3661 | adapter->stats.ictxqec += er32(ICTXQEC); |
| 3662 | adapter->stats.ictxqmtc += er32(ICTXQMTC); |
| 3663 | adapter->stats.icrxdmtc += er32(ICRXDMTC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3664 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | |
| 3667 | /* Fill out the OS statistics structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3669 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3670 | |
| 3671 | /* Rx Errors */ |
| 3672 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3673 | /* RLEC on some newer hardware can be incorrect so build |
| 3674 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3676 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3677 | adapter->stats.ruc + adapter->stats.roc + |
| 3678 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3679 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
| 3680 | adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3682 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3684 | |
| 3685 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3686 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
| 3687 | adapter->net_stats.tx_errors = adapter->stats.txerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3689 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3690 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3691 | if (hw->bad_tx_carr_stats_fd && |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3692 | adapter->link_duplex == FULL_DUPLEX) { |
| 3693 | adapter->net_stats.tx_carrier_errors = 0; |
| 3694 | adapter->stats.tncrs = 0; |
| 3695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | |
| 3697 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3698 | |
| 3699 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3700 | if (hw->media_type == e1000_media_type_copper) { |
| 3701 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3703 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3704 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3705 | } |
| 3706 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3707 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | (hw->phy_type == e1000_phy_m88) && |
| 3709 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3710 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3711 | } |
| 3712 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3713 | /* Management Stats */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3714 | if (hw->has_smbus) { |
| 3715 | adapter->stats.mgptc += er32(MGTPTC); |
| 3716 | adapter->stats.mgprc += er32(MGTPRC); |
| 3717 | adapter->stats.mgpdc += er32(MGTPDC); |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3718 | } |
| 3719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3721 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3722 | |
| 3723 | /** |
| 3724 | * e1000_intr_msi - Interrupt Handler |
| 3725 | * @irq: interrupt number |
| 3726 | * @data: pointer to a network interface device structure |
| 3727 | **/ |
| 3728 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3729 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3730 | { |
| 3731 | struct net_device *netdev = data; |
| 3732 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3733 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3734 | u32 icr = er32(ICR); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3735 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3736 | /* in NAPI mode read ICR disables interrupts using IAM */ |
| 3737 | |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3738 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 3739 | hw->get_link_status = 1; |
| 3740 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
| 3741 | * link down event; disable receives here in the ISR and reset |
| 3742 | * adapter in watchdog */ |
| 3743 | if (netif_carrier_ok(netdev) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3744 | (hw->mac_type == e1000_80003es2lan)) { |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3745 | /* disable receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3746 | u32 rctl = er32(RCTL); |
| 3747 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3748 | } |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3749 | /* guard against interrupt when we're going down */ |
| 3750 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3751 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3752 | } |
| 3753 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3754 | if (likely(napi_schedule_prep(&adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3755 | adapter->total_tx_bytes = 0; |
| 3756 | adapter->total_tx_packets = 0; |
| 3757 | adapter->total_rx_bytes = 0; |
| 3758 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3759 | __napi_schedule(&adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3760 | } else |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3761 | e1000_irq_enable(adapter); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3762 | |
| 3763 | return IRQ_HANDLED; |
| 3764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | |
| 3766 | /** |
| 3767 | * e1000_intr - Interrupt Handler |
| 3768 | * @irq: interrupt number |
| 3769 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | **/ |
| 3771 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3772 | static irqreturn_t e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | { |
| 3774 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3775 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3777 | u32 rctl, icr = er32(ICR); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 3778 | |
Jesse Brandeburg | e151a60 | 2009-05-04 11:19:42 +0000 | [diff] [blame] | 3779 | if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags))) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3780 | return IRQ_NONE; /* Not our interrupt */ |
| 3781 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3782 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 3783 | * not set, then the adapter didn't send an interrupt */ |
| 3784 | if (unlikely(hw->mac_type >= e1000_82571 && |
| 3785 | !(icr & E1000_ICR_INT_ASSERTED))) |
| 3786 | return IRQ_NONE; |
| 3787 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3788 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
| 3789 | * need for the IMC write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3791 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3793 | /* 80003ES2LAN workaround-- |
| 3794 | * For packet buffer work-around on link down event; |
| 3795 | * disable receives here in the ISR and |
| 3796 | * reset adapter in watchdog |
| 3797 | */ |
| 3798 | if (netif_carrier_ok(netdev) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3799 | (hw->mac_type == e1000_80003es2lan)) { |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3800 | /* disable receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3801 | rctl = er32(RCTL); |
| 3802 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3803 | } |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3804 | /* guard against interrupt when we're going down */ |
| 3805 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3806 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3809 | if (unlikely(hw->mac_type < e1000_82571)) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3810 | /* disable interrupts, without the synchronize_irq bit */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3811 | ew32(IMC, ~0); |
| 3812 | E1000_WRITE_FLUSH(); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3813 | } |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3814 | if (likely(napi_schedule_prep(&adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3815 | adapter->total_tx_bytes = 0; |
| 3816 | adapter->total_tx_packets = 0; |
| 3817 | adapter->total_rx_bytes = 0; |
| 3818 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3819 | __napi_schedule(&adapter->napi); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3820 | } else { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3821 | /* this really should not happen! if it does it is basically a |
| 3822 | * bug, but not a hard error, so enable ints and continue */ |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3823 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3824 | e1000_irq_enable(adapter); |
| 3825 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | return IRQ_HANDLED; |
| 3828 | } |
| 3829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | /** |
| 3831 | * e1000_clean - NAPI Rx polling callback |
| 3832 | * @adapter: board private structure |
| 3833 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3834 | static int e1000_clean(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3836 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
| 3837 | struct net_device *poll_dev = adapter->netdev; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3838 | int tx_cleaned = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3839 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 3840 | adapter = netdev_priv(poll_dev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3841 | |
Alexander Duyck | 8017943 | 2009-01-21 14:42:47 -0800 | [diff] [blame] | 3842 | tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3843 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3844 | adapter->clean_rx(adapter, &adapter->rx_ring[0], |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3845 | &work_done, budget); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3846 | |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3847 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3848 | work_done = budget; |
| 3849 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3850 | /* If budget not fully consumed, exit the polling mode */ |
| 3851 | if (work_done < budget) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3852 | if (likely(adapter->itr_setting & 3)) |
| 3853 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3854 | napi_complete(napi); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3855 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3856 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | } |
| 3858 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3859 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | /** |
| 3863 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3864 | * @adapter: board private structure |
| 3865 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3866 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3867 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3869 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | struct net_device *netdev = adapter->netdev; |
| 3871 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3872 | struct e1000_buffer *buffer_info; |
| 3873 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3874 | unsigned int count = 0; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3875 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | |
| 3877 | i = tx_ring->next_to_clean; |
| 3878 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3879 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3880 | |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3881 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 3882 | (count < tx_ring->count)) { |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3883 | bool cleaned = false; |
| 3884 | for ( ; !cleaned; count++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3886 | buffer_info = &tx_ring->buffer_info[i]; |
| 3887 | cleaned = (i == eop); |
| 3888 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3889 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3890 | struct sk_buff *skb = buffer_info->skb; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3891 | unsigned int segs, bytecount; |
| 3892 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 3893 | /* multiply data chunks by size of headers */ |
| 3894 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 3895 | skb->len; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3896 | total_tx_packets += segs; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3897 | total_tx_bytes += bytecount; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3898 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3899 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3900 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3902 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3906 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3907 | } |
| 3908 | |
| 3909 | tx_ring->next_to_clean = i; |
| 3910 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3911 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3912 | if (unlikely(count && netif_carrier_ok(netdev) && |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3913 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 3914 | /* Make sure that anybody stopping the queue after this |
| 3915 | * sees the new next_to_clean. |
| 3916 | */ |
| 3917 | smp_mb(); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3918 | if (netif_queue_stopped(netdev)) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3919 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3920 | ++adapter->restart_queue; |
| 3921 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3922 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3923 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3924 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3925 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | * check with the clearing of time_stamp and movement of i */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3927 | adapter->detect_tx_hung = false; |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3928 | if (tx_ring->buffer_info[i].time_stamp && |
| 3929 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 3930 | (adapter->tx_timeout_factor * HZ)) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3931 | && !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3932 | |
| 3933 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 3934 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3935 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3936 | " TDH <%x>\n" |
| 3937 | " TDT <%x>\n" |
| 3938 | " next_to_use <%x>\n" |
| 3939 | " next_to_clean <%x>\n" |
| 3940 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3941 | " time_stamp <%lx>\n" |
| 3942 | " next_to_watch <%x>\n" |
| 3943 | " jiffies <%lx>\n" |
| 3944 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3945 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 3946 | sizeof(struct e1000_tx_ring)), |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3947 | readl(hw->hw_addr + tx_ring->tdh), |
| 3948 | readl(hw->hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3949 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3950 | tx_ring->next_to_clean, |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3951 | tx_ring->buffer_info[i].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3952 | eop, |
| 3953 | jiffies, |
| 3954 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3956 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3958 | adapter->total_tx_bytes += total_tx_bytes; |
| 3959 | adapter->total_tx_packets += total_tx_packets; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 3960 | adapter->net_stats.tx_bytes += total_tx_bytes; |
| 3961 | adapter->net_stats.tx_packets += total_tx_packets; |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3962 | return (count < tx_ring->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | /** |
| 3966 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3967 | * @adapter: board private structure |
| 3968 | * @status_err: receive descriptor status and error fields |
| 3969 | * @csum: receive descriptor csum field |
| 3970 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | **/ |
| 3972 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3973 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
| 3974 | u32 csum, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3976 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3977 | u16 status = (u16)status_err; |
| 3978 | u8 errors = (u8)(status_err >> 24); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3979 | skb->ip_summed = CHECKSUM_NONE; |
| 3980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | /* 82543 or newer only */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3982 | if (unlikely(hw->mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3984 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3985 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3986 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3987 | /* let the stack verify checksum errors */ |
| 3988 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | return; |
| 3990 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3991 | /* TCP/UDP Checksum has not been calculated */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3992 | if (hw->mac_type <= e1000_82547_rev_2) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3993 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3994 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3996 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3997 | return; |
| 3998 | } |
| 3999 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4000 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | /* TCP checksum is good */ |
| 4002 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4003 | } else if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4004 | /* IP fragment with UDP payload */ |
| 4005 | /* Hardware complements the payload checksum, so we undo it |
| 4006 | * and then put the value in host order for further stack use. |
| 4007 | */ |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 4008 | __sum16 sum = (__force __sum16)htons(csum); |
| 4009 | skb->csum = csum_unfold(~sum); |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 4010 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4012 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | /** |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4016 | * e1000_consume_page - helper function |
| 4017 | **/ |
| 4018 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 4019 | u16 length) |
| 4020 | { |
| 4021 | bi->page = NULL; |
| 4022 | skb->len += length; |
| 4023 | skb->data_len += length; |
| 4024 | skb->truesize += length; |
| 4025 | } |
| 4026 | |
| 4027 | /** |
| 4028 | * e1000_receive_skb - helper function to handle rx indications |
| 4029 | * @adapter: board private structure |
| 4030 | * @status: descriptor status field as written by hardware |
| 4031 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 4032 | * @skb: pointer to sk_buff to be indicated to stack |
| 4033 | */ |
| 4034 | static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status, |
| 4035 | __le16 vlan, struct sk_buff *skb) |
| 4036 | { |
| 4037 | if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) { |
| 4038 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
| 4039 | le16_to_cpu(vlan) & |
| 4040 | E1000_RXD_SPC_VLAN_MASK); |
| 4041 | } else { |
| 4042 | netif_receive_skb(skb); |
| 4043 | } |
| 4044 | } |
| 4045 | |
| 4046 | /** |
| 4047 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 4048 | * @adapter: board private structure |
| 4049 | * @rx_ring: ring to clean |
| 4050 | * @work_done: amount of napi work completed this call |
| 4051 | * @work_to_do: max amount of work allowed for this call to do |
| 4052 | * |
| 4053 | * the return value indicates whether actual cleaning was done, there |
| 4054 | * is no guarantee that everything was cleaned |
| 4055 | */ |
| 4056 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 4057 | struct e1000_rx_ring *rx_ring, |
| 4058 | int *work_done, int work_to_do) |
| 4059 | { |
| 4060 | struct e1000_hw *hw = &adapter->hw; |
| 4061 | struct net_device *netdev = adapter->netdev; |
| 4062 | struct pci_dev *pdev = adapter->pdev; |
| 4063 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4064 | struct e1000_buffer *buffer_info, *next_buffer; |
| 4065 | unsigned long irq_flags; |
| 4066 | u32 length; |
| 4067 | unsigned int i; |
| 4068 | int cleaned_count = 0; |
| 4069 | bool cleaned = false; |
| 4070 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 4071 | |
| 4072 | i = rx_ring->next_to_clean; |
| 4073 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4074 | buffer_info = &rx_ring->buffer_info[i]; |
| 4075 | |
| 4076 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 4077 | struct sk_buff *skb; |
| 4078 | u8 status; |
| 4079 | |
| 4080 | if (*work_done >= work_to_do) |
| 4081 | break; |
| 4082 | (*work_done)++; |
| 4083 | |
| 4084 | status = rx_desc->status; |
| 4085 | skb = buffer_info->skb; |
| 4086 | buffer_info->skb = NULL; |
| 4087 | |
| 4088 | if (++i == rx_ring->count) i = 0; |
| 4089 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 4090 | prefetch(next_rxd); |
| 4091 | |
| 4092 | next_buffer = &rx_ring->buffer_info[i]; |
| 4093 | |
| 4094 | cleaned = true; |
| 4095 | cleaned_count++; |
| 4096 | pci_unmap_page(pdev, buffer_info->dma, buffer_info->length, |
| 4097 | PCI_DMA_FROMDEVICE); |
| 4098 | buffer_info->dma = 0; |
| 4099 | |
| 4100 | length = le16_to_cpu(rx_desc->length); |
| 4101 | |
| 4102 | /* errors is only valid for DD + EOP descriptors */ |
| 4103 | if (unlikely((status & E1000_RXD_STAT_EOP) && |
| 4104 | (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { |
| 4105 | u8 last_byte = *(skb->data + length - 1); |
| 4106 | if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
| 4107 | last_byte)) { |
| 4108 | spin_lock_irqsave(&adapter->stats_lock, |
| 4109 | irq_flags); |
| 4110 | e1000_tbi_adjust_stats(hw, &adapter->stats, |
| 4111 | length, skb->data); |
| 4112 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4113 | irq_flags); |
| 4114 | length--; |
| 4115 | } else { |
| 4116 | /* recycle both page and skb */ |
| 4117 | buffer_info->skb = skb; |
| 4118 | /* an error means any chain goes out the window |
| 4119 | * too */ |
| 4120 | if (rx_ring->rx_skb_top) |
| 4121 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 4122 | rx_ring->rx_skb_top = NULL; |
| 4123 | goto next_desc; |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | #define rxtop rx_ring->rx_skb_top |
| 4128 | if (!(status & E1000_RXD_STAT_EOP)) { |
| 4129 | /* this descriptor is only the beginning (or middle) */ |
| 4130 | if (!rxtop) { |
| 4131 | /* this is the beginning of a chain */ |
| 4132 | rxtop = skb; |
| 4133 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 4134 | 0, length); |
| 4135 | } else { |
| 4136 | /* this is the middle of a chain */ |
| 4137 | skb_fill_page_desc(rxtop, |
| 4138 | skb_shinfo(rxtop)->nr_frags, |
| 4139 | buffer_info->page, 0, length); |
| 4140 | /* re-use the skb, only consumed the page */ |
| 4141 | buffer_info->skb = skb; |
| 4142 | } |
| 4143 | e1000_consume_page(buffer_info, rxtop, length); |
| 4144 | goto next_desc; |
| 4145 | } else { |
| 4146 | if (rxtop) { |
| 4147 | /* end of the chain */ |
| 4148 | skb_fill_page_desc(rxtop, |
| 4149 | skb_shinfo(rxtop)->nr_frags, |
| 4150 | buffer_info->page, 0, length); |
| 4151 | /* re-use the current skb, we only consumed the |
| 4152 | * page */ |
| 4153 | buffer_info->skb = skb; |
| 4154 | skb = rxtop; |
| 4155 | rxtop = NULL; |
| 4156 | e1000_consume_page(buffer_info, skb, length); |
| 4157 | } else { |
| 4158 | /* no chain, got EOP, this buf is the packet |
| 4159 | * copybreak to save the put_page/alloc_page */ |
| 4160 | if (length <= copybreak && |
| 4161 | skb_tailroom(skb) >= length) { |
| 4162 | u8 *vaddr; |
| 4163 | vaddr = kmap_atomic(buffer_info->page, |
| 4164 | KM_SKB_DATA_SOFTIRQ); |
| 4165 | memcpy(skb_tail_pointer(skb), vaddr, length); |
| 4166 | kunmap_atomic(vaddr, |
| 4167 | KM_SKB_DATA_SOFTIRQ); |
| 4168 | /* re-use the page, so don't erase |
| 4169 | * buffer_info->page */ |
| 4170 | skb_put(skb, length); |
| 4171 | } else { |
| 4172 | skb_fill_page_desc(skb, 0, |
| 4173 | buffer_info->page, 0, |
| 4174 | length); |
| 4175 | e1000_consume_page(buffer_info, skb, |
| 4176 | length); |
| 4177 | } |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
| 4182 | e1000_rx_checksum(adapter, |
| 4183 | (u32)(status) | |
| 4184 | ((u32)(rx_desc->errors) << 24), |
| 4185 | le16_to_cpu(rx_desc->csum), skb); |
| 4186 | |
| 4187 | pskb_trim(skb, skb->len - 4); |
| 4188 | |
| 4189 | /* probably a little skewed due to removing CRC */ |
| 4190 | total_rx_bytes += skb->len; |
| 4191 | total_rx_packets++; |
| 4192 | |
| 4193 | /* eth type trans needs skb->data to point to something */ |
| 4194 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
| 4195 | DPRINTK(DRV, ERR, "pskb_may_pull failed.\n"); |
| 4196 | dev_kfree_skb(skb); |
| 4197 | goto next_desc; |
| 4198 | } |
| 4199 | |
| 4200 | skb->protocol = eth_type_trans(skb, netdev); |
| 4201 | |
| 4202 | e1000_receive_skb(adapter, status, rx_desc->special, skb); |
| 4203 | |
| 4204 | next_desc: |
| 4205 | rx_desc->status = 0; |
| 4206 | |
| 4207 | /* return some buffers to hardware, one at a time is too slow */ |
| 4208 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4209 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4210 | cleaned_count = 0; |
| 4211 | } |
| 4212 | |
| 4213 | /* use prefetched values */ |
| 4214 | rx_desc = next_rxd; |
| 4215 | buffer_info = next_buffer; |
| 4216 | } |
| 4217 | rx_ring->next_to_clean = i; |
| 4218 | |
| 4219 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4220 | if (cleaned_count) |
| 4221 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4222 | |
| 4223 | adapter->total_rx_packets += total_rx_packets; |
| 4224 | adapter->total_rx_bytes += total_rx_bytes; |
| 4225 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4226 | adapter->net_stats.rx_packets += total_rx_packets; |
| 4227 | return cleaned; |
| 4228 | } |
| 4229 | |
| 4230 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4231 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | * @adapter: board private structure |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4233 | * @rx_ring: ring to clean |
| 4234 | * @work_done: amount of napi work completed this call |
| 4235 | * @work_to_do: max amount of work allowed for this call to do |
| 4236 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4237 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4238 | struct e1000_rx_ring *rx_ring, |
| 4239 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4241 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | struct net_device *netdev = adapter->netdev; |
| 4243 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4244 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4245 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4247 | u32 length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4249 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4250 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4251 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | |
| 4253 | i = rx_ring->next_to_clean; |
| 4254 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4255 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4257 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4258 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4259 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4260 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4261 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | break; |
| 4263 | (*work_done)++; |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4264 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4265 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4266 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4267 | buffer_info->skb = NULL; |
| 4268 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4269 | prefetch(skb->data - NET_IP_ALIGN); |
| 4270 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4271 | if (++i == rx_ring->count) i = 0; |
| 4272 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4273 | prefetch(next_rxd); |
| 4274 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4275 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4276 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4277 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4278 | cleaned_count++; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4279 | pci_unmap_single(pdev, buffer_info->dma, buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 4281 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | length = le16_to_cpu(rx_desc->length); |
Neil Horman | ea30e11 | 2009-06-02 01:29:58 -0700 | [diff] [blame] | 4284 | /* !EOP means multiple descriptors were used to store a single |
| 4285 | * packet, also make sure the frame isn't just CRC only */ |
| 4286 | if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) { |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4287 | /* All receives must fit into a single buffer */ |
| 4288 | E1000_DBG("%s: Receive packet consumed multiple" |
| 4289 | " buffers\n", netdev->name); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 4290 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4291 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | goto next_desc; |
| 4293 | } |
| 4294 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4295 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4296 | u8 last_byte = *(skb->data + length - 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4297 | if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
| 4298 | last_byte)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4300 | e1000_tbi_adjust_stats(hw, &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | length, skb->data); |
| 4302 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4303 | flags); |
| 4304 | length--; |
| 4305 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4306 | /* recycle */ |
| 4307 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | goto next_desc; |
| 4309 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4312 | /* adjust length to remove Ethernet CRC, this must be |
| 4313 | * done after the TBI_ACCEPT workaround above */ |
| 4314 | length -= 4; |
| 4315 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4316 | /* probably a little skewed due to removing CRC */ |
| 4317 | total_rx_bytes += length; |
| 4318 | total_rx_packets++; |
| 4319 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4320 | /* code added for copybreak, this should improve |
| 4321 | * performance for small packets with large amounts |
| 4322 | * of reassembly being done in the stack */ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4323 | if (length < copybreak) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4324 | struct sk_buff *new_skb = |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4325 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4326 | if (new_skb) { |
| 4327 | skb_reserve(new_skb, NET_IP_ALIGN); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 4328 | skb_copy_to_linear_data_offset(new_skb, |
| 4329 | -NET_IP_ALIGN, |
| 4330 | (skb->data - |
| 4331 | NET_IP_ALIGN), |
| 4332 | (length + |
| 4333 | NET_IP_ALIGN)); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4334 | /* save the skb in buffer_info as good */ |
| 4335 | buffer_info->skb = skb; |
| 4336 | skb = new_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4337 | } |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4338 | /* else just continue with the old one */ |
| 4339 | } |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4340 | /* end copybreak code */ |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4341 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
| 4343 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4344 | e1000_rx_checksum(adapter, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4345 | (u32)(status) | |
| 4346 | ((u32)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4347 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | skb->protocol = eth_type_trans(skb, netdev); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4350 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4351 | e1000_receive_skb(adapter, status, rx_desc->special, skb); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4353 | next_desc: |
| 4354 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4356 | /* return some buffers to hardware, one at a time is too slow */ |
| 4357 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4358 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4359 | cleaned_count = 0; |
| 4360 | } |
| 4361 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4362 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4363 | rx_desc = next_rxd; |
| 4364 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4367 | |
| 4368 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4369 | if (cleaned_count) |
| 4370 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4372 | adapter->total_rx_packets += total_rx_packets; |
| 4373 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4374 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4375 | adapter->net_stats.rx_packets += total_rx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | return cleaned; |
| 4377 | } |
| 4378 | |
| 4379 | /** |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4380 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 4381 | * @adapter: address of board private structure |
| 4382 | * @rx_ring: pointer to receive ring structure |
| 4383 | * @cleaned_count: number of buffers to allocate this pass |
| 4384 | **/ |
| 4385 | |
| 4386 | static void |
| 4387 | e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 4388 | struct e1000_rx_ring *rx_ring, int cleaned_count) |
| 4389 | { |
| 4390 | struct net_device *netdev = adapter->netdev; |
| 4391 | struct pci_dev *pdev = adapter->pdev; |
| 4392 | struct e1000_rx_desc *rx_desc; |
| 4393 | struct e1000_buffer *buffer_info; |
| 4394 | struct sk_buff *skb; |
| 4395 | unsigned int i; |
| 4396 | unsigned int bufsz = 256 - |
| 4397 | 16 /*for skb_reserve */ - |
| 4398 | NET_IP_ALIGN; |
| 4399 | |
| 4400 | i = rx_ring->next_to_use; |
| 4401 | buffer_info = &rx_ring->buffer_info[i]; |
| 4402 | |
| 4403 | while (cleaned_count--) { |
| 4404 | skb = buffer_info->skb; |
| 4405 | if (skb) { |
| 4406 | skb_trim(skb, 0); |
| 4407 | goto check_page; |
| 4408 | } |
| 4409 | |
| 4410 | skb = netdev_alloc_skb(netdev, bufsz); |
| 4411 | if (unlikely(!skb)) { |
| 4412 | /* Better luck next round */ |
| 4413 | adapter->alloc_rx_buff_failed++; |
| 4414 | break; |
| 4415 | } |
| 4416 | |
| 4417 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4418 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4419 | struct sk_buff *oldskb = skb; |
| 4420 | DPRINTK(PROBE, ERR, "skb align check failed: %u bytes " |
| 4421 | "at %p\n", bufsz, skb->data); |
| 4422 | /* Try again, without freeing the previous */ |
| 4423 | skb = netdev_alloc_skb(netdev, bufsz); |
| 4424 | /* Failed allocation, critical failure */ |
| 4425 | if (!skb) { |
| 4426 | dev_kfree_skb(oldskb); |
| 4427 | adapter->alloc_rx_buff_failed++; |
| 4428 | break; |
| 4429 | } |
| 4430 | |
| 4431 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4432 | /* give up */ |
| 4433 | dev_kfree_skb(skb); |
| 4434 | dev_kfree_skb(oldskb); |
| 4435 | break; /* while (cleaned_count--) */ |
| 4436 | } |
| 4437 | |
| 4438 | /* Use new allocation */ |
| 4439 | dev_kfree_skb(oldskb); |
| 4440 | } |
| 4441 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4442 | * this will result in a 16 byte aligned IP header after |
| 4443 | * the 14 byte MAC header is removed |
| 4444 | */ |
| 4445 | skb_reserve(skb, NET_IP_ALIGN); |
| 4446 | |
| 4447 | buffer_info->skb = skb; |
| 4448 | buffer_info->length = adapter->rx_buffer_len; |
| 4449 | check_page: |
| 4450 | /* allocate a new page if necessary */ |
| 4451 | if (!buffer_info->page) { |
| 4452 | buffer_info->page = alloc_page(GFP_ATOMIC); |
| 4453 | if (unlikely(!buffer_info->page)) { |
| 4454 | adapter->alloc_rx_buff_failed++; |
| 4455 | break; |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | if (!buffer_info->dma) |
| 4460 | buffer_info->dma = pci_map_page(pdev, |
| 4461 | buffer_info->page, 0, |
| 4462 | buffer_info->length, |
| 4463 | PCI_DMA_FROMDEVICE); |
| 4464 | |
| 4465 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4466 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4467 | |
| 4468 | if (unlikely(++i == rx_ring->count)) |
| 4469 | i = 0; |
| 4470 | buffer_info = &rx_ring->buffer_info[i]; |
| 4471 | } |
| 4472 | |
| 4473 | if (likely(rx_ring->next_to_use != i)) { |
| 4474 | rx_ring->next_to_use = i; |
| 4475 | if (unlikely(i-- == 0)) |
| 4476 | i = (rx_ring->count - 1); |
| 4477 | |
| 4478 | /* Force memory writes to complete before letting h/w |
| 4479 | * know there are new descriptors to fetch. (Only |
| 4480 | * applicable for weak-ordered memory model archs, |
| 4481 | * such as IA-64). */ |
| 4482 | wmb(); |
| 4483 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4488 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | * @adapter: address of board private structure |
| 4490 | **/ |
| 4491 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4492 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
| 4493 | struct e1000_rx_ring *rx_ring, |
| 4494 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4496 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | struct net_device *netdev = adapter->netdev; |
| 4498 | struct pci_dev *pdev = adapter->pdev; |
| 4499 | struct e1000_rx_desc *rx_desc; |
| 4500 | struct e1000_buffer *buffer_info; |
| 4501 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4502 | unsigned int i; |
| 4503 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | |
| 4505 | i = rx_ring->next_to_use; |
| 4506 | buffer_info = &rx_ring->buffer_info[i]; |
| 4507 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4508 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4509 | skb = buffer_info->skb; |
| 4510 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4511 | skb_trim(skb, 0); |
| 4512 | goto map_skb; |
| 4513 | } |
| 4514 | |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4515 | skb = netdev_alloc_skb(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4516 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4518 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | break; |
| 4520 | } |
| 4521 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4522 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4524 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4525 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 4526 | "at %p\n", bufsz, skb->data); |
| 4527 | /* Try again, without freeing the previous */ |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4528 | skb = netdev_alloc_skb(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4529 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | if (!skb) { |
| 4531 | dev_kfree_skb(oldskb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4532 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | break; |
| 4534 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4537 | /* give up */ |
| 4538 | dev_kfree_skb(skb); |
| 4539 | dev_kfree_skb(oldskb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4540 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4543 | |
| 4544 | /* Use new allocation */ |
| 4545 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4548 | * this will result in a 16 byte aligned IP header after |
| 4549 | * the 14 byte MAC header is removed |
| 4550 | */ |
| 4551 | skb_reserve(skb, NET_IP_ALIGN); |
| 4552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | buffer_info->skb = skb; |
| 4554 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4555 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | buffer_info->dma = pci_map_single(pdev, |
| 4557 | skb->data, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4558 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | PCI_DMA_FROMDEVICE); |
| 4560 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4561 | /* |
| 4562 | * XXX if it was allocated cleanly it will never map to a |
| 4563 | * boundary crossing |
| 4564 | */ |
| 4565 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4566 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4567 | if (!e1000_check_64k_bound(adapter, |
| 4568 | (void *)(unsigned long)buffer_info->dma, |
| 4569 | adapter->rx_buffer_len)) { |
| 4570 | DPRINTK(RX_ERR, ERR, |
| 4571 | "dma align check failed: %u bytes at %p\n", |
| 4572 | adapter->rx_buffer_len, |
| 4573 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | dev_kfree_skb(skb); |
| 4575 | buffer_info->skb = NULL; |
| 4576 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4577 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | adapter->rx_buffer_len, |
| 4579 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 4580 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame^] | 4582 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | break; /* while !buffer_info->skb */ |
| 4584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4586 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4587 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4588 | if (unlikely(++i == rx_ring->count)) |
| 4589 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | buffer_info = &rx_ring->buffer_info[i]; |
| 4591 | } |
| 4592 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4593 | if (likely(rx_ring->next_to_use != i)) { |
| 4594 | rx_ring->next_to_use = i; |
| 4595 | if (unlikely(i-- == 0)) |
| 4596 | i = (rx_ring->count - 1); |
| 4597 | |
| 4598 | /* Force memory writes to complete before letting h/w |
| 4599 | * know there are new descriptors to fetch. (Only |
| 4600 | * applicable for weak-ordered memory model archs, |
| 4601 | * such as IA-64). */ |
| 4602 | wmb(); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4603 | writel(i, hw->hw_addr + rx_ring->rdt); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | /** |
| 4608 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4609 | * @adapter: |
| 4610 | **/ |
| 4611 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4612 | static void e1000_smartspeed(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4614 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4615 | u16 phy_status; |
| 4616 | u16 phy_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4618 | if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg || |
| 4619 | !(hw->autoneg_advertised & ADVERTISE_1000_FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4620 | return; |
| 4621 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4622 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | /* If Master/Slave config fault is asserted twice, |
| 4624 | * we assume back-to-back */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4625 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4626 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4627 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4628 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4629 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4630 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4632 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4633 | phy_ctrl); |
| 4634 | adapter->smartspeed++; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4635 | if (!e1000_phy_setup_autoneg(hw) && |
| 4636 | !e1000_read_phy_reg(hw, PHY_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | &phy_ctrl)) { |
| 4638 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4639 | MII_CR_RESTART_AUTO_NEG); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4640 | e1000_write_phy_reg(hw, PHY_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | phy_ctrl); |
| 4642 | } |
| 4643 | } |
| 4644 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4645 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4646 | /* If still no link, perhaps using 2/3 pair cable */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4647 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | phy_ctrl |= CR_1000T_MS_ENABLE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4649 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); |
| 4650 | if (!e1000_phy_setup_autoneg(hw) && |
| 4651 | !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4653 | MII_CR_RESTART_AUTO_NEG); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4654 | e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | } |
| 4656 | } |
| 4657 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4658 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4659 | adapter->smartspeed = 0; |
| 4660 | } |
| 4661 | |
| 4662 | /** |
| 4663 | * e1000_ioctl - |
| 4664 | * @netdev: |
| 4665 | * @ifreq: |
| 4666 | * @cmd: |
| 4667 | **/ |
| 4668 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4669 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | { |
| 4671 | switch (cmd) { |
| 4672 | case SIOCGMIIPHY: |
| 4673 | case SIOCGMIIREG: |
| 4674 | case SIOCSMIIREG: |
| 4675 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4676 | default: |
| 4677 | return -EOPNOTSUPP; |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * e1000_mii_ioctl - |
| 4683 | * @netdev: |
| 4684 | * @ifreq: |
| 4685 | * @cmd: |
| 4686 | **/ |
| 4687 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4688 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 4689 | int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4691 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4692 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4694 | int retval; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4695 | u16 mii_reg; |
| 4696 | u16 spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4697 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4699 | if (hw->media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | return -EOPNOTSUPP; |
| 4701 | |
| 4702 | switch (cmd) { |
| 4703 | case SIOCGMIIPHY: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4704 | data->phy_id = hw->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | break; |
| 4706 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4707 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4709 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4710 | if (e1000_read_phy_reg(hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4711 | &data->val_out)) { |
| 4712 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4713 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4714 | } |
| 4715 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | break; |
| 4717 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4718 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4720 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | return -EFAULT; |
| 4722 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4723 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4724 | if (e1000_write_phy_reg(hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4725 | mii_reg)) { |
| 4726 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4728 | } |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4729 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4730 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | switch (data->reg_num) { |
| 4732 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4733 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4735 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4736 | hw->autoneg = 1; |
| 4737 | hw->autoneg_advertised = 0x2F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4738 | } else { |
| 4739 | if (mii_reg & 0x40) |
| 4740 | spddplx = SPEED_1000; |
| 4741 | else if (mii_reg & 0x2000) |
| 4742 | spddplx = SPEED_100; |
| 4743 | else |
| 4744 | spddplx = SPEED_10; |
| 4745 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4746 | ? DUPLEX_FULL : |
| 4747 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | retval = e1000_set_spd_dplx(adapter, |
| 4749 | spddplx); |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4750 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | return retval; |
| 4752 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4753 | if (netif_running(adapter->netdev)) |
| 4754 | e1000_reinit_locked(adapter); |
| 4755 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | e1000_reset(adapter); |
| 4757 | break; |
| 4758 | case M88E1000_PHY_SPEC_CTRL: |
| 4759 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4760 | if (e1000_phy_reset(hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | return -EIO; |
| 4762 | break; |
| 4763 | } |
| 4764 | } else { |
| 4765 | switch (data->reg_num) { |
| 4766 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4767 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4769 | if (netif_running(adapter->netdev)) |
| 4770 | e1000_reinit_locked(adapter); |
| 4771 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4772 | e1000_reset(adapter); |
| 4773 | break; |
| 4774 | } |
| 4775 | } |
| 4776 | break; |
| 4777 | default: |
| 4778 | return -EOPNOTSUPP; |
| 4779 | } |
| 4780 | return E1000_SUCCESS; |
| 4781 | } |
| 4782 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4783 | void e1000_pci_set_mwi(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4784 | { |
| 4785 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4786 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4787 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4788 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4789 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | } |
| 4791 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4792 | void e1000_pci_clear_mwi(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | { |
| 4794 | struct e1000_adapter *adapter = hw->back; |
| 4795 | |
| 4796 | pci_clear_mwi(adapter->pdev); |
| 4797 | } |
| 4798 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4799 | int e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4800 | { |
| 4801 | struct e1000_adapter *adapter = hw->back; |
| 4802 | return pcix_get_mmrbc(adapter->pdev); |
| 4803 | } |
| 4804 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4805 | void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4806 | { |
| 4807 | struct e1000_adapter *adapter = hw->back; |
| 4808 | pcix_set_mmrbc(adapter->pdev, mmrbc); |
| 4809 | } |
| 4810 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4811 | s32 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] | 4812 | { |
| 4813 | struct e1000_adapter *adapter = hw->back; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4814 | u16 cap_offset; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4815 | |
| 4816 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 4817 | if (!cap_offset) |
| 4818 | return -E1000_ERR_CONFIG; |
| 4819 | |
| 4820 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 4821 | |
| 4822 | return E1000_SUCCESS; |
| 4823 | } |
| 4824 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4825 | void e1000_io_write(struct e1000_hw *hw, unsigned long port, u32 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | { |
| 4827 | outl(value, port); |
| 4828 | } |
| 4829 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4830 | static void e1000_vlan_rx_register(struct net_device *netdev, |
| 4831 | struct vlan_group *grp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4833 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4834 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4835 | u32 ctrl, rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4837 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4838 | e1000_irq_disable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | adapter->vlgrp = grp; |
| 4840 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4841 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | /* enable VLAN tag insert/strip */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4843 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | ctrl |= E1000_CTRL_VME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4845 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4847 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4848 | /* enable VLAN receive filtering */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4849 | rctl = er32(RCTL); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4850 | rctl &= ~E1000_RCTL_CFIEN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4851 | ew32(RCTL, rctl); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4852 | e1000_update_mng_vlan(adapter); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | } else { |
| 4855 | /* disable VLAN tag insert/strip */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4856 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | ctrl &= ~E1000_CTRL_VME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4858 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4860 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4861 | if (adapter->mng_vlan_id != |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4862 | (u16)E1000_MNG_VLAN_NONE) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4863 | e1000_vlan_rx_kill_vid(netdev, |
| 4864 | adapter->mng_vlan_id); |
| 4865 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4866 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4870 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4871 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4874 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4876 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4877 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4878 | u32 vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4879 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4880 | if ((hw->mng_cookie.status & |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4881 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4882 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4883 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | /* add VID to filter table */ |
| 4885 | index = (vid >> 5) & 0x7F; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4886 | vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | vfta |= (1 << (vid & 0x1F)); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4888 | e1000_write_vfta(hw, index, vfta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | } |
| 4890 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4891 | 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] | 4892 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4893 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4894 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4895 | u32 vfta, index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4897 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4898 | e1000_irq_disable(adapter); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4899 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4900 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4901 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4903 | if ((hw->mng_cookie.status & |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4904 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4905 | (vid == adapter->mng_vlan_id)) { |
| 4906 | /* release control to f/w */ |
| 4907 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4908 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4909 | } |
| 4910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | /* remove VID from filter table */ |
| 4912 | index = (vid >> 5) & 0x7F; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4913 | vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | vfta &= ~(1 << (vid & 0x1F)); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4915 | e1000_write_vfta(hw, index, vfta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4918 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | { |
| 4920 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4921 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4922 | if (adapter->vlgrp) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4923 | u16 vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4924 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4925 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | continue; |
| 4927 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 4928 | } |
| 4929 | } |
| 4930 | } |
| 4931 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4932 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4934 | struct e1000_hw *hw = &adapter->hw; |
| 4935 | |
| 4936 | hw->autoneg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4938 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4939 | if ((hw->media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4940 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 4941 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 4942 | return -EINVAL; |
| 4943 | } |
| 4944 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4945 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | case SPEED_10 + DUPLEX_HALF: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4947 | hw->forced_speed_duplex = e1000_10_half; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | break; |
| 4949 | case SPEED_10 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4950 | hw->forced_speed_duplex = e1000_10_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | break; |
| 4952 | case SPEED_100 + DUPLEX_HALF: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4953 | hw->forced_speed_duplex = e1000_100_half; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | break; |
| 4955 | case SPEED_100 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4956 | hw->forced_speed_duplex = e1000_100_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | break; |
| 4958 | case SPEED_1000 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4959 | hw->autoneg = 1; |
| 4960 | hw->autoneg_advertised = ADVERTISE_1000_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | break; |
| 4962 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 4963 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4964 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | return -EINVAL; |
| 4966 | } |
| 4967 | return 0; |
| 4968 | } |
| 4969 | |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4970 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | { |
| 4972 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4973 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4974 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4975 | u32 ctrl, ctrl_ext, rctl, status; |
| 4976 | u32 wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 4977 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4978 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 4979 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | |
| 4981 | netif_device_detach(netdev); |
| 4982 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4983 | if (netif_running(netdev)) { |
| 4984 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4987 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4988 | #ifdef CONFIG_PM |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 4989 | retval = pci_save_state(pdev); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4990 | if (retval) |
| 4991 | return retval; |
| 4992 | #endif |
| 4993 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4994 | status = er32(STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4995 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | wufc &= ~E1000_WUFC_LNKC; |
| 4997 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4998 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | e1000_setup_rctl(adapter); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 5000 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | |
| 5002 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 5003 | if (wufc & E1000_WUFC_MC) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5004 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | rctl |= E1000_RCTL_MPE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5006 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | } |
| 5008 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5009 | if (hw->mac_type >= e1000_82540) { |
| 5010 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | /* advertise wake from D3Cold */ |
| 5012 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5013 | /* phy power management enable */ |
| 5014 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5015 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 5016 | E1000_CTRL_EN_PHY_PWR_MGMT; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5017 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5020 | if (hw->media_type == e1000_media_type_fiber || |
| 5021 | hw->media_type == e1000_media_type_internal_serdes) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | /* keep the laser running in D3 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5023 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5025 | ew32(CTRL_EXT, ctrl_ext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5028 | /* Allow time for pending master requests to run */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5029 | e1000_disable_pciex_master(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5030 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5031 | ew32(WUC, E1000_WUC_PME_EN); |
| 5032 | ew32(WUFC, wufc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | } else { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5034 | ew32(WUC, 0); |
| 5035 | ew32(WUFC, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5038 | e1000_release_manageability(adapter); |
| 5039 | |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5040 | *enable_wake = !!wufc; |
| 5041 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5042 | /* make sure adapter isn't asleep if manageability is enabled */ |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5043 | if (adapter->en_mng_pt) |
| 5044 | *enable_wake = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5046 | if (hw->phy_type == e1000_phy_igp_3) |
| 5047 | e1000_phy_powerdown_workaround(hw); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5048 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5049 | if (netif_running(netdev)) |
| 5050 | e1000_free_irq(adapter); |
| 5051 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5052 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5053 | * would have already happened in close and is redundant. */ |
| 5054 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | return 0; |
| 5059 | } |
| 5060 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5061 | #ifdef CONFIG_PM |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5062 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5063 | { |
| 5064 | int retval; |
| 5065 | bool wake; |
| 5066 | |
| 5067 | retval = __e1000_shutdown(pdev, &wake); |
| 5068 | if (retval) |
| 5069 | return retval; |
| 5070 | |
| 5071 | if (wake) { |
| 5072 | pci_prepare_to_sleep(pdev); |
| 5073 | } else { |
| 5074 | pci_wake_from_d3(pdev, false); |
| 5075 | pci_set_power_state(pdev, PCI_D3hot); |
| 5076 | } |
| 5077 | |
| 5078 | return 0; |
| 5079 | } |
| 5080 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5081 | static int e1000_resume(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | { |
| 5083 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5084 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5085 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5086 | u32 err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5088 | pci_set_power_state(pdev, PCI_D0); |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5089 | pci_restore_state(pdev); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 5090 | |
| 5091 | if (adapter->need_ioport) |
| 5092 | err = pci_enable_device(pdev); |
| 5093 | else |
| 5094 | err = pci_enable_device_mem(pdev); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 5095 | if (err) { |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 5096 | printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
| 5097 | return err; |
| 5098 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 5099 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5101 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5102 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 5104 | if (netif_running(netdev)) { |
| 5105 | err = e1000_request_irq(adapter); |
| 5106 | if (err) |
| 5107 | return err; |
| 5108 | } |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5109 | |
| 5110 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | e1000_reset(adapter); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5112 | ew32(WUS, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5114 | e1000_init_manageability(adapter); |
| 5115 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5116 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 | e1000_up(adapter); |
| 5118 | |
| 5119 | netif_device_attach(netdev); |
| 5120 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5121 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5122 | * DRV_LOAD until the interface is up. For all other cases, |
| 5123 | * let the f/w know that the h/w is now under the control |
| 5124 | * of the driver. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5125 | if (hw->mac_type != e1000_82573 || |
| 5126 | !e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5127 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | return 0; |
| 5130 | } |
| 5131 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5132 | |
| 5133 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5134 | { |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5135 | bool wake; |
| 5136 | |
| 5137 | __e1000_shutdown(pdev, &wake); |
| 5138 | |
| 5139 | if (system_state == SYSTEM_POWER_OFF) { |
| 5140 | pci_wake_from_d3(pdev, wake); |
| 5141 | pci_set_power_state(pdev, PCI_D3hot); |
| 5142 | } |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5146 | /* |
| 5147 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5148 | * without having to re-enable interrupts. It's not called while |
| 5149 | * the interrupt routine is executing. |
| 5150 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5151 | static void e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5153 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 5154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5156 | e1000_intr(adapter->pdev->irq, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | enable_irq(adapter->pdev->irq); |
| 5158 | } |
| 5159 | #endif |
| 5160 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5161 | /** |
| 5162 | * e1000_io_error_detected - called when PCI error is detected |
| 5163 | * @pdev: Pointer to PCI device |
| 5164 | * @state: The current pci conneection state |
| 5165 | * |
| 5166 | * This function is called after a PCI bus error affecting |
| 5167 | * this device has been detected. |
| 5168 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5169 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5170 | pci_channel_state_t state) |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5171 | { |
| 5172 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 5173 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5174 | |
| 5175 | netif_device_detach(netdev); |
| 5176 | |
Andre Detsch | eab6330 | 2009-06-30 12:46:13 +0000 | [diff] [blame] | 5177 | if (state == pci_channel_io_perm_failure) |
| 5178 | return PCI_ERS_RESULT_DISCONNECT; |
| 5179 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5180 | if (netif_running(netdev)) |
| 5181 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 5182 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5183 | |
| 5184 | /* Request a slot slot reset. */ |
| 5185 | return PCI_ERS_RESULT_NEED_RESET; |
| 5186 | } |
| 5187 | |
| 5188 | /** |
| 5189 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5190 | * @pdev: Pointer to PCI device |
| 5191 | * |
| 5192 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5193 | * resembles the first-half of the e1000_resume routine. |
| 5194 | */ |
| 5195 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5196 | { |
| 5197 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 5198 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5199 | struct e1000_hw *hw = &adapter->hw; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 5200 | int err; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5201 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 5202 | if (adapter->need_ioport) |
| 5203 | err = pci_enable_device(pdev); |
| 5204 | else |
| 5205 | err = pci_enable_device_mem(pdev); |
| 5206 | if (err) { |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5207 | printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
| 5208 | return PCI_ERS_RESULT_DISCONNECT; |
| 5209 | } |
| 5210 | pci_set_master(pdev); |
| 5211 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 5212 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5213 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5214 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5215 | e1000_reset(adapter); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5216 | ew32(WUS, ~0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5217 | |
| 5218 | return PCI_ERS_RESULT_RECOVERED; |
| 5219 | } |
| 5220 | |
| 5221 | /** |
| 5222 | * e1000_io_resume - called when traffic can start flowing again. |
| 5223 | * @pdev: Pointer to PCI device |
| 5224 | * |
| 5225 | * This callback is called when the error recovery driver tells us that |
| 5226 | * its OK to resume normal operation. Implementation resembles the |
| 5227 | * second-half of the e1000_resume routine. |
| 5228 | */ |
| 5229 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5230 | { |
| 5231 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 5232 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5233 | struct e1000_hw *hw = &adapter->hw; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5234 | |
| 5235 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5236 | |
| 5237 | if (netif_running(netdev)) { |
| 5238 | if (e1000_up(adapter)) { |
| 5239 | printk("e1000: can't bring device back up after reset\n"); |
| 5240 | return; |
| 5241 | } |
| 5242 | } |
| 5243 | |
| 5244 | netif_device_attach(netdev); |
| 5245 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5246 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5247 | * DRV_LOAD until the interface is up. For all other cases, |
| 5248 | * let the f/w know that the h/w is now under the control |
| 5249 | * of the driver. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5250 | if (hw->mac_type != e1000_82573 || |
| 5251 | !e1000_check_mng_mode(hw)) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5252 | e1000_get_hw_control(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5253 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | /* e1000_main.c */ |