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