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