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