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; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 644 | bool legacy_pba_adjust = false; |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 645 | u16 hwm; |
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) { |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 689 | if (hw->max_frame_size > E1000_RXBUFFER_8192) |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 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 | } |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 699 | } else if (hw->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) { |
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 |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 704 | * large enough to accommodate two full transmit packets, |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 705 | * rounded up to the next 1KB and expressed in KB. Likewise, |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 706 | * the Rx FIFO should be large enough to accommodate at least |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 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; |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 714 | /* |
| 715 | * the tx fifo also stores 16 bytes of information about the tx |
| 716 | * but don't include ethernet FCS because hardware appends it |
| 717 | */ |
| 718 | min_tx_space = (hw->max_frame_size + |
| 719 | sizeof(struct e1000_tx_desc) - |
| 720 | ETH_FCS_LEN) * 2; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 721 | min_tx_space = ALIGN(min_tx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 722 | min_tx_space >>= 10; |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 723 | /* software strips receive CRC, so leave room for it */ |
| 724 | min_rx_space = hw->max_frame_size; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 725 | min_rx_space = ALIGN(min_rx_space, 1024); |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 726 | min_rx_space >>= 10; |
| 727 | |
| 728 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 729 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 730 | * allocation, take space away from current Rx allocation */ |
| 731 | if (tx_space < min_tx_space && |
| 732 | ((min_tx_space - tx_space) < pba)) { |
| 733 | pba = pba - (min_tx_space - tx_space); |
| 734 | |
| 735 | /* PCI/PCIx hardware has PBA alignment constraints */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 736 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 737 | case e1000_82545 ... e1000_82546_rev_3: |
| 738 | pba &= ~(E1000_PBA_8K - 1); |
| 739 | break; |
| 740 | default: |
| 741 | break; |
| 742 | } |
| 743 | |
| 744 | /* if short on rx space, rx wins and must trump tx |
| 745 | * adjustment or use Early Receive if available */ |
| 746 | if (pba < min_rx_space) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 747 | switch (hw->mac_type) { |
Bruce Allan | 018ea44 | 2006-12-15 10:39:45 +0100 | [diff] [blame] | 748 | case e1000_82573: |
| 749 | /* ERT enabled in e1000_configure_rx */ |
| 750 | break; |
| 751 | default: |
| 752 | pba = min_rx_space; |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 758 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 759 | ew32(PBA, pba); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 761 | /* |
| 762 | * flow control settings: |
| 763 | * The high water mark must be low enough to fit one full frame |
| 764 | * (or the size used for early receive) above it in the Rx FIFO. |
| 765 | * Set it to the lower of: |
| 766 | * - 90% of the Rx FIFO size, and |
| 767 | * - the full Rx FIFO size minus the early receive size (for parts |
| 768 | * with ERT support assuming ERT set to E1000_ERT_2048), or |
| 769 | * - the full Rx FIFO size minus one full frame |
| 770 | */ |
| 771 | hwm = min(((pba << 10) * 9 / 10), |
| 772 | ((pba << 10) - hw->max_frame_size)); |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 773 | |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 774 | hw->fc_high_water = hwm & 0xFFF8; /* 8-byte granularity */ |
| 775 | hw->fc_low_water = hw->fc_high_water - 8; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 776 | hw->fc_pause_time = E1000_FC_PAUSE_TIME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 777 | hw->fc_send_xon = 1; |
| 778 | hw->fc = hw->original_fc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 780 | /* Allow time for pending master requests to run */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 781 | e1000_reset_hw(hw); |
| 782 | if (hw->mac_type >= e1000_82544) |
| 783 | ew32(WUC, 0); |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 784 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 785 | if (e1000_init_hw(hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 787 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 788 | |
| 789 | /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 790 | if (hw->mac_type >= e1000_82544 && |
| 791 | hw->mac_type <= e1000_82547_rev_2 && |
| 792 | hw->autoneg == 1 && |
| 793 | hw->autoneg_advertised == ADVERTISE_1000_FULL) { |
| 794 | u32 ctrl = er32(CTRL); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 795 | /* clear phy power management bit if we are in gig only mode, |
| 796 | * which if enabled will attempt negotiation to 100Mb, which |
| 797 | * can cause a loss of link at power off or driver unload */ |
| 798 | ctrl &= ~E1000_CTRL_SWDPIN3; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 799 | ew32(CTRL, ctrl); |
Jesse Brandeburg | 3d5460a | 2006-12-15 10:33:46 +0100 | [diff] [blame] | 800 | } |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 803 | ew32(VET, ETHERNET_IEEE_VLAN_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 805 | e1000_reset_adaptive(hw); |
| 806 | e1000_phy_get_info(hw, &adapter->phy_info); |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 807 | |
| 808 | if (!adapter->smart_power_down && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 809 | (hw->mac_type == e1000_82571 || |
| 810 | hw->mac_type == e1000_82572)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 811 | u16 phy_data = 0; |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 812 | /* speed up time to link by disabling smart power down, ignore |
| 813 | * the return value of this function because there is nothing |
| 814 | * different we would do if it failed */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 815 | e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 816 | &phy_data); |
| 817 | phy_data &= ~IGP02E1000_PM_SPD; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 818 | e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 9a53a20 | 2006-06-27 09:06:45 -0700 | [diff] [blame] | 819 | phy_data); |
| 820 | } |
| 821 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 822 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /** |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 826 | * Dump the eeprom for users having checksum issues |
| 827 | **/ |
Adrian Bunk | b4ea895 | 2008-02-01 08:21:28 -0800 | [diff] [blame] | 828 | static void e1000_dump_eeprom(struct e1000_adapter *adapter) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 829 | { |
| 830 | struct net_device *netdev = adapter->netdev; |
| 831 | struct ethtool_eeprom eeprom; |
| 832 | const struct ethtool_ops *ops = netdev->ethtool_ops; |
| 833 | u8 *data; |
| 834 | int i; |
| 835 | u16 csum_old, csum_new = 0; |
| 836 | |
| 837 | eeprom.len = ops->get_eeprom_len(netdev); |
| 838 | eeprom.offset = 0; |
| 839 | |
| 840 | data = kmalloc(eeprom.len, GFP_KERNEL); |
| 841 | if (!data) { |
| 842 | printk(KERN_ERR "Unable to allocate memory to dump EEPROM" |
| 843 | " data\n"); |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | ops->get_eeprom(netdev, &eeprom, data); |
| 848 | |
| 849 | csum_old = (data[EEPROM_CHECKSUM_REG * 2]) + |
| 850 | (data[EEPROM_CHECKSUM_REG * 2 + 1] << 8); |
| 851 | for (i = 0; i < EEPROM_CHECKSUM_REG * 2; i += 2) |
| 852 | csum_new += data[i] + (data[i + 1] << 8); |
| 853 | csum_new = EEPROM_SUM - csum_new; |
| 854 | |
| 855 | printk(KERN_ERR "/*********************/\n"); |
| 856 | printk(KERN_ERR "Current EEPROM Checksum : 0x%04x\n", csum_old); |
| 857 | printk(KERN_ERR "Calculated : 0x%04x\n", csum_new); |
| 858 | |
| 859 | printk(KERN_ERR "Offset Values\n"); |
| 860 | printk(KERN_ERR "======== ======\n"); |
| 861 | print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 16, 1, data, 128, 0); |
| 862 | |
| 863 | printk(KERN_ERR "Include this output when contacting your support " |
| 864 | "provider.\n"); |
| 865 | printk(KERN_ERR "This is not a software error! Something bad " |
| 866 | "happened to your hardware or\n"); |
| 867 | printk(KERN_ERR "EEPROM image. Ignoring this " |
| 868 | "problem could result in further problems,\n"); |
| 869 | printk(KERN_ERR "possibly loss of data, corruption or system hangs!\n"); |
| 870 | printk(KERN_ERR "The MAC Address will be reset to 00:00:00:00:00:00, " |
| 871 | "which is invalid\n"); |
| 872 | printk(KERN_ERR "and requires you to set the proper MAC " |
| 873 | "address manually before continuing\n"); |
| 874 | printk(KERN_ERR "to enable this network device.\n"); |
| 875 | printk(KERN_ERR "Please inspect the EEPROM dump and report the issue " |
| 876 | "to your hardware vendor\n"); |
Jeff Kirsher | 63cd31f | 2008-07-11 15:17:33 -0700 | [diff] [blame] | 877 | printk(KERN_ERR "or Intel Customer Support.\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 878 | printk(KERN_ERR "/*********************/\n"); |
| 879 | |
| 880 | kfree(data); |
| 881 | } |
| 882 | |
| 883 | /** |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 884 | * e1000_is_need_ioport - determine if an adapter needs ioport resources or not |
| 885 | * @pdev: PCI device information struct |
| 886 | * |
| 887 | * Return true if an adapter needs ioport resources |
| 888 | **/ |
| 889 | static int e1000_is_need_ioport(struct pci_dev *pdev) |
| 890 | { |
| 891 | switch (pdev->device) { |
| 892 | case E1000_DEV_ID_82540EM: |
| 893 | case E1000_DEV_ID_82540EM_LOM: |
| 894 | case E1000_DEV_ID_82540EP: |
| 895 | case E1000_DEV_ID_82540EP_LOM: |
| 896 | case E1000_DEV_ID_82540EP_LP: |
| 897 | case E1000_DEV_ID_82541EI: |
| 898 | case E1000_DEV_ID_82541EI_MOBILE: |
| 899 | case E1000_DEV_ID_82541ER: |
| 900 | case E1000_DEV_ID_82541ER_LOM: |
| 901 | case E1000_DEV_ID_82541GI: |
| 902 | case E1000_DEV_ID_82541GI_LF: |
| 903 | case E1000_DEV_ID_82541GI_MOBILE: |
| 904 | case E1000_DEV_ID_82544EI_COPPER: |
| 905 | case E1000_DEV_ID_82544EI_FIBER: |
| 906 | case E1000_DEV_ID_82544GC_COPPER: |
| 907 | case E1000_DEV_ID_82544GC_LOM: |
| 908 | case E1000_DEV_ID_82545EM_COPPER: |
| 909 | case E1000_DEV_ID_82545EM_FIBER: |
| 910 | case E1000_DEV_ID_82546EB_COPPER: |
| 911 | case E1000_DEV_ID_82546EB_FIBER: |
| 912 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 913 | return true; |
| 914 | default: |
| 915 | return false; |
| 916 | } |
| 917 | } |
| 918 | |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 919 | static const struct net_device_ops e1000_netdev_ops = { |
| 920 | .ndo_open = e1000_open, |
| 921 | .ndo_stop = e1000_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 922 | .ndo_start_xmit = e1000_xmit_frame, |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 923 | .ndo_get_stats = e1000_get_stats, |
| 924 | .ndo_set_rx_mode = e1000_set_rx_mode, |
| 925 | .ndo_set_mac_address = e1000_set_mac, |
| 926 | .ndo_tx_timeout = e1000_tx_timeout, |
| 927 | .ndo_change_mtu = e1000_change_mtu, |
| 928 | .ndo_do_ioctl = e1000_ioctl, |
| 929 | .ndo_validate_addr = eth_validate_addr, |
| 930 | |
| 931 | .ndo_vlan_rx_register = e1000_vlan_rx_register, |
| 932 | .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid, |
| 933 | .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid, |
| 934 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 935 | .ndo_poll_controller = e1000_netpoll, |
| 936 | #endif |
| 937 | }; |
| 938 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 939 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | * e1000_probe - Device Initialization Routine |
| 941 | * @pdev: PCI device information struct |
| 942 | * @ent: entry in e1000_pci_tbl |
| 943 | * |
| 944 | * Returns 0 on success, negative on failure |
| 945 | * |
| 946 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 947 | * The OS initialization, configuring of the adapter private structure, |
| 948 | * and a hardware reset occur. |
| 949 | **/ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 950 | static int __devinit e1000_probe(struct pci_dev *pdev, |
| 951 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | { |
| 953 | struct net_device *netdev; |
| 954 | struct e1000_adapter *adapter; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 955 | struct e1000_hw *hw; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | static int cards_found = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 958 | static int global_quad_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 959 | int i, err, pci_using_dac; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 960 | u16 eeprom_data = 0; |
| 961 | u16 eeprom_apme_mask = E1000_EEPROM_APME; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 962 | int bars, need_ioport; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 963 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 964 | /* do not allocate ioport bars when not needed */ |
| 965 | need_ioport = e1000_is_need_ioport(pdev); |
| 966 | if (need_ioport) { |
| 967 | bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); |
| 968 | err = pci_enable_device(pdev); |
| 969 | } else { |
| 970 | bars = pci_select_bars(pdev, IORESOURCE_MEM); |
Karsten Keil | 4d7155b | 2009-02-03 15:18:01 -0800 | [diff] [blame] | 971 | err = pci_enable_device_mem(pdev); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 972 | } |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 973 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | return err; |
| 975 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 976 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 977 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | pci_using_dac = 1; |
| 979 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 980 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 981 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 982 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 983 | if (err) { |
| 984 | E1000_ERR("No usable DMA configuration, " |
| 985 | "aborting\n"); |
| 986 | goto err_dma; |
| 987 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | pci_using_dac = 0; |
| 990 | } |
| 991 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 992 | err = pci_request_selected_regions(pdev, bars, e1000_driver_name); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 993 | if (err) |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 994 | goto err_pci_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | pci_set_master(pdev); |
| 997 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 998 | err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1000 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | goto err_alloc_etherdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1004 | |
| 1005 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1006 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | adapter->netdev = netdev; |
| 1008 | adapter->pdev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | adapter->msg_enable = (1 << debug) - 1; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1010 | adapter->bars = bars; |
| 1011 | adapter->need_ioport = need_ioport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1013 | hw = &adapter->hw; |
| 1014 | hw->back = adapter; |
| 1015 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1016 | err = -EIO; |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 1017 | hw->hw_addr = pci_ioremap_bar(pdev, BAR_0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1018 | if (!hw->hw_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | goto err_ioremap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1021 | if (adapter->need_ioport) { |
| 1022 | for (i = BAR_1; i <= BAR_5; i++) { |
| 1023 | if (pci_resource_len(pdev, i) == 0) |
| 1024 | continue; |
| 1025 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
| 1026 | hw->io_base = pci_resource_start(pdev, i); |
| 1027 | break; |
| 1028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 1032 | netdev->netdev_ops = &e1000_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | e1000_set_ethtool_ops(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | netdev->watchdog_timeo = 5 * HZ; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1035 | netif_napi_add(netdev, &adapter->napi, e1000_clean, 64); |
Stephen Hemminger | 0e7614b | 2008-11-19 22:18:22 -0800 | [diff] [blame] | 1036 | |
Auke Kok | 0eb5a34 | 2006-09-27 12:53:17 -0700 | [diff] [blame] | 1037 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | adapter->bd_number = cards_found; |
| 1040 | |
| 1041 | /* setup the private structure */ |
| 1042 | |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 1043 | err = e1000_sw_init(adapter); |
| 1044 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | goto err_sw_init; |
| 1046 | |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1047 | err = -EIO; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1048 | /* Flash BAR mapping must happen after e1000_sw_init |
| 1049 | * because it depends on mac_type */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1050 | if ((hw->mac_type == e1000_ich8lan) && |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1051 | (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) { |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 1052 | hw->flash_address = pci_ioremap_bar(pdev, 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1053 | if (!hw->flash_address) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1054 | goto err_flashmap; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1057 | if (e1000_check_phy_reset_block(hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1058 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 1059 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1060 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | netdev->features = NETIF_F_SG | |
| 1062 | NETIF_F_HW_CSUM | |
| 1063 | NETIF_F_HW_VLAN_TX | |
| 1064 | NETIF_F_HW_VLAN_RX | |
| 1065 | NETIF_F_HW_VLAN_FILTER; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1066 | if (hw->mac_type == e1000_ich8lan) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1067 | netdev->features &= ~NETIF_F_HW_VLAN_FILTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1070 | if ((hw->mac_type >= e1000_82544) && |
| 1071 | (hw->mac_type != e1000_82547)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1073 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1074 | if (hw->mac_type > e1000_82547_rev_2) |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 1075 | netdev->features |= NETIF_F_TSO6; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1076 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | netdev->features |= NETIF_F_HIGHDMA; |
| 1078 | |
Patrick McHardy | 20501a6 | 2008-10-11 12:25:59 -0700 | [diff] [blame] | 1079 | netdev->vlan_features |= NETIF_F_TSO; |
| 1080 | netdev->vlan_features |= NETIF_F_TSO6; |
| 1081 | netdev->vlan_features |= NETIF_F_HW_CSUM; |
| 1082 | netdev->vlan_features |= NETIF_F_SG; |
| 1083 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1084 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1085 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1086 | /* initialize eeprom parameters */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1087 | if (e1000_init_eeprom_params(hw)) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1088 | E1000_ERR("EEPROM initialization failed\n"); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1089 | goto err_eeprom; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1092 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1094 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1095 | e1000_reset_hw(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* make sure the EEPROM is good */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1098 | if (e1000_validate_eeprom_checksum(hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1100 | e1000_dump_eeprom(adapter); |
| 1101 | /* |
| 1102 | * set MAC address to all zeroes to invalidate and temporary |
| 1103 | * disable this device for the user. This blocks regular |
| 1104 | * traffic while still permitting ethtool ioctls from reaching |
| 1105 | * the hardware as well as allowing the user to run the |
| 1106 | * interface after manually setting a hw addr using |
| 1107 | * `ip set address` |
| 1108 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1109 | memset(hw->mac_addr, 0, netdev->addr_len); |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1110 | } else { |
| 1111 | /* copy the MAC address out of the EEPROM */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1112 | if (e1000_read_mac_addr(hw)) |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1113 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1115 | /* don't block initalization here due to bad MAC address */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1116 | memcpy(netdev->dev_addr, hw->mac_addr, netdev->addr_len); |
| 1117 | memcpy(netdev->perm_addr, hw->mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
Auke Kok | 67b3c27 | 2007-12-17 13:50:23 -0800 | [diff] [blame] | 1119 | if (!is_valid_ether_addr(netdev->perm_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1122 | e1000_get_bus_info(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
| 1124 | init_timer(&adapter->tx_fifo_stall_timer); |
| 1125 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1126 | adapter->tx_fifo_stall_timer.data = (unsigned long)adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
| 1128 | init_timer(&adapter->watchdog_timer); |
| 1129 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 1130 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | init_timer(&adapter->phy_info_timer); |
| 1133 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1134 | adapter->phy_info_timer.data = (unsigned long)adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1136 | INIT_WORK(&adapter->reset_task, e1000_reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | e1000_check_options(adapter); |
| 1139 | |
| 1140 | /* Initial Wake on LAN setting |
| 1141 | * If APM wake is enabled in the EEPROM, |
| 1142 | * enable the ACPI Magic Packet filter |
| 1143 | */ |
| 1144 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1145 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | case e1000_82542_rev2_0: |
| 1147 | case e1000_82542_rev2_1: |
| 1148 | case e1000_82543: |
| 1149 | break; |
| 1150 | case e1000_82544: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1151 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 1153 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 1154 | break; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1155 | case e1000_ich8lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1156 | e1000_read_eeprom(hw, |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1157 | EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data); |
| 1158 | eeprom_apme_mask = E1000_EEPROM_ICH8_APME; |
| 1159 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | case e1000_82546: |
| 1161 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1162 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1163 | case e1000_80003es2lan: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1164 | if (er32(STATUS) & E1000_STATUS_FUNC_1){ |
| 1165 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 1167 | break; |
| 1168 | } |
| 1169 | /* Fall Through */ |
| 1170 | default: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1171 | e1000_read_eeprom(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 1173 | break; |
| 1174 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1175 | if (eeprom_data & eeprom_apme_mask) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1176 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1177 | |
| 1178 | /* now that we have the eeprom settings, apply the special cases |
| 1179 | * where the eeprom may be wrong or the board simply won't support |
| 1180 | * wake on lan on a particular port */ |
| 1181 | switch (pdev->device) { |
| 1182 | case E1000_DEV_ID_82546GB_PCIE: |
| 1183 | adapter->eeprom_wol = 0; |
| 1184 | break; |
| 1185 | case E1000_DEV_ID_82546EB_FIBER: |
| 1186 | case E1000_DEV_ID_82546GB_FIBER: |
| 1187 | case E1000_DEV_ID_82571EB_FIBER: |
| 1188 | /* Wake events only supported on port A for dual fiber |
| 1189 | * regardless of eeprom setting */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1190 | if (er32(STATUS) & E1000_STATUS_FUNC_1) |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1191 | adapter->eeprom_wol = 0; |
| 1192 | break; |
| 1193 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1194 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Auke Kok | ce57a02 | 2007-08-09 14:09:34 -0700 | [diff] [blame] | 1195 | case E1000_DEV_ID_82571EB_QUAD_FIBER: |
Auke Kok | fc2307d | 2006-11-01 08:47:56 -0800 | [diff] [blame] | 1196 | case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: |
Auke Kok | f4ec7f9 | 2007-08-30 11:23:58 -0700 | [diff] [blame] | 1197 | case E1000_DEV_ID_82571PT_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1198 | /* if quad port adapter, disable WoL on all but port A */ |
| 1199 | if (global_quad_port_a != 0) |
| 1200 | adapter->eeprom_wol = 0; |
| 1201 | else |
| 1202 | adapter->quad_port_a = 1; |
| 1203 | /* Reset for multiple quad port adapters */ |
| 1204 | if (++global_quad_port_a == 4) |
| 1205 | global_quad_port_a = 0; |
| 1206 | break; |
| 1207 | } |
| 1208 | |
| 1209 | /* initialize the wol settings based on the eeprom settings */ |
| 1210 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | de12648 | 2008-11-07 20:30:19 +0000 | [diff] [blame] | 1211 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1213 | /* print bus type/speed/width info */ |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1214 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 1215 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 1216 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 1217 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 1218 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 1219 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 1220 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 1221 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 1222 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 1223 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 1224 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 1225 | "32-bit")); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1226 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1227 | printk("%pM\n", netdev->dev_addr); |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 1228 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1229 | if (hw->bus_type == e1000_bus_type_pci_express) { |
Auke Kok | 14782ca | 2008-02-11 09:25:46 -0800 | [diff] [blame] | 1230 | DPRINTK(PROBE, WARNING, "This device (id %04x:%04x) will no " |
| 1231 | "longer be supported by this driver in the future.\n", |
| 1232 | pdev->vendor, pdev->device); |
| 1233 | DPRINTK(PROBE, WARNING, "please use the \"e1000e\" " |
| 1234 | "driver instead.\n"); |
| 1235 | } |
| 1236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | /* reset the hardware with the new settings */ |
| 1238 | e1000_reset(adapter); |
| 1239 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1240 | /* If the controller is 82573 and f/w is AMT, do not set |
| 1241 | * DRV_LOAD until the interface is up. For all other cases, |
| 1242 | * let the f/w know that the h/w is now under the control |
| 1243 | * of the driver. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1244 | if (hw->mac_type != e1000_82573 || |
| 1245 | !e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1246 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1247 | |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1248 | strcpy(netdev->name, "eth%d"); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 1249 | err = register_netdev(netdev); |
| 1250 | if (err) |
Auke Kok | 416b5d1 | 2007-06-01 10:22:39 -0700 | [diff] [blame] | 1251 | goto err_register; |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1252 | |
Jesse Brandeburg | eb62efd | 2009-04-17 20:44:36 +0000 | [diff] [blame] | 1253 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 1254 | netif_carrier_off(netdev); |
| 1255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 1257 | |
| 1258 | cards_found++; |
| 1259 | return 0; |
| 1260 | |
| 1261 | err_register: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1262 | e1000_release_hw_control(adapter); |
| 1263 | err_eeprom: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1264 | if (!e1000_check_phy_reset_block(hw)) |
| 1265 | e1000_phy_hw_reset(hw); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1266 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1267 | if (hw->flash_address) |
| 1268 | iounmap(hw->flash_address); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1269 | err_flashmap: |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1270 | kfree(adapter->tx_ring); |
| 1271 | kfree(adapter->rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | err_sw_init: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1273 | iounmap(hw->hw_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | err_ioremap: |
| 1275 | free_netdev(netdev); |
| 1276 | err_alloc_etherdev: |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1277 | pci_release_selected_regions(pdev, bars); |
Vasily Averin | 6dd62ab | 2006-08-28 14:56:22 -0700 | [diff] [blame] | 1278 | err_pci_reg: |
| 1279 | err_dma: |
| 1280 | pci_disable_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | return err; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * e1000_remove - Device Removal Routine |
| 1286 | * @pdev: PCI device information struct |
| 1287 | * |
| 1288 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 1289 | * that it should release a PCI device. The could be caused by a |
| 1290 | * Hot-Plug event, or because the driver is going to be removed from |
| 1291 | * memory. |
| 1292 | **/ |
| 1293 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1294 | static void __devexit e1000_remove(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | { |
| 1296 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1297 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1298 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Oleg Nesterov | 28e53bd | 2007-05-09 02:34:22 -0700 | [diff] [blame] | 1300 | cancel_work_sync(&adapter->reset_task); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 1301 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 1302 | e1000_release_manageability(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1304 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1305 | * would have already happened in close and is redundant. */ |
| 1306 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1307 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1308 | unregister_netdev(netdev); |
| 1309 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1310 | if (!e1000_check_phy_reset_block(hw)) |
| 1311 | e1000_phy_hw_reset(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1313 | kfree(adapter->tx_ring); |
| 1314 | kfree(adapter->rx_ring); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1315 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1316 | iounmap(hw->hw_addr); |
| 1317 | if (hw->flash_address) |
| 1318 | iounmap(hw->flash_address); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 1319 | pci_release_selected_regions(pdev, adapter->bars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
| 1321 | free_netdev(netdev); |
| 1322 | |
| 1323 | pci_disable_device(pdev); |
| 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 1328 | * @adapter: board private structure to initialize |
| 1329 | * |
| 1330 | * e1000_sw_init initializes the Adapter private data structure. |
| 1331 | * Fields are initialized based on PCI device information and |
| 1332 | * OS network device settings (MTU size). |
| 1333 | **/ |
| 1334 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1335 | static int __devinit e1000_sw_init(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | { |
| 1337 | struct e1000_hw *hw = &adapter->hw; |
| 1338 | struct net_device *netdev = adapter->netdev; |
| 1339 | struct pci_dev *pdev = adapter->pdev; |
| 1340 | |
| 1341 | /* PCI config space info */ |
| 1342 | |
| 1343 | hw->vendor_id = pdev->vendor; |
| 1344 | hw->device_id = pdev->device; |
| 1345 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1346 | hw->subsystem_id = pdev->subsystem_device; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1347 | hw->revision_id = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | |
| 1349 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 1350 | |
Auke Kok | eb0f805 | 2006-07-14 16:14:48 -0700 | [diff] [blame] | 1351 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | hw->max_frame_size = netdev->mtu + |
| 1353 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1354 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 1355 | |
| 1356 | /* identify the MAC */ |
| 1357 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1358 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 1360 | return -EIO; |
| 1361 | } |
| 1362 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1363 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | default: |
| 1365 | break; |
| 1366 | case e1000_82541: |
| 1367 | case e1000_82547: |
| 1368 | case e1000_82541_rev_2: |
| 1369 | case e1000_82547_rev_2: |
| 1370 | hw->phy_init_script = 1; |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | e1000_set_media_type(hw); |
| 1375 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1376 | hw->wait_autoneg_complete = false; |
| 1377 | hw->tbi_compatibility_en = true; |
| 1378 | hw->adaptive_ifs = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
| 1380 | /* Copper options */ |
| 1381 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1382 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | hw->mdix = AUTO_ALL_MODES; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1384 | hw->disable_polarity_correction = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1386 | } |
| 1387 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1388 | adapter->num_tx_queues = 1; |
| 1389 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1390 | |
| 1391 | if (e1000_alloc_queues(adapter)) { |
| 1392 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1393 | return -ENOMEM; |
| 1394 | } |
| 1395 | |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1396 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1397 | e1000_irq_disable(adapter); |
| 1398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1401 | set_bit(__E1000_DOWN, &adapter->flags); |
| 1402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1407 | * e1000_alloc_queues - Allocate memory for all rings |
| 1408 | * @adapter: board private structure to initialize |
| 1409 | * |
| 1410 | * 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] | 1411 | * number of queues at compile-time. |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1412 | **/ |
| 1413 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1414 | static int __devinit e1000_alloc_queues(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1415 | { |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1416 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1417 | sizeof(struct e1000_tx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1418 | if (!adapter->tx_ring) |
| 1419 | return -ENOMEM; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1420 | |
Yan Burman | 1c7e5b1 | 2007-03-06 08:58:04 -0800 | [diff] [blame] | 1421 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1422 | sizeof(struct e1000_rx_ring), GFP_KERNEL); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1423 | if (!adapter->rx_ring) { |
| 1424 | kfree(adapter->tx_ring); |
| 1425 | return -ENOMEM; |
| 1426 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1427 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1428 | return E1000_SUCCESS; |
| 1429 | } |
| 1430 | |
| 1431 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | * e1000_open - Called when a network interface is made active |
| 1433 | * @netdev: network interface device structure |
| 1434 | * |
| 1435 | * Returns 0 on success, negative value on failure |
| 1436 | * |
| 1437 | * The open entry point is called when a network interface is made |
| 1438 | * active by the system (IFF_UP). At this point all resources needed |
| 1439 | * for transmit and receive operations are allocated, the interrupt |
| 1440 | * handler is registered with the OS, the watchdog timer is started, |
| 1441 | * and the stack is notified that the interface is ready. |
| 1442 | **/ |
| 1443 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1444 | static int e1000_open(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1446 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1447 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | int err; |
| 1449 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1450 | /* disallow open during test */ |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 1451 | if (test_bit(__E1000_TESTING, &adapter->flags)) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1452 | return -EBUSY; |
| 1453 | |
Jesse Brandeburg | eb62efd | 2009-04-17 20:44:36 +0000 | [diff] [blame] | 1454 | netif_carrier_off(netdev); |
| 1455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | /* allocate transmit descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1457 | err = e1000_setup_all_tx_resources(adapter); |
| 1458 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | goto err_setup_tx; |
| 1460 | |
| 1461 | /* allocate receive descriptors */ |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1462 | err = e1000_setup_all_rx_resources(adapter); |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1463 | if (err) |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1464 | goto err_setup_rx; |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1465 | |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1466 | e1000_power_up_phy(adapter); |
| 1467 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1468 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1469 | if ((hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1470 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1471 | e1000_update_mng_vlan(adapter); |
| 1472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1474 | /* If AMT is enabled, let the firmware know that the network |
| 1475 | * interface is now open */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1476 | if (hw->mac_type == e1000_82573 && |
| 1477 | e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1478 | e1000_get_hw_control(adapter); |
| 1479 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1480 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1481 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1482 | * as soon as we call pci_request_irq, so we have to setup our |
| 1483 | * clean_rx handler before we do so. */ |
| 1484 | e1000_configure(adapter); |
| 1485 | |
| 1486 | err = e1000_request_irq(adapter); |
| 1487 | if (err) |
| 1488 | goto err_req_irq; |
| 1489 | |
| 1490 | /* From here on the code is the same as e1000_up() */ |
| 1491 | clear_bit(__E1000_DOWN, &adapter->flags); |
| 1492 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1493 | napi_enable(&adapter->napi); |
Herbert Xu | 4731305 | 2007-05-29 15:07:31 -0700 | [diff] [blame] | 1494 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1495 | e1000_irq_enable(adapter); |
| 1496 | |
Ben Hutchings | 076152d | 2008-07-18 17:50:57 -0700 | [diff] [blame] | 1497 | netif_start_queue(netdev); |
| 1498 | |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1499 | /* fire a link status change interrupt to start the watchdog */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1500 | ew32(ICS, E1000_ICS_LSC); |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | return E1000_SUCCESS; |
| 1503 | |
Linus Torvalds | b5bf28c | 2007-02-21 11:21:44 -0800 | [diff] [blame] | 1504 | err_req_irq: |
Auke Kok | e0aac5a | 2007-03-06 08:57:21 -0800 | [diff] [blame] | 1505 | e1000_release_hw_control(adapter); |
| 1506 | e1000_power_down_phy(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1507 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1509 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | err_setup_tx: |
| 1511 | e1000_reset(adapter); |
| 1512 | |
| 1513 | return err; |
| 1514 | } |
| 1515 | |
| 1516 | /** |
| 1517 | * e1000_close - Disables a network interface |
| 1518 | * @netdev: network interface device structure |
| 1519 | * |
| 1520 | * Returns 0, this is not allowed to fail |
| 1521 | * |
| 1522 | * The close entry point is called when an interface is de-activated |
| 1523 | * by the OS. The hardware is still under the drivers control, but |
| 1524 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1525 | * hardware, and all transmit and receive resources are freed. |
| 1526 | **/ |
| 1527 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1528 | static int e1000_close(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1530 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1531 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1533 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | e1000_down(adapter); |
Auke Kok | 79f05bf | 2006-06-27 09:06:32 -0700 | [diff] [blame] | 1535 | e1000_power_down_phy(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1536 | e1000_free_irq(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1538 | e1000_free_all_tx_resources(adapter); |
| 1539 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1541 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1542 | * 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] | 1543 | if ((hw->mng_cookie.status & |
Bruce Allan | 4666560 | 2006-09-27 12:54:08 -0700 | [diff] [blame] | 1544 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 1545 | !(adapter->vlgrp && |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1546 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1547 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1548 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1549 | |
| 1550 | /* If AMT is enabled, let the firmware know that the network |
| 1551 | * interface is now closed */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1552 | if (hw->mac_type == e1000_82573 && |
| 1553 | e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1554 | e1000_release_hw_control(adapter); |
| 1555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | return 0; |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1561 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1562 | * @start: address of beginning of memory |
| 1563 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1565 | static bool e1000_check_64k_bound(struct e1000_adapter *adapter, void *start, |
| 1566 | unsigned long len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1568 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 1569 | unsigned long begin = (unsigned long)start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | unsigned long end = begin + len; |
| 1571 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1572 | /* First rev 82545 and 82546 need to not allow any memory |
| 1573 | * write location to cross 64k boundary due to errata 23 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1574 | if (hw->mac_type == e1000_82545 || |
| 1575 | hw->mac_type == e1000_82546) { |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1576 | return ((begin ^ (end - 1)) >> 16) != 0 ? false : true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 1579 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1584 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1585 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | * |
| 1587 | * Return 0 on success, negative on failure |
| 1588 | **/ |
| 1589 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1590 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1591 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | struct pci_dev *pdev = adapter->pdev; |
| 1594 | int size; |
| 1595 | |
| 1596 | size = sizeof(struct e1000_buffer) * txdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1597 | txdr->buffer_info = vmalloc(size); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1598 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1599 | DPRINTK(PROBE, ERR, |
| 1600 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | return -ENOMEM; |
| 1602 | } |
| 1603 | memset(txdr->buffer_info, 0, size); |
| 1604 | |
| 1605 | /* round up to nearest 4K */ |
| 1606 | |
| 1607 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1608 | txdr->size = ALIGN(txdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | |
| 1610 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1611 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1614 | DPRINTK(PROBE, ERR, |
| 1615 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | return -ENOMEM; |
| 1617 | } |
| 1618 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1619 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1621 | void *olddesc = txdr->desc; |
| 1622 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1623 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1624 | "at %p\n", txdr->size, txdr->desc); |
| 1625 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1627 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1628 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1630 | goto setup_tx_desc_die; |
| 1631 | } |
| 1632 | |
| 1633 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1634 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1635 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1636 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1638 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1639 | "Unable to allocate aligned memory " |
| 1640 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | vfree(txdr->buffer_info); |
| 1642 | return -ENOMEM; |
| 1643 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1644 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1646 | } |
| 1647 | } |
| 1648 | memset(txdr->desc, 0, txdr->size); |
| 1649 | |
| 1650 | txdr->next_to_use = 0; |
| 1651 | txdr->next_to_clean = 0; |
| 1652 | |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
| 1656 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1657 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1658 | * (Descriptors) for all queues |
| 1659 | * @adapter: board private structure |
| 1660 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1661 | * Return 0 on success, negative on failure |
| 1662 | **/ |
| 1663 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1664 | int e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1665 | { |
| 1666 | int i, err = 0; |
| 1667 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1668 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1669 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1670 | if (err) { |
| 1671 | DPRINTK(PROBE, ERR, |
| 1672 | "Allocation for Tx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1673 | for (i-- ; i >= 0; i--) |
| 1674 | e1000_free_tx_resources(adapter, |
| 1675 | &adapter->tx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1676 | break; |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | return err; |
| 1681 | } |
| 1682 | |
| 1683 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1685 | * @adapter: board private structure |
| 1686 | * |
| 1687 | * Configure the Tx unit of the MAC after a reset. |
| 1688 | **/ |
| 1689 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1690 | static void e1000_configure_tx(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1692 | u64 tdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1693 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1694 | u32 tdlen, tctl, tipg, tarc; |
| 1695 | u32 ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
| 1697 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1698 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1699 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1700 | case 1: |
| 1701 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1702 | tdba = adapter->tx_ring[0].dma; |
| 1703 | tdlen = adapter->tx_ring[0].count * |
| 1704 | sizeof(struct e1000_tx_desc); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1705 | ew32(TDLEN, tdlen); |
| 1706 | ew32(TDBAH, (tdba >> 32)); |
| 1707 | ew32(TDBAL, (tdba & 0x00000000ffffffffULL)); |
| 1708 | ew32(TDT, 0); |
| 1709 | ew32(TDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 1710 | adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH); |
| 1711 | 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] | 1712 | break; |
| 1713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
| 1715 | /* Set the default values for the Tx Inter Packet Gap timer */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1716 | if (hw->mac_type <= e1000_82547_rev_2 && |
Jesse Brandeburg | d89b6c6 | 2006-12-15 10:38:32 +0100 | [diff] [blame] | 1717 | (hw->media_type == e1000_media_type_fiber || |
| 1718 | hw->media_type == e1000_media_type_internal_serdes)) |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1719 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1720 | else |
| 1721 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1722 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1723 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | case e1000_82542_rev2_0: |
| 1725 | case e1000_82542_rev2_1: |
| 1726 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1727 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1728 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1730 | case e1000_80003es2lan: |
| 1731 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1732 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1733 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1735 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1736 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1737 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1739 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1740 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1741 | ew32(TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
| 1743 | /* Set the Tx Interrupt Delay register */ |
| 1744 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1745 | ew32(TIDV, adapter->tx_int_delay); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1746 | if (hw->mac_type >= e1000_82540) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1747 | ew32(TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
| 1749 | /* Program the Transmit Control Register */ |
| 1750 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1751 | tctl = er32(TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1753 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1755 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1756 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1757 | tarc = er32(TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 1758 | /* set the speed mode bit, we'll clear it if we're not at |
| 1759 | * gigabit link later */ |
Jeff Kirsher | 09ae3e8 | 2006-09-27 12:53:51 -0700 | [diff] [blame] | 1760 | tarc |= (1 << 21); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1761 | ew32(TARC0, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1762 | } else if (hw->mac_type == e1000_80003es2lan) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1763 | tarc = er32(TARC0); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1764 | tarc |= 1; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1765 | ew32(TARC0, tarc); |
| 1766 | tarc = er32(TARC1); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1767 | tarc |= 1; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1768 | ew32(TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1769 | } |
| 1770 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1771 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | |
| 1773 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
Jesse Brandeburg | 6a042da | 2006-11-01 08:48:04 -0800 | [diff] [blame] | 1774 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS; |
| 1775 | |
| 1776 | /* only set IDE if we are delaying interrupts using the timers */ |
| 1777 | if (adapter->tx_int_delay) |
| 1778 | adapter->txd_cmd |= E1000_TXD_CMD_IDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1780 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1782 | else |
| 1783 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1784 | |
| 1785 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1786 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1787 | if (hw->mac_type == e1000_82544 && |
| 1788 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1790 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1791 | ew32(TCTL, tctl); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | /** |
| 1796 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1797 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1798 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | * |
| 1800 | * Returns 0 on success, negative on failure |
| 1801 | **/ |
| 1802 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1803 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1804 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1806 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1808 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
| 1810 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1811 | rxdr->buffer_info = vmalloc(size); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1812 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1813 | DPRINTK(PROBE, ERR, |
| 1814 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | return -ENOMEM; |
| 1816 | } |
| 1817 | memset(rxdr->buffer_info, 0, size); |
| 1818 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1819 | if (hw->mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1820 | desc_len = sizeof(struct e1000_rx_desc); |
| 1821 | else |
| 1822 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | /* Round up to nearest 4K */ |
| 1825 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1826 | rxdr->size = rxdr->count * desc_len; |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 1827 | rxdr->size = ALIGN(rxdr->size, 4096); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
| 1829 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1830 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1831 | if (!rxdr->desc) { |
| 1832 | DPRINTK(PROBE, ERR, |
| 1833 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | vfree(rxdr->buffer_info); |
| 1836 | return -ENOMEM; |
| 1837 | } |
| 1838 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1839 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1841 | void *olddesc = rxdr->desc; |
| 1842 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1843 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1844 | "at %p\n", rxdr->size, rxdr->desc); |
| 1845 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1847 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1848 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1850 | DPRINTK(PROBE, ERR, |
| 1851 | "Unable to allocate memory " |
| 1852 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | goto setup_rx_desc_die; |
| 1854 | } |
| 1855 | |
| 1856 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1857 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1858 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1859 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1861 | DPRINTK(PROBE, ERR, |
| 1862 | "Unable to allocate aligned memory " |
| 1863 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1864 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1866 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1868 | } |
| 1869 | } |
| 1870 | memset(rxdr->desc, 0, rxdr->size); |
| 1871 | |
| 1872 | rxdr->next_to_clean = 0; |
| 1873 | rxdr->next_to_use = 0; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 1874 | rxdr->rx_skb_top = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
| 1876 | return 0; |
| 1877 | } |
| 1878 | |
| 1879 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1880 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1881 | * (Descriptors) for all queues |
| 1882 | * @adapter: board private structure |
| 1883 | * |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1884 | * Return 0 on success, negative on failure |
| 1885 | **/ |
| 1886 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1887 | int e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1888 | { |
| 1889 | int i, err = 0; |
| 1890 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1891 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1892 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1893 | if (err) { |
| 1894 | DPRINTK(PROBE, ERR, |
| 1895 | "Allocation for Rx Queue %u failed\n", i); |
Vasily Averin | 3fbbc72 | 2006-08-28 14:56:24 -0700 | [diff] [blame] | 1896 | for (i-- ; i >= 0; i--) |
| 1897 | e1000_free_rx_resources(adapter, |
| 1898 | &adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1899 | break; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | return err; |
| 1904 | } |
| 1905 | |
| 1906 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1907 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | * @adapter: Board private structure |
| 1909 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1910 | static void e1000_setup_rctl(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1912 | struct e1000_hw *hw = &adapter->hw; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 1913 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1915 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
| 1917 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1918 | |
| 1919 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1920 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1921 | (hw->mc_filter_type << E1000_RCTL_MO_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1923 | if (hw->tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | rctl |= E1000_RCTL_SBP; |
| 1925 | else |
| 1926 | rctl &= ~E1000_RCTL_SBP; |
| 1927 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1928 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1929 | rctl &= ~E1000_RCTL_LPE; |
| 1930 | else |
| 1931 | rctl |= E1000_RCTL_LPE; |
| 1932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | /* Setup buffer sizes */ |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 1934 | rctl &= ~E1000_RCTL_SZ_4096; |
| 1935 | rctl |= E1000_RCTL_BSEX; |
| 1936 | switch (adapter->rx_buffer_len) { |
| 1937 | case E1000_RXBUFFER_256: |
| 1938 | rctl |= E1000_RCTL_SZ_256; |
| 1939 | rctl &= ~E1000_RCTL_BSEX; |
| 1940 | break; |
| 1941 | case E1000_RXBUFFER_512: |
| 1942 | rctl |= E1000_RCTL_SZ_512; |
| 1943 | rctl &= ~E1000_RCTL_BSEX; |
| 1944 | break; |
| 1945 | case E1000_RXBUFFER_1024: |
| 1946 | rctl |= E1000_RCTL_SZ_1024; |
| 1947 | rctl &= ~E1000_RCTL_BSEX; |
| 1948 | break; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1949 | case E1000_RXBUFFER_2048: |
| 1950 | default: |
| 1951 | rctl |= E1000_RCTL_SZ_2048; |
| 1952 | rctl &= ~E1000_RCTL_BSEX; |
| 1953 | break; |
| 1954 | case E1000_RXBUFFER_4096: |
| 1955 | rctl |= E1000_RCTL_SZ_4096; |
| 1956 | break; |
| 1957 | case E1000_RXBUFFER_8192: |
| 1958 | rctl |= E1000_RCTL_SZ_8192; |
| 1959 | break; |
| 1960 | case E1000_RXBUFFER_16384: |
| 1961 | rctl |= E1000_RCTL_SZ_16384; |
| 1962 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1965 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | /** |
| 1969 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1970 | * @adapter: board private structure |
| 1971 | * |
| 1972 | * Configure the Rx unit of the MAC after a reset. |
| 1973 | **/ |
| 1974 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 1975 | static void e1000_configure_rx(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1977 | u64 rdba; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1978 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 1979 | u32 rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1980 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 1981 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
| 1982 | rdlen = adapter->rx_ring[0].count * |
| 1983 | sizeof(struct e1000_rx_desc); |
| 1984 | adapter->clean_rx = e1000_clean_jumbo_rx_irq; |
| 1985 | adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers; |
| 1986 | } else { |
| 1987 | rdlen = adapter->rx_ring[0].count * |
| 1988 | sizeof(struct e1000_rx_desc); |
| 1989 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1990 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | |
| 1993 | /* disable receives while setting up the descriptors */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1994 | rctl = er32(RCTL); |
| 1995 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
| 1997 | /* set the Receive Delay Timer Register */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 1998 | ew32(RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2000 | if (hw->mac_type >= e1000_82540) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2001 | ew32(RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2002 | if (adapter->itr_setting != 0) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2003 | ew32(ITR, 1000000000 / (adapter->itr * 256)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2006 | if (hw->mac_type >= e1000_82571) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2007 | ctrl_ext = er32(CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2008 | /* Reset delay timers after every interrupt */ |
Auke Kok | 6fc7a7e | 2006-04-14 19:05:12 -0700 | [diff] [blame] | 2009 | ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2010 | /* Auto-Mask interrupts upon ICR access */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 2011 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2012 | ew32(IAM, 0xffffffff); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2013 | ew32(CTRL_EXT, ctrl_ext); |
| 2014 | E1000_WRITE_FLUSH(); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 2015 | } |
| 2016 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2017 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2018 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2019 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2020 | case 1: |
| 2021 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2022 | rdba = adapter->rx_ring[0].dma; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2023 | ew32(RDLEN, rdlen); |
| 2024 | ew32(RDBAH, (rdba >> 32)); |
| 2025 | ew32(RDBAL, (rdba & 0x00000000ffffffffULL)); |
| 2026 | ew32(RDT, 0); |
| 2027 | ew32(RDH, 0); |
Auke Kok | 6a95169 | 2006-09-11 14:00:21 -0700 | [diff] [blame] | 2028 | adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH); |
| 2029 | 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] | 2030 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2031 | } |
| 2032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2034 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2035 | rxcsum = er32(RXCSUM); |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2036 | if (adapter->rx_csum) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2037 | rxcsum |= E1000_RXCSUM_TUOFL; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2038 | else |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2039 | /* don't need to clear IPPCSE as it defaults to 0 */ |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2040 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2041 | ew32(RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | /* Enable Receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2045 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2049 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 2050 | * @adapter: board private structure |
| 2051 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2052 | * |
| 2053 | * Free all transmit software resources |
| 2054 | **/ |
| 2055 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2056 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 2057 | struct e1000_tx_ring *tx_ring) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2058 | { |
| 2059 | struct pci_dev *pdev = adapter->pdev; |
| 2060 | |
| 2061 | e1000_clean_tx_ring(adapter, tx_ring); |
| 2062 | |
| 2063 | vfree(tx_ring->buffer_info); |
| 2064 | tx_ring->buffer_info = NULL; |
| 2065 | |
| 2066 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2067 | |
| 2068 | tx_ring->desc = NULL; |
| 2069 | } |
| 2070 | |
| 2071 | /** |
| 2072 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | * @adapter: board private structure |
| 2074 | * |
| 2075 | * Free all transmit software resources |
| 2076 | **/ |
| 2077 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2078 | void e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2080 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2082 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2083 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2086 | static void e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 2087 | struct e1000_buffer *buffer_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | { |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2089 | buffer_info->dma = 0; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2090 | if (buffer_info->skb) { |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2091 | skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb, |
| 2092 | DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | dev_kfree_skb_any(buffer_info->skb); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2094 | buffer_info->skb = NULL; |
| 2095 | } |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2096 | buffer_info->time_stamp = 0; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2097 | /* buffer_info must be completely set up in the transmit path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | /** |
| 2101 | * e1000_clean_tx_ring - Free Tx Buffers |
| 2102 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2103 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | **/ |
| 2105 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2106 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 2107 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2109 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | struct e1000_buffer *buffer_info; |
| 2111 | unsigned long size; |
| 2112 | unsigned int i; |
| 2113 | |
| 2114 | /* Free all the Tx ring sk_buffs */ |
| 2115 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2116 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | buffer_info = &tx_ring->buffer_info[i]; |
| 2118 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2119 | } |
| 2120 | |
| 2121 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 2122 | memset(tx_ring->buffer_info, 0, size); |
| 2123 | |
| 2124 | /* Zero out the descriptor ring */ |
| 2125 | |
| 2126 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2127 | |
| 2128 | tx_ring->next_to_use = 0; |
| 2129 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2130 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2132 | writel(0, hw->hw_addr + tx_ring->tdh); |
| 2133 | writel(0, hw->hw_addr + tx_ring->tdt); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2138 | * @adapter: board private structure |
| 2139 | **/ |
| 2140 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2141 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2142 | { |
| 2143 | int i; |
| 2144 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2145 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2146 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * e1000_free_rx_resources - Free Rx Resources |
| 2151 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2152 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | * |
| 2154 | * Free all receive software resources |
| 2155 | **/ |
| 2156 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2157 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 2158 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | struct pci_dev *pdev = adapter->pdev; |
| 2161 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2162 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
| 2164 | vfree(rx_ring->buffer_info); |
| 2165 | rx_ring->buffer_info = NULL; |
| 2166 | |
| 2167 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2168 | |
| 2169 | rx_ring->desc = NULL; |
| 2170 | } |
| 2171 | |
| 2172 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2173 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2175 | * |
| 2176 | * Free all receive software resources |
| 2177 | **/ |
| 2178 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2179 | void e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2180 | { |
| 2181 | int i; |
| 2182 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2183 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2184 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2185 | } |
| 2186 | |
| 2187 | /** |
| 2188 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 2189 | * @adapter: board private structure |
| 2190 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | **/ |
| 2192 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2193 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 2194 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2196 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | struct e1000_buffer *buffer_info; |
| 2198 | struct pci_dev *pdev = adapter->pdev; |
| 2199 | unsigned long size; |
Brandeburg, Jesse | 630b25c | 2008-09-16 13:01:28 -0700 | [diff] [blame] | 2200 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
| 2202 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2203 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2205 | if (buffer_info->dma && |
| 2206 | adapter->clean_rx == e1000_clean_rx_irq) { |
| 2207 | pci_unmap_single(pdev, buffer_info->dma, |
| 2208 | buffer_info->length, |
| 2209 | PCI_DMA_FROMDEVICE); |
| 2210 | } else if (buffer_info->dma && |
| 2211 | adapter->clean_rx == e1000_clean_jumbo_rx_irq) { |
| 2212 | pci_unmap_page(pdev, buffer_info->dma, |
| 2213 | buffer_info->length, |
| 2214 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2217 | buffer_info->dma = 0; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2218 | if (buffer_info->page) { |
| 2219 | put_page(buffer_info->page); |
| 2220 | buffer_info->page = NULL; |
| 2221 | } |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 2222 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | dev_kfree_skb(buffer_info->skb); |
| 2224 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | } |
| 2227 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 2228 | /* there also may be some cached data from a chained receive */ |
| 2229 | if (rx_ring->rx_skb_top) { |
| 2230 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 2231 | rx_ring->rx_skb_top = NULL; |
| 2232 | } |
| 2233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 2235 | memset(rx_ring->buffer_info, 0, size); |
| 2236 | |
| 2237 | /* Zero out the descriptor ring */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2239 | |
| 2240 | rx_ring->next_to_clean = 0; |
| 2241 | rx_ring->next_to_use = 0; |
| 2242 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2243 | writel(0, hw->hw_addr + rx_ring->rdh); |
| 2244 | writel(0, hw->hw_addr + rx_ring->rdt); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | /** |
| 2248 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2249 | * @adapter: board private structure |
| 2250 | **/ |
| 2251 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2252 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2253 | { |
| 2254 | int i; |
| 2255 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2256 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2257 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 2261 | * and memory write and invalidate disabled for certain operations |
| 2262 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2263 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter) |
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 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2267 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2269 | e1000_pci_clear_mwi(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2271 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | rctl |= E1000_RCTL_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2273 | ew32(RCTL, rctl); |
| 2274 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | mdelay(5); |
| 2276 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2277 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2278 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2281 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2283 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2285 | u32 rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2287 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | rctl &= ~E1000_RCTL_RST; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2289 | ew32(RCTL, rctl); |
| 2290 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | mdelay(5); |
| 2292 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2293 | if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE) |
| 2294 | e1000_pci_set_mwi(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2296 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2297 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2298 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2299 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2300 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2306 | * @netdev: network interface device structure |
| 2307 | * @p: pointer to an address structure |
| 2308 | * |
| 2309 | * Returns 0 on success, negative on failure |
| 2310 | **/ |
| 2311 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2312 | static int e1000_set_mac(struct net_device *netdev, void *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2314 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2315 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | struct sockaddr *addr = p; |
| 2317 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2318 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | return -EADDRNOTAVAIL; |
| 2320 | |
| 2321 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2322 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2323 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | e1000_enter_82542_rst(adapter); |
| 2325 | |
| 2326 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2327 | memcpy(hw->mac_addr, addr->sa_data, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2329 | e1000_rar_set(hw, hw->mac_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2331 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2332 | * due to controller reset from the other port. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2333 | if (hw->mac_type == e1000_82571) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2334 | /* activate the work around */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2335 | hw->laa_is_present = 1; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2336 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2337 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2338 | * between the time RAR[0] gets clobbered and the time it |
| 2339 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2340 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2341 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2342 | * RAR[14] */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2343 | e1000_rar_set(hw, hw->mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2344 | E1000_RAR_ENTRIES - 1); |
| 2345 | } |
| 2346 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2347 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | e1000_leave_82542_rst(adapter); |
| 2349 | |
| 2350 | return 0; |
| 2351 | } |
| 2352 | |
| 2353 | /** |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2354 | * e1000_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | * @netdev: network interface device structure |
| 2356 | * |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2357 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 2358 | * address lists or the network interface flags are updated. This routine is |
| 2359 | * responsible for configuring the hardware for proper unicast, multicast, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | * promiscuous mode, and all-multi behavior. |
| 2361 | **/ |
| 2362 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2363 | static void e1000_set_rx_mode(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2365 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2367 | struct netdev_hw_addr *ha; |
| 2368 | bool use_uc = false; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2369 | struct dev_addr_list *mc_ptr; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2370 | u32 rctl; |
| 2371 | u32 hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2372 | int i, rar_entries = E1000_RAR_ENTRIES; |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2373 | int mta_reg_count = (hw->mac_type == e1000_ich8lan) ? |
| 2374 | E1000_NUM_MTA_REGISTERS_ICH8LAN : |
| 2375 | E1000_NUM_MTA_REGISTERS; |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2376 | u32 *mcarray = kcalloc(mta_reg_count, sizeof(u32), GFP_ATOMIC); |
| 2377 | |
| 2378 | if (!mcarray) { |
| 2379 | DPRINTK(PROBE, ERR, "memory allocation failed\n"); |
| 2380 | return; |
| 2381 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2382 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2383 | if (hw->mac_type == e1000_ich8lan) |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2384 | rar_entries = E1000_RAR_ENTRIES_ICH8LAN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2386 | /* reserve RAR[14] for LAA over-write work-around */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2387 | if (hw->mac_type == e1000_82571) |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2388 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2390 | /* Check for Promiscuous and All Multicast modes */ |
| 2391 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2392 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2394 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2396 | rctl &= ~E1000_RCTL_VFE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2398 | if (netdev->flags & IFF_ALLMULTI) { |
| 2399 | rctl |= E1000_RCTL_MPE; |
| 2400 | } else { |
| 2401 | rctl &= ~E1000_RCTL_MPE; |
| 2402 | } |
Patrick McHardy | 78ed11a | 2008-07-16 20:16:14 -0700 | [diff] [blame] | 2403 | if (adapter->hw.mac_type != e1000_ich8lan) |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2404 | rctl |= E1000_RCTL_VFE; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2405 | } |
| 2406 | |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2407 | if (netdev->uc.count > rar_entries - 1) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2408 | rctl |= E1000_RCTL_UPE; |
| 2409 | } else if (!(netdev->flags & IFF_PROMISC)) { |
| 2410 | rctl &= ~E1000_RCTL_UPE; |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2411 | use_uc = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2414 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | |
| 2416 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2417 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2418 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | e1000_enter_82542_rst(adapter); |
| 2420 | |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2421 | /* load the first 14 addresses into the exact filters 1-14. Unicast |
| 2422 | * addresses take precedence to avoid disabling unicast filtering |
| 2423 | * when possible. |
| 2424 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | * RAR 0 is used for the station MAC adddress |
| 2426 | * 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] | 2427 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | */ |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2429 | i = 1; |
| 2430 | if (use_uc) |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2431 | list_for_each_entry(ha, &netdev->uc.list, list) { |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2432 | if (i == rar_entries) |
| 2433 | break; |
| 2434 | e1000_rar_set(hw, ha->addr, i++); |
| 2435 | } |
| 2436 | |
| 2437 | WARN_ON(i == rar_entries); |
| 2438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | mc_ptr = netdev->mc_list; |
| 2440 | |
Jiri Pirko | ccffad2 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2441 | for (; i < rar_entries; i++) { |
| 2442 | if (mc_ptr) { |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2443 | e1000_rar_set(hw, mc_ptr->da_addr, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | mc_ptr = mc_ptr->next; |
| 2445 | } else { |
| 2446 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2447 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2449 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | /* load any remaining addresses into the hash table */ |
| 2454 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2455 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2456 | u32 hash_reg, hash_bit, mta; |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 2457 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->da_addr); |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2458 | hash_reg = (hash_value >> 5) & 0x7F; |
| 2459 | hash_bit = hash_value & 0x1F; |
| 2460 | mta = (1 << hash_bit); |
| 2461 | mcarray[hash_reg] |= mta; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2464 | /* write the hash table completely, write from bottom to avoid |
| 2465 | * both stupid write combining chipsets, and flushing each write */ |
| 2466 | for (i = mta_reg_count - 1; i >= 0 ; i--) { |
| 2467 | /* |
| 2468 | * If we are on an 82544 has an errata where writing odd |
| 2469 | * offsets overwrites the previous even offset, but writing |
| 2470 | * backwards over the range solves the issue by always |
| 2471 | * writing the odd offset first |
| 2472 | */ |
| 2473 | E1000_WRITE_REG_ARRAY(hw, MTA, i, mcarray[i]); |
| 2474 | } |
| 2475 | E1000_WRITE_FLUSH(); |
| 2476 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2477 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | e1000_leave_82542_rst(adapter); |
Jesse Brandeburg | 81c5228 | 2009-04-04 16:36:53 -0700 | [diff] [blame] | 2479 | |
| 2480 | kfree(mcarray); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2484 | * the phy */ |
| 2485 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2486 | static void e1000_update_phy_info(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2488 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2489 | struct e1000_hw *hw = &adapter->hw; |
| 2490 | e1000_phy_get_info(hw, &adapter->phy_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | /** |
| 2494 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2495 | * @data: pointer to adapter cast into an unsigned long |
| 2496 | **/ |
| 2497 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2498 | static void e1000_82547_tx_fifo_stall(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2500 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2501 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | struct net_device *netdev = adapter->netdev; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2503 | u32 tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2505 | if (atomic_read(&adapter->tx_fifo_stall)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2506 | if ((er32(TDT) == er32(TDH)) && |
| 2507 | (er32(TDFT) == er32(TDFH)) && |
| 2508 | (er32(TDFTS) == er32(TDFHS))) { |
| 2509 | tctl = er32(TCTL); |
| 2510 | ew32(TCTL, tctl & ~E1000_TCTL_EN); |
| 2511 | ew32(TDFT, adapter->tx_head_addr); |
| 2512 | ew32(TDFH, adapter->tx_head_addr); |
| 2513 | ew32(TDFTS, adapter->tx_head_addr); |
| 2514 | ew32(TDFHS, adapter->tx_head_addr); |
| 2515 | ew32(TCTL, tctl); |
| 2516 | E1000_WRITE_FLUSH(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | |
| 2518 | adapter->tx_fifo_head = 0; |
| 2519 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2520 | netif_wake_queue(netdev); |
| 2521 | } else { |
| 2522 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2523 | } |
| 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | /** |
| 2528 | * e1000_watchdog - Timer Call-back |
| 2529 | * @data: pointer to adapter cast into an unsigned long |
| 2530 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2531 | static void e1000_watchdog(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 2533 | struct e1000_adapter *adapter = (struct e1000_adapter *)data; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2534 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2536 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2537 | u32 link, tctl; |
| 2538 | s32 ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2540 | ret_val = e1000_check_for_link(hw); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2541 | if ((ret_val == E1000_ERR_PHY) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2542 | (hw->phy_type == e1000_phy_igp_3) && |
| 2543 | (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) { |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 2544 | /* See e1000_kumeran_lock_loss_workaround() */ |
| 2545 | DPRINTK(LINK, INFO, |
| 2546 | "Gigabit has been disabled, downgrading speed\n"); |
| 2547 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2548 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2549 | if (hw->mac_type == e1000_82573) { |
| 2550 | e1000_enable_tx_pkt_filtering(hw); |
| 2551 | if (adapter->mng_vlan_id != hw->mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2552 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2555 | if ((hw->media_type == e1000_media_type_internal_serdes) && |
| 2556 | !(er32(TXCW) & E1000_TXCW_ANE)) |
| 2557 | link = !hw->serdes_link_down; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | else |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2559 | link = er32(STATUS) & E1000_STATUS_LU; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2561 | if (link) { |
| 2562 | if (!netif_carrier_ok(netdev)) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2563 | u32 ctrl; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2564 | bool txb2b = true; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2565 | e1000_get_speed_and_duplex(hw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | &adapter->link_speed, |
| 2567 | &adapter->link_duplex); |
| 2568 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2569 | ctrl = er32(CTRL); |
Jeff Kirsher | b30c4d8f | 2008-11-27 00:22:45 -0800 | [diff] [blame] | 2570 | printk(KERN_INFO "e1000: %s NIC Link is Up %d Mbps %s, " |
| 2571 | "Flow Control: %s\n", |
| 2572 | netdev->name, |
| 2573 | adapter->link_speed, |
| 2574 | adapter->link_duplex == FULL_DUPLEX ? |
Auke Kok | 9669f53 | 2007-01-18 09:25:26 -0800 | [diff] [blame] | 2575 | "Full Duplex" : "Half Duplex", |
| 2576 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2577 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2578 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2579 | E1000_CTRL_TFCE) ? "TX" : "None" ))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2581 | /* tweak tx_queue_len according to speed/duplex |
| 2582 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2583 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2584 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2585 | switch (adapter->link_speed) { |
| 2586 | case SPEED_10: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2587 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2588 | netdev->tx_queue_len = 10; |
| 2589 | adapter->tx_timeout_factor = 8; |
| 2590 | break; |
| 2591 | case SPEED_100: |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2592 | txb2b = false; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2593 | netdev->tx_queue_len = 100; |
| 2594 | /* maybe add some timeout factor ? */ |
| 2595 | break; |
| 2596 | } |
| 2597 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2598 | if ((hw->mac_type == e1000_82571 || |
| 2599 | hw->mac_type == e1000_82572) && |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2600 | !txb2b) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2601 | u32 tarc0; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2602 | tarc0 = er32(TARC0); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2603 | tarc0 &= ~(1 << 21); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2604 | ew32(TARC0, tarc0); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2605 | } |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 2606 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2607 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2608 | * some hardware issues */ |
| 2609 | if (!adapter->tso_force && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2610 | hw->bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2611 | switch (adapter->link_speed) { |
| 2612 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2613 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2614 | DPRINTK(PROBE,INFO, |
| 2615 | "10/100 speed: disabling TSO\n"); |
| 2616 | netdev->features &= ~NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2617 | netdev->features &= ~NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2618 | break; |
| 2619 | case SPEED_1000: |
| 2620 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 87ca4e5 | 2006-11-01 08:47:36 -0800 | [diff] [blame] | 2621 | netdev->features |= NETIF_F_TSO6; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2622 | break; |
| 2623 | default: |
| 2624 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2625 | break; |
| 2626 | } |
| 2627 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2628 | |
| 2629 | /* enable transmits in the hardware, need to do this |
| 2630 | * after setting TARC0 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2631 | tctl = er32(TCTL); |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2632 | tctl |= E1000_TCTL_EN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2633 | ew32(TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | netif_carrier_on(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2636 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | adapter->smartspeed = 0; |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2638 | } else { |
| 2639 | /* make sure the receive unit is started */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2640 | if (hw->rx_needs_kicking) { |
| 2641 | u32 rctl = er32(RCTL); |
| 2642 | ew32(RCTL, rctl | E1000_RCTL_EN); |
Jeff Garzik | bb8e331 | 2006-12-15 11:06:17 -0500 | [diff] [blame] | 2643 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
| 2645 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2646 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | adapter->link_speed = 0; |
| 2648 | adapter->link_duplex = 0; |
Jeff Kirsher | b30c4d8f | 2008-11-27 00:22:45 -0800 | [diff] [blame] | 2649 | printk(KERN_INFO "e1000: %s NIC Link is Down\n", |
| 2650 | netdev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | netif_carrier_off(netdev); |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2652 | mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ)); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2653 | |
| 2654 | /* 80003ES2LAN workaround-- |
| 2655 | * For packet buffer work-around on link down event; |
| 2656 | * disable receives in the ISR and |
| 2657 | * reset device here in the watchdog |
| 2658 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2659 | if (hw->mac_type == e1000_80003es2lan) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2660 | /* reset device */ |
| 2661 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | e1000_smartspeed(adapter); |
| 2665 | } |
| 2666 | |
| 2667 | e1000_update_stats(adapter); |
| 2668 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2669 | hw->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | adapter->tpt_old = adapter->stats.tpt; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2671 | hw->collision_delta = adapter->stats.colc - adapter->colc_old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | adapter->colc_old = adapter->stats.colc; |
| 2673 | |
| 2674 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2675 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2676 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2677 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2678 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2679 | e1000_update_adaptive(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2681 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2682 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | /* We've lost link, so the controller stops DMA, |
| 2684 | * but we've got queued Tx work that's never going |
| 2685 | * to get done, so reset controller to flush Tx. |
| 2686 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2687 | adapter->tx_timeout_count++; |
| 2688 | schedule_work(&adapter->reset_task); |
Jesse Brandeburg | c2d5ab4 | 2009-05-07 11:07:35 +0000 | [diff] [blame] | 2689 | /* return immediately since reset is imminent */ |
| 2690 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | } |
| 2692 | } |
| 2693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | /* Cause software interrupt to ensure rx ring is cleaned */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2695 | ew32(ICS, E1000_ICS_RXDMT0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2697 | /* Force detection of hung controller every watchdog period */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2698 | adapter->detect_tx_hung = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2700 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2701 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2702 | if (hw->mac_type == e1000_82571 && hw->laa_is_present) |
| 2703 | e1000_rar_set(hw, hw->mac_addr, 0); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | /* Reset the timer */ |
Arjan van de Ven | 56e1393 | 2007-03-06 02:41:48 -0800 | [diff] [blame] | 2706 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2709 | enum latency_range { |
| 2710 | lowest_latency = 0, |
| 2711 | low_latency = 1, |
| 2712 | bulk_latency = 2, |
| 2713 | latency_invalid = 255 |
| 2714 | }; |
| 2715 | |
| 2716 | /** |
| 2717 | * e1000_update_itr - update the dynamic ITR value based on statistics |
| 2718 | * Stores a new ITR value based on packets and byte |
| 2719 | * counts during the last interrupt. The advantage of per interrupt |
| 2720 | * computation is faster updates and more accurate ITR for the current |
| 2721 | * traffic pattern. Constants in this function were computed |
| 2722 | * based on theoretical maximum wire speed and thresholds were set based |
| 2723 | * on testing data as well as attempting to minimize response time |
| 2724 | * while increasing bulk throughput. |
| 2725 | * this functionality is controlled by the InterruptThrottleRate module |
| 2726 | * parameter (see e1000_param.c) |
| 2727 | * @adapter: pointer to adapter |
| 2728 | * @itr_setting: current adapter->itr |
| 2729 | * @packets: the number of packets during this measurement interval |
| 2730 | * @bytes: the number of bytes during this measurement interval |
| 2731 | **/ |
| 2732 | static unsigned int e1000_update_itr(struct e1000_adapter *adapter, |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2733 | u16 itr_setting, int packets, int bytes) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2734 | { |
| 2735 | unsigned int retval = itr_setting; |
| 2736 | struct e1000_hw *hw = &adapter->hw; |
| 2737 | |
| 2738 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2739 | goto update_itr_done; |
| 2740 | |
| 2741 | if (packets == 0) |
| 2742 | goto update_itr_done; |
| 2743 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2744 | switch (itr_setting) { |
| 2745 | case lowest_latency: |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2746 | /* jumbo frames get bulk treatment*/ |
| 2747 | if (bytes/packets > 8000) |
| 2748 | retval = bulk_latency; |
| 2749 | else if ((packets < 5) && (bytes > 512)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2750 | retval = low_latency; |
| 2751 | break; |
| 2752 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2753 | if (bytes > 10000) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2754 | /* jumbo frames need bulk latency setting */ |
| 2755 | if (bytes/packets > 8000) |
| 2756 | retval = bulk_latency; |
| 2757 | else if ((packets < 10) || ((bytes/packets) > 1200)) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2758 | retval = bulk_latency; |
| 2759 | else if ((packets > 35)) |
| 2760 | retval = lowest_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2761 | } else if (bytes/packets > 2000) |
| 2762 | retval = bulk_latency; |
| 2763 | else if (packets <= 2 && bytes < 512) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2764 | retval = lowest_latency; |
| 2765 | break; |
| 2766 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2767 | if (bytes > 25000) { |
| 2768 | if (packets > 35) |
| 2769 | retval = low_latency; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2770 | } else if (bytes < 6000) { |
| 2771 | retval = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2772 | } |
| 2773 | break; |
| 2774 | } |
| 2775 | |
| 2776 | update_itr_done: |
| 2777 | return retval; |
| 2778 | } |
| 2779 | |
| 2780 | static void e1000_set_itr(struct e1000_adapter *adapter) |
| 2781 | { |
| 2782 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2783 | u16 current_itr; |
| 2784 | u32 new_itr = adapter->itr; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2785 | |
| 2786 | if (unlikely(hw->mac_type < e1000_82540)) |
| 2787 | return; |
| 2788 | |
| 2789 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2790 | if (unlikely(adapter->link_speed != SPEED_1000)) { |
| 2791 | current_itr = 0; |
| 2792 | new_itr = 4000; |
| 2793 | goto set_itr_now; |
| 2794 | } |
| 2795 | |
| 2796 | adapter->tx_itr = e1000_update_itr(adapter, |
| 2797 | adapter->tx_itr, |
| 2798 | adapter->total_tx_packets, |
| 2799 | adapter->total_tx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2800 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2801 | if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency) |
| 2802 | adapter->tx_itr = low_latency; |
| 2803 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2804 | adapter->rx_itr = e1000_update_itr(adapter, |
| 2805 | adapter->rx_itr, |
| 2806 | adapter->total_rx_packets, |
| 2807 | adapter->total_rx_bytes); |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 2808 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
| 2809 | if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency) |
| 2810 | adapter->rx_itr = low_latency; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2811 | |
| 2812 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2813 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2814 | switch (current_itr) { |
| 2815 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2816 | case lowest_latency: |
| 2817 | new_itr = 70000; |
| 2818 | break; |
| 2819 | case low_latency: |
| 2820 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 2821 | break; |
| 2822 | case bulk_latency: |
| 2823 | new_itr = 4000; |
| 2824 | break; |
| 2825 | default: |
| 2826 | break; |
| 2827 | } |
| 2828 | |
| 2829 | set_itr_now: |
| 2830 | if (new_itr != adapter->itr) { |
| 2831 | /* this attempts to bias the interrupt rate towards Bulk |
| 2832 | * by adding intermediate steps when interrupt rate is |
| 2833 | * increasing */ |
| 2834 | new_itr = new_itr > adapter->itr ? |
| 2835 | min(adapter->itr + (new_itr >> 2), new_itr) : |
| 2836 | new_itr; |
| 2837 | adapter->itr = new_itr; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2838 | ew32(ITR, 1000000000 / (new_itr * 256)); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | return; |
| 2842 | } |
| 2843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2845 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2846 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2847 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2849 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2850 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2851 | static int e1000_tso(struct e1000_adapter *adapter, |
| 2852 | struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2855 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2857 | u32 cmd_length = 0; |
| 2858 | u16 ipcse = 0, tucse, mss; |
| 2859 | u8 ipcss, ipcso, tucss, tucso, hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | int err; |
| 2861 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2862 | if (skb_is_gso(skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | if (skb_header_cloned(skb)) { |
| 2864 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2865 | if (err) |
| 2866 | return err; |
| 2867 | } |
| 2868 | |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 2869 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2870 | mss = skb_shinfo(skb)->gso_size; |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 2871 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2872 | struct iphdr *iph = ip_hdr(skb); |
| 2873 | iph->tot_len = 0; |
| 2874 | iph->check = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2875 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2876 | iph->daddr, 0, |
| 2877 | IPPROTO_TCP, |
| 2878 | 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2879 | cmd_length = E1000_TXD_CMD_IP; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2880 | ipcse = skb_transport_offset(skb) - 1; |
Auke Kok | e15fdd0 | 2006-08-16 11:28:45 -0700 | [diff] [blame] | 2881 | } else if (skb->protocol == htons(ETH_P_IPV6)) { |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2882 | ipv6_hdr(skb)->payload_len = 0; |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2883 | tcp_hdr(skb)->check = |
Arnaldo Carvalho de Melo | 0660e03 | 2007-04-25 17:54:47 -0700 | [diff] [blame] | 2884 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2885 | &ipv6_hdr(skb)->daddr, |
| 2886 | 0, IPPROTO_TCP, 0); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2887 | ipcse = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2888 | } |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 2889 | ipcss = skb_network_offset(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2890 | ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data; |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 2891 | tucss = skb_transport_offset(skb); |
Arnaldo Carvalho de Melo | aa8223c | 2007-04-10 21:04:22 -0700 | [diff] [blame] | 2892 | tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | tucse = 0; |
| 2894 | |
| 2895 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2896 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2898 | i = tx_ring->next_to_use; |
| 2899 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2900 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | |
| 2902 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2903 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2904 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2905 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2906 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2907 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2908 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2909 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2910 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2911 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2912 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 2913 | buffer_info->next_to_watch = i; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2914 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2915 | if (++i == tx_ring->count) i = 0; |
| 2916 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2918 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | } |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 2920 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2923 | static bool e1000_tx_csum(struct e1000_adapter *adapter, |
| 2924 | struct e1000_tx_ring *tx_ring, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | { |
| 2926 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2927 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | unsigned int i; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 2929 | u8 css; |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2930 | u32 cmd_len = E1000_TXD_CMD_DEXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2932 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 2933 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2935 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 2936 | case cpu_to_be16(ETH_P_IP): |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2937 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 2938 | cmd_len |= E1000_TXD_CMD_TCP; |
| 2939 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 2940 | case cpu_to_be16(ETH_P_IPV6): |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2941 | /* XXX not handling all IPV6 headers */ |
| 2942 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 2943 | cmd_len |= E1000_TXD_CMD_TCP; |
| 2944 | break; |
| 2945 | default: |
| 2946 | if (unlikely(net_ratelimit())) |
| 2947 | DPRINTK(DRV, WARNING, |
| 2948 | "checksum_partial proto=%x!\n", skb->protocol); |
| 2949 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Dave Graham | 3ed3067 | 2008-10-09 14:29:26 -0700 | [diff] [blame] | 2952 | css = skb_transport_offset(skb); |
| 2953 | |
| 2954 | i = tx_ring->next_to_use; |
| 2955 | buffer_info = &tx_ring->buffer_info[i]; |
| 2956 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
| 2957 | |
| 2958 | context_desc->lower_setup.ip_config = 0; |
| 2959 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 2960 | context_desc->upper_setup.tcp_fields.tucso = |
| 2961 | css + skb->csum_offset; |
| 2962 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2963 | context_desc->tcp_seg_setup.data = 0; |
| 2964 | context_desc->cmd_and_length = cpu_to_le32(cmd_len); |
| 2965 | |
| 2966 | buffer_info->time_stamp = jiffies; |
| 2967 | buffer_info->next_to_watch = i; |
| 2968 | |
| 2969 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2970 | tx_ring->next_to_use = i; |
| 2971 | |
| 2972 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | #define E1000_MAX_TXD_PWR 12 |
| 2976 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2977 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 2978 | static int e1000_tx_map(struct e1000_adapter *adapter, |
| 2979 | struct e1000_tx_ring *tx_ring, |
| 2980 | struct sk_buff *skb, unsigned int first, |
| 2981 | unsigned int max_per_txd, unsigned int nr_frags, |
| 2982 | unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 2984 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2985 | struct e1000_buffer *buffer_info; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2986 | unsigned int len = skb_headlen(skb); |
| 2987 | unsigned int offset, size, count = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | unsigned int f; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2989 | dma_addr_t *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | |
| 2991 | i = tx_ring->next_to_use; |
| 2992 | |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2993 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 2994 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2995 | return 0; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2996 | } |
| 2997 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 2998 | map = skb_shinfo(skb)->dma_maps; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 2999 | offset = 0; |
| 3000 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3001 | while (len) { |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3002 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | size = min(len, max_per_txd); |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3004 | /* Workaround for Controller erratum -- |
| 3005 | * descriptor for non-tso packet in a linear SKB that follows a |
| 3006 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3007 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3008 | if (!skb->data_len && tx_ring->last_tx_tso && |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3009 | !skb_is_gso(skb)) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3010 | tx_ring->last_tx_tso = 0; |
| 3011 | size -= 4; |
| 3012 | } |
| 3013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | /* Workaround for premature desc write-backs |
| 3015 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3016 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | size -= 4; |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3018 | /* work-around for errata 10 and it applies |
| 3019 | * to all controllers in PCI-X mode |
| 3020 | * The fix is to make sure that the first descriptor of a |
| 3021 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 3022 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3023 | if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3024 | (size > 2015) && count == 0)) |
| 3025 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 3028 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3029 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 3031 | size > 4)) |
| 3032 | size -= 4; |
| 3033 | |
| 3034 | buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3035 | buffer_info->dma = skb_shinfo(skb)->dma_head + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3037 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | |
| 3039 | len -= size; |
| 3040 | offset += size; |
| 3041 | count++; |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3042 | if (len) { |
| 3043 | i++; |
| 3044 | if (unlikely(i == tx_ring->count)) |
| 3045 | i = 0; |
| 3046 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3049 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | struct skb_frag_struct *frag; |
| 3051 | |
| 3052 | frag = &skb_shinfo(skb)->frags[f]; |
| 3053 | len = frag->size; |
Jesse Brandeburg | d20b606 | 2009-03-02 16:03:21 -0800 | [diff] [blame] | 3054 | offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3056 | while (len) { |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3057 | i++; |
| 3058 | if (unlikely(i == tx_ring->count)) |
| 3059 | i = 0; |
| 3060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | buffer_info = &tx_ring->buffer_info[i]; |
| 3062 | size = min(len, max_per_txd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | /* Workaround for premature desc write-backs |
| 3064 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3065 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | size -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | /* Workaround for potential 82544 hang in PCI-X. |
| 3068 | * Avoid terminating buffers within evenly-aligned |
| 3069 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3070 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 3072 | size > 4)) |
| 3073 | size -= 4; |
| 3074 | |
| 3075 | buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3076 | buffer_info->dma = map[f] + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | buffer_info->time_stamp = jiffies; |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3078 | buffer_info->next_to_watch = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | |
| 3080 | len -= size; |
| 3081 | offset += size; |
| 3082 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | tx_ring->buffer_info[i].skb = skb; |
| 3087 | tx_ring->buffer_info[first].next_to_watch = i; |
| 3088 | |
| 3089 | return count; |
| 3090 | } |
| 3091 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3092 | static void e1000_tx_queue(struct e1000_adapter *adapter, |
| 3093 | struct e1000_tx_ring *tx_ring, int tx_flags, |
| 3094 | int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3096 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | struct e1000_tx_desc *tx_desc = NULL; |
| 3098 | struct e1000_buffer *buffer_info; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3099 | u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | unsigned int i; |
| 3101 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3102 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 3104 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3105 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3106 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3107 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3108 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3111 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 3113 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 3114 | } |
| 3115 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3116 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | txd_lower |= E1000_TXD_CMD_VLE; |
| 3118 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 3119 | } |
| 3120 | |
| 3121 | i = tx_ring->next_to_use; |
| 3122 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3123 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | buffer_info = &tx_ring->buffer_info[i]; |
| 3125 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3126 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3127 | tx_desc->lower.data = |
| 3128 | cpu_to_le32(txd_lower | buffer_info->length); |
| 3129 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3130 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 3134 | |
| 3135 | /* Force memory writes to complete before letting h/w |
| 3136 | * know there are new descriptors to fetch. (Only |
| 3137 | * applicable for weak-ordered memory model archs, |
| 3138 | * such as IA-64). */ |
| 3139 | wmb(); |
| 3140 | |
| 3141 | tx_ring->next_to_use = i; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3142 | writel(i, hw->hw_addr + tx_ring->tdt); |
Jesse Brandeburg | 2ce9047 | 2006-11-01 08:47:42 -0800 | [diff] [blame] | 3143 | /* we need this if more than one processor can write to our tail |
| 3144 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3145 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 3150 | * The workaround is to avoid queuing a large packet that would span |
| 3151 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 3152 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 3153 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 3154 | * to the beginning of the Tx FIFO. |
| 3155 | **/ |
| 3156 | |
| 3157 | #define E1000_FIFO_HDR 0x10 |
| 3158 | #define E1000_82547_PAD_LEN 0x3E0 |
| 3159 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3160 | static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 3161 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3163 | u32 fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 3164 | u32 skb_fifo_len = skb->len + E1000_FIFO_HDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | |
Milind Arun Choudhary | 9099cfb | 2007-04-27 13:55:29 -0700 | [diff] [blame] | 3166 | skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3168 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | goto no_fifo_stall_required; |
| 3170 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3171 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | return 1; |
| 3173 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3174 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 3176 | return 1; |
| 3177 | } |
| 3178 | |
| 3179 | no_fifo_stall_required: |
| 3180 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3181 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 3183 | return 0; |
| 3184 | } |
| 3185 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3186 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3187 | static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter, |
| 3188 | struct sk_buff *skb) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3189 | { |
| 3190 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3191 | u16 length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3192 | if (vlan_tx_tag_present(skb)) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3193 | if (!((vlan_tx_tag_get(skb) == hw->mng_cookie.vlan_id) && |
| 3194 | ( hw->mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3195 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 3196 | return 0; |
| 3197 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 3198 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Joe Perches | e982f17 | 2008-07-11 15:17:18 -0700 | [diff] [blame] | 3199 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3200 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 3201 | const struct iphdr *ip = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3202 | (struct iphdr *)((u8 *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3203 | if (IPPROTO_UDP == ip->protocol) { |
| 3204 | struct udphdr *udp = |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3205 | (struct udphdr *)((u8 *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3206 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3207 | if (ntohs(udp->dest) == 67) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3208 | offset = (u8 *)udp + 8 - skb->data; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3209 | length = skb->len - offset; |
| 3210 | |
| 3211 | return e1000_mng_write_dhcp_info(hw, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3212 | (u8 *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3213 | length); |
| 3214 | } |
| 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | return 0; |
| 3219 | } |
| 3220 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3221 | static int __e1000_maybe_stop_tx(struct net_device *netdev, int size) |
| 3222 | { |
| 3223 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3224 | struct e1000_tx_ring *tx_ring = adapter->tx_ring; |
| 3225 | |
| 3226 | netif_stop_queue(netdev); |
| 3227 | /* Herbert's original patch had: |
| 3228 | * smp_mb__after_netif_stop_queue(); |
| 3229 | * but since that doesn't exist yet, just open code it. */ |
| 3230 | smp_mb(); |
| 3231 | |
| 3232 | /* We need to check again in a case another CPU has just |
| 3233 | * made room available. */ |
| 3234 | if (likely(E1000_DESC_UNUSED(tx_ring) < size)) |
| 3235 | return -EBUSY; |
| 3236 | |
| 3237 | /* A reprieve! */ |
| 3238 | netif_start_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3239 | ++adapter->restart_queue; |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3240 | return 0; |
| 3241 | } |
| 3242 | |
| 3243 | static int e1000_maybe_stop_tx(struct net_device *netdev, |
| 3244 | struct e1000_tx_ring *tx_ring, int size) |
| 3245 | { |
| 3246 | if (likely(E1000_DESC_UNUSED(tx_ring) >= size)) |
| 3247 | return 0; |
| 3248 | return __e1000_maybe_stop_tx(netdev, size); |
| 3249 | } |
| 3250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3252 | 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] | 3253 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3254 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3255 | struct e1000_hw *hw = &adapter->hw; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3256 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 3258 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 3259 | unsigned int tx_flags = 0; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3260 | unsigned int len = skb->len - skb->data_len; |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3261 | unsigned int nr_frags; |
| 3262 | unsigned int mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | int count = 0; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3264 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | unsigned int f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3267 | /* This goes back to the question of how to logically map a tx queue |
| 3268 | * to a flow. Right now, performance is impacted slightly negatively |
| 3269 | * if using multiple tx queues. If the stack breaks away from a |
| 3270 | * single qdisc implementation, we can look at this again. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3271 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 3272 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3273 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | dev_kfree_skb_any(skb); |
| 3275 | return NETDEV_TX_OK; |
| 3276 | } |
| 3277 | |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3278 | /* 82571 and newer doesn't need the workaround that limited descriptor |
| 3279 | * length to 4kB */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3280 | if (hw->mac_type >= e1000_82571) |
Jesse Brandeburg | 032fe6e | 2006-10-24 14:46:04 -0700 | [diff] [blame] | 3281 | max_per_txd = 8192; |
| 3282 | |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 3283 | mss = skb_shinfo(skb)->gso_size; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 3284 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | * make sure there is enough room in the FIFO before |
| 3286 | * initiating the DMA for each buffer. The calc is: |
| 3287 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 3288 | * overrun the FIFO, adjust the max buffer len if mss |
| 3289 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3290 | if (mss) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3291 | u8 hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | max_per_txd = min(mss << 2, max_per_txd); |
| 3293 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3294 | |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3295 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
| 3296 | * points to just header, pull a few bytes of payload from |
| 3297 | * frags into skb->data */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame] | 3298 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Krishna Kumar | 6d1e3aa | 2007-10-05 14:15:16 -0700 | [diff] [blame] | 3299 | if (skb->data_len && hdr_len == len) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3300 | switch (hw->mac_type) { |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3301 | unsigned int pull_size; |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3302 | case e1000_82544: |
| 3303 | /* Make sure we have room to chop off 4 bytes, |
| 3304 | * and that the end alignment will work out to |
| 3305 | * this hardware's requirements |
| 3306 | * NOTE: this is a TSO only workaround |
| 3307 | * if end byte alignment not correct move us |
| 3308 | * into the next dword */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3309 | if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4) |
Herbert Xu | 683a2aa | 2006-12-16 12:04:33 +1100 | [diff] [blame] | 3310 | break; |
| 3311 | /* fall through */ |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3312 | case e1000_82571: |
| 3313 | case e1000_82572: |
| 3314 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3315 | case e1000_ich8lan: |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3316 | pull_size = min((unsigned int)4, skb->data_len); |
| 3317 | if (!__pskb_pull_tail(skb, pull_size)) { |
Auke Kok | a5eafce | 2006-06-27 09:06:49 -0700 | [diff] [blame] | 3318 | DPRINTK(DRV, ERR, |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3319 | "__pskb_pull_tail failed.\n"); |
| 3320 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc7 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 3321 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 3322 | } |
| 3323 | len = skb->len - skb->data_len; |
| 3324 | break; |
| 3325 | default: |
| 3326 | /* do nothing */ |
| 3327 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 3328 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 3332 | /* reserve a descriptor for the offload context */ |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 3333 | if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3335 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3336 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3337 | /* Controller Erratum workaround */ |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 3338 | 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] | 3339 | count++; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 3342 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3343 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | count++; |
| 3345 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3346 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3347 | * in PCI-X mode, so add one more descriptor to the count |
| 3348 | */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3349 | if (unlikely((hw->bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 3350 | (len > 2015))) |
| 3351 | count++; |
| 3352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3354 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 3356 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3357 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | count += nr_frags; |
| 3359 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 3360 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3361 | if (hw->tx_pkt_filtering && |
| 3362 | (hw->mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3363 | e1000_transfer_dhcp_info(adapter, skb); |
| 3364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3365 | /* need: count + 2 desc gap to keep tail from touching |
| 3366 | * head, otherwise try next time */ |
Alexander Duyck | 8017943 | 2009-01-21 14:42:47 -0800 | [diff] [blame] | 3367 | if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3370 | if (unlikely(hw->mac_type == e1000_82547)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3371 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | netif_stop_queue(netdev); |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3373 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | return NETDEV_TX_BUSY; |
| 3375 | } |
| 3376 | } |
| 3377 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3378 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 3380 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 3381 | } |
| 3382 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3383 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3384 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3385 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | if (tso < 0) { |
| 3387 | dev_kfree_skb_any(skb); |
| 3388 | return NETDEV_TX_OK; |
| 3389 | } |
| 3390 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3391 | if (likely(tso)) { |
| 3392 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3394 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 3396 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3397 | /* 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] | 3398 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3399 | * no longer assume, we must. */ |
Alexey Dobriyan | 6082823 | 2006-05-23 14:52:21 -0700 | [diff] [blame] | 3400 | if (likely(skb->protocol == htons(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3401 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 3402 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3403 | count = e1000_tx_map(adapter, tx_ring, skb, first, max_per_txd, |
| 3404 | nr_frags, mss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3406 | if (count) { |
| 3407 | e1000_tx_queue(adapter, tx_ring, tx_flags, count); |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3408 | /* Make sure there is space in the ring for the next send. */ |
| 3409 | e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | |
Alexander Duyck | 37e73df | 2009-03-25 21:58:45 +0000 | [diff] [blame] | 3411 | } else { |
| 3412 | dev_kfree_skb_any(skb); |
| 3413 | tx_ring->buffer_info[first].time_stamp = 0; |
| 3414 | tx_ring->next_to_use = first; |
| 3415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | return NETDEV_TX_OK; |
| 3418 | } |
| 3419 | |
| 3420 | /** |
| 3421 | * e1000_tx_timeout - Respond to a Tx Hang |
| 3422 | * @netdev: network interface device structure |
| 3423 | **/ |
| 3424 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3425 | static void e1000_tx_timeout(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3427 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | |
| 3429 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3430 | adapter->tx_timeout_count++; |
| 3431 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3434 | static void e1000_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3436 | struct e1000_adapter *adapter = |
| 3437 | container_of(work, struct e1000_adapter, reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3439 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | /** |
| 3443 | * e1000_get_stats - Get System Network Statistics |
| 3444 | * @netdev: network interface device structure |
| 3445 | * |
| 3446 | * Returns the address of the device statistics structure. |
| 3447 | * The statistics are actually updated from the timer callback. |
| 3448 | **/ |
| 3449 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3450 | static struct net_device_stats *e1000_get_stats(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3452 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3454 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | return &adapter->net_stats; |
| 3456 | } |
| 3457 | |
| 3458 | /** |
| 3459 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 3460 | * @netdev: network interface device structure |
| 3461 | * @new_mtu: new value for maximum frame size |
| 3462 | * |
| 3463 | * Returns 0 on success, negative on failure |
| 3464 | **/ |
| 3465 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3466 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3468 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3469 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3471 | u16 eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3473 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 3474 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3475 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 3476 | return -EINVAL; |
| 3477 | } |
| 3478 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3479 | /* Adapter-specific max frame size limits. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3480 | switch (hw->mac_type) { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3481 | case e1000_undefined ... e1000_82542_rev2_1: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3482 | case e1000_ich8lan: |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 3483 | if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) { |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3484 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3485 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3486 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3487 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3488 | case e1000_82573: |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3489 | /* Jumbo Frames not supported if: |
| 3490 | * - this is not an 82573L device |
| 3491 | * - ASPM is enabled in any way (0x1A bits 3:2) */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3492 | e1000_read_eeprom(hw, EEPROM_INIT_3GIO_3, 1, |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3493 | &eeprom_data); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3494 | if ((hw->device_id != E1000_DEV_ID_82573L) || |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3495 | (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) { |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 3496 | if (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) { |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3497 | DPRINTK(PROBE, ERR, |
| 3498 | "Jumbo Frames not supported.\n"); |
| 3499 | return -EINVAL; |
| 3500 | } |
| 3501 | break; |
| 3502 | } |
Bruce Allan | 249d71d | 2006-09-27 12:53:45 -0700 | [diff] [blame] | 3503 | /* ERT will be enabled later to enable wire speed receives */ |
| 3504 | |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 3505 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3506 | case e1000_82571: |
| 3507 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3508 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3509 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3510 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3511 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3512 | return -EINVAL; |
| 3513 | } |
| 3514 | break; |
| 3515 | default: |
| 3516 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3517 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 3520 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3521 | * 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] | 3522 | * larger slab size. |
| 3523 | * i.e. RXBUFFER_2048 --> size-4096 slab |
| 3524 | * however with the new *_jumbo_rx* routines, jumbo receives will use |
| 3525 | * fragmented skbs */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3526 | |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3527 | if (max_frame <= E1000_RXBUFFER_256) |
| 3528 | adapter->rx_buffer_len = E1000_RXBUFFER_256; |
| 3529 | else if (max_frame <= E1000_RXBUFFER_512) |
| 3530 | adapter->rx_buffer_len = E1000_RXBUFFER_512; |
| 3531 | else if (max_frame <= E1000_RXBUFFER_1024) |
| 3532 | adapter->rx_buffer_len = E1000_RXBUFFER_1024; |
| 3533 | else if (max_frame <= E1000_RXBUFFER_2048) |
| 3534 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3535 | else |
| 3536 | #if (PAGE_SIZE >= E1000_RXBUFFER_16384) |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3537 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 3538 | #elif (PAGE_SIZE >= E1000_RXBUFFER_4096) |
| 3539 | adapter->rx_buffer_len = PAGE_SIZE; |
| 3540 | #endif |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3541 | |
| 3542 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3543 | if (!hw->tbi_compatibility_on && |
Jesse Brandeburg | b7cb8c2 | 2009-07-06 10:45:01 +0000 | [diff] [blame^] | 3544 | ((max_frame == (ETH_FRAME_LEN + ETH_FCS_LEN)) || |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 3545 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))) |
| 3546 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3547 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3548 | netdev->mtu = new_mtu; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3549 | hw->max_frame_size = max_frame; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3550 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 3551 | if (netif_running(netdev)) |
| 3552 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | return 0; |
| 3555 | } |
| 3556 | |
| 3557 | /** |
| 3558 | * e1000_update_stats - Update the board statistics counters |
| 3559 | * @adapter: board private structure |
| 3560 | **/ |
| 3561 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3562 | void e1000_update_stats(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | { |
| 3564 | struct e1000_hw *hw = &adapter->hw; |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3565 | struct pci_dev *pdev = adapter->pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3567 | u16 phy_tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | |
| 3569 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3570 | |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3571 | /* |
| 3572 | * Prevent stats update while adapter is being reset, or if the pci |
| 3573 | * connection is down. |
| 3574 | */ |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3575 | if (adapter->link_speed == 0) |
| 3576 | return; |
Linas Vepstas | 81b1955 | 2006-12-12 18:29:15 -0600 | [diff] [blame] | 3577 | if (pci_channel_offline(pdev)) |
Linas Vepstas | 282f33c | 2006-06-08 22:19:44 -0700 | [diff] [blame] | 3578 | return; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 3579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3581 | |
Masatake YAMATO | 828d055 | 2007-10-20 03:06:37 +0200 | [diff] [blame] | 3582 | /* these counters are modified from e1000_tbi_adjust_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | * called from the interrupt context, so they must only |
| 3584 | * be written while holding adapter->stats_lock |
| 3585 | */ |
| 3586 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3587 | adapter->stats.crcerrs += er32(CRCERRS); |
| 3588 | adapter->stats.gprc += er32(GPRC); |
| 3589 | adapter->stats.gorcl += er32(GORCL); |
| 3590 | adapter->stats.gorch += er32(GORCH); |
| 3591 | adapter->stats.bprc += er32(BPRC); |
| 3592 | adapter->stats.mprc += er32(MPRC); |
| 3593 | adapter->stats.roc += er32(ROC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3594 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3595 | if (hw->mac_type != e1000_ich8lan) { |
| 3596 | adapter->stats.prc64 += er32(PRC64); |
| 3597 | adapter->stats.prc127 += er32(PRC127); |
| 3598 | adapter->stats.prc255 += er32(PRC255); |
| 3599 | adapter->stats.prc511 += er32(PRC511); |
| 3600 | adapter->stats.prc1023 += er32(PRC1023); |
| 3601 | adapter->stats.prc1522 += er32(PRC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3604 | adapter->stats.symerrs += er32(SYMERRS); |
| 3605 | adapter->stats.mpc += er32(MPC); |
| 3606 | adapter->stats.scc += er32(SCC); |
| 3607 | adapter->stats.ecol += er32(ECOL); |
| 3608 | adapter->stats.mcc += er32(MCC); |
| 3609 | adapter->stats.latecol += er32(LATECOL); |
| 3610 | adapter->stats.dc += er32(DC); |
| 3611 | adapter->stats.sec += er32(SEC); |
| 3612 | adapter->stats.rlec += er32(RLEC); |
| 3613 | adapter->stats.xonrxc += er32(XONRXC); |
| 3614 | adapter->stats.xontxc += er32(XONTXC); |
| 3615 | adapter->stats.xoffrxc += er32(XOFFRXC); |
| 3616 | adapter->stats.xofftxc += er32(XOFFTXC); |
| 3617 | adapter->stats.fcruc += er32(FCRUC); |
| 3618 | adapter->stats.gptc += er32(GPTC); |
| 3619 | adapter->stats.gotcl += er32(GOTCL); |
| 3620 | adapter->stats.gotch += er32(GOTCH); |
| 3621 | adapter->stats.rnbc += er32(RNBC); |
| 3622 | adapter->stats.ruc += er32(RUC); |
| 3623 | adapter->stats.rfc += er32(RFC); |
| 3624 | adapter->stats.rjc += er32(RJC); |
| 3625 | adapter->stats.torl += er32(TORL); |
| 3626 | adapter->stats.torh += er32(TORH); |
| 3627 | adapter->stats.totl += er32(TOTL); |
| 3628 | adapter->stats.toth += er32(TOTH); |
| 3629 | adapter->stats.tpr += er32(TPR); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3630 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3631 | if (hw->mac_type != e1000_ich8lan) { |
| 3632 | adapter->stats.ptc64 += er32(PTC64); |
| 3633 | adapter->stats.ptc127 += er32(PTC127); |
| 3634 | adapter->stats.ptc255 += er32(PTC255); |
| 3635 | adapter->stats.ptc511 += er32(PTC511); |
| 3636 | adapter->stats.ptc1023 += er32(PTC1023); |
| 3637 | adapter->stats.ptc1522 += er32(PTC1522); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3640 | adapter->stats.mptc += er32(MPTC); |
| 3641 | adapter->stats.bptc += er32(BPTC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | |
| 3643 | /* used for adaptive IFS */ |
| 3644 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3645 | hw->tx_packet_delta = er32(TPT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | adapter->stats.tpt += hw->tx_packet_delta; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3647 | hw->collision_delta = er32(COLC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | adapter->stats.colc += hw->collision_delta; |
| 3649 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3650 | if (hw->mac_type >= e1000_82543) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3651 | adapter->stats.algnerrc += er32(ALGNERRC); |
| 3652 | adapter->stats.rxerrc += er32(RXERRC); |
| 3653 | adapter->stats.tncrs += er32(TNCRS); |
| 3654 | adapter->stats.cexterr += er32(CEXTERR); |
| 3655 | adapter->stats.tsctc += er32(TSCTC); |
| 3656 | adapter->stats.tsctfc += er32(TSCTFC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3658 | if (hw->mac_type > e1000_82547_rev_2) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3659 | adapter->stats.iac += er32(IAC); |
| 3660 | adapter->stats.icrxoc += er32(ICRXOC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3661 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3662 | if (hw->mac_type != e1000_ich8lan) { |
| 3663 | adapter->stats.icrxptc += er32(ICRXPTC); |
| 3664 | adapter->stats.icrxatc += er32(ICRXATC); |
| 3665 | adapter->stats.ictxptc += er32(ICTXPTC); |
| 3666 | adapter->stats.ictxatc += er32(ICTXATC); |
| 3667 | adapter->stats.ictxqec += er32(ICTXQEC); |
| 3668 | adapter->stats.ictxqmtc += er32(ICTXQMTC); |
| 3669 | adapter->stats.icrxdmtc += er32(ICRXDMTC); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 3670 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | |
| 3673 | /* Fill out the OS statistics structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3675 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3676 | |
| 3677 | /* Rx Errors */ |
| 3678 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3679 | /* RLEC on some newer hardware can be incorrect so build |
| 3680 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3682 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3683 | adapter->stats.ruc + adapter->stats.roc + |
| 3684 | adapter->stats.cexterr; |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3685 | adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc; |
| 3686 | adapter->net_stats.rx_length_errors = adapter->stats.rlerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3688 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3690 | |
| 3691 | /* Tx Errors */ |
Mitch Williams | 4955985 | 2006-09-27 12:53:37 -0700 | [diff] [blame] | 3692 | adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol; |
| 3693 | adapter->net_stats.tx_errors = adapter->stats.txerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3695 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3696 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3697 | if (hw->bad_tx_carr_stats_fd && |
Jeff Garzik | 167fb28 | 2006-12-15 10:41:15 -0500 | [diff] [blame] | 3698 | adapter->link_duplex == FULL_DUPLEX) { |
| 3699 | adapter->net_stats.tx_carrier_errors = 0; |
| 3700 | adapter->stats.tncrs = 0; |
| 3701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | |
| 3703 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3704 | |
| 3705 | /* Phy Stats */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3706 | if (hw->media_type == e1000_media_type_copper) { |
| 3707 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3709 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3710 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3711 | } |
| 3712 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3713 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | (hw->phy_type == e1000_phy_m88) && |
| 3715 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3716 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3717 | } |
| 3718 | |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3719 | /* Management Stats */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3720 | if (hw->has_smbus) { |
| 3721 | adapter->stats.mgptc += er32(MGTPTC); |
| 3722 | adapter->stats.mgprc += er32(MGTPRC); |
| 3723 | adapter->stats.mgpdc += er32(MGTPDC); |
Jeff Garzik | 15e376b | 2006-12-15 11:16:33 -0500 | [diff] [blame] | 3724 | } |
| 3725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3727 | } |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3728 | |
| 3729 | /** |
| 3730 | * e1000_intr_msi - Interrupt Handler |
| 3731 | * @irq: interrupt number |
| 3732 | * @data: pointer to a network interface device structure |
| 3733 | **/ |
| 3734 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3735 | static irqreturn_t e1000_intr_msi(int irq, void *data) |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3736 | { |
| 3737 | struct net_device *netdev = data; |
| 3738 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 3739 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3740 | u32 icr = er32(ICR); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3741 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3742 | /* in NAPI mode read ICR disables interrupts using IAM */ |
| 3743 | |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3744 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 3745 | hw->get_link_status = 1; |
| 3746 | /* 80003ES2LAN workaround-- For packet buffer work-around on |
| 3747 | * link down event; disable receives here in the ISR and reset |
| 3748 | * adapter in watchdog */ |
| 3749 | if (netif_carrier_ok(netdev) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3750 | (hw->mac_type == e1000_80003es2lan)) { |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3751 | /* disable receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3752 | u32 rctl = er32(RCTL); |
| 3753 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3754 | } |
Jesse Brandeburg | b5fc8f0 | 2007-01-18 09:25:21 -0800 | [diff] [blame] | 3755 | /* guard against interrupt when we're going down */ |
| 3756 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3757 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3758 | } |
| 3759 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3760 | if (likely(napi_schedule_prep(&adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3761 | adapter->total_tx_bytes = 0; |
| 3762 | adapter->total_tx_packets = 0; |
| 3763 | adapter->total_rx_bytes = 0; |
| 3764 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3765 | __napi_schedule(&adapter->napi); |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3766 | } else |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3767 | e1000_irq_enable(adapter); |
Jesse Brandeburg | 9ac9828 | 2006-11-01 08:48:10 -0800 | [diff] [blame] | 3768 | |
| 3769 | return IRQ_HANDLED; |
| 3770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | |
| 3772 | /** |
| 3773 | * e1000_intr - Interrupt Handler |
| 3774 | * @irq: interrupt number |
| 3775 | * @data: pointer to a network interface device structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | **/ |
| 3777 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3778 | static irqreturn_t e1000_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | { |
| 3780 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3781 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3783 | u32 rctl, icr = er32(ICR); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 3784 | |
Jesse Brandeburg | e151a60 | 2009-05-04 11:19:42 +0000 | [diff] [blame] | 3785 | if (unlikely((!icr) || test_bit(__E1000_DOWN, &adapter->flags))) |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3786 | return IRQ_NONE; /* Not our interrupt */ |
| 3787 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3788 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 3789 | * not set, then the adapter didn't send an interrupt */ |
| 3790 | if (unlikely(hw->mac_type >= e1000_82571 && |
| 3791 | !(icr & E1000_ICR_INT_ASSERTED))) |
| 3792 | return IRQ_NONE; |
| 3793 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 3794 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
| 3795 | * need for the IMC write */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3797 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3799 | /* 80003ES2LAN workaround-- |
| 3800 | * For packet buffer work-around on link down event; |
| 3801 | * disable receives here in the ISR and |
| 3802 | * reset adapter in watchdog |
| 3803 | */ |
| 3804 | if (netif_carrier_ok(netdev) && |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3805 | (hw->mac_type == e1000_80003es2lan)) { |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3806 | /* disable receives */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3807 | rctl = er32(RCTL); |
| 3808 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3809 | } |
Auke Kok | 1314bbf | 2006-09-27 12:54:02 -0700 | [diff] [blame] | 3810 | /* guard against interrupt when we're going down */ |
| 3811 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3812 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3815 | if (unlikely(hw->mac_type < e1000_82571)) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3816 | /* disable interrupts, without the synchronize_irq bit */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3817 | ew32(IMC, ~0); |
| 3818 | E1000_WRITE_FLUSH(); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3819 | } |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3820 | if (likely(napi_schedule_prep(&adapter->napi))) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3821 | adapter->total_tx_bytes = 0; |
| 3822 | adapter->total_tx_packets = 0; |
| 3823 | adapter->total_rx_bytes = 0; |
| 3824 | adapter->total_rx_packets = 0; |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3825 | __napi_schedule(&adapter->napi); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3826 | } else { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 3827 | /* this really should not happen! if it does it is basically a |
| 3828 | * bug, but not a hard error, so enable ints and continue */ |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3829 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3830 | e1000_irq_enable(adapter); |
| 3831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | return IRQ_HANDLED; |
| 3834 | } |
| 3835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | /** |
| 3837 | * e1000_clean - NAPI Rx polling callback |
| 3838 | * @adapter: board private structure |
| 3839 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3840 | static int e1000_clean(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3842 | struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi); |
| 3843 | struct net_device *poll_dev = adapter->netdev; |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3844 | int tx_cleaned = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3845 | |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 3846 | adapter = netdev_priv(poll_dev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3847 | |
Alexander Duyck | 8017943 | 2009-01-21 14:42:47 -0800 | [diff] [blame] | 3848 | tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[0]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3849 | |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 3850 | adapter->clean_rx(adapter, &adapter->rx_ring[0], |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3851 | &work_done, budget); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3852 | |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3853 | if (!tx_cleaned) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3854 | work_done = budget; |
| 3855 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3856 | /* If budget not fully consumed, exit the polling mode */ |
| 3857 | if (work_done < budget) { |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3858 | if (likely(adapter->itr_setting & 3)) |
| 3859 | e1000_set_itr(adapter); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3860 | napi_complete(napi); |
Jesse Brandeburg | a6c4232 | 2009-03-25 21:59:22 +0000 | [diff] [blame] | 3861 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 3862 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3865 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | /** |
| 3869 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3870 | * @adapter: board private structure |
| 3871 | **/ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3872 | static bool e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3873 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3875 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | struct net_device *netdev = adapter->netdev; |
| 3877 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3878 | struct e1000_buffer *buffer_info; |
| 3879 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3880 | unsigned int count = 0; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3881 | unsigned int total_tx_bytes=0, total_tx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | |
| 3883 | i = tx_ring->next_to_clean; |
| 3884 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3885 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3886 | |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3887 | while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 3888 | (count < tx_ring->count)) { |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3889 | bool cleaned = false; |
| 3890 | for ( ; !cleaned; count++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3892 | buffer_info = &tx_ring->buffer_info[i]; |
| 3893 | cleaned = (i == eop); |
| 3894 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3895 | if (cleaned) { |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3896 | struct sk_buff *skb = buffer_info->skb; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3897 | unsigned int segs, bytecount; |
| 3898 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 3899 | /* multiply data chunks by size of headers */ |
| 3900 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 3901 | skb->len; |
Jesse Brandeburg | 2b65326 | 2006-12-15 10:30:44 +0100 | [diff] [blame] | 3902 | total_tx_packets += segs; |
Jesse Brandeburg | 7753b17 | 2007-01-18 09:25:31 -0800 | [diff] [blame] | 3903 | total_tx_bytes += bytecount; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3904 | } |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3905 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jesse Brandeburg | a9ebadd | 2006-11-01 08:47:53 -0800 | [diff] [blame] | 3906 | tx_desc->upper.data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3908 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3912 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3913 | } |
| 3914 | |
| 3915 | tx_ring->next_to_clean = i; |
| 3916 | |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3917 | #define TX_WAKE_THRESHOLD 32 |
Jesse Brandeburg | 843f426 | 2009-04-16 16:59:47 +0000 | [diff] [blame] | 3918 | if (unlikely(count && netif_carrier_ok(netdev) && |
Jesse Brandeburg | 65c7973 | 2006-09-27 12:53:48 -0700 | [diff] [blame] | 3919 | E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) { |
| 3920 | /* Make sure that anybody stopping the queue after this |
| 3921 | * sees the new next_to_clean. |
| 3922 | */ |
| 3923 | smp_mb(); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3924 | if (netif_queue_stopped(netdev)) { |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3925 | netif_wake_queue(netdev); |
Jesse Brandeburg | fcfb122 | 2006-11-01 08:47:59 -0800 | [diff] [blame] | 3926 | ++adapter->restart_queue; |
| 3927 | } |
Auke Kok | 77b2aad | 2006-04-14 19:05:25 -0700 | [diff] [blame] | 3928 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3929 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3930 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3931 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | * check with the clearing of time_stamp and movement of i */ |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 3933 | adapter->detect_tx_hung = false; |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3934 | if (tx_ring->buffer_info[i].time_stamp && |
| 3935 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 3936 | (adapter->tx_timeout_factor * HZ)) |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3937 | && !(er32(STATUS) & E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3938 | |
| 3939 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 3940 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3941 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3942 | " TDH <%x>\n" |
| 3943 | " TDT <%x>\n" |
| 3944 | " next_to_use <%x>\n" |
| 3945 | " next_to_clean <%x>\n" |
| 3946 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3947 | " time_stamp <%lx>\n" |
| 3948 | " next_to_watch <%x>\n" |
| 3949 | " jiffies <%lx>\n" |
| 3950 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3951 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 3952 | sizeof(struct e1000_tx_ring)), |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3953 | readl(hw->hw_addr + tx_ring->tdh), |
| 3954 | readl(hw->hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3955 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3956 | tx_ring->next_to_clean, |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3957 | tx_ring->buffer_info[i].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3958 | eop, |
| 3959 | jiffies, |
| 3960 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | } |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 3964 | adapter->total_tx_bytes += total_tx_bytes; |
| 3965 | adapter->total_tx_packets += total_tx_packets; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 3966 | adapter->net_stats.tx_bytes += total_tx_bytes; |
| 3967 | adapter->net_stats.tx_packets += total_tx_packets; |
Alexander Duyck | ccfb342 | 2009-03-25 21:59:04 +0000 | [diff] [blame] | 3968 | return (count < tx_ring->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | /** |
| 3972 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3973 | * @adapter: board private structure |
| 3974 | * @status_err: receive descriptor status and error fields |
| 3975 | * @csum: receive descriptor csum field |
| 3976 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | **/ |
| 3978 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 3979 | static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err, |
| 3980 | u32 csum, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3982 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 3983 | u16 status = (u16)status_err; |
| 3984 | u8 errors = (u8)(status_err >> 24); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3985 | skb->ip_summed = CHECKSUM_NONE; |
| 3986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | /* 82543 or newer only */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3988 | if (unlikely(hw->mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3990 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3991 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3992 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3993 | /* let the stack verify checksum errors */ |
| 3994 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | return; |
| 3996 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3997 | /* TCP/UDP Checksum has not been calculated */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 3998 | if (hw->mac_type <= e1000_82547_rev_2) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3999 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4000 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4002 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4003 | return; |
| 4004 | } |
| 4005 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4006 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | /* TCP checksum is good */ |
| 4008 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4009 | } else if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4010 | /* IP fragment with UDP payload */ |
| 4011 | /* Hardware complements the payload checksum, so we undo it |
| 4012 | * and then put the value in host order for further stack use. |
| 4013 | */ |
Al Viro | 3e18826 | 2007-12-11 19:49:39 +0000 | [diff] [blame] | 4014 | __sum16 sum = (__force __sum16)htons(csum); |
| 4015 | skb->csum = csum_unfold(~sum); |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 4016 | skb->ip_summed = CHECKSUM_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4018 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | /** |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4022 | * e1000_consume_page - helper function |
| 4023 | **/ |
| 4024 | static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb, |
| 4025 | u16 length) |
| 4026 | { |
| 4027 | bi->page = NULL; |
| 4028 | skb->len += length; |
| 4029 | skb->data_len += length; |
| 4030 | skb->truesize += length; |
| 4031 | } |
| 4032 | |
| 4033 | /** |
| 4034 | * e1000_receive_skb - helper function to handle rx indications |
| 4035 | * @adapter: board private structure |
| 4036 | * @status: descriptor status field as written by hardware |
| 4037 | * @vlan: descriptor vlan field as written by hardware (no le/be conversion) |
| 4038 | * @skb: pointer to sk_buff to be indicated to stack |
| 4039 | */ |
| 4040 | static void e1000_receive_skb(struct e1000_adapter *adapter, u8 status, |
| 4041 | __le16 vlan, struct sk_buff *skb) |
| 4042 | { |
| 4043 | if (unlikely(adapter->vlgrp && (status & E1000_RXD_STAT_VP))) { |
| 4044 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
| 4045 | le16_to_cpu(vlan) & |
| 4046 | E1000_RXD_SPC_VLAN_MASK); |
| 4047 | } else { |
| 4048 | netif_receive_skb(skb); |
| 4049 | } |
| 4050 | } |
| 4051 | |
| 4052 | /** |
| 4053 | * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy |
| 4054 | * @adapter: board private structure |
| 4055 | * @rx_ring: ring to clean |
| 4056 | * @work_done: amount of napi work completed this call |
| 4057 | * @work_to_do: max amount of work allowed for this call to do |
| 4058 | * |
| 4059 | * the return value indicates whether actual cleaning was done, there |
| 4060 | * is no guarantee that everything was cleaned |
| 4061 | */ |
| 4062 | static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter, |
| 4063 | struct e1000_rx_ring *rx_ring, |
| 4064 | int *work_done, int work_to_do) |
| 4065 | { |
| 4066 | struct e1000_hw *hw = &adapter->hw; |
| 4067 | struct net_device *netdev = adapter->netdev; |
| 4068 | struct pci_dev *pdev = adapter->pdev; |
| 4069 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4070 | struct e1000_buffer *buffer_info, *next_buffer; |
| 4071 | unsigned long irq_flags; |
| 4072 | u32 length; |
| 4073 | unsigned int i; |
| 4074 | int cleaned_count = 0; |
| 4075 | bool cleaned = false; |
| 4076 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
| 4077 | |
| 4078 | i = rx_ring->next_to_clean; |
| 4079 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4080 | buffer_info = &rx_ring->buffer_info[i]; |
| 4081 | |
| 4082 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
| 4083 | struct sk_buff *skb; |
| 4084 | u8 status; |
| 4085 | |
| 4086 | if (*work_done >= work_to_do) |
| 4087 | break; |
| 4088 | (*work_done)++; |
| 4089 | |
| 4090 | status = rx_desc->status; |
| 4091 | skb = buffer_info->skb; |
| 4092 | buffer_info->skb = NULL; |
| 4093 | |
| 4094 | if (++i == rx_ring->count) i = 0; |
| 4095 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
| 4096 | prefetch(next_rxd); |
| 4097 | |
| 4098 | next_buffer = &rx_ring->buffer_info[i]; |
| 4099 | |
| 4100 | cleaned = true; |
| 4101 | cleaned_count++; |
| 4102 | pci_unmap_page(pdev, buffer_info->dma, buffer_info->length, |
| 4103 | PCI_DMA_FROMDEVICE); |
| 4104 | buffer_info->dma = 0; |
| 4105 | |
| 4106 | length = le16_to_cpu(rx_desc->length); |
| 4107 | |
| 4108 | /* errors is only valid for DD + EOP descriptors */ |
| 4109 | if (unlikely((status & E1000_RXD_STAT_EOP) && |
| 4110 | (rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK))) { |
| 4111 | u8 last_byte = *(skb->data + length - 1); |
| 4112 | if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
| 4113 | last_byte)) { |
| 4114 | spin_lock_irqsave(&adapter->stats_lock, |
| 4115 | irq_flags); |
| 4116 | e1000_tbi_adjust_stats(hw, &adapter->stats, |
| 4117 | length, skb->data); |
| 4118 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4119 | irq_flags); |
| 4120 | length--; |
| 4121 | } else { |
| 4122 | /* recycle both page and skb */ |
| 4123 | buffer_info->skb = skb; |
| 4124 | /* an error means any chain goes out the window |
| 4125 | * too */ |
| 4126 | if (rx_ring->rx_skb_top) |
| 4127 | dev_kfree_skb(rx_ring->rx_skb_top); |
| 4128 | rx_ring->rx_skb_top = NULL; |
| 4129 | goto next_desc; |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | #define rxtop rx_ring->rx_skb_top |
| 4134 | if (!(status & E1000_RXD_STAT_EOP)) { |
| 4135 | /* this descriptor is only the beginning (or middle) */ |
| 4136 | if (!rxtop) { |
| 4137 | /* this is the beginning of a chain */ |
| 4138 | rxtop = skb; |
| 4139 | skb_fill_page_desc(rxtop, 0, buffer_info->page, |
| 4140 | 0, length); |
| 4141 | } else { |
| 4142 | /* this is the middle of a chain */ |
| 4143 | skb_fill_page_desc(rxtop, |
| 4144 | skb_shinfo(rxtop)->nr_frags, |
| 4145 | buffer_info->page, 0, length); |
| 4146 | /* re-use the skb, only consumed the page */ |
| 4147 | buffer_info->skb = skb; |
| 4148 | } |
| 4149 | e1000_consume_page(buffer_info, rxtop, length); |
| 4150 | goto next_desc; |
| 4151 | } else { |
| 4152 | if (rxtop) { |
| 4153 | /* end of the chain */ |
| 4154 | skb_fill_page_desc(rxtop, |
| 4155 | skb_shinfo(rxtop)->nr_frags, |
| 4156 | buffer_info->page, 0, length); |
| 4157 | /* re-use the current skb, we only consumed the |
| 4158 | * page */ |
| 4159 | buffer_info->skb = skb; |
| 4160 | skb = rxtop; |
| 4161 | rxtop = NULL; |
| 4162 | e1000_consume_page(buffer_info, skb, length); |
| 4163 | } else { |
| 4164 | /* no chain, got EOP, this buf is the packet |
| 4165 | * copybreak to save the put_page/alloc_page */ |
| 4166 | if (length <= copybreak && |
| 4167 | skb_tailroom(skb) >= length) { |
| 4168 | u8 *vaddr; |
| 4169 | vaddr = kmap_atomic(buffer_info->page, |
| 4170 | KM_SKB_DATA_SOFTIRQ); |
| 4171 | memcpy(skb_tail_pointer(skb), vaddr, length); |
| 4172 | kunmap_atomic(vaddr, |
| 4173 | KM_SKB_DATA_SOFTIRQ); |
| 4174 | /* re-use the page, so don't erase |
| 4175 | * buffer_info->page */ |
| 4176 | skb_put(skb, length); |
| 4177 | } else { |
| 4178 | skb_fill_page_desc(skb, 0, |
| 4179 | buffer_info->page, 0, |
| 4180 | length); |
| 4181 | e1000_consume_page(buffer_info, skb, |
| 4182 | length); |
| 4183 | } |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | /* Receive Checksum Offload XXX recompute due to CRC strip? */ |
| 4188 | e1000_rx_checksum(adapter, |
| 4189 | (u32)(status) | |
| 4190 | ((u32)(rx_desc->errors) << 24), |
| 4191 | le16_to_cpu(rx_desc->csum), skb); |
| 4192 | |
| 4193 | pskb_trim(skb, skb->len - 4); |
| 4194 | |
| 4195 | /* probably a little skewed due to removing CRC */ |
| 4196 | total_rx_bytes += skb->len; |
| 4197 | total_rx_packets++; |
| 4198 | |
| 4199 | /* eth type trans needs skb->data to point to something */ |
| 4200 | if (!pskb_may_pull(skb, ETH_HLEN)) { |
| 4201 | DPRINTK(DRV, ERR, "pskb_may_pull failed.\n"); |
| 4202 | dev_kfree_skb(skb); |
| 4203 | goto next_desc; |
| 4204 | } |
| 4205 | |
| 4206 | skb->protocol = eth_type_trans(skb, netdev); |
| 4207 | |
| 4208 | e1000_receive_skb(adapter, status, rx_desc->special, skb); |
| 4209 | |
| 4210 | next_desc: |
| 4211 | rx_desc->status = 0; |
| 4212 | |
| 4213 | /* return some buffers to hardware, one at a time is too slow */ |
| 4214 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4215 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4216 | cleaned_count = 0; |
| 4217 | } |
| 4218 | |
| 4219 | /* use prefetched values */ |
| 4220 | rx_desc = next_rxd; |
| 4221 | buffer_info = next_buffer; |
| 4222 | } |
| 4223 | rx_ring->next_to_clean = i; |
| 4224 | |
| 4225 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4226 | if (cleaned_count) |
| 4227 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4228 | |
| 4229 | adapter->total_rx_packets += total_rx_packets; |
| 4230 | adapter->total_rx_bytes += total_rx_bytes; |
| 4231 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4232 | adapter->net_stats.rx_packets += total_rx_packets; |
| 4233 | return cleaned; |
| 4234 | } |
| 4235 | |
| 4236 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4237 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | * @adapter: board private structure |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4239 | * @rx_ring: ring to clean |
| 4240 | * @work_done: amount of napi work completed this call |
| 4241 | * @work_to_do: max amount of work allowed for this call to do |
| 4242 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4243 | static bool e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 4244 | struct e1000_rx_ring *rx_ring, |
| 4245 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4247 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | struct net_device *netdev = adapter->netdev; |
| 4249 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4250 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 4251 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | unsigned long flags; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4253 | u32 length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4255 | int cleaned_count = 0; |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4256 | bool cleaned = false; |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4257 | unsigned int total_rx_bytes=0, total_rx_packets=0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
| 4259 | i = rx_ring->next_to_clean; |
| 4260 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4261 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4263 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Auke Kok | 24f476e | 2006-06-08 09:28:47 -0700 | [diff] [blame] | 4264 | struct sk_buff *skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4265 | u8 status; |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4266 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4267 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | break; |
| 4269 | (*work_done)++; |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4270 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4271 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4272 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4273 | buffer_info->skb = NULL; |
| 4274 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4275 | prefetch(skb->data - NET_IP_ALIGN); |
| 4276 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4277 | if (++i == rx_ring->count) i = 0; |
| 4278 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4279 | prefetch(next_rxd); |
| 4280 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4281 | next_buffer = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4282 | |
Joe Perches | c3033b0 | 2008-03-21 11:06:25 -0700 | [diff] [blame] | 4283 | cleaned = true; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4284 | cleaned_count++; |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4285 | pci_unmap_single(pdev, buffer_info->dma, buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 4287 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | length = le16_to_cpu(rx_desc->length); |
Neil Horman | ea30e11 | 2009-06-02 01:29:58 -0700 | [diff] [blame] | 4290 | /* !EOP means multiple descriptors were used to store a single |
| 4291 | * packet, also make sure the frame isn't just CRC only */ |
| 4292 | if (unlikely(!(status & E1000_RXD_STAT_EOP) || (length <= 4))) { |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 4293 | /* All receives must fit into a single buffer */ |
| 4294 | E1000_DBG("%s: Receive packet consumed multiple" |
| 4295 | " buffers\n", netdev->name); |
Auke Kok | 864c4e4 | 2006-06-27 09:06:53 -0700 | [diff] [blame] | 4296 | /* recycle */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 4297 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | goto next_desc; |
| 4299 | } |
| 4300 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4301 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4302 | u8 last_byte = *(skb->data + length - 1); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4303 | if (TBI_ACCEPT(hw, status, rx_desc->errors, length, |
| 4304 | last_byte)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4306 | e1000_tbi_adjust_stats(hw, &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | length, skb->data); |
| 4308 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 4309 | flags); |
| 4310 | length--; |
| 4311 | } else { |
Auke Kok | 9e2feac | 2006-04-14 19:05:18 -0700 | [diff] [blame] | 4312 | /* recycle */ |
| 4313 | buffer_info->skb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | goto next_desc; |
| 4315 | } |
Auke Kok | 1cb5821 | 2006-04-18 12:31:04 -0700 | [diff] [blame] | 4316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | |
Jesse Brandeburg | d2a1e21 | 2006-10-24 14:46:06 -0700 | [diff] [blame] | 4318 | /* adjust length to remove Ethernet CRC, this must be |
| 4319 | * done after the TBI_ACCEPT workaround above */ |
| 4320 | length -= 4; |
| 4321 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4322 | /* probably a little skewed due to removing CRC */ |
| 4323 | total_rx_bytes += length; |
| 4324 | total_rx_packets++; |
| 4325 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4326 | /* code added for copybreak, this should improve |
| 4327 | * performance for small packets with large amounts |
| 4328 | * of reassembly being done in the stack */ |
Jesse Brandeburg | 1f75386 | 2006-12-15 10:40:39 +0100 | [diff] [blame] | 4329 | if (length < copybreak) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4330 | struct sk_buff *new_skb = |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4331 | netdev_alloc_skb(netdev, length + NET_IP_ALIGN); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4332 | if (new_skb) { |
| 4333 | skb_reserve(new_skb, NET_IP_ALIGN); |
Arnaldo Carvalho de Melo | 27d7ff4 | 2007-03-31 11:55:19 -0300 | [diff] [blame] | 4334 | skb_copy_to_linear_data_offset(new_skb, |
| 4335 | -NET_IP_ALIGN, |
| 4336 | (skb->data - |
| 4337 | NET_IP_ALIGN), |
| 4338 | (length + |
| 4339 | NET_IP_ALIGN)); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4340 | /* save the skb in buffer_info as good */ |
| 4341 | buffer_info->skb = skb; |
| 4342 | skb = new_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4343 | } |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4344 | /* else just continue with the old one */ |
| 4345 | } |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4346 | /* end copybreak code */ |
Auke Kok | 996695d | 2006-11-01 08:47:50 -0800 | [diff] [blame] | 4347 | skb_put(skb, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | |
| 4349 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4350 | e1000_rx_checksum(adapter, |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4351 | (u32)(status) | |
| 4352 | ((u32)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 4353 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | skb->protocol = eth_type_trans(skb, netdev); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4356 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4357 | e1000_receive_skb(adapter, status, rx_desc->special, skb); |
Francois Romieu | c3570ac | 2008-07-11 15:17:38 -0700 | [diff] [blame] | 4358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | next_desc: |
| 4360 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4362 | /* return some buffers to hardware, one at a time is too slow */ |
| 4363 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 4364 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 4365 | cleaned_count = 0; |
| 4366 | } |
| 4367 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 4368 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 4369 | rx_desc = next_rxd; |
| 4370 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4372 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4373 | |
| 4374 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 4375 | if (cleaned_count) |
| 4376 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | |
Jesse Brandeburg | 835bb12 | 2006-11-01 08:48:13 -0800 | [diff] [blame] | 4378 | adapter->total_rx_packets += total_rx_packets; |
| 4379 | adapter->total_rx_bytes += total_rx_bytes; |
Auke Kok | ef90e4e | 2007-11-13 20:49:15 -0800 | [diff] [blame] | 4380 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 4381 | adapter->net_stats.rx_packets += total_rx_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | return cleaned; |
| 4383 | } |
| 4384 | |
| 4385 | /** |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4386 | * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers |
| 4387 | * @adapter: address of board private structure |
| 4388 | * @rx_ring: pointer to receive ring structure |
| 4389 | * @cleaned_count: number of buffers to allocate this pass |
| 4390 | **/ |
| 4391 | |
| 4392 | static void |
| 4393 | e1000_alloc_jumbo_rx_buffers(struct e1000_adapter *adapter, |
| 4394 | struct e1000_rx_ring *rx_ring, int cleaned_count) |
| 4395 | { |
| 4396 | struct net_device *netdev = adapter->netdev; |
| 4397 | struct pci_dev *pdev = adapter->pdev; |
| 4398 | struct e1000_rx_desc *rx_desc; |
| 4399 | struct e1000_buffer *buffer_info; |
| 4400 | struct sk_buff *skb; |
| 4401 | unsigned int i; |
| 4402 | unsigned int bufsz = 256 - |
| 4403 | 16 /*for skb_reserve */ - |
| 4404 | NET_IP_ALIGN; |
| 4405 | |
| 4406 | i = rx_ring->next_to_use; |
| 4407 | buffer_info = &rx_ring->buffer_info[i]; |
| 4408 | |
| 4409 | while (cleaned_count--) { |
| 4410 | skb = buffer_info->skb; |
| 4411 | if (skb) { |
| 4412 | skb_trim(skb, 0); |
| 4413 | goto check_page; |
| 4414 | } |
| 4415 | |
| 4416 | skb = netdev_alloc_skb(netdev, bufsz); |
| 4417 | if (unlikely(!skb)) { |
| 4418 | /* Better luck next round */ |
| 4419 | adapter->alloc_rx_buff_failed++; |
| 4420 | break; |
| 4421 | } |
| 4422 | |
| 4423 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4424 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4425 | struct sk_buff *oldskb = skb; |
| 4426 | DPRINTK(PROBE, ERR, "skb align check failed: %u bytes " |
| 4427 | "at %p\n", bufsz, skb->data); |
| 4428 | /* Try again, without freeing the previous */ |
| 4429 | skb = netdev_alloc_skb(netdev, bufsz); |
| 4430 | /* Failed allocation, critical failure */ |
| 4431 | if (!skb) { |
| 4432 | dev_kfree_skb(oldskb); |
| 4433 | adapter->alloc_rx_buff_failed++; |
| 4434 | break; |
| 4435 | } |
| 4436 | |
| 4437 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4438 | /* give up */ |
| 4439 | dev_kfree_skb(skb); |
| 4440 | dev_kfree_skb(oldskb); |
| 4441 | break; /* while (cleaned_count--) */ |
| 4442 | } |
| 4443 | |
| 4444 | /* Use new allocation */ |
| 4445 | dev_kfree_skb(oldskb); |
| 4446 | } |
| 4447 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4448 | * this will result in a 16 byte aligned IP header after |
| 4449 | * the 14 byte MAC header is removed |
| 4450 | */ |
| 4451 | skb_reserve(skb, NET_IP_ALIGN); |
| 4452 | |
| 4453 | buffer_info->skb = skb; |
| 4454 | buffer_info->length = adapter->rx_buffer_len; |
| 4455 | check_page: |
| 4456 | /* allocate a new page if necessary */ |
| 4457 | if (!buffer_info->page) { |
| 4458 | buffer_info->page = alloc_page(GFP_ATOMIC); |
| 4459 | if (unlikely(!buffer_info->page)) { |
| 4460 | adapter->alloc_rx_buff_failed++; |
| 4461 | break; |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | if (!buffer_info->dma) |
| 4466 | buffer_info->dma = pci_map_page(pdev, |
| 4467 | buffer_info->page, 0, |
| 4468 | buffer_info->length, |
| 4469 | PCI_DMA_FROMDEVICE); |
| 4470 | |
| 4471 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4472 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4473 | |
| 4474 | if (unlikely(++i == rx_ring->count)) |
| 4475 | i = 0; |
| 4476 | buffer_info = &rx_ring->buffer_info[i]; |
| 4477 | } |
| 4478 | |
| 4479 | if (likely(rx_ring->next_to_use != i)) { |
| 4480 | rx_ring->next_to_use = i; |
| 4481 | if (unlikely(i-- == 0)) |
| 4482 | i = (rx_ring->count - 1); |
| 4483 | |
| 4484 | /* Force memory writes to complete before letting h/w |
| 4485 | * know there are new descriptors to fetch. (Only |
| 4486 | * applicable for weak-ordered memory model archs, |
| 4487 | * such as IA-64). */ |
| 4488 | wmb(); |
| 4489 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4494 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | * @adapter: address of board private structure |
| 4496 | **/ |
| 4497 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4498 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
| 4499 | struct e1000_rx_ring *rx_ring, |
| 4500 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4501 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4502 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | struct net_device *netdev = adapter->netdev; |
| 4504 | struct pci_dev *pdev = adapter->pdev; |
| 4505 | struct e1000_rx_desc *rx_desc; |
| 4506 | struct e1000_buffer *buffer_info; |
| 4507 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4508 | unsigned int i; |
| 4509 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | |
| 4511 | i = rx_ring->next_to_use; |
| 4512 | buffer_info = &rx_ring->buffer_info[i]; |
| 4513 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4514 | while (cleaned_count--) { |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4515 | skb = buffer_info->skb; |
| 4516 | if (skb) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4517 | skb_trim(skb, 0); |
| 4518 | goto map_skb; |
| 4519 | } |
| 4520 | |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4521 | skb = netdev_alloc_skb(netdev, bufsz); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4522 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 4524 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | break; |
| 4526 | } |
| 4527 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4528 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4530 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4531 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 4532 | "at %p\n", bufsz, skb->data); |
| 4533 | /* Try again, without freeing the previous */ |
David S. Miller | 87f5032 | 2006-07-31 22:39:40 -0700 | [diff] [blame] | 4534 | skb = netdev_alloc_skb(netdev, bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4535 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | if (!skb) { |
| 4537 | dev_kfree_skb(oldskb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4538 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | break; |
| 4540 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 4543 | /* give up */ |
| 4544 | dev_kfree_skb(skb); |
| 4545 | dev_kfree_skb(oldskb); |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4546 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | break; /* while !buffer_info->skb */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | } |
Christoph Hellwig | ca6f722 | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 4549 | |
| 4550 | /* Use new allocation */ |
| 4551 | dev_kfree_skb(oldskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4554 | * this will result in a 16 byte aligned IP header after |
| 4555 | * the 14 byte MAC header is removed |
| 4556 | */ |
| 4557 | skb_reserve(skb, NET_IP_ALIGN); |
| 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | buffer_info->skb = skb; |
| 4560 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 4561 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | buffer_info->dma = pci_map_single(pdev, |
| 4563 | skb->data, |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4564 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | PCI_DMA_FROMDEVICE); |
| 4566 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4567 | /* |
| 4568 | * XXX if it was allocated cleanly it will never map to a |
| 4569 | * boundary crossing |
| 4570 | */ |
| 4571 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4572 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 4573 | if (!e1000_check_64k_bound(adapter, |
| 4574 | (void *)(unsigned long)buffer_info->dma, |
| 4575 | adapter->rx_buffer_len)) { |
| 4576 | DPRINTK(RX_ERR, ERR, |
| 4577 | "dma align check failed: %u bytes at %p\n", |
| 4578 | adapter->rx_buffer_len, |
| 4579 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | dev_kfree_skb(skb); |
| 4581 | buffer_info->skb = NULL; |
| 4582 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4583 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | adapter->rx_buffer_len, |
| 4585 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 679be3b | 2009-06-30 12:45:34 +0000 | [diff] [blame] | 4586 | buffer_info->dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | |
Jesse Brandeburg | edbbb3c | 2009-07-06 10:44:39 +0000 | [diff] [blame] | 4588 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | break; /* while !buffer_info->skb */ |
| 4590 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 4592 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4593 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4594 | if (unlikely(++i == rx_ring->count)) |
| 4595 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | buffer_info = &rx_ring->buffer_info[i]; |
| 4597 | } |
| 4598 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4599 | if (likely(rx_ring->next_to_use != i)) { |
| 4600 | rx_ring->next_to_use = i; |
| 4601 | if (unlikely(i-- == 0)) |
| 4602 | i = (rx_ring->count - 1); |
| 4603 | |
| 4604 | /* Force memory writes to complete before letting h/w |
| 4605 | * know there are new descriptors to fetch. (Only |
| 4606 | * applicable for weak-ordered memory model archs, |
| 4607 | * such as IA-64). */ |
| 4608 | wmb(); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4609 | writel(i, hw->hw_addr + rx_ring->rdt); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | /** |
| 4614 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4615 | * @adapter: |
| 4616 | **/ |
| 4617 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4618 | static void e1000_smartspeed(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4619 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4620 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4621 | u16 phy_status; |
| 4622 | u16 phy_ctrl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4624 | if ((hw->phy_type != e1000_phy_igp) || !hw->autoneg || |
| 4625 | !(hw->autoneg_advertised & ADVERTISE_1000_FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | return; |
| 4627 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4628 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | /* If Master/Slave config fault is asserted twice, |
| 4630 | * we assume back-to-back */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4631 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4632 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4633 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4634 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4635 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4636 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4638 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | phy_ctrl); |
| 4640 | adapter->smartspeed++; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4641 | if (!e1000_phy_setup_autoneg(hw) && |
| 4642 | !e1000_read_phy_reg(hw, PHY_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4643 | &phy_ctrl)) { |
| 4644 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4645 | MII_CR_RESTART_AUTO_NEG); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4646 | e1000_write_phy_reg(hw, PHY_CTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | phy_ctrl); |
| 4648 | } |
| 4649 | } |
| 4650 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4651 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | /* If still no link, perhaps using 2/3 pair cable */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4653 | e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | phy_ctrl |= CR_1000T_MS_ENABLE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4655 | e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_ctrl); |
| 4656 | if (!e1000_phy_setup_autoneg(hw) && |
| 4657 | !e1000_read_phy_reg(hw, PHY_CTRL, &phy_ctrl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4659 | MII_CR_RESTART_AUTO_NEG); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4660 | e1000_write_phy_reg(hw, PHY_CTRL, phy_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | } |
| 4662 | } |
| 4663 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4664 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | adapter->smartspeed = 0; |
| 4666 | } |
| 4667 | |
| 4668 | /** |
| 4669 | * e1000_ioctl - |
| 4670 | * @netdev: |
| 4671 | * @ifreq: |
| 4672 | * @cmd: |
| 4673 | **/ |
| 4674 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4675 | 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] | 4676 | { |
| 4677 | switch (cmd) { |
| 4678 | case SIOCGMIIPHY: |
| 4679 | case SIOCGMIIREG: |
| 4680 | case SIOCSMIIREG: |
| 4681 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4682 | default: |
| 4683 | return -EOPNOTSUPP; |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | /** |
| 4688 | * e1000_mii_ioctl - |
| 4689 | * @netdev: |
| 4690 | * @ifreq: |
| 4691 | * @cmd: |
| 4692 | **/ |
| 4693 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4694 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 4695 | int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4696 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4697 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4698 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4700 | int retval; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4701 | u16 mii_reg; |
| 4702 | u16 spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4703 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4705 | if (hw->media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4706 | return -EOPNOTSUPP; |
| 4707 | |
| 4708 | switch (cmd) { |
| 4709 | case SIOCGMIIPHY: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4710 | data->phy_id = hw->phy_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4711 | break; |
| 4712 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4713 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4715 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4716 | if (e1000_read_phy_reg(hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4717 | &data->val_out)) { |
| 4718 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4720 | } |
| 4721 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | break; |
| 4723 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4724 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4726 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | return -EFAULT; |
| 4728 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4729 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4730 | if (e1000_write_phy_reg(hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4731 | mii_reg)) { |
| 4732 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4734 | } |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4735 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4736 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | switch (data->reg_num) { |
| 4738 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4739 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4741 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4742 | hw->autoneg = 1; |
| 4743 | hw->autoneg_advertised = 0x2F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | } else { |
| 4745 | if (mii_reg & 0x40) |
| 4746 | spddplx = SPEED_1000; |
| 4747 | else if (mii_reg & 0x2000) |
| 4748 | spddplx = SPEED_100; |
| 4749 | else |
| 4750 | spddplx = SPEED_10; |
| 4751 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4752 | ? DUPLEX_FULL : |
| 4753 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | retval = e1000_set_spd_dplx(adapter, |
| 4755 | spddplx); |
Jesse Brandeburg | f0163ac | 2007-11-13 21:00:09 -0800 | [diff] [blame] | 4756 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | return retval; |
| 4758 | } |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4759 | if (netif_running(adapter->netdev)) |
| 4760 | e1000_reinit_locked(adapter); |
| 4761 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | e1000_reset(adapter); |
| 4763 | break; |
| 4764 | case M88E1000_PHY_SPEC_CTRL: |
| 4765 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4766 | if (e1000_phy_reset(hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | return -EIO; |
| 4768 | break; |
| 4769 | } |
| 4770 | } else { |
| 4771 | switch (data->reg_num) { |
| 4772 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4773 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | break; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4775 | if (netif_running(adapter->netdev)) |
| 4776 | e1000_reinit_locked(adapter); |
| 4777 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | e1000_reset(adapter); |
| 4779 | break; |
| 4780 | } |
| 4781 | } |
| 4782 | break; |
| 4783 | default: |
| 4784 | return -EOPNOTSUPP; |
| 4785 | } |
| 4786 | return E1000_SUCCESS; |
| 4787 | } |
| 4788 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4789 | void e1000_pci_set_mwi(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | { |
| 4791 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4792 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4794 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4795 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4798 | void e1000_pci_clear_mwi(struct e1000_hw *hw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4799 | { |
| 4800 | struct e1000_adapter *adapter = hw->back; |
| 4801 | |
| 4802 | pci_clear_mwi(adapter->pdev); |
| 4803 | } |
| 4804 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4805 | int e1000_pcix_get_mmrbc(struct e1000_hw *hw) |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4806 | { |
| 4807 | struct e1000_adapter *adapter = hw->back; |
| 4808 | return pcix_get_mmrbc(adapter->pdev); |
| 4809 | } |
| 4810 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4811 | void e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc) |
Peter Oruba | 007755e | 2007-09-28 22:42:06 -0700 | [diff] [blame] | 4812 | { |
| 4813 | struct e1000_adapter *adapter = hw->back; |
| 4814 | pcix_set_mmrbc(adapter->pdev, mmrbc); |
| 4815 | } |
| 4816 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4817 | 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] | 4818 | { |
| 4819 | struct e1000_adapter *adapter = hw->back; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4820 | u16 cap_offset; |
Jeff Kirsher | caeccb6 | 2006-09-27 12:53:57 -0700 | [diff] [blame] | 4821 | |
| 4822 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 4823 | if (!cap_offset) |
| 4824 | return -E1000_ERR_CONFIG; |
| 4825 | |
| 4826 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 4827 | |
| 4828 | return E1000_SUCCESS; |
| 4829 | } |
| 4830 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4831 | 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] | 4832 | { |
| 4833 | outl(value, port); |
| 4834 | } |
| 4835 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4836 | static void e1000_vlan_rx_register(struct net_device *netdev, |
| 4837 | struct vlan_group *grp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4839 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4840 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4841 | u32 ctrl, rctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4843 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4844 | e1000_irq_disable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | adapter->vlgrp = grp; |
| 4846 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4847 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4848 | /* enable VLAN tag insert/strip */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4849 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | ctrl |= E1000_CTRL_VME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4851 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4853 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4854 | /* enable VLAN receive filtering */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4855 | rctl = er32(RCTL); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4856 | rctl &= ~E1000_RCTL_CFIEN; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4857 | ew32(RCTL, rctl); |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4858 | e1000_update_mng_vlan(adapter); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | } else { |
| 4861 | /* disable VLAN tag insert/strip */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4862 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | ctrl &= ~E1000_CTRL_VME; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4864 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4866 | if (adapter->hw.mac_type != e1000_ich8lan) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4867 | if (adapter->mng_vlan_id != |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4868 | (u16)E1000_MNG_VLAN_NONE) { |
Auke Kok | 90fb513 | 2006-11-01 08:47:30 -0800 | [diff] [blame] | 4869 | e1000_vlan_rx_kill_vid(netdev, |
| 4870 | adapter->mng_vlan_id); |
| 4871 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4872 | } |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 4873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4876 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4877 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | } |
| 4879 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4880 | 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] | 4881 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4882 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4883 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4884 | u32 vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4885 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4886 | if ((hw->mng_cookie.status & |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4887 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4888 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4889 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | /* add VID to filter table */ |
| 4891 | index = (vid >> 5) & 0x7F; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4892 | vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | vfta |= (1 << (vid & 0x1F)); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4894 | e1000_write_vfta(hw, index, vfta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4895 | } |
| 4896 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4897 | 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] | 4898 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4899 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4900 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4901 | u32 vfta, index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4903 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4904 | e1000_irq_disable(adapter); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4905 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jesse Brandeburg | 9150b76 | 2008-03-21 11:06:58 -0700 | [diff] [blame] | 4906 | if (!test_bit(__E1000_DOWN, &adapter->flags)) |
| 4907 | e1000_irq_enable(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4909 | if ((hw->mng_cookie.status & |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4910 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4911 | (vid == adapter->mng_vlan_id)) { |
| 4912 | /* release control to f/w */ |
| 4913 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4914 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4915 | } |
| 4916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | /* remove VID from filter table */ |
| 4918 | index = (vid >> 5) & 0x7F; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4919 | vfta = E1000_READ_REG_ARRAY(hw, VFTA, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | vfta &= ~(1 << (vid & 0x1F)); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4921 | e1000_write_vfta(hw, index, vfta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | } |
| 4923 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4924 | static void e1000_restore_vlan(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | { |
| 4926 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4927 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4928 | if (adapter->vlgrp) { |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4929 | u16 vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4930 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 4931 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | continue; |
| 4933 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 4934 | } |
| 4935 | } |
| 4936 | } |
| 4937 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 4938 | int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4940 | struct e1000_hw *hw = &adapter->hw; |
| 4941 | |
| 4942 | hw->autoneg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4944 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4945 | if ((hw->media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4946 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 4947 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 4948 | return -EINVAL; |
| 4949 | } |
| 4950 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4951 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | case SPEED_10 + DUPLEX_HALF: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4953 | hw->forced_speed_duplex = e1000_10_half; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | break; |
| 4955 | case SPEED_10 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4956 | hw->forced_speed_duplex = e1000_10_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | break; |
| 4958 | case SPEED_100 + DUPLEX_HALF: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4959 | hw->forced_speed_duplex = e1000_100_half; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | break; |
| 4961 | case SPEED_100 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4962 | hw->forced_speed_duplex = e1000_100_full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | break; |
| 4964 | case SPEED_1000 + DUPLEX_FULL: |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4965 | hw->autoneg = 1; |
| 4966 | hw->autoneg_advertised = ADVERTISE_1000_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | break; |
| 4968 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 4969 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4970 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | return -EINVAL; |
| 4972 | } |
| 4973 | return 0; |
| 4974 | } |
| 4975 | |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 4976 | static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | { |
| 4978 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4979 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 4980 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 4981 | u32 ctrl, ctrl_ext, rctl, status; |
| 4982 | u32 wufc = adapter->wol; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 4983 | #ifdef CONFIG_PM |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4984 | int retval = 0; |
Auke Kok | 6fdfef1 | 2006-06-27 09:06:36 -0700 | [diff] [blame] | 4985 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | |
| 4987 | netif_device_detach(netdev); |
| 4988 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4989 | if (netif_running(netdev)) { |
| 4990 | WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4991 | e1000_down(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 4992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4994 | #ifdef CONFIG_PM |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 4995 | retval = pci_save_state(pdev); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4996 | if (retval) |
| 4997 | return retval; |
| 4998 | #endif |
| 4999 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5000 | status = er32(STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5001 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | wufc &= ~E1000_WUFC_LNKC; |
| 5003 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5004 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | e1000_setup_rctl(adapter); |
Patrick McHardy | db0ce50 | 2007-11-13 20:54:59 -0800 | [diff] [blame] | 5006 | e1000_set_rx_mode(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | |
| 5008 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 5009 | if (wufc & E1000_WUFC_MC) { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5010 | rctl = er32(RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | rctl |= E1000_RCTL_MPE; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5012 | ew32(RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | } |
| 5014 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5015 | if (hw->mac_type >= e1000_82540) { |
| 5016 | ctrl = er32(CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | /* advertise wake from D3Cold */ |
| 5018 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5019 | /* phy power management enable */ |
| 5020 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5021 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 5022 | E1000_CTRL_EN_PHY_PWR_MGMT; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5023 | ew32(CTRL, ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5026 | if (hw->media_type == e1000_media_type_fiber || |
| 5027 | hw->media_type == e1000_media_type_internal_serdes) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 | /* keep the laser running in D3 */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5029 | ctrl_ext = er32(CTRL_EXT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5031 | ew32(CTRL_EXT, ctrl_ext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5034 | /* Allow time for pending master requests to run */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5035 | e1000_disable_pciex_master(hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5036 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5037 | ew32(WUC, E1000_WUC_PME_EN); |
| 5038 | ew32(WUFC, wufc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | } else { |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5040 | ew32(WUC, 0); |
| 5041 | ew32(WUFC, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | } |
| 5043 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5044 | e1000_release_manageability(adapter); |
| 5045 | |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5046 | *enable_wake = !!wufc; |
| 5047 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5048 | /* make sure adapter isn't asleep if manageability is enabled */ |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5049 | if (adapter->en_mng_pt) |
| 5050 | *enable_wake = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5052 | if (hw->phy_type == e1000_phy_igp_3) |
| 5053 | e1000_phy_powerdown_workaround(hw); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 5054 | |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5055 | if (netif_running(netdev)) |
| 5056 | e1000_free_irq(adapter); |
| 5057 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5058 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5059 | * would have already happened in close and is redundant. */ |
| 5060 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 5063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | return 0; |
| 5065 | } |
| 5066 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 5067 | #ifdef CONFIG_PM |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5068 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5069 | { |
| 5070 | int retval; |
| 5071 | bool wake; |
| 5072 | |
| 5073 | retval = __e1000_shutdown(pdev, &wake); |
| 5074 | if (retval) |
| 5075 | return retval; |
| 5076 | |
| 5077 | if (wake) { |
| 5078 | pci_prepare_to_sleep(pdev); |
| 5079 | } else { |
| 5080 | pci_wake_from_d3(pdev, false); |
| 5081 | pci_set_power_state(pdev, PCI_D3hot); |
| 5082 | } |
| 5083 | |
| 5084 | return 0; |
| 5085 | } |
| 5086 | |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5087 | static int e1000_resume(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | { |
| 5089 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5090 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5091 | struct e1000_hw *hw = &adapter->hw; |
Joe Perches | 406874a | 2008-04-03 10:06:32 -0700 | [diff] [blame] | 5092 | u32 err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5094 | pci_set_power_state(pdev, PCI_D0); |
Kok, Auke | 1d33e9c | 2007-02-16 14:39:28 -0800 | [diff] [blame] | 5095 | pci_restore_state(pdev); |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 5096 | |
| 5097 | if (adapter->need_ioport) |
| 5098 | err = pci_enable_device(pdev); |
| 5099 | else |
| 5100 | err = pci_enable_device_mem(pdev); |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 5101 | if (err) { |
Auke Kok | 3d1dd8c | 2006-08-28 14:56:27 -0700 | [diff] [blame] | 5102 | printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); |
| 5103 | return err; |
| 5104 | } |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 5105 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | |
Auke Kok | d0e027d | 2006-04-14 19:04:40 -0700 | [diff] [blame] | 5107 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5108 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5109 | |
Joe Perches | c7be73b | 2008-07-11 15:17:28 -0700 | [diff] [blame] | 5110 | if (netif_running(netdev)) { |
| 5111 | err = e1000_request_irq(adapter); |
| 5112 | if (err) |
| 5113 | return err; |
| 5114 | } |
Auke Kok | edd106f | 2006-11-06 08:57:12 -0800 | [diff] [blame] | 5115 | |
| 5116 | e1000_power_up_phy(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5117 | e1000_reset(adapter); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5118 | ew32(WUS, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5120 | e1000_init_manageability(adapter); |
| 5121 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 5122 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | e1000_up(adapter); |
| 5124 | |
| 5125 | netif_device_attach(netdev); |
| 5126 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5127 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5128 | * DRV_LOAD until the interface is up. For all other cases, |
| 5129 | * let the f/w know that the h/w is now under the control |
| 5130 | * of the driver. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5131 | if (hw->mac_type != e1000_82573 || |
| 5132 | !e1000_check_mng_mode(hw)) |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 5133 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 5134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5135 | return 0; |
| 5136 | } |
| 5137 | #endif |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5138 | |
| 5139 | static void e1000_shutdown(struct pci_dev *pdev) |
| 5140 | { |
Rafael J. Wysocki | b43fcd7 | 2009-04-15 17:43:24 +0000 | [diff] [blame] | 5141 | bool wake; |
| 5142 | |
| 5143 | __e1000_shutdown(pdev, &wake); |
| 5144 | |
| 5145 | if (system_state == SYSTEM_POWER_OFF) { |
| 5146 | pci_wake_from_d3(pdev, wake); |
| 5147 | pci_set_power_state(pdev, PCI_D3hot); |
| 5148 | } |
Auke Kok | c653e63 | 2006-05-23 13:35:57 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5152 | /* |
| 5153 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5154 | * without having to re-enable interrupts. It's not called while |
| 5155 | * the interrupt routine is executing. |
| 5156 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5157 | static void e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 5159 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | d3d9e48 | 2006-07-14 16:14:23 -0700 | [diff] [blame] | 5160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | disable_irq(adapter->pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5162 | e1000_intr(adapter->pdev->irq, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | enable_irq(adapter->pdev->irq); |
| 5164 | } |
| 5165 | #endif |
| 5166 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5167 | /** |
| 5168 | * e1000_io_error_detected - called when PCI error is detected |
| 5169 | * @pdev: Pointer to PCI device |
| 5170 | * @state: The current pci conneection state |
| 5171 | * |
| 5172 | * This function is called after a PCI bus error affecting |
| 5173 | * this device has been detected. |
| 5174 | */ |
Joe Perches | 6479884 | 2008-07-11 15:17:02 -0700 | [diff] [blame] | 5175 | static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, |
| 5176 | pci_channel_state_t state) |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5177 | { |
| 5178 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 5179 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5180 | |
| 5181 | netif_device_detach(netdev); |
| 5182 | |
Andre Detsch | eab6330 | 2009-06-30 12:46:13 +0000 | [diff] [blame] | 5183 | if (state == pci_channel_io_perm_failure) |
| 5184 | return PCI_ERS_RESULT_DISCONNECT; |
| 5185 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5186 | if (netif_running(netdev)) |
| 5187 | e1000_down(adapter); |
Linas Vepstas | 72e8d6b | 2006-09-18 20:58:06 -0700 | [diff] [blame] | 5188 | pci_disable_device(pdev); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5189 | |
| 5190 | /* Request a slot slot reset. */ |
| 5191 | return PCI_ERS_RESULT_NEED_RESET; |
| 5192 | } |
| 5193 | |
| 5194 | /** |
| 5195 | * e1000_io_slot_reset - called after the pci bus has been reset. |
| 5196 | * @pdev: Pointer to PCI device |
| 5197 | * |
| 5198 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5199 | * resembles the first-half of the e1000_resume routine. |
| 5200 | */ |
| 5201 | static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev) |
| 5202 | { |
| 5203 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 5204 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5205 | struct e1000_hw *hw = &adapter->hw; |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 5206 | int err; |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5207 | |
Taku Izumi | 8125029 | 2008-07-11 15:17:44 -0700 | [diff] [blame] | 5208 | if (adapter->need_ioport) |
| 5209 | err = pci_enable_device(pdev); |
| 5210 | else |
| 5211 | err = pci_enable_device_mem(pdev); |
| 5212 | if (err) { |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5213 | printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n"); |
| 5214 | return PCI_ERS_RESULT_DISCONNECT; |
| 5215 | } |
| 5216 | pci_set_master(pdev); |
| 5217 | |
Linas Vepstas | dbf38c9 | 2006-09-27 12:54:11 -0700 | [diff] [blame] | 5218 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5219 | pci_enable_wake(pdev, PCI_D3cold, 0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5220 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5221 | e1000_reset(adapter); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5222 | ew32(WUS, ~0); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5223 | |
| 5224 | return PCI_ERS_RESULT_RECOVERED; |
| 5225 | } |
| 5226 | |
| 5227 | /** |
| 5228 | * e1000_io_resume - called when traffic can start flowing again. |
| 5229 | * @pdev: Pointer to PCI device |
| 5230 | * |
| 5231 | * This callback is called when the error recovery driver tells us that |
| 5232 | * its OK to resume normal operation. Implementation resembles the |
| 5233 | * second-half of the e1000_resume routine. |
| 5234 | */ |
| 5235 | static void e1000_io_resume(struct pci_dev *pdev) |
| 5236 | { |
| 5237 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 5238 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5239 | struct e1000_hw *hw = &adapter->hw; |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5240 | |
| 5241 | e1000_init_manageability(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5242 | |
| 5243 | if (netif_running(netdev)) { |
| 5244 | if (e1000_up(adapter)) { |
| 5245 | printk("e1000: can't bring device back up after reset\n"); |
| 5246 | return; |
| 5247 | } |
| 5248 | } |
| 5249 | |
| 5250 | netif_device_attach(netdev); |
| 5251 | |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5252 | /* If the controller is 82573 and f/w is AMT, do not set |
| 5253 | * DRV_LOAD until the interface is up. For all other cases, |
| 5254 | * let the f/w know that the h/w is now under the control |
| 5255 | * of the driver. */ |
Joe Perches | 1dc3291 | 2008-07-11 15:17:08 -0700 | [diff] [blame] | 5256 | if (hw->mac_type != e1000_82573 || |
| 5257 | !e1000_check_mng_mode(hw)) |
Jeff Garzik | 0fccd0e | 2006-12-15 10:56:10 -0500 | [diff] [blame] | 5258 | e1000_get_hw_control(adapter); |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5259 | |
Auke Kok | 9026729 | 2006-06-08 09:30:24 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | /* e1000_main.c */ |