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