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