Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2009 Intel Corporation. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 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 |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 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 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/vmalloc.h> |
| 32 | #include <linux/pagemap.h> |
| 33 | #include <linux/netdevice.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 34 | #include <linux/ipv6.h> |
| 35 | #include <net/checksum.h> |
| 36 | #include <net/ip6_checksum.h> |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 37 | #include <linux/net_tstamp.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 38 | #include <linux/mii.h> |
| 39 | #include <linux/ethtool.h> |
| 40 | #include <linux/if_vlan.h> |
| 41 | #include <linux/pci.h> |
Alexander Duyck | c54106b | 2008-10-16 21:26:57 -0700 | [diff] [blame] | 42 | #include <linux/pci-aspm.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 43 | #include <linux/delay.h> |
| 44 | #include <linux/interrupt.h> |
| 45 | #include <linux/if_ether.h> |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 46 | #include <linux/aer.h> |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 47 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 48 | #include <linux/dca.h> |
| 49 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 50 | #include "igb.h" |
| 51 | |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 52 | #define DRV_VERSION "1.3.16-k2" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 53 | char igb_driver_name[] = "igb"; |
| 54 | char igb_driver_version[] = DRV_VERSION; |
| 55 | static const char igb_driver_string[] = |
| 56 | "Intel(R) Gigabit Ethernet Network Driver"; |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 57 | static const char igb_copyright[] = "Copyright (c) 2007-2009 Intel Corporation."; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 58 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 59 | static const struct e1000_info *igb_info_tbl[] = { |
| 60 | [board_82575] = &e1000_82575_info, |
| 61 | }; |
| 62 | |
| 63 | static struct pci_device_id igb_pci_tbl[] = { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 64 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 }, |
Alexander Duyck | 9eb2341 | 2009-03-13 20:42:15 +0000 | [diff] [blame] | 65 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 }, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 66 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 }, |
| 67 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 }, |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 68 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 }, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 69 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 }, |
| 70 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 }, |
| 71 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 }, |
| 72 | /* required last entry */ |
| 73 | {0, } |
| 74 | }; |
| 75 | |
| 76 | MODULE_DEVICE_TABLE(pci, igb_pci_tbl); |
| 77 | |
| 78 | void igb_reset(struct igb_adapter *); |
| 79 | static int igb_setup_all_tx_resources(struct igb_adapter *); |
| 80 | static int igb_setup_all_rx_resources(struct igb_adapter *); |
| 81 | static void igb_free_all_tx_resources(struct igb_adapter *); |
| 82 | static void igb_free_all_rx_resources(struct igb_adapter *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 83 | void igb_update_stats(struct igb_adapter *); |
| 84 | static int igb_probe(struct pci_dev *, const struct pci_device_id *); |
| 85 | static void __devexit igb_remove(struct pci_dev *pdev); |
| 86 | static int igb_sw_init(struct igb_adapter *); |
| 87 | static int igb_open(struct net_device *); |
| 88 | static int igb_close(struct net_device *); |
| 89 | static void igb_configure_tx(struct igb_adapter *); |
| 90 | static void igb_configure_rx(struct igb_adapter *); |
| 91 | static void igb_setup_rctl(struct igb_adapter *); |
| 92 | static void igb_clean_all_tx_rings(struct igb_adapter *); |
| 93 | static void igb_clean_all_rx_rings(struct igb_adapter *); |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 94 | static void igb_clean_tx_ring(struct igb_ring *); |
| 95 | static void igb_clean_rx_ring(struct igb_ring *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 96 | static void igb_set_multi(struct net_device *); |
| 97 | static void igb_update_phy_info(unsigned long); |
| 98 | static void igb_watchdog(unsigned long); |
| 99 | static void igb_watchdog_task(struct work_struct *); |
| 100 | static int igb_xmit_frame_ring_adv(struct sk_buff *, struct net_device *, |
| 101 | struct igb_ring *); |
| 102 | static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *); |
| 103 | static struct net_device_stats *igb_get_stats(struct net_device *); |
| 104 | static int igb_change_mtu(struct net_device *, int); |
| 105 | static int igb_set_mac(struct net_device *, void *); |
| 106 | static irqreturn_t igb_intr(int irq, void *); |
| 107 | static irqreturn_t igb_intr_msi(int irq, void *); |
| 108 | static irqreturn_t igb_msix_other(int irq, void *); |
| 109 | static irqreturn_t igb_msix_rx(int irq, void *); |
| 110 | static irqreturn_t igb_msix_tx(int irq, void *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 111 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 112 | static void igb_update_rx_dca(struct igb_ring *); |
| 113 | static void igb_update_tx_dca(struct igb_ring *); |
| 114 | static void igb_setup_dca(struct igb_adapter *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 115 | #endif /* CONFIG_IGB_DCA */ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 116 | static bool igb_clean_tx_irq(struct igb_ring *); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 117 | static int igb_poll(struct napi_struct *, int); |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 118 | static bool igb_clean_rx_irq_adv(struct igb_ring *, int *, int); |
| 119 | static void igb_alloc_rx_buffers_adv(struct igb_ring *, int); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 120 | static int igb_ioctl(struct net_device *, struct ifreq *, int cmd); |
| 121 | static void igb_tx_timeout(struct net_device *); |
| 122 | static void igb_reset_task(struct work_struct *); |
| 123 | static void igb_vlan_rx_register(struct net_device *, struct vlan_group *); |
| 124 | static void igb_vlan_rx_add_vid(struct net_device *, u16); |
| 125 | static void igb_vlan_rx_kill_vid(struct net_device *, u16); |
| 126 | static void igb_restore_vlan(struct igb_adapter *); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 127 | static void igb_ping_all_vfs(struct igb_adapter *); |
| 128 | static void igb_msg_task(struct igb_adapter *); |
| 129 | static int igb_rcv_msg_from_vf(struct igb_adapter *, u32); |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame^] | 130 | static inline void igb_set_rah_pool(struct e1000_hw *, int , int); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 131 | static void igb_vmm_control(struct igb_adapter *); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 132 | static int igb_set_vf_mac(struct igb_adapter *adapter, int, unsigned char *); |
| 133 | static void igb_restore_vf_multicasts(struct igb_adapter *adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 134 | |
Eric Dumazet | c8159b2 | 2009-07-13 11:11:41 -0700 | [diff] [blame] | 135 | static inline void igb_set_vmolr(struct e1000_hw *hw, int vfn) |
| 136 | { |
| 137 | u32 reg_data; |
| 138 | |
| 139 | reg_data = rd32(E1000_VMOLR(vfn)); |
| 140 | reg_data |= E1000_VMOLR_BAM | /* Accept broadcast */ |
| 141 | E1000_VMOLR_ROPE | /* Accept packets matched in UTA */ |
| 142 | E1000_VMOLR_ROMPE | /* Accept packets matched in MTA */ |
| 143 | E1000_VMOLR_AUPE | /* Accept untagged packets */ |
| 144 | E1000_VMOLR_STRVLAN; /* Strip vlan tags */ |
| 145 | wr32(E1000_VMOLR(vfn), reg_data); |
| 146 | } |
| 147 | |
| 148 | static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size, |
| 149 | int vfn) |
| 150 | { |
| 151 | struct e1000_hw *hw = &adapter->hw; |
| 152 | u32 vmolr; |
| 153 | |
| 154 | vmolr = rd32(E1000_VMOLR(vfn)); |
| 155 | vmolr &= ~E1000_VMOLR_RLPML_MASK; |
| 156 | vmolr |= size | E1000_VMOLR_LPE; |
| 157 | wr32(E1000_VMOLR(vfn), vmolr); |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static inline void igb_set_rah_pool(struct e1000_hw *hw, int pool, int entry) |
| 163 | { |
| 164 | u32 reg_data; |
| 165 | |
| 166 | reg_data = rd32(E1000_RAH(entry)); |
| 167 | reg_data &= ~E1000_RAH_POOL_MASK; |
| 168 | reg_data |= E1000_RAH_POOL_1 << pool;; |
| 169 | wr32(E1000_RAH(entry), reg_data); |
| 170 | } |
| 171 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 172 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 173 | static int igb_suspend(struct pci_dev *, pm_message_t); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 174 | static int igb_resume(struct pci_dev *); |
| 175 | #endif |
| 176 | static void igb_shutdown(struct pci_dev *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 177 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 178 | static int igb_notify_dca(struct notifier_block *, unsigned long, void *); |
| 179 | static struct notifier_block dca_notifier = { |
| 180 | .notifier_call = igb_notify_dca, |
| 181 | .next = NULL, |
| 182 | .priority = 0 |
| 183 | }; |
| 184 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 185 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 186 | /* for netdump / net console */ |
| 187 | static void igb_netpoll(struct net_device *); |
| 188 | #endif |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 189 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 190 | static unsigned int max_vfs = 0; |
| 191 | module_param(max_vfs, uint, 0); |
| 192 | MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate " |
| 193 | "per physical function"); |
| 194 | #endif /* CONFIG_PCI_IOV */ |
| 195 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 196 | static pci_ers_result_t igb_io_error_detected(struct pci_dev *, |
| 197 | pci_channel_state_t); |
| 198 | static pci_ers_result_t igb_io_slot_reset(struct pci_dev *); |
| 199 | static void igb_io_resume(struct pci_dev *); |
| 200 | |
| 201 | static struct pci_error_handlers igb_err_handler = { |
| 202 | .error_detected = igb_io_error_detected, |
| 203 | .slot_reset = igb_io_slot_reset, |
| 204 | .resume = igb_io_resume, |
| 205 | }; |
| 206 | |
| 207 | |
| 208 | static struct pci_driver igb_driver = { |
| 209 | .name = igb_driver_name, |
| 210 | .id_table = igb_pci_tbl, |
| 211 | .probe = igb_probe, |
| 212 | .remove = __devexit_p(igb_remove), |
| 213 | #ifdef CONFIG_PM |
| 214 | /* Power Managment Hooks */ |
| 215 | .suspend = igb_suspend, |
| 216 | .resume = igb_resume, |
| 217 | #endif |
| 218 | .shutdown = igb_shutdown, |
| 219 | .err_handler = &igb_err_handler |
| 220 | }; |
| 221 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 222 | static int global_quad_port_a; /* global quad port a indication */ |
| 223 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 224 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 225 | MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver"); |
| 226 | MODULE_LICENSE("GPL"); |
| 227 | MODULE_VERSION(DRV_VERSION); |
| 228 | |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 229 | /** |
| 230 | * Scale the NIC clock cycle by a large factor so that |
| 231 | * relatively small clock corrections can be added or |
| 232 | * substracted at each clock tick. The drawbacks of a |
| 233 | * large factor are a) that the clock register overflows |
| 234 | * more quickly (not such a big deal) and b) that the |
| 235 | * increment per tick has to fit into 24 bits. |
| 236 | * |
| 237 | * Note that |
| 238 | * TIMINCA = IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS * |
| 239 | * IGB_TSYNC_SCALE |
| 240 | * TIMINCA += TIMINCA * adjustment [ppm] / 1e9 |
| 241 | * |
| 242 | * The base scale factor is intentionally a power of two |
| 243 | * so that the division in %struct timecounter can be done with |
| 244 | * a shift. |
| 245 | */ |
| 246 | #define IGB_TSYNC_SHIFT (19) |
| 247 | #define IGB_TSYNC_SCALE (1<<IGB_TSYNC_SHIFT) |
| 248 | |
| 249 | /** |
| 250 | * The duration of one clock cycle of the NIC. |
| 251 | * |
| 252 | * @todo This hard-coded value is part of the specification and might change |
| 253 | * in future hardware revisions. Add revision check. |
| 254 | */ |
| 255 | #define IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS 16 |
| 256 | |
| 257 | #if (IGB_TSYNC_SCALE * IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS) >= (1<<24) |
| 258 | # error IGB_TSYNC_SCALE and/or IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS are too large to fit into TIMINCA |
| 259 | #endif |
| 260 | |
| 261 | /** |
| 262 | * igb_read_clock - read raw cycle counter (to be used by time counter) |
| 263 | */ |
| 264 | static cycle_t igb_read_clock(const struct cyclecounter *tc) |
| 265 | { |
| 266 | struct igb_adapter *adapter = |
| 267 | container_of(tc, struct igb_adapter, cycles); |
| 268 | struct e1000_hw *hw = &adapter->hw; |
| 269 | u64 stamp; |
| 270 | |
| 271 | stamp = rd32(E1000_SYSTIML); |
| 272 | stamp |= (u64)rd32(E1000_SYSTIMH) << 32ULL; |
| 273 | |
| 274 | return stamp; |
| 275 | } |
| 276 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 277 | #ifdef DEBUG |
| 278 | /** |
| 279 | * igb_get_hw_dev_name - return device name string |
| 280 | * used by hardware layer to print debugging information |
| 281 | **/ |
| 282 | char *igb_get_hw_dev_name(struct e1000_hw *hw) |
| 283 | { |
| 284 | struct igb_adapter *adapter = hw->back; |
| 285 | return adapter->netdev->name; |
| 286 | } |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 287 | |
| 288 | /** |
| 289 | * igb_get_time_str - format current NIC and system time as string |
| 290 | */ |
| 291 | static char *igb_get_time_str(struct igb_adapter *adapter, |
| 292 | char buffer[160]) |
| 293 | { |
| 294 | cycle_t hw = adapter->cycles.read(&adapter->cycles); |
| 295 | struct timespec nic = ns_to_timespec(timecounter_read(&adapter->clock)); |
| 296 | struct timespec sys; |
| 297 | struct timespec delta; |
| 298 | getnstimeofday(&sys); |
| 299 | |
| 300 | delta = timespec_sub(nic, sys); |
| 301 | |
| 302 | sprintf(buffer, |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 303 | "HW %llu, NIC %ld.%09lus, SYS %ld.%09lus, NIC-SYS %lds + %09luns", |
| 304 | hw, |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 305 | (long)nic.tv_sec, nic.tv_nsec, |
| 306 | (long)sys.tv_sec, sys.tv_nsec, |
| 307 | (long)delta.tv_sec, delta.tv_nsec); |
| 308 | |
| 309 | return buffer; |
| 310 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 311 | #endif |
| 312 | |
| 313 | /** |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 314 | * igb_desc_unused - calculate if we have unused descriptors |
| 315 | **/ |
| 316 | static int igb_desc_unused(struct igb_ring *ring) |
| 317 | { |
| 318 | if (ring->next_to_clean > ring->next_to_use) |
| 319 | return ring->next_to_clean - ring->next_to_use - 1; |
| 320 | |
| 321 | return ring->count + ring->next_to_clean - ring->next_to_use - 1; |
| 322 | } |
| 323 | |
| 324 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 325 | * igb_init_module - Driver Registration Routine |
| 326 | * |
| 327 | * igb_init_module is the first routine called when the driver is |
| 328 | * loaded. All it does is register with the PCI subsystem. |
| 329 | **/ |
| 330 | static int __init igb_init_module(void) |
| 331 | { |
| 332 | int ret; |
| 333 | printk(KERN_INFO "%s - version %s\n", |
| 334 | igb_driver_string, igb_driver_version); |
| 335 | |
| 336 | printk(KERN_INFO "%s\n", igb_copyright); |
| 337 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 338 | global_quad_port_a = 0; |
| 339 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 340 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 341 | dca_register_notify(&dca_notifier); |
| 342 | #endif |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 343 | |
| 344 | ret = pci_register_driver(&igb_driver); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | module_init(igb_init_module); |
| 349 | |
| 350 | /** |
| 351 | * igb_exit_module - Driver Exit Cleanup Routine |
| 352 | * |
| 353 | * igb_exit_module is called just before the driver is removed |
| 354 | * from memory. |
| 355 | **/ |
| 356 | static void __exit igb_exit_module(void) |
| 357 | { |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 358 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 359 | dca_unregister_notify(&dca_notifier); |
| 360 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 361 | pci_unregister_driver(&igb_driver); |
| 362 | } |
| 363 | |
| 364 | module_exit(igb_exit_module); |
| 365 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 366 | #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1)) |
| 367 | /** |
| 368 | * igb_cache_ring_register - Descriptor ring to register mapping |
| 369 | * @adapter: board private structure to initialize |
| 370 | * |
| 371 | * Once we know the feature-set enabled for the device, we'll cache |
| 372 | * the register offset the descriptor ring is assigned to. |
| 373 | **/ |
| 374 | static void igb_cache_ring_register(struct igb_adapter *adapter) |
| 375 | { |
| 376 | int i; |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 377 | unsigned int rbase_offset = adapter->vfs_allocated_count; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 378 | |
| 379 | switch (adapter->hw.mac.type) { |
| 380 | case e1000_82576: |
| 381 | /* The queues are allocated for virtualization such that VF 0 |
| 382 | * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc. |
| 383 | * In order to avoid collision we start at the first free queue |
| 384 | * and continue consuming queues in the same sequence |
| 385 | */ |
| 386 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 387 | adapter->rx_ring[i].reg_idx = rbase_offset + |
| 388 | Q_IDX_82576(i); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 389 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 390 | adapter->tx_ring[i].reg_idx = rbase_offset + |
| 391 | Q_IDX_82576(i); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 392 | break; |
| 393 | case e1000_82575: |
| 394 | default: |
| 395 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 396 | adapter->rx_ring[i].reg_idx = i; |
| 397 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 398 | adapter->tx_ring[i].reg_idx = i; |
| 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 403 | /** |
| 404 | * igb_alloc_queues - Allocate memory for all rings |
| 405 | * @adapter: board private structure to initialize |
| 406 | * |
| 407 | * We allocate one ring per queue at run-time since we don't know the |
| 408 | * number of queues at compile-time. |
| 409 | **/ |
| 410 | static int igb_alloc_queues(struct igb_adapter *adapter) |
| 411 | { |
| 412 | int i; |
| 413 | |
| 414 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 415 | sizeof(struct igb_ring), GFP_KERNEL); |
| 416 | if (!adapter->tx_ring) |
| 417 | return -ENOMEM; |
| 418 | |
| 419 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 420 | sizeof(struct igb_ring), GFP_KERNEL); |
| 421 | if (!adapter->rx_ring) { |
| 422 | kfree(adapter->tx_ring); |
| 423 | return -ENOMEM; |
| 424 | } |
| 425 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 426 | adapter->rx_ring->buddy = adapter->tx_ring; |
| 427 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 428 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 429 | struct igb_ring *ring = &(adapter->tx_ring[i]); |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 430 | ring->count = adapter->tx_ring_count; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 431 | ring->adapter = adapter; |
| 432 | ring->queue_index = i; |
| 433 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 434 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 435 | struct igb_ring *ring = &(adapter->rx_ring[i]); |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 436 | ring->count = adapter->rx_ring_count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 437 | ring->adapter = adapter; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 438 | ring->queue_index = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 439 | ring->itr_register = E1000_ITR; |
| 440 | |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 441 | /* set a default napi handler for each rx_ring */ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 442 | netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 443 | } |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 444 | |
| 445 | igb_cache_ring_register(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 449 | static void igb_free_queues(struct igb_adapter *adapter) |
| 450 | { |
| 451 | int i; |
| 452 | |
| 453 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 454 | netif_napi_del(&adapter->rx_ring[i].napi); |
| 455 | |
Alexander Duyck | d1a8c9e | 2009-03-31 20:38:19 +0000 | [diff] [blame] | 456 | adapter->num_rx_queues = 0; |
| 457 | adapter->num_tx_queues = 0; |
| 458 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 459 | kfree(adapter->tx_ring); |
| 460 | kfree(adapter->rx_ring); |
| 461 | } |
| 462 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 463 | #define IGB_N0_QUEUE -1 |
| 464 | static void igb_assign_vector(struct igb_adapter *adapter, int rx_queue, |
| 465 | int tx_queue, int msix_vector) |
| 466 | { |
| 467 | u32 msixbm = 0; |
| 468 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 469 | u32 ivar, index; |
| 470 | |
| 471 | switch (hw->mac.type) { |
| 472 | case e1000_82575: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 473 | /* The 82575 assigns vectors using a bitmask, which matches the |
| 474 | bitmask for the EICR/EIMS/EIMC registers. To assign one |
| 475 | or more queues to a vector, we write the appropriate bits |
| 476 | into the MSIXBM register for that vector. */ |
| 477 | if (rx_queue > IGB_N0_QUEUE) { |
| 478 | msixbm = E1000_EICR_RX_QUEUE0 << rx_queue; |
| 479 | adapter->rx_ring[rx_queue].eims_value = msixbm; |
| 480 | } |
| 481 | if (tx_queue > IGB_N0_QUEUE) { |
| 482 | msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue; |
| 483 | adapter->tx_ring[tx_queue].eims_value = |
| 484 | E1000_EICR_TX_QUEUE0 << tx_queue; |
| 485 | } |
| 486 | array_wr32(E1000_MSIXBM(0), msix_vector, msixbm); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 487 | break; |
| 488 | case e1000_82576: |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 489 | /* 82576 uses a table-based method for assigning vectors. |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 490 | Each queue has a single entry in the table to which we write |
| 491 | a vector number along with a "valid" bit. Sadly, the layout |
| 492 | of the table is somewhat counterintuitive. */ |
| 493 | if (rx_queue > IGB_N0_QUEUE) { |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 494 | index = (rx_queue >> 1) + adapter->vfs_allocated_count; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 495 | ivar = array_rd32(E1000_IVAR0, index); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 496 | if (rx_queue & 0x1) { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 497 | /* vector goes into third byte of register */ |
| 498 | ivar = ivar & 0xFF00FFFF; |
| 499 | ivar |= (msix_vector | E1000_IVAR_VALID) << 16; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 500 | } else { |
| 501 | /* vector goes into low byte of register */ |
| 502 | ivar = ivar & 0xFFFFFF00; |
| 503 | ivar |= msix_vector | E1000_IVAR_VALID; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 504 | } |
| 505 | adapter->rx_ring[rx_queue].eims_value= 1 << msix_vector; |
| 506 | array_wr32(E1000_IVAR0, index, ivar); |
| 507 | } |
| 508 | if (tx_queue > IGB_N0_QUEUE) { |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 509 | index = (tx_queue >> 1) + adapter->vfs_allocated_count; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 510 | ivar = array_rd32(E1000_IVAR0, index); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 511 | if (tx_queue & 0x1) { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 512 | /* vector goes into high byte of register */ |
| 513 | ivar = ivar & 0x00FFFFFF; |
| 514 | ivar |= (msix_vector | E1000_IVAR_VALID) << 24; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 515 | } else { |
| 516 | /* vector goes into second byte of register */ |
| 517 | ivar = ivar & 0xFFFF00FF; |
| 518 | ivar |= (msix_vector | E1000_IVAR_VALID) << 8; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 519 | } |
| 520 | adapter->tx_ring[tx_queue].eims_value= 1 << msix_vector; |
| 521 | array_wr32(E1000_IVAR0, index, ivar); |
| 522 | } |
| 523 | break; |
| 524 | default: |
| 525 | BUG(); |
| 526 | break; |
| 527 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /** |
| 531 | * igb_configure_msix - Configure MSI-X hardware |
| 532 | * |
| 533 | * igb_configure_msix sets up the hardware to properly |
| 534 | * generate MSI-X interrupts. |
| 535 | **/ |
| 536 | static void igb_configure_msix(struct igb_adapter *adapter) |
| 537 | { |
| 538 | u32 tmp; |
| 539 | int i, vector = 0; |
| 540 | struct e1000_hw *hw = &adapter->hw; |
| 541 | |
| 542 | adapter->eims_enable_mask = 0; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 543 | if (hw->mac.type == e1000_82576) |
| 544 | /* Turn on MSI-X capability first, or our settings |
| 545 | * won't stick. And it will take days to debug. */ |
| 546 | wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE | |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 547 | E1000_GPIE_PBA | E1000_GPIE_EIAME | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 548 | E1000_GPIE_NSICR); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 549 | |
| 550 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 551 | struct igb_ring *tx_ring = &adapter->tx_ring[i]; |
| 552 | igb_assign_vector(adapter, IGB_N0_QUEUE, i, vector++); |
| 553 | adapter->eims_enable_mask |= tx_ring->eims_value; |
| 554 | if (tx_ring->itr_val) |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 555 | writel(tx_ring->itr_val, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 556 | hw->hw_addr + tx_ring->itr_register); |
| 557 | else |
| 558 | writel(1, hw->hw_addr + tx_ring->itr_register); |
| 559 | } |
| 560 | |
| 561 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 562 | struct igb_ring *rx_ring = &adapter->rx_ring[i]; |
Harvey Harrison | 25ac3c2 | 2008-07-16 12:45:27 -0700 | [diff] [blame] | 563 | rx_ring->buddy = NULL; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 564 | igb_assign_vector(adapter, i, IGB_N0_QUEUE, vector++); |
| 565 | adapter->eims_enable_mask |= rx_ring->eims_value; |
| 566 | if (rx_ring->itr_val) |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 567 | writel(rx_ring->itr_val, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 568 | hw->hw_addr + rx_ring->itr_register); |
| 569 | else |
| 570 | writel(1, hw->hw_addr + rx_ring->itr_register); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | /* set vector for other causes, i.e. link changes */ |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 575 | switch (hw->mac.type) { |
| 576 | case e1000_82575: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 577 | array_wr32(E1000_MSIXBM(0), vector++, |
| 578 | E1000_EIMS_OTHER); |
| 579 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 580 | tmp = rd32(E1000_CTRL_EXT); |
| 581 | /* enable MSI-X PBA support*/ |
| 582 | tmp |= E1000_CTRL_EXT_PBA_CLR; |
| 583 | |
| 584 | /* Auto-Mask interrupts upon ICR read. */ |
| 585 | tmp |= E1000_CTRL_EXT_EIAME; |
| 586 | tmp |= E1000_CTRL_EXT_IRCA; |
| 587 | |
| 588 | wr32(E1000_CTRL_EXT, tmp); |
| 589 | adapter->eims_enable_mask |= E1000_EIMS_OTHER; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 590 | adapter->eims_other = E1000_EIMS_OTHER; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 591 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 592 | break; |
| 593 | |
| 594 | case e1000_82576: |
| 595 | tmp = (vector++ | E1000_IVAR_VALID) << 8; |
| 596 | wr32(E1000_IVAR_MISC, tmp); |
| 597 | |
| 598 | adapter->eims_enable_mask = (1 << (vector)) - 1; |
| 599 | adapter->eims_other = 1 << (vector - 1); |
| 600 | break; |
| 601 | default: |
| 602 | /* do nothing, since nothing else supports MSI-X */ |
| 603 | break; |
| 604 | } /* switch (hw->mac.type) */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 605 | wrfl(); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * igb_request_msix - Initialize MSI-X interrupts |
| 610 | * |
| 611 | * igb_request_msix allocates MSI-X vectors and requests interrupts from the |
| 612 | * kernel. |
| 613 | **/ |
| 614 | static int igb_request_msix(struct igb_adapter *adapter) |
| 615 | { |
| 616 | struct net_device *netdev = adapter->netdev; |
| 617 | int i, err = 0, vector = 0; |
| 618 | |
| 619 | vector = 0; |
| 620 | |
| 621 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 622 | struct igb_ring *ring = &(adapter->tx_ring[i]); |
Alexander Duyck | cb7b48f | 2008-12-05 15:08:03 -0800 | [diff] [blame] | 623 | sprintf(ring->name, "%s-tx-%d", netdev->name, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 624 | err = request_irq(adapter->msix_entries[vector].vector, |
| 625 | &igb_msix_tx, 0, ring->name, |
| 626 | &(adapter->tx_ring[i])); |
| 627 | if (err) |
| 628 | goto out; |
| 629 | ring->itr_register = E1000_EITR(0) + (vector << 2); |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 630 | ring->itr_val = 976; /* ~4000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 631 | vector++; |
| 632 | } |
| 633 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 634 | struct igb_ring *ring = &(adapter->rx_ring[i]); |
| 635 | if (strlen(netdev->name) < (IFNAMSIZ - 5)) |
Alexander Duyck | cb7b48f | 2008-12-05 15:08:03 -0800 | [diff] [blame] | 636 | sprintf(ring->name, "%s-rx-%d", netdev->name, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 637 | else |
| 638 | memcpy(ring->name, netdev->name, IFNAMSIZ); |
| 639 | err = request_irq(adapter->msix_entries[vector].vector, |
| 640 | &igb_msix_rx, 0, ring->name, |
| 641 | &(adapter->rx_ring[i])); |
| 642 | if (err) |
| 643 | goto out; |
| 644 | ring->itr_register = E1000_EITR(0) + (vector << 2); |
| 645 | ring->itr_val = adapter->itr; |
| 646 | vector++; |
| 647 | } |
| 648 | |
| 649 | err = request_irq(adapter->msix_entries[vector].vector, |
| 650 | &igb_msix_other, 0, netdev->name, netdev); |
| 651 | if (err) |
| 652 | goto out; |
| 653 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 654 | igb_configure_msix(adapter); |
| 655 | return 0; |
| 656 | out: |
| 657 | return err; |
| 658 | } |
| 659 | |
| 660 | static void igb_reset_interrupt_capability(struct igb_adapter *adapter) |
| 661 | { |
| 662 | if (adapter->msix_entries) { |
| 663 | pci_disable_msix(adapter->pdev); |
| 664 | kfree(adapter->msix_entries); |
| 665 | adapter->msix_entries = NULL; |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 666 | } else if (adapter->flags & IGB_FLAG_HAS_MSI) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 667 | pci_disable_msi(adapter->pdev); |
| 668 | return; |
| 669 | } |
| 670 | |
| 671 | |
| 672 | /** |
| 673 | * igb_set_interrupt_capability - set MSI or MSI-X if supported |
| 674 | * |
| 675 | * Attempt to configure interrupts using the best available |
| 676 | * capabilities of the hardware and kernel. |
| 677 | **/ |
| 678 | static void igb_set_interrupt_capability(struct igb_adapter *adapter) |
| 679 | { |
| 680 | int err; |
| 681 | int numvecs, i; |
| 682 | |
Alexander Duyck | 83b7180 | 2009-02-06 23:15:45 +0000 | [diff] [blame] | 683 | /* Number of supported queues. */ |
| 684 | /* Having more queues than CPUs doesn't make sense. */ |
| 685 | adapter->num_rx_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus()); |
| 686 | adapter->num_tx_queues = min_t(u32, IGB_MAX_TX_QUEUES, num_online_cpus()); |
| 687 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 688 | numvecs = adapter->num_tx_queues + adapter->num_rx_queues + 1; |
| 689 | adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry), |
| 690 | GFP_KERNEL); |
| 691 | if (!adapter->msix_entries) |
| 692 | goto msi_only; |
| 693 | |
| 694 | for (i = 0; i < numvecs; i++) |
| 695 | adapter->msix_entries[i].entry = i; |
| 696 | |
| 697 | err = pci_enable_msix(adapter->pdev, |
| 698 | adapter->msix_entries, |
| 699 | numvecs); |
| 700 | if (err == 0) |
Alexander Duyck | 34a20e8 | 2008-08-26 04:25:13 -0700 | [diff] [blame] | 701 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 702 | |
| 703 | igb_reset_interrupt_capability(adapter); |
| 704 | |
| 705 | /* If we can't do MSI-X, try MSI */ |
| 706 | msi_only: |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 707 | #ifdef CONFIG_PCI_IOV |
| 708 | /* disable SR-IOV for non MSI-X configurations */ |
| 709 | if (adapter->vf_data) { |
| 710 | struct e1000_hw *hw = &adapter->hw; |
| 711 | /* disable iov and allow time for transactions to clear */ |
| 712 | pci_disable_sriov(adapter->pdev); |
| 713 | msleep(500); |
| 714 | |
| 715 | kfree(adapter->vf_data); |
| 716 | adapter->vf_data = NULL; |
| 717 | wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ); |
| 718 | msleep(100); |
| 719 | dev_info(&adapter->pdev->dev, "IOV Disabled\n"); |
| 720 | } |
| 721 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 722 | adapter->num_rx_queues = 1; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 723 | adapter->num_tx_queues = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 724 | if (!pci_enable_msi(adapter->pdev)) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 725 | adapter->flags |= IGB_FLAG_HAS_MSI; |
Alexander Duyck | 34a20e8 | 2008-08-26 04:25:13 -0700 | [diff] [blame] | 726 | out: |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 727 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 728 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 729 | return; |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * igb_request_irq - initialize interrupts |
| 734 | * |
| 735 | * Attempts to configure interrupts using the best available |
| 736 | * capabilities of the hardware and kernel. |
| 737 | **/ |
| 738 | static int igb_request_irq(struct igb_adapter *adapter) |
| 739 | { |
| 740 | struct net_device *netdev = adapter->netdev; |
| 741 | struct e1000_hw *hw = &adapter->hw; |
| 742 | int err = 0; |
| 743 | |
| 744 | if (adapter->msix_entries) { |
| 745 | err = igb_request_msix(adapter); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 746 | if (!err) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 747 | goto request_done; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 748 | /* fall back to MSI */ |
| 749 | igb_reset_interrupt_capability(adapter); |
| 750 | if (!pci_enable_msi(adapter->pdev)) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 751 | adapter->flags |= IGB_FLAG_HAS_MSI; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 752 | igb_free_all_tx_resources(adapter); |
| 753 | igb_free_all_rx_resources(adapter); |
| 754 | adapter->num_rx_queues = 1; |
| 755 | igb_alloc_queues(adapter); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 756 | } else { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 757 | switch (hw->mac.type) { |
| 758 | case e1000_82575: |
| 759 | wr32(E1000_MSIXBM(0), |
| 760 | (E1000_EICR_RX_QUEUE0 | E1000_EIMS_OTHER)); |
| 761 | break; |
| 762 | case e1000_82576: |
| 763 | wr32(E1000_IVAR0, E1000_IVAR_VALID); |
| 764 | break; |
| 765 | default: |
| 766 | break; |
| 767 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 768 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 769 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 770 | if (adapter->flags & IGB_FLAG_HAS_MSI) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 771 | err = request_irq(adapter->pdev->irq, &igb_intr_msi, 0, |
| 772 | netdev->name, netdev); |
| 773 | if (!err) |
| 774 | goto request_done; |
| 775 | /* fall back to legacy interrupts */ |
| 776 | igb_reset_interrupt_capability(adapter); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 777 | adapter->flags &= ~IGB_FLAG_HAS_MSI; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | err = request_irq(adapter->pdev->irq, &igb_intr, IRQF_SHARED, |
| 781 | netdev->name, netdev); |
| 782 | |
Andy Gospodarek | 6cb5e57 | 2008-02-15 14:05:25 -0800 | [diff] [blame] | 783 | if (err) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 784 | dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n", |
| 785 | err); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 786 | |
| 787 | request_done: |
| 788 | return err; |
| 789 | } |
| 790 | |
| 791 | static void igb_free_irq(struct igb_adapter *adapter) |
| 792 | { |
| 793 | struct net_device *netdev = adapter->netdev; |
| 794 | |
| 795 | if (adapter->msix_entries) { |
| 796 | int vector = 0, i; |
| 797 | |
| 798 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 799 | free_irq(adapter->msix_entries[vector++].vector, |
| 800 | &(adapter->tx_ring[i])); |
| 801 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 802 | free_irq(adapter->msix_entries[vector++].vector, |
| 803 | &(adapter->rx_ring[i])); |
| 804 | |
| 805 | free_irq(adapter->msix_entries[vector++].vector, netdev); |
| 806 | return; |
| 807 | } |
| 808 | |
| 809 | free_irq(adapter->pdev->irq, netdev); |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * igb_irq_disable - Mask off interrupt generation on the NIC |
| 814 | * @adapter: board private structure |
| 815 | **/ |
| 816 | static void igb_irq_disable(struct igb_adapter *adapter) |
| 817 | { |
| 818 | struct e1000_hw *hw = &adapter->hw; |
| 819 | |
| 820 | if (adapter->msix_entries) { |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 821 | wr32(E1000_EIAM, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 822 | wr32(E1000_EIMC, ~0); |
| 823 | wr32(E1000_EIAC, 0); |
| 824 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 825 | |
| 826 | wr32(E1000_IAM, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 827 | wr32(E1000_IMC, ~0); |
| 828 | wrfl(); |
| 829 | synchronize_irq(adapter->pdev->irq); |
| 830 | } |
| 831 | |
| 832 | /** |
| 833 | * igb_irq_enable - Enable default interrupt generation settings |
| 834 | * @adapter: board private structure |
| 835 | **/ |
| 836 | static void igb_irq_enable(struct igb_adapter *adapter) |
| 837 | { |
| 838 | struct e1000_hw *hw = &adapter->hw; |
| 839 | |
| 840 | if (adapter->msix_entries) { |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 841 | wr32(E1000_EIAC, adapter->eims_enable_mask); |
| 842 | wr32(E1000_EIAM, adapter->eims_enable_mask); |
| 843 | wr32(E1000_EIMS, adapter->eims_enable_mask); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 844 | if (adapter->vfs_allocated_count) |
| 845 | wr32(E1000_MBVFIMR, 0xFF); |
| 846 | wr32(E1000_IMS, (E1000_IMS_LSC | E1000_IMS_VMMB | |
| 847 | E1000_IMS_DOUTSYNC)); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 848 | } else { |
| 849 | wr32(E1000_IMS, IMS_ENABLE_MASK); |
| 850 | wr32(E1000_IAM, IMS_ENABLE_MASK); |
| 851 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void igb_update_mng_vlan(struct igb_adapter *adapter) |
| 855 | { |
| 856 | struct net_device *netdev = adapter->netdev; |
| 857 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 858 | u16 old_vid = adapter->mng_vlan_id; |
| 859 | if (adapter->vlgrp) { |
| 860 | if (!vlan_group_get_device(adapter->vlgrp, vid)) { |
| 861 | if (adapter->hw.mng_cookie.status & |
| 862 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 863 | igb_vlan_rx_add_vid(netdev, vid); |
| 864 | adapter->mng_vlan_id = vid; |
| 865 | } else |
| 866 | adapter->mng_vlan_id = IGB_MNG_VLAN_NONE; |
| 867 | |
| 868 | if ((old_vid != (u16)IGB_MNG_VLAN_NONE) && |
| 869 | (vid != old_vid) && |
| 870 | !vlan_group_get_device(adapter->vlgrp, old_vid)) |
| 871 | igb_vlan_rx_kill_vid(netdev, old_vid); |
| 872 | } else |
| 873 | adapter->mng_vlan_id = vid; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * igb_release_hw_control - release control of the h/w to f/w |
| 879 | * @adapter: address of board private structure |
| 880 | * |
| 881 | * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit. |
| 882 | * For ASF and Pass Through versions of f/w this means that the |
| 883 | * driver is no longer loaded. |
| 884 | * |
| 885 | **/ |
| 886 | static void igb_release_hw_control(struct igb_adapter *adapter) |
| 887 | { |
| 888 | struct e1000_hw *hw = &adapter->hw; |
| 889 | u32 ctrl_ext; |
| 890 | |
| 891 | /* Let firmware take over control of h/w */ |
| 892 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 893 | wr32(E1000_CTRL_EXT, |
| 894 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | /** |
| 899 | * igb_get_hw_control - get control of the h/w from f/w |
| 900 | * @adapter: address of board private structure |
| 901 | * |
| 902 | * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit. |
| 903 | * For ASF and Pass Through versions of f/w this means that |
| 904 | * the driver is loaded. |
| 905 | * |
| 906 | **/ |
| 907 | static void igb_get_hw_control(struct igb_adapter *adapter) |
| 908 | { |
| 909 | struct e1000_hw *hw = &adapter->hw; |
| 910 | u32 ctrl_ext; |
| 911 | |
| 912 | /* Let firmware know the driver has taken over */ |
| 913 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 914 | wr32(E1000_CTRL_EXT, |
| 915 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
| 916 | } |
| 917 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 918 | /** |
| 919 | * igb_configure - configure the hardware for RX and TX |
| 920 | * @adapter: private board structure |
| 921 | **/ |
| 922 | static void igb_configure(struct igb_adapter *adapter) |
| 923 | { |
| 924 | struct net_device *netdev = adapter->netdev; |
| 925 | int i; |
| 926 | |
| 927 | igb_get_hw_control(adapter); |
| 928 | igb_set_multi(netdev); |
| 929 | |
| 930 | igb_restore_vlan(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 931 | |
| 932 | igb_configure_tx(adapter); |
| 933 | igb_setup_rctl(adapter); |
| 934 | igb_configure_rx(adapter); |
Alexander Duyck | 662d720 | 2008-06-27 11:00:29 -0700 | [diff] [blame] | 935 | |
| 936 | igb_rx_fifo_flush_82575(&adapter->hw); |
| 937 | |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 938 | /* call igb_desc_unused which always leaves |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 939 | * at least 1 descriptor unused to make sure |
| 940 | * next_to_use != next_to_clean */ |
| 941 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 942 | struct igb_ring *ring = &adapter->rx_ring[i]; |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 943 | igb_alloc_rx_buffers_adv(ring, igb_desc_unused(ring)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | |
| 947 | adapter->tx_queue_len = netdev->tx_queue_len; |
| 948 | } |
| 949 | |
| 950 | |
| 951 | /** |
| 952 | * igb_up - Open the interface and prepare it to handle traffic |
| 953 | * @adapter: board private structure |
| 954 | **/ |
| 955 | |
| 956 | int igb_up(struct igb_adapter *adapter) |
| 957 | { |
| 958 | struct e1000_hw *hw = &adapter->hw; |
| 959 | int i; |
| 960 | |
| 961 | /* hardware has been reset, we need to reload some things */ |
| 962 | igb_configure(adapter); |
| 963 | |
| 964 | clear_bit(__IGB_DOWN, &adapter->state); |
| 965 | |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 966 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 967 | napi_enable(&adapter->rx_ring[i].napi); |
| 968 | if (adapter->msix_entries) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 969 | igb_configure_msix(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 970 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 971 | igb_vmm_control(adapter); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 972 | igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0); |
| 973 | igb_set_vmolr(hw, adapter->vfs_allocated_count); |
| 974 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 975 | /* Clear any pending interrupts. */ |
| 976 | rd32(E1000_ICR); |
| 977 | igb_irq_enable(adapter); |
| 978 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 979 | netif_tx_start_all_queues(adapter->netdev); |
| 980 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 981 | /* Fire a link change interrupt to start the watchdog. */ |
| 982 | wr32(E1000_ICS, E1000_ICS_LSC); |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | void igb_down(struct igb_adapter *adapter) |
| 987 | { |
| 988 | struct e1000_hw *hw = &adapter->hw; |
| 989 | struct net_device *netdev = adapter->netdev; |
| 990 | u32 tctl, rctl; |
| 991 | int i; |
| 992 | |
| 993 | /* signal that we're down so the interrupt handler does not |
| 994 | * reschedule our watchdog timer */ |
| 995 | set_bit(__IGB_DOWN, &adapter->state); |
| 996 | |
| 997 | /* disable receives in the hardware */ |
| 998 | rctl = rd32(E1000_RCTL); |
| 999 | wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN); |
| 1000 | /* flush and sleep below */ |
| 1001 | |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 1002 | netif_tx_stop_all_queues(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1003 | |
| 1004 | /* disable transmits in the hardware */ |
| 1005 | tctl = rd32(E1000_TCTL); |
| 1006 | tctl &= ~E1000_TCTL_EN; |
| 1007 | wr32(E1000_TCTL, tctl); |
| 1008 | /* flush both disables and wait for them to finish */ |
| 1009 | wrfl(); |
| 1010 | msleep(10); |
| 1011 | |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1012 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1013 | napi_disable(&adapter->rx_ring[i].napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1014 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1015 | igb_irq_disable(adapter); |
| 1016 | |
| 1017 | del_timer_sync(&adapter->watchdog_timer); |
| 1018 | del_timer_sync(&adapter->phy_info_timer); |
| 1019 | |
| 1020 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 1021 | netif_carrier_off(netdev); |
Alexander Duyck | 04fe635 | 2009-02-06 23:22:32 +0000 | [diff] [blame] | 1022 | |
| 1023 | /* record the stats before reset*/ |
| 1024 | igb_update_stats(adapter); |
| 1025 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1026 | adapter->link_speed = 0; |
| 1027 | adapter->link_duplex = 0; |
| 1028 | |
Jeff Kirsher | 3023682 | 2008-06-24 17:01:15 -0700 | [diff] [blame] | 1029 | if (!pci_channel_offline(adapter->pdev)) |
| 1030 | igb_reset(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1031 | igb_clean_all_tx_rings(adapter); |
| 1032 | igb_clean_all_rx_rings(adapter); |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 1033 | #ifdef CONFIG_IGB_DCA |
| 1034 | |
| 1035 | /* since we reset the hardware DCA settings were cleared */ |
| 1036 | igb_setup_dca(adapter); |
| 1037 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | void igb_reinit_locked(struct igb_adapter *adapter) |
| 1041 | { |
| 1042 | WARN_ON(in_interrupt()); |
| 1043 | while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) |
| 1044 | msleep(1); |
| 1045 | igb_down(adapter); |
| 1046 | igb_up(adapter); |
| 1047 | clear_bit(__IGB_RESETTING, &adapter->state); |
| 1048 | } |
| 1049 | |
| 1050 | void igb_reset(struct igb_adapter *adapter) |
| 1051 | { |
| 1052 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1053 | struct e1000_mac_info *mac = &hw->mac; |
| 1054 | struct e1000_fc_info *fc = &hw->fc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1055 | u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
| 1056 | u16 hwm; |
| 1057 | |
| 1058 | /* Repartition Pba for greater than 9k mtu |
| 1059 | * To take effect CTRL.RST is required. |
| 1060 | */ |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1061 | switch (mac->type) { |
| 1062 | case e1000_82576: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1063 | pba = E1000_PBA_64K; |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1064 | break; |
| 1065 | case e1000_82575: |
| 1066 | default: |
| 1067 | pba = E1000_PBA_34K; |
| 1068 | break; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1069 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1070 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1071 | if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 1072 | (mac->type < e1000_82576)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1073 | /* adjust PBA for jumbo frames */ |
| 1074 | wr32(E1000_PBA, pba); |
| 1075 | |
| 1076 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 1077 | * large enough to accommodate two full transmit packets, |
| 1078 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 1079 | * the Rx FIFO should be large enough to accommodate at least |
| 1080 | * one full receive packet and is similarly rounded up and |
| 1081 | * expressed in KB. */ |
| 1082 | pba = rd32(E1000_PBA); |
| 1083 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 1084 | tx_space = pba >> 16; |
| 1085 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 1086 | pba &= 0xffff; |
| 1087 | /* the tx fifo also stores 16 bytes of information about the tx |
| 1088 | * but don't include ethernet FCS because hardware appends it */ |
| 1089 | min_tx_space = (adapter->max_frame_size + |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 1090 | sizeof(union e1000_adv_tx_desc) - |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1091 | ETH_FCS_LEN) * 2; |
| 1092 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 1093 | min_tx_space >>= 10; |
| 1094 | /* software strips receive CRC, so leave room for it */ |
| 1095 | min_rx_space = adapter->max_frame_size; |
| 1096 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 1097 | min_rx_space >>= 10; |
| 1098 | |
| 1099 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 1100 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 1101 | * allocation, take space away from current Rx allocation */ |
| 1102 | if (tx_space < min_tx_space && |
| 1103 | ((min_tx_space - tx_space) < pba)) { |
| 1104 | pba = pba - (min_tx_space - tx_space); |
| 1105 | |
| 1106 | /* if short on rx space, rx wins and must trump tx |
| 1107 | * adjustment */ |
| 1108 | if (pba < min_rx_space) |
| 1109 | pba = min_rx_space; |
| 1110 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1111 | wr32(E1000_PBA, pba); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1112 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1113 | |
| 1114 | /* flow control settings */ |
| 1115 | /* The high water mark must be low enough to fit one full frame |
| 1116 | * (or the size used for early receive) above it in the Rx FIFO. |
| 1117 | * Set it to the lower of: |
| 1118 | * - 90% of the Rx FIFO size, or |
| 1119 | * - the full Rx FIFO size minus one full frame */ |
| 1120 | hwm = min(((pba << 10) * 9 / 10), |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1121 | ((pba << 10) - 2 * adapter->max_frame_size)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1122 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1123 | if (mac->type < e1000_82576) { |
| 1124 | fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */ |
| 1125 | fc->low_water = fc->high_water - 8; |
| 1126 | } else { |
| 1127 | fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */ |
| 1128 | fc->low_water = fc->high_water - 16; |
| 1129 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1130 | fc->pause_time = 0xFFFF; |
| 1131 | fc->send_xon = 1; |
| 1132 | fc->type = fc->original_type; |
| 1133 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1134 | /* disable receive for all VFs and wait one second */ |
| 1135 | if (adapter->vfs_allocated_count) { |
| 1136 | int i; |
| 1137 | for (i = 0 ; i < adapter->vfs_allocated_count; i++) |
| 1138 | adapter->vf_data[i].clear_to_send = false; |
| 1139 | |
| 1140 | /* ping all the active vfs to let them know we are going down */ |
| 1141 | igb_ping_all_vfs(adapter); |
| 1142 | |
| 1143 | /* disable transmits and receives */ |
| 1144 | wr32(E1000_VFRE, 0); |
| 1145 | wr32(E1000_VFTE, 0); |
| 1146 | } |
| 1147 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1148 | /* Allow time for pending master requests to run */ |
| 1149 | adapter->hw.mac.ops.reset_hw(&adapter->hw); |
| 1150 | wr32(E1000_WUC, 0); |
| 1151 | |
| 1152 | if (adapter->hw.mac.ops.init_hw(&adapter->hw)) |
| 1153 | dev_err(&adapter->pdev->dev, "Hardware Error\n"); |
| 1154 | |
| 1155 | igb_update_mng_vlan(adapter); |
| 1156 | |
| 1157 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 1158 | wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE); |
| 1159 | |
| 1160 | igb_reset_adaptive(&adapter->hw); |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 1161 | igb_get_phy_info(&adapter->hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1164 | static const struct net_device_ops igb_netdev_ops = { |
| 1165 | .ndo_open = igb_open, |
| 1166 | .ndo_stop = igb_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 1167 | .ndo_start_xmit = igb_xmit_frame_adv, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1168 | .ndo_get_stats = igb_get_stats, |
| 1169 | .ndo_set_multicast_list = igb_set_multi, |
| 1170 | .ndo_set_mac_address = igb_set_mac, |
| 1171 | .ndo_change_mtu = igb_change_mtu, |
| 1172 | .ndo_do_ioctl = igb_ioctl, |
| 1173 | .ndo_tx_timeout = igb_tx_timeout, |
| 1174 | .ndo_validate_addr = eth_validate_addr, |
| 1175 | .ndo_vlan_rx_register = igb_vlan_rx_register, |
| 1176 | .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid, |
| 1177 | .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid, |
| 1178 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1179 | .ndo_poll_controller = igb_netpoll, |
| 1180 | #endif |
| 1181 | }; |
| 1182 | |
Taku Izumi | 42bfd33a | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 1183 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1184 | * igb_probe - Device Initialization Routine |
| 1185 | * @pdev: PCI device information struct |
| 1186 | * @ent: entry in igb_pci_tbl |
| 1187 | * |
| 1188 | * Returns 0 on success, negative on failure |
| 1189 | * |
| 1190 | * igb_probe initializes an adapter identified by a pci_dev structure. |
| 1191 | * The OS initialization, configuring of the adapter private structure, |
| 1192 | * and a hardware reset occur. |
| 1193 | **/ |
| 1194 | static int __devinit igb_probe(struct pci_dev *pdev, |
| 1195 | const struct pci_device_id *ent) |
| 1196 | { |
| 1197 | struct net_device *netdev; |
| 1198 | struct igb_adapter *adapter; |
| 1199 | struct e1000_hw *hw; |
| 1200 | const struct e1000_info *ei = igb_info_tbl[ent->driver_data]; |
| 1201 | unsigned long mmio_start, mmio_len; |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 1202 | int err, pci_using_dac; |
Alexander Duyck | 682337f | 2009-03-14 22:26:40 -0700 | [diff] [blame] | 1203 | u16 eeprom_data = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1204 | u16 eeprom_apme_mask = IGB_EEPROM_APME; |
| 1205 | u32 part_num; |
| 1206 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1207 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1208 | if (err) |
| 1209 | return err; |
| 1210 | |
| 1211 | pci_using_dac = 0; |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1212 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1213 | if (!err) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 1214 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1215 | if (!err) |
| 1216 | pci_using_dac = 1; |
| 1217 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1218 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1219 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1220 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1221 | if (err) { |
| 1222 | dev_err(&pdev->dev, "No usable DMA " |
| 1223 | "configuration, aborting\n"); |
| 1224 | goto err_dma; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1229 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 1230 | IORESOURCE_MEM), |
| 1231 | igb_driver_name); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1232 | if (err) |
| 1233 | goto err_pci_reg; |
| 1234 | |
Jeff Kirsher | ea943d4 | 2008-12-11 20:34:19 -0800 | [diff] [blame] | 1235 | err = pci_enable_pcie_error_reporting(pdev); |
| 1236 | if (err) { |
| 1237 | dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed " |
| 1238 | "0x%x\n", err); |
| 1239 | /* non-fatal, continue */ |
| 1240 | } |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 1241 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1242 | pci_set_master(pdev); |
Auke Kok | c682fc2 | 2008-04-23 11:09:34 -0700 | [diff] [blame] | 1243 | pci_save_state(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1244 | |
| 1245 | err = -ENOMEM; |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 1246 | netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), |
| 1247 | IGB_ABS_MAX_TX_QUEUES); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1248 | if (!netdev) |
| 1249 | goto err_alloc_etherdev; |
| 1250 | |
| 1251 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1252 | |
| 1253 | pci_set_drvdata(pdev, netdev); |
| 1254 | adapter = netdev_priv(netdev); |
| 1255 | adapter->netdev = netdev; |
| 1256 | adapter->pdev = pdev; |
| 1257 | hw = &adapter->hw; |
| 1258 | hw->back = adapter; |
| 1259 | adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 1260 | |
| 1261 | mmio_start = pci_resource_start(pdev, 0); |
| 1262 | mmio_len = pci_resource_len(pdev, 0); |
| 1263 | |
| 1264 | err = -EIO; |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 1265 | hw->hw_addr = ioremap(mmio_start, mmio_len); |
| 1266 | if (!hw->hw_addr) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1267 | goto err_ioremap; |
| 1268 | |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1269 | netdev->netdev_ops = &igb_netdev_ops; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1270 | igb_set_ethtool_ops(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1271 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1272 | |
| 1273 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 1274 | |
| 1275 | netdev->mem_start = mmio_start; |
| 1276 | netdev->mem_end = mmio_start + mmio_len; |
| 1277 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1278 | /* PCI config space info */ |
| 1279 | hw->vendor_id = pdev->vendor; |
| 1280 | hw->device_id = pdev->device; |
| 1281 | hw->revision_id = pdev->revision; |
| 1282 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1283 | hw->subsystem_device_id = pdev->subsystem_device; |
| 1284 | |
| 1285 | /* setup the private structure */ |
| 1286 | hw->back = adapter; |
| 1287 | /* Copy the default MAC, PHY and NVM function pointers */ |
| 1288 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 1289 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 1290 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 1291 | /* Initialize skew-specific constants */ |
| 1292 | err = ei->get_invariants(hw); |
| 1293 | if (err) |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1294 | goto err_sw_init; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1295 | |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1296 | #ifdef CONFIG_PCI_IOV |
| 1297 | /* since iov functionality isn't critical to base device function we |
| 1298 | * can accept failure. If it fails we don't allow iov to be enabled */ |
| 1299 | if (hw->mac.type == e1000_82576) { |
| 1300 | /* 82576 supports a maximum of 7 VFs in addition to the PF */ |
| 1301 | unsigned int num_vfs = (max_vfs > 7) ? 7 : max_vfs; |
| 1302 | int i; |
| 1303 | unsigned char mac_addr[ETH_ALEN]; |
| 1304 | |
Alexander Duyck | 9ca046d | 2009-04-09 22:49:39 +0000 | [diff] [blame] | 1305 | if (num_vfs) { |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1306 | adapter->vf_data = kcalloc(num_vfs, |
| 1307 | sizeof(struct vf_data_storage), |
| 1308 | GFP_KERNEL); |
Alexander Duyck | 9ca046d | 2009-04-09 22:49:39 +0000 | [diff] [blame] | 1309 | if (!adapter->vf_data) { |
| 1310 | dev_err(&pdev->dev, |
| 1311 | "Could not allocate VF private data - " |
| 1312 | "IOV enable failed\n"); |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1313 | } else { |
Alexander Duyck | 9ca046d | 2009-04-09 22:49:39 +0000 | [diff] [blame] | 1314 | err = pci_enable_sriov(pdev, num_vfs); |
| 1315 | if (!err) { |
| 1316 | adapter->vfs_allocated_count = num_vfs; |
| 1317 | dev_info(&pdev->dev, |
| 1318 | "%d vfs allocated\n", |
| 1319 | num_vfs); |
| 1320 | for (i = 0; |
| 1321 | i < adapter->vfs_allocated_count; |
| 1322 | i++) { |
| 1323 | random_ether_addr(mac_addr); |
| 1324 | igb_set_vf_mac(adapter, i, |
| 1325 | mac_addr); |
| 1326 | } |
| 1327 | } else { |
| 1328 | kfree(adapter->vf_data); |
| 1329 | adapter->vf_data = NULL; |
| 1330 | } |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | #endif |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1336 | /* setup the private structure */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1337 | err = igb_sw_init(adapter); |
| 1338 | if (err) |
| 1339 | goto err_sw_init; |
| 1340 | |
| 1341 | igb_get_bus_info_pcie(hw); |
| 1342 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1343 | /* set flags */ |
| 1344 | switch (hw->mac.type) { |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1345 | case e1000_82575: |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1346 | adapter->flags |= IGB_FLAG_NEED_CTX_IDX; |
| 1347 | break; |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 1348 | case e1000_82576: |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1349 | default: |
| 1350 | break; |
| 1351 | } |
| 1352 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1353 | hw->phy.autoneg_wait_to_complete = false; |
| 1354 | hw->mac.adaptive_ifs = true; |
| 1355 | |
| 1356 | /* Copper options */ |
| 1357 | if (hw->phy.media_type == e1000_media_type_copper) { |
| 1358 | hw->phy.mdix = AUTO_ALL_MODES; |
| 1359 | hw->phy.disable_polarity_correction = false; |
| 1360 | hw->phy.ms_type = e1000_ms_hw_default; |
| 1361 | } |
| 1362 | |
| 1363 | if (igb_check_reset_block(hw)) |
| 1364 | dev_info(&pdev->dev, |
| 1365 | "PHY reset is blocked due to SOL/IDER session.\n"); |
| 1366 | |
| 1367 | netdev->features = NETIF_F_SG | |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1368 | NETIF_F_IP_CSUM | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1369 | NETIF_F_HW_VLAN_TX | |
| 1370 | NETIF_F_HW_VLAN_RX | |
| 1371 | NETIF_F_HW_VLAN_FILTER; |
| 1372 | |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1373 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1374 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1375 | netdev->features |= NETIF_F_TSO6; |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1376 | |
Herbert Xu | 5c0999b | 2009-01-19 15:20:57 -0800 | [diff] [blame] | 1377 | netdev->features |= NETIF_F_GRO; |
Alexander Duyck | d335252 | 2008-07-08 15:12:13 -0700 | [diff] [blame] | 1378 | |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1379 | netdev->vlan_features |= NETIF_F_TSO; |
| 1380 | netdev->vlan_features |= NETIF_F_TSO6; |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1381 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1382 | netdev->vlan_features |= NETIF_F_SG; |
| 1383 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1384 | if (pci_using_dac) |
| 1385 | netdev->features |= NETIF_F_HIGHDMA; |
| 1386 | |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 1387 | if (adapter->hw.mac.type == e1000_82576) |
| 1388 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 1389 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1390 | adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw); |
| 1391 | |
| 1392 | /* before reading the NVM, reset the controller to put the device in a |
| 1393 | * known good starting state */ |
| 1394 | hw->mac.ops.reset_hw(hw); |
| 1395 | |
| 1396 | /* make sure the NVM is good */ |
| 1397 | if (igb_validate_nvm_checksum(hw) < 0) { |
| 1398 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
| 1399 | err = -EIO; |
| 1400 | goto err_eeprom; |
| 1401 | } |
| 1402 | |
| 1403 | /* copy the MAC address out of the NVM */ |
| 1404 | if (hw->mac.ops.read_mac_addr(hw)) |
| 1405 | dev_err(&pdev->dev, "NVM Read Error\n"); |
| 1406 | |
| 1407 | memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len); |
| 1408 | memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len); |
| 1409 | |
| 1410 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
| 1411 | dev_err(&pdev->dev, "Invalid MAC Address\n"); |
| 1412 | err = -EIO; |
| 1413 | goto err_eeprom; |
| 1414 | } |
| 1415 | |
Alexander Duyck | 0e34048 | 2009-03-20 00:17:08 +0000 | [diff] [blame] | 1416 | setup_timer(&adapter->watchdog_timer, &igb_watchdog, |
| 1417 | (unsigned long) adapter); |
| 1418 | setup_timer(&adapter->phy_info_timer, &igb_update_phy_info, |
| 1419 | (unsigned long) adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1420 | |
| 1421 | INIT_WORK(&adapter->reset_task, igb_reset_task); |
| 1422 | INIT_WORK(&adapter->watchdog_task, igb_watchdog_task); |
| 1423 | |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1424 | /* Initialize link properties that are user-changeable */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1425 | adapter->fc_autoneg = true; |
| 1426 | hw->mac.autoneg = true; |
| 1427 | hw->phy.autoneg_advertised = 0x2f; |
| 1428 | |
| 1429 | hw->fc.original_type = e1000_fc_default; |
| 1430 | hw->fc.type = e1000_fc_default; |
| 1431 | |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 1432 | adapter->itr_setting = IGB_DEFAULT_ITR; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1433 | adapter->itr = IGB_START_ITR; |
| 1434 | |
| 1435 | igb_validate_mdi_setting(hw); |
| 1436 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1437 | /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM, |
| 1438 | * enable the ACPI Magic Packet filter |
| 1439 | */ |
| 1440 | |
Alexander Duyck | a2cf8b6 | 2009-03-13 20:41:17 +0000 | [diff] [blame] | 1441 | if (hw->bus.func == 0) |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 1442 | hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
Alexander Duyck | a2cf8b6 | 2009-03-13 20:41:17 +0000 | [diff] [blame] | 1443 | else if (hw->bus.func == 1) |
| 1444 | hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1445 | |
| 1446 | if (eeprom_data & eeprom_apme_mask) |
| 1447 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 1448 | |
| 1449 | /* now that we have the eeprom settings, apply the special cases where |
| 1450 | * the eeprom may be wrong or the board simply won't support wake on |
| 1451 | * lan on a particular port */ |
| 1452 | switch (pdev->device) { |
| 1453 | case E1000_DEV_ID_82575GB_QUAD_COPPER: |
| 1454 | adapter->eeprom_wol = 0; |
| 1455 | break; |
| 1456 | case E1000_DEV_ID_82575EB_FIBER_SERDES: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1457 | case E1000_DEV_ID_82576_FIBER: |
| 1458 | case E1000_DEV_ID_82576_SERDES: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1459 | /* Wake events only supported on port A for dual fiber |
| 1460 | * regardless of eeprom setting */ |
| 1461 | if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) |
| 1462 | adapter->eeprom_wol = 0; |
| 1463 | break; |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 1464 | case E1000_DEV_ID_82576_QUAD_COPPER: |
| 1465 | /* if quad port adapter, disable WoL on all but port A */ |
| 1466 | if (global_quad_port_a != 0) |
| 1467 | adapter->eeprom_wol = 0; |
| 1468 | else |
| 1469 | adapter->flags |= IGB_FLAG_QUAD_PORT_A; |
| 1470 | /* Reset for multiple quad port adapters */ |
| 1471 | if (++global_quad_port_a == 4) |
| 1472 | global_quad_port_a = 0; |
| 1473 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | /* initialize the wol settings based on the eeprom settings */ |
| 1477 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | e1b86d8 | 2008-11-07 20:30:37 +0000 | [diff] [blame] | 1478 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1479 | |
| 1480 | /* reset the hardware with the new settings */ |
| 1481 | igb_reset(adapter); |
| 1482 | |
| 1483 | /* let the f/w know that the h/w is now under the control of the |
| 1484 | * driver. */ |
| 1485 | igb_get_hw_control(adapter); |
| 1486 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1487 | strcpy(netdev->name, "eth%d"); |
| 1488 | err = register_netdev(netdev); |
| 1489 | if (err) |
| 1490 | goto err_register; |
| 1491 | |
Jesse Brandeburg | b168dfc | 2009-04-17 20:44:32 +0000 | [diff] [blame] | 1492 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 1493 | netif_carrier_off(netdev); |
| 1494 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 1495 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 1496 | if (dca_add_requester(&pdev->dev) == 0) { |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1497 | adapter->flags |= IGB_FLAG_DCA_ENABLED; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1498 | dev_info(&pdev->dev, "DCA enabled\n"); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1499 | igb_setup_dca(adapter); |
| 1500 | } |
| 1501 | #endif |
| 1502 | |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 1503 | /* |
| 1504 | * Initialize hardware timer: we keep it running just in case |
| 1505 | * that some program needs it later on. |
| 1506 | */ |
| 1507 | memset(&adapter->cycles, 0, sizeof(adapter->cycles)); |
| 1508 | adapter->cycles.read = igb_read_clock; |
| 1509 | adapter->cycles.mask = CLOCKSOURCE_MASK(64); |
| 1510 | adapter->cycles.mult = 1; |
| 1511 | adapter->cycles.shift = IGB_TSYNC_SHIFT; |
| 1512 | wr32(E1000_TIMINCA, |
| 1513 | (1<<24) | |
| 1514 | IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS * IGB_TSYNC_SCALE); |
| 1515 | #if 0 |
| 1516 | /* |
| 1517 | * Avoid rollover while we initialize by resetting the time counter. |
| 1518 | */ |
| 1519 | wr32(E1000_SYSTIML, 0x00000000); |
| 1520 | wr32(E1000_SYSTIMH, 0x00000000); |
| 1521 | #else |
| 1522 | /* |
| 1523 | * Set registers so that rollover occurs soon to test this. |
| 1524 | */ |
| 1525 | wr32(E1000_SYSTIML, 0x00000000); |
| 1526 | wr32(E1000_SYSTIMH, 0xFF800000); |
| 1527 | #endif |
| 1528 | wrfl(); |
| 1529 | timecounter_init(&adapter->clock, |
| 1530 | &adapter->cycles, |
| 1531 | ktime_to_ns(ktime_get_real())); |
| 1532 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 1533 | /* |
| 1534 | * Synchronize our NIC clock against system wall clock. NIC |
| 1535 | * time stamp reading requires ~3us per sample, each sample |
| 1536 | * was pretty stable even under load => only require 10 |
| 1537 | * samples for each offset comparison. |
| 1538 | */ |
| 1539 | memset(&adapter->compare, 0, sizeof(adapter->compare)); |
| 1540 | adapter->compare.source = &adapter->clock; |
| 1541 | adapter->compare.target = ktime_get_real; |
| 1542 | adapter->compare.num_samples = 10; |
| 1543 | timecompare_update(&adapter->compare, 0); |
| 1544 | |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 1545 | #ifdef DEBUG |
| 1546 | { |
| 1547 | char buffer[160]; |
| 1548 | printk(KERN_DEBUG |
| 1549 | "igb: %s: hw %p initialized timer\n", |
| 1550 | igb_get_time_str(adapter, buffer), |
| 1551 | &adapter->hw); |
| 1552 | } |
| 1553 | #endif |
| 1554 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1555 | dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n"); |
| 1556 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 1557 | dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1558 | netdev->name, |
| 1559 | ((hw->bus.speed == e1000_bus_speed_2500) |
| 1560 | ? "2.5Gb/s" : "unknown"), |
Alexander Duyck | 59c3de8 | 2009-03-31 20:38:00 +0000 | [diff] [blame] | 1561 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 1562 | (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" : |
| 1563 | (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" : |
| 1564 | "unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 1565 | netdev->dev_addr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1566 | |
| 1567 | igb_read_part_num(hw, &part_num); |
| 1568 | dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name, |
| 1569 | (part_num >> 8), (part_num & 0xff)); |
| 1570 | |
| 1571 | dev_info(&pdev->dev, |
| 1572 | "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n", |
| 1573 | adapter->msix_entries ? "MSI-X" : |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1574 | (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1575 | adapter->num_rx_queues, adapter->num_tx_queues); |
| 1576 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1577 | return 0; |
| 1578 | |
| 1579 | err_register: |
| 1580 | igb_release_hw_control(adapter); |
| 1581 | err_eeprom: |
| 1582 | if (!igb_check_reset_block(hw)) |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 1583 | igb_reset_phy(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1584 | |
| 1585 | if (hw->flash_address) |
| 1586 | iounmap(hw->flash_address); |
| 1587 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 1588 | igb_free_queues(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1589 | err_sw_init: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1590 | iounmap(hw->hw_addr); |
| 1591 | err_ioremap: |
| 1592 | free_netdev(netdev); |
| 1593 | err_alloc_etherdev: |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1594 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 1595 | IORESOURCE_MEM)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1596 | err_pci_reg: |
| 1597 | err_dma: |
| 1598 | pci_disable_device(pdev); |
| 1599 | return err; |
| 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * igb_remove - Device Removal Routine |
| 1604 | * @pdev: PCI device information struct |
| 1605 | * |
| 1606 | * igb_remove is called by the PCI subsystem to alert the driver |
| 1607 | * that it should release a PCI device. The could be caused by a |
| 1608 | * Hot-Plug event, or because the driver is going to be removed from |
| 1609 | * memory. |
| 1610 | **/ |
| 1611 | static void __devexit igb_remove(struct pci_dev *pdev) |
| 1612 | { |
| 1613 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 1614 | struct igb_adapter *adapter = netdev_priv(netdev); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1615 | struct e1000_hw *hw = &adapter->hw; |
Jeff Kirsher | ea943d4 | 2008-12-11 20:34:19 -0800 | [diff] [blame] | 1616 | int err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1617 | |
| 1618 | /* flush_scheduled work may reschedule our watchdog task, so |
| 1619 | * explicitly disable watchdog tasks from being rescheduled */ |
| 1620 | set_bit(__IGB_DOWN, &adapter->state); |
| 1621 | del_timer_sync(&adapter->watchdog_timer); |
| 1622 | del_timer_sync(&adapter->phy_info_timer); |
| 1623 | |
| 1624 | flush_scheduled_work(); |
| 1625 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 1626 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1627 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) { |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1628 | dev_info(&pdev->dev, "DCA disabled\n"); |
| 1629 | dca_remove_requester(&pdev->dev); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1630 | adapter->flags &= ~IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 1631 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 1632 | } |
| 1633 | #endif |
| 1634 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1635 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 1636 | * would have already happened in close and is redundant. */ |
| 1637 | igb_release_hw_control(adapter); |
| 1638 | |
| 1639 | unregister_netdev(netdev); |
| 1640 | |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 1641 | if (!igb_check_reset_block(&adapter->hw)) |
| 1642 | igb_reset_phy(&adapter->hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1643 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1644 | igb_reset_interrupt_capability(adapter); |
| 1645 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 1646 | igb_free_queues(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1647 | |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 1648 | #ifdef CONFIG_PCI_IOV |
| 1649 | /* reclaim resources allocated to VFs */ |
| 1650 | if (adapter->vf_data) { |
| 1651 | /* disable iov and allow time for transactions to clear */ |
| 1652 | pci_disable_sriov(pdev); |
| 1653 | msleep(500); |
| 1654 | |
| 1655 | kfree(adapter->vf_data); |
| 1656 | adapter->vf_data = NULL; |
| 1657 | wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ); |
| 1658 | msleep(100); |
| 1659 | dev_info(&pdev->dev, "IOV Disabled\n"); |
| 1660 | } |
| 1661 | #endif |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 1662 | iounmap(hw->hw_addr); |
| 1663 | if (hw->flash_address) |
| 1664 | iounmap(hw->flash_address); |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1665 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 1666 | IORESOURCE_MEM)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1667 | |
| 1668 | free_netdev(netdev); |
| 1669 | |
Jeff Kirsher | ea943d4 | 2008-12-11 20:34:19 -0800 | [diff] [blame] | 1670 | err = pci_disable_pcie_error_reporting(pdev); |
| 1671 | if (err) |
| 1672 | dev_err(&pdev->dev, |
| 1673 | "pci_disable_pcie_error_reporting failed 0x%x\n", err); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 1674 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1675 | pci_disable_device(pdev); |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * igb_sw_init - Initialize general software structures (struct igb_adapter) |
| 1680 | * @adapter: board private structure to initialize |
| 1681 | * |
| 1682 | * igb_sw_init initializes the Adapter private data structure. |
| 1683 | * Fields are initialized based on PCI device information and |
| 1684 | * OS network device settings (MTU size). |
| 1685 | **/ |
| 1686 | static int __devinit igb_sw_init(struct igb_adapter *adapter) |
| 1687 | { |
| 1688 | struct e1000_hw *hw = &adapter->hw; |
| 1689 | struct net_device *netdev = adapter->netdev; |
| 1690 | struct pci_dev *pdev = adapter->pdev; |
| 1691 | |
| 1692 | pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word); |
| 1693 | |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 1694 | adapter->tx_ring_count = IGB_DEFAULT_TXD; |
| 1695 | adapter->rx_ring_count = IGB_DEFAULT_RXD; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1696 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
| 1697 | adapter->rx_ps_hdr_size = 0; /* disable packet split */ |
| 1698 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 1699 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
| 1700 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 1701 | /* This call may decrease the number of queues depending on |
| 1702 | * interrupt mode. */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1703 | igb_set_interrupt_capability(adapter); |
| 1704 | |
| 1705 | if (igb_alloc_queues(adapter)) { |
| 1706 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 1707 | return -ENOMEM; |
| 1708 | } |
| 1709 | |
| 1710 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
| 1711 | igb_irq_disable(adapter); |
| 1712 | |
| 1713 | set_bit(__IGB_DOWN, &adapter->state); |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
| 1717 | /** |
| 1718 | * igb_open - Called when a network interface is made active |
| 1719 | * @netdev: network interface device structure |
| 1720 | * |
| 1721 | * Returns 0 on success, negative value on failure |
| 1722 | * |
| 1723 | * The open entry point is called when a network interface is made |
| 1724 | * active by the system (IFF_UP). At this point all resources needed |
| 1725 | * for transmit and receive operations are allocated, the interrupt |
| 1726 | * handler is registered with the OS, the watchdog timer is started, |
| 1727 | * and the stack is notified that the interface is ready. |
| 1728 | **/ |
| 1729 | static int igb_open(struct net_device *netdev) |
| 1730 | { |
| 1731 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 1732 | struct e1000_hw *hw = &adapter->hw; |
| 1733 | int err; |
| 1734 | int i; |
| 1735 | |
| 1736 | /* disallow open during test */ |
| 1737 | if (test_bit(__IGB_TESTING, &adapter->state)) |
| 1738 | return -EBUSY; |
| 1739 | |
Jesse Brandeburg | b168dfc | 2009-04-17 20:44:32 +0000 | [diff] [blame] | 1740 | netif_carrier_off(netdev); |
| 1741 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1742 | /* allocate transmit descriptors */ |
| 1743 | err = igb_setup_all_tx_resources(adapter); |
| 1744 | if (err) |
| 1745 | goto err_setup_tx; |
| 1746 | |
| 1747 | /* allocate receive descriptors */ |
| 1748 | err = igb_setup_all_rx_resources(adapter); |
| 1749 | if (err) |
| 1750 | goto err_setup_rx; |
| 1751 | |
| 1752 | /* e1000_power_up_phy(adapter); */ |
| 1753 | |
| 1754 | adapter->mng_vlan_id = IGB_MNG_VLAN_NONE; |
| 1755 | if ((adapter->hw.mng_cookie.status & |
| 1756 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN)) |
| 1757 | igb_update_mng_vlan(adapter); |
| 1758 | |
| 1759 | /* before we allocate an interrupt, we must be ready to handle it. |
| 1760 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 1761 | * as soon as we call pci_request_irq, so we have to setup our |
| 1762 | * clean_rx handler before we do so. */ |
| 1763 | igb_configure(adapter); |
| 1764 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1765 | igb_vmm_control(adapter); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 1766 | igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0); |
| 1767 | igb_set_vmolr(hw, adapter->vfs_allocated_count); |
| 1768 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1769 | err = igb_request_irq(adapter); |
| 1770 | if (err) |
| 1771 | goto err_req_irq; |
| 1772 | |
| 1773 | /* From here on the code is the same as igb_up() */ |
| 1774 | clear_bit(__IGB_DOWN, &adapter->state); |
| 1775 | |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1776 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1777 | napi_enable(&adapter->rx_ring[i].napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1778 | |
| 1779 | /* Clear any pending interrupts. */ |
| 1780 | rd32(E1000_ICR); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1781 | |
| 1782 | igb_irq_enable(adapter); |
| 1783 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 1784 | netif_tx_start_all_queues(netdev); |
| 1785 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1786 | /* Fire a link status change interrupt to start the watchdog. */ |
| 1787 | wr32(E1000_ICS, E1000_ICS_LSC); |
| 1788 | |
| 1789 | return 0; |
| 1790 | |
| 1791 | err_req_irq: |
| 1792 | igb_release_hw_control(adapter); |
| 1793 | /* e1000_power_down_phy(adapter); */ |
| 1794 | igb_free_all_rx_resources(adapter); |
| 1795 | err_setup_rx: |
| 1796 | igb_free_all_tx_resources(adapter); |
| 1797 | err_setup_tx: |
| 1798 | igb_reset(adapter); |
| 1799 | |
| 1800 | return err; |
| 1801 | } |
| 1802 | |
| 1803 | /** |
| 1804 | * igb_close - Disables a network interface |
| 1805 | * @netdev: network interface device structure |
| 1806 | * |
| 1807 | * Returns 0, this is not allowed to fail |
| 1808 | * |
| 1809 | * The close entry point is called when an interface is de-activated |
| 1810 | * by the OS. The hardware is still under the driver's control, but |
| 1811 | * needs to be disabled. A global MAC reset is issued to stop the |
| 1812 | * hardware, and all transmit and receive resources are freed. |
| 1813 | **/ |
| 1814 | static int igb_close(struct net_device *netdev) |
| 1815 | { |
| 1816 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 1817 | |
| 1818 | WARN_ON(test_bit(__IGB_RESETTING, &adapter->state)); |
| 1819 | igb_down(adapter); |
| 1820 | |
| 1821 | igb_free_irq(adapter); |
| 1822 | |
| 1823 | igb_free_all_tx_resources(adapter); |
| 1824 | igb_free_all_rx_resources(adapter); |
| 1825 | |
| 1826 | /* kill manageability vlan ID if supported, but not if a vlan with |
| 1827 | * the same ID is registered on the host OS (let 8021q kill it) */ |
| 1828 | if ((adapter->hw.mng_cookie.status & |
| 1829 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 1830 | !(adapter->vlgrp && |
| 1831 | vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) |
| 1832 | igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * igb_setup_tx_resources - allocate Tx resources (Descriptors) |
| 1839 | * @adapter: board private structure |
| 1840 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
| 1841 | * |
| 1842 | * Return 0 on success, negative on failure |
| 1843 | **/ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1844 | int igb_setup_tx_resources(struct igb_adapter *adapter, |
| 1845 | struct igb_ring *tx_ring) |
| 1846 | { |
| 1847 | struct pci_dev *pdev = adapter->pdev; |
| 1848 | int size; |
| 1849 | |
| 1850 | size = sizeof(struct igb_buffer) * tx_ring->count; |
| 1851 | tx_ring->buffer_info = vmalloc(size); |
| 1852 | if (!tx_ring->buffer_info) |
| 1853 | goto err; |
| 1854 | memset(tx_ring->buffer_info, 0, size); |
| 1855 | |
| 1856 | /* round up to nearest 4K */ |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 1857 | tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1858 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 1859 | |
| 1860 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 1861 | &tx_ring->dma); |
| 1862 | |
| 1863 | if (!tx_ring->desc) |
| 1864 | goto err; |
| 1865 | |
| 1866 | tx_ring->adapter = adapter; |
| 1867 | tx_ring->next_to_use = 0; |
| 1868 | tx_ring->next_to_clean = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1869 | return 0; |
| 1870 | |
| 1871 | err: |
| 1872 | vfree(tx_ring->buffer_info); |
| 1873 | dev_err(&adapter->pdev->dev, |
| 1874 | "Unable to allocate memory for the transmit descriptor ring\n"); |
| 1875 | return -ENOMEM; |
| 1876 | } |
| 1877 | |
| 1878 | /** |
| 1879 | * igb_setup_all_tx_resources - wrapper to allocate Tx resources |
| 1880 | * (Descriptors) for all queues |
| 1881 | * @adapter: board private structure |
| 1882 | * |
| 1883 | * Return 0 on success, negative on failure |
| 1884 | **/ |
| 1885 | static int igb_setup_all_tx_resources(struct igb_adapter *adapter) |
| 1886 | { |
| 1887 | int i, err = 0; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 1888 | int r_idx; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1889 | |
| 1890 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1891 | err = igb_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 1892 | if (err) { |
| 1893 | dev_err(&adapter->pdev->dev, |
| 1894 | "Allocation for Tx Queue %u failed\n", i); |
| 1895 | for (i--; i >= 0; i--) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 1896 | igb_free_tx_resources(&adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1897 | break; |
| 1898 | } |
| 1899 | } |
| 1900 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 1901 | for (i = 0; i < IGB_MAX_TX_QUEUES; i++) { |
| 1902 | r_idx = i % adapter->num_tx_queues; |
| 1903 | adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx]; |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 1904 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1905 | return err; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
| 1909 | * igb_configure_tx - Configure transmit Unit after Reset |
| 1910 | * @adapter: board private structure |
| 1911 | * |
| 1912 | * Configure the Tx unit of the MAC after a reset. |
| 1913 | **/ |
| 1914 | static void igb_configure_tx(struct igb_adapter *adapter) |
| 1915 | { |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 1916 | u64 tdba; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1917 | struct e1000_hw *hw = &adapter->hw; |
| 1918 | u32 tctl; |
| 1919 | u32 txdctl, txctrl; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1920 | int i, j; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1921 | |
| 1922 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 1923 | struct igb_ring *ring = &adapter->tx_ring[i]; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1924 | j = ring->reg_idx; |
| 1925 | wr32(E1000_TDLEN(j), |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 1926 | ring->count * sizeof(union e1000_adv_tx_desc)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1927 | tdba = ring->dma; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1928 | wr32(E1000_TDBAL(j), |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 1929 | tdba & 0x00000000ffffffffULL); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1930 | wr32(E1000_TDBAH(j), tdba >> 32); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1931 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1932 | ring->head = E1000_TDH(j); |
| 1933 | ring->tail = E1000_TDT(j); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1934 | writel(0, hw->hw_addr + ring->tail); |
| 1935 | writel(0, hw->hw_addr + ring->head); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1936 | txdctl = rd32(E1000_TXDCTL(j)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1937 | txdctl |= E1000_TXDCTL_QUEUE_ENABLE; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1938 | wr32(E1000_TXDCTL(j), txdctl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1939 | |
| 1940 | /* Turn off Relaxed Ordering on head write-backs. The |
| 1941 | * writebacks MUST be delivered in order or it will |
| 1942 | * completely screw up our bookeeping. |
| 1943 | */ |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1944 | txctrl = rd32(E1000_DCA_TXCTRL(j)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1945 | txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 1946 | wr32(E1000_DCA_TXCTRL(j), txctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1947 | } |
| 1948 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 1949 | /* disable queue 0 to prevent tail bump w/o re-configuration */ |
| 1950 | if (adapter->vfs_allocated_count) |
| 1951 | wr32(E1000_TXDCTL(0), 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1952 | |
| 1953 | /* Program the Transmit Control Register */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1954 | tctl = rd32(E1000_TCTL); |
| 1955 | tctl &= ~E1000_TCTL_CT; |
| 1956 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 1957 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 1958 | |
| 1959 | igb_config_collision_dist(hw); |
| 1960 | |
| 1961 | /* Setup Transmit Descriptor Settings for eop descriptor */ |
| 1962 | adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS; |
| 1963 | |
| 1964 | /* Enable transmits */ |
| 1965 | tctl |= E1000_TCTL_EN; |
| 1966 | |
| 1967 | wr32(E1000_TCTL, tctl); |
| 1968 | } |
| 1969 | |
| 1970 | /** |
| 1971 | * igb_setup_rx_resources - allocate Rx resources (Descriptors) |
| 1972 | * @adapter: board private structure |
| 1973 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 1974 | * |
| 1975 | * Returns 0 on success, negative on failure |
| 1976 | **/ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1977 | int igb_setup_rx_resources(struct igb_adapter *adapter, |
| 1978 | struct igb_ring *rx_ring) |
| 1979 | { |
| 1980 | struct pci_dev *pdev = adapter->pdev; |
| 1981 | int size, desc_len; |
| 1982 | |
| 1983 | size = sizeof(struct igb_buffer) * rx_ring->count; |
| 1984 | rx_ring->buffer_info = vmalloc(size); |
| 1985 | if (!rx_ring->buffer_info) |
| 1986 | goto err; |
| 1987 | memset(rx_ring->buffer_info, 0, size); |
| 1988 | |
| 1989 | desc_len = sizeof(union e1000_adv_rx_desc); |
| 1990 | |
| 1991 | /* Round up to nearest 4K */ |
| 1992 | rx_ring->size = rx_ring->count * desc_len; |
| 1993 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 1994 | |
| 1995 | rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, |
| 1996 | &rx_ring->dma); |
| 1997 | |
| 1998 | if (!rx_ring->desc) |
| 1999 | goto err; |
| 2000 | |
| 2001 | rx_ring->next_to_clean = 0; |
| 2002 | rx_ring->next_to_use = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2003 | |
| 2004 | rx_ring->adapter = adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2005 | |
| 2006 | return 0; |
| 2007 | |
| 2008 | err: |
| 2009 | vfree(rx_ring->buffer_info); |
| 2010 | dev_err(&adapter->pdev->dev, "Unable to allocate memory for " |
| 2011 | "the receive descriptor ring\n"); |
| 2012 | return -ENOMEM; |
| 2013 | } |
| 2014 | |
| 2015 | /** |
| 2016 | * igb_setup_all_rx_resources - wrapper to allocate Rx resources |
| 2017 | * (Descriptors) for all queues |
| 2018 | * @adapter: board private structure |
| 2019 | * |
| 2020 | * Return 0 on success, negative on failure |
| 2021 | **/ |
| 2022 | static int igb_setup_all_rx_resources(struct igb_adapter *adapter) |
| 2023 | { |
| 2024 | int i, err = 0; |
| 2025 | |
| 2026 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2027 | err = igb_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2028 | if (err) { |
| 2029 | dev_err(&adapter->pdev->dev, |
| 2030 | "Allocation for Rx Queue %u failed\n", i); |
| 2031 | for (i--; i >= 0; i--) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2032 | igb_free_rx_resources(&adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2033 | break; |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | return err; |
| 2038 | } |
| 2039 | |
| 2040 | /** |
| 2041 | * igb_setup_rctl - configure the receive control registers |
| 2042 | * @adapter: Board private structure |
| 2043 | **/ |
| 2044 | static void igb_setup_rctl(struct igb_adapter *adapter) |
| 2045 | { |
| 2046 | struct e1000_hw *hw = &adapter->hw; |
| 2047 | u32 rctl; |
| 2048 | u32 srrctl = 0; |
Alexander Duyck | 77a2294 | 2009-05-06 16:43:48 -0700 | [diff] [blame] | 2049 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2050 | |
| 2051 | rctl = rd32(E1000_RCTL); |
| 2052 | |
| 2053 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
Alexander Duyck | 69d728b | 2008-11-25 01:04:03 -0800 | [diff] [blame] | 2054 | rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2055 | |
Alexander Duyck | 69d728b | 2008-11-25 01:04:03 -0800 | [diff] [blame] | 2056 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2057 | (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2058 | |
Auke Kok | 87cb7e8 | 2008-07-08 15:08:29 -0700 | [diff] [blame] | 2059 | /* |
| 2060 | * enable stripping of CRC. It's unlikely this will break BMC |
| 2061 | * redirection as it did with e1000. Newer features require |
| 2062 | * that the HW strips the CRC. |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2063 | */ |
Auke Kok | 87cb7e8 | 2008-07-08 15:08:29 -0700 | [diff] [blame] | 2064 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2065 | |
Alexander Duyck | 9b07f3d3 | 2008-11-25 01:03:26 -0800 | [diff] [blame] | 2066 | /* |
Alexander Duyck | ec54d7d | 2009-01-31 00:52:57 -0800 | [diff] [blame] | 2067 | * disable store bad packets and clear size bits. |
Alexander Duyck | 9b07f3d3 | 2008-11-25 01:03:26 -0800 | [diff] [blame] | 2068 | */ |
Alexander Duyck | ec54d7d | 2009-01-31 00:52:57 -0800 | [diff] [blame] | 2069 | rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2070 | |
Alexander Duyck | ec54d7d | 2009-01-31 00:52:57 -0800 | [diff] [blame] | 2071 | /* enable LPE when to prevent packets larger than max_frame_size */ |
Alexander Duyck | 9b07f3d3 | 2008-11-25 01:03:26 -0800 | [diff] [blame] | 2072 | rctl |= E1000_RCTL_LPE; |
Alexander Duyck | b4557be | 2008-12-10 01:08:59 -0800 | [diff] [blame] | 2073 | |
| 2074 | /* Setup buffer sizes */ |
| 2075 | switch (adapter->rx_buffer_len) { |
| 2076 | case IGB_RXBUFFER_256: |
| 2077 | rctl |= E1000_RCTL_SZ_256; |
| 2078 | break; |
| 2079 | case IGB_RXBUFFER_512: |
| 2080 | rctl |= E1000_RCTL_SZ_512; |
| 2081 | break; |
| 2082 | default: |
| 2083 | srrctl = ALIGN(adapter->rx_buffer_len, 1024) |
| 2084 | >> E1000_SRRCTL_BSIZEPKT_SHIFT; |
| 2085 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | /* 82575 and greater support packet-split where the protocol |
| 2089 | * header is placed in skb->data and the packet data is |
| 2090 | * placed in pages hanging off of skb_shinfo(skb)->nr_frags. |
| 2091 | * In the case of a non-split, skb->data is linearly filled, |
| 2092 | * followed by the page buffers. Therefore, skb->data is |
| 2093 | * sized to hold the largest protocol header. |
| 2094 | */ |
| 2095 | /* allocations using alloc_page take too long for regular MTU |
| 2096 | * so only enable packet split for jumbo frames */ |
Alexander Duyck | ec54d7d | 2009-01-31 00:52:57 -0800 | [diff] [blame] | 2097 | if (adapter->netdev->mtu > ETH_DATA_LEN) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2098 | adapter->rx_ps_hdr_size = IGB_RXBUFFER_128; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 2099 | srrctl |= adapter->rx_ps_hdr_size << |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2100 | E1000_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2101 | srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
| 2102 | } else { |
| 2103 | adapter->rx_ps_hdr_size = 0; |
| 2104 | srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF; |
| 2105 | } |
| 2106 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2107 | /* Attention!!! For SR-IOV PF driver operations you must enable |
| 2108 | * queue drop for all VF and PF queues to prevent head of line blocking |
| 2109 | * if an un-trusted VF does not provide descriptors to hardware. |
| 2110 | */ |
| 2111 | if (adapter->vfs_allocated_count) { |
| 2112 | u32 vmolr; |
| 2113 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2114 | /* set all queue drop enable bits */ |
| 2115 | wr32(E1000_QDE, ALL_QUEUES); |
| 2116 | srrctl |= E1000_SRRCTL_DROP_EN; |
| 2117 | |
| 2118 | /* disable queue 0 to prevent tail write w/o re-config */ |
| 2119 | wr32(E1000_RXDCTL(0), 0); |
| 2120 | |
Alexander Duyck | 77a2294 | 2009-05-06 16:43:48 -0700 | [diff] [blame] | 2121 | vmolr = rd32(E1000_VMOLR(adapter->vfs_allocated_count)); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2122 | if (rctl & E1000_RCTL_LPE) |
| 2123 | vmolr |= E1000_VMOLR_LPE; |
Alexander Duyck | 77a2294 | 2009-05-06 16:43:48 -0700 | [diff] [blame] | 2124 | if (adapter->num_rx_queues > 1) |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2125 | vmolr |= E1000_VMOLR_RSSE; |
Alexander Duyck | 77a2294 | 2009-05-06 16:43:48 -0700 | [diff] [blame] | 2126 | wr32(E1000_VMOLR(adapter->vfs_allocated_count), vmolr); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2127 | } |
| 2128 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2129 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 77a2294 | 2009-05-06 16:43:48 -0700 | [diff] [blame] | 2130 | int j = adapter->rx_ring[i].reg_idx; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2131 | wr32(E1000_SRRCTL(j), srrctl); |
| 2132 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2133 | |
| 2134 | wr32(E1000_RCTL, rctl); |
| 2135 | } |
| 2136 | |
| 2137 | /** |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2138 | * igb_rlpml_set - set maximum receive packet size |
| 2139 | * @adapter: board private structure |
| 2140 | * |
| 2141 | * Configure maximum receivable packet size. |
| 2142 | **/ |
| 2143 | static void igb_rlpml_set(struct igb_adapter *adapter) |
| 2144 | { |
| 2145 | u32 max_frame_size = adapter->max_frame_size; |
| 2146 | struct e1000_hw *hw = &adapter->hw; |
| 2147 | u16 pf_id = adapter->vfs_allocated_count; |
| 2148 | |
| 2149 | if (adapter->vlgrp) |
| 2150 | max_frame_size += VLAN_TAG_SIZE; |
| 2151 | |
| 2152 | /* if vfs are enabled we set RLPML to the largest possible request |
| 2153 | * size and set the VMOLR RLPML to the size we need */ |
| 2154 | if (pf_id) { |
| 2155 | igb_set_vf_rlpml(adapter, max_frame_size, pf_id); |
| 2156 | max_frame_size = MAX_STD_JUMBO_FRAME_SIZE + VLAN_TAG_SIZE; |
| 2157 | } |
| 2158 | |
| 2159 | wr32(E1000_RLPML, max_frame_size); |
| 2160 | } |
| 2161 | |
| 2162 | /** |
| 2163 | * igb_configure_vt_default_pool - Configure VT default pool |
| 2164 | * @adapter: board private structure |
| 2165 | * |
| 2166 | * Configure the default pool |
| 2167 | **/ |
| 2168 | static void igb_configure_vt_default_pool(struct igb_adapter *adapter) |
| 2169 | { |
| 2170 | struct e1000_hw *hw = &adapter->hw; |
| 2171 | u16 pf_id = adapter->vfs_allocated_count; |
| 2172 | u32 vtctl; |
| 2173 | |
| 2174 | /* not in sr-iov mode - do nothing */ |
| 2175 | if (!pf_id) |
| 2176 | return; |
| 2177 | |
| 2178 | vtctl = rd32(E1000_VT_CTL); |
| 2179 | vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK | |
| 2180 | E1000_VT_CTL_DISABLE_DEF_POOL); |
| 2181 | vtctl |= pf_id << E1000_VT_CTL_DEFAULT_POOL_SHIFT; |
| 2182 | wr32(E1000_VT_CTL, vtctl); |
| 2183 | } |
| 2184 | |
| 2185 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2186 | * igb_configure_rx - Configure receive Unit after Reset |
| 2187 | * @adapter: board private structure |
| 2188 | * |
| 2189 | * Configure the Rx unit of the MAC after a reset. |
| 2190 | **/ |
| 2191 | static void igb_configure_rx(struct igb_adapter *adapter) |
| 2192 | { |
| 2193 | u64 rdba; |
| 2194 | struct e1000_hw *hw = &adapter->hw; |
| 2195 | u32 rctl, rxcsum; |
| 2196 | u32 rxdctl; |
Hannes Eder | 9107584 | 2009-02-18 19:36:04 -0800 | [diff] [blame] | 2197 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2198 | |
| 2199 | /* disable receives while setting up the descriptors */ |
| 2200 | rctl = rd32(E1000_RCTL); |
| 2201 | wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN); |
| 2202 | wrfl(); |
| 2203 | mdelay(10); |
| 2204 | |
| 2205 | if (adapter->itr_setting > 3) |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2206 | wr32(E1000_ITR, adapter->itr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2207 | |
| 2208 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2209 | * the Base and Length of the Rx Descriptor Ring */ |
| 2210 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2211 | struct igb_ring *ring = &adapter->rx_ring[i]; |
Hannes Eder | 9107584 | 2009-02-18 19:36:04 -0800 | [diff] [blame] | 2212 | int j = ring->reg_idx; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2213 | rdba = ring->dma; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2214 | wr32(E1000_RDBAL(j), |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2215 | rdba & 0x00000000ffffffffULL); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2216 | wr32(E1000_RDBAH(j), rdba >> 32); |
| 2217 | wr32(E1000_RDLEN(j), |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2218 | ring->count * sizeof(union e1000_adv_rx_desc)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2219 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2220 | ring->head = E1000_RDH(j); |
| 2221 | ring->tail = E1000_RDT(j); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2222 | writel(0, hw->hw_addr + ring->tail); |
| 2223 | writel(0, hw->hw_addr + ring->head); |
| 2224 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2225 | rxdctl = rd32(E1000_RXDCTL(j)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2226 | rxdctl |= E1000_RXDCTL_QUEUE_ENABLE; |
| 2227 | rxdctl &= 0xFFF00000; |
| 2228 | rxdctl |= IGB_RX_PTHRESH; |
| 2229 | rxdctl |= IGB_RX_HTHRESH << 8; |
| 2230 | rxdctl |= IGB_RX_WTHRESH << 16; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2231 | wr32(E1000_RXDCTL(j), rxdctl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | if (adapter->num_rx_queues > 1) { |
| 2235 | u32 random[10]; |
| 2236 | u32 mrqc; |
| 2237 | u32 j, shift; |
| 2238 | union e1000_reta { |
| 2239 | u32 dword; |
| 2240 | u8 bytes[4]; |
| 2241 | } reta; |
| 2242 | |
| 2243 | get_random_bytes(&random[0], 40); |
| 2244 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 2245 | if (hw->mac.type >= e1000_82576) |
| 2246 | shift = 0; |
| 2247 | else |
| 2248 | shift = 6; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2249 | for (j = 0; j < (32 * 4); j++) { |
| 2250 | reta.bytes[j & 3] = |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 2251 | adapter->rx_ring[(j % adapter->num_rx_queues)].reg_idx << shift; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2252 | if ((j & 3) == 3) |
| 2253 | writel(reta.dword, |
| 2254 | hw->hw_addr + E1000_RETA(0) + (j & ~3)); |
| 2255 | } |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2256 | if (adapter->vfs_allocated_count) |
| 2257 | mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q; |
| 2258 | else |
| 2259 | mrqc = E1000_MRQC_ENABLE_RSS_4Q; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2260 | |
| 2261 | /* Fill out hash function seeds */ |
| 2262 | for (j = 0; j < 10; j++) |
| 2263 | array_wr32(E1000_RSSRK(0), j, random[j]); |
| 2264 | |
| 2265 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 | |
| 2266 | E1000_MRQC_RSS_FIELD_IPV4_TCP); |
| 2267 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 | |
| 2268 | E1000_MRQC_RSS_FIELD_IPV6_TCP); |
| 2269 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP | |
| 2270 | E1000_MRQC_RSS_FIELD_IPV6_UDP); |
| 2271 | mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX | |
| 2272 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX); |
| 2273 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2274 | wr32(E1000_MRQC, mrqc); |
Alexander Duyck | 2844f79 | 2009-04-27 22:35:14 +0000 | [diff] [blame] | 2275 | } else if (adapter->vfs_allocated_count) { |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2276 | /* Enable multi-queue for sr-iov */ |
Alexander Duyck | 2844f79 | 2009-04-27 22:35:14 +0000 | [diff] [blame] | 2277 | wr32(E1000_MRQC, E1000_MRQC_ENABLE_VMDQ); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2278 | } |
| 2279 | |
Alexander Duyck | 2844f79 | 2009-04-27 22:35:14 +0000 | [diff] [blame] | 2280 | /* Enable Receive Checksum Offload for TCP and UDP */ |
| 2281 | rxcsum = rd32(E1000_RXCSUM); |
| 2282 | /* Disable raw packet checksumming */ |
| 2283 | rxcsum |= E1000_RXCSUM_PCSD; |
Alexander Duyck | 7beb014 | 2009-05-06 10:25:23 +0000 | [diff] [blame] | 2284 | |
| 2285 | if (adapter->hw.mac.type == e1000_82576) |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 2286 | /* Enable Receive Checksum Offload for SCTP */ |
| 2287 | rxcsum |= E1000_RXCSUM_CRCOFL; |
| 2288 | |
Alexander Duyck | 7beb014 | 2009-05-06 10:25:23 +0000 | [diff] [blame] | 2289 | /* Don't need to set TUOFL or IPOFL, they default to 1 */ |
Alexander Duyck | 2844f79 | 2009-04-27 22:35:14 +0000 | [diff] [blame] | 2290 | wr32(E1000_RXCSUM, rxcsum); |
| 2291 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2292 | /* Set the default pool for the PF's first queue */ |
| 2293 | igb_configure_vt_default_pool(adapter); |
| 2294 | |
| 2295 | igb_rlpml_set(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2296 | |
| 2297 | /* Enable Receives */ |
| 2298 | wr32(E1000_RCTL, rctl); |
| 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * igb_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2303 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2304 | * |
| 2305 | * Free all transmit software resources |
| 2306 | **/ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 2307 | void igb_free_tx_resources(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2308 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2309 | struct pci_dev *pdev = tx_ring->adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2310 | |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2311 | igb_clean_tx_ring(tx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2312 | |
| 2313 | vfree(tx_ring->buffer_info); |
| 2314 | tx_ring->buffer_info = NULL; |
| 2315 | |
| 2316 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 2317 | |
| 2318 | tx_ring->desc = NULL; |
| 2319 | } |
| 2320 | |
| 2321 | /** |
| 2322 | * igb_free_all_tx_resources - Free Tx Resources for All Queues |
| 2323 | * @adapter: board private structure |
| 2324 | * |
| 2325 | * Free all transmit software resources |
| 2326 | **/ |
| 2327 | static void igb_free_all_tx_resources(struct igb_adapter *adapter) |
| 2328 | { |
| 2329 | int i; |
| 2330 | |
| 2331 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2332 | igb_free_tx_resources(&adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | static void igb_unmap_and_free_tx_resource(struct igb_adapter *adapter, |
| 2336 | struct igb_buffer *buffer_info) |
| 2337 | { |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 2338 | buffer_info->dma = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2339 | if (buffer_info->skb) { |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 2340 | skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb, |
| 2341 | DMA_TO_DEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2342 | dev_kfree_skb_any(buffer_info->skb); |
| 2343 | buffer_info->skb = NULL; |
| 2344 | } |
| 2345 | buffer_info->time_stamp = 0; |
| 2346 | /* buffer_info must be completely set up in the transmit path */ |
| 2347 | } |
| 2348 | |
| 2349 | /** |
| 2350 | * igb_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2351 | * @tx_ring: ring to be cleaned |
| 2352 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2353 | static void igb_clean_tx_ring(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2354 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2355 | struct igb_adapter *adapter = tx_ring->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2356 | struct igb_buffer *buffer_info; |
| 2357 | unsigned long size; |
| 2358 | unsigned int i; |
| 2359 | |
| 2360 | if (!tx_ring->buffer_info) |
| 2361 | return; |
| 2362 | /* Free all the Tx ring sk_buffs */ |
| 2363 | |
| 2364 | for (i = 0; i < tx_ring->count; i++) { |
| 2365 | buffer_info = &tx_ring->buffer_info[i]; |
| 2366 | igb_unmap_and_free_tx_resource(adapter, buffer_info); |
| 2367 | } |
| 2368 | |
| 2369 | size = sizeof(struct igb_buffer) * tx_ring->count; |
| 2370 | memset(tx_ring->buffer_info, 0, size); |
| 2371 | |
| 2372 | /* Zero out the descriptor ring */ |
| 2373 | |
| 2374 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2375 | |
| 2376 | tx_ring->next_to_use = 0; |
| 2377 | tx_ring->next_to_clean = 0; |
| 2378 | |
| 2379 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2380 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 2381 | } |
| 2382 | |
| 2383 | /** |
| 2384 | * igb_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2385 | * @adapter: board private structure |
| 2386 | **/ |
| 2387 | static void igb_clean_all_tx_rings(struct igb_adapter *adapter) |
| 2388 | { |
| 2389 | int i; |
| 2390 | |
| 2391 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2392 | igb_clean_tx_ring(&adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | /** |
| 2396 | * igb_free_rx_resources - Free Rx Resources |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2397 | * @rx_ring: ring to clean the resources from |
| 2398 | * |
| 2399 | * Free all receive software resources |
| 2400 | **/ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 2401 | void igb_free_rx_resources(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2402 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2403 | struct pci_dev *pdev = rx_ring->adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2404 | |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2405 | igb_clean_rx_ring(rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2406 | |
| 2407 | vfree(rx_ring->buffer_info); |
| 2408 | rx_ring->buffer_info = NULL; |
| 2409 | |
| 2410 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 2411 | |
| 2412 | rx_ring->desc = NULL; |
| 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * igb_free_all_rx_resources - Free Rx Resources for All Queues |
| 2417 | * @adapter: board private structure |
| 2418 | * |
| 2419 | * Free all receive software resources |
| 2420 | **/ |
| 2421 | static void igb_free_all_rx_resources(struct igb_adapter *adapter) |
| 2422 | { |
| 2423 | int i; |
| 2424 | |
| 2425 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2426 | igb_free_rx_resources(&adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | /** |
| 2430 | * igb_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2431 | * @rx_ring: ring to free buffers from |
| 2432 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2433 | static void igb_clean_rx_ring(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2434 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2435 | struct igb_adapter *adapter = rx_ring->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2436 | struct igb_buffer *buffer_info; |
| 2437 | struct pci_dev *pdev = adapter->pdev; |
| 2438 | unsigned long size; |
| 2439 | unsigned int i; |
| 2440 | |
| 2441 | if (!rx_ring->buffer_info) |
| 2442 | return; |
| 2443 | /* Free all the Rx ring sk_buffs */ |
| 2444 | for (i = 0; i < rx_ring->count; i++) { |
| 2445 | buffer_info = &rx_ring->buffer_info[i]; |
| 2446 | if (buffer_info->dma) { |
| 2447 | if (adapter->rx_ps_hdr_size) |
| 2448 | pci_unmap_single(pdev, buffer_info->dma, |
| 2449 | adapter->rx_ps_hdr_size, |
| 2450 | PCI_DMA_FROMDEVICE); |
| 2451 | else |
| 2452 | pci_unmap_single(pdev, buffer_info->dma, |
| 2453 | adapter->rx_buffer_len, |
| 2454 | PCI_DMA_FROMDEVICE); |
| 2455 | buffer_info->dma = 0; |
| 2456 | } |
| 2457 | |
| 2458 | if (buffer_info->skb) { |
| 2459 | dev_kfree_skb(buffer_info->skb); |
| 2460 | buffer_info->skb = NULL; |
| 2461 | } |
| 2462 | if (buffer_info->page) { |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 2463 | if (buffer_info->page_dma) |
| 2464 | pci_unmap_page(pdev, buffer_info->page_dma, |
| 2465 | PAGE_SIZE / 2, |
| 2466 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2467 | put_page(buffer_info->page); |
| 2468 | buffer_info->page = NULL; |
| 2469 | buffer_info->page_dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 2470 | buffer_info->page_offset = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2474 | size = sizeof(struct igb_buffer) * rx_ring->count; |
| 2475 | memset(rx_ring->buffer_info, 0, size); |
| 2476 | |
| 2477 | /* Zero out the descriptor ring */ |
| 2478 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2479 | |
| 2480 | rx_ring->next_to_clean = 0; |
| 2481 | rx_ring->next_to_use = 0; |
| 2482 | |
| 2483 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2484 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * igb_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2489 | * @adapter: board private structure |
| 2490 | **/ |
| 2491 | static void igb_clean_all_rx_rings(struct igb_adapter *adapter) |
| 2492 | { |
| 2493 | int i; |
| 2494 | |
| 2495 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 2496 | igb_clean_rx_ring(&adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | /** |
| 2500 | * igb_set_mac - Change the Ethernet Address of the NIC |
| 2501 | * @netdev: network interface device structure |
| 2502 | * @p: pointer to an address structure |
| 2503 | * |
| 2504 | * Returns 0 on success, negative on failure |
| 2505 | **/ |
| 2506 | static int igb_set_mac(struct net_device *netdev, void *p) |
| 2507 | { |
| 2508 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2509 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2510 | struct sockaddr *addr = p; |
| 2511 | |
| 2512 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2513 | return -EADDRNOTAVAIL; |
| 2514 | |
| 2515 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2516 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2517 | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2518 | hw->mac.ops.rar_set(hw, hw->mac.addr, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2519 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2520 | igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0); |
| 2521 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2522 | return 0; |
| 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * igb_set_multi - Multicast and Promiscuous mode set |
| 2527 | * @netdev: network interface device structure |
| 2528 | * |
| 2529 | * The set_multi entry point is called whenever the multicast address |
| 2530 | * list or the network interface flags are updated. This routine is |
| 2531 | * responsible for configuring the hardware for proper multicast, |
| 2532 | * promiscuous mode, and all-multi behavior. |
| 2533 | **/ |
| 2534 | static void igb_set_multi(struct net_device *netdev) |
| 2535 | { |
| 2536 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 2537 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2538 | struct dev_mc_list *mc_ptr; |
Alexander Duyck | c5cd11e | 2009-03-20 00:17:25 +0000 | [diff] [blame] | 2539 | u8 *mta_list = NULL; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2540 | u32 rctl; |
| 2541 | int i; |
| 2542 | |
| 2543 | /* Check for Promiscuous and All Multicast modes */ |
| 2544 | |
| 2545 | rctl = rd32(E1000_RCTL); |
| 2546 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2547 | if (netdev->flags & IFF_PROMISC) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2548 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2549 | rctl &= ~E1000_RCTL_VFE; |
| 2550 | } else { |
| 2551 | if (netdev->flags & IFF_ALLMULTI) { |
| 2552 | rctl |= E1000_RCTL_MPE; |
| 2553 | rctl &= ~E1000_RCTL_UPE; |
| 2554 | } else |
| 2555 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE); |
Patrick McHardy | 78ed11a | 2008-07-16 20:16:14 -0700 | [diff] [blame] | 2556 | rctl |= E1000_RCTL_VFE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2557 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2558 | wr32(E1000_RCTL, rctl); |
| 2559 | |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame^] | 2560 | if (!netdev->mc_count) { |
| 2561 | /* nothing to program, so clear mc list */ |
| 2562 | igb_update_mc_addr_list(hw, NULL, 0); |
| 2563 | igb_restore_vf_multicasts(adapter); |
| 2564 | return; |
| 2565 | } |
| 2566 | |
| 2567 | mta_list = kzalloc(netdev->mc_count * 6, GFP_ATOMIC); |
| 2568 | if (!mta_list) { |
| 2569 | dev_err(&adapter->pdev->dev, |
| 2570 | "failed to allocate multicast filter list\n"); |
| 2571 | return; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2572 | } |
| 2573 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2574 | /* The shared function expects a packed array of only addresses. */ |
| 2575 | mc_ptr = netdev->mc_list; |
| 2576 | |
| 2577 | for (i = 0; i < netdev->mc_count; i++) { |
| 2578 | if (!mc_ptr) |
| 2579 | break; |
| 2580 | memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN); |
| 2581 | mc_ptr = mc_ptr->next; |
| 2582 | } |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame^] | 2583 | igb_update_mc_addr_list(hw, mta_list, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2584 | kfree(mta_list); |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame^] | 2585 | igb_restore_vf_multicasts(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 2589 | * the phy */ |
| 2590 | static void igb_update_phy_info(unsigned long data) |
| 2591 | { |
| 2592 | struct igb_adapter *adapter = (struct igb_adapter *) data; |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 2593 | igb_get_phy_info(&adapter->hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | /** |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 2597 | * igb_has_link - check shared code for link and determine up/down |
| 2598 | * @adapter: pointer to driver private info |
| 2599 | **/ |
| 2600 | static bool igb_has_link(struct igb_adapter *adapter) |
| 2601 | { |
| 2602 | struct e1000_hw *hw = &adapter->hw; |
| 2603 | bool link_active = false; |
| 2604 | s32 ret_val = 0; |
| 2605 | |
| 2606 | /* get_link_status is set on LSC (link status) interrupt or |
| 2607 | * rx sequence error interrupt. get_link_status will stay |
| 2608 | * false until the e1000_check_for_link establishes link |
| 2609 | * for copper adapters ONLY |
| 2610 | */ |
| 2611 | switch (hw->phy.media_type) { |
| 2612 | case e1000_media_type_copper: |
| 2613 | if (hw->mac.get_link_status) { |
| 2614 | ret_val = hw->mac.ops.check_for_link(hw); |
| 2615 | link_active = !hw->mac.get_link_status; |
| 2616 | } else { |
| 2617 | link_active = true; |
| 2618 | } |
| 2619 | break; |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 2620 | case e1000_media_type_internal_serdes: |
| 2621 | ret_val = hw->mac.ops.check_for_link(hw); |
| 2622 | link_active = hw->mac.serdes_has_link; |
| 2623 | break; |
| 2624 | default: |
| 2625 | case e1000_media_type_unknown: |
| 2626 | break; |
| 2627 | } |
| 2628 | |
| 2629 | return link_active; |
| 2630 | } |
| 2631 | |
| 2632 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2633 | * igb_watchdog - Timer Call-back |
| 2634 | * @data: pointer to adapter cast into an unsigned long |
| 2635 | **/ |
| 2636 | static void igb_watchdog(unsigned long data) |
| 2637 | { |
| 2638 | struct igb_adapter *adapter = (struct igb_adapter *)data; |
| 2639 | /* Do the rest outside of interrupt context */ |
| 2640 | schedule_work(&adapter->watchdog_task); |
| 2641 | } |
| 2642 | |
| 2643 | static void igb_watchdog_task(struct work_struct *work) |
| 2644 | { |
| 2645 | struct igb_adapter *adapter = container_of(work, |
| 2646 | struct igb_adapter, watchdog_task); |
| 2647 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2648 | struct net_device *netdev = adapter->netdev; |
| 2649 | struct igb_ring *tx_ring = adapter->tx_ring; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2650 | u32 link; |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 2651 | u32 eics = 0; |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 2652 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2653 | |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 2654 | link = igb_has_link(adapter); |
| 2655 | if ((netif_carrier_ok(netdev)) && link) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2656 | goto link_up; |
| 2657 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2658 | if (link) { |
| 2659 | if (!netif_carrier_ok(netdev)) { |
| 2660 | u32 ctrl; |
| 2661 | hw->mac.ops.get_speed_and_duplex(&adapter->hw, |
| 2662 | &adapter->link_speed, |
| 2663 | &adapter->link_duplex); |
| 2664 | |
| 2665 | ctrl = rd32(E1000_CTRL); |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 2666 | /* Links status message must follow this format */ |
| 2667 | printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, " |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2668 | "Flow Control: %s\n", |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 2669 | netdev->name, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2670 | adapter->link_speed, |
| 2671 | adapter->link_duplex == FULL_DUPLEX ? |
| 2672 | "Full Duplex" : "Half Duplex", |
| 2673 | ((ctrl & E1000_CTRL_TFCE) && (ctrl & |
| 2674 | E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl & |
| 2675 | E1000_CTRL_RFCE) ? "RX" : ((ctrl & |
| 2676 | E1000_CTRL_TFCE) ? "TX" : "None"))); |
| 2677 | |
| 2678 | /* tweak tx_queue_len according to speed/duplex and |
| 2679 | * adjust the timeout factor */ |
| 2680 | netdev->tx_queue_len = adapter->tx_queue_len; |
| 2681 | adapter->tx_timeout_factor = 1; |
| 2682 | switch (adapter->link_speed) { |
| 2683 | case SPEED_10: |
| 2684 | netdev->tx_queue_len = 10; |
| 2685 | adapter->tx_timeout_factor = 14; |
| 2686 | break; |
| 2687 | case SPEED_100: |
| 2688 | netdev->tx_queue_len = 100; |
| 2689 | /* maybe add some timeout factor ? */ |
| 2690 | break; |
| 2691 | } |
| 2692 | |
| 2693 | netif_carrier_on(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2694 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 2695 | igb_ping_all_vfs(adapter); |
| 2696 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 2697 | /* link state has changed, schedule phy info update */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2698 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 2699 | mod_timer(&adapter->phy_info_timer, |
| 2700 | round_jiffies(jiffies + 2 * HZ)); |
| 2701 | } |
| 2702 | } else { |
| 2703 | if (netif_carrier_ok(netdev)) { |
| 2704 | adapter->link_speed = 0; |
| 2705 | adapter->link_duplex = 0; |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 2706 | /* Links status message must follow this format */ |
| 2707 | printk(KERN_INFO "igb: %s NIC Link is Down\n", |
| 2708 | netdev->name); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2709 | netif_carrier_off(netdev); |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 2710 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 2711 | igb_ping_all_vfs(adapter); |
| 2712 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 2713 | /* link state has changed, schedule phy info update */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2714 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 2715 | mod_timer(&adapter->phy_info_timer, |
| 2716 | round_jiffies(jiffies + 2 * HZ)); |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | link_up: |
| 2721 | igb_update_stats(adapter); |
| 2722 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 2723 | hw->mac.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2724 | adapter->tpt_old = adapter->stats.tpt; |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 2725 | hw->mac.collision_delta = adapter->stats.colc - adapter->colc_old; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2726 | adapter->colc_old = adapter->stats.colc; |
| 2727 | |
| 2728 | adapter->gorc = adapter->stats.gorc - adapter->gorc_old; |
| 2729 | adapter->gorc_old = adapter->stats.gorc; |
| 2730 | adapter->gotc = adapter->stats.gotc - adapter->gotc_old; |
| 2731 | adapter->gotc_old = adapter->stats.gotc; |
| 2732 | |
| 2733 | igb_update_adaptive(&adapter->hw); |
| 2734 | |
| 2735 | if (!netif_carrier_ok(netdev)) { |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 2736 | if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2737 | /* We've lost link, so the controller stops DMA, |
| 2738 | * but we've got queued Tx work that's never going |
| 2739 | * to get done, so reset controller to flush Tx. |
| 2740 | * (Do the reset outside of interrupt context). */ |
| 2741 | adapter->tx_timeout_count++; |
| 2742 | schedule_work(&adapter->reset_task); |
Jesse Brandeburg | c2d5ab4 | 2009-05-07 11:07:35 +0000 | [diff] [blame] | 2743 | /* return immediately since reset is imminent */ |
| 2744 | return; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | /* Cause software interrupt to ensure rx ring is cleaned */ |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 2749 | if (adapter->msix_entries) { |
| 2750 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2751 | eics |= adapter->rx_ring[i].eims_value; |
| 2752 | wr32(E1000_EICS, eics); |
| 2753 | } else { |
| 2754 | wr32(E1000_ICS, E1000_ICS_RXDMT0); |
| 2755 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2756 | |
| 2757 | /* Force detection of hung controller every watchdog period */ |
| 2758 | tx_ring->detect_tx_hung = true; |
| 2759 | |
| 2760 | /* Reset the timer */ |
| 2761 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 2762 | mod_timer(&adapter->watchdog_timer, |
| 2763 | round_jiffies(jiffies + 2 * HZ)); |
| 2764 | } |
| 2765 | |
| 2766 | enum latency_range { |
| 2767 | lowest_latency = 0, |
| 2768 | low_latency = 1, |
| 2769 | bulk_latency = 2, |
| 2770 | latency_invalid = 255 |
| 2771 | }; |
| 2772 | |
| 2773 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2774 | /** |
| 2775 | * igb_update_ring_itr - update the dynamic ITR value based on packet size |
| 2776 | * |
| 2777 | * Stores a new ITR value based on strictly on packet size. This |
| 2778 | * algorithm is less sophisticated than that used in igb_update_itr, |
| 2779 | * due to the difficulty of synchronizing statistics across multiple |
| 2780 | * receive rings. The divisors and thresholds used by this fuction |
| 2781 | * were determined based on theoretical maximum wire speed and testing |
| 2782 | * data, in order to minimize response time while increasing bulk |
| 2783 | * throughput. |
| 2784 | * This functionality is controlled by the InterruptThrottleRate module |
| 2785 | * parameter (see igb_param.c) |
| 2786 | * NOTE: This function is called only when operating in a multiqueue |
| 2787 | * receive environment. |
| 2788 | * @rx_ring: pointer to ring |
| 2789 | **/ |
| 2790 | static void igb_update_ring_itr(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2791 | { |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2792 | int new_val = rx_ring->itr_val; |
| 2793 | int avg_wire_size = 0; |
| 2794 | struct igb_adapter *adapter = rx_ring->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2795 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2796 | if (!rx_ring->total_packets) |
| 2797 | goto clear_counts; /* no packets, so don't do anything */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2798 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2799 | /* For non-gigabit speeds, just fix the interrupt rate at 4000 |
| 2800 | * ints/sec - ITR timer value of 120 ticks. |
| 2801 | */ |
| 2802 | if (adapter->link_speed != SPEED_1000) { |
| 2803 | new_val = 120; |
| 2804 | goto set_itr_val; |
| 2805 | } |
| 2806 | avg_wire_size = rx_ring->total_bytes / rx_ring->total_packets; |
| 2807 | |
| 2808 | /* Add 24 bytes to size to account for CRC, preamble, and gap */ |
| 2809 | avg_wire_size += 24; |
| 2810 | |
| 2811 | /* Don't starve jumbo frames */ |
| 2812 | avg_wire_size = min(avg_wire_size, 3000); |
| 2813 | |
| 2814 | /* Give a little boost to mid-size frames */ |
| 2815 | if ((avg_wire_size > 300) && (avg_wire_size < 1200)) |
| 2816 | new_val = avg_wire_size / 3; |
| 2817 | else |
| 2818 | new_val = avg_wire_size / 2; |
| 2819 | |
| 2820 | set_itr_val: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2821 | if (new_val != rx_ring->itr_val) { |
| 2822 | rx_ring->itr_val = new_val; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2823 | rx_ring->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2824 | } |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2825 | clear_counts: |
| 2826 | rx_ring->total_bytes = 0; |
| 2827 | rx_ring->total_packets = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * igb_update_itr - update the dynamic ITR value based on statistics |
| 2832 | * Stores a new ITR value based on packets and byte |
| 2833 | * counts during the last interrupt. The advantage of per interrupt |
| 2834 | * computation is faster updates and more accurate ITR for the current |
| 2835 | * traffic pattern. Constants in this function were computed |
| 2836 | * based on theoretical maximum wire speed and thresholds were set based |
| 2837 | * on testing data as well as attempting to minimize response time |
| 2838 | * while increasing bulk throughput. |
| 2839 | * this functionality is controlled by the InterruptThrottleRate module |
| 2840 | * parameter (see igb_param.c) |
| 2841 | * NOTE: These calculations are only valid when operating in a single- |
| 2842 | * queue environment. |
| 2843 | * @adapter: pointer to adapter |
| 2844 | * @itr_setting: current adapter->itr |
| 2845 | * @packets: the number of packets during this measurement interval |
| 2846 | * @bytes: the number of bytes during this measurement interval |
| 2847 | **/ |
| 2848 | static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting, |
| 2849 | int packets, int bytes) |
| 2850 | { |
| 2851 | unsigned int retval = itr_setting; |
| 2852 | |
| 2853 | if (packets == 0) |
| 2854 | goto update_itr_done; |
| 2855 | |
| 2856 | switch (itr_setting) { |
| 2857 | case lowest_latency: |
| 2858 | /* handle TSO and jumbo frames */ |
| 2859 | if (bytes/packets > 8000) |
| 2860 | retval = bulk_latency; |
| 2861 | else if ((packets < 5) && (bytes > 512)) |
| 2862 | retval = low_latency; |
| 2863 | break; |
| 2864 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 2865 | if (bytes > 10000) { |
| 2866 | /* this if handles the TSO accounting */ |
| 2867 | if (bytes/packets > 8000) { |
| 2868 | retval = bulk_latency; |
| 2869 | } else if ((packets < 10) || ((bytes/packets) > 1200)) { |
| 2870 | retval = bulk_latency; |
| 2871 | } else if ((packets > 35)) { |
| 2872 | retval = lowest_latency; |
| 2873 | } |
| 2874 | } else if (bytes/packets > 2000) { |
| 2875 | retval = bulk_latency; |
| 2876 | } else if (packets <= 2 && bytes < 512) { |
| 2877 | retval = lowest_latency; |
| 2878 | } |
| 2879 | break; |
| 2880 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 2881 | if (bytes > 25000) { |
| 2882 | if (packets > 35) |
| 2883 | retval = low_latency; |
Alexander Duyck | 1e5c3d2 | 2009-02-12 18:17:21 +0000 | [diff] [blame] | 2884 | } else if (bytes < 1500) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2885 | retval = low_latency; |
| 2886 | } |
| 2887 | break; |
| 2888 | } |
| 2889 | |
| 2890 | update_itr_done: |
| 2891 | return retval; |
| 2892 | } |
| 2893 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2894 | static void igb_set_itr(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2895 | { |
| 2896 | u16 current_itr; |
| 2897 | u32 new_itr = adapter->itr; |
| 2898 | |
| 2899 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 2900 | if (adapter->link_speed != SPEED_1000) { |
| 2901 | current_itr = 0; |
| 2902 | new_itr = 4000; |
| 2903 | goto set_itr_now; |
| 2904 | } |
| 2905 | |
| 2906 | adapter->rx_itr = igb_update_itr(adapter, |
| 2907 | adapter->rx_itr, |
| 2908 | adapter->rx_ring->total_packets, |
| 2909 | adapter->rx_ring->total_bytes); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2910 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2911 | if (adapter->rx_ring->buddy) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2912 | adapter->tx_itr = igb_update_itr(adapter, |
| 2913 | adapter->tx_itr, |
| 2914 | adapter->tx_ring->total_packets, |
| 2915 | adapter->tx_ring->total_bytes); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2916 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
| 2917 | } else { |
| 2918 | current_itr = adapter->rx_itr; |
| 2919 | } |
| 2920 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2921 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2922 | if (adapter->itr_setting == 3 && current_itr == lowest_latency) |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2923 | current_itr = low_latency; |
| 2924 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2925 | switch (current_itr) { |
| 2926 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2927 | case lowest_latency: |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 2928 | new_itr = 56; /* aka 70,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2929 | break; |
| 2930 | case low_latency: |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 2931 | new_itr = 196; /* aka 20,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2932 | break; |
| 2933 | case bulk_latency: |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 2934 | new_itr = 980; /* aka 4,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2935 | break; |
| 2936 | default: |
| 2937 | break; |
| 2938 | } |
| 2939 | |
| 2940 | set_itr_now: |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2941 | adapter->rx_ring->total_bytes = 0; |
| 2942 | adapter->rx_ring->total_packets = 0; |
| 2943 | if (adapter->rx_ring->buddy) { |
| 2944 | adapter->rx_ring->buddy->total_bytes = 0; |
| 2945 | adapter->rx_ring->buddy->total_packets = 0; |
| 2946 | } |
| 2947 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2948 | if (new_itr != adapter->itr) { |
| 2949 | /* this attempts to bias the interrupt rate towards Bulk |
| 2950 | * by adding intermediate steps when interrupt rate is |
| 2951 | * increasing */ |
| 2952 | new_itr = new_itr > adapter->itr ? |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 2953 | max((new_itr * adapter->itr) / |
| 2954 | (new_itr + (adapter->itr >> 2)), new_itr) : |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2955 | new_itr; |
| 2956 | /* Don't write the value here; it resets the adapter's |
| 2957 | * internal timer, and causes us to delay far longer than |
| 2958 | * we should between interrupts. Instead, we write the ITR |
| 2959 | * value at the beginning of the next interrupt so the timing |
| 2960 | * ends up being correct. |
| 2961 | */ |
| 2962 | adapter->itr = new_itr; |
Alexander Duyck | 78b1f607 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 2963 | adapter->rx_ring->itr_val = new_itr; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 2964 | adapter->rx_ring->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | return; |
| 2968 | } |
| 2969 | |
| 2970 | |
| 2971 | #define IGB_TX_FLAGS_CSUM 0x00000001 |
| 2972 | #define IGB_TX_FLAGS_VLAN 0x00000002 |
| 2973 | #define IGB_TX_FLAGS_TSO 0x00000004 |
| 2974 | #define IGB_TX_FLAGS_IPV4 0x00000008 |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 2975 | #define IGB_TX_FLAGS_TSTAMP 0x00000010 |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2976 | #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 2977 | #define IGB_TX_FLAGS_VLAN_SHIFT 16 |
| 2978 | |
| 2979 | static inline int igb_tso_adv(struct igb_adapter *adapter, |
| 2980 | struct igb_ring *tx_ring, |
| 2981 | struct sk_buff *skb, u32 tx_flags, u8 *hdr_len) |
| 2982 | { |
| 2983 | struct e1000_adv_tx_context_desc *context_desc; |
| 2984 | unsigned int i; |
| 2985 | int err; |
| 2986 | struct igb_buffer *buffer_info; |
| 2987 | u32 info = 0, tu_cmd = 0; |
| 2988 | u32 mss_l4len_idx, l4len; |
| 2989 | *hdr_len = 0; |
| 2990 | |
| 2991 | if (skb_header_cloned(skb)) { |
| 2992 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2993 | if (err) |
| 2994 | return err; |
| 2995 | } |
| 2996 | |
| 2997 | l4len = tcp_hdrlen(skb); |
| 2998 | *hdr_len += l4len; |
| 2999 | |
| 3000 | if (skb->protocol == htons(ETH_P_IP)) { |
| 3001 | struct iphdr *iph = ip_hdr(skb); |
| 3002 | iph->tot_len = 0; |
| 3003 | iph->check = 0; |
| 3004 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 3005 | iph->daddr, 0, |
| 3006 | IPPROTO_TCP, |
| 3007 | 0); |
| 3008 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 3009 | ipv6_hdr(skb)->payload_len = 0; |
| 3010 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 3011 | &ipv6_hdr(skb)->daddr, |
| 3012 | 0, IPPROTO_TCP, 0); |
| 3013 | } |
| 3014 | |
| 3015 | i = tx_ring->next_to_use; |
| 3016 | |
| 3017 | buffer_info = &tx_ring->buffer_info[i]; |
| 3018 | context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3019 | /* VLAN MACLEN IPLEN */ |
| 3020 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 3021 | info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK); |
| 3022 | info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT); |
| 3023 | *hdr_len += skb_network_offset(skb); |
| 3024 | info |= skb_network_header_len(skb); |
| 3025 | *hdr_len += skb_network_header_len(skb); |
| 3026 | context_desc->vlan_macip_lens = cpu_to_le32(info); |
| 3027 | |
| 3028 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 3029 | tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT); |
| 3030 | |
| 3031 | if (skb->protocol == htons(ETH_P_IP)) |
| 3032 | tu_cmd |= E1000_ADVTXD_TUCMD_IPV4; |
| 3033 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
| 3034 | |
| 3035 | context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd); |
| 3036 | |
| 3037 | /* MSS L4LEN IDX */ |
| 3038 | mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT); |
| 3039 | mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT); |
| 3040 | |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3041 | /* For 82575, context index must be unique per ring. */ |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3042 | if (adapter->flags & IGB_FLAG_NEED_CTX_IDX) |
| 3043 | mss_l4len_idx |= tx_ring->queue_index << 4; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3044 | |
| 3045 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 3046 | context_desc->seqnum_seed = 0; |
| 3047 | |
| 3048 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3049 | buffer_info->next_to_watch = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3050 | buffer_info->dma = 0; |
| 3051 | i++; |
| 3052 | if (i == tx_ring->count) |
| 3053 | i = 0; |
| 3054 | |
| 3055 | tx_ring->next_to_use = i; |
| 3056 | |
| 3057 | return true; |
| 3058 | } |
| 3059 | |
| 3060 | static inline bool igb_tx_csum_adv(struct igb_adapter *adapter, |
| 3061 | struct igb_ring *tx_ring, |
| 3062 | struct sk_buff *skb, u32 tx_flags) |
| 3063 | { |
| 3064 | struct e1000_adv_tx_context_desc *context_desc; |
| 3065 | unsigned int i; |
| 3066 | struct igb_buffer *buffer_info; |
| 3067 | u32 info = 0, tu_cmd = 0; |
| 3068 | |
| 3069 | if ((skb->ip_summed == CHECKSUM_PARTIAL) || |
| 3070 | (tx_flags & IGB_TX_FLAGS_VLAN)) { |
| 3071 | i = tx_ring->next_to_use; |
| 3072 | buffer_info = &tx_ring->buffer_info[i]; |
| 3073 | context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3074 | |
| 3075 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 3076 | info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK); |
| 3077 | info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT); |
| 3078 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 3079 | info |= skb_network_header_len(skb); |
| 3080 | |
| 3081 | context_desc->vlan_macip_lens = cpu_to_le32(info); |
| 3082 | |
| 3083 | tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT); |
| 3084 | |
| 3085 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arthur Jones | fa4a7ef | 2009-03-21 16:55:07 -0700 | [diff] [blame] | 3086 | __be16 protocol; |
| 3087 | |
| 3088 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) { |
| 3089 | const struct vlan_ethhdr *vhdr = |
| 3090 | (const struct vlan_ethhdr*)skb->data; |
| 3091 | |
| 3092 | protocol = vhdr->h_vlan_encapsulated_proto; |
| 3093 | } else { |
| 3094 | protocol = skb->protocol; |
| 3095 | } |
| 3096 | |
| 3097 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3098 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3099 | tu_cmd |= E1000_ADVTXD_TUCMD_IPV4; |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3100 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 3101 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 3102 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 3103 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP; |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3104 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3105 | case cpu_to_be16(ETH_P_IPV6): |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3106 | /* XXX what about other V6 headers?? */ |
| 3107 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 3108 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 3109 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 3110 | tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP; |
Mitch Williams | 44b0cda | 2008-03-07 10:32:13 -0800 | [diff] [blame] | 3111 | break; |
| 3112 | default: |
| 3113 | if (unlikely(net_ratelimit())) |
| 3114 | dev_warn(&adapter->pdev->dev, |
| 3115 | "partial checksum but proto=%x!\n", |
| 3116 | skb->protocol); |
| 3117 | break; |
| 3118 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd); |
| 3122 | context_desc->seqnum_seed = 0; |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3123 | if (adapter->flags & IGB_FLAG_NEED_CTX_IDX) |
| 3124 | context_desc->mss_l4len_idx = |
| 3125 | cpu_to_le32(tx_ring->queue_index << 4); |
Alexander Duyck | 265de40 | 2009-02-06 23:22:52 +0000 | [diff] [blame] | 3126 | else |
| 3127 | context_desc->mss_l4len_idx = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3128 | |
| 3129 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3130 | buffer_info->next_to_watch = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3131 | buffer_info->dma = 0; |
| 3132 | |
| 3133 | i++; |
| 3134 | if (i == tx_ring->count) |
| 3135 | i = 0; |
| 3136 | tx_ring->next_to_use = i; |
| 3137 | |
| 3138 | return true; |
| 3139 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3140 | return false; |
| 3141 | } |
| 3142 | |
| 3143 | #define IGB_MAX_TXD_PWR 16 |
| 3144 | #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR) |
| 3145 | |
| 3146 | static inline int igb_tx_map_adv(struct igb_adapter *adapter, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3147 | struct igb_ring *tx_ring, struct sk_buff *skb, |
| 3148 | unsigned int first) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3149 | { |
| 3150 | struct igb_buffer *buffer_info; |
| 3151 | unsigned int len = skb_headlen(skb); |
| 3152 | unsigned int count = 0, i; |
| 3153 | unsigned int f; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3154 | dma_addr_t *map; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3155 | |
| 3156 | i = tx_ring->next_to_use; |
| 3157 | |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3158 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 3159 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
| 3160 | return 0; |
| 3161 | } |
| 3162 | |
| 3163 | map = skb_shinfo(skb)->dma_maps; |
| 3164 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3165 | buffer_info = &tx_ring->buffer_info[i]; |
| 3166 | BUG_ON(len >= IGB_MAX_DATA_PER_TXD); |
| 3167 | buffer_info->length = len; |
| 3168 | /* set time_stamp *before* dma to help avoid a possible race */ |
| 3169 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3170 | buffer_info->next_to_watch = i; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3171 | buffer_info->dma = skb_shinfo(skb)->dma_head; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3172 | |
| 3173 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { |
| 3174 | struct skb_frag_struct *frag; |
| 3175 | |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3176 | i++; |
| 3177 | if (i == tx_ring->count) |
| 3178 | i = 0; |
| 3179 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3180 | frag = &skb_shinfo(skb)->frags[f]; |
| 3181 | len = frag->size; |
| 3182 | |
| 3183 | buffer_info = &tx_ring->buffer_info[i]; |
| 3184 | BUG_ON(len >= IGB_MAX_DATA_PER_TXD); |
| 3185 | buffer_info->length = len; |
| 3186 | buffer_info->time_stamp = jiffies; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3187 | buffer_info->next_to_watch = i; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3188 | buffer_info->dma = map[count]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3189 | count++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3190 | } |
| 3191 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3192 | tx_ring->buffer_info[i].skb = skb; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3193 | tx_ring->buffer_info[first].next_to_watch = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3194 | |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 3195 | return count + 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | static inline void igb_tx_queue_adv(struct igb_adapter *adapter, |
| 3199 | struct igb_ring *tx_ring, |
| 3200 | int tx_flags, int count, u32 paylen, |
| 3201 | u8 hdr_len) |
| 3202 | { |
| 3203 | union e1000_adv_tx_desc *tx_desc = NULL; |
| 3204 | struct igb_buffer *buffer_info; |
| 3205 | u32 olinfo_status = 0, cmd_type_len; |
| 3206 | unsigned int i; |
| 3207 | |
| 3208 | cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS | |
| 3209 | E1000_ADVTXD_DCMD_DEXT); |
| 3210 | |
| 3211 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 3212 | cmd_type_len |= E1000_ADVTXD_DCMD_VLE; |
| 3213 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 3214 | if (tx_flags & IGB_TX_FLAGS_TSTAMP) |
| 3215 | cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP; |
| 3216 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3217 | if (tx_flags & IGB_TX_FLAGS_TSO) { |
| 3218 | cmd_type_len |= E1000_ADVTXD_DCMD_TSE; |
| 3219 | |
| 3220 | /* insert tcp checksum */ |
| 3221 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; |
| 3222 | |
| 3223 | /* insert ip checksum */ |
| 3224 | if (tx_flags & IGB_TX_FLAGS_IPV4) |
| 3225 | olinfo_status |= E1000_TXD_POPTS_IXSM << 8; |
| 3226 | |
| 3227 | } else if (tx_flags & IGB_TX_FLAGS_CSUM) { |
| 3228 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; |
| 3229 | } |
| 3230 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3231 | if ((adapter->flags & IGB_FLAG_NEED_CTX_IDX) && |
| 3232 | (tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_TSO | |
| 3233 | IGB_TX_FLAGS_VLAN))) |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3234 | olinfo_status |= tx_ring->queue_index << 4; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3235 | |
| 3236 | olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT); |
| 3237 | |
| 3238 | i = tx_ring->next_to_use; |
| 3239 | while (count--) { |
| 3240 | buffer_info = &tx_ring->buffer_info[i]; |
| 3241 | tx_desc = E1000_TX_DESC_ADV(*tx_ring, i); |
| 3242 | tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
| 3243 | tx_desc->read.cmd_type_len = |
| 3244 | cpu_to_le32(cmd_type_len | buffer_info->length); |
| 3245 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
| 3246 | i++; |
| 3247 | if (i == tx_ring->count) |
| 3248 | i = 0; |
| 3249 | } |
| 3250 | |
| 3251 | tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd); |
| 3252 | /* Force memory writes to complete before letting h/w |
| 3253 | * know there are new descriptors to fetch. (Only |
| 3254 | * applicable for weak-ordered memory model archs, |
| 3255 | * such as IA-64). */ |
| 3256 | wmb(); |
| 3257 | |
| 3258 | tx_ring->next_to_use = i; |
| 3259 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 3260 | /* we need this if more than one processor can write to our tail |
| 3261 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 3262 | mmiowb(); |
| 3263 | } |
| 3264 | |
| 3265 | static int __igb_maybe_stop_tx(struct net_device *netdev, |
| 3266 | struct igb_ring *tx_ring, int size) |
| 3267 | { |
| 3268 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3269 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3270 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3271 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3272 | /* Herbert's original patch had: |
| 3273 | * smp_mb__after_netif_stop_queue(); |
| 3274 | * but since that doesn't exist yet, just open code it. */ |
| 3275 | smp_mb(); |
| 3276 | |
| 3277 | /* We need to check again in a case another CPU has just |
| 3278 | * made room available. */ |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 3279 | if (igb_desc_unused(tx_ring) < size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3280 | return -EBUSY; |
| 3281 | |
| 3282 | /* A reprieve! */ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3283 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3284 | ++adapter->restart_queue; |
| 3285 | return 0; |
| 3286 | } |
| 3287 | |
| 3288 | static int igb_maybe_stop_tx(struct net_device *netdev, |
| 3289 | struct igb_ring *tx_ring, int size) |
| 3290 | { |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 3291 | if (igb_desc_unused(tx_ring) >= size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3292 | return 0; |
| 3293 | return __igb_maybe_stop_tx(netdev, tx_ring, size); |
| 3294 | } |
| 3295 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3296 | static int igb_xmit_frame_ring_adv(struct sk_buff *skb, |
| 3297 | struct net_device *netdev, |
| 3298 | struct igb_ring *tx_ring) |
| 3299 | { |
| 3300 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3301 | unsigned int first; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3302 | unsigned int tx_flags = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3303 | u8 hdr_len = 0; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3304 | int count = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3305 | int tso = 0; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 3306 | union skb_shared_tx *shtx; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3307 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3308 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 3309 | dev_kfree_skb_any(skb); |
| 3310 | return NETDEV_TX_OK; |
| 3311 | } |
| 3312 | |
| 3313 | if (skb->len <= 0) { |
| 3314 | dev_kfree_skb_any(skb); |
| 3315 | return NETDEV_TX_OK; |
| 3316 | } |
| 3317 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3318 | /* need: 1 descriptor per page, |
| 3319 | * + 2 desc gap to keep tail from touching head, |
| 3320 | * + 1 desc for skb->data, |
| 3321 | * + 1 desc for context descriptor, |
| 3322 | * otherwise try next time */ |
| 3323 | if (igb_maybe_stop_tx(netdev, tx_ring, skb_shinfo(skb)->nr_frags + 4)) { |
| 3324 | /* this is a hard error */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3325 | return NETDEV_TX_BUSY; |
| 3326 | } |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 3327 | |
| 3328 | /* |
| 3329 | * TODO: check that there currently is no other packet with |
| 3330 | * time stamping in the queue |
| 3331 | * |
| 3332 | * When doing time stamping, keep the connection to the socket |
| 3333 | * a while longer: it is still needed by skb_hwtstamp_tx(), |
| 3334 | * called either in igb_tx_hwtstamp() or by our caller when |
| 3335 | * doing software time stamping. |
| 3336 | */ |
| 3337 | shtx = skb_tx(skb); |
| 3338 | if (unlikely(shtx->hardware)) { |
| 3339 | shtx->in_progress = 1; |
| 3340 | tx_flags |= IGB_TX_FLAGS_TSTAMP; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 3341 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3342 | |
| 3343 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 3344 | tx_flags |= IGB_TX_FLAGS_VLAN; |
| 3345 | tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT); |
| 3346 | } |
| 3347 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3348 | if (skb->protocol == htons(ETH_P_IP)) |
| 3349 | tx_flags |= IGB_TX_FLAGS_IPV4; |
| 3350 | |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 3351 | first = tx_ring->next_to_use; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3352 | tso = skb_is_gso(skb) ? igb_tso_adv(adapter, tx_ring, skb, tx_flags, |
| 3353 | &hdr_len) : 0; |
| 3354 | |
| 3355 | if (tso < 0) { |
| 3356 | dev_kfree_skb_any(skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3357 | return NETDEV_TX_OK; |
| 3358 | } |
| 3359 | |
| 3360 | if (tso) |
| 3361 | tx_flags |= IGB_TX_FLAGS_TSO; |
Alexander Duyck | bc1cbd3 | 2009-02-13 14:45:17 +0000 | [diff] [blame] | 3362 | else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags) && |
| 3363 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 3364 | tx_flags |= IGB_TX_FLAGS_CSUM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3365 | |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3366 | /* |
| 3367 | * count reflects descriptors mapped, if 0 then mapping error |
| 3368 | * has occured and we need to rewind the descriptor queue |
| 3369 | */ |
| 3370 | count = igb_tx_map_adv(adapter, tx_ring, skb, first); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3371 | |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3372 | if (count) { |
| 3373 | igb_tx_queue_adv(adapter, tx_ring, tx_flags, count, |
| 3374 | skb->len, hdr_len); |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 3375 | /* Make sure there is space in the ring for the next send. */ |
| 3376 | igb_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 4); |
| 3377 | } else { |
| 3378 | dev_kfree_skb_any(skb); |
| 3379 | tx_ring->buffer_info[first].time_stamp = 0; |
| 3380 | tx_ring->next_to_use = first; |
| 3381 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3382 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3383 | return NETDEV_TX_OK; |
| 3384 | } |
| 3385 | |
| 3386 | static int igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *netdev) |
| 3387 | { |
| 3388 | struct igb_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3389 | struct igb_ring *tx_ring; |
| 3390 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3391 | int r_idx = 0; |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 3392 | r_idx = skb->queue_mapping & (IGB_ABS_MAX_TX_QUEUES - 1); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3393 | tx_ring = adapter->multi_tx_table[r_idx]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3394 | |
| 3395 | /* This goes back to the question of how to logically map a tx queue |
| 3396 | * to a flow. Right now, performance is impacted slightly negatively |
| 3397 | * if using multiple tx queues. If the stack breaks away from a |
| 3398 | * single qdisc implementation, we can look at this again. */ |
| 3399 | return (igb_xmit_frame_ring_adv(skb, netdev, tx_ring)); |
| 3400 | } |
| 3401 | |
| 3402 | /** |
| 3403 | * igb_tx_timeout - Respond to a Tx Hang |
| 3404 | * @netdev: network interface device structure |
| 3405 | **/ |
| 3406 | static void igb_tx_timeout(struct net_device *netdev) |
| 3407 | { |
| 3408 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3409 | struct e1000_hw *hw = &adapter->hw; |
| 3410 | |
| 3411 | /* Do the reset outside of interrupt context */ |
| 3412 | adapter->tx_timeout_count++; |
| 3413 | schedule_work(&adapter->reset_task); |
Alexander Duyck | 265de40 | 2009-02-06 23:22:52 +0000 | [diff] [blame] | 3414 | wr32(E1000_EICS, |
| 3415 | (adapter->eims_enable_mask & ~adapter->eims_other)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | static void igb_reset_task(struct work_struct *work) |
| 3419 | { |
| 3420 | struct igb_adapter *adapter; |
| 3421 | adapter = container_of(work, struct igb_adapter, reset_task); |
| 3422 | |
| 3423 | igb_reinit_locked(adapter); |
| 3424 | } |
| 3425 | |
| 3426 | /** |
| 3427 | * igb_get_stats - Get System Network Statistics |
| 3428 | * @netdev: network interface device structure |
| 3429 | * |
| 3430 | * Returns the address of the device statistics structure. |
| 3431 | * The statistics are actually updated from the timer callback. |
| 3432 | **/ |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3433 | static struct net_device_stats *igb_get_stats(struct net_device *netdev) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3434 | { |
| 3435 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3436 | |
| 3437 | /* only return the current stats */ |
| 3438 | return &adapter->net_stats; |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * igb_change_mtu - Change the Maximum Transfer Unit |
| 3443 | * @netdev: network interface device structure |
| 3444 | * @new_mtu: new value for maximum frame size |
| 3445 | * |
| 3446 | * Returns 0 on success, negative on failure |
| 3447 | **/ |
| 3448 | static int igb_change_mtu(struct net_device *netdev, int new_mtu) |
| 3449 | { |
| 3450 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3451 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3452 | |
| 3453 | if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) || |
| 3454 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 3455 | dev_err(&adapter->pdev->dev, "Invalid MTU setting\n"); |
| 3456 | return -EINVAL; |
| 3457 | } |
| 3458 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3459 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
| 3460 | dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n"); |
| 3461 | return -EINVAL; |
| 3462 | } |
| 3463 | |
| 3464 | while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) |
| 3465 | msleep(1); |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3466 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3467 | /* igb_down has a dependency on max_frame_size */ |
| 3468 | adapter->max_frame_size = max_frame; |
| 3469 | if (netif_running(netdev)) |
| 3470 | igb_down(adapter); |
| 3471 | |
| 3472 | /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN |
| 3473 | * means we reserve 2 more, this pushes us to allocate from the next |
| 3474 | * larger slab size. |
| 3475 | * i.e. RXBUFFER_2048 --> size-4096 slab |
| 3476 | */ |
| 3477 | |
| 3478 | if (max_frame <= IGB_RXBUFFER_256) |
| 3479 | adapter->rx_buffer_len = IGB_RXBUFFER_256; |
| 3480 | else if (max_frame <= IGB_RXBUFFER_512) |
| 3481 | adapter->rx_buffer_len = IGB_RXBUFFER_512; |
| 3482 | else if (max_frame <= IGB_RXBUFFER_1024) |
| 3483 | adapter->rx_buffer_len = IGB_RXBUFFER_1024; |
| 3484 | else if (max_frame <= IGB_RXBUFFER_2048) |
| 3485 | adapter->rx_buffer_len = IGB_RXBUFFER_2048; |
| 3486 | else |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 3487 | #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384 |
| 3488 | adapter->rx_buffer_len = IGB_RXBUFFER_16384; |
| 3489 | #else |
| 3490 | adapter->rx_buffer_len = PAGE_SIZE / 2; |
| 3491 | #endif |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 3492 | |
| 3493 | /* if sr-iov is enabled we need to force buffer size to 1K or larger */ |
| 3494 | if (adapter->vfs_allocated_count && |
| 3495 | (adapter->rx_buffer_len < IGB_RXBUFFER_1024)) |
| 3496 | adapter->rx_buffer_len = IGB_RXBUFFER_1024; |
| 3497 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3498 | /* adjust allocation if LPE protects us, and we aren't using SBP */ |
| 3499 | if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) || |
| 3500 | (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)) |
| 3501 | adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
| 3502 | |
| 3503 | dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n", |
| 3504 | netdev->mtu, new_mtu); |
| 3505 | netdev->mtu = new_mtu; |
| 3506 | |
| 3507 | if (netif_running(netdev)) |
| 3508 | igb_up(adapter); |
| 3509 | else |
| 3510 | igb_reset(adapter); |
| 3511 | |
| 3512 | clear_bit(__IGB_RESETTING, &adapter->state); |
| 3513 | |
| 3514 | return 0; |
| 3515 | } |
| 3516 | |
| 3517 | /** |
| 3518 | * igb_update_stats - Update the board statistics counters |
| 3519 | * @adapter: board private structure |
| 3520 | **/ |
| 3521 | |
| 3522 | void igb_update_stats(struct igb_adapter *adapter) |
| 3523 | { |
| 3524 | struct e1000_hw *hw = &adapter->hw; |
| 3525 | struct pci_dev *pdev = adapter->pdev; |
| 3526 | u16 phy_tmp; |
| 3527 | |
| 3528 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 3529 | |
| 3530 | /* |
| 3531 | * Prevent stats update while adapter is being reset, or if the pci |
| 3532 | * connection is down. |
| 3533 | */ |
| 3534 | if (adapter->link_speed == 0) |
| 3535 | return; |
| 3536 | if (pci_channel_offline(pdev)) |
| 3537 | return; |
| 3538 | |
| 3539 | adapter->stats.crcerrs += rd32(E1000_CRCERRS); |
| 3540 | adapter->stats.gprc += rd32(E1000_GPRC); |
| 3541 | adapter->stats.gorc += rd32(E1000_GORCL); |
| 3542 | rd32(E1000_GORCH); /* clear GORCL */ |
| 3543 | adapter->stats.bprc += rd32(E1000_BPRC); |
| 3544 | adapter->stats.mprc += rd32(E1000_MPRC); |
| 3545 | adapter->stats.roc += rd32(E1000_ROC); |
| 3546 | |
| 3547 | adapter->stats.prc64 += rd32(E1000_PRC64); |
| 3548 | adapter->stats.prc127 += rd32(E1000_PRC127); |
| 3549 | adapter->stats.prc255 += rd32(E1000_PRC255); |
| 3550 | adapter->stats.prc511 += rd32(E1000_PRC511); |
| 3551 | adapter->stats.prc1023 += rd32(E1000_PRC1023); |
| 3552 | adapter->stats.prc1522 += rd32(E1000_PRC1522); |
| 3553 | adapter->stats.symerrs += rd32(E1000_SYMERRS); |
| 3554 | adapter->stats.sec += rd32(E1000_SEC); |
| 3555 | |
| 3556 | adapter->stats.mpc += rd32(E1000_MPC); |
| 3557 | adapter->stats.scc += rd32(E1000_SCC); |
| 3558 | adapter->stats.ecol += rd32(E1000_ECOL); |
| 3559 | adapter->stats.mcc += rd32(E1000_MCC); |
| 3560 | adapter->stats.latecol += rd32(E1000_LATECOL); |
| 3561 | adapter->stats.dc += rd32(E1000_DC); |
| 3562 | adapter->stats.rlec += rd32(E1000_RLEC); |
| 3563 | adapter->stats.xonrxc += rd32(E1000_XONRXC); |
| 3564 | adapter->stats.xontxc += rd32(E1000_XONTXC); |
| 3565 | adapter->stats.xoffrxc += rd32(E1000_XOFFRXC); |
| 3566 | adapter->stats.xofftxc += rd32(E1000_XOFFTXC); |
| 3567 | adapter->stats.fcruc += rd32(E1000_FCRUC); |
| 3568 | adapter->stats.gptc += rd32(E1000_GPTC); |
| 3569 | adapter->stats.gotc += rd32(E1000_GOTCL); |
| 3570 | rd32(E1000_GOTCH); /* clear GOTCL */ |
| 3571 | adapter->stats.rnbc += rd32(E1000_RNBC); |
| 3572 | adapter->stats.ruc += rd32(E1000_RUC); |
| 3573 | adapter->stats.rfc += rd32(E1000_RFC); |
| 3574 | adapter->stats.rjc += rd32(E1000_RJC); |
| 3575 | adapter->stats.tor += rd32(E1000_TORH); |
| 3576 | adapter->stats.tot += rd32(E1000_TOTH); |
| 3577 | adapter->stats.tpr += rd32(E1000_TPR); |
| 3578 | |
| 3579 | adapter->stats.ptc64 += rd32(E1000_PTC64); |
| 3580 | adapter->stats.ptc127 += rd32(E1000_PTC127); |
| 3581 | adapter->stats.ptc255 += rd32(E1000_PTC255); |
| 3582 | adapter->stats.ptc511 += rd32(E1000_PTC511); |
| 3583 | adapter->stats.ptc1023 += rd32(E1000_PTC1023); |
| 3584 | adapter->stats.ptc1522 += rd32(E1000_PTC1522); |
| 3585 | |
| 3586 | adapter->stats.mptc += rd32(E1000_MPTC); |
| 3587 | adapter->stats.bptc += rd32(E1000_BPTC); |
| 3588 | |
| 3589 | /* used for adaptive IFS */ |
| 3590 | |
| 3591 | hw->mac.tx_packet_delta = rd32(E1000_TPT); |
| 3592 | adapter->stats.tpt += hw->mac.tx_packet_delta; |
| 3593 | hw->mac.collision_delta = rd32(E1000_COLC); |
| 3594 | adapter->stats.colc += hw->mac.collision_delta; |
| 3595 | |
| 3596 | adapter->stats.algnerrc += rd32(E1000_ALGNERRC); |
| 3597 | adapter->stats.rxerrc += rd32(E1000_RXERRC); |
| 3598 | adapter->stats.tncrs += rd32(E1000_TNCRS); |
| 3599 | adapter->stats.tsctc += rd32(E1000_TSCTC); |
| 3600 | adapter->stats.tsctfc += rd32(E1000_TSCTFC); |
| 3601 | |
| 3602 | adapter->stats.iac += rd32(E1000_IAC); |
| 3603 | adapter->stats.icrxoc += rd32(E1000_ICRXOC); |
| 3604 | adapter->stats.icrxptc += rd32(E1000_ICRXPTC); |
| 3605 | adapter->stats.icrxatc += rd32(E1000_ICRXATC); |
| 3606 | adapter->stats.ictxptc += rd32(E1000_ICTXPTC); |
| 3607 | adapter->stats.ictxatc += rd32(E1000_ICTXATC); |
| 3608 | adapter->stats.ictxqec += rd32(E1000_ICTXQEC); |
| 3609 | adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC); |
| 3610 | adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC); |
| 3611 | |
| 3612 | /* Fill out the OS statistics structure */ |
| 3613 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3614 | adapter->net_stats.collisions = adapter->stats.colc; |
| 3615 | |
| 3616 | /* Rx Errors */ |
| 3617 | |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 3618 | if (hw->mac.type != e1000_82575) { |
| 3619 | u32 rqdpc_tmp; |
Jesper Dangaard Brouer | 3ea73af | 2009-05-26 13:50:48 +0000 | [diff] [blame] | 3620 | u64 rqdpc_total = 0; |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 3621 | int i; |
| 3622 | /* Read out drops stats per RX queue. Notice RQDPC (Receive |
| 3623 | * Queue Drop Packet Count) stats only gets incremented, if |
| 3624 | * the DROP_EN but it set (in the SRRCTL register for that |
| 3625 | * queue). If DROP_EN bit is NOT set, then the some what |
| 3626 | * equivalent count is stored in RNBC (not per queue basis). |
| 3627 | * Also note the drop count is due to lack of available |
| 3628 | * descriptors. |
| 3629 | */ |
| 3630 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3631 | rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0xFFF; |
| 3632 | adapter->rx_ring[i].rx_stats.drops += rqdpc_tmp; |
Jesper Dangaard Brouer | 3ea73af | 2009-05-26 13:50:48 +0000 | [diff] [blame] | 3633 | rqdpc_total += adapter->rx_ring[i].rx_stats.drops; |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 3634 | } |
Jesper Dangaard Brouer | 3ea73af | 2009-05-26 13:50:48 +0000 | [diff] [blame] | 3635 | adapter->net_stats.rx_fifo_errors = rqdpc_total; |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Jesper Dangaard Brouer | 3ea73af | 2009-05-26 13:50:48 +0000 | [diff] [blame] | 3638 | /* Note RNBC (Receive No Buffers Count) is an not an exact |
| 3639 | * drop count as the hardware FIFO might save the day. Thats |
| 3640 | * one of the reason for saving it in rx_fifo_errors, as its |
| 3641 | * potentially not a true drop. |
| 3642 | */ |
| 3643 | adapter->net_stats.rx_fifo_errors += adapter->stats.rnbc; |
| 3644 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3645 | /* RLEC on some newer hardware can be incorrect so build |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 3646 | * our own version based on RUC and ROC */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3647 | adapter->net_stats.rx_errors = adapter->stats.rxerrc + |
| 3648 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 3649 | adapter->stats.ruc + adapter->stats.roc + |
| 3650 | adapter->stats.cexterr; |
| 3651 | adapter->net_stats.rx_length_errors = adapter->stats.ruc + |
| 3652 | adapter->stats.roc; |
| 3653 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
| 3654 | adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc; |
| 3655 | adapter->net_stats.rx_missed_errors = adapter->stats.mpc; |
| 3656 | |
| 3657 | /* Tx Errors */ |
| 3658 | adapter->net_stats.tx_errors = adapter->stats.ecol + |
| 3659 | adapter->stats.latecol; |
| 3660 | adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; |
| 3661 | adapter->net_stats.tx_window_errors = adapter->stats.latecol; |
| 3662 | adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; |
| 3663 | |
| 3664 | /* Tx Dropped needs to be maintained elsewhere */ |
| 3665 | |
| 3666 | /* Phy Stats */ |
| 3667 | if (hw->phy.media_type == e1000_media_type_copper) { |
| 3668 | if ((adapter->link_speed == SPEED_1000) && |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3669 | (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3670 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 3671 | adapter->phy_stats.idle_errors += phy_tmp; |
| 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | /* Management Stats */ |
| 3676 | adapter->stats.mgptc += rd32(E1000_MGTPTC); |
| 3677 | adapter->stats.mgprc += rd32(E1000_MGTPRC); |
| 3678 | adapter->stats.mgpdc += rd32(E1000_MGTPDC); |
| 3679 | } |
| 3680 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3681 | static irqreturn_t igb_msix_other(int irq, void *data) |
| 3682 | { |
| 3683 | struct net_device *netdev = data; |
| 3684 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3685 | struct e1000_hw *hw = &adapter->hw; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 3686 | u32 icr = rd32(E1000_ICR); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3687 | |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 3688 | /* reading ICR causes bit 31 of EICR to be cleared */ |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 3689 | |
| 3690 | if(icr & E1000_ICR_DOUTSYNC) { |
| 3691 | /* HW is reporting DMA is out of sync */ |
| 3692 | adapter->stats.doosync++; |
| 3693 | } |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 3694 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3695 | /* Check for a mailbox event */ |
| 3696 | if (icr & E1000_ICR_VMMB) |
| 3697 | igb_msg_task(adapter); |
| 3698 | |
| 3699 | if (icr & E1000_ICR_LSC) { |
| 3700 | hw->mac.get_link_status = 1; |
| 3701 | /* guard against interrupt when we're going down */ |
| 3702 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3703 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 3704 | } |
| 3705 | |
| 3706 | wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_VMMB); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 3707 | wr32(E1000_EIMS, adapter->eims_other); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3708 | |
| 3709 | return IRQ_HANDLED; |
| 3710 | } |
| 3711 | |
| 3712 | static irqreturn_t igb_msix_tx(int irq, void *data) |
| 3713 | { |
| 3714 | struct igb_ring *tx_ring = data; |
| 3715 | struct igb_adapter *adapter = tx_ring->adapter; |
| 3716 | struct e1000_hw *hw = &adapter->hw; |
| 3717 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 3718 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3719 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3720 | igb_update_tx_dca(tx_ring); |
| 3721 | #endif |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3722 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3723 | tx_ring->total_bytes = 0; |
| 3724 | tx_ring->total_packets = 0; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3725 | |
| 3726 | /* auto mask will automatically reenable the interrupt when we write |
| 3727 | * EICS */ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3728 | if (!igb_clean_tx_irq(tx_ring)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3729 | /* Ring was not completely cleaned, so fire another interrupt */ |
| 3730 | wr32(E1000_EICS, tx_ring->eims_value); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3731 | else |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3732 | wr32(E1000_EIMS, tx_ring->eims_value); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 3733 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3734 | return IRQ_HANDLED; |
| 3735 | } |
| 3736 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3737 | static void igb_write_itr(struct igb_ring *ring) |
| 3738 | { |
| 3739 | struct e1000_hw *hw = &ring->adapter->hw; |
| 3740 | if ((ring->adapter->itr_setting & 3) && ring->set_itr) { |
| 3741 | switch (hw->mac.type) { |
| 3742 | case e1000_82576: |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3743 | wr32(ring->itr_register, ring->itr_val | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3744 | 0x80000000); |
| 3745 | break; |
| 3746 | default: |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 3747 | wr32(ring->itr_register, ring->itr_val | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3748 | (ring->itr_val << 16)); |
| 3749 | break; |
| 3750 | } |
| 3751 | ring->set_itr = 0; |
| 3752 | } |
| 3753 | } |
| 3754 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3755 | static irqreturn_t igb_msix_rx(int irq, void *data) |
| 3756 | { |
| 3757 | struct igb_ring *rx_ring = data; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3758 | |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 3759 | /* Write the ITR value calculated at the end of the |
| 3760 | * previous interrupt. |
| 3761 | */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3762 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3763 | igb_write_itr(rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3764 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3765 | if (napi_schedule_prep(&rx_ring->napi)) |
| 3766 | __napi_schedule(&rx_ring->napi); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 3767 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 3768 | #ifdef CONFIG_IGB_DCA |
David S. Miller | 8d25332 | 2008-12-26 15:13:55 -0800 | [diff] [blame] | 3769 | if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3770 | igb_update_rx_dca(rx_ring); |
| 3771 | #endif |
| 3772 | return IRQ_HANDLED; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3773 | } |
| 3774 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 3775 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3776 | static void igb_update_rx_dca(struct igb_ring *rx_ring) |
| 3777 | { |
| 3778 | u32 dca_rxctrl; |
| 3779 | struct igb_adapter *adapter = rx_ring->adapter; |
| 3780 | struct e1000_hw *hw = &adapter->hw; |
| 3781 | int cpu = get_cpu(); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 3782 | int q = rx_ring->reg_idx; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3783 | |
| 3784 | if (rx_ring->cpu != cpu) { |
| 3785 | dca_rxctrl = rd32(E1000_DCA_RXCTRL(q)); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 3786 | if (hw->mac.type == e1000_82576) { |
| 3787 | dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576; |
Maciej Sosnowski | 92be791 | 2009-03-13 20:40:21 +0000 | [diff] [blame] | 3788 | dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) << |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 3789 | E1000_DCA_RXCTRL_CPUID_SHIFT; |
| 3790 | } else { |
| 3791 | dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK; |
Maciej Sosnowski | 92be791 | 2009-03-13 20:40:21 +0000 | [diff] [blame] | 3792 | dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 3793 | } |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3794 | dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN; |
| 3795 | dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN; |
| 3796 | dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN; |
| 3797 | wr32(E1000_DCA_RXCTRL(q), dca_rxctrl); |
| 3798 | rx_ring->cpu = cpu; |
| 3799 | } |
| 3800 | put_cpu(); |
| 3801 | } |
| 3802 | |
| 3803 | static void igb_update_tx_dca(struct igb_ring *tx_ring) |
| 3804 | { |
| 3805 | u32 dca_txctrl; |
| 3806 | struct igb_adapter *adapter = tx_ring->adapter; |
| 3807 | struct e1000_hw *hw = &adapter->hw; |
| 3808 | int cpu = get_cpu(); |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 3809 | int q = tx_ring->reg_idx; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3810 | |
| 3811 | if (tx_ring->cpu != cpu) { |
| 3812 | dca_txctrl = rd32(E1000_DCA_TXCTRL(q)); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 3813 | if (hw->mac.type == e1000_82576) { |
| 3814 | dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576; |
Maciej Sosnowski | 92be791 | 2009-03-13 20:40:21 +0000 | [diff] [blame] | 3815 | dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) << |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 3816 | E1000_DCA_TXCTRL_CPUID_SHIFT; |
| 3817 | } else { |
| 3818 | dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK; |
Maciej Sosnowski | 92be791 | 2009-03-13 20:40:21 +0000 | [diff] [blame] | 3819 | dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 3820 | } |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3821 | dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN; |
| 3822 | wr32(E1000_DCA_TXCTRL(q), dca_txctrl); |
| 3823 | tx_ring->cpu = cpu; |
| 3824 | } |
| 3825 | put_cpu(); |
| 3826 | } |
| 3827 | |
| 3828 | static void igb_setup_dca(struct igb_adapter *adapter) |
| 3829 | { |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 3830 | struct e1000_hw *hw = &adapter->hw; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3831 | int i; |
| 3832 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3833 | if (!(adapter->flags & IGB_FLAG_DCA_ENABLED)) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3834 | return; |
| 3835 | |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 3836 | /* Always use CB2 mode, difference is masked in the CB driver. */ |
| 3837 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2); |
| 3838 | |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3839 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3840 | adapter->tx_ring[i].cpu = -1; |
| 3841 | igb_update_tx_dca(&adapter->tx_ring[i]); |
| 3842 | } |
| 3843 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3844 | adapter->rx_ring[i].cpu = -1; |
| 3845 | igb_update_rx_dca(&adapter->rx_ring[i]); |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | static int __igb_notify_dca(struct device *dev, void *data) |
| 3850 | { |
| 3851 | struct net_device *netdev = dev_get_drvdata(dev); |
| 3852 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3853 | struct e1000_hw *hw = &adapter->hw; |
| 3854 | unsigned long event = *(unsigned long *)data; |
| 3855 | |
| 3856 | switch (event) { |
| 3857 | case DCA_PROVIDER_ADD: |
| 3858 | /* if already enabled, don't do it again */ |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3859 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3860 | break; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3861 | /* Always use CB2 mode, difference is masked |
| 3862 | * in the CB driver. */ |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 3863 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3864 | if (dca_add_requester(dev) == 0) { |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 3865 | adapter->flags |= IGB_FLAG_DCA_ENABLED; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3866 | dev_info(&adapter->pdev->dev, "DCA enabled\n"); |
| 3867 | igb_setup_dca(adapter); |
| 3868 | break; |
| 3869 | } |
| 3870 | /* Fall Through since DCA is disabled. */ |
| 3871 | case DCA_PROVIDER_REMOVE: |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3872 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) { |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3873 | /* without this a class_device is left |
| 3874 | * hanging around in the sysfs model */ |
| 3875 | dca_remove_requester(dev); |
| 3876 | dev_info(&adapter->pdev->dev, "DCA disabled\n"); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 3877 | adapter->flags &= ~IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 3878 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3879 | } |
| 3880 | break; |
| 3881 | } |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 3882 | |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 3883 | return 0; |
| 3884 | } |
| 3885 | |
| 3886 | static int igb_notify_dca(struct notifier_block *nb, unsigned long event, |
| 3887 | void *p) |
| 3888 | { |
| 3889 | int ret_val; |
| 3890 | |
| 3891 | ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event, |
| 3892 | __igb_notify_dca); |
| 3893 | |
| 3894 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 3895 | } |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 3896 | #endif /* CONFIG_IGB_DCA */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3897 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3898 | static void igb_ping_all_vfs(struct igb_adapter *adapter) |
| 3899 | { |
| 3900 | struct e1000_hw *hw = &adapter->hw; |
| 3901 | u32 ping; |
| 3902 | int i; |
| 3903 | |
| 3904 | for (i = 0 ; i < adapter->vfs_allocated_count; i++) { |
| 3905 | ping = E1000_PF_CONTROL_MSG; |
| 3906 | if (adapter->vf_data[i].clear_to_send) |
| 3907 | ping |= E1000_VT_MSGTYPE_CTS; |
| 3908 | igb_write_mbx(hw, &ping, 1, i); |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | static int igb_set_vf_multicasts(struct igb_adapter *adapter, |
| 3913 | u32 *msgbuf, u32 vf) |
| 3914 | { |
| 3915 | int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT; |
| 3916 | u16 *hash_list = (u16 *)&msgbuf[1]; |
| 3917 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
| 3918 | int i; |
| 3919 | |
| 3920 | /* only up to 30 hash values supported */ |
| 3921 | if (n > 30) |
| 3922 | n = 30; |
| 3923 | |
| 3924 | /* salt away the number of multi cast addresses assigned |
| 3925 | * to this VF for later use to restore when the PF multi cast |
| 3926 | * list changes |
| 3927 | */ |
| 3928 | vf_data->num_vf_mc_hashes = n; |
| 3929 | |
| 3930 | /* VFs are limited to using the MTA hash table for their multicast |
| 3931 | * addresses */ |
| 3932 | for (i = 0; i < n; i++) |
| 3933 | vf_data->vf_mc_hashes[i] = hash_list[i];; |
| 3934 | |
| 3935 | /* Flush and reset the mta with the new values */ |
| 3936 | igb_set_multi(adapter->netdev); |
| 3937 | |
| 3938 | return 0; |
| 3939 | } |
| 3940 | |
| 3941 | static void igb_restore_vf_multicasts(struct igb_adapter *adapter) |
| 3942 | { |
| 3943 | struct e1000_hw *hw = &adapter->hw; |
| 3944 | struct vf_data_storage *vf_data; |
| 3945 | int i, j; |
| 3946 | |
| 3947 | for (i = 0; i < adapter->vfs_allocated_count; i++) { |
| 3948 | vf_data = &adapter->vf_data[i]; |
Alexander Duyck | 75f4f38 | 2009-03-13 20:41:55 +0000 | [diff] [blame] | 3949 | for (j = 0; j < vf_data->num_vf_mc_hashes; j++) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3950 | igb_mta_set(hw, vf_data->vf_mc_hashes[j]); |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf) |
| 3955 | { |
| 3956 | struct e1000_hw *hw = &adapter->hw; |
| 3957 | u32 pool_mask, reg, vid; |
| 3958 | int i; |
| 3959 | |
| 3960 | pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf); |
| 3961 | |
| 3962 | /* Find the vlan filter for this id */ |
| 3963 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 3964 | reg = rd32(E1000_VLVF(i)); |
| 3965 | |
| 3966 | /* remove the vf from the pool */ |
| 3967 | reg &= ~pool_mask; |
| 3968 | |
| 3969 | /* if pool is empty then remove entry from vfta */ |
| 3970 | if (!(reg & E1000_VLVF_POOLSEL_MASK) && |
| 3971 | (reg & E1000_VLVF_VLANID_ENABLE)) { |
| 3972 | reg = 0; |
| 3973 | vid = reg & E1000_VLVF_VLANID_MASK; |
| 3974 | igb_vfta_set(hw, vid, false); |
| 3975 | } |
| 3976 | |
| 3977 | wr32(E1000_VLVF(i), reg); |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf) |
| 3982 | { |
| 3983 | struct e1000_hw *hw = &adapter->hw; |
| 3984 | u32 reg, i; |
| 3985 | |
| 3986 | /* It is an error to call this function when VFs are not enabled */ |
| 3987 | if (!adapter->vfs_allocated_count) |
| 3988 | return -1; |
| 3989 | |
| 3990 | /* Find the vlan filter for this id */ |
| 3991 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 3992 | reg = rd32(E1000_VLVF(i)); |
| 3993 | if ((reg & E1000_VLVF_VLANID_ENABLE) && |
| 3994 | vid == (reg & E1000_VLVF_VLANID_MASK)) |
| 3995 | break; |
| 3996 | } |
| 3997 | |
| 3998 | if (add) { |
| 3999 | if (i == E1000_VLVF_ARRAY_SIZE) { |
| 4000 | /* Did not find a matching VLAN ID entry that was |
| 4001 | * enabled. Search for a free filter entry, i.e. |
| 4002 | * one without the enable bit set |
| 4003 | */ |
| 4004 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 4005 | reg = rd32(E1000_VLVF(i)); |
| 4006 | if (!(reg & E1000_VLVF_VLANID_ENABLE)) |
| 4007 | break; |
| 4008 | } |
| 4009 | } |
| 4010 | if (i < E1000_VLVF_ARRAY_SIZE) { |
| 4011 | /* Found an enabled/available entry */ |
| 4012 | reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf); |
| 4013 | |
| 4014 | /* if !enabled we need to set this up in vfta */ |
| 4015 | if (!(reg & E1000_VLVF_VLANID_ENABLE)) { |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 4016 | /* add VID to filter table, if bit already set |
| 4017 | * PF must have added it outside of table */ |
| 4018 | if (igb_vfta_set(hw, vid, true)) |
| 4019 | reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + |
| 4020 | adapter->vfs_allocated_count); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4021 | reg |= E1000_VLVF_VLANID_ENABLE; |
| 4022 | } |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 4023 | reg &= ~E1000_VLVF_VLANID_MASK; |
| 4024 | reg |= vid; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4025 | |
| 4026 | wr32(E1000_VLVF(i), reg); |
| 4027 | return 0; |
| 4028 | } |
| 4029 | } else { |
| 4030 | if (i < E1000_VLVF_ARRAY_SIZE) { |
| 4031 | /* remove vf from the pool */ |
| 4032 | reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf)); |
| 4033 | /* if pool is empty then remove entry from vfta */ |
| 4034 | if (!(reg & E1000_VLVF_POOLSEL_MASK)) { |
| 4035 | reg = 0; |
| 4036 | igb_vfta_set(hw, vid, false); |
| 4037 | } |
| 4038 | wr32(E1000_VLVF(i), reg); |
| 4039 | return 0; |
| 4040 | } |
| 4041 | } |
| 4042 | return -1; |
| 4043 | } |
| 4044 | |
| 4045 | static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf) |
| 4046 | { |
| 4047 | int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT; |
| 4048 | int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK); |
| 4049 | |
| 4050 | return igb_vlvf_set(adapter, vid, add, vf); |
| 4051 | } |
| 4052 | |
| 4053 | static inline void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf) |
| 4054 | { |
| 4055 | struct e1000_hw *hw = &adapter->hw; |
| 4056 | |
| 4057 | /* disable mailbox functionality for vf */ |
| 4058 | adapter->vf_data[vf].clear_to_send = false; |
| 4059 | |
| 4060 | /* reset offloads to defaults */ |
| 4061 | igb_set_vmolr(hw, vf); |
| 4062 | |
| 4063 | /* reset vlans for device */ |
| 4064 | igb_clear_vf_vfta(adapter, vf); |
| 4065 | |
| 4066 | /* reset multicast table array for vf */ |
| 4067 | adapter->vf_data[vf].num_vf_mc_hashes = 0; |
| 4068 | |
| 4069 | /* Flush and reset the mta with the new values */ |
| 4070 | igb_set_multi(adapter->netdev); |
| 4071 | } |
| 4072 | |
| 4073 | static inline void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf) |
| 4074 | { |
| 4075 | struct e1000_hw *hw = &adapter->hw; |
| 4076 | unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses; |
| 4077 | u32 reg, msgbuf[3]; |
| 4078 | u8 *addr = (u8 *)(&msgbuf[1]); |
| 4079 | |
| 4080 | /* process all the same items cleared in a function level reset */ |
| 4081 | igb_vf_reset_event(adapter, vf); |
| 4082 | |
| 4083 | /* set vf mac address */ |
| 4084 | igb_rar_set(hw, vf_mac, vf + 1); |
| 4085 | igb_set_rah_pool(hw, vf, vf + 1); |
| 4086 | |
| 4087 | /* enable transmit and receive for vf */ |
| 4088 | reg = rd32(E1000_VFTE); |
| 4089 | wr32(E1000_VFTE, reg | (1 << vf)); |
| 4090 | reg = rd32(E1000_VFRE); |
| 4091 | wr32(E1000_VFRE, reg | (1 << vf)); |
| 4092 | |
| 4093 | /* enable mailbox functionality for vf */ |
| 4094 | adapter->vf_data[vf].clear_to_send = true; |
| 4095 | |
| 4096 | /* reply to reset with ack and vf mac address */ |
| 4097 | msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK; |
| 4098 | memcpy(addr, vf_mac, 6); |
| 4099 | igb_write_mbx(hw, msgbuf, 3, vf); |
| 4100 | } |
| 4101 | |
| 4102 | static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf) |
| 4103 | { |
| 4104 | unsigned char *addr = (char *)&msg[1]; |
| 4105 | int err = -1; |
| 4106 | |
| 4107 | if (is_valid_ether_addr(addr)) |
| 4108 | err = igb_set_vf_mac(adapter, vf, addr); |
| 4109 | |
| 4110 | return err; |
| 4111 | |
| 4112 | } |
| 4113 | |
| 4114 | static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf) |
| 4115 | { |
| 4116 | struct e1000_hw *hw = &adapter->hw; |
| 4117 | u32 msg = E1000_VT_MSGTYPE_NACK; |
| 4118 | |
| 4119 | /* if device isn't clear to send it shouldn't be reading either */ |
| 4120 | if (!adapter->vf_data[vf].clear_to_send) |
| 4121 | igb_write_mbx(hw, &msg, 1, vf); |
| 4122 | } |
| 4123 | |
| 4124 | |
| 4125 | static void igb_msg_task(struct igb_adapter *adapter) |
| 4126 | { |
| 4127 | struct e1000_hw *hw = &adapter->hw; |
| 4128 | u32 vf; |
| 4129 | |
| 4130 | for (vf = 0; vf < adapter->vfs_allocated_count; vf++) { |
| 4131 | /* process any reset requests */ |
| 4132 | if (!igb_check_for_rst(hw, vf)) { |
| 4133 | adapter->vf_data[vf].clear_to_send = false; |
| 4134 | igb_vf_reset_event(adapter, vf); |
| 4135 | } |
| 4136 | |
| 4137 | /* process any messages pending */ |
| 4138 | if (!igb_check_for_msg(hw, vf)) |
| 4139 | igb_rcv_msg_from_vf(adapter, vf); |
| 4140 | |
| 4141 | /* process any acks */ |
| 4142 | if (!igb_check_for_ack(hw, vf)) |
| 4143 | igb_rcv_ack_from_vf(adapter, vf); |
| 4144 | |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | static int igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf) |
| 4149 | { |
| 4150 | u32 mbx_size = E1000_VFMAILBOX_SIZE; |
| 4151 | u32 msgbuf[mbx_size]; |
| 4152 | struct e1000_hw *hw = &adapter->hw; |
| 4153 | s32 retval; |
| 4154 | |
| 4155 | retval = igb_read_mbx(hw, msgbuf, mbx_size, vf); |
| 4156 | |
| 4157 | if (retval) |
| 4158 | dev_err(&adapter->pdev->dev, |
| 4159 | "Error receiving message from VF\n"); |
| 4160 | |
| 4161 | /* this is a message we already processed, do nothing */ |
| 4162 | if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK)) |
| 4163 | return retval; |
| 4164 | |
| 4165 | /* |
| 4166 | * until the vf completes a reset it should not be |
| 4167 | * allowed to start any configuration. |
| 4168 | */ |
| 4169 | |
| 4170 | if (msgbuf[0] == E1000_VF_RESET) { |
| 4171 | igb_vf_reset_msg(adapter, vf); |
| 4172 | |
| 4173 | return retval; |
| 4174 | } |
| 4175 | |
| 4176 | if (!adapter->vf_data[vf].clear_to_send) { |
| 4177 | msgbuf[0] |= E1000_VT_MSGTYPE_NACK; |
| 4178 | igb_write_mbx(hw, msgbuf, 1, vf); |
| 4179 | return retval; |
| 4180 | } |
| 4181 | |
| 4182 | switch ((msgbuf[0] & 0xFFFF)) { |
| 4183 | case E1000_VF_SET_MAC_ADDR: |
| 4184 | retval = igb_set_vf_mac_addr(adapter, msgbuf, vf); |
| 4185 | break; |
| 4186 | case E1000_VF_SET_MULTICAST: |
| 4187 | retval = igb_set_vf_multicasts(adapter, msgbuf, vf); |
| 4188 | break; |
| 4189 | case E1000_VF_SET_LPE: |
| 4190 | retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf); |
| 4191 | break; |
| 4192 | case E1000_VF_SET_VLAN: |
| 4193 | retval = igb_set_vf_vlan(adapter, msgbuf, vf); |
| 4194 | break; |
| 4195 | default: |
| 4196 | dev_err(&adapter->pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]); |
| 4197 | retval = -1; |
| 4198 | break; |
| 4199 | } |
| 4200 | |
| 4201 | /* notify the VF of the results of what it sent us */ |
| 4202 | if (retval) |
| 4203 | msgbuf[0] |= E1000_VT_MSGTYPE_NACK; |
| 4204 | else |
| 4205 | msgbuf[0] |= E1000_VT_MSGTYPE_ACK; |
| 4206 | |
| 4207 | msgbuf[0] |= E1000_VT_MSGTYPE_CTS; |
| 4208 | |
| 4209 | igb_write_mbx(hw, msgbuf, 1, vf); |
| 4210 | |
| 4211 | return retval; |
| 4212 | } |
| 4213 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4214 | /** |
| 4215 | * igb_intr_msi - Interrupt Handler |
| 4216 | * @irq: interrupt number |
| 4217 | * @data: pointer to a network interface device structure |
| 4218 | **/ |
| 4219 | static irqreturn_t igb_intr_msi(int irq, void *data) |
| 4220 | { |
| 4221 | struct net_device *netdev = data; |
| 4222 | struct igb_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4223 | struct e1000_hw *hw = &adapter->hw; |
| 4224 | /* read ICR disables interrupts using IAM */ |
| 4225 | u32 icr = rd32(E1000_ICR); |
| 4226 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 4227 | igb_write_itr(adapter->rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4228 | |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4229 | if(icr & E1000_ICR_DOUTSYNC) { |
| 4230 | /* HW is reporting DMA is out of sync */ |
| 4231 | adapter->stats.doosync++; |
| 4232 | } |
| 4233 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4234 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 4235 | hw->mac.get_link_status = 1; |
| 4236 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 4237 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 4238 | } |
| 4239 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 4240 | napi_schedule(&adapter->rx_ring[0].napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4241 | |
| 4242 | return IRQ_HANDLED; |
| 4243 | } |
| 4244 | |
| 4245 | /** |
Alexander Duyck | 4a3c643 | 2009-02-06 23:20:49 +0000 | [diff] [blame] | 4246 | * igb_intr - Legacy Interrupt Handler |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4247 | * @irq: interrupt number |
| 4248 | * @data: pointer to a network interface device structure |
| 4249 | **/ |
| 4250 | static irqreturn_t igb_intr(int irq, void *data) |
| 4251 | { |
| 4252 | struct net_device *netdev = data; |
| 4253 | struct igb_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4254 | struct e1000_hw *hw = &adapter->hw; |
| 4255 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
| 4256 | * need for the IMC write */ |
| 4257 | u32 icr = rd32(E1000_ICR); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4258 | if (!icr) |
| 4259 | return IRQ_NONE; /* Not our interrupt */ |
| 4260 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 4261 | igb_write_itr(adapter->rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4262 | |
| 4263 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 4264 | * not set, then the adapter didn't send an interrupt */ |
| 4265 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 4266 | return IRQ_NONE; |
| 4267 | |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4268 | if(icr & E1000_ICR_DOUTSYNC) { |
| 4269 | /* HW is reporting DMA is out of sync */ |
| 4270 | adapter->stats.doosync++; |
| 4271 | } |
| 4272 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4273 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 4274 | hw->mac.get_link_status = 1; |
| 4275 | /* guard against interrupt when we're going down */ |
| 4276 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 4277 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 4278 | } |
| 4279 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 4280 | napi_schedule(&adapter->rx_ring[0].napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4281 | |
| 4282 | return IRQ_HANDLED; |
| 4283 | } |
| 4284 | |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 4285 | static inline void igb_rx_irq_enable(struct igb_ring *rx_ring) |
| 4286 | { |
| 4287 | struct igb_adapter *adapter = rx_ring->adapter; |
| 4288 | struct e1000_hw *hw = &adapter->hw; |
| 4289 | |
| 4290 | if (adapter->itr_setting & 3) { |
| 4291 | if (adapter->num_rx_queues == 1) |
| 4292 | igb_set_itr(adapter); |
| 4293 | else |
| 4294 | igb_update_ring_itr(rx_ring); |
| 4295 | } |
| 4296 | |
| 4297 | if (!test_bit(__IGB_DOWN, &adapter->state)) { |
| 4298 | if (adapter->msix_entries) |
| 4299 | wr32(E1000_EIMS, rx_ring->eims_value); |
| 4300 | else |
| 4301 | igb_irq_enable(adapter); |
| 4302 | } |
| 4303 | } |
| 4304 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4305 | /** |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4306 | * igb_poll - NAPI Rx polling callback |
| 4307 | * @napi: napi polling structure |
| 4308 | * @budget: count of how many packets we should handle |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4309 | **/ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4310 | static int igb_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4311 | { |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4312 | struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4313 | int work_done = 0; |
| 4314 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 4315 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | bd38e5d | 2009-03-13 20:40:58 +0000 | [diff] [blame] | 4316 | if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4317 | igb_update_rx_dca(rx_ring); |
| 4318 | #endif |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4319 | igb_clean_rx_irq_adv(rx_ring, &work_done, budget); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4320 | |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 4321 | if (rx_ring->buddy) { |
| 4322 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | bd38e5d | 2009-03-13 20:40:58 +0000 | [diff] [blame] | 4323 | if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED) |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 4324 | igb_update_tx_dca(rx_ring->buddy); |
| 4325 | #endif |
| 4326 | if (!igb_clean_tx_irq(rx_ring->buddy)) |
| 4327 | work_done = budget; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4328 | } |
| 4329 | |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 4330 | /* If not enough Rx work done, exit the polling mode */ |
Alexander Duyck | 5e6d5b1 | 2009-03-13 20:40:38 +0000 | [diff] [blame] | 4331 | if (work_done < budget) { |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 4332 | napi_complete(napi); |
| 4333 | igb_rx_irq_enable(rx_ring); |
| 4334 | } |
| 4335 | |
| 4336 | return work_done; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4337 | } |
Al Viro | 6d8126f | 2008-03-16 22:23:24 +0000 | [diff] [blame] | 4338 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4339 | /** |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4340 | * igb_hwtstamp - utility function which checks for TX time stamp |
| 4341 | * @adapter: board private structure |
| 4342 | * @skb: packet that was just sent |
| 4343 | * |
| 4344 | * If we were asked to do hardware stamping and such a time stamp is |
| 4345 | * available, then it must have been for this skb here because we only |
| 4346 | * allow only one such packet into the queue. |
| 4347 | */ |
| 4348 | static void igb_tx_hwtstamp(struct igb_adapter *adapter, struct sk_buff *skb) |
| 4349 | { |
| 4350 | union skb_shared_tx *shtx = skb_tx(skb); |
| 4351 | struct e1000_hw *hw = &adapter->hw; |
| 4352 | |
| 4353 | if (unlikely(shtx->hardware)) { |
| 4354 | u32 valid = rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID; |
| 4355 | if (valid) { |
| 4356 | u64 regval = rd32(E1000_TXSTMPL); |
| 4357 | u64 ns; |
| 4358 | struct skb_shared_hwtstamps shhwtstamps; |
| 4359 | |
| 4360 | memset(&shhwtstamps, 0, sizeof(shhwtstamps)); |
| 4361 | regval |= (u64)rd32(E1000_TXSTMPH) << 32; |
| 4362 | ns = timecounter_cyc2time(&adapter->clock, |
| 4363 | regval); |
| 4364 | timecompare_update(&adapter->compare, ns); |
| 4365 | shhwtstamps.hwtstamp = ns_to_ktime(ns); |
| 4366 | shhwtstamps.syststamp = |
| 4367 | timecompare_transform(&adapter->compare, ns); |
| 4368 | skb_tstamp_tx(skb, &shhwtstamps); |
| 4369 | } |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4370 | } |
| 4371 | } |
| 4372 | |
| 4373 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4374 | * igb_clean_tx_irq - Reclaim resources after transmit completes |
| 4375 | * @adapter: board private structure |
| 4376 | * returns true if ring is completely cleaned |
| 4377 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4378 | static bool igb_clean_tx_irq(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4379 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4380 | struct igb_adapter *adapter = tx_ring->adapter; |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4381 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4382 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4383 | struct igb_buffer *buffer_info; |
| 4384 | struct sk_buff *skb; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4385 | union e1000_adv_tx_desc *tx_desc, *eop_desc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4386 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4387 | unsigned int i, eop, count = 0; |
| 4388 | bool cleaned = false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4389 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4390 | i = tx_ring->next_to_clean; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4391 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 4392 | eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop); |
| 4393 | |
| 4394 | while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) && |
| 4395 | (count < tx_ring->count)) { |
| 4396 | for (cleaned = false; !cleaned; count++) { |
| 4397 | tx_desc = E1000_TX_DESC_ADV(*tx_ring, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4398 | buffer_info = &tx_ring->buffer_info[i]; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4399 | cleaned = (i == eop); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4400 | skb = buffer_info->skb; |
| 4401 | |
| 4402 | if (skb) { |
| 4403 | unsigned int segs, bytecount; |
| 4404 | /* gso_segs is currently only valid for tcp */ |
| 4405 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 4406 | /* multiply data chunks by size of headers */ |
| 4407 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 4408 | skb->len; |
| 4409 | total_packets += segs; |
| 4410 | total_bytes += bytecount; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4411 | |
| 4412 | igb_tx_hwtstamp(adapter, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | igb_unmap_and_free_tx_resource(adapter, buffer_info); |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4416 | tx_desc->wb.status = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4417 | |
| 4418 | i++; |
| 4419 | if (i == tx_ring->count) |
| 4420 | i = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4421 | } |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4422 | eop = tx_ring->buffer_info[i].next_to_watch; |
| 4423 | eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop); |
| 4424 | } |
| 4425 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4426 | tx_ring->next_to_clean = i; |
| 4427 | |
Alexander Duyck | fc7d345 | 2008-08-26 04:25:08 -0700 | [diff] [blame] | 4428 | if (unlikely(count && |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4429 | netif_carrier_ok(netdev) && |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 4430 | igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4431 | /* Make sure that anybody stopping the queue after this |
| 4432 | * sees the new next_to_clean. |
| 4433 | */ |
| 4434 | smp_mb(); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4435 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 4436 | !(test_bit(__IGB_DOWN, &adapter->state))) { |
| 4437 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
| 4438 | ++adapter->restart_queue; |
| 4439 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | if (tx_ring->detect_tx_hung) { |
| 4443 | /* Detect a transmit hang in hardware, this serializes the |
| 4444 | * check with the clearing of time_stamp and movement of i */ |
| 4445 | tx_ring->detect_tx_hung = false; |
| 4446 | if (tx_ring->buffer_info[i].time_stamp && |
| 4447 | time_after(jiffies, tx_ring->buffer_info[i].time_stamp + |
| 4448 | (adapter->tx_timeout_factor * HZ)) |
| 4449 | && !(rd32(E1000_STATUS) & |
| 4450 | E1000_STATUS_TXOFF)) { |
| 4451 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4452 | /* detected Tx unit hang */ |
| 4453 | dev_err(&adapter->pdev->dev, |
| 4454 | "Detected Tx Unit Hang\n" |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4455 | " Tx Queue <%d>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4456 | " TDH <%x>\n" |
| 4457 | " TDT <%x>\n" |
| 4458 | " next_to_use <%x>\n" |
| 4459 | " next_to_clean <%x>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4460 | "buffer_info[next_to_clean]\n" |
| 4461 | " time_stamp <%lx>\n" |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4462 | " next_to_watch <%x>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4463 | " jiffies <%lx>\n" |
| 4464 | " desc.status <%x>\n", |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4465 | tx_ring->queue_index, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4466 | readl(adapter->hw.hw_addr + tx_ring->head), |
| 4467 | readl(adapter->hw.hw_addr + tx_ring->tail), |
| 4468 | tx_ring->next_to_use, |
| 4469 | tx_ring->next_to_clean, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4470 | tx_ring->buffer_info[i].time_stamp, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4471 | eop, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4472 | jiffies, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4473 | eop_desc->wb.status); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4474 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | tx_ring->total_bytes += total_bytes; |
| 4478 | tx_ring->total_packets += total_packets; |
Alexander Duyck | e21ed35 | 2008-07-08 15:07:24 -0700 | [diff] [blame] | 4479 | tx_ring->tx_stats.bytes += total_bytes; |
| 4480 | tx_ring->tx_stats.packets += total_packets; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4481 | adapter->net_stats.tx_bytes += total_bytes; |
| 4482 | adapter->net_stats.tx_packets += total_packets; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4483 | return (count < tx_ring->count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4486 | /** |
| 4487 | * igb_receive_skb - helper function to handle rx indications |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 4488 | * @ring: pointer to receive ring receving this packet |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4489 | * @status: descriptor status field as written by hardware |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4490 | * @rx_desc: receive descriptor containing vlan and type information. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4491 | * @skb: pointer to sk_buff to be indicated to stack |
| 4492 | **/ |
Alexander Duyck | d335252 | 2008-07-08 15:12:13 -0700 | [diff] [blame] | 4493 | static void igb_receive_skb(struct igb_ring *ring, u8 status, |
| 4494 | union e1000_adv_rx_desc * rx_desc, |
| 4495 | struct sk_buff *skb) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4496 | { |
Alexander Duyck | d335252 | 2008-07-08 15:12:13 -0700 | [diff] [blame] | 4497 | struct igb_adapter * adapter = ring->adapter; |
| 4498 | bool vlan_extracted = (adapter->vlgrp && (status & E1000_RXD_STAT_VP)); |
| 4499 | |
David S. Miller | 0c8dfc8 | 2009-01-27 16:22:32 -0800 | [diff] [blame] | 4500 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 4501 | if (vlan_extracted) |
| 4502 | vlan_gro_receive(&ring->napi, adapter->vlgrp, |
| 4503 | le16_to_cpu(rx_desc->wb.upper.vlan), |
| 4504 | skb); |
| 4505 | else |
| 4506 | napi_gro_receive(&ring->napi, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4507 | } |
| 4508 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4509 | static inline void igb_rx_checksum_adv(struct igb_adapter *adapter, |
| 4510 | u32 status_err, struct sk_buff *skb) |
| 4511 | { |
| 4512 | skb->ip_summed = CHECKSUM_NONE; |
| 4513 | |
| 4514 | /* Ignore Checksum bit is set or checksum is disabled through ethtool */ |
Alexander Duyck | 7beb014 | 2009-05-06 10:25:23 +0000 | [diff] [blame] | 4515 | if ((status_err & E1000_RXD_STAT_IXSM) || |
| 4516 | (adapter->flags & IGB_FLAG_RX_CSUM_DISABLED)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4517 | return; |
| 4518 | /* TCP/UDP checksum error bit is set */ |
| 4519 | if (status_err & |
| 4520 | (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) { |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 4521 | /* |
| 4522 | * work around errata with sctp packets where the TCPE aka |
| 4523 | * L4E bit is set incorrectly on 64 byte (60 byte w/o crc) |
| 4524 | * packets, (aka let the stack check the crc32c) |
| 4525 | */ |
| 4526 | if (!((adapter->hw.mac.type == e1000_82576) && |
| 4527 | (skb->len == 60))) |
| 4528 | adapter->hw_csum_err++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4529 | /* let the stack verify checksum errors */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4530 | return; |
| 4531 | } |
| 4532 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 4533 | if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)) |
| 4534 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4535 | |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 4536 | dev_dbg(&adapter->pdev->dev, "cksum success: bits %08X\n", status_err); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4537 | adapter->hw_csum_good++; |
| 4538 | } |
| 4539 | |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4540 | static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring, |
| 4541 | int *work_done, int budget) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4542 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4543 | struct igb_adapter *adapter = rx_ring->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4544 | struct net_device *netdev = adapter->netdev; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4545 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4546 | struct pci_dev *pdev = adapter->pdev; |
| 4547 | union e1000_adv_rx_desc *rx_desc , *next_rxd; |
| 4548 | struct igb_buffer *buffer_info , *next_buffer; |
| 4549 | struct sk_buff *skb; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4550 | bool cleaned = false; |
| 4551 | int cleaned_count = 0; |
| 4552 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4553 | unsigned int i; |
| 4554 | u32 length, hlen, staterr; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4555 | |
| 4556 | i = rx_ring->next_to_clean; |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 4557 | buffer_info = &rx_ring->buffer_info[i]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4558 | rx_desc = E1000_RX_DESC_ADV(*rx_ring, i); |
| 4559 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 4560 | |
| 4561 | while (staterr & E1000_RXD_STAT_DD) { |
| 4562 | if (*work_done >= budget) |
| 4563 | break; |
| 4564 | (*work_done)++; |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 4565 | |
| 4566 | skb = buffer_info->skb; |
| 4567 | prefetch(skb->data - NET_IP_ALIGN); |
| 4568 | buffer_info->skb = NULL; |
| 4569 | |
| 4570 | i++; |
| 4571 | if (i == rx_ring->count) |
| 4572 | i = 0; |
| 4573 | next_rxd = E1000_RX_DESC_ADV(*rx_ring, i); |
| 4574 | prefetch(next_rxd); |
| 4575 | next_buffer = &rx_ring->buffer_info[i]; |
| 4576 | |
| 4577 | length = le16_to_cpu(rx_desc->wb.upper.length); |
| 4578 | cleaned = true; |
| 4579 | cleaned_count++; |
| 4580 | |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 4581 | /* this is the fast path for the non-packet split case */ |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 4582 | if (!adapter->rx_ps_hdr_size) { |
| 4583 | pci_unmap_single(pdev, buffer_info->dma, |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 4584 | adapter->rx_buffer_len, |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 4585 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 4586 | buffer_info->dma = 0; |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 4587 | skb_put(skb, length); |
| 4588 | goto send_up; |
| 4589 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4590 | |
| 4591 | /* HW will not DMA in data larger than the given buffer, even |
| 4592 | * if it parses the (NFS, of course) header to be larger. In |
| 4593 | * that case, it fills the header buffer and spills the rest |
| 4594 | * into the page. |
| 4595 | */ |
Al Viro | 7deb07b | 2008-03-16 22:43:06 +0000 | [diff] [blame] | 4596 | hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) & |
| 4597 | E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4598 | if (hlen > adapter->rx_ps_hdr_size) |
| 4599 | hlen = adapter->rx_ps_hdr_size; |
| 4600 | |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4601 | if (!skb_shinfo(skb)->nr_frags) { |
| 4602 | pci_unmap_single(pdev, buffer_info->dma, |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 4603 | adapter->rx_ps_hdr_size, |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4604 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 4605 | buffer_info->dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4606 | skb_put(skb, hlen); |
| 4607 | } |
| 4608 | |
| 4609 | if (length) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4610 | pci_unmap_page(pdev, buffer_info->page_dma, |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4611 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4612 | buffer_info->page_dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4613 | |
| 4614 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++, |
| 4615 | buffer_info->page, |
| 4616 | buffer_info->page_offset, |
| 4617 | length); |
| 4618 | |
| 4619 | if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) || |
| 4620 | (page_count(buffer_info->page) != 1)) |
| 4621 | buffer_info->page = NULL; |
| 4622 | else |
| 4623 | get_page(buffer_info->page); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4624 | |
| 4625 | skb->len += length; |
| 4626 | skb->data_len += length; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4627 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4628 | skb->truesize += length; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4629 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4630 | |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4631 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Alexander Duyck | b2d5653 | 2008-11-20 00:47:34 -0800 | [diff] [blame] | 4632 | buffer_info->skb = next_buffer->skb; |
| 4633 | buffer_info->dma = next_buffer->dma; |
| 4634 | next_buffer->skb = skb; |
| 4635 | next_buffer->dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4636 | goto next_desc; |
| 4637 | } |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 4638 | send_up: |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4639 | /* |
| 4640 | * If this bit is set, then the RX registers contain |
| 4641 | * the time stamp. No other packet will be time |
| 4642 | * stamped until we read these registers, so read the |
| 4643 | * registers to make them available again. Because |
| 4644 | * only one packet can be time stamped at a time, we |
| 4645 | * know that the register values must belong to this |
| 4646 | * one here and therefore we don't need to compare |
| 4647 | * any of the additional attributes stored for it. |
| 4648 | * |
| 4649 | * If nothing went wrong, then it should have a |
| 4650 | * skb_shared_tx that we can turn into a |
| 4651 | * skb_shared_hwtstamps. |
| 4652 | * |
| 4653 | * TODO: can time stamping be triggered (thus locking |
| 4654 | * the registers) without the packet reaching this point |
| 4655 | * here? In that case RX time stamping would get stuck. |
| 4656 | * |
| 4657 | * TODO: in "time stamp all packets" mode this bit is |
| 4658 | * not set. Need a global flag for this mode and then |
| 4659 | * always read the registers. Cannot be done without |
| 4660 | * a race condition. |
| 4661 | */ |
| 4662 | if (unlikely(staterr & E1000_RXD_STAT_TS)) { |
| 4663 | u64 regval; |
| 4664 | u64 ns; |
| 4665 | struct skb_shared_hwtstamps *shhwtstamps = |
| 4666 | skb_hwtstamps(skb); |
| 4667 | |
| 4668 | WARN(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID), |
| 4669 | "igb: no RX time stamp available for time stamped packet"); |
| 4670 | regval = rd32(E1000_RXSTMPL); |
| 4671 | regval |= (u64)rd32(E1000_RXSTMPH) << 32; |
| 4672 | ns = timecounter_cyc2time(&adapter->clock, regval); |
| 4673 | timecompare_update(&adapter->compare, ns); |
| 4674 | memset(shhwtstamps, 0, sizeof(*shhwtstamps)); |
| 4675 | shhwtstamps->hwtstamp = ns_to_ktime(ns); |
| 4676 | shhwtstamps->syststamp = |
| 4677 | timecompare_transform(&adapter->compare, ns); |
| 4678 | } |
| 4679 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4680 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
| 4681 | dev_kfree_skb_irq(skb); |
| 4682 | goto next_desc; |
| 4683 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4684 | |
| 4685 | total_bytes += skb->len; |
| 4686 | total_packets++; |
| 4687 | |
| 4688 | igb_rx_checksum_adv(adapter, staterr, skb); |
| 4689 | |
| 4690 | skb->protocol = eth_type_trans(skb, netdev); |
| 4691 | |
Alexander Duyck | d335252 | 2008-07-08 15:12:13 -0700 | [diff] [blame] | 4692 | igb_receive_skb(rx_ring, staterr, rx_desc, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4693 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4694 | next_desc: |
| 4695 | rx_desc->wb.upper.status_error = 0; |
| 4696 | |
| 4697 | /* return some buffers to hardware, one at a time is too slow */ |
| 4698 | if (cleaned_count >= IGB_RX_BUFFER_WRITE) { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4699 | igb_alloc_rx_buffers_adv(rx_ring, cleaned_count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4700 | cleaned_count = 0; |
| 4701 | } |
| 4702 | |
| 4703 | /* use prefetched values */ |
| 4704 | rx_desc = next_rxd; |
| 4705 | buffer_info = next_buffer; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4706 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 4707 | } |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4708 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4709 | rx_ring->next_to_clean = i; |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 4710 | cleaned_count = igb_desc_unused(rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4711 | |
| 4712 | if (cleaned_count) |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4713 | igb_alloc_rx_buffers_adv(rx_ring, cleaned_count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4714 | |
| 4715 | rx_ring->total_packets += total_packets; |
| 4716 | rx_ring->total_bytes += total_bytes; |
| 4717 | rx_ring->rx_stats.packets += total_packets; |
| 4718 | rx_ring->rx_stats.bytes += total_bytes; |
| 4719 | adapter->net_stats.rx_bytes += total_bytes; |
| 4720 | adapter->net_stats.rx_packets += total_packets; |
| 4721 | return cleaned; |
| 4722 | } |
| 4723 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4724 | /** |
| 4725 | * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split |
| 4726 | * @adapter: address of board private structure |
| 4727 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4728 | static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4729 | int cleaned_count) |
| 4730 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 4731 | struct igb_adapter *adapter = rx_ring->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4732 | struct net_device *netdev = adapter->netdev; |
| 4733 | struct pci_dev *pdev = adapter->pdev; |
| 4734 | union e1000_adv_rx_desc *rx_desc; |
| 4735 | struct igb_buffer *buffer_info; |
| 4736 | struct sk_buff *skb; |
| 4737 | unsigned int i; |
Alexander Duyck | db76176 | 2009-02-06 23:15:25 +0000 | [diff] [blame] | 4738 | int bufsz; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4739 | |
| 4740 | i = rx_ring->next_to_use; |
| 4741 | buffer_info = &rx_ring->buffer_info[i]; |
| 4742 | |
Alexander Duyck | db76176 | 2009-02-06 23:15:25 +0000 | [diff] [blame] | 4743 | if (adapter->rx_ps_hdr_size) |
| 4744 | bufsz = adapter->rx_ps_hdr_size; |
| 4745 | else |
| 4746 | bufsz = adapter->rx_buffer_len; |
Alexander Duyck | db76176 | 2009-02-06 23:15:25 +0000 | [diff] [blame] | 4747 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4748 | while (cleaned_count--) { |
| 4749 | rx_desc = E1000_RX_DESC_ADV(*rx_ring, i); |
| 4750 | |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4751 | if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4752 | if (!buffer_info->page) { |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4753 | buffer_info->page = alloc_page(GFP_ATOMIC); |
| 4754 | if (!buffer_info->page) { |
| 4755 | adapter->alloc_rx_buff_failed++; |
| 4756 | goto no_buffers; |
| 4757 | } |
| 4758 | buffer_info->page_offset = 0; |
| 4759 | } else { |
| 4760 | buffer_info->page_offset ^= PAGE_SIZE / 2; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4761 | } |
| 4762 | buffer_info->page_dma = |
Alexander Duyck | db76176 | 2009-02-06 23:15:25 +0000 | [diff] [blame] | 4763 | pci_map_page(pdev, buffer_info->page, |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 4764 | buffer_info->page_offset, |
| 4765 | PAGE_SIZE / 2, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4766 | PCI_DMA_FROMDEVICE); |
| 4767 | } |
| 4768 | |
| 4769 | if (!buffer_info->skb) { |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 4770 | skb = netdev_alloc_skb(netdev, bufsz + NET_IP_ALIGN); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4771 | if (!skb) { |
| 4772 | adapter->alloc_rx_buff_failed++; |
| 4773 | goto no_buffers; |
| 4774 | } |
| 4775 | |
| 4776 | /* Make buffer alignment 2 beyond a 16 byte boundary |
| 4777 | * this will result in a 16 byte aligned IP header after |
| 4778 | * the 14 byte MAC header is removed |
| 4779 | */ |
| 4780 | skb_reserve(skb, NET_IP_ALIGN); |
| 4781 | |
| 4782 | buffer_info->skb = skb; |
| 4783 | buffer_info->dma = pci_map_single(pdev, skb->data, |
| 4784 | bufsz, |
| 4785 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4786 | } |
| 4787 | /* Refresh the desc even if buffer_addrs didn't change because |
| 4788 | * each write-back erases this info. */ |
| 4789 | if (adapter->rx_ps_hdr_size) { |
| 4790 | rx_desc->read.pkt_addr = |
| 4791 | cpu_to_le64(buffer_info->page_dma); |
| 4792 | rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma); |
| 4793 | } else { |
| 4794 | rx_desc->read.pkt_addr = |
| 4795 | cpu_to_le64(buffer_info->dma); |
| 4796 | rx_desc->read.hdr_addr = 0; |
| 4797 | } |
| 4798 | |
| 4799 | i++; |
| 4800 | if (i == rx_ring->count) |
| 4801 | i = 0; |
| 4802 | buffer_info = &rx_ring->buffer_info[i]; |
| 4803 | } |
| 4804 | |
| 4805 | no_buffers: |
| 4806 | if (rx_ring->next_to_use != i) { |
| 4807 | rx_ring->next_to_use = i; |
| 4808 | if (i == 0) |
| 4809 | i = (rx_ring->count - 1); |
| 4810 | else |
| 4811 | i--; |
| 4812 | |
| 4813 | /* Force memory writes to complete before letting h/w |
| 4814 | * know there are new descriptors to fetch. (Only |
| 4815 | * applicable for weak-ordered memory model archs, |
| 4816 | * such as IA-64). */ |
| 4817 | wmb(); |
| 4818 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 4819 | } |
| 4820 | } |
| 4821 | |
| 4822 | /** |
| 4823 | * igb_mii_ioctl - |
| 4824 | * @netdev: |
| 4825 | * @ifreq: |
| 4826 | * @cmd: |
| 4827 | **/ |
| 4828 | static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 4829 | { |
| 4830 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 4831 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4832 | |
| 4833 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
| 4834 | return -EOPNOTSUPP; |
| 4835 | |
| 4836 | switch (cmd) { |
| 4837 | case SIOCGMIIPHY: |
| 4838 | data->phy_id = adapter->hw.phy.addr; |
| 4839 | break; |
| 4840 | case SIOCGMIIREG: |
| 4841 | if (!capable(CAP_NET_ADMIN)) |
| 4842 | return -EPERM; |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 4843 | if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
| 4844 | &data->val_out)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4845 | return -EIO; |
| 4846 | break; |
| 4847 | case SIOCSMIIREG: |
| 4848 | default: |
| 4849 | return -EOPNOTSUPP; |
| 4850 | } |
| 4851 | return 0; |
| 4852 | } |
| 4853 | |
| 4854 | /** |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 4855 | * igb_hwtstamp_ioctl - control hardware time stamping |
| 4856 | * @netdev: |
| 4857 | * @ifreq: |
| 4858 | * @cmd: |
| 4859 | * |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4860 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 4861 | * disable it when requested, although it shouldn't case any overhead |
| 4862 | * when no packet needs it. At most one packet in the queue may be |
| 4863 | * marked for time stamping, otherwise it would be impossible to tell |
| 4864 | * for sure to which packet the hardware time stamp belongs. |
| 4865 | * |
| 4866 | * Incoming time stamping has to be configured via the hardware |
| 4867 | * filters. Not all combinations are supported, in particular event |
| 4868 | * type has to be specified. Matching the kind of event packet is |
| 4869 | * not supported, with the exception of "all V2 events regardless of |
| 4870 | * level 2 or 4". |
| 4871 | * |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 4872 | **/ |
| 4873 | static int igb_hwtstamp_ioctl(struct net_device *netdev, |
| 4874 | struct ifreq *ifr, int cmd) |
| 4875 | { |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4876 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 4877 | struct e1000_hw *hw = &adapter->hw; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 4878 | struct hwtstamp_config config; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4879 | u32 tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED; |
| 4880 | u32 tsync_rx_ctl_bit = E1000_TSYNCRXCTL_ENABLED; |
| 4881 | u32 tsync_rx_ctl_type = 0; |
| 4882 | u32 tsync_rx_cfg = 0; |
| 4883 | int is_l4 = 0; |
| 4884 | int is_l2 = 0; |
| 4885 | short port = 319; /* PTP */ |
| 4886 | u32 regval; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 4887 | |
| 4888 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 4889 | return -EFAULT; |
| 4890 | |
| 4891 | /* reserved for future extensions */ |
| 4892 | if (config.flags) |
| 4893 | return -EINVAL; |
| 4894 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4895 | switch (config.tx_type) { |
| 4896 | case HWTSTAMP_TX_OFF: |
| 4897 | tsync_tx_ctl_bit = 0; |
| 4898 | break; |
| 4899 | case HWTSTAMP_TX_ON: |
| 4900 | tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED; |
| 4901 | break; |
| 4902 | default: |
| 4903 | return -ERANGE; |
| 4904 | } |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 4905 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4906 | switch (config.rx_filter) { |
| 4907 | case HWTSTAMP_FILTER_NONE: |
| 4908 | tsync_rx_ctl_bit = 0; |
| 4909 | break; |
| 4910 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 4911 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 4912 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 4913 | case HWTSTAMP_FILTER_ALL: |
| 4914 | /* |
| 4915 | * register TSYNCRXCFG must be set, therefore it is not |
| 4916 | * possible to time stamp both Sync and Delay_Req messages |
| 4917 | * => fall back to time stamping all packets |
| 4918 | */ |
| 4919 | tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_ALL; |
| 4920 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 4921 | break; |
| 4922 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 4923 | tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 4924 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE; |
| 4925 | is_l4 = 1; |
| 4926 | break; |
| 4927 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 4928 | tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1; |
| 4929 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE; |
| 4930 | is_l4 = 1; |
| 4931 | break; |
| 4932 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 4933 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 4934 | tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 4935 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE; |
| 4936 | is_l2 = 1; |
| 4937 | is_l4 = 1; |
| 4938 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 4939 | break; |
| 4940 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 4941 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 4942 | tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
| 4943 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE; |
| 4944 | is_l2 = 1; |
| 4945 | is_l4 = 1; |
| 4946 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 4947 | break; |
| 4948 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 4949 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 4950 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
| 4951 | tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
| 4952 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
| 4953 | is_l2 = 1; |
| 4954 | break; |
| 4955 | default: |
| 4956 | return -ERANGE; |
| 4957 | } |
| 4958 | |
| 4959 | /* enable/disable TX */ |
| 4960 | regval = rd32(E1000_TSYNCTXCTL); |
| 4961 | regval = (regval & ~E1000_TSYNCTXCTL_ENABLED) | tsync_tx_ctl_bit; |
| 4962 | wr32(E1000_TSYNCTXCTL, regval); |
| 4963 | |
| 4964 | /* enable/disable RX, define which PTP packets are time stamped */ |
| 4965 | regval = rd32(E1000_TSYNCRXCTL); |
| 4966 | regval = (regval & ~E1000_TSYNCRXCTL_ENABLED) | tsync_rx_ctl_bit; |
| 4967 | regval = (regval & ~0xE) | tsync_rx_ctl_type; |
| 4968 | wr32(E1000_TSYNCRXCTL, regval); |
| 4969 | wr32(E1000_TSYNCRXCFG, tsync_rx_cfg); |
| 4970 | |
| 4971 | /* |
| 4972 | * Ethertype Filter Queue Filter[0][15:0] = 0x88F7 |
| 4973 | * (Ethertype to filter on) |
| 4974 | * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter) |
| 4975 | * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping) |
| 4976 | */ |
| 4977 | wr32(E1000_ETQF0, is_l2 ? 0x440088f7 : 0); |
| 4978 | |
| 4979 | /* L4 Queue Filter[0]: only filter by source and destination port */ |
| 4980 | wr32(E1000_SPQF0, htons(port)); |
| 4981 | wr32(E1000_IMIREXT(0), is_l4 ? |
| 4982 | ((1<<12) | (1<<19) /* bypass size and control flags */) : 0); |
| 4983 | wr32(E1000_IMIR(0), is_l4 ? |
| 4984 | (htons(port) |
| 4985 | | (0<<16) /* immediate interrupt disabled */ |
| 4986 | | 0 /* (1<<17) bit cleared: do not bypass |
| 4987 | destination port check */) |
| 4988 | : 0); |
| 4989 | wr32(E1000_FTQF0, is_l4 ? |
| 4990 | (0x11 /* UDP */ |
| 4991 | | (1<<15) /* VF not compared */ |
| 4992 | | (1<<27) /* Enable Timestamping */ |
| 4993 | | (7<<28) /* only source port filter enabled, |
| 4994 | source/target address and protocol |
| 4995 | masked */) |
| 4996 | : ((1<<15) | (15<<28) /* all mask bits set = filter not |
| 4997 | enabled */)); |
| 4998 | |
| 4999 | wrfl(); |
| 5000 | |
| 5001 | adapter->hwtstamp_config = config; |
| 5002 | |
| 5003 | /* clear TX/RX time stamp registers, just to be sure */ |
| 5004 | regval = rd32(E1000_TXSTMPH); |
| 5005 | regval = rd32(E1000_RXSTMPH); |
| 5006 | |
| 5007 | return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 5008 | -EFAULT : 0; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5012 | * igb_ioctl - |
| 5013 | * @netdev: |
| 5014 | * @ifreq: |
| 5015 | * @cmd: |
| 5016 | **/ |
| 5017 | static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 5018 | { |
| 5019 | switch (cmd) { |
| 5020 | case SIOCGMIIPHY: |
| 5021 | case SIOCGMIIREG: |
| 5022 | case SIOCSMIIREG: |
| 5023 | return igb_mii_ioctl(netdev, ifr, cmd); |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 5024 | case SIOCSHWTSTAMP: |
| 5025 | return igb_hwtstamp_ioctl(netdev, ifr, cmd); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5026 | default: |
| 5027 | return -EOPNOTSUPP; |
| 5028 | } |
| 5029 | } |
| 5030 | |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 5031 | s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
| 5032 | { |
| 5033 | struct igb_adapter *adapter = hw->back; |
| 5034 | u16 cap_offset; |
| 5035 | |
| 5036 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 5037 | if (!cap_offset) |
| 5038 | return -E1000_ERR_CONFIG; |
| 5039 | |
| 5040 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 5041 | |
| 5042 | return 0; |
| 5043 | } |
| 5044 | |
| 5045 | s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
| 5046 | { |
| 5047 | struct igb_adapter *adapter = hw->back; |
| 5048 | u16 cap_offset; |
| 5049 | |
| 5050 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); |
| 5051 | if (!cap_offset) |
| 5052 | return -E1000_ERR_CONFIG; |
| 5053 | |
| 5054 | pci_write_config_word(adapter->pdev, cap_offset + reg, *value); |
| 5055 | |
| 5056 | return 0; |
| 5057 | } |
| 5058 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5059 | static void igb_vlan_rx_register(struct net_device *netdev, |
| 5060 | struct vlan_group *grp) |
| 5061 | { |
| 5062 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5063 | struct e1000_hw *hw = &adapter->hw; |
| 5064 | u32 ctrl, rctl; |
| 5065 | |
| 5066 | igb_irq_disable(adapter); |
| 5067 | adapter->vlgrp = grp; |
| 5068 | |
| 5069 | if (grp) { |
| 5070 | /* enable VLAN tag insert/strip */ |
| 5071 | ctrl = rd32(E1000_CTRL); |
| 5072 | ctrl |= E1000_CTRL_VME; |
| 5073 | wr32(E1000_CTRL, ctrl); |
| 5074 | |
| 5075 | /* enable VLAN receive filtering */ |
| 5076 | rctl = rd32(E1000_RCTL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5077 | rctl &= ~E1000_RCTL_CFIEN; |
| 5078 | wr32(E1000_RCTL, rctl); |
| 5079 | igb_update_mng_vlan(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5080 | } else { |
| 5081 | /* disable VLAN tag insert/strip */ |
| 5082 | ctrl = rd32(E1000_CTRL); |
| 5083 | ctrl &= ~E1000_CTRL_VME; |
| 5084 | wr32(E1000_CTRL, ctrl); |
| 5085 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5086 | if (adapter->mng_vlan_id != (u16)IGB_MNG_VLAN_NONE) { |
| 5087 | igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id); |
| 5088 | adapter->mng_vlan_id = IGB_MNG_VLAN_NONE; |
| 5089 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5090 | } |
| 5091 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 5092 | igb_rlpml_set(adapter); |
| 5093 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5094 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 5095 | igb_irq_enable(adapter); |
| 5096 | } |
| 5097 | |
| 5098 | static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 5099 | { |
| 5100 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5101 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5102 | int pf_id = adapter->vfs_allocated_count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5103 | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 5104 | if ((hw->mng_cookie.status & |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5105 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 5106 | (vid == adapter->mng_vlan_id)) |
| 5107 | return; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5108 | |
| 5109 | /* add vid to vlvf if sr-iov is enabled, |
| 5110 | * if that fails add directly to filter table */ |
| 5111 | if (igb_vlvf_set(adapter, vid, true, pf_id)) |
| 5112 | igb_vfta_set(hw, vid, true); |
| 5113 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 5117 | { |
| 5118 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5119 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5120 | int pf_id = adapter->vfs_allocated_count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5121 | |
| 5122 | igb_irq_disable(adapter); |
| 5123 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
| 5124 | |
| 5125 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 5126 | igb_irq_enable(adapter); |
| 5127 | |
| 5128 | if ((adapter->hw.mng_cookie.status & |
| 5129 | E1000_MNG_DHCP_COOKIE_STATUS_VLAN) && |
| 5130 | (vid == adapter->mng_vlan_id)) { |
| 5131 | /* release control to f/w */ |
| 5132 | igb_release_hw_control(adapter); |
| 5133 | return; |
| 5134 | } |
| 5135 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5136 | /* remove vid from vlvf if sr-iov is enabled, |
| 5137 | * if not in vlvf remove from vfta */ |
| 5138 | if (igb_vlvf_set(adapter, vid, false, pf_id)) |
| 5139 | igb_vfta_set(hw, vid, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | static void igb_restore_vlan(struct igb_adapter *adapter) |
| 5143 | { |
| 5144 | igb_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 5145 | |
| 5146 | if (adapter->vlgrp) { |
| 5147 | u16 vid; |
| 5148 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 5149 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 5150 | continue; |
| 5151 | igb_vlan_rx_add_vid(adapter->netdev, vid); |
| 5152 | } |
| 5153 | } |
| 5154 | } |
| 5155 | |
| 5156 | int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx) |
| 5157 | { |
| 5158 | struct e1000_mac_info *mac = &adapter->hw.mac; |
| 5159 | |
| 5160 | mac->autoneg = 0; |
| 5161 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5162 | switch (spddplx) { |
| 5163 | case SPEED_10 + DUPLEX_HALF: |
| 5164 | mac->forced_speed_duplex = ADVERTISE_10_HALF; |
| 5165 | break; |
| 5166 | case SPEED_10 + DUPLEX_FULL: |
| 5167 | mac->forced_speed_duplex = ADVERTISE_10_FULL; |
| 5168 | break; |
| 5169 | case SPEED_100 + DUPLEX_HALF: |
| 5170 | mac->forced_speed_duplex = ADVERTISE_100_HALF; |
| 5171 | break; |
| 5172 | case SPEED_100 + DUPLEX_FULL: |
| 5173 | mac->forced_speed_duplex = ADVERTISE_100_FULL; |
| 5174 | break; |
| 5175 | case SPEED_1000 + DUPLEX_FULL: |
| 5176 | mac->autoneg = 1; |
| 5177 | adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL; |
| 5178 | break; |
| 5179 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 5180 | default: |
| 5181 | dev_err(&adapter->pdev->dev, |
| 5182 | "Unsupported Speed/Duplex configuration\n"); |
| 5183 | return -EINVAL; |
| 5184 | } |
| 5185 | return 0; |
| 5186 | } |
| 5187 | |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 5188 | static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5189 | { |
| 5190 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5191 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5192 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 5193 | u32 ctrl, rctl, status; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5194 | u32 wufc = adapter->wol; |
| 5195 | #ifdef CONFIG_PM |
| 5196 | int retval = 0; |
| 5197 | #endif |
| 5198 | |
| 5199 | netif_device_detach(netdev); |
| 5200 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 5201 | if (netif_running(netdev)) |
| 5202 | igb_close(netdev); |
| 5203 | |
| 5204 | igb_reset_interrupt_capability(adapter); |
| 5205 | |
| 5206 | igb_free_queues(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5207 | |
| 5208 | #ifdef CONFIG_PM |
| 5209 | retval = pci_save_state(pdev); |
| 5210 | if (retval) |
| 5211 | return retval; |
| 5212 | #endif |
| 5213 | |
| 5214 | status = rd32(E1000_STATUS); |
| 5215 | if (status & E1000_STATUS_LU) |
| 5216 | wufc &= ~E1000_WUFC_LNKC; |
| 5217 | |
| 5218 | if (wufc) { |
| 5219 | igb_setup_rctl(adapter); |
| 5220 | igb_set_multi(netdev); |
| 5221 | |
| 5222 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5223 | if (wufc & E1000_WUFC_MC) { |
| 5224 | rctl = rd32(E1000_RCTL); |
| 5225 | rctl |= E1000_RCTL_MPE; |
| 5226 | wr32(E1000_RCTL, rctl); |
| 5227 | } |
| 5228 | |
| 5229 | ctrl = rd32(E1000_CTRL); |
| 5230 | /* advertise wake from D3Cold */ |
| 5231 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 5232 | /* phy power management enable */ |
| 5233 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 5234 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 5235 | wr32(E1000_CTRL, ctrl); |
| 5236 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5237 | /* Allow time for pending master requests to run */ |
| 5238 | igb_disable_pcie_master(&adapter->hw); |
| 5239 | |
| 5240 | wr32(E1000_WUC, E1000_WUC_PME_EN); |
| 5241 | wr32(E1000_WUFC, wufc); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5242 | } else { |
| 5243 | wr32(E1000_WUC, 0); |
| 5244 | wr32(E1000_WUFC, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5245 | } |
| 5246 | |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 5247 | *enable_wake = wufc || adapter->en_mng_pt; |
| 5248 | if (!*enable_wake) |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 5249 | igb_shutdown_fiber_serdes_link_82575(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5250 | |
| 5251 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 5252 | * would have already happened in close and is redundant. */ |
| 5253 | igb_release_hw_control(adapter); |
| 5254 | |
| 5255 | pci_disable_device(pdev); |
| 5256 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5257 | return 0; |
| 5258 | } |
| 5259 | |
| 5260 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 5261 | static int igb_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5262 | { |
| 5263 | int retval; |
| 5264 | bool wake; |
| 5265 | |
| 5266 | retval = __igb_shutdown(pdev, &wake); |
| 5267 | if (retval) |
| 5268 | return retval; |
| 5269 | |
| 5270 | if (wake) { |
| 5271 | pci_prepare_to_sleep(pdev); |
| 5272 | } else { |
| 5273 | pci_wake_from_d3(pdev, false); |
| 5274 | pci_set_power_state(pdev, PCI_D3hot); |
| 5275 | } |
| 5276 | |
| 5277 | return 0; |
| 5278 | } |
| 5279 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5280 | static int igb_resume(struct pci_dev *pdev) |
| 5281 | { |
| 5282 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5283 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5284 | struct e1000_hw *hw = &adapter->hw; |
| 5285 | u32 err; |
| 5286 | |
| 5287 | pci_set_power_state(pdev, PCI_D0); |
| 5288 | pci_restore_state(pdev); |
Taku Izumi | 42bfd33a | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 5289 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 5290 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5291 | if (err) { |
| 5292 | dev_err(&pdev->dev, |
| 5293 | "igb: Cannot enable PCI device from suspend\n"); |
| 5294 | return err; |
| 5295 | } |
| 5296 | pci_set_master(pdev); |
| 5297 | |
| 5298 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5299 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5300 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 5301 | igb_set_interrupt_capability(adapter); |
| 5302 | |
| 5303 | if (igb_alloc_queues(adapter)) { |
| 5304 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 5305 | return -ENOMEM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | /* e1000_power_up_phy(adapter); */ |
| 5309 | |
| 5310 | igb_reset(adapter); |
Alexander Duyck | a8564f0 | 2009-02-06 23:21:10 +0000 | [diff] [blame] | 5311 | |
| 5312 | /* let the f/w know that the h/w is now under the control of the |
| 5313 | * driver. */ |
| 5314 | igb_get_hw_control(adapter); |
| 5315 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5316 | wr32(E1000_WUS, ~0); |
| 5317 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 5318 | if (netif_running(netdev)) { |
| 5319 | err = igb_open(netdev); |
| 5320 | if (err) |
| 5321 | return err; |
| 5322 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5323 | |
| 5324 | netif_device_attach(netdev); |
| 5325 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5326 | return 0; |
| 5327 | } |
| 5328 | #endif |
| 5329 | |
| 5330 | static void igb_shutdown(struct pci_dev *pdev) |
| 5331 | { |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 5332 | bool wake; |
| 5333 | |
| 5334 | __igb_shutdown(pdev, &wake); |
| 5335 | |
| 5336 | if (system_state == SYSTEM_POWER_OFF) { |
| 5337 | pci_wake_from_d3(pdev, wake); |
| 5338 | pci_set_power_state(pdev, PCI_D3hot); |
| 5339 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5343 | /* |
| 5344 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5345 | * without having to re-enable interrupts. It's not called while |
| 5346 | * the interrupt routine is executing. |
| 5347 | */ |
| 5348 | static void igb_netpoll(struct net_device *netdev) |
| 5349 | { |
| 5350 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 5351 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5352 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5353 | |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 5354 | if (!adapter->msix_entries) { |
| 5355 | igb_irq_disable(adapter); |
| 5356 | napi_schedule(&adapter->rx_ring[0].napi); |
| 5357 | return; |
| 5358 | } |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 5359 | |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 5360 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5361 | struct igb_ring *tx_ring = &adapter->tx_ring[i]; |
| 5362 | wr32(E1000_EIMC, tx_ring->eims_value); |
| 5363 | igb_clean_tx_irq(tx_ring); |
| 5364 | wr32(E1000_EIMS, tx_ring->eims_value); |
| 5365 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5366 | |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 5367 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5368 | struct igb_ring *rx_ring = &adapter->rx_ring[i]; |
| 5369 | wr32(E1000_EIMC, rx_ring->eims_value); |
| 5370 | napi_schedule(&rx_ring->napi); |
| 5371 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5372 | } |
| 5373 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 5374 | |
| 5375 | /** |
| 5376 | * igb_io_error_detected - called when PCI error is detected |
| 5377 | * @pdev: Pointer to PCI device |
| 5378 | * @state: The current pci connection state |
| 5379 | * |
| 5380 | * This function is called after a PCI bus error affecting |
| 5381 | * this device has been detected. |
| 5382 | */ |
| 5383 | static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev, |
| 5384 | pci_channel_state_t state) |
| 5385 | { |
| 5386 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5387 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5388 | |
| 5389 | netif_device_detach(netdev); |
| 5390 | |
Alexander Duyck | 59ed6ee | 2009-06-30 12:46:34 +0000 | [diff] [blame] | 5391 | if (state == pci_channel_io_perm_failure) |
| 5392 | return PCI_ERS_RESULT_DISCONNECT; |
| 5393 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5394 | if (netif_running(netdev)) |
| 5395 | igb_down(adapter); |
| 5396 | pci_disable_device(pdev); |
| 5397 | |
| 5398 | /* Request a slot slot reset. */ |
| 5399 | return PCI_ERS_RESULT_NEED_RESET; |
| 5400 | } |
| 5401 | |
| 5402 | /** |
| 5403 | * igb_io_slot_reset - called after the pci bus has been reset. |
| 5404 | * @pdev: Pointer to PCI device |
| 5405 | * |
| 5406 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 5407 | * resembles the first-half of the igb_resume routine. |
| 5408 | */ |
| 5409 | static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev) |
| 5410 | { |
| 5411 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5412 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5413 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 5414 | pci_ers_result_t result; |
Taku Izumi | 42bfd33a | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 5415 | int err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5416 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 5417 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5418 | dev_err(&pdev->dev, |
| 5419 | "Cannot re-enable PCI device after reset.\n"); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 5420 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5421 | } else { |
| 5422 | pci_set_master(pdev); |
| 5423 | pci_restore_state(pdev); |
| 5424 | |
| 5425 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 5426 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 5427 | |
| 5428 | igb_reset(adapter); |
| 5429 | wr32(E1000_WUS, ~0); |
| 5430 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5431 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5432 | |
Jeff Kirsher | ea943d4 | 2008-12-11 20:34:19 -0800 | [diff] [blame] | 5433 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5434 | if (err) { |
| 5435 | dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status " |
| 5436 | "failed 0x%0x\n", err); |
| 5437 | /* non-fatal, continue */ |
| 5438 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5439 | |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 5440 | return result; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | /** |
| 5444 | * igb_io_resume - called when traffic can start flowing again. |
| 5445 | * @pdev: Pointer to PCI device |
| 5446 | * |
| 5447 | * This callback is called when the error recovery driver tells us that |
| 5448 | * its OK to resume normal operation. Implementation resembles the |
| 5449 | * second-half of the igb_resume routine. |
| 5450 | */ |
| 5451 | static void igb_io_resume(struct pci_dev *pdev) |
| 5452 | { |
| 5453 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5454 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5455 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5456 | if (netif_running(netdev)) { |
| 5457 | if (igb_up(adapter)) { |
| 5458 | dev_err(&pdev->dev, "igb_up failed after reset\n"); |
| 5459 | return; |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | netif_device_attach(netdev); |
| 5464 | |
| 5465 | /* let the f/w know that the h/w is now under the control of the |
| 5466 | * driver. */ |
| 5467 | igb_get_hw_control(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5468 | } |
| 5469 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5470 | static int igb_set_vf_mac(struct igb_adapter *adapter, |
| 5471 | int vf, unsigned char *mac_addr) |
| 5472 | { |
| 5473 | struct e1000_hw *hw = &adapter->hw; |
| 5474 | int rar_entry = vf + 1; /* VF MAC addresses start at entry 1 */ |
| 5475 | |
| 5476 | igb_rar_set(hw, mac_addr, rar_entry); |
| 5477 | |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 5478 | memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5479 | |
| 5480 | igb_set_rah_pool(hw, vf, rar_entry); |
| 5481 | |
| 5482 | return 0; |
| 5483 | } |
| 5484 | |
| 5485 | static void igb_vmm_control(struct igb_adapter *adapter) |
| 5486 | { |
| 5487 | struct e1000_hw *hw = &adapter->hw; |
| 5488 | u32 reg_data; |
| 5489 | |
| 5490 | if (!adapter->vfs_allocated_count) |
| 5491 | return; |
| 5492 | |
| 5493 | /* VF's need PF reset indication before they |
| 5494 | * can send/receive mail */ |
| 5495 | reg_data = rd32(E1000_CTRL_EXT); |
| 5496 | reg_data |= E1000_CTRL_EXT_PFRSTD; |
| 5497 | wr32(E1000_CTRL_EXT, reg_data); |
| 5498 | |
| 5499 | igb_vmdq_set_loopback_pf(hw, true); |
| 5500 | igb_vmdq_set_replication_pf(hw, true); |
| 5501 | } |
| 5502 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5503 | /* igb_main.c */ |