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