Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4 | Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the Free |
| 8 | Software Foundation; either version 2 of the License, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License along with |
| 17 | this program; if not, write to the Free Software Foundation, Inc., 59 |
| 18 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | |
| 20 | The full GNU General Public License is included in this distribution in the |
| 21 | file called LICENSE. |
| 22 | |
| 23 | Contact Information: |
| 24 | Linux NICS <linux.nics@intel.com> |
| 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | #include "e1000.h" |
| 30 | |
| 31 | /* Change Log |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 32 | * 7.0.33 3-Feb-2006 |
| 33 | * o Added another fix for the pass false carrier bit |
| 34 | * 7.0.32 24-Jan-2006 |
| 35 | * o Need to rebuild with noew version number for the pass false carrier |
| 36 | * fix in e1000_hw.c |
| 37 | * 7.0.30 18-Jan-2006 |
| 38 | * o fixup for tso workaround to disable it for pci-x |
| 39 | * o fix mem leak on 82542 |
| 40 | * o fixes for 10 Mb/s connections and incorrect stats |
| 41 | * 7.0.28 01/06/2006 |
| 42 | * o hardware workaround to only set "speed mode" bit for 1G link. |
| 43 | * 7.0.26 12/23/2005 |
| 44 | * o wake on lan support modified for device ID 10B5 |
| 45 | * o fix dhcp + vlan issue not making it to the iAMT firmware |
| 46 | * 7.0.24 12/9/2005 |
| 47 | * o New hardware support for the Gigabit NIC embedded in the south bridge |
| 48 | * o Fixes to the recycling logic (skb->tail) from IBM LTC |
Jesse Brandeburg | 73629bb | 2006-01-18 13:01:41 -0800 | [diff] [blame] | 49 | * 6.3.9 12/16/2005 |
| 50 | * o incorporate fix for recycled skbs from IBM LTC |
| 51 | * 6.3.7 11/18/2005 |
| 52 | * o Honor eeprom setting for enabling/disabling Wake On Lan |
| 53 | * 6.3.5 11/17/2005 |
| 54 | * o Fix memory leak in rx ring handling for PCI Express adapters |
| 55 | * 6.3.4 11/8/05 |
| 56 | * o Patch from Jesper Juhl to remove redundant NULL checks for kfree |
| 57 | * 6.3.2 9/20/05 |
| 58 | * o Render logic that sets/resets DRV_LOAD as inline functions to |
| 59 | * avoid code replication. If f/w is AMT then set DRV_LOAD only when |
| 60 | * network interface is open. |
| 61 | * o Handle DRV_LOAD set/reset in cases where AMT uses VLANs. |
| 62 | * o Adjust PBA partioning for Jumbo frames using MTU size and not |
| 63 | * rx_buffer_len |
| 64 | * 6.3.1 9/19/05 |
| 65 | * o Use adapter->tx_timeout_factor in Tx Hung Detect logic |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 66 | * (e1000_clean_tx_irq) |
Jesse Brandeburg | 73629bb | 2006-01-18 13:01:41 -0800 | [diff] [blame] | 67 | * o Support for 8086:10B5 device (Quad Port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
| 69 | |
| 70 | char e1000_driver_name[] = "e1000"; |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 71 | static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #ifndef CONFIG_E1000_NAPI |
| 73 | #define DRIVERNAPI |
| 74 | #else |
| 75 | #define DRIVERNAPI "-NAPI" |
| 76 | #endif |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 77 | #define DRV_VERSION "7.0.33-k2"DRIVERNAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | char e1000_driver_version[] = DRV_VERSION; |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 79 | static char e1000_copyright[] = "Copyright (c) 1999-2005 Intel Corporation."; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | /* e1000_pci_tbl - PCI Device ID Table |
| 82 | * |
| 83 | * Last entry must be all 0s |
| 84 | * |
| 85 | * Macro expands to... |
| 86 | * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)} |
| 87 | */ |
| 88 | static struct pci_device_id e1000_pci_tbl[] = { |
| 89 | INTEL_E1000_ETHERNET_DEVICE(0x1000), |
| 90 | INTEL_E1000_ETHERNET_DEVICE(0x1001), |
| 91 | INTEL_E1000_ETHERNET_DEVICE(0x1004), |
| 92 | INTEL_E1000_ETHERNET_DEVICE(0x1008), |
| 93 | INTEL_E1000_ETHERNET_DEVICE(0x1009), |
| 94 | INTEL_E1000_ETHERNET_DEVICE(0x100C), |
| 95 | INTEL_E1000_ETHERNET_DEVICE(0x100D), |
| 96 | INTEL_E1000_ETHERNET_DEVICE(0x100E), |
| 97 | INTEL_E1000_ETHERNET_DEVICE(0x100F), |
| 98 | INTEL_E1000_ETHERNET_DEVICE(0x1010), |
| 99 | INTEL_E1000_ETHERNET_DEVICE(0x1011), |
| 100 | INTEL_E1000_ETHERNET_DEVICE(0x1012), |
| 101 | INTEL_E1000_ETHERNET_DEVICE(0x1013), |
| 102 | INTEL_E1000_ETHERNET_DEVICE(0x1014), |
| 103 | INTEL_E1000_ETHERNET_DEVICE(0x1015), |
| 104 | INTEL_E1000_ETHERNET_DEVICE(0x1016), |
| 105 | INTEL_E1000_ETHERNET_DEVICE(0x1017), |
| 106 | INTEL_E1000_ETHERNET_DEVICE(0x1018), |
| 107 | INTEL_E1000_ETHERNET_DEVICE(0x1019), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 108 | INTEL_E1000_ETHERNET_DEVICE(0x101A), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | INTEL_E1000_ETHERNET_DEVICE(0x101D), |
| 110 | INTEL_E1000_ETHERNET_DEVICE(0x101E), |
| 111 | INTEL_E1000_ETHERNET_DEVICE(0x1026), |
| 112 | INTEL_E1000_ETHERNET_DEVICE(0x1027), |
| 113 | INTEL_E1000_ETHERNET_DEVICE(0x1028), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 114 | INTEL_E1000_ETHERNET_DEVICE(0x105E), |
| 115 | INTEL_E1000_ETHERNET_DEVICE(0x105F), |
| 116 | INTEL_E1000_ETHERNET_DEVICE(0x1060), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | INTEL_E1000_ETHERNET_DEVICE(0x1075), |
| 118 | INTEL_E1000_ETHERNET_DEVICE(0x1076), |
| 119 | INTEL_E1000_ETHERNET_DEVICE(0x1077), |
| 120 | INTEL_E1000_ETHERNET_DEVICE(0x1078), |
| 121 | INTEL_E1000_ETHERNET_DEVICE(0x1079), |
| 122 | INTEL_E1000_ETHERNET_DEVICE(0x107A), |
| 123 | INTEL_E1000_ETHERNET_DEVICE(0x107B), |
| 124 | INTEL_E1000_ETHERNET_DEVICE(0x107C), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 125 | INTEL_E1000_ETHERNET_DEVICE(0x107D), |
| 126 | INTEL_E1000_ETHERNET_DEVICE(0x107E), |
| 127 | INTEL_E1000_ETHERNET_DEVICE(0x107F), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | INTEL_E1000_ETHERNET_DEVICE(0x108A), |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 129 | INTEL_E1000_ETHERNET_DEVICE(0x108B), |
| 130 | INTEL_E1000_ETHERNET_DEVICE(0x108C), |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 131 | INTEL_E1000_ETHERNET_DEVICE(0x1096), |
| 132 | INTEL_E1000_ETHERNET_DEVICE(0x1098), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 133 | INTEL_E1000_ETHERNET_DEVICE(0x1099), |
Mallikarjuna R Chilakala | 07b8fed | 2005-10-19 10:40:08 -0400 | [diff] [blame] | 134 | INTEL_E1000_ETHERNET_DEVICE(0x109A), |
Jeff Kirsher | b7ee49d | 2006-01-12 16:51:21 -0800 | [diff] [blame] | 135 | INTEL_E1000_ETHERNET_DEVICE(0x10B5), |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 136 | INTEL_E1000_ETHERNET_DEVICE(0x10B9), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* required last entry */ |
| 138 | {0,} |
| 139 | }; |
| 140 | |
| 141 | MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); |
| 142 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 143 | static int e1000_setup_tx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 144 | struct e1000_tx_ring *txdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 145 | static int e1000_setup_rx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 146 | struct e1000_rx_ring *rxdr); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 147 | static void e1000_free_tx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 148 | struct e1000_tx_ring *tx_ring); |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 149 | static void e1000_free_rx_resources(struct e1000_adapter *adapter, |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 150 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* Local Function Prototypes */ |
| 153 | |
| 154 | static int e1000_init_module(void); |
| 155 | static void e1000_exit_module(void); |
| 156 | static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent); |
| 157 | static void __devexit e1000_remove(struct pci_dev *pdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 158 | static int e1000_alloc_queues(struct e1000_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static int e1000_sw_init(struct e1000_adapter *adapter); |
| 160 | static int e1000_open(struct net_device *netdev); |
| 161 | static int e1000_close(struct net_device *netdev); |
| 162 | static void e1000_configure_tx(struct e1000_adapter *adapter); |
| 163 | static void e1000_configure_rx(struct e1000_adapter *adapter); |
| 164 | static void e1000_setup_rctl(struct e1000_adapter *adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 165 | static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter); |
| 166 | static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter); |
| 167 | static void e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 168 | struct e1000_tx_ring *tx_ring); |
| 169 | static void e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 170 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | static void e1000_set_multi(struct net_device *netdev); |
| 172 | static void e1000_update_phy_info(unsigned long data); |
| 173 | static void e1000_watchdog(unsigned long data); |
| 174 | static void e1000_watchdog_task(struct e1000_adapter *adapter); |
| 175 | static void e1000_82547_tx_fifo_stall(unsigned long data); |
| 176 | static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev); |
| 177 | static struct net_device_stats * e1000_get_stats(struct net_device *netdev); |
| 178 | static int e1000_change_mtu(struct net_device *netdev, int new_mtu); |
| 179 | static int e1000_set_mac(struct net_device *netdev, void *p); |
| 180 | static irqreturn_t e1000_intr(int irq, void *data, struct pt_regs *regs); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 181 | static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 182 | struct e1000_tx_ring *tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 184 | static int e1000_clean(struct net_device *poll_dev, int *budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 186 | struct e1000_rx_ring *rx_ring, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | int *work_done, int work_to_do); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 188 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 189 | struct e1000_rx_ring *rx_ring, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 190 | int *work_done, int work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 192 | static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 193 | struct e1000_rx_ring *rx_ring); |
| 194 | static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 195 | struct e1000_rx_ring *rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | #endif |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 197 | static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 198 | struct e1000_rx_ring *rx_ring, |
| 199 | int cleaned_count); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 200 | static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 201 | struct e1000_rx_ring *rx_ring, |
| 202 | int cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd); |
| 204 | static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, |
| 205 | int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | static void e1000_enter_82542_rst(struct e1000_adapter *adapter); |
| 207 | static void e1000_leave_82542_rst(struct e1000_adapter *adapter); |
| 208 | static void e1000_tx_timeout(struct net_device *dev); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 209 | static void e1000_reset_task(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static void e1000_smartspeed(struct e1000_adapter *adapter); |
| 211 | static inline int e1000_82547_fifo_workaround(struct e1000_adapter *adapter, |
| 212 | struct sk_buff *skb); |
| 213 | |
| 214 | static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp); |
| 215 | static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid); |
| 216 | static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); |
| 217 | static void e1000_restore_vlan(struct e1000_adapter *adapter); |
| 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | #ifdef CONFIG_PM |
Ashutosh Naik | 977e74b | 2005-10-28 15:14:53 -0700 | [diff] [blame] | 220 | static int e1000_suspend(struct pci_dev *pdev, pm_message_t state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | static int e1000_resume(struct pci_dev *pdev); |
| 222 | #endif |
| 223 | |
| 224 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 225 | /* for netdump / net console */ |
| 226 | static void e1000_netpoll (struct net_device *netdev); |
| 227 | #endif |
| 228 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | static struct pci_driver e1000_driver = { |
| 231 | .name = e1000_driver_name, |
| 232 | .id_table = e1000_pci_tbl, |
| 233 | .probe = e1000_probe, |
| 234 | .remove = __devexit_p(e1000_remove), |
| 235 | /* Power Managment Hooks */ |
| 236 | #ifdef CONFIG_PM |
| 237 | .suspend = e1000_suspend, |
| 238 | .resume = e1000_resume |
| 239 | #endif |
| 240 | }; |
| 241 | |
| 242 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 243 | MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver"); |
| 244 | MODULE_LICENSE("GPL"); |
| 245 | MODULE_VERSION(DRV_VERSION); |
| 246 | |
| 247 | static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 248 | module_param(debug, int, 0); |
| 249 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 250 | |
| 251 | /** |
| 252 | * e1000_init_module - Driver Registration Routine |
| 253 | * |
| 254 | * e1000_init_module is the first routine called when the driver is |
| 255 | * loaded. All it does is register with the PCI subsystem. |
| 256 | **/ |
| 257 | |
| 258 | static int __init |
| 259 | e1000_init_module(void) |
| 260 | { |
| 261 | int ret; |
| 262 | printk(KERN_INFO "%s - version %s\n", |
| 263 | e1000_driver_string, e1000_driver_version); |
| 264 | |
| 265 | printk(KERN_INFO "%s\n", e1000_copyright); |
| 266 | |
| 267 | ret = pci_module_init(&e1000_driver); |
Tony Luck | 8b378def | 2005-07-28 01:07:38 -0700 | [diff] [blame] | 268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | return ret; |
| 270 | } |
| 271 | |
| 272 | module_init(e1000_init_module); |
| 273 | |
| 274 | /** |
| 275 | * e1000_exit_module - Driver Exit Cleanup Routine |
| 276 | * |
| 277 | * e1000_exit_module is called just before the driver is removed |
| 278 | * from memory. |
| 279 | **/ |
| 280 | |
| 281 | static void __exit |
| 282 | e1000_exit_module(void) |
| 283 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | pci_unregister_driver(&e1000_driver); |
| 285 | } |
| 286 | |
| 287 | module_exit(e1000_exit_module); |
| 288 | |
| 289 | /** |
| 290 | * e1000_irq_disable - Mask off interrupt generation on the NIC |
| 291 | * @adapter: board private structure |
| 292 | **/ |
| 293 | |
| 294 | static inline void |
| 295 | e1000_irq_disable(struct e1000_adapter *adapter) |
| 296 | { |
| 297 | atomic_inc(&adapter->irq_sem); |
| 298 | E1000_WRITE_REG(&adapter->hw, IMC, ~0); |
| 299 | E1000_WRITE_FLUSH(&adapter->hw); |
| 300 | synchronize_irq(adapter->pdev->irq); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * e1000_irq_enable - Enable default interrupt generation settings |
| 305 | * @adapter: board private structure |
| 306 | **/ |
| 307 | |
| 308 | static inline void |
| 309 | e1000_irq_enable(struct e1000_adapter *adapter) |
| 310 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 311 | if (likely(atomic_dec_and_test(&adapter->irq_sem))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK); |
| 313 | E1000_WRITE_FLUSH(&adapter->hw); |
| 314 | } |
| 315 | } |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 316 | |
| 317 | static void |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 318 | e1000_update_mng_vlan(struct e1000_adapter *adapter) |
| 319 | { |
| 320 | struct net_device *netdev = adapter->netdev; |
| 321 | uint16_t vid = adapter->hw.mng_cookie.vlan_id; |
| 322 | uint16_t old_vid = adapter->mng_vlan_id; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 323 | if (adapter->vlgrp) { |
| 324 | if (!adapter->vlgrp->vlan_devices[vid]) { |
| 325 | if (adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 326 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) { |
| 327 | e1000_vlan_rx_add_vid(netdev, vid); |
| 328 | adapter->mng_vlan_id = vid; |
| 329 | } else |
| 330 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 331 | |
| 332 | if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) && |
| 333 | (vid != old_vid) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 334 | !adapter->vlgrp->vlan_devices[old_vid]) |
| 335 | e1000_vlan_rx_kill_vid(netdev, old_vid); |
Jeff Kirsher | c5f226f | 2006-03-02 18:17:55 -0800 | [diff] [blame] | 336 | } else |
| 337 | adapter->mng_vlan_id = vid; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 340 | |
| 341 | /** |
| 342 | * e1000_release_hw_control - release control of the h/w to f/w |
| 343 | * @adapter: address of board private structure |
| 344 | * |
| 345 | * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 346 | * For ASF and Pass Through versions of f/w this means that the |
| 347 | * driver is no longer loaded. For AMT version (only with 82573) i |
| 348 | * of the f/w this means that the netowrk i/f is closed. |
| 349 | * |
| 350 | **/ |
| 351 | |
| 352 | static inline void |
| 353 | e1000_release_hw_control(struct e1000_adapter *adapter) |
| 354 | { |
| 355 | uint32_t ctrl_ext; |
| 356 | uint32_t swsm; |
| 357 | |
| 358 | /* Let firmware taken over control of h/w */ |
| 359 | switch (adapter->hw.mac_type) { |
| 360 | case e1000_82571: |
| 361 | case e1000_82572: |
| 362 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 363 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 364 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
| 365 | break; |
| 366 | case e1000_82573: |
| 367 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 368 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 369 | swsm & ~E1000_SWSM_DRV_LOAD); |
| 370 | default: |
| 371 | break; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * e1000_get_hw_control - get control of the h/w from f/w |
| 377 | * @adapter: address of board private structure |
| 378 | * |
| 379 | * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit. |
| 380 | * For ASF and Pass Through versions of f/w this means that |
| 381 | * the driver is loaded. For AMT version (only with 82573) |
| 382 | * of the f/w this means that the netowrk i/f is open. |
| 383 | * |
| 384 | **/ |
| 385 | |
| 386 | static inline void |
| 387 | e1000_get_hw_control(struct e1000_adapter *adapter) |
| 388 | { |
| 389 | uint32_t ctrl_ext; |
| 390 | uint32_t swsm; |
| 391 | /* Let firmware know the driver has taken over */ |
| 392 | switch (adapter->hw.mac_type) { |
| 393 | case e1000_82571: |
| 394 | case e1000_82572: |
| 395 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 396 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, |
| 397 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
| 398 | break; |
| 399 | case e1000_82573: |
| 400 | swsm = E1000_READ_REG(&adapter->hw, SWSM); |
| 401 | E1000_WRITE_REG(&adapter->hw, SWSM, |
| 402 | swsm | E1000_SWSM_DRV_LOAD); |
| 403 | break; |
| 404 | default: |
| 405 | break; |
| 406 | } |
| 407 | } |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | int |
| 410 | e1000_up(struct e1000_adapter *adapter) |
| 411 | { |
| 412 | struct net_device *netdev = adapter->netdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 413 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | /* hardware has been reset, we need to reload some things */ |
| 416 | |
| 417 | /* Reset the PHY if it was previously powered down */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 418 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | uint16_t mii_reg; |
| 420 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 421 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | e1000_phy_reset(&adapter->hw); |
| 423 | } |
| 424 | |
| 425 | e1000_set_multi(netdev); |
| 426 | |
| 427 | e1000_restore_vlan(adapter); |
| 428 | |
| 429 | e1000_configure_tx(adapter); |
| 430 | e1000_setup_rctl(adapter); |
| 431 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 432 | /* call E1000_DESC_UNUSED which always leaves |
| 433 | * at least 1 descriptor unused to make sure |
| 434 | * next_to_use != next_to_clean */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 435 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 436 | struct e1000_rx_ring *ring = &adapter->rx_ring[i]; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 437 | adapter->alloc_rx_buf(adapter, ring, |
| 438 | E1000_DESC_UNUSED(ring)); |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 441 | #ifdef CONFIG_PCI_MSI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 442 | if (adapter->hw.mac_type > e1000_82547_rev_2) { |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 443 | adapter->have_msi = TRUE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 444 | if ((err = pci_enable_msi(adapter->pdev))) { |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 445 | DPRINTK(PROBE, ERR, |
| 446 | "Unable to allocate MSI interrupt Error: %d\n", err); |
| 447 | adapter->have_msi = FALSE; |
| 448 | } |
| 449 | } |
| 450 | #endif |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 451 | if ((err = request_irq(adapter->pdev->irq, &e1000_intr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | SA_SHIRQ | SA_SAMPLE_RANDOM, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 453 | netdev->name, netdev))) { |
| 454 | DPRINTK(PROBE, ERR, |
| 455 | "Unable to allocate interrupt Error: %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return err; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 459 | adapter->tx_queue_len = netdev->tx_queue_len; |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | mod_timer(&adapter->watchdog_timer, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | #ifdef CONFIG_E1000_NAPI |
| 464 | netif_poll_enable(netdev); |
| 465 | #endif |
Malli Chilakala | 5de5562 | 2005-04-28 19:39:30 -0700 | [diff] [blame] | 466 | e1000_irq_enable(adapter); |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | void |
| 472 | e1000_down(struct e1000_adapter *adapter) |
| 473 | { |
| 474 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 475 | boolean_t mng_mode_enabled = (adapter->hw.mac_type >= e1000_82571) && |
| 476 | e1000_check_mng_mode(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | e1000_irq_disable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | free_irq(adapter->pdev->irq, netdev); |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 481 | #ifdef CONFIG_PCI_MSI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 482 | if (adapter->hw.mac_type > e1000_82547_rev_2 && |
Malli Chilakala | fa4f7ef | 2005-04-28 19:39:13 -0700 | [diff] [blame] | 483 | adapter->have_msi == TRUE) |
| 484 | pci_disable_msi(adapter->pdev); |
| 485 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | del_timer_sync(&adapter->tx_fifo_stall_timer); |
| 487 | del_timer_sync(&adapter->watchdog_timer); |
| 488 | del_timer_sync(&adapter->phy_info_timer); |
| 489 | |
| 490 | #ifdef CONFIG_E1000_NAPI |
| 491 | netif_poll_disable(netdev); |
| 492 | #endif |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 493 | netdev->tx_queue_len = adapter->tx_queue_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | adapter->link_speed = 0; |
| 495 | adapter->link_duplex = 0; |
| 496 | netif_carrier_off(netdev); |
| 497 | netif_stop_queue(netdev); |
| 498 | |
| 499 | e1000_reset(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 500 | e1000_clean_all_tx_rings(adapter); |
| 501 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 503 | /* Power down the PHY so no link is implied when interface is down * |
| 504 | * The PHY cannot be powered down if any of the following is TRUE * |
| 505 | * (a) WoL is enabled |
| 506 | * (b) AMT is active |
| 507 | * (c) SoL/IDER session is active */ |
| 508 | if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 509 | adapter->hw.media_type == e1000_media_type_copper && |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 510 | !(E1000_READ_REG(&adapter->hw, MANC) & E1000_MANC_SMBUS_EN) && |
| 511 | !mng_mode_enabled && |
| 512 | !e1000_check_phy_reset_block(&adapter->hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | uint16_t mii_reg; |
| 514 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg); |
| 515 | mii_reg |= MII_CR_POWER_DOWN; |
| 516 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg); |
Malli Chilakala | 4e48a2b | 2005-04-28 19:39:53 -0700 | [diff] [blame] | 517 | mdelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | void |
| 522 | e1000_reset(struct e1000_adapter *adapter) |
| 523 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 524 | uint32_t pba, manc; |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 525 | uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | /* Repartition Pba for greater than 9k mtu |
| 528 | * To take effect CTRL.RST is required. |
| 529 | */ |
| 530 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 531 | switch (adapter->hw.mac_type) { |
| 532 | case e1000_82547: |
Malli Chilakala | 0e6ef3e | 2005-04-28 19:44:14 -0700 | [diff] [blame] | 533 | case e1000_82547_rev_2: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 534 | pba = E1000_PBA_30K; |
| 535 | break; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 536 | case e1000_82571: |
| 537 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 538 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 539 | pba = E1000_PBA_38K; |
| 540 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 541 | case e1000_82573: |
| 542 | pba = E1000_PBA_12K; |
| 543 | break; |
| 544 | default: |
| 545 | pba = E1000_PBA_48K; |
| 546 | break; |
| 547 | } |
| 548 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 549 | if ((adapter->hw.mac_type != e1000_82573) && |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 550 | (adapter->netdev->mtu > E1000_RXBUFFER_8192)) |
Malli Chilakala | 1125ecb | 2005-04-28 19:44:25 -0700 | [diff] [blame] | 551 | pba -= 8; /* allocate more FIFO for Tx */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 552 | |
| 553 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 554 | if (adapter->hw.mac_type == e1000_82547) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | adapter->tx_fifo_head = 0; |
| 556 | adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; |
| 557 | adapter->tx_fifo_size = |
| 558 | (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; |
| 559 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 560 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | E1000_WRITE_REG(&adapter->hw, PBA, pba); |
| 563 | |
| 564 | /* flow control settings */ |
Jeff Kirsher | f11b7f8 | 2006-01-12 16:50:51 -0800 | [diff] [blame] | 565 | /* Set the FC high water mark to 90% of the FIFO size. |
| 566 | * Required to clear last 3 LSB */ |
| 567 | fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8; |
| 568 | |
| 569 | adapter->hw.fc_high_water = fc_high_water_mark; |
| 570 | adapter->hw.fc_low_water = fc_high_water_mark - 8; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 571 | if (adapter->hw.mac_type == e1000_80003es2lan) |
| 572 | adapter->hw.fc_pause_time = 0xFFFF; |
| 573 | else |
| 574 | adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | adapter->hw.fc_send_xon = 1; |
| 576 | adapter->hw.fc = adapter->hw.original_fc; |
| 577 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 578 | /* Allow time for pending master requests to run */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | e1000_reset_hw(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 580 | if (adapter->hw.mac_type >= e1000_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 582 | if (e1000_init_hw(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | DPRINTK(PROBE, ERR, "Hardware Error\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 584 | e1000_update_mng_vlan(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 586 | E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); |
| 587 | |
| 588 | e1000_reset_adaptive(&adapter->hw); |
| 589 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 590 | if (adapter->en_mng_pt) { |
| 591 | manc = E1000_READ_REG(&adapter->hw, MANC); |
| 592 | manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST); |
| 593 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
| 598 | * e1000_probe - Device Initialization Routine |
| 599 | * @pdev: PCI device information struct |
| 600 | * @ent: entry in e1000_pci_tbl |
| 601 | * |
| 602 | * Returns 0 on success, negative on failure |
| 603 | * |
| 604 | * e1000_probe initializes an adapter identified by a pci_dev structure. |
| 605 | * The OS initialization, configuring of the adapter private structure, |
| 606 | * and a hardware reset occur. |
| 607 | **/ |
| 608 | |
| 609 | static int __devinit |
| 610 | e1000_probe(struct pci_dev *pdev, |
| 611 | const struct pci_device_id *ent) |
| 612 | { |
| 613 | struct net_device *netdev; |
| 614 | struct e1000_adapter *adapter; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 615 | unsigned long mmio_start, mmio_len; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | static int cards_found = 0; |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 618 | static int e1000_ksp3_port_a = 0; /* global ksp3 port a indication */ |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 619 | int i, err, pci_using_dac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | uint16_t eeprom_data; |
| 621 | uint16_t eeprom_apme_mask = E1000_EEPROM_APME; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 622 | if ((err = pci_enable_device(pdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return err; |
| 624 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 625 | if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | pci_using_dac = 1; |
| 627 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 628 | if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | E1000_ERR("No usable DMA configuration, aborting\n"); |
| 630 | return err; |
| 631 | } |
| 632 | pci_using_dac = 0; |
| 633 | } |
| 634 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 635 | if ((err = pci_request_regions(pdev, e1000_driver_name))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return err; |
| 637 | |
| 638 | pci_set_master(pdev); |
| 639 | |
| 640 | netdev = alloc_etherdev(sizeof(struct e1000_adapter)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 641 | if (!netdev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | err = -ENOMEM; |
| 643 | goto err_alloc_etherdev; |
| 644 | } |
| 645 | |
| 646 | SET_MODULE_OWNER(netdev); |
| 647 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 648 | |
| 649 | pci_set_drvdata(pdev, netdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 650 | adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | adapter->netdev = netdev; |
| 652 | adapter->pdev = pdev; |
| 653 | adapter->hw.back = adapter; |
| 654 | adapter->msg_enable = (1 << debug) - 1; |
| 655 | |
| 656 | mmio_start = pci_resource_start(pdev, BAR_0); |
| 657 | mmio_len = pci_resource_len(pdev, BAR_0); |
| 658 | |
| 659 | adapter->hw.hw_addr = ioremap(mmio_start, mmio_len); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 660 | if (!adapter->hw.hw_addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | err = -EIO; |
| 662 | goto err_ioremap; |
| 663 | } |
| 664 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 665 | for (i = BAR_1; i <= BAR_5; i++) { |
| 666 | if (pci_resource_len(pdev, i) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | continue; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 668 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | adapter->hw.io_base = pci_resource_start(pdev, i); |
| 670 | break; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | netdev->open = &e1000_open; |
| 675 | netdev->stop = &e1000_close; |
| 676 | netdev->hard_start_xmit = &e1000_xmit_frame; |
| 677 | netdev->get_stats = &e1000_get_stats; |
| 678 | netdev->set_multicast_list = &e1000_set_multi; |
| 679 | netdev->set_mac_address = &e1000_set_mac; |
| 680 | netdev->change_mtu = &e1000_change_mtu; |
| 681 | netdev->do_ioctl = &e1000_ioctl; |
| 682 | e1000_set_ethtool_ops(netdev); |
| 683 | netdev->tx_timeout = &e1000_tx_timeout; |
| 684 | netdev->watchdog_timeo = 5 * HZ; |
| 685 | #ifdef CONFIG_E1000_NAPI |
| 686 | netdev->poll = &e1000_clean; |
| 687 | netdev->weight = 64; |
| 688 | #endif |
| 689 | netdev->vlan_rx_register = e1000_vlan_rx_register; |
| 690 | netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid; |
| 691 | netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid; |
| 692 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 693 | netdev->poll_controller = e1000_netpoll; |
| 694 | #endif |
| 695 | strcpy(netdev->name, pci_name(pdev)); |
| 696 | |
| 697 | netdev->mem_start = mmio_start; |
| 698 | netdev->mem_end = mmio_start + mmio_len; |
| 699 | netdev->base_addr = adapter->hw.io_base; |
| 700 | |
| 701 | adapter->bd_number = cards_found; |
| 702 | |
| 703 | /* setup the private structure */ |
| 704 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 705 | if ((err = e1000_sw_init(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | goto err_sw_init; |
| 707 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 708 | if ((err = e1000_check_phy_reset_block(&adapter->hw))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 709 | DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n"); |
| 710 | |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 711 | /* if ksp3, indicate if it's port a being setup */ |
| 712 | if (pdev->device == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3 && |
| 713 | e1000_ksp3_port_a == 0) |
| 714 | adapter->ksp3_port_a = 1; |
| 715 | e1000_ksp3_port_a++; |
| 716 | /* Reset for multiple KP3 adapters */ |
| 717 | if (e1000_ksp3_port_a == 4) |
| 718 | e1000_ksp3_port_a = 0; |
| 719 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 720 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | netdev->features = NETIF_F_SG | |
| 722 | NETIF_F_HW_CSUM | |
| 723 | NETIF_F_HW_VLAN_TX | |
| 724 | NETIF_F_HW_VLAN_RX | |
| 725 | NETIF_F_HW_VLAN_FILTER; |
| 726 | } |
| 727 | |
| 728 | #ifdef NETIF_F_TSO |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 729 | if ((adapter->hw.mac_type >= e1000_82544) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | (adapter->hw.mac_type != e1000_82547)) |
| 731 | netdev->features |= NETIF_F_TSO; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 732 | |
| 733 | #ifdef NETIF_F_TSO_IPV6 |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 734 | if (adapter->hw.mac_type > e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 735 | netdev->features |= NETIF_F_TSO_IPV6; |
| 736 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | #endif |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 738 | if (pci_using_dac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | netdev->features |= NETIF_F_HIGHDMA; |
| 740 | |
| 741 | /* hard_start_xmit is safe against parallel locking */ |
| 742 | netdev->features |= NETIF_F_LLTX; |
| 743 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 744 | adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw); |
| 745 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 746 | /* before reading the EEPROM, reset the controller to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | * put the device in a known good starting state */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | e1000_reset_hw(&adapter->hw); |
| 750 | |
| 751 | /* make sure the EEPROM is good */ |
| 752 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 753 | if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n"); |
| 755 | err = -EIO; |
| 756 | goto err_eeprom; |
| 757 | } |
| 758 | |
| 759 | /* copy the MAC address out of the EEPROM */ |
| 760 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 761 | if (e1000_read_mac_addr(&adapter->hw)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | DPRINTK(PROBE, ERR, "EEPROM Read Error\n"); |
| 763 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
John W. Linville | 9beb0ac | 2005-09-12 10:48:55 -0400 | [diff] [blame] | 764 | memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 766 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | DPRINTK(PROBE, ERR, "Invalid MAC Address\n"); |
| 768 | err = -EIO; |
| 769 | goto err_eeprom; |
| 770 | } |
| 771 | |
| 772 | e1000_read_part_num(&adapter->hw, &(adapter->part_num)); |
| 773 | |
| 774 | e1000_get_bus_info(&adapter->hw); |
| 775 | |
| 776 | init_timer(&adapter->tx_fifo_stall_timer); |
| 777 | adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; |
| 778 | adapter->tx_fifo_stall_timer.data = (unsigned long) adapter; |
| 779 | |
| 780 | init_timer(&adapter->watchdog_timer); |
| 781 | adapter->watchdog_timer.function = &e1000_watchdog; |
| 782 | adapter->watchdog_timer.data = (unsigned long) adapter; |
| 783 | |
| 784 | INIT_WORK(&adapter->watchdog_task, |
| 785 | (void (*)(void *))e1000_watchdog_task, adapter); |
| 786 | |
| 787 | init_timer(&adapter->phy_info_timer); |
| 788 | adapter->phy_info_timer.function = &e1000_update_phy_info; |
| 789 | adapter->phy_info_timer.data = (unsigned long) adapter; |
| 790 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 791 | INIT_WORK(&adapter->reset_task, |
| 792 | (void (*)(void *))e1000_reset_task, netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | /* we're going to reset, so assume we have no link for now */ |
| 795 | |
| 796 | netif_carrier_off(netdev); |
| 797 | netif_stop_queue(netdev); |
| 798 | |
| 799 | e1000_check_options(adapter); |
| 800 | |
| 801 | /* Initial Wake on LAN setting |
| 802 | * If APM wake is enabled in the EEPROM, |
| 803 | * enable the ACPI Magic Packet filter |
| 804 | */ |
| 805 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 806 | switch (adapter->hw.mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | case e1000_82542_rev2_0: |
| 808 | case e1000_82542_rev2_1: |
| 809 | case e1000_82543: |
| 810 | break; |
| 811 | case e1000_82544: |
| 812 | e1000_read_eeprom(&adapter->hw, |
| 813 | EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); |
| 814 | eeprom_apme_mask = E1000_EEPROM_82544_APM; |
| 815 | break; |
| 816 | case e1000_82546: |
| 817 | case e1000_82546_rev_3: |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 818 | case e1000_82571: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 819 | case e1000_80003es2lan: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 820 | if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | e1000_read_eeprom(&adapter->hw, |
| 822 | EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
| 823 | break; |
| 824 | } |
| 825 | /* Fall Through */ |
| 826 | default: |
| 827 | e1000_read_eeprom(&adapter->hw, |
| 828 | EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
| 829 | break; |
| 830 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 831 | if (eeprom_data & eeprom_apme_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | adapter->wol |= E1000_WUFC_MAG; |
| 833 | |
Jeff Kirsher | fb3d47d | 2006-01-12 16:51:25 -0800 | [diff] [blame] | 834 | /* print bus type/speed/width info */ |
| 835 | { |
| 836 | struct e1000_hw *hw = &adapter->hw; |
| 837 | DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ", |
| 838 | ((hw->bus_type == e1000_bus_type_pcix) ? "-X" : |
| 839 | (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")), |
| 840 | ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
| 841 | (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" : |
| 842 | (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" : |
| 843 | (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" : |
| 844 | (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"), |
| 845 | ((hw->bus_width == e1000_bus_width_64) ? "64-bit" : |
| 846 | (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" : |
| 847 | (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" : |
| 848 | "32-bit")); |
| 849 | } |
| 850 | |
| 851 | for (i = 0; i < 6; i++) |
| 852 | printk("%2.2x%c", netdev->dev_addr[i], i == 5 ? '\n' : ':'); |
| 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | /* reset the hardware with the new settings */ |
| 855 | e1000_reset(adapter); |
| 856 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 857 | /* If the controller is 82573 and f/w is AMT, do not set |
| 858 | * DRV_LOAD until the interface is up. For all other cases, |
| 859 | * let the f/w know that the h/w is now under the control |
| 860 | * of the driver. */ |
| 861 | if (adapter->hw.mac_type != e1000_82573 || |
| 862 | !e1000_check_mng_mode(&adapter->hw)) |
| 863 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | strcpy(netdev->name, "eth%d"); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 866 | if ((err = register_netdev(netdev))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | goto err_register; |
| 868 | |
| 869 | DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n"); |
| 870 | |
| 871 | cards_found++; |
| 872 | return 0; |
| 873 | |
| 874 | err_register: |
| 875 | err_sw_init: |
| 876 | err_eeprom: |
| 877 | iounmap(adapter->hw.hw_addr); |
| 878 | err_ioremap: |
| 879 | free_netdev(netdev); |
| 880 | err_alloc_etherdev: |
| 881 | pci_release_regions(pdev); |
| 882 | return err; |
| 883 | } |
| 884 | |
| 885 | /** |
| 886 | * e1000_remove - Device Removal Routine |
| 887 | * @pdev: PCI device information struct |
| 888 | * |
| 889 | * e1000_remove is called by the PCI subsystem to alert the driver |
| 890 | * that it should release a PCI device. The could be caused by a |
| 891 | * Hot-Plug event, or because the driver is going to be removed from |
| 892 | * memory. |
| 893 | **/ |
| 894 | |
| 895 | static void __devexit |
| 896 | e1000_remove(struct pci_dev *pdev) |
| 897 | { |
| 898 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 899 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 900 | uint32_t manc; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 901 | #ifdef CONFIG_E1000_NAPI |
| 902 | int i; |
| 903 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 905 | flush_scheduled_work(); |
| 906 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 907 | if (adapter->hw.mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | adapter->hw.media_type == e1000_media_type_copper) { |
| 909 | manc = E1000_READ_REG(&adapter->hw, MANC); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 910 | if (manc & E1000_MANC_SMBUS_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | manc |= E1000_MANC_ARP_EN; |
| 912 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 913 | } |
| 914 | } |
| 915 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 916 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 917 | * would have already happened in close and is redundant. */ |
| 918 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | unregister_netdev(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 921 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 922 | for (i = 0; i < adapter->num_rx_queues; i++) |
Stephen Hemminger | 1533306 | 2006-03-20 22:32:28 -0800 | [diff] [blame] | 923 | dev_put(&adapter->polling_netdev[i]); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 924 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 926 | if (!e1000_check_phy_reset_block(&adapter->hw)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 927 | e1000_phy_hw_reset(&adapter->hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 929 | kfree(adapter->tx_ring); |
| 930 | kfree(adapter->rx_ring); |
| 931 | #ifdef CONFIG_E1000_NAPI |
| 932 | kfree(adapter->polling_netdev); |
| 933 | #endif |
| 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | iounmap(adapter->hw.hw_addr); |
| 936 | pci_release_regions(pdev); |
| 937 | |
| 938 | free_netdev(netdev); |
| 939 | |
| 940 | pci_disable_device(pdev); |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * e1000_sw_init - Initialize general software structures (struct e1000_adapter) |
| 945 | * @adapter: board private structure to initialize |
| 946 | * |
| 947 | * e1000_sw_init initializes the Adapter private data structure. |
| 948 | * Fields are initialized based on PCI device information and |
| 949 | * OS network device settings (MTU size). |
| 950 | **/ |
| 951 | |
| 952 | static int __devinit |
| 953 | e1000_sw_init(struct e1000_adapter *adapter) |
| 954 | { |
| 955 | struct e1000_hw *hw = &adapter->hw; |
| 956 | struct net_device *netdev = adapter->netdev; |
| 957 | struct pci_dev *pdev = adapter->pdev; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 958 | #ifdef CONFIG_E1000_NAPI |
| 959 | int i; |
| 960 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
| 962 | /* PCI config space info */ |
| 963 | |
| 964 | hw->vendor_id = pdev->vendor; |
| 965 | hw->device_id = pdev->device; |
| 966 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 967 | hw->subsystem_id = pdev->subsystem_device; |
| 968 | |
| 969 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 970 | |
| 971 | pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word); |
| 972 | |
| 973 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 974 | adapter->rx_ps_bsize0 = E1000_RXBUFFER_256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | hw->max_frame_size = netdev->mtu + |
| 976 | ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 977 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 978 | |
| 979 | /* identify the MAC */ |
| 980 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 981 | if (e1000_set_mac_type(hw)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | DPRINTK(PROBE, ERR, "Unknown MAC Type\n"); |
| 983 | return -EIO; |
| 984 | } |
| 985 | |
| 986 | /* initialize eeprom parameters */ |
| 987 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 988 | if (e1000_init_eeprom_params(hw)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 989 | E1000_ERR("EEPROM initialization failed\n"); |
| 990 | return -EIO; |
| 991 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 993 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | default: |
| 995 | break; |
| 996 | case e1000_82541: |
| 997 | case e1000_82547: |
| 998 | case e1000_82541_rev_2: |
| 999 | case e1000_82547_rev_2: |
| 1000 | hw->phy_init_script = 1; |
| 1001 | break; |
| 1002 | } |
| 1003 | |
| 1004 | e1000_set_media_type(hw); |
| 1005 | |
| 1006 | hw->wait_autoneg_complete = FALSE; |
| 1007 | hw->tbi_compatibility_en = TRUE; |
| 1008 | hw->adaptive_ifs = TRUE; |
| 1009 | |
| 1010 | /* Copper options */ |
| 1011 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1012 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | hw->mdix = AUTO_ALL_MODES; |
| 1014 | hw->disable_polarity_correction = FALSE; |
| 1015 | hw->master_slave = E1000_MASTER_SLAVE; |
| 1016 | } |
| 1017 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1018 | adapter->num_tx_queues = 1; |
| 1019 | adapter->num_rx_queues = 1; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1020 | |
| 1021 | if (e1000_alloc_queues(adapter)) { |
| 1022 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 1023 | return -ENOMEM; |
| 1024 | } |
| 1025 | |
| 1026 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1027 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1028 | adapter->polling_netdev[i].priv = adapter; |
| 1029 | adapter->polling_netdev[i].poll = &e1000_clean; |
| 1030 | adapter->polling_netdev[i].weight = 64; |
| 1031 | dev_hold(&adapter->polling_netdev[i]); |
| 1032 | set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state); |
| 1033 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1034 | spin_lock_init(&adapter->tx_queue_lock); |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1035 | #endif |
| 1036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | atomic_set(&adapter->irq_sem, 1); |
| 1038 | spin_lock_init(&adapter->stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1044 | * e1000_alloc_queues - Allocate memory for all rings |
| 1045 | * @adapter: board private structure to initialize |
| 1046 | * |
| 1047 | * We allocate one ring per queue at run-time since we don't know the |
| 1048 | * number of queues at compile-time. The polling_netdev array is |
| 1049 | * intended for Multiqueue, but should work fine with a single queue. |
| 1050 | **/ |
| 1051 | |
| 1052 | static int __devinit |
| 1053 | e1000_alloc_queues(struct e1000_adapter *adapter) |
| 1054 | { |
| 1055 | int size; |
| 1056 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1057 | size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1058 | adapter->tx_ring = kmalloc(size, GFP_KERNEL); |
| 1059 | if (!adapter->tx_ring) |
| 1060 | return -ENOMEM; |
| 1061 | memset(adapter->tx_ring, 0, size); |
| 1062 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1063 | size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1064 | adapter->rx_ring = kmalloc(size, GFP_KERNEL); |
| 1065 | if (!adapter->rx_ring) { |
| 1066 | kfree(adapter->tx_ring); |
| 1067 | return -ENOMEM; |
| 1068 | } |
| 1069 | memset(adapter->rx_ring, 0, size); |
| 1070 | |
| 1071 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1072 | size = sizeof(struct net_device) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1073 | adapter->polling_netdev = kmalloc(size, GFP_KERNEL); |
| 1074 | if (!adapter->polling_netdev) { |
| 1075 | kfree(adapter->tx_ring); |
| 1076 | kfree(adapter->rx_ring); |
| 1077 | return -ENOMEM; |
| 1078 | } |
| 1079 | memset(adapter->polling_netdev, 0, size); |
| 1080 | #endif |
| 1081 | |
| 1082 | return E1000_SUCCESS; |
| 1083 | } |
| 1084 | |
| 1085 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | * e1000_open - Called when a network interface is made active |
| 1087 | * @netdev: network interface device structure |
| 1088 | * |
| 1089 | * Returns 0 on success, negative value on failure |
| 1090 | * |
| 1091 | * The open entry point is called when a network interface is made |
| 1092 | * active by the system (IFF_UP). At this point all resources needed |
| 1093 | * for transmit and receive operations are allocated, the interrupt |
| 1094 | * handler is registered with the OS, the watchdog timer is started, |
| 1095 | * and the stack is notified that the interface is ready. |
| 1096 | **/ |
| 1097 | |
| 1098 | static int |
| 1099 | e1000_open(struct net_device *netdev) |
| 1100 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1101 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | int err; |
| 1103 | |
| 1104 | /* allocate transmit descriptors */ |
| 1105 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1106 | if ((err = e1000_setup_all_tx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | goto err_setup_tx; |
| 1108 | |
| 1109 | /* allocate receive descriptors */ |
| 1110 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1111 | if ((err = e1000_setup_all_rx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | goto err_setup_rx; |
| 1113 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1114 | if ((err = e1000_up(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | goto err_up; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1116 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1117 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1118 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1119 | e1000_update_mng_vlan(adapter); |
| 1120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1122 | /* If AMT is enabled, let the firmware know that the network |
| 1123 | * interface is now open */ |
| 1124 | if (adapter->hw.mac_type == e1000_82573 && |
| 1125 | e1000_check_mng_mode(&adapter->hw)) |
| 1126 | e1000_get_hw_control(adapter); |
| 1127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | return E1000_SUCCESS; |
| 1129 | |
| 1130 | err_up: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1131 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | err_setup_rx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1133 | e1000_free_all_tx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | err_setup_tx: |
| 1135 | e1000_reset(adapter); |
| 1136 | |
| 1137 | return err; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * e1000_close - Disables a network interface |
| 1142 | * @netdev: network interface device structure |
| 1143 | * |
| 1144 | * Returns 0, this is not allowed to fail |
| 1145 | * |
| 1146 | * The close entry point is called when an interface is de-activated |
| 1147 | * by the OS. The hardware is still under the drivers control, but |
| 1148 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1149 | * hardware, and all transmit and receive resources are freed. |
| 1150 | **/ |
| 1151 | |
| 1152 | static int |
| 1153 | e1000_close(struct net_device *netdev) |
| 1154 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1155 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
| 1157 | e1000_down(adapter); |
| 1158 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1159 | e1000_free_all_tx_resources(adapter); |
| 1160 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1162 | if ((adapter->hw.mng_cookie.status & |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1163 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) { |
| 1164 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1165 | } |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 1166 | |
| 1167 | /* If AMT is enabled, let the firmware know that the network |
| 1168 | * interface is now closed */ |
| 1169 | if (adapter->hw.mac_type == e1000_82573 && |
| 1170 | e1000_check_mng_mode(&adapter->hw)) |
| 1171 | e1000_release_hw_control(adapter); |
| 1172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | /** |
| 1177 | * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary |
| 1178 | * @adapter: address of board private structure |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1179 | * @start: address of beginning of memory |
| 1180 | * @len: length of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | **/ |
| 1182 | static inline boolean_t |
| 1183 | e1000_check_64k_bound(struct e1000_adapter *adapter, |
| 1184 | void *start, unsigned long len) |
| 1185 | { |
| 1186 | unsigned long begin = (unsigned long) start; |
| 1187 | unsigned long end = begin + len; |
| 1188 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1189 | /* First rev 82545 and 82546 need to not allow any memory |
| 1190 | * write location to cross 64k boundary due to errata 23 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | if (adapter->hw.mac_type == e1000_82545 || |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1192 | adapter->hw.mac_type == e1000_82546) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE; |
| 1194 | } |
| 1195 | |
| 1196 | return TRUE; |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * e1000_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1201 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1202 | * @txdr: tx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | * |
| 1204 | * Return 0 on success, negative on failure |
| 1205 | **/ |
| 1206 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1207 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1208 | e1000_setup_tx_resources(struct e1000_adapter *adapter, |
| 1209 | struct e1000_tx_ring *txdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | struct pci_dev *pdev = adapter->pdev; |
| 1212 | int size; |
| 1213 | |
| 1214 | size = sizeof(struct e1000_buffer) * txdr->count; |
Ravikiran G Thirumalai | a7ec15d | 2005-10-28 15:14:49 -0700 | [diff] [blame] | 1215 | |
| 1216 | txdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1217 | if (!txdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1218 | DPRINTK(PROBE, ERR, |
| 1219 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | return -ENOMEM; |
| 1221 | } |
| 1222 | memset(txdr->buffer_info, 0, size); |
| 1223 | |
| 1224 | /* round up to nearest 4K */ |
| 1225 | |
| 1226 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
| 1227 | E1000_ROUNDUP(txdr->size, 4096); |
| 1228 | |
| 1229 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1230 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | setup_tx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | vfree(txdr->buffer_info); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1233 | DPRINTK(PROBE, ERR, |
| 1234 | "Unable to allocate memory for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | return -ENOMEM; |
| 1236 | } |
| 1237 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1238 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1240 | void *olddesc = txdr->desc; |
| 1241 | dma_addr_t olddma = txdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1242 | DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes " |
| 1243 | "at %p\n", txdr->size, txdr->desc); |
| 1244 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1246 | /* Failed allocation, critical failure */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1247 | if (!txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1249 | goto setup_tx_desc_die; |
| 1250 | } |
| 1251 | |
| 1252 | if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) { |
| 1253 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1254 | pci_free_consistent(pdev, txdr->size, txdr->desc, |
| 1255 | txdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1257 | DPRINTK(PROBE, ERR, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1258 | "Unable to allocate aligned memory " |
| 1259 | "for the transmit descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | vfree(txdr->buffer_info); |
| 1261 | return -ENOMEM; |
| 1262 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1263 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | pci_free_consistent(pdev, txdr->size, olddesc, olddma); |
| 1265 | } |
| 1266 | } |
| 1267 | memset(txdr->desc, 0, txdr->size); |
| 1268 | |
| 1269 | txdr->next_to_use = 0; |
| 1270 | txdr->next_to_clean = 0; |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1271 | spin_lock_init(&txdr->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1277 | * e1000_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1278 | * (Descriptors) for all queues |
| 1279 | * @adapter: board private structure |
| 1280 | * |
| 1281 | * If this function returns with an error, then it's possible one or |
| 1282 | * more of the rings is populated (while the rest are not). It is the |
| 1283 | * callers duty to clean those orphaned rings. |
| 1284 | * |
| 1285 | * Return 0 on success, negative on failure |
| 1286 | **/ |
| 1287 | |
| 1288 | int |
| 1289 | e1000_setup_all_tx_resources(struct e1000_adapter *adapter) |
| 1290 | { |
| 1291 | int i, err = 0; |
| 1292 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1293 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1294 | err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1295 | if (err) { |
| 1296 | DPRINTK(PROBE, ERR, |
| 1297 | "Allocation for Tx Queue %u failed\n", i); |
| 1298 | break; |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | return err; |
| 1303 | } |
| 1304 | |
| 1305 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | * e1000_configure_tx - Configure 8254x Transmit Unit after Reset |
| 1307 | * @adapter: board private structure |
| 1308 | * |
| 1309 | * Configure the Tx unit of the MAC after a reset. |
| 1310 | **/ |
| 1311 | |
| 1312 | static void |
| 1313 | e1000_configure_tx(struct e1000_adapter *adapter) |
| 1314 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1315 | uint64_t tdba; |
| 1316 | struct e1000_hw *hw = &adapter->hw; |
| 1317 | uint32_t tdlen, tctl, tipg, tarc; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1318 | uint32_t ipgr1, ipgr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
| 1320 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1321 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1322 | switch (adapter->num_tx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1323 | case 1: |
| 1324 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1325 | tdba = adapter->tx_ring[0].dma; |
| 1326 | tdlen = adapter->tx_ring[0].count * |
| 1327 | sizeof(struct e1000_tx_desc); |
| 1328 | E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL)); |
| 1329 | E1000_WRITE_REG(hw, TDBAH, (tdba >> 32)); |
| 1330 | E1000_WRITE_REG(hw, TDLEN, tdlen); |
| 1331 | E1000_WRITE_REG(hw, TDH, 0); |
| 1332 | E1000_WRITE_REG(hw, TDT, 0); |
| 1333 | adapter->tx_ring[0].tdh = E1000_TDH; |
| 1334 | adapter->tx_ring[0].tdt = E1000_TDT; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1335 | break; |
| 1336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
| 1338 | /* Set the default values for the Tx Inter Packet Gap timer */ |
| 1339 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1340 | if (hw->media_type == e1000_media_type_fiber || |
| 1341 | hw->media_type == e1000_media_type_internal_serdes) |
| 1342 | tipg = DEFAULT_82543_TIPG_IPGT_FIBER; |
| 1343 | else |
| 1344 | tipg = DEFAULT_82543_TIPG_IPGT_COPPER; |
| 1345 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1346 | switch (hw->mac_type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | case e1000_82542_rev2_0: |
| 1348 | case e1000_82542_rev2_1: |
| 1349 | tipg = DEFAULT_82542_TIPG_IPGT; |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1350 | ipgr1 = DEFAULT_82542_TIPG_IPGR1; |
| 1351 | ipgr2 = DEFAULT_82542_TIPG_IPGR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | break; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1353 | case e1000_80003es2lan: |
| 1354 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1355 | ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2; |
| 1356 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | default: |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1358 | ipgr1 = DEFAULT_82543_TIPG_IPGR1; |
| 1359 | ipgr2 = DEFAULT_82543_TIPG_IPGR2; |
| 1360 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | } |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1362 | tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT; |
| 1363 | tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1364 | E1000_WRITE_REG(hw, TIPG, tipg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
| 1366 | /* Set the Tx Interrupt Delay register */ |
| 1367 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1368 | E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay); |
| 1369 | if (hw->mac_type >= e1000_82540) |
| 1370 | E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | /* Program the Transmit Control Register */ |
| 1373 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1374 | tctl = E1000_READ_REG(hw, TCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
| 1376 | tctl &= ~E1000_TCTL_CT; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1377 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1379 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1380 | #ifdef DISABLE_MULR |
| 1381 | /* disable Multiple Reads for debugging */ |
| 1382 | tctl &= ~E1000_TCTL_MULR; |
| 1383 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1385 | if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) { |
| 1386 | tarc = E1000_READ_REG(hw, TARC0); |
| 1387 | tarc |= ((1 << 25) | (1 << 21)); |
| 1388 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1389 | tarc = E1000_READ_REG(hw, TARC1); |
| 1390 | tarc |= (1 << 25); |
| 1391 | if (tctl & E1000_TCTL_MULR) |
| 1392 | tarc &= ~(1 << 28); |
| 1393 | else |
| 1394 | tarc |= (1 << 28); |
| 1395 | E1000_WRITE_REG(hw, TARC1, tarc); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1396 | } else if (hw->mac_type == e1000_80003es2lan) { |
| 1397 | tarc = E1000_READ_REG(hw, TARC0); |
| 1398 | tarc |= 1; |
| 1399 | if (hw->media_type == e1000_media_type_internal_serdes) |
| 1400 | tarc |= (1 << 20); |
| 1401 | E1000_WRITE_REG(hw, TARC0, tarc); |
| 1402 | tarc = E1000_READ_REG(hw, TARC1); |
| 1403 | tarc |= 1; |
| 1404 | E1000_WRITE_REG(hw, TARC1, tarc); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1405 | } |
| 1406 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1407 | e1000_config_collision_dist(hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
| 1409 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 1410 | adapter->txd_cmd = E1000_TXD_CMD_IDE | E1000_TXD_CMD_EOP | |
| 1411 | E1000_TXD_CMD_IFCS; |
| 1412 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1413 | if (hw->mac_type < e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | adapter->txd_cmd |= E1000_TXD_CMD_RPS; |
| 1415 | else |
| 1416 | adapter->txd_cmd |= E1000_TXD_CMD_RS; |
| 1417 | |
| 1418 | /* Cache if we're 82544 running in PCI-X because we'll |
| 1419 | * need this to apply a workaround later in the send path. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1420 | if (hw->mac_type == e1000_82544 && |
| 1421 | hw->bus_type == e1000_bus_type_pcix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | adapter->pcix_82544 = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 1423 | |
| 1424 | E1000_WRITE_REG(hw, TCTL, tctl); |
| 1425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * e1000_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1430 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1431 | * @rxdr: rx descriptor ring (for a specific queue) to setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | * |
| 1433 | * Returns 0 on success, negative on failure |
| 1434 | **/ |
| 1435 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1436 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1437 | e1000_setup_rx_resources(struct e1000_adapter *adapter, |
| 1438 | struct e1000_rx_ring *rxdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1441 | int size, desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
| 1443 | size = sizeof(struct e1000_buffer) * rxdr->count; |
Ravikiran G Thirumalai | a7ec15d | 2005-10-28 15:14:49 -0700 | [diff] [blame] | 1444 | rxdr->buffer_info = vmalloc_node(size, pcibus_to_node(pdev->bus)); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1445 | if (!rxdr->buffer_info) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1446 | DPRINTK(PROBE, ERR, |
| 1447 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | return -ENOMEM; |
| 1449 | } |
| 1450 | memset(rxdr->buffer_info, 0, size); |
| 1451 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1452 | size = sizeof(struct e1000_ps_page) * rxdr->count; |
| 1453 | rxdr->ps_page = kmalloc(size, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1454 | if (!rxdr->ps_page) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1455 | vfree(rxdr->buffer_info); |
| 1456 | DPRINTK(PROBE, ERR, |
| 1457 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1458 | return -ENOMEM; |
| 1459 | } |
| 1460 | memset(rxdr->ps_page, 0, size); |
| 1461 | |
| 1462 | size = sizeof(struct e1000_ps_page_dma) * rxdr->count; |
| 1463 | rxdr->ps_page_dma = kmalloc(size, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1464 | if (!rxdr->ps_page_dma) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1465 | vfree(rxdr->buffer_info); |
| 1466 | kfree(rxdr->ps_page); |
| 1467 | DPRINTK(PROBE, ERR, |
| 1468 | "Unable to allocate memory for the receive descriptor ring\n"); |
| 1469 | return -ENOMEM; |
| 1470 | } |
| 1471 | memset(rxdr->ps_page_dma, 0, size); |
| 1472 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1473 | if (adapter->hw.mac_type <= e1000_82547_rev_2) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1474 | desc_len = sizeof(struct e1000_rx_desc); |
| 1475 | else |
| 1476 | desc_len = sizeof(union e1000_rx_desc_packet_split); |
| 1477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | /* Round up to nearest 4K */ |
| 1479 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1480 | rxdr->size = rxdr->count * desc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | E1000_ROUNDUP(rxdr->size, 4096); |
| 1482 | |
| 1483 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
| 1484 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1485 | if (!rxdr->desc) { |
| 1486 | DPRINTK(PROBE, ERR, |
| 1487 | "Unable to allocate memory for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | setup_rx_desc_die: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | vfree(rxdr->buffer_info); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1490 | kfree(rxdr->ps_page); |
| 1491 | kfree(rxdr->ps_page_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | return -ENOMEM; |
| 1493 | } |
| 1494 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1495 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1497 | void *olddesc = rxdr->desc; |
| 1498 | dma_addr_t olddma = rxdr->dma; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1499 | DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes " |
| 1500 | "at %p\n", rxdr->size, rxdr->desc); |
| 1501 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1503 | /* Failed allocation, critical failure */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1504 | if (!rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1506 | DPRINTK(PROBE, ERR, |
| 1507 | "Unable to allocate memory " |
| 1508 | "for the receive descriptor ring\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | goto setup_rx_desc_die; |
| 1510 | } |
| 1511 | |
| 1512 | if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) { |
| 1513 | /* give up */ |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1514 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, |
| 1515 | rxdr->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1517 | DPRINTK(PROBE, ERR, |
| 1518 | "Unable to allocate aligned memory " |
| 1519 | "for the receive descriptor ring\n"); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1520 | goto setup_rx_desc_die; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1522 | /* Free old allocation, new allocation was successful */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | pci_free_consistent(pdev, rxdr->size, olddesc, olddma); |
| 1524 | } |
| 1525 | } |
| 1526 | memset(rxdr->desc, 0, rxdr->size); |
| 1527 | |
| 1528 | rxdr->next_to_clean = 0; |
| 1529 | rxdr->next_to_use = 0; |
| 1530 | |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1535 | * e1000_setup_all_rx_resources - wrapper to allocate Rx resources |
| 1536 | * (Descriptors) for all queues |
| 1537 | * @adapter: board private structure |
| 1538 | * |
| 1539 | * If this function returns with an error, then it's possible one or |
| 1540 | * more of the rings is populated (while the rest are not). It is the |
| 1541 | * callers duty to clean those orphaned rings. |
| 1542 | * |
| 1543 | * Return 0 on success, negative on failure |
| 1544 | **/ |
| 1545 | |
| 1546 | int |
| 1547 | e1000_setup_all_rx_resources(struct e1000_adapter *adapter) |
| 1548 | { |
| 1549 | int i, err = 0; |
| 1550 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1551 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1552 | err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1553 | if (err) { |
| 1554 | DPRINTK(PROBE, ERR, |
| 1555 | "Allocation for Rx Queue %u failed\n", i); |
| 1556 | break; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | return err; |
| 1561 | } |
| 1562 | |
| 1563 | /** |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1564 | * e1000_setup_rctl - configure the receive control registers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | * @adapter: Board private structure |
| 1566 | **/ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1567 | #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \ |
| 1568 | (((S) & (PAGE_SIZE - 1)) ? 1 : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | static void |
| 1570 | e1000_setup_rctl(struct e1000_adapter *adapter) |
| 1571 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1572 | uint32_t rctl, rfctl; |
| 1573 | uint32_t psrctl = 0; |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1574 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1575 | uint32_t pages = 0; |
| 1576 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
| 1578 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1579 | |
| 1580 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
| 1581 | |
| 1582 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | |
| 1583 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1584 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1585 | |
Jeff Kirsher | 0fadb05 | 2006-01-12 16:51:05 -0800 | [diff] [blame] | 1586 | if (adapter->hw.mac_type > e1000_82543) |
| 1587 | rctl |= E1000_RCTL_SECRC; |
| 1588 | |
| 1589 | if (adapter->hw.tbi_compatibility_on == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | rctl |= E1000_RCTL_SBP; |
| 1591 | else |
| 1592 | rctl &= ~E1000_RCTL_SBP; |
| 1593 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1594 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1595 | rctl &= ~E1000_RCTL_LPE; |
| 1596 | else |
| 1597 | rctl |= E1000_RCTL_LPE; |
| 1598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | /* Setup buffer sizes */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1600 | if (adapter->hw.mac_type >= e1000_82571) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1601 | /* We can now specify buffers in 1K increments. |
| 1602 | * BSIZE and BSEX are ignored in this case. */ |
| 1603 | rctl |= adapter->rx_buffer_len << 0x11; |
| 1604 | } else { |
| 1605 | rctl &= ~E1000_RCTL_SZ_4096; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 1606 | rctl |= E1000_RCTL_BSEX; |
| 1607 | switch (adapter->rx_buffer_len) { |
| 1608 | case E1000_RXBUFFER_2048: |
| 1609 | default: |
| 1610 | rctl |= E1000_RCTL_SZ_2048; |
| 1611 | rctl &= ~E1000_RCTL_BSEX; |
| 1612 | break; |
| 1613 | case E1000_RXBUFFER_4096: |
| 1614 | rctl |= E1000_RCTL_SZ_4096; |
| 1615 | break; |
| 1616 | case E1000_RXBUFFER_8192: |
| 1617 | rctl |= E1000_RCTL_SZ_8192; |
| 1618 | break; |
| 1619 | case E1000_RXBUFFER_16384: |
| 1620 | rctl |= E1000_RCTL_SZ_16384; |
| 1621 | break; |
| 1622 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1623 | } |
| 1624 | |
Jesse Brandeburg | 35ec56b | 2006-01-18 13:01:30 -0800 | [diff] [blame] | 1625 | #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1626 | /* 82571 and greater support packet-split where the protocol |
| 1627 | * header is placed in skb->data and the packet data is |
| 1628 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 1629 | * In the case of a non-split, skb->data is linearly filled, |
| 1630 | * followed by the page buffers. Therefore, skb->data is |
| 1631 | * sized to hold the largest protocol header. |
| 1632 | */ |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1633 | pages = PAGE_USE_COUNT(adapter->netdev->mtu); |
| 1634 | if ((adapter->hw.mac_type > e1000_82547_rev_2) && (pages <= 3) && |
| 1635 | PAGE_SIZE <= 16384) |
| 1636 | adapter->rx_ps_pages = pages; |
| 1637 | else |
| 1638 | adapter->rx_ps_pages = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1639 | #endif |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1640 | if (adapter->rx_ps_pages) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1641 | /* Configure extra packet-split registers */ |
| 1642 | rfctl = E1000_READ_REG(&adapter->hw, RFCTL); |
| 1643 | rfctl |= E1000_RFCTL_EXTEN; |
| 1644 | /* disable IPv6 packet split support */ |
| 1645 | rfctl |= E1000_RFCTL_IPV6_DIS; |
| 1646 | E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl); |
| 1647 | |
| 1648 | rctl |= E1000_RCTL_DTYP_PS | E1000_RCTL_SECRC; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1649 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1650 | psrctl |= adapter->rx_ps_bsize0 >> |
| 1651 | E1000_PSRCTL_BSIZE0_SHIFT; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1652 | |
| 1653 | switch (adapter->rx_ps_pages) { |
| 1654 | case 3: |
| 1655 | psrctl |= PAGE_SIZE << |
| 1656 | E1000_PSRCTL_BSIZE3_SHIFT; |
| 1657 | case 2: |
| 1658 | psrctl |= PAGE_SIZE << |
| 1659 | E1000_PSRCTL_BSIZE2_SHIFT; |
| 1660 | case 1: |
| 1661 | psrctl |= PAGE_SIZE >> |
| 1662 | E1000_PSRCTL_BSIZE1_SHIFT; |
| 1663 | break; |
| 1664 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1665 | |
| 1666 | E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 1670 | } |
| 1671 | |
| 1672 | /** |
| 1673 | * e1000_configure_rx - Configure 8254x Receive Unit after Reset |
| 1674 | * @adapter: board private structure |
| 1675 | * |
| 1676 | * Configure the Rx unit of the MAC after a reset. |
| 1677 | **/ |
| 1678 | |
| 1679 | static void |
| 1680 | e1000_configure_rx(struct e1000_adapter *adapter) |
| 1681 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1682 | uint64_t rdba; |
| 1683 | struct e1000_hw *hw = &adapter->hw; |
| 1684 | uint32_t rdlen, rctl, rxcsum, ctrl_ext; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1685 | |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 1686 | if (adapter->rx_ps_pages) { |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 1687 | /* this is a 32 byte descriptor */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1688 | rdlen = adapter->rx_ring[0].count * |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1689 | sizeof(union e1000_rx_desc_packet_split); |
| 1690 | adapter->clean_rx = e1000_clean_rx_irq_ps; |
| 1691 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps; |
| 1692 | } else { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1693 | rdlen = adapter->rx_ring[0].count * |
| 1694 | sizeof(struct e1000_rx_desc); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1695 | adapter->clean_rx = e1000_clean_rx_irq; |
| 1696 | adapter->alloc_rx_buf = e1000_alloc_rx_buffers; |
| 1697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
| 1699 | /* disable receives while setting up the descriptors */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1700 | rctl = E1000_READ_REG(hw, RCTL); |
| 1701 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
| 1703 | /* set the Receive Delay Timer Register */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1704 | E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1706 | if (hw->mac_type >= e1000_82540) { |
| 1707 | E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1708 | if (adapter->itr > 1) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1709 | E1000_WRITE_REG(hw, ITR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | 1000000000 / (adapter->itr * 256)); |
| 1711 | } |
| 1712 | |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1713 | if (hw->mac_type >= e1000_82571) { |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1714 | ctrl_ext = E1000_READ_REG(hw, CTRL_EXT); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1715 | /* Reset delay timers after every interrupt */ |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1716 | ctrl_ext |= E1000_CTRL_EXT_CANC; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1717 | #ifdef CONFIG_E1000_NAPI |
| 1718 | /* Auto-Mask interrupts upon ICR read. */ |
| 1719 | ctrl_ext |= E1000_CTRL_EXT_IAME; |
| 1720 | #endif |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1721 | E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 1722 | E1000_WRITE_REG(hw, IAM, ~0); |
Mallikarjuna R Chilakala | 2ae76d9 | 2005-10-04 07:04:22 -0400 | [diff] [blame] | 1723 | E1000_WRITE_FLUSH(hw); |
| 1724 | } |
| 1725 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1726 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1727 | * the Base and Length of the Rx Descriptor Ring */ |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1728 | switch (adapter->num_rx_queues) { |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1729 | case 1: |
| 1730 | default: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1731 | rdba = adapter->rx_ring[0].dma; |
| 1732 | E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL)); |
| 1733 | E1000_WRITE_REG(hw, RDBAH, (rdba >> 32)); |
| 1734 | E1000_WRITE_REG(hw, RDLEN, rdlen); |
| 1735 | E1000_WRITE_REG(hw, RDH, 0); |
| 1736 | E1000_WRITE_REG(hw, RDT, 0); |
| 1737 | adapter->rx_ring[0].rdh = E1000_RDH; |
| 1738 | adapter->rx_ring[0].rdt = E1000_RDT; |
| 1739 | break; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | /* Enable 82543 Receive Checksum Offload for TCP and UDP */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1743 | if (hw->mac_type >= e1000_82543) { |
| 1744 | rxcsum = E1000_READ_REG(hw, RXCSUM); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1745 | if (adapter->rx_csum == TRUE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1746 | rxcsum |= E1000_RXCSUM_TUOFL; |
| 1747 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1748 | /* Enable 82571 IPv4 payload checksum for UDP fragments |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1749 | * Must be used in conjunction with packet-split. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1750 | if ((hw->mac_type >= e1000_82571) && |
| 1751 | (adapter->rx_ps_pages)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1752 | rxcsum |= E1000_RXCSUM_IPPCSE; |
| 1753 | } |
| 1754 | } else { |
| 1755 | rxcsum &= ~E1000_RXCSUM_TUOFL; |
| 1756 | /* don't need to clear IPPCSE as it defaults to 0 */ |
| 1757 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1758 | E1000_WRITE_REG(hw, RXCSUM, rxcsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1761 | if (hw->mac_type == e1000_82573) |
| 1762 | E1000_WRITE_REG(hw, ERT, 0x0100); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | /* Enable Receives */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1765 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1769 | * e1000_free_tx_resources - Free Tx Resources per Queue |
| 1770 | * @adapter: board private structure |
| 1771 | * @tx_ring: Tx descriptor ring for a specific queue |
| 1772 | * |
| 1773 | * Free all transmit software resources |
| 1774 | **/ |
| 1775 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1776 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1777 | e1000_free_tx_resources(struct e1000_adapter *adapter, |
| 1778 | struct e1000_tx_ring *tx_ring) |
| 1779 | { |
| 1780 | struct pci_dev *pdev = adapter->pdev; |
| 1781 | |
| 1782 | e1000_clean_tx_ring(adapter, tx_ring); |
| 1783 | |
| 1784 | vfree(tx_ring->buffer_info); |
| 1785 | tx_ring->buffer_info = NULL; |
| 1786 | |
| 1787 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 1788 | |
| 1789 | tx_ring->desc = NULL; |
| 1790 | } |
| 1791 | |
| 1792 | /** |
| 1793 | * e1000_free_all_tx_resources - Free Tx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | * @adapter: board private structure |
| 1795 | * |
| 1796 | * Free all transmit software resources |
| 1797 | **/ |
| 1798 | |
| 1799 | void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1800 | e1000_free_all_tx_resources(struct e1000_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1802 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1804 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1805 | e1000_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | static inline void |
| 1809 | e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter, |
| 1810 | struct e1000_buffer *buffer_info) |
| 1811 | { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1812 | if (buffer_info->dma) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1813 | pci_unmap_page(adapter->pdev, |
| 1814 | buffer_info->dma, |
| 1815 | buffer_info->length, |
| 1816 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | } |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 1818 | if (buffer_info->skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | dev_kfree_skb_any(buffer_info->skb); |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 1820 | memset(buffer_info, 0, sizeof(struct e1000_buffer)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | /** |
| 1824 | * e1000_clean_tx_ring - Free Tx Buffers |
| 1825 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1826 | * @tx_ring: ring to be cleaned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | **/ |
| 1828 | |
| 1829 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1830 | e1000_clean_tx_ring(struct e1000_adapter *adapter, |
| 1831 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | struct e1000_buffer *buffer_info; |
| 1834 | unsigned long size; |
| 1835 | unsigned int i; |
| 1836 | |
| 1837 | /* Free all the Tx ring sk_buffs */ |
| 1838 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1839 | for (i = 0; i < tx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | buffer_info = &tx_ring->buffer_info[i]; |
| 1841 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
| 1842 | } |
| 1843 | |
| 1844 | size = sizeof(struct e1000_buffer) * tx_ring->count; |
| 1845 | memset(tx_ring->buffer_info, 0, size); |
| 1846 | |
| 1847 | /* Zero out the descriptor ring */ |
| 1848 | |
| 1849 | memset(tx_ring->desc, 0, tx_ring->size); |
| 1850 | |
| 1851 | tx_ring->next_to_use = 0; |
| 1852 | tx_ring->next_to_clean = 0; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1853 | tx_ring->last_tx_tso = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1855 | writel(0, adapter->hw.hw_addr + tx_ring->tdh); |
| 1856 | writel(0, adapter->hw.hw_addr + tx_ring->tdt); |
| 1857 | } |
| 1858 | |
| 1859 | /** |
| 1860 | * e1000_clean_all_tx_rings - Free Tx Buffers for all queues |
| 1861 | * @adapter: board private structure |
| 1862 | **/ |
| 1863 | |
| 1864 | static void |
| 1865 | e1000_clean_all_tx_rings(struct e1000_adapter *adapter) |
| 1866 | { |
| 1867 | int i; |
| 1868 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1869 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1870 | e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | /** |
| 1874 | * e1000_free_rx_resources - Free Rx Resources |
| 1875 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1876 | * @rx_ring: ring to clean the resources from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | * |
| 1878 | * Free all receive software resources |
| 1879 | **/ |
| 1880 | |
Adrian Bunk | 3ad2cc6 | 2005-10-30 16:53:34 +0100 | [diff] [blame] | 1881 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1882 | e1000_free_rx_resources(struct e1000_adapter *adapter, |
| 1883 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | struct pci_dev *pdev = adapter->pdev; |
| 1886 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1887 | e1000_clean_rx_ring(adapter, rx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
| 1889 | vfree(rx_ring->buffer_info); |
| 1890 | rx_ring->buffer_info = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1891 | kfree(rx_ring->ps_page); |
| 1892 | rx_ring->ps_page = NULL; |
| 1893 | kfree(rx_ring->ps_page_dma); |
| 1894 | rx_ring->ps_page_dma = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
| 1896 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 1897 | |
| 1898 | rx_ring->desc = NULL; |
| 1899 | } |
| 1900 | |
| 1901 | /** |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1902 | * e1000_free_all_rx_resources - Free Rx Resources for All Queues |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | * @adapter: board private structure |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1904 | * |
| 1905 | * Free all receive software resources |
| 1906 | **/ |
| 1907 | |
| 1908 | void |
| 1909 | e1000_free_all_rx_resources(struct e1000_adapter *adapter) |
| 1910 | { |
| 1911 | int i; |
| 1912 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1913 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1914 | e1000_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 1915 | } |
| 1916 | |
| 1917 | /** |
| 1918 | * e1000_clean_rx_ring - Free Rx Buffers per Queue |
| 1919 | * @adapter: board private structure |
| 1920 | * @rx_ring: ring to free buffers from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | **/ |
| 1922 | |
| 1923 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1924 | e1000_clean_rx_ring(struct e1000_adapter *adapter, |
| 1925 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | struct e1000_buffer *buffer_info; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1928 | struct e1000_ps_page *ps_page; |
| 1929 | struct e1000_ps_page_dma *ps_page_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | struct pci_dev *pdev = adapter->pdev; |
| 1931 | unsigned long size; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1932 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | |
| 1934 | /* Free all the Rx ring sk_buffs */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1935 | for (i = 0; i < rx_ring->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | buffer_info = &rx_ring->buffer_info[i]; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1937 | if (buffer_info->skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | pci_unmap_single(pdev, |
| 1939 | buffer_info->dma, |
| 1940 | buffer_info->length, |
| 1941 | PCI_DMA_FROMDEVICE); |
| 1942 | |
| 1943 | dev_kfree_skb(buffer_info->skb); |
| 1944 | buffer_info->skb = NULL; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 1945 | } |
| 1946 | ps_page = &rx_ring->ps_page[i]; |
| 1947 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 1948 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
| 1949 | if (!ps_page->ps_page[j]) break; |
| 1950 | pci_unmap_page(pdev, |
| 1951 | ps_page_dma->ps_page_dma[j], |
| 1952 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 1953 | ps_page_dma->ps_page_dma[j] = 0; |
| 1954 | put_page(ps_page->ps_page[j]); |
| 1955 | ps_page->ps_page[j] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | size = sizeof(struct e1000_buffer) * rx_ring->count; |
| 1960 | memset(rx_ring->buffer_info, 0, size); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 1961 | size = sizeof(struct e1000_ps_page) * rx_ring->count; |
| 1962 | memset(rx_ring->ps_page, 0, size); |
| 1963 | size = sizeof(struct e1000_ps_page_dma) * rx_ring->count; |
| 1964 | memset(rx_ring->ps_page_dma, 0, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | |
| 1966 | /* Zero out the descriptor ring */ |
| 1967 | |
| 1968 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1969 | |
| 1970 | rx_ring->next_to_clean = 0; |
| 1971 | rx_ring->next_to_use = 0; |
| 1972 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1973 | writel(0, adapter->hw.hw_addr + rx_ring->rdh); |
| 1974 | writel(0, adapter->hw.hw_addr + rx_ring->rdt); |
| 1975 | } |
| 1976 | |
| 1977 | /** |
| 1978 | * e1000_clean_all_rx_rings - Free Rx Buffers for all queues |
| 1979 | * @adapter: board private structure |
| 1980 | **/ |
| 1981 | |
| 1982 | static void |
| 1983 | e1000_clean_all_rx_rings(struct e1000_adapter *adapter) |
| 1984 | { |
| 1985 | int i; |
| 1986 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 1987 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1988 | e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | /* The 82542 2.0 (revision 2) needs to have the receive unit in reset |
| 1992 | * and memory write and invalidate disabled for certain operations |
| 1993 | */ |
| 1994 | static void |
| 1995 | e1000_enter_82542_rst(struct e1000_adapter *adapter) |
| 1996 | { |
| 1997 | struct net_device *netdev = adapter->netdev; |
| 1998 | uint32_t rctl; |
| 1999 | |
| 2000 | e1000_pci_clear_mwi(&adapter->hw); |
| 2001 | |
| 2002 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2003 | rctl |= E1000_RCTL_RST; |
| 2004 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2005 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2006 | mdelay(5); |
| 2007 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2008 | if (netif_running(netdev)) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2009 | e1000_clean_all_rx_rings(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | static void |
| 2013 | e1000_leave_82542_rst(struct e1000_adapter *adapter) |
| 2014 | { |
| 2015 | struct net_device *netdev = adapter->netdev; |
| 2016 | uint32_t rctl; |
| 2017 | |
| 2018 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 2019 | rctl &= ~E1000_RCTL_RST; |
| 2020 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 2021 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2022 | mdelay(5); |
| 2023 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2024 | if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | e1000_pci_set_mwi(&adapter->hw); |
| 2026 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2027 | if (netif_running(netdev)) { |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2028 | /* No need to loop, because 82542 supports only 1 queue */ |
| 2029 | struct e1000_rx_ring *ring = &adapter->rx_ring[0]; |
Jesse Brandeburg | 7c4d336 | 2006-01-18 13:01:45 -0800 | [diff] [blame] | 2030 | e1000_configure_rx(adapter); |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 2031 | adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | /** |
| 2036 | * e1000_set_mac - Change the Ethernet Address of the NIC |
| 2037 | * @netdev: network interface device structure |
| 2038 | * @p: pointer to an address structure |
| 2039 | * |
| 2040 | * Returns 0 on success, negative on failure |
| 2041 | **/ |
| 2042 | |
| 2043 | static int |
| 2044 | e1000_set_mac(struct net_device *netdev, void *p) |
| 2045 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2046 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | struct sockaddr *addr = p; |
| 2048 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2049 | if (!is_valid_ether_addr(addr->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | return -EADDRNOTAVAIL; |
| 2051 | |
| 2052 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2053 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2054 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | e1000_enter_82542_rst(adapter); |
| 2056 | |
| 2057 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2058 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 2059 | |
| 2060 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2061 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2062 | /* With 82571 controllers, LAA may be overwritten (with the default) |
| 2063 | * due to controller reset from the other port. */ |
| 2064 | if (adapter->hw.mac_type == e1000_82571) { |
| 2065 | /* activate the work around */ |
| 2066 | adapter->hw.laa_is_present = 1; |
| 2067 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2068 | /* Hold a copy of the LAA in RAR[14] This is done so that |
| 2069 | * between the time RAR[0] gets clobbered and the time it |
| 2070 | * gets fixed (in e1000_watchdog), the actual LAA is in one |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2071 | * of the RARs and no incoming packets directed to this port |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2072 | * are dropped. Eventaully the LAA will be in RAR[0] and |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2073 | * RAR[14] */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2074 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2075 | E1000_RAR_ENTRIES - 1); |
| 2076 | } |
| 2077 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2078 | if (adapter->hw.mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | e1000_leave_82542_rst(adapter); |
| 2080 | |
| 2081 | return 0; |
| 2082 | } |
| 2083 | |
| 2084 | /** |
| 2085 | * e1000_set_multi - Multicast and Promiscuous mode set |
| 2086 | * @netdev: network interface device structure |
| 2087 | * |
| 2088 | * The set_multi entry point is called whenever the multicast address |
| 2089 | * list or the network interface flags are updated. This routine is |
| 2090 | * responsible for configuring the hardware for proper multicast, |
| 2091 | * promiscuous mode, and all-multi behavior. |
| 2092 | **/ |
| 2093 | |
| 2094 | static void |
| 2095 | e1000_set_multi(struct net_device *netdev) |
| 2096 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2097 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | struct e1000_hw *hw = &adapter->hw; |
| 2099 | struct dev_mc_list *mc_ptr; |
| 2100 | uint32_t rctl; |
| 2101 | uint32_t hash_value; |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2102 | int i, rar_entries = E1000_RAR_ENTRIES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2104 | /* reserve RAR[14] for LAA over-write work-around */ |
| 2105 | if (adapter->hw.mac_type == e1000_82571) |
| 2106 | rar_entries--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2108 | /* Check for Promiscuous and All Multicast modes */ |
| 2109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | rctl = E1000_READ_REG(hw, RCTL); |
| 2111 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2112 | if (netdev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2114 | } else if (netdev->flags & IFF_ALLMULTI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | rctl |= E1000_RCTL_MPE; |
| 2116 | rctl &= ~E1000_RCTL_UPE; |
| 2117 | } else { |
| 2118 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
| 2119 | } |
| 2120 | |
| 2121 | E1000_WRITE_REG(hw, RCTL, rctl); |
| 2122 | |
| 2123 | /* 82542 2.0 needs to be in reset to write receive address registers */ |
| 2124 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2125 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | e1000_enter_82542_rst(adapter); |
| 2127 | |
| 2128 | /* load the first 14 multicast address into the exact filters 1-14 |
| 2129 | * RAR 0 is used for the station MAC adddress |
| 2130 | * 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] | 2131 | * -- with 82571 controllers only 0-13 entries are filled here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | */ |
| 2133 | mc_ptr = netdev->mc_list; |
| 2134 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2135 | for (i = 1; i < rar_entries; i++) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2136 | if (mc_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | e1000_rar_set(hw, mc_ptr->dmi_addr, i); |
| 2138 | mc_ptr = mc_ptr->next; |
| 2139 | } else { |
| 2140 | E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0); |
| 2141 | E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | /* clear the old settings from the multicast hash table */ |
| 2146 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2147 | for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); |
| 2149 | |
| 2150 | /* load any remaining addresses into the hash table */ |
| 2151 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2152 | for (; mc_ptr; mc_ptr = mc_ptr->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr); |
| 2154 | e1000_mta_set(hw, hash_value); |
| 2155 | } |
| 2156 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2157 | if (hw->mac_type == e1000_82542_rev2_0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | e1000_leave_82542_rst(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2162 | * the phy */ |
| 2163 | |
| 2164 | static void |
| 2165 | e1000_update_phy_info(unsigned long data) |
| 2166 | { |
| 2167 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2168 | e1000_phy_get_info(&adapter->hw, &adapter->phy_info); |
| 2169 | } |
| 2170 | |
| 2171 | /** |
| 2172 | * e1000_82547_tx_fifo_stall - Timer Call-back |
| 2173 | * @data: pointer to adapter cast into an unsigned long |
| 2174 | **/ |
| 2175 | |
| 2176 | static void |
| 2177 | e1000_82547_tx_fifo_stall(unsigned long data) |
| 2178 | { |
| 2179 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2180 | struct net_device *netdev = adapter->netdev; |
| 2181 | uint32_t tctl; |
| 2182 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2183 | if (atomic_read(&adapter->tx_fifo_stall)) { |
| 2184 | if ((E1000_READ_REG(&adapter->hw, TDT) == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | E1000_READ_REG(&adapter->hw, TDH)) && |
| 2186 | (E1000_READ_REG(&adapter->hw, TDFT) == |
| 2187 | E1000_READ_REG(&adapter->hw, TDFH)) && |
| 2188 | (E1000_READ_REG(&adapter->hw, TDFTS) == |
| 2189 | E1000_READ_REG(&adapter->hw, TDFHS))) { |
| 2190 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2191 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 2192 | tctl & ~E1000_TCTL_EN); |
| 2193 | E1000_WRITE_REG(&adapter->hw, TDFT, |
| 2194 | adapter->tx_head_addr); |
| 2195 | E1000_WRITE_REG(&adapter->hw, TDFH, |
| 2196 | adapter->tx_head_addr); |
| 2197 | E1000_WRITE_REG(&adapter->hw, TDFTS, |
| 2198 | adapter->tx_head_addr); |
| 2199 | E1000_WRITE_REG(&adapter->hw, TDFHS, |
| 2200 | adapter->tx_head_addr); |
| 2201 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
| 2202 | E1000_WRITE_FLUSH(&adapter->hw); |
| 2203 | |
| 2204 | adapter->tx_fifo_head = 0; |
| 2205 | atomic_set(&adapter->tx_fifo_stall, 0); |
| 2206 | netif_wake_queue(netdev); |
| 2207 | } else { |
| 2208 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1); |
| 2209 | } |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | /** |
| 2214 | * e1000_watchdog - Timer Call-back |
| 2215 | * @data: pointer to adapter cast into an unsigned long |
| 2216 | **/ |
| 2217 | static void |
| 2218 | e1000_watchdog(unsigned long data) |
| 2219 | { |
| 2220 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 2221 | |
| 2222 | /* Do the rest outside of interrupt context */ |
| 2223 | schedule_work(&adapter->watchdog_task); |
| 2224 | } |
| 2225 | |
| 2226 | static void |
| 2227 | e1000_watchdog_task(struct e1000_adapter *adapter) |
| 2228 | { |
| 2229 | struct net_device *netdev = adapter->netdev; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2230 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2231 | uint32_t link, tctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | |
| 2233 | e1000_check_for_link(&adapter->hw); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2234 | if (adapter->hw.mac_type == e1000_82573) { |
| 2235 | e1000_enable_tx_pkt_filtering(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2236 | if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2237 | e1000_update_mng_vlan(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2240 | if ((adapter->hw.media_type == e1000_media_type_internal_serdes) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE)) |
| 2242 | link = !adapter->hw.serdes_link_down; |
| 2243 | else |
| 2244 | link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU; |
| 2245 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2246 | if (link) { |
| 2247 | if (!netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | e1000_get_speed_and_duplex(&adapter->hw, |
| 2249 | &adapter->link_speed, |
| 2250 | &adapter->link_duplex); |
| 2251 | |
| 2252 | DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s\n", |
| 2253 | adapter->link_speed, |
| 2254 | adapter->link_duplex == FULL_DUPLEX ? |
| 2255 | "Full Duplex" : "Half Duplex"); |
| 2256 | |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2257 | /* tweak tx_queue_len according to speed/duplex |
| 2258 | * and adjust the timeout factor */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2259 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2260 | adapter->tx_timeout_factor = 1; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2261 | adapter->txb2b = 1; |
| 2262 | switch (adapter->link_speed) { |
| 2263 | case SPEED_10: |
| 2264 | adapter->txb2b = 0; |
| 2265 | netdev->tx_queue_len = 10; |
| 2266 | adapter->tx_timeout_factor = 8; |
| 2267 | break; |
| 2268 | case SPEED_100: |
| 2269 | adapter->txb2b = 0; |
| 2270 | netdev->tx_queue_len = 100; |
| 2271 | /* maybe add some timeout factor ? */ |
| 2272 | break; |
| 2273 | } |
| 2274 | |
| 2275 | if ((adapter->hw.mac_type == e1000_82571 || |
| 2276 | adapter->hw.mac_type == e1000_82572) && |
| 2277 | adapter->txb2b == 0) { |
| 2278 | #define SPEED_MODE_BIT (1 << 21) |
| 2279 | uint32_t tarc0; |
| 2280 | tarc0 = E1000_READ_REG(&adapter->hw, TARC0); |
| 2281 | tarc0 &= ~SPEED_MODE_BIT; |
| 2282 | E1000_WRITE_REG(&adapter->hw, TARC0, tarc0); |
| 2283 | } |
| 2284 | |
| 2285 | #ifdef NETIF_F_TSO |
| 2286 | /* disable TSO for pcie and 10/100 speeds, to avoid |
| 2287 | * some hardware issues */ |
| 2288 | if (!adapter->tso_force && |
| 2289 | adapter->hw.bus_type == e1000_bus_type_pci_express){ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2290 | switch (adapter->link_speed) { |
| 2291 | case SPEED_10: |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2292 | case SPEED_100: |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2293 | DPRINTK(PROBE,INFO, |
| 2294 | "10/100 speed: disabling TSO\n"); |
| 2295 | netdev->features &= ~NETIF_F_TSO; |
| 2296 | break; |
| 2297 | case SPEED_1000: |
| 2298 | netdev->features |= NETIF_F_TSO; |
| 2299 | break; |
| 2300 | default: |
| 2301 | /* oops */ |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2302 | break; |
| 2303 | } |
| 2304 | } |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 2305 | #endif |
| 2306 | |
| 2307 | /* enable transmits in the hardware, need to do this |
| 2308 | * after setting TARC0 */ |
| 2309 | tctl = E1000_READ_REG(&adapter->hw, TCTL); |
| 2310 | tctl |= E1000_TCTL_EN; |
| 2311 | E1000_WRITE_REG(&adapter->hw, TCTL, tctl); |
Jeff Kirsher | 66a2b0a | 2006-01-12 16:50:53 -0800 | [diff] [blame] | 2312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | netif_carrier_on(netdev); |
| 2314 | netif_wake_queue(netdev); |
| 2315 | mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
| 2316 | adapter->smartspeed = 0; |
| 2317 | } |
| 2318 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2319 | if (netif_carrier_ok(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | adapter->link_speed = 0; |
| 2321 | adapter->link_duplex = 0; |
| 2322 | DPRINTK(LINK, INFO, "NIC Link is Down\n"); |
| 2323 | netif_carrier_off(netdev); |
| 2324 | netif_stop_queue(netdev); |
| 2325 | mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2326 | |
| 2327 | /* 80003ES2LAN workaround-- |
| 2328 | * For packet buffer work-around on link down event; |
| 2329 | * disable receives in the ISR and |
| 2330 | * reset device here in the watchdog |
| 2331 | */ |
| 2332 | if (adapter->hw.mac_type == e1000_80003es2lan) { |
| 2333 | /* reset device */ |
| 2334 | schedule_work(&adapter->reset_task); |
| 2335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | e1000_smartspeed(adapter); |
| 2339 | } |
| 2340 | |
| 2341 | e1000_update_stats(adapter); |
| 2342 | |
| 2343 | adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
| 2344 | adapter->tpt_old = adapter->stats.tpt; |
| 2345 | adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old; |
| 2346 | adapter->colc_old = adapter->stats.colc; |
| 2347 | |
| 2348 | adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old; |
| 2349 | adapter->gorcl_old = adapter->stats.gorcl; |
| 2350 | adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old; |
| 2351 | adapter->gotcl_old = adapter->stats.gotcl; |
| 2352 | |
| 2353 | e1000_update_adaptive(&adapter->hw); |
| 2354 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 2355 | if (!netif_carrier_ok(netdev)) { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2356 | if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | /* We've lost link, so the controller stops DMA, |
| 2358 | * but we've got queued Tx work that's never going |
| 2359 | * to get done, so reset controller to flush Tx. |
| 2360 | * (Do the reset outside of interrupt context). */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2361 | adapter->tx_timeout_count++; |
| 2362 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | /* Dynamic mode for Interrupt Throttle Rate (ITR) */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2367 | if (adapter->hw.mac_type >= e1000_82540 && adapter->itr == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | /* Symmetric Tx/Rx gets a reduced ITR=2000; Total |
| 2369 | * asymmetrical Tx or Rx gets ITR=8000; everyone |
| 2370 | * else is between 2000-8000. */ |
| 2371 | uint32_t goc = (adapter->gotcl + adapter->gorcl) / 10000; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2372 | uint32_t dif = (adapter->gotcl > adapter->gorcl ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | adapter->gotcl - adapter->gorcl : |
| 2374 | adapter->gorcl - adapter->gotcl) / 10000; |
| 2375 | uint32_t itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000; |
| 2376 | E1000_WRITE_REG(&adapter->hw, ITR, 1000000000 / (itr * 256)); |
| 2377 | } |
| 2378 | |
| 2379 | /* Cause software interrupt to ensure rx ring is cleaned */ |
| 2380 | E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0); |
| 2381 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2382 | /* Force detection of hung controller every watchdog period */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | adapter->detect_tx_hung = TRUE; |
| 2384 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2385 | /* With 82571 controllers, LAA may be overwritten due to controller |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2386 | * reset from the other port. Set the appropriate LAA in RAR[0] */ |
| 2387 | if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present) |
| 2388 | e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0); |
| 2389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | /* Reset the timer */ |
| 2391 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 2392 | } |
| 2393 | |
| 2394 | #define E1000_TX_FLAGS_CSUM 0x00000001 |
| 2395 | #define E1000_TX_FLAGS_VLAN 0x00000002 |
| 2396 | #define E1000_TX_FLAGS_TSO 0x00000004 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2397 | #define E1000_TX_FLAGS_IPV4 0x00000008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2399 | #define E1000_TX_FLAGS_VLAN_SHIFT 16 |
| 2400 | |
| 2401 | static inline int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2402 | e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2403 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | { |
| 2405 | #ifdef NETIF_F_TSO |
| 2406 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2407 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | unsigned int i; |
| 2409 | uint32_t cmd_length = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2410 | uint16_t ipcse = 0, tucse, mss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | uint8_t ipcss, ipcso, tucss, tucso, hdr_len; |
| 2412 | int err; |
| 2413 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2414 | if (skb_shinfo(skb)->tso_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | if (skb_header_cloned(skb)) { |
| 2416 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2417 | if (err) |
| 2418 | return err; |
| 2419 | } |
| 2420 | |
| 2421 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
| 2422 | mss = skb_shinfo(skb)->tso_size; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2423 | if (skb->protocol == ntohs(ETH_P_IP)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2424 | skb->nh.iph->tot_len = 0; |
| 2425 | skb->nh.iph->check = 0; |
| 2426 | skb->h.th->check = |
| 2427 | ~csum_tcpudp_magic(skb->nh.iph->saddr, |
| 2428 | skb->nh.iph->daddr, |
| 2429 | 0, |
| 2430 | IPPROTO_TCP, |
| 2431 | 0); |
| 2432 | cmd_length = E1000_TXD_CMD_IP; |
| 2433 | ipcse = skb->h.raw - skb->data - 1; |
| 2434 | #ifdef NETIF_F_TSO_IPV6 |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2435 | } else if (skb->protocol == ntohs(ETH_P_IPV6)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2436 | skb->nh.ipv6h->payload_len = 0; |
| 2437 | skb->h.th->check = |
| 2438 | ~csum_ipv6_magic(&skb->nh.ipv6h->saddr, |
| 2439 | &skb->nh.ipv6h->daddr, |
| 2440 | 0, |
| 2441 | IPPROTO_TCP, |
| 2442 | 0); |
| 2443 | ipcse = 0; |
| 2444 | #endif |
| 2445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | ipcss = skb->nh.raw - skb->data; |
| 2447 | ipcso = (void *)&(skb->nh.iph->check) - (void *)skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | tucss = skb->h.raw - skb->data; |
| 2449 | tucso = (void *)&(skb->h.th->check) - (void *)skb->data; |
| 2450 | tucse = 0; |
| 2451 | |
| 2452 | cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2453 | E1000_TXD_CMD_TCP | (skb->len - (hdr_len))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2455 | i = tx_ring->next_to_use; |
| 2456 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2457 | buffer_info = &tx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | |
| 2459 | context_desc->lower_setup.ip_fields.ipcss = ipcss; |
| 2460 | context_desc->lower_setup.ip_fields.ipcso = ipcso; |
| 2461 | context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse); |
| 2462 | context_desc->upper_setup.tcp_fields.tucss = tucss; |
| 2463 | context_desc->upper_setup.tcp_fields.tucso = tucso; |
| 2464 | context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse); |
| 2465 | context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss); |
| 2466 | context_desc->tcp_seg_setup.fields.hdr_len = hdr_len; |
| 2467 | context_desc->cmd_and_length = cpu_to_le32(cmd_length); |
| 2468 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2469 | buffer_info->time_stamp = jiffies; |
| 2470 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2471 | if (++i == tx_ring->count) i = 0; |
| 2472 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2474 | return TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | } |
| 2476 | #endif |
| 2477 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 2478 | return FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | static inline boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2482 | e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2483 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { |
| 2485 | struct e1000_context_desc *context_desc; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2486 | struct e1000_buffer *buffer_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | unsigned int i; |
| 2488 | uint8_t css; |
| 2489 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2490 | if (likely(skb->ip_summed == CHECKSUM_HW)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | css = skb->h.raw - skb->data; |
| 2492 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2493 | i = tx_ring->next_to_use; |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2494 | buffer_info = &tx_ring->buffer_info[i]; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2495 | context_desc = E1000_CONTEXT_DESC(*tx_ring, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | |
| 2497 | context_desc->upper_setup.tcp_fields.tucss = css; |
| 2498 | context_desc->upper_setup.tcp_fields.tucso = css + skb->csum; |
| 2499 | context_desc->upper_setup.tcp_fields.tucse = 0; |
| 2500 | context_desc->tcp_seg_setup.data = 0; |
| 2501 | context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT); |
| 2502 | |
Jeff Kirsher | 545c67c | 2006-01-12 16:50:25 -0800 | [diff] [blame] | 2503 | buffer_info->time_stamp = jiffies; |
| 2504 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2505 | if (unlikely(++i == tx_ring->count)) i = 0; |
| 2506 | tx_ring->next_to_use = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
| 2508 | return TRUE; |
| 2509 | } |
| 2510 | |
| 2511 | return FALSE; |
| 2512 | } |
| 2513 | |
| 2514 | #define E1000_MAX_TXD_PWR 12 |
| 2515 | #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR) |
| 2516 | |
| 2517 | static inline int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2518 | e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2519 | struct sk_buff *skb, unsigned int first, unsigned int max_per_txd, |
| 2520 | unsigned int nr_frags, unsigned int mss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | struct e1000_buffer *buffer_info; |
| 2523 | unsigned int len = skb->len; |
| 2524 | unsigned int offset = 0, size, count = 0, i; |
| 2525 | unsigned int f; |
| 2526 | len -= skb->data_len; |
| 2527 | |
| 2528 | i = tx_ring->next_to_use; |
| 2529 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2530 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2531 | buffer_info = &tx_ring->buffer_info[i]; |
| 2532 | size = min(len, max_per_txd); |
| 2533 | #ifdef NETIF_F_TSO |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2534 | /* Workaround for Controller erratum -- |
| 2535 | * descriptor for non-tso packet in a linear SKB that follows a |
| 2536 | * tso gets written back prematurely before the data is fully |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2537 | * DMA'd to the controller */ |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2538 | if (!skb->data_len && tx_ring->last_tx_tso && |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2539 | !skb_shinfo(skb)->tso_size) { |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2540 | tx_ring->last_tx_tso = 0; |
| 2541 | size -= 4; |
| 2542 | } |
| 2543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | /* Workaround for premature desc write-backs |
| 2545 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2546 | if (unlikely(mss && !nr_frags && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | size -= 4; |
| 2548 | #endif |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2549 | /* work-around for errata 10 and it applies |
| 2550 | * to all controllers in PCI-X mode |
| 2551 | * The fix is to make sure that the first descriptor of a |
| 2552 | * packet is smaller than 2048 - 16 - 16 (or 2016) bytes |
| 2553 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2554 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2555 | (size > 2015) && count == 0)) |
| 2556 | size = 2015; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | /* Workaround for potential 82544 hang in PCI-X. Avoid |
| 2559 | * terminating buffers within evenly-aligned dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2560 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | !((unsigned long)(skb->data + offset + size - 1) & 4) && |
| 2562 | size > 4)) |
| 2563 | size -= 4; |
| 2564 | |
| 2565 | buffer_info->length = size; |
| 2566 | buffer_info->dma = |
| 2567 | pci_map_single(adapter->pdev, |
| 2568 | skb->data + offset, |
| 2569 | size, |
| 2570 | PCI_DMA_TODEVICE); |
| 2571 | buffer_info->time_stamp = jiffies; |
| 2572 | |
| 2573 | len -= size; |
| 2574 | offset += size; |
| 2575 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2576 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2579 | for (f = 0; f < nr_frags; f++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | struct skb_frag_struct *frag; |
| 2581 | |
| 2582 | frag = &skb_shinfo(skb)->frags[f]; |
| 2583 | len = frag->size; |
| 2584 | offset = frag->page_offset; |
| 2585 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2586 | while (len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | buffer_info = &tx_ring->buffer_info[i]; |
| 2588 | size = min(len, max_per_txd); |
| 2589 | #ifdef NETIF_F_TSO |
| 2590 | /* Workaround for premature desc write-backs |
| 2591 | * in TSO mode. Append 4-byte sentinel desc */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2592 | if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | size -= 4; |
| 2594 | #endif |
| 2595 | /* Workaround for potential 82544 hang in PCI-X. |
| 2596 | * Avoid terminating buffers within evenly-aligned |
| 2597 | * dwords. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2598 | if (unlikely(adapter->pcix_82544 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | !((unsigned long)(frag->page+offset+size-1) & 4) && |
| 2600 | size > 4)) |
| 2601 | size -= 4; |
| 2602 | |
| 2603 | buffer_info->length = size; |
| 2604 | buffer_info->dma = |
| 2605 | pci_map_page(adapter->pdev, |
| 2606 | frag->page, |
| 2607 | offset, |
| 2608 | size, |
| 2609 | PCI_DMA_TODEVICE); |
| 2610 | buffer_info->time_stamp = jiffies; |
| 2611 | |
| 2612 | len -= size; |
| 2613 | offset += size; |
| 2614 | count++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2615 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | i = (i == 0) ? tx_ring->count - 1 : i - 1; |
| 2620 | tx_ring->buffer_info[i].skb = skb; |
| 2621 | tx_ring->buffer_info[first].next_to_watch = i; |
| 2622 | |
| 2623 | return count; |
| 2624 | } |
| 2625 | |
| 2626 | static inline void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2627 | e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring, |
| 2628 | int tx_flags, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | struct e1000_tx_desc *tx_desc = NULL; |
| 2631 | struct e1000_buffer *buffer_info; |
| 2632 | uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS; |
| 2633 | unsigned int i; |
| 2634 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2635 | if (likely(tx_flags & E1000_TX_FLAGS_TSO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D | |
| 2637 | E1000_TXD_CMD_TSE; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2638 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 2639 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2640 | if (likely(tx_flags & E1000_TX_FLAGS_IPV4)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2641 | txd_upper |= E1000_TXD_POPTS_IXSM << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2644 | if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D; |
| 2646 | txd_upper |= E1000_TXD_POPTS_TXSM << 8; |
| 2647 | } |
| 2648 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2649 | if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | txd_lower |= E1000_TXD_CMD_VLE; |
| 2651 | txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK); |
| 2652 | } |
| 2653 | |
| 2654 | i = tx_ring->next_to_use; |
| 2655 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2656 | while (count--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | buffer_info = &tx_ring->buffer_info[i]; |
| 2658 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 2659 | tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 2660 | tx_desc->lower.data = |
| 2661 | cpu_to_le32(txd_lower | buffer_info->length); |
| 2662 | tx_desc->upper.data = cpu_to_le32(txd_upper); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2663 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd); |
| 2667 | |
| 2668 | /* Force memory writes to complete before letting h/w |
| 2669 | * know there are new descriptors to fetch. (Only |
| 2670 | * applicable for weak-ordered memory model archs, |
| 2671 | * such as IA-64). */ |
| 2672 | wmb(); |
| 2673 | |
| 2674 | tx_ring->next_to_use = i; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2675 | writel(i, adapter->hw.hw_addr + tx_ring->tdt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * 82547 workaround to avoid controller hang in half-duplex environment. |
| 2680 | * The workaround is to avoid queuing a large packet that would span |
| 2681 | * the internal Tx FIFO ring boundary by notifying the stack to resend |
| 2682 | * the packet at a later time. This gives the Tx FIFO an opportunity to |
| 2683 | * flush all packets. When that occurs, we reset the Tx FIFO pointers |
| 2684 | * to the beginning of the Tx FIFO. |
| 2685 | **/ |
| 2686 | |
| 2687 | #define E1000_FIFO_HDR 0x10 |
| 2688 | #define E1000_82547_PAD_LEN 0x3E0 |
| 2689 | |
| 2690 | static inline int |
| 2691 | e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 2692 | { |
| 2693 | uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head; |
| 2694 | uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR; |
| 2695 | |
| 2696 | E1000_ROUNDUP(skb_fifo_len, E1000_FIFO_HDR); |
| 2697 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2698 | if (adapter->link_duplex != HALF_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | goto no_fifo_stall_required; |
| 2700 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2701 | if (atomic_read(&adapter->tx_fifo_stall)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | return 1; |
| 2703 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2704 | if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | atomic_set(&adapter->tx_fifo_stall, 1); |
| 2706 | return 1; |
| 2707 | } |
| 2708 | |
| 2709 | no_fifo_stall_required: |
| 2710 | adapter->tx_fifo_head += skb_fifo_len; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2711 | if (adapter->tx_fifo_head >= adapter->tx_fifo_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | adapter->tx_fifo_head -= adapter->tx_fifo_size; |
| 2713 | return 0; |
| 2714 | } |
| 2715 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2716 | #define MINIMUM_DHCP_PACKET_SIZE 282 |
| 2717 | static inline int |
| 2718 | e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb) |
| 2719 | { |
| 2720 | struct e1000_hw *hw = &adapter->hw; |
| 2721 | uint16_t length, offset; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2722 | if (vlan_tx_tag_present(skb)) { |
| 2723 | if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) && |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2724 | ( adapter->hw.mng_cookie.status & |
| 2725 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) ) |
| 2726 | return 0; |
| 2727 | } |
Jeff Kirsher | 20a4402 | 2006-03-02 18:18:08 -0800 | [diff] [blame] | 2728 | if (skb->len > MINIMUM_DHCP_PACKET_SIZE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2729 | struct ethhdr *eth = (struct ethhdr *) skb->data; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2730 | if ((htons(ETH_P_IP) == eth->h_proto)) { |
| 2731 | const struct iphdr *ip = |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2732 | (struct iphdr *)((uint8_t *)skb->data+14); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2733 | if (IPPROTO_UDP == ip->protocol) { |
| 2734 | struct udphdr *udp = |
| 2735 | (struct udphdr *)((uint8_t *)ip + |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2736 | (ip->ihl << 2)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2737 | if (ntohs(udp->dest) == 67) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2738 | offset = (uint8_t *)udp + 8 - skb->data; |
| 2739 | length = skb->len - offset; |
| 2740 | |
| 2741 | return e1000_mng_write_dhcp_info(hw, |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2742 | (uint8_t *)udp + 8, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2743 | length); |
| 2744 | } |
| 2745 | } |
| 2746 | } |
| 2747 | } |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 ) |
| 2752 | static int |
| 2753 | e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 2754 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2755 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2756 | struct e1000_tx_ring *tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD; |
| 2758 | unsigned int max_txd_pwr = E1000_MAX_TXD_PWR; |
| 2759 | unsigned int tx_flags = 0; |
| 2760 | unsigned int len = skb->len; |
| 2761 | unsigned long flags; |
| 2762 | unsigned int nr_frags = 0; |
| 2763 | unsigned int mss = 0; |
| 2764 | int count = 0; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2765 | int tso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | unsigned int f; |
| 2767 | len -= skb->data_len; |
| 2768 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2769 | tx_ring = adapter->tx_ring; |
Mallikarjuna R Chilakala | 24025e4ec | 2005-10-04 07:03:23 -0400 | [diff] [blame] | 2770 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2771 | if (unlikely(skb->len <= 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | dev_kfree_skb_any(skb); |
| 2773 | return NETDEV_TX_OK; |
| 2774 | } |
| 2775 | |
| 2776 | #ifdef NETIF_F_TSO |
| 2777 | mss = skb_shinfo(skb)->tso_size; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2778 | /* The controller does a simple calculation to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | * make sure there is enough room in the FIFO before |
| 2780 | * initiating the DMA for each buffer. The calc is: |
| 2781 | * 4 = ceil(buffer len/mss). To make sure we don't |
| 2782 | * overrun the FIFO, adjust the max buffer len if mss |
| 2783 | * drops. */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2784 | if (mss) { |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2785 | uint8_t hdr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | max_per_txd = min(mss << 2, max_per_txd); |
| 2787 | max_txd_pwr = fls(max_per_txd) - 1; |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2788 | |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 2789 | /* TSO Workaround for 82571/2/3 Controllers -- if skb->data |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2790 | * points to just header, pull a few bytes of payload from |
| 2791 | * frags into skb->data */ |
| 2792 | hdr_len = ((skb->h.raw - skb->data) + (skb->h.th->doff << 2)); |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 2793 | if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) { |
| 2794 | switch (adapter->hw.mac_type) { |
| 2795 | unsigned int pull_size; |
| 2796 | case e1000_82571: |
| 2797 | case e1000_82572: |
| 2798 | case e1000_82573: |
| 2799 | pull_size = min((unsigned int)4, skb->data_len); |
| 2800 | if (!__pskb_pull_tail(skb, pull_size)) { |
| 2801 | printk(KERN_ERR |
| 2802 | "__pskb_pull_tail failed.\n"); |
| 2803 | dev_kfree_skb_any(skb); |
Jeff Garzik | 749dfc70 | 2006-03-11 13:35:31 -0500 | [diff] [blame] | 2804 | return NETDEV_TX_OK; |
Jeff Kirsher | 9f68788 | 2006-03-02 18:20:17 -0800 | [diff] [blame] | 2805 | } |
| 2806 | len = skb->len - skb->data_len; |
| 2807 | break; |
| 2808 | default: |
| 2809 | /* do nothing */ |
| 2810 | break; |
Jeff Kirsher | d74bbd3 | 2006-01-12 16:51:07 -0800 | [diff] [blame] | 2811 | } |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
Jeff Kirsher | 9a3056d | 2006-01-12 16:50:23 -0800 | [diff] [blame] | 2815 | /* reserve a descriptor for the offload context */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2816 | if ((mss) || (skb->ip_summed == CHECKSUM_HW)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | count++; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 2818 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2819 | #else |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2820 | if (skb->ip_summed == CHECKSUM_HW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | count++; |
| 2822 | #endif |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2823 | |
| 2824 | #ifdef NETIF_F_TSO |
| 2825 | /* Controller Erratum workaround */ |
| 2826 | if (!skb->data_len && tx_ring->last_tx_tso && |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2827 | !skb_shinfo(skb)->tso_size) |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2828 | count++; |
| 2829 | #endif |
| 2830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | count += TXD_USE_COUNT(len, max_txd_pwr); |
| 2832 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2833 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | count++; |
| 2835 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2836 | /* work-around for errata 10 and it applies to all controllers |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2837 | * in PCI-X mode, so add one more descriptor to the count |
| 2838 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2839 | if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) && |
Malli Chilakala | 97338bd | 2005-04-28 19:41:46 -0700 | [diff] [blame] | 2840 | (len > 2015))) |
| 2841 | count++; |
| 2842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | nr_frags = skb_shinfo(skb)->nr_frags; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2844 | for (f = 0; f < nr_frags; f++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size, |
| 2846 | max_txd_pwr); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2847 | if (adapter->pcix_82544) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | count += nr_frags; |
| 2849 | |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 2850 | |
| 2851 | if (adapter->hw.tx_pkt_filtering && |
| 2852 | (adapter->hw.mac_type == e1000_82573)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2853 | e1000_transfer_dhcp_info(adapter, skb); |
| 2854 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2855 | local_irq_save(flags); |
| 2856 | if (!spin_trylock(&tx_ring->tx_lock)) { |
| 2857 | /* Collision - tell upper layer to requeue */ |
| 2858 | local_irq_restore(flags); |
| 2859 | return NETDEV_TX_LOCKED; |
| 2860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | |
| 2862 | /* need: count + 2 desc gap to keep tail from touching |
| 2863 | * head, otherwise try next time */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2864 | if (unlikely(E1000_DESC_UNUSED(tx_ring) < count + 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | netif_stop_queue(netdev); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2866 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | return NETDEV_TX_BUSY; |
| 2868 | } |
| 2869 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2870 | if (unlikely(adapter->hw.mac_type == e1000_82547)) { |
| 2871 | if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | netif_stop_queue(netdev); |
| 2873 | mod_timer(&adapter->tx_fifo_stall_timer, jiffies); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2874 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | return NETDEV_TX_BUSY; |
| 2876 | } |
| 2877 | } |
| 2878 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2879 | if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | tx_flags |= E1000_TX_FLAGS_VLAN; |
| 2881 | tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT); |
| 2882 | } |
| 2883 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2884 | first = tx_ring->next_to_use; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2885 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2886 | tso = e1000_tso(adapter, tx_ring, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | if (tso < 0) { |
| 2888 | dev_kfree_skb_any(skb); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2889 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | return NETDEV_TX_OK; |
| 2891 | } |
| 2892 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2893 | if (likely(tso)) { |
| 2894 | tx_ring->last_tx_tso = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | tx_flags |= E1000_TX_FLAGS_TSO; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 2896 | } else if (likely(e1000_tx_csum(adapter, tx_ring, skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | tx_flags |= E1000_TX_FLAGS_CSUM; |
| 2898 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2899 | /* 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] | 2900 | * 82571 hardware supports TSO capabilities for IPv6 as well... |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2901 | * no longer assume, we must. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2902 | if (likely(skb->protocol == ntohs(ETH_P_IP))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2903 | tx_flags |= E1000_TX_FLAGS_IPV4; |
| 2904 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2905 | e1000_tx_queue(adapter, tx_ring, tx_flags, |
| 2906 | e1000_tx_map(adapter, tx_ring, skb, first, |
| 2907 | max_per_txd, nr_frags, mss)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | |
| 2909 | netdev->trans_start = jiffies; |
| 2910 | |
| 2911 | /* Make sure there is space in the ring for the next send. */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2912 | if (unlikely(E1000_DESC_UNUSED(tx_ring) < MAX_SKB_FRAGS + 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | netif_stop_queue(netdev); |
| 2914 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 2915 | spin_unlock_irqrestore(&tx_ring->tx_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | return NETDEV_TX_OK; |
| 2917 | } |
| 2918 | |
| 2919 | /** |
| 2920 | * e1000_tx_timeout - Respond to a Tx Hang |
| 2921 | * @netdev: network interface device structure |
| 2922 | **/ |
| 2923 | |
| 2924 | static void |
| 2925 | e1000_tx_timeout(struct net_device *netdev) |
| 2926 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2927 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
| 2929 | /* Do the reset outside of interrupt context */ |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2930 | adapter->tx_timeout_count++; |
| 2931 | schedule_work(&adapter->reset_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | static void |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 2935 | e1000_reset_task(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2937 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | |
| 2939 | e1000_down(adapter); |
| 2940 | e1000_up(adapter); |
| 2941 | } |
| 2942 | |
| 2943 | /** |
| 2944 | * e1000_get_stats - Get System Network Statistics |
| 2945 | * @netdev: network interface device structure |
| 2946 | * |
| 2947 | * Returns the address of the device statistics structure. |
| 2948 | * The statistics are actually updated from the timer callback. |
| 2949 | **/ |
| 2950 | |
| 2951 | static struct net_device_stats * |
| 2952 | e1000_get_stats(struct net_device *netdev) |
| 2953 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2954 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 2956 | /* only return the current stats */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | return &adapter->net_stats; |
| 2958 | } |
| 2959 | |
| 2960 | /** |
| 2961 | * e1000_change_mtu - Change the Maximum Transfer Unit |
| 2962 | * @netdev: network interface device structure |
| 2963 | * @new_mtu: new value for maximum frame size |
| 2964 | * |
| 2965 | * Returns 0 on success, negative on failure |
| 2966 | **/ |
| 2967 | |
| 2968 | static int |
| 2969 | e1000_change_mtu(struct net_device *netdev, int new_mtu) |
| 2970 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 2971 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 2973 | uint16_t eeprom_data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 2975 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 2976 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 2977 | DPRINTK(PROBE, ERR, "Invalid MTU setting\n"); |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 2978 | return -EINVAL; |
| 2979 | } |
| 2980 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2981 | /* Adapter-specific max frame size limits. */ |
| 2982 | switch (adapter->hw.mac_type) { |
| 2983 | case e1000_82542_rev2_0: |
| 2984 | case e1000_82542_rev2_1: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2985 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 2986 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n"); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2987 | return -EINVAL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 2988 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 2989 | break; |
Jeff Kirsher | 85b22eb | 2006-03-02 18:20:29 -0800 | [diff] [blame] | 2990 | case e1000_82573: |
| 2991 | /* only enable jumbo frames if ASPM is disabled completely |
| 2992 | * this means both bits must be zero in 0x1A bits 3:2 */ |
| 2993 | e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1, |
| 2994 | &eeprom_data); |
| 2995 | if (eeprom_data & EEPROM_WORD1A_ASPM_MASK) { |
| 2996 | if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) { |
| 2997 | DPRINTK(PROBE, ERR, |
| 2998 | "Jumbo Frames not supported.\n"); |
| 2999 | return -EINVAL; |
| 3000 | } |
| 3001 | break; |
| 3002 | } |
| 3003 | /* fall through to get support */ |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3004 | case e1000_82571: |
| 3005 | case e1000_82572: |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3006 | case e1000_80003es2lan: |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3007 | #define MAX_STD_JUMBO_FRAME_SIZE 9234 |
| 3008 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3009 | DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n"); |
| 3010 | return -EINVAL; |
| 3011 | } |
| 3012 | break; |
| 3013 | default: |
| 3014 | /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */ |
| 3015 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3018 | |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3019 | if (adapter->hw.mac_type > e1000_82547_rev_2) { |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3020 | adapter->rx_buffer_len = max_frame; |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3021 | E1000_ROUNDUP(adapter->rx_buffer_len, 1024); |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3022 | } else { |
| 3023 | if(unlikely((adapter->hw.mac_type < e1000_82543) && |
| 3024 | (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE))) { |
| 3025 | DPRINTK(PROBE, ERR, "Jumbo Frames not supported " |
| 3026 | "on 82542\n"); |
| 3027 | return -EINVAL; |
| 3028 | } else { |
| 3029 | if(max_frame <= E1000_RXBUFFER_2048) |
| 3030 | adapter->rx_buffer_len = E1000_RXBUFFER_2048; |
| 3031 | else if(max_frame <= E1000_RXBUFFER_4096) |
| 3032 | adapter->rx_buffer_len = E1000_RXBUFFER_4096; |
| 3033 | else if(max_frame <= E1000_RXBUFFER_8192) |
| 3034 | adapter->rx_buffer_len = E1000_RXBUFFER_8192; |
| 3035 | else if(max_frame <= E1000_RXBUFFER_16384) |
| 3036 | adapter->rx_buffer_len = E1000_RXBUFFER_16384; |
| 3037 | } |
| 3038 | } |
Jeff Kirsher | 997f5cb | 2006-01-12 16:50:55 -0800 | [diff] [blame] | 3039 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3040 | netdev->mtu = new_mtu; |
| 3041 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3042 | if (netif_running(netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | e1000_down(adapter); |
| 3044 | e1000_up(adapter); |
| 3045 | } |
| 3046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | adapter->hw.max_frame_size = max_frame; |
| 3048 | |
| 3049 | return 0; |
| 3050 | } |
| 3051 | |
| 3052 | /** |
| 3053 | * e1000_update_stats - Update the board statistics counters |
| 3054 | * @adapter: board private structure |
| 3055 | **/ |
| 3056 | |
| 3057 | void |
| 3058 | e1000_update_stats(struct e1000_adapter *adapter) |
| 3059 | { |
| 3060 | struct e1000_hw *hw = &adapter->hw; |
| 3061 | unsigned long flags; |
| 3062 | uint16_t phy_tmp; |
| 3063 | |
| 3064 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3065 | |
| 3066 | spin_lock_irqsave(&adapter->stats_lock, flags); |
| 3067 | |
| 3068 | /* these counters are modified from e1000_adjust_tbi_stats, |
| 3069 | * called from the interrupt context, so they must only |
| 3070 | * be written while holding adapter->stats_lock |
| 3071 | */ |
| 3072 | |
| 3073 | adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS); |
| 3074 | adapter->stats.gprc += E1000_READ_REG(hw, GPRC); |
| 3075 | adapter->stats.gorcl += E1000_READ_REG(hw, GORCL); |
| 3076 | adapter->stats.gorch += E1000_READ_REG(hw, GORCH); |
| 3077 | adapter->stats.bprc += E1000_READ_REG(hw, BPRC); |
| 3078 | adapter->stats.mprc += E1000_READ_REG(hw, MPRC); |
| 3079 | adapter->stats.roc += E1000_READ_REG(hw, ROC); |
| 3080 | adapter->stats.prc64 += E1000_READ_REG(hw, PRC64); |
| 3081 | adapter->stats.prc127 += E1000_READ_REG(hw, PRC127); |
| 3082 | adapter->stats.prc255 += E1000_READ_REG(hw, PRC255); |
| 3083 | adapter->stats.prc511 += E1000_READ_REG(hw, PRC511); |
| 3084 | adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023); |
| 3085 | adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522); |
| 3086 | |
| 3087 | adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS); |
| 3088 | adapter->stats.mpc += E1000_READ_REG(hw, MPC); |
| 3089 | adapter->stats.scc += E1000_READ_REG(hw, SCC); |
| 3090 | adapter->stats.ecol += E1000_READ_REG(hw, ECOL); |
| 3091 | adapter->stats.mcc += E1000_READ_REG(hw, MCC); |
| 3092 | adapter->stats.latecol += E1000_READ_REG(hw, LATECOL); |
| 3093 | adapter->stats.dc += E1000_READ_REG(hw, DC); |
| 3094 | adapter->stats.sec += E1000_READ_REG(hw, SEC); |
| 3095 | adapter->stats.rlec += E1000_READ_REG(hw, RLEC); |
| 3096 | adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC); |
| 3097 | adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC); |
| 3098 | adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC); |
| 3099 | adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC); |
| 3100 | adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC); |
| 3101 | adapter->stats.gptc += E1000_READ_REG(hw, GPTC); |
| 3102 | adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL); |
| 3103 | adapter->stats.gotch += E1000_READ_REG(hw, GOTCH); |
| 3104 | adapter->stats.rnbc += E1000_READ_REG(hw, RNBC); |
| 3105 | adapter->stats.ruc += E1000_READ_REG(hw, RUC); |
| 3106 | adapter->stats.rfc += E1000_READ_REG(hw, RFC); |
| 3107 | adapter->stats.rjc += E1000_READ_REG(hw, RJC); |
| 3108 | adapter->stats.torl += E1000_READ_REG(hw, TORL); |
| 3109 | adapter->stats.torh += E1000_READ_REG(hw, TORH); |
| 3110 | adapter->stats.totl += E1000_READ_REG(hw, TOTL); |
| 3111 | adapter->stats.toth += E1000_READ_REG(hw, TOTH); |
| 3112 | adapter->stats.tpr += E1000_READ_REG(hw, TPR); |
| 3113 | adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64); |
| 3114 | adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127); |
| 3115 | adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255); |
| 3116 | adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511); |
| 3117 | adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023); |
| 3118 | adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522); |
| 3119 | adapter->stats.mptc += E1000_READ_REG(hw, MPTC); |
| 3120 | adapter->stats.bptc += E1000_READ_REG(hw, BPTC); |
| 3121 | |
| 3122 | /* used for adaptive IFS */ |
| 3123 | |
| 3124 | hw->tx_packet_delta = E1000_READ_REG(hw, TPT); |
| 3125 | adapter->stats.tpt += hw->tx_packet_delta; |
| 3126 | hw->collision_delta = E1000_READ_REG(hw, COLC); |
| 3127 | adapter->stats.colc += hw->collision_delta; |
| 3128 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3129 | if (hw->mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC); |
| 3131 | adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC); |
| 3132 | adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS); |
| 3133 | adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR); |
| 3134 | adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC); |
| 3135 | adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC); |
| 3136 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3137 | if (hw->mac_type > e1000_82547_rev_2) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3138 | adapter->stats.iac += E1000_READ_REG(hw, IAC); |
| 3139 | adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC); |
| 3140 | adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC); |
| 3141 | adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC); |
| 3142 | adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC); |
| 3143 | adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC); |
| 3144 | adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC); |
| 3145 | adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC); |
| 3146 | adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC); |
| 3147 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
| 3149 | /* Fill out the OS statistics structure */ |
| 3150 | |
| 3151 | adapter->net_stats.rx_packets = adapter->stats.gprc; |
| 3152 | adapter->net_stats.tx_packets = adapter->stats.gptc; |
| 3153 | adapter->net_stats.rx_bytes = adapter->stats.gorcl; |
| 3154 | adapter->net_stats.tx_bytes = adapter->stats.gotcl; |
| 3155 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3156 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3157 | |
| 3158 | /* Rx Errors */ |
| 3159 | |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3160 | /* RLEC on some newer hardware can be incorrect so build |
| 3161 | * our own version based on RUC and ROC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3163 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3164 | adapter->stats.ruc + adapter->stats.roc + |
| 3165 | adapter->stats.cexterr; |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 3166 | adapter->net_stats.rx_dropped = 0; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3167 | adapter->net_stats.rx_length_errors = adapter->stats.ruc + |
| 3168 | adapter->stats.roc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3170 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3172 | |
| 3173 | /* Tx Errors */ |
| 3174 | |
| 3175 | adapter->net_stats.tx_errors = adapter->stats.ecol + |
| 3176 | adapter->stats.latecol; |
| 3177 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3178 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3179 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
| 3180 | |
| 3181 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3182 | |
| 3183 | /* Phy Stats */ |
| 3184 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3185 | if (hw->media_type == e1000_media_type_copper) { |
| 3186 | if ((adapter->link_speed == SPEED_1000) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
| 3188 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3189 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3190 | } |
| 3191 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3192 | if ((hw->mac_type <= e1000_82546) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | (hw->phy_type == e1000_phy_m88) && |
| 3194 | !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp)) |
| 3195 | adapter->phy_stats.receive_errors += phy_tmp; |
| 3196 | } |
| 3197 | |
| 3198 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
| 3199 | } |
| 3200 | |
| 3201 | /** |
| 3202 | * e1000_intr - Interrupt Handler |
| 3203 | * @irq: interrupt number |
| 3204 | * @data: pointer to a network interface device structure |
| 3205 | * @pt_regs: CPU registers structure |
| 3206 | **/ |
| 3207 | |
| 3208 | static irqreturn_t |
| 3209 | e1000_intr(int irq, void *data, struct pt_regs *regs) |
| 3210 | { |
| 3211 | struct net_device *netdev = data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 3212 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3214 | uint32_t rctl, icr = E1000_READ_REG(hw, ICR); |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3215 | #ifndef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3216 | int i; |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3217 | #else |
| 3218 | /* Interrupt Auto-Mask...upon reading ICR, |
| 3219 | * interrupts are masked. No need for the |
| 3220 | * IMC write, but it does mean we should |
| 3221 | * account for it ASAP. */ |
| 3222 | if (likely(hw->mac_type >= e1000_82571)) |
| 3223 | atomic_inc(&adapter->irq_sem); |
Jeff Garzik | be2b28e | 2005-10-04 07:13:43 -0400 | [diff] [blame] | 3224 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3226 | if (unlikely(!icr)) { |
| 3227 | #ifdef CONFIG_E1000_NAPI |
| 3228 | if (hw->mac_type >= e1000_82571) |
| 3229 | e1000_irq_enable(adapter); |
| 3230 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | return IRQ_NONE; /* Not our interrupt */ |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3234 | if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | hw->get_link_status = 1; |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 3236 | /* 80003ES2LAN workaround-- |
| 3237 | * For packet buffer work-around on link down event; |
| 3238 | * disable receives here in the ISR and |
| 3239 | * reset adapter in watchdog |
| 3240 | */ |
| 3241 | if (netif_carrier_ok(netdev) && |
| 3242 | (adapter->hw.mac_type == e1000_80003es2lan)) { |
| 3243 | /* disable receives */ |
| 3244 | rctl = E1000_READ_REG(hw, RCTL); |
| 3245 | E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 3246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 3248 | } |
| 3249 | |
| 3250 | #ifdef CONFIG_E1000_NAPI |
Jeff Kirsher | 1e613fd | 2006-01-12 16:51:16 -0800 | [diff] [blame] | 3251 | if (unlikely(hw->mac_type < e1000_82571)) { |
| 3252 | atomic_inc(&adapter->irq_sem); |
| 3253 | E1000_WRITE_REG(hw, IMC, ~0); |
| 3254 | E1000_WRITE_FLUSH(hw); |
| 3255 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3256 | if (likely(netif_rx_schedule_prep(&adapter->polling_netdev[0]))) |
| 3257 | __netif_rx_schedule(&adapter->polling_netdev[0]); |
| 3258 | else |
| 3259 | e1000_irq_enable(adapter); |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3260 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | /* Writing IMC and IMS is needed for 82547. |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3262 | * Due to Hub Link bus being occupied, an interrupt |
| 3263 | * de-assertion message is not able to be sent. |
| 3264 | * When an interrupt assertion message is generated later, |
| 3265 | * two messages are re-ordered and sent out. |
| 3266 | * That causes APIC to think 82547 is in de-assertion |
| 3267 | * state, while 82547 is in assertion state, resulting |
| 3268 | * in dead lock. Writing IMC forces 82547 into |
| 3269 | * de-assertion state. |
| 3270 | */ |
| 3271 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | atomic_inc(&adapter->irq_sem); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3273 | E1000_WRITE_REG(hw, IMC, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3276 | for (i = 0; i < E1000_MAX_INTR; i++) |
| 3277 | if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) & |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3278 | !e1000_clean_tx_irq(adapter, adapter->tx_ring))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | break; |
| 3280 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3281 | if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | e1000_irq_enable(adapter); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3283 | |
Jeff Kirsher | c1605eb | 2006-03-02 18:16:38 -0800 | [diff] [blame] | 3284 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | |
| 3286 | return IRQ_HANDLED; |
| 3287 | } |
| 3288 | |
| 3289 | #ifdef CONFIG_E1000_NAPI |
| 3290 | /** |
| 3291 | * e1000_clean - NAPI Rx polling callback |
| 3292 | * @adapter: board private structure |
| 3293 | **/ |
| 3294 | |
| 3295 | static int |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3296 | e1000_clean(struct net_device *poll_dev, int *budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3298 | struct e1000_adapter *adapter; |
| 3299 | int work_to_do = min(*budget, poll_dev->quota); |
Jeff Kirsher | 38bd3b2 | 2006-01-12 16:51:37 -0800 | [diff] [blame] | 3300 | int tx_cleaned = 0, i = 0, work_done = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3301 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3302 | /* Must NOT use netdev_priv macro here. */ |
| 3303 | adapter = poll_dev->priv; |
| 3304 | |
| 3305 | /* Keep link state information with original netdev */ |
| 3306 | if (!netif_carrier_ok(adapter->netdev)) |
| 3307 | goto quit_polling; |
| 3308 | |
| 3309 | while (poll_dev != &adapter->polling_netdev[i]) { |
| 3310 | i++; |
Eric Sesterhenn | 5d9428d | 2006-04-02 13:52:48 +0200 | [diff] [blame] | 3311 | BUG_ON(i == adapter->num_rx_queues); |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3312 | } |
| 3313 | |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 3314 | if (likely(adapter->num_tx_queues == 1)) { |
| 3315 | /* e1000_clean is called per-cpu. This lock protects |
| 3316 | * tx_ring[0] from being cleaned by multiple cpus |
| 3317 | * simultaneously. A failure obtaining the lock means |
| 3318 | * tx_ring[0] is currently being cleaned anyway. */ |
| 3319 | if (spin_trylock(&adapter->tx_queue_lock)) { |
| 3320 | tx_cleaned = e1000_clean_tx_irq(adapter, |
| 3321 | &adapter->tx_ring[0]); |
| 3322 | spin_unlock(&adapter->tx_queue_lock); |
| 3323 | } |
| 3324 | } else |
| 3325 | tx_cleaned = e1000_clean_tx_irq(adapter, &adapter->tx_ring[i]); |
| 3326 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3327 | adapter->clean_rx(adapter, &adapter->rx_ring[i], |
| 3328 | &work_done, work_to_do); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | |
| 3330 | *budget -= work_done; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3331 | poll_dev->quota -= work_done; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3332 | |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 3333 | /* If no Tx and not enough Rx work done, exit the polling mode */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3334 | if ((!tx_cleaned && (work_done == 0)) || |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3335 | !netif_running(adapter->netdev)) { |
| 3336 | quit_polling: |
| 3337 | netif_rx_complete(poll_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | e1000_irq_enable(adapter); |
| 3339 | return 0; |
| 3340 | } |
| 3341 | |
| 3342 | return 1; |
| 3343 | } |
| 3344 | |
| 3345 | #endif |
| 3346 | /** |
| 3347 | * e1000_clean_tx_irq - Reclaim resources after transmit completes |
| 3348 | * @adapter: board private structure |
| 3349 | **/ |
| 3350 | |
| 3351 | static boolean_t |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3352 | e1000_clean_tx_irq(struct e1000_adapter *adapter, |
| 3353 | struct e1000_tx_ring *tx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | struct net_device *netdev = adapter->netdev; |
| 3356 | struct e1000_tx_desc *tx_desc, *eop_desc; |
| 3357 | struct e1000_buffer *buffer_info; |
| 3358 | unsigned int i, eop; |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3359 | #ifdef CONFIG_E1000_NAPI |
| 3360 | unsigned int count = 0; |
| 3361 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | boolean_t cleaned = FALSE; |
| 3363 | |
| 3364 | i = tx_ring->next_to_clean; |
| 3365 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3366 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
| 3367 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3368 | while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3369 | for (cleaned = FALSE; !cleaned; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 3371 | buffer_info = &tx_ring->buffer_info[i]; |
| 3372 | cleaned = (i == eop); |
| 3373 | |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 3374 | e1000_unmap_and_free_tx_resource(adapter, buffer_info); |
Jeff Kirsher | 8241e35 | 2006-01-12 16:51:34 -0800 | [diff] [blame] | 3375 | memset(tx_desc, 0, sizeof(struct e1000_tx_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3377 | if (unlikely(++i == tx_ring->count)) i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | } |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3379 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 3382 | eop_desc = E1000_TX_DESC(*tx_ring, eop); |
Jeff Kirsher | 2a1af5d | 2006-03-02 18:20:43 -0800 | [diff] [blame] | 3383 | #ifdef CONFIG_E1000_NAPI |
| 3384 | #define E1000_TX_WEIGHT 64 |
| 3385 | /* weight of a sort for tx, to avoid endless transmit cleanup */ |
| 3386 | if (count++ == E1000_TX_WEIGHT) break; |
| 3387 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | tx_ring->next_to_clean = i; |
| 3391 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3392 | spin_lock(&tx_ring->tx_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3394 | if (unlikely(cleaned && netif_queue_stopped(netdev) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | netif_carrier_ok(netdev))) |
| 3396 | netif_wake_queue(netdev); |
| 3397 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3398 | spin_unlock(&tx_ring->tx_lock); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3399 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3400 | if (adapter->detect_tx_hung) { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3401 | /* Detect a transmit hang in hardware, this serializes the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | * check with the clearing of time_stamp and movement of i */ |
| 3403 | adapter->detect_tx_hung = FALSE; |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3404 | if (tx_ring->buffer_info[eop].dma && |
| 3405 | time_after(jiffies, tx_ring->buffer_info[eop].time_stamp + |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 3406 | (adapter->tx_timeout_factor * HZ)) |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3407 | && !(E1000_READ_REG(&adapter->hw, STATUS) & |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3408 | E1000_STATUS_TXOFF)) { |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3409 | |
| 3410 | /* detected Tx unit hang */ |
Malli Chilakala | c6963ef | 2005-06-17 17:42:07 -0700 | [diff] [blame] | 3411 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3412 | " Tx Queue <%lu>\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3413 | " TDH <%x>\n" |
| 3414 | " TDT <%x>\n" |
| 3415 | " next_to_use <%x>\n" |
| 3416 | " next_to_clean <%x>\n" |
| 3417 | "buffer_info[next_to_clean]\n" |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3418 | " time_stamp <%lx>\n" |
| 3419 | " next_to_watch <%x>\n" |
| 3420 | " jiffies <%lx>\n" |
| 3421 | " next_to_watch.status <%x>\n", |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 3422 | (unsigned long)((tx_ring - adapter->tx_ring) / |
| 3423 | sizeof(struct e1000_tx_ring)), |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3424 | readl(adapter->hw.hw_addr + tx_ring->tdh), |
| 3425 | readl(adapter->hw.hw_addr + tx_ring->tdt), |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3426 | tx_ring->next_to_use, |
Jeff Kirsher | 392137f | 2006-01-12 16:50:57 -0800 | [diff] [blame] | 3427 | tx_ring->next_to_clean, |
| 3428 | tx_ring->buffer_info[eop].time_stamp, |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3429 | eop, |
| 3430 | jiffies, |
| 3431 | eop_desc->upper.fields.status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | netif_stop_queue(netdev); |
Malli Chilakala | 70b8f1e | 2005-04-28 19:40:40 -0700 | [diff] [blame] | 3433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | return cleaned; |
| 3436 | } |
| 3437 | |
| 3438 | /** |
| 3439 | * e1000_rx_checksum - Receive Checksum Offload for 82543 |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3440 | * @adapter: board private structure |
| 3441 | * @status_err: receive descriptor status and error fields |
| 3442 | * @csum: receive descriptor csum field |
| 3443 | * @sk_buff: socket buffer with received data |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | **/ |
| 3445 | |
| 3446 | static inline void |
| 3447 | e1000_rx_checksum(struct e1000_adapter *adapter, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3448 | uint32_t status_err, uint32_t csum, |
| 3449 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3451 | uint16_t status = (uint16_t)status_err; |
| 3452 | uint8_t errors = (uint8_t)(status_err >> 24); |
| 3453 | skb->ip_summed = CHECKSUM_NONE; |
| 3454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | /* 82543 or newer only */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3456 | if (unlikely(adapter->hw.mac_type < e1000_82543)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | /* Ignore Checksum bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3458 | if (unlikely(status & E1000_RXD_STAT_IXSM)) return; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3459 | /* TCP/UDP checksum error bit is set */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3460 | if (unlikely(errors & E1000_RXD_ERR_TCPE)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3461 | /* let the stack verify checksum errors */ |
| 3462 | adapter->hw_csum_err++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | return; |
| 3464 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3465 | /* TCP/UDP Checksum has not been calculated */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3466 | if (adapter->hw.mac_type <= e1000_82547_rev_2) { |
| 3467 | if (!(status & E1000_RXD_STAT_TCPCS)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3468 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | } else { |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3470 | if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3471 | return; |
| 3472 | } |
| 3473 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 3474 | if (likely(status & E1000_RXD_STAT_TCPCS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3475 | /* TCP checksum is good */ |
| 3476 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3477 | } else if (adapter->hw.mac_type > e1000_82547_rev_2) { |
| 3478 | /* IP fragment with UDP payload */ |
| 3479 | /* Hardware complements the payload checksum, so we undo it |
| 3480 | * and then put the value in host order for further stack use. |
| 3481 | */ |
| 3482 | csum = ntohl(csum ^ 0xFFFF); |
| 3483 | skb->csum = csum; |
| 3484 | skb->ip_summed = CHECKSUM_HW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3486 | adapter->hw_csum_good++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3490 | * e1000_clean_rx_irq - Send received data up the network stack; legacy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | * @adapter: board private structure |
| 3492 | **/ |
| 3493 | |
| 3494 | static boolean_t |
| 3495 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3496 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 3497 | struct e1000_rx_ring *rx_ring, |
| 3498 | int *work_done, int work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3500 | e1000_clean_rx_irq(struct e1000_adapter *adapter, |
| 3501 | struct e1000_rx_ring *rx_ring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | #endif |
| 3503 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | struct net_device *netdev = adapter->netdev; |
| 3505 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3506 | struct e1000_rx_desc *rx_desc, *next_rxd; |
| 3507 | struct e1000_buffer *buffer_info, *next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | unsigned long flags; |
| 3509 | uint32_t length; |
| 3510 | uint8_t last_byte; |
| 3511 | unsigned int i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3512 | int cleaned_count = 0; |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3513 | boolean_t cleaned = FALSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | |
| 3515 | i = rx_ring->next_to_clean; |
| 3516 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3517 | buffer_info = &rx_ring->buffer_info[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3519 | while (rx_desc->status & E1000_RXD_STAT_DD) { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3520 | struct sk_buff *skb, *next_skb; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3521 | u8 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3523 | if (*work_done >= work_to_do) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | break; |
| 3525 | (*work_done)++; |
| 3526 | #endif |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3527 | status = rx_desc->status; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3528 | skb = buffer_info->skb; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3529 | buffer_info->skb = NULL; |
| 3530 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3531 | prefetch(skb->data - NET_IP_ALIGN); |
| 3532 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3533 | if (++i == rx_ring->count) i = 0; |
| 3534 | next_rxd = E1000_RX_DESC(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3535 | prefetch(next_rxd); |
| 3536 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3537 | next_buffer = &rx_ring->buffer_info[i]; |
| 3538 | next_skb = next_buffer->skb; |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3539 | prefetch(next_skb->data - NET_IP_ALIGN); |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3540 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3541 | cleaned = TRUE; |
| 3542 | cleaned_count++; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3543 | pci_unmap_single(pdev, |
| 3544 | buffer_info->dma, |
| 3545 | buffer_info->length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | PCI_DMA_FROMDEVICE); |
| 3547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | length = le16_to_cpu(rx_desc->length); |
| 3549 | |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3550 | if (unlikely(!(status & E1000_RXD_STAT_EOP))) { |
| 3551 | /* All receives must fit into a single buffer */ |
| 3552 | E1000_DBG("%s: Receive packet consumed multiple" |
| 3553 | " buffers\n", netdev->name); |
| 3554 | dev_kfree_skb_irq(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | goto next_desc; |
| 3556 | } |
| 3557 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3558 | if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | last_byte = *(skb->data + length - 1); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3560 | if (TBI_ACCEPT(&adapter->hw, status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | rx_desc->errors, length, last_byte)) { |
| 3562 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3563 | e1000_tbi_adjust_stats(&adapter->hw, |
| 3564 | &adapter->stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | length, skb->data); |
| 3566 | spin_unlock_irqrestore(&adapter->stats_lock, |
| 3567 | flags); |
| 3568 | length--; |
| 3569 | } else { |
| 3570 | dev_kfree_skb_irq(skb); |
| 3571 | goto next_desc; |
| 3572 | } |
| 3573 | } |
| 3574 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3575 | /* code added for copybreak, this should improve |
| 3576 | * performance for small packets with large amounts |
| 3577 | * of reassembly being done in the stack */ |
| 3578 | #define E1000_CB_LENGTH 256 |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3579 | if (length < E1000_CB_LENGTH) { |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3580 | struct sk_buff *new_skb = |
| 3581 | dev_alloc_skb(length + NET_IP_ALIGN); |
| 3582 | if (new_skb) { |
| 3583 | skb_reserve(new_skb, NET_IP_ALIGN); |
| 3584 | new_skb->dev = netdev; |
| 3585 | memcpy(new_skb->data - NET_IP_ALIGN, |
| 3586 | skb->data - NET_IP_ALIGN, |
| 3587 | length + NET_IP_ALIGN); |
| 3588 | /* save the skb in buffer_info as good */ |
| 3589 | buffer_info->skb = skb; |
| 3590 | skb = new_skb; |
| 3591 | skb_put(skb, length); |
| 3592 | } |
Jeff Kirsher | a1415ee | 2006-02-28 20:24:07 -0800 | [diff] [blame] | 3593 | } else |
| 3594 | skb_put(skb, length); |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3595 | |
| 3596 | /* end copybreak code */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | |
| 3598 | /* Receive Checksum Offload */ |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3599 | e1000_rx_checksum(adapter, |
| 3600 | (uint32_t)(status) | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3601 | ((uint32_t)(rx_desc->errors) << 24), |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 3602 | le16_to_cpu(rx_desc->csum), skb); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | skb->protocol = eth_type_trans(skb, netdev); |
| 3605 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3606 | if (unlikely(adapter->vlgrp && |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3607 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3609 | le16_to_cpu(rx_desc->special) & |
| 3610 | E1000_RXD_SPC_VLAN_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | } else { |
| 3612 | netif_receive_skb(skb); |
| 3613 | } |
| 3614 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3615 | if (unlikely(adapter->vlgrp && |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3616 | (status & E1000_RXD_STAT_VP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
| 3618 | le16_to_cpu(rx_desc->special) & |
| 3619 | E1000_RXD_SPC_VLAN_MASK); |
| 3620 | } else { |
| 3621 | netif_rx(skb); |
| 3622 | } |
| 3623 | #endif /* CONFIG_E1000_NAPI */ |
| 3624 | netdev->last_rx = jiffies; |
| 3625 | |
| 3626 | next_desc: |
| 3627 | rx_desc->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3629 | /* return some buffers to hardware, one at a time is too slow */ |
| 3630 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 3631 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 3632 | cleaned_count = 0; |
| 3633 | } |
| 3634 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3635 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3636 | rx_desc = next_rxd; |
| 3637 | buffer_info = next_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3640 | |
| 3641 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 3642 | if (cleaned_count) |
| 3643 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | |
| 3645 | return cleaned; |
| 3646 | } |
| 3647 | |
| 3648 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3649 | * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split |
| 3650 | * @adapter: board private structure |
| 3651 | **/ |
| 3652 | |
| 3653 | static boolean_t |
| 3654 | #ifdef CONFIG_E1000_NAPI |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3655 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 3656 | struct e1000_rx_ring *rx_ring, |
| 3657 | int *work_done, int work_to_do) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3658 | #else |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3659 | e1000_clean_rx_irq_ps(struct e1000_adapter *adapter, |
| 3660 | struct e1000_rx_ring *rx_ring) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3661 | #endif |
| 3662 | { |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3663 | union e1000_rx_desc_packet_split *rx_desc, *next_rxd; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3664 | struct net_device *netdev = adapter->netdev; |
| 3665 | struct pci_dev *pdev = adapter->pdev; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3666 | struct e1000_buffer *buffer_info, *next_buffer; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3667 | struct e1000_ps_page *ps_page; |
| 3668 | struct e1000_ps_page_dma *ps_page_dma; |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3669 | struct sk_buff *skb, *next_skb; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3670 | unsigned int i, j; |
| 3671 | uint32_t length, staterr; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3672 | int cleaned_count = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3673 | boolean_t cleaned = FALSE; |
| 3674 | |
| 3675 | i = rx_ring->next_to_clean; |
| 3676 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3677 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3678 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3679 | while (staterr & E1000_RXD_STAT_DD) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3680 | buffer_info = &rx_ring->buffer_info[i]; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3681 | ps_page = &rx_ring->ps_page[i]; |
| 3682 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 3683 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3684 | if (unlikely(*work_done >= work_to_do)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3685 | break; |
| 3686 | (*work_done)++; |
| 3687 | #endif |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3688 | skb = buffer_info->skb; |
| 3689 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3690 | /* in the packet split case this is header only */ |
| 3691 | prefetch(skb->data - NET_IP_ALIGN); |
| 3692 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3693 | if (++i == rx_ring->count) i = 0; |
| 3694 | next_rxd = E1000_RX_DESC_PS(*rx_ring, i); |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3695 | prefetch(next_rxd); |
| 3696 | |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3697 | next_buffer = &rx_ring->buffer_info[i]; |
| 3698 | next_skb = next_buffer->skb; |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3699 | prefetch(next_skb->data - NET_IP_ALIGN); |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3700 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3701 | cleaned = TRUE; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3702 | cleaned_count++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3703 | pci_unmap_single(pdev, buffer_info->dma, |
| 3704 | buffer_info->length, |
| 3705 | PCI_DMA_FROMDEVICE); |
| 3706 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3707 | if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3708 | E1000_DBG("%s: Packet Split buffers didn't pick up" |
| 3709 | " the full packet\n", netdev->name); |
| 3710 | dev_kfree_skb_irq(skb); |
| 3711 | goto next_desc; |
| 3712 | } |
| 3713 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3714 | if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3715 | dev_kfree_skb_irq(skb); |
| 3716 | goto next_desc; |
| 3717 | } |
| 3718 | |
| 3719 | length = le16_to_cpu(rx_desc->wb.middle.length0); |
| 3720 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3721 | if (unlikely(!length)) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3722 | E1000_DBG("%s: Last part of the packet spanning" |
| 3723 | " multiple descriptors\n", netdev->name); |
| 3724 | dev_kfree_skb_irq(skb); |
| 3725 | goto next_desc; |
| 3726 | } |
| 3727 | |
| 3728 | /* Good Receive */ |
| 3729 | skb_put(skb, length); |
| 3730 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 3731 | { |
| 3732 | /* this looks ugly, but it seems compiler issues make it |
| 3733 | more efficient than reusing j */ |
| 3734 | int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]); |
| 3735 | |
| 3736 | /* page alloc/put takes too long and effects small packet |
| 3737 | * throughput, so unsplit small packets and save the alloc/put*/ |
| 3738 | if (l1 && ((length + l1) < E1000_CB_LENGTH)) { |
| 3739 | u8 *vaddr; |
| 3740 | /* there is no documentation about how to call |
| 3741 | * kmap_atomic, so we can't hold the mapping |
| 3742 | * very long */ |
| 3743 | pci_dma_sync_single_for_cpu(pdev, |
| 3744 | ps_page_dma->ps_page_dma[0], |
| 3745 | PAGE_SIZE, |
| 3746 | PCI_DMA_FROMDEVICE); |
| 3747 | vaddr = kmap_atomic(ps_page->ps_page[0], |
| 3748 | KM_SKB_DATA_SOFTIRQ); |
| 3749 | memcpy(skb->tail, vaddr, l1); |
| 3750 | kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ); |
| 3751 | pci_dma_sync_single_for_device(pdev, |
| 3752 | ps_page_dma->ps_page_dma[0], |
| 3753 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 3754 | skb_put(skb, l1); |
| 3755 | length += l1; |
| 3756 | goto copydone; |
| 3757 | } /* if */ |
| 3758 | } |
| 3759 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3760 | for (j = 0; j < adapter->rx_ps_pages; j++) { |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3761 | if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j]))) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3762 | break; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3763 | pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j], |
| 3764 | PAGE_SIZE, PCI_DMA_FROMDEVICE); |
| 3765 | ps_page_dma->ps_page_dma[j] = 0; |
Jeff Kirsher | 329bfd0 | 2006-03-02 18:20:02 -0800 | [diff] [blame] | 3766 | skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0, |
| 3767 | length); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3768 | ps_page->ps_page[j] = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3769 | skb->len += length; |
| 3770 | skb->data_len += length; |
Auke Kok | bcb4919 | 2006-04-25 22:50:04 -0700 | [diff] [blame^] | 3771 | skb->truesize += length; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
Jeff Kirsher | dc7c6ad | 2006-03-02 18:21:40 -0800 | [diff] [blame] | 3774 | copydone: |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3775 | e1000_rx_checksum(adapter, staterr, |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 3776 | le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3777 | skb->protocol = eth_type_trans(skb, netdev); |
| 3778 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3779 | if (likely(rx_desc->wb.upper.header_status & |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 3780 | cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))) |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3781 | adapter->rx_hdr_split++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3782 | #ifdef CONFIG_E1000_NAPI |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3783 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3784 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3785 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 3786 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3787 | } else { |
| 3788 | netif_receive_skb(skb); |
| 3789 | } |
| 3790 | #else /* CONFIG_E1000_NAPI */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3791 | if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3792 | vlan_hwaccel_rx(skb, adapter->vlgrp, |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3793 | le16_to_cpu(rx_desc->wb.middle.vlan) & |
| 3794 | E1000_RXD_SPC_VLAN_MASK); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3795 | } else { |
| 3796 | netif_rx(skb); |
| 3797 | } |
| 3798 | #endif /* CONFIG_E1000_NAPI */ |
| 3799 | netdev->last_rx = jiffies; |
| 3800 | |
| 3801 | next_desc: |
David S. Miller | c3d7a3a | 2006-03-15 14:26:28 -0800 | [diff] [blame] | 3802 | rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3803 | buffer_info->skb = NULL; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3804 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3805 | /* return some buffers to hardware, one at a time is too slow */ |
| 3806 | if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) { |
| 3807 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
| 3808 | cleaned_count = 0; |
| 3809 | } |
| 3810 | |
Jeff Kirsher | 30320be | 2006-03-02 18:21:57 -0800 | [diff] [blame] | 3811 | /* use prefetched values */ |
Jesse Brandeburg | 86c3d59 | 2006-01-18 13:01:43 -0800 | [diff] [blame] | 3812 | rx_desc = next_rxd; |
| 3813 | buffer_info = next_buffer; |
| 3814 | |
Malli Chilakala | 683a38f | 2005-06-17 17:43:25 -0700 | [diff] [blame] | 3815 | staterr = le32_to_cpu(rx_desc->wb.middle.status_error); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3816 | } |
| 3817 | rx_ring->next_to_clean = i; |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3818 | |
| 3819 | cleaned_count = E1000_DESC_UNUSED(rx_ring); |
| 3820 | if (cleaned_count) |
| 3821 | adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3822 | |
| 3823 | return cleaned; |
| 3824 | } |
| 3825 | |
| 3826 | /** |
| 3827 | * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | * @adapter: address of board private structure |
| 3829 | **/ |
| 3830 | |
| 3831 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3832 | e1000_alloc_rx_buffers(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3833 | struct e1000_rx_ring *rx_ring, |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3834 | int cleaned_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | struct net_device *netdev = adapter->netdev; |
| 3837 | struct pci_dev *pdev = adapter->pdev; |
| 3838 | struct e1000_rx_desc *rx_desc; |
| 3839 | struct e1000_buffer *buffer_info; |
| 3840 | struct sk_buff *skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3841 | unsigned int i; |
| 3842 | unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | |
| 3844 | i = rx_ring->next_to_use; |
| 3845 | buffer_info = &rx_ring->buffer_info[i]; |
| 3846 | |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3847 | while (cleaned_count--) { |
| 3848 | if (!(skb = buffer_info->skb)) |
| 3849 | skb = dev_alloc_skb(bufsz); |
| 3850 | else { |
| 3851 | skb_trim(skb, 0); |
| 3852 | goto map_skb; |
| 3853 | } |
| 3854 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3855 | if (unlikely(!skb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | /* Better luck next round */ |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3857 | adapter->alloc_rx_buff_failed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | break; |
| 3859 | } |
| 3860 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3861 | /* Fix for errata 23, can't cross 64kB boundary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 3863 | struct sk_buff *oldskb = skb; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3864 | DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes " |
| 3865 | "at %p\n", bufsz, skb->data); |
| 3866 | /* Try again, without freeing the previous */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | skb = dev_alloc_skb(bufsz); |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3868 | /* Failed allocation, critical failure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | if (!skb) { |
| 3870 | dev_kfree_skb(oldskb); |
| 3871 | break; |
| 3872 | } |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) { |
| 3875 | /* give up */ |
| 3876 | dev_kfree_skb(skb); |
| 3877 | dev_kfree_skb(oldskb); |
| 3878 | break; /* while !buffer_info->skb */ |
| 3879 | } else { |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3880 | /* Use new allocation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | dev_kfree_skb(oldskb); |
| 3882 | } |
| 3883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 3885 | * this will result in a 16 byte aligned IP header after |
| 3886 | * the 14 byte MAC header is removed |
| 3887 | */ |
| 3888 | skb_reserve(skb, NET_IP_ALIGN); |
| 3889 | |
| 3890 | skb->dev = netdev; |
| 3891 | |
| 3892 | buffer_info->skb = skb; |
| 3893 | buffer_info->length = adapter->rx_buffer_len; |
Jeff Kirsher | a292ca6 | 2006-01-12 16:51:30 -0800 | [diff] [blame] | 3894 | map_skb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | buffer_info->dma = pci_map_single(pdev, |
| 3896 | skb->data, |
| 3897 | adapter->rx_buffer_len, |
| 3898 | PCI_DMA_FROMDEVICE); |
| 3899 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3900 | /* Fix for errata 23, can't cross 64kB boundary */ |
| 3901 | if (!e1000_check_64k_bound(adapter, |
| 3902 | (void *)(unsigned long)buffer_info->dma, |
| 3903 | adapter->rx_buffer_len)) { |
| 3904 | DPRINTK(RX_ERR, ERR, |
| 3905 | "dma align check failed: %u bytes at %p\n", |
| 3906 | adapter->rx_buffer_len, |
| 3907 | (void *)(unsigned long)buffer_info->dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | dev_kfree_skb(skb); |
| 3909 | buffer_info->skb = NULL; |
| 3910 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 3911 | pci_unmap_single(pdev, buffer_info->dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | adapter->rx_buffer_len, |
| 3913 | PCI_DMA_FROMDEVICE); |
| 3914 | |
| 3915 | break; /* while !buffer_info->skb */ |
| 3916 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | rx_desc = E1000_RX_DESC(*rx_ring, i); |
| 3918 | rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3919 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3920 | if (unlikely(++i == rx_ring->count)) |
| 3921 | i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | buffer_info = &rx_ring->buffer_info[i]; |
| 3923 | } |
| 3924 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3925 | if (likely(rx_ring->next_to_use != i)) { |
| 3926 | rx_ring->next_to_use = i; |
| 3927 | if (unlikely(i-- == 0)) |
| 3928 | i = (rx_ring->count - 1); |
| 3929 | |
| 3930 | /* Force memory writes to complete before letting h/w |
| 3931 | * know there are new descriptors to fetch. (Only |
| 3932 | * applicable for weak-ordered memory model archs, |
| 3933 | * such as IA-64). */ |
| 3934 | wmb(); |
| 3935 | writel(i, adapter->hw.hw_addr + rx_ring->rdt); |
| 3936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | /** |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3940 | * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split |
| 3941 | * @adapter: address of board private structure |
| 3942 | **/ |
| 3943 | |
| 3944 | static void |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 3945 | e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter, |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3946 | struct e1000_rx_ring *rx_ring, |
| 3947 | int cleaned_count) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3948 | { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3949 | struct net_device *netdev = adapter->netdev; |
| 3950 | struct pci_dev *pdev = adapter->pdev; |
| 3951 | union e1000_rx_desc_packet_split *rx_desc; |
| 3952 | struct e1000_buffer *buffer_info; |
| 3953 | struct e1000_ps_page *ps_page; |
| 3954 | struct e1000_ps_page_dma *ps_page_dma; |
| 3955 | struct sk_buff *skb; |
| 3956 | unsigned int i, j; |
| 3957 | |
| 3958 | i = rx_ring->next_to_use; |
| 3959 | buffer_info = &rx_ring->buffer_info[i]; |
| 3960 | ps_page = &rx_ring->ps_page[i]; |
| 3961 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 3962 | |
Jeff Kirsher | 72d64a4 | 2006-01-12 16:51:19 -0800 | [diff] [blame] | 3963 | while (cleaned_count--) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3964 | rx_desc = E1000_RX_DESC_PS(*rx_ring, i); |
| 3965 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3966 | for (j = 0; j < PS_PAGE_BUFFERS; j++) { |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3967 | if (j < adapter->rx_ps_pages) { |
| 3968 | if (likely(!ps_page->ps_page[j])) { |
| 3969 | ps_page->ps_page[j] = |
| 3970 | alloc_page(GFP_ATOMIC); |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3971 | if (unlikely(!ps_page->ps_page[j])) { |
| 3972 | adapter->alloc_rx_buff_failed++; |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3973 | goto no_buffers; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3974 | } |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3975 | ps_page_dma->ps_page_dma[j] = |
| 3976 | pci_map_page(pdev, |
| 3977 | ps_page->ps_page[j], |
| 3978 | 0, PAGE_SIZE, |
| 3979 | PCI_DMA_FROMDEVICE); |
| 3980 | } |
| 3981 | /* Refresh the desc even if buffer_addrs didn't |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 3982 | * change because each write-back erases |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 3983 | * this info. |
| 3984 | */ |
| 3985 | rx_desc->read.buffer_addr[j+1] = |
| 3986 | cpu_to_le64(ps_page_dma->ps_page_dma[j]); |
| 3987 | } else |
| 3988 | rx_desc->read.buffer_addr[j+1] = ~0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | skb = dev_alloc_skb(adapter->rx_ps_bsize0 + NET_IP_ALIGN); |
| 3992 | |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3993 | if (unlikely(!skb)) { |
| 3994 | adapter->alloc_rx_buff_failed++; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3995 | break; |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 3996 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 3997 | |
| 3998 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 3999 | * this will result in a 16 byte aligned IP header after |
| 4000 | * the 14 byte MAC header is removed |
| 4001 | */ |
| 4002 | skb_reserve(skb, NET_IP_ALIGN); |
| 4003 | |
| 4004 | skb->dev = netdev; |
| 4005 | |
| 4006 | buffer_info->skb = skb; |
| 4007 | buffer_info->length = adapter->rx_ps_bsize0; |
| 4008 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4009 | adapter->rx_ps_bsize0, |
| 4010 | PCI_DMA_FROMDEVICE); |
| 4011 | |
| 4012 | rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma); |
| 4013 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4014 | if (unlikely(++i == rx_ring->count)) i = 0; |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4015 | buffer_info = &rx_ring->buffer_info[i]; |
| 4016 | ps_page = &rx_ring->ps_page[i]; |
| 4017 | ps_page_dma = &rx_ring->ps_page_dma[i]; |
| 4018 | } |
| 4019 | |
| 4020 | no_buffers: |
Jesse Brandeburg | b92ff8e | 2006-01-18 13:01:32 -0800 | [diff] [blame] | 4021 | if (likely(rx_ring->next_to_use != i)) { |
| 4022 | rx_ring->next_to_use = i; |
| 4023 | if (unlikely(i-- == 0)) i = (rx_ring->count - 1); |
| 4024 | |
| 4025 | /* Force memory writes to complete before letting h/w |
| 4026 | * know there are new descriptors to fetch. (Only |
| 4027 | * applicable for weak-ordered memory model archs, |
| 4028 | * such as IA-64). */ |
| 4029 | wmb(); |
| 4030 | /* Hardware increments by 16 bytes, but packet split |
| 4031 | * descriptors are 32 bytes...so we increment tail |
| 4032 | * twice as much. |
| 4033 | */ |
| 4034 | writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt); |
| 4035 | } |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers. |
| 4040 | * @adapter: |
| 4041 | **/ |
| 4042 | |
| 4043 | static void |
| 4044 | e1000_smartspeed(struct e1000_adapter *adapter) |
| 4045 | { |
| 4046 | uint16_t phy_status; |
| 4047 | uint16_t phy_ctrl; |
| 4048 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4049 | if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL)) |
| 4051 | return; |
| 4052 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4053 | if (adapter->smartspeed == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | /* If Master/Slave config fault is asserted twice, |
| 4055 | * we assume back-to-back */ |
| 4056 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4057 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4059 | if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4060 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4061 | if (phy_ctrl & CR_1000T_MS_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | phy_ctrl &= ~CR_1000T_MS_ENABLE; |
| 4063 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, |
| 4064 | phy_ctrl); |
| 4065 | adapter->smartspeed++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4066 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, |
| 4068 | &phy_ctrl)) { |
| 4069 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4070 | MII_CR_RESTART_AUTO_NEG); |
| 4071 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, |
| 4072 | phy_ctrl); |
| 4073 | } |
| 4074 | } |
| 4075 | return; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4076 | } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | /* If still no link, perhaps using 2/3 pair cable */ |
| 4078 | e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl); |
| 4079 | phy_ctrl |= CR_1000T_MS_ENABLE; |
| 4080 | e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4081 | if (!e1000_phy_setup_autoneg(&adapter->hw) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) { |
| 4083 | phy_ctrl |= (MII_CR_AUTO_NEG_EN | |
| 4084 | MII_CR_RESTART_AUTO_NEG); |
| 4085 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl); |
| 4086 | } |
| 4087 | } |
| 4088 | /* Restart process after E1000_SMARTSPEED_MAX iterations */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4089 | if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | adapter->smartspeed = 0; |
| 4091 | } |
| 4092 | |
| 4093 | /** |
| 4094 | * e1000_ioctl - |
| 4095 | * @netdev: |
| 4096 | * @ifreq: |
| 4097 | * @cmd: |
| 4098 | **/ |
| 4099 | |
| 4100 | static int |
| 4101 | e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4102 | { |
| 4103 | switch (cmd) { |
| 4104 | case SIOCGMIIPHY: |
| 4105 | case SIOCGMIIREG: |
| 4106 | case SIOCSMIIREG: |
| 4107 | return e1000_mii_ioctl(netdev, ifr, cmd); |
| 4108 | default: |
| 4109 | return -EOPNOTSUPP; |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | /** |
| 4114 | * e1000_mii_ioctl - |
| 4115 | * @netdev: |
| 4116 | * @ifreq: |
| 4117 | * @cmd: |
| 4118 | **/ |
| 4119 | |
| 4120 | static int |
| 4121 | e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4122 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4123 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4125 | int retval; |
| 4126 | uint16_t mii_reg; |
| 4127 | uint16_t spddplx; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4128 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4130 | if (adapter->hw.media_type != e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | return -EOPNOTSUPP; |
| 4132 | |
| 4133 | switch (cmd) { |
| 4134 | case SIOCGMIIPHY: |
| 4135 | data->phy_id = adapter->hw.phy_addr; |
| 4136 | break; |
| 4137 | case SIOCGMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4138 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | return -EPERM; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4140 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4141 | if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4142 | &data->val_out)) { |
| 4143 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4145 | } |
| 4146 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | break; |
| 4148 | case SIOCSMIIREG: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4149 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | return -EPERM; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4151 | if (data->reg_num & ~(0x1F)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | return -EFAULT; |
| 4153 | mii_reg = data->val_in; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4154 | spin_lock_irqsave(&adapter->stats_lock, flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4155 | if (e1000_write_phy_reg(&adapter->hw, data->reg_num, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4156 | mii_reg)) { |
| 4157 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4159 | } |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4160 | if (adapter->hw.phy_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | switch (data->reg_num) { |
| 4162 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4163 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4165 | if (mii_reg & MII_CR_AUTO_NEG_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | adapter->hw.autoneg = 1; |
| 4167 | adapter->hw.autoneg_advertised = 0x2F; |
| 4168 | } else { |
| 4169 | if (mii_reg & 0x40) |
| 4170 | spddplx = SPEED_1000; |
| 4171 | else if (mii_reg & 0x2000) |
| 4172 | spddplx = SPEED_100; |
| 4173 | else |
| 4174 | spddplx = SPEED_10; |
| 4175 | spddplx += (mii_reg & 0x100) |
Jeff Kirsher | cb76432 | 2006-03-08 17:24:12 -0800 | [diff] [blame] | 4176 | ? DUPLEX_FULL : |
| 4177 | DUPLEX_HALF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | retval = e1000_set_spd_dplx(adapter, |
| 4179 | spddplx); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4180 | if (retval) { |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4181 | spin_unlock_irqrestore( |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4182 | &adapter->stats_lock, |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4183 | flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | return retval; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4187 | if (netif_running(adapter->netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | e1000_down(adapter); |
| 4189 | e1000_up(adapter); |
| 4190 | } else |
| 4191 | e1000_reset(adapter); |
| 4192 | break; |
| 4193 | case M88E1000_PHY_SPEC_CTRL: |
| 4194 | case M88E1000_EXT_PHY_SPEC_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4195 | if (e1000_phy_reset(&adapter->hw)) { |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4196 | spin_unlock_irqrestore( |
| 4197 | &adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | return -EIO; |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | break; |
| 4201 | } |
| 4202 | } else { |
| 4203 | switch (data->reg_num) { |
| 4204 | case PHY_CTRL: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4205 | if (mii_reg & MII_CR_POWER_DOWN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | break; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4207 | if (netif_running(adapter->netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | e1000_down(adapter); |
| 4209 | e1000_up(adapter); |
| 4210 | } else |
| 4211 | e1000_reset(adapter); |
| 4212 | break; |
| 4213 | } |
| 4214 | } |
Malli Chilakala | 97876fc | 2005-06-17 17:40:19 -0700 | [diff] [blame] | 4215 | spin_unlock_irqrestore(&adapter->stats_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | break; |
| 4217 | default: |
| 4218 | return -EOPNOTSUPP; |
| 4219 | } |
| 4220 | return E1000_SUCCESS; |
| 4221 | } |
| 4222 | |
| 4223 | void |
| 4224 | e1000_pci_set_mwi(struct e1000_hw *hw) |
| 4225 | { |
| 4226 | struct e1000_adapter *adapter = hw->back; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4227 | int ret_val = pci_set_mwi(adapter->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4229 | if (ret_val) |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4230 | DPRINTK(PROBE, ERR, "Error in setting MWI\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | void |
| 4234 | e1000_pci_clear_mwi(struct e1000_hw *hw) |
| 4235 | { |
| 4236 | struct e1000_adapter *adapter = hw->back; |
| 4237 | |
| 4238 | pci_clear_mwi(adapter->pdev); |
| 4239 | } |
| 4240 | |
| 4241 | void |
| 4242 | e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4243 | { |
| 4244 | struct e1000_adapter *adapter = hw->back; |
| 4245 | |
| 4246 | pci_read_config_word(adapter->pdev, reg, value); |
| 4247 | } |
| 4248 | |
| 4249 | void |
| 4250 | e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value) |
| 4251 | { |
| 4252 | struct e1000_adapter *adapter = hw->back; |
| 4253 | |
| 4254 | pci_write_config_word(adapter->pdev, reg, *value); |
| 4255 | } |
| 4256 | |
| 4257 | uint32_t |
| 4258 | e1000_io_read(struct e1000_hw *hw, unsigned long port) |
| 4259 | { |
| 4260 | return inl(port); |
| 4261 | } |
| 4262 | |
| 4263 | void |
| 4264 | e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value) |
| 4265 | { |
| 4266 | outl(value, port); |
| 4267 | } |
| 4268 | |
| 4269 | static void |
| 4270 | e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp) |
| 4271 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4272 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | uint32_t ctrl, rctl; |
| 4274 | |
| 4275 | e1000_irq_disable(adapter); |
| 4276 | adapter->vlgrp = grp; |
| 4277 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4278 | if (grp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | /* enable VLAN tag insert/strip */ |
| 4280 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4281 | ctrl |= E1000_CTRL_VME; |
| 4282 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4283 | |
| 4284 | /* enable VLAN receive filtering */ |
| 4285 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4286 | rctl |= E1000_RCTL_VFE; |
| 4287 | rctl &= ~E1000_RCTL_CFIEN; |
| 4288 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4289 | e1000_update_mng_vlan(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | } else { |
| 4291 | /* disable VLAN tag insert/strip */ |
| 4292 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4293 | ctrl &= ~E1000_CTRL_VME; |
| 4294 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4295 | |
| 4296 | /* disable VLAN filtering */ |
| 4297 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4298 | rctl &= ~E1000_RCTL_VFE; |
| 4299 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4300 | if (adapter->mng_vlan_id != (uint16_t)E1000_MNG_VLAN_NONE) { |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4301 | e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 4302 | adapter->mng_vlan_id = E1000_MNG_VLAN_NONE; |
| 4303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | e1000_irq_enable(adapter); |
| 4307 | } |
| 4308 | |
| 4309 | static void |
| 4310 | e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid) |
| 4311 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4312 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | uint32_t vfta, index; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4314 | |
| 4315 | if ((adapter->hw.mng_cookie.status & |
| 4316 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
| 4317 | (vid == adapter->mng_vlan_id)) |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4318 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | /* add VID to filter table */ |
| 4320 | index = (vid >> 5) & 0x7F; |
| 4321 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4322 | vfta |= (1 << (vid & 0x1F)); |
| 4323 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4324 | } |
| 4325 | |
| 4326 | static void |
| 4327 | e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid) |
| 4328 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4329 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | uint32_t vfta, index; |
| 4331 | |
| 4332 | e1000_irq_disable(adapter); |
| 4333 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4334 | if (adapter->vlgrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | adapter->vlgrp->vlan_devices[vid] = NULL; |
| 4336 | |
| 4337 | e1000_irq_enable(adapter); |
| 4338 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4339 | if ((adapter->hw.mng_cookie.status & |
| 4340 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) && |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4341 | (vid == adapter->mng_vlan_id)) { |
| 4342 | /* release control to f/w */ |
| 4343 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4344 | return; |
Jeff Kirsher | ff14701 | 2006-01-12 16:51:10 -0800 | [diff] [blame] | 4345 | } |
| 4346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | /* remove VID from filter table */ |
| 4348 | index = (vid >> 5) & 0x7F; |
| 4349 | vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index); |
| 4350 | vfta &= ~(1 << (vid & 0x1F)); |
| 4351 | e1000_write_vfta(&adapter->hw, index, vfta); |
| 4352 | } |
| 4353 | |
| 4354 | static void |
| 4355 | e1000_restore_vlan(struct e1000_adapter *adapter) |
| 4356 | { |
| 4357 | e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 4358 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4359 | if (adapter->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4360 | uint16_t vid; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4361 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 4362 | if (!adapter->vlgrp->vlan_devices[vid]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | continue; |
| 4364 | e1000_vlan_rx_add_vid(adapter->netdev, vid); |
| 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | int |
| 4370 | e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx) |
| 4371 | { |
| 4372 | adapter->hw.autoneg = 0; |
| 4373 | |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4374 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4375 | if ((adapter->hw.media_type == e1000_media_type_fiber) && |
Malli Chilakala | 6921368 | 2005-06-17 17:44:20 -0700 | [diff] [blame] | 4376 | spddplx != (SPEED_1000 + DUPLEX_FULL)) { |
| 4377 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
| 4378 | return -EINVAL; |
| 4379 | } |
| 4380 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4381 | switch (spddplx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | case SPEED_10 + DUPLEX_HALF: |
| 4383 | adapter->hw.forced_speed_duplex = e1000_10_half; |
| 4384 | break; |
| 4385 | case SPEED_10 + DUPLEX_FULL: |
| 4386 | adapter->hw.forced_speed_duplex = e1000_10_full; |
| 4387 | break; |
| 4388 | case SPEED_100 + DUPLEX_HALF: |
| 4389 | adapter->hw.forced_speed_duplex = e1000_100_half; |
| 4390 | break; |
| 4391 | case SPEED_100 + DUPLEX_FULL: |
| 4392 | adapter->hw.forced_speed_duplex = e1000_100_full; |
| 4393 | break; |
| 4394 | case SPEED_1000 + DUPLEX_FULL: |
| 4395 | adapter->hw.autoneg = 1; |
| 4396 | adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL; |
| 4397 | break; |
| 4398 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 4399 | default: |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4400 | DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | return -EINVAL; |
| 4402 | } |
| 4403 | return 0; |
| 4404 | } |
| 4405 | |
Martin J. Bligh | b6a1d5f | 2005-10-28 15:14:44 -0700 | [diff] [blame] | 4406 | #ifdef CONFIG_PM |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4407 | /* Save/restore 16 or 64 dwords of PCI config space depending on which |
| 4408 | * bus we're on (PCI(X) vs. PCI-E) |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4409 | */ |
| 4410 | #define PCIE_CONFIG_SPACE_LEN 256 |
| 4411 | #define PCI_CONFIG_SPACE_LEN 64 |
| 4412 | static int |
| 4413 | e1000_pci_save_state(struct e1000_adapter *adapter) |
| 4414 | { |
| 4415 | struct pci_dev *dev = adapter->pdev; |
| 4416 | int size; |
| 4417 | int i; |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4418 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4419 | if (adapter->hw.mac_type >= e1000_82571) |
| 4420 | size = PCIE_CONFIG_SPACE_LEN; |
| 4421 | else |
| 4422 | size = PCI_CONFIG_SPACE_LEN; |
| 4423 | |
| 4424 | WARN_ON(adapter->config_space != NULL); |
| 4425 | |
| 4426 | adapter->config_space = kmalloc(size, GFP_KERNEL); |
| 4427 | if (!adapter->config_space) { |
| 4428 | DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size); |
| 4429 | return -ENOMEM; |
| 4430 | } |
| 4431 | for (i = 0; i < (size / 4); i++) |
| 4432 | pci_read_config_dword(dev, i * 4, &adapter->config_space[i]); |
| 4433 | return 0; |
| 4434 | } |
| 4435 | |
| 4436 | static void |
| 4437 | e1000_pci_restore_state(struct e1000_adapter *adapter) |
| 4438 | { |
| 4439 | struct pci_dev *dev = adapter->pdev; |
| 4440 | int size; |
| 4441 | int i; |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4442 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4443 | if (adapter->config_space == NULL) |
| 4444 | return; |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4445 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4446 | if (adapter->hw.mac_type >= e1000_82571) |
| 4447 | size = PCIE_CONFIG_SPACE_LEN; |
| 4448 | else |
| 4449 | size = PCI_CONFIG_SPACE_LEN; |
| 4450 | for (i = 0; i < (size / 4); i++) |
| 4451 | pci_write_config_dword(dev, i * 4, adapter->config_space[i]); |
| 4452 | kfree(adapter->config_space); |
| 4453 | adapter->config_space = NULL; |
| 4454 | return; |
| 4455 | } |
| 4456 | #endif /* CONFIG_PM */ |
| 4457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | static int |
Pavel Machek | 829ca9a | 2005-09-03 15:56:56 -0700 | [diff] [blame] | 4459 | e1000_suspend(struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4460 | { |
| 4461 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4462 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4463 | uint32_t ctrl, ctrl_ext, rctl, manc, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | uint32_t wufc = adapter->wol; |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4465 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | |
| 4467 | netif_device_detach(netdev); |
| 4468 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4469 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4470 | e1000_down(adapter); |
| 4471 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4472 | #ifdef CONFIG_PM |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4473 | /* Implement our own version of pci_save_state(pdev) because pci- |
| 4474 | * express adapters have 256-byte config spaces. */ |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4475 | retval = e1000_pci_save_state(adapter); |
| 4476 | if (retval) |
| 4477 | return retval; |
| 4478 | #endif |
| 4479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | status = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4481 | if (status & E1000_STATUS_LU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | wufc &= ~E1000_WUFC_LNKC; |
| 4483 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4484 | if (wufc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | e1000_setup_rctl(adapter); |
| 4486 | e1000_set_multi(netdev); |
| 4487 | |
| 4488 | /* turn on all-multi mode if wake on multicast is enabled */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4489 | if (adapter->wol & E1000_WUFC_MC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 4491 | rctl |= E1000_RCTL_MPE; |
| 4492 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 4493 | } |
| 4494 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4495 | if (adapter->hw.mac_type >= e1000_82540) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | ctrl = E1000_READ_REG(&adapter->hw, CTRL); |
| 4497 | /* advertise wake from D3Cold */ |
| 4498 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 4499 | /* phy power management enable */ |
| 4500 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 4501 | ctrl |= E1000_CTRL_ADVD3WUC | |
| 4502 | E1000_CTRL_EN_PHY_PWR_MGMT; |
| 4503 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl); |
| 4504 | } |
| 4505 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4506 | if (adapter->hw.media_type == e1000_media_type_fiber || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 4508 | /* keep the laser running in D3 */ |
| 4509 | ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT); |
| 4510 | ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA; |
| 4511 | E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext); |
| 4512 | } |
| 4513 | |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4514 | /* Allow time for pending master requests to run */ |
| 4515 | e1000_disable_pciex_master(&adapter->hw); |
| 4516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN); |
| 4518 | E1000_WRITE_REG(&adapter->hw, WUFC, wufc); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4519 | retval = pci_enable_wake(pdev, PCI_D3hot, 1); |
| 4520 | if (retval) |
| 4521 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
| 4522 | retval = pci_enable_wake(pdev, PCI_D3cold, 1); |
| 4523 | if (retval) |
| 4524 | DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | } else { |
| 4526 | E1000_WRITE_REG(&adapter->hw, WUC, 0); |
| 4527 | E1000_WRITE_REG(&adapter->hw, WUFC, 0); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4528 | retval = pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4529 | if (retval) |
| 4530 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4531 | retval = pci_enable_wake(pdev, PCI_D3cold, 0); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4532 | if (retval) |
| 4533 | DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | } |
| 4535 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4536 | if (adapter->hw.mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | adapter->hw.media_type == e1000_media_type_copper) { |
| 4538 | manc = E1000_READ_REG(&adapter->hw, MANC); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4539 | if (manc & E1000_MANC_SMBUS_EN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | manc |= E1000_MANC_ARP_EN; |
| 4541 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4542 | retval = pci_enable_wake(pdev, PCI_D3hot, 1); |
| 4543 | if (retval) |
| 4544 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
| 4545 | retval = pci_enable_wake(pdev, PCI_D3cold, 1); |
| 4546 | if (retval) |
Jeff Kirsher | 0f15a8f | 2006-03-02 18:46:29 -0800 | [diff] [blame] | 4547 | DPRINTK(PROBE, ERR, |
| 4548 | "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4552 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 4553 | * would have already happened in close and is redundant. */ |
| 4554 | e1000_release_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | pci_disable_device(pdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4557 | |
| 4558 | retval = pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 4559 | if (retval) |
| 4560 | DPRINTK(PROBE, ERR, "Error in setting power state\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | |
| 4562 | return 0; |
| 4563 | } |
| 4564 | |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4565 | #ifdef CONFIG_PM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | static int |
| 4567 | e1000_resume(struct pci_dev *pdev) |
| 4568 | { |
| 4569 | struct net_device *netdev = pci_get_drvdata(pdev); |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4570 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4571 | int retval; |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4572 | uint32_t manc, ret_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4574 | retval = pci_set_power_state(pdev, PCI_D0); |
| 4575 | if (retval) |
| 4576 | DPRINTK(PROBE, ERR, "Error in setting power state\n"); |
Jesse Brandeburg | 2f82665 | 2006-01-18 13:01:34 -0800 | [diff] [blame] | 4577 | e1000_pci_restore_state(adapter); |
Malli Chilakala | 2b02893 | 2005-06-17 17:46:06 -0700 | [diff] [blame] | 4578 | ret_val = pci_enable_device(pdev); |
Malli Chilakala | a4cb847 | 2005-04-28 19:41:28 -0700 | [diff] [blame] | 4579 | pci_set_master(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4580 | |
Jeff Kirsher | 240b171 | 2006-01-12 16:51:28 -0800 | [diff] [blame] | 4581 | retval = pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4582 | if (retval) |
| 4583 | DPRINTK(PROBE, ERR, "Error enabling D3 wake\n"); |
| 4584 | retval = pci_enable_wake(pdev, PCI_D3cold, 0); |
| 4585 | if (retval) |
| 4586 | DPRINTK(PROBE, ERR, "Error enabling D3 cold wake\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4587 | |
| 4588 | e1000_reset(adapter); |
| 4589 | E1000_WRITE_REG(&adapter->hw, WUS, ~0); |
| 4590 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4591 | if (netif_running(netdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | e1000_up(adapter); |
| 4593 | |
| 4594 | netif_device_attach(netdev); |
| 4595 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 4596 | if (adapter->hw.mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | adapter->hw.media_type == e1000_media_type_copper) { |
| 4598 | manc = E1000_READ_REG(&adapter->hw, MANC); |
| 4599 | manc &= ~(E1000_MANC_ARP_EN); |
| 4600 | E1000_WRITE_REG(&adapter->hw, MANC, manc); |
| 4601 | } |
| 4602 | |
Jeff Kirsher | b55ccb3 | 2006-01-12 16:50:30 -0800 | [diff] [blame] | 4603 | /* If the controller is 82573 and f/w is AMT, do not set |
| 4604 | * DRV_LOAD until the interface is up. For all other cases, |
| 4605 | * let the f/w know that the h/w is now under the control |
| 4606 | * of the driver. */ |
| 4607 | if (adapter->hw.mac_type != e1000_82573 || |
| 4608 | !e1000_check_mng_mode(&adapter->hw)) |
| 4609 | e1000_get_hw_control(adapter); |
Malli Chilakala | 2d7edb9 | 2005-04-28 19:43:52 -0700 | [diff] [blame] | 4610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | return 0; |
| 4612 | } |
| 4613 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4614 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4615 | /* |
| 4616 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 4617 | * without having to re-enable interrupts. It's not called while |
| 4618 | * the interrupt routine is executing. |
| 4619 | */ |
| 4620 | static void |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 4621 | e1000_netpoll(struct net_device *netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 4623 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | disable_irq(adapter->pdev->irq); |
| 4625 | e1000_intr(adapter->pdev->irq, netdev, NULL); |
Andrew Morton | c4cfe56 | 2005-10-15 00:32:29 -0700 | [diff] [blame] | 4626 | e1000_clean_tx_irq(adapter, adapter->tx_ring); |
Jeff Kirsher | e8da8be | 2006-01-12 16:51:14 -0800 | [diff] [blame] | 4627 | #ifndef CONFIG_E1000_NAPI |
| 4628 | adapter->clean_rx(adapter, adapter->rx_ring); |
| 4629 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4630 | enable_irq(adapter->pdev->irq); |
| 4631 | } |
| 4632 | #endif |
| 4633 | |
| 4634 | /* e1000_main.c */ |