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