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