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