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