Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Carolyn Wyborny | 4297f99 | 2011-06-29 01:16:10 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2011 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> |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 31 | #include <linux/bitops.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/pagemap.h> |
| 34 | #include <linux/netdevice.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 35 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 37 | #include <net/checksum.h> |
| 38 | #include <net/ip6_checksum.h> |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 39 | #include <linux/net_tstamp.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 40 | #include <linux/mii.h> |
| 41 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 42 | #include <linux/if.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 43 | #include <linux/if_vlan.h> |
| 44 | #include <linux/pci.h> |
Alexander Duyck | c54106b | 2008-10-16 21:26:57 -0700 | [diff] [blame] | 45 | #include <linux/pci-aspm.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 46 | #include <linux/delay.h> |
| 47 | #include <linux/interrupt.h> |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 48 | #include <linux/ip.h> |
| 49 | #include <linux/tcp.h> |
| 50 | #include <linux/sctp.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 51 | #include <linux/if_ether.h> |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 52 | #include <linux/aer.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 53 | #include <linux/prefetch.h> |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 54 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 55 | #include <linux/dca.h> |
| 56 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 57 | #include "igb.h" |
| 58 | |
Carolyn Wyborny | 0d1fe82 | 2011-03-11 20:58:19 -0800 | [diff] [blame] | 59 | #define MAJ 3 |
| 60 | #define MIN 0 |
| 61 | #define BUILD 6 |
Carolyn Wyborny | 0d1fe82 | 2011-03-11 20:58:19 -0800 | [diff] [blame] | 62 | #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \ |
Carolyn Wyborny | 929dd04 | 2011-05-26 03:02:26 +0000 | [diff] [blame] | 63 | __stringify(BUILD) "-k" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 64 | char igb_driver_name[] = "igb"; |
| 65 | char igb_driver_version[] = DRV_VERSION; |
| 66 | static const char igb_driver_string[] = |
| 67 | "Intel(R) Gigabit Ethernet Network Driver"; |
Carolyn Wyborny | 4c4b42c | 2011-02-17 09:02:30 +0000 | [diff] [blame] | 68 | static const char igb_copyright[] = "Copyright (c) 2007-2011 Intel Corporation."; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 69 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 70 | static const struct e1000_info *igb_info_tbl[] = { |
| 71 | [board_82575] = &e1000_82575_info, |
| 72 | }; |
| 73 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 74 | static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 75 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 }, |
| 76 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 }, |
| 77 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 }, |
| 78 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 }, |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 79 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 }, |
| 80 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 }, |
Carolyn Wyborny | 6493d24 | 2011-01-14 05:33:46 +0000 | [diff] [blame] | 81 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 }, |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 82 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 }, |
| 83 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 }, |
| 84 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 }, |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 85 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 }, |
| 86 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 }, |
Gasparakis, Joseph | 1b5dda3 | 2010-12-09 01:41:01 +0000 | [diff] [blame] | 87 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 }, |
| 88 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 }, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 89 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 }, |
Alexander Duyck | 9eb2341 | 2009-03-13 20:42:15 +0000 | [diff] [blame] | 90 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 }, |
Alexander Duyck | 747d49b | 2009-10-05 06:33:27 +0000 | [diff] [blame] | 91 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 }, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 92 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 }, |
| 93 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 }, |
Alexander Duyck | 4703bf7 | 2009-07-23 18:09:48 +0000 | [diff] [blame] | 94 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 }, |
Carolyn Wyborny | b894fa2 | 2010-03-19 06:07:48 +0000 | [diff] [blame] | 95 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 }, |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 96 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 }, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 97 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 }, |
| 98 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 }, |
| 99 | { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 }, |
| 100 | /* required last entry */ |
| 101 | {0, } |
| 102 | }; |
| 103 | |
| 104 | MODULE_DEVICE_TABLE(pci, igb_pci_tbl); |
| 105 | |
| 106 | void igb_reset(struct igb_adapter *); |
| 107 | static int igb_setup_all_tx_resources(struct igb_adapter *); |
| 108 | static int igb_setup_all_rx_resources(struct igb_adapter *); |
| 109 | static void igb_free_all_tx_resources(struct igb_adapter *); |
| 110 | static void igb_free_all_rx_resources(struct igb_adapter *); |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 111 | static void igb_setup_mrqc(struct igb_adapter *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 112 | static int igb_probe(struct pci_dev *, const struct pci_device_id *); |
| 113 | static void __devexit igb_remove(struct pci_dev *pdev); |
Anders Berggren | 673b8b7 | 2011-02-04 07:32:32 +0000 | [diff] [blame] | 114 | static void igb_init_hw_timer(struct igb_adapter *adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 115 | static int igb_sw_init(struct igb_adapter *); |
| 116 | static int igb_open(struct net_device *); |
| 117 | static int igb_close(struct net_device *); |
| 118 | static void igb_configure_tx(struct igb_adapter *); |
| 119 | static void igb_configure_rx(struct igb_adapter *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 120 | static void igb_clean_all_tx_rings(struct igb_adapter *); |
| 121 | static void igb_clean_all_rx_rings(struct igb_adapter *); |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 122 | static void igb_clean_tx_ring(struct igb_ring *); |
| 123 | static void igb_clean_rx_ring(struct igb_ring *); |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 124 | static void igb_set_rx_mode(struct net_device *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 125 | static void igb_update_phy_info(unsigned long); |
| 126 | static void igb_watchdog(unsigned long); |
| 127 | static void igb_watchdog_task(struct work_struct *); |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 128 | static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, struct net_device *); |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 129 | static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev, |
| 130 | struct rtnl_link_stats64 *stats); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 131 | static int igb_change_mtu(struct net_device *, int); |
| 132 | static int igb_set_mac(struct net_device *, void *); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 133 | static void igb_set_uta(struct igb_adapter *adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 134 | static irqreturn_t igb_intr(int irq, void *); |
| 135 | static irqreturn_t igb_intr_msi(int irq, void *); |
| 136 | static irqreturn_t igb_msix_other(int irq, void *); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 137 | static irqreturn_t igb_msix_ring(int irq, void *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 138 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 139 | static void igb_update_dca(struct igb_q_vector *); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 140 | static void igb_setup_dca(struct igb_adapter *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 141 | #endif /* CONFIG_IGB_DCA */ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 142 | static int igb_poll(struct napi_struct *, int); |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 143 | static bool igb_clean_tx_irq(struct igb_q_vector *); |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 144 | static bool igb_clean_rx_irq(struct igb_q_vector *, int); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 145 | static int igb_ioctl(struct net_device *, struct ifreq *, int cmd); |
| 146 | static void igb_tx_timeout(struct net_device *); |
| 147 | static void igb_reset_task(struct work_struct *); |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 148 | static void igb_vlan_mode(struct net_device *netdev, u32 features); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 149 | static void igb_vlan_rx_add_vid(struct net_device *, u16); |
| 150 | static void igb_vlan_rx_kill_vid(struct net_device *, u16); |
| 151 | static void igb_restore_vlan(struct igb_adapter *); |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 152 | static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 153 | static void igb_ping_all_vfs(struct igb_adapter *); |
| 154 | static void igb_msg_task(struct igb_adapter *); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 155 | static void igb_vmm_control(struct igb_adapter *); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 156 | static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 157 | static void igb_restore_vf_multicasts(struct igb_adapter *adapter); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 158 | static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac); |
| 159 | static int igb_ndo_set_vf_vlan(struct net_device *netdev, |
| 160 | int vf, u16 vlan, u8 qos); |
| 161 | static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate); |
| 162 | static int igb_ndo_get_vf_config(struct net_device *netdev, int vf, |
| 163 | struct ifla_vf_info *ivi); |
Lior Levy | 17dc566 | 2011-02-08 02:28:46 +0000 | [diff] [blame] | 164 | static void igb_check_vf_rate_limit(struct igb_adapter *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 165 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 166 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 167 | static int igb_suspend(struct pci_dev *, pm_message_t); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 168 | static int igb_resume(struct pci_dev *); |
| 169 | #endif |
| 170 | static void igb_shutdown(struct pci_dev *); |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 171 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 172 | static int igb_notify_dca(struct notifier_block *, unsigned long, void *); |
| 173 | static struct notifier_block dca_notifier = { |
| 174 | .notifier_call = igb_notify_dca, |
| 175 | .next = NULL, |
| 176 | .priority = 0 |
| 177 | }; |
| 178 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 179 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 180 | /* for netdump / net console */ |
| 181 | static void igb_netpoll(struct net_device *); |
| 182 | #endif |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 183 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 184 | static unsigned int max_vfs = 0; |
| 185 | module_param(max_vfs, uint, 0); |
| 186 | MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate " |
| 187 | "per physical function"); |
| 188 | #endif /* CONFIG_PCI_IOV */ |
| 189 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 190 | static pci_ers_result_t igb_io_error_detected(struct pci_dev *, |
| 191 | pci_channel_state_t); |
| 192 | static pci_ers_result_t igb_io_slot_reset(struct pci_dev *); |
| 193 | static void igb_io_resume(struct pci_dev *); |
| 194 | |
| 195 | static struct pci_error_handlers igb_err_handler = { |
| 196 | .error_detected = igb_io_error_detected, |
| 197 | .slot_reset = igb_io_slot_reset, |
| 198 | .resume = igb_io_resume, |
| 199 | }; |
| 200 | |
| 201 | |
| 202 | static struct pci_driver igb_driver = { |
| 203 | .name = igb_driver_name, |
| 204 | .id_table = igb_pci_tbl, |
| 205 | .probe = igb_probe, |
| 206 | .remove = __devexit_p(igb_remove), |
| 207 | #ifdef CONFIG_PM |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 208 | /* Power Management Hooks */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 209 | .suspend = igb_suspend, |
| 210 | .resume = igb_resume, |
| 211 | #endif |
| 212 | .shutdown = igb_shutdown, |
| 213 | .err_handler = &igb_err_handler |
| 214 | }; |
| 215 | |
| 216 | MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>"); |
| 217 | MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver"); |
| 218 | MODULE_LICENSE("GPL"); |
| 219 | MODULE_VERSION(DRV_VERSION); |
| 220 | |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 221 | struct igb_reg_info { |
| 222 | u32 ofs; |
| 223 | char *name; |
| 224 | }; |
| 225 | |
| 226 | static const struct igb_reg_info igb_reg_info_tbl[] = { |
| 227 | |
| 228 | /* General Registers */ |
| 229 | {E1000_CTRL, "CTRL"}, |
| 230 | {E1000_STATUS, "STATUS"}, |
| 231 | {E1000_CTRL_EXT, "CTRL_EXT"}, |
| 232 | |
| 233 | /* Interrupt Registers */ |
| 234 | {E1000_ICR, "ICR"}, |
| 235 | |
| 236 | /* RX Registers */ |
| 237 | {E1000_RCTL, "RCTL"}, |
| 238 | {E1000_RDLEN(0), "RDLEN"}, |
| 239 | {E1000_RDH(0), "RDH"}, |
| 240 | {E1000_RDT(0), "RDT"}, |
| 241 | {E1000_RXDCTL(0), "RXDCTL"}, |
| 242 | {E1000_RDBAL(0), "RDBAL"}, |
| 243 | {E1000_RDBAH(0), "RDBAH"}, |
| 244 | |
| 245 | /* TX Registers */ |
| 246 | {E1000_TCTL, "TCTL"}, |
| 247 | {E1000_TDBAL(0), "TDBAL"}, |
| 248 | {E1000_TDBAH(0), "TDBAH"}, |
| 249 | {E1000_TDLEN(0), "TDLEN"}, |
| 250 | {E1000_TDH(0), "TDH"}, |
| 251 | {E1000_TDT(0), "TDT"}, |
| 252 | {E1000_TXDCTL(0), "TXDCTL"}, |
| 253 | {E1000_TDFH, "TDFH"}, |
| 254 | {E1000_TDFT, "TDFT"}, |
| 255 | {E1000_TDFHS, "TDFHS"}, |
| 256 | {E1000_TDFPC, "TDFPC"}, |
| 257 | |
| 258 | /* List Terminator */ |
| 259 | {} |
| 260 | }; |
| 261 | |
| 262 | /* |
| 263 | * igb_regdump - register printout routine |
| 264 | */ |
| 265 | static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo) |
| 266 | { |
| 267 | int n = 0; |
| 268 | char rname[16]; |
| 269 | u32 regs[8]; |
| 270 | |
| 271 | switch (reginfo->ofs) { |
| 272 | case E1000_RDLEN(0): |
| 273 | for (n = 0; n < 4; n++) |
| 274 | regs[n] = rd32(E1000_RDLEN(n)); |
| 275 | break; |
| 276 | case E1000_RDH(0): |
| 277 | for (n = 0; n < 4; n++) |
| 278 | regs[n] = rd32(E1000_RDH(n)); |
| 279 | break; |
| 280 | case E1000_RDT(0): |
| 281 | for (n = 0; n < 4; n++) |
| 282 | regs[n] = rd32(E1000_RDT(n)); |
| 283 | break; |
| 284 | case E1000_RXDCTL(0): |
| 285 | for (n = 0; n < 4; n++) |
| 286 | regs[n] = rd32(E1000_RXDCTL(n)); |
| 287 | break; |
| 288 | case E1000_RDBAL(0): |
| 289 | for (n = 0; n < 4; n++) |
| 290 | regs[n] = rd32(E1000_RDBAL(n)); |
| 291 | break; |
| 292 | case E1000_RDBAH(0): |
| 293 | for (n = 0; n < 4; n++) |
| 294 | regs[n] = rd32(E1000_RDBAH(n)); |
| 295 | break; |
| 296 | case E1000_TDBAL(0): |
| 297 | for (n = 0; n < 4; n++) |
| 298 | regs[n] = rd32(E1000_RDBAL(n)); |
| 299 | break; |
| 300 | case E1000_TDBAH(0): |
| 301 | for (n = 0; n < 4; n++) |
| 302 | regs[n] = rd32(E1000_TDBAH(n)); |
| 303 | break; |
| 304 | case E1000_TDLEN(0): |
| 305 | for (n = 0; n < 4; n++) |
| 306 | regs[n] = rd32(E1000_TDLEN(n)); |
| 307 | break; |
| 308 | case E1000_TDH(0): |
| 309 | for (n = 0; n < 4; n++) |
| 310 | regs[n] = rd32(E1000_TDH(n)); |
| 311 | break; |
| 312 | case E1000_TDT(0): |
| 313 | for (n = 0; n < 4; n++) |
| 314 | regs[n] = rd32(E1000_TDT(n)); |
| 315 | break; |
| 316 | case E1000_TXDCTL(0): |
| 317 | for (n = 0; n < 4; n++) |
| 318 | regs[n] = rd32(E1000_TXDCTL(n)); |
| 319 | break; |
| 320 | default: |
| 321 | printk(KERN_INFO "%-15s %08x\n", |
| 322 | reginfo->name, rd32(reginfo->ofs)); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]"); |
| 327 | printk(KERN_INFO "%-15s ", rname); |
| 328 | for (n = 0; n < 4; n++) |
| 329 | printk(KERN_CONT "%08x ", regs[n]); |
| 330 | printk(KERN_CONT "\n"); |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * igb_dump - Print registers, tx-rings and rx-rings |
| 335 | */ |
| 336 | static void igb_dump(struct igb_adapter *adapter) |
| 337 | { |
| 338 | struct net_device *netdev = adapter->netdev; |
| 339 | struct e1000_hw *hw = &adapter->hw; |
| 340 | struct igb_reg_info *reginfo; |
| 341 | int n = 0; |
| 342 | struct igb_ring *tx_ring; |
| 343 | union e1000_adv_tx_desc *tx_desc; |
| 344 | struct my_u0 { u64 a; u64 b; } *u0; |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 345 | struct igb_ring *rx_ring; |
| 346 | union e1000_adv_rx_desc *rx_desc; |
| 347 | u32 staterr; |
| 348 | int i = 0; |
| 349 | |
| 350 | if (!netif_msg_hw(adapter)) |
| 351 | return; |
| 352 | |
| 353 | /* Print netdevice Info */ |
| 354 | if (netdev) { |
| 355 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
| 356 | printk(KERN_INFO "Device Name state " |
| 357 | "trans_start last_rx\n"); |
| 358 | printk(KERN_INFO "%-15s %016lX %016lX %016lX\n", |
| 359 | netdev->name, |
| 360 | netdev->state, |
| 361 | netdev->trans_start, |
| 362 | netdev->last_rx); |
| 363 | } |
| 364 | |
| 365 | /* Print Registers */ |
| 366 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
| 367 | printk(KERN_INFO " Register Name Value\n"); |
| 368 | for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl; |
| 369 | reginfo->name; reginfo++) { |
| 370 | igb_regdump(hw, reginfo); |
| 371 | } |
| 372 | |
| 373 | /* Print TX Ring Summary */ |
| 374 | if (!netdev || !netif_running(netdev)) |
| 375 | goto exit; |
| 376 | |
| 377 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
| 378 | printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]" |
| 379 | " leng ntw timestamp\n"); |
| 380 | for (n = 0; n < adapter->num_tx_queues; n++) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 381 | struct igb_tx_buffer *buffer_info; |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 382 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 383 | buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 384 | printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n", |
| 385 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
| 386 | (u64)buffer_info->dma, |
| 387 | buffer_info->length, |
| 388 | buffer_info->next_to_watch, |
| 389 | (u64)buffer_info->time_stamp); |
| 390 | } |
| 391 | |
| 392 | /* Print TX Rings */ |
| 393 | if (!netif_msg_tx_done(adapter)) |
| 394 | goto rx_ring_summary; |
| 395 | |
| 396 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 397 | |
| 398 | /* Transmit Descriptor Formats |
| 399 | * |
| 400 | * Advanced Transmit Descriptor |
| 401 | * +--------------------------------------------------------------+ |
| 402 | * 0 | Buffer Address [63:0] | |
| 403 | * +--------------------------------------------------------------+ |
| 404 | * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN | |
| 405 | * +--------------------------------------------------------------+ |
| 406 | * 63 46 45 40 39 38 36 35 32 31 24 15 0 |
| 407 | */ |
| 408 | |
| 409 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 410 | tx_ring = adapter->tx_ring[n]; |
| 411 | printk(KERN_INFO "------------------------------------\n"); |
| 412 | printk(KERN_INFO "TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 413 | printk(KERN_INFO "------------------------------------\n"); |
| 414 | printk(KERN_INFO "T [desc] [address 63:0 ] " |
| 415 | "[PlPOCIStDDM Ln] [bi->dma ] " |
| 416 | "leng ntw timestamp bi->skb\n"); |
| 417 | |
| 418 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 419 | struct igb_tx_buffer *buffer_info; |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 420 | tx_desc = IGB_TX_DESC(tx_ring, i); |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 421 | buffer_info = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 422 | u0 = (struct my_u0 *)tx_desc; |
| 423 | printk(KERN_INFO "T [0x%03X] %016llX %016llX %016llX" |
| 424 | " %04X %3X %016llX %p", i, |
| 425 | le64_to_cpu(u0->a), |
| 426 | le64_to_cpu(u0->b), |
| 427 | (u64)buffer_info->dma, |
| 428 | buffer_info->length, |
| 429 | buffer_info->next_to_watch, |
| 430 | (u64)buffer_info->time_stamp, |
| 431 | buffer_info->skb); |
| 432 | if (i == tx_ring->next_to_use && |
| 433 | i == tx_ring->next_to_clean) |
| 434 | printk(KERN_CONT " NTC/U\n"); |
| 435 | else if (i == tx_ring->next_to_use) |
| 436 | printk(KERN_CONT " NTU\n"); |
| 437 | else if (i == tx_ring->next_to_clean) |
| 438 | printk(KERN_CONT " NTC\n"); |
| 439 | else |
| 440 | printk(KERN_CONT "\n"); |
| 441 | |
| 442 | if (netif_msg_pktdata(adapter) && buffer_info->dma != 0) |
| 443 | print_hex_dump(KERN_INFO, "", |
| 444 | DUMP_PREFIX_ADDRESS, |
| 445 | 16, 1, phys_to_virt(buffer_info->dma), |
| 446 | buffer_info->length, true); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /* Print RX Rings Summary */ |
| 451 | rx_ring_summary: |
| 452 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
| 453 | printk(KERN_INFO "Queue [NTU] [NTC]\n"); |
| 454 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 455 | rx_ring = adapter->rx_ring[n]; |
| 456 | printk(KERN_INFO " %5d %5X %5X\n", n, |
| 457 | rx_ring->next_to_use, rx_ring->next_to_clean); |
| 458 | } |
| 459 | |
| 460 | /* Print RX Rings */ |
| 461 | if (!netif_msg_rx_status(adapter)) |
| 462 | goto exit; |
| 463 | |
| 464 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 465 | |
| 466 | /* Advanced Receive Descriptor (Read) Format |
| 467 | * 63 1 0 |
| 468 | * +-----------------------------------------------------+ |
| 469 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 470 | * +----------------------------------------------+------+ |
| 471 | * 8 | Header Buffer Address [63:1] | DD | |
| 472 | * +-----------------------------------------------------+ |
| 473 | * |
| 474 | * |
| 475 | * Advanced Receive Descriptor (Write-Back) Format |
| 476 | * |
| 477 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 478 | * +------------------------------------------------------+ |
| 479 | * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS | |
| 480 | * | Checksum Ident | | | | Type | Type | |
| 481 | * +------------------------------------------------------+ |
| 482 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 483 | * +------------------------------------------------------+ |
| 484 | * 63 48 47 32 31 20 19 0 |
| 485 | */ |
| 486 | |
| 487 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 488 | rx_ring = adapter->rx_ring[n]; |
| 489 | printk(KERN_INFO "------------------------------------\n"); |
| 490 | printk(KERN_INFO "RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 491 | printk(KERN_INFO "------------------------------------\n"); |
| 492 | printk(KERN_INFO "R [desc] [ PktBuf A0] " |
| 493 | "[ HeadBuf DD] [bi->dma ] [bi->skb] " |
| 494 | "<-- Adv Rx Read format\n"); |
| 495 | printk(KERN_INFO "RWB[desc] [PcsmIpSHl PtRs] " |
| 496 | "[vl er S cks ln] ---------------- [bi->skb] " |
| 497 | "<-- Adv Rx Write-Back format\n"); |
| 498 | |
| 499 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 500 | struct igb_rx_buffer *buffer_info; |
| 501 | buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 502 | rx_desc = IGB_RX_DESC(rx_ring, i); |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 503 | u0 = (struct my_u0 *)rx_desc; |
| 504 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 505 | if (staterr & E1000_RXD_STAT_DD) { |
| 506 | /* Descriptor Done */ |
| 507 | printk(KERN_INFO "RWB[0x%03X] %016llX " |
| 508 | "%016llX ---------------- %p", i, |
| 509 | le64_to_cpu(u0->a), |
| 510 | le64_to_cpu(u0->b), |
| 511 | buffer_info->skb); |
| 512 | } else { |
| 513 | printk(KERN_INFO "R [0x%03X] %016llX " |
| 514 | "%016llX %016llX %p", i, |
| 515 | le64_to_cpu(u0->a), |
| 516 | le64_to_cpu(u0->b), |
| 517 | (u64)buffer_info->dma, |
| 518 | buffer_info->skb); |
| 519 | |
| 520 | if (netif_msg_pktdata(adapter)) { |
| 521 | print_hex_dump(KERN_INFO, "", |
| 522 | DUMP_PREFIX_ADDRESS, |
| 523 | 16, 1, |
| 524 | phys_to_virt(buffer_info->dma), |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 525 | IGB_RX_HDR_LEN, true); |
| 526 | print_hex_dump(KERN_INFO, "", |
| 527 | DUMP_PREFIX_ADDRESS, |
| 528 | 16, 1, |
| 529 | phys_to_virt( |
| 530 | buffer_info->page_dma + |
| 531 | buffer_info->page_offset), |
| 532 | PAGE_SIZE/2, true); |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | if (i == rx_ring->next_to_use) |
| 537 | printk(KERN_CONT " NTU\n"); |
| 538 | else if (i == rx_ring->next_to_clean) |
| 539 | printk(KERN_CONT " NTC\n"); |
| 540 | else |
| 541 | printk(KERN_CONT "\n"); |
| 542 | |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | exit: |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 551 | /** |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 552 | * igb_read_clock - read raw cycle counter (to be used by time counter) |
| 553 | */ |
| 554 | static cycle_t igb_read_clock(const struct cyclecounter *tc) |
| 555 | { |
| 556 | struct igb_adapter *adapter = |
| 557 | container_of(tc, struct igb_adapter, cycles); |
| 558 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 559 | u64 stamp = 0; |
| 560 | int shift = 0; |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 561 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 562 | /* |
| 563 | * The timestamp latches on lowest register read. For the 82580 |
| 564 | * the lowest register is SYSTIMR instead of SYSTIML. However we never |
| 565 | * adjusted TIMINCA so SYSTIMR will just read as all 0s so ignore it. |
| 566 | */ |
| 567 | if (hw->mac.type == e1000_82580) { |
| 568 | stamp = rd32(E1000_SYSTIMR) >> 8; |
| 569 | shift = IGB_82580_TSYNC_SHIFT; |
| 570 | } |
| 571 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 572 | stamp |= (u64)rd32(E1000_SYSTIML) << shift; |
| 573 | stamp |= (u64)rd32(E1000_SYSTIMH) << (shift + 32); |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 574 | return stamp; |
| 575 | } |
| 576 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 577 | /** |
Alexander Duyck | c041076 | 2010-03-25 13:10:08 +0000 | [diff] [blame] | 578 | * igb_get_hw_dev - return device |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 579 | * used by hardware layer to print debugging information |
| 580 | **/ |
Alexander Duyck | c041076 | 2010-03-25 13:10:08 +0000 | [diff] [blame] | 581 | struct net_device *igb_get_hw_dev(struct e1000_hw *hw) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 582 | { |
| 583 | struct igb_adapter *adapter = hw->back; |
Alexander Duyck | c041076 | 2010-03-25 13:10:08 +0000 | [diff] [blame] | 584 | return adapter->netdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 585 | } |
Patrick Ohly | 38c845c | 2009-02-12 05:03:41 +0000 | [diff] [blame] | 586 | |
| 587 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 588 | * igb_init_module - Driver Registration Routine |
| 589 | * |
| 590 | * igb_init_module is the first routine called when the driver is |
| 591 | * loaded. All it does is register with the PCI subsystem. |
| 592 | **/ |
| 593 | static int __init igb_init_module(void) |
| 594 | { |
| 595 | int ret; |
| 596 | printk(KERN_INFO "%s - version %s\n", |
| 597 | igb_driver_string, igb_driver_version); |
| 598 | |
| 599 | printk(KERN_INFO "%s\n", igb_copyright); |
| 600 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 601 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 602 | dca_register_notify(&dca_notifier); |
| 603 | #endif |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 604 | ret = pci_register_driver(&igb_driver); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 605 | return ret; |
| 606 | } |
| 607 | |
| 608 | module_init(igb_init_module); |
| 609 | |
| 610 | /** |
| 611 | * igb_exit_module - Driver Exit Cleanup Routine |
| 612 | * |
| 613 | * igb_exit_module is called just before the driver is removed |
| 614 | * from memory. |
| 615 | **/ |
| 616 | static void __exit igb_exit_module(void) |
| 617 | { |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 618 | #ifdef CONFIG_IGB_DCA |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 619 | dca_unregister_notify(&dca_notifier); |
| 620 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 621 | pci_unregister_driver(&igb_driver); |
| 622 | } |
| 623 | |
| 624 | module_exit(igb_exit_module); |
| 625 | |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 626 | #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1)) |
| 627 | /** |
| 628 | * igb_cache_ring_register - Descriptor ring to register mapping |
| 629 | * @adapter: board private structure to initialize |
| 630 | * |
| 631 | * Once we know the feature-set enabled for the device, we'll cache |
| 632 | * the register offset the descriptor ring is assigned to. |
| 633 | **/ |
| 634 | static void igb_cache_ring_register(struct igb_adapter *adapter) |
| 635 | { |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 636 | int i = 0, j = 0; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 637 | u32 rbase_offset = adapter->vfs_allocated_count; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 638 | |
| 639 | switch (adapter->hw.mac.type) { |
| 640 | case e1000_82576: |
| 641 | /* The queues are allocated for virtualization such that VF 0 |
| 642 | * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc. |
| 643 | * In order to avoid collision we start at the first free queue |
| 644 | * and continue consuming queues in the same sequence |
| 645 | */ |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 646 | if (adapter->vfs_allocated_count) { |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 647 | for (; i < adapter->rss_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 648 | adapter->rx_ring[i]->reg_idx = rbase_offset + |
| 649 | Q_IDX_82576(i); |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 650 | } |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 651 | case e1000_82575: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 652 | case e1000_82580: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 653 | case e1000_i350: |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 654 | default: |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 655 | for (; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 656 | adapter->rx_ring[i]->reg_idx = rbase_offset + i; |
Alexander Duyck | ee1b9f0 | 2009-10-27 23:49:40 +0000 | [diff] [blame] | 657 | for (; j < adapter->num_tx_queues; j++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 658 | adapter->tx_ring[j]->reg_idx = rbase_offset + j; |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | } |
| 662 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 663 | static void igb_free_queues(struct igb_adapter *adapter) |
| 664 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 665 | int i; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 666 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 667 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 668 | kfree(adapter->tx_ring[i]); |
| 669 | adapter->tx_ring[i] = NULL; |
| 670 | } |
| 671 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 672 | kfree(adapter->rx_ring[i]); |
| 673 | adapter->rx_ring[i] = NULL; |
| 674 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 675 | adapter->num_rx_queues = 0; |
| 676 | adapter->num_tx_queues = 0; |
| 677 | } |
| 678 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 679 | /** |
| 680 | * igb_alloc_queues - Allocate memory for all rings |
| 681 | * @adapter: board private structure to initialize |
| 682 | * |
| 683 | * We allocate one ring per queue at run-time since we don't know the |
| 684 | * number of queues at compile-time. |
| 685 | **/ |
| 686 | static int igb_alloc_queues(struct igb_adapter *adapter) |
| 687 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 688 | struct igb_ring *ring; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 689 | int i; |
| 690 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 691 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 692 | ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL); |
| 693 | if (!ring) |
| 694 | goto err; |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 695 | ring->count = adapter->tx_ring_count; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 696 | ring->queue_index = i; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 697 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 698 | ring->netdev = adapter->netdev; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 699 | /* For 82575, context index must be unique per ring. */ |
| 700 | if (adapter->hw.mac.type == e1000_82575) |
| 701 | ring->flags = IGB_RING_FLAG_TX_CTX_IDX; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 702 | adapter->tx_ring[i] = ring; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 703 | } |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 704 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 705 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 706 | ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL); |
| 707 | if (!ring) |
| 708 | goto err; |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 709 | ring->count = adapter->rx_ring_count; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 710 | ring->queue_index = i; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 711 | ring->dev = &adapter->pdev->dev; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 712 | ring->netdev = adapter->netdev; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 713 | ring->flags = IGB_RING_FLAG_RX_CSUM; /* enable rx checksum */ |
| 714 | /* set flag indicating ring supports SCTP checksum offload */ |
| 715 | if (adapter->hw.mac.type >= e1000_82576) |
| 716 | ring->flags |= IGB_RING_FLAG_RX_SCTP_CSUM; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 717 | adapter->rx_ring[i] = ring; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 718 | } |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 719 | |
| 720 | igb_cache_ring_register(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 721 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 722 | return 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 723 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 724 | err: |
| 725 | igb_free_queues(adapter); |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 726 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 727 | return -ENOMEM; |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 730 | #define IGB_N0_QUEUE -1 |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 731 | static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 732 | { |
| 733 | u32 msixbm = 0; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 734 | struct igb_adapter *adapter = q_vector->adapter; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 735 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 736 | u32 ivar, index; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 737 | int rx_queue = IGB_N0_QUEUE; |
| 738 | int tx_queue = IGB_N0_QUEUE; |
| 739 | |
| 740 | if (q_vector->rx_ring) |
| 741 | rx_queue = q_vector->rx_ring->reg_idx; |
| 742 | if (q_vector->tx_ring) |
| 743 | tx_queue = q_vector->tx_ring->reg_idx; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 744 | |
| 745 | switch (hw->mac.type) { |
| 746 | case e1000_82575: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 747 | /* The 82575 assigns vectors using a bitmask, which matches the |
| 748 | bitmask for the EICR/EIMS/EIMC registers. To assign one |
| 749 | or more queues to a vector, we write the appropriate bits |
| 750 | into the MSIXBM register for that vector. */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 751 | if (rx_queue > IGB_N0_QUEUE) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 752 | msixbm = E1000_EICR_RX_QUEUE0 << rx_queue; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 753 | if (tx_queue > IGB_N0_QUEUE) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 754 | msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue; |
Alexander Duyck | feeb272 | 2010-02-03 21:59:51 +0000 | [diff] [blame] | 755 | if (!adapter->msix_entries && msix_vector == 0) |
| 756 | msixbm |= E1000_EIMS_OTHER; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 757 | array_wr32(E1000_MSIXBM(0), msix_vector, msixbm); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 758 | q_vector->eims_value = msixbm; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 759 | break; |
| 760 | case e1000_82576: |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 761 | /* 82576 uses a table-based method for assigning vectors. |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 762 | Each queue has a single entry in the table to which we write |
| 763 | a vector number along with a "valid" bit. Sadly, the layout |
| 764 | of the table is somewhat counterintuitive. */ |
| 765 | if (rx_queue > IGB_N0_QUEUE) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 766 | index = (rx_queue & 0x7); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 767 | ivar = array_rd32(E1000_IVAR0, index); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 768 | if (rx_queue < 8) { |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 769 | /* vector goes into low byte of register */ |
| 770 | ivar = ivar & 0xFFFFFF00; |
| 771 | ivar |= msix_vector | E1000_IVAR_VALID; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 772 | } else { |
| 773 | /* vector goes into third byte of register */ |
| 774 | ivar = ivar & 0xFF00FFFF; |
| 775 | ivar |= (msix_vector | E1000_IVAR_VALID) << 16; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 776 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 777 | array_wr32(E1000_IVAR0, index, ivar); |
| 778 | } |
| 779 | if (tx_queue > IGB_N0_QUEUE) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 780 | index = (tx_queue & 0x7); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 781 | ivar = array_rd32(E1000_IVAR0, index); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 782 | if (tx_queue < 8) { |
Alexander Duyck | 26bc19e | 2008-12-26 01:34:11 -0800 | [diff] [blame] | 783 | /* vector goes into second byte of register */ |
| 784 | ivar = ivar & 0xFFFF00FF; |
| 785 | ivar |= (msix_vector | E1000_IVAR_VALID) << 8; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 786 | } else { |
| 787 | /* vector goes into high byte of register */ |
| 788 | ivar = ivar & 0x00FFFFFF; |
| 789 | ivar |= (msix_vector | E1000_IVAR_VALID) << 24; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 790 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 791 | array_wr32(E1000_IVAR0, index, ivar); |
| 792 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 793 | q_vector->eims_value = 1 << msix_vector; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 794 | break; |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 795 | case e1000_82580: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 796 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 797 | /* 82580 uses the same table-based approach as 82576 but has fewer |
| 798 | entries as a result we carry over for queues greater than 4. */ |
| 799 | if (rx_queue > IGB_N0_QUEUE) { |
| 800 | index = (rx_queue >> 1); |
| 801 | ivar = array_rd32(E1000_IVAR0, index); |
| 802 | if (rx_queue & 0x1) { |
| 803 | /* vector goes into third byte of register */ |
| 804 | ivar = ivar & 0xFF00FFFF; |
| 805 | ivar |= (msix_vector | E1000_IVAR_VALID) << 16; |
| 806 | } else { |
| 807 | /* vector goes into low byte of register */ |
| 808 | ivar = ivar & 0xFFFFFF00; |
| 809 | ivar |= msix_vector | E1000_IVAR_VALID; |
| 810 | } |
| 811 | array_wr32(E1000_IVAR0, index, ivar); |
| 812 | } |
| 813 | if (tx_queue > IGB_N0_QUEUE) { |
| 814 | index = (tx_queue >> 1); |
| 815 | ivar = array_rd32(E1000_IVAR0, index); |
| 816 | if (tx_queue & 0x1) { |
| 817 | /* vector goes into high byte of register */ |
| 818 | ivar = ivar & 0x00FFFFFF; |
| 819 | ivar |= (msix_vector | E1000_IVAR_VALID) << 24; |
| 820 | } else { |
| 821 | /* vector goes into second byte of register */ |
| 822 | ivar = ivar & 0xFFFF00FF; |
| 823 | ivar |= (msix_vector | E1000_IVAR_VALID) << 8; |
| 824 | } |
| 825 | array_wr32(E1000_IVAR0, index, ivar); |
| 826 | } |
| 827 | q_vector->eims_value = 1 << msix_vector; |
| 828 | break; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 829 | default: |
| 830 | BUG(); |
| 831 | break; |
| 832 | } |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 833 | |
| 834 | /* add q_vector eims value to global eims_enable_mask */ |
| 835 | adapter->eims_enable_mask |= q_vector->eims_value; |
| 836 | |
| 837 | /* configure q_vector to set itr on first interrupt */ |
| 838 | q_vector->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | /** |
| 842 | * igb_configure_msix - Configure MSI-X hardware |
| 843 | * |
| 844 | * igb_configure_msix sets up the hardware to properly |
| 845 | * generate MSI-X interrupts. |
| 846 | **/ |
| 847 | static void igb_configure_msix(struct igb_adapter *adapter) |
| 848 | { |
| 849 | u32 tmp; |
| 850 | int i, vector = 0; |
| 851 | struct e1000_hw *hw = &adapter->hw; |
| 852 | |
| 853 | adapter->eims_enable_mask = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 854 | |
| 855 | /* set vector for other causes, i.e. link changes */ |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 856 | switch (hw->mac.type) { |
| 857 | case e1000_82575: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 858 | tmp = rd32(E1000_CTRL_EXT); |
| 859 | /* enable MSI-X PBA support*/ |
| 860 | tmp |= E1000_CTRL_EXT_PBA_CLR; |
| 861 | |
| 862 | /* Auto-Mask interrupts upon ICR read. */ |
| 863 | tmp |= E1000_CTRL_EXT_EIAME; |
| 864 | tmp |= E1000_CTRL_EXT_IRCA; |
| 865 | |
| 866 | wr32(E1000_CTRL_EXT, tmp); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 867 | |
| 868 | /* enable msix_other interrupt */ |
| 869 | array_wr32(E1000_MSIXBM(0), vector++, |
| 870 | E1000_EIMS_OTHER); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 871 | adapter->eims_other = E1000_EIMS_OTHER; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 872 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 873 | break; |
| 874 | |
| 875 | case e1000_82576: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 876 | case e1000_82580: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 877 | case e1000_i350: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 878 | /* Turn on MSI-X capability first, or our settings |
| 879 | * won't stick. And it will take days to debug. */ |
| 880 | wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE | |
| 881 | E1000_GPIE_PBA | E1000_GPIE_EIAME | |
| 882 | E1000_GPIE_NSICR); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 883 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 884 | /* enable msix_other interrupt */ |
| 885 | adapter->eims_other = 1 << vector; |
| 886 | tmp = (vector++ | E1000_IVAR_VALID) << 8; |
| 887 | |
| 888 | wr32(E1000_IVAR_MISC, tmp); |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 889 | break; |
| 890 | default: |
| 891 | /* do nothing, since nothing else supports MSI-X */ |
| 892 | break; |
| 893 | } /* switch (hw->mac.type) */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 894 | |
| 895 | adapter->eims_enable_mask |= adapter->eims_other; |
| 896 | |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 897 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 898 | igb_assign_vector(adapter->q_vector[i], vector++); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 899 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 900 | wrfl(); |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * igb_request_msix - Initialize MSI-X interrupts |
| 905 | * |
| 906 | * igb_request_msix allocates MSI-X vectors and requests interrupts from the |
| 907 | * kernel. |
| 908 | **/ |
| 909 | static int igb_request_msix(struct igb_adapter *adapter) |
| 910 | { |
| 911 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 912 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 913 | int i, err = 0, vector = 0; |
| 914 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 915 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 916 | igb_msix_other, 0, netdev->name, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 917 | if (err) |
| 918 | goto out; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 919 | vector++; |
| 920 | |
| 921 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 922 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 923 | |
| 924 | q_vector->itr_register = hw->hw_addr + E1000_EITR(vector); |
| 925 | |
| 926 | if (q_vector->rx_ring && q_vector->tx_ring) |
| 927 | sprintf(q_vector->name, "%s-TxRx-%u", netdev->name, |
| 928 | q_vector->rx_ring->queue_index); |
| 929 | else if (q_vector->tx_ring) |
| 930 | sprintf(q_vector->name, "%s-tx-%u", netdev->name, |
| 931 | q_vector->tx_ring->queue_index); |
| 932 | else if (q_vector->rx_ring) |
| 933 | sprintf(q_vector->name, "%s-rx-%u", netdev->name, |
| 934 | q_vector->rx_ring->queue_index); |
| 935 | else |
| 936 | sprintf(q_vector->name, "%s-unused", netdev->name); |
| 937 | |
| 938 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 939 | igb_msix_ring, 0, q_vector->name, |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 940 | q_vector); |
| 941 | if (err) |
| 942 | goto out; |
| 943 | vector++; |
| 944 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 945 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 946 | igb_configure_msix(adapter); |
| 947 | return 0; |
| 948 | out: |
| 949 | return err; |
| 950 | } |
| 951 | |
| 952 | static void igb_reset_interrupt_capability(struct igb_adapter *adapter) |
| 953 | { |
| 954 | if (adapter->msix_entries) { |
| 955 | pci_disable_msix(adapter->pdev); |
| 956 | kfree(adapter->msix_entries); |
| 957 | adapter->msix_entries = NULL; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 958 | } else if (adapter->flags & IGB_FLAG_HAS_MSI) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 959 | pci_disable_msi(adapter->pdev); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 960 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 963 | /** |
| 964 | * igb_free_q_vectors - Free memory allocated for interrupt vectors |
| 965 | * @adapter: board private structure to initialize |
| 966 | * |
| 967 | * This function frees the memory allocated to the q_vectors. In addition if |
| 968 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 969 | * to freeing the q_vector. |
| 970 | **/ |
| 971 | static void igb_free_q_vectors(struct igb_adapter *adapter) |
| 972 | { |
| 973 | int v_idx; |
| 974 | |
| 975 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
| 976 | struct igb_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 977 | adapter->q_vector[v_idx] = NULL; |
Nick Nunley | fe0592b | 2010-02-17 01:05:35 +0000 | [diff] [blame] | 978 | if (!q_vector) |
| 979 | continue; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 980 | netif_napi_del(&q_vector->napi); |
| 981 | kfree(q_vector); |
| 982 | } |
| 983 | adapter->num_q_vectors = 0; |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * igb_clear_interrupt_scheme - reset the device to a state of no interrupts |
| 988 | * |
| 989 | * This function resets the device so that it has 0 rx queues, tx queues, and |
| 990 | * MSI-X interrupts allocated. |
| 991 | */ |
| 992 | static void igb_clear_interrupt_scheme(struct igb_adapter *adapter) |
| 993 | { |
| 994 | igb_free_queues(adapter); |
| 995 | igb_free_q_vectors(adapter); |
| 996 | igb_reset_interrupt_capability(adapter); |
| 997 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 998 | |
| 999 | /** |
| 1000 | * igb_set_interrupt_capability - set MSI or MSI-X if supported |
| 1001 | * |
| 1002 | * Attempt to configure interrupts using the best available |
| 1003 | * capabilities of the hardware and kernel. |
| 1004 | **/ |
Ben Hutchings | 21adef3 | 2010-09-27 08:28:39 +0000 | [diff] [blame] | 1005 | static int igb_set_interrupt_capability(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1006 | { |
| 1007 | int err; |
| 1008 | int numvecs, i; |
| 1009 | |
Alexander Duyck | 83b7180 | 2009-02-06 23:15:45 +0000 | [diff] [blame] | 1010 | /* Number of supported queues. */ |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 1011 | adapter->num_rx_queues = adapter->rss_queues; |
Greg Rose | 5fa8517 | 2010-07-01 13:38:16 +0000 | [diff] [blame] | 1012 | if (adapter->vfs_allocated_count) |
| 1013 | adapter->num_tx_queues = 1; |
| 1014 | else |
| 1015 | adapter->num_tx_queues = adapter->rss_queues; |
Alexander Duyck | 83b7180 | 2009-02-06 23:15:45 +0000 | [diff] [blame] | 1016 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1017 | /* start with one vector for every rx queue */ |
| 1018 | numvecs = adapter->num_rx_queues; |
| 1019 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 1020 | /* if tx handler is separate add 1 for every tx queue */ |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 1021 | if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS)) |
| 1022 | numvecs += adapter->num_tx_queues; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1023 | |
| 1024 | /* store the number of vectors reserved for queues */ |
| 1025 | adapter->num_q_vectors = numvecs; |
| 1026 | |
| 1027 | /* add 1 vector for link status interrupts */ |
| 1028 | numvecs++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1029 | adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry), |
| 1030 | GFP_KERNEL); |
| 1031 | if (!adapter->msix_entries) |
| 1032 | goto msi_only; |
| 1033 | |
| 1034 | for (i = 0; i < numvecs; i++) |
| 1035 | adapter->msix_entries[i].entry = i; |
| 1036 | |
| 1037 | err = pci_enable_msix(adapter->pdev, |
| 1038 | adapter->msix_entries, |
| 1039 | numvecs); |
| 1040 | if (err == 0) |
Alexander Duyck | 34a20e8 | 2008-08-26 04:25:13 -0700 | [diff] [blame] | 1041 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1042 | |
| 1043 | igb_reset_interrupt_capability(adapter); |
| 1044 | |
| 1045 | /* If we can't do MSI-X, try MSI */ |
| 1046 | msi_only: |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1047 | #ifdef CONFIG_PCI_IOV |
| 1048 | /* disable SR-IOV for non MSI-X configurations */ |
| 1049 | if (adapter->vf_data) { |
| 1050 | struct e1000_hw *hw = &adapter->hw; |
| 1051 | /* disable iov and allow time for transactions to clear */ |
| 1052 | pci_disable_sriov(adapter->pdev); |
| 1053 | msleep(500); |
| 1054 | |
| 1055 | kfree(adapter->vf_data); |
| 1056 | adapter->vf_data = NULL; |
| 1057 | wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1058 | wrfl(); |
Alexander Duyck | 2a3abf6 | 2009-04-07 14:37:52 +0000 | [diff] [blame] | 1059 | msleep(100); |
| 1060 | dev_info(&adapter->pdev->dev, "IOV Disabled\n"); |
| 1061 | } |
| 1062 | #endif |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1063 | adapter->vfs_allocated_count = 0; |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 1064 | adapter->rss_queues = 1; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1065 | adapter->flags |= IGB_FLAG_QUEUE_PAIRS; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1066 | adapter->num_rx_queues = 1; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 1067 | adapter->num_tx_queues = 1; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1068 | adapter->num_q_vectors = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1069 | if (!pci_enable_msi(adapter->pdev)) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1070 | adapter->flags |= IGB_FLAG_HAS_MSI; |
Alexander Duyck | 34a20e8 | 2008-08-26 04:25:13 -0700 | [diff] [blame] | 1071 | out: |
Ben Hutchings | 21adef3 | 2010-09-27 08:28:39 +0000 | [diff] [blame] | 1072 | /* Notify the stack of the (possibly) reduced queue counts. */ |
| 1073 | netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues); |
| 1074 | return netif_set_real_num_rx_queues(adapter->netdev, |
| 1075 | adapter->num_rx_queues); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | /** |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1079 | * igb_alloc_q_vectors - Allocate memory for interrupt vectors |
| 1080 | * @adapter: board private structure to initialize |
| 1081 | * |
| 1082 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 1083 | * return -ENOMEM. |
| 1084 | **/ |
| 1085 | static int igb_alloc_q_vectors(struct igb_adapter *adapter) |
| 1086 | { |
| 1087 | struct igb_q_vector *q_vector; |
| 1088 | struct e1000_hw *hw = &adapter->hw; |
| 1089 | int v_idx; |
| 1090 | |
| 1091 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
| 1092 | q_vector = kzalloc(sizeof(struct igb_q_vector), GFP_KERNEL); |
| 1093 | if (!q_vector) |
| 1094 | goto err_out; |
| 1095 | q_vector->adapter = adapter; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1096 | q_vector->itr_register = hw->hw_addr + E1000_EITR(0); |
| 1097 | q_vector->itr_val = IGB_START_ITR; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1098 | netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64); |
| 1099 | adapter->q_vector[v_idx] = q_vector; |
| 1100 | } |
| 1101 | return 0; |
| 1102 | |
| 1103 | err_out: |
Nick Nunley | fe0592b | 2010-02-17 01:05:35 +0000 | [diff] [blame] | 1104 | igb_free_q_vectors(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1105 | return -ENOMEM; |
| 1106 | } |
| 1107 | |
| 1108 | static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter, |
| 1109 | int ring_idx, int v_idx) |
| 1110 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1111 | struct igb_q_vector *q_vector = adapter->q_vector[v_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1112 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1113 | q_vector->rx_ring = adapter->rx_ring[ring_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1114 | q_vector->rx_ring->q_vector = q_vector; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1115 | q_vector->itr_val = adapter->rx_itr_setting; |
| 1116 | if (q_vector->itr_val && q_vector->itr_val <= 3) |
| 1117 | q_vector->itr_val = IGB_START_ITR; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter, |
| 1121 | int ring_idx, int v_idx) |
| 1122 | { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1123 | struct igb_q_vector *q_vector = adapter->q_vector[v_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1124 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1125 | q_vector->tx_ring = adapter->tx_ring[ring_idx]; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1126 | q_vector->tx_ring->q_vector = q_vector; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1127 | q_vector->itr_val = adapter->tx_itr_setting; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 1128 | q_vector->tx_work_limit = adapter->tx_work_limit; |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 1129 | if (q_vector->itr_val && q_vector->itr_val <= 3) |
| 1130 | q_vector->itr_val = IGB_START_ITR; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * igb_map_ring_to_vector - maps allocated queues to vectors |
| 1135 | * |
| 1136 | * This function maps the recently allocated queues to vectors. |
| 1137 | **/ |
| 1138 | static int igb_map_ring_to_vector(struct igb_adapter *adapter) |
| 1139 | { |
| 1140 | int i; |
| 1141 | int v_idx = 0; |
| 1142 | |
| 1143 | if ((adapter->num_q_vectors < adapter->num_rx_queues) || |
| 1144 | (adapter->num_q_vectors < adapter->num_tx_queues)) |
| 1145 | return -ENOMEM; |
| 1146 | |
| 1147 | if (adapter->num_q_vectors >= |
| 1148 | (adapter->num_rx_queues + adapter->num_tx_queues)) { |
| 1149 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1150 | igb_map_rx_ring_to_vector(adapter, i, v_idx++); |
| 1151 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 1152 | igb_map_tx_ring_to_vector(adapter, i, v_idx++); |
| 1153 | } else { |
| 1154 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1155 | if (i < adapter->num_tx_queues) |
| 1156 | igb_map_tx_ring_to_vector(adapter, i, v_idx); |
| 1157 | igb_map_rx_ring_to_vector(adapter, i, v_idx++); |
| 1158 | } |
| 1159 | for (; i < adapter->num_tx_queues; i++) |
| 1160 | igb_map_tx_ring_to_vector(adapter, i, v_idx++); |
| 1161 | } |
| 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors |
| 1167 | * |
| 1168 | * This function initializes the interrupts and allocates all of the queues. |
| 1169 | **/ |
| 1170 | static int igb_init_interrupt_scheme(struct igb_adapter *adapter) |
| 1171 | { |
| 1172 | struct pci_dev *pdev = adapter->pdev; |
| 1173 | int err; |
| 1174 | |
Ben Hutchings | 21adef3 | 2010-09-27 08:28:39 +0000 | [diff] [blame] | 1175 | err = igb_set_interrupt_capability(adapter); |
| 1176 | if (err) |
| 1177 | return err; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1178 | |
| 1179 | err = igb_alloc_q_vectors(adapter); |
| 1180 | if (err) { |
| 1181 | dev_err(&pdev->dev, "Unable to allocate memory for vectors\n"); |
| 1182 | goto err_alloc_q_vectors; |
| 1183 | } |
| 1184 | |
| 1185 | err = igb_alloc_queues(adapter); |
| 1186 | if (err) { |
| 1187 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 1188 | goto err_alloc_queues; |
| 1189 | } |
| 1190 | |
| 1191 | err = igb_map_ring_to_vector(adapter); |
| 1192 | if (err) { |
| 1193 | dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n"); |
| 1194 | goto err_map_queues; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | return 0; |
| 1199 | err_map_queues: |
| 1200 | igb_free_queues(adapter); |
| 1201 | err_alloc_queues: |
| 1202 | igb_free_q_vectors(adapter); |
| 1203 | err_alloc_q_vectors: |
| 1204 | igb_reset_interrupt_capability(adapter); |
| 1205 | return err; |
| 1206 | } |
| 1207 | |
| 1208 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1209 | * igb_request_irq - initialize interrupts |
| 1210 | * |
| 1211 | * Attempts to configure interrupts using the best available |
| 1212 | * capabilities of the hardware and kernel. |
| 1213 | **/ |
| 1214 | static int igb_request_irq(struct igb_adapter *adapter) |
| 1215 | { |
| 1216 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1217 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1218 | int err = 0; |
| 1219 | |
| 1220 | if (adapter->msix_entries) { |
| 1221 | err = igb_request_msix(adapter); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1222 | if (!err) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1223 | goto request_done; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1224 | /* fall back to MSI */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1225 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1226 | if (!pci_enable_msi(adapter->pdev)) |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1227 | adapter->flags |= IGB_FLAG_HAS_MSI; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1228 | igb_free_all_tx_resources(adapter); |
| 1229 | igb_free_all_rx_resources(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1230 | adapter->num_tx_queues = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1231 | adapter->num_rx_queues = 1; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1232 | adapter->num_q_vectors = 1; |
| 1233 | err = igb_alloc_q_vectors(adapter); |
| 1234 | if (err) { |
| 1235 | dev_err(&pdev->dev, |
| 1236 | "Unable to allocate memory for vectors\n"); |
| 1237 | goto request_done; |
| 1238 | } |
| 1239 | err = igb_alloc_queues(adapter); |
| 1240 | if (err) { |
| 1241 | dev_err(&pdev->dev, |
| 1242 | "Unable to allocate memory for queues\n"); |
| 1243 | igb_free_q_vectors(adapter); |
| 1244 | goto request_done; |
| 1245 | } |
| 1246 | igb_setup_all_tx_resources(adapter); |
| 1247 | igb_setup_all_rx_resources(adapter); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1248 | } else { |
Alexander Duyck | feeb272 | 2010-02-03 21:59:51 +0000 | [diff] [blame] | 1249 | igb_assign_vector(adapter->q_vector[0], 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1250 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1251 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1252 | if (adapter->flags & IGB_FLAG_HAS_MSI) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1253 | err = request_irq(adapter->pdev->irq, igb_intr_msi, 0, |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1254 | netdev->name, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1255 | if (!err) |
| 1256 | goto request_done; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1257 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1258 | /* fall back to legacy interrupts */ |
| 1259 | igb_reset_interrupt_capability(adapter); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 1260 | adapter->flags &= ~IGB_FLAG_HAS_MSI; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1261 | } |
| 1262 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1263 | err = request_irq(adapter->pdev->irq, igb_intr, IRQF_SHARED, |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1264 | netdev->name, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1265 | |
Andy Gospodarek | 6cb5e57 | 2008-02-15 14:05:25 -0800 | [diff] [blame] | 1266 | if (err) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1267 | dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n", |
| 1268 | err); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1269 | |
| 1270 | request_done: |
| 1271 | return err; |
| 1272 | } |
| 1273 | |
| 1274 | static void igb_free_irq(struct igb_adapter *adapter) |
| 1275 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1276 | if (adapter->msix_entries) { |
| 1277 | int vector = 0, i; |
| 1278 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1279 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1280 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1281 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 1282 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 1283 | free_irq(adapter->msix_entries[vector++].vector, |
| 1284 | q_vector); |
| 1285 | } |
| 1286 | } else { |
| 1287 | free_irq(adapter->pdev->irq, adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1288 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * igb_irq_disable - Mask off interrupt generation on the NIC |
| 1293 | * @adapter: board private structure |
| 1294 | **/ |
| 1295 | static void igb_irq_disable(struct igb_adapter *adapter) |
| 1296 | { |
| 1297 | struct e1000_hw *hw = &adapter->hw; |
| 1298 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1299 | /* |
| 1300 | * we need to be careful when disabling interrupts. The VFs are also |
| 1301 | * mapped into these registers and so clearing the bits can cause |
| 1302 | * issues on the VF drivers so we only need to clear what we set |
| 1303 | */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1304 | if (adapter->msix_entries) { |
Alexander Duyck | 2dfd121 | 2009-09-03 14:49:15 +0000 | [diff] [blame] | 1305 | u32 regval = rd32(E1000_EIAM); |
| 1306 | wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask); |
| 1307 | wr32(E1000_EIMC, adapter->eims_enable_mask); |
| 1308 | regval = rd32(E1000_EIAC); |
| 1309 | wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1310 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1311 | |
| 1312 | wr32(E1000_IAM, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1313 | wr32(E1000_IMC, ~0); |
| 1314 | wrfl(); |
Emil Tantilov | 81a6185 | 2010-08-02 14:40:52 +0000 | [diff] [blame] | 1315 | if (adapter->msix_entries) { |
| 1316 | int i; |
| 1317 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 1318 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1319 | } else { |
| 1320 | synchronize_irq(adapter->pdev->irq); |
| 1321 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * igb_irq_enable - Enable default interrupt generation settings |
| 1326 | * @adapter: board private structure |
| 1327 | **/ |
| 1328 | static void igb_irq_enable(struct igb_adapter *adapter) |
| 1329 | { |
| 1330 | struct e1000_hw *hw = &adapter->hw; |
| 1331 | |
| 1332 | if (adapter->msix_entries) { |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1333 | u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC; |
Alexander Duyck | 2dfd121 | 2009-09-03 14:49:15 +0000 | [diff] [blame] | 1334 | u32 regval = rd32(E1000_EIAC); |
| 1335 | wr32(E1000_EIAC, regval | adapter->eims_enable_mask); |
| 1336 | regval = rd32(E1000_EIAM); |
| 1337 | wr32(E1000_EIAM, regval | adapter->eims_enable_mask); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1338 | wr32(E1000_EIMS, adapter->eims_enable_mask); |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1339 | if (adapter->vfs_allocated_count) { |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1340 | wr32(E1000_MBVFIMR, 0xFF); |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1341 | ims |= E1000_IMS_VMMB; |
| 1342 | } |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1343 | if (adapter->hw.mac.type == e1000_82580) |
| 1344 | ims |= E1000_IMS_DRSTA; |
| 1345 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1346 | wr32(E1000_IMS, ims); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1347 | } else { |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1348 | wr32(E1000_IMS, IMS_ENABLE_MASK | |
| 1349 | E1000_IMS_DRSTA); |
| 1350 | wr32(E1000_IAM, IMS_ENABLE_MASK | |
| 1351 | E1000_IMS_DRSTA); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1352 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | static void igb_update_mng_vlan(struct igb_adapter *adapter) |
| 1356 | { |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 1357 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1358 | u16 vid = adapter->hw.mng_cookie.vlan_id; |
| 1359 | u16 old_vid = adapter->mng_vlan_id; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1360 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 1361 | if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) { |
| 1362 | /* add VID to filter table */ |
| 1363 | igb_vfta_set(hw, vid, true); |
| 1364 | adapter->mng_vlan_id = vid; |
| 1365 | } else { |
| 1366 | adapter->mng_vlan_id = IGB_MNG_VLAN_NONE; |
| 1367 | } |
| 1368 | |
| 1369 | if ((old_vid != (u16)IGB_MNG_VLAN_NONE) && |
| 1370 | (vid != old_vid) && |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 1371 | !test_bit(old_vid, adapter->active_vlans)) { |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 1372 | /* remove VID from filter table */ |
| 1373 | igb_vfta_set(hw, old_vid, false); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | /** |
| 1378 | * igb_release_hw_control - release control of the h/w to f/w |
| 1379 | * @adapter: address of board private structure |
| 1380 | * |
| 1381 | * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit. |
| 1382 | * For ASF and Pass Through versions of f/w this means that the |
| 1383 | * driver is no longer loaded. |
| 1384 | * |
| 1385 | **/ |
| 1386 | static void igb_release_hw_control(struct igb_adapter *adapter) |
| 1387 | { |
| 1388 | struct e1000_hw *hw = &adapter->hw; |
| 1389 | u32 ctrl_ext; |
| 1390 | |
| 1391 | /* Let firmware take over control of h/w */ |
| 1392 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 1393 | wr32(E1000_CTRL_EXT, |
| 1394 | ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD); |
| 1395 | } |
| 1396 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1397 | /** |
| 1398 | * igb_get_hw_control - get control of the h/w from f/w |
| 1399 | * @adapter: address of board private structure |
| 1400 | * |
| 1401 | * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit. |
| 1402 | * For ASF and Pass Through versions of f/w this means that |
| 1403 | * the driver is loaded. |
| 1404 | * |
| 1405 | **/ |
| 1406 | static void igb_get_hw_control(struct igb_adapter *adapter) |
| 1407 | { |
| 1408 | struct e1000_hw *hw = &adapter->hw; |
| 1409 | u32 ctrl_ext; |
| 1410 | |
| 1411 | /* Let firmware know the driver has taken over */ |
| 1412 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 1413 | wr32(E1000_CTRL_EXT, |
| 1414 | ctrl_ext | E1000_CTRL_EXT_DRV_LOAD); |
| 1415 | } |
| 1416 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1417 | /** |
| 1418 | * igb_configure - configure the hardware for RX and TX |
| 1419 | * @adapter: private board structure |
| 1420 | **/ |
| 1421 | static void igb_configure(struct igb_adapter *adapter) |
| 1422 | { |
| 1423 | struct net_device *netdev = adapter->netdev; |
| 1424 | int i; |
| 1425 | |
| 1426 | igb_get_hw_control(adapter); |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 1427 | igb_set_rx_mode(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1428 | |
| 1429 | igb_restore_vlan(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1430 | |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 1431 | igb_setup_tctl(adapter); |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 1432 | igb_setup_mrqc(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1433 | igb_setup_rctl(adapter); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 1434 | |
| 1435 | igb_configure_tx(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1436 | igb_configure_rx(adapter); |
Alexander Duyck | 662d720 | 2008-06-27 11:00:29 -0700 | [diff] [blame] | 1437 | |
| 1438 | igb_rx_fifo_flush_82575(&adapter->hw); |
| 1439 | |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 1440 | /* call igb_desc_unused which always leaves |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1441 | * at least 1 descriptor unused to make sure |
| 1442 | * next_to_use != next_to_clean */ |
| 1443 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 1444 | struct igb_ring *ring = adapter->rx_ring[i]; |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 1445 | igb_alloc_rx_buffers(ring, igb_desc_unused(ring)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1446 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1447 | } |
| 1448 | |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1449 | /** |
| 1450 | * igb_power_up_link - Power up the phy/serdes link |
| 1451 | * @adapter: address of board private structure |
| 1452 | **/ |
| 1453 | void igb_power_up_link(struct igb_adapter *adapter) |
| 1454 | { |
| 1455 | if (adapter->hw.phy.media_type == e1000_media_type_copper) |
| 1456 | igb_power_up_phy_copper(&adapter->hw); |
| 1457 | else |
| 1458 | igb_power_up_serdes_link_82575(&adapter->hw); |
| 1459 | } |
| 1460 | |
| 1461 | /** |
| 1462 | * igb_power_down_link - Power down the phy/serdes link |
| 1463 | * @adapter: address of board private structure |
| 1464 | */ |
| 1465 | static void igb_power_down_link(struct igb_adapter *adapter) |
| 1466 | { |
| 1467 | if (adapter->hw.phy.media_type == e1000_media_type_copper) |
| 1468 | igb_power_down_phy_copper_82575(&adapter->hw); |
| 1469 | else |
| 1470 | igb_shutdown_serdes_link_82575(&adapter->hw); |
| 1471 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1472 | |
| 1473 | /** |
| 1474 | * igb_up - Open the interface and prepare it to handle traffic |
| 1475 | * @adapter: board private structure |
| 1476 | **/ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1477 | int igb_up(struct igb_adapter *adapter) |
| 1478 | { |
| 1479 | struct e1000_hw *hw = &adapter->hw; |
| 1480 | int i; |
| 1481 | |
| 1482 | /* hardware has been reset, we need to reload some things */ |
| 1483 | igb_configure(adapter); |
| 1484 | |
| 1485 | clear_bit(__IGB_DOWN, &adapter->state); |
| 1486 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1487 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 1488 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 1489 | napi_enable(&q_vector->napi); |
| 1490 | } |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 1491 | if (adapter->msix_entries) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1492 | igb_configure_msix(adapter); |
Alexander Duyck | feeb272 | 2010-02-03 21:59:51 +0000 | [diff] [blame] | 1493 | else |
| 1494 | igb_assign_vector(adapter->q_vector[0], 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1495 | |
| 1496 | /* Clear any pending interrupts. */ |
| 1497 | rd32(E1000_ICR); |
| 1498 | igb_irq_enable(adapter); |
| 1499 | |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 1500 | /* notify VFs that reset has been completed */ |
| 1501 | if (adapter->vfs_allocated_count) { |
| 1502 | u32 reg_data = rd32(E1000_CTRL_EXT); |
| 1503 | reg_data |= E1000_CTRL_EXT_PFRSTD; |
| 1504 | wr32(E1000_CTRL_EXT, reg_data); |
| 1505 | } |
| 1506 | |
Jesse Brandeburg | 4cb9be7 | 2009-04-21 18:42:05 +0000 | [diff] [blame] | 1507 | netif_tx_start_all_queues(adapter->netdev); |
| 1508 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 1509 | /* start the watchdog. */ |
| 1510 | hw->mac.get_link_status = 1; |
| 1511 | schedule_work(&adapter->watchdog_task); |
| 1512 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | void igb_down(struct igb_adapter *adapter) |
| 1517 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1518 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1519 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1520 | u32 tctl, rctl; |
| 1521 | int i; |
| 1522 | |
| 1523 | /* signal that we're down so the interrupt handler does not |
| 1524 | * reschedule our watchdog timer */ |
| 1525 | set_bit(__IGB_DOWN, &adapter->state); |
| 1526 | |
| 1527 | /* disable receives in the hardware */ |
| 1528 | rctl = rd32(E1000_RCTL); |
| 1529 | wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN); |
| 1530 | /* flush and sleep below */ |
| 1531 | |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 1532 | netif_tx_stop_all_queues(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1533 | |
| 1534 | /* disable transmits in the hardware */ |
| 1535 | tctl = rd32(E1000_TCTL); |
| 1536 | tctl &= ~E1000_TCTL_EN; |
| 1537 | wr32(E1000_TCTL, tctl); |
| 1538 | /* flush both disables and wait for them to finish */ |
| 1539 | wrfl(); |
| 1540 | msleep(10); |
| 1541 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 1542 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 1543 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 1544 | napi_disable(&q_vector->napi); |
| 1545 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1546 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1547 | igb_irq_disable(adapter); |
| 1548 | |
| 1549 | del_timer_sync(&adapter->watchdog_timer); |
| 1550 | del_timer_sync(&adapter->phy_info_timer); |
| 1551 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1552 | netif_carrier_off(netdev); |
Alexander Duyck | 04fe635 | 2009-02-06 23:22:32 +0000 | [diff] [blame] | 1553 | |
| 1554 | /* record the stats before reset*/ |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 1555 | spin_lock(&adapter->stats64_lock); |
| 1556 | igb_update_stats(adapter, &adapter->stats64); |
| 1557 | spin_unlock(&adapter->stats64_lock); |
Alexander Duyck | 04fe635 | 2009-02-06 23:22:32 +0000 | [diff] [blame] | 1558 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1559 | adapter->link_speed = 0; |
| 1560 | adapter->link_duplex = 0; |
| 1561 | |
Jeff Kirsher | 3023682 | 2008-06-24 17:01:15 -0700 | [diff] [blame] | 1562 | if (!pci_channel_offline(adapter->pdev)) |
| 1563 | igb_reset(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1564 | igb_clean_all_tx_rings(adapter); |
| 1565 | igb_clean_all_rx_rings(adapter); |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 1566 | #ifdef CONFIG_IGB_DCA |
| 1567 | |
| 1568 | /* since we reset the hardware DCA settings were cleared */ |
| 1569 | igb_setup_dca(adapter); |
| 1570 | #endif |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | void igb_reinit_locked(struct igb_adapter *adapter) |
| 1574 | { |
| 1575 | WARN_ON(in_interrupt()); |
| 1576 | while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) |
| 1577 | msleep(1); |
| 1578 | igb_down(adapter); |
| 1579 | igb_up(adapter); |
| 1580 | clear_bit(__IGB_RESETTING, &adapter->state); |
| 1581 | } |
| 1582 | |
| 1583 | void igb_reset(struct igb_adapter *adapter) |
| 1584 | { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 1585 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1586 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1587 | struct e1000_mac_info *mac = &hw->mac; |
| 1588 | struct e1000_fc_info *fc = &hw->fc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1589 | u32 pba = 0, tx_space, min_tx_space, min_rx_space; |
| 1590 | u16 hwm; |
| 1591 | |
| 1592 | /* Repartition Pba for greater than 9k mtu |
| 1593 | * To take effect CTRL.RST is required. |
| 1594 | */ |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1595 | switch (mac->type) { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 1596 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1597 | case e1000_82580: |
| 1598 | pba = rd32(E1000_RXPBS); |
| 1599 | pba = igb_rxpbs_adjust_82580(pba); |
| 1600 | break; |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1601 | case e1000_82576: |
Alexander Duyck | d249be5 | 2009-10-27 23:46:38 +0000 | [diff] [blame] | 1602 | pba = rd32(E1000_RXPBS); |
| 1603 | pba &= E1000_RXPBS_SIZE_MASK_82576; |
Alexander Duyck | fa4dfae | 2009-02-06 23:21:31 +0000 | [diff] [blame] | 1604 | break; |
| 1605 | case e1000_82575: |
| 1606 | default: |
| 1607 | pba = E1000_PBA_34K; |
| 1608 | break; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1609 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1610 | |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1611 | if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) && |
| 1612 | (mac->type < e1000_82576)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1613 | /* adjust PBA for jumbo frames */ |
| 1614 | wr32(E1000_PBA, pba); |
| 1615 | |
| 1616 | /* To maintain wire speed transmits, the Tx FIFO should be |
| 1617 | * large enough to accommodate two full transmit packets, |
| 1618 | * rounded up to the next 1KB and expressed in KB. Likewise, |
| 1619 | * the Rx FIFO should be large enough to accommodate at least |
| 1620 | * one full receive packet and is similarly rounded up and |
| 1621 | * expressed in KB. */ |
| 1622 | pba = rd32(E1000_PBA); |
| 1623 | /* upper 16 bits has Tx packet buffer allocation size in KB */ |
| 1624 | tx_space = pba >> 16; |
| 1625 | /* lower 16 bits has Rx packet buffer allocation size in KB */ |
| 1626 | pba &= 0xffff; |
| 1627 | /* the tx fifo also stores 16 bytes of information about the tx |
| 1628 | * but don't include ethernet FCS because hardware appends it */ |
| 1629 | min_tx_space = (adapter->max_frame_size + |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 1630 | sizeof(union e1000_adv_tx_desc) - |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1631 | ETH_FCS_LEN) * 2; |
| 1632 | min_tx_space = ALIGN(min_tx_space, 1024); |
| 1633 | min_tx_space >>= 10; |
| 1634 | /* software strips receive CRC, so leave room for it */ |
| 1635 | min_rx_space = adapter->max_frame_size; |
| 1636 | min_rx_space = ALIGN(min_rx_space, 1024); |
| 1637 | min_rx_space >>= 10; |
| 1638 | |
| 1639 | /* If current Tx allocation is less than the min Tx FIFO size, |
| 1640 | * and the min Tx FIFO size is less than the current Rx FIFO |
| 1641 | * allocation, take space away from current Rx allocation */ |
| 1642 | if (tx_space < min_tx_space && |
| 1643 | ((min_tx_space - tx_space) < pba)) { |
| 1644 | pba = pba - (min_tx_space - tx_space); |
| 1645 | |
| 1646 | /* if short on rx space, rx wins and must trump tx |
| 1647 | * adjustment */ |
| 1648 | if (pba < min_rx_space) |
| 1649 | pba = min_rx_space; |
| 1650 | } |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1651 | wr32(E1000_PBA, pba); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1652 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1653 | |
| 1654 | /* flow control settings */ |
| 1655 | /* The high water mark must be low enough to fit one full frame |
| 1656 | * (or the size used for early receive) above it in the Rx FIFO. |
| 1657 | * Set it to the lower of: |
| 1658 | * - 90% of the Rx FIFO size, or |
| 1659 | * - the full Rx FIFO size minus one full frame */ |
| 1660 | hwm = min(((pba << 10) * 9 / 10), |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1661 | ((pba << 10) - 2 * adapter->max_frame_size)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1662 | |
Alexander Duyck | d405ea3 | 2009-12-23 13:21:27 +0000 | [diff] [blame] | 1663 | fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */ |
| 1664 | fc->low_water = fc->high_water - 16; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1665 | fc->pause_time = 0xFFFF; |
| 1666 | fc->send_xon = 1; |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 1667 | fc->current_mode = fc->requested_mode; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1668 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1669 | /* disable receive for all VFs and wait one second */ |
| 1670 | if (adapter->vfs_allocated_count) { |
| 1671 | int i; |
| 1672 | for (i = 0 ; i < adapter->vfs_allocated_count; i++) |
Greg Rose | 8fa7e0f | 2010-11-06 05:43:21 +0000 | [diff] [blame] | 1673 | adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1674 | |
| 1675 | /* ping all the active vfs to let them know we are going down */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 1676 | igb_ping_all_vfs(adapter); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1677 | |
| 1678 | /* disable transmits and receives */ |
| 1679 | wr32(E1000_VFRE, 0); |
| 1680 | wr32(E1000_VFTE, 0); |
| 1681 | } |
| 1682 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1683 | /* Allow time for pending master requests to run */ |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1684 | hw->mac.ops.reset_hw(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1685 | wr32(E1000_WUC, 0); |
| 1686 | |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1687 | if (hw->mac.ops.init_hw(hw)) |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 1688 | dev_err(&pdev->dev, "Hardware Error\n"); |
Carolyn Wyborny | 831ec0b | 2011-03-11 20:43:54 -0800 | [diff] [blame] | 1689 | if (hw->mac.type > e1000_82580) { |
| 1690 | if (adapter->flags & IGB_FLAG_DMAC) { |
| 1691 | u32 reg; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1692 | |
Carolyn Wyborny | 831ec0b | 2011-03-11 20:43:54 -0800 | [diff] [blame] | 1693 | /* |
| 1694 | * DMA Coalescing high water mark needs to be higher |
| 1695 | * than * the * Rx threshold. The Rx threshold is |
| 1696 | * currently * pba - 6, so we * should use a high water |
| 1697 | * mark of pba * - 4. */ |
| 1698 | hwm = (pba - 4) << 10; |
| 1699 | |
| 1700 | reg = (((pba-6) << E1000_DMACR_DMACTHR_SHIFT) |
| 1701 | & E1000_DMACR_DMACTHR_MASK); |
| 1702 | |
| 1703 | /* transition to L0x or L1 if available..*/ |
| 1704 | reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK); |
| 1705 | |
| 1706 | /* watchdog timer= +-1000 usec in 32usec intervals */ |
| 1707 | reg |= (1000 >> 5); |
| 1708 | wr32(E1000_DMACR, reg); |
| 1709 | |
| 1710 | /* no lower threshold to disable coalescing(smart fifb) |
| 1711 | * -UTRESH=0*/ |
| 1712 | wr32(E1000_DMCRTRH, 0); |
| 1713 | |
| 1714 | /* set hwm to PBA - 2 * max frame size */ |
| 1715 | wr32(E1000_FCRTC, hwm); |
| 1716 | |
| 1717 | /* |
| 1718 | * This sets the time to wait before requesting tran- |
| 1719 | * sition to * low power state to number of usecs needed |
| 1720 | * to receive 1 512 * byte frame at gigabit line rate |
| 1721 | */ |
| 1722 | reg = rd32(E1000_DMCTLX); |
| 1723 | reg |= IGB_DMCTLX_DCFLUSH_DIS; |
| 1724 | |
| 1725 | /* Delay 255 usec before entering Lx state. */ |
| 1726 | reg |= 0xFF; |
| 1727 | wr32(E1000_DMCTLX, reg); |
| 1728 | |
| 1729 | /* free space in Tx packet buffer to wake from DMAC */ |
| 1730 | wr32(E1000_DMCTXTH, |
| 1731 | (IGB_MIN_TXPBSIZE - |
| 1732 | (IGB_TX_BUF_4096 + adapter->max_frame_size)) |
| 1733 | >> 6); |
| 1734 | |
| 1735 | /* make low power state decision controlled by DMAC */ |
| 1736 | reg = rd32(E1000_PCIEMISC); |
| 1737 | reg |= E1000_PCIEMISC_LX_DECISION; |
| 1738 | wr32(E1000_PCIEMISC, reg); |
| 1739 | } /* end if IGB_FLAG_DMAC set */ |
| 1740 | } |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 1741 | if (hw->mac.type == e1000_82580) { |
| 1742 | u32 reg = rd32(E1000_PCIEMISC); |
| 1743 | wr32(E1000_PCIEMISC, |
| 1744 | reg & ~E1000_PCIEMISC_LX_DECISION); |
| 1745 | } |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1746 | if (!netif_running(adapter->netdev)) |
| 1747 | igb_power_down_link(adapter); |
| 1748 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1749 | igb_update_mng_vlan(adapter); |
| 1750 | |
| 1751 | /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ |
| 1752 | wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE); |
| 1753 | |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1754 | igb_get_phy_info(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1755 | } |
| 1756 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 1757 | static u32 igb_fix_features(struct net_device *netdev, u32 features) |
| 1758 | { |
| 1759 | /* |
| 1760 | * Since there is no support for separate rx/tx vlan accel |
| 1761 | * enable/disable make sure tx flag is always in same state as rx. |
| 1762 | */ |
| 1763 | if (features & NETIF_F_HW_VLAN_RX) |
| 1764 | features |= NETIF_F_HW_VLAN_TX; |
| 1765 | else |
| 1766 | features &= ~NETIF_F_HW_VLAN_TX; |
| 1767 | |
| 1768 | return features; |
| 1769 | } |
| 1770 | |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1771 | static int igb_set_features(struct net_device *netdev, u32 features) |
| 1772 | { |
| 1773 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 1774 | int i; |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 1775 | u32 changed = netdev->features ^ features; |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1776 | |
| 1777 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1778 | if (features & NETIF_F_RXCSUM) |
| 1779 | adapter->rx_ring[i]->flags |= IGB_RING_FLAG_RX_CSUM; |
| 1780 | else |
| 1781 | adapter->rx_ring[i]->flags &= ~IGB_RING_FLAG_RX_CSUM; |
| 1782 | } |
| 1783 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 1784 | if (changed & NETIF_F_HW_VLAN_RX) |
| 1785 | igb_vlan_mode(netdev, features); |
| 1786 | |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1787 | return 0; |
| 1788 | } |
| 1789 | |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1790 | static const struct net_device_ops igb_netdev_ops = { |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 1791 | .ndo_open = igb_open, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1792 | .ndo_stop = igb_close, |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 1793 | .ndo_start_xmit = igb_xmit_frame, |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 1794 | .ndo_get_stats64 = igb_get_stats64, |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 1795 | .ndo_set_rx_mode = igb_set_rx_mode, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1796 | .ndo_set_mac_address = igb_set_mac, |
| 1797 | .ndo_change_mtu = igb_change_mtu, |
| 1798 | .ndo_do_ioctl = igb_ioctl, |
| 1799 | .ndo_tx_timeout = igb_tx_timeout, |
| 1800 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1801 | .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid, |
| 1802 | .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid, |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 1803 | .ndo_set_vf_mac = igb_ndo_set_vf_mac, |
| 1804 | .ndo_set_vf_vlan = igb_ndo_set_vf_vlan, |
| 1805 | .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw, |
| 1806 | .ndo_get_vf_config = igb_ndo_get_vf_config, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1807 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1808 | .ndo_poll_controller = igb_netpoll, |
| 1809 | #endif |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 1810 | .ndo_fix_features = igb_fix_features, |
| 1811 | .ndo_set_features = igb_set_features, |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1812 | }; |
| 1813 | |
Taku Izumi | 42bfd33 | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 1814 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1815 | * igb_probe - Device Initialization Routine |
| 1816 | * @pdev: PCI device information struct |
| 1817 | * @ent: entry in igb_pci_tbl |
| 1818 | * |
| 1819 | * Returns 0 on success, negative on failure |
| 1820 | * |
| 1821 | * igb_probe initializes an adapter identified by a pci_dev structure. |
| 1822 | * The OS initialization, configuring of the adapter private structure, |
| 1823 | * and a hardware reset occur. |
| 1824 | **/ |
| 1825 | static int __devinit igb_probe(struct pci_dev *pdev, |
| 1826 | const struct pci_device_id *ent) |
| 1827 | { |
| 1828 | struct net_device *netdev; |
| 1829 | struct igb_adapter *adapter; |
| 1830 | struct e1000_hw *hw; |
Alexander Duyck | 4337e99 | 2009-10-27 23:48:31 +0000 | [diff] [blame] | 1831 | u16 eeprom_data = 0; |
Carolyn Wyborny | 9835fd7 | 2010-11-22 17:17:21 +0000 | [diff] [blame] | 1832 | s32 ret_val; |
Alexander Duyck | 4337e99 | 2009-10-27 23:48:31 +0000 | [diff] [blame] | 1833 | static int global_quad_port_a; /* global quad port a indication */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1834 | const struct e1000_info *ei = igb_info_tbl[ent->driver_data]; |
| 1835 | unsigned long mmio_start, mmio_len; |
David S. Miller | 2d6a5e9 | 2009-03-17 15:01:30 -0700 | [diff] [blame] | 1836 | int err, pci_using_dac; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1837 | u16 eeprom_apme_mask = IGB_EEPROM_APME; |
Carolyn Wyborny | 9835fd7 | 2010-11-22 17:17:21 +0000 | [diff] [blame] | 1838 | u8 part_str[E1000_PBANUM_LENGTH]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1839 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 1840 | /* Catch broken hardware that put the wrong VF device ID in |
| 1841 | * the PCIe SR-IOV capability. |
| 1842 | */ |
| 1843 | if (pdev->is_virtfn) { |
| 1844 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 1845 | pci_name(pdev), pdev->vendor, pdev->device); |
| 1846 | return -EINVAL; |
| 1847 | } |
| 1848 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1849 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1850 | if (err) |
| 1851 | return err; |
| 1852 | |
| 1853 | pci_using_dac = 0; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1854 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1855 | if (!err) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1856 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1857 | if (!err) |
| 1858 | pci_using_dac = 1; |
| 1859 | } else { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1860 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1861 | if (err) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 1862 | err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1863 | if (err) { |
| 1864 | dev_err(&pdev->dev, "No usable DMA " |
| 1865 | "configuration, aborting\n"); |
| 1866 | goto err_dma; |
| 1867 | } |
| 1868 | } |
| 1869 | } |
| 1870 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 1871 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 1872 | IORESOURCE_MEM), |
| 1873 | igb_driver_name); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1874 | if (err) |
| 1875 | goto err_pci_reg; |
| 1876 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 1877 | pci_enable_pcie_error_reporting(pdev); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 1878 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1879 | pci_set_master(pdev); |
Auke Kok | c682fc2 | 2008-04-23 11:09:34 -0700 | [diff] [blame] | 1880 | pci_save_state(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1881 | |
| 1882 | err = -ENOMEM; |
Alexander Duyck | 1bfaf07 | 2009-02-19 20:39:23 -0800 | [diff] [blame] | 1883 | netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), |
Alexander Duyck | 1cc3bd8 | 2011-08-26 07:44:10 +0000 | [diff] [blame] | 1884 | IGB_MAX_TX_QUEUES); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1885 | if (!netdev) |
| 1886 | goto err_alloc_etherdev; |
| 1887 | |
| 1888 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 1889 | |
| 1890 | pci_set_drvdata(pdev, netdev); |
| 1891 | adapter = netdev_priv(netdev); |
| 1892 | adapter->netdev = netdev; |
| 1893 | adapter->pdev = pdev; |
| 1894 | hw = &adapter->hw; |
| 1895 | hw->back = adapter; |
| 1896 | adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE; |
| 1897 | |
| 1898 | mmio_start = pci_resource_start(pdev, 0); |
| 1899 | mmio_len = pci_resource_len(pdev, 0); |
| 1900 | |
| 1901 | err = -EIO; |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 1902 | hw->hw_addr = ioremap(mmio_start, mmio_len); |
| 1903 | if (!hw->hw_addr) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1904 | goto err_ioremap; |
| 1905 | |
Stephen Hemminger | 2e5c692 | 2008-11-19 22:20:44 -0800 | [diff] [blame] | 1906 | netdev->netdev_ops = &igb_netdev_ops; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1907 | igb_set_ethtool_ops(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1908 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1909 | |
| 1910 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
| 1911 | |
| 1912 | netdev->mem_start = mmio_start; |
| 1913 | netdev->mem_end = mmio_start + mmio_len; |
| 1914 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1915 | /* PCI config space info */ |
| 1916 | hw->vendor_id = pdev->vendor; |
| 1917 | hw->device_id = pdev->device; |
| 1918 | hw->revision_id = pdev->revision; |
| 1919 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1920 | hw->subsystem_device_id = pdev->subsystem_device; |
| 1921 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1922 | /* Copy the default MAC, PHY and NVM function pointers */ |
| 1923 | memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops)); |
| 1924 | memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops)); |
| 1925 | memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops)); |
| 1926 | /* Initialize skew-specific constants */ |
| 1927 | err = ei->get_invariants(hw); |
| 1928 | if (err) |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1929 | goto err_sw_init; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1930 | |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 1931 | /* setup the private structure */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1932 | err = igb_sw_init(adapter); |
| 1933 | if (err) |
| 1934 | goto err_sw_init; |
| 1935 | |
| 1936 | igb_get_bus_info_pcie(hw); |
| 1937 | |
| 1938 | hw->phy.autoneg_wait_to_complete = false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1939 | |
| 1940 | /* Copper options */ |
| 1941 | if (hw->phy.media_type == e1000_media_type_copper) { |
| 1942 | hw->phy.mdix = AUTO_ALL_MODES; |
| 1943 | hw->phy.disable_polarity_correction = false; |
| 1944 | hw->phy.ms_type = e1000_ms_hw_default; |
| 1945 | } |
| 1946 | |
| 1947 | if (igb_check_reset_block(hw)) |
| 1948 | dev_info(&pdev->dev, |
| 1949 | "PHY reset is blocked due to SOL/IDER session.\n"); |
| 1950 | |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1951 | netdev->hw_features = NETIF_F_SG | |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1952 | NETIF_F_IP_CSUM | |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1953 | NETIF_F_IPV6_CSUM | |
| 1954 | NETIF_F_TSO | |
| 1955 | NETIF_F_TSO6 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 1956 | NETIF_F_RXCSUM | |
| 1957 | NETIF_F_HW_VLAN_RX; |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1958 | |
| 1959 | netdev->features = netdev->hw_features | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1960 | NETIF_F_HW_VLAN_TX | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1961 | NETIF_F_HW_VLAN_FILTER; |
| 1962 | |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1963 | netdev->vlan_features |= NETIF_F_TSO; |
| 1964 | netdev->vlan_features |= NETIF_F_TSO6; |
Alexander Duyck | 7d8eb29 | 2009-02-06 23:18:27 +0000 | [diff] [blame] | 1965 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 1966 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | 48f29ff | 2008-06-05 04:06:27 -0700 | [diff] [blame] | 1967 | netdev->vlan_features |= NETIF_F_SG; |
| 1968 | |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 1969 | if (pci_using_dac) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1970 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 1971 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 1972 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1973 | |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1974 | if (hw->mac.type >= e1000_82576) { |
| 1975 | netdev->hw_features |= NETIF_F_SCTP_CSUM; |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 1976 | netdev->features |= NETIF_F_SCTP_CSUM; |
Michał Mirosław | ac52caa | 2011-06-08 08:38:01 +0000 | [diff] [blame] | 1977 | } |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 1978 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 1979 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 1980 | |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 1981 | adapter->en_mng_pt = igb_enable_mng_pass_thru(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1982 | |
| 1983 | /* before reading the NVM, reset the controller to put the device in a |
| 1984 | * known good starting state */ |
| 1985 | hw->mac.ops.reset_hw(hw); |
| 1986 | |
| 1987 | /* make sure the NVM is good */ |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 1988 | if (hw->nvm.ops.validate(hw) < 0) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1989 | dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n"); |
| 1990 | err = -EIO; |
| 1991 | goto err_eeprom; |
| 1992 | } |
| 1993 | |
| 1994 | /* copy the MAC address out of the NVM */ |
| 1995 | if (hw->mac.ops.read_mac_addr(hw)) |
| 1996 | dev_err(&pdev->dev, "NVM Read Error\n"); |
| 1997 | |
| 1998 | memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len); |
| 1999 | memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len); |
| 2000 | |
| 2001 | if (!is_valid_ether_addr(netdev->perm_addr)) { |
| 2002 | dev_err(&pdev->dev, "Invalid MAC Address\n"); |
| 2003 | err = -EIO; |
| 2004 | goto err_eeprom; |
| 2005 | } |
| 2006 | |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 2007 | setup_timer(&adapter->watchdog_timer, igb_watchdog, |
Alexander Duyck | 0e34048 | 2009-03-20 00:17:08 +0000 | [diff] [blame] | 2008 | (unsigned long) adapter); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 2009 | setup_timer(&adapter->phy_info_timer, igb_update_phy_info, |
Alexander Duyck | 0e34048 | 2009-03-20 00:17:08 +0000 | [diff] [blame] | 2010 | (unsigned long) adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2011 | |
| 2012 | INIT_WORK(&adapter->reset_task, igb_reset_task); |
| 2013 | INIT_WORK(&adapter->watchdog_task, igb_watchdog_task); |
| 2014 | |
Alexander Duyck | 450c87c | 2009-02-06 23:22:11 +0000 | [diff] [blame] | 2015 | /* Initialize link properties that are user-changeable */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2016 | adapter->fc_autoneg = true; |
| 2017 | hw->mac.autoneg = true; |
| 2018 | hw->phy.autoneg_advertised = 0x2f; |
| 2019 | |
Alexander Duyck | 0cce119 | 2009-07-23 18:10:24 +0000 | [diff] [blame] | 2020 | hw->fc.requested_mode = e1000_fc_default; |
| 2021 | hw->fc.current_mode = e1000_fc_default; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2022 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2023 | igb_validate_mdi_setting(hw); |
| 2024 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2025 | /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM, |
| 2026 | * enable the ACPI Magic Packet filter |
| 2027 | */ |
| 2028 | |
Alexander Duyck | a2cf8b6 | 2009-03-13 20:41:17 +0000 | [diff] [blame] | 2029 | if (hw->bus.func == 0) |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 2030 | hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data); |
Carolyn Wyborny | 6d337dc | 2011-07-07 00:24:56 +0000 | [diff] [blame] | 2031 | else if (hw->mac.type >= e1000_82580) |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 2032 | hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A + |
| 2033 | NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1, |
| 2034 | &eeprom_data); |
Alexander Duyck | a2cf8b6 | 2009-03-13 20:41:17 +0000 | [diff] [blame] | 2035 | else if (hw->bus.func == 1) |
| 2036 | 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] | 2037 | |
| 2038 | if (eeprom_data & eeprom_apme_mask) |
| 2039 | adapter->eeprom_wol |= E1000_WUFC_MAG; |
| 2040 | |
| 2041 | /* now that we have the eeprom settings, apply the special cases where |
| 2042 | * the eeprom may be wrong or the board simply won't support wake on |
| 2043 | * lan on a particular port */ |
| 2044 | switch (pdev->device) { |
| 2045 | case E1000_DEV_ID_82575GB_QUAD_COPPER: |
| 2046 | adapter->eeprom_wol = 0; |
| 2047 | break; |
| 2048 | case E1000_DEV_ID_82575EB_FIBER_SERDES: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 2049 | case E1000_DEV_ID_82576_FIBER: |
| 2050 | case E1000_DEV_ID_82576_SERDES: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2051 | /* Wake events only supported on port A for dual fiber |
| 2052 | * regardless of eeprom setting */ |
| 2053 | if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1) |
| 2054 | adapter->eeprom_wol = 0; |
| 2055 | break; |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 2056 | case E1000_DEV_ID_82576_QUAD_COPPER: |
Stefan Assmann | d5aa225 | 2010-04-09 09:51:34 +0000 | [diff] [blame] | 2057 | case E1000_DEV_ID_82576_QUAD_COPPER_ET2: |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 2058 | /* if quad port adapter, disable WoL on all but port A */ |
| 2059 | if (global_quad_port_a != 0) |
| 2060 | adapter->eeprom_wol = 0; |
| 2061 | else |
| 2062 | adapter->flags |= IGB_FLAG_QUAD_PORT_A; |
| 2063 | /* Reset for multiple quad port adapters */ |
| 2064 | if (++global_quad_port_a == 4) |
| 2065 | global_quad_port_a = 0; |
| 2066 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | /* initialize the wol settings based on the eeprom settings */ |
| 2070 | adapter->wol = adapter->eeprom_wol; |
\"Rafael J. Wysocki\ | e1b86d8 | 2008-11-07 20:30:37 +0000 | [diff] [blame] | 2071 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2072 | |
| 2073 | /* reset the hardware with the new settings */ |
| 2074 | igb_reset(adapter); |
| 2075 | |
| 2076 | /* let the f/w know that the h/w is now under the control of the |
| 2077 | * driver. */ |
| 2078 | igb_get_hw_control(adapter); |
| 2079 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2080 | strcpy(netdev->name, "eth%d"); |
| 2081 | err = register_netdev(netdev); |
| 2082 | if (err) |
| 2083 | goto err_register; |
| 2084 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 2085 | igb_vlan_mode(netdev, netdev->features); |
| 2086 | |
Jesse Brandeburg | b168dfc | 2009-04-17 20:44:32 +0000 | [diff] [blame] | 2087 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 2088 | netif_carrier_off(netdev); |
| 2089 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 2090 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 2091 | if (dca_add_requester(&pdev->dev) == 0) { |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 2092 | adapter->flags |= IGB_FLAG_DCA_ENABLED; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2093 | dev_info(&pdev->dev, "DCA enabled\n"); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2094 | igb_setup_dca(adapter); |
| 2095 | } |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 2096 | |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2097 | #endif |
Anders Berggren | 673b8b7 | 2011-02-04 07:32:32 +0000 | [diff] [blame] | 2098 | /* do hw tstamp init after resetting */ |
| 2099 | igb_init_hw_timer(adapter); |
| 2100 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2101 | dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n"); |
| 2102 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 2103 | dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2104 | netdev->name, |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2105 | ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" : |
Alexander Duyck | ff846f5 | 2010-04-27 01:02:40 +0000 | [diff] [blame] | 2106 | (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" : |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2107 | "unknown"), |
Alexander Duyck | 59c3de8 | 2009-03-31 20:38:00 +0000 | [diff] [blame] | 2108 | ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" : |
| 2109 | (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" : |
| 2110 | (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" : |
| 2111 | "unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 2112 | netdev->dev_addr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2113 | |
Carolyn Wyborny | 9835fd7 | 2010-11-22 17:17:21 +0000 | [diff] [blame] | 2114 | ret_val = igb_read_part_string(hw, part_str, E1000_PBANUM_LENGTH); |
| 2115 | if (ret_val) |
| 2116 | strcpy(part_str, "Unknown"); |
| 2117 | dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2118 | dev_info(&pdev->dev, |
| 2119 | "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n", |
| 2120 | adapter->msix_entries ? "MSI-X" : |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 2121 | (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2122 | adapter->num_rx_queues, adapter->num_tx_queues); |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2123 | switch (hw->mac.type) { |
| 2124 | case e1000_i350: |
| 2125 | igb_set_eee_i350(hw); |
| 2126 | break; |
| 2127 | default: |
| 2128 | break; |
| 2129 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2130 | return 0; |
| 2131 | |
| 2132 | err_register: |
| 2133 | igb_release_hw_control(adapter); |
| 2134 | err_eeprom: |
| 2135 | if (!igb_check_reset_block(hw)) |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 2136 | igb_reset_phy(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2137 | |
| 2138 | if (hw->flash_address) |
| 2139 | iounmap(hw->flash_address); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2140 | err_sw_init: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2141 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2142 | iounmap(hw->hw_addr); |
| 2143 | err_ioremap: |
| 2144 | free_netdev(netdev); |
| 2145 | err_alloc_etherdev: |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2146 | pci_release_selected_regions(pdev, |
| 2147 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2148 | err_pci_reg: |
| 2149 | err_dma: |
| 2150 | pci_disable_device(pdev); |
| 2151 | return err; |
| 2152 | } |
| 2153 | |
| 2154 | /** |
| 2155 | * igb_remove - Device Removal Routine |
| 2156 | * @pdev: PCI device information struct |
| 2157 | * |
| 2158 | * igb_remove is called by the PCI subsystem to alert the driver |
| 2159 | * that it should release a PCI device. The could be caused by a |
| 2160 | * Hot-Plug event, or because the driver is going to be removed from |
| 2161 | * memory. |
| 2162 | **/ |
| 2163 | static void __devexit igb_remove(struct pci_dev *pdev) |
| 2164 | { |
| 2165 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2166 | struct igb_adapter *adapter = netdev_priv(netdev); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2167 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2168 | |
Tejun Heo | 760141a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 2169 | /* |
| 2170 | * The watchdog timer may be rescheduled, so explicitly |
| 2171 | * disable watchdog from being rescheduled. |
| 2172 | */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2173 | set_bit(__IGB_DOWN, &adapter->state); |
| 2174 | del_timer_sync(&adapter->watchdog_timer); |
| 2175 | del_timer_sync(&adapter->phy_info_timer); |
| 2176 | |
Tejun Heo | 760141a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 2177 | cancel_work_sync(&adapter->reset_task); |
| 2178 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2179 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 2180 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 2181 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) { |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2182 | dev_info(&pdev->dev, "DCA disabled\n"); |
| 2183 | dca_remove_requester(&pdev->dev); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 2184 | adapter->flags &= ~IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 2185 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 2186 | } |
| 2187 | #endif |
| 2188 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2189 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 2190 | * would have already happened in close and is redundant. */ |
| 2191 | igb_release_hw_control(adapter); |
| 2192 | |
| 2193 | unregister_netdev(netdev); |
| 2194 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2195 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2196 | |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 2197 | #ifdef CONFIG_PCI_IOV |
| 2198 | /* reclaim resources allocated to VFs */ |
| 2199 | if (adapter->vf_data) { |
| 2200 | /* disable iov and allow time for transactions to clear */ |
| 2201 | pci_disable_sriov(pdev); |
| 2202 | msleep(500); |
| 2203 | |
| 2204 | kfree(adapter->vf_data); |
| 2205 | adapter->vf_data = NULL; |
| 2206 | wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 2207 | wrfl(); |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 2208 | msleep(100); |
| 2209 | dev_info(&pdev->dev, "IOV Disabled\n"); |
| 2210 | } |
| 2211 | #endif |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2212 | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2213 | iounmap(hw->hw_addr); |
| 2214 | if (hw->flash_address) |
| 2215 | iounmap(hw->flash_address); |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2216 | pci_release_selected_regions(pdev, |
| 2217 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2218 | |
| 2219 | free_netdev(netdev); |
| 2220 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 2221 | pci_disable_pcie_error_reporting(pdev); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 2222 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2223 | pci_disable_device(pdev); |
| 2224 | } |
| 2225 | |
| 2226 | /** |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2227 | * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space |
| 2228 | * @adapter: board private structure to initialize |
| 2229 | * |
| 2230 | * This function initializes the vf specific data storage and then attempts to |
| 2231 | * allocate the VFs. The reason for ordering it this way is because it is much |
| 2232 | * mor expensive time wise to disable SR-IOV than it is to allocate and free |
| 2233 | * the memory for the VFs. |
| 2234 | **/ |
| 2235 | static void __devinit igb_probe_vfs(struct igb_adapter * adapter) |
| 2236 | { |
| 2237 | #ifdef CONFIG_PCI_IOV |
| 2238 | struct pci_dev *pdev = adapter->pdev; |
| 2239 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2240 | if (adapter->vfs_allocated_count) { |
| 2241 | adapter->vf_data = kcalloc(adapter->vfs_allocated_count, |
| 2242 | sizeof(struct vf_data_storage), |
| 2243 | GFP_KERNEL); |
| 2244 | /* if allocation failed then we do not support SR-IOV */ |
| 2245 | if (!adapter->vf_data) { |
| 2246 | adapter->vfs_allocated_count = 0; |
| 2247 | dev_err(&pdev->dev, "Unable to allocate memory for VF " |
| 2248 | "Data Storage\n"); |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | if (pci_enable_sriov(pdev, adapter->vfs_allocated_count)) { |
| 2253 | kfree(adapter->vf_data); |
| 2254 | adapter->vf_data = NULL; |
| 2255 | #endif /* CONFIG_PCI_IOV */ |
| 2256 | adapter->vfs_allocated_count = 0; |
| 2257 | #ifdef CONFIG_PCI_IOV |
| 2258 | } else { |
| 2259 | unsigned char mac_addr[ETH_ALEN]; |
| 2260 | int i; |
| 2261 | dev_info(&pdev->dev, "%d vfs allocated\n", |
| 2262 | adapter->vfs_allocated_count); |
| 2263 | for (i = 0; i < adapter->vfs_allocated_count; i++) { |
| 2264 | random_ether_addr(mac_addr); |
| 2265 | igb_set_vf_mac(adapter, i, mac_addr); |
| 2266 | } |
Carolyn Wyborny | 831ec0b | 2011-03-11 20:43:54 -0800 | [diff] [blame] | 2267 | /* DMA Coalescing is not supported in IOV mode. */ |
| 2268 | if (adapter->flags & IGB_FLAG_DMAC) |
| 2269 | adapter->flags &= ~IGB_FLAG_DMAC; |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2270 | } |
| 2271 | #endif /* CONFIG_PCI_IOV */ |
| 2272 | } |
| 2273 | |
Alexander Duyck | 115f459 | 2009-11-12 18:37:00 +0000 | [diff] [blame] | 2274 | |
| 2275 | /** |
| 2276 | * igb_init_hw_timer - Initialize hardware timer used with IEEE 1588 timestamp |
| 2277 | * @adapter: board private structure to initialize |
| 2278 | * |
| 2279 | * igb_init_hw_timer initializes the function pointer and values for the hw |
| 2280 | * timer found in hardware. |
| 2281 | **/ |
| 2282 | static void igb_init_hw_timer(struct igb_adapter *adapter) |
| 2283 | { |
| 2284 | struct e1000_hw *hw = &adapter->hw; |
| 2285 | |
| 2286 | switch (hw->mac.type) { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 2287 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 2288 | case e1000_82580: |
| 2289 | memset(&adapter->cycles, 0, sizeof(adapter->cycles)); |
| 2290 | adapter->cycles.read = igb_read_clock; |
| 2291 | adapter->cycles.mask = CLOCKSOURCE_MASK(64); |
| 2292 | adapter->cycles.mult = 1; |
| 2293 | /* |
| 2294 | * The 82580 timesync updates the system timer every 8ns by 8ns |
| 2295 | * and the value cannot be shifted. Instead we need to shift |
| 2296 | * the registers to generate a 64bit timer value. As a result |
| 2297 | * SYSTIMR/L/H, TXSTMPL/H, RXSTMPL/H all have to be shifted by |
| 2298 | * 24 in order to generate a larger value for synchronization. |
| 2299 | */ |
| 2300 | adapter->cycles.shift = IGB_82580_TSYNC_SHIFT; |
| 2301 | /* disable system timer temporarily by setting bit 31 */ |
| 2302 | wr32(E1000_TSAUXC, 0x80000000); |
| 2303 | wrfl(); |
| 2304 | |
| 2305 | /* Set registers so that rollover occurs soon to test this. */ |
| 2306 | wr32(E1000_SYSTIMR, 0x00000000); |
| 2307 | wr32(E1000_SYSTIML, 0x80000000); |
| 2308 | wr32(E1000_SYSTIMH, 0x000000FF); |
| 2309 | wrfl(); |
| 2310 | |
| 2311 | /* enable system timer by clearing bit 31 */ |
| 2312 | wr32(E1000_TSAUXC, 0x0); |
| 2313 | wrfl(); |
| 2314 | |
| 2315 | timecounter_init(&adapter->clock, |
| 2316 | &adapter->cycles, |
| 2317 | ktime_to_ns(ktime_get_real())); |
| 2318 | /* |
| 2319 | * Synchronize our NIC clock against system wall clock. NIC |
| 2320 | * time stamp reading requires ~3us per sample, each sample |
| 2321 | * was pretty stable even under load => only require 10 |
| 2322 | * samples for each offset comparison. |
| 2323 | */ |
| 2324 | memset(&adapter->compare, 0, sizeof(adapter->compare)); |
| 2325 | adapter->compare.source = &adapter->clock; |
| 2326 | adapter->compare.target = ktime_get_real; |
| 2327 | adapter->compare.num_samples = 10; |
| 2328 | timecompare_update(&adapter->compare, 0); |
| 2329 | break; |
Alexander Duyck | 115f459 | 2009-11-12 18:37:00 +0000 | [diff] [blame] | 2330 | case e1000_82576: |
| 2331 | /* |
| 2332 | * Initialize hardware timer: we keep it running just in case |
| 2333 | * that some program needs it later on. |
| 2334 | */ |
| 2335 | memset(&adapter->cycles, 0, sizeof(adapter->cycles)); |
| 2336 | adapter->cycles.read = igb_read_clock; |
| 2337 | adapter->cycles.mask = CLOCKSOURCE_MASK(64); |
| 2338 | adapter->cycles.mult = 1; |
| 2339 | /** |
| 2340 | * Scale the NIC clock cycle by a large factor so that |
| 2341 | * relatively small clock corrections can be added or |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2342 | * subtracted at each clock tick. The drawbacks of a large |
Alexander Duyck | 115f459 | 2009-11-12 18:37:00 +0000 | [diff] [blame] | 2343 | * factor are a) that the clock register overflows more quickly |
| 2344 | * (not such a big deal) and b) that the increment per tick has |
| 2345 | * to fit into 24 bits. As a result we need to use a shift of |
| 2346 | * 19 so we can fit a value of 16 into the TIMINCA register. |
| 2347 | */ |
| 2348 | adapter->cycles.shift = IGB_82576_TSYNC_SHIFT; |
| 2349 | wr32(E1000_TIMINCA, |
| 2350 | (1 << E1000_TIMINCA_16NS_SHIFT) | |
| 2351 | (16 << IGB_82576_TSYNC_SHIFT)); |
| 2352 | |
| 2353 | /* Set registers so that rollover occurs soon to test this. */ |
| 2354 | wr32(E1000_SYSTIML, 0x00000000); |
| 2355 | wr32(E1000_SYSTIMH, 0xFF800000); |
| 2356 | wrfl(); |
| 2357 | |
| 2358 | timecounter_init(&adapter->clock, |
| 2359 | &adapter->cycles, |
| 2360 | ktime_to_ns(ktime_get_real())); |
| 2361 | /* |
| 2362 | * Synchronize our NIC clock against system wall clock. NIC |
| 2363 | * time stamp reading requires ~3us per sample, each sample |
| 2364 | * was pretty stable even under load => only require 10 |
| 2365 | * samples for each offset comparison. |
| 2366 | */ |
| 2367 | memset(&adapter->compare, 0, sizeof(adapter->compare)); |
| 2368 | adapter->compare.source = &adapter->clock; |
| 2369 | adapter->compare.target = ktime_get_real; |
| 2370 | adapter->compare.num_samples = 10; |
| 2371 | timecompare_update(&adapter->compare, 0); |
| 2372 | break; |
| 2373 | case e1000_82575: |
| 2374 | /* 82575 does not support timesync */ |
| 2375 | default: |
| 2376 | break; |
| 2377 | } |
| 2378 | |
| 2379 | } |
| 2380 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2381 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2382 | * igb_sw_init - Initialize general software structures (struct igb_adapter) |
| 2383 | * @adapter: board private structure to initialize |
| 2384 | * |
| 2385 | * igb_sw_init initializes the Adapter private data structure. |
| 2386 | * Fields are initialized based on PCI device information and |
| 2387 | * OS network device settings (MTU size). |
| 2388 | **/ |
| 2389 | static int __devinit igb_sw_init(struct igb_adapter *adapter) |
| 2390 | { |
| 2391 | struct e1000_hw *hw = &adapter->hw; |
| 2392 | struct net_device *netdev = adapter->netdev; |
| 2393 | struct pci_dev *pdev = adapter->pdev; |
| 2394 | |
| 2395 | pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word); |
| 2396 | |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 2397 | /* set default ring sizes */ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 2398 | adapter->tx_ring_count = IGB_DEFAULT_TXD; |
| 2399 | adapter->rx_ring_count = IGB_DEFAULT_RXD; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 2400 | |
| 2401 | /* set default ITR values */ |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 2402 | adapter->rx_itr_setting = IGB_DEFAULT_ITR; |
| 2403 | adapter->tx_itr_setting = IGB_DEFAULT_ITR; |
| 2404 | |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 2405 | /* set default work limits */ |
| 2406 | adapter->tx_work_limit = IGB_DEFAULT_TX_WORK; |
| 2407 | |
Alexander Duyck | 153285f | 2011-08-26 07:43:32 +0000 | [diff] [blame] | 2408 | adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + |
| 2409 | VLAN_HLEN; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2410 | adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; |
| 2411 | |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 2412 | spin_lock_init(&adapter->stats64_lock); |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2413 | #ifdef CONFIG_PCI_IOV |
Carolyn Wyborny | 6b78bb1 | 2011-01-20 06:40:45 +0000 | [diff] [blame] | 2414 | switch (hw->mac.type) { |
| 2415 | case e1000_82576: |
| 2416 | case e1000_i350: |
Stefan Assmann | 9b082d7 | 2011-02-24 20:03:31 +0000 | [diff] [blame] | 2417 | if (max_vfs > 7) { |
| 2418 | dev_warn(&pdev->dev, |
| 2419 | "Maximum of 7 VFs per PF, using max\n"); |
| 2420 | adapter->vfs_allocated_count = 7; |
| 2421 | } else |
| 2422 | adapter->vfs_allocated_count = max_vfs; |
Carolyn Wyborny | 6b78bb1 | 2011-01-20 06:40:45 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | default: |
| 2425 | break; |
| 2426 | } |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2427 | #endif /* CONFIG_PCI_IOV */ |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2428 | adapter->rss_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus()); |
Williams, Mitch A | 665c8c8 | 2011-06-07 14:22:57 -0700 | [diff] [blame] | 2429 | /* i350 cannot do RSS and SR-IOV at the same time */ |
| 2430 | if (hw->mac.type == e1000_i350 && adapter->vfs_allocated_count) |
| 2431 | adapter->rss_queues = 1; |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2432 | |
| 2433 | /* |
| 2434 | * if rss_queues > 4 or vfs are going to be allocated with rss_queues |
| 2435 | * then we should combine the queues into a queue pair in order to |
| 2436 | * conserve interrupts due to limited supply |
| 2437 | */ |
| 2438 | if ((adapter->rss_queues > 4) || |
| 2439 | ((adapter->rss_queues > 1) && (adapter->vfs_allocated_count > 6))) |
| 2440 | adapter->flags |= IGB_FLAG_QUEUE_PAIRS; |
| 2441 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2442 | /* This call may decrease the number of queues */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2443 | if (igb_init_interrupt_scheme(adapter)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2444 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 2445 | return -ENOMEM; |
| 2446 | } |
| 2447 | |
Alexander Duyck | a6b623e | 2009-10-27 23:47:53 +0000 | [diff] [blame] | 2448 | igb_probe_vfs(adapter); |
| 2449 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2450 | /* Explicitly disable IRQ since the NIC can be in any state. */ |
| 2451 | igb_irq_disable(adapter); |
| 2452 | |
Carolyn Wyborny | 831ec0b | 2011-03-11 20:43:54 -0800 | [diff] [blame] | 2453 | if (hw->mac.type == e1000_i350) |
| 2454 | adapter->flags &= ~IGB_FLAG_DMAC; |
| 2455 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2456 | set_bit(__IGB_DOWN, &adapter->state); |
| 2457 | return 0; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * igb_open - Called when a network interface is made active |
| 2462 | * @netdev: network interface device structure |
| 2463 | * |
| 2464 | * Returns 0 on success, negative value on failure |
| 2465 | * |
| 2466 | * The open entry point is called when a network interface is made |
| 2467 | * active by the system (IFF_UP). At this point all resources needed |
| 2468 | * for transmit and receive operations are allocated, the interrupt |
| 2469 | * handler is registered with the OS, the watchdog timer is started, |
| 2470 | * and the stack is notified that the interface is ready. |
| 2471 | **/ |
| 2472 | static int igb_open(struct net_device *netdev) |
| 2473 | { |
| 2474 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 2475 | struct e1000_hw *hw = &adapter->hw; |
| 2476 | int err; |
| 2477 | int i; |
| 2478 | |
| 2479 | /* disallow open during test */ |
| 2480 | if (test_bit(__IGB_TESTING, &adapter->state)) |
| 2481 | return -EBUSY; |
| 2482 | |
Jesse Brandeburg | b168dfc | 2009-04-17 20:44:32 +0000 | [diff] [blame] | 2483 | netif_carrier_off(netdev); |
| 2484 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2485 | /* allocate transmit descriptors */ |
| 2486 | err = igb_setup_all_tx_resources(adapter); |
| 2487 | if (err) |
| 2488 | goto err_setup_tx; |
| 2489 | |
| 2490 | /* allocate receive descriptors */ |
| 2491 | err = igb_setup_all_rx_resources(adapter); |
| 2492 | if (err) |
| 2493 | goto err_setup_rx; |
| 2494 | |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2495 | igb_power_up_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2496 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2497 | /* before we allocate an interrupt, we must be ready to handle it. |
| 2498 | * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt |
| 2499 | * as soon as we call pci_request_irq, so we have to setup our |
| 2500 | * clean_rx handler before we do so. */ |
| 2501 | igb_configure(adapter); |
| 2502 | |
| 2503 | err = igb_request_irq(adapter); |
| 2504 | if (err) |
| 2505 | goto err_req_irq; |
| 2506 | |
| 2507 | /* From here on the code is the same as igb_up() */ |
| 2508 | clear_bit(__IGB_DOWN, &adapter->state); |
| 2509 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 2510 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 2511 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 2512 | napi_enable(&q_vector->napi); |
| 2513 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2514 | |
| 2515 | /* Clear any pending interrupts. */ |
| 2516 | rd32(E1000_ICR); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 2517 | |
| 2518 | igb_irq_enable(adapter); |
| 2519 | |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 2520 | /* notify VFs that reset has been completed */ |
| 2521 | if (adapter->vfs_allocated_count) { |
| 2522 | u32 reg_data = rd32(E1000_CTRL_EXT); |
| 2523 | reg_data |= E1000_CTRL_EXT_PFRSTD; |
| 2524 | wr32(E1000_CTRL_EXT, reg_data); |
| 2525 | } |
| 2526 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 2527 | netif_tx_start_all_queues(netdev); |
| 2528 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 2529 | /* start the watchdog. */ |
| 2530 | hw->mac.get_link_status = 1; |
| 2531 | schedule_work(&adapter->watchdog_task); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2532 | |
| 2533 | return 0; |
| 2534 | |
| 2535 | err_req_irq: |
| 2536 | igb_release_hw_control(adapter); |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 2537 | igb_power_down_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2538 | igb_free_all_rx_resources(adapter); |
| 2539 | err_setup_rx: |
| 2540 | igb_free_all_tx_resources(adapter); |
| 2541 | err_setup_tx: |
| 2542 | igb_reset(adapter); |
| 2543 | |
| 2544 | return err; |
| 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * igb_close - Disables a network interface |
| 2549 | * @netdev: network interface device structure |
| 2550 | * |
| 2551 | * Returns 0, this is not allowed to fail |
| 2552 | * |
| 2553 | * The close entry point is called when an interface is de-activated |
| 2554 | * by the OS. The hardware is still under the driver's control, but |
| 2555 | * needs to be disabled. A global MAC reset is issued to stop the |
| 2556 | * hardware, and all transmit and receive resources are freed. |
| 2557 | **/ |
| 2558 | static int igb_close(struct net_device *netdev) |
| 2559 | { |
| 2560 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 2561 | |
| 2562 | WARN_ON(test_bit(__IGB_RESETTING, &adapter->state)); |
| 2563 | igb_down(adapter); |
| 2564 | |
| 2565 | igb_free_irq(adapter); |
| 2566 | |
| 2567 | igb_free_all_tx_resources(adapter); |
| 2568 | igb_free_all_rx_resources(adapter); |
| 2569 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2570 | return 0; |
| 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * igb_setup_tx_resources - allocate Tx resources (Descriptors) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2575 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
| 2576 | * |
| 2577 | * Return 0 on success, negative on failure |
| 2578 | **/ |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 2579 | int igb_setup_tx_resources(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2580 | { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2581 | struct device *dev = tx_ring->dev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2582 | int size; |
| 2583 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 2584 | size = sizeof(struct igb_tx_buffer) * tx_ring->count; |
| 2585 | tx_ring->tx_buffer_info = vzalloc(size); |
| 2586 | if (!tx_ring->tx_buffer_info) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2587 | goto err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2588 | |
| 2589 | /* round up to nearest 4K */ |
Alexander Duyck | 85e8d00 | 2009-02-16 00:00:20 -0800 | [diff] [blame] | 2590 | tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2591 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2592 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2593 | tx_ring->desc = dma_alloc_coherent(dev, |
| 2594 | tx_ring->size, |
| 2595 | &tx_ring->dma, |
| 2596 | GFP_KERNEL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2597 | |
| 2598 | if (!tx_ring->desc) |
| 2599 | goto err; |
| 2600 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2601 | tx_ring->next_to_use = 0; |
| 2602 | tx_ring->next_to_clean = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2603 | return 0; |
| 2604 | |
| 2605 | err: |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 2606 | vfree(tx_ring->tx_buffer_info); |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2607 | dev_err(dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2608 | "Unable to allocate memory for the transmit descriptor ring\n"); |
| 2609 | return -ENOMEM; |
| 2610 | } |
| 2611 | |
| 2612 | /** |
| 2613 | * igb_setup_all_tx_resources - wrapper to allocate Tx resources |
| 2614 | * (Descriptors) for all queues |
| 2615 | * @adapter: board private structure |
| 2616 | * |
| 2617 | * Return 0 on success, negative on failure |
| 2618 | **/ |
| 2619 | static int igb_setup_all_tx_resources(struct igb_adapter *adapter) |
| 2620 | { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2621 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2622 | int i, err = 0; |
| 2623 | |
| 2624 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2625 | err = igb_setup_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2626 | if (err) { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2627 | dev_err(&pdev->dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2628 | "Allocation for Tx Queue %u failed\n", i); |
| 2629 | for (i--; i >= 0; i--) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2630 | igb_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2631 | break; |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | return err; |
| 2636 | } |
| 2637 | |
| 2638 | /** |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2639 | * igb_setup_tctl - configure the transmit control registers |
| 2640 | * @adapter: Board private structure |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2641 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2642 | void igb_setup_tctl(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2643 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2644 | struct e1000_hw *hw = &adapter->hw; |
| 2645 | u32 tctl; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2646 | |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2647 | /* disable queue 0 which is enabled by default on 82575 and 82576 */ |
| 2648 | wr32(E1000_TXDCTL(0), 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2649 | |
| 2650 | /* Program the Transmit Control Register */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2651 | tctl = rd32(E1000_TCTL); |
| 2652 | tctl &= ~E1000_TCTL_CT; |
| 2653 | tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC | |
| 2654 | (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT); |
| 2655 | |
| 2656 | igb_config_collision_dist(hw); |
| 2657 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2658 | /* Enable transmits */ |
| 2659 | tctl |= E1000_TCTL_EN; |
| 2660 | |
| 2661 | wr32(E1000_TCTL, tctl); |
| 2662 | } |
| 2663 | |
| 2664 | /** |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2665 | * igb_configure_tx_ring - Configure transmit ring after Reset |
| 2666 | * @adapter: board private structure |
| 2667 | * @ring: tx ring to configure |
| 2668 | * |
| 2669 | * Configure a transmit ring after a reset. |
| 2670 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2671 | void igb_configure_tx_ring(struct igb_adapter *adapter, |
| 2672 | struct igb_ring *ring) |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2673 | { |
| 2674 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 2675 | u32 txdctl = 0; |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2676 | u64 tdba = ring->dma; |
| 2677 | int reg_idx = ring->reg_idx; |
| 2678 | |
| 2679 | /* disable the queue */ |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 2680 | wr32(E1000_TXDCTL(reg_idx), 0); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2681 | wrfl(); |
| 2682 | mdelay(10); |
| 2683 | |
| 2684 | wr32(E1000_TDLEN(reg_idx), |
| 2685 | ring->count * sizeof(union e1000_adv_tx_desc)); |
| 2686 | wr32(E1000_TDBAL(reg_idx), |
| 2687 | tdba & 0x00000000ffffffffULL); |
| 2688 | wr32(E1000_TDBAH(reg_idx), tdba >> 32); |
| 2689 | |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 2690 | ring->tail = hw->hw_addr + E1000_TDT(reg_idx); |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 2691 | wr32(E1000_TDH(reg_idx), 0); |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 2692 | writel(0, ring->tail); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2693 | |
| 2694 | txdctl |= IGB_TX_PTHRESH; |
| 2695 | txdctl |= IGB_TX_HTHRESH << 8; |
| 2696 | txdctl |= IGB_TX_WTHRESH << 16; |
| 2697 | |
| 2698 | txdctl |= E1000_TXDCTL_QUEUE_ENABLE; |
| 2699 | wr32(E1000_TXDCTL(reg_idx), txdctl); |
| 2700 | } |
| 2701 | |
| 2702 | /** |
| 2703 | * igb_configure_tx - Configure transmit Unit after Reset |
| 2704 | * @adapter: board private structure |
| 2705 | * |
| 2706 | * Configure the Tx unit of the MAC after a reset. |
| 2707 | **/ |
| 2708 | static void igb_configure_tx(struct igb_adapter *adapter) |
| 2709 | { |
| 2710 | int i; |
| 2711 | |
| 2712 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2713 | igb_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2717 | * igb_setup_rx_resources - allocate Rx resources (Descriptors) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2718 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 2719 | * |
| 2720 | * Returns 0 on success, negative on failure |
| 2721 | **/ |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 2722 | int igb_setup_rx_resources(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2723 | { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2724 | struct device *dev = rx_ring->dev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2725 | int size, desc_len; |
| 2726 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 2727 | size = sizeof(struct igb_rx_buffer) * rx_ring->count; |
| 2728 | rx_ring->rx_buffer_info = vzalloc(size); |
| 2729 | if (!rx_ring->rx_buffer_info) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2730 | goto err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2731 | |
| 2732 | desc_len = sizeof(union e1000_adv_rx_desc); |
| 2733 | |
| 2734 | /* Round up to nearest 4K */ |
| 2735 | rx_ring->size = rx_ring->count * desc_len; |
| 2736 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2737 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2738 | rx_ring->desc = dma_alloc_coherent(dev, |
| 2739 | rx_ring->size, |
| 2740 | &rx_ring->dma, |
| 2741 | GFP_KERNEL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2742 | |
| 2743 | if (!rx_ring->desc) |
| 2744 | goto err; |
| 2745 | |
| 2746 | rx_ring->next_to_clean = 0; |
| 2747 | rx_ring->next_to_use = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2748 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2749 | return 0; |
| 2750 | |
| 2751 | err: |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 2752 | vfree(rx_ring->rx_buffer_info); |
| 2753 | rx_ring->rx_buffer_info = NULL; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 2754 | dev_err(dev, "Unable to allocate memory for the receive descriptor" |
| 2755 | " ring\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2756 | return -ENOMEM; |
| 2757 | } |
| 2758 | |
| 2759 | /** |
| 2760 | * igb_setup_all_rx_resources - wrapper to allocate Rx resources |
| 2761 | * (Descriptors) for all queues |
| 2762 | * @adapter: board private structure |
| 2763 | * |
| 2764 | * Return 0 on success, negative on failure |
| 2765 | **/ |
| 2766 | static int igb_setup_all_rx_resources(struct igb_adapter *adapter) |
| 2767 | { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2768 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2769 | int i, err = 0; |
| 2770 | |
| 2771 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2772 | err = igb_setup_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2773 | if (err) { |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 2774 | dev_err(&pdev->dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2775 | "Allocation for Rx Queue %u failed\n", i); |
| 2776 | for (i--; i >= 0; i--) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 2777 | igb_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2778 | break; |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | return err; |
| 2783 | } |
| 2784 | |
| 2785 | /** |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2786 | * igb_setup_mrqc - configure the multiple receive queue control registers |
| 2787 | * @adapter: Board private structure |
| 2788 | **/ |
| 2789 | static void igb_setup_mrqc(struct igb_adapter *adapter) |
| 2790 | { |
| 2791 | struct e1000_hw *hw = &adapter->hw; |
| 2792 | u32 mrqc, rxcsum; |
| 2793 | u32 j, num_rx_queues, shift = 0, shift2 = 0; |
| 2794 | union e1000_reta { |
| 2795 | u32 dword; |
| 2796 | u8 bytes[4]; |
| 2797 | } reta; |
| 2798 | static const u8 rsshash[40] = { |
| 2799 | 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67, |
| 2800 | 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb, |
| 2801 | 0xae, 0x7b, 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, |
| 2802 | 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa }; |
| 2803 | |
| 2804 | /* Fill out hash function seeds */ |
| 2805 | for (j = 0; j < 10; j++) { |
| 2806 | u32 rsskey = rsshash[(j * 4)]; |
| 2807 | rsskey |= rsshash[(j * 4) + 1] << 8; |
| 2808 | rsskey |= rsshash[(j * 4) + 2] << 16; |
| 2809 | rsskey |= rsshash[(j * 4) + 3] << 24; |
| 2810 | array_wr32(E1000_RSSRK(0), j, rsskey); |
| 2811 | } |
| 2812 | |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2813 | num_rx_queues = adapter->rss_queues; |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2814 | |
| 2815 | if (adapter->vfs_allocated_count) { |
| 2816 | /* 82575 and 82576 supports 2 RSS queues for VMDq */ |
| 2817 | switch (hw->mac.type) { |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 2818 | case e1000_i350: |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 2819 | case e1000_82580: |
| 2820 | num_rx_queues = 1; |
| 2821 | shift = 0; |
| 2822 | break; |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2823 | case e1000_82576: |
| 2824 | shift = 3; |
| 2825 | num_rx_queues = 2; |
| 2826 | break; |
| 2827 | case e1000_82575: |
| 2828 | shift = 2; |
| 2829 | shift2 = 6; |
| 2830 | default: |
| 2831 | break; |
| 2832 | } |
| 2833 | } else { |
| 2834 | if (hw->mac.type == e1000_82575) |
| 2835 | shift = 6; |
| 2836 | } |
| 2837 | |
| 2838 | for (j = 0; j < (32 * 4); j++) { |
| 2839 | reta.bytes[j & 3] = (j % num_rx_queues) << shift; |
| 2840 | if (shift2) |
| 2841 | reta.bytes[j & 3] |= num_rx_queues << shift2; |
| 2842 | if ((j & 3) == 3) |
| 2843 | wr32(E1000_RETA(j >> 2), reta.dword); |
| 2844 | } |
| 2845 | |
| 2846 | /* |
| 2847 | * Disable raw packet checksumming so that RSS hash is placed in |
| 2848 | * descriptor on writeback. No need to enable TCP/UDP/IP checksum |
| 2849 | * offloads as they are enabled by default |
| 2850 | */ |
| 2851 | rxcsum = rd32(E1000_RXCSUM); |
| 2852 | rxcsum |= E1000_RXCSUM_PCSD; |
| 2853 | |
| 2854 | if (adapter->hw.mac.type >= e1000_82576) |
| 2855 | /* Enable Receive Checksum Offload for SCTP */ |
| 2856 | rxcsum |= E1000_RXCSUM_CRCOFL; |
| 2857 | |
| 2858 | /* Don't need to set TUOFL or IPOFL, they default to 1 */ |
| 2859 | wr32(E1000_RXCSUM, rxcsum); |
| 2860 | |
| 2861 | /* If VMDq is enabled then we set the appropriate mode for that, else |
| 2862 | * we default to RSS so that an RSS hash is calculated per packet even |
| 2863 | * if we are only using one queue */ |
| 2864 | if (adapter->vfs_allocated_count) { |
| 2865 | if (hw->mac.type > e1000_82575) { |
| 2866 | /* Set the default pool for the PF's first queue */ |
| 2867 | u32 vtctl = rd32(E1000_VT_CTL); |
| 2868 | vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK | |
| 2869 | E1000_VT_CTL_DISABLE_DEF_POOL); |
| 2870 | vtctl |= adapter->vfs_allocated_count << |
| 2871 | E1000_VT_CTL_DEFAULT_POOL_SHIFT; |
| 2872 | wr32(E1000_VT_CTL, vtctl); |
| 2873 | } |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 2874 | if (adapter->rss_queues > 1) |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2875 | mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q; |
| 2876 | else |
| 2877 | mrqc = E1000_MRQC_ENABLE_VMDQ; |
| 2878 | } else { |
| 2879 | mrqc = E1000_MRQC_ENABLE_RSS_4Q; |
| 2880 | } |
| 2881 | igb_vmm_control(adapter); |
| 2882 | |
Alexander Duyck | 4478a9c | 2010-07-01 20:01:05 +0000 | [diff] [blame] | 2883 | /* |
| 2884 | * Generate RSS hash based on TCP port numbers and/or |
| 2885 | * IPv4/v6 src and dst addresses since UDP cannot be |
| 2886 | * hashed reliably due to IP fragmentation |
| 2887 | */ |
| 2888 | mrqc |= E1000_MRQC_RSS_FIELD_IPV4 | |
| 2889 | E1000_MRQC_RSS_FIELD_IPV4_TCP | |
| 2890 | E1000_MRQC_RSS_FIELD_IPV6 | |
| 2891 | E1000_MRQC_RSS_FIELD_IPV6_TCP | |
| 2892 | E1000_MRQC_RSS_FIELD_IPV6_TCP_EX; |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 2893 | |
| 2894 | wr32(E1000_MRQC, mrqc); |
| 2895 | } |
| 2896 | |
| 2897 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2898 | * igb_setup_rctl - configure the receive control registers |
| 2899 | * @adapter: Board private structure |
| 2900 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 2901 | void igb_setup_rctl(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2902 | { |
| 2903 | struct e1000_hw *hw = &adapter->hw; |
| 2904 | u32 rctl; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2905 | |
| 2906 | rctl = rd32(E1000_RCTL); |
| 2907 | |
| 2908 | rctl &= ~(3 << E1000_RCTL_MO_SHIFT); |
Alexander Duyck | 69d728b | 2008-11-25 01:04:03 -0800 | [diff] [blame] | 2909 | rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2910 | |
Alexander Duyck | 69d728b | 2008-11-25 01:04:03 -0800 | [diff] [blame] | 2911 | rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF | |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 2912 | (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2913 | |
Auke Kok | 87cb7e8 | 2008-07-08 15:08:29 -0700 | [diff] [blame] | 2914 | /* |
| 2915 | * enable stripping of CRC. It's unlikely this will break BMC |
| 2916 | * redirection as it did with e1000. Newer features require |
| 2917 | * that the HW strips the CRC. |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 2918 | */ |
Auke Kok | 87cb7e8 | 2008-07-08 15:08:29 -0700 | [diff] [blame] | 2919 | rctl |= E1000_RCTL_SECRC; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2920 | |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 2921 | /* disable store bad packets and clear size bits. */ |
Alexander Duyck | ec54d7d | 2009-01-31 00:52:57 -0800 | [diff] [blame] | 2922 | rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2923 | |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 2924 | /* enable LPE to prevent packets larger than max_frame_size */ |
| 2925 | rctl |= E1000_RCTL_LPE; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2926 | |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 2927 | /* disable queue 0 to prevent tail write w/o re-config */ |
| 2928 | wr32(E1000_RXDCTL(0), 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2929 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2930 | /* Attention!!! For SR-IOV PF driver operations you must enable |
| 2931 | * queue drop for all VF and PF queues to prevent head of line blocking |
| 2932 | * if an un-trusted VF does not provide descriptors to hardware. |
| 2933 | */ |
| 2934 | if (adapter->vfs_allocated_count) { |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2935 | /* set all queue drop enable bits */ |
| 2936 | wr32(E1000_QDE, ALL_QUEUES); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2937 | } |
| 2938 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2939 | wr32(E1000_RCTL, rctl); |
| 2940 | } |
| 2941 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2942 | static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size, |
| 2943 | int vfn) |
| 2944 | { |
| 2945 | struct e1000_hw *hw = &adapter->hw; |
| 2946 | u32 vmolr; |
| 2947 | |
| 2948 | /* if it isn't the PF check to see if VFs are enabled and |
| 2949 | * increase the size to support vlan tags */ |
| 2950 | if (vfn < adapter->vfs_allocated_count && |
| 2951 | adapter->vf_data[vfn].vlans_enabled) |
| 2952 | size += VLAN_TAG_SIZE; |
| 2953 | |
| 2954 | vmolr = rd32(E1000_VMOLR(vfn)); |
| 2955 | vmolr &= ~E1000_VMOLR_RLPML_MASK; |
| 2956 | vmolr |= size | E1000_VMOLR_LPE; |
| 2957 | wr32(E1000_VMOLR(vfn), vmolr); |
| 2958 | |
| 2959 | return 0; |
| 2960 | } |
| 2961 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2962 | /** |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2963 | * igb_rlpml_set - set maximum receive packet size |
| 2964 | * @adapter: board private structure |
| 2965 | * |
| 2966 | * Configure maximum receivable packet size. |
| 2967 | **/ |
| 2968 | static void igb_rlpml_set(struct igb_adapter *adapter) |
| 2969 | { |
Alexander Duyck | 153285f | 2011-08-26 07:43:32 +0000 | [diff] [blame] | 2970 | u32 max_frame_size = adapter->max_frame_size; |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2971 | struct e1000_hw *hw = &adapter->hw; |
| 2972 | u16 pf_id = adapter->vfs_allocated_count; |
| 2973 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2974 | if (pf_id) { |
| 2975 | igb_set_vf_rlpml(adapter, max_frame_size, pf_id); |
Alexander Duyck | 153285f | 2011-08-26 07:43:32 +0000 | [diff] [blame] | 2976 | /* |
| 2977 | * If we're in VMDQ or SR-IOV mode, then set global RLPML |
| 2978 | * to our max jumbo frame size, in case we need to enable |
| 2979 | * jumbo frames on one of the rings later. |
| 2980 | * This will not pass over-length frames into the default |
| 2981 | * queue because it's gated by the VMOLR.RLPML. |
| 2982 | */ |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2983 | max_frame_size = MAX_JUMBO_FRAME_SIZE; |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | wr32(E1000_RLPML, max_frame_size); |
| 2987 | } |
| 2988 | |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 2989 | static inline void igb_set_vmolr(struct igb_adapter *adapter, |
| 2990 | int vfn, bool aupe) |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 2991 | { |
| 2992 | struct e1000_hw *hw = &adapter->hw; |
| 2993 | u32 vmolr; |
| 2994 | |
| 2995 | /* |
| 2996 | * This register exists only on 82576 and newer so if we are older then |
| 2997 | * we should exit and do nothing |
| 2998 | */ |
| 2999 | if (hw->mac.type < e1000_82576) |
| 3000 | return; |
| 3001 | |
| 3002 | vmolr = rd32(E1000_VMOLR(vfn)); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 3003 | vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */ |
| 3004 | if (aupe) |
| 3005 | vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */ |
| 3006 | else |
| 3007 | vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */ |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 3008 | |
| 3009 | /* clear all bits that might not be set */ |
| 3010 | vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE); |
| 3011 | |
Alexander Duyck | a99955f | 2009-11-12 18:37:19 +0000 | [diff] [blame] | 3012 | if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count) |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 3013 | vmolr |= E1000_VMOLR_RSSE; /* enable RSS */ |
| 3014 | /* |
| 3015 | * for VMDq only allow the VFs and pool 0 to accept broadcast and |
| 3016 | * multicast packets |
| 3017 | */ |
| 3018 | if (vfn <= adapter->vfs_allocated_count) |
| 3019 | vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */ |
| 3020 | |
| 3021 | wr32(E1000_VMOLR(vfn), vmolr); |
| 3022 | } |
| 3023 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 3024 | /** |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3025 | * igb_configure_rx_ring - Configure a receive ring after Reset |
| 3026 | * @adapter: board private structure |
| 3027 | * @ring: receive ring to be configured |
| 3028 | * |
| 3029 | * Configure the Rx unit of the MAC after a reset. |
| 3030 | **/ |
Alexander Duyck | d7ee5b3 | 2009-10-27 15:54:23 +0000 | [diff] [blame] | 3031 | void igb_configure_rx_ring(struct igb_adapter *adapter, |
| 3032 | struct igb_ring *ring) |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3033 | { |
| 3034 | struct e1000_hw *hw = &adapter->hw; |
| 3035 | u64 rdba = ring->dma; |
| 3036 | int reg_idx = ring->reg_idx; |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 3037 | u32 srrctl = 0, rxdctl = 0; |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3038 | |
| 3039 | /* disable the queue */ |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 3040 | wr32(E1000_RXDCTL(reg_idx), 0); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3041 | |
| 3042 | /* Set DMA base address registers */ |
| 3043 | wr32(E1000_RDBAL(reg_idx), |
| 3044 | rdba & 0x00000000ffffffffULL); |
| 3045 | wr32(E1000_RDBAH(reg_idx), rdba >> 32); |
| 3046 | wr32(E1000_RDLEN(reg_idx), |
| 3047 | ring->count * sizeof(union e1000_adv_rx_desc)); |
| 3048 | |
| 3049 | /* initialize head and tail */ |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 3050 | ring->tail = hw->hw_addr + E1000_RDT(reg_idx); |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 3051 | wr32(E1000_RDH(reg_idx), 0); |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 3052 | writel(0, ring->tail); |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3053 | |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 3054 | /* set descriptor configuration */ |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 3055 | srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 3056 | #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384 |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 3057 | srrctl |= IGB_RXBUFFER_16384 >> E1000_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 3058 | #else |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 3059 | srrctl |= (PAGE_SIZE / 2) >> E1000_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 3060 | #endif |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 3061 | srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 3062 | if (hw->mac.type == e1000_82580) |
| 3063 | srrctl |= E1000_SRRCTL_TIMESTAMP; |
Nick Nunley | e6bdb6f | 2010-02-17 01:03:38 +0000 | [diff] [blame] | 3064 | /* Only set Drop Enable if we are supporting multiple queues */ |
| 3065 | if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1) |
| 3066 | srrctl |= E1000_SRRCTL_DROP_EN; |
Alexander Duyck | 952f72a | 2009-10-27 15:51:07 +0000 | [diff] [blame] | 3067 | |
| 3068 | wr32(E1000_SRRCTL(reg_idx), srrctl); |
| 3069 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 3070 | /* set filtering for VMDQ pools */ |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 3071 | igb_set_vmolr(adapter, reg_idx & 0x7, true); |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 3072 | |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3073 | rxdctl |= IGB_RX_PTHRESH; |
| 3074 | rxdctl |= IGB_RX_HTHRESH << 8; |
| 3075 | rxdctl |= IGB_RX_WTHRESH << 16; |
Alexander Duyck | a74420e | 2011-08-26 07:43:27 +0000 | [diff] [blame] | 3076 | |
| 3077 | /* enable receive descriptor fetching */ |
| 3078 | rxdctl |= E1000_RXDCTL_QUEUE_ENABLE; |
Alexander Duyck | 85b430b | 2009-10-27 15:50:29 +0000 | [diff] [blame] | 3079 | wr32(E1000_RXDCTL(reg_idx), rxdctl); |
| 3080 | } |
| 3081 | |
| 3082 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3083 | * igb_configure_rx - Configure receive Unit after Reset |
| 3084 | * @adapter: board private structure |
| 3085 | * |
| 3086 | * Configure the Rx unit of the MAC after a reset. |
| 3087 | **/ |
| 3088 | static void igb_configure_rx(struct igb_adapter *adapter) |
| 3089 | { |
Hannes Eder | 9107584 | 2009-02-18 19:36:04 -0800 | [diff] [blame] | 3090 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3091 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3092 | /* set UTA to appropriate mode */ |
| 3093 | igb_set_uta(adapter); |
| 3094 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 3095 | /* set the correct pool for the PF default MAC address in entry 0 */ |
| 3096 | igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0, |
| 3097 | adapter->vfs_allocated_count); |
| 3098 | |
Alexander Duyck | 06cf266 | 2009-10-27 15:53:25 +0000 | [diff] [blame] | 3099 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3100 | * the Base and Length of the Rx Descriptor Ring */ |
| 3101 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3102 | igb_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | /** |
| 3106 | * igb_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3107 | * @tx_ring: Tx descriptor ring for a specific queue |
| 3108 | * |
| 3109 | * Free all transmit software resources |
| 3110 | **/ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 3111 | void igb_free_tx_resources(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3112 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3113 | igb_clean_tx_ring(tx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3114 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3115 | vfree(tx_ring->tx_buffer_info); |
| 3116 | tx_ring->tx_buffer_info = NULL; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3117 | |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 3118 | /* if not set, then don't free */ |
| 3119 | if (!tx_ring->desc) |
| 3120 | return; |
| 3121 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3122 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 3123 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3124 | |
| 3125 | tx_ring->desc = NULL; |
| 3126 | } |
| 3127 | |
| 3128 | /** |
| 3129 | * igb_free_all_tx_resources - Free Tx Resources for All Queues |
| 3130 | * @adapter: board private structure |
| 3131 | * |
| 3132 | * Free all transmit software resources |
| 3133 | **/ |
| 3134 | static void igb_free_all_tx_resources(struct igb_adapter *adapter) |
| 3135 | { |
| 3136 | int i; |
| 3137 | |
| 3138 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3139 | igb_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3140 | } |
| 3141 | |
Alexander Duyck | b1a436c | 2009-10-27 15:54:43 +0000 | [diff] [blame] | 3142 | void igb_unmap_and_free_tx_resource(struct igb_ring *tx_ring, |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3143 | struct igb_tx_buffer *buffer_info) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3144 | { |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3145 | if (buffer_info->dma) { |
| 3146 | if (buffer_info->mapped_as_page) |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3147 | dma_unmap_page(tx_ring->dev, |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3148 | buffer_info->dma, |
| 3149 | buffer_info->length, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3150 | DMA_TO_DEVICE); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3151 | else |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3152 | dma_unmap_single(tx_ring->dev, |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3153 | buffer_info->dma, |
| 3154 | buffer_info->length, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3155 | DMA_TO_DEVICE); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3156 | buffer_info->dma = 0; |
| 3157 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3158 | if (buffer_info->skb) { |
| 3159 | dev_kfree_skb_any(buffer_info->skb); |
| 3160 | buffer_info->skb = NULL; |
| 3161 | } |
| 3162 | buffer_info->time_stamp = 0; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 3163 | buffer_info->length = 0; |
| 3164 | buffer_info->next_to_watch = 0; |
| 3165 | buffer_info->mapped_as_page = false; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | /** |
| 3169 | * igb_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3170 | * @tx_ring: ring to be cleaned |
| 3171 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3172 | static void igb_clean_tx_ring(struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3173 | { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3174 | struct igb_tx_buffer *buffer_info; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3175 | unsigned long size; |
| 3176 | unsigned int i; |
| 3177 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3178 | if (!tx_ring->tx_buffer_info) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3179 | return; |
| 3180 | /* Free all the Tx ring sk_buffs */ |
| 3181 | |
| 3182 | for (i = 0; i < tx_ring->count; i++) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3183 | buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3184 | igb_unmap_and_free_tx_resource(tx_ring, buffer_info); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3185 | } |
| 3186 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3187 | size = sizeof(struct igb_tx_buffer) * tx_ring->count; |
| 3188 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3189 | |
| 3190 | /* Zero out the descriptor ring */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3191 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3192 | |
| 3193 | tx_ring->next_to_use = 0; |
| 3194 | tx_ring->next_to_clean = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | /** |
| 3198 | * igb_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3199 | * @adapter: board private structure |
| 3200 | **/ |
| 3201 | static void igb_clean_all_tx_rings(struct igb_adapter *adapter) |
| 3202 | { |
| 3203 | int i; |
| 3204 | |
| 3205 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3206 | igb_clean_tx_ring(adapter->tx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * igb_free_rx_resources - Free Rx Resources |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3211 | * @rx_ring: ring to clean the resources from |
| 3212 | * |
| 3213 | * Free all receive software resources |
| 3214 | **/ |
Alexander Duyck | 68fd991 | 2008-11-20 00:48:10 -0800 | [diff] [blame] | 3215 | void igb_free_rx_resources(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3216 | { |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3217 | igb_clean_rx_ring(rx_ring); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3218 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3219 | vfree(rx_ring->rx_buffer_info); |
| 3220 | rx_ring->rx_buffer_info = NULL; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3221 | |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 3222 | /* if not set, then don't free */ |
| 3223 | if (!rx_ring->desc) |
| 3224 | return; |
| 3225 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3226 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 3227 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3228 | |
| 3229 | rx_ring->desc = NULL; |
| 3230 | } |
| 3231 | |
| 3232 | /** |
| 3233 | * igb_free_all_rx_resources - Free Rx Resources for All Queues |
| 3234 | * @adapter: board private structure |
| 3235 | * |
| 3236 | * Free all receive software resources |
| 3237 | **/ |
| 3238 | static void igb_free_all_rx_resources(struct igb_adapter *adapter) |
| 3239 | { |
| 3240 | int i; |
| 3241 | |
| 3242 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3243 | igb_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | /** |
| 3247 | * igb_clean_rx_ring - Free Rx Buffers per Queue |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3248 | * @rx_ring: ring to free buffers from |
| 3249 | **/ |
Mitch Williams | 3b644cf | 2008-06-27 10:59:48 -0700 | [diff] [blame] | 3250 | static void igb_clean_rx_ring(struct igb_ring *rx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3251 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3252 | unsigned long size; |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 3253 | u16 i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3254 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3255 | if (!rx_ring->rx_buffer_info) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3256 | return; |
Alexander Duyck | 439705e | 2009-10-27 23:49:20 +0000 | [diff] [blame] | 3257 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3258 | /* Free all the Rx ring sk_buffs */ |
| 3259 | for (i = 0; i < rx_ring->count; i++) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3260 | struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3261 | if (buffer_info->dma) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3262 | dma_unmap_single(rx_ring->dev, |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3263 | buffer_info->dma, |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 3264 | IGB_RX_HDR_LEN, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3265 | DMA_FROM_DEVICE); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3266 | buffer_info->dma = 0; |
| 3267 | } |
| 3268 | |
| 3269 | if (buffer_info->skb) { |
| 3270 | dev_kfree_skb(buffer_info->skb); |
| 3271 | buffer_info->skb = NULL; |
| 3272 | } |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 3273 | if (buffer_info->page_dma) { |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3274 | dma_unmap_page(rx_ring->dev, |
Alexander Duyck | 8078529 | 2009-10-27 15:51:47 +0000 | [diff] [blame] | 3275 | buffer_info->page_dma, |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 3276 | PAGE_SIZE / 2, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 3277 | DMA_FROM_DEVICE); |
Alexander Duyck | 6ec43fe | 2009-10-27 15:50:48 +0000 | [diff] [blame] | 3278 | buffer_info->page_dma = 0; |
| 3279 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3280 | if (buffer_info->page) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3281 | put_page(buffer_info->page); |
| 3282 | buffer_info->page = NULL; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 3283 | buffer_info->page_offset = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3284 | } |
| 3285 | } |
| 3286 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 3287 | size = sizeof(struct igb_rx_buffer) * rx_ring->count; |
| 3288 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3289 | |
| 3290 | /* Zero out the descriptor ring */ |
| 3291 | memset(rx_ring->desc, 0, rx_ring->size); |
| 3292 | |
| 3293 | rx_ring->next_to_clean = 0; |
| 3294 | rx_ring->next_to_use = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | /** |
| 3298 | * igb_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3299 | * @adapter: board private structure |
| 3300 | **/ |
| 3301 | static void igb_clean_all_rx_rings(struct igb_adapter *adapter) |
| 3302 | { |
| 3303 | int i; |
| 3304 | |
| 3305 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3306 | igb_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | /** |
| 3310 | * igb_set_mac - Change the Ethernet Address of the NIC |
| 3311 | * @netdev: network interface device structure |
| 3312 | * @p: pointer to an address structure |
| 3313 | * |
| 3314 | * Returns 0 on success, negative on failure |
| 3315 | **/ |
| 3316 | static int igb_set_mac(struct net_device *netdev, void *p) |
| 3317 | { |
| 3318 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 3319 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3320 | struct sockaddr *addr = p; |
| 3321 | |
| 3322 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3323 | return -EADDRNOTAVAIL; |
| 3324 | |
| 3325 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Alexander Duyck | 28b0759 | 2009-02-06 23:20:31 +0000 | [diff] [blame] | 3326 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3327 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 3328 | /* set the correct pool for the new PF MAC address in entry 0 */ |
| 3329 | igb_rar_set_qsel(adapter, hw->mac.addr, 0, |
| 3330 | adapter->vfs_allocated_count); |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 3331 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3332 | return 0; |
| 3333 | } |
| 3334 | |
| 3335 | /** |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3336 | * igb_write_mc_addr_list - write multicast addresses to MTA |
| 3337 | * @netdev: network interface device structure |
| 3338 | * |
| 3339 | * Writes multicast address list to the MTA hash table. |
| 3340 | * Returns: -ENOMEM on failure |
| 3341 | * 0 on no addresses written |
| 3342 | * X on writing X addresses to MTA |
| 3343 | **/ |
| 3344 | static int igb_write_mc_addr_list(struct net_device *netdev) |
| 3345 | { |
| 3346 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3347 | struct e1000_hw *hw = &adapter->hw; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3348 | struct netdev_hw_addr *ha; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3349 | u8 *mta_list; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3350 | int i; |
| 3351 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3352 | if (netdev_mc_empty(netdev)) { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3353 | /* nothing to program, so clear mc list */ |
| 3354 | igb_update_mc_addr_list(hw, NULL, 0); |
| 3355 | igb_restore_vf_multicasts(adapter); |
| 3356 | return 0; |
| 3357 | } |
| 3358 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3359 | mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3360 | if (!mta_list) |
| 3361 | return -ENOMEM; |
| 3362 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3363 | /* The shared function expects a packed array of only addresses. */ |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 3364 | i = 0; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3365 | netdev_for_each_mc_addr(ha, netdev) |
| 3366 | memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3367 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3368 | igb_update_mc_addr_list(hw, mta_list, i); |
| 3369 | kfree(mta_list); |
| 3370 | |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 3371 | return netdev_mc_count(netdev); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | /** |
| 3375 | * igb_write_uc_addr_list - write unicast addresses to RAR table |
| 3376 | * @netdev: network interface device structure |
| 3377 | * |
| 3378 | * Writes unicast address list to the RAR table. |
| 3379 | * Returns: -ENOMEM on failure/insufficient address space |
| 3380 | * 0 on no addresses written |
| 3381 | * X on writing X addresses to the RAR table |
| 3382 | **/ |
| 3383 | static int igb_write_uc_addr_list(struct net_device *netdev) |
| 3384 | { |
| 3385 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3386 | struct e1000_hw *hw = &adapter->hw; |
| 3387 | unsigned int vfn = adapter->vfs_allocated_count; |
| 3388 | unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1); |
| 3389 | int count = 0; |
| 3390 | |
| 3391 | /* return ENOMEM indicating insufficient memory for addresses */ |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 3392 | if (netdev_uc_count(netdev) > rar_entries) |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3393 | return -ENOMEM; |
| 3394 | |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 3395 | if (!netdev_uc_empty(netdev) && rar_entries) { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3396 | struct netdev_hw_addr *ha; |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 3397 | |
| 3398 | netdev_for_each_uc_addr(ha, netdev) { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3399 | if (!rar_entries) |
| 3400 | break; |
| 3401 | igb_rar_set_qsel(adapter, ha->addr, |
| 3402 | rar_entries--, |
| 3403 | vfn); |
| 3404 | count++; |
| 3405 | } |
| 3406 | } |
| 3407 | /* write the addresses in reverse order to avoid write combining */ |
| 3408 | for (; rar_entries > 0 ; rar_entries--) { |
| 3409 | wr32(E1000_RAH(rar_entries), 0); |
| 3410 | wr32(E1000_RAL(rar_entries), 0); |
| 3411 | } |
| 3412 | wrfl(); |
| 3413 | |
| 3414 | return count; |
| 3415 | } |
| 3416 | |
| 3417 | /** |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3418 | * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3419 | * @netdev: network interface device structure |
| 3420 | * |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3421 | * The set_rx_mode entry point is called whenever the unicast or multicast |
| 3422 | * address lists or the network interface flags are updated. This routine is |
| 3423 | * responsible for configuring the hardware for proper unicast, multicast, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3424 | * promiscuous mode, and all-multi behavior. |
| 3425 | **/ |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3426 | static void igb_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3427 | { |
| 3428 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 3429 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3430 | unsigned int vfn = adapter->vfs_allocated_count; |
| 3431 | u32 rctl, vmolr = 0; |
| 3432 | int count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3433 | |
| 3434 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3435 | rctl = rd32(E1000_RCTL); |
| 3436 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3437 | /* clear the effected bits */ |
| 3438 | rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE); |
| 3439 | |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3440 | if (netdev->flags & IFF_PROMISC) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3441 | rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE); |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3442 | vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME); |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3443 | } else { |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3444 | if (netdev->flags & IFF_ALLMULTI) { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3445 | rctl |= E1000_RCTL_MPE; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3446 | vmolr |= E1000_VMOLR_MPME; |
| 3447 | } else { |
| 3448 | /* |
| 3449 | * Write addresses to the MTA, if the attempt fails |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3450 | * then we should just turn on promiscuous mode so |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3451 | * that we can at least receive multicast traffic |
| 3452 | */ |
| 3453 | count = igb_write_mc_addr_list(netdev); |
| 3454 | if (count < 0) { |
| 3455 | rctl |= E1000_RCTL_MPE; |
| 3456 | vmolr |= E1000_VMOLR_MPME; |
| 3457 | } else if (count) { |
| 3458 | vmolr |= E1000_VMOLR_ROMPE; |
| 3459 | } |
| 3460 | } |
| 3461 | /* |
| 3462 | * Write addresses to available RAR registers, if there is not |
| 3463 | * sufficient space to store all the addresses then enable |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3464 | * unicast promiscuous mode |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3465 | */ |
| 3466 | count = igb_write_uc_addr_list(netdev); |
| 3467 | if (count < 0) { |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 3468 | rctl |= E1000_RCTL_UPE; |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3469 | vmolr |= E1000_VMOLR_ROPE; |
| 3470 | } |
Patrick McHardy | 78ed11a | 2008-07-16 20:16:14 -0700 | [diff] [blame] | 3471 | rctl |= E1000_RCTL_VFE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3472 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3473 | wr32(E1000_RCTL, rctl); |
| 3474 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3475 | /* |
| 3476 | * In order to support SR-IOV and eventually VMDq it is necessary to set |
| 3477 | * the VMOLR to enable the appropriate modes. Without this workaround |
| 3478 | * we will have issues with VLAN tag stripping not being done for frames |
| 3479 | * that are only arriving because we are the default pool |
| 3480 | */ |
| 3481 | if (hw->mac.type < e1000_82576) |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame] | 3482 | return; |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame] | 3483 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 3484 | vmolr |= rd32(E1000_VMOLR(vfn)) & |
| 3485 | ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE); |
| 3486 | wr32(E1000_VMOLR(vfn), vmolr); |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame] | 3487 | igb_restore_vf_multicasts(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3488 | } |
| 3489 | |
Greg Rose | 1380046 | 2010-11-06 02:08:26 +0000 | [diff] [blame] | 3490 | static void igb_check_wvbr(struct igb_adapter *adapter) |
| 3491 | { |
| 3492 | struct e1000_hw *hw = &adapter->hw; |
| 3493 | u32 wvbr = 0; |
| 3494 | |
| 3495 | switch (hw->mac.type) { |
| 3496 | case e1000_82576: |
| 3497 | case e1000_i350: |
| 3498 | if (!(wvbr = rd32(E1000_WVBR))) |
| 3499 | return; |
| 3500 | break; |
| 3501 | default: |
| 3502 | break; |
| 3503 | } |
| 3504 | |
| 3505 | adapter->wvbr |= wvbr; |
| 3506 | } |
| 3507 | |
| 3508 | #define IGB_STAGGERED_QUEUE_OFFSET 8 |
| 3509 | |
| 3510 | static void igb_spoof_check(struct igb_adapter *adapter) |
| 3511 | { |
| 3512 | int j; |
| 3513 | |
| 3514 | if (!adapter->wvbr) |
| 3515 | return; |
| 3516 | |
| 3517 | for(j = 0; j < adapter->vfs_allocated_count; j++) { |
| 3518 | if (adapter->wvbr & (1 << j) || |
| 3519 | adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) { |
| 3520 | dev_warn(&adapter->pdev->dev, |
| 3521 | "Spoof event(s) detected on VF %d\n", j); |
| 3522 | adapter->wvbr &= |
| 3523 | ~((1 << j) | |
| 3524 | (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))); |
| 3525 | } |
| 3526 | } |
| 3527 | } |
| 3528 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3529 | /* Need to wait a few seconds after link up to get diagnostic information from |
| 3530 | * the phy */ |
| 3531 | static void igb_update_phy_info(unsigned long data) |
| 3532 | { |
| 3533 | struct igb_adapter *adapter = (struct igb_adapter *) data; |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 3534 | igb_get_phy_info(&adapter->hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | /** |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3538 | * igb_has_link - check shared code for link and determine up/down |
| 3539 | * @adapter: pointer to driver private info |
| 3540 | **/ |
Nick Nunley | 3145535 | 2010-02-17 01:01:21 +0000 | [diff] [blame] | 3541 | bool igb_has_link(struct igb_adapter *adapter) |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3542 | { |
| 3543 | struct e1000_hw *hw = &adapter->hw; |
| 3544 | bool link_active = false; |
| 3545 | s32 ret_val = 0; |
| 3546 | |
| 3547 | /* get_link_status is set on LSC (link status) interrupt or |
| 3548 | * rx sequence error interrupt. get_link_status will stay |
| 3549 | * false until the e1000_check_for_link establishes link |
| 3550 | * for copper adapters ONLY |
| 3551 | */ |
| 3552 | switch (hw->phy.media_type) { |
| 3553 | case e1000_media_type_copper: |
| 3554 | if (hw->mac.get_link_status) { |
| 3555 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3556 | link_active = !hw->mac.get_link_status; |
| 3557 | } else { |
| 3558 | link_active = true; |
| 3559 | } |
| 3560 | break; |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3561 | case e1000_media_type_internal_serdes: |
| 3562 | ret_val = hw->mac.ops.check_for_link(hw); |
| 3563 | link_active = hw->mac.serdes_has_link; |
| 3564 | break; |
| 3565 | default: |
| 3566 | case e1000_media_type_unknown: |
| 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | return link_active; |
| 3571 | } |
| 3572 | |
Stefan Assmann | 563988d | 2011-04-05 04:27:15 +0000 | [diff] [blame] | 3573 | static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event) |
| 3574 | { |
| 3575 | bool ret = false; |
| 3576 | u32 ctrl_ext, thstat; |
| 3577 | |
| 3578 | /* check for thermal sensor event on i350, copper only */ |
| 3579 | if (hw->mac.type == e1000_i350) { |
| 3580 | thstat = rd32(E1000_THSTAT); |
| 3581 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 3582 | |
| 3583 | if ((hw->phy.media_type == e1000_media_type_copper) && |
| 3584 | !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) { |
| 3585 | ret = !!(thstat & event); |
| 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | return ret; |
| 3590 | } |
| 3591 | |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3592 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3593 | * igb_watchdog - Timer Call-back |
| 3594 | * @data: pointer to adapter cast into an unsigned long |
| 3595 | **/ |
| 3596 | static void igb_watchdog(unsigned long data) |
| 3597 | { |
| 3598 | struct igb_adapter *adapter = (struct igb_adapter *)data; |
| 3599 | /* Do the rest outside of interrupt context */ |
| 3600 | schedule_work(&adapter->watchdog_task); |
| 3601 | } |
| 3602 | |
| 3603 | static void igb_watchdog_task(struct work_struct *work) |
| 3604 | { |
| 3605 | struct igb_adapter *adapter = container_of(work, |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 3606 | struct igb_adapter, |
| 3607 | watchdog_task); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3608 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3609 | struct net_device *netdev = adapter->netdev; |
Stefan Assmann | 563988d | 2011-04-05 04:27:15 +0000 | [diff] [blame] | 3610 | u32 link; |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 3611 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3612 | |
Alexander Duyck | 4d6b725 | 2009-02-06 23:16:24 +0000 | [diff] [blame] | 3613 | link = igb_has_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3614 | if (link) { |
| 3615 | if (!netif_carrier_ok(netdev)) { |
| 3616 | u32 ctrl; |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 3617 | hw->mac.ops.get_speed_and_duplex(hw, |
| 3618 | &adapter->link_speed, |
| 3619 | &adapter->link_duplex); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3620 | |
| 3621 | ctrl = rd32(E1000_CTRL); |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 3622 | /* Links status message must follow this format */ |
| 3623 | printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, " |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3624 | "Flow Control: %s\n", |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 3625 | netdev->name, |
| 3626 | adapter->link_speed, |
| 3627 | adapter->link_duplex == FULL_DUPLEX ? |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3628 | "Full Duplex" : "Half Duplex", |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 3629 | ((ctrl & E1000_CTRL_TFCE) && |
| 3630 | (ctrl & E1000_CTRL_RFCE)) ? "RX/TX" : |
| 3631 | ((ctrl & E1000_CTRL_RFCE) ? "RX" : |
| 3632 | ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None"))); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3633 | |
Stefan Assmann | 563988d | 2011-04-05 04:27:15 +0000 | [diff] [blame] | 3634 | /* check for thermal sensor event */ |
| 3635 | if (igb_thermal_sensor_event(hw, E1000_THSTAT_LINK_THROTTLE)) { |
| 3636 | printk(KERN_INFO "igb: %s The network adapter " |
| 3637 | "link speed was downshifted " |
| 3638 | "because it overheated.\n", |
| 3639 | netdev->name); |
Carolyn Wyborny | 7ef5ed1 | 2011-03-12 08:59:47 +0000 | [diff] [blame] | 3640 | } |
Stefan Assmann | 563988d | 2011-04-05 04:27:15 +0000 | [diff] [blame] | 3641 | |
Emil Tantilov | d07f3e3 | 2010-03-23 18:34:57 +0000 | [diff] [blame] | 3642 | /* adjust timeout factor according to speed/duplex */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3643 | adapter->tx_timeout_factor = 1; |
| 3644 | switch (adapter->link_speed) { |
| 3645 | case SPEED_10: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3646 | adapter->tx_timeout_factor = 14; |
| 3647 | break; |
| 3648 | case SPEED_100: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3649 | /* maybe add some timeout factor ? */ |
| 3650 | break; |
| 3651 | } |
| 3652 | |
| 3653 | netif_carrier_on(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3654 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3655 | igb_ping_all_vfs(adapter); |
Lior Levy | 17dc566 | 2011-02-08 02:28:46 +0000 | [diff] [blame] | 3656 | igb_check_vf_rate_limit(adapter); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3657 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 3658 | /* link state has changed, schedule phy info update */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3659 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3660 | mod_timer(&adapter->phy_info_timer, |
| 3661 | round_jiffies(jiffies + 2 * HZ)); |
| 3662 | } |
| 3663 | } else { |
| 3664 | if (netif_carrier_ok(netdev)) { |
| 3665 | adapter->link_speed = 0; |
| 3666 | adapter->link_duplex = 0; |
Stefan Assmann | 563988d | 2011-04-05 04:27:15 +0000 | [diff] [blame] | 3667 | |
| 3668 | /* check for thermal sensor event */ |
| 3669 | if (igb_thermal_sensor_event(hw, E1000_THSTAT_PWR_DOWN)) { |
| 3670 | printk(KERN_ERR "igb: %s The network adapter " |
| 3671 | "was stopped because it " |
| 3672 | "overheated.\n", |
Carolyn Wyborny | 7ef5ed1 | 2011-03-12 08:59:47 +0000 | [diff] [blame] | 3673 | netdev->name); |
Carolyn Wyborny | 7ef5ed1 | 2011-03-12 08:59:47 +0000 | [diff] [blame] | 3674 | } |
Stefan Assmann | 563988d | 2011-04-05 04:27:15 +0000 | [diff] [blame] | 3675 | |
Alexander Duyck | 527d47c | 2008-11-27 00:21:39 -0800 | [diff] [blame] | 3676 | /* Links status message must follow this format */ |
| 3677 | printk(KERN_INFO "igb: %s NIC Link is Down\n", |
| 3678 | netdev->name); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3679 | netif_carrier_off(netdev); |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 3680 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 3681 | igb_ping_all_vfs(adapter); |
| 3682 | |
Alexander Duyck | 4b1a987 | 2009-02-06 23:19:50 +0000 | [diff] [blame] | 3683 | /* link state has changed, schedule phy info update */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3684 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3685 | mod_timer(&adapter->phy_info_timer, |
| 3686 | round_jiffies(jiffies + 2 * HZ)); |
| 3687 | } |
| 3688 | } |
| 3689 | |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 3690 | spin_lock(&adapter->stats64_lock); |
| 3691 | igb_update_stats(adapter, &adapter->stats64); |
| 3692 | spin_unlock(&adapter->stats64_lock); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3693 | |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3694 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3695 | struct igb_ring *tx_ring = adapter->tx_ring[i]; |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3696 | if (!netif_carrier_ok(netdev)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3697 | /* We've lost link, so the controller stops DMA, |
| 3698 | * but we've got queued Tx work that's never going |
| 3699 | * to get done, so reset controller to flush Tx. |
| 3700 | * (Do the reset outside of interrupt context). */ |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3701 | if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) { |
| 3702 | adapter->tx_timeout_count++; |
| 3703 | schedule_work(&adapter->reset_task); |
| 3704 | /* return immediately since reset is imminent */ |
| 3705 | return; |
| 3706 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3707 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3708 | |
Alexander Duyck | dbabb06 | 2009-11-12 18:38:16 +0000 | [diff] [blame] | 3709 | /* Force detection of hung controller every watchdog period */ |
| 3710 | tx_ring->detect_tx_hung = true; |
| 3711 | } |
Alexander Duyck | f7ba205 | 2009-10-27 23:48:51 +0000 | [diff] [blame] | 3712 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3713 | /* Cause software interrupt to ensure rx ring is cleaned */ |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 3714 | if (adapter->msix_entries) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3715 | u32 eics = 0; |
| 3716 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 3717 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 3718 | eics |= q_vector->eims_value; |
| 3719 | } |
Alexander Duyck | 7a6ea55 | 2008-08-26 04:25:03 -0700 | [diff] [blame] | 3720 | wr32(E1000_EICS, eics); |
| 3721 | } else { |
| 3722 | wr32(E1000_ICS, E1000_ICS_RXDMT0); |
| 3723 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3724 | |
Greg Rose | 1380046 | 2010-11-06 02:08:26 +0000 | [diff] [blame] | 3725 | igb_spoof_check(adapter); |
| 3726 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3727 | /* Reset the timer */ |
| 3728 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 3729 | mod_timer(&adapter->watchdog_timer, |
| 3730 | round_jiffies(jiffies + 2 * HZ)); |
| 3731 | } |
| 3732 | |
| 3733 | enum latency_range { |
| 3734 | lowest_latency = 0, |
| 3735 | low_latency = 1, |
| 3736 | bulk_latency = 2, |
| 3737 | latency_invalid = 255 |
| 3738 | }; |
| 3739 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3740 | /** |
| 3741 | * igb_update_ring_itr - update the dynamic ITR value based on packet size |
| 3742 | * |
| 3743 | * Stores a new ITR value based on strictly on packet size. This |
| 3744 | * algorithm is less sophisticated than that used in igb_update_itr, |
| 3745 | * due to the difficulty of synchronizing statistics across multiple |
Stefan Weil | eef35c2 | 2010-08-06 21:11:15 +0200 | [diff] [blame] | 3746 | * receive rings. The divisors and thresholds used by this function |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3747 | * were determined based on theoretical maximum wire speed and testing |
| 3748 | * data, in order to minimize response time while increasing bulk |
| 3749 | * throughput. |
| 3750 | * This functionality is controlled by the InterruptThrottleRate module |
| 3751 | * parameter (see igb_param.c) |
| 3752 | * NOTE: This function is called only when operating in a multiqueue |
| 3753 | * receive environment. |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3754 | * @q_vector: pointer to q_vector |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3755 | **/ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3756 | static void igb_update_ring_itr(struct igb_q_vector *q_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3757 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3758 | int new_val = q_vector->itr_val; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3759 | int avg_wire_size = 0; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3760 | struct igb_adapter *adapter = q_vector->adapter; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 3761 | struct igb_ring *ring; |
| 3762 | unsigned int packets; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3763 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3764 | /* For non-gigabit speeds, just fix the interrupt rate at 4000 |
| 3765 | * ints/sec - ITR timer value of 120 ticks. |
| 3766 | */ |
| 3767 | if (adapter->link_speed != SPEED_1000) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3768 | new_val = 976; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3769 | goto set_itr_val; |
| 3770 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3771 | |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 3772 | ring = q_vector->rx_ring; |
| 3773 | if (ring) { |
| 3774 | packets = ACCESS_ONCE(ring->total_packets); |
| 3775 | |
| 3776 | if (packets) |
| 3777 | avg_wire_size = ring->total_bytes / packets; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 3780 | ring = q_vector->tx_ring; |
| 3781 | if (ring) { |
| 3782 | packets = ACCESS_ONCE(ring->total_packets); |
| 3783 | |
| 3784 | if (packets) |
| 3785 | avg_wire_size = max_t(u32, avg_wire_size, |
| 3786 | ring->total_bytes / packets); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | /* if avg_wire_size isn't set no work was done */ |
| 3790 | if (!avg_wire_size) |
| 3791 | goto clear_counts; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3792 | |
| 3793 | /* Add 24 bytes to size to account for CRC, preamble, and gap */ |
| 3794 | avg_wire_size += 24; |
| 3795 | |
| 3796 | /* Don't starve jumbo frames */ |
| 3797 | avg_wire_size = min(avg_wire_size, 3000); |
| 3798 | |
| 3799 | /* Give a little boost to mid-size frames */ |
| 3800 | if ((avg_wire_size > 300) && (avg_wire_size < 1200)) |
| 3801 | new_val = avg_wire_size / 3; |
| 3802 | else |
| 3803 | new_val = avg_wire_size / 2; |
| 3804 | |
Nick Nunley | abe1c36 | 2010-02-17 01:03:19 +0000 | [diff] [blame] | 3805 | /* when in itr mode 3 do not exceed 20K ints/sec */ |
| 3806 | if (adapter->rx_itr_setting == 3 && new_val < 196) |
| 3807 | new_val = 196; |
| 3808 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3809 | set_itr_val: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3810 | if (new_val != q_vector->itr_val) { |
| 3811 | q_vector->itr_val = new_val; |
| 3812 | q_vector->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3813 | } |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3814 | clear_counts: |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3815 | if (q_vector->rx_ring) { |
| 3816 | q_vector->rx_ring->total_bytes = 0; |
| 3817 | q_vector->rx_ring->total_packets = 0; |
| 3818 | } |
| 3819 | if (q_vector->tx_ring) { |
| 3820 | q_vector->tx_ring->total_bytes = 0; |
| 3821 | q_vector->tx_ring->total_packets = 0; |
| 3822 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * igb_update_itr - update the dynamic ITR value based on statistics |
| 3827 | * Stores a new ITR value based on packets and byte |
| 3828 | * counts during the last interrupt. The advantage of per interrupt |
| 3829 | * computation is faster updates and more accurate ITR for the current |
| 3830 | * traffic pattern. Constants in this function were computed |
| 3831 | * based on theoretical maximum wire speed and thresholds were set based |
| 3832 | * on testing data as well as attempting to minimize response time |
| 3833 | * while increasing bulk throughput. |
| 3834 | * this functionality is controlled by the InterruptThrottleRate module |
| 3835 | * parameter (see igb_param.c) |
| 3836 | * NOTE: These calculations are only valid when operating in a single- |
| 3837 | * queue environment. |
| 3838 | * @adapter: pointer to adapter |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3839 | * @itr_setting: current q_vector->itr_val |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3840 | * @packets: the number of packets during this measurement interval |
| 3841 | * @bytes: the number of bytes during this measurement interval |
| 3842 | **/ |
| 3843 | static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting, |
| 3844 | int packets, int bytes) |
| 3845 | { |
| 3846 | unsigned int retval = itr_setting; |
| 3847 | |
| 3848 | if (packets == 0) |
| 3849 | goto update_itr_done; |
| 3850 | |
| 3851 | switch (itr_setting) { |
| 3852 | case lowest_latency: |
| 3853 | /* handle TSO and jumbo frames */ |
| 3854 | if (bytes/packets > 8000) |
| 3855 | retval = bulk_latency; |
| 3856 | else if ((packets < 5) && (bytes > 512)) |
| 3857 | retval = low_latency; |
| 3858 | break; |
| 3859 | case low_latency: /* 50 usec aka 20000 ints/s */ |
| 3860 | if (bytes > 10000) { |
| 3861 | /* this if handles the TSO accounting */ |
| 3862 | if (bytes/packets > 8000) { |
| 3863 | retval = bulk_latency; |
| 3864 | } else if ((packets < 10) || ((bytes/packets) > 1200)) { |
| 3865 | retval = bulk_latency; |
| 3866 | } else if ((packets > 35)) { |
| 3867 | retval = lowest_latency; |
| 3868 | } |
| 3869 | } else if (bytes/packets > 2000) { |
| 3870 | retval = bulk_latency; |
| 3871 | } else if (packets <= 2 && bytes < 512) { |
| 3872 | retval = lowest_latency; |
| 3873 | } |
| 3874 | break; |
| 3875 | case bulk_latency: /* 250 usec aka 4000 ints/s */ |
| 3876 | if (bytes > 25000) { |
| 3877 | if (packets > 35) |
| 3878 | retval = low_latency; |
Alexander Duyck | 1e5c3d2 | 2009-02-12 18:17:21 +0000 | [diff] [blame] | 3879 | } else if (bytes < 1500) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3880 | retval = low_latency; |
| 3881 | } |
| 3882 | break; |
| 3883 | } |
| 3884 | |
| 3885 | update_itr_done: |
| 3886 | return retval; |
| 3887 | } |
| 3888 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3889 | static void igb_set_itr(struct igb_adapter *adapter) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3890 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3891 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3892 | u16 current_itr; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3893 | u32 new_itr = q_vector->itr_val; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3894 | |
| 3895 | /* for non-gigabit speeds, just fix the interrupt rate at 4000 */ |
| 3896 | if (adapter->link_speed != SPEED_1000) { |
| 3897 | current_itr = 0; |
| 3898 | new_itr = 4000; |
| 3899 | goto set_itr_now; |
| 3900 | } |
| 3901 | |
| 3902 | adapter->rx_itr = igb_update_itr(adapter, |
| 3903 | adapter->rx_itr, |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3904 | q_vector->rx_ring->total_packets, |
| 3905 | q_vector->rx_ring->total_bytes); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3906 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3907 | adapter->tx_itr = igb_update_itr(adapter, |
| 3908 | adapter->tx_itr, |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3909 | q_vector->tx_ring->total_packets, |
| 3910 | q_vector->tx_ring->total_bytes); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3911 | current_itr = max(adapter->rx_itr, adapter->tx_itr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3912 | |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3913 | /* conservative mode (itr 3) eliminates the lowest_latency setting */ |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 3914 | if (adapter->rx_itr_setting == 3 && current_itr == lowest_latency) |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3915 | current_itr = low_latency; |
| 3916 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3917 | switch (current_itr) { |
| 3918 | /* counts and packets in update_itr are dependent on these numbers */ |
| 3919 | case lowest_latency: |
Alexander Duyck | 78b1f60 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 3920 | new_itr = 56; /* aka 70,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3921 | break; |
| 3922 | case low_latency: |
Alexander Duyck | 78b1f60 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 3923 | new_itr = 196; /* aka 20,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3924 | break; |
| 3925 | case bulk_latency: |
Alexander Duyck | 78b1f60 | 2009-04-23 11:20:29 +0000 | [diff] [blame] | 3926 | new_itr = 980; /* aka 4,000 ints/sec */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3927 | break; |
| 3928 | default: |
| 3929 | break; |
| 3930 | } |
| 3931 | |
| 3932 | set_itr_now: |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 3933 | q_vector->rx_ring->total_bytes = 0; |
| 3934 | q_vector->rx_ring->total_packets = 0; |
| 3935 | q_vector->tx_ring->total_bytes = 0; |
| 3936 | q_vector->tx_ring->total_packets = 0; |
Alexander Duyck | 6eb5a7f | 2008-07-08 15:14:44 -0700 | [diff] [blame] | 3937 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3938 | if (new_itr != q_vector->itr_val) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3939 | /* this attempts to bias the interrupt rate towards Bulk |
| 3940 | * by adding intermediate steps when interrupt rate is |
| 3941 | * increasing */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3942 | new_itr = new_itr > q_vector->itr_val ? |
| 3943 | max((new_itr * q_vector->itr_val) / |
| 3944 | (new_itr + (q_vector->itr_val >> 2)), |
| 3945 | new_itr) : |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3946 | new_itr; |
| 3947 | /* Don't write the value here; it resets the adapter's |
| 3948 | * internal timer, and causes us to delay far longer than |
| 3949 | * we should between interrupts. Instead, we write the ITR |
| 3950 | * value at the beginning of the next interrupt so the timing |
| 3951 | * ends up being correct. |
| 3952 | */ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 3953 | q_vector->itr_val = new_itr; |
| 3954 | q_vector->set_itr = 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3955 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3956 | } |
| 3957 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3958 | #define IGB_TX_FLAGS_CSUM 0x00000001 |
| 3959 | #define IGB_TX_FLAGS_VLAN 0x00000002 |
| 3960 | #define IGB_TX_FLAGS_TSO 0x00000004 |
| 3961 | #define IGB_TX_FLAGS_IPV4 0x00000008 |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 3962 | #define IGB_TX_FLAGS_TSTAMP 0x00000010 |
| 3963 | #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000 |
| 3964 | #define IGB_TX_FLAGS_VLAN_SHIFT 16 |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3965 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 3966 | void igb_tx_ctxtdesc(struct igb_ring *tx_ring, u32 vlan_macip_lens, |
| 3967 | u32 type_tucmd, u32 mss_l4len_idx) |
| 3968 | { |
| 3969 | struct e1000_adv_tx_context_desc *context_desc; |
| 3970 | u16 i = tx_ring->next_to_use; |
| 3971 | |
| 3972 | context_desc = IGB_TX_CTXTDESC(tx_ring, i); |
| 3973 | |
| 3974 | i++; |
| 3975 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 3976 | |
| 3977 | /* set bits to identify this as an advanced context descriptor */ |
| 3978 | type_tucmd |= E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT; |
| 3979 | |
| 3980 | /* For 82575, context index must be unique per ring. */ |
| 3981 | if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) |
| 3982 | mss_l4len_idx |= tx_ring->reg_idx << 4; |
| 3983 | |
| 3984 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 3985 | context_desc->seqnum_seed = 0; |
| 3986 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 3987 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 3988 | } |
| 3989 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 3990 | static inline int igb_tso(struct igb_ring *tx_ring, |
| 3991 | struct sk_buff *skb, u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3992 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3993 | int err; |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 3994 | u32 vlan_macip_lens, type_tucmd; |
| 3995 | u32 mss_l4len_idx, l4len; |
| 3996 | |
| 3997 | if (!skb_is_gso(skb)) |
| 3998 | return 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 3999 | |
| 4000 | if (skb_header_cloned(skb)) { |
| 4001 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4002 | if (err) |
| 4003 | return err; |
| 4004 | } |
| 4005 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4006 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 4007 | type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4008 | |
| 4009 | if (skb->protocol == htons(ETH_P_IP)) { |
| 4010 | struct iphdr *iph = ip_hdr(skb); |
| 4011 | iph->tot_len = 0; |
| 4012 | iph->check = 0; |
| 4013 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 4014 | iph->daddr, 0, |
| 4015 | IPPROTO_TCP, |
| 4016 | 0); |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4017 | type_tucmd |= E1000_ADVTXD_TUCMD_IPV4; |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 4018 | } else if (skb_is_gso_v6(skb)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4019 | ipv6_hdr(skb)->payload_len = 0; |
| 4020 | tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 4021 | &ipv6_hdr(skb)->daddr, |
| 4022 | 0, IPPROTO_TCP, 0); |
| 4023 | } |
| 4024 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4025 | l4len = tcp_hdrlen(skb); |
| 4026 | *hdr_len = skb_transport_offset(skb) + l4len; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4027 | |
| 4028 | /* MSS L4LEN IDX */ |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4029 | mss_l4len_idx = l4len << E1000_ADVTXD_L4LEN_SHIFT; |
| 4030 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4031 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4032 | /* VLAN MACLEN IPLEN */ |
| 4033 | vlan_macip_lens = skb_network_header_len(skb); |
| 4034 | vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT; |
| 4035 | vlan_macip_lens |= tx_flags & IGB_TX_FLAGS_VLAN_MASK; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4036 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4037 | igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4038 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4039 | return 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4042 | static inline bool igb_tx_csum(struct igb_ring *tx_ring, |
| 4043 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4044 | { |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4045 | u32 vlan_macip_lens = 0; |
| 4046 | u32 mss_l4len_idx = 0; |
| 4047 | u32 type_tucmd = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4048 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4049 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
| 4050 | if (!(tx_flags & IGB_TX_FLAGS_VLAN)) |
| 4051 | return false; |
| 4052 | } else { |
| 4053 | u8 l4_hdr = 0; |
| 4054 | switch (skb->protocol) { |
| 4055 | case __constant_htons(ETH_P_IP): |
| 4056 | vlan_macip_lens |= skb_network_header_len(skb); |
| 4057 | type_tucmd |= E1000_ADVTXD_TUCMD_IPV4; |
| 4058 | l4_hdr = ip_hdr(skb)->protocol; |
| 4059 | break; |
| 4060 | case __constant_htons(ETH_P_IPV6): |
| 4061 | vlan_macip_lens |= skb_network_header_len(skb); |
| 4062 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 4063 | break; |
| 4064 | default: |
| 4065 | if (unlikely(net_ratelimit())) { |
| 4066 | dev_warn(tx_ring->dev, |
| 4067 | "partial checksum but proto=%x!\n", |
| 4068 | skb->protocol); |
Arthur Jones | fa4a7ef | 2009-03-21 16:55:07 -0700 | [diff] [blame] | 4069 | } |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4070 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4071 | } |
| 4072 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4073 | switch (l4_hdr) { |
| 4074 | case IPPROTO_TCP: |
| 4075 | type_tucmd |= E1000_ADVTXD_TUCMD_L4T_TCP; |
| 4076 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 4077 | E1000_ADVTXD_L4LEN_SHIFT; |
| 4078 | break; |
| 4079 | case IPPROTO_SCTP: |
| 4080 | type_tucmd |= E1000_ADVTXD_TUCMD_L4T_SCTP; |
| 4081 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 4082 | E1000_ADVTXD_L4LEN_SHIFT; |
| 4083 | break; |
| 4084 | case IPPROTO_UDP: |
| 4085 | mss_l4len_idx = sizeof(struct udphdr) << |
| 4086 | E1000_ADVTXD_L4LEN_SHIFT; |
| 4087 | break; |
| 4088 | default: |
| 4089 | if (unlikely(net_ratelimit())) { |
| 4090 | dev_warn(tx_ring->dev, |
| 4091 | "partial checksum but l4 proto=%x!\n", |
| 4092 | l4_hdr); |
| 4093 | } |
| 4094 | break; |
| 4095 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4096 | } |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4097 | |
| 4098 | vlan_macip_lens |= skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT; |
| 4099 | vlan_macip_lens |= tx_flags & IGB_TX_FLAGS_VLAN_MASK; |
| 4100 | |
| 4101 | igb_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, mss_l4len_idx); |
| 4102 | |
| 4103 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | #define IGB_MAX_TXD_PWR 16 |
| 4107 | #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR) |
| 4108 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4109 | static inline int igb_tx_map(struct igb_ring *tx_ring, struct sk_buff *skb, |
| 4110 | unsigned int first) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4111 | { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4112 | struct igb_tx_buffer *buffer_info; |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 4113 | struct device *dev = tx_ring->dev; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 4114 | unsigned int hlen = skb_headlen(skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4115 | unsigned int count = 0, i; |
| 4116 | unsigned int f; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 4117 | u16 gso_segs = skb_shinfo(skb)->gso_segs ?: 1; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4118 | |
| 4119 | i = tx_ring->next_to_use; |
| 4120 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4121 | buffer_info = &tx_ring->tx_buffer_info[i]; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 4122 | BUG_ON(hlen >= IGB_MAX_DATA_PER_TXD); |
| 4123 | buffer_info->length = hlen; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4124 | buffer_info->next_to_watch = i; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 4125 | buffer_info->dma = dma_map_single(dev, skb->data, hlen, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 4126 | DMA_TO_DEVICE); |
| 4127 | if (dma_mapping_error(dev, buffer_info->dma)) |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4128 | goto dma_error; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4129 | |
| 4130 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 4131 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[f]; |
| 4132 | unsigned int len = frag->size; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4133 | |
Alexander Duyck | 8581145 | 2010-01-23 01:35:00 -0800 | [diff] [blame] | 4134 | count++; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4135 | i++; |
| 4136 | if (i == tx_ring->count) |
| 4137 | i = 0; |
| 4138 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4139 | buffer_info = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4140 | BUG_ON(len >= IGB_MAX_DATA_PER_TXD); |
| 4141 | buffer_info->length = len; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4142 | buffer_info->next_to_watch = i; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4143 | buffer_info->mapped_as_page = true; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 4144 | buffer_info->dma = skb_frag_dma_map(dev, frag, 0, len, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 4145 | DMA_TO_DEVICE); |
| 4146 | if (dma_mapping_error(dev, buffer_info->dma)) |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4147 | goto dma_error; |
| 4148 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4149 | } |
| 4150 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4151 | buffer_info->skb = skb; |
| 4152 | buffer_info->tx_flags = skb_shinfo(skb)->tx_flags; |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 4153 | /* multiply data chunks by size of headers */ |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4154 | buffer_info->bytecount = ((gso_segs - 1) * hlen) + skb->len; |
| 4155 | buffer_info->gso_segs = gso_segs; |
| 4156 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4157 | tx_ring->tx_buffer_info[first].time_stamp = jiffies; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4158 | |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4159 | return ++count; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4160 | |
| 4161 | dma_error: |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 4162 | dev_err(dev, "TX DMA map failed\n"); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4163 | |
| 4164 | /* clear timestamp and dma mappings for failed buffer_info mapping */ |
| 4165 | buffer_info->dma = 0; |
| 4166 | buffer_info->time_stamp = 0; |
| 4167 | buffer_info->length = 0; |
| 4168 | buffer_info->next_to_watch = 0; |
| 4169 | buffer_info->mapped_as_page = false; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4170 | |
| 4171 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Nick Nunley | a77ff70 | 2010-02-17 01:06:16 +0000 | [diff] [blame] | 4172 | while (count--) { |
| 4173 | if (i == 0) |
| 4174 | i = tx_ring->count; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4175 | i--; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4176 | buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4177 | igb_unmap_and_free_tx_resource(tx_ring, buffer_info); |
| 4178 | } |
| 4179 | |
| 4180 | return 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4181 | } |
| 4182 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4183 | static inline void igb_tx_queue(struct igb_ring *tx_ring, |
| 4184 | u32 tx_flags, int count, u32 paylen, |
| 4185 | u8 hdr_len) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4186 | { |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4187 | union e1000_adv_tx_desc *tx_desc; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4188 | struct igb_tx_buffer *buffer_info; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4189 | u32 olinfo_status = 0, cmd_type_len; |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4190 | unsigned int i = tx_ring->next_to_use; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4191 | |
| 4192 | cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS | |
| 4193 | E1000_ADVTXD_DCMD_DEXT); |
| 4194 | |
| 4195 | if (tx_flags & IGB_TX_FLAGS_VLAN) |
| 4196 | cmd_type_len |= E1000_ADVTXD_DCMD_VLE; |
| 4197 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4198 | if (tx_flags & IGB_TX_FLAGS_TSTAMP) |
| 4199 | cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP; |
| 4200 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4201 | if (tx_flags & IGB_TX_FLAGS_TSO) { |
| 4202 | cmd_type_len |= E1000_ADVTXD_DCMD_TSE; |
| 4203 | |
| 4204 | /* insert tcp checksum */ |
| 4205 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; |
| 4206 | |
| 4207 | /* insert ip checksum */ |
| 4208 | if (tx_flags & IGB_TX_FLAGS_IPV4) |
| 4209 | olinfo_status |= E1000_TXD_POPTS_IXSM << 8; |
| 4210 | |
| 4211 | } else if (tx_flags & IGB_TX_FLAGS_CSUM) { |
| 4212 | olinfo_status |= E1000_TXD_POPTS_TXSM << 8; |
| 4213 | } |
| 4214 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4215 | if ((tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) && |
| 4216 | (tx_flags & (IGB_TX_FLAGS_CSUM | |
| 4217 | IGB_TX_FLAGS_TSO | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4218 | IGB_TX_FLAGS_VLAN))) |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4219 | olinfo_status |= tx_ring->reg_idx << 4; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4220 | |
| 4221 | olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT); |
| 4222 | |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4223 | do { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4224 | buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 4225 | tx_desc = IGB_TX_DESC(tx_ring, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4226 | tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma); |
| 4227 | tx_desc->read.cmd_type_len = |
| 4228 | cpu_to_le32(cmd_type_len | buffer_info->length); |
| 4229 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4230 | count--; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4231 | i++; |
| 4232 | if (i == tx_ring->count) |
| 4233 | i = 0; |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4234 | } while (count > 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4235 | |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4236 | tx_desc->read.cmd_type_len |= cpu_to_le32(IGB_ADVTXD_DCMD); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4237 | /* Force memory writes to complete before letting h/w |
| 4238 | * know there are new descriptors to fetch. (Only |
| 4239 | * applicable for weak-ordered memory model archs, |
| 4240 | * such as IA-64). */ |
| 4241 | wmb(); |
| 4242 | |
| 4243 | tx_ring->next_to_use = i; |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 4244 | writel(i, tx_ring->tail); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4245 | /* we need this if more than one processor can write to our tail |
| 4246 | * at a time, it syncronizes IO on IA64/Altix systems */ |
| 4247 | mmiowb(); |
| 4248 | } |
| 4249 | |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4250 | static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, int size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4251 | { |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4252 | struct net_device *netdev = tx_ring->netdev; |
| 4253 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4254 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4255 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4256 | /* Herbert's original patch had: |
| 4257 | * smp_mb__after_netif_stop_queue(); |
| 4258 | * but since that doesn't exist yet, just open code it. */ |
| 4259 | smp_mb(); |
| 4260 | |
| 4261 | /* We need to check again in a case another CPU has just |
| 4262 | * made room available. */ |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 4263 | if (igb_desc_unused(tx_ring) < size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4264 | return -EBUSY; |
| 4265 | |
| 4266 | /* A reprieve! */ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4267 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4268 | |
| 4269 | u64_stats_update_begin(&tx_ring->tx_syncp2); |
| 4270 | tx_ring->tx_stats.restart_queue2++; |
| 4271 | u64_stats_update_end(&tx_ring->tx_syncp2); |
| 4272 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4273 | return 0; |
| 4274 | } |
| 4275 | |
Nick Nunley | 717ba08 | 2010-02-17 01:04:18 +0000 | [diff] [blame] | 4276 | static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, int size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4277 | { |
Alexander Duyck | c493ea4 | 2009-03-20 00:16:50 +0000 | [diff] [blame] | 4278 | if (igb_desc_unused(tx_ring) >= size) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4279 | return 0; |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4280 | return __igb_maybe_stop_tx(tx_ring, size); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4281 | } |
| 4282 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4283 | netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb, |
| 4284 | struct igb_ring *tx_ring) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4285 | { |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4286 | int tso, count; |
Nick Nunley | 91d4ee3 | 2010-02-17 01:04:56 +0000 | [diff] [blame] | 4287 | u32 tx_flags = 0; |
| 4288 | u16 first; |
| 4289 | u8 hdr_len = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4290 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4291 | /* need: 1 descriptor per page, |
| 4292 | * + 2 desc gap to keep tail from touching head, |
| 4293 | * + 1 desc for skb->data, |
| 4294 | * + 1 desc for context descriptor, |
| 4295 | * otherwise try next time */ |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4296 | if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4297 | /* this is a hard error */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4298 | return NETDEV_TX_BUSY; |
| 4299 | } |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4300 | |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 4301 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { |
| 4302 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4303 | tx_flags |= IGB_TX_FLAGS_TSTAMP; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 4304 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4305 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 4306 | if (vlan_tx_tag_present(skb)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4307 | tx_flags |= IGB_TX_FLAGS_VLAN; |
| 4308 | tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT); |
| 4309 | } |
| 4310 | |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4311 | if (skb->protocol == htons(ETH_P_IP)) |
| 4312 | tx_flags |= IGB_TX_FLAGS_IPV4; |
| 4313 | |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 4314 | first = tx_ring->next_to_use; |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4315 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4316 | tso = igb_tso(tx_ring, skb, tx_flags, &hdr_len); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4317 | |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4318 | if (tso < 0) |
| 4319 | goto out_drop; |
| 4320 | else if (tso) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4321 | tx_flags |= IGB_TX_FLAGS_TSO; |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4322 | else if (igb_tx_csum(tx_ring, skb, tx_flags) && |
Alexander Duyck | bc1cbd3 | 2009-02-13 14:45:17 +0000 | [diff] [blame] | 4323 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 4324 | tx_flags |= IGB_TX_FLAGS_CSUM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4325 | |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4326 | /* |
Alexander Duyck | cdfd01f | 2009-10-27 23:50:57 +0000 | [diff] [blame] | 4327 | * count reflects descriptors mapped, if 0 or less then mapping error |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4328 | * has occurred and we need to rewind the descriptor queue |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4329 | */ |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4330 | count = igb_tx_map(tx_ring, skb, first); |
Alexander Duyck | 6366ad3 | 2009-12-02 16:47:18 +0000 | [diff] [blame] | 4331 | if (!count) { |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4332 | dev_kfree_skb_any(skb); |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 4333 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4334 | tx_ring->next_to_use = first; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4335 | return NETDEV_TX_OK; |
Alexander Duyck | 65689fe | 2009-03-20 00:17:43 +0000 | [diff] [blame] | 4336 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4337 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4338 | igb_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len); |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4339 | |
| 4340 | /* Make sure there is space in the ring for the next send. */ |
Alexander Duyck | e694e96 | 2009-10-27 15:53:06 +0000 | [diff] [blame] | 4341 | igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4); |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 4342 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4343 | return NETDEV_TX_OK; |
Alexander Duyck | 7d13a7d | 2011-08-26 07:44:32 +0000 | [diff] [blame^] | 4344 | |
| 4345 | out_drop: |
| 4346 | dev_kfree_skb_any(skb); |
| 4347 | return NETDEV_TX_OK; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4348 | } |
| 4349 | |
Alexander Duyck | 1cc3bd8 | 2011-08-26 07:44:10 +0000 | [diff] [blame] | 4350 | static inline struct igb_ring *igb_tx_queue_mapping(struct igb_adapter *adapter, |
| 4351 | struct sk_buff *skb) |
| 4352 | { |
| 4353 | unsigned int r_idx = skb->queue_mapping; |
| 4354 | |
| 4355 | if (r_idx >= adapter->num_tx_queues) |
| 4356 | r_idx = r_idx % adapter->num_tx_queues; |
| 4357 | |
| 4358 | return adapter->tx_ring[r_idx]; |
| 4359 | } |
| 4360 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 4361 | static netdev_tx_t igb_xmit_frame(struct sk_buff *skb, |
| 4362 | struct net_device *netdev) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4363 | { |
| 4364 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | b1a436c | 2009-10-27 15:54:43 +0000 | [diff] [blame] | 4365 | |
| 4366 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 4367 | dev_kfree_skb_any(skb); |
| 4368 | return NETDEV_TX_OK; |
| 4369 | } |
| 4370 | |
| 4371 | if (skb->len <= 0) { |
| 4372 | dev_kfree_skb_any(skb); |
| 4373 | return NETDEV_TX_OK; |
| 4374 | } |
| 4375 | |
Alexander Duyck | 1cc3bd8 | 2011-08-26 07:44:10 +0000 | [diff] [blame] | 4376 | /* |
| 4377 | * The minimum packet size with TCTL.PSP set is 17 so pad the skb |
| 4378 | * in order to meet this minimum size requirement. |
| 4379 | */ |
| 4380 | if (skb->len < 17) { |
| 4381 | if (skb_padto(skb, 17)) |
| 4382 | return NETDEV_TX_OK; |
| 4383 | skb->len = 17; |
| 4384 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4385 | |
Alexander Duyck | 1cc3bd8 | 2011-08-26 07:44:10 +0000 | [diff] [blame] | 4386 | return igb_xmit_frame_ring(skb, igb_tx_queue_mapping(adapter, skb)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * igb_tx_timeout - Respond to a Tx Hang |
| 4391 | * @netdev: network interface device structure |
| 4392 | **/ |
| 4393 | static void igb_tx_timeout(struct net_device *netdev) |
| 4394 | { |
| 4395 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 4396 | struct e1000_hw *hw = &adapter->hw; |
| 4397 | |
| 4398 | /* Do the reset outside of interrupt context */ |
| 4399 | adapter->tx_timeout_count++; |
Alexander Duyck | f7ba205 | 2009-10-27 23:48:51 +0000 | [diff] [blame] | 4400 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 4401 | if (hw->mac.type == e1000_82580) |
| 4402 | hw->dev_spec._82575.global_device_reset = true; |
| 4403 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4404 | schedule_work(&adapter->reset_task); |
Alexander Duyck | 265de40 | 2009-02-06 23:22:52 +0000 | [diff] [blame] | 4405 | wr32(E1000_EICS, |
| 4406 | (adapter->eims_enable_mask & ~adapter->eims_other)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | static void igb_reset_task(struct work_struct *work) |
| 4410 | { |
| 4411 | struct igb_adapter *adapter; |
| 4412 | adapter = container_of(work, struct igb_adapter, reset_task); |
| 4413 | |
Taku Izumi | c97ec42 | 2010-04-27 14:39:30 +0000 | [diff] [blame] | 4414 | igb_dump(adapter); |
| 4415 | netdev_err(adapter->netdev, "Reset adapter\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4416 | igb_reinit_locked(adapter); |
| 4417 | } |
| 4418 | |
| 4419 | /** |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4420 | * igb_get_stats64 - Get System Network Statistics |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4421 | * @netdev: network interface device structure |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4422 | * @stats: rtnl_link_stats64 pointer |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4423 | * |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4424 | **/ |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4425 | static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev, |
| 4426 | struct rtnl_link_stats64 *stats) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4427 | { |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4428 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 4429 | |
| 4430 | spin_lock(&adapter->stats64_lock); |
| 4431 | igb_update_stats(adapter, &adapter->stats64); |
| 4432 | memcpy(stats, &adapter->stats64, sizeof(*stats)); |
| 4433 | spin_unlock(&adapter->stats64_lock); |
| 4434 | |
| 4435 | return stats; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | /** |
| 4439 | * igb_change_mtu - Change the Maximum Transfer Unit |
| 4440 | * @netdev: network interface device structure |
| 4441 | * @new_mtu: new value for maximum frame size |
| 4442 | * |
| 4443 | * Returns 0 on success, negative on failure |
| 4444 | **/ |
| 4445 | static int igb_change_mtu(struct net_device *netdev, int new_mtu) |
| 4446 | { |
| 4447 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4448 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | 153285f | 2011-08-26 07:43:32 +0000 | [diff] [blame] | 4449 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4450 | |
Alexander Duyck | c809d22 | 2009-10-27 23:52:13 +0000 | [diff] [blame] | 4451 | if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4452 | dev_err(&pdev->dev, "Invalid MTU setting\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4453 | return -EINVAL; |
| 4454 | } |
| 4455 | |
Alexander Duyck | 153285f | 2011-08-26 07:43:32 +0000 | [diff] [blame] | 4456 | #define MAX_STD_JUMBO_FRAME_SIZE 9238 |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4457 | if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4458 | dev_err(&pdev->dev, "MTU > 9216 not supported.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4459 | return -EINVAL; |
| 4460 | } |
| 4461 | |
| 4462 | while (test_and_set_bit(__IGB_RESETTING, &adapter->state)) |
| 4463 | msleep(1); |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4464 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4465 | /* igb_down has a dependency on max_frame_size */ |
| 4466 | adapter->max_frame_size = max_frame; |
Alexander Duyck | 559e9c4 | 2009-10-27 23:52:50 +0000 | [diff] [blame] | 4467 | |
Alexander Duyck | 4c84485 | 2009-10-27 15:52:07 +0000 | [diff] [blame] | 4468 | if (netif_running(netdev)) |
| 4469 | igb_down(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4470 | |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4471 | dev_info(&pdev->dev, "changing MTU from %d to %d\n", |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4472 | netdev->mtu, new_mtu); |
| 4473 | netdev->mtu = new_mtu; |
| 4474 | |
| 4475 | if (netif_running(netdev)) |
| 4476 | igb_up(adapter); |
| 4477 | else |
| 4478 | igb_reset(adapter); |
| 4479 | |
| 4480 | clear_bit(__IGB_RESETTING, &adapter->state); |
| 4481 | |
| 4482 | return 0; |
| 4483 | } |
| 4484 | |
| 4485 | /** |
| 4486 | * igb_update_stats - Update the board statistics counters |
| 4487 | * @adapter: board private structure |
| 4488 | **/ |
| 4489 | |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4490 | void igb_update_stats(struct igb_adapter *adapter, |
| 4491 | struct rtnl_link_stats64 *net_stats) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4492 | { |
| 4493 | struct e1000_hw *hw = &adapter->hw; |
| 4494 | struct pci_dev *pdev = adapter->pdev; |
Mitch Williams | fa3d9a6 | 2010-03-23 18:34:38 +0000 | [diff] [blame] | 4495 | u32 reg, mpc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4496 | u16 phy_tmp; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4497 | int i; |
| 4498 | u64 bytes, packets; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4499 | unsigned int start; |
| 4500 | u64 _bytes, _packets; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4501 | |
| 4502 | #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF |
| 4503 | |
| 4504 | /* |
| 4505 | * Prevent stats update while adapter is being reset, or if the pci |
| 4506 | * connection is down. |
| 4507 | */ |
| 4508 | if (adapter->link_speed == 0) |
| 4509 | return; |
| 4510 | if (pci_channel_offline(pdev)) |
| 4511 | return; |
| 4512 | |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4513 | bytes = 0; |
| 4514 | packets = 0; |
| 4515 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4516 | u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF; |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4517 | struct igb_ring *ring = adapter->rx_ring[i]; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4518 | |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4519 | ring->rx_stats.drops += rqdpc_tmp; |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4520 | net_stats->rx_fifo_errors += rqdpc_tmp; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4521 | |
| 4522 | do { |
| 4523 | start = u64_stats_fetch_begin_bh(&ring->rx_syncp); |
| 4524 | _bytes = ring->rx_stats.bytes; |
| 4525 | _packets = ring->rx_stats.packets; |
| 4526 | } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start)); |
| 4527 | bytes += _bytes; |
| 4528 | packets += _packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4529 | } |
| 4530 | |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4531 | net_stats->rx_bytes = bytes; |
| 4532 | net_stats->rx_packets = packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4533 | |
| 4534 | bytes = 0; |
| 4535 | packets = 0; |
| 4536 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | 3025a44 | 2010-02-17 01:02:39 +0000 | [diff] [blame] | 4537 | struct igb_ring *ring = adapter->tx_ring[i]; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 4538 | do { |
| 4539 | start = u64_stats_fetch_begin_bh(&ring->tx_syncp); |
| 4540 | _bytes = ring->tx_stats.bytes; |
| 4541 | _packets = ring->tx_stats.packets; |
| 4542 | } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start)); |
| 4543 | bytes += _bytes; |
| 4544 | packets += _packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4545 | } |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4546 | net_stats->tx_bytes = bytes; |
| 4547 | net_stats->tx_packets = packets; |
Alexander Duyck | 3f9c016 | 2009-10-27 23:48:12 +0000 | [diff] [blame] | 4548 | |
| 4549 | /* read stats registers */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4550 | adapter->stats.crcerrs += rd32(E1000_CRCERRS); |
| 4551 | adapter->stats.gprc += rd32(E1000_GPRC); |
| 4552 | adapter->stats.gorc += rd32(E1000_GORCL); |
| 4553 | rd32(E1000_GORCH); /* clear GORCL */ |
| 4554 | adapter->stats.bprc += rd32(E1000_BPRC); |
| 4555 | adapter->stats.mprc += rd32(E1000_MPRC); |
| 4556 | adapter->stats.roc += rd32(E1000_ROC); |
| 4557 | |
| 4558 | adapter->stats.prc64 += rd32(E1000_PRC64); |
| 4559 | adapter->stats.prc127 += rd32(E1000_PRC127); |
| 4560 | adapter->stats.prc255 += rd32(E1000_PRC255); |
| 4561 | adapter->stats.prc511 += rd32(E1000_PRC511); |
| 4562 | adapter->stats.prc1023 += rd32(E1000_PRC1023); |
| 4563 | adapter->stats.prc1522 += rd32(E1000_PRC1522); |
| 4564 | adapter->stats.symerrs += rd32(E1000_SYMERRS); |
| 4565 | adapter->stats.sec += rd32(E1000_SEC); |
| 4566 | |
Mitch Williams | fa3d9a6 | 2010-03-23 18:34:38 +0000 | [diff] [blame] | 4567 | mpc = rd32(E1000_MPC); |
| 4568 | adapter->stats.mpc += mpc; |
| 4569 | net_stats->rx_fifo_errors += mpc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4570 | adapter->stats.scc += rd32(E1000_SCC); |
| 4571 | adapter->stats.ecol += rd32(E1000_ECOL); |
| 4572 | adapter->stats.mcc += rd32(E1000_MCC); |
| 4573 | adapter->stats.latecol += rd32(E1000_LATECOL); |
| 4574 | adapter->stats.dc += rd32(E1000_DC); |
| 4575 | adapter->stats.rlec += rd32(E1000_RLEC); |
| 4576 | adapter->stats.xonrxc += rd32(E1000_XONRXC); |
| 4577 | adapter->stats.xontxc += rd32(E1000_XONTXC); |
| 4578 | adapter->stats.xoffrxc += rd32(E1000_XOFFRXC); |
| 4579 | adapter->stats.xofftxc += rd32(E1000_XOFFTXC); |
| 4580 | adapter->stats.fcruc += rd32(E1000_FCRUC); |
| 4581 | adapter->stats.gptc += rd32(E1000_GPTC); |
| 4582 | adapter->stats.gotc += rd32(E1000_GOTCL); |
| 4583 | rd32(E1000_GOTCH); /* clear GOTCL */ |
Mitch Williams | fa3d9a6 | 2010-03-23 18:34:38 +0000 | [diff] [blame] | 4584 | adapter->stats.rnbc += rd32(E1000_RNBC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4585 | adapter->stats.ruc += rd32(E1000_RUC); |
| 4586 | adapter->stats.rfc += rd32(E1000_RFC); |
| 4587 | adapter->stats.rjc += rd32(E1000_RJC); |
| 4588 | adapter->stats.tor += rd32(E1000_TORH); |
| 4589 | adapter->stats.tot += rd32(E1000_TOTH); |
| 4590 | adapter->stats.tpr += rd32(E1000_TPR); |
| 4591 | |
| 4592 | adapter->stats.ptc64 += rd32(E1000_PTC64); |
| 4593 | adapter->stats.ptc127 += rd32(E1000_PTC127); |
| 4594 | adapter->stats.ptc255 += rd32(E1000_PTC255); |
| 4595 | adapter->stats.ptc511 += rd32(E1000_PTC511); |
| 4596 | adapter->stats.ptc1023 += rd32(E1000_PTC1023); |
| 4597 | adapter->stats.ptc1522 += rd32(E1000_PTC1522); |
| 4598 | |
| 4599 | adapter->stats.mptc += rd32(E1000_MPTC); |
| 4600 | adapter->stats.bptc += rd32(E1000_BPTC); |
| 4601 | |
Nick Nunley | 2d0b0f6 | 2010-02-17 01:02:59 +0000 | [diff] [blame] | 4602 | adapter->stats.tpt += rd32(E1000_TPT); |
| 4603 | adapter->stats.colc += rd32(E1000_COLC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4604 | |
| 4605 | adapter->stats.algnerrc += rd32(E1000_ALGNERRC); |
Nick Nunley | 43915c7c | 2010-02-17 01:03:58 +0000 | [diff] [blame] | 4606 | /* read internal phy specific stats */ |
| 4607 | reg = rd32(E1000_CTRL_EXT); |
| 4608 | if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) { |
| 4609 | adapter->stats.rxerrc += rd32(E1000_RXERRC); |
| 4610 | adapter->stats.tncrs += rd32(E1000_TNCRS); |
| 4611 | } |
| 4612 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4613 | adapter->stats.tsctc += rd32(E1000_TSCTC); |
| 4614 | adapter->stats.tsctfc += rd32(E1000_TSCTFC); |
| 4615 | |
| 4616 | adapter->stats.iac += rd32(E1000_IAC); |
| 4617 | adapter->stats.icrxoc += rd32(E1000_ICRXOC); |
| 4618 | adapter->stats.icrxptc += rd32(E1000_ICRXPTC); |
| 4619 | adapter->stats.icrxatc += rd32(E1000_ICRXATC); |
| 4620 | adapter->stats.ictxptc += rd32(E1000_ICTXPTC); |
| 4621 | adapter->stats.ictxatc += rd32(E1000_ICTXATC); |
| 4622 | adapter->stats.ictxqec += rd32(E1000_ICTXQEC); |
| 4623 | adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC); |
| 4624 | adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC); |
| 4625 | |
| 4626 | /* Fill out the OS statistics structure */ |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4627 | net_stats->multicast = adapter->stats.mprc; |
| 4628 | net_stats->collisions = adapter->stats.colc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4629 | |
| 4630 | /* Rx Errors */ |
| 4631 | |
| 4632 | /* RLEC on some newer hardware can be incorrect so build |
Jesper Dangaard Brouer | 8c0ab70 | 2009-05-26 13:50:31 +0000 | [diff] [blame] | 4633 | * our own version based on RUC and ROC */ |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4634 | net_stats->rx_errors = adapter->stats.rxerrc + |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4635 | adapter->stats.crcerrs + adapter->stats.algnerrc + |
| 4636 | adapter->stats.ruc + adapter->stats.roc + |
| 4637 | adapter->stats.cexterr; |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4638 | net_stats->rx_length_errors = adapter->stats.ruc + |
| 4639 | adapter->stats.roc; |
| 4640 | net_stats->rx_crc_errors = adapter->stats.crcerrs; |
| 4641 | net_stats->rx_frame_errors = adapter->stats.algnerrc; |
| 4642 | net_stats->rx_missed_errors = adapter->stats.mpc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4643 | |
| 4644 | /* Tx Errors */ |
Alexander Duyck | 128e45e | 2009-11-12 18:37:38 +0000 | [diff] [blame] | 4645 | net_stats->tx_errors = adapter->stats.ecol + |
| 4646 | adapter->stats.latecol; |
| 4647 | net_stats->tx_aborted_errors = adapter->stats.ecol; |
| 4648 | net_stats->tx_window_errors = adapter->stats.latecol; |
| 4649 | net_stats->tx_carrier_errors = adapter->stats.tncrs; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4650 | |
| 4651 | /* Tx Dropped needs to be maintained elsewhere */ |
| 4652 | |
| 4653 | /* Phy Stats */ |
| 4654 | if (hw->phy.media_type == e1000_media_type_copper) { |
| 4655 | if ((adapter->link_speed == SPEED_1000) && |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4656 | (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4657 | phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK; |
| 4658 | adapter->phy_stats.idle_errors += phy_tmp; |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | /* Management Stats */ |
| 4663 | adapter->stats.mgptc += rd32(E1000_MGTPTC); |
| 4664 | adapter->stats.mgprc += rd32(E1000_MGTPRC); |
| 4665 | adapter->stats.mgpdc += rd32(E1000_MGTPDC); |
Carolyn Wyborny | 0a915b9 | 2011-02-26 07:42:37 +0000 | [diff] [blame] | 4666 | |
| 4667 | /* OS2BMC Stats */ |
| 4668 | reg = rd32(E1000_MANC); |
| 4669 | if (reg & E1000_MANC_EN_BMC2OS) { |
| 4670 | adapter->stats.o2bgptc += rd32(E1000_O2BGPTC); |
| 4671 | adapter->stats.o2bspc += rd32(E1000_O2BSPC); |
| 4672 | adapter->stats.b2ospc += rd32(E1000_B2OSPC); |
| 4673 | adapter->stats.b2ogprc += rd32(E1000_B2OGPRC); |
| 4674 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4675 | } |
| 4676 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4677 | static irqreturn_t igb_msix_other(int irq, void *data) |
| 4678 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4679 | struct igb_adapter *adapter = data; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4680 | struct e1000_hw *hw = &adapter->hw; |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 4681 | u32 icr = rd32(E1000_ICR); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 4682 | /* reading ICR causes bit 31 of EICR to be cleared */ |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4683 | |
Alexander Duyck | 7f081d4 | 2010-01-07 17:41:00 +0000 | [diff] [blame] | 4684 | if (icr & E1000_ICR_DRSTA) |
| 4685 | schedule_work(&adapter->reset_task); |
| 4686 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4687 | if (icr & E1000_ICR_DOUTSYNC) { |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4688 | /* HW is reporting DMA is out of sync */ |
| 4689 | adapter->stats.doosync++; |
Greg Rose | 1380046 | 2010-11-06 02:08:26 +0000 | [diff] [blame] | 4690 | /* The DMA Out of Sync is also indication of a spoof event |
| 4691 | * in IOV mode. Check the Wrong VM Behavior register to |
| 4692 | * see if it is really a spoof event. */ |
| 4693 | igb_check_wvbr(adapter); |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 4694 | } |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 4695 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4696 | /* Check for a mailbox event */ |
| 4697 | if (icr & E1000_ICR_VMMB) |
| 4698 | igb_msg_task(adapter); |
| 4699 | |
| 4700 | if (icr & E1000_ICR_LSC) { |
| 4701 | hw->mac.get_link_status = 1; |
| 4702 | /* guard against interrupt when we're going down */ |
| 4703 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 4704 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 4705 | } |
| 4706 | |
Alexander Duyck | 25568a5 | 2009-10-27 23:49:59 +0000 | [diff] [blame] | 4707 | if (adapter->vfs_allocated_count) |
| 4708 | wr32(E1000_IMS, E1000_IMS_LSC | |
| 4709 | E1000_IMS_VMMB | |
| 4710 | E1000_IMS_DOUTSYNC); |
| 4711 | else |
| 4712 | wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC); |
PJ Waskiewicz | 844290e | 2008-06-27 11:00:39 -0700 | [diff] [blame] | 4713 | wr32(E1000_EIMS, adapter->eims_other); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4714 | |
| 4715 | return IRQ_HANDLED; |
| 4716 | } |
| 4717 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4718 | static void igb_write_itr(struct igb_q_vector *q_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4719 | { |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 4720 | struct igb_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4721 | u32 itr_val = q_vector->itr_val & 0x7FFC; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4722 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4723 | if (!q_vector->set_itr) |
| 4724 | return; |
Alexander Duyck | 73cd78f | 2009-02-12 18:16:59 +0000 | [diff] [blame] | 4725 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4726 | if (!itr_val) |
| 4727 | itr_val = 0x4; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4728 | |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 4729 | if (adapter->hw.mac.type == e1000_82575) |
| 4730 | itr_val |= itr_val << 16; |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4731 | else |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4732 | itr_val |= 0x8000000; |
| 4733 | |
| 4734 | writel(itr_val, q_vector->itr_register); |
| 4735 | q_vector->set_itr = 0; |
| 4736 | } |
| 4737 | |
| 4738 | static irqreturn_t igb_msix_ring(int irq, void *data) |
| 4739 | { |
| 4740 | struct igb_q_vector *q_vector = data; |
| 4741 | |
| 4742 | /* Write the ITR value calculated from the previous interrupt. */ |
| 4743 | igb_write_itr(q_vector); |
| 4744 | |
| 4745 | napi_schedule(&q_vector->napi); |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 4746 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4747 | return IRQ_HANDLED; |
| 4748 | } |
| 4749 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 4750 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4751 | static void igb_update_dca(struct igb_q_vector *q_vector) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4752 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4753 | struct igb_adapter *adapter = q_vector->adapter; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4754 | struct e1000_hw *hw = &adapter->hw; |
| 4755 | int cpu = get_cpu(); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4756 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4757 | if (q_vector->cpu == cpu) |
| 4758 | goto out_no_update; |
| 4759 | |
| 4760 | if (q_vector->tx_ring) { |
| 4761 | int q = q_vector->tx_ring->reg_idx; |
| 4762 | u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q)); |
| 4763 | if (hw->mac.type == e1000_82575) { |
| 4764 | dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK; |
| 4765 | dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 4766 | } else { |
| 4767 | dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576; |
| 4768 | dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 4769 | E1000_DCA_TXCTRL_CPUID_SHIFT; |
| 4770 | } |
| 4771 | dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN; |
| 4772 | wr32(E1000_DCA_TXCTRL(q), dca_txctrl); |
| 4773 | } |
| 4774 | if (q_vector->rx_ring) { |
| 4775 | int q = q_vector->rx_ring->reg_idx; |
| 4776 | u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q)); |
| 4777 | if (hw->mac.type == e1000_82575) { |
| 4778 | dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK; |
| 4779 | dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 4780 | } else { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4781 | dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576; |
Maciej Sosnowski | 92be791 | 2009-03-13 20:40:21 +0000 | [diff] [blame] | 4782 | dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) << |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4783 | E1000_DCA_RXCTRL_CPUID_SHIFT; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 4784 | } |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4785 | dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN; |
| 4786 | dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN; |
| 4787 | dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN; |
| 4788 | wr32(E1000_DCA_RXCTRL(q), dca_rxctrl); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4789 | } |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4790 | q_vector->cpu = cpu; |
| 4791 | out_no_update: |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4792 | put_cpu(); |
| 4793 | } |
| 4794 | |
| 4795 | static void igb_setup_dca(struct igb_adapter *adapter) |
| 4796 | { |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 4797 | struct e1000_hw *hw = &adapter->hw; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4798 | int i; |
| 4799 | |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4800 | if (!(adapter->flags & IGB_FLAG_DCA_ENABLED)) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4801 | return; |
| 4802 | |
Alexander Duyck | 7e0e99e | 2009-05-21 13:06:56 +0000 | [diff] [blame] | 4803 | /* Always use CB2 mode, difference is masked in the CB driver. */ |
| 4804 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2); |
| 4805 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4806 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 26b3927 | 2010-02-17 01:00:41 +0000 | [diff] [blame] | 4807 | adapter->q_vector[i]->cpu = -1; |
| 4808 | igb_update_dca(adapter->q_vector[i]); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | static int __igb_notify_dca(struct device *dev, void *data) |
| 4813 | { |
| 4814 | struct net_device *netdev = dev_get_drvdata(dev); |
| 4815 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4816 | struct pci_dev *pdev = adapter->pdev; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4817 | struct e1000_hw *hw = &adapter->hw; |
| 4818 | unsigned long event = *(unsigned long *)data; |
| 4819 | |
| 4820 | switch (event) { |
| 4821 | case DCA_PROVIDER_ADD: |
| 4822 | /* if already enabled, don't do it again */ |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4823 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4824 | break; |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4825 | if (dca_add_requester(dev) == 0) { |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 4826 | adapter->flags |= IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4827 | dev_info(&pdev->dev, "DCA enabled\n"); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4828 | igb_setup_dca(adapter); |
| 4829 | break; |
| 4830 | } |
| 4831 | /* Fall Through since DCA is disabled. */ |
| 4832 | case DCA_PROVIDER_REMOVE: |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4833 | if (adapter->flags & IGB_FLAG_DCA_ENABLED) { |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4834 | /* without this a class_device is left |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 4835 | * hanging around in the sysfs model */ |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4836 | dca_remove_requester(dev); |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 4837 | dev_info(&pdev->dev, "DCA disabled\n"); |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 4838 | adapter->flags &= ~IGB_FLAG_DCA_ENABLED; |
Alexander Duyck | cbd347a | 2009-02-15 23:59:44 -0800 | [diff] [blame] | 4839 | wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4840 | } |
| 4841 | break; |
| 4842 | } |
Alexander Duyck | bbd98fe | 2009-01-31 00:52:30 -0800 | [diff] [blame] | 4843 | |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 4844 | return 0; |
| 4845 | } |
| 4846 | |
| 4847 | static int igb_notify_dca(struct notifier_block *nb, unsigned long event, |
| 4848 | void *p) |
| 4849 | { |
| 4850 | int ret_val; |
| 4851 | |
| 4852 | ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event, |
| 4853 | __igb_notify_dca); |
| 4854 | |
| 4855 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 4856 | } |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 4857 | #endif /* CONFIG_IGB_DCA */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 4858 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4859 | static void igb_ping_all_vfs(struct igb_adapter *adapter) |
| 4860 | { |
| 4861 | struct e1000_hw *hw = &adapter->hw; |
| 4862 | u32 ping; |
| 4863 | int i; |
| 4864 | |
| 4865 | for (i = 0 ; i < adapter->vfs_allocated_count; i++) { |
| 4866 | ping = E1000_PF_CONTROL_MSG; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 4867 | if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4868 | ping |= E1000_VT_MSGTYPE_CTS; |
| 4869 | igb_write_mbx(hw, &ping, 1, i); |
| 4870 | } |
| 4871 | } |
| 4872 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4873 | static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf) |
| 4874 | { |
| 4875 | struct e1000_hw *hw = &adapter->hw; |
| 4876 | u32 vmolr = rd32(E1000_VMOLR(vf)); |
| 4877 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
| 4878 | |
Alexander Duyck | d85b9004 | 2010-09-22 17:56:20 +0000 | [diff] [blame] | 4879 | vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4880 | IGB_VF_FLAG_MULTI_PROMISC); |
| 4881 | vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME); |
| 4882 | |
| 4883 | if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) { |
| 4884 | vmolr |= E1000_VMOLR_MPME; |
Alexander Duyck | d85b9004 | 2010-09-22 17:56:20 +0000 | [diff] [blame] | 4885 | vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC; |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4886 | *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST; |
| 4887 | } else { |
| 4888 | /* |
| 4889 | * if we have hashes and we are clearing a multicast promisc |
| 4890 | * flag we need to write the hashes to the MTA as this step |
| 4891 | * was previously skipped |
| 4892 | */ |
| 4893 | if (vf_data->num_vf_mc_hashes > 30) { |
| 4894 | vmolr |= E1000_VMOLR_MPME; |
| 4895 | } else if (vf_data->num_vf_mc_hashes) { |
| 4896 | int j; |
| 4897 | vmolr |= E1000_VMOLR_ROMPE; |
| 4898 | for (j = 0; j < vf_data->num_vf_mc_hashes; j++) |
| 4899 | igb_mta_set(hw, vf_data->vf_mc_hashes[j]); |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | wr32(E1000_VMOLR(vf), vmolr); |
| 4904 | |
| 4905 | /* there are flags left unprocessed, likely not supported */ |
| 4906 | if (*msgbuf & E1000_VT_MSGINFO_MASK) |
| 4907 | return -EINVAL; |
| 4908 | |
| 4909 | return 0; |
| 4910 | |
| 4911 | } |
| 4912 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4913 | static int igb_set_vf_multicasts(struct igb_adapter *adapter, |
| 4914 | u32 *msgbuf, u32 vf) |
| 4915 | { |
| 4916 | int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT; |
| 4917 | u16 *hash_list = (u16 *)&msgbuf[1]; |
| 4918 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
| 4919 | int i; |
| 4920 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4921 | /* salt away the number of multicast addresses assigned |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4922 | * to this VF for later use to restore when the PF multi cast |
| 4923 | * list changes |
| 4924 | */ |
| 4925 | vf_data->num_vf_mc_hashes = n; |
| 4926 | |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4927 | /* only up to 30 hash values supported */ |
| 4928 | if (n > 30) |
| 4929 | n = 30; |
| 4930 | |
| 4931 | /* store the hashes for later use */ |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4932 | for (i = 0; i < n; i++) |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 4933 | vf_data->vf_mc_hashes[i] = hash_list[i]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4934 | |
| 4935 | /* Flush and reset the mta with the new values */ |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 4936 | igb_set_rx_mode(adapter->netdev); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4937 | |
| 4938 | return 0; |
| 4939 | } |
| 4940 | |
| 4941 | static void igb_restore_vf_multicasts(struct igb_adapter *adapter) |
| 4942 | { |
| 4943 | struct e1000_hw *hw = &adapter->hw; |
| 4944 | struct vf_data_storage *vf_data; |
| 4945 | int i, j; |
| 4946 | |
| 4947 | for (i = 0; i < adapter->vfs_allocated_count; i++) { |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4948 | u32 vmolr = rd32(E1000_VMOLR(i)); |
| 4949 | vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME); |
| 4950 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4951 | vf_data = &adapter->vf_data[i]; |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 4952 | |
| 4953 | if ((vf_data->num_vf_mc_hashes > 30) || |
| 4954 | (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) { |
| 4955 | vmolr |= E1000_VMOLR_MPME; |
| 4956 | } else if (vf_data->num_vf_mc_hashes) { |
| 4957 | vmolr |= E1000_VMOLR_ROMPE; |
| 4958 | for (j = 0; j < vf_data->num_vf_mc_hashes; j++) |
| 4959 | igb_mta_set(hw, vf_data->vf_mc_hashes[j]); |
| 4960 | } |
| 4961 | wr32(E1000_VMOLR(i), vmolr); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4962 | } |
| 4963 | } |
| 4964 | |
| 4965 | static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf) |
| 4966 | { |
| 4967 | struct e1000_hw *hw = &adapter->hw; |
| 4968 | u32 pool_mask, reg, vid; |
| 4969 | int i; |
| 4970 | |
| 4971 | pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf); |
| 4972 | |
| 4973 | /* Find the vlan filter for this id */ |
| 4974 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 4975 | reg = rd32(E1000_VLVF(i)); |
| 4976 | |
| 4977 | /* remove the vf from the pool */ |
| 4978 | reg &= ~pool_mask; |
| 4979 | |
| 4980 | /* if pool is empty then remove entry from vfta */ |
| 4981 | if (!(reg & E1000_VLVF_POOLSEL_MASK) && |
| 4982 | (reg & E1000_VLVF_VLANID_ENABLE)) { |
| 4983 | reg = 0; |
| 4984 | vid = reg & E1000_VLVF_VLANID_MASK; |
| 4985 | igb_vfta_set(hw, vid, false); |
| 4986 | } |
| 4987 | |
| 4988 | wr32(E1000_VLVF(i), reg); |
| 4989 | } |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 4990 | |
| 4991 | adapter->vf_data[vf].vlans_enabled = 0; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf) |
| 4995 | { |
| 4996 | struct e1000_hw *hw = &adapter->hw; |
| 4997 | u32 reg, i; |
| 4998 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 4999 | /* The vlvf table only exists on 82576 hardware and newer */ |
| 5000 | if (hw->mac.type < e1000_82576) |
| 5001 | return -1; |
| 5002 | |
| 5003 | /* we only need to do this if VMDq is enabled */ |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5004 | if (!adapter->vfs_allocated_count) |
| 5005 | return -1; |
| 5006 | |
| 5007 | /* Find the vlan filter for this id */ |
| 5008 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 5009 | reg = rd32(E1000_VLVF(i)); |
| 5010 | if ((reg & E1000_VLVF_VLANID_ENABLE) && |
| 5011 | vid == (reg & E1000_VLVF_VLANID_MASK)) |
| 5012 | break; |
| 5013 | } |
| 5014 | |
| 5015 | if (add) { |
| 5016 | if (i == E1000_VLVF_ARRAY_SIZE) { |
| 5017 | /* Did not find a matching VLAN ID entry that was |
| 5018 | * enabled. Search for a free filter entry, i.e. |
| 5019 | * one without the enable bit set |
| 5020 | */ |
| 5021 | for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) { |
| 5022 | reg = rd32(E1000_VLVF(i)); |
| 5023 | if (!(reg & E1000_VLVF_VLANID_ENABLE)) |
| 5024 | break; |
| 5025 | } |
| 5026 | } |
| 5027 | if (i < E1000_VLVF_ARRAY_SIZE) { |
| 5028 | /* Found an enabled/available entry */ |
| 5029 | reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf); |
| 5030 | |
| 5031 | /* if !enabled we need to set this up in vfta */ |
| 5032 | if (!(reg & E1000_VLVF_VLANID_ENABLE)) { |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 5033 | /* add VID to filter table */ |
| 5034 | igb_vfta_set(hw, vid, true); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5035 | reg |= E1000_VLVF_VLANID_ENABLE; |
| 5036 | } |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 5037 | reg &= ~E1000_VLVF_VLANID_MASK; |
| 5038 | reg |= vid; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5039 | wr32(E1000_VLVF(i), reg); |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 5040 | |
| 5041 | /* do not modify RLPML for PF devices */ |
| 5042 | if (vf >= adapter->vfs_allocated_count) |
| 5043 | return 0; |
| 5044 | |
| 5045 | if (!adapter->vf_data[vf].vlans_enabled) { |
| 5046 | u32 size; |
| 5047 | reg = rd32(E1000_VMOLR(vf)); |
| 5048 | size = reg & E1000_VMOLR_RLPML_MASK; |
| 5049 | size += 4; |
| 5050 | reg &= ~E1000_VMOLR_RLPML_MASK; |
| 5051 | reg |= size; |
| 5052 | wr32(E1000_VMOLR(vf), reg); |
| 5053 | } |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 5054 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 5055 | adapter->vf_data[vf].vlans_enabled++; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5056 | return 0; |
| 5057 | } |
| 5058 | } else { |
| 5059 | if (i < E1000_VLVF_ARRAY_SIZE) { |
| 5060 | /* remove vf from the pool */ |
| 5061 | reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf)); |
| 5062 | /* if pool is empty then remove entry from vfta */ |
| 5063 | if (!(reg & E1000_VLVF_POOLSEL_MASK)) { |
| 5064 | reg = 0; |
| 5065 | igb_vfta_set(hw, vid, false); |
| 5066 | } |
| 5067 | wr32(E1000_VLVF(i), reg); |
Alexander Duyck | ae641bd | 2009-09-03 14:49:33 +0000 | [diff] [blame] | 5068 | |
| 5069 | /* do not modify RLPML for PF devices */ |
| 5070 | if (vf >= adapter->vfs_allocated_count) |
| 5071 | return 0; |
| 5072 | |
| 5073 | adapter->vf_data[vf].vlans_enabled--; |
| 5074 | if (!adapter->vf_data[vf].vlans_enabled) { |
| 5075 | u32 size; |
| 5076 | reg = rd32(E1000_VMOLR(vf)); |
| 5077 | size = reg & E1000_VMOLR_RLPML_MASK; |
| 5078 | size -= 4; |
| 5079 | reg &= ~E1000_VMOLR_RLPML_MASK; |
| 5080 | reg |= size; |
| 5081 | wr32(E1000_VMOLR(vf), reg); |
| 5082 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5083 | } |
| 5084 | } |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 5085 | return 0; |
| 5086 | } |
| 5087 | |
| 5088 | static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf) |
| 5089 | { |
| 5090 | struct e1000_hw *hw = &adapter->hw; |
| 5091 | |
| 5092 | if (vid) |
| 5093 | wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT)); |
| 5094 | else |
| 5095 | wr32(E1000_VMVIR(vf), 0); |
| 5096 | } |
| 5097 | |
| 5098 | static int igb_ndo_set_vf_vlan(struct net_device *netdev, |
| 5099 | int vf, u16 vlan, u8 qos) |
| 5100 | { |
| 5101 | int err = 0; |
| 5102 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 5103 | |
| 5104 | if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7)) |
| 5105 | return -EINVAL; |
| 5106 | if (vlan || qos) { |
| 5107 | err = igb_vlvf_set(adapter, vlan, !!vlan, vf); |
| 5108 | if (err) |
| 5109 | goto out; |
| 5110 | igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf); |
| 5111 | igb_set_vmolr(adapter, vf, !vlan); |
| 5112 | adapter->vf_data[vf].pf_vlan = vlan; |
| 5113 | adapter->vf_data[vf].pf_qos = qos; |
| 5114 | dev_info(&adapter->pdev->dev, |
| 5115 | "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf); |
| 5116 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 5117 | dev_warn(&adapter->pdev->dev, |
| 5118 | "The VF VLAN has been set," |
| 5119 | " but the PF device is not up.\n"); |
| 5120 | dev_warn(&adapter->pdev->dev, |
| 5121 | "Bring the PF device up before" |
| 5122 | " attempting to use the VF device.\n"); |
| 5123 | } |
| 5124 | } else { |
| 5125 | igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan, |
| 5126 | false, vf); |
| 5127 | igb_set_vmvir(adapter, vlan, vf); |
| 5128 | igb_set_vmolr(adapter, vf, true); |
| 5129 | adapter->vf_data[vf].pf_vlan = 0; |
| 5130 | adapter->vf_data[vf].pf_qos = 0; |
| 5131 | } |
| 5132 | out: |
| 5133 | return err; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf) |
| 5137 | { |
| 5138 | int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT; |
| 5139 | int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK); |
| 5140 | |
| 5141 | return igb_vlvf_set(adapter, vid, add, vf); |
| 5142 | } |
| 5143 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5144 | static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5145 | { |
Greg Rose | 8fa7e0f | 2010-11-06 05:43:21 +0000 | [diff] [blame] | 5146 | /* clear flags - except flag that indicates PF has set the MAC */ |
| 5147 | adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5148 | adapter->vf_data[vf].last_nack = jiffies; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5149 | |
| 5150 | /* reset offloads to defaults */ |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 5151 | igb_set_vmolr(adapter, vf, true); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5152 | |
| 5153 | /* reset vlans for device */ |
| 5154 | igb_clear_vf_vfta(adapter, vf); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 5155 | if (adapter->vf_data[vf].pf_vlan) |
| 5156 | igb_ndo_set_vf_vlan(adapter->netdev, vf, |
| 5157 | adapter->vf_data[vf].pf_vlan, |
| 5158 | adapter->vf_data[vf].pf_qos); |
| 5159 | else |
| 5160 | igb_clear_vf_vfta(adapter, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5161 | |
| 5162 | /* reset multicast table array for vf */ |
| 5163 | adapter->vf_data[vf].num_vf_mc_hashes = 0; |
| 5164 | |
| 5165 | /* Flush and reset the mta with the new values */ |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 5166 | igb_set_rx_mode(adapter->netdev); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5167 | } |
| 5168 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5169 | static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf) |
| 5170 | { |
| 5171 | unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses; |
| 5172 | |
| 5173 | /* generate a new mac address as we were hotplug removed/added */ |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 5174 | if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC)) |
| 5175 | random_ether_addr(vf_mac); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5176 | |
| 5177 | /* process remaining reset events */ |
| 5178 | igb_vf_reset(adapter, vf); |
| 5179 | } |
| 5180 | |
| 5181 | static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5182 | { |
| 5183 | struct e1000_hw *hw = &adapter->hw; |
| 5184 | unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses; |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 5185 | int rar_entry = hw->mac.rar_entry_count - (vf + 1); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5186 | u32 reg, msgbuf[3]; |
| 5187 | u8 *addr = (u8 *)(&msgbuf[1]); |
| 5188 | |
| 5189 | /* process all the same items cleared in a function level reset */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5190 | igb_vf_reset(adapter, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5191 | |
| 5192 | /* set vf mac address */ |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 5193 | igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5194 | |
| 5195 | /* enable transmit and receive for vf */ |
| 5196 | reg = rd32(E1000_VFTE); |
| 5197 | wr32(E1000_VFTE, reg | (1 << vf)); |
| 5198 | reg = rd32(E1000_VFRE); |
| 5199 | wr32(E1000_VFRE, reg | (1 << vf)); |
| 5200 | |
Greg Rose | 8fa7e0f | 2010-11-06 05:43:21 +0000 | [diff] [blame] | 5201 | adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5202 | |
| 5203 | /* reply to reset with ack and vf mac address */ |
| 5204 | msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK; |
| 5205 | memcpy(addr, vf_mac, 6); |
| 5206 | igb_write_mbx(hw, msgbuf, 3, vf); |
| 5207 | } |
| 5208 | |
| 5209 | static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf) |
| 5210 | { |
Greg Rose | de42edd | 2010-07-01 13:39:23 +0000 | [diff] [blame] | 5211 | /* |
| 5212 | * The VF MAC Address is stored in a packed array of bytes |
| 5213 | * starting at the second 32 bit word of the msg array |
| 5214 | */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5215 | unsigned char *addr = (char *)&msg[1]; |
| 5216 | int err = -1; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5217 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5218 | if (is_valid_ether_addr(addr)) |
| 5219 | err = igb_set_vf_mac(adapter, vf, addr); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5220 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5221 | return err; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf) |
| 5225 | { |
| 5226 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5227 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5228 | u32 msg = E1000_VT_MSGTYPE_NACK; |
| 5229 | |
| 5230 | /* if device isn't clear to send it shouldn't be reading either */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5231 | if (!(vf_data->flags & IGB_VF_FLAG_CTS) && |
| 5232 | time_after(jiffies, vf_data->last_nack + (2 * HZ))) { |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5233 | igb_write_mbx(hw, &msg, 1, vf); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5234 | vf_data->last_nack = jiffies; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5235 | } |
| 5236 | } |
| 5237 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5238 | static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5239 | { |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5240 | struct pci_dev *pdev = adapter->pdev; |
| 5241 | u32 msgbuf[E1000_VFMAILBOX_SIZE]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5242 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5243 | struct vf_data_storage *vf_data = &adapter->vf_data[vf]; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5244 | s32 retval; |
| 5245 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5246 | retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5247 | |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5248 | if (retval) { |
| 5249 | /* if receive failed revoke VF CTS stats and restart init */ |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5250 | dev_err(&pdev->dev, "Error receiving message from VF\n"); |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5251 | vf_data->flags &= ~IGB_VF_FLAG_CTS; |
| 5252 | if (!time_after(jiffies, vf_data->last_nack + (2 * HZ))) |
| 5253 | return; |
| 5254 | goto out; |
| 5255 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5256 | |
| 5257 | /* this is a message we already processed, do nothing */ |
| 5258 | if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK)) |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5259 | return; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5260 | |
| 5261 | /* |
| 5262 | * until the vf completes a reset it should not be |
| 5263 | * allowed to start any configuration. |
| 5264 | */ |
| 5265 | |
| 5266 | if (msgbuf[0] == E1000_VF_RESET) { |
| 5267 | igb_vf_reset_msg(adapter, vf); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5268 | return; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5269 | } |
| 5270 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5271 | if (!(vf_data->flags & IGB_VF_FLAG_CTS)) { |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5272 | if (!time_after(jiffies, vf_data->last_nack + (2 * HZ))) |
| 5273 | return; |
| 5274 | retval = -1; |
| 5275 | goto out; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | switch ((msgbuf[0] & 0xFFFF)) { |
| 5279 | case E1000_VF_SET_MAC_ADDR: |
Greg Rose | a6b5ea3 | 2010-11-06 05:42:59 +0000 | [diff] [blame] | 5280 | retval = -EINVAL; |
| 5281 | if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC)) |
| 5282 | retval = igb_set_vf_mac_addr(adapter, msgbuf, vf); |
| 5283 | else |
| 5284 | dev_warn(&pdev->dev, |
| 5285 | "VF %d attempted to override administratively " |
| 5286 | "set MAC address\nReload the VF driver to " |
| 5287 | "resume operations\n", vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5288 | break; |
Alexander Duyck | 7d5753f | 2009-10-27 23:47:16 +0000 | [diff] [blame] | 5289 | case E1000_VF_SET_PROMISC: |
| 5290 | retval = igb_set_vf_promisc(adapter, msgbuf, vf); |
| 5291 | break; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5292 | case E1000_VF_SET_MULTICAST: |
| 5293 | retval = igb_set_vf_multicasts(adapter, msgbuf, vf); |
| 5294 | break; |
| 5295 | case E1000_VF_SET_LPE: |
| 5296 | retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf); |
| 5297 | break; |
| 5298 | case E1000_VF_SET_VLAN: |
Greg Rose | a6b5ea3 | 2010-11-06 05:42:59 +0000 | [diff] [blame] | 5299 | retval = -1; |
| 5300 | if (vf_data->pf_vlan) |
| 5301 | dev_warn(&pdev->dev, |
| 5302 | "VF %d attempted to override administratively " |
| 5303 | "set VLAN tag\nReload the VF driver to " |
| 5304 | "resume operations\n", vf); |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 5305 | else |
| 5306 | retval = igb_set_vf_vlan(adapter, msgbuf, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5307 | break; |
| 5308 | default: |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 5309 | dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5310 | retval = -1; |
| 5311 | break; |
| 5312 | } |
| 5313 | |
Alexander Duyck | fef45f4 | 2009-12-11 22:57:34 -0800 | [diff] [blame] | 5314 | msgbuf[0] |= E1000_VT_MSGTYPE_CTS; |
| 5315 | out: |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5316 | /* notify the VF of the results of what it sent us */ |
| 5317 | if (retval) |
| 5318 | msgbuf[0] |= E1000_VT_MSGTYPE_NACK; |
| 5319 | else |
| 5320 | msgbuf[0] |= E1000_VT_MSGTYPE_ACK; |
| 5321 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5322 | igb_write_mbx(hw, msgbuf, 1, vf); |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5323 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5324 | |
Alexander Duyck | f2ca0db | 2009-10-27 23:46:57 +0000 | [diff] [blame] | 5325 | static void igb_msg_task(struct igb_adapter *adapter) |
| 5326 | { |
| 5327 | struct e1000_hw *hw = &adapter->hw; |
| 5328 | u32 vf; |
| 5329 | |
| 5330 | for (vf = 0; vf < adapter->vfs_allocated_count; vf++) { |
| 5331 | /* process any reset requests */ |
| 5332 | if (!igb_check_for_rst(hw, vf)) |
| 5333 | igb_vf_reset_event(adapter, vf); |
| 5334 | |
| 5335 | /* process any messages pending */ |
| 5336 | if (!igb_check_for_msg(hw, vf)) |
| 5337 | igb_rcv_msg_from_vf(adapter, vf); |
| 5338 | |
| 5339 | /* process any acks */ |
| 5340 | if (!igb_check_for_ack(hw, vf)) |
| 5341 | igb_rcv_ack_from_vf(adapter, vf); |
| 5342 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 5343 | } |
| 5344 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5345 | /** |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 5346 | * igb_set_uta - Set unicast filter table address |
| 5347 | * @adapter: board private structure |
| 5348 | * |
| 5349 | * The unicast table address is a register array of 32-bit registers. |
| 5350 | * The table is meant to be used in a way similar to how the MTA is used |
| 5351 | * however due to certain limitations in the hardware it is necessary to |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5352 | * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous |
| 5353 | * enable bit to allow vlan tag stripping when promiscuous mode is enabled |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 5354 | **/ |
| 5355 | static void igb_set_uta(struct igb_adapter *adapter) |
| 5356 | { |
| 5357 | struct e1000_hw *hw = &adapter->hw; |
| 5358 | int i; |
| 5359 | |
| 5360 | /* The UTA table only exists on 82576 hardware and newer */ |
| 5361 | if (hw->mac.type < e1000_82576) |
| 5362 | return; |
| 5363 | |
| 5364 | /* we only need to do this if VMDq is enabled */ |
| 5365 | if (!adapter->vfs_allocated_count) |
| 5366 | return; |
| 5367 | |
| 5368 | for (i = 0; i < hw->mac.uta_reg_count; i++) |
| 5369 | array_wr32(E1000_UTA, i, ~0); |
| 5370 | } |
| 5371 | |
| 5372 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5373 | * igb_intr_msi - Interrupt Handler |
| 5374 | * @irq: interrupt number |
| 5375 | * @data: pointer to a network interface device structure |
| 5376 | **/ |
| 5377 | static irqreturn_t igb_intr_msi(int irq, void *data) |
| 5378 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5379 | struct igb_adapter *adapter = data; |
| 5380 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5381 | struct e1000_hw *hw = &adapter->hw; |
| 5382 | /* read ICR disables interrupts using IAM */ |
| 5383 | u32 icr = rd32(E1000_ICR); |
| 5384 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5385 | igb_write_itr(q_vector); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5386 | |
Alexander Duyck | 7f081d4 | 2010-01-07 17:41:00 +0000 | [diff] [blame] | 5387 | if (icr & E1000_ICR_DRSTA) |
| 5388 | schedule_work(&adapter->reset_task); |
| 5389 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5390 | if (icr & E1000_ICR_DOUTSYNC) { |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 5391 | /* HW is reporting DMA is out of sync */ |
| 5392 | adapter->stats.doosync++; |
| 5393 | } |
| 5394 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5395 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 5396 | hw->mac.get_link_status = 1; |
| 5397 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 5398 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 5399 | } |
| 5400 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5401 | napi_schedule(&q_vector->napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5402 | |
| 5403 | return IRQ_HANDLED; |
| 5404 | } |
| 5405 | |
| 5406 | /** |
Alexander Duyck | 4a3c643 | 2009-02-06 23:20:49 +0000 | [diff] [blame] | 5407 | * igb_intr - Legacy Interrupt Handler |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5408 | * @irq: interrupt number |
| 5409 | * @data: pointer to a network interface device structure |
| 5410 | **/ |
| 5411 | static irqreturn_t igb_intr(int irq, void *data) |
| 5412 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5413 | struct igb_adapter *adapter = data; |
| 5414 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5415 | struct e1000_hw *hw = &adapter->hw; |
| 5416 | /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No |
| 5417 | * need for the IMC write */ |
| 5418 | u32 icr = rd32(E1000_ICR); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5419 | if (!icr) |
| 5420 | return IRQ_NONE; /* Not our interrupt */ |
| 5421 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5422 | igb_write_itr(q_vector); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5423 | |
| 5424 | /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is |
| 5425 | * not set, then the adapter didn't send an interrupt */ |
| 5426 | if (!(icr & E1000_ICR_INT_ASSERTED)) |
| 5427 | return IRQ_NONE; |
| 5428 | |
Alexander Duyck | 7f081d4 | 2010-01-07 17:41:00 +0000 | [diff] [blame] | 5429 | if (icr & E1000_ICR_DRSTA) |
| 5430 | schedule_work(&adapter->reset_task); |
| 5431 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5432 | if (icr & E1000_ICR_DOUTSYNC) { |
Alexander Duyck | dda0e08 | 2009-02-06 23:19:08 +0000 | [diff] [blame] | 5433 | /* HW is reporting DMA is out of sync */ |
| 5434 | adapter->stats.doosync++; |
| 5435 | } |
| 5436 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5437 | if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) { |
| 5438 | hw->mac.get_link_status = 1; |
| 5439 | /* guard against interrupt when we're going down */ |
| 5440 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 5441 | mod_timer(&adapter->watchdog_timer, jiffies + 1); |
| 5442 | } |
| 5443 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5444 | napi_schedule(&q_vector->napi); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5445 | |
| 5446 | return IRQ_HANDLED; |
| 5447 | } |
| 5448 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5449 | static inline void igb_ring_irq_enable(struct igb_q_vector *q_vector) |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5450 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5451 | struct igb_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5452 | struct e1000_hw *hw = &adapter->hw; |
| 5453 | |
Alexander Duyck | 4fc82ad | 2009-10-27 23:45:42 +0000 | [diff] [blame] | 5454 | if ((q_vector->rx_ring && (adapter->rx_itr_setting & 3)) || |
| 5455 | (!q_vector->rx_ring && (adapter->tx_itr_setting & 3))) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5456 | if (!adapter->msix_entries) |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5457 | igb_set_itr(adapter); |
| 5458 | else |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5459 | igb_update_ring_itr(q_vector); |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | if (!test_bit(__IGB_DOWN, &adapter->state)) { |
| 5463 | if (adapter->msix_entries) |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5464 | wr32(E1000_EIMS, q_vector->eims_value); |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5465 | else |
| 5466 | igb_irq_enable(adapter); |
| 5467 | } |
| 5468 | } |
| 5469 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5470 | /** |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5471 | * igb_poll - NAPI Rx polling callback |
| 5472 | * @napi: napi polling structure |
| 5473 | * @budget: count of how many packets we should handle |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5474 | **/ |
Peter P Waskiewicz Jr | 661086d | 2008-07-08 15:06:51 -0700 | [diff] [blame] | 5475 | static int igb_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5476 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5477 | struct igb_q_vector *q_vector = container_of(napi, |
| 5478 | struct igb_q_vector, |
| 5479 | napi); |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5480 | bool clean_complete = true; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5481 | |
Jeff Kirsher | 421e02f | 2008-10-17 11:08:31 -0700 | [diff] [blame] | 5482 | #ifdef CONFIG_IGB_DCA |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5483 | if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED) |
| 5484 | igb_update_dca(q_vector); |
Jeb Cramer | fe4506b | 2008-07-08 15:07:55 -0700 | [diff] [blame] | 5485 | #endif |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5486 | if (q_vector->tx_ring) |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5487 | clean_complete = igb_clean_tx_irq(q_vector); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5488 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5489 | if (q_vector->rx_ring) |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5490 | clean_complete &= igb_clean_rx_irq(q_vector, budget); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5491 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5492 | /* If all work not completed, return budget and keep polling */ |
| 5493 | if (!clean_complete) |
| 5494 | return budget; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5495 | |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5496 | /* If not enough Rx work done, exit the polling mode */ |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5497 | napi_complete(napi); |
| 5498 | igb_ring_irq_enable(q_vector); |
Alexander Duyck | 4654425 | 2009-02-19 20:39:04 -0800 | [diff] [blame] | 5499 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5500 | return 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5501 | } |
Al Viro | 6d8126f | 2008-03-16 22:23:24 +0000 | [diff] [blame] | 5502 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5503 | /** |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5504 | * igb_systim_to_hwtstamp - convert system time value to hw timestamp |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5505 | * @adapter: board private structure |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5506 | * @shhwtstamps: timestamp structure to update |
| 5507 | * @regval: unsigned 64bit system time value. |
| 5508 | * |
| 5509 | * We need to convert the system time value stored in the RX/TXSTMP registers |
| 5510 | * into a hwtstamp which can be used by the upper level timestamping functions |
| 5511 | */ |
| 5512 | static void igb_systim_to_hwtstamp(struct igb_adapter *adapter, |
| 5513 | struct skb_shared_hwtstamps *shhwtstamps, |
| 5514 | u64 regval) |
| 5515 | { |
| 5516 | u64 ns; |
| 5517 | |
Alexander Duyck | 55cac24 | 2009-11-19 12:42:21 +0000 | [diff] [blame] | 5518 | /* |
| 5519 | * The 82580 starts with 1ns at bit 0 in RX/TXSTMPL, shift this up to |
| 5520 | * 24 to match clock shift we setup earlier. |
| 5521 | */ |
| 5522 | if (adapter->hw.mac.type == e1000_82580) |
| 5523 | regval <<= IGB_82580_TSYNC_SHIFT; |
| 5524 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5525 | ns = timecounter_cyc2time(&adapter->clock, regval); |
| 5526 | timecompare_update(&adapter->compare, ns); |
| 5527 | memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps)); |
| 5528 | shhwtstamps->hwtstamp = ns_to_ktime(ns); |
| 5529 | shhwtstamps->syststamp = timecompare_transform(&adapter->compare, ns); |
| 5530 | } |
| 5531 | |
| 5532 | /** |
| 5533 | * igb_tx_hwtstamp - utility function which checks for TX time stamp |
| 5534 | * @q_vector: pointer to q_vector containing needed info |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5535 | * @buffer: pointer to igb_tx_buffer structure |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5536 | * |
| 5537 | * If we were asked to do hardware stamping and such a time stamp is |
| 5538 | * available, then it must have been for this skb here because we only |
| 5539 | * allow only one such packet into the queue. |
| 5540 | */ |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5541 | static void igb_tx_hwtstamp(struct igb_q_vector *q_vector, |
| 5542 | struct igb_tx_buffer *buffer_info) |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5543 | { |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5544 | struct igb_adapter *adapter = q_vector->adapter; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5545 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5546 | struct skb_shared_hwtstamps shhwtstamps; |
| 5547 | u64 regval; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5548 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5549 | /* if skb does not support hw timestamp or TX stamp not valid exit */ |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 5550 | if (likely(!(buffer_info->tx_flags & SKBTX_HW_TSTAMP)) || |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5551 | !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID)) |
| 5552 | return; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5553 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5554 | regval = rd32(E1000_TXSTMPL); |
| 5555 | regval |= (u64)rd32(E1000_TXSTMPH) << 32; |
| 5556 | |
| 5557 | igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval); |
Nick Nunley | 2873957 | 2010-05-04 21:58:07 +0000 | [diff] [blame] | 5558 | skb_tstamp_tx(buffer_info->skb, &shhwtstamps); |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5562 | * igb_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5563 | * @q_vector: pointer to q_vector containing needed info |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5564 | * returns true if ring is completely cleaned |
| 5565 | **/ |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5566 | static bool igb_clean_tx_irq(struct igb_q_vector *q_vector) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5567 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5568 | struct igb_adapter *adapter = q_vector->adapter; |
| 5569 | struct igb_ring *tx_ring = q_vector->tx_ring; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5570 | struct igb_tx_buffer *tx_buffer; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5571 | union e1000_adv_tx_desc *tx_desc; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5572 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5573 | unsigned int budget = q_vector->tx_work_limit; |
| 5574 | u16 i = tx_ring->next_to_clean; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5575 | |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5576 | if (test_bit(__IGB_DOWN, &adapter->state)) |
| 5577 | return true; |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5578 | |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5579 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5580 | tx_desc = IGB_TX_DESC(tx_ring, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5581 | |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5582 | for (; budget; budget--) { |
| 5583 | u16 eop = tx_buffer->next_to_watch; |
| 5584 | union e1000_adv_tx_desc *eop_desc; |
| 5585 | |
| 5586 | eop_desc = IGB_TX_DESC(tx_ring, eop); |
| 5587 | |
| 5588 | /* if DD is not set pending work has not been completed */ |
| 5589 | if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD))) |
| 5590 | break; |
| 5591 | |
| 5592 | /* prevent any other reads prior to eop_desc being verified */ |
| 5593 | rmb(); |
| 5594 | |
| 5595 | do { |
| 5596 | tx_desc->wb.status = 0; |
| 5597 | if (likely(tx_desc == eop_desc)) { |
| 5598 | eop_desc = NULL; |
| 5599 | |
| 5600 | total_bytes += tx_buffer->bytecount; |
| 5601 | total_packets += tx_buffer->gso_segs; |
| 5602 | igb_tx_hwtstamp(q_vector, tx_buffer); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5603 | } |
| 5604 | |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5605 | igb_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5606 | |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5607 | tx_buffer++; |
| 5608 | tx_desc++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5609 | i++; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5610 | if (unlikely(i == tx_ring->count)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5611 | i = 0; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5612 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5613 | tx_desc = IGB_TX_DESC(tx_ring, 0); |
| 5614 | } |
| 5615 | } while (eop_desc); |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5616 | } |
| 5617 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5618 | tx_ring->next_to_clean = i; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5619 | u64_stats_update_begin(&tx_ring->tx_syncp); |
| 5620 | tx_ring->tx_stats.bytes += total_bytes; |
| 5621 | tx_ring->tx_stats.packets += total_packets; |
| 5622 | u64_stats_update_end(&tx_ring->tx_syncp); |
| 5623 | tx_ring->total_bytes += total_bytes; |
| 5624 | tx_ring->total_packets += total_packets; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5625 | |
| 5626 | if (tx_ring->detect_tx_hung) { |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5627 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5628 | u16 eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5629 | union e1000_adv_tx_desc *eop_desc; |
| 5630 | |
| 5631 | eop_desc = IGB_TX_DESC(tx_ring, eop); |
| 5632 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5633 | /* Detect a transmit hang in hardware, this serializes the |
| 5634 | * check with the clearing of time_stamp and movement of i */ |
| 5635 | tx_ring->detect_tx_hung = false; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5636 | if (tx_ring->tx_buffer_info[i].time_stamp && |
| 5637 | time_after(jiffies, tx_ring->tx_buffer_info[i].time_stamp + |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 5638 | (adapter->tx_timeout_factor * HZ)) && |
| 5639 | !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5640 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5641 | /* detected Tx unit hang */ |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5642 | dev_err(tx_ring->dev, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5643 | "Detected Tx Unit Hang\n" |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 5644 | " Tx Queue <%d>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5645 | " TDH <%x>\n" |
| 5646 | " TDT <%x>\n" |
| 5647 | " next_to_use <%x>\n" |
| 5648 | " next_to_clean <%x>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5649 | "buffer_info[next_to_clean]\n" |
| 5650 | " time_stamp <%lx>\n" |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5651 | " next_to_watch <%x>\n" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5652 | " jiffies <%lx>\n" |
| 5653 | " desc.status <%x>\n", |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 5654 | tx_ring->queue_index, |
Alexander Duyck | 238ac81 | 2011-08-26 07:43:48 +0000 | [diff] [blame] | 5655 | rd32(E1000_TDH(tx_ring->reg_idx)), |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 5656 | readl(tx_ring->tail), |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5657 | tx_ring->next_to_use, |
| 5658 | tx_ring->next_to_clean, |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5659 | tx_ring->tx_buffer_info[eop].time_stamp, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5660 | eop, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5661 | jiffies, |
Alexander Duyck | 0e014cb | 2008-12-26 01:33:18 -0800 | [diff] [blame] | 5662 | eop_desc->wb.status); |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5663 | netif_stop_subqueue(tx_ring->netdev, |
| 5664 | tx_ring->queue_index); |
| 5665 | |
| 5666 | /* we are about to reset, no point in enabling stuff */ |
| 5667 | return true; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5668 | } |
| 5669 | } |
Alexander Duyck | 13fde97 | 2011-10-05 13:35:24 +0000 | [diff] [blame] | 5670 | |
| 5671 | if (unlikely(total_packets && |
| 5672 | netif_carrier_ok(tx_ring->netdev) && |
| 5673 | igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) { |
| 5674 | /* Make sure that anybody stopping the queue after this |
| 5675 | * sees the new next_to_clean. |
| 5676 | */ |
| 5677 | smp_mb(); |
| 5678 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 5679 | tx_ring->queue_index) && |
| 5680 | !(test_bit(__IGB_DOWN, &adapter->state))) { |
| 5681 | netif_wake_subqueue(tx_ring->netdev, |
| 5682 | tx_ring->queue_index); |
| 5683 | |
| 5684 | u64_stats_update_begin(&tx_ring->tx_syncp); |
| 5685 | tx_ring->tx_stats.restart_queue++; |
| 5686 | u64_stats_update_end(&tx_ring->tx_syncp); |
| 5687 | } |
| 5688 | } |
| 5689 | |
| 5690 | return !!budget; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5691 | } |
| 5692 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5693 | static inline void igb_rx_checksum(struct igb_ring *ring, |
| 5694 | u32 status_err, struct sk_buff *skb) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5695 | { |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5696 | skb_checksum_none_assert(skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5697 | |
| 5698 | /* Ignore Checksum bit is set or checksum is disabled through ethtool */ |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5699 | if (!(ring->flags & IGB_RING_FLAG_RX_CSUM) || |
| 5700 | (status_err & E1000_RXD_STAT_IXSM)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5701 | return; |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5702 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5703 | /* TCP/UDP checksum error bit is set */ |
| 5704 | if (status_err & |
| 5705 | (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) { |
Jesse Brandeburg | b947356 | 2009-04-27 22:36:13 +0000 | [diff] [blame] | 5706 | /* |
| 5707 | * work around errata with sctp packets where the TCPE aka |
| 5708 | * L4E bit is set incorrectly on 64 byte (60 byte w/o crc) |
| 5709 | * packets, (aka let the stack check the crc32c) |
| 5710 | */ |
Alexander Duyck | 85ad76b | 2009-10-27 15:52:46 +0000 | [diff] [blame] | 5711 | if ((skb->len == 60) && |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 5712 | (ring->flags & IGB_RING_FLAG_RX_SCTP_CSUM)) { |
| 5713 | u64_stats_update_begin(&ring->rx_syncp); |
Alexander Duyck | 04a5fca | 2009-10-27 15:52:27 +0000 | [diff] [blame] | 5714 | ring->rx_stats.csum_err++; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 5715 | u64_stats_update_end(&ring->rx_syncp); |
| 5716 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5717 | /* let the stack verify checksum errors */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5718 | return; |
| 5719 | } |
| 5720 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 5721 | if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)) |
| 5722 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5723 | |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5724 | dev_dbg(ring->dev, "cksum success: bits %08X\n", status_err); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5725 | } |
| 5726 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5727 | static void igb_rx_hwtstamp(struct igb_q_vector *q_vector, u32 staterr, |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5728 | struct sk_buff *skb) |
| 5729 | { |
| 5730 | struct igb_adapter *adapter = q_vector->adapter; |
| 5731 | struct e1000_hw *hw = &adapter->hw; |
| 5732 | u64 regval; |
| 5733 | |
| 5734 | /* |
| 5735 | * If this bit is set, then the RX registers contain the time stamp. No |
| 5736 | * other packet will be time stamped until we read these registers, so |
| 5737 | * read the registers to make them available again. Because only one |
| 5738 | * packet can be time stamped at a time, we know that the register |
| 5739 | * values must belong to this one here and therefore we don't need to |
| 5740 | * compare any of the additional attributes stored for it. |
| 5741 | * |
Oliver Hartkopp | 2244d07 | 2010-08-17 08:59:14 +0000 | [diff] [blame] | 5742 | * If nothing went wrong, then it should have a shared tx_flags that we |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5743 | * can turn into a skb_shared_hwtstamps. |
| 5744 | */ |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5745 | if (staterr & E1000_RXDADV_STAT_TSIP) { |
| 5746 | u32 *stamp = (u32 *)skb->data; |
| 5747 | regval = le32_to_cpu(*(stamp + 2)); |
| 5748 | regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32; |
| 5749 | skb_pull(skb, IGB_TS_HDR_LEN); |
| 5750 | } else { |
| 5751 | if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) |
| 5752 | return; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5753 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5754 | regval = rd32(E1000_RXSTMPL); |
| 5755 | regval |= (u64)rd32(E1000_RXSTMPH) << 32; |
| 5756 | } |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 5757 | |
| 5758 | igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval); |
| 5759 | } |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 5760 | static inline u16 igb_get_hlen(union e1000_adv_rx_desc *rx_desc) |
Alexander Duyck | 2d94d8a | 2009-07-23 18:10:06 +0000 | [diff] [blame] | 5761 | { |
| 5762 | /* HW will not DMA in data larger than the given buffer, even if it |
| 5763 | * parses the (NFS, of course) header to be larger. In that case, it |
| 5764 | * fills the header buffer and spills the rest into the page. |
| 5765 | */ |
| 5766 | u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) & |
| 5767 | E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT; |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 5768 | if (hlen > IGB_RX_HDR_LEN) |
| 5769 | hlen = IGB_RX_HDR_LEN; |
Alexander Duyck | 2d94d8a | 2009-07-23 18:10:06 +0000 | [diff] [blame] | 5770 | return hlen; |
| 5771 | } |
| 5772 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5773 | static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5774 | { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5775 | struct igb_ring *rx_ring = q_vector->rx_ring; |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5776 | union e1000_adv_rx_desc *rx_desc; |
| 5777 | const int current_node = numa_node_id(); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5778 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 2d94d8a | 2009-07-23 18:10:06 +0000 | [diff] [blame] | 5779 | u32 staterr; |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5780 | u16 cleaned_count = igb_desc_unused(rx_ring); |
| 5781 | u16 i = rx_ring->next_to_clean; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5782 | |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 5783 | rx_desc = IGB_RX_DESC(rx_ring, i); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5784 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 5785 | |
| 5786 | while (staterr & E1000_RXD_STAT_DD) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5787 | struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5788 | struct sk_buff *skb = buffer_info->skb; |
| 5789 | union e1000_adv_rx_desc *next_rxd; |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5790 | |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5791 | buffer_info->skb = NULL; |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5792 | prefetch(skb->data); |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5793 | |
| 5794 | i++; |
| 5795 | if (i == rx_ring->count) |
| 5796 | i = 0; |
Alexander Duyck | 42d0781 | 2009-10-27 23:51:16 +0000 | [diff] [blame] | 5797 | |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 5798 | next_rxd = IGB_RX_DESC(rx_ring, i); |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5799 | prefetch(next_rxd); |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5800 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5801 | /* |
| 5802 | * This memory barrier is needed to keep us from reading |
| 5803 | * any other fields out of the rx_desc until we know the |
| 5804 | * RXD_STAT_DD bit is set |
| 5805 | */ |
| 5806 | rmb(); |
Alexander Duyck | 69d3ca5 | 2009-02-06 23:15:04 +0000 | [diff] [blame] | 5807 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5808 | if (!skb_is_nonlinear(skb)) { |
| 5809 | __skb_put(skb, igb_get_hlen(rx_desc)); |
| 5810 | dma_unmap_single(rx_ring->dev, buffer_info->dma, |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 5811 | IGB_RX_HDR_LEN, |
Alexander Duyck | 59d7198 | 2010-04-27 13:09:25 +0000 | [diff] [blame] | 5812 | DMA_FROM_DEVICE); |
Jesse Brandeburg | 91615f7 | 2009-06-30 12:45:15 +0000 | [diff] [blame] | 5813 | buffer_info->dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5814 | } |
| 5815 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5816 | if (rx_desc->wb.upper.length) { |
| 5817 | u16 length = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5818 | |
Koki Sanagi | aa91340 | 2010-04-27 01:01:19 +0000 | [diff] [blame] | 5819 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5820 | buffer_info->page, |
| 5821 | buffer_info->page_offset, |
| 5822 | length); |
| 5823 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5824 | skb->len += length; |
| 5825 | skb->data_len += length; |
| 5826 | skb->truesize += length; |
| 5827 | |
Alexander Duyck | d1eff35 | 2009-11-12 18:38:35 +0000 | [diff] [blame] | 5828 | if ((page_count(buffer_info->page) != 1) || |
| 5829 | (page_to_nid(buffer_info->page) != current_node)) |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5830 | buffer_info->page = NULL; |
| 5831 | else |
| 5832 | get_page(buffer_info->page); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5833 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5834 | dma_unmap_page(rx_ring->dev, buffer_info->page_dma, |
| 5835 | PAGE_SIZE / 2, DMA_FROM_DEVICE); |
| 5836 | buffer_info->page_dma = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5837 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5838 | |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5839 | if (!(staterr & E1000_RXD_STAT_EOP)) { |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5840 | struct igb_rx_buffer *next_buffer; |
| 5841 | next_buffer = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | b2d5653 | 2008-11-20 00:47:34 -0800 | [diff] [blame] | 5842 | buffer_info->skb = next_buffer->skb; |
| 5843 | buffer_info->dma = next_buffer->dma; |
| 5844 | next_buffer->skb = skb; |
| 5845 | next_buffer->dma = 0; |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5846 | goto next_desc; |
| 5847 | } |
Alexander Duyck | 44390ca | 2011-08-26 07:43:38 +0000 | [diff] [blame] | 5848 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5849 | if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) { |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5850 | dev_kfree_skb_any(skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5851 | goto next_desc; |
| 5852 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5853 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 5854 | if (staterr & (E1000_RXDADV_STAT_TSIP | E1000_RXDADV_STAT_TS)) |
| 5855 | igb_rx_hwtstamp(q_vector, staterr, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5856 | total_bytes += skb->len; |
| 5857 | total_packets++; |
| 5858 | |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5859 | igb_rx_checksum(rx_ring, staterr, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5860 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5861 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5862 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 5863 | if (staterr & E1000_RXD_STAT_VP) { |
| 5864 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 5865 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 5866 | __vlan_hwaccel_put_tag(skb, vid); |
| 5867 | } |
| 5868 | napi_gro_receive(&q_vector->napi, skb); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5869 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5870 | budget--; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5871 | next_desc: |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5872 | if (!budget) |
| 5873 | break; |
| 5874 | |
| 5875 | cleaned_count++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5876 | /* return some buffers to hardware, one at a time is too slow */ |
| 5877 | if (cleaned_count >= IGB_RX_BUFFER_WRITE) { |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5878 | igb_alloc_rx_buffers(rx_ring, cleaned_count); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5879 | cleaned_count = 0; |
| 5880 | } |
| 5881 | |
| 5882 | /* use prefetched values */ |
| 5883 | rx_desc = next_rxd; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5884 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 5885 | } |
Alexander Duyck | bf36c1a | 2008-07-08 15:11:40 -0700 | [diff] [blame] | 5886 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5887 | rx_ring->next_to_clean = i; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 5888 | u64_stats_update_begin(&rx_ring->rx_syncp); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5889 | rx_ring->rx_stats.packets += total_packets; |
| 5890 | rx_ring->rx_stats.bytes += total_bytes; |
Eric Dumazet | 12dcd86 | 2010-10-15 17:27:10 +0000 | [diff] [blame] | 5891 | u64_stats_update_end(&rx_ring->rx_syncp); |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5892 | rx_ring->total_packets += total_packets; |
| 5893 | rx_ring->total_bytes += total_bytes; |
| 5894 | |
| 5895 | if (cleaned_count) |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5896 | igb_alloc_rx_buffers(rx_ring, cleaned_count); |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5897 | |
Alexander Duyck | 16eb881 | 2011-08-26 07:43:54 +0000 | [diff] [blame] | 5898 | return !!budget; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5899 | } |
| 5900 | |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5901 | static bool igb_alloc_mapped_skb(struct igb_ring *rx_ring, |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5902 | struct igb_rx_buffer *bi) |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5903 | { |
| 5904 | struct sk_buff *skb = bi->skb; |
| 5905 | dma_addr_t dma = bi->dma; |
| 5906 | |
| 5907 | if (dma) |
| 5908 | return true; |
| 5909 | |
| 5910 | if (likely(!skb)) { |
| 5911 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 5912 | IGB_RX_HDR_LEN); |
| 5913 | bi->skb = skb; |
| 5914 | if (!skb) { |
| 5915 | rx_ring->rx_stats.alloc_failed++; |
| 5916 | return false; |
| 5917 | } |
| 5918 | |
| 5919 | /* initialize skb for ring */ |
| 5920 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 5921 | } |
| 5922 | |
| 5923 | dma = dma_map_single(rx_ring->dev, skb->data, |
| 5924 | IGB_RX_HDR_LEN, DMA_FROM_DEVICE); |
| 5925 | |
| 5926 | if (dma_mapping_error(rx_ring->dev, dma)) { |
| 5927 | rx_ring->rx_stats.alloc_failed++; |
| 5928 | return false; |
| 5929 | } |
| 5930 | |
| 5931 | bi->dma = dma; |
| 5932 | return true; |
| 5933 | } |
| 5934 | |
| 5935 | static bool igb_alloc_mapped_page(struct igb_ring *rx_ring, |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5936 | struct igb_rx_buffer *bi) |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5937 | { |
| 5938 | struct page *page = bi->page; |
| 5939 | dma_addr_t page_dma = bi->page_dma; |
| 5940 | unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2); |
| 5941 | |
| 5942 | if (page_dma) |
| 5943 | return true; |
| 5944 | |
| 5945 | if (!page) { |
| 5946 | page = netdev_alloc_page(rx_ring->netdev); |
| 5947 | bi->page = page; |
| 5948 | if (unlikely(!page)) { |
| 5949 | rx_ring->rx_stats.alloc_failed++; |
| 5950 | return false; |
| 5951 | } |
| 5952 | } |
| 5953 | |
| 5954 | page_dma = dma_map_page(rx_ring->dev, page, |
| 5955 | page_offset, PAGE_SIZE / 2, |
| 5956 | DMA_FROM_DEVICE); |
| 5957 | |
| 5958 | if (dma_mapping_error(rx_ring->dev, page_dma)) { |
| 5959 | rx_ring->rx_stats.alloc_failed++; |
| 5960 | return false; |
| 5961 | } |
| 5962 | |
| 5963 | bi->page_dma = page_dma; |
| 5964 | bi->page_offset = page_offset; |
| 5965 | return true; |
| 5966 | } |
| 5967 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5968 | /** |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5969 | * igb_alloc_rx_buffers - Replace used receive buffers; packet split |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5970 | * @adapter: address of board private structure |
| 5971 | **/ |
Alexander Duyck | cd392f5 | 2011-08-26 07:43:59 +0000 | [diff] [blame] | 5972 | void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5973 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5974 | union e1000_adv_rx_desc *rx_desc; |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5975 | struct igb_rx_buffer *bi; |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5976 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5977 | |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 5978 | rx_desc = IGB_RX_DESC(rx_ring, i); |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 5979 | bi = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5980 | i -= rx_ring->count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5981 | |
| 5982 | while (cleaned_count--) { |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5983 | if (!igb_alloc_mapped_skb(rx_ring, bi)) |
| 5984 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5985 | |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5986 | /* Refresh the desc even if buffer_addrs didn't change |
| 5987 | * because each write-back erases this info. */ |
| 5988 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5989 | |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5990 | if (!igb_alloc_mapped_page(rx_ring, bi)) |
| 5991 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5992 | |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5993 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5994 | |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5995 | rx_desc++; |
| 5996 | bi++; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5997 | i++; |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 5998 | if (unlikely(!i)) { |
Alexander Duyck | 6013690 | 2011-08-26 07:44:05 +0000 | [diff] [blame] | 5999 | rx_desc = IGB_RX_DESC(rx_ring, 0); |
Alexander Duyck | 0603464 | 2011-08-26 07:44:22 +0000 | [diff] [blame] | 6000 | bi = rx_ring->rx_buffer_info; |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 6001 | i -= rx_ring->count; |
| 6002 | } |
| 6003 | |
| 6004 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 6005 | rx_desc->read.hdr_addr = 0; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6006 | } |
| 6007 | |
Alexander Duyck | c023cd8 | 2011-08-26 07:43:43 +0000 | [diff] [blame] | 6008 | i += rx_ring->count; |
| 6009 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6010 | if (rx_ring->next_to_use != i) { |
| 6011 | rx_ring->next_to_use = i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6012 | |
| 6013 | /* Force memory writes to complete before letting h/w |
| 6014 | * know there are new descriptors to fetch. (Only |
| 6015 | * applicable for weak-ordered memory model archs, |
| 6016 | * such as IA-64). */ |
| 6017 | wmb(); |
Alexander Duyck | fce99e3 | 2009-10-27 15:51:27 +0000 | [diff] [blame] | 6018 | writel(i, rx_ring->tail); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6019 | } |
| 6020 | } |
| 6021 | |
| 6022 | /** |
| 6023 | * igb_mii_ioctl - |
| 6024 | * @netdev: |
| 6025 | * @ifreq: |
| 6026 | * @cmd: |
| 6027 | **/ |
| 6028 | static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 6029 | { |
| 6030 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6031 | struct mii_ioctl_data *data = if_mii(ifr); |
| 6032 | |
| 6033 | if (adapter->hw.phy.media_type != e1000_media_type_copper) |
| 6034 | return -EOPNOTSUPP; |
| 6035 | |
| 6036 | switch (cmd) { |
| 6037 | case SIOCGMIIPHY: |
| 6038 | data->phy_id = adapter->hw.phy.addr; |
| 6039 | break; |
| 6040 | case SIOCGMIIREG: |
Alexander Duyck | f5f4cf0 | 2008-11-21 21:30:24 -0800 | [diff] [blame] | 6041 | if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F, |
| 6042 | &data->val_out)) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6043 | return -EIO; |
| 6044 | break; |
| 6045 | case SIOCSMIIREG: |
| 6046 | default: |
| 6047 | return -EOPNOTSUPP; |
| 6048 | } |
| 6049 | return 0; |
| 6050 | } |
| 6051 | |
| 6052 | /** |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6053 | * igb_hwtstamp_ioctl - control hardware time stamping |
| 6054 | * @netdev: |
| 6055 | * @ifreq: |
| 6056 | * @cmd: |
| 6057 | * |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6058 | * Outgoing time stamping can be enabled and disabled. Play nice and |
| 6059 | * disable it when requested, although it shouldn't case any overhead |
| 6060 | * when no packet needs it. At most one packet in the queue may be |
| 6061 | * marked for time stamping, otherwise it would be impossible to tell |
| 6062 | * for sure to which packet the hardware time stamp belongs. |
| 6063 | * |
| 6064 | * Incoming time stamping has to be configured via the hardware |
| 6065 | * filters. Not all combinations are supported, in particular event |
| 6066 | * type has to be specified. Matching the kind of event packet is |
| 6067 | * not supported, with the exception of "all V2 events regardless of |
| 6068 | * level 2 or 4". |
| 6069 | * |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6070 | **/ |
| 6071 | static int igb_hwtstamp_ioctl(struct net_device *netdev, |
| 6072 | struct ifreq *ifr, int cmd) |
| 6073 | { |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6074 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6075 | struct e1000_hw *hw = &adapter->hw; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6076 | struct hwtstamp_config config; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6077 | u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; |
| 6078 | u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6079 | u32 tsync_rx_cfg = 0; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6080 | bool is_l4 = false; |
| 6081 | bool is_l2 = false; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6082 | u32 regval; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6083 | |
| 6084 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) |
| 6085 | return -EFAULT; |
| 6086 | |
| 6087 | /* reserved for future extensions */ |
| 6088 | if (config.flags) |
| 6089 | return -EINVAL; |
| 6090 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6091 | switch (config.tx_type) { |
| 6092 | case HWTSTAMP_TX_OFF: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6093 | tsync_tx_ctl = 0; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6094 | case HWTSTAMP_TX_ON: |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6095 | break; |
| 6096 | default: |
| 6097 | return -ERANGE; |
| 6098 | } |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6099 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6100 | switch (config.rx_filter) { |
| 6101 | case HWTSTAMP_FILTER_NONE: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6102 | tsync_rx_ctl = 0; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6103 | break; |
| 6104 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 6105 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 6106 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 6107 | case HWTSTAMP_FILTER_ALL: |
| 6108 | /* |
| 6109 | * register TSYNCRXCFG must be set, therefore it is not |
| 6110 | * possible to time stamp both Sync and Delay_Req messages |
| 6111 | * => fall back to time stamping all packets |
| 6112 | */ |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6113 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6114 | config.rx_filter = HWTSTAMP_FILTER_ALL; |
| 6115 | break; |
| 6116 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6117 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6118 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6119 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6120 | break; |
| 6121 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6122 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6123 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6124 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6125 | break; |
| 6126 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 6127 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6128 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6129 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6130 | is_l2 = true; |
| 6131 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6132 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 6133 | break; |
| 6134 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 6135 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6136 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6137 | tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6138 | is_l2 = true; |
| 6139 | is_l4 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6140 | config.rx_filter = HWTSTAMP_FILTER_SOME; |
| 6141 | break; |
| 6142 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 6143 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 6144 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6145 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6146 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6147 | is_l2 = true; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6148 | break; |
| 6149 | default: |
| 6150 | return -ERANGE; |
| 6151 | } |
| 6152 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6153 | if (hw->mac.type == e1000_82575) { |
| 6154 | if (tsync_rx_ctl | tsync_tx_ctl) |
| 6155 | return -EINVAL; |
| 6156 | return 0; |
| 6157 | } |
| 6158 | |
Nick Nunley | 757b77e | 2010-03-26 11:36:47 +0000 | [diff] [blame] | 6159 | /* |
| 6160 | * Per-packet timestamping only works if all packets are |
| 6161 | * timestamped, so enable timestamping in all packets as |
| 6162 | * long as one rx filter was configured. |
| 6163 | */ |
| 6164 | if ((hw->mac.type == e1000_82580) && tsync_rx_ctl) { |
| 6165 | tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; |
| 6166 | tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; |
| 6167 | } |
| 6168 | |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6169 | /* enable/disable TX */ |
| 6170 | regval = rd32(E1000_TSYNCTXCTL); |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6171 | regval &= ~E1000_TSYNCTXCTL_ENABLED; |
| 6172 | regval |= tsync_tx_ctl; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6173 | wr32(E1000_TSYNCTXCTL, regval); |
| 6174 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6175 | /* enable/disable RX */ |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6176 | regval = rd32(E1000_TSYNCRXCTL); |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6177 | regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); |
| 6178 | regval |= tsync_rx_ctl; |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6179 | wr32(E1000_TSYNCRXCTL, regval); |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6180 | |
| 6181 | /* define which PTP packets are time stamped */ |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6182 | wr32(E1000_TSYNCRXCFG, tsync_rx_cfg); |
| 6183 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6184 | /* define ethertype filter for timestamped packets */ |
| 6185 | if (is_l2) |
| 6186 | wr32(E1000_ETQF(3), |
| 6187 | (E1000_ETQF_FILTER_ENABLE | /* enable filter */ |
| 6188 | E1000_ETQF_1588 | /* enable timestamping */ |
| 6189 | ETH_P_1588)); /* 1588 eth protocol type */ |
| 6190 | else |
| 6191 | wr32(E1000_ETQF(3), 0); |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6192 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6193 | #define PTP_PORT 319 |
| 6194 | /* L4 Queue Filter[3]: filter by destination port and protocol */ |
| 6195 | if (is_l4) { |
| 6196 | u32 ftqf = (IPPROTO_UDP /* UDP */ |
| 6197 | | E1000_FTQF_VF_BP /* VF not compared */ |
| 6198 | | E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */ |
| 6199 | | E1000_FTQF_MASK); /* mask all inputs */ |
| 6200 | ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */ |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6201 | |
Alexander Duyck | c5b9bd5 | 2009-10-27 23:46:01 +0000 | [diff] [blame] | 6202 | wr32(E1000_IMIR(3), htons(PTP_PORT)); |
| 6203 | wr32(E1000_IMIREXT(3), |
| 6204 | (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP)); |
| 6205 | if (hw->mac.type == e1000_82576) { |
| 6206 | /* enable source port check */ |
| 6207 | wr32(E1000_SPQF(3), htons(PTP_PORT)); |
| 6208 | ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP; |
| 6209 | } |
| 6210 | wr32(E1000_FTQF(3), ftqf); |
| 6211 | } else { |
| 6212 | wr32(E1000_FTQF(3), E1000_FTQF_MASK); |
| 6213 | } |
Patrick Ohly | 33af6bc | 2009-02-12 05:03:43 +0000 | [diff] [blame] | 6214 | wrfl(); |
| 6215 | |
| 6216 | adapter->hwtstamp_config = config; |
| 6217 | |
| 6218 | /* clear TX/RX time stamp registers, just to be sure */ |
| 6219 | regval = rd32(E1000_TXSTMPH); |
| 6220 | regval = rd32(E1000_RXSTMPH); |
| 6221 | |
| 6222 | return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? |
| 6223 | -EFAULT : 0; |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | /** |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6227 | * igb_ioctl - |
| 6228 | * @netdev: |
| 6229 | * @ifreq: |
| 6230 | * @cmd: |
| 6231 | **/ |
| 6232 | static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 6233 | { |
| 6234 | switch (cmd) { |
| 6235 | case SIOCGMIIPHY: |
| 6236 | case SIOCGMIIREG: |
| 6237 | case SIOCSMIIREG: |
| 6238 | return igb_mii_ioctl(netdev, ifr, cmd); |
Patrick Ohly | c6cb090 | 2009-02-12 05:03:42 +0000 | [diff] [blame] | 6239 | case SIOCSHWTSTAMP: |
| 6240 | return igb_hwtstamp_ioctl(netdev, ifr, cmd); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6241 | default: |
| 6242 | return -EOPNOTSUPP; |
| 6243 | } |
| 6244 | } |
| 6245 | |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 6246 | s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
| 6247 | { |
| 6248 | struct igb_adapter *adapter = hw->back; |
| 6249 | u16 cap_offset; |
| 6250 | |
Jon Mason | bdaae04 | 2011-06-27 07:44:01 +0000 | [diff] [blame] | 6251 | cap_offset = adapter->pdev->pcie_cap; |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 6252 | if (!cap_offset) |
| 6253 | return -E1000_ERR_CONFIG; |
| 6254 | |
| 6255 | pci_read_config_word(adapter->pdev, cap_offset + reg, value); |
| 6256 | |
| 6257 | return 0; |
| 6258 | } |
| 6259 | |
| 6260 | s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value) |
| 6261 | { |
| 6262 | struct igb_adapter *adapter = hw->back; |
| 6263 | u16 cap_offset; |
| 6264 | |
Jon Mason | bdaae04 | 2011-06-27 07:44:01 +0000 | [diff] [blame] | 6265 | cap_offset = adapter->pdev->pcie_cap; |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 6266 | if (!cap_offset) |
| 6267 | return -E1000_ERR_CONFIG; |
| 6268 | |
| 6269 | pci_write_config_word(adapter->pdev, cap_offset + reg, *value); |
| 6270 | |
| 6271 | return 0; |
| 6272 | } |
| 6273 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 6274 | static void igb_vlan_mode(struct net_device *netdev, u32 features) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6275 | { |
| 6276 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6277 | struct e1000_hw *hw = &adapter->hw; |
| 6278 | u32 ctrl, rctl; |
| 6279 | |
| 6280 | igb_irq_disable(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6281 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 6282 | if (features & NETIF_F_HW_VLAN_RX) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6283 | /* enable VLAN tag insert/strip */ |
| 6284 | ctrl = rd32(E1000_CTRL); |
| 6285 | ctrl |= E1000_CTRL_VME; |
| 6286 | wr32(E1000_CTRL, ctrl); |
| 6287 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6288 | /* Disable CFI check */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6289 | rctl = rd32(E1000_RCTL); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6290 | rctl &= ~E1000_RCTL_CFIEN; |
| 6291 | wr32(E1000_RCTL, rctl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6292 | } else { |
| 6293 | /* disable VLAN tag insert/strip */ |
| 6294 | ctrl = rd32(E1000_CTRL); |
| 6295 | ctrl &= ~E1000_CTRL_VME; |
| 6296 | wr32(E1000_CTRL, ctrl); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6297 | } |
| 6298 | |
Alexander Duyck | e173952 | 2009-02-19 20:39:44 -0800 | [diff] [blame] | 6299 | igb_rlpml_set(adapter); |
| 6300 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6301 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 6302 | igb_irq_enable(adapter); |
| 6303 | } |
| 6304 | |
| 6305 | static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 6306 | { |
| 6307 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6308 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6309 | int pf_id = adapter->vfs_allocated_count; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6310 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6311 | /* attempt to add filter to vlvf array */ |
| 6312 | igb_vlvf_set(adapter, vid, true, pf_id); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6313 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6314 | /* add the filter since PF can receive vlans w/o entry in vlvf */ |
| 6315 | igb_vfta_set(hw, vid, true); |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 6316 | |
| 6317 | set_bit(vid, adapter->active_vlans); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 6321 | { |
| 6322 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6323 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6324 | int pf_id = adapter->vfs_allocated_count; |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6325 | s32 err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6326 | |
| 6327 | igb_irq_disable(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6328 | |
| 6329 | if (!test_bit(__IGB_DOWN, &adapter->state)) |
| 6330 | igb_irq_enable(adapter); |
| 6331 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6332 | /* remove vlan from VLVF table array */ |
| 6333 | err = igb_vlvf_set(adapter, vid, false, pf_id); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6334 | |
Alexander Duyck | 5146623 | 2009-10-27 23:47:35 +0000 | [diff] [blame] | 6335 | /* if vid was not present in VLVF just remove it from table */ |
| 6336 | if (err) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6337 | igb_vfta_set(hw, vid, false); |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 6338 | |
| 6339 | clear_bit(vid, adapter->active_vlans); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | static void igb_restore_vlan(struct igb_adapter *adapter) |
| 6343 | { |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 6344 | u16 vid; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6345 | |
Jiri Pirko | b2cb09b | 2011-07-21 03:27:27 +0000 | [diff] [blame] | 6346 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 6347 | igb_vlan_rx_add_vid(adapter->netdev, vid); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6348 | } |
| 6349 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 6350 | int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6351 | { |
Alexander Duyck | 090b179 | 2009-10-27 23:51:55 +0000 | [diff] [blame] | 6352 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6353 | struct e1000_mac_info *mac = &adapter->hw.mac; |
| 6354 | |
| 6355 | mac->autoneg = 0; |
| 6356 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 6357 | /* Make sure dplx is at most 1 bit and lsb of speed is not set |
| 6358 | * for the switch() below to work */ |
| 6359 | if ((spd & 1) || (dplx & ~1)) |
| 6360 | goto err_inval; |
| 6361 | |
Carolyn Wyborny | cd2638a | 2010-10-12 22:27:02 +0000 | [diff] [blame] | 6362 | /* Fiber NIC's only allow 1000 Gbps Full duplex */ |
| 6363 | if ((adapter->hw.phy.media_type == e1000_media_type_internal_serdes) && |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 6364 | spd != SPEED_1000 && |
| 6365 | dplx != DUPLEX_FULL) |
| 6366 | goto err_inval; |
Carolyn Wyborny | cd2638a | 2010-10-12 22:27:02 +0000 | [diff] [blame] | 6367 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 6368 | switch (spd + dplx) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6369 | case SPEED_10 + DUPLEX_HALF: |
| 6370 | mac->forced_speed_duplex = ADVERTISE_10_HALF; |
| 6371 | break; |
| 6372 | case SPEED_10 + DUPLEX_FULL: |
| 6373 | mac->forced_speed_duplex = ADVERTISE_10_FULL; |
| 6374 | break; |
| 6375 | case SPEED_100 + DUPLEX_HALF: |
| 6376 | mac->forced_speed_duplex = ADVERTISE_100_HALF; |
| 6377 | break; |
| 6378 | case SPEED_100 + DUPLEX_FULL: |
| 6379 | mac->forced_speed_duplex = ADVERTISE_100_FULL; |
| 6380 | break; |
| 6381 | case SPEED_1000 + DUPLEX_FULL: |
| 6382 | mac->autoneg = 1; |
| 6383 | adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL; |
| 6384 | break; |
| 6385 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 6386 | default: |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 6387 | goto err_inval; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6388 | } |
| 6389 | return 0; |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 6390 | |
| 6391 | err_inval: |
| 6392 | dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n"); |
| 6393 | return -EINVAL; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6394 | } |
| 6395 | |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6396 | static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6397 | { |
| 6398 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6399 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6400 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 6401 | u32 ctrl, rctl, status; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6402 | u32 wufc = adapter->wol; |
| 6403 | #ifdef CONFIG_PM |
| 6404 | int retval = 0; |
| 6405 | #endif |
| 6406 | |
| 6407 | netif_device_detach(netdev); |
| 6408 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 6409 | if (netif_running(netdev)) |
| 6410 | igb_close(netdev); |
| 6411 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6412 | igb_clear_interrupt_scheme(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6413 | |
| 6414 | #ifdef CONFIG_PM |
| 6415 | retval = pci_save_state(pdev); |
| 6416 | if (retval) |
| 6417 | return retval; |
| 6418 | #endif |
| 6419 | |
| 6420 | status = rd32(E1000_STATUS); |
| 6421 | if (status & E1000_STATUS_LU) |
| 6422 | wufc &= ~E1000_WUFC_LNKC; |
| 6423 | |
| 6424 | if (wufc) { |
| 6425 | igb_setup_rctl(adapter); |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 6426 | igb_set_rx_mode(netdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6427 | |
| 6428 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 6429 | if (wufc & E1000_WUFC_MC) { |
| 6430 | rctl = rd32(E1000_RCTL); |
| 6431 | rctl |= E1000_RCTL_MPE; |
| 6432 | wr32(E1000_RCTL, rctl); |
| 6433 | } |
| 6434 | |
| 6435 | ctrl = rd32(E1000_CTRL); |
| 6436 | /* advertise wake from D3Cold */ |
| 6437 | #define E1000_CTRL_ADVD3WUC 0x00100000 |
| 6438 | /* phy power management enable */ |
| 6439 | #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000 |
| 6440 | ctrl |= E1000_CTRL_ADVD3WUC; |
| 6441 | wr32(E1000_CTRL, ctrl); |
| 6442 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6443 | /* Allow time for pending master requests to run */ |
Alexander Duyck | 330a6d6 | 2009-10-27 23:51:35 +0000 | [diff] [blame] | 6444 | igb_disable_pcie_master(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6445 | |
| 6446 | wr32(E1000_WUC, E1000_WUC_PME_EN); |
| 6447 | wr32(E1000_WUFC, wufc); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6448 | } else { |
| 6449 | wr32(E1000_WUC, 0); |
| 6450 | wr32(E1000_WUFC, 0); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6451 | } |
| 6452 | |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6453 | *enable_wake = wufc || adapter->en_mng_pt; |
| 6454 | if (!*enable_wake) |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 6455 | igb_power_down_link(adapter); |
| 6456 | else |
| 6457 | igb_power_up_link(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6458 | |
| 6459 | /* Release control of h/w to f/w. If f/w is AMT enabled, this |
| 6460 | * would have already happened in close and is redundant. */ |
| 6461 | igb_release_hw_control(adapter); |
| 6462 | |
| 6463 | pci_disable_device(pdev); |
| 6464 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6465 | return 0; |
| 6466 | } |
| 6467 | |
| 6468 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6469 | static int igb_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6470 | { |
| 6471 | int retval; |
| 6472 | bool wake; |
| 6473 | |
| 6474 | retval = __igb_shutdown(pdev, &wake); |
| 6475 | if (retval) |
| 6476 | return retval; |
| 6477 | |
| 6478 | if (wake) { |
| 6479 | pci_prepare_to_sleep(pdev); |
| 6480 | } else { |
| 6481 | pci_wake_from_d3(pdev, false); |
| 6482 | pci_set_power_state(pdev, PCI_D3hot); |
| 6483 | } |
| 6484 | |
| 6485 | return 0; |
| 6486 | } |
| 6487 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6488 | static int igb_resume(struct pci_dev *pdev) |
| 6489 | { |
| 6490 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6491 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6492 | struct e1000_hw *hw = &adapter->hw; |
| 6493 | u32 err; |
| 6494 | |
| 6495 | pci_set_power_state(pdev, PCI_D0); |
| 6496 | pci_restore_state(pdev); |
Nick Nunley | b94f2d7 | 2010-02-17 01:02:19 +0000 | [diff] [blame] | 6497 | pci_save_state(pdev); |
Taku Izumi | 42bfd33 | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 6498 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 6499 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6500 | if (err) { |
| 6501 | dev_err(&pdev->dev, |
| 6502 | "igb: Cannot enable PCI device from suspend\n"); |
| 6503 | return err; |
| 6504 | } |
| 6505 | pci_set_master(pdev); |
| 6506 | |
| 6507 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 6508 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 6509 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6510 | if (igb_init_interrupt_scheme(adapter)) { |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 6511 | dev_err(&pdev->dev, "Unable to allocate memory for queues\n"); |
| 6512 | return -ENOMEM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6513 | } |
| 6514 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6515 | igb_reset(adapter); |
Alexander Duyck | a8564f0 | 2009-02-06 23:21:10 +0000 | [diff] [blame] | 6516 | |
| 6517 | /* let the f/w know that the h/w is now under the control of the |
| 6518 | * driver. */ |
| 6519 | igb_get_hw_control(adapter); |
| 6520 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6521 | wr32(E1000_WUS, ~0); |
| 6522 | |
Alexander Duyck | a88f10e | 2008-07-08 15:13:38 -0700 | [diff] [blame] | 6523 | if (netif_running(netdev)) { |
| 6524 | err = igb_open(netdev); |
| 6525 | if (err) |
| 6526 | return err; |
| 6527 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6528 | |
| 6529 | netif_device_attach(netdev); |
| 6530 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6531 | return 0; |
| 6532 | } |
| 6533 | #endif |
| 6534 | |
| 6535 | static void igb_shutdown(struct pci_dev *pdev) |
| 6536 | { |
Rafael J. Wysocki | 3fe7c4c | 2009-03-31 21:23:50 +0000 | [diff] [blame] | 6537 | bool wake; |
| 6538 | |
| 6539 | __igb_shutdown(pdev, &wake); |
| 6540 | |
| 6541 | if (system_state == SYSTEM_POWER_OFF) { |
| 6542 | pci_wake_from_d3(pdev, wake); |
| 6543 | pci_set_power_state(pdev, PCI_D3hot); |
| 6544 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6545 | } |
| 6546 | |
| 6547 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6548 | /* |
| 6549 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 6550 | * without having to re-enable interrupts. It's not called while |
| 6551 | * the interrupt routine is executing. |
| 6552 | */ |
| 6553 | static void igb_netpoll(struct net_device *netdev) |
| 6554 | { |
| 6555 | struct igb_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6556 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6557 | int i; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6558 | |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6559 | if (!adapter->msix_entries) { |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6560 | struct igb_q_vector *q_vector = adapter->q_vector[0]; |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6561 | igb_irq_disable(adapter); |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6562 | napi_schedule(&q_vector->napi); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6563 | return; |
| 6564 | } |
Alexander Duyck | 7dfc16f | 2008-07-08 15:10:46 -0700 | [diff] [blame] | 6565 | |
Alexander Duyck | 047e003 | 2009-10-27 15:49:27 +0000 | [diff] [blame] | 6566 | for (i = 0; i < adapter->num_q_vectors; i++) { |
| 6567 | struct igb_q_vector *q_vector = adapter->q_vector[i]; |
| 6568 | wr32(E1000_EIMC, q_vector->eims_value); |
| 6569 | napi_schedule(&q_vector->napi); |
Alexander Duyck | eebbbdb | 2009-02-06 23:19:29 +0000 | [diff] [blame] | 6570 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6571 | } |
| 6572 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 6573 | |
| 6574 | /** |
| 6575 | * igb_io_error_detected - called when PCI error is detected |
| 6576 | * @pdev: Pointer to PCI device |
| 6577 | * @state: The current pci connection state |
| 6578 | * |
| 6579 | * This function is called after a PCI bus error affecting |
| 6580 | * this device has been detected. |
| 6581 | */ |
| 6582 | static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev, |
| 6583 | pci_channel_state_t state) |
| 6584 | { |
| 6585 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6586 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6587 | |
| 6588 | netif_device_detach(netdev); |
| 6589 | |
Alexander Duyck | 59ed6ee | 2009-06-30 12:46:34 +0000 | [diff] [blame] | 6590 | if (state == pci_channel_io_perm_failure) |
| 6591 | return PCI_ERS_RESULT_DISCONNECT; |
| 6592 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6593 | if (netif_running(netdev)) |
| 6594 | igb_down(adapter); |
| 6595 | pci_disable_device(pdev); |
| 6596 | |
| 6597 | /* Request a slot slot reset. */ |
| 6598 | return PCI_ERS_RESULT_NEED_RESET; |
| 6599 | } |
| 6600 | |
| 6601 | /** |
| 6602 | * igb_io_slot_reset - called after the pci bus has been reset. |
| 6603 | * @pdev: Pointer to PCI device |
| 6604 | * |
| 6605 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 6606 | * resembles the first-half of the igb_resume routine. |
| 6607 | */ |
| 6608 | static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev) |
| 6609 | { |
| 6610 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6611 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6612 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6613 | pci_ers_result_t result; |
Taku Izumi | 42bfd33 | 2008-06-20 12:10:30 +0900 | [diff] [blame] | 6614 | int err; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6615 | |
Alexander Duyck | aed5dec | 2009-02-06 23:16:04 +0000 | [diff] [blame] | 6616 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6617 | dev_err(&pdev->dev, |
| 6618 | "Cannot re-enable PCI device after reset.\n"); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6619 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6620 | } else { |
| 6621 | pci_set_master(pdev); |
| 6622 | pci_restore_state(pdev); |
Nick Nunley | b94f2d7 | 2010-02-17 01:02:19 +0000 | [diff] [blame] | 6623 | pci_save_state(pdev); |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6624 | |
| 6625 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 6626 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 6627 | |
| 6628 | igb_reset(adapter); |
| 6629 | wr32(E1000_WUS, ~0); |
| 6630 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6631 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6632 | |
Jeff Kirsher | ea943d4 | 2008-12-11 20:34:19 -0800 | [diff] [blame] | 6633 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6634 | if (err) { |
| 6635 | dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status " |
| 6636 | "failed 0x%0x\n", err); |
| 6637 | /* non-fatal, continue */ |
| 6638 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6639 | |
Alexander Duyck | 40a914f | 2008-11-27 00:24:37 -0800 | [diff] [blame] | 6640 | return result; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | /** |
| 6644 | * igb_io_resume - called when traffic can start flowing again. |
| 6645 | * @pdev: Pointer to PCI device |
| 6646 | * |
| 6647 | * This callback is called when the error recovery driver tells us that |
| 6648 | * its OK to resume normal operation. Implementation resembles the |
| 6649 | * second-half of the igb_resume routine. |
| 6650 | */ |
| 6651 | static void igb_io_resume(struct pci_dev *pdev) |
| 6652 | { |
| 6653 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6654 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6655 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6656 | if (netif_running(netdev)) { |
| 6657 | if (igb_up(adapter)) { |
| 6658 | dev_err(&pdev->dev, "igb_up failed after reset\n"); |
| 6659 | return; |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | netif_device_attach(netdev); |
| 6664 | |
| 6665 | /* let the f/w know that the h/w is now under the control of the |
| 6666 | * driver. */ |
| 6667 | igb_get_hw_control(adapter); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6668 | } |
| 6669 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 6670 | static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index, |
| 6671 | u8 qsel) |
| 6672 | { |
| 6673 | u32 rar_low, rar_high; |
| 6674 | struct e1000_hw *hw = &adapter->hw; |
| 6675 | |
| 6676 | /* HW expects these in little endian so we reverse the byte order |
| 6677 | * from network order (big endian) to little endian |
| 6678 | */ |
| 6679 | rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) | |
| 6680 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); |
| 6681 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); |
| 6682 | |
| 6683 | /* Indicate to hardware the Address is Valid. */ |
| 6684 | rar_high |= E1000_RAH_AV; |
| 6685 | |
| 6686 | if (hw->mac.type == e1000_82575) |
| 6687 | rar_high |= E1000_RAH_POOL_1 * qsel; |
| 6688 | else |
| 6689 | rar_high |= E1000_RAH_POOL_1 << qsel; |
| 6690 | |
| 6691 | wr32(E1000_RAL(index), rar_low); |
| 6692 | wrfl(); |
| 6693 | wr32(E1000_RAH(index), rar_high); |
| 6694 | wrfl(); |
| 6695 | } |
| 6696 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6697 | static int igb_set_vf_mac(struct igb_adapter *adapter, |
| 6698 | int vf, unsigned char *mac_addr) |
| 6699 | { |
| 6700 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | ff41f8d | 2009-09-03 14:48:56 +0000 | [diff] [blame] | 6701 | /* VF MAC addresses start at end of receive addresses and moves |
| 6702 | * torwards the first, as a result a collision should not be possible */ |
| 6703 | int rar_entry = hw->mac.rar_entry_count - (vf + 1); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6704 | |
Alexander Duyck | 3768011 | 2009-02-19 20:40:30 -0800 | [diff] [blame] | 6705 | memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6706 | |
Alexander Duyck | 26ad917 | 2009-10-05 06:32:49 +0000 | [diff] [blame] | 6707 | igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf); |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6708 | |
| 6709 | return 0; |
| 6710 | } |
| 6711 | |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 6712 | static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) |
| 6713 | { |
| 6714 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6715 | if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count)) |
| 6716 | return -EINVAL; |
| 6717 | adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC; |
| 6718 | dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf); |
| 6719 | dev_info(&adapter->pdev->dev, "Reload the VF driver to make this" |
| 6720 | " change effective."); |
| 6721 | if (test_bit(__IGB_DOWN, &adapter->state)) { |
| 6722 | dev_warn(&adapter->pdev->dev, "The VF MAC address has been set," |
| 6723 | " but the PF device is not up.\n"); |
| 6724 | dev_warn(&adapter->pdev->dev, "Bring the PF device up before" |
| 6725 | " attempting to use the VF device.\n"); |
| 6726 | } |
| 6727 | return igb_set_vf_mac(adapter, vf, mac); |
| 6728 | } |
| 6729 | |
Lior Levy | 17dc566 | 2011-02-08 02:28:46 +0000 | [diff] [blame] | 6730 | static int igb_link_mbps(int internal_link_speed) |
| 6731 | { |
| 6732 | switch (internal_link_speed) { |
| 6733 | case SPEED_100: |
| 6734 | return 100; |
| 6735 | case SPEED_1000: |
| 6736 | return 1000; |
| 6737 | default: |
| 6738 | return 0; |
| 6739 | } |
| 6740 | } |
| 6741 | |
| 6742 | static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate, |
| 6743 | int link_speed) |
| 6744 | { |
| 6745 | int rf_dec, rf_int; |
| 6746 | u32 bcnrc_val; |
| 6747 | |
| 6748 | if (tx_rate != 0) { |
| 6749 | /* Calculate the rate factor values to set */ |
| 6750 | rf_int = link_speed / tx_rate; |
| 6751 | rf_dec = (link_speed - (rf_int * tx_rate)); |
| 6752 | rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate; |
| 6753 | |
| 6754 | bcnrc_val = E1000_RTTBCNRC_RS_ENA; |
| 6755 | bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) & |
| 6756 | E1000_RTTBCNRC_RF_INT_MASK); |
| 6757 | bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK); |
| 6758 | } else { |
| 6759 | bcnrc_val = 0; |
| 6760 | } |
| 6761 | |
| 6762 | wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */ |
| 6763 | wr32(E1000_RTTBCNRC, bcnrc_val); |
| 6764 | } |
| 6765 | |
| 6766 | static void igb_check_vf_rate_limit(struct igb_adapter *adapter) |
| 6767 | { |
| 6768 | int actual_link_speed, i; |
| 6769 | bool reset_rate = false; |
| 6770 | |
| 6771 | /* VF TX rate limit was not set or not supported */ |
| 6772 | if ((adapter->vf_rate_link_speed == 0) || |
| 6773 | (adapter->hw.mac.type != e1000_82576)) |
| 6774 | return; |
| 6775 | |
| 6776 | actual_link_speed = igb_link_mbps(adapter->link_speed); |
| 6777 | if (actual_link_speed != adapter->vf_rate_link_speed) { |
| 6778 | reset_rate = true; |
| 6779 | adapter->vf_rate_link_speed = 0; |
| 6780 | dev_info(&adapter->pdev->dev, |
| 6781 | "Link speed has been changed. VF Transmit " |
| 6782 | "rate is disabled\n"); |
| 6783 | } |
| 6784 | |
| 6785 | for (i = 0; i < adapter->vfs_allocated_count; i++) { |
| 6786 | if (reset_rate) |
| 6787 | adapter->vf_data[i].tx_rate = 0; |
| 6788 | |
| 6789 | igb_set_vf_rate_limit(&adapter->hw, i, |
| 6790 | adapter->vf_data[i].tx_rate, |
| 6791 | actual_link_speed); |
| 6792 | } |
| 6793 | } |
| 6794 | |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 6795 | static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate) |
| 6796 | { |
Lior Levy | 17dc566 | 2011-02-08 02:28:46 +0000 | [diff] [blame] | 6797 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6798 | struct e1000_hw *hw = &adapter->hw; |
| 6799 | int actual_link_speed; |
| 6800 | |
| 6801 | if (hw->mac.type != e1000_82576) |
| 6802 | return -EOPNOTSUPP; |
| 6803 | |
| 6804 | actual_link_speed = igb_link_mbps(adapter->link_speed); |
| 6805 | if ((vf >= adapter->vfs_allocated_count) || |
| 6806 | (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) || |
| 6807 | (tx_rate < 0) || (tx_rate > actual_link_speed)) |
| 6808 | return -EINVAL; |
| 6809 | |
| 6810 | adapter->vf_rate_link_speed = actual_link_speed; |
| 6811 | adapter->vf_data[vf].tx_rate = (u16)tx_rate; |
| 6812 | igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed); |
| 6813 | |
| 6814 | return 0; |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 6815 | } |
| 6816 | |
| 6817 | static int igb_ndo_get_vf_config(struct net_device *netdev, |
| 6818 | int vf, struct ifla_vf_info *ivi) |
| 6819 | { |
| 6820 | struct igb_adapter *adapter = netdev_priv(netdev); |
| 6821 | if (vf >= adapter->vfs_allocated_count) |
| 6822 | return -EINVAL; |
| 6823 | ivi->vf = vf; |
| 6824 | memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN); |
Lior Levy | 17dc566 | 2011-02-08 02:28:46 +0000 | [diff] [blame] | 6825 | ivi->tx_rate = adapter->vf_data[vf].tx_rate; |
Williams, Mitch A | 8151d29 | 2010-02-10 01:44:24 +0000 | [diff] [blame] | 6826 | ivi->vlan = adapter->vf_data[vf].pf_vlan; |
| 6827 | ivi->qos = adapter->vf_data[vf].pf_qos; |
| 6828 | return 0; |
| 6829 | } |
| 6830 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6831 | static void igb_vmm_control(struct igb_adapter *adapter) |
| 6832 | { |
| 6833 | struct e1000_hw *hw = &adapter->hw; |
Alexander Duyck | 10d8e90 | 2009-10-27 15:54:04 +0000 | [diff] [blame] | 6834 | u32 reg; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6835 | |
Alexander Duyck | 52a1dd4 | 2010-03-22 14:07:46 +0000 | [diff] [blame] | 6836 | switch (hw->mac.type) { |
| 6837 | case e1000_82575: |
| 6838 | default: |
| 6839 | /* replication is not supported for 82575 */ |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6840 | return; |
Alexander Duyck | 52a1dd4 | 2010-03-22 14:07:46 +0000 | [diff] [blame] | 6841 | case e1000_82576: |
| 6842 | /* notify HW that the MAC is adding vlan tags */ |
| 6843 | reg = rd32(E1000_DTXCTL); |
| 6844 | reg |= E1000_DTXCTL_VLAN_ADDED; |
| 6845 | wr32(E1000_DTXCTL, reg); |
| 6846 | case e1000_82580: |
| 6847 | /* enable replication vlan tag stripping */ |
| 6848 | reg = rd32(E1000_RPLOLR); |
| 6849 | reg |= E1000_RPLOLR_STRVLAN; |
| 6850 | wr32(E1000_RPLOLR, reg); |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 6851 | case e1000_i350: |
| 6852 | /* none of the above registers are supported by i350 */ |
Alexander Duyck | 52a1dd4 | 2010-03-22 14:07:46 +0000 | [diff] [blame] | 6853 | break; |
| 6854 | } |
Alexander Duyck | 10d8e90 | 2009-10-27 15:54:04 +0000 | [diff] [blame] | 6855 | |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 6856 | if (adapter->vfs_allocated_count) { |
| 6857 | igb_vmdq_set_loopback_pf(hw, true); |
| 6858 | igb_vmdq_set_replication_pf(hw, true); |
Greg Rose | 1380046 | 2010-11-06 02:08:26 +0000 | [diff] [blame] | 6859 | igb_vmdq_set_anti_spoofing_pf(hw, true, |
| 6860 | adapter->vfs_allocated_count); |
Alexander Duyck | d496030 | 2009-10-27 15:53:45 +0000 | [diff] [blame] | 6861 | } else { |
| 6862 | igb_vmdq_set_loopback_pf(hw, false); |
| 6863 | igb_vmdq_set_replication_pf(hw, false); |
| 6864 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 6865 | } |
| 6866 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 6867 | /* igb_main.c */ |